Statistics
| Branch: | Revision:

root / hw / unin_pci.c @ 2a424990

History | View | Annotate | Download (9.6 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 a455783b Isaku Yamahata
    pci_mem_config = pci_host_config_register_io_memory(&s->host_state);
88 4f5e19e6 Isaku Yamahata
    pci_mem_data = pci_host_data_register_io_memory(&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_dec_21154_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 bridge */
103 2e29bd04 Blue Swirl
    s = FROM_SYSBUS(UNINState, dev);
104 2e29bd04 Blue Swirl
105 2e29bd04 Blue Swirl
    // XXX: s = &pci_bridge[2];
106 a455783b Isaku Yamahata
    pci_mem_config = pci_host_config_register_io_memory_noswap(&s->host_state);
107 4f5e19e6 Isaku Yamahata
    pci_mem_data = pci_host_data_register_io_memory(&s->host_state);
108 2e29bd04 Blue Swirl
    sysbus_init_mmio(dev, 0x1000, pci_mem_config);
109 2e29bd04 Blue Swirl
    sysbus_init_mmio(dev, 0x1000, pci_mem_data);
110 81a322d4 Gerd Hoffmann
    return 0;
111 2e29bd04 Blue Swirl
}
112 2e29bd04 Blue Swirl
113 81a322d4 Gerd Hoffmann
static int pci_unin_agp_init_device(SysBusDevice *dev)
114 2e29bd04 Blue Swirl
{
115 2e29bd04 Blue Swirl
    UNINState *s;
116 2e29bd04 Blue Swirl
    int pci_mem_config, pci_mem_data;
117 2e29bd04 Blue Swirl
118 2e29bd04 Blue Swirl
    /* Uninorth AGP bus */
119 2e29bd04 Blue Swirl
    s = FROM_SYSBUS(UNINState, dev);
120 2e29bd04 Blue Swirl
121 a455783b Isaku Yamahata
    pci_mem_config = pci_host_config_register_io_memory_noswap(&s->host_state);
122 4f5e19e6 Isaku Yamahata
    pci_mem_data = pci_host_data_register_io_memory(&s->host_state);
123 2e29bd04 Blue Swirl
    sysbus_init_mmio(dev, 0x1000, pci_mem_config);
124 2e29bd04 Blue Swirl
    sysbus_init_mmio(dev, 0x1000, pci_mem_data);
125 81a322d4 Gerd Hoffmann
    return 0;
126 2e29bd04 Blue Swirl
}
127 2e29bd04 Blue Swirl
128 81a322d4 Gerd Hoffmann
static int pci_unin_internal_init_device(SysBusDevice *dev)
129 2e29bd04 Blue Swirl
{
130 2e29bd04 Blue Swirl
    UNINState *s;
131 2e29bd04 Blue Swirl
    int pci_mem_config, pci_mem_data;
132 2e29bd04 Blue Swirl
133 2e29bd04 Blue Swirl
    /* Uninorth internal bus */
134 2e29bd04 Blue Swirl
    s = FROM_SYSBUS(UNINState, dev);
135 2e29bd04 Blue Swirl
136 a455783b Isaku Yamahata
    pci_mem_config = pci_host_config_register_io_memory_noswap(&s->host_state);
137 4f5e19e6 Isaku Yamahata
    pci_mem_data = pci_host_data_register_io_memory(&s->host_state);
138 2e29bd04 Blue Swirl
    sysbus_init_mmio(dev, 0x1000, pci_mem_config);
139 2e29bd04 Blue Swirl
    sysbus_init_mmio(dev, 0x1000, pci_mem_data);
140 81a322d4 Gerd Hoffmann
    return 0;
141 2e29bd04 Blue Swirl
}
142 2e29bd04 Blue Swirl
143 2e29bd04 Blue Swirl
PCIBus *pci_pmac_init(qemu_irq *pic)
144 2e29bd04 Blue Swirl
{
145 2e29bd04 Blue Swirl
    DeviceState *dev;
146 2e29bd04 Blue Swirl
    SysBusDevice *s;
147 2e29bd04 Blue Swirl
    UNINState *d;
148 2e29bd04 Blue Swirl
149 2e29bd04 Blue Swirl
    /* Use values found on a real PowerMac */
150 2e29bd04 Blue Swirl
    /* Uninorth main bus */
151 2e29bd04 Blue Swirl
    dev = qdev_create(NULL, "Uni-north main");
152 e23a1b33 Markus Armbruster
    qdev_init_nofail(dev);
153 2e29bd04 Blue Swirl
    s = sysbus_from_qdev(dev);
154 2e29bd04 Blue Swirl
    d = FROM_SYSBUS(UNINState, s);
155 cdd0935c Blue Swirl
    d->host_state.bus = pci_register_bus(&d->busdev.qdev, "pci",
156 2e29bd04 Blue Swirl
                                         pci_unin_set_irq, pci_unin_map_irq,
157 2e29bd04 Blue Swirl
                                         pic, 11 << 3, 4);
158 2e29bd04 Blue Swirl
159 60398748 Blue Swirl
#if 0
160 2e29bd04 Blue Swirl
    pci_create_simple(d->host_state.bus, 11 << 3, "Uni-north main");
161 60398748 Blue Swirl
#endif
162 2e29bd04 Blue Swirl
163 2e29bd04 Blue Swirl
    sysbus_mmio_map(s, 0, 0xf2800000);
164 2e29bd04 Blue Swirl
    sysbus_mmio_map(s, 1, 0xf2c00000);
165 2e29bd04 Blue Swirl
166 2e29bd04 Blue Swirl
    /* DEC 21154 bridge */
167 2e29bd04 Blue Swirl
#if 0
168 2e29bd04 Blue Swirl
    /* XXX: not activated as PPC BIOS doesn't handle multiple buses properly */
169 2e29bd04 Blue Swirl
    pci_create_simple(d->host_state.bus, 12 << 3, "DEC 21154");
170 2e29bd04 Blue Swirl
#endif
171 2e29bd04 Blue Swirl
172 2e29bd04 Blue Swirl
    /* Uninorth AGP bus */
173 60398748 Blue Swirl
    pci_create_simple(d->host_state.bus, 11 << 3, "Uni-north AGP");
174 d27d06f2 Blue Swirl
    dev = qdev_create(NULL, "Uni-north AGP");
175 d27d06f2 Blue Swirl
    qdev_init_nofail(dev);
176 d27d06f2 Blue Swirl
    s = sysbus_from_qdev(dev);
177 d27d06f2 Blue Swirl
    sysbus_mmio_map(s, 0, 0xf0800000);
178 d27d06f2 Blue Swirl
    sysbus_mmio_map(s, 1, 0xf0c00000);
179 2e29bd04 Blue Swirl
180 2e29bd04 Blue Swirl
    /* Uninorth internal bus */
181 2e29bd04 Blue Swirl
#if 0
182 2e29bd04 Blue Swirl
    /* XXX: not needed for now */
183 2e29bd04 Blue Swirl
    pci_create_simple(d->host_state.bus, 14 << 3, "Uni-north internal");
184 d27d06f2 Blue Swirl
    dev = qdev_create(NULL, "Uni-north internal");
185 d27d06f2 Blue Swirl
    qdev_init_nofail(dev);
186 d27d06f2 Blue Swirl
    s = sysbus_from_qdev(dev);
187 d27d06f2 Blue Swirl
    sysbus_mmio_map(s, 0, 0xf4800000);
188 d27d06f2 Blue Swirl
    sysbus_mmio_map(s, 1, 0xf4c00000);
189 2e29bd04 Blue Swirl
#endif
190 2e29bd04 Blue Swirl
191 2e29bd04 Blue Swirl
    return d->host_state.bus;
192 2e29bd04 Blue Swirl
}
193 2e29bd04 Blue Swirl
194 81a322d4 Gerd Hoffmann
static int unin_main_pci_host_init(PCIDevice *d)
195 2e29bd04 Blue Swirl
{
196 deb54399 aliguori
    pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_APPLE);
197 4ebcf884 blueswir1
    pci_config_set_device_id(d->config, PCI_DEVICE_ID_APPLE_UNI_N_PCI);
198 502a5395 pbrook
    d->config[0x08] = 0x00; // revision
199 173a543b blueswir1
    pci_config_set_class(d->config, PCI_CLASS_BRIDGE_HOST);
200 502a5395 pbrook
    d->config[0x0C] = 0x08; // cache_line_size
201 502a5395 pbrook
    d->config[0x0D] = 0x10; // latency_timer
202 6407f373 Isaku Yamahata
    d->config[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type
203 502a5395 pbrook
    d->config[0x34] = 0x00; // capabilities_pointer
204 81a322d4 Gerd Hoffmann
    return 0;
205 2e29bd04 Blue Swirl
}
206 502a5395 pbrook
207 81a322d4 Gerd Hoffmann
static int dec_21154_pci_host_init(PCIDevice *d)
208 2e29bd04 Blue Swirl
{
209 502a5395 pbrook
    /* pci-to-pci bridge */
210 4ebcf884 blueswir1
    pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_DEC);
211 4ebcf884 blueswir1
    pci_config_set_device_id(d->config, PCI_DEVICE_ID_DEC_21154);
212 502a5395 pbrook
    d->config[0x08] = 0x05; // revision
213 173a543b blueswir1
    pci_config_set_class(d->config, PCI_CLASS_BRIDGE_PCI);
214 502a5395 pbrook
    d->config[0x0C] = 0x08; // cache_line_size
215 502a5395 pbrook
    d->config[0x0D] = 0x20; // latency_timer
216 6407f373 Isaku Yamahata
    d->config[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_BRIDGE; // header_type
217 502a5395 pbrook
218 502a5395 pbrook
    d->config[0x18] = 0x01; // primary_bus
219 502a5395 pbrook
    d->config[0x19] = 0x02; // secondary_bus
220 502a5395 pbrook
    d->config[0x1A] = 0x02; // subordinate_bus
221 502a5395 pbrook
    d->config[0x1B] = 0x20; // secondary_latency_timer
222 502a5395 pbrook
    d->config[0x1C] = 0x11; // io_base
223 502a5395 pbrook
    d->config[0x1D] = 0x01; // io_limit
224 502a5395 pbrook
    d->config[0x20] = 0x00; // memory_base
225 502a5395 pbrook
    d->config[0x21] = 0x80;
226 502a5395 pbrook
    d->config[0x22] = 0x00; // memory_limit
227 502a5395 pbrook
    d->config[0x23] = 0x80;
228 502a5395 pbrook
    d->config[0x24] = 0x01; // prefetchable_memory_base
229 502a5395 pbrook
    d->config[0x25] = 0x80;
230 502a5395 pbrook
    d->config[0x26] = 0xF1; // prefectchable_memory_limit
231 502a5395 pbrook
    d->config[0x27] = 0x7F;
232 502a5395 pbrook
    // d->config[0x34] = 0xdc // capabilities_pointer
233 81a322d4 Gerd Hoffmann
    return 0;
234 2e29bd04 Blue Swirl
}
235 502a5395 pbrook
236 81a322d4 Gerd Hoffmann
static int unin_agp_pci_host_init(PCIDevice *d)
237 2e29bd04 Blue Swirl
{
238 deb54399 aliguori
    pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_APPLE);
239 deb54399 aliguori
    pci_config_set_device_id(d->config, PCI_DEVICE_ID_APPLE_UNI_N_AGP);
240 502a5395 pbrook
    d->config[0x08] = 0x00; // revision
241 173a543b blueswir1
    pci_config_set_class(d->config, PCI_CLASS_BRIDGE_HOST);
242 502a5395 pbrook
    d->config[0x0C] = 0x08; // cache_line_size
243 502a5395 pbrook
    d->config[0x0D] = 0x10; // latency_timer
244 6407f373 Isaku Yamahata
    d->config[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type
245 502a5395 pbrook
    //    d->config[0x34] = 0x80; // capabilities_pointer
246 81a322d4 Gerd Hoffmann
    return 0;
247 2e29bd04 Blue Swirl
}
248 502a5395 pbrook
249 81a322d4 Gerd Hoffmann
static int unin_internal_pci_host_init(PCIDevice *d)
250 2e29bd04 Blue Swirl
{
251 deb54399 aliguori
    pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_APPLE);
252 4ebcf884 blueswir1
    pci_config_set_device_id(d->config, PCI_DEVICE_ID_APPLE_UNI_N_I_PCI);
253 502a5395 pbrook
    d->config[0x08] = 0x00; // revision
254 173a543b blueswir1
    pci_config_set_class(d->config, PCI_CLASS_BRIDGE_HOST);
255 502a5395 pbrook
    d->config[0x0C] = 0x08; // cache_line_size
256 502a5395 pbrook
    d->config[0x0D] = 0x10; // latency_timer
257 6407f373 Isaku Yamahata
    d->config[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type
258 502a5395 pbrook
    d->config[0x34] = 0x00; // capabilities_pointer
259 81a322d4 Gerd Hoffmann
    return 0;
260 2e29bd04 Blue Swirl
}
261 2e29bd04 Blue Swirl
262 2e29bd04 Blue Swirl
static PCIDeviceInfo unin_main_pci_host_info = {
263 2e29bd04 Blue Swirl
    .qdev.name = "Uni-north main",
264 2e29bd04 Blue Swirl
    .qdev.size = sizeof(PCIDevice),
265 2e29bd04 Blue Swirl
    .init      = unin_main_pci_host_init,
266 2e29bd04 Blue Swirl
};
267 2e29bd04 Blue Swirl
268 2e29bd04 Blue Swirl
static PCIDeviceInfo dec_21154_pci_host_info = {
269 2e29bd04 Blue Swirl
    .qdev.name = "DEC 21154",
270 2e29bd04 Blue Swirl
    .qdev.size = sizeof(PCIDevice),
271 2e29bd04 Blue Swirl
    .init      = dec_21154_pci_host_init,
272 2e29bd04 Blue Swirl
};
273 f3902383 blueswir1
274 2e29bd04 Blue Swirl
static PCIDeviceInfo unin_agp_pci_host_info = {
275 2e29bd04 Blue Swirl
    .qdev.name = "Uni-north AGP",
276 2e29bd04 Blue Swirl
    .qdev.size = sizeof(PCIDevice),
277 2e29bd04 Blue Swirl
    .init      = unin_agp_pci_host_init,
278 2e29bd04 Blue Swirl
};
279 2e29bd04 Blue Swirl
280 2e29bd04 Blue Swirl
static PCIDeviceInfo unin_internal_pci_host_info = {
281 2e29bd04 Blue Swirl
    .qdev.name = "Uni-north internal",
282 2e29bd04 Blue Swirl
    .qdev.size = sizeof(PCIDevice),
283 2e29bd04 Blue Swirl
    .init      = unin_internal_pci_host_init,
284 2e29bd04 Blue Swirl
};
285 2e29bd04 Blue Swirl
286 2e29bd04 Blue Swirl
static void unin_register_devices(void)
287 2e29bd04 Blue Swirl
{
288 2e29bd04 Blue Swirl
    sysbus_register_dev("Uni-north main", sizeof(UNINState),
289 2e29bd04 Blue Swirl
                        pci_unin_main_init_device);
290 2e29bd04 Blue Swirl
    pci_qdev_register(&unin_main_pci_host_info);
291 2e29bd04 Blue Swirl
    sysbus_register_dev("DEC 21154", sizeof(UNINState),
292 2e29bd04 Blue Swirl
                        pci_dec_21154_init_device);
293 2e29bd04 Blue Swirl
    pci_qdev_register(&dec_21154_pci_host_info);
294 2e29bd04 Blue Swirl
    sysbus_register_dev("Uni-north AGP", sizeof(UNINState),
295 2e29bd04 Blue Swirl
                        pci_unin_agp_init_device);
296 2e29bd04 Blue Swirl
    pci_qdev_register(&unin_agp_pci_host_info);
297 2e29bd04 Blue Swirl
    sysbus_register_dev("Uni-north internal", sizeof(UNINState),
298 2e29bd04 Blue Swirl
                        pci_unin_internal_init_device);
299 2e29bd04 Blue Swirl
    pci_qdev_register(&unin_internal_pci_host_info);
300 502a5395 pbrook
}
301 2e29bd04 Blue Swirl
302 2e29bd04 Blue Swirl
device_init(unin_register_devices)