2 * QEMU PowerPC E500 embedded processors pci controller emulation
4 * Copyright (C) 2009 Freescale Semiconductor, Inc. All rights reserved.
6 * Author: Yu Liu, <yu.liu@freescale.com>
8 * This file is derived from hw/ppc4xx_pci.c,
9 * the copyright for that material belongs to the original owners.
11 * This is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
20 typedef target_phys_addr_t pci_addr_t
;
27 #define pci_debug(fmt, ...) fprintf(stderr, fmt, ## __VA_ARGS__)
29 #define pci_debug(fmt, ...)
32 #define PCIE500_CFGADDR 0x0
33 #define PCIE500_CFGDATA 0x4
34 #define PCIE500_REG_BASE 0xC00
35 #define PCIE500_REG_SIZE (0x1000 - PCIE500_REG_BASE)
37 #define PPCE500_PCI_CONFIG_ADDR 0x0
38 #define PPCE500_PCI_CONFIG_DATA 0x4
39 #define PPCE500_PCI_INTACK 0x8
41 #define PPCE500_PCI_OW1 (0xC20 - PCIE500_REG_BASE)
42 #define PPCE500_PCI_OW2 (0xC40 - PCIE500_REG_BASE)
43 #define PPCE500_PCI_OW3 (0xC60 - PCIE500_REG_BASE)
44 #define PPCE500_PCI_OW4 (0xC80 - PCIE500_REG_BASE)
45 #define PPCE500_PCI_IW3 (0xDA0 - PCIE500_REG_BASE)
46 #define PPCE500_PCI_IW2 (0xDC0 - PCIE500_REG_BASE)
47 #define PPCE500_PCI_IW1 (0xDE0 - PCIE500_REG_BASE)
49 #define PPCE500_PCI_GASKET_TIMR (0xE20 - PCIE500_REG_BASE)
52 #define PCI_POTEAR 0x4
53 #define PCI_POWBAR 0x8
54 #define PCI_POWAR 0x10
57 #define PCI_PIWBAR 0x8
58 #define PCI_PIWBEAR 0xC
59 #define PCI_PIWAR 0x10
61 #define PPCE500_PCI_NR_POBS 5
62 #define PPCE500_PCI_NR_PIBS 3
78 struct PPCE500PCIState
{
79 struct pci_outbound pob
[PPCE500_PCI_NR_POBS
];
80 struct pci_inbound pib
[PPCE500_PCI_NR_PIBS
];
82 PCIHostState pci_state
;
86 typedef struct PPCE500PCIState PPCE500PCIState
;
88 static uint32_t pcie500_cfgaddr_readl(void *opaque
, target_phys_addr_t addr
)
90 PPCE500PCIState
*pci
= opaque
;
92 pci_debug("%s: (addr:" TARGET_FMT_plx
") -> value:%x\n", __func__
, addr
,
93 pci
->pci_state
.config_reg
);
94 return pci
->pci_state
.config_reg
;
97 static CPUReadMemoryFunc
*pcie500_cfgaddr_read
[] = {
98 &pcie500_cfgaddr_readl
,
99 &pcie500_cfgaddr_readl
,
100 &pcie500_cfgaddr_readl
,
103 static void pcie500_cfgaddr_writel(void *opaque
, target_phys_addr_t addr
,
106 PPCE500PCIState
*controller
= opaque
;
108 pci_debug("%s: value:%x -> (addr:" TARGET_FMT_plx
")\n", __func__
, value
,
110 controller
->pci_state
.config_reg
= value
& ~0x3;
113 static CPUWriteMemoryFunc
*pcie500_cfgaddr_write
[] = {
114 &pcie500_cfgaddr_writel
,
115 &pcie500_cfgaddr_writel
,
116 &pcie500_cfgaddr_writel
,
119 static CPUReadMemoryFunc
*pcie500_cfgdata_read
[] = {
120 &pci_host_data_readb
,
121 &pci_host_data_readw
,
122 &pci_host_data_readl
,
125 static CPUWriteMemoryFunc
*pcie500_cfgdata_write
[] = {
126 &pci_host_data_writeb
,
127 &pci_host_data_writew
,
128 &pci_host_data_writel
,
131 static uint32_t pci_reg_read4(void *opaque
, target_phys_addr_t addr
)
133 PPCE500PCIState
*pci
= opaque
;
140 case PPCE500_PCI_OW1
:
141 case PPCE500_PCI_OW2
:
142 case PPCE500_PCI_OW3
:
143 case PPCE500_PCI_OW4
:
144 switch (addr
& 0xC) {
145 case PCI_POTAR
: value
= pci
->pob
[(addr
>> 5) & 0x7].potar
; break;
146 case PCI_POTEAR
: value
= pci
->pob
[(addr
>> 5) & 0x7].potear
; break;
147 case PCI_POWBAR
: value
= pci
->pob
[(addr
>> 5) & 0x7].powbar
; break;
148 case PCI_POWAR
: value
= pci
->pob
[(addr
>> 5) & 0x7].powar
; break;
153 case PPCE500_PCI_IW3
:
154 case PPCE500_PCI_IW2
:
155 case PPCE500_PCI_IW1
:
156 switch (addr
& 0xC) {
157 case PCI_PITAR
: value
= pci
->pib
[(addr
>> 5) & 0x3].pitar
; break;
158 case PCI_PIWBAR
: value
= pci
->pib
[(addr
>> 5) & 0x3].piwbar
; break;
159 case PCI_PIWBEAR
: value
= pci
->pib
[(addr
>> 5) & 0x3].piwbear
; break;
160 case PCI_PIWAR
: value
= pci
->pib
[(addr
>> 5) & 0x3].piwar
; break;
165 case PPCE500_PCI_GASKET_TIMR
:
166 value
= pci
->gasket_time
;
173 pci_debug("%s: win:%lx(addr:" TARGET_FMT_plx
") -> value:%x\n", __func__
,
178 static CPUReadMemoryFunc
*e500_pci_reg_read
[] = {
184 static void pci_reg_write4(void *opaque
, target_phys_addr_t addr
,
187 PPCE500PCIState
*pci
= opaque
;
192 pci_debug("%s: value:%x -> win:%lx(addr:" TARGET_FMT_plx
")\n",
193 __func__
, value
, win
, addr
);
196 case PPCE500_PCI_OW1
:
197 case PPCE500_PCI_OW2
:
198 case PPCE500_PCI_OW3
:
199 case PPCE500_PCI_OW4
:
200 switch (addr
& 0xC) {
201 case PCI_POTAR
: pci
->pob
[(addr
>> 5) & 0x7].potar
= value
; break;
202 case PCI_POTEAR
: pci
->pob
[(addr
>> 5) & 0x7].potear
= value
; break;
203 case PCI_POWBAR
: pci
->pob
[(addr
>> 5) & 0x7].powbar
= value
; break;
204 case PCI_POWAR
: pci
->pob
[(addr
>> 5) & 0x7].powar
= value
; break;
209 case PPCE500_PCI_IW3
:
210 case PPCE500_PCI_IW2
:
211 case PPCE500_PCI_IW1
:
212 switch (addr
& 0xC) {
213 case PCI_PITAR
: pci
->pib
[(addr
>> 5) & 0x3].pitar
= value
; break;
214 case PCI_PIWBAR
: pci
->pib
[(addr
>> 5) & 0x3].piwbar
= value
; break;
215 case PCI_PIWBEAR
: pci
->pib
[(addr
>> 5) & 0x3].piwbear
= value
; break;
216 case PCI_PIWAR
: pci
->pib
[(addr
>> 5) & 0x3].piwar
= value
; break;
221 case PPCE500_PCI_GASKET_TIMR
:
222 pci
->gasket_time
= value
;
230 static CPUWriteMemoryFunc
*e500_pci_reg_write
[] = {
236 static int mpc85xx_pci_map_irq(PCIDevice
*pci_dev
, int irq_num
)
238 int devno
= pci_dev
->devfn
>> 3, ret
= 0;
244 ret
= (irq_num
+ devno
- 0x10) % 4;
247 printf("Error:%s:unknow dev number\n", __func__
);
250 pci_debug("%s: devfn %x irq %d -> %d devno:%x\n", __func__
,
251 pci_dev
->devfn
, irq_num
, ret
, devno
);
256 static void mpc85xx_pci_set_irq(qemu_irq
*pic
, int irq_num
, int level
)
258 pci_debug("%s: PCI irq %d, level:%d\n", __func__
, irq_num
, level
);
260 qemu_set_irq(pic
[irq_num
], level
);
263 static void ppce500_pci_save(QEMUFile
*f
, void *opaque
)
265 PPCE500PCIState
*controller
= opaque
;
268 pci_device_save(controller
->pci_dev
, f
);
270 for (i
= 0; i
< PPCE500_PCI_NR_POBS
; i
++) {
271 qemu_put_be32s(f
, &controller
->pob
[i
].potar
);
272 qemu_put_be32s(f
, &controller
->pob
[i
].potear
);
273 qemu_put_be32s(f
, &controller
->pob
[i
].powbar
);
274 qemu_put_be32s(f
, &controller
->pob
[i
].powar
);
277 for (i
= 0; i
< PPCE500_PCI_NR_PIBS
; i
++) {
278 qemu_put_be32s(f
, &controller
->pib
[i
].pitar
);
279 qemu_put_be32s(f
, &controller
->pib
[i
].piwbar
);
280 qemu_put_be32s(f
, &controller
->pib
[i
].piwbear
);
281 qemu_put_be32s(f
, &controller
->pib
[i
].piwar
);
283 qemu_put_be32s(f
, &controller
->gasket_time
);
286 static int ppce500_pci_load(QEMUFile
*f
, void *opaque
, int version_id
)
288 PPCE500PCIState
*controller
= opaque
;
294 pci_device_load(controller
->pci_dev
, f
);
296 for (i
= 0; i
< PPCE500_PCI_NR_POBS
; i
++) {
297 qemu_get_be32s(f
, &controller
->pob
[i
].potar
);
298 qemu_get_be32s(f
, &controller
->pob
[i
].potear
);
299 qemu_get_be32s(f
, &controller
->pob
[i
].powbar
);
300 qemu_get_be32s(f
, &controller
->pob
[i
].powar
);
303 for (i
= 0; i
< PPCE500_PCI_NR_PIBS
; i
++) {
304 qemu_get_be32s(f
, &controller
->pib
[i
].pitar
);
305 qemu_get_be32s(f
, &controller
->pib
[i
].piwbar
);
306 qemu_get_be32s(f
, &controller
->pib
[i
].piwbear
);
307 qemu_get_be32s(f
, &controller
->pib
[i
].piwar
);
309 qemu_get_be32s(f
, &controller
->gasket_time
);
314 PCIBus
*ppce500_pci_init(qemu_irq pci_irqs
[4], target_phys_addr_t registers
)
316 PPCE500PCIState
*controller
;
319 static int ppce500_pci_id
;
321 controller
= qemu_mallocz(sizeof(PPCE500PCIState
));
323 controller
->pci_state
.bus
= pci_register_bus(NULL
, "pci",
327 d
= pci_register_device(controller
->pci_state
.bus
,
328 "host bridge", sizeof(PCIDevice
),
331 pci_config_set_vendor_id(d
->config
, PCI_VENDOR_ID_FREESCALE
);
332 pci_config_set_device_id(d
->config
, PCI_DEVICE_ID_MPC8533E
);
333 pci_config_set_class(d
->config
, PCI_CLASS_PROCESSOR_POWERPC
);
335 controller
->pci_dev
= d
;
338 index
= cpu_register_io_memory(pcie500_cfgaddr_read
,
339 pcie500_cfgaddr_write
, controller
);
342 cpu_register_physical_memory(registers
+ PCIE500_CFGADDR
, 4, index
);
345 index
= cpu_register_io_memory(pcie500_cfgdata_read
,
346 pcie500_cfgdata_write
,
347 &controller
->pci_state
);
350 cpu_register_physical_memory(registers
+ PCIE500_CFGDATA
, 4, index
);
352 index
= cpu_register_io_memory(e500_pci_reg_read
,
353 e500_pci_reg_write
, controller
);
356 cpu_register_physical_memory(registers
+ PCIE500_REG_BASE
,
357 PCIE500_REG_SIZE
, index
);
359 /* XXX load/save code not tested. */
360 register_savevm("ppce500_pci", ppce500_pci_id
++, 1,
361 ppce500_pci_save
, ppce500_pci_load
, controller
);
363 return controller
->pci_state
.bus
;
366 printf("%s error\n", __func__
);
367 qemu_free(controller
);