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.
23 #define pci_debug(fmt, ...) fprintf(stderr, fmt, ## __VA_ARGS__)
25 #define pci_debug(fmt, ...)
28 #define PCIE500_CFGADDR 0x0
29 #define PCIE500_CFGDATA 0x4
30 #define PCIE500_REG_BASE 0xC00
31 #define PCIE500_ALL_SIZE 0x1000
32 #define PCIE500_REG_SIZE (PCIE500_ALL_SIZE - 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 PCIHostState pci_state
;
77 struct pci_outbound pob
[PPCE500_PCI_NR_POBS
];
78 struct pci_inbound pib
[PPCE500_PCI_NR_PIBS
];
85 typedef struct PPCE500PCIState PPCE500PCIState
;
87 static uint64_t pci_reg_read4(void *opaque
, target_phys_addr_t addr
,
90 PPCE500PCIState
*pci
= opaque
;
100 case PPCE500_PCI_OW3
:
101 case PPCE500_PCI_OW4
:
102 idx
= (addr
>> 5) & 0x7;
103 switch (addr
& 0xC) {
105 value
= pci
->pob
[idx
].potar
;
108 value
= pci
->pob
[idx
].potear
;
111 value
= pci
->pob
[idx
].powbar
;
114 value
= pci
->pob
[idx
].powar
;
121 case PPCE500_PCI_IW3
:
122 case PPCE500_PCI_IW2
:
123 case PPCE500_PCI_IW1
:
124 idx
= ((addr
>> 5) & 0x3) - 1;
125 switch (addr
& 0xC) {
127 value
= pci
->pib
[idx
].pitar
;
130 value
= pci
->pib
[idx
].piwbar
;
133 value
= pci
->pib
[idx
].piwbear
;
136 value
= pci
->pib
[idx
].piwar
;
143 case PPCE500_PCI_GASKET_TIMR
:
144 value
= pci
->gasket_time
;
151 pci_debug("%s: win:%lx(addr:" TARGET_FMT_plx
") -> value:%x\n", __func__
,
156 static void pci_reg_write4(void *opaque
, target_phys_addr_t addr
,
157 uint64_t value
, unsigned size
)
159 PPCE500PCIState
*pci
= opaque
;
165 pci_debug("%s: value:%x -> win:%lx(addr:" TARGET_FMT_plx
")\n",
166 __func__
, (unsigned)value
, win
, addr
);
169 case PPCE500_PCI_OW1
:
170 case PPCE500_PCI_OW2
:
171 case PPCE500_PCI_OW3
:
172 case PPCE500_PCI_OW4
:
173 idx
= (addr
>> 5) & 0x7;
174 switch (addr
& 0xC) {
176 pci
->pob
[idx
].potar
= value
;
179 pci
->pob
[idx
].potear
= value
;
182 pci
->pob
[idx
].powbar
= value
;
185 pci
->pob
[idx
].powar
= value
;
192 case PPCE500_PCI_IW3
:
193 case PPCE500_PCI_IW2
:
194 case PPCE500_PCI_IW1
:
195 idx
= ((addr
>> 5) & 0x3) - 1;
196 switch (addr
& 0xC) {
198 pci
->pib
[idx
].pitar
= value
;
201 pci
->pib
[idx
].piwbar
= value
;
204 pci
->pib
[idx
].piwbear
= value
;
207 pci
->pib
[idx
].piwar
= value
;
214 case PPCE500_PCI_GASKET_TIMR
:
215 pci
->gasket_time
= value
;
223 static const MemoryRegionOps e500_pci_reg_ops
= {
224 .read
= pci_reg_read4
,
225 .write
= pci_reg_write4
,
226 .endianness
= DEVICE_BIG_ENDIAN
,
229 static int mpc85xx_pci_map_irq(PCIDevice
*pci_dev
, int irq_num
)
231 int devno
= pci_dev
->devfn
>> 3, ret
= 0;
237 ret
= (irq_num
+ devno
- 0x10) % 4;
240 printf("Error:%s:unknown dev number\n", __func__
);
243 pci_debug("%s: devfn %x irq %d -> %d devno:%x\n", __func__
,
244 pci_dev
->devfn
, irq_num
, ret
, devno
);
249 static void mpc85xx_pci_set_irq(void *opaque
, int irq_num
, int level
)
251 qemu_irq
*pic
= opaque
;
253 pci_debug("%s: PCI irq %d, level:%d\n", __func__
, irq_num
, level
);
255 qemu_set_irq(pic
[irq_num
], level
);
258 static const VMStateDescription vmstate_pci_outbound
= {
259 .name
= "pci_outbound",
261 .minimum_version_id
= 0,
262 .minimum_version_id_old
= 0,
263 .fields
= (VMStateField
[]) {
264 VMSTATE_UINT32(potar
, struct pci_outbound
),
265 VMSTATE_UINT32(potear
, struct pci_outbound
),
266 VMSTATE_UINT32(powbar
, struct pci_outbound
),
267 VMSTATE_UINT32(powar
, struct pci_outbound
),
268 VMSTATE_END_OF_LIST()
272 static const VMStateDescription vmstate_pci_inbound
= {
273 .name
= "pci_inbound",
275 .minimum_version_id
= 0,
276 .minimum_version_id_old
= 0,
277 .fields
= (VMStateField
[]) {
278 VMSTATE_UINT32(pitar
, struct pci_inbound
),
279 VMSTATE_UINT32(piwbar
, struct pci_inbound
),
280 VMSTATE_UINT32(piwbear
, struct pci_inbound
),
281 VMSTATE_UINT32(piwar
, struct pci_inbound
),
282 VMSTATE_END_OF_LIST()
286 static const VMStateDescription vmstate_ppce500_pci
= {
287 .name
= "ppce500_pci",
289 .minimum_version_id
= 1,
290 .minimum_version_id_old
= 1,
291 .fields
= (VMStateField
[]) {
292 VMSTATE_STRUCT_ARRAY(pob
, PPCE500PCIState
, PPCE500_PCI_NR_POBS
, 1,
293 vmstate_pci_outbound
, struct pci_outbound
),
294 VMSTATE_STRUCT_ARRAY(pib
, PPCE500PCIState
, PPCE500_PCI_NR_PIBS
, 1,
295 vmstate_pci_outbound
, struct pci_inbound
),
296 VMSTATE_UINT32(gasket_time
, PPCE500PCIState
),
297 VMSTATE_END_OF_LIST()
301 static void e500_pci_map(SysBusDevice
*dev
, target_phys_addr_t base
)
303 PCIHostState
*h
= FROM_SYSBUS(PCIHostState
, sysbus_from_qdev(dev
));
304 PPCE500PCIState
*s
= DO_UPCAST(PPCE500PCIState
, pci_state
, h
);
306 sysbus_add_memory(dev
, base
+ PCIE500_CFGADDR
, &h
->conf_mem
);
307 sysbus_add_memory(dev
, base
+ PCIE500_CFGDATA
, &h
->data_mem
);
308 sysbus_add_memory(dev
, base
+ PCIE500_REG_BASE
, &s
->iomem
);
311 static void e500_pci_unmap(SysBusDevice
*dev
, target_phys_addr_t base
)
313 PCIHostState
*h
= FROM_SYSBUS(PCIHostState
, sysbus_from_qdev(dev
));
314 PPCE500PCIState
*s
= DO_UPCAST(PPCE500PCIState
, pci_state
, h
);
316 sysbus_del_memory(dev
, &h
->conf_mem
);
317 sysbus_del_memory(dev
, &h
->data_mem
);
318 sysbus_del_memory(dev
, &s
->iomem
);
321 #include "exec-memory.h"
323 static int e500_pcihost_initfn(SysBusDevice
*dev
)
329 MemoryRegion
*address_space_mem
= get_system_memory();
330 MemoryRegion
*address_space_io
= get_system_io();
332 h
= FROM_SYSBUS(PCIHostState
, sysbus_from_qdev(dev
));
333 s
= DO_UPCAST(PPCE500PCIState
, pci_state
, h
);
335 for (i
= 0; i
< ARRAY_SIZE(s
->irq
); i
++) {
336 sysbus_init_irq(dev
, &s
->irq
[i
]);
339 b
= pci_register_bus(&s
->pci_state
.busdev
.qdev
, NULL
, mpc85xx_pci_set_irq
,
340 mpc85xx_pci_map_irq
, s
->irq
, address_space_mem
,
341 address_space_io
, PCI_DEVFN(0x11, 0), 4);
342 s
->pci_state
.bus
= b
;
344 pci_create_simple(b
, 0, "e500-host-bridge");
346 memory_region_init_io(&h
->conf_mem
, &pci_host_conf_be_ops
, h
,
348 memory_region_init_io(&h
->data_mem
, &pci_host_data_le_ops
, h
,
350 memory_region_init_io(&s
->iomem
, &e500_pci_reg_ops
, s
,
351 "pci.reg", PCIE500_REG_SIZE
);
352 sysbus_init_mmio_cb2(dev
, e500_pci_map
, e500_pci_unmap
);
357 static PCIDeviceInfo e500_host_bridge_info
= {
358 .qdev
.name
= "e500-host-bridge",
359 .qdev
.desc
= "Host bridge",
360 .qdev
.size
= sizeof(PCIDevice
),
361 .vendor_id
= PCI_VENDOR_ID_FREESCALE
,
362 .device_id
= PCI_DEVICE_ID_MPC8533E
,
363 .class_id
= PCI_CLASS_PROCESSOR_POWERPC
,
366 static SysBusDeviceInfo e500_pcihost_info
= {
367 .init
= e500_pcihost_initfn
,
368 .qdev
.name
= "e500-pcihost",
369 .qdev
.size
= sizeof(PPCE500PCIState
),
370 .qdev
.vmsd
= &vmstate_ppce500_pci
,
373 static void e500_pci_register(void)
375 sysbus_register_withprop(&e500_pcihost_info
);
376 pci_qdev_register(&e500_host_bridge_info
);
378 device_init(e500_pci_register
);