root / hw / grackle_pci.c @ 0ed8b6f6
History | View | Annotate | Download (5.2 kB)
1 | 502a5395 | pbrook | /*
|
---|---|---|---|
2 | 3cbee15b | j_mayer | * QEMU Grackle PCI host (heathrow OldWorld PowerMac)
|
3 | 502a5395 | pbrook | *
|
4 | 3cbee15b | j_mayer | * Copyright (c) 2006-2007 Fabrice Bellard
|
5 | 3cbee15b | j_mayer | * Copyright (c) 2007 Jocelyn Mayer
|
6 | 5fafdf24 | ths | *
|
7 | 502a5395 | pbrook | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
8 | 502a5395 | pbrook | * of this software and associated documentation files (the "Software"), to deal
|
9 | 502a5395 | pbrook | * in the Software without restriction, including without limitation the rights
|
10 | 502a5395 | pbrook | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 | 502a5395 | pbrook | * copies of the Software, and to permit persons to whom the Software is
|
12 | 502a5395 | pbrook | * furnished to do so, subject to the following conditions:
|
13 | 502a5395 | pbrook | *
|
14 | 502a5395 | pbrook | * The above copyright notice and this permission notice shall be included in
|
15 | 502a5395 | pbrook | * all copies or substantial portions of the Software.
|
16 | 502a5395 | pbrook | *
|
17 | 502a5395 | pbrook | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18 | 502a5395 | pbrook | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19 | 502a5395 | pbrook | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
20 | 502a5395 | pbrook | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21 | 502a5395 | pbrook | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22 | 502a5395 | pbrook | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
23 | 502a5395 | pbrook | * THE SOFTWARE.
|
24 | 502a5395 | pbrook | */
|
25 | 502a5395 | pbrook | |
26 | 426f17bb | Blue Swirl | #include "sysbus.h" |
27 | 3cbee15b | j_mayer | #include "ppc_mac.h" |
28 | 87ecb68b | pbrook | #include "pci.h" |
29 | 4f5e19e6 | Isaku Yamahata | #include "pci_host.h" |
30 | 87ecb68b | pbrook | |
31 | ea026b2f | blueswir1 | /* debug Grackle */
|
32 | ea026b2f | blueswir1 | //#define DEBUG_GRACKLE
|
33 | ea026b2f | blueswir1 | |
34 | ea026b2f | blueswir1 | #ifdef DEBUG_GRACKLE
|
35 | 001faf32 | Blue Swirl | #define GRACKLE_DPRINTF(fmt, ...) \
|
36 | 001faf32 | Blue Swirl | do { printf("GRACKLE: " fmt , ## __VA_ARGS__); } while (0) |
37 | ea026b2f | blueswir1 | #else
|
38 | 001faf32 | Blue Swirl | #define GRACKLE_DPRINTF(fmt, ...)
|
39 | ea026b2f | blueswir1 | #endif
|
40 | ea026b2f | blueswir1 | |
41 | 426f17bb | Blue Swirl | typedef struct GrackleState { |
42 | 426f17bb | Blue Swirl | SysBusDevice busdev; |
43 | 426f17bb | Blue Swirl | PCIHostState host_state; |
44 | 46f3069c | Blue Swirl | MemoryRegion pci_mmio; |
45 | 46f3069c | Blue Swirl | MemoryRegion pci_hole; |
46 | 426f17bb | Blue Swirl | } GrackleState; |
47 | 502a5395 | pbrook | |
48 | d2b59317 | pbrook | /* Don't know if this matches real hardware, but it agrees with OHW. */
|
49 | d2b59317 | pbrook | static int pci_grackle_map_irq(PCIDevice *pci_dev, int irq_num) |
50 | 502a5395 | pbrook | { |
51 | d2b59317 | pbrook | return (irq_num + (pci_dev->devfn >> 3)) & 3; |
52 | d2b59317 | pbrook | } |
53 | d2b59317 | pbrook | |
54 | 5d4e84c8 | Juan Quintela | static void pci_grackle_set_irq(void *opaque, int irq_num, int level) |
55 | d2b59317 | pbrook | { |
56 | 5d4e84c8 | Juan Quintela | qemu_irq *pic = opaque; |
57 | 5d4e84c8 | Juan Quintela | |
58 | ea026b2f | blueswir1 | GRACKLE_DPRINTF("set_irq num %d level %d\n", irq_num, level);
|
59 | 3cbee15b | j_mayer | qemu_set_irq(pic[irq_num + 0x15], level);
|
60 | 502a5395 | pbrook | } |
61 | 502a5395 | pbrook | |
62 | 6e6b7363 | blueswir1 | static void pci_grackle_reset(void *opaque) |
63 | 6e6b7363 | blueswir1 | { |
64 | 6e6b7363 | blueswir1 | } |
65 | 6e6b7363 | blueswir1 | |
66 | 1e39101c | Avi Kivity | PCIBus *pci_grackle_init(uint32_t base, qemu_irq *pic, |
67 | aee97b84 | Avi Kivity | MemoryRegion *address_space_mem, |
68 | aee97b84 | Avi Kivity | MemoryRegion *address_space_io) |
69 | 502a5395 | pbrook | { |
70 | 426f17bb | Blue Swirl | DeviceState *dev; |
71 | 426f17bb | Blue Swirl | SysBusDevice *s; |
72 | 426f17bb | Blue Swirl | GrackleState *d; |
73 | 426f17bb | Blue Swirl | |
74 | 0ae46996 | Andreas Färber | dev = qdev_create(NULL, "grackle-pcihost"); |
75 | e23a1b33 | Markus Armbruster | qdev_init_nofail(dev); |
76 | 426f17bb | Blue Swirl | s = sysbus_from_qdev(dev); |
77 | 426f17bb | Blue Swirl | d = FROM_SYSBUS(GrackleState, s); |
78 | 46f3069c | Blue Swirl | |
79 | 46f3069c | Blue Swirl | memory_region_init(&d->pci_mmio, "pci-mmio", 0x100000000ULL); |
80 | 46f3069c | Blue Swirl | memory_region_init_alias(&d->pci_hole, "pci-hole", &d->pci_mmio,
|
81 | 46f3069c | Blue Swirl | 0x80000000ULL, 0x7e000000ULL); |
82 | 46f3069c | Blue Swirl | memory_region_add_subregion(address_space_mem, 0x80000000ULL,
|
83 | 46f3069c | Blue Swirl | &d->pci_hole); |
84 | 46f3069c | Blue Swirl | |
85 | cdd0935c | Blue Swirl | d->host_state.bus = pci_register_bus(&d->busdev.qdev, "pci",
|
86 | 426f17bb | Blue Swirl | pci_grackle_set_irq, |
87 | 426f17bb | Blue Swirl | pci_grackle_map_irq, |
88 | aee97b84 | Avi Kivity | pic, |
89 | 46f3069c | Blue Swirl | &d->pci_mmio, |
90 | aee97b84 | Avi Kivity | address_space_io, |
91 | aee97b84 | Avi Kivity | 0, 4); |
92 | 426f17bb | Blue Swirl | |
93 | 426f17bb | Blue Swirl | pci_create_simple(d->host_state.bus, 0, "grackle"); |
94 | 426f17bb | Blue Swirl | |
95 | 426f17bb | Blue Swirl | sysbus_mmio_map(s, 0, base);
|
96 | 426f17bb | Blue Swirl | sysbus_mmio_map(s, 1, base + 0x00200000); |
97 | 426f17bb | Blue Swirl | |
98 | 426f17bb | Blue Swirl | return d->host_state.bus;
|
99 | 426f17bb | Blue Swirl | } |
100 | 426f17bb | Blue Swirl | |
101 | 81a322d4 | Gerd Hoffmann | static int pci_grackle_init_device(SysBusDevice *dev) |
102 | 426f17bb | Blue Swirl | { |
103 | 426f17bb | Blue Swirl | GrackleState *s; |
104 | 426f17bb | Blue Swirl | |
105 | 426f17bb | Blue Swirl | s = FROM_SYSBUS(GrackleState, dev); |
106 | 426f17bb | Blue Swirl | |
107 | d0ed8076 | Avi Kivity | memory_region_init_io(&s->host_state.conf_mem, &pci_host_conf_le_ops, |
108 | d0ed8076 | Avi Kivity | &s->host_state, "pci-conf-idx", 0x1000); |
109 | d0ed8076 | Avi Kivity | memory_region_init_io(&s->host_state.data_mem, &pci_host_data_le_ops, |
110 | d0ed8076 | Avi Kivity | &s->host_state, "pci-data-idx", 0x1000); |
111 | 750ecd44 | Avi Kivity | sysbus_init_mmio(dev, &s->host_state.conf_mem); |
112 | 750ecd44 | Avi Kivity | sysbus_init_mmio(dev, &s->host_state.data_mem); |
113 | 426f17bb | Blue Swirl | |
114 | 426f17bb | Blue Swirl | qemu_register_reset(pci_grackle_reset, &s->host_state); |
115 | 81a322d4 | Gerd Hoffmann | return 0; |
116 | 426f17bb | Blue Swirl | } |
117 | 426f17bb | Blue Swirl | |
118 | 81a322d4 | Gerd Hoffmann | static int grackle_pci_host_init(PCIDevice *d) |
119 | 426f17bb | Blue Swirl | { |
120 | 502a5395 | pbrook | d->config[0x09] = 0x01; |
121 | 81a322d4 | Gerd Hoffmann | return 0; |
122 | 426f17bb | Blue Swirl | } |
123 | 502a5395 | pbrook | |
124 | 40021f08 | Anthony Liguori | static void grackle_pci_class_init(ObjectClass *klass, void *data) |
125 | 40021f08 | Anthony Liguori | { |
126 | 40021f08 | Anthony Liguori | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); |
127 | 39bffca2 | Anthony Liguori | DeviceClass *dc = DEVICE_CLASS(klass); |
128 | 40021f08 | Anthony Liguori | |
129 | 40021f08 | Anthony Liguori | k->init = grackle_pci_host_init; |
130 | 40021f08 | Anthony Liguori | k->vendor_id = PCI_VENDOR_ID_MOTOROLA; |
131 | 40021f08 | Anthony Liguori | k->device_id = PCI_DEVICE_ID_MOTOROLA_MPC106; |
132 | 40021f08 | Anthony Liguori | k->revision = 0x00;
|
133 | 40021f08 | Anthony Liguori | k->class_id = PCI_CLASS_BRIDGE_HOST; |
134 | 39bffca2 | Anthony Liguori | dc->no_user = 1;
|
135 | 40021f08 | Anthony Liguori | } |
136 | 40021f08 | Anthony Liguori | |
137 | 39bffca2 | Anthony Liguori | static TypeInfo grackle_pci_info = {
|
138 | 39bffca2 | Anthony Liguori | .name = "grackle",
|
139 | 39bffca2 | Anthony Liguori | .parent = TYPE_PCI_DEVICE, |
140 | 39bffca2 | Anthony Liguori | .instance_size = sizeof(PCIDevice),
|
141 | 40021f08 | Anthony Liguori | .class_init = grackle_pci_class_init, |
142 | 426f17bb | Blue Swirl | }; |
143 | 6e6b7363 | blueswir1 | |
144 | 999e12bb | Anthony Liguori | static void pci_grackle_class_init(ObjectClass *klass, void *data) |
145 | 999e12bb | Anthony Liguori | { |
146 | 999e12bb | Anthony Liguori | SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); |
147 | 39bffca2 | Anthony Liguori | DeviceClass *dc = DEVICE_CLASS(klass); |
148 | 999e12bb | Anthony Liguori | |
149 | 999e12bb | Anthony Liguori | k->init = pci_grackle_init_device; |
150 | 39bffca2 | Anthony Liguori | dc->no_user = 1;
|
151 | 999e12bb | Anthony Liguori | } |
152 | 999e12bb | Anthony Liguori | |
153 | 39bffca2 | Anthony Liguori | static TypeInfo grackle_pci_host_info = {
|
154 | 39bffca2 | Anthony Liguori | .name = "grackle-pcihost",
|
155 | 39bffca2 | Anthony Liguori | .parent = TYPE_SYS_BUS_DEVICE, |
156 | 39bffca2 | Anthony Liguori | .instance_size = sizeof(GrackleState),
|
157 | 39bffca2 | Anthony Liguori | .class_init = pci_grackle_class_init, |
158 | 0ae46996 | Andreas Färber | }; |
159 | 0ae46996 | Andreas Färber | |
160 | 83f7d43a | Andreas Färber | static void grackle_register_types(void) |
161 | 426f17bb | Blue Swirl | { |
162 | 39bffca2 | Anthony Liguori | type_register_static(&grackle_pci_info); |
163 | 39bffca2 | Anthony Liguori | type_register_static(&grackle_pci_host_info); |
164 | 502a5395 | pbrook | } |
165 | 426f17bb | Blue Swirl | |
166 | 83f7d43a | Andreas Färber | type_init(grackle_register_types) |