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