2 * QEMU Uninorth PCI host (for all Mac99 and newer machines)
4 * Copyright (c) 2006 Fabrice Bellard
6 * 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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
25 #include "qemu/osdep.h"
27 #include "hw/qdev-properties.h"
28 #include "qemu/module.h"
29 #include "hw/pci/pci.h"
30 #include "hw/pci/pci_host.h"
31 #include "hw/pci-host/uninorth.h"
34 static int pci_unin_map_irq(PCIDevice
*pci_dev
, int irq_num
)
36 return (irq_num
+ (pci_dev
->devfn
>> 3)) & 3;
39 static void pci_unin_set_irq(void *opaque
, int irq_num
, int level
)
41 UNINHostState
*s
= opaque
;
43 trace_unin_set_irq(irq_num
, level
);
44 qemu_set_irq(s
->irqs
[irq_num
], level
);
47 static uint32_t unin_get_config_reg(uint32_t reg
, uint32_t addr
)
51 if (reg
& (1u << 31)) {
52 /* XXX OpenBIOS compatibility hack */
53 retval
= reg
| (addr
& 3);
56 retval
= (reg
& ~7u) | (addr
& 7);
60 /* Grab CFA0 style values */
61 slot
= ctz32(reg
& 0xfffff800);
63 slot
= -1; /* XXX: should this be 0? */
65 func
= PCI_FUNC(reg
>> 8);
67 /* ... and then convert them to x86 format */
69 retval
= (reg
& (0xff - 7)) | (addr
& 7);
71 retval
|= PCI_DEVFN(slot
, func
) << 8;
74 trace_unin_get_config_reg(reg
, addr
, retval
);
79 static void unin_data_write(void *opaque
, hwaddr addr
,
80 uint64_t val
, unsigned len
)
82 UNINHostState
*s
= opaque
;
83 PCIHostState
*phb
= PCI_HOST_BRIDGE(s
);
84 trace_unin_data_write(addr
, len
, val
);
85 pci_data_write(phb
->bus
,
86 unin_get_config_reg(phb
->config_reg
, addr
),
90 static uint64_t unin_data_read(void *opaque
, hwaddr addr
,
93 UNINHostState
*s
= opaque
;
94 PCIHostState
*phb
= PCI_HOST_BRIDGE(s
);
97 val
= pci_data_read(phb
->bus
,
98 unin_get_config_reg(phb
->config_reg
, addr
),
100 trace_unin_data_read(addr
, len
, val
);
104 static const MemoryRegionOps unin_data_ops
= {
105 .read
= unin_data_read
,
106 .write
= unin_data_write
,
107 .endianness
= DEVICE_LITTLE_ENDIAN
,
110 static char *pci_unin_main_ofw_unit_address(const SysBusDevice
*dev
)
112 UNINHostState
*s
= UNI_NORTH_PCI_HOST_BRIDGE(dev
);
114 return g_strdup_printf("%x", s
->ofw_addr
);
117 static void pci_unin_main_realize(DeviceState
*dev
, Error
**errp
)
119 UNINHostState
*s
= UNI_NORTH_PCI_HOST_BRIDGE(dev
);
120 PCIHostState
*h
= PCI_HOST_BRIDGE(dev
);
122 h
->bus
= pci_register_root_bus(dev
, NULL
,
123 pci_unin_set_irq
, pci_unin_map_irq
,
127 PCI_DEVFN(11, 0), 4, TYPE_PCI_BUS
);
129 pci_create_simple(h
->bus
, PCI_DEVFN(11, 0), "uni-north-pci");
131 /* DEC 21154 bridge */
133 /* XXX: not activated as PPC BIOS doesn't handle multiple buses properly */
134 pci_create_simple(h
->bus
, PCI_DEVFN(12, 0), "dec-21154");
138 static void pci_unin_main_init(Object
*obj
)
140 UNINHostState
*s
= UNI_NORTH_PCI_HOST_BRIDGE(obj
);
141 SysBusDevice
*sbd
= SYS_BUS_DEVICE(obj
);
142 PCIHostState
*h
= PCI_HOST_BRIDGE(obj
);
144 /* Use values found on a real PowerMac */
145 /* Uninorth main bus */
146 memory_region_init_io(&h
->conf_mem
, OBJECT(h
), &pci_host_conf_le_ops
,
147 obj
, "unin-pci-conf-idx", 0x1000);
148 memory_region_init_io(&h
->data_mem
, OBJECT(h
), &unin_data_ops
, obj
,
149 "unin-pci-conf-data", 0x1000);
151 memory_region_init(&s
->pci_mmio
, OBJECT(s
), "unin-pci-mmio",
153 memory_region_init_io(&s
->pci_io
, OBJECT(s
), &unassigned_io_ops
, obj
,
154 "unin-pci-isa-mmio", 0x00800000);
156 memory_region_init_alias(&s
->pci_hole
, OBJECT(s
),
157 "unin-pci-hole", &s
->pci_mmio
,
158 0x80000000ULL
, 0x10000000ULL
);
160 sysbus_init_mmio(sbd
, &h
->conf_mem
);
161 sysbus_init_mmio(sbd
, &h
->data_mem
);
162 sysbus_init_mmio(sbd
, &s
->pci_hole
);
163 sysbus_init_mmio(sbd
, &s
->pci_io
);
165 qdev_init_gpio_out(DEVICE(obj
), s
->irqs
, ARRAY_SIZE(s
->irqs
));
168 static void pci_u3_agp_realize(DeviceState
*dev
, Error
**errp
)
170 UNINHostState
*s
= U3_AGP_HOST_BRIDGE(dev
);
171 PCIHostState
*h
= PCI_HOST_BRIDGE(dev
);
173 h
->bus
= pci_register_root_bus(dev
, NULL
,
174 pci_unin_set_irq
, pci_unin_map_irq
,
178 PCI_DEVFN(11, 0), 4, TYPE_PCI_BUS
);
180 pci_create_simple(h
->bus
, PCI_DEVFN(11, 0), "u3-agp");
183 static void pci_u3_agp_init(Object
*obj
)
185 UNINHostState
*s
= U3_AGP_HOST_BRIDGE(obj
);
186 SysBusDevice
*sbd
= SYS_BUS_DEVICE(obj
);
187 PCIHostState
*h
= PCI_HOST_BRIDGE(obj
);
189 /* Uninorth U3 AGP bus */
190 memory_region_init_io(&h
->conf_mem
, OBJECT(h
), &pci_host_conf_le_ops
,
191 obj
, "unin-pci-conf-idx", 0x1000);
192 memory_region_init_io(&h
->data_mem
, OBJECT(h
), &unin_data_ops
, obj
,
193 "unin-pci-conf-data", 0x1000);
195 memory_region_init(&s
->pci_mmio
, OBJECT(s
), "unin-pci-mmio",
197 memory_region_init_io(&s
->pci_io
, OBJECT(s
), &unassigned_io_ops
, obj
,
198 "unin-pci-isa-mmio", 0x00800000);
200 memory_region_init_alias(&s
->pci_hole
, OBJECT(s
),
201 "unin-pci-hole", &s
->pci_mmio
,
202 0x80000000ULL
, 0x70000000ULL
);
204 sysbus_init_mmio(sbd
, &h
->conf_mem
);
205 sysbus_init_mmio(sbd
, &h
->data_mem
);
206 sysbus_init_mmio(sbd
, &s
->pci_hole
);
207 sysbus_init_mmio(sbd
, &s
->pci_io
);
209 qdev_init_gpio_out(DEVICE(obj
), s
->irqs
, ARRAY_SIZE(s
->irqs
));
212 static void pci_unin_agp_realize(DeviceState
*dev
, Error
**errp
)
214 UNINHostState
*s
= UNI_NORTH_AGP_HOST_BRIDGE(dev
);
215 PCIHostState
*h
= PCI_HOST_BRIDGE(dev
);
217 h
->bus
= pci_register_root_bus(dev
, NULL
,
218 pci_unin_set_irq
, pci_unin_map_irq
,
222 PCI_DEVFN(11, 0), 4, TYPE_PCI_BUS
);
224 pci_create_simple(h
->bus
, PCI_DEVFN(11, 0), "uni-north-agp");
227 static void pci_unin_agp_init(Object
*obj
)
229 UNINHostState
*s
= UNI_NORTH_AGP_HOST_BRIDGE(obj
);
230 SysBusDevice
*sbd
= SYS_BUS_DEVICE(obj
);
231 PCIHostState
*h
= PCI_HOST_BRIDGE(obj
);
233 /* Uninorth AGP bus */
234 memory_region_init_io(&h
->conf_mem
, OBJECT(h
), &pci_host_conf_le_ops
,
235 obj
, "unin-agp-conf-idx", 0x1000);
236 memory_region_init_io(&h
->data_mem
, OBJECT(h
), &pci_host_data_le_ops
,
237 obj
, "unin-agp-conf-data", 0x1000);
239 sysbus_init_mmio(sbd
, &h
->conf_mem
);
240 sysbus_init_mmio(sbd
, &h
->data_mem
);
242 qdev_init_gpio_out(DEVICE(obj
), s
->irqs
, ARRAY_SIZE(s
->irqs
));
245 static void pci_unin_internal_realize(DeviceState
*dev
, Error
**errp
)
247 UNINHostState
*s
= UNI_NORTH_INTERNAL_PCI_HOST_BRIDGE(dev
);
248 PCIHostState
*h
= PCI_HOST_BRIDGE(dev
);
250 h
->bus
= pci_register_root_bus(dev
, NULL
,
251 pci_unin_set_irq
, pci_unin_map_irq
,
255 PCI_DEVFN(14, 0), 4, TYPE_PCI_BUS
);
257 pci_create_simple(h
->bus
, PCI_DEVFN(14, 0), "uni-north-internal-pci");
260 static void pci_unin_internal_init(Object
*obj
)
262 UNINHostState
*s
= UNI_NORTH_INTERNAL_PCI_HOST_BRIDGE(obj
);
263 SysBusDevice
*sbd
= SYS_BUS_DEVICE(obj
);
264 PCIHostState
*h
= PCI_HOST_BRIDGE(obj
);
266 /* Uninorth internal bus */
267 memory_region_init_io(&h
->conf_mem
, OBJECT(h
), &pci_host_conf_le_ops
,
268 obj
, "unin-pci-conf-idx", 0x1000);
269 memory_region_init_io(&h
->data_mem
, OBJECT(h
), &pci_host_data_le_ops
,
270 obj
, "unin-pci-conf-data", 0x1000);
272 sysbus_init_mmio(sbd
, &h
->conf_mem
);
273 sysbus_init_mmio(sbd
, &h
->data_mem
);
275 qdev_init_gpio_out(DEVICE(obj
), s
->irqs
, ARRAY_SIZE(s
->irqs
));
278 static void unin_main_pci_host_realize(PCIDevice
*d
, Error
**errp
)
280 /* cache_line_size */
281 d
->config
[0x0C] = 0x08;
283 d
->config
[0x0D] = 0x10;
284 /* capabilities_pointer */
285 d
->config
[0x34] = 0x00;
288 * Set kMacRISCPCIAddressSelect (0x48) register to indicate PCI
289 * memory space with base 0x80000000, size 0x10000000 for Apple's
290 * AppleMacRiscPCI driver
292 d
->config
[0x48] = 0x0;
293 d
->config
[0x49] = 0x0;
294 d
->config
[0x4a] = 0x0;
295 d
->config
[0x4b] = 0x1;
298 static void unin_agp_pci_host_realize(PCIDevice
*d
, Error
**errp
)
300 /* cache_line_size */
301 d
->config
[0x0C] = 0x08;
303 d
->config
[0x0D] = 0x10;
304 /* capabilities_pointer
305 d->config[0x34] = 0x80; */
308 static void u3_agp_pci_host_realize(PCIDevice
*d
, Error
**errp
)
310 /* cache line size */
311 d
->config
[0x0C] = 0x08;
313 d
->config
[0x0D] = 0x10;
316 static void unin_internal_pci_host_realize(PCIDevice
*d
, Error
**errp
)
318 /* cache_line_size */
319 d
->config
[0x0C] = 0x08;
321 d
->config
[0x0D] = 0x10;
322 /* capabilities_pointer */
323 d
->config
[0x34] = 0x00;
326 static void unin_main_pci_host_class_init(ObjectClass
*klass
, void *data
)
328 PCIDeviceClass
*k
= PCI_DEVICE_CLASS(klass
);
329 DeviceClass
*dc
= DEVICE_CLASS(klass
);
331 k
->realize
= unin_main_pci_host_realize
;
332 k
->vendor_id
= PCI_VENDOR_ID_APPLE
;
333 k
->device_id
= PCI_DEVICE_ID_APPLE_UNI_N_PCI
;
335 k
->class_id
= PCI_CLASS_BRIDGE_HOST
;
337 * PCI-facing part of the host bridge, not usable without the
338 * host-facing part, which can't be device_add'ed, yet.
340 dc
->user_creatable
= false;
343 static const TypeInfo unin_main_pci_host_info
= {
344 .name
= "uni-north-pci",
345 .parent
= TYPE_PCI_DEVICE
,
346 .instance_size
= sizeof(PCIDevice
),
347 .class_init
= unin_main_pci_host_class_init
,
348 .interfaces
= (InterfaceInfo
[]) {
349 { INTERFACE_CONVENTIONAL_PCI_DEVICE
},
354 static void u3_agp_pci_host_class_init(ObjectClass
*klass
, void *data
)
356 PCIDeviceClass
*k
= PCI_DEVICE_CLASS(klass
);
357 DeviceClass
*dc
= DEVICE_CLASS(klass
);
359 k
->realize
= u3_agp_pci_host_realize
;
360 k
->vendor_id
= PCI_VENDOR_ID_APPLE
;
361 k
->device_id
= PCI_DEVICE_ID_APPLE_U3_AGP
;
363 k
->class_id
= PCI_CLASS_BRIDGE_HOST
;
365 * PCI-facing part of the host bridge, not usable without the
366 * host-facing part, which can't be device_add'ed, yet.
368 dc
->user_creatable
= false;
371 static const TypeInfo u3_agp_pci_host_info
= {
373 .parent
= TYPE_PCI_DEVICE
,
374 .instance_size
= sizeof(PCIDevice
),
375 .class_init
= u3_agp_pci_host_class_init
,
376 .interfaces
= (InterfaceInfo
[]) {
377 { INTERFACE_CONVENTIONAL_PCI_DEVICE
},
382 static void unin_agp_pci_host_class_init(ObjectClass
*klass
, void *data
)
384 PCIDeviceClass
*k
= PCI_DEVICE_CLASS(klass
);
385 DeviceClass
*dc
= DEVICE_CLASS(klass
);
387 k
->realize
= unin_agp_pci_host_realize
;
388 k
->vendor_id
= PCI_VENDOR_ID_APPLE
;
389 k
->device_id
= PCI_DEVICE_ID_APPLE_UNI_N_AGP
;
391 k
->class_id
= PCI_CLASS_BRIDGE_HOST
;
393 * PCI-facing part of the host bridge, not usable without the
394 * host-facing part, which can't be device_add'ed, yet.
396 dc
->user_creatable
= false;
399 static const TypeInfo unin_agp_pci_host_info
= {
400 .name
= "uni-north-agp",
401 .parent
= TYPE_PCI_DEVICE
,
402 .instance_size
= sizeof(PCIDevice
),
403 .class_init
= unin_agp_pci_host_class_init
,
404 .interfaces
= (InterfaceInfo
[]) {
405 { INTERFACE_CONVENTIONAL_PCI_DEVICE
},
410 static void unin_internal_pci_host_class_init(ObjectClass
*klass
, void *data
)
412 PCIDeviceClass
*k
= PCI_DEVICE_CLASS(klass
);
413 DeviceClass
*dc
= DEVICE_CLASS(klass
);
415 k
->realize
= unin_internal_pci_host_realize
;
416 k
->vendor_id
= PCI_VENDOR_ID_APPLE
;
417 k
->device_id
= PCI_DEVICE_ID_APPLE_UNI_N_I_PCI
;
419 k
->class_id
= PCI_CLASS_BRIDGE_HOST
;
421 * PCI-facing part of the host bridge, not usable without the
422 * host-facing part, which can't be device_add'ed, yet.
424 dc
->user_creatable
= false;
427 static const TypeInfo unin_internal_pci_host_info
= {
428 .name
= "uni-north-internal-pci",
429 .parent
= TYPE_PCI_DEVICE
,
430 .instance_size
= sizeof(PCIDevice
),
431 .class_init
= unin_internal_pci_host_class_init
,
432 .interfaces
= (InterfaceInfo
[]) {
433 { INTERFACE_CONVENTIONAL_PCI_DEVICE
},
438 static Property pci_unin_main_pci_host_props
[] = {
439 DEFINE_PROP_UINT32("ofw-addr", UNINHostState
, ofw_addr
, -1),
440 DEFINE_PROP_END_OF_LIST()
443 static void pci_unin_main_class_init(ObjectClass
*klass
, void *data
)
445 DeviceClass
*dc
= DEVICE_CLASS(klass
);
446 SysBusDeviceClass
*sbc
= SYS_BUS_DEVICE_CLASS(klass
);
448 dc
->realize
= pci_unin_main_realize
;
449 device_class_set_props(dc
, pci_unin_main_pci_host_props
);
450 set_bit(DEVICE_CATEGORY_BRIDGE
, dc
->categories
);
452 sbc
->explicit_ofw_unit_address
= pci_unin_main_ofw_unit_address
;
455 static const TypeInfo pci_unin_main_info
= {
456 .name
= TYPE_UNI_NORTH_PCI_HOST_BRIDGE
,
457 .parent
= TYPE_PCI_HOST_BRIDGE
,
458 .instance_size
= sizeof(UNINHostState
),
459 .instance_init
= pci_unin_main_init
,
460 .class_init
= pci_unin_main_class_init
,
463 static void pci_u3_agp_class_init(ObjectClass
*klass
, void *data
)
465 DeviceClass
*dc
= DEVICE_CLASS(klass
);
467 dc
->realize
= pci_u3_agp_realize
;
468 set_bit(DEVICE_CATEGORY_BRIDGE
, dc
->categories
);
471 static const TypeInfo pci_u3_agp_info
= {
472 .name
= TYPE_U3_AGP_HOST_BRIDGE
,
473 .parent
= TYPE_PCI_HOST_BRIDGE
,
474 .instance_size
= sizeof(UNINHostState
),
475 .instance_init
= pci_u3_agp_init
,
476 .class_init
= pci_u3_agp_class_init
,
479 static void pci_unin_agp_class_init(ObjectClass
*klass
, void *data
)
481 DeviceClass
*dc
= DEVICE_CLASS(klass
);
483 dc
->realize
= pci_unin_agp_realize
;
484 set_bit(DEVICE_CATEGORY_BRIDGE
, dc
->categories
);
487 static const TypeInfo pci_unin_agp_info
= {
488 .name
= TYPE_UNI_NORTH_AGP_HOST_BRIDGE
,
489 .parent
= TYPE_PCI_HOST_BRIDGE
,
490 .instance_size
= sizeof(UNINHostState
),
491 .instance_init
= pci_unin_agp_init
,
492 .class_init
= pci_unin_agp_class_init
,
495 static void pci_unin_internal_class_init(ObjectClass
*klass
, void *data
)
497 DeviceClass
*dc
= DEVICE_CLASS(klass
);
499 dc
->realize
= pci_unin_internal_realize
;
500 set_bit(DEVICE_CATEGORY_BRIDGE
, dc
->categories
);
503 static const TypeInfo pci_unin_internal_info
= {
504 .name
= TYPE_UNI_NORTH_INTERNAL_PCI_HOST_BRIDGE
,
505 .parent
= TYPE_PCI_HOST_BRIDGE
,
506 .instance_size
= sizeof(UNINHostState
),
507 .instance_init
= pci_unin_internal_init
,
508 .class_init
= pci_unin_internal_class_init
,
512 static void unin_write(void *opaque
, hwaddr addr
, uint64_t value
,
515 trace_unin_write(addr
, value
);
518 static uint64_t unin_read(void *opaque
, hwaddr addr
, unsigned size
)
524 value
= UNINORTH_VERSION_10A
;
530 trace_unin_read(addr
, value
);
535 static const MemoryRegionOps unin_ops
= {
538 .endianness
= DEVICE_BIG_ENDIAN
,
541 static void unin_init(Object
*obj
)
543 UNINState
*s
= UNI_NORTH(obj
);
544 SysBusDevice
*sbd
= SYS_BUS_DEVICE(obj
);
546 memory_region_init_io(&s
->mem
, obj
, &unin_ops
, s
, "unin", 0x1000);
548 sysbus_init_mmio(sbd
, &s
->mem
);
551 static void unin_class_init(ObjectClass
*klass
, void *data
)
553 DeviceClass
*dc
= DEVICE_CLASS(klass
);
555 set_bit(DEVICE_CATEGORY_BRIDGE
, dc
->categories
);
558 static const TypeInfo unin_info
= {
559 .name
= TYPE_UNI_NORTH
,
560 .parent
= TYPE_SYS_BUS_DEVICE
,
561 .instance_size
= sizeof(UNINState
),
562 .instance_init
= unin_init
,
563 .class_init
= unin_class_init
,
566 static void unin_register_types(void)
568 type_register_static(&unin_main_pci_host_info
);
569 type_register_static(&u3_agp_pci_host_info
);
570 type_register_static(&unin_agp_pci_host_info
);
571 type_register_static(&unin_internal_pci_host_info
);
573 type_register_static(&pci_unin_main_info
);
574 type_register_static(&pci_u3_agp_info
);
575 type_register_static(&pci_unin_agp_info
);
576 type_register_static(&pci_unin_internal_info
);
578 type_register_static(&unin_info
);
581 type_init(unin_register_types
)