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/qdev-properties.h"
23 #include "hw/pci/pci.h"
24 #include "sysemu/block-backend.h"
25 #include "sysemu/reset.h"
28 /*****************************************************************************/
29 /* L2 Cache as SRAM */
32 DCR_L2CACHE_BASE
= 0x30,
33 DCR_L2CACHE_CFG
= DCR_L2CACHE_BASE
,
41 DCR_L2CACHE_END
= DCR_L2CACHE_SNP1
,
44 /* base is 460ex-specific, cf. U-Boot, ppc4xx-isram.h */
46 DCR_ISRAM0_BASE
= 0x20,
47 DCR_ISRAM0_SB0CR
= DCR_ISRAM0_BASE
,
58 DCR_ISRAM0_END
= DCR_ISRAM0_DPC
62 DCR_ISRAM1_BASE
= 0xb0,
63 DCR_ISRAM1_SB0CR
= DCR_ISRAM1_BASE
,
65 DCR_ISRAM1_BEAR
= DCR_ISRAM1_BASE
+ 0x04,
72 DCR_ISRAM1_END
= DCR_ISRAM1_DPC
75 typedef struct ppc4xx_l2sram_t
{
82 static void l2sram_update_mappings(ppc4xx_l2sram_t
*l2sram
,
83 uint32_t isarc
, uint32_t isacntl
,
84 uint32_t dsarc
, uint32_t dsacntl
)
86 if (l2sram
->isarc
!= isarc
||
87 (l2sram
->isacntl
& 0x80000000) != (isacntl
& 0x80000000)) {
88 if (l2sram
->isacntl
& 0x80000000) {
89 /* Unmap previously assigned memory region */
90 memory_region_del_subregion(get_system_memory(),
93 if (isacntl
& 0x80000000) {
94 /* Map new instruction memory region */
95 memory_region_add_subregion(get_system_memory(), isarc
,
99 if (l2sram
->dsarc
!= dsarc
||
100 (l2sram
->dsacntl
& 0x80000000) != (dsacntl
& 0x80000000)) {
101 if (l2sram
->dsacntl
& 0x80000000) {
102 /* Beware not to unmap the region we just mapped */
103 if (!(isacntl
& 0x80000000) || l2sram
->dsarc
!= isarc
) {
104 /* Unmap previously assigned memory region */
105 memory_region_del_subregion(get_system_memory(),
109 if (dsacntl
& 0x80000000) {
110 /* Beware not to remap the region we just mapped */
111 if (!(isacntl
& 0x80000000) || dsarc
!= isarc
) {
112 /* Map new data memory region */
113 memory_region_add_subregion(get_system_memory(), dsarc
,
121 static uint32_t dcr_read_l2sram(void *opaque
, int dcrn
)
123 ppc4xx_l2sram_t
*l2sram
= opaque
;
127 case DCR_L2CACHE_CFG
:
128 case DCR_L2CACHE_CMD
:
129 case DCR_L2CACHE_ADDR
:
130 case DCR_L2CACHE_DATA
:
131 case DCR_L2CACHE_STAT
:
132 case DCR_L2CACHE_CVER
:
133 case DCR_L2CACHE_SNP0
:
134 case DCR_L2CACHE_SNP1
:
135 ret
= l2sram
->l2cache
[dcrn
- DCR_L2CACHE_BASE
];
138 case DCR_ISRAM0_SB0CR
:
139 case DCR_ISRAM0_SB1CR
:
140 case DCR_ISRAM0_SB2CR
:
141 case DCR_ISRAM0_SB3CR
:
142 case DCR_ISRAM0_BEAR
:
143 case DCR_ISRAM0_BESR0
:
144 case DCR_ISRAM0_BESR1
:
145 case DCR_ISRAM0_PMEG
:
147 case DCR_ISRAM0_REVID
:
149 ret
= l2sram
->isram0
[dcrn
- DCR_ISRAM0_BASE
];
159 static void dcr_write_l2sram(void *opaque
, int dcrn
, uint32_t val
)
161 /*ppc4xx_l2sram_t *l2sram = opaque;*/
162 /* FIXME: Actually handle L2 cache mapping */
165 case DCR_L2CACHE_CFG
:
166 case DCR_L2CACHE_CMD
:
167 case DCR_L2CACHE_ADDR
:
168 case DCR_L2CACHE_DATA
:
169 case DCR_L2CACHE_STAT
:
170 case DCR_L2CACHE_CVER
:
171 case DCR_L2CACHE_SNP0
:
172 case DCR_L2CACHE_SNP1
:
173 /*l2sram->l2cache[dcrn - DCR_L2CACHE_BASE] = val;*/
176 case DCR_ISRAM0_SB0CR
:
177 case DCR_ISRAM0_SB1CR
:
178 case DCR_ISRAM0_SB2CR
:
179 case DCR_ISRAM0_SB3CR
:
180 case DCR_ISRAM0_BEAR
:
181 case DCR_ISRAM0_BESR0
:
182 case DCR_ISRAM0_BESR1
:
183 case DCR_ISRAM0_PMEG
:
185 case DCR_ISRAM0_REVID
:
187 /*l2sram->isram0[dcrn - DCR_L2CACHE_BASE] = val;*/
190 case DCR_ISRAM1_SB0CR
:
191 case DCR_ISRAM1_BEAR
:
192 case DCR_ISRAM1_BESR0
:
193 case DCR_ISRAM1_BESR1
:
194 case DCR_ISRAM1_PMEG
:
196 case DCR_ISRAM1_REVID
:
198 /*l2sram->isram1[dcrn - DCR_L2CACHE_BASE] = val;*/
201 /*l2sram_update_mappings(l2sram, isarc, isacntl, dsarc, dsacntl);*/
204 static void l2sram_reset(void *opaque
)
206 ppc4xx_l2sram_t
*l2sram
= opaque
;
208 memset(l2sram
->l2cache
, 0, sizeof(l2sram
->l2cache
));
209 l2sram
->l2cache
[DCR_L2CACHE_STAT
- DCR_L2CACHE_BASE
] = 0x80000000;
210 memset(l2sram
->isram0
, 0, sizeof(l2sram
->isram0
));
211 /*l2sram_update_mappings(l2sram, isarc, isacntl, dsarc, dsacntl);*/
214 void ppc4xx_l2sram_init(CPUPPCState
*env
)
216 ppc4xx_l2sram_t
*l2sram
;
218 l2sram
= g_malloc0(sizeof(*l2sram
));
219 /* XXX: Size is 4*64kB for 460ex, cf. U-Boot, ppc4xx-isram.h */
220 memory_region_init_ram(&l2sram
->bank
[0], NULL
, "ppc4xx.l2sram_bank0",
221 64 * KiB
, &error_abort
);
222 memory_region_init_ram(&l2sram
->bank
[1], NULL
, "ppc4xx.l2sram_bank1",
223 64 * KiB
, &error_abort
);
224 memory_region_init_ram(&l2sram
->bank
[2], NULL
, "ppc4xx.l2sram_bank2",
225 64 * KiB
, &error_abort
);
226 memory_region_init_ram(&l2sram
->bank
[3], NULL
, "ppc4xx.l2sram_bank3",
227 64 * KiB
, &error_abort
);
228 qemu_register_reset(&l2sram_reset
, l2sram
);
229 ppc_dcr_register(env
, DCR_L2CACHE_CFG
,
230 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
231 ppc_dcr_register(env
, DCR_L2CACHE_CMD
,
232 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
233 ppc_dcr_register(env
, DCR_L2CACHE_ADDR
,
234 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
235 ppc_dcr_register(env
, DCR_L2CACHE_DATA
,
236 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
237 ppc_dcr_register(env
, DCR_L2CACHE_STAT
,
238 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
239 ppc_dcr_register(env
, DCR_L2CACHE_CVER
,
240 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
241 ppc_dcr_register(env
, DCR_L2CACHE_SNP0
,
242 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
243 ppc_dcr_register(env
, DCR_L2CACHE_SNP1
,
244 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
246 ppc_dcr_register(env
, DCR_ISRAM0_SB0CR
,
247 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
248 ppc_dcr_register(env
, DCR_ISRAM0_SB1CR
,
249 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
250 ppc_dcr_register(env
, DCR_ISRAM0_SB2CR
,
251 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
252 ppc_dcr_register(env
, DCR_ISRAM0_SB3CR
,
253 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
254 ppc_dcr_register(env
, DCR_ISRAM0_PMEG
,
255 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
256 ppc_dcr_register(env
, DCR_ISRAM0_DPC
,
257 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
259 ppc_dcr_register(env
, DCR_ISRAM1_SB0CR
,
260 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
261 ppc_dcr_register(env
, DCR_ISRAM1_PMEG
,
262 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
263 ppc_dcr_register(env
, DCR_ISRAM1_DPC
,
264 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
267 /*****************************************************************************/
268 /* Clocking Power on Reset */
280 typedef struct ppc4xx_cpr_t
{
284 static uint32_t dcr_read_cpr(void *opaque
, int dcrn
)
286 ppc4xx_cpr_t
*cpr
= opaque
;
296 ret
= (0xb5 << 24) | (1 << 16) | (9 << 8);
319 static void dcr_write_cpr(void *opaque
, int dcrn
, uint32_t val
)
321 ppc4xx_cpr_t
*cpr
= opaque
;
334 static void ppc4xx_cpr_reset(void *opaque
)
336 ppc4xx_cpr_t
*cpr
= opaque
;
341 void ppc4xx_cpr_init(CPUPPCState
*env
)
345 cpr
= g_malloc0(sizeof(*cpr
));
346 ppc_dcr_register(env
, CPR0_CFGADDR
, cpr
, &dcr_read_cpr
, &dcr_write_cpr
);
347 ppc_dcr_register(env
, CPR0_CFGDATA
, cpr
, &dcr_read_cpr
, &dcr_write_cpr
);
348 qemu_register_reset(ppc4xx_cpr_reset
, cpr
);
351 /*****************************************************************************/
353 typedef struct ppc4xx_sdr_t ppc4xx_sdr_t
;
354 struct ppc4xx_sdr_t
{
359 SDR0_CFGADDR
= 0x00e,
375 PESDR0_RSTSTA
= 0x310,
379 PESDR1_RSTSTA
= 0x365,
382 #define SDR0_DDR0_DDRM_ENCODE(n) ((((unsigned long)(n)) & 0x03) << 29)
383 #define SDR0_DDR0_DDRM_DDR1 0x20000000
384 #define SDR0_DDR0_DDRM_DDR2 0x40000000
386 static uint32_t dcr_read_sdr(void *opaque
, int dcrn
)
388 ppc4xx_sdr_t
*sdr
= opaque
;
398 ret
= (0xb5 << 8) | (1 << 4) | 9;
401 ret
= (5 << 29) | (2 << 26) | (1 << 24);
404 ret
= 1 << 20; /* No Security/Kasumi support */
407 ret
= SDR0_DDR0_DDRM_ENCODE(1) | SDR0_DDR0_DDRM_DDR1
;
411 ret
= (1 << 24) | (1 << 16);
415 ret
= (1 << 16) | (1 << 12);
436 static void dcr_write_sdr(void *opaque
, int dcrn
, uint32_t val
)
438 ppc4xx_sdr_t
*sdr
= opaque
;
446 case 0x00: /* B0CR */
457 static void sdr_reset(void *opaque
)
459 ppc4xx_sdr_t
*sdr
= opaque
;
464 void ppc4xx_sdr_init(CPUPPCState
*env
)
468 sdr
= g_malloc0(sizeof(*sdr
));
469 qemu_register_reset(&sdr_reset
, sdr
);
470 ppc_dcr_register(env
, SDR0_CFGADDR
,
471 sdr
, &dcr_read_sdr
, &dcr_write_sdr
);
472 ppc_dcr_register(env
, SDR0_CFGDATA
,
473 sdr
, &dcr_read_sdr
, &dcr_write_sdr
);
474 ppc_dcr_register(env
, SDR0_102
,
475 sdr
, &dcr_read_sdr
, &dcr_write_sdr
);
476 ppc_dcr_register(env
, SDR0_103
,
477 sdr
, &dcr_read_sdr
, &dcr_write_sdr
);
478 ppc_dcr_register(env
, SDR0_128
,
479 sdr
, &dcr_read_sdr
, &dcr_write_sdr
);
480 ppc_dcr_register(env
, SDR0_USB0
,
481 sdr
, &dcr_read_sdr
, &dcr_write_sdr
);
484 /*****************************************************************************/
485 /* SDRAM controller */
486 typedef struct ppc440_sdram_t
{
489 MemoryRegion containers
[4]; /* used for clipping */
490 MemoryRegion
*ram_memories
;
497 SDRAM0_CFGADDR
= 0x10,
503 SDRAM_CONF1HB
= 0x45,
504 SDRAM_PLBADDULL
= 0x4a,
505 SDRAM_CONF1LL
= 0x4b,
506 SDRAM_CONFPATHB
= 0x4f,
507 SDRAM_PLBADDUHB
= 0x50,
510 static uint32_t sdram_bcr(hwaddr ram_base
, hwaddr ram_size
)
546 error_report("invalid RAM size " TARGET_FMT_plx
, ram_size
);
549 bcr
|= ram_base
>> 2 & 0xffe00000;
555 static inline hwaddr
sdram_base(uint32_t bcr
)
557 return (bcr
& 0xffe00000) << 2;
560 static uint64_t sdram_size(uint32_t bcr
)
565 sh
= 1024 - ((bcr
>> 6) & 0x3ff);
571 static void sdram_set_bcr(ppc440_sdram_t
*sdram
, int i
,
572 uint32_t bcr
, int enabled
)
574 if (sdram
->bcr
[i
] & 1) {
575 /* First unmap RAM if enabled */
576 memory_region_del_subregion(get_system_memory(),
577 &sdram
->containers
[i
]);
578 memory_region_del_subregion(&sdram
->containers
[i
],
579 &sdram
->ram_memories
[i
]);
580 object_unparent(OBJECT(&sdram
->containers
[i
]));
582 sdram
->bcr
[i
] = bcr
& 0xffe0ffc1;
583 if (enabled
&& (bcr
& 1)) {
584 memory_region_init(&sdram
->containers
[i
], NULL
, "sdram-containers",
586 memory_region_add_subregion(&sdram
->containers
[i
], 0,
587 &sdram
->ram_memories
[i
]);
588 memory_region_add_subregion(get_system_memory(),
590 &sdram
->containers
[i
]);
594 static void sdram_map_bcr(ppc440_sdram_t
*sdram
)
598 for (i
= 0; i
< sdram
->nbanks
; i
++) {
599 if (sdram
->ram_sizes
[i
] != 0) {
600 sdram_set_bcr(sdram
, i
, sdram_bcr(sdram
->ram_bases
[i
],
601 sdram
->ram_sizes
[i
]), 1);
603 sdram_set_bcr(sdram
, i
, 0, 0);
608 static uint32_t dcr_read_sdram(void *opaque
, int dcrn
)
610 ppc440_sdram_t
*sdram
= opaque
;
618 if (sdram
->ram_sizes
[dcrn
- SDRAM_R0BAS
]) {
619 ret
= sdram_bcr(sdram
->ram_bases
[dcrn
- SDRAM_R0BAS
],
620 sdram
->ram_sizes
[dcrn
- SDRAM_R0BAS
]);
625 case SDRAM_CONFPATHB
:
626 case SDRAM_PLBADDULL
:
627 case SDRAM_PLBADDUHB
:
633 switch (sdram
->addr
) {
634 case 0x14: /* SDRAM_MCSTAT (405EX) */
638 case 0x21: /* SDRAM_MCOPT2 */
641 case 0x40: /* SDRAM_MB0CF */
644 case 0x7A: /* SDRAM_DLCR */
647 case 0xE1: /* SDR0_DDR0 */
648 ret
= SDR0_DDR0_DDRM_ENCODE(1) | SDR0_DDR0_DDRM_DDR1
;
661 static void dcr_write_sdram(void *opaque
, int dcrn
, uint32_t val
)
663 ppc440_sdram_t
*sdram
= opaque
;
672 case SDRAM_CONFPATHB
:
673 case SDRAM_PLBADDULL
:
674 case SDRAM_PLBADDUHB
:
680 switch (sdram
->addr
) {
681 case 0x00: /* B0CR */
692 static void sdram_reset(void *opaque
)
694 ppc440_sdram_t
*sdram
= opaque
;
699 void ppc440_sdram_init(CPUPPCState
*env
, int nbanks
,
700 MemoryRegion
*ram_memories
,
701 hwaddr
*ram_bases
, hwaddr
*ram_sizes
,
704 ppc440_sdram_t
*sdram
;
706 sdram
= g_malloc0(sizeof(*sdram
));
707 sdram
->nbanks
= nbanks
;
708 sdram
->ram_memories
= ram_memories
;
709 memcpy(sdram
->ram_bases
, ram_bases
, nbanks
* sizeof(hwaddr
));
710 memcpy(sdram
->ram_sizes
, ram_sizes
, nbanks
* sizeof(hwaddr
));
711 qemu_register_reset(&sdram_reset
, sdram
);
712 ppc_dcr_register(env
, SDRAM0_CFGADDR
,
713 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
714 ppc_dcr_register(env
, SDRAM0_CFGDATA
,
715 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
717 sdram_map_bcr(sdram
);
720 ppc_dcr_register(env
, SDRAM_R0BAS
,
721 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
722 ppc_dcr_register(env
, SDRAM_R1BAS
,
723 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
724 ppc_dcr_register(env
, SDRAM_R2BAS
,
725 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
726 ppc_dcr_register(env
, SDRAM_R3BAS
,
727 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
728 ppc_dcr_register(env
, SDRAM_CONF1HB
,
729 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
730 ppc_dcr_register(env
, SDRAM_PLBADDULL
,
731 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
732 ppc_dcr_register(env
, SDRAM_CONF1LL
,
733 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
734 ppc_dcr_register(env
, SDRAM_CONFPATHB
,
735 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
736 ppc_dcr_register(env
, SDRAM_PLBADDUHB
,
737 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
740 /*****************************************************************************/
741 /* PLB to AHB bridge */
747 typedef struct ppc4xx_ahb_t
{
752 static uint32_t dcr_read_ahb(void *opaque
, int dcrn
)
754 ppc4xx_ahb_t
*ahb
= opaque
;
771 static void dcr_write_ahb(void *opaque
, int dcrn
, uint32_t val
)
773 ppc4xx_ahb_t
*ahb
= opaque
;
785 static void ppc4xx_ahb_reset(void *opaque
)
787 ppc4xx_ahb_t
*ahb
= opaque
;
794 void ppc4xx_ahb_init(CPUPPCState
*env
)
798 ahb
= g_malloc0(sizeof(*ahb
));
799 ppc_dcr_register(env
, AHB_TOP
, ahb
, &dcr_read_ahb
, &dcr_write_ahb
);
800 ppc_dcr_register(env
, AHB_BOT
, ahb
, &dcr_read_ahb
, &dcr_write_ahb
);
801 qemu_register_reset(ppc4xx_ahb_reset
, ahb
);
804 /*****************************************************************************/
807 #define DMA0_CR_CE (1 << 31)
808 #define DMA0_CR_PW (1 << 26 | 1 << 25)
809 #define DMA0_CR_DAI (1 << 24)
810 #define DMA0_CR_SAI (1 << 23)
811 #define DMA0_CR_DEC (1 << 2)
843 static uint32_t dcr_read_dma(void *opaque
, int dcrn
)
845 PPC4xxDmaState
*dma
= opaque
;
847 int addr
= dcrn
- dma
->base
;
854 val
= dma
->ch
[chnl
].cr
;
857 val
= dma
->ch
[chnl
].ct
;
860 val
= dma
->ch
[chnl
].sa
>> 32;
863 val
= dma
->ch
[chnl
].sa
;
866 val
= dma
->ch
[chnl
].da
>> 32;
869 val
= dma
->ch
[chnl
].da
;
872 val
= dma
->ch
[chnl
].sg
>> 32;
875 val
= dma
->ch
[chnl
].sg
;
883 qemu_log_mask(LOG_UNIMP
, "%s: unimplemented register %x (%d, %x)\n",
884 __func__
, dcrn
, chnl
, addr
);
890 static void dcr_write_dma(void *opaque
, int dcrn
, uint32_t val
)
892 PPC4xxDmaState
*dma
= opaque
;
893 int addr
= dcrn
- dma
->base
;
900 dma
->ch
[chnl
].cr
= val
;
901 if (val
& DMA0_CR_CE
) {
902 int count
= dma
->ch
[chnl
].ct
& 0xffff;
905 int width
, i
, sidx
, didx
;
906 uint8_t *rptr
, *wptr
;
910 width
= 1 << ((val
& DMA0_CR_PW
) >> 25);
911 rptr
= cpu_physical_memory_map(dma
->ch
[chnl
].sa
, &rlen
,
913 wptr
= cpu_physical_memory_map(dma
->ch
[chnl
].da
, &wlen
,
916 if (!(val
& DMA0_CR_DEC
) &&
917 val
& DMA0_CR_SAI
&& val
& DMA0_CR_DAI
) {
918 /* optimise common case */
919 memmove(wptr
, rptr
, count
* width
);
920 sidx
= didx
= count
* width
;
922 /* do it the slow way */
923 for (sidx
= didx
= i
= 0; i
< count
; i
++) {
924 uint64_t v
= ldn_le_p(rptr
+ sidx
, width
);
925 stn_le_p(wptr
+ didx
, width
, v
);
926 if (val
& DMA0_CR_SAI
) {
929 if (val
& DMA0_CR_DAI
) {
936 cpu_physical_memory_unmap(wptr
, wlen
, 1, didx
);
939 cpu_physical_memory_unmap(rptr
, rlen
, 0, sidx
);
945 dma
->ch
[chnl
].ct
= val
;
948 dma
->ch
[chnl
].sa
&= 0xffffffffULL
;
949 dma
->ch
[chnl
].sa
|= (uint64_t)val
<< 32;
952 dma
->ch
[chnl
].sa
&= 0xffffffff00000000ULL
;
953 dma
->ch
[chnl
].sa
|= val
;
956 dma
->ch
[chnl
].da
&= 0xffffffffULL
;
957 dma
->ch
[chnl
].da
|= (uint64_t)val
<< 32;
960 dma
->ch
[chnl
].da
&= 0xffffffff00000000ULL
;
961 dma
->ch
[chnl
].da
|= val
;
964 dma
->ch
[chnl
].sg
&= 0xffffffffULL
;
965 dma
->ch
[chnl
].sg
|= (uint64_t)val
<< 32;
968 dma
->ch
[chnl
].sg
&= 0xffffffff00000000ULL
;
969 dma
->ch
[chnl
].sg
|= val
;
977 qemu_log_mask(LOG_UNIMP
, "%s: unimplemented register %x (%d, %x)\n",
978 __func__
, dcrn
, chnl
, addr
);
982 static void ppc4xx_dma_reset(void *opaque
)
984 PPC4xxDmaState
*dma
= opaque
;
985 int dma_base
= dma
->base
;
987 memset(dma
, 0, sizeof(*dma
));
988 dma
->base
= dma_base
;
991 void ppc4xx_dma_init(CPUPPCState
*env
, int dcr_base
)
996 dma
= g_malloc0(sizeof(*dma
));
997 dma
->base
= dcr_base
;
998 qemu_register_reset(&ppc4xx_dma_reset
, dma
);
999 for (i
= 0; i
< 4; i
++) {
1000 ppc_dcr_register(env
, dcr_base
+ i
* 8 + DMA0_CR
,
1001 dma
, &dcr_read_dma
, &dcr_write_dma
);
1002 ppc_dcr_register(env
, dcr_base
+ i
* 8 + DMA0_CT
,
1003 dma
, &dcr_read_dma
, &dcr_write_dma
);
1004 ppc_dcr_register(env
, dcr_base
+ i
* 8 + DMA0_SAH
,
1005 dma
, &dcr_read_dma
, &dcr_write_dma
);
1006 ppc_dcr_register(env
, dcr_base
+ i
* 8 + DMA0_SAL
,
1007 dma
, &dcr_read_dma
, &dcr_write_dma
);
1008 ppc_dcr_register(env
, dcr_base
+ i
* 8 + DMA0_DAH
,
1009 dma
, &dcr_read_dma
, &dcr_write_dma
);
1010 ppc_dcr_register(env
, dcr_base
+ i
* 8 + DMA0_DAL
,
1011 dma
, &dcr_read_dma
, &dcr_write_dma
);
1012 ppc_dcr_register(env
, dcr_base
+ i
* 8 + DMA0_SGH
,
1013 dma
, &dcr_read_dma
, &dcr_write_dma
);
1014 ppc_dcr_register(env
, dcr_base
+ i
* 8 + DMA0_SGL
,
1015 dma
, &dcr_read_dma
, &dcr_write_dma
);
1017 ppc_dcr_register(env
, dcr_base
+ DMA0_SR
,
1018 dma
, &dcr_read_dma
, &dcr_write_dma
);
1019 ppc_dcr_register(env
, dcr_base
+ DMA0_SGC
,
1020 dma
, &dcr_read_dma
, &dcr_write_dma
);
1021 ppc_dcr_register(env
, dcr_base
+ DMA0_SLP
,
1022 dma
, &dcr_read_dma
, &dcr_write_dma
);
1023 ppc_dcr_register(env
, dcr_base
+ DMA0_POL
,
1024 dma
, &dcr_read_dma
, &dcr_write_dma
);
1027 /*****************************************************************************/
1028 /* PCI Express controller */
1029 /* FIXME: This is not complete and does not work, only implemented partially
1030 * to allow firmware and guests to find an empty bus. Cards should use PCI.
1032 #include "hw/pci/pcie_host.h"
1034 #define TYPE_PPC460EX_PCIE_HOST "ppc460ex-pcie-host"
1035 #define PPC460EX_PCIE_HOST(obj) \
1036 OBJECT_CHECK(PPC460EXPCIEState, (obj), TYPE_PPC460EX_PCIE_HOST)
1038 typedef struct PPC460EXPCIEState
{
1039 PCIExpressHost host
;
1059 } PPC460EXPCIEState
;
1061 #define DCRN_PCIE0_BASE 0x100
1062 #define DCRN_PCIE1_BASE 0x120
1090 static uint32_t dcr_read_pcie(void *opaque
, int dcrn
)
1092 PPC460EXPCIEState
*state
= opaque
;
1095 switch (dcrn
- state
->dcrn_base
) {
1097 ret
= state
->cfg_base
>> 32;
1100 ret
= state
->cfg_base
;
1103 ret
= state
->cfg_mask
;
1106 ret
= state
->msg_base
>> 32;
1109 ret
= state
->msg_base
;
1112 ret
= state
->msg_mask
;
1115 ret
= state
->omr1_base
>> 32;
1118 ret
= state
->omr1_base
;
1120 case PEGPL_OMR1MSKH
:
1121 ret
= state
->omr1_mask
>> 32;
1123 case PEGPL_OMR1MSKL
:
1124 ret
= state
->omr1_mask
;
1127 ret
= state
->omr2_base
>> 32;
1130 ret
= state
->omr2_base
;
1132 case PEGPL_OMR2MSKH
:
1133 ret
= state
->omr2_mask
>> 32;
1135 case PEGPL_OMR2MSKL
:
1136 ret
= state
->omr3_mask
;
1139 ret
= state
->omr3_base
>> 32;
1142 ret
= state
->omr3_base
;
1144 case PEGPL_OMR3MSKH
:
1145 ret
= state
->omr3_mask
>> 32;
1147 case PEGPL_OMR3MSKL
:
1148 ret
= state
->omr3_mask
;
1151 ret
= state
->reg_base
>> 32;
1154 ret
= state
->reg_base
;
1157 ret
= state
->reg_mask
;
1160 ret
= state
->special
;
1170 static void dcr_write_pcie(void *opaque
, int dcrn
, uint32_t val
)
1172 PPC460EXPCIEState
*s
= opaque
;
1175 switch (dcrn
- s
->dcrn_base
) {
1177 s
->cfg_base
= ((uint64_t)val
<< 32) | (s
->cfg_base
& 0xffffffff);
1180 s
->cfg_base
= (s
->cfg_base
& 0xffffffff00000000ULL
) | val
;
1184 size
= ~(val
& 0xfffffffe) + 1;
1185 pcie_host_mmcfg_update(PCIE_HOST_BRIDGE(s
), val
& 1, s
->cfg_base
, size
);
1188 s
->msg_base
= ((uint64_t)val
<< 32) | (s
->msg_base
& 0xffffffff);
1191 s
->msg_base
= (s
->msg_base
& 0xffffffff00000000ULL
) | val
;
1197 s
->omr1_base
= ((uint64_t)val
<< 32) | (s
->omr1_base
& 0xffffffff);
1200 s
->omr1_base
= (s
->omr1_base
& 0xffffffff00000000ULL
) | val
;
1202 case PEGPL_OMR1MSKH
:
1203 s
->omr1_mask
= ((uint64_t)val
<< 32) | (s
->omr1_mask
& 0xffffffff);
1205 case PEGPL_OMR1MSKL
:
1206 s
->omr1_mask
= (s
->omr1_mask
& 0xffffffff00000000ULL
) | val
;
1209 s
->omr2_base
= ((uint64_t)val
<< 32) | (s
->omr2_base
& 0xffffffff);
1212 s
->omr2_base
= (s
->omr2_base
& 0xffffffff00000000ULL
) | val
;
1214 case PEGPL_OMR2MSKH
:
1215 s
->omr2_mask
= ((uint64_t)val
<< 32) | (s
->omr2_mask
& 0xffffffff);
1217 case PEGPL_OMR2MSKL
:
1218 s
->omr2_mask
= (s
->omr2_mask
& 0xffffffff00000000ULL
) | val
;
1221 s
->omr3_base
= ((uint64_t)val
<< 32) | (s
->omr3_base
& 0xffffffff);
1224 s
->omr3_base
= (s
->omr3_base
& 0xffffffff00000000ULL
) | val
;
1226 case PEGPL_OMR3MSKH
:
1227 s
->omr3_mask
= ((uint64_t)val
<< 32) | (s
->omr3_mask
& 0xffffffff);
1229 case PEGPL_OMR3MSKL
:
1230 s
->omr3_mask
= (s
->omr3_mask
& 0xffffffff00000000ULL
) | val
;
1233 s
->reg_base
= ((uint64_t)val
<< 32) | (s
->reg_base
& 0xffffffff);
1236 s
->reg_base
= (s
->reg_base
& 0xffffffff00000000ULL
) | val
;
1240 /* FIXME: how is size encoded? */
1241 size
= (val
== 0x7001 ? 4096 : ~(val
& 0xfffffffe) + 1);
1252 static void ppc460ex_set_irq(void *opaque
, int irq_num
, int level
)
1254 PPC460EXPCIEState
*s
= opaque
;
1255 qemu_set_irq(s
->irq
[irq_num
], level
);
1258 static void ppc460ex_pcie_realize(DeviceState
*dev
, Error
**errp
)
1260 PPC460EXPCIEState
*s
= PPC460EX_PCIE_HOST(dev
);
1261 PCIHostState
*pci
= PCI_HOST_BRIDGE(dev
);
1265 switch (s
->dcrn_base
) {
1266 case DCRN_PCIE0_BASE
:
1269 case DCRN_PCIE1_BASE
:
1273 error_setg(errp
, "invalid PCIe DCRN base");
1276 snprintf(buf
, sizeof(buf
), "pcie%d-io", id
);
1277 memory_region_init(&s
->iomem
, OBJECT(s
), buf
, UINT64_MAX
);
1278 for (i
= 0; i
< 4; i
++) {
1279 sysbus_init_irq(SYS_BUS_DEVICE(dev
), &s
->irq
[i
]);
1281 snprintf(buf
, sizeof(buf
), "pcie.%d", id
);
1282 pci
->bus
= pci_register_root_bus(DEVICE(s
), buf
, ppc460ex_set_irq
,
1283 pci_swizzle_map_irq_fn
, s
, &s
->iomem
,
1284 get_system_io(), 0, 4, TYPE_PCIE_BUS
);
1287 static Property ppc460ex_pcie_props
[] = {
1288 DEFINE_PROP_INT32("dcrn-base", PPC460EXPCIEState
, dcrn_base
, -1),
1289 DEFINE_PROP_END_OF_LIST(),
1292 static void ppc460ex_pcie_class_init(ObjectClass
*klass
, void *data
)
1294 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1296 set_bit(DEVICE_CATEGORY_BRIDGE
, dc
->categories
);
1297 dc
->realize
= ppc460ex_pcie_realize
;
1298 device_class_set_props(dc
, ppc460ex_pcie_props
);
1299 dc
->hotpluggable
= false;
1302 static const TypeInfo ppc460ex_pcie_host_info
= {
1303 .name
= TYPE_PPC460EX_PCIE_HOST
,
1304 .parent
= TYPE_PCIE_HOST_BRIDGE
,
1305 .instance_size
= sizeof(PPC460EXPCIEState
),
1306 .class_init
= ppc460ex_pcie_class_init
,
1309 static void ppc460ex_pcie_register(void)
1311 type_register_static(&ppc460ex_pcie_host_info
);
1314 type_init(ppc460ex_pcie_register
)
1316 static void ppc460ex_pcie_register_dcrs(PPC460EXPCIEState
*s
, CPUPPCState
*env
)
1318 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_CFGBAH
, s
,
1319 &dcr_read_pcie
, &dcr_write_pcie
);
1320 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_CFGBAL
, s
,
1321 &dcr_read_pcie
, &dcr_write_pcie
);
1322 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_CFGMSK
, s
,
1323 &dcr_read_pcie
, &dcr_write_pcie
);
1324 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_MSGBAH
, s
,
1325 &dcr_read_pcie
, &dcr_write_pcie
);
1326 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_MSGBAL
, s
,
1327 &dcr_read_pcie
, &dcr_write_pcie
);
1328 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_MSGMSK
, s
,
1329 &dcr_read_pcie
, &dcr_write_pcie
);
1330 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR1BAH
, s
,
1331 &dcr_read_pcie
, &dcr_write_pcie
);
1332 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR1BAL
, s
,
1333 &dcr_read_pcie
, &dcr_write_pcie
);
1334 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR1MSKH
, s
,
1335 &dcr_read_pcie
, &dcr_write_pcie
);
1336 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR1MSKL
, s
,
1337 &dcr_read_pcie
, &dcr_write_pcie
);
1338 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR2BAH
, s
,
1339 &dcr_read_pcie
, &dcr_write_pcie
);
1340 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR2BAL
, s
,
1341 &dcr_read_pcie
, &dcr_write_pcie
);
1342 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR2MSKH
, s
,
1343 &dcr_read_pcie
, &dcr_write_pcie
);
1344 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR2MSKL
, s
,
1345 &dcr_read_pcie
, &dcr_write_pcie
);
1346 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR3BAH
, s
,
1347 &dcr_read_pcie
, &dcr_write_pcie
);
1348 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR3BAL
, s
,
1349 &dcr_read_pcie
, &dcr_write_pcie
);
1350 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR3MSKH
, s
,
1351 &dcr_read_pcie
, &dcr_write_pcie
);
1352 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR3MSKL
, s
,
1353 &dcr_read_pcie
, &dcr_write_pcie
);
1354 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_REGBAH
, s
,
1355 &dcr_read_pcie
, &dcr_write_pcie
);
1356 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_REGBAL
, s
,
1357 &dcr_read_pcie
, &dcr_write_pcie
);
1358 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_REGMSK
, s
,
1359 &dcr_read_pcie
, &dcr_write_pcie
);
1360 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_SPECIAL
, s
,
1361 &dcr_read_pcie
, &dcr_write_pcie
);
1362 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_CFG
, s
,
1363 &dcr_read_pcie
, &dcr_write_pcie
);
1366 void ppc460ex_pcie_init(CPUPPCState
*env
)
1370 dev
= qdev_new(TYPE_PPC460EX_PCIE_HOST
);
1371 qdev_prop_set_int32(dev
, "dcrn-base", DCRN_PCIE0_BASE
);
1372 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
1373 ppc460ex_pcie_register_dcrs(PPC460EX_PCIE_HOST(dev
), env
);
1375 dev
= qdev_new(TYPE_PPC460EX_PCIE_HOST
);
1376 qdev_prop_set_int32(dev
, "dcrn-base", DCRN_PCIE1_BASE
);
1377 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
1378 ppc460ex_pcie_register_dcrs(PPC460EX_PCIE_HOST(dev
), env
);