root / hw / unin_pci.c @ 9752c371
History | View | Annotate | Download (7.7 kB)
1 | 502a5395 | pbrook | /*
|
---|---|---|---|
2 | 502a5395 | pbrook | * QEMU Uninorth PCI host (for all Mac99 and newer machines)
|
3 | 502a5395 | pbrook | *
|
4 | 502a5395 | pbrook | * Copyright (c) 2006 Fabrice Bellard
|
5 | 5fafdf24 | ths | *
|
6 | 502a5395 | pbrook | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 502a5395 | pbrook | * of this software and associated documentation files (the "Software"), to deal
|
8 | 502a5395 | pbrook | * in the Software without restriction, including without limitation the rights
|
9 | 502a5395 | pbrook | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 502a5395 | pbrook | * copies of the Software, and to permit persons to whom the Software is
|
11 | 502a5395 | pbrook | * furnished to do so, subject to the following conditions:
|
12 | 502a5395 | pbrook | *
|
13 | 502a5395 | pbrook | * The above copyright notice and this permission notice shall be included in
|
14 | 502a5395 | pbrook | * all copies or substantial portions of the Software.
|
15 | 502a5395 | pbrook | *
|
16 | 502a5395 | pbrook | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 502a5395 | pbrook | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 502a5395 | pbrook | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 502a5395 | pbrook | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 502a5395 | pbrook | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 502a5395 | pbrook | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 502a5395 | pbrook | * THE SOFTWARE.
|
23 | 502a5395 | pbrook | */
|
24 | 87ecb68b | pbrook | #include "hw.h" |
25 | 87ecb68b | pbrook | #include "ppc_mac.h" |
26 | 87ecb68b | pbrook | #include "pci.h" |
27 | 4f5e19e6 | Isaku Yamahata | #include "pci_host.h" |
28 | 87ecb68b | pbrook | |
29 | f3902383 | blueswir1 | /* debug UniNorth */
|
30 | f3902383 | blueswir1 | //#define DEBUG_UNIN
|
31 | f3902383 | blueswir1 | |
32 | f3902383 | blueswir1 | #ifdef DEBUG_UNIN
|
33 | 001faf32 | Blue Swirl | #define UNIN_DPRINTF(fmt, ...) \
|
34 | 001faf32 | Blue Swirl | do { printf("UNIN: " fmt , ## __VA_ARGS__); } while (0) |
35 | f3902383 | blueswir1 | #else
|
36 | 001faf32 | Blue Swirl | #define UNIN_DPRINTF(fmt, ...)
|
37 | f3902383 | blueswir1 | #endif
|
38 | f3902383 | blueswir1 | |
39 | 2e29bd04 | Blue Swirl | typedef struct UNINState { |
40 | 2e29bd04 | Blue Swirl | SysBusDevice busdev; |
41 | 2e29bd04 | Blue Swirl | PCIHostState host_state; |
42 | 2e29bd04 | Blue Swirl | } UNINState; |
43 | 502a5395 | pbrook | |
44 | d2b59317 | pbrook | /* Don't know if this matches real hardware, but it agrees with OHW. */
|
45 | d2b59317 | pbrook | static int pci_unin_map_irq(PCIDevice *pci_dev, int irq_num) |
46 | 502a5395 | pbrook | { |
47 | d2b59317 | pbrook | return (irq_num + (pci_dev->devfn >> 3)) & 3; |
48 | d2b59317 | pbrook | } |
49 | d2b59317 | pbrook | |
50 | 5d4e84c8 | Juan Quintela | static void pci_unin_set_irq(void *opaque, int irq_num, int level) |
51 | d2b59317 | pbrook | { |
52 | 5d4e84c8 | Juan Quintela | qemu_irq *pic = opaque; |
53 | 5d4e84c8 | Juan Quintela | |
54 | d537cf6c | pbrook | qemu_set_irq(pic[irq_num + 8], level);
|
55 | 502a5395 | pbrook | } |
56 | 502a5395 | pbrook | |
57 | f3902383 | blueswir1 | static void pci_unin_save(QEMUFile* f, void *opaque) |
58 | f3902383 | blueswir1 | { |
59 | f3902383 | blueswir1 | PCIDevice *d = opaque; |
60 | f3902383 | blueswir1 | |
61 | f3902383 | blueswir1 | pci_device_save(d, f); |
62 | f3902383 | blueswir1 | } |
63 | f3902383 | blueswir1 | |
64 | f3902383 | blueswir1 | static int pci_unin_load(QEMUFile* f, void *opaque, int version_id) |
65 | f3902383 | blueswir1 | { |
66 | f3902383 | blueswir1 | PCIDevice *d = opaque; |
67 | f3902383 | blueswir1 | |
68 | f3902383 | blueswir1 | if (version_id != 1) |
69 | f3902383 | blueswir1 | return -EINVAL;
|
70 | f3902383 | blueswir1 | |
71 | f3902383 | blueswir1 | return pci_device_load(d, f);
|
72 | f3902383 | blueswir1 | } |
73 | f3902383 | blueswir1 | |
74 | f3902383 | blueswir1 | static void pci_unin_reset(void *opaque) |
75 | f3902383 | blueswir1 | { |
76 | f3902383 | blueswir1 | } |
77 | f3902383 | blueswir1 | |
78 | 81a322d4 | Gerd Hoffmann | static int pci_unin_main_init_device(SysBusDevice *dev) |
79 | 502a5395 | pbrook | { |
80 | 502a5395 | pbrook | UNINState *s; |
81 | 502a5395 | pbrook | int pci_mem_config, pci_mem_data;
|
82 | 502a5395 | pbrook | |
83 | 502a5395 | pbrook | /* Use values found on a real PowerMac */
|
84 | 502a5395 | pbrook | /* Uninorth main bus */
|
85 | 2e29bd04 | Blue Swirl | s = FROM_SYSBUS(UNINState, dev); |
86 | 502a5395 | pbrook | |
87 | f08b32fe | Isaku Yamahata | pci_mem_config = pci_host_conf_register_mmio(&s->host_state); |
88 | f08b32fe | Isaku Yamahata | pci_mem_data = pci_host_data_register_mmio(&s->host_state); |
89 | 2e29bd04 | Blue Swirl | sysbus_init_mmio(dev, 0x1000, pci_mem_config);
|
90 | 2e29bd04 | Blue Swirl | sysbus_init_mmio(dev, 0x1000, pci_mem_data);
|
91 | 2e29bd04 | Blue Swirl | |
92 | 2e29bd04 | Blue Swirl | register_savevm("uninorth", 0, 1, pci_unin_save, pci_unin_load, &s->host_state); |
93 | 2e29bd04 | Blue Swirl | qemu_register_reset(pci_unin_reset, &s->host_state); |
94 | 81a322d4 | Gerd Hoffmann | return 0; |
95 | 2e29bd04 | Blue Swirl | } |
96 | 2e29bd04 | Blue Swirl | |
97 | 81a322d4 | Gerd Hoffmann | static int pci_unin_agp_init_device(SysBusDevice *dev) |
98 | 2e29bd04 | Blue Swirl | { |
99 | 2e29bd04 | Blue Swirl | UNINState *s; |
100 | 2e29bd04 | Blue Swirl | int pci_mem_config, pci_mem_data;
|
101 | 2e29bd04 | Blue Swirl | |
102 | 2e29bd04 | Blue Swirl | /* Uninorth AGP bus */
|
103 | 2e29bd04 | Blue Swirl | s = FROM_SYSBUS(UNINState, dev); |
104 | 2e29bd04 | Blue Swirl | |
105 | f08b32fe | Isaku Yamahata | pci_mem_config = pci_host_conf_register_mmio_noswap(&s->host_state); |
106 | f08b32fe | Isaku Yamahata | pci_mem_data = pci_host_data_register_mmio(&s->host_state); |
107 | 2e29bd04 | Blue Swirl | sysbus_init_mmio(dev, 0x1000, pci_mem_config);
|
108 | 2e29bd04 | Blue Swirl | sysbus_init_mmio(dev, 0x1000, pci_mem_data);
|
109 | 81a322d4 | Gerd Hoffmann | return 0; |
110 | 2e29bd04 | Blue Swirl | } |
111 | 2e29bd04 | Blue Swirl | |
112 | 81a322d4 | Gerd Hoffmann | static int pci_unin_internal_init_device(SysBusDevice *dev) |
113 | 2e29bd04 | Blue Swirl | { |
114 | 2e29bd04 | Blue Swirl | UNINState *s; |
115 | 2e29bd04 | Blue Swirl | int pci_mem_config, pci_mem_data;
|
116 | 2e29bd04 | Blue Swirl | |
117 | 2e29bd04 | Blue Swirl | /* Uninorth internal bus */
|
118 | 2e29bd04 | Blue Swirl | s = FROM_SYSBUS(UNINState, dev); |
119 | 2e29bd04 | Blue Swirl | |
120 | f08b32fe | Isaku Yamahata | pci_mem_config = pci_host_conf_register_mmio_noswap(&s->host_state); |
121 | f08b32fe | Isaku Yamahata | pci_mem_data = pci_host_data_register_mmio(&s->host_state); |
122 | 2e29bd04 | Blue Swirl | sysbus_init_mmio(dev, 0x1000, pci_mem_config);
|
123 | 2e29bd04 | Blue Swirl | sysbus_init_mmio(dev, 0x1000, pci_mem_data);
|
124 | 81a322d4 | Gerd Hoffmann | return 0; |
125 | 2e29bd04 | Blue Swirl | } |
126 | 2e29bd04 | Blue Swirl | |
127 | 2e29bd04 | Blue Swirl | PCIBus *pci_pmac_init(qemu_irq *pic) |
128 | 2e29bd04 | Blue Swirl | { |
129 | 2e29bd04 | Blue Swirl | DeviceState *dev; |
130 | 2e29bd04 | Blue Swirl | SysBusDevice *s; |
131 | 2e29bd04 | Blue Swirl | UNINState *d; |
132 | 2e29bd04 | Blue Swirl | |
133 | 2e29bd04 | Blue Swirl | /* Use values found on a real PowerMac */
|
134 | 2e29bd04 | Blue Swirl | /* Uninorth main bus */
|
135 | 18dd19a7 | Markus Armbruster | dev = qdev_create(NULL, "uni-north"); |
136 | e23a1b33 | Markus Armbruster | qdev_init_nofail(dev); |
137 | 2e29bd04 | Blue Swirl | s = sysbus_from_qdev(dev); |
138 | 2e29bd04 | Blue Swirl | d = FROM_SYSBUS(UNINState, s); |
139 | cdd0935c | Blue Swirl | d->host_state.bus = pci_register_bus(&d->busdev.qdev, "pci",
|
140 | 2e29bd04 | Blue Swirl | pci_unin_set_irq, pci_unin_map_irq, |
141 | 2e29bd04 | Blue Swirl | pic, 11 << 3, 4); |
142 | 2e29bd04 | Blue Swirl | |
143 | 60398748 | Blue Swirl | #if 0
|
144 | 18dd19a7 | Markus Armbruster | pci_create_simple(d->host_state.bus, 11 << 3, "uni-north");
|
145 | 60398748 | Blue Swirl | #endif
|
146 | 2e29bd04 | Blue Swirl | |
147 | 2e29bd04 | Blue Swirl | sysbus_mmio_map(s, 0, 0xf2800000); |
148 | 2e29bd04 | Blue Swirl | sysbus_mmio_map(s, 1, 0xf2c00000); |
149 | 2e29bd04 | Blue Swirl | |
150 | 2e29bd04 | Blue Swirl | /* DEC 21154 bridge */
|
151 | 2e29bd04 | Blue Swirl | #if 0
|
152 | 2e29bd04 | Blue Swirl | /* XXX: not activated as PPC BIOS doesn't handle multiple buses properly */
|
153 | 556cd098 | Markus Armbruster | pci_create_simple(d->host_state.bus, 12 << 3, "dec-21154");
|
154 | 2e29bd04 | Blue Swirl | #endif
|
155 | 2e29bd04 | Blue Swirl | |
156 | 2e29bd04 | Blue Swirl | /* Uninorth AGP bus */
|
157 | 18dd19a7 | Markus Armbruster | pci_create_simple(d->host_state.bus, 11 << 3, "uni-north-agp"); |
158 | 18dd19a7 | Markus Armbruster | dev = qdev_create(NULL, "uni-north-agp"); |
159 | d27d06f2 | Blue Swirl | qdev_init_nofail(dev); |
160 | d27d06f2 | Blue Swirl | s = sysbus_from_qdev(dev); |
161 | d27d06f2 | Blue Swirl | sysbus_mmio_map(s, 0, 0xf0800000); |
162 | d27d06f2 | Blue Swirl | sysbus_mmio_map(s, 1, 0xf0c00000); |
163 | 2e29bd04 | Blue Swirl | |
164 | 2e29bd04 | Blue Swirl | /* Uninorth internal bus */
|
165 | 2e29bd04 | Blue Swirl | #if 0
|
166 | 2e29bd04 | Blue Swirl | /* XXX: not needed for now */
|
167 | 18dd19a7 | Markus Armbruster | pci_create_simple(d->host_state.bus, 14 << 3, "uni-north-pci");
|
168 | 18dd19a7 | Markus Armbruster | dev = qdev_create(NULL, "uni-north-pci");
|
169 | d27d06f2 | Blue Swirl | qdev_init_nofail(dev);
|
170 | d27d06f2 | Blue Swirl | s = sysbus_from_qdev(dev);
|
171 | d27d06f2 | Blue Swirl | sysbus_mmio_map(s, 0, 0xf4800000);
|
172 | d27d06f2 | Blue Swirl | sysbus_mmio_map(s, 1, 0xf4c00000);
|
173 | 2e29bd04 | Blue Swirl | #endif
|
174 | 2e29bd04 | Blue Swirl | |
175 | 2e29bd04 | Blue Swirl | return d->host_state.bus;
|
176 | 2e29bd04 | Blue Swirl | } |
177 | 2e29bd04 | Blue Swirl | |
178 | 81a322d4 | Gerd Hoffmann | static int unin_main_pci_host_init(PCIDevice *d) |
179 | 2e29bd04 | Blue Swirl | { |
180 | deb54399 | aliguori | pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_APPLE); |
181 | 4ebcf884 | blueswir1 | pci_config_set_device_id(d->config, PCI_DEVICE_ID_APPLE_UNI_N_PCI); |
182 | 502a5395 | pbrook | d->config[0x08] = 0x00; // revision |
183 | 173a543b | blueswir1 | pci_config_set_class(d->config, PCI_CLASS_BRIDGE_HOST); |
184 | 502a5395 | pbrook | d->config[0x0C] = 0x08; // cache_line_size |
185 | 502a5395 | pbrook | d->config[0x0D] = 0x10; // latency_timer |
186 | 6407f373 | Isaku Yamahata | d->config[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type
|
187 | 502a5395 | pbrook | d->config[0x34] = 0x00; // capabilities_pointer |
188 | 81a322d4 | Gerd Hoffmann | return 0; |
189 | 2e29bd04 | Blue Swirl | } |
190 | 502a5395 | pbrook | |
191 | 81a322d4 | Gerd Hoffmann | static int unin_agp_pci_host_init(PCIDevice *d) |
192 | 2e29bd04 | Blue Swirl | { |
193 | deb54399 | aliguori | pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_APPLE); |
194 | deb54399 | aliguori | pci_config_set_device_id(d->config, PCI_DEVICE_ID_APPLE_UNI_N_AGP); |
195 | 502a5395 | pbrook | d->config[0x08] = 0x00; // revision |
196 | 173a543b | blueswir1 | pci_config_set_class(d->config, PCI_CLASS_BRIDGE_HOST); |
197 | 502a5395 | pbrook | d->config[0x0C] = 0x08; // cache_line_size |
198 | 502a5395 | pbrook | d->config[0x0D] = 0x10; // latency_timer |
199 | 6407f373 | Isaku Yamahata | d->config[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type
|
200 | 502a5395 | pbrook | // d->config[0x34] = 0x80; // capabilities_pointer
|
201 | 81a322d4 | Gerd Hoffmann | return 0; |
202 | 2e29bd04 | Blue Swirl | } |
203 | 502a5395 | pbrook | |
204 | 81a322d4 | Gerd Hoffmann | static int unin_internal_pci_host_init(PCIDevice *d) |
205 | 2e29bd04 | Blue Swirl | { |
206 | deb54399 | aliguori | pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_APPLE); |
207 | 4ebcf884 | blueswir1 | pci_config_set_device_id(d->config, PCI_DEVICE_ID_APPLE_UNI_N_I_PCI); |
208 | 502a5395 | pbrook | d->config[0x08] = 0x00; // revision |
209 | 173a543b | blueswir1 | pci_config_set_class(d->config, PCI_CLASS_BRIDGE_HOST); |
210 | 502a5395 | pbrook | d->config[0x0C] = 0x08; // cache_line_size |
211 | 502a5395 | pbrook | d->config[0x0D] = 0x10; // latency_timer |
212 | 6407f373 | Isaku Yamahata | d->config[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type
|
213 | 502a5395 | pbrook | d->config[0x34] = 0x00; // capabilities_pointer |
214 | 81a322d4 | Gerd Hoffmann | return 0; |
215 | 2e29bd04 | Blue Swirl | } |
216 | 2e29bd04 | Blue Swirl | |
217 | 2e29bd04 | Blue Swirl | static PCIDeviceInfo unin_main_pci_host_info = {
|
218 | 18dd19a7 | Markus Armbruster | .qdev.name = "uni-north",
|
219 | 2e29bd04 | Blue Swirl | .qdev.size = sizeof(PCIDevice),
|
220 | 2e29bd04 | Blue Swirl | .init = unin_main_pci_host_init, |
221 | 2e29bd04 | Blue Swirl | }; |
222 | 2e29bd04 | Blue Swirl | |
223 | 2e29bd04 | Blue Swirl | static PCIDeviceInfo unin_agp_pci_host_info = {
|
224 | 18dd19a7 | Markus Armbruster | .qdev.name = "uni-north-agp",
|
225 | 2e29bd04 | Blue Swirl | .qdev.size = sizeof(PCIDevice),
|
226 | 2e29bd04 | Blue Swirl | .init = unin_agp_pci_host_init, |
227 | 2e29bd04 | Blue Swirl | }; |
228 | 2e29bd04 | Blue Swirl | |
229 | 2e29bd04 | Blue Swirl | static PCIDeviceInfo unin_internal_pci_host_info = {
|
230 | 18dd19a7 | Markus Armbruster | .qdev.name = "uni-north-pci",
|
231 | 2e29bd04 | Blue Swirl | .qdev.size = sizeof(PCIDevice),
|
232 | 2e29bd04 | Blue Swirl | .init = unin_internal_pci_host_init, |
233 | 2e29bd04 | Blue Swirl | }; |
234 | 2e29bd04 | Blue Swirl | |
235 | 2e29bd04 | Blue Swirl | static void unin_register_devices(void) |
236 | 2e29bd04 | Blue Swirl | { |
237 | 18dd19a7 | Markus Armbruster | sysbus_register_dev("uni-north", sizeof(UNINState), |
238 | 2e29bd04 | Blue Swirl | pci_unin_main_init_device); |
239 | 2e29bd04 | Blue Swirl | pci_qdev_register(&unin_main_pci_host_info); |
240 | 18dd19a7 | Markus Armbruster | sysbus_register_dev("uni-north-agp", sizeof(UNINState), |
241 | 2e29bd04 | Blue Swirl | pci_unin_agp_init_device); |
242 | 2e29bd04 | Blue Swirl | pci_qdev_register(&unin_agp_pci_host_info); |
243 | 18dd19a7 | Markus Armbruster | sysbus_register_dev("uni-north-pci", sizeof(UNINState), |
244 | 2e29bd04 | Blue Swirl | pci_unin_internal_init_device); |
245 | 2e29bd04 | Blue Swirl | pci_qdev_register(&unin_internal_pci_host_info); |
246 | 502a5395 | pbrook | } |
247 | 2e29bd04 | Blue Swirl | |
248 | 2e29bd04 | Blue Swirl | device_init(unin_register_devices) |