]>
Commit | Line | Data |
---|---|---|
502a5395 PB |
1 | /* |
2 | * QEMU Uninorth PCI host (for all Mac99 and newer machines) | |
3 | * | |
4 | * Copyright (c) 2006 Fabrice Bellard | |
5fafdf24 | 5 | * |
502a5395 PB |
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: | |
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 | */ | |
87ecb68b PB |
24 | #include "hw.h" |
25 | #include "ppc_mac.h" | |
26 | #include "pci.h" | |
4f5e19e6 | 27 | #include "pci_host.h" |
87ecb68b | 28 | |
f3902383 BS |
29 | /* debug UniNorth */ |
30 | //#define DEBUG_UNIN | |
31 | ||
32 | #ifdef DEBUG_UNIN | |
001faf32 BS |
33 | #define UNIN_DPRINTF(fmt, ...) \ |
34 | do { printf("UNIN: " fmt , ## __VA_ARGS__); } while (0) | |
f3902383 | 35 | #else |
001faf32 | 36 | #define UNIN_DPRINTF(fmt, ...) |
f3902383 BS |
37 | #endif |
38 | ||
fa0be69a AG |
39 | static const int unin_irq_line[] = { 0x1b, 0x1c, 0x1d, 0x1e }; |
40 | ||
2e29bd04 BS |
41 | typedef struct UNINState { |
42 | SysBusDevice busdev; | |
43 | PCIHostState host_state; | |
44 | } UNINState; | |
502a5395 | 45 | |
d2b59317 | 46 | static int pci_unin_map_irq(PCIDevice *pci_dev, int irq_num) |
502a5395 | 47 | { |
fa0be69a AG |
48 | int retval; |
49 | int devfn = pci_dev->devfn & 0x00FFFFFF; | |
50 | ||
51 | retval = (((devfn >> 11) & 0x1F) + irq_num) & 3; | |
52 | ||
53 | return retval; | |
d2b59317 PB |
54 | } |
55 | ||
5d4e84c8 | 56 | static void pci_unin_set_irq(void *opaque, int irq_num, int level) |
d2b59317 | 57 | { |
5d4e84c8 JQ |
58 | qemu_irq *pic = opaque; |
59 | ||
fa0be69a AG |
60 | UNIN_DPRINTF("%s: setting INT %d = %d\n", __func__, |
61 | unin_irq_line[irq_num], level); | |
62 | qemu_set_irq(pic[unin_irq_line[irq_num]], level); | |
502a5395 PB |
63 | } |
64 | ||
f3902383 BS |
65 | static void pci_unin_reset(void *opaque) |
66 | { | |
67 | } | |
68 | ||
d86f0e32 AG |
69 | static uint32_t unin_get_config_reg(uint32_t reg, uint32_t addr) |
70 | { | |
71 | uint32_t retval; | |
72 | ||
73 | if (reg & (1u << 31)) { | |
74 | /* XXX OpenBIOS compatibility hack */ | |
75 | retval = reg | (addr & 3); | |
76 | } else if (reg & 1) { | |
77 | /* CFA1 style */ | |
78 | retval = (reg & ~7u) | (addr & 7); | |
79 | } else { | |
80 | uint32_t slot, func; | |
81 | ||
82 | /* Grab CFA0 style values */ | |
83 | slot = ffs(reg & 0xfffff800) - 1; | |
84 | func = (reg >> 8) & 7; | |
85 | ||
86 | /* ... and then convert them to x86 format */ | |
87 | /* config pointer */ | |
88 | retval = (reg & (0xff - 7)) | (addr & 7); | |
89 | /* slot */ | |
90 | retval |= slot << 11; | |
91 | /* fn */ | |
92 | retval |= func << 8; | |
93 | } | |
94 | ||
95 | ||
96 | UNIN_DPRINTF("Converted config space accessor %08x/%08x -> %08x\n", | |
97 | reg, addr, retval); | |
98 | ||
99 | return retval; | |
100 | } | |
101 | ||
d2c33733 AK |
102 | static void unin_data_write(void *opaque, target_phys_addr_t addr, |
103 | uint64_t val, unsigned len) | |
d86f0e32 | 104 | { |
d2c33733 AK |
105 | UNINState *s = opaque; |
106 | UNIN_DPRINTF("write addr %" TARGET_FMT_plx " len %d val %"PRIx64"\n", | |
107 | addr, len, val); | |
d86f0e32 AG |
108 | pci_data_write(s->host_state.bus, |
109 | unin_get_config_reg(s->host_state.config_reg, addr), | |
110 | val, len); | |
111 | } | |
112 | ||
d2c33733 AK |
113 | static uint64_t unin_data_read(void *opaque, target_phys_addr_t addr, |
114 | unsigned len) | |
d86f0e32 | 115 | { |
d2c33733 | 116 | UNINState *s = opaque; |
d86f0e32 AG |
117 | uint32_t val; |
118 | ||
119 | val = pci_data_read(s->host_state.bus, | |
120 | unin_get_config_reg(s->host_state.config_reg, addr), | |
121 | len); | |
d2c33733 AK |
122 | UNIN_DPRINTF("read addr %" TARGET_FMT_plx " len %d val %x\n", |
123 | addr, len, val); | |
d86f0e32 AG |
124 | return val; |
125 | } | |
126 | ||
d2c33733 AK |
127 | static const MemoryRegionOps unin_data_ops = { |
128 | .read = unin_data_read, | |
129 | .write = unin_data_write, | |
130 | .endianness = DEVICE_LITTLE_ENDIAN, | |
131 | }; | |
132 | ||
81a322d4 | 133 | static int pci_unin_main_init_device(SysBusDevice *dev) |
502a5395 PB |
134 | { |
135 | UNINState *s; | |
502a5395 PB |
136 | |
137 | /* Use values found on a real PowerMac */ | |
138 | /* Uninorth main bus */ | |
2e29bd04 | 139 | s = FROM_SYSBUS(UNINState, dev); |
502a5395 | 140 | |
d2c33733 AK |
141 | memory_region_init_io(&s->host_state.conf_mem, &pci_host_conf_le_ops, |
142 | &s->host_state, "pci-conf-idx", 0x1000); | |
143 | memory_region_init_io(&s->host_state.data_mem, &unin_data_ops, s, | |
144 | "pci-conf-data", 0x1000); | |
145 | sysbus_init_mmio_region(dev, &s->host_state.conf_mem); | |
146 | sysbus_init_mmio_region(dev, &s->host_state.data_mem); | |
2e29bd04 | 147 | |
2e29bd04 | 148 | qemu_register_reset(pci_unin_reset, &s->host_state); |
81a322d4 | 149 | return 0; |
2e29bd04 BS |
150 | } |
151 | ||
d2c33733 | 152 | |
0f921197 AG |
153 | static int pci_u3_agp_init_device(SysBusDevice *dev) |
154 | { | |
155 | UNINState *s; | |
0f921197 AG |
156 | |
157 | /* Uninorth U3 AGP bus */ | |
158 | s = FROM_SYSBUS(UNINState, dev); | |
159 | ||
d2c33733 AK |
160 | memory_region_init_io(&s->host_state.conf_mem, &pci_host_conf_le_ops, |
161 | &s->host_state, "pci-conf-idx", 0x1000); | |
162 | memory_region_init_io(&s->host_state.data_mem, &unin_data_ops, s, | |
163 | "pci-conf-data", 0x1000); | |
164 | sysbus_init_mmio_region(dev, &s->host_state.conf_mem); | |
165 | sysbus_init_mmio_region(dev, &s->host_state.data_mem); | |
0f921197 | 166 | |
0f921197 AG |
167 | qemu_register_reset(pci_unin_reset, &s->host_state); |
168 | ||
169 | return 0; | |
170 | } | |
171 | ||
81a322d4 | 172 | static int pci_unin_agp_init_device(SysBusDevice *dev) |
2e29bd04 BS |
173 | { |
174 | UNINState *s; | |
2e29bd04 BS |
175 | |
176 | /* Uninorth AGP bus */ | |
177 | s = FROM_SYSBUS(UNINState, dev); | |
178 | ||
d2c33733 AK |
179 | memory_region_init_io(&s->host_state.conf_mem, &pci_host_conf_le_ops, |
180 | &s->host_state, "pci-conf-idx", 0x1000); | |
181 | memory_region_init_io(&s->host_state.data_mem, &pci_host_data_le_ops, | |
182 | &s->host_state, "pci-conf-data", 0x1000); | |
183 | sysbus_init_mmio_region(dev, &s->host_state.conf_mem); | |
184 | sysbus_init_mmio_region(dev, &s->host_state.data_mem); | |
81a322d4 | 185 | return 0; |
2e29bd04 BS |
186 | } |
187 | ||
81a322d4 | 188 | static int pci_unin_internal_init_device(SysBusDevice *dev) |
2e29bd04 BS |
189 | { |
190 | UNINState *s; | |
2e29bd04 BS |
191 | |
192 | /* Uninorth internal bus */ | |
193 | s = FROM_SYSBUS(UNINState, dev); | |
194 | ||
d2c33733 AK |
195 | memory_region_init_io(&s->host_state.conf_mem, &pci_host_conf_le_ops, |
196 | &s->host_state, "pci-conf-idx", 0x1000); | |
197 | memory_region_init_io(&s->host_state.data_mem, &pci_host_data_le_ops, | |
198 | &s->host_state, "pci-conf-data", 0x1000); | |
199 | sysbus_init_mmio_region(dev, &s->host_state.conf_mem); | |
200 | sysbus_init_mmio_region(dev, &s->host_state.data_mem); | |
81a322d4 | 201 | return 0; |
2e29bd04 BS |
202 | } |
203 | ||
aee97b84 AK |
204 | PCIBus *pci_pmac_init(qemu_irq *pic, |
205 | MemoryRegion *address_space_mem, | |
206 | MemoryRegion *address_space_io) | |
2e29bd04 BS |
207 | { |
208 | DeviceState *dev; | |
209 | SysBusDevice *s; | |
210 | UNINState *d; | |
211 | ||
212 | /* Use values found on a real PowerMac */ | |
213 | /* Uninorth main bus */ | |
18dd19a7 | 214 | dev = qdev_create(NULL, "uni-north"); |
e23a1b33 | 215 | qdev_init_nofail(dev); |
2e29bd04 BS |
216 | s = sysbus_from_qdev(dev); |
217 | d = FROM_SYSBUS(UNINState, s); | |
cdd0935c | 218 | d->host_state.bus = pci_register_bus(&d->busdev.qdev, "pci", |
2e29bd04 | 219 | pci_unin_set_irq, pci_unin_map_irq, |
aee97b84 AK |
220 | pic, |
221 | address_space_mem, | |
222 | address_space_io, | |
1e39101c | 223 | PCI_DEVFN(11, 0), 4); |
2e29bd04 | 224 | |
60398748 | 225 | #if 0 |
520128bd | 226 | pci_create_simple(d->host_state.bus, PCI_DEVFN(11, 0), "uni-north"); |
60398748 | 227 | #endif |
2e29bd04 BS |
228 | |
229 | sysbus_mmio_map(s, 0, 0xf2800000); | |
230 | sysbus_mmio_map(s, 1, 0xf2c00000); | |
231 | ||
232 | /* DEC 21154 bridge */ | |
233 | #if 0 | |
234 | /* XXX: not activated as PPC BIOS doesn't handle multiple buses properly */ | |
520128bd | 235 | pci_create_simple(d->host_state.bus, PCI_DEVFN(12, 0), "dec-21154"); |
2e29bd04 BS |
236 | #endif |
237 | ||
238 | /* Uninorth AGP bus */ | |
520128bd | 239 | pci_create_simple(d->host_state.bus, PCI_DEVFN(11, 0), "uni-north-agp"); |
18dd19a7 | 240 | dev = qdev_create(NULL, "uni-north-agp"); |
d27d06f2 BS |
241 | qdev_init_nofail(dev); |
242 | s = sysbus_from_qdev(dev); | |
243 | sysbus_mmio_map(s, 0, 0xf0800000); | |
244 | sysbus_mmio_map(s, 1, 0xf0c00000); | |
2e29bd04 BS |
245 | |
246 | /* Uninorth internal bus */ | |
247 | #if 0 | |
248 | /* XXX: not needed for now */ | |
520128bd | 249 | pci_create_simple(d->host_state.bus, PCI_DEVFN(14, 0), "uni-north-pci"); |
18dd19a7 | 250 | dev = qdev_create(NULL, "uni-north-pci"); |
d27d06f2 BS |
251 | qdev_init_nofail(dev); |
252 | s = sysbus_from_qdev(dev); | |
253 | sysbus_mmio_map(s, 0, 0xf4800000); | |
254 | sysbus_mmio_map(s, 1, 0xf4c00000); | |
2e29bd04 BS |
255 | #endif |
256 | ||
257 | return d->host_state.bus; | |
258 | } | |
259 | ||
aee97b84 AK |
260 | PCIBus *pci_pmac_u3_init(qemu_irq *pic, |
261 | MemoryRegion *address_space_mem, | |
262 | MemoryRegion *address_space_io) | |
0f921197 AG |
263 | { |
264 | DeviceState *dev; | |
265 | SysBusDevice *s; | |
266 | UNINState *d; | |
267 | ||
268 | /* Uninorth AGP bus */ | |
269 | ||
270 | dev = qdev_create(NULL, "u3-agp"); | |
271 | qdev_init_nofail(dev); | |
272 | s = sysbus_from_qdev(dev); | |
273 | d = FROM_SYSBUS(UNINState, s); | |
274 | ||
275 | d->host_state.bus = pci_register_bus(&d->busdev.qdev, "pci", | |
276 | pci_unin_set_irq, pci_unin_map_irq, | |
aee97b84 AK |
277 | pic, |
278 | address_space_mem, | |
279 | address_space_io, | |
1e39101c | 280 | PCI_DEVFN(11, 0), 4); |
0f921197 AG |
281 | |
282 | sysbus_mmio_map(s, 0, 0xf0800000); | |
283 | sysbus_mmio_map(s, 1, 0xf0c00000); | |
284 | ||
285 | pci_create_simple(d->host_state.bus, 11 << 3, "u3-agp"); | |
286 | ||
287 | return d->host_state.bus; | |
288 | } | |
289 | ||
81a322d4 | 290 | static int unin_main_pci_host_init(PCIDevice *d) |
2e29bd04 | 291 | { |
502a5395 PB |
292 | d->config[0x0C] = 0x08; // cache_line_size |
293 | d->config[0x0D] = 0x10; // latency_timer | |
502a5395 | 294 | d->config[0x34] = 0x00; // capabilities_pointer |
81a322d4 | 295 | return 0; |
2e29bd04 | 296 | } |
502a5395 | 297 | |
81a322d4 | 298 | static int unin_agp_pci_host_init(PCIDevice *d) |
2e29bd04 | 299 | { |
502a5395 PB |
300 | d->config[0x0C] = 0x08; // cache_line_size |
301 | d->config[0x0D] = 0x10; // latency_timer | |
502a5395 | 302 | // d->config[0x34] = 0x80; // capabilities_pointer |
81a322d4 | 303 | return 0; |
2e29bd04 | 304 | } |
502a5395 | 305 | |
0f921197 AG |
306 | static int u3_agp_pci_host_init(PCIDevice *d) |
307 | { | |
0f921197 AG |
308 | /* cache line size */ |
309 | d->config[0x0C] = 0x08; | |
310 | /* latency timer */ | |
311 | d->config[0x0D] = 0x10; | |
0f921197 AG |
312 | return 0; |
313 | } | |
314 | ||
81a322d4 | 315 | static int unin_internal_pci_host_init(PCIDevice *d) |
2e29bd04 | 316 | { |
502a5395 PB |
317 | d->config[0x0C] = 0x08; // cache_line_size |
318 | d->config[0x0D] = 0x10; // latency_timer | |
502a5395 | 319 | d->config[0x34] = 0x00; // capabilities_pointer |
81a322d4 | 320 | return 0; |
2e29bd04 BS |
321 | } |
322 | ||
323 | static PCIDeviceInfo unin_main_pci_host_info = { | |
18dd19a7 | 324 | .qdev.name = "uni-north", |
2e29bd04 BS |
325 | .qdev.size = sizeof(PCIDevice), |
326 | .init = unin_main_pci_host_init, | |
d7b61ecc IY |
327 | .vendor_id = PCI_VENDOR_ID_APPLE, |
328 | .device_id = PCI_DEVICE_ID_APPLE_UNI_N_PCI, | |
329 | .revision = 0x00, | |
330 | .class_id = PCI_CLASS_BRIDGE_HOST, | |
2e29bd04 BS |
331 | }; |
332 | ||
0f921197 AG |
333 | static PCIDeviceInfo u3_agp_pci_host_info = { |
334 | .qdev.name = "u3-agp", | |
335 | .qdev.size = sizeof(PCIDevice), | |
336 | .init = u3_agp_pci_host_init, | |
d7b61ecc IY |
337 | .vendor_id = PCI_VENDOR_ID_APPLE, |
338 | .device_id = PCI_DEVICE_ID_APPLE_U3_AGP, | |
339 | .revision = 0x00, | |
340 | .class_id = PCI_CLASS_BRIDGE_HOST, | |
0f921197 AG |
341 | }; |
342 | ||
2e29bd04 | 343 | static PCIDeviceInfo unin_agp_pci_host_info = { |
18dd19a7 | 344 | .qdev.name = "uni-north-agp", |
2e29bd04 BS |
345 | .qdev.size = sizeof(PCIDevice), |
346 | .init = unin_agp_pci_host_init, | |
d7b61ecc IY |
347 | .vendor_id = PCI_VENDOR_ID_APPLE, |
348 | .device_id = PCI_DEVICE_ID_APPLE_UNI_N_AGP, | |
349 | .revision = 0x00, | |
350 | .class_id = PCI_CLASS_BRIDGE_HOST, | |
2e29bd04 BS |
351 | }; |
352 | ||
353 | static PCIDeviceInfo unin_internal_pci_host_info = { | |
18dd19a7 | 354 | .qdev.name = "uni-north-pci", |
2e29bd04 BS |
355 | .qdev.size = sizeof(PCIDevice), |
356 | .init = unin_internal_pci_host_init, | |
d7b61ecc IY |
357 | .vendor_id = PCI_VENDOR_ID_APPLE, |
358 | .device_id = PCI_DEVICE_ID_APPLE_UNI_N_I_PCI, | |
359 | .revision = 0x00, | |
360 | .class_id = PCI_CLASS_BRIDGE_HOST, | |
2e29bd04 BS |
361 | }; |
362 | ||
363 | static void unin_register_devices(void) | |
364 | { | |
18dd19a7 | 365 | sysbus_register_dev("uni-north", sizeof(UNINState), |
2e29bd04 BS |
366 | pci_unin_main_init_device); |
367 | pci_qdev_register(&unin_main_pci_host_info); | |
0f921197 AG |
368 | sysbus_register_dev("u3-agp", sizeof(UNINState), |
369 | pci_u3_agp_init_device); | |
370 | pci_qdev_register(&u3_agp_pci_host_info); | |
18dd19a7 | 371 | sysbus_register_dev("uni-north-agp", sizeof(UNINState), |
2e29bd04 BS |
372 | pci_unin_agp_init_device); |
373 | pci_qdev_register(&unin_agp_pci_host_info); | |
18dd19a7 | 374 | sysbus_register_dev("uni-north-pci", sizeof(UNINState), |
2e29bd04 BS |
375 | pci_unin_internal_init_device); |
376 | pci_qdev_register(&unin_internal_pci_host_info); | |
502a5395 | 377 | } |
2e29bd04 BS |
378 | |
379 | device_init(unin_register_devices) |