root / hw / grackle_pci.c @ afe3ef1d
History | View | Annotate | Download (4 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 | 426f17bb | Blue Swirl | } GrackleState; |
45 | 502a5395 | pbrook | |
46 | d2b59317 | pbrook | /* Don't know if this matches real hardware, but it agrees with OHW. */
|
47 | d2b59317 | pbrook | static int pci_grackle_map_irq(PCIDevice *pci_dev, int irq_num) |
48 | 502a5395 | pbrook | { |
49 | d2b59317 | pbrook | return (irq_num + (pci_dev->devfn >> 3)) & 3; |
50 | d2b59317 | pbrook | } |
51 | d2b59317 | pbrook | |
52 | 5d4e84c8 | Juan Quintela | static void pci_grackle_set_irq(void *opaque, int irq_num, int level) |
53 | d2b59317 | pbrook | { |
54 | 5d4e84c8 | Juan Quintela | qemu_irq *pic = opaque; |
55 | 5d4e84c8 | Juan Quintela | |
56 | ea026b2f | blueswir1 | GRACKLE_DPRINTF("set_irq num %d level %d\n", irq_num, level);
|
57 | 3cbee15b | j_mayer | qemu_set_irq(pic[irq_num + 0x15], level);
|
58 | 502a5395 | pbrook | } |
59 | 502a5395 | pbrook | |
60 | 6e6b7363 | blueswir1 | static void pci_grackle_reset(void *opaque) |
61 | 6e6b7363 | blueswir1 | { |
62 | 6e6b7363 | blueswir1 | } |
63 | 6e6b7363 | blueswir1 | |
64 | d537cf6c | pbrook | PCIBus *pci_grackle_init(uint32_t base, qemu_irq *pic) |
65 | 502a5395 | pbrook | { |
66 | 426f17bb | Blue Swirl | DeviceState *dev; |
67 | 426f17bb | Blue Swirl | SysBusDevice *s; |
68 | 426f17bb | Blue Swirl | GrackleState *d; |
69 | 426f17bb | Blue Swirl | |
70 | 426f17bb | Blue Swirl | dev = qdev_create(NULL, "grackle"); |
71 | e23a1b33 | Markus Armbruster | qdev_init_nofail(dev); |
72 | 426f17bb | Blue Swirl | s = sysbus_from_qdev(dev); |
73 | 426f17bb | Blue Swirl | d = FROM_SYSBUS(GrackleState, s); |
74 | cdd0935c | Blue Swirl | d->host_state.bus = pci_register_bus(&d->busdev.qdev, "pci",
|
75 | 426f17bb | Blue Swirl | pci_grackle_set_irq, |
76 | 426f17bb | Blue Swirl | pci_grackle_map_irq, |
77 | 426f17bb | Blue Swirl | pic, 0, 4); |
78 | 426f17bb | Blue Swirl | |
79 | 426f17bb | Blue Swirl | pci_create_simple(d->host_state.bus, 0, "grackle"); |
80 | 426f17bb | Blue Swirl | |
81 | 426f17bb | Blue Swirl | sysbus_mmio_map(s, 0, base);
|
82 | 426f17bb | Blue Swirl | sysbus_mmio_map(s, 1, base + 0x00200000); |
83 | 426f17bb | Blue Swirl | |
84 | 426f17bb | Blue Swirl | return d->host_state.bus;
|
85 | 426f17bb | Blue Swirl | } |
86 | 426f17bb | Blue Swirl | |
87 | 81a322d4 | Gerd Hoffmann | static int pci_grackle_init_device(SysBusDevice *dev) |
88 | 426f17bb | Blue Swirl | { |
89 | 426f17bb | Blue Swirl | GrackleState *s; |
90 | 426f17bb | Blue Swirl | int pci_mem_config, pci_mem_data;
|
91 | 426f17bb | Blue Swirl | |
92 | 426f17bb | Blue Swirl | s = FROM_SYSBUS(GrackleState, dev); |
93 | 426f17bb | Blue Swirl | |
94 | 6ebf5905 | Alexander Graf | pci_mem_config = pci_host_conf_register_mmio(&s->host_state, |
95 | 6ebf5905 | Alexander Graf | DEVICE_LITTLE_ENDIAN); |
96 | 6ebf5905 | Alexander Graf | pci_mem_data = pci_host_data_register_mmio(&s->host_state, |
97 | 6ebf5905 | Alexander Graf | DEVICE_LITTLE_ENDIAN); |
98 | 426f17bb | Blue Swirl | sysbus_init_mmio(dev, 0x1000, pci_mem_config);
|
99 | 426f17bb | Blue Swirl | sysbus_init_mmio(dev, 0x1000, pci_mem_data);
|
100 | 426f17bb | Blue Swirl | |
101 | 426f17bb | Blue Swirl | qemu_register_reset(pci_grackle_reset, &s->host_state); |
102 | 81a322d4 | Gerd Hoffmann | return 0; |
103 | 426f17bb | Blue Swirl | } |
104 | 426f17bb | Blue Swirl | |
105 | 81a322d4 | Gerd Hoffmann | static int grackle_pci_host_init(PCIDevice *d) |
106 | 426f17bb | Blue Swirl | { |
107 | deb54399 | aliguori | pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_MOTOROLA); |
108 | deb54399 | aliguori | pci_config_set_device_id(d->config, PCI_DEVICE_ID_MOTOROLA_MPC106); |
109 | 502a5395 | pbrook | d->config[0x08] = 0x00; // revision |
110 | 502a5395 | pbrook | d->config[0x09] = 0x01; |
111 | 173a543b | blueswir1 | pci_config_set_class(d->config, PCI_CLASS_BRIDGE_HOST); |
112 | 81a322d4 | Gerd Hoffmann | return 0; |
113 | 426f17bb | Blue Swirl | } |
114 | 502a5395 | pbrook | |
115 | 426f17bb | Blue Swirl | static PCIDeviceInfo grackle_pci_host_info = {
|
116 | 426f17bb | Blue Swirl | .qdev.name = "grackle",
|
117 | 426f17bb | Blue Swirl | .qdev.size = sizeof(PCIDevice),
|
118 | 426f17bb | Blue Swirl | .init = grackle_pci_host_init, |
119 | 426f17bb | Blue Swirl | }; |
120 | 6e6b7363 | blueswir1 | |
121 | 426f17bb | Blue Swirl | static void grackle_register_devices(void) |
122 | 426f17bb | Blue Swirl | { |
123 | 426f17bb | Blue Swirl | sysbus_register_dev("grackle", sizeof(GrackleState), |
124 | 426f17bb | Blue Swirl | pci_grackle_init_device); |
125 | 426f17bb | Blue Swirl | pci_qdev_register(&grackle_pci_host_info); |
126 | 502a5395 | pbrook | } |
127 | 426f17bb | Blue Swirl | |
128 | 426f17bb | Blue Swirl | device_init(grackle_register_devices) |