2 * QEMU PowerPC 440 embedded processors emulation
4 * Copyright (c) 2012 François Revol
5 * Copyright (c) 2016-2019 BALATON Zoltan
7 * This work is licensed under the GNU GPL license version 2 or later.
11 #include "qemu/osdep.h"
12 #include "qemu/units.h"
13 #include "qemu/error-report.h"
14 #include "qapi/error.h"
16 #include "qemu/module.h"
19 #include "exec/address-spaces.h"
20 #include "exec/memory.h"
21 #include "hw/ppc/ppc.h"
22 #include "hw/pci/pci.h"
23 #include "sysemu/block-backend.h"
26 /*****************************************************************************/
27 /* L2 Cache as SRAM */
30 DCR_L2CACHE_BASE
= 0x30,
31 DCR_L2CACHE_CFG
= DCR_L2CACHE_BASE
,
39 DCR_L2CACHE_END
= DCR_L2CACHE_SNP1
,
42 /* base is 460ex-specific, cf. U-Boot, ppc4xx-isram.h */
44 DCR_ISRAM0_BASE
= 0x20,
45 DCR_ISRAM0_SB0CR
= DCR_ISRAM0_BASE
,
56 DCR_ISRAM0_END
= DCR_ISRAM0_DPC
60 DCR_ISRAM1_BASE
= 0xb0,
61 DCR_ISRAM1_SB0CR
= DCR_ISRAM1_BASE
,
63 DCR_ISRAM1_BEAR
= DCR_ISRAM1_BASE
+ 0x04,
70 DCR_ISRAM1_END
= DCR_ISRAM1_DPC
73 typedef struct ppc4xx_l2sram_t
{
80 static void l2sram_update_mappings(ppc4xx_l2sram_t
*l2sram
,
81 uint32_t isarc
, uint32_t isacntl
,
82 uint32_t dsarc
, uint32_t dsacntl
)
84 if (l2sram
->isarc
!= isarc
||
85 (l2sram
->isacntl
& 0x80000000) != (isacntl
& 0x80000000)) {
86 if (l2sram
->isacntl
& 0x80000000) {
87 /* Unmap previously assigned memory region */
88 memory_region_del_subregion(get_system_memory(),
91 if (isacntl
& 0x80000000) {
92 /* Map new instruction memory region */
93 memory_region_add_subregion(get_system_memory(), isarc
,
97 if (l2sram
->dsarc
!= dsarc
||
98 (l2sram
->dsacntl
& 0x80000000) != (dsacntl
& 0x80000000)) {
99 if (l2sram
->dsacntl
& 0x80000000) {
100 /* Beware not to unmap the region we just mapped */
101 if (!(isacntl
& 0x80000000) || l2sram
->dsarc
!= isarc
) {
102 /* Unmap previously assigned memory region */
103 memory_region_del_subregion(get_system_memory(),
107 if (dsacntl
& 0x80000000) {
108 /* Beware not to remap the region we just mapped */
109 if (!(isacntl
& 0x80000000) || dsarc
!= isarc
) {
110 /* Map new data memory region */
111 memory_region_add_subregion(get_system_memory(), dsarc
,
119 static uint32_t dcr_read_l2sram(void *opaque
, int dcrn
)
121 ppc4xx_l2sram_t
*l2sram
= opaque
;
125 case DCR_L2CACHE_CFG
:
126 case DCR_L2CACHE_CMD
:
127 case DCR_L2CACHE_ADDR
:
128 case DCR_L2CACHE_DATA
:
129 case DCR_L2CACHE_STAT
:
130 case DCR_L2CACHE_CVER
:
131 case DCR_L2CACHE_SNP0
:
132 case DCR_L2CACHE_SNP1
:
133 ret
= l2sram
->l2cache
[dcrn
- DCR_L2CACHE_BASE
];
136 case DCR_ISRAM0_SB0CR
:
137 case DCR_ISRAM0_SB1CR
:
138 case DCR_ISRAM0_SB2CR
:
139 case DCR_ISRAM0_SB3CR
:
140 case DCR_ISRAM0_BEAR
:
141 case DCR_ISRAM0_BESR0
:
142 case DCR_ISRAM0_BESR1
:
143 case DCR_ISRAM0_PMEG
:
145 case DCR_ISRAM0_REVID
:
147 ret
= l2sram
->isram0
[dcrn
- DCR_ISRAM0_BASE
];
157 static void dcr_write_l2sram(void *opaque
, int dcrn
, uint32_t val
)
159 /*ppc4xx_l2sram_t *l2sram = opaque;*/
160 /* FIXME: Actually handle L2 cache mapping */
163 case DCR_L2CACHE_CFG
:
164 case DCR_L2CACHE_CMD
:
165 case DCR_L2CACHE_ADDR
:
166 case DCR_L2CACHE_DATA
:
167 case DCR_L2CACHE_STAT
:
168 case DCR_L2CACHE_CVER
:
169 case DCR_L2CACHE_SNP0
:
170 case DCR_L2CACHE_SNP1
:
171 /*l2sram->l2cache[dcrn - DCR_L2CACHE_BASE] = val;*/
174 case DCR_ISRAM0_SB0CR
:
175 case DCR_ISRAM0_SB1CR
:
176 case DCR_ISRAM0_SB2CR
:
177 case DCR_ISRAM0_SB3CR
:
178 case DCR_ISRAM0_BEAR
:
179 case DCR_ISRAM0_BESR0
:
180 case DCR_ISRAM0_BESR1
:
181 case DCR_ISRAM0_PMEG
:
183 case DCR_ISRAM0_REVID
:
185 /*l2sram->isram0[dcrn - DCR_L2CACHE_BASE] = val;*/
188 case DCR_ISRAM1_SB0CR
:
189 case DCR_ISRAM1_BEAR
:
190 case DCR_ISRAM1_BESR0
:
191 case DCR_ISRAM1_BESR1
:
192 case DCR_ISRAM1_PMEG
:
194 case DCR_ISRAM1_REVID
:
196 /*l2sram->isram1[dcrn - DCR_L2CACHE_BASE] = val;*/
199 /*l2sram_update_mappings(l2sram, isarc, isacntl, dsarc, dsacntl);*/
202 static void l2sram_reset(void *opaque
)
204 ppc4xx_l2sram_t
*l2sram
= opaque
;
206 memset(l2sram
->l2cache
, 0, sizeof(l2sram
->l2cache
));
207 l2sram
->l2cache
[DCR_L2CACHE_STAT
- DCR_L2CACHE_BASE
] = 0x80000000;
208 memset(l2sram
->isram0
, 0, sizeof(l2sram
->isram0
));
209 /*l2sram_update_mappings(l2sram, isarc, isacntl, dsarc, dsacntl);*/
212 void ppc4xx_l2sram_init(CPUPPCState
*env
)
214 ppc4xx_l2sram_t
*l2sram
;
216 l2sram
= g_malloc0(sizeof(*l2sram
));
217 /* XXX: Size is 4*64kB for 460ex, cf. U-Boot, ppc4xx-isram.h */
218 memory_region_init_ram(&l2sram
->bank
[0], NULL
, "ppc4xx.l2sram_bank0",
219 64 * KiB
, &error_abort
);
220 memory_region_init_ram(&l2sram
->bank
[1], NULL
, "ppc4xx.l2sram_bank1",
221 64 * KiB
, &error_abort
);
222 memory_region_init_ram(&l2sram
->bank
[2], NULL
, "ppc4xx.l2sram_bank2",
223 64 * KiB
, &error_abort
);
224 memory_region_init_ram(&l2sram
->bank
[3], NULL
, "ppc4xx.l2sram_bank3",
225 64 * KiB
, &error_abort
);
226 qemu_register_reset(&l2sram_reset
, l2sram
);
227 ppc_dcr_register(env
, DCR_L2CACHE_CFG
,
228 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
229 ppc_dcr_register(env
, DCR_L2CACHE_CMD
,
230 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
231 ppc_dcr_register(env
, DCR_L2CACHE_ADDR
,
232 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
233 ppc_dcr_register(env
, DCR_L2CACHE_DATA
,
234 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
235 ppc_dcr_register(env
, DCR_L2CACHE_STAT
,
236 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
237 ppc_dcr_register(env
, DCR_L2CACHE_CVER
,
238 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
239 ppc_dcr_register(env
, DCR_L2CACHE_SNP0
,
240 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
241 ppc_dcr_register(env
, DCR_L2CACHE_SNP1
,
242 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
244 ppc_dcr_register(env
, DCR_ISRAM0_SB0CR
,
245 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
246 ppc_dcr_register(env
, DCR_ISRAM0_SB1CR
,
247 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
248 ppc_dcr_register(env
, DCR_ISRAM0_SB2CR
,
249 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
250 ppc_dcr_register(env
, DCR_ISRAM0_SB3CR
,
251 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
252 ppc_dcr_register(env
, DCR_ISRAM0_PMEG
,
253 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
254 ppc_dcr_register(env
, DCR_ISRAM0_DPC
,
255 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
257 ppc_dcr_register(env
, DCR_ISRAM1_SB0CR
,
258 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
259 ppc_dcr_register(env
, DCR_ISRAM1_PMEG
,
260 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
261 ppc_dcr_register(env
, DCR_ISRAM1_DPC
,
262 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
265 /*****************************************************************************/
266 /* Clocking Power on Reset */
278 typedef struct ppc4xx_cpr_t
{
282 static uint32_t dcr_read_cpr(void *opaque
, int dcrn
)
284 ppc4xx_cpr_t
*cpr
= opaque
;
294 ret
= (0xb5 << 24) | (1 << 16) | (9 << 8);
317 static void dcr_write_cpr(void *opaque
, int dcrn
, uint32_t val
)
319 ppc4xx_cpr_t
*cpr
= opaque
;
332 static void ppc4xx_cpr_reset(void *opaque
)
334 ppc4xx_cpr_t
*cpr
= opaque
;
339 void ppc4xx_cpr_init(CPUPPCState
*env
)
343 cpr
= g_malloc0(sizeof(*cpr
));
344 ppc_dcr_register(env
, CPR0_CFGADDR
, cpr
, &dcr_read_cpr
, &dcr_write_cpr
);
345 ppc_dcr_register(env
, CPR0_CFGDATA
, cpr
, &dcr_read_cpr
, &dcr_write_cpr
);
346 qemu_register_reset(ppc4xx_cpr_reset
, cpr
);
349 /*****************************************************************************/
351 typedef struct ppc4xx_sdr_t ppc4xx_sdr_t
;
352 struct ppc4xx_sdr_t
{
357 SDR0_CFGADDR
= 0x00e,
373 PESDR0_RSTSTA
= 0x310,
377 PESDR1_RSTSTA
= 0x365,
380 #define SDR0_DDR0_DDRM_ENCODE(n) ((((unsigned long)(n)) & 0x03) << 29)
381 #define SDR0_DDR0_DDRM_DDR1 0x20000000
382 #define SDR0_DDR0_DDRM_DDR2 0x40000000
384 static uint32_t dcr_read_sdr(void *opaque
, int dcrn
)
386 ppc4xx_sdr_t
*sdr
= opaque
;
396 ret
= (0xb5 << 8) | (1 << 4) | 9;
399 ret
= (5 << 29) | (2 << 26) | (1 << 24);
402 ret
= 1 << 20; /* No Security/Kasumi support */
405 ret
= SDR0_DDR0_DDRM_ENCODE(1) | SDR0_DDR0_DDRM_DDR1
;
409 ret
= (1 << 24) | (1 << 16);
413 ret
= (1 << 16) | (1 << 12);
434 static void dcr_write_sdr(void *opaque
, int dcrn
, uint32_t val
)
436 ppc4xx_sdr_t
*sdr
= opaque
;
444 case 0x00: /* B0CR */
455 static void sdr_reset(void *opaque
)
457 ppc4xx_sdr_t
*sdr
= opaque
;
462 void ppc4xx_sdr_init(CPUPPCState
*env
)
466 sdr
= g_malloc0(sizeof(*sdr
));
467 qemu_register_reset(&sdr_reset
, sdr
);
468 ppc_dcr_register(env
, SDR0_CFGADDR
,
469 sdr
, &dcr_read_sdr
, &dcr_write_sdr
);
470 ppc_dcr_register(env
, SDR0_CFGDATA
,
471 sdr
, &dcr_read_sdr
, &dcr_write_sdr
);
472 ppc_dcr_register(env
, SDR0_102
,
473 sdr
, &dcr_read_sdr
, &dcr_write_sdr
);
474 ppc_dcr_register(env
, SDR0_103
,
475 sdr
, &dcr_read_sdr
, &dcr_write_sdr
);
476 ppc_dcr_register(env
, SDR0_128
,
477 sdr
, &dcr_read_sdr
, &dcr_write_sdr
);
478 ppc_dcr_register(env
, SDR0_USB0
,
479 sdr
, &dcr_read_sdr
, &dcr_write_sdr
);
482 /*****************************************************************************/
483 /* SDRAM controller */
484 typedef struct ppc440_sdram_t
{
487 MemoryRegion containers
[4]; /* used for clipping */
488 MemoryRegion
*ram_memories
;
495 SDRAM0_CFGADDR
= 0x10,
501 SDRAM_CONF1HB
= 0x45,
502 SDRAM_PLBADDULL
= 0x4a,
503 SDRAM_CONF1LL
= 0x4b,
504 SDRAM_CONFPATHB
= 0x4f,
505 SDRAM_PLBADDUHB
= 0x50,
508 static uint32_t sdram_bcr(hwaddr ram_base
, hwaddr ram_size
)
544 error_report("invalid RAM size " TARGET_FMT_plx
, ram_size
);
547 bcr
|= ram_base
>> 2 & 0xffe00000;
553 static inline hwaddr
sdram_base(uint32_t bcr
)
555 return (bcr
& 0xffe00000) << 2;
558 static uint64_t sdram_size(uint32_t bcr
)
563 sh
= 1024 - ((bcr
>> 6) & 0x3ff);
569 static void sdram_set_bcr(ppc440_sdram_t
*sdram
, int i
,
570 uint32_t bcr
, int enabled
)
572 if (sdram
->bcr
[i
] & 1) {
573 /* First unmap RAM if enabled */
574 memory_region_del_subregion(get_system_memory(),
575 &sdram
->containers
[i
]);
576 memory_region_del_subregion(&sdram
->containers
[i
],
577 &sdram
->ram_memories
[i
]);
578 object_unparent(OBJECT(&sdram
->containers
[i
]));
580 sdram
->bcr
[i
] = bcr
& 0xffe0ffc1;
581 if (enabled
&& (bcr
& 1)) {
582 memory_region_init(&sdram
->containers
[i
], NULL
, "sdram-containers",
584 memory_region_add_subregion(&sdram
->containers
[i
], 0,
585 &sdram
->ram_memories
[i
]);
586 memory_region_add_subregion(get_system_memory(),
588 &sdram
->containers
[i
]);
592 static void sdram_map_bcr(ppc440_sdram_t
*sdram
)
596 for (i
= 0; i
< sdram
->nbanks
; i
++) {
597 if (sdram
->ram_sizes
[i
] != 0) {
598 sdram_set_bcr(sdram
, i
, sdram_bcr(sdram
->ram_bases
[i
],
599 sdram
->ram_sizes
[i
]), 1);
601 sdram_set_bcr(sdram
, i
, 0, 0);
606 static uint32_t dcr_read_sdram(void *opaque
, int dcrn
)
608 ppc440_sdram_t
*sdram
= opaque
;
616 if (sdram
->ram_sizes
[dcrn
- SDRAM_R0BAS
]) {
617 ret
= sdram_bcr(sdram
->ram_bases
[dcrn
- SDRAM_R0BAS
],
618 sdram
->ram_sizes
[dcrn
- SDRAM_R0BAS
]);
623 case SDRAM_CONFPATHB
:
624 case SDRAM_PLBADDULL
:
625 case SDRAM_PLBADDUHB
:
631 switch (sdram
->addr
) {
632 case 0x14: /* SDRAM_MCSTAT (405EX) */
636 case 0x21: /* SDRAM_MCOPT2 */
639 case 0x40: /* SDRAM_MB0CF */
642 case 0x7A: /* SDRAM_DLCR */
645 case 0xE1: /* SDR0_DDR0 */
646 ret
= SDR0_DDR0_DDRM_ENCODE(1) | SDR0_DDR0_DDRM_DDR1
;
659 static void dcr_write_sdram(void *opaque
, int dcrn
, uint32_t val
)
661 ppc440_sdram_t
*sdram
= opaque
;
670 case SDRAM_CONFPATHB
:
671 case SDRAM_PLBADDULL
:
672 case SDRAM_PLBADDUHB
:
678 switch (sdram
->addr
) {
679 case 0x00: /* B0CR */
690 static void sdram_reset(void *opaque
)
692 ppc440_sdram_t
*sdram
= opaque
;
697 void ppc440_sdram_init(CPUPPCState
*env
, int nbanks
,
698 MemoryRegion
*ram_memories
,
699 hwaddr
*ram_bases
, hwaddr
*ram_sizes
,
702 ppc440_sdram_t
*sdram
;
704 sdram
= g_malloc0(sizeof(*sdram
));
705 sdram
->nbanks
= nbanks
;
706 sdram
->ram_memories
= ram_memories
;
707 memcpy(sdram
->ram_bases
, ram_bases
, nbanks
* sizeof(hwaddr
));
708 memcpy(sdram
->ram_sizes
, ram_sizes
, nbanks
* sizeof(hwaddr
));
709 qemu_register_reset(&sdram_reset
, sdram
);
710 ppc_dcr_register(env
, SDRAM0_CFGADDR
,
711 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
712 ppc_dcr_register(env
, SDRAM0_CFGDATA
,
713 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
715 sdram_map_bcr(sdram
);
718 ppc_dcr_register(env
, SDRAM_R0BAS
,
719 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
720 ppc_dcr_register(env
, SDRAM_R1BAS
,
721 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
722 ppc_dcr_register(env
, SDRAM_R2BAS
,
723 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
724 ppc_dcr_register(env
, SDRAM_R3BAS
,
725 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
726 ppc_dcr_register(env
, SDRAM_CONF1HB
,
727 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
728 ppc_dcr_register(env
, SDRAM_PLBADDULL
,
729 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
730 ppc_dcr_register(env
, SDRAM_CONF1LL
,
731 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
732 ppc_dcr_register(env
, SDRAM_CONFPATHB
,
733 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
734 ppc_dcr_register(env
, SDRAM_PLBADDUHB
,
735 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
738 /*****************************************************************************/
739 /* PLB to AHB bridge */
745 typedef struct ppc4xx_ahb_t
{
750 static uint32_t dcr_read_ahb(void *opaque
, int dcrn
)
752 ppc4xx_ahb_t
*ahb
= opaque
;
769 static void dcr_write_ahb(void *opaque
, int dcrn
, uint32_t val
)
771 ppc4xx_ahb_t
*ahb
= opaque
;
783 static void ppc4xx_ahb_reset(void *opaque
)
785 ppc4xx_ahb_t
*ahb
= opaque
;
792 void ppc4xx_ahb_init(CPUPPCState
*env
)
796 ahb
= g_malloc0(sizeof(*ahb
));
797 ppc_dcr_register(env
, AHB_TOP
, ahb
, &dcr_read_ahb
, &dcr_write_ahb
);
798 ppc_dcr_register(env
, AHB_BOT
, ahb
, &dcr_read_ahb
, &dcr_write_ahb
);
799 qemu_register_reset(ppc4xx_ahb_reset
, ahb
);
802 /*****************************************************************************/
805 #define DMA0_CR_CE (1 << 31)
806 #define DMA0_CR_PW (1 << 26 | 1 << 25)
807 #define DMA0_CR_DAI (1 << 24)
808 #define DMA0_CR_SAI (1 << 23)
809 #define DMA0_CR_DEC (1 << 2)
841 static uint32_t dcr_read_dma(void *opaque
, int dcrn
)
843 PPC4xxDmaState
*dma
= opaque
;
845 int addr
= dcrn
- dma
->base
;
852 val
= dma
->ch
[chnl
].cr
;
855 val
= dma
->ch
[chnl
].ct
;
858 val
= dma
->ch
[chnl
].sa
>> 32;
861 val
= dma
->ch
[chnl
].sa
;
864 val
= dma
->ch
[chnl
].da
>> 32;
867 val
= dma
->ch
[chnl
].da
;
870 val
= dma
->ch
[chnl
].sg
>> 32;
873 val
= dma
->ch
[chnl
].sg
;
881 qemu_log_mask(LOG_UNIMP
, "%s: unimplemented register %x (%d, %x)\n",
882 __func__
, dcrn
, chnl
, addr
);
888 static void dcr_write_dma(void *opaque
, int dcrn
, uint32_t val
)
890 PPC4xxDmaState
*dma
= opaque
;
891 int addr
= dcrn
- dma
->base
;
898 dma
->ch
[chnl
].cr
= val
;
899 if (val
& DMA0_CR_CE
) {
900 int count
= dma
->ch
[chnl
].ct
& 0xffff;
903 int width
, i
, sidx
, didx
;
904 uint8_t *rptr
, *wptr
;
908 width
= 1 << ((val
& DMA0_CR_PW
) >> 25);
909 rptr
= cpu_physical_memory_map(dma
->ch
[chnl
].sa
, &rlen
, 0);
910 wptr
= cpu_physical_memory_map(dma
->ch
[chnl
].da
, &wlen
, 1);
912 if (!(val
& DMA0_CR_DEC
) &&
913 val
& DMA0_CR_SAI
&& val
& DMA0_CR_DAI
) {
914 /* optimise common case */
915 memmove(wptr
, rptr
, count
* width
);
916 sidx
= didx
= count
* width
;
918 /* do it the slow way */
919 for (sidx
= didx
= i
= 0; i
< count
; i
++) {
920 uint64_t v
= ldn_le_p(rptr
+ sidx
, width
);
921 stn_le_p(wptr
+ didx
, width
, v
);
922 if (val
& DMA0_CR_SAI
) {
925 if (val
& DMA0_CR_DAI
) {
932 cpu_physical_memory_unmap(wptr
, wlen
, 1, didx
);
935 cpu_physical_memory_unmap(rptr
, rlen
, 0, sidx
);
941 dma
->ch
[chnl
].ct
= val
;
944 dma
->ch
[chnl
].sa
&= 0xffffffffULL
;
945 dma
->ch
[chnl
].sa
|= (uint64_t)val
<< 32;
948 dma
->ch
[chnl
].sa
&= 0xffffffff00000000ULL
;
949 dma
->ch
[chnl
].sa
|= val
;
952 dma
->ch
[chnl
].da
&= 0xffffffffULL
;
953 dma
->ch
[chnl
].da
|= (uint64_t)val
<< 32;
956 dma
->ch
[chnl
].da
&= 0xffffffff00000000ULL
;
957 dma
->ch
[chnl
].da
|= val
;
960 dma
->ch
[chnl
].sg
&= 0xffffffffULL
;
961 dma
->ch
[chnl
].sg
|= (uint64_t)val
<< 32;
964 dma
->ch
[chnl
].sg
&= 0xffffffff00000000ULL
;
965 dma
->ch
[chnl
].sg
|= val
;
973 qemu_log_mask(LOG_UNIMP
, "%s: unimplemented register %x (%d, %x)\n",
974 __func__
, dcrn
, chnl
, addr
);
978 static void ppc4xx_dma_reset(void *opaque
)
980 PPC4xxDmaState
*dma
= opaque
;
981 int dma_base
= dma
->base
;
983 memset(dma
, 0, sizeof(*dma
));
984 dma
->base
= dma_base
;
987 void ppc4xx_dma_init(CPUPPCState
*env
, int dcr_base
)
992 dma
= g_malloc0(sizeof(*dma
));
993 dma
->base
= dcr_base
;
994 qemu_register_reset(&ppc4xx_dma_reset
, dma
);
995 for (i
= 0; i
< 4; i
++) {
996 ppc_dcr_register(env
, dcr_base
+ i
* 8 + DMA0_CR
,
997 dma
, &dcr_read_dma
, &dcr_write_dma
);
998 ppc_dcr_register(env
, dcr_base
+ i
* 8 + DMA0_CT
,
999 dma
, &dcr_read_dma
, &dcr_write_dma
);
1000 ppc_dcr_register(env
, dcr_base
+ i
* 8 + DMA0_SAH
,
1001 dma
, &dcr_read_dma
, &dcr_write_dma
);
1002 ppc_dcr_register(env
, dcr_base
+ i
* 8 + DMA0_SAL
,
1003 dma
, &dcr_read_dma
, &dcr_write_dma
);
1004 ppc_dcr_register(env
, dcr_base
+ i
* 8 + DMA0_DAH
,
1005 dma
, &dcr_read_dma
, &dcr_write_dma
);
1006 ppc_dcr_register(env
, dcr_base
+ i
* 8 + DMA0_DAL
,
1007 dma
, &dcr_read_dma
, &dcr_write_dma
);
1008 ppc_dcr_register(env
, dcr_base
+ i
* 8 + DMA0_SGH
,
1009 dma
, &dcr_read_dma
, &dcr_write_dma
);
1010 ppc_dcr_register(env
, dcr_base
+ i
* 8 + DMA0_SGL
,
1011 dma
, &dcr_read_dma
, &dcr_write_dma
);
1013 ppc_dcr_register(env
, dcr_base
+ DMA0_SR
,
1014 dma
, &dcr_read_dma
, &dcr_write_dma
);
1015 ppc_dcr_register(env
, dcr_base
+ DMA0_SGC
,
1016 dma
, &dcr_read_dma
, &dcr_write_dma
);
1017 ppc_dcr_register(env
, dcr_base
+ DMA0_SLP
,
1018 dma
, &dcr_read_dma
, &dcr_write_dma
);
1019 ppc_dcr_register(env
, dcr_base
+ DMA0_POL
,
1020 dma
, &dcr_read_dma
, &dcr_write_dma
);
1023 /*****************************************************************************/
1024 /* PCI Express controller */
1025 /* FIXME: This is not complete and does not work, only implemented partially
1026 * to allow firmware and guests to find an empty bus. Cards should use PCI.
1028 #include "hw/pci/pcie_host.h"
1030 #define TYPE_PPC460EX_PCIE_HOST "ppc460ex-pcie-host"
1031 #define PPC460EX_PCIE_HOST(obj) \
1032 OBJECT_CHECK(PPC460EXPCIEState, (obj), TYPE_PPC460EX_PCIE_HOST)
1034 typedef struct PPC460EXPCIEState
{
1035 PCIExpressHost host
;
1055 } PPC460EXPCIEState
;
1057 #define DCRN_PCIE0_BASE 0x100
1058 #define DCRN_PCIE1_BASE 0x120
1086 static uint32_t dcr_read_pcie(void *opaque
, int dcrn
)
1088 PPC460EXPCIEState
*state
= opaque
;
1091 switch (dcrn
- state
->dcrn_base
) {
1093 ret
= state
->cfg_base
>> 32;
1096 ret
= state
->cfg_base
;
1099 ret
= state
->cfg_mask
;
1102 ret
= state
->msg_base
>> 32;
1105 ret
= state
->msg_base
;
1108 ret
= state
->msg_mask
;
1111 ret
= state
->omr1_base
>> 32;
1114 ret
= state
->omr1_base
;
1116 case PEGPL_OMR1MSKH
:
1117 ret
= state
->omr1_mask
>> 32;
1119 case PEGPL_OMR1MSKL
:
1120 ret
= state
->omr1_mask
;
1123 ret
= state
->omr2_base
>> 32;
1126 ret
= state
->omr2_base
;
1128 case PEGPL_OMR2MSKH
:
1129 ret
= state
->omr2_mask
>> 32;
1131 case PEGPL_OMR2MSKL
:
1132 ret
= state
->omr3_mask
;
1135 ret
= state
->omr3_base
>> 32;
1138 ret
= state
->omr3_base
;
1140 case PEGPL_OMR3MSKH
:
1141 ret
= state
->omr3_mask
>> 32;
1143 case PEGPL_OMR3MSKL
:
1144 ret
= state
->omr3_mask
;
1147 ret
= state
->reg_base
>> 32;
1150 ret
= state
->reg_base
;
1153 ret
= state
->reg_mask
;
1156 ret
= state
->special
;
1166 static void dcr_write_pcie(void *opaque
, int dcrn
, uint32_t val
)
1168 PPC460EXPCIEState
*s
= opaque
;
1171 switch (dcrn
- s
->dcrn_base
) {
1173 s
->cfg_base
= ((uint64_t)val
<< 32) | (s
->cfg_base
& 0xffffffff);
1176 s
->cfg_base
= (s
->cfg_base
& 0xffffffff00000000ULL
) | val
;
1180 size
= ~(val
& 0xfffffffe) + 1;
1181 qemu_mutex_lock_iothread();
1182 pcie_host_mmcfg_update(PCIE_HOST_BRIDGE(s
), val
& 1, s
->cfg_base
, size
);
1183 qemu_mutex_unlock_iothread();
1186 s
->msg_base
= ((uint64_t)val
<< 32) | (s
->msg_base
& 0xffffffff);
1189 s
->msg_base
= (s
->msg_base
& 0xffffffff00000000ULL
) | val
;
1195 s
->omr1_base
= ((uint64_t)val
<< 32) | (s
->omr1_base
& 0xffffffff);
1198 s
->omr1_base
= (s
->omr1_base
& 0xffffffff00000000ULL
) | val
;
1200 case PEGPL_OMR1MSKH
:
1201 s
->omr1_mask
= ((uint64_t)val
<< 32) | (s
->omr1_mask
& 0xffffffff);
1203 case PEGPL_OMR1MSKL
:
1204 s
->omr1_mask
= (s
->omr1_mask
& 0xffffffff00000000ULL
) | val
;
1207 s
->omr2_base
= ((uint64_t)val
<< 32) | (s
->omr2_base
& 0xffffffff);
1210 s
->omr2_base
= (s
->omr2_base
& 0xffffffff00000000ULL
) | val
;
1212 case PEGPL_OMR2MSKH
:
1213 s
->omr2_mask
= ((uint64_t)val
<< 32) | (s
->omr2_mask
& 0xffffffff);
1215 case PEGPL_OMR2MSKL
:
1216 s
->omr2_mask
= (s
->omr2_mask
& 0xffffffff00000000ULL
) | val
;
1219 s
->omr3_base
= ((uint64_t)val
<< 32) | (s
->omr3_base
& 0xffffffff);
1222 s
->omr3_base
= (s
->omr3_base
& 0xffffffff00000000ULL
) | val
;
1224 case PEGPL_OMR3MSKH
:
1225 s
->omr3_mask
= ((uint64_t)val
<< 32) | (s
->omr3_mask
& 0xffffffff);
1227 case PEGPL_OMR3MSKL
:
1228 s
->omr3_mask
= (s
->omr3_mask
& 0xffffffff00000000ULL
) | val
;
1231 s
->reg_base
= ((uint64_t)val
<< 32) | (s
->reg_base
& 0xffffffff);
1234 s
->reg_base
= (s
->reg_base
& 0xffffffff00000000ULL
) | val
;
1238 /* FIXME: how is size encoded? */
1239 size
= (val
== 0x7001 ? 4096 : ~(val
& 0xfffffffe) + 1);
1250 static void ppc460ex_set_irq(void *opaque
, int irq_num
, int level
)
1252 PPC460EXPCIEState
*s
= opaque
;
1253 qemu_set_irq(s
->irq
[irq_num
], level
);
1256 static void ppc460ex_pcie_realize(DeviceState
*dev
, Error
**errp
)
1258 PPC460EXPCIEState
*s
= PPC460EX_PCIE_HOST(dev
);
1259 PCIHostState
*pci
= PCI_HOST_BRIDGE(dev
);
1263 switch (s
->dcrn_base
) {
1264 case DCRN_PCIE0_BASE
:
1267 case DCRN_PCIE1_BASE
:
1271 error_setg(errp
, "invalid PCIe DCRN base");
1274 snprintf(buf
, sizeof(buf
), "pcie%d-io", id
);
1275 memory_region_init(&s
->iomem
, OBJECT(s
), buf
, UINT64_MAX
);
1276 for (i
= 0; i
< 4; i
++) {
1277 sysbus_init_irq(SYS_BUS_DEVICE(dev
), &s
->irq
[i
]);
1279 snprintf(buf
, sizeof(buf
), "pcie.%d", id
);
1280 pci
->bus
= pci_register_root_bus(DEVICE(s
), buf
, ppc460ex_set_irq
,
1281 pci_swizzle_map_irq_fn
, s
, &s
->iomem
,
1282 get_system_io(), 0, 4, TYPE_PCIE_BUS
);
1285 static Property ppc460ex_pcie_props
[] = {
1286 DEFINE_PROP_INT32("dcrn-base", PPC460EXPCIEState
, dcrn_base
, -1),
1287 DEFINE_PROP_END_OF_LIST(),
1290 static void ppc460ex_pcie_class_init(ObjectClass
*klass
, void *data
)
1292 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1294 set_bit(DEVICE_CATEGORY_BRIDGE
, dc
->categories
);
1295 dc
->realize
= ppc460ex_pcie_realize
;
1296 dc
->props
= ppc460ex_pcie_props
;
1297 dc
->hotpluggable
= false;
1300 static const TypeInfo ppc460ex_pcie_host_info
= {
1301 .name
= TYPE_PPC460EX_PCIE_HOST
,
1302 .parent
= TYPE_PCIE_HOST_BRIDGE
,
1303 .instance_size
= sizeof(PPC460EXPCIEState
),
1304 .class_init
= ppc460ex_pcie_class_init
,
1307 static void ppc460ex_pcie_register(void)
1309 type_register_static(&ppc460ex_pcie_host_info
);
1312 type_init(ppc460ex_pcie_register
)
1314 static void ppc460ex_pcie_register_dcrs(PPC460EXPCIEState
*s
, CPUPPCState
*env
)
1316 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_CFGBAH
, s
,
1317 &dcr_read_pcie
, &dcr_write_pcie
);
1318 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_CFGBAL
, s
,
1319 &dcr_read_pcie
, &dcr_write_pcie
);
1320 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_CFGMSK
, s
,
1321 &dcr_read_pcie
, &dcr_write_pcie
);
1322 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_MSGBAH
, s
,
1323 &dcr_read_pcie
, &dcr_write_pcie
);
1324 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_MSGBAL
, s
,
1325 &dcr_read_pcie
, &dcr_write_pcie
);
1326 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_MSGMSK
, s
,
1327 &dcr_read_pcie
, &dcr_write_pcie
);
1328 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR1BAH
, s
,
1329 &dcr_read_pcie
, &dcr_write_pcie
);
1330 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR1BAL
, s
,
1331 &dcr_read_pcie
, &dcr_write_pcie
);
1332 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR1MSKH
, s
,
1333 &dcr_read_pcie
, &dcr_write_pcie
);
1334 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR1MSKL
, s
,
1335 &dcr_read_pcie
, &dcr_write_pcie
);
1336 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR2BAH
, s
,
1337 &dcr_read_pcie
, &dcr_write_pcie
);
1338 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR2BAL
, s
,
1339 &dcr_read_pcie
, &dcr_write_pcie
);
1340 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR2MSKH
, s
,
1341 &dcr_read_pcie
, &dcr_write_pcie
);
1342 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR2MSKL
, s
,
1343 &dcr_read_pcie
, &dcr_write_pcie
);
1344 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR3BAH
, s
,
1345 &dcr_read_pcie
, &dcr_write_pcie
);
1346 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR3BAL
, s
,
1347 &dcr_read_pcie
, &dcr_write_pcie
);
1348 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR3MSKH
, s
,
1349 &dcr_read_pcie
, &dcr_write_pcie
);
1350 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR3MSKL
, s
,
1351 &dcr_read_pcie
, &dcr_write_pcie
);
1352 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_REGBAH
, s
,
1353 &dcr_read_pcie
, &dcr_write_pcie
);
1354 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_REGBAL
, s
,
1355 &dcr_read_pcie
, &dcr_write_pcie
);
1356 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_REGMSK
, s
,
1357 &dcr_read_pcie
, &dcr_write_pcie
);
1358 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_SPECIAL
, s
,
1359 &dcr_read_pcie
, &dcr_write_pcie
);
1360 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_CFG
, s
,
1361 &dcr_read_pcie
, &dcr_write_pcie
);
1364 void ppc460ex_pcie_init(CPUPPCState
*env
)
1368 dev
= qdev_create(NULL
, TYPE_PPC460EX_PCIE_HOST
);
1369 qdev_prop_set_int32(dev
, "dcrn-base", DCRN_PCIE0_BASE
);
1370 qdev_init_nofail(dev
);
1371 object_property_set_bool(OBJECT(dev
), true, "realized", NULL
);
1372 ppc460ex_pcie_register_dcrs(PPC460EX_PCIE_HOST(dev
), env
);
1374 dev
= qdev_create(NULL
, TYPE_PPC460EX_PCIE_HOST
);
1375 qdev_prop_set_int32(dev
, "dcrn-base", DCRN_PCIE1_BASE
);
1376 qdev_init_nofail(dev
);
1377 object_property_set_bool(OBJECT(dev
), true, "realized", NULL
);
1378 ppc460ex_pcie_register_dcrs(PPC460EX_PCIE_HOST(dev
), env
);