2 * QEMU PowerPC 440 embedded processors emulation
4 * Copyright (c) 2012 François Revol
5 * Copyright (c) 2016-2018 BALATON Zoltan
7 * This work is licensed under the GNU GPL license version 2 or later.
11 #include "qemu/osdep.h"
12 #include "qemu-common.h"
13 #include "qemu/cutils.h"
14 #include "qemu/error-report.h"
15 #include "qapi/error.h"
18 #include "exec/address-spaces.h"
19 #include "exec/memory.h"
20 #include "hw/ppc/ppc.h"
21 #include "hw/pci/pci.h"
22 #include "sysemu/block-backend.h"
23 #include "hw/ppc/ppc440.h"
25 /*****************************************************************************/
26 /* L2 Cache as SRAM */
29 DCR_L2CACHE_BASE
= 0x30,
30 DCR_L2CACHE_CFG
= DCR_L2CACHE_BASE
,
38 DCR_L2CACHE_END
= DCR_L2CACHE_SNP1
,
41 /* base is 460ex-specific, cf. U-Boot, ppc4xx-isram.h */
43 DCR_ISRAM0_BASE
= 0x20,
44 DCR_ISRAM0_SB0CR
= DCR_ISRAM0_BASE
,
55 DCR_ISRAM0_END
= DCR_ISRAM0_DPC
59 DCR_ISRAM1_BASE
= 0xb0,
60 DCR_ISRAM1_SB0CR
= DCR_ISRAM1_BASE
,
62 DCR_ISRAM1_BEAR
= DCR_ISRAM1_BASE
+ 0x04,
69 DCR_ISRAM1_END
= DCR_ISRAM1_DPC
72 typedef struct ppc4xx_l2sram_t
{
79 static void l2sram_update_mappings(ppc4xx_l2sram_t
*l2sram
,
80 uint32_t isarc
, uint32_t isacntl
,
81 uint32_t dsarc
, uint32_t dsacntl
)
83 if (l2sram
->isarc
!= isarc
||
84 (l2sram
->isacntl
& 0x80000000) != (isacntl
& 0x80000000)) {
85 if (l2sram
->isacntl
& 0x80000000) {
86 /* Unmap previously assigned memory region */
87 memory_region_del_subregion(get_system_memory(),
90 if (isacntl
& 0x80000000) {
91 /* Map new instruction memory region */
92 memory_region_add_subregion(get_system_memory(), isarc
,
96 if (l2sram
->dsarc
!= dsarc
||
97 (l2sram
->dsacntl
& 0x80000000) != (dsacntl
& 0x80000000)) {
98 if (l2sram
->dsacntl
& 0x80000000) {
99 /* Beware not to unmap the region we just mapped */
100 if (!(isacntl
& 0x80000000) || l2sram
->dsarc
!= isarc
) {
101 /* Unmap previously assigned memory region */
102 memory_region_del_subregion(get_system_memory(),
106 if (dsacntl
& 0x80000000) {
107 /* Beware not to remap the region we just mapped */
108 if (!(isacntl
& 0x80000000) || dsarc
!= isarc
) {
109 /* Map new data memory region */
110 memory_region_add_subregion(get_system_memory(), dsarc
,
118 static uint32_t dcr_read_l2sram(void *opaque
, int dcrn
)
120 ppc4xx_l2sram_t
*l2sram
= opaque
;
124 case DCR_L2CACHE_CFG
:
125 case DCR_L2CACHE_CMD
:
126 case DCR_L2CACHE_ADDR
:
127 case DCR_L2CACHE_DATA
:
128 case DCR_L2CACHE_STAT
:
129 case DCR_L2CACHE_CVER
:
130 case DCR_L2CACHE_SNP0
:
131 case DCR_L2CACHE_SNP1
:
132 ret
= l2sram
->l2cache
[dcrn
- DCR_L2CACHE_BASE
];
135 case DCR_ISRAM0_SB0CR
:
136 case DCR_ISRAM0_SB1CR
:
137 case DCR_ISRAM0_SB2CR
:
138 case DCR_ISRAM0_SB3CR
:
139 case DCR_ISRAM0_BEAR
:
140 case DCR_ISRAM0_BESR0
:
141 case DCR_ISRAM0_BESR1
:
142 case DCR_ISRAM0_PMEG
:
144 case DCR_ISRAM0_REVID
:
146 ret
= l2sram
->isram0
[dcrn
- DCR_ISRAM0_BASE
];
156 static void dcr_write_l2sram(void *opaque
, int dcrn
, uint32_t val
)
158 /*ppc4xx_l2sram_t *l2sram = opaque;*/
159 /* FIXME: Actually handle L2 cache mapping */
162 case DCR_L2CACHE_CFG
:
163 case DCR_L2CACHE_CMD
:
164 case DCR_L2CACHE_ADDR
:
165 case DCR_L2CACHE_DATA
:
166 case DCR_L2CACHE_STAT
:
167 case DCR_L2CACHE_CVER
:
168 case DCR_L2CACHE_SNP0
:
169 case DCR_L2CACHE_SNP1
:
170 /*l2sram->l2cache[dcrn - DCR_L2CACHE_BASE] = val;*/
173 case DCR_ISRAM0_SB0CR
:
174 case DCR_ISRAM0_SB1CR
:
175 case DCR_ISRAM0_SB2CR
:
176 case DCR_ISRAM0_SB3CR
:
177 case DCR_ISRAM0_BEAR
:
178 case DCR_ISRAM0_BESR0
:
179 case DCR_ISRAM0_BESR1
:
180 case DCR_ISRAM0_PMEG
:
182 case DCR_ISRAM0_REVID
:
184 /*l2sram->isram0[dcrn - DCR_L2CACHE_BASE] = val;*/
187 case DCR_ISRAM1_SB0CR
:
188 case DCR_ISRAM1_BEAR
:
189 case DCR_ISRAM1_BESR0
:
190 case DCR_ISRAM1_BESR1
:
191 case DCR_ISRAM1_PMEG
:
193 case DCR_ISRAM1_REVID
:
195 /*l2sram->isram1[dcrn - DCR_L2CACHE_BASE] = val;*/
198 /*l2sram_update_mappings(l2sram, isarc, isacntl, dsarc, dsacntl);*/
201 static void l2sram_reset(void *opaque
)
203 ppc4xx_l2sram_t
*l2sram
= opaque
;
205 memset(l2sram
->l2cache
, 0, sizeof(l2sram
->l2cache
));
206 l2sram
->l2cache
[DCR_L2CACHE_STAT
- DCR_L2CACHE_BASE
] = 0x80000000;
207 memset(l2sram
->isram0
, 0, sizeof(l2sram
->isram0
));
208 /*l2sram_update_mappings(l2sram, isarc, isacntl, dsarc, dsacntl);*/
211 void ppc4xx_l2sram_init(CPUPPCState
*env
)
213 ppc4xx_l2sram_t
*l2sram
;
215 l2sram
= g_malloc0(sizeof(*l2sram
));
216 /* XXX: Size is 4*64kB for 460ex, cf. U-Boot, ppc4xx-isram.h */
217 memory_region_init_ram(&l2sram
->bank
[0], NULL
, "ppc4xx.l2sram_bank0",
218 64 * K_BYTE
, &error_abort
);
219 memory_region_init_ram(&l2sram
->bank
[1], NULL
, "ppc4xx.l2sram_bank1",
220 64 * K_BYTE
, &error_abort
);
221 memory_region_init_ram(&l2sram
->bank
[2], NULL
, "ppc4xx.l2sram_bank2",
222 64 * K_BYTE
, &error_abort
);
223 memory_region_init_ram(&l2sram
->bank
[3], NULL
, "ppc4xx.l2sram_bank3",
224 64 * K_BYTE
, &error_abort
);
225 qemu_register_reset(&l2sram_reset
, l2sram
);
226 ppc_dcr_register(env
, DCR_L2CACHE_CFG
,
227 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
228 ppc_dcr_register(env
, DCR_L2CACHE_CMD
,
229 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
230 ppc_dcr_register(env
, DCR_L2CACHE_ADDR
,
231 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
232 ppc_dcr_register(env
, DCR_L2CACHE_DATA
,
233 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
234 ppc_dcr_register(env
, DCR_L2CACHE_STAT
,
235 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
236 ppc_dcr_register(env
, DCR_L2CACHE_CVER
,
237 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
238 ppc_dcr_register(env
, DCR_L2CACHE_SNP0
,
239 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
240 ppc_dcr_register(env
, DCR_L2CACHE_SNP1
,
241 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
243 ppc_dcr_register(env
, DCR_ISRAM0_SB0CR
,
244 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
245 ppc_dcr_register(env
, DCR_ISRAM0_SB1CR
,
246 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
247 ppc_dcr_register(env
, DCR_ISRAM0_SB2CR
,
248 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
249 ppc_dcr_register(env
, DCR_ISRAM0_SB3CR
,
250 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
251 ppc_dcr_register(env
, DCR_ISRAM0_PMEG
,
252 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
253 ppc_dcr_register(env
, DCR_ISRAM0_DPC
,
254 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
256 ppc_dcr_register(env
, DCR_ISRAM1_SB0CR
,
257 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
258 ppc_dcr_register(env
, DCR_ISRAM1_PMEG
,
259 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
260 ppc_dcr_register(env
, DCR_ISRAM1_DPC
,
261 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
264 /*****************************************************************************/
265 /* Clocking Power on Reset */
277 typedef struct ppc4xx_cpr_t
{
281 static uint32_t dcr_read_cpr(void *opaque
, int dcrn
)
283 ppc4xx_cpr_t
*cpr
= opaque
;
293 ret
= (0xb5 << 24) | (1 << 16) | (9 << 8);
316 static void dcr_write_cpr(void *opaque
, int dcrn
, uint32_t val
)
318 ppc4xx_cpr_t
*cpr
= opaque
;
331 static void ppc4xx_cpr_reset(void *opaque
)
333 ppc4xx_cpr_t
*cpr
= opaque
;
338 void ppc4xx_cpr_init(CPUPPCState
*env
)
342 cpr
= g_malloc0(sizeof(*cpr
));
343 ppc_dcr_register(env
, CPR0_CFGADDR
, cpr
, &dcr_read_cpr
, &dcr_write_cpr
);
344 ppc_dcr_register(env
, CPR0_CFGDATA
, cpr
, &dcr_read_cpr
, &dcr_write_cpr
);
345 qemu_register_reset(ppc4xx_cpr_reset
, cpr
);
348 /*****************************************************************************/
350 typedef struct ppc4xx_sdr_t ppc4xx_sdr_t
;
351 struct ppc4xx_sdr_t
{
356 SDR0_CFGADDR
= 0x00e,
372 PESDR0_RSTSTA
= 0x310,
376 PESDR1_RSTSTA
= 0x365,
379 #define SDR0_DDR0_DDRM_ENCODE(n) ((((unsigned long)(n)) & 0x03) << 29)
380 #define SDR0_DDR0_DDRM_DDR1 0x20000000
381 #define SDR0_DDR0_DDRM_DDR2 0x40000000
383 static uint32_t dcr_read_sdr(void *opaque
, int dcrn
)
385 ppc4xx_sdr_t
*sdr
= opaque
;
395 /* FIXME: Is this correct? This breaks timing in U-Boot */
396 ret
= 0; /*(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 ppc4xx_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 /* XXX: TOFIX: some patches have made this code become inconsistent:
509 * there are type inconsistencies, mixing hwaddr, target_ulong
512 static uint32_t sdram_bcr(hwaddr ram_base
, hwaddr ram_size
)
542 error_report("invalid RAM size " TARGET_FMT_plx
, ram_size
);
545 bcr
|= ram_base
& 0xFF800000;
551 static inline hwaddr
sdram_base(uint32_t bcr
)
553 return bcr
& 0xFF800000;
556 static target_ulong
sdram_size(uint32_t bcr
)
561 sh
= 1024 - ((bcr
>> 6) & 0x3ff);
565 size
= 8 * M_BYTE
* sh
;
571 static void sdram_set_bcr(ppc4xx_sdram_t
*sdram
,
572 uint32_t *bcrp
, uint32_t bcr
, int enabled
)
574 unsigned n
= bcrp
- sdram
->bcr
;
578 memory_region_del_subregion(get_system_memory(),
579 &sdram
->containers
[n
]);
580 memory_region_del_subregion(&sdram
->containers
[n
],
581 &sdram
->ram_memories
[n
]);
582 object_unparent(OBJECT(&sdram
->containers
[n
]));
584 *bcrp
= bcr
& 0xFFDEE001;
585 if (enabled
&& (bcr
& 1)) {
586 memory_region_init(&sdram
->containers
[n
], NULL
, "sdram-containers",
588 memory_region_add_subregion(&sdram
->containers
[n
], 0,
589 &sdram
->ram_memories
[n
]);
590 memory_region_add_subregion(get_system_memory(),
592 &sdram
->containers
[n
]);
596 static void sdram_map_bcr(ppc4xx_sdram_t
*sdram
)
600 for (i
= 0; i
< sdram
->nbanks
; i
++) {
601 if (sdram
->ram_sizes
[i
] != 0) {
604 sdram_bcr(sdram
->ram_bases
[i
], sdram
->ram_sizes
[i
]),
607 sdram_set_bcr(sdram
, &sdram
->bcr
[i
], 0, 0);
612 static uint32_t dcr_read_sdram(void *opaque
, int dcrn
)
614 ppc4xx_sdram_t
*sdram
= opaque
;
622 ret
= sdram_bcr(sdram
->ram_bases
[dcrn
- SDRAM_R0BAS
],
623 sdram
->ram_sizes
[dcrn
- SDRAM_R0BAS
]);
627 case SDRAM_CONFPATHB
:
628 case SDRAM_PLBADDULL
:
629 case SDRAM_PLBADDUHB
:
635 switch (sdram
->addr
) {
636 case 0x14: /* SDRAM_MCSTAT (405EX) */
640 case 0x21: /* SDRAM_MCOPT2 */
643 case 0x40: /* SDRAM_MB0CF */
646 case 0x7A: /* SDRAM_DLCR */
649 case 0xE1: /* SDR0_DDR0 */
650 ret
= SDR0_DDR0_DDRM_ENCODE(1) | SDR0_DDR0_DDRM_DDR1
;
663 static void dcr_write_sdram(void *opaque
, int dcrn
, uint32_t val
)
665 ppc4xx_sdram_t
*sdram
= opaque
;
674 case SDRAM_CONFPATHB
:
675 case SDRAM_PLBADDULL
:
676 case SDRAM_PLBADDUHB
:
682 switch (sdram
->addr
) {
683 case 0x00: /* B0CR */
694 static void sdram_reset(void *opaque
)
696 ppc4xx_sdram_t
*sdram
= opaque
;
701 void ppc440_sdram_init(CPUPPCState
*env
, int nbanks
,
702 MemoryRegion
*ram_memories
,
703 hwaddr
*ram_bases
, hwaddr
*ram_sizes
,
706 ppc4xx_sdram_t
*sdram
;
708 sdram
= g_malloc0(sizeof(*sdram
));
709 sdram
->nbanks
= nbanks
;
710 sdram
->ram_memories
= ram_memories
;
711 memcpy(sdram
->ram_bases
, ram_bases
, nbanks
* sizeof(hwaddr
));
712 memcpy(sdram
->ram_sizes
, ram_sizes
, nbanks
* sizeof(hwaddr
));
713 qemu_register_reset(&sdram_reset
, sdram
);
714 ppc_dcr_register(env
, SDRAM0_CFGADDR
,
715 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
716 ppc_dcr_register(env
, SDRAM0_CFGDATA
,
717 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
719 sdram_map_bcr(sdram
);
722 ppc_dcr_register(env
, SDRAM_R0BAS
,
723 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
724 ppc_dcr_register(env
, SDRAM_R1BAS
,
725 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
726 ppc_dcr_register(env
, SDRAM_R2BAS
,
727 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
728 ppc_dcr_register(env
, SDRAM_R3BAS
,
729 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
730 ppc_dcr_register(env
, SDRAM_CONF1HB
,
731 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
732 ppc_dcr_register(env
, SDRAM_PLBADDULL
,
733 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
734 ppc_dcr_register(env
, SDRAM_CONF1LL
,
735 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
736 ppc_dcr_register(env
, SDRAM_CONFPATHB
,
737 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
738 ppc_dcr_register(env
, SDRAM_PLBADDUHB
,
739 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
742 /*****************************************************************************/
743 /* PLB to AHB bridge */
749 typedef struct ppc4xx_ahb_t
{
754 static uint32_t dcr_read_ahb(void *opaque
, int dcrn
)
756 ppc4xx_ahb_t
*ahb
= opaque
;
773 static void dcr_write_ahb(void *opaque
, int dcrn
, uint32_t val
)
775 ppc4xx_ahb_t
*ahb
= opaque
;
787 static void ppc4xx_ahb_reset(void *opaque
)
789 ppc4xx_ahb_t
*ahb
= opaque
;
796 void ppc4xx_ahb_init(CPUPPCState
*env
)
800 ahb
= g_malloc0(sizeof(*ahb
));
801 ppc_dcr_register(env
, AHB_TOP
, ahb
, &dcr_read_ahb
, &dcr_write_ahb
);
802 ppc_dcr_register(env
, AHB_BOT
, ahb
, &dcr_read_ahb
, &dcr_write_ahb
);
803 qemu_register_reset(ppc4xx_ahb_reset
, ahb
);
806 /*****************************************************************************/
807 /* PCI Express controller */
808 /* FIXME: This is not complete and does not work, only implemented partially
809 * to allow firmware and guests to find an empty bus. Cards should use PCI.
811 #include "hw/pci/pcie_host.h"
813 #define TYPE_PPC460EX_PCIE_HOST "ppc460ex-pcie-host"
814 #define PPC460EX_PCIE_HOST(obj) \
815 OBJECT_CHECK(PPC460EXPCIEState, (obj), TYPE_PPC460EX_PCIE_HOST)
817 typedef struct PPC460EXPCIEState
{
840 #define DCRN_PCIE0_BASE 0x100
841 #define DCRN_PCIE1_BASE 0x120
869 static uint32_t dcr_read_pcie(void *opaque
, int dcrn
)
871 PPC460EXPCIEState
*state
= opaque
;
874 switch (dcrn
- state
->dcrn_base
) {
876 ret
= state
->cfg_base
>> 32;
879 ret
= state
->cfg_base
;
882 ret
= state
->cfg_mask
;
885 ret
= state
->msg_base
>> 32;
888 ret
= state
->msg_base
;
891 ret
= state
->msg_mask
;
894 ret
= state
->omr1_base
>> 32;
897 ret
= state
->omr1_base
;
900 ret
= state
->omr1_mask
>> 32;
903 ret
= state
->omr1_mask
;
906 ret
= state
->omr2_base
>> 32;
909 ret
= state
->omr2_base
;
912 ret
= state
->omr2_mask
>> 32;
915 ret
= state
->omr3_mask
;
918 ret
= state
->omr3_base
>> 32;
921 ret
= state
->omr3_base
;
924 ret
= state
->omr3_mask
>> 32;
927 ret
= state
->omr3_mask
;
930 ret
= state
->reg_base
>> 32;
933 ret
= state
->reg_base
;
936 ret
= state
->reg_mask
;
939 ret
= state
->special
;
949 static void dcr_write_pcie(void *opaque
, int dcrn
, uint32_t val
)
951 PPC460EXPCIEState
*s
= opaque
;
954 switch (dcrn
- s
->dcrn_base
) {
956 s
->cfg_base
= ((uint64_t)val
<< 32) | (s
->cfg_base
& 0xffffffff);
959 s
->cfg_base
= (s
->cfg_base
& 0xffffffff00000000ULL
) | val
;
963 size
= ~(val
& 0xfffffffe) + 1;
964 qemu_mutex_lock_iothread();
965 pcie_host_mmcfg_update(PCIE_HOST_BRIDGE(s
), val
& 1, s
->cfg_base
, size
);
966 qemu_mutex_unlock_iothread();
969 s
->msg_base
= ((uint64_t)val
<< 32) | (s
->msg_base
& 0xffffffff);
972 s
->msg_base
= (s
->msg_base
& 0xffffffff00000000ULL
) | val
;
978 s
->omr1_base
= ((uint64_t)val
<< 32) | (s
->omr1_base
& 0xffffffff);
981 s
->omr1_base
= (s
->omr1_base
& 0xffffffff00000000ULL
) | val
;
984 s
->omr1_mask
= ((uint64_t)val
<< 32) | (s
->omr1_mask
& 0xffffffff);
987 s
->omr1_mask
= (s
->omr1_mask
& 0xffffffff00000000ULL
) | val
;
990 s
->omr2_base
= ((uint64_t)val
<< 32) | (s
->omr2_base
& 0xffffffff);
993 s
->omr2_base
= (s
->omr2_base
& 0xffffffff00000000ULL
) | val
;
996 s
->omr2_mask
= ((uint64_t)val
<< 32) | (s
->omr2_mask
& 0xffffffff);
999 s
->omr2_mask
= (s
->omr2_mask
& 0xffffffff00000000ULL
) | val
;
1002 s
->omr3_base
= ((uint64_t)val
<< 32) | (s
->omr3_base
& 0xffffffff);
1005 s
->omr3_base
= (s
->omr3_base
& 0xffffffff00000000ULL
) | val
;
1007 case PEGPL_OMR3MSKH
:
1008 s
->omr3_mask
= ((uint64_t)val
<< 32) | (s
->omr3_mask
& 0xffffffff);
1010 case PEGPL_OMR3MSKL
:
1011 s
->omr3_mask
= (s
->omr3_mask
& 0xffffffff00000000ULL
) | val
;
1014 s
->reg_base
= ((uint64_t)val
<< 32) | (s
->reg_base
& 0xffffffff);
1017 s
->reg_base
= (s
->reg_base
& 0xffffffff00000000ULL
) | val
;
1021 /* FIXME: how is size encoded? */
1022 size
= (val
== 0x7001 ? 4096 : ~(val
& 0xfffffffe) + 1);
1033 static void ppc460ex_set_irq(void *opaque
, int irq_num
, int level
)
1035 PPC460EXPCIEState
*s
= opaque
;
1036 qemu_set_irq(s
->irq
[irq_num
], level
);
1039 static void ppc460ex_pcie_realize(DeviceState
*dev
, Error
**errp
)
1041 PPC460EXPCIEState
*s
= PPC460EX_PCIE_HOST(dev
);
1042 PCIHostState
*pci
= PCI_HOST_BRIDGE(dev
);
1046 switch (s
->dcrn_base
) {
1047 case DCRN_PCIE0_BASE
:
1050 case DCRN_PCIE1_BASE
:
1054 snprintf(buf
, sizeof(buf
), "pcie%d-io", id
);
1055 memory_region_init(&s
->iomem
, OBJECT(s
), buf
, UINT64_MAX
);
1056 for (i
= 0; i
< 4; i
++) {
1057 sysbus_init_irq(SYS_BUS_DEVICE(dev
), &s
->irq
[i
]);
1059 snprintf(buf
, sizeof(buf
), "pcie.%d", id
);
1060 pci
->bus
= pci_register_root_bus(DEVICE(s
), buf
, ppc460ex_set_irq
,
1061 pci_swizzle_map_irq_fn
, s
, &s
->iomem
,
1062 get_system_io(), 0, 4, TYPE_PCIE_BUS
);
1065 static Property ppc460ex_pcie_props
[] = {
1066 DEFINE_PROP_INT32("dcrn-base", PPC460EXPCIEState
, dcrn_base
, -1),
1067 DEFINE_PROP_END_OF_LIST(),
1070 static void ppc460ex_pcie_class_init(ObjectClass
*klass
, void *data
)
1072 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1074 set_bit(DEVICE_CATEGORY_BRIDGE
, dc
->categories
);
1075 dc
->realize
= ppc460ex_pcie_realize
;
1076 dc
->props
= ppc460ex_pcie_props
;
1077 dc
->hotpluggable
= false;
1080 static const TypeInfo ppc460ex_pcie_host_info
= {
1081 .name
= TYPE_PPC460EX_PCIE_HOST
,
1082 .parent
= TYPE_PCIE_HOST_BRIDGE
,
1083 .instance_size
= sizeof(PPC460EXPCIEState
),
1084 .class_init
= ppc460ex_pcie_class_init
,
1087 static void ppc460ex_pcie_register(void)
1089 type_register_static(&ppc460ex_pcie_host_info
);
1092 type_init(ppc460ex_pcie_register
)
1094 static void ppc460ex_pcie_register_dcrs(PPC460EXPCIEState
*s
, CPUPPCState
*env
)
1096 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_CFGBAH
, s
,
1097 &dcr_read_pcie
, &dcr_write_pcie
);
1098 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_CFGBAL
, s
,
1099 &dcr_read_pcie
, &dcr_write_pcie
);
1100 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_CFGMSK
, s
,
1101 &dcr_read_pcie
, &dcr_write_pcie
);
1102 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_MSGBAH
, s
,
1103 &dcr_read_pcie
, &dcr_write_pcie
);
1104 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_MSGBAL
, s
,
1105 &dcr_read_pcie
, &dcr_write_pcie
);
1106 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_MSGMSK
, s
,
1107 &dcr_read_pcie
, &dcr_write_pcie
);
1108 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR1BAH
, s
,
1109 &dcr_read_pcie
, &dcr_write_pcie
);
1110 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR1BAL
, s
,
1111 &dcr_read_pcie
, &dcr_write_pcie
);
1112 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR1MSKH
, s
,
1113 &dcr_read_pcie
, &dcr_write_pcie
);
1114 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR1MSKL
, s
,
1115 &dcr_read_pcie
, &dcr_write_pcie
);
1116 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR2BAH
, s
,
1117 &dcr_read_pcie
, &dcr_write_pcie
);
1118 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR2BAL
, s
,
1119 &dcr_read_pcie
, &dcr_write_pcie
);
1120 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR2MSKH
, s
,
1121 &dcr_read_pcie
, &dcr_write_pcie
);
1122 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR2MSKL
, s
,
1123 &dcr_read_pcie
, &dcr_write_pcie
);
1124 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR3BAH
, s
,
1125 &dcr_read_pcie
, &dcr_write_pcie
);
1126 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR3BAL
, s
,
1127 &dcr_read_pcie
, &dcr_write_pcie
);
1128 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR3MSKH
, s
,
1129 &dcr_read_pcie
, &dcr_write_pcie
);
1130 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR3MSKL
, s
,
1131 &dcr_read_pcie
, &dcr_write_pcie
);
1132 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_REGBAH
, s
,
1133 &dcr_read_pcie
, &dcr_write_pcie
);
1134 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_REGBAL
, s
,
1135 &dcr_read_pcie
, &dcr_write_pcie
);
1136 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_REGMSK
, s
,
1137 &dcr_read_pcie
, &dcr_write_pcie
);
1138 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_SPECIAL
, s
,
1139 &dcr_read_pcie
, &dcr_write_pcie
);
1140 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_CFG
, s
,
1141 &dcr_read_pcie
, &dcr_write_pcie
);
1144 void ppc460ex_pcie_init(CPUPPCState
*env
)
1148 dev
= qdev_create(NULL
, TYPE_PPC460EX_PCIE_HOST
);
1149 qdev_prop_set_int32(dev
, "dcrn-base", DCRN_PCIE0_BASE
);
1150 qdev_init_nofail(dev
);
1151 object_property_set_bool(OBJECT(dev
), true, "realized", NULL
);
1152 ppc460ex_pcie_register_dcrs(PPC460EX_PCIE_HOST(dev
), env
);
1154 dev
= qdev_create(NULL
, TYPE_PPC460EX_PCIE_HOST
);
1155 qdev_prop_set_int32(dev
, "dcrn-base", DCRN_PCIE1_BASE
);
1156 qdev_init_nofail(dev
);
1157 object_property_set_bool(OBJECT(dev
), true, "realized", NULL
);
1158 ppc460ex_pcie_register_dcrs(PPC460EX_PCIE_HOST(dev
), env
);