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 "qapi/error.h"
16 #include "hw/ppc/ppc4xx.h"
17 #include "hw/qdev-properties.h"
18 #include "hw/pci/pci.h"
19 #include "sysemu/reset.h"
22 /*****************************************************************************/
23 /* L2 Cache as SRAM */
26 DCR_L2CACHE_BASE
= 0x30,
27 DCR_L2CACHE_CFG
= DCR_L2CACHE_BASE
,
35 DCR_L2CACHE_END
= DCR_L2CACHE_SNP1
,
38 /* base is 460ex-specific, cf. U-Boot, ppc4xx-isram.h */
40 DCR_ISRAM0_BASE
= 0x20,
41 DCR_ISRAM0_SB0CR
= DCR_ISRAM0_BASE
,
52 DCR_ISRAM0_END
= DCR_ISRAM0_DPC
56 DCR_ISRAM1_BASE
= 0xb0,
57 DCR_ISRAM1_SB0CR
= DCR_ISRAM1_BASE
,
59 DCR_ISRAM1_BEAR
= DCR_ISRAM1_BASE
+ 0x04,
66 DCR_ISRAM1_END
= DCR_ISRAM1_DPC
69 typedef struct ppc4xx_l2sram_t
{
76 static void l2sram_update_mappings(ppc4xx_l2sram_t
*l2sram
,
77 uint32_t isarc
, uint32_t isacntl
,
78 uint32_t dsarc
, uint32_t dsacntl
)
80 if (l2sram
->isarc
!= isarc
||
81 (l2sram
->isacntl
& 0x80000000) != (isacntl
& 0x80000000)) {
82 if (l2sram
->isacntl
& 0x80000000) {
83 /* Unmap previously assigned memory region */
84 memory_region_del_subregion(get_system_memory(),
87 if (isacntl
& 0x80000000) {
88 /* Map new instruction memory region */
89 memory_region_add_subregion(get_system_memory(), isarc
,
93 if (l2sram
->dsarc
!= dsarc
||
94 (l2sram
->dsacntl
& 0x80000000) != (dsacntl
& 0x80000000)) {
95 if (l2sram
->dsacntl
& 0x80000000) {
96 /* Beware not to unmap the region we just mapped */
97 if (!(isacntl
& 0x80000000) || l2sram
->dsarc
!= isarc
) {
98 /* Unmap previously assigned memory region */
99 memory_region_del_subregion(get_system_memory(),
103 if (dsacntl
& 0x80000000) {
104 /* Beware not to remap the region we just mapped */
105 if (!(isacntl
& 0x80000000) || dsarc
!= isarc
) {
106 /* Map new data memory region */
107 memory_region_add_subregion(get_system_memory(), dsarc
,
115 static uint32_t dcr_read_l2sram(void *opaque
, int dcrn
)
117 ppc4xx_l2sram_t
*l2sram
= opaque
;
121 case DCR_L2CACHE_CFG
:
122 case DCR_L2CACHE_CMD
:
123 case DCR_L2CACHE_ADDR
:
124 case DCR_L2CACHE_DATA
:
125 case DCR_L2CACHE_STAT
:
126 case DCR_L2CACHE_CVER
:
127 case DCR_L2CACHE_SNP0
:
128 case DCR_L2CACHE_SNP1
:
129 ret
= l2sram
->l2cache
[dcrn
- DCR_L2CACHE_BASE
];
132 case DCR_ISRAM0_SB0CR
:
133 case DCR_ISRAM0_SB1CR
:
134 case DCR_ISRAM0_SB2CR
:
135 case DCR_ISRAM0_SB3CR
:
136 case DCR_ISRAM0_BEAR
:
137 case DCR_ISRAM0_BESR0
:
138 case DCR_ISRAM0_BESR1
:
139 case DCR_ISRAM0_PMEG
:
141 case DCR_ISRAM0_REVID
:
143 ret
= l2sram
->isram0
[dcrn
- DCR_ISRAM0_BASE
];
153 static void dcr_write_l2sram(void *opaque
, int dcrn
, uint32_t val
)
155 /*ppc4xx_l2sram_t *l2sram = opaque;*/
156 /* FIXME: Actually handle L2 cache mapping */
159 case DCR_L2CACHE_CFG
:
160 case DCR_L2CACHE_CMD
:
161 case DCR_L2CACHE_ADDR
:
162 case DCR_L2CACHE_DATA
:
163 case DCR_L2CACHE_STAT
:
164 case DCR_L2CACHE_CVER
:
165 case DCR_L2CACHE_SNP0
:
166 case DCR_L2CACHE_SNP1
:
167 /*l2sram->l2cache[dcrn - DCR_L2CACHE_BASE] = val;*/
170 case DCR_ISRAM0_SB0CR
:
171 case DCR_ISRAM0_SB1CR
:
172 case DCR_ISRAM0_SB2CR
:
173 case DCR_ISRAM0_SB3CR
:
174 case DCR_ISRAM0_BEAR
:
175 case DCR_ISRAM0_BESR0
:
176 case DCR_ISRAM0_BESR1
:
177 case DCR_ISRAM0_PMEG
:
179 case DCR_ISRAM0_REVID
:
181 /*l2sram->isram0[dcrn - DCR_L2CACHE_BASE] = val;*/
184 case DCR_ISRAM1_SB0CR
:
185 case DCR_ISRAM1_BEAR
:
186 case DCR_ISRAM1_BESR0
:
187 case DCR_ISRAM1_BESR1
:
188 case DCR_ISRAM1_PMEG
:
190 case DCR_ISRAM1_REVID
:
192 /*l2sram->isram1[dcrn - DCR_L2CACHE_BASE] = val;*/
195 /*l2sram_update_mappings(l2sram, isarc, isacntl, dsarc, dsacntl);*/
198 static void l2sram_reset(void *opaque
)
200 ppc4xx_l2sram_t
*l2sram
= opaque
;
202 memset(l2sram
->l2cache
, 0, sizeof(l2sram
->l2cache
));
203 l2sram
->l2cache
[DCR_L2CACHE_STAT
- DCR_L2CACHE_BASE
] = 0x80000000;
204 memset(l2sram
->isram0
, 0, sizeof(l2sram
->isram0
));
205 /*l2sram_update_mappings(l2sram, isarc, isacntl, dsarc, dsacntl);*/
208 void ppc4xx_l2sram_init(CPUPPCState
*env
)
210 ppc4xx_l2sram_t
*l2sram
;
212 l2sram
= g_malloc0(sizeof(*l2sram
));
213 /* XXX: Size is 4*64kB for 460ex, cf. U-Boot, ppc4xx-isram.h */
214 memory_region_init_ram(&l2sram
->bank
[0], NULL
, "ppc4xx.l2sram_bank0",
215 64 * KiB
, &error_abort
);
216 memory_region_init_ram(&l2sram
->bank
[1], NULL
, "ppc4xx.l2sram_bank1",
217 64 * KiB
, &error_abort
);
218 memory_region_init_ram(&l2sram
->bank
[2], NULL
, "ppc4xx.l2sram_bank2",
219 64 * KiB
, &error_abort
);
220 memory_region_init_ram(&l2sram
->bank
[3], NULL
, "ppc4xx.l2sram_bank3",
221 64 * KiB
, &error_abort
);
222 qemu_register_reset(&l2sram_reset
, l2sram
);
223 ppc_dcr_register(env
, DCR_L2CACHE_CFG
,
224 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
225 ppc_dcr_register(env
, DCR_L2CACHE_CMD
,
226 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
227 ppc_dcr_register(env
, DCR_L2CACHE_ADDR
,
228 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
229 ppc_dcr_register(env
, DCR_L2CACHE_DATA
,
230 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
231 ppc_dcr_register(env
, DCR_L2CACHE_STAT
,
232 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
233 ppc_dcr_register(env
, DCR_L2CACHE_CVER
,
234 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
235 ppc_dcr_register(env
, DCR_L2CACHE_SNP0
,
236 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
237 ppc_dcr_register(env
, DCR_L2CACHE_SNP1
,
238 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
240 ppc_dcr_register(env
, DCR_ISRAM0_SB0CR
,
241 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
242 ppc_dcr_register(env
, DCR_ISRAM0_SB1CR
,
243 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
244 ppc_dcr_register(env
, DCR_ISRAM0_SB2CR
,
245 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
246 ppc_dcr_register(env
, DCR_ISRAM0_SB3CR
,
247 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
248 ppc_dcr_register(env
, DCR_ISRAM0_PMEG
,
249 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
250 ppc_dcr_register(env
, DCR_ISRAM0_DPC
,
251 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
253 ppc_dcr_register(env
, DCR_ISRAM1_SB0CR
,
254 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
255 ppc_dcr_register(env
, DCR_ISRAM1_PMEG
,
256 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
257 ppc_dcr_register(env
, DCR_ISRAM1_DPC
,
258 l2sram
, &dcr_read_l2sram
, &dcr_write_l2sram
);
261 /*****************************************************************************/
262 /* Clocking Power on Reset */
274 typedef struct ppc4xx_cpr_t
{
278 static uint32_t dcr_read_cpr(void *opaque
, int dcrn
)
280 ppc4xx_cpr_t
*cpr
= opaque
;
290 ret
= (0xb5 << 24) | (1 << 16) | (9 << 8);
313 static void dcr_write_cpr(void *opaque
, int dcrn
, uint32_t val
)
315 ppc4xx_cpr_t
*cpr
= opaque
;
328 static void ppc4xx_cpr_reset(void *opaque
)
330 ppc4xx_cpr_t
*cpr
= opaque
;
335 void ppc4xx_cpr_init(CPUPPCState
*env
)
339 cpr
= g_malloc0(sizeof(*cpr
));
340 ppc_dcr_register(env
, CPR0_CFGADDR
, cpr
, &dcr_read_cpr
, &dcr_write_cpr
);
341 ppc_dcr_register(env
, CPR0_CFGDATA
, cpr
, &dcr_read_cpr
, &dcr_write_cpr
);
342 qemu_register_reset(ppc4xx_cpr_reset
, cpr
);
345 /*****************************************************************************/
347 typedef struct ppc4xx_sdr_t ppc4xx_sdr_t
;
348 struct ppc4xx_sdr_t
{
353 SDR0_CFGADDR
= 0x00e,
369 PESDR0_RSTSTA
= 0x310,
373 PESDR1_RSTSTA
= 0x365,
376 static uint32_t dcr_read_sdr(void *opaque
, int dcrn
)
378 ppc4xx_sdr_t
*sdr
= opaque
;
388 ret
= (0xb5 << 8) | (1 << 4) | 9;
391 ret
= (5 << 29) | (2 << 26) | (1 << 24);
394 ret
= 1 << 20; /* No Security/Kasumi support */
397 ret
= SDR0_DDR0_DDRM_ENCODE(1) | SDR0_DDR0_DDRM_DDR1
;
401 ret
= (1 << 24) | (1 << 16);
405 ret
= (1 << 16) | (1 << 12);
426 static void dcr_write_sdr(void *opaque
, int dcrn
, uint32_t val
)
428 ppc4xx_sdr_t
*sdr
= opaque
;
436 case 0x00: /* B0CR */
447 static void sdr_reset(void *opaque
)
449 ppc4xx_sdr_t
*sdr
= opaque
;
454 void ppc4xx_sdr_init(CPUPPCState
*env
)
458 sdr
= g_malloc0(sizeof(*sdr
));
459 qemu_register_reset(&sdr_reset
, sdr
);
460 ppc_dcr_register(env
, SDR0_CFGADDR
,
461 sdr
, &dcr_read_sdr
, &dcr_write_sdr
);
462 ppc_dcr_register(env
, SDR0_CFGDATA
,
463 sdr
, &dcr_read_sdr
, &dcr_write_sdr
);
464 ppc_dcr_register(env
, SDR0_102
,
465 sdr
, &dcr_read_sdr
, &dcr_write_sdr
);
466 ppc_dcr_register(env
, SDR0_103
,
467 sdr
, &dcr_read_sdr
, &dcr_write_sdr
);
468 ppc_dcr_register(env
, SDR0_128
,
469 sdr
, &dcr_read_sdr
, &dcr_write_sdr
);
470 ppc_dcr_register(env
, SDR0_USB0
,
471 sdr
, &dcr_read_sdr
, &dcr_write_sdr
);
474 /*****************************************************************************/
475 /* PLB to AHB bridge */
481 typedef struct ppc4xx_ahb_t
{
486 static uint32_t dcr_read_ahb(void *opaque
, int dcrn
)
488 ppc4xx_ahb_t
*ahb
= opaque
;
505 static void dcr_write_ahb(void *opaque
, int dcrn
, uint32_t val
)
507 ppc4xx_ahb_t
*ahb
= opaque
;
519 static void ppc4xx_ahb_reset(void *opaque
)
521 ppc4xx_ahb_t
*ahb
= opaque
;
528 void ppc4xx_ahb_init(CPUPPCState
*env
)
532 ahb
= g_malloc0(sizeof(*ahb
));
533 ppc_dcr_register(env
, AHB_TOP
, ahb
, &dcr_read_ahb
, &dcr_write_ahb
);
534 ppc_dcr_register(env
, AHB_BOT
, ahb
, &dcr_read_ahb
, &dcr_write_ahb
);
535 qemu_register_reset(ppc4xx_ahb_reset
, ahb
);
538 /*****************************************************************************/
541 #define DMA0_CR_CE (1 << 31)
542 #define DMA0_CR_PW (1 << 26 | 1 << 25)
543 #define DMA0_CR_DAI (1 << 24)
544 #define DMA0_CR_SAI (1 << 23)
545 #define DMA0_CR_DEC (1 << 2)
577 static uint32_t dcr_read_dma(void *opaque
, int dcrn
)
579 PPC4xxDmaState
*dma
= opaque
;
581 int addr
= dcrn
- dma
->base
;
588 val
= dma
->ch
[chnl
].cr
;
591 val
= dma
->ch
[chnl
].ct
;
594 val
= dma
->ch
[chnl
].sa
>> 32;
597 val
= dma
->ch
[chnl
].sa
;
600 val
= dma
->ch
[chnl
].da
>> 32;
603 val
= dma
->ch
[chnl
].da
;
606 val
= dma
->ch
[chnl
].sg
>> 32;
609 val
= dma
->ch
[chnl
].sg
;
617 qemu_log_mask(LOG_UNIMP
, "%s: unimplemented register %x (%d, %x)\n",
618 __func__
, dcrn
, chnl
, addr
);
624 static void dcr_write_dma(void *opaque
, int dcrn
, uint32_t val
)
626 PPC4xxDmaState
*dma
= opaque
;
627 int addr
= dcrn
- dma
->base
;
634 dma
->ch
[chnl
].cr
= val
;
635 if (val
& DMA0_CR_CE
) {
636 int count
= dma
->ch
[chnl
].ct
& 0xffff;
639 int width
, i
, sidx
, didx
;
640 uint8_t *rptr
, *wptr
;
645 width
= 1 << ((val
& DMA0_CR_PW
) >> 25);
646 xferlen
= count
* width
;
647 wlen
= rlen
= xferlen
;
648 rptr
= cpu_physical_memory_map(dma
->ch
[chnl
].sa
, &rlen
,
650 wptr
= cpu_physical_memory_map(dma
->ch
[chnl
].da
, &wlen
,
652 if (rptr
&& rlen
== xferlen
&& wptr
&& wlen
== xferlen
) {
653 if (!(val
& DMA0_CR_DEC
) &&
654 val
& DMA0_CR_SAI
&& val
& DMA0_CR_DAI
) {
655 /* optimise common case */
656 memmove(wptr
, rptr
, count
* width
);
657 sidx
= didx
= count
* width
;
659 /* do it the slow way */
660 for (sidx
= didx
= i
= 0; i
< count
; i
++) {
661 uint64_t v
= ldn_le_p(rptr
+ sidx
, width
);
662 stn_le_p(wptr
+ didx
, width
, v
);
663 if (val
& DMA0_CR_SAI
) {
666 if (val
& DMA0_CR_DAI
) {
673 cpu_physical_memory_unmap(wptr
, wlen
, 1, didx
);
676 cpu_physical_memory_unmap(rptr
, rlen
, 0, sidx
);
682 dma
->ch
[chnl
].ct
= val
;
685 dma
->ch
[chnl
].sa
&= 0xffffffffULL
;
686 dma
->ch
[chnl
].sa
|= (uint64_t)val
<< 32;
689 dma
->ch
[chnl
].sa
&= 0xffffffff00000000ULL
;
690 dma
->ch
[chnl
].sa
|= val
;
693 dma
->ch
[chnl
].da
&= 0xffffffffULL
;
694 dma
->ch
[chnl
].da
|= (uint64_t)val
<< 32;
697 dma
->ch
[chnl
].da
&= 0xffffffff00000000ULL
;
698 dma
->ch
[chnl
].da
|= val
;
701 dma
->ch
[chnl
].sg
&= 0xffffffffULL
;
702 dma
->ch
[chnl
].sg
|= (uint64_t)val
<< 32;
705 dma
->ch
[chnl
].sg
&= 0xffffffff00000000ULL
;
706 dma
->ch
[chnl
].sg
|= val
;
714 qemu_log_mask(LOG_UNIMP
, "%s: unimplemented register %x (%d, %x)\n",
715 __func__
, dcrn
, chnl
, addr
);
719 static void ppc4xx_dma_reset(void *opaque
)
721 PPC4xxDmaState
*dma
= opaque
;
722 int dma_base
= dma
->base
;
724 memset(dma
, 0, sizeof(*dma
));
725 dma
->base
= dma_base
;
728 void ppc4xx_dma_init(CPUPPCState
*env
, int dcr_base
)
733 dma
= g_malloc0(sizeof(*dma
));
734 dma
->base
= dcr_base
;
735 qemu_register_reset(&ppc4xx_dma_reset
, dma
);
736 for (i
= 0; i
< 4; i
++) {
737 ppc_dcr_register(env
, dcr_base
+ i
* 8 + DMA0_CR
,
738 dma
, &dcr_read_dma
, &dcr_write_dma
);
739 ppc_dcr_register(env
, dcr_base
+ i
* 8 + DMA0_CT
,
740 dma
, &dcr_read_dma
, &dcr_write_dma
);
741 ppc_dcr_register(env
, dcr_base
+ i
* 8 + DMA0_SAH
,
742 dma
, &dcr_read_dma
, &dcr_write_dma
);
743 ppc_dcr_register(env
, dcr_base
+ i
* 8 + DMA0_SAL
,
744 dma
, &dcr_read_dma
, &dcr_write_dma
);
745 ppc_dcr_register(env
, dcr_base
+ i
* 8 + DMA0_DAH
,
746 dma
, &dcr_read_dma
, &dcr_write_dma
);
747 ppc_dcr_register(env
, dcr_base
+ i
* 8 + DMA0_DAL
,
748 dma
, &dcr_read_dma
, &dcr_write_dma
);
749 ppc_dcr_register(env
, dcr_base
+ i
* 8 + DMA0_SGH
,
750 dma
, &dcr_read_dma
, &dcr_write_dma
);
751 ppc_dcr_register(env
, dcr_base
+ i
* 8 + DMA0_SGL
,
752 dma
, &dcr_read_dma
, &dcr_write_dma
);
754 ppc_dcr_register(env
, dcr_base
+ DMA0_SR
,
755 dma
, &dcr_read_dma
, &dcr_write_dma
);
756 ppc_dcr_register(env
, dcr_base
+ DMA0_SGC
,
757 dma
, &dcr_read_dma
, &dcr_write_dma
);
758 ppc_dcr_register(env
, dcr_base
+ DMA0_SLP
,
759 dma
, &dcr_read_dma
, &dcr_write_dma
);
760 ppc_dcr_register(env
, dcr_base
+ DMA0_POL
,
761 dma
, &dcr_read_dma
, &dcr_write_dma
);
764 /*****************************************************************************/
765 /* PCI Express controller */
767 * FIXME: This is not complete and does not work, only implemented partially
768 * to allow firmware and guests to find an empty bus. Cards should use PCI.
770 #include "hw/pci/pcie_host.h"
772 #define TYPE_PPC460EX_PCIE_HOST "ppc460ex-pcie-host"
773 OBJECT_DECLARE_SIMPLE_TYPE(PPC460EXPCIEState
, PPC460EX_PCIE_HOST
)
775 struct PPC460EXPCIEState
{
798 #define DCRN_PCIE0_BASE 0x100
799 #define DCRN_PCIE1_BASE 0x120
827 static uint32_t dcr_read_pcie(void *opaque
, int dcrn
)
829 PPC460EXPCIEState
*state
= opaque
;
832 switch (dcrn
- state
->dcrn_base
) {
834 ret
= state
->cfg_base
>> 32;
837 ret
= state
->cfg_base
;
840 ret
= state
->cfg_mask
;
843 ret
= state
->msg_base
>> 32;
846 ret
= state
->msg_base
;
849 ret
= state
->msg_mask
;
852 ret
= state
->omr1_base
>> 32;
855 ret
= state
->omr1_base
;
858 ret
= state
->omr1_mask
>> 32;
861 ret
= state
->omr1_mask
;
864 ret
= state
->omr2_base
>> 32;
867 ret
= state
->omr2_base
;
870 ret
= state
->omr2_mask
>> 32;
873 ret
= state
->omr3_mask
;
876 ret
= state
->omr3_base
>> 32;
879 ret
= state
->omr3_base
;
882 ret
= state
->omr3_mask
>> 32;
885 ret
= state
->omr3_mask
;
888 ret
= state
->reg_base
>> 32;
891 ret
= state
->reg_base
;
894 ret
= state
->reg_mask
;
897 ret
= state
->special
;
907 static void dcr_write_pcie(void *opaque
, int dcrn
, uint32_t val
)
909 PPC460EXPCIEState
*s
= opaque
;
912 switch (dcrn
- s
->dcrn_base
) {
914 s
->cfg_base
= ((uint64_t)val
<< 32) | (s
->cfg_base
& 0xffffffff);
917 s
->cfg_base
= (s
->cfg_base
& 0xffffffff00000000ULL
) | val
;
921 size
= ~(val
& 0xfffffffe) + 1;
923 * Firmware sets this register to E0000001. Why we are not sure,
924 * but the current guess is anything above PCIE_MMCFG_SIZE_MAX is
927 if (size
> PCIE_MMCFG_SIZE_MAX
) {
928 size
= PCIE_MMCFG_SIZE_MAX
;
930 pcie_host_mmcfg_update(PCIE_HOST_BRIDGE(s
), val
& 1, s
->cfg_base
, size
);
933 s
->msg_base
= ((uint64_t)val
<< 32) | (s
->msg_base
& 0xffffffff);
936 s
->msg_base
= (s
->msg_base
& 0xffffffff00000000ULL
) | val
;
942 s
->omr1_base
= ((uint64_t)val
<< 32) | (s
->omr1_base
& 0xffffffff);
945 s
->omr1_base
= (s
->omr1_base
& 0xffffffff00000000ULL
) | val
;
948 s
->omr1_mask
= ((uint64_t)val
<< 32) | (s
->omr1_mask
& 0xffffffff);
951 s
->omr1_mask
= (s
->omr1_mask
& 0xffffffff00000000ULL
) | val
;
954 s
->omr2_base
= ((uint64_t)val
<< 32) | (s
->omr2_base
& 0xffffffff);
957 s
->omr2_base
= (s
->omr2_base
& 0xffffffff00000000ULL
) | val
;
960 s
->omr2_mask
= ((uint64_t)val
<< 32) | (s
->omr2_mask
& 0xffffffff);
963 s
->omr2_mask
= (s
->omr2_mask
& 0xffffffff00000000ULL
) | val
;
966 s
->omr3_base
= ((uint64_t)val
<< 32) | (s
->omr3_base
& 0xffffffff);
969 s
->omr3_base
= (s
->omr3_base
& 0xffffffff00000000ULL
) | val
;
972 s
->omr3_mask
= ((uint64_t)val
<< 32) | (s
->omr3_mask
& 0xffffffff);
975 s
->omr3_mask
= (s
->omr3_mask
& 0xffffffff00000000ULL
) | val
;
978 s
->reg_base
= ((uint64_t)val
<< 32) | (s
->reg_base
& 0xffffffff);
981 s
->reg_base
= (s
->reg_base
& 0xffffffff00000000ULL
) | val
;
985 /* FIXME: how is size encoded? */
986 size
= (val
== 0x7001 ? 4096 : ~(val
& 0xfffffffe) + 1);
997 static void ppc460ex_set_irq(void *opaque
, int irq_num
, int level
)
999 PPC460EXPCIEState
*s
= opaque
;
1000 qemu_set_irq(s
->irq
[irq_num
], level
);
1003 static void ppc460ex_pcie_realize(DeviceState
*dev
, Error
**errp
)
1005 PPC460EXPCIEState
*s
= PPC460EX_PCIE_HOST(dev
);
1006 PCIHostState
*pci
= PCI_HOST_BRIDGE(dev
);
1010 switch (s
->dcrn_base
) {
1011 case DCRN_PCIE0_BASE
:
1014 case DCRN_PCIE1_BASE
:
1018 error_setg(errp
, "invalid PCIe DCRN base");
1021 snprintf(buf
, sizeof(buf
), "pcie%d-io", id
);
1022 memory_region_init(&s
->iomem
, OBJECT(s
), buf
, UINT64_MAX
);
1023 for (i
= 0; i
< 4; i
++) {
1024 sysbus_init_irq(SYS_BUS_DEVICE(dev
), &s
->irq
[i
]);
1026 snprintf(buf
, sizeof(buf
), "pcie.%d", id
);
1027 pci
->bus
= pci_register_root_bus(DEVICE(s
), buf
, ppc460ex_set_irq
,
1028 pci_swizzle_map_irq_fn
, s
, &s
->iomem
,
1029 get_system_io(), 0, 4, TYPE_PCIE_BUS
);
1032 static Property ppc460ex_pcie_props
[] = {
1033 DEFINE_PROP_INT32("dcrn-base", PPC460EXPCIEState
, dcrn_base
, -1),
1034 DEFINE_PROP_END_OF_LIST(),
1037 static void ppc460ex_pcie_class_init(ObjectClass
*klass
, void *data
)
1039 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1041 set_bit(DEVICE_CATEGORY_BRIDGE
, dc
->categories
);
1042 dc
->realize
= ppc460ex_pcie_realize
;
1043 device_class_set_props(dc
, ppc460ex_pcie_props
);
1044 dc
->hotpluggable
= false;
1047 static const TypeInfo ppc460ex_pcie_host_info
= {
1048 .name
= TYPE_PPC460EX_PCIE_HOST
,
1049 .parent
= TYPE_PCIE_HOST_BRIDGE
,
1050 .instance_size
= sizeof(PPC460EXPCIEState
),
1051 .class_init
= ppc460ex_pcie_class_init
,
1054 static void ppc460ex_pcie_register(void)
1056 type_register_static(&ppc460ex_pcie_host_info
);
1059 type_init(ppc460ex_pcie_register
)
1061 static void ppc460ex_pcie_register_dcrs(PPC460EXPCIEState
*s
, CPUPPCState
*env
)
1063 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_CFGBAH
, s
,
1064 &dcr_read_pcie
, &dcr_write_pcie
);
1065 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_CFGBAL
, s
,
1066 &dcr_read_pcie
, &dcr_write_pcie
);
1067 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_CFGMSK
, s
,
1068 &dcr_read_pcie
, &dcr_write_pcie
);
1069 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_MSGBAH
, s
,
1070 &dcr_read_pcie
, &dcr_write_pcie
);
1071 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_MSGBAL
, s
,
1072 &dcr_read_pcie
, &dcr_write_pcie
);
1073 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_MSGMSK
, s
,
1074 &dcr_read_pcie
, &dcr_write_pcie
);
1075 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR1BAH
, s
,
1076 &dcr_read_pcie
, &dcr_write_pcie
);
1077 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR1BAL
, s
,
1078 &dcr_read_pcie
, &dcr_write_pcie
);
1079 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR1MSKH
, s
,
1080 &dcr_read_pcie
, &dcr_write_pcie
);
1081 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR1MSKL
, s
,
1082 &dcr_read_pcie
, &dcr_write_pcie
);
1083 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR2BAH
, s
,
1084 &dcr_read_pcie
, &dcr_write_pcie
);
1085 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR2BAL
, s
,
1086 &dcr_read_pcie
, &dcr_write_pcie
);
1087 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR2MSKH
, s
,
1088 &dcr_read_pcie
, &dcr_write_pcie
);
1089 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR2MSKL
, s
,
1090 &dcr_read_pcie
, &dcr_write_pcie
);
1091 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR3BAH
, s
,
1092 &dcr_read_pcie
, &dcr_write_pcie
);
1093 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR3BAL
, s
,
1094 &dcr_read_pcie
, &dcr_write_pcie
);
1095 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR3MSKH
, s
,
1096 &dcr_read_pcie
, &dcr_write_pcie
);
1097 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_OMR3MSKL
, s
,
1098 &dcr_read_pcie
, &dcr_write_pcie
);
1099 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_REGBAH
, s
,
1100 &dcr_read_pcie
, &dcr_write_pcie
);
1101 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_REGBAL
, s
,
1102 &dcr_read_pcie
, &dcr_write_pcie
);
1103 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_REGMSK
, s
,
1104 &dcr_read_pcie
, &dcr_write_pcie
);
1105 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_SPECIAL
, s
,
1106 &dcr_read_pcie
, &dcr_write_pcie
);
1107 ppc_dcr_register(env
, s
->dcrn_base
+ PEGPL_CFG
, s
,
1108 &dcr_read_pcie
, &dcr_write_pcie
);
1111 void ppc460ex_pcie_init(CPUPPCState
*env
)
1115 dev
= qdev_new(TYPE_PPC460EX_PCIE_HOST
);
1116 qdev_prop_set_int32(dev
, "dcrn-base", DCRN_PCIE0_BASE
);
1117 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
1118 ppc460ex_pcie_register_dcrs(PPC460EX_PCIE_HOST(dev
), env
);
1120 dev
= qdev_new(TYPE_PPC460EX_PCIE_HOST
);
1121 qdev_prop_set_int32(dev
, "dcrn-base", DCRN_PCIE1_BASE
);
1122 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
1123 ppc460ex_pcie_register_dcrs(PPC460EX_PCIE_HOST(dev
), env
);