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.
24 #define pci_debug(fmt, ...) fprintf(stderr, fmt, ## __VA_ARGS__)
26 #define pci_debug(fmt, ...)
29 #define PCIE500_CFGADDR 0x0
30 #define PCIE500_CFGDATA 0x4
31 #define PCIE500_REG_BASE 0xC00
32 #define PCIE500_REG_SIZE (0x1000 - PCIE500_REG_BASE)
34 #define PPCE500_PCI_CONFIG_ADDR 0x0
35 #define PPCE500_PCI_CONFIG_DATA 0x4
36 #define PPCE500_PCI_INTACK 0x8
38 #define PPCE500_PCI_OW1 (0xC20 - PCIE500_REG_BASE)
39 #define PPCE500_PCI_OW2 (0xC40 - PCIE500_REG_BASE)
40 #define PPCE500_PCI_OW3 (0xC60 - PCIE500_REG_BASE)
41 #define PPCE500_PCI_OW4 (0xC80 - PCIE500_REG_BASE)
42 #define PPCE500_PCI_IW3 (0xDA0 - PCIE500_REG_BASE)
43 #define PPCE500_PCI_IW2 (0xDC0 - PCIE500_REG_BASE)
44 #define PPCE500_PCI_IW1 (0xDE0 - PCIE500_REG_BASE)
46 #define PPCE500_PCI_GASKET_TIMR (0xE20 - PCIE500_REG_BASE)
49 #define PCI_POTEAR 0x4
50 #define PCI_POWBAR 0x8
51 #define PCI_POWAR 0x10
54 #define PCI_PIWBAR 0x8
55 #define PCI_PIWBEAR 0xC
56 #define PCI_PIWAR 0x10
58 #define PPCE500_PCI_NR_POBS 5
59 #define PPCE500_PCI_NR_PIBS 3
75 struct PPCE500PCIState
{
76 struct pci_outbound pob
[PPCE500_PCI_NR_POBS
];
77 struct pci_inbound pib
[PPCE500_PCI_NR_PIBS
];
79 PCIHostState pci_state
;
83 typedef struct PPCE500PCIState PPCE500PCIState
;
85 static uint32_t pci_reg_read4(void *opaque
, target_phys_addr_t addr
)
87 PPCE500PCIState
*pci
= opaque
;
99 case PCI_POTAR
: value
= pci
->pob
[(addr
>> 5) & 0x7].potar
; break;
100 case PCI_POTEAR
: value
= pci
->pob
[(addr
>> 5) & 0x7].potear
; break;
101 case PCI_POWBAR
: value
= pci
->pob
[(addr
>> 5) & 0x7].powbar
; break;
102 case PCI_POWAR
: value
= pci
->pob
[(addr
>> 5) & 0x7].powar
; break;
107 case PPCE500_PCI_IW3
:
108 case PPCE500_PCI_IW2
:
109 case PPCE500_PCI_IW1
:
110 switch (addr
& 0xC) {
111 case PCI_PITAR
: value
= pci
->pib
[(addr
>> 5) & 0x3].pitar
; break;
112 case PCI_PIWBAR
: value
= pci
->pib
[(addr
>> 5) & 0x3].piwbar
; break;
113 case PCI_PIWBEAR
: value
= pci
->pib
[(addr
>> 5) & 0x3].piwbear
; break;
114 case PCI_PIWAR
: value
= pci
->pib
[(addr
>> 5) & 0x3].piwar
; break;
119 case PPCE500_PCI_GASKET_TIMR
:
120 value
= pci
->gasket_time
;
127 pci_debug("%s: win:%lx(addr:" TARGET_FMT_plx
") -> value:%x\n", __func__
,
132 static CPUReadMemoryFunc
* const e500_pci_reg_read
[] = {
138 static void pci_reg_write4(void *opaque
, target_phys_addr_t addr
,
141 PPCE500PCIState
*pci
= opaque
;
146 pci_debug("%s: value:%x -> win:%lx(addr:" TARGET_FMT_plx
")\n",
147 __func__
, value
, win
, addr
);
150 case PPCE500_PCI_OW1
:
151 case PPCE500_PCI_OW2
:
152 case PPCE500_PCI_OW3
:
153 case PPCE500_PCI_OW4
:
154 switch (addr
& 0xC) {
155 case PCI_POTAR
: pci
->pob
[(addr
>> 5) & 0x7].potar
= value
; break;
156 case PCI_POTEAR
: pci
->pob
[(addr
>> 5) & 0x7].potear
= value
; break;
157 case PCI_POWBAR
: pci
->pob
[(addr
>> 5) & 0x7].powbar
= value
; break;
158 case PCI_POWAR
: pci
->pob
[(addr
>> 5) & 0x7].powar
= value
; break;
163 case PPCE500_PCI_IW3
:
164 case PPCE500_PCI_IW2
:
165 case PPCE500_PCI_IW1
:
166 switch (addr
& 0xC) {
167 case PCI_PITAR
: pci
->pib
[(addr
>> 5) & 0x3].pitar
= value
; break;
168 case PCI_PIWBAR
: pci
->pib
[(addr
>> 5) & 0x3].piwbar
= value
; break;
169 case PCI_PIWBEAR
: pci
->pib
[(addr
>> 5) & 0x3].piwbear
= value
; break;
170 case PCI_PIWAR
: pci
->pib
[(addr
>> 5) & 0x3].piwar
= value
; break;
175 case PPCE500_PCI_GASKET_TIMR
:
176 pci
->gasket_time
= value
;
184 static CPUWriteMemoryFunc
* const e500_pci_reg_write
[] = {
190 static int mpc85xx_pci_map_irq(PCIDevice
*pci_dev
, int irq_num
)
192 int devno
= pci_dev
->devfn
>> 3, ret
= 0;
198 ret
= (irq_num
+ devno
- 0x10) % 4;
201 printf("Error:%s:unknown dev number\n", __func__
);
204 pci_debug("%s: devfn %x irq %d -> %d devno:%x\n", __func__
,
205 pci_dev
->devfn
, irq_num
, ret
, devno
);
210 static void mpc85xx_pci_set_irq(void *opaque
, int irq_num
, int level
)
212 qemu_irq
*pic
= opaque
;
214 pci_debug("%s: PCI irq %d, level:%d\n", __func__
, irq_num
, level
);
216 qemu_set_irq(pic
[irq_num
], level
);
219 static const VMStateDescription vmstate_pci_outbound
= {
220 .name
= "pci_outbound",
222 .minimum_version_id
= 0,
223 .minimum_version_id_old
= 0,
224 .fields
= (VMStateField
[]) {
225 VMSTATE_UINT32(potar
, struct pci_outbound
),
226 VMSTATE_UINT32(potear
, struct pci_outbound
),
227 VMSTATE_UINT32(powbar
, struct pci_outbound
),
228 VMSTATE_UINT32(powar
, struct pci_outbound
),
229 VMSTATE_END_OF_LIST()
233 static const VMStateDescription vmstate_pci_inbound
= {
234 .name
= "pci_inbound",
236 .minimum_version_id
= 0,
237 .minimum_version_id_old
= 0,
238 .fields
= (VMStateField
[]) {
239 VMSTATE_UINT32(pitar
, struct pci_inbound
),
240 VMSTATE_UINT32(piwbar
, struct pci_inbound
),
241 VMSTATE_UINT32(piwbear
, struct pci_inbound
),
242 VMSTATE_UINT32(piwar
, struct pci_inbound
),
243 VMSTATE_END_OF_LIST()
247 static const VMStateDescription vmstate_ppce500_pci
= {
248 .name
= "ppce500_pci",
250 .minimum_version_id
= 1,
251 .minimum_version_id_old
= 1,
252 .fields
= (VMStateField
[]) {
253 VMSTATE_PCI_DEVICE_POINTER(pci_dev
, PPCE500PCIState
),
254 VMSTATE_STRUCT_ARRAY(pob
, PPCE500PCIState
, PPCE500_PCI_NR_POBS
, 1,
255 vmstate_pci_outbound
, struct pci_outbound
),
256 VMSTATE_STRUCT_ARRAY(pib
, PPCE500PCIState
, PPCE500_PCI_NR_PIBS
, 1,
257 vmstate_pci_outbound
, struct pci_inbound
),
258 VMSTATE_UINT32(gasket_time
, PPCE500PCIState
),
259 VMSTATE_END_OF_LIST()
263 PCIBus
*ppce500_pci_init(qemu_irq pci_irqs
[4], target_phys_addr_t registers
)
265 PPCE500PCIState
*controller
;
268 static int ppce500_pci_id
;
270 controller
= qemu_mallocz(sizeof(PPCE500PCIState
));
272 controller
->pci_state
.bus
= pci_register_bus(NULL
, "pci",
275 pci_irqs
, PCI_DEVFN(0x11, 0),
277 d
= pci_register_device(controller
->pci_state
.bus
,
278 "host bridge", sizeof(PCIDevice
),
281 pci_config_set_vendor_id(d
->config
, PCI_VENDOR_ID_FREESCALE
);
282 pci_config_set_device_id(d
->config
, PCI_DEVICE_ID_MPC8533E
);
283 pci_config_set_class(d
->config
, PCI_CLASS_PROCESSOR_POWERPC
);
285 controller
->pci_dev
= d
;
288 index
= pci_host_conf_register_mmio(&controller
->pci_state
,
292 cpu_register_physical_memory(registers
+ PCIE500_CFGADDR
, 4, index
);
295 index
= pci_host_data_register_mmio(&controller
->pci_state
,
299 cpu_register_physical_memory(registers
+ PCIE500_CFGDATA
, 4, index
);
301 index
= cpu_register_io_memory(e500_pci_reg_read
,
302 e500_pci_reg_write
, controller
,
303 DEVICE_NATIVE_ENDIAN
);
306 cpu_register_physical_memory(registers
+ PCIE500_REG_BASE
,
307 PCIE500_REG_SIZE
, index
);
309 /* XXX load/save code not tested. */
310 vmstate_register(&d
->qdev
, ppce500_pci_id
++, &vmstate_ppce500_pci
,
313 return controller
->pci_state
.bus
;
316 printf("%s error\n", __func__
);
317 qemu_free(controller
);