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 #define TYPE_PPC_E500_PCI_HOST_BRIDGE "e500-pcihost"
77 #define PPC_E500_PCI_HOST_BRIDGE(obj) \
78 OBJECT_CHECK(PPCE500PCIState, (obj), TYPE_PPC_E500_PCI_HOST_BRIDGE)
80 struct PPCE500PCIState
{
81 PCIHostState parent_obj
;
83 struct pci_outbound pob
[PPCE500_PCI_NR_POBS
];
84 struct pci_inbound pib
[PPCE500_PCI_NR_PIBS
];
88 MemoryRegion container
;
92 typedef struct PPCE500PCIState PPCE500PCIState
;
94 static uint64_t pci_reg_read4(void *opaque
, target_phys_addr_t addr
,
97 PPCE500PCIState
*pci
= opaque
;
105 case PPCE500_PCI_OW1
:
106 case PPCE500_PCI_OW2
:
107 case PPCE500_PCI_OW3
:
108 case PPCE500_PCI_OW4
:
109 idx
= (addr
>> 5) & 0x7;
110 switch (addr
& 0xC) {
112 value
= pci
->pob
[idx
].potar
;
115 value
= pci
->pob
[idx
].potear
;
118 value
= pci
->pob
[idx
].powbar
;
121 value
= pci
->pob
[idx
].powar
;
128 case PPCE500_PCI_IW3
:
129 case PPCE500_PCI_IW2
:
130 case PPCE500_PCI_IW1
:
131 idx
= ((addr
>> 5) & 0x3) - 1;
132 switch (addr
& 0xC) {
134 value
= pci
->pib
[idx
].pitar
;
137 value
= pci
->pib
[idx
].piwbar
;
140 value
= pci
->pib
[idx
].piwbear
;
143 value
= pci
->pib
[idx
].piwar
;
150 case PPCE500_PCI_GASKET_TIMR
:
151 value
= pci
->gasket_time
;
158 pci_debug("%s: win:%lx(addr:" TARGET_FMT_plx
") -> value:%x\n", __func__
,
163 static void pci_reg_write4(void *opaque
, target_phys_addr_t addr
,
164 uint64_t value
, unsigned size
)
166 PPCE500PCIState
*pci
= opaque
;
172 pci_debug("%s: value:%x -> win:%lx(addr:" TARGET_FMT_plx
")\n",
173 __func__
, (unsigned)value
, win
, addr
);
176 case PPCE500_PCI_OW1
:
177 case PPCE500_PCI_OW2
:
178 case PPCE500_PCI_OW3
:
179 case PPCE500_PCI_OW4
:
180 idx
= (addr
>> 5) & 0x7;
181 switch (addr
& 0xC) {
183 pci
->pob
[idx
].potar
= value
;
186 pci
->pob
[idx
].potear
= value
;
189 pci
->pob
[idx
].powbar
= value
;
192 pci
->pob
[idx
].powar
= value
;
199 case PPCE500_PCI_IW3
:
200 case PPCE500_PCI_IW2
:
201 case PPCE500_PCI_IW1
:
202 idx
= ((addr
>> 5) & 0x3) - 1;
203 switch (addr
& 0xC) {
205 pci
->pib
[idx
].pitar
= value
;
208 pci
->pib
[idx
].piwbar
= value
;
211 pci
->pib
[idx
].piwbear
= value
;
214 pci
->pib
[idx
].piwar
= value
;
221 case PPCE500_PCI_GASKET_TIMR
:
222 pci
->gasket_time
= value
;
230 static const MemoryRegionOps e500_pci_reg_ops
= {
231 .read
= pci_reg_read4
,
232 .write
= pci_reg_write4
,
233 .endianness
= DEVICE_BIG_ENDIAN
,
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:unknown 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(void *opaque
, int irq_num
, int level
)
258 qemu_irq
*pic
= opaque
;
260 pci_debug("%s: PCI irq %d, level:%d\n", __func__
, irq_num
, level
);
262 qemu_set_irq(pic
[irq_num
], level
);
265 static const VMStateDescription vmstate_pci_outbound
= {
266 .name
= "pci_outbound",
268 .minimum_version_id
= 0,
269 .minimum_version_id_old
= 0,
270 .fields
= (VMStateField
[]) {
271 VMSTATE_UINT32(potar
, struct pci_outbound
),
272 VMSTATE_UINT32(potear
, struct pci_outbound
),
273 VMSTATE_UINT32(powbar
, struct pci_outbound
),
274 VMSTATE_UINT32(powar
, struct pci_outbound
),
275 VMSTATE_END_OF_LIST()
279 static const VMStateDescription vmstate_pci_inbound
= {
280 .name
= "pci_inbound",
282 .minimum_version_id
= 0,
283 .minimum_version_id_old
= 0,
284 .fields
= (VMStateField
[]) {
285 VMSTATE_UINT32(pitar
, struct pci_inbound
),
286 VMSTATE_UINT32(piwbar
, struct pci_inbound
),
287 VMSTATE_UINT32(piwbear
, struct pci_inbound
),
288 VMSTATE_UINT32(piwar
, struct pci_inbound
),
289 VMSTATE_END_OF_LIST()
293 static const VMStateDescription vmstate_ppce500_pci
= {
294 .name
= "ppce500_pci",
296 .minimum_version_id
= 1,
297 .minimum_version_id_old
= 1,
298 .fields
= (VMStateField
[]) {
299 VMSTATE_STRUCT_ARRAY(pob
, PPCE500PCIState
, PPCE500_PCI_NR_POBS
, 1,
300 vmstate_pci_outbound
, struct pci_outbound
),
301 VMSTATE_STRUCT_ARRAY(pib
, PPCE500PCIState
, PPCE500_PCI_NR_PIBS
, 1,
302 vmstate_pci_outbound
, struct pci_inbound
),
303 VMSTATE_UINT32(gasket_time
, PPCE500PCIState
),
304 VMSTATE_END_OF_LIST()
308 #include "exec-memory.h"
310 static int e500_pcihost_initfn(SysBusDevice
*dev
)
316 MemoryRegion
*address_space_mem
= get_system_memory();
317 MemoryRegion
*address_space_io
= get_system_io();
319 h
= PCI_HOST_BRIDGE(dev
);
320 s
= PPC_E500_PCI_HOST_BRIDGE(dev
);
322 for (i
= 0; i
< ARRAY_SIZE(s
->irq
); i
++) {
323 sysbus_init_irq(dev
, &s
->irq
[i
]);
326 b
= pci_register_bus(DEVICE(dev
), NULL
, mpc85xx_pci_set_irq
,
327 mpc85xx_pci_map_irq
, s
->irq
, address_space_mem
,
328 address_space_io
, PCI_DEVFN(0x11, 0), 4);
331 pci_create_simple(b
, 0, "e500-host-bridge");
333 memory_region_init(&s
->container
, "pci-container", PCIE500_ALL_SIZE
);
334 memory_region_init_io(&h
->conf_mem
, &pci_host_conf_be_ops
, h
,
336 memory_region_init_io(&h
->data_mem
, &pci_host_data_le_ops
, h
,
338 memory_region_init_io(&s
->iomem
, &e500_pci_reg_ops
, s
,
339 "pci.reg", PCIE500_REG_SIZE
);
340 memory_region_add_subregion(&s
->container
, PCIE500_CFGADDR
, &h
->conf_mem
);
341 memory_region_add_subregion(&s
->container
, PCIE500_CFGDATA
, &h
->data_mem
);
342 memory_region_add_subregion(&s
->container
, PCIE500_REG_BASE
, &s
->iomem
);
343 sysbus_init_mmio(dev
, &s
->container
);
348 static void e500_host_bridge_class_init(ObjectClass
*klass
, void *data
)
350 DeviceClass
*dc
= DEVICE_CLASS(klass
);
351 PCIDeviceClass
*k
= PCI_DEVICE_CLASS(klass
);
353 k
->vendor_id
= PCI_VENDOR_ID_FREESCALE
;
354 k
->device_id
= PCI_DEVICE_ID_MPC8533E
;
355 k
->class_id
= PCI_CLASS_PROCESSOR_POWERPC
;
356 dc
->desc
= "Host bridge";
359 static const TypeInfo e500_host_bridge_info
= {
360 .name
= "e500-host-bridge",
361 .parent
= TYPE_PCI_DEVICE
,
362 .instance_size
= sizeof(PCIDevice
),
363 .class_init
= e500_host_bridge_class_init
,
366 static void e500_pcihost_class_init(ObjectClass
*klass
, void *data
)
368 DeviceClass
*dc
= DEVICE_CLASS(klass
);
369 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
371 k
->init
= e500_pcihost_initfn
;
372 dc
->vmsd
= &vmstate_ppce500_pci
;
375 static const TypeInfo e500_pcihost_info
= {
376 .name
= TYPE_PPC_E500_PCI_HOST_BRIDGE
,
377 .parent
= TYPE_PCI_HOST_BRIDGE
,
378 .instance_size
= sizeof(PPCE500PCIState
),
379 .class_init
= e500_pcihost_class_init
,
382 static void e500_pci_register_types(void)
384 type_register_static(&e500_pcihost_info
);
385 type_register_static(&e500_host_bridge_info
);
388 type_init(e500_pci_register_types
)