blob: 215b64ffed98ea970565601e12395a62ce1a3510 [file] [log] [blame]
pbrook502a5392006-05-13 16:11:23 +00001/*
2 * QEMU Uninorth PCI host (for all Mac99 and newer machines)
3 *
4 * Copyright (c) 2006 Fabrice Bellard
ths5fafdf22007-09-16 21:08:06 +00005 *
pbrook502a5392006-05-13 16:11:23 +00006 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
Paolo Bonzini83c9f4c2013-02-04 15:40:22 +010024#include "hw/hw.h"
25#include "hw/ppc/mac.h"
26#include "hw/pci/pci.h"
27#include "hw/pci/pci_host.h"
pbrook87ecb682007-11-17 17:14:51 +000028
blueswir1f3902382009-02-05 20:22:07 +000029/* debug UniNorth */
30//#define DEBUG_UNIN
31
32#ifdef DEBUG_UNIN
Blue Swirl001faf32009-05-13 17:53:17 +000033#define UNIN_DPRINTF(fmt, ...) \
34 do { printf("UNIN: " fmt , ## __VA_ARGS__); } while (0)
blueswir1f3902382009-02-05 20:22:07 +000035#else
Blue Swirl001faf32009-05-13 17:53:17 +000036#define UNIN_DPRINTF(fmt, ...)
blueswir1f3902382009-02-05 20:22:07 +000037#endif
38
Alexander Graffa0be692010-02-09 17:37:04 +010039static const int unin_irq_line[] = { 0x1b, 0x1c, 0x1d, 0x1e };
40
Andreas Färber57fd7b72012-08-20 19:08:06 +020041#define TYPE_UNI_NORTH_PCI_HOST_BRIDGE "uni-north-pci-pcihost"
42#define TYPE_UNI_NORTH_AGP_HOST_BRIDGE "uni-north-agp-pcihost"
43#define TYPE_UNI_NORTH_INTERNAL_PCI_HOST_BRIDGE "uni-north-internal-pci-pcihost"
44#define TYPE_U3_AGP_HOST_BRIDGE "u3-agp-pcihost"
45
46#define UNI_NORTH_PCI_HOST_BRIDGE(obj) \
47 OBJECT_CHECK(UNINState, (obj), TYPE_UNI_NORTH_PCI_HOST_BRIDGE)
48#define UNI_NORTH_AGP_HOST_BRIDGE(obj) \
49 OBJECT_CHECK(UNINState, (obj), TYPE_UNI_NORTH_AGP_HOST_BRIDGE)
50#define UNI_NORTH_INTERNAL_PCI_HOST_BRIDGE(obj) \
51 OBJECT_CHECK(UNINState, (obj), TYPE_UNI_NORTH_INTERNAL_PCI_HOST_BRIDGE)
52#define U3_AGP_HOST_BRIDGE(obj) \
53 OBJECT_CHECK(UNINState, (obj), TYPE_U3_AGP_HOST_BRIDGE)
54
Blue Swirl2e29bd02009-07-31 20:23:28 +000055typedef struct UNINState {
Andreas Färber67c332f2012-08-20 19:08:09 +020056 PCIHostState parent_obj;
Andreas Färber57fd7b72012-08-20 19:08:06 +020057
Blue Swirl46f30692011-09-17 20:30:50 +000058 MemoryRegion pci_mmio;
59 MemoryRegion pci_hole;
Blue Swirl2e29bd02009-07-31 20:23:28 +000060} UNINState;
pbrook502a5392006-05-13 16:11:23 +000061
pbrookd2b59312006-09-24 00:16:34 +000062static int pci_unin_map_irq(PCIDevice *pci_dev, int irq_num)
pbrook502a5392006-05-13 16:11:23 +000063{
Alexander Graffa0be692010-02-09 17:37:04 +010064 int retval;
65 int devfn = pci_dev->devfn & 0x00FFFFFF;
66
67 retval = (((devfn >> 11) & 0x1F) + irq_num) & 3;
68
69 return retval;
pbrookd2b59312006-09-24 00:16:34 +000070}
71
Juan Quintela5d4e84c2009-08-28 15:28:17 +020072static void pci_unin_set_irq(void *opaque, int irq_num, int level)
pbrookd2b59312006-09-24 00:16:34 +000073{
Juan Quintela5d4e84c2009-08-28 15:28:17 +020074 qemu_irq *pic = opaque;
75
Alexander Graffa0be692010-02-09 17:37:04 +010076 UNIN_DPRINTF("%s: setting INT %d = %d\n", __func__,
77 unin_irq_line[irq_num], level);
78 qemu_set_irq(pic[unin_irq_line[irq_num]], level);
pbrook502a5392006-05-13 16:11:23 +000079}
80
Alexander Grafd86f0e32010-02-09 17:37:01 +010081static uint32_t unin_get_config_reg(uint32_t reg, uint32_t addr)
82{
83 uint32_t retval;
84
85 if (reg & (1u << 31)) {
86 /* XXX OpenBIOS compatibility hack */
87 retval = reg | (addr & 3);
88 } else if (reg & 1) {
89 /* CFA1 style */
90 retval = (reg & ~7u) | (addr & 7);
91 } else {
92 uint32_t slot, func;
93
94 /* Grab CFA0 style values */
Stefan Hajnoczi5863d372015-03-23 15:29:25 +000095 slot = ctz32(reg & 0xfffff800);
96 if (slot == 32) {
97 slot = -1; /* XXX: should this be 0? */
98 }
Alexander Grafd86f0e32010-02-09 17:37:01 +010099 func = (reg >> 8) & 7;
100
101 /* ... and then convert them to x86 format */
102 /* config pointer */
103 retval = (reg & (0xff - 7)) | (addr & 7);
104 /* slot */
105 retval |= slot << 11;
106 /* fn */
107 retval |= func << 8;
108 }
109
110
111 UNIN_DPRINTF("Converted config space accessor %08x/%08x -> %08x\n",
112 reg, addr, retval);
113
114 return retval;
115}
116
Avi Kivitya8170e52012-10-23 12:30:10 +0200117static void unin_data_write(void *opaque, hwaddr addr,
Avi Kivityd0ed8072011-07-24 17:47:18 +0300118 uint64_t val, unsigned len)
Alexander Grafd86f0e32010-02-09 17:37:01 +0100119{
Avi Kivityd0ed8072011-07-24 17:47:18 +0300120 UNINState *s = opaque;
Andreas Färber67c332f2012-08-20 19:08:09 +0200121 PCIHostState *phb = PCI_HOST_BRIDGE(s);
Avi Kivityd0ed8072011-07-24 17:47:18 +0300122 UNIN_DPRINTF("write addr %" TARGET_FMT_plx " len %d val %"PRIx64"\n",
123 addr, len, val);
Andreas Färber67c332f2012-08-20 19:08:09 +0200124 pci_data_write(phb->bus,
125 unin_get_config_reg(phb->config_reg, addr),
Alexander Grafd86f0e32010-02-09 17:37:01 +0100126 val, len);
127}
128
Avi Kivitya8170e52012-10-23 12:30:10 +0200129static uint64_t unin_data_read(void *opaque, hwaddr addr,
Avi Kivityd0ed8072011-07-24 17:47:18 +0300130 unsigned len)
Alexander Grafd86f0e32010-02-09 17:37:01 +0100131{
Avi Kivityd0ed8072011-07-24 17:47:18 +0300132 UNINState *s = opaque;
Andreas Färber67c332f2012-08-20 19:08:09 +0200133 PCIHostState *phb = PCI_HOST_BRIDGE(s);
Alexander Grafd86f0e32010-02-09 17:37:01 +0100134 uint32_t val;
135
Andreas Färber67c332f2012-08-20 19:08:09 +0200136 val = pci_data_read(phb->bus,
137 unin_get_config_reg(phb->config_reg, addr),
Alexander Grafd86f0e32010-02-09 17:37:01 +0100138 len);
Avi Kivityd0ed8072011-07-24 17:47:18 +0300139 UNIN_DPRINTF("read addr %" TARGET_FMT_plx " len %d val %x\n",
140 addr, len, val);
Alexander Grafd86f0e32010-02-09 17:37:01 +0100141 return val;
142}
143
Avi Kivityd0ed8072011-07-24 17:47:18 +0300144static const MemoryRegionOps unin_data_ops = {
145 .read = unin_data_read,
146 .write = unin_data_write,
147 .endianness = DEVICE_LITTLE_ENDIAN,
148};
149
Gerd Hoffmann81a322d2009-08-14 10:36:05 +0200150static int pci_unin_main_init_device(SysBusDevice *dev)
pbrook502a5392006-05-13 16:11:23 +0000151{
Andreas Färberff452ac2012-01-19 07:40:17 +0000152 PCIHostState *h;
pbrook502a5392006-05-13 16:11:23 +0000153
154 /* Use values found on a real PowerMac */
155 /* Uninorth main bus */
Andreas Färber8558d942012-08-20 19:08:08 +0200156 h = PCI_HOST_BRIDGE(dev);
pbrook502a5392006-05-13 16:11:23 +0000157
Paolo Bonzini40c5dce2013-06-06 21:25:08 -0400158 memory_region_init_io(&h->conf_mem, OBJECT(h), &pci_host_conf_le_ops,
Andreas Färber57fd7b72012-08-20 19:08:06 +0200159 dev, "pci-conf-idx", 0x1000);
Paolo Bonzini40c5dce2013-06-06 21:25:08 -0400160 memory_region_init_io(&h->data_mem, OBJECT(h), &unin_data_ops, dev,
Avi Kivityd0ed8072011-07-24 17:47:18 +0300161 "pci-conf-data", 0x1000);
Andreas Färber57fd7b72012-08-20 19:08:06 +0200162 sysbus_init_mmio(dev, &h->conf_mem);
163 sysbus_init_mmio(dev, &h->data_mem);
Blue Swirl2e29bd02009-07-31 20:23:28 +0000164
Gerd Hoffmann81a322d2009-08-14 10:36:05 +0200165 return 0;
Blue Swirl2e29bd02009-07-31 20:23:28 +0000166}
167
Avi Kivityd0ed8072011-07-24 17:47:18 +0300168
Alexander Graf0f921192010-02-09 17:37:02 +0100169static int pci_u3_agp_init_device(SysBusDevice *dev)
170{
Andreas Färberff452ac2012-01-19 07:40:17 +0000171 PCIHostState *h;
Alexander Graf0f921192010-02-09 17:37:02 +0100172
173 /* Uninorth U3 AGP bus */
Andreas Färber8558d942012-08-20 19:08:08 +0200174 h = PCI_HOST_BRIDGE(dev);
Alexander Graf0f921192010-02-09 17:37:02 +0100175
Paolo Bonzini40c5dce2013-06-06 21:25:08 -0400176 memory_region_init_io(&h->conf_mem, OBJECT(h), &pci_host_conf_le_ops,
Andreas Färber57fd7b72012-08-20 19:08:06 +0200177 dev, "pci-conf-idx", 0x1000);
Paolo Bonzini40c5dce2013-06-06 21:25:08 -0400178 memory_region_init_io(&h->data_mem, OBJECT(h), &unin_data_ops, dev,
Avi Kivityd0ed8072011-07-24 17:47:18 +0300179 "pci-conf-data", 0x1000);
Andreas Färber57fd7b72012-08-20 19:08:06 +0200180 sysbus_init_mmio(dev, &h->conf_mem);
181 sysbus_init_mmio(dev, &h->data_mem);
Alexander Graf0f921192010-02-09 17:37:02 +0100182
Alexander Graf0f921192010-02-09 17:37:02 +0100183 return 0;
184}
185
Gerd Hoffmann81a322d2009-08-14 10:36:05 +0200186static int pci_unin_agp_init_device(SysBusDevice *dev)
Blue Swirl2e29bd02009-07-31 20:23:28 +0000187{
Andreas Färberff452ac2012-01-19 07:40:17 +0000188 PCIHostState *h;
Blue Swirl2e29bd02009-07-31 20:23:28 +0000189
190 /* Uninorth AGP bus */
Andreas Färber8558d942012-08-20 19:08:08 +0200191 h = PCI_HOST_BRIDGE(dev);
Blue Swirl2e29bd02009-07-31 20:23:28 +0000192
Paolo Bonzini40c5dce2013-06-06 21:25:08 -0400193 memory_region_init_io(&h->conf_mem, OBJECT(h), &pci_host_conf_le_ops,
Andreas Färber57fd7b72012-08-20 19:08:06 +0200194 dev, "pci-conf-idx", 0x1000);
Paolo Bonzini40c5dce2013-06-06 21:25:08 -0400195 memory_region_init_io(&h->data_mem, OBJECT(h), &pci_host_data_le_ops,
Andreas Färber57fd7b72012-08-20 19:08:06 +0200196 dev, "pci-conf-data", 0x1000);
197 sysbus_init_mmio(dev, &h->conf_mem);
198 sysbus_init_mmio(dev, &h->data_mem);
Gerd Hoffmann81a322d2009-08-14 10:36:05 +0200199 return 0;
Blue Swirl2e29bd02009-07-31 20:23:28 +0000200}
201
Gerd Hoffmann81a322d2009-08-14 10:36:05 +0200202static int pci_unin_internal_init_device(SysBusDevice *dev)
Blue Swirl2e29bd02009-07-31 20:23:28 +0000203{
Andreas Färberff452ac2012-01-19 07:40:17 +0000204 PCIHostState *h;
Blue Swirl2e29bd02009-07-31 20:23:28 +0000205
206 /* Uninorth internal bus */
Andreas Färber8558d942012-08-20 19:08:08 +0200207 h = PCI_HOST_BRIDGE(dev);
Blue Swirl2e29bd02009-07-31 20:23:28 +0000208
Paolo Bonzini40c5dce2013-06-06 21:25:08 -0400209 memory_region_init_io(&h->conf_mem, OBJECT(h), &pci_host_conf_le_ops,
Andreas Färber57fd7b72012-08-20 19:08:06 +0200210 dev, "pci-conf-idx", 0x1000);
Paolo Bonzini40c5dce2013-06-06 21:25:08 -0400211 memory_region_init_io(&h->data_mem, OBJECT(h), &pci_host_data_le_ops,
Andreas Färber57fd7b72012-08-20 19:08:06 +0200212 dev, "pci-conf-data", 0x1000);
213 sysbus_init_mmio(dev, &h->conf_mem);
214 sysbus_init_mmio(dev, &h->data_mem);
Gerd Hoffmann81a322d2009-08-14 10:36:05 +0200215 return 0;
Blue Swirl2e29bd02009-07-31 20:23:28 +0000216}
217
Avi Kivityaee97b82011-08-08 16:09:04 +0300218PCIBus *pci_pmac_init(qemu_irq *pic,
219 MemoryRegion *address_space_mem,
220 MemoryRegion *address_space_io)
Blue Swirl2e29bd02009-07-31 20:23:28 +0000221{
222 DeviceState *dev;
223 SysBusDevice *s;
Andreas Färberff452ac2012-01-19 07:40:17 +0000224 PCIHostState *h;
Blue Swirl2e29bd02009-07-31 20:23:28 +0000225 UNINState *d;
226
227 /* Use values found on a real PowerMac */
228 /* Uninorth main bus */
Andreas Färber57fd7b72012-08-20 19:08:06 +0200229 dev = qdev_create(NULL, TYPE_UNI_NORTH_PCI_HOST_BRIDGE);
Markus Armbrustere23a1b32009-10-07 01:15:58 +0200230 qdev_init_nofail(dev);
Andreas Färber57fd7b72012-08-20 19:08:06 +0200231 s = SYS_BUS_DEVICE(dev);
Andreas Färber8558d942012-08-20 19:08:08 +0200232 h = PCI_HOST_BRIDGE(s);
Andreas Färber57fd7b72012-08-20 19:08:06 +0200233 d = UNI_NORTH_PCI_HOST_BRIDGE(dev);
Paolo Bonzini40c5dce2013-06-06 21:25:08 -0400234 memory_region_init(&d->pci_mmio, OBJECT(d), "pci-mmio", 0x100000000ULL);
235 memory_region_init_alias(&d->pci_hole, OBJECT(d), "pci-hole", &d->pci_mmio,
BALATON Zoltan1be88252014-06-23 21:10:59 +0200236 0x80000000ULL, 0x10000000ULL);
Blue Swirl46f30692011-09-17 20:30:50 +0000237 memory_region_add_subregion(address_space_mem, 0x80000000ULL,
238 &d->pci_hole);
239
Alexander Graf8a0e1102013-12-04 12:42:32 +0100240 h->bus = pci_register_bus(dev, NULL,
Andreas Färber57fd7b72012-08-20 19:08:06 +0200241 pci_unin_set_irq, pci_unin_map_irq,
242 pic,
243 &d->pci_mmio,
244 address_space_io,
Alex Williamson60a0e442013-03-14 16:01:11 -0600245 PCI_DEVFN(11, 0), 4, TYPE_PCI_BUS);
Blue Swirl2e29bd02009-07-31 20:23:28 +0000246
Blue Swirl60398742009-11-15 14:30:56 +0000247#if 0
Andreas Färber57fd7b72012-08-20 19:08:06 +0200248 pci_create_simple(h->bus, PCI_DEVFN(11, 0), "uni-north");
Blue Swirl60398742009-11-15 14:30:56 +0000249#endif
Blue Swirl2e29bd02009-07-31 20:23:28 +0000250
251 sysbus_mmio_map(s, 0, 0xf2800000);
252 sysbus_mmio_map(s, 1, 0xf2c00000);
253
254 /* DEC 21154 bridge */
255#if 0
256 /* XXX: not activated as PPC BIOS doesn't handle multiple buses properly */
Andreas Färber57fd7b72012-08-20 19:08:06 +0200257 pci_create_simple(h->bus, PCI_DEVFN(12, 0), "dec-21154");
Blue Swirl2e29bd02009-07-31 20:23:28 +0000258#endif
259
260 /* Uninorth AGP bus */
Andreas Färber57fd7b72012-08-20 19:08:06 +0200261 pci_create_simple(h->bus, PCI_DEVFN(11, 0), "uni-north-agp");
262 dev = qdev_create(NULL, TYPE_UNI_NORTH_AGP_HOST_BRIDGE);
Blue Swirld27d06f2009-11-15 17:42:17 +0000263 qdev_init_nofail(dev);
Andreas Färber57fd7b72012-08-20 19:08:06 +0200264 s = SYS_BUS_DEVICE(dev);
Blue Swirld27d06f2009-11-15 17:42:17 +0000265 sysbus_mmio_map(s, 0, 0xf0800000);
266 sysbus_mmio_map(s, 1, 0xf0c00000);
Blue Swirl2e29bd02009-07-31 20:23:28 +0000267
268 /* Uninorth internal bus */
269#if 0
270 /* XXX: not needed for now */
Andreas Färber57fd7b72012-08-20 19:08:06 +0200271 pci_create_simple(h->bus, PCI_DEVFN(14, 0),
Andreas Färber70f9c982012-01-19 07:40:16 +0000272 "uni-north-internal-pci");
Andreas Färber57fd7b72012-08-20 19:08:06 +0200273 dev = qdev_create(NULL, TYPE_UNI_NORTH_INTERNAL_PCI_HOST_BRIDGE);
Blue Swirld27d06f2009-11-15 17:42:17 +0000274 qdev_init_nofail(dev);
Andreas Färber57fd7b72012-08-20 19:08:06 +0200275 s = SYS_BUS_DEVICE(dev);
Blue Swirld27d06f2009-11-15 17:42:17 +0000276 sysbus_mmio_map(s, 0, 0xf4800000);
277 sysbus_mmio_map(s, 1, 0xf4c00000);
Blue Swirl2e29bd02009-07-31 20:23:28 +0000278#endif
279
Andreas Färber57fd7b72012-08-20 19:08:06 +0200280 return h->bus;
Blue Swirl2e29bd02009-07-31 20:23:28 +0000281}
282
Avi Kivityaee97b82011-08-08 16:09:04 +0300283PCIBus *pci_pmac_u3_init(qemu_irq *pic,
284 MemoryRegion *address_space_mem,
285 MemoryRegion *address_space_io)
Alexander Graf0f921192010-02-09 17:37:02 +0100286{
287 DeviceState *dev;
288 SysBusDevice *s;
Andreas Färberff452ac2012-01-19 07:40:17 +0000289 PCIHostState *h;
Alexander Graf0f921192010-02-09 17:37:02 +0100290 UNINState *d;
291
292 /* Uninorth AGP bus */
293
Andreas Färber57fd7b72012-08-20 19:08:06 +0200294 dev = qdev_create(NULL, TYPE_U3_AGP_HOST_BRIDGE);
Alexander Graf0f921192010-02-09 17:37:02 +0100295 qdev_init_nofail(dev);
Andreas Färber57fd7b72012-08-20 19:08:06 +0200296 s = SYS_BUS_DEVICE(dev);
Andreas Färber8558d942012-08-20 19:08:08 +0200297 h = PCI_HOST_BRIDGE(dev);
Andreas Färber57fd7b72012-08-20 19:08:06 +0200298 d = U3_AGP_HOST_BRIDGE(dev);
Alexander Graf0f921192010-02-09 17:37:02 +0100299
Paolo Bonzini40c5dce2013-06-06 21:25:08 -0400300 memory_region_init(&d->pci_mmio, OBJECT(d), "pci-mmio", 0x100000000ULL);
301 memory_region_init_alias(&d->pci_hole, OBJECT(d), "pci-hole", &d->pci_mmio,
Blue Swirl46f30692011-09-17 20:30:50 +0000302 0x80000000ULL, 0x70000000ULL);
303 memory_region_add_subregion(address_space_mem, 0x80000000ULL,
304 &d->pci_hole);
305
Alexander Graf8a0e1102013-12-04 12:42:32 +0100306 h->bus = pci_register_bus(dev, NULL,
Andreas Färber57fd7b72012-08-20 19:08:06 +0200307 pci_unin_set_irq, pci_unin_map_irq,
308 pic,
309 &d->pci_mmio,
310 address_space_io,
Alex Williamson60a0e442013-03-14 16:01:11 -0600311 PCI_DEVFN(11, 0), 4, TYPE_PCI_BUS);
Alexander Graf0f921192010-02-09 17:37:02 +0100312
313 sysbus_mmio_map(s, 0, 0xf0800000);
314 sysbus_mmio_map(s, 1, 0xf0c00000);
315
Andreas Färber57fd7b72012-08-20 19:08:06 +0200316 pci_create_simple(h->bus, 11 << 3, "u3-agp");
Alexander Graf0f921192010-02-09 17:37:02 +0100317
Andreas Färber57fd7b72012-08-20 19:08:06 +0200318 return h->bus;
Alexander Graf0f921192010-02-09 17:37:02 +0100319}
320
Markus Armbruster9af21db2015-01-19 15:52:30 +0100321static void unin_main_pci_host_realize(PCIDevice *d, Error **errp)
Blue Swirl2e29bd02009-07-31 20:23:28 +0000322{
pbrook502a5392006-05-13 16:11:23 +0000323 d->config[0x0C] = 0x08; // cache_line_size
324 d->config[0x0D] = 0x10; // latency_timer
pbrook502a5392006-05-13 16:11:23 +0000325 d->config[0x34] = 0x00; // capabilities_pointer
Blue Swirl2e29bd02009-07-31 20:23:28 +0000326}
pbrook502a5392006-05-13 16:11:23 +0000327
Markus Armbruster9af21db2015-01-19 15:52:30 +0100328static void unin_agp_pci_host_realize(PCIDevice *d, Error **errp)
Blue Swirl2e29bd02009-07-31 20:23:28 +0000329{
pbrook502a5392006-05-13 16:11:23 +0000330 d->config[0x0C] = 0x08; // cache_line_size
331 d->config[0x0D] = 0x10; // latency_timer
pbrook502a5392006-05-13 16:11:23 +0000332 // d->config[0x34] = 0x80; // capabilities_pointer
Blue Swirl2e29bd02009-07-31 20:23:28 +0000333}
pbrook502a5392006-05-13 16:11:23 +0000334
Markus Armbruster9af21db2015-01-19 15:52:30 +0100335static void u3_agp_pci_host_realize(PCIDevice *d, Error **errp)
Alexander Graf0f921192010-02-09 17:37:02 +0100336{
Alexander Graf0f921192010-02-09 17:37:02 +0100337 /* cache line size */
338 d->config[0x0C] = 0x08;
339 /* latency timer */
340 d->config[0x0D] = 0x10;
Alexander Graf0f921192010-02-09 17:37:02 +0100341}
342
Markus Armbruster9af21db2015-01-19 15:52:30 +0100343static void unin_internal_pci_host_realize(PCIDevice *d, Error **errp)
Blue Swirl2e29bd02009-07-31 20:23:28 +0000344{
pbrook502a5392006-05-13 16:11:23 +0000345 d->config[0x0C] = 0x08; // cache_line_size
346 d->config[0x0D] = 0x10; // latency_timer
pbrook502a5392006-05-13 16:11:23 +0000347 d->config[0x34] = 0x00; // capabilities_pointer
pbrook502a5392006-05-13 16:11:23 +0000348}
Blue Swirl2e29bd02009-07-31 20:23:28 +0000349
Anthony Liguori40021f02011-12-04 12:22:06 -0600350static void unin_main_pci_host_class_init(ObjectClass *klass, void *data)
351{
352 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
Markus Armbruster08c58f92013-11-28 17:26:58 +0100353 DeviceClass *dc = DEVICE_CLASS(klass);
Anthony Liguori40021f02011-12-04 12:22:06 -0600354
Markus Armbruster9af21db2015-01-19 15:52:30 +0100355 k->realize = unin_main_pci_host_realize;
Anthony Liguori40021f02011-12-04 12:22:06 -0600356 k->vendor_id = PCI_VENDOR_ID_APPLE;
357 k->device_id = PCI_DEVICE_ID_APPLE_UNI_N_PCI;
358 k->revision = 0x00;
359 k->class_id = PCI_CLASS_BRIDGE_HOST;
Markus Armbruster08c58f92013-11-28 17:26:58 +0100360 /*
361 * PCI-facing part of the host bridge, not usable without the
362 * host-facing part, which can't be device_add'ed, yet.
363 */
364 dc->cannot_instantiate_with_device_add_yet = true;
Anthony Liguori40021f02011-12-04 12:22:06 -0600365}
366
Andreas Färber4240abf2012-08-20 19:07:56 +0200367static const TypeInfo unin_main_pci_host_info = {
Anthony Liguori40021f02011-12-04 12:22:06 -0600368 .name = "uni-north-pci",
Anthony Liguori39bffca2011-12-07 21:34:16 -0600369 .parent = TYPE_PCI_DEVICE,
370 .instance_size = sizeof(PCIDevice),
Anthony Liguori40021f02011-12-04 12:22:06 -0600371 .class_init = unin_main_pci_host_class_init,
Blue Swirl2e29bd02009-07-31 20:23:28 +0000372};
373
Anthony Liguori40021f02011-12-04 12:22:06 -0600374static void u3_agp_pci_host_class_init(ObjectClass *klass, void *data)
375{
376 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
Markus Armbruster08c58f92013-11-28 17:26:58 +0100377 DeviceClass *dc = DEVICE_CLASS(klass);
Anthony Liguori40021f02011-12-04 12:22:06 -0600378
Markus Armbruster9af21db2015-01-19 15:52:30 +0100379 k->realize = u3_agp_pci_host_realize;
Anthony Liguori40021f02011-12-04 12:22:06 -0600380 k->vendor_id = PCI_VENDOR_ID_APPLE;
381 k->device_id = PCI_DEVICE_ID_APPLE_U3_AGP;
382 k->revision = 0x00;
383 k->class_id = PCI_CLASS_BRIDGE_HOST;
Markus Armbruster08c58f92013-11-28 17:26:58 +0100384 /*
385 * PCI-facing part of the host bridge, not usable without the
386 * host-facing part, which can't be device_add'ed, yet.
387 */
388 dc->cannot_instantiate_with_device_add_yet = true;
Anthony Liguori40021f02011-12-04 12:22:06 -0600389}
390
Andreas Färber4240abf2012-08-20 19:07:56 +0200391static const TypeInfo u3_agp_pci_host_info = {
Anthony Liguori40021f02011-12-04 12:22:06 -0600392 .name = "u3-agp",
Anthony Liguori39bffca2011-12-07 21:34:16 -0600393 .parent = TYPE_PCI_DEVICE,
394 .instance_size = sizeof(PCIDevice),
Anthony Liguori40021f02011-12-04 12:22:06 -0600395 .class_init = u3_agp_pci_host_class_init,
Alexander Graf0f921192010-02-09 17:37:02 +0100396};
397
Anthony Liguori40021f02011-12-04 12:22:06 -0600398static void unin_agp_pci_host_class_init(ObjectClass *klass, void *data)
399{
400 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
Markus Armbruster08c58f92013-11-28 17:26:58 +0100401 DeviceClass *dc = DEVICE_CLASS(klass);
Anthony Liguori40021f02011-12-04 12:22:06 -0600402
Markus Armbruster9af21db2015-01-19 15:52:30 +0100403 k->realize = unin_agp_pci_host_realize;
Anthony Liguori40021f02011-12-04 12:22:06 -0600404 k->vendor_id = PCI_VENDOR_ID_APPLE;
405 k->device_id = PCI_DEVICE_ID_APPLE_UNI_N_AGP;
406 k->revision = 0x00;
407 k->class_id = PCI_CLASS_BRIDGE_HOST;
Markus Armbruster08c58f92013-11-28 17:26:58 +0100408 /*
409 * PCI-facing part of the host bridge, not usable without the
410 * host-facing part, which can't be device_add'ed, yet.
411 */
412 dc->cannot_instantiate_with_device_add_yet = true;
Anthony Liguori40021f02011-12-04 12:22:06 -0600413}
414
Andreas Färber4240abf2012-08-20 19:07:56 +0200415static const TypeInfo unin_agp_pci_host_info = {
Anthony Liguori40021f02011-12-04 12:22:06 -0600416 .name = "uni-north-agp",
Anthony Liguori39bffca2011-12-07 21:34:16 -0600417 .parent = TYPE_PCI_DEVICE,
418 .instance_size = sizeof(PCIDevice),
Anthony Liguori40021f02011-12-04 12:22:06 -0600419 .class_init = unin_agp_pci_host_class_init,
Blue Swirl2e29bd02009-07-31 20:23:28 +0000420};
421
Anthony Liguori40021f02011-12-04 12:22:06 -0600422static void unin_internal_pci_host_class_init(ObjectClass *klass, void *data)
423{
424 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
Markus Armbruster08c58f92013-11-28 17:26:58 +0100425 DeviceClass *dc = DEVICE_CLASS(klass);
Anthony Liguori40021f02011-12-04 12:22:06 -0600426
Markus Armbruster9af21db2015-01-19 15:52:30 +0100427 k->realize = unin_internal_pci_host_realize;
Anthony Liguori40021f02011-12-04 12:22:06 -0600428 k->vendor_id = PCI_VENDOR_ID_APPLE;
429 k->device_id = PCI_DEVICE_ID_APPLE_UNI_N_I_PCI;
430 k->revision = 0x00;
431 k->class_id = PCI_CLASS_BRIDGE_HOST;
Markus Armbruster08c58f92013-11-28 17:26:58 +0100432 /*
433 * PCI-facing part of the host bridge, not usable without the
434 * host-facing part, which can't be device_add'ed, yet.
435 */
436 dc->cannot_instantiate_with_device_add_yet = true;
Anthony Liguori40021f02011-12-04 12:22:06 -0600437}
438
Andreas Färber4240abf2012-08-20 19:07:56 +0200439static const TypeInfo unin_internal_pci_host_info = {
Anthony Liguori40021f02011-12-04 12:22:06 -0600440 .name = "uni-north-internal-pci",
Anthony Liguori39bffca2011-12-07 21:34:16 -0600441 .parent = TYPE_PCI_DEVICE,
442 .instance_size = sizeof(PCIDevice),
Anthony Liguori40021f02011-12-04 12:22:06 -0600443 .class_init = unin_internal_pci_host_class_init,
Blue Swirl2e29bd02009-07-31 20:23:28 +0000444};
445
Anthony Liguori999e12b2012-01-24 13:12:29 -0600446static void pci_unin_main_class_init(ObjectClass *klass, void *data)
447{
448 SysBusDeviceClass *sbc = SYS_BUS_DEVICE_CLASS(klass);
Laurent Vivier1d16f862015-09-26 18:22:09 +0200449 DeviceClass *dc = DEVICE_CLASS(klass);
Anthony Liguori999e12b2012-01-24 13:12:29 -0600450
451 sbc->init = pci_unin_main_init_device;
Laurent Vivier1d16f862015-09-26 18:22:09 +0200452 set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
Anthony Liguori999e12b2012-01-24 13:12:29 -0600453}
454
Andreas Färber4240abf2012-08-20 19:07:56 +0200455static const TypeInfo pci_unin_main_info = {
Andreas Färber57fd7b72012-08-20 19:08:06 +0200456 .name = TYPE_UNI_NORTH_PCI_HOST_BRIDGE,
Andreas Färber8558d942012-08-20 19:08:08 +0200457 .parent = TYPE_PCI_HOST_BRIDGE,
Anthony Liguori39bffca2011-12-07 21:34:16 -0600458 .instance_size = sizeof(UNINState),
459 .class_init = pci_unin_main_class_init,
Andreas Färber70f9c982012-01-19 07:40:16 +0000460};
461
Anthony Liguori999e12b2012-01-24 13:12:29 -0600462static void pci_u3_agp_class_init(ObjectClass *klass, void *data)
463{
464 SysBusDeviceClass *sbc = SYS_BUS_DEVICE_CLASS(klass);
Laurent Vivier1d16f862015-09-26 18:22:09 +0200465 DeviceClass *dc = DEVICE_CLASS(klass);
Anthony Liguori999e12b2012-01-24 13:12:29 -0600466
467 sbc->init = pci_u3_agp_init_device;
Laurent Vivier1d16f862015-09-26 18:22:09 +0200468 set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
Anthony Liguori999e12b2012-01-24 13:12:29 -0600469}
470
Andreas Färber4240abf2012-08-20 19:07:56 +0200471static const TypeInfo pci_u3_agp_info = {
Andreas Färber57fd7b72012-08-20 19:08:06 +0200472 .name = TYPE_U3_AGP_HOST_BRIDGE,
Andreas Färber8558d942012-08-20 19:08:08 +0200473 .parent = TYPE_PCI_HOST_BRIDGE,
Anthony Liguori39bffca2011-12-07 21:34:16 -0600474 .instance_size = sizeof(UNINState),
475 .class_init = pci_u3_agp_class_init,
Andreas Färber70f9c982012-01-19 07:40:16 +0000476};
477
Anthony Liguori999e12b2012-01-24 13:12:29 -0600478static void pci_unin_agp_class_init(ObjectClass *klass, void *data)
479{
480 SysBusDeviceClass *sbc = SYS_BUS_DEVICE_CLASS(klass);
Laurent Vivier1d16f862015-09-26 18:22:09 +0200481 DeviceClass *dc = DEVICE_CLASS(klass);
Anthony Liguori999e12b2012-01-24 13:12:29 -0600482
483 sbc->init = pci_unin_agp_init_device;
Laurent Vivier1d16f862015-09-26 18:22:09 +0200484 set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
Anthony Liguori999e12b2012-01-24 13:12:29 -0600485}
486
Andreas Färber4240abf2012-08-20 19:07:56 +0200487static const TypeInfo pci_unin_agp_info = {
Andreas Färber57fd7b72012-08-20 19:08:06 +0200488 .name = TYPE_UNI_NORTH_AGP_HOST_BRIDGE,
Andreas Färber8558d942012-08-20 19:08:08 +0200489 .parent = TYPE_PCI_HOST_BRIDGE,
Anthony Liguori39bffca2011-12-07 21:34:16 -0600490 .instance_size = sizeof(UNINState),
491 .class_init = pci_unin_agp_class_init,
Andreas Färber70f9c982012-01-19 07:40:16 +0000492};
493
Anthony Liguori999e12b2012-01-24 13:12:29 -0600494static void pci_unin_internal_class_init(ObjectClass *klass, void *data)
495{
496 SysBusDeviceClass *sbc = SYS_BUS_DEVICE_CLASS(klass);
Laurent Vivier1d16f862015-09-26 18:22:09 +0200497 DeviceClass *dc = DEVICE_CLASS(klass);
Anthony Liguori999e12b2012-01-24 13:12:29 -0600498
499 sbc->init = pci_unin_internal_init_device;
Laurent Vivier1d16f862015-09-26 18:22:09 +0200500 set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
Anthony Liguori999e12b2012-01-24 13:12:29 -0600501}
502
Andreas Färber4240abf2012-08-20 19:07:56 +0200503static const TypeInfo pci_unin_internal_info = {
Andreas Färber57fd7b72012-08-20 19:08:06 +0200504 .name = TYPE_UNI_NORTH_INTERNAL_PCI_HOST_BRIDGE,
Andreas Färber8558d942012-08-20 19:08:08 +0200505 .parent = TYPE_PCI_HOST_BRIDGE,
Anthony Liguori39bffca2011-12-07 21:34:16 -0600506 .instance_size = sizeof(UNINState),
507 .class_init = pci_unin_internal_class_init,
Andreas Färber70f9c982012-01-19 07:40:16 +0000508};
509
Andreas Färber83f7d432012-02-09 15:20:55 +0100510static void unin_register_types(void)
Blue Swirl2e29bd02009-07-31 20:23:28 +0000511{
Anthony Liguori39bffca2011-12-07 21:34:16 -0600512 type_register_static(&unin_main_pci_host_info);
513 type_register_static(&u3_agp_pci_host_info);
514 type_register_static(&unin_agp_pci_host_info);
515 type_register_static(&unin_internal_pci_host_info);
Anthony Liguori999e12b2012-01-24 13:12:29 -0600516
Anthony Liguori39bffca2011-12-07 21:34:16 -0600517 type_register_static(&pci_unin_main_info);
518 type_register_static(&pci_u3_agp_info);
519 type_register_static(&pci_unin_agp_info);
520 type_register_static(&pci_unin_internal_info);
Blue Swirl2e29bd02009-07-31 20:23:28 +0000521}
522
Andreas Färber83f7d432012-02-09 15:20:55 +0100523type_init(unin_register_types)