root / hw / unin_pci.c @ 7f23f812
History | View | Annotate | Download (12.1 kB)
1 |
/*
|
---|---|
2 |
* QEMU Uninorth PCI host (for all Mac99 and newer machines)
|
3 |
*
|
4 |
* Copyright (c) 2006 Fabrice Bellard
|
5 |
*
|
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 |
*/
|
24 |
#include "hw.h" |
25 |
#include "ppc_mac.h" |
26 |
#include "pci.h" |
27 |
|
28 |
/* debug UniNorth */
|
29 |
//#define DEBUG_UNIN
|
30 |
|
31 |
#ifdef DEBUG_UNIN
|
32 |
#define UNIN_DPRINTF(fmt, ...) \
|
33 |
do { printf("UNIN: " fmt , ## __VA_ARGS__); } while (0) |
34 |
#else
|
35 |
#define UNIN_DPRINTF(fmt, ...)
|
36 |
#endif
|
37 |
|
38 |
typedef target_phys_addr_t pci_addr_t;
|
39 |
#include "pci_host.h" |
40 |
|
41 |
typedef struct UNINState { |
42 |
SysBusDevice busdev; |
43 |
PCIHostState host_state; |
44 |
} UNINState; |
45 |
|
46 |
static void pci_unin_main_config_writel (void *opaque, target_phys_addr_t addr, |
47 |
uint32_t val) |
48 |
{ |
49 |
UNINState *s = opaque; |
50 |
|
51 |
UNIN_DPRINTF("config_writel addr " TARGET_FMT_plx " val %x\n", addr, val); |
52 |
#ifdef TARGET_WORDS_BIGENDIAN
|
53 |
val = bswap32(val); |
54 |
#endif
|
55 |
|
56 |
s->host_state.config_reg = val; |
57 |
} |
58 |
|
59 |
static uint32_t pci_unin_main_config_readl (void *opaque, |
60 |
target_phys_addr_t addr) |
61 |
{ |
62 |
UNINState *s = opaque; |
63 |
uint32_t val; |
64 |
|
65 |
val = s->host_state.config_reg; |
66 |
#ifdef TARGET_WORDS_BIGENDIAN
|
67 |
val = bswap32(val); |
68 |
#endif
|
69 |
UNIN_DPRINTF("config_readl addr " TARGET_FMT_plx " val %x\n", addr, val); |
70 |
|
71 |
return val;
|
72 |
} |
73 |
|
74 |
static CPUWriteMemoryFunc * const pci_unin_main_config_write[] = { |
75 |
&pci_unin_main_config_writel, |
76 |
&pci_unin_main_config_writel, |
77 |
&pci_unin_main_config_writel, |
78 |
}; |
79 |
|
80 |
static CPUReadMemoryFunc * const pci_unin_main_config_read[] = { |
81 |
&pci_unin_main_config_readl, |
82 |
&pci_unin_main_config_readl, |
83 |
&pci_unin_main_config_readl, |
84 |
}; |
85 |
|
86 |
static CPUWriteMemoryFunc * const pci_unin_main_write[] = { |
87 |
&pci_host_data_writeb, |
88 |
&pci_host_data_writew, |
89 |
&pci_host_data_writel, |
90 |
}; |
91 |
|
92 |
static CPUReadMemoryFunc * const pci_unin_main_read[] = { |
93 |
&pci_host_data_readb, |
94 |
&pci_host_data_readw, |
95 |
&pci_host_data_readl, |
96 |
}; |
97 |
|
98 |
static void pci_unin_config_writel (void *opaque, target_phys_addr_t addr, |
99 |
uint32_t val) |
100 |
{ |
101 |
UNINState *s = opaque; |
102 |
|
103 |
s->host_state.config_reg = val; |
104 |
} |
105 |
|
106 |
static uint32_t pci_unin_config_readl (void *opaque, |
107 |
target_phys_addr_t addr) |
108 |
{ |
109 |
UNINState *s = opaque; |
110 |
|
111 |
return s->host_state.config_reg;
|
112 |
} |
113 |
|
114 |
static CPUWriteMemoryFunc * const pci_unin_config_write[] = { |
115 |
&pci_unin_config_writel, |
116 |
&pci_unin_config_writel, |
117 |
&pci_unin_config_writel, |
118 |
}; |
119 |
|
120 |
static CPUReadMemoryFunc * const pci_unin_config_read[] = { |
121 |
&pci_unin_config_readl, |
122 |
&pci_unin_config_readl, |
123 |
&pci_unin_config_readl, |
124 |
}; |
125 |
|
126 |
static CPUWriteMemoryFunc * const pci_unin_write[] = { |
127 |
&pci_host_data_writeb, |
128 |
&pci_host_data_writew, |
129 |
&pci_host_data_writel, |
130 |
}; |
131 |
|
132 |
static CPUReadMemoryFunc * const pci_unin_read[] = { |
133 |
&pci_host_data_readb, |
134 |
&pci_host_data_readw, |
135 |
&pci_host_data_readl, |
136 |
}; |
137 |
|
138 |
/* Don't know if this matches real hardware, but it agrees with OHW. */
|
139 |
static int pci_unin_map_irq(PCIDevice *pci_dev, int irq_num) |
140 |
{ |
141 |
return (irq_num + (pci_dev->devfn >> 3)) & 3; |
142 |
} |
143 |
|
144 |
static void pci_unin_set_irq(void *opaque, int irq_num, int level) |
145 |
{ |
146 |
qemu_irq *pic = opaque; |
147 |
|
148 |
qemu_set_irq(pic[irq_num + 8], level);
|
149 |
} |
150 |
|
151 |
static void pci_unin_save(QEMUFile* f, void *opaque) |
152 |
{ |
153 |
PCIDevice *d = opaque; |
154 |
|
155 |
pci_device_save(d, f); |
156 |
} |
157 |
|
158 |
static int pci_unin_load(QEMUFile* f, void *opaque, int version_id) |
159 |
{ |
160 |
PCIDevice *d = opaque; |
161 |
|
162 |
if (version_id != 1) |
163 |
return -EINVAL;
|
164 |
|
165 |
return pci_device_load(d, f);
|
166 |
} |
167 |
|
168 |
static void pci_unin_reset(void *opaque) |
169 |
{ |
170 |
} |
171 |
|
172 |
static int pci_unin_main_init_device(SysBusDevice *dev) |
173 |
{ |
174 |
UNINState *s; |
175 |
int pci_mem_config, pci_mem_data;
|
176 |
|
177 |
/* Use values found on a real PowerMac */
|
178 |
/* Uninorth main bus */
|
179 |
s = FROM_SYSBUS(UNINState, dev); |
180 |
|
181 |
pci_mem_config = cpu_register_io_memory(pci_unin_main_config_read, |
182 |
pci_unin_main_config_write, s); |
183 |
pci_mem_data = cpu_register_io_memory(pci_unin_main_read, |
184 |
pci_unin_main_write, &s->host_state); |
185 |
|
186 |
sysbus_init_mmio(dev, 0x1000, pci_mem_config);
|
187 |
sysbus_init_mmio(dev, 0x1000, pci_mem_data);
|
188 |
|
189 |
register_savevm("uninorth", 0, 1, pci_unin_save, pci_unin_load, &s->host_state); |
190 |
qemu_register_reset(pci_unin_reset, &s->host_state); |
191 |
pci_unin_reset(&s->host_state); |
192 |
return 0; |
193 |
} |
194 |
|
195 |
static int pci_dec_21154_init_device(SysBusDevice *dev) |
196 |
{ |
197 |
UNINState *s; |
198 |
int pci_mem_config, pci_mem_data;
|
199 |
|
200 |
/* Uninorth bridge */
|
201 |
s = FROM_SYSBUS(UNINState, dev); |
202 |
|
203 |
// XXX: s = &pci_bridge[2];
|
204 |
pci_mem_config = cpu_register_io_memory(pci_unin_config_read, |
205 |
pci_unin_config_write, s); |
206 |
pci_mem_data = cpu_register_io_memory(pci_unin_main_read, |
207 |
pci_unin_main_write, &s->host_state); |
208 |
sysbus_init_mmio(dev, 0x1000, pci_mem_config);
|
209 |
sysbus_init_mmio(dev, 0x1000, pci_mem_data);
|
210 |
return 0; |
211 |
} |
212 |
|
213 |
static int pci_unin_agp_init_device(SysBusDevice *dev) |
214 |
{ |
215 |
UNINState *s; |
216 |
int pci_mem_config, pci_mem_data;
|
217 |
|
218 |
/* Uninorth AGP bus */
|
219 |
s = FROM_SYSBUS(UNINState, dev); |
220 |
|
221 |
pci_mem_config = cpu_register_io_memory(pci_unin_config_read, |
222 |
pci_unin_config_write, s); |
223 |
pci_mem_data = cpu_register_io_memory(pci_unin_main_read, |
224 |
pci_unin_main_write, &s->host_state); |
225 |
sysbus_init_mmio(dev, 0x1000, pci_mem_config);
|
226 |
sysbus_init_mmio(dev, 0x1000, pci_mem_data);
|
227 |
return 0; |
228 |
} |
229 |
|
230 |
static int pci_unin_internal_init_device(SysBusDevice *dev) |
231 |
{ |
232 |
UNINState *s; |
233 |
int pci_mem_config, pci_mem_data;
|
234 |
|
235 |
/* Uninorth internal bus */
|
236 |
s = FROM_SYSBUS(UNINState, dev); |
237 |
|
238 |
pci_mem_config = cpu_register_io_memory(pci_unin_config_read, |
239 |
pci_unin_config_write, s); |
240 |
pci_mem_data = cpu_register_io_memory(pci_unin_read, |
241 |
pci_unin_write, s); |
242 |
sysbus_init_mmio(dev, 0x1000, pci_mem_config);
|
243 |
sysbus_init_mmio(dev, 0x1000, pci_mem_data);
|
244 |
return 0; |
245 |
} |
246 |
|
247 |
PCIBus *pci_pmac_init(qemu_irq *pic) |
248 |
{ |
249 |
DeviceState *dev; |
250 |
SysBusDevice *s; |
251 |
UNINState *d; |
252 |
|
253 |
/* Use values found on a real PowerMac */
|
254 |
/* Uninorth main bus */
|
255 |
dev = qdev_create(NULL, "Uni-north main"); |
256 |
qdev_init(dev); |
257 |
s = sysbus_from_qdev(dev); |
258 |
d = FROM_SYSBUS(UNINState, s); |
259 |
d->host_state.bus = pci_register_bus(&d->busdev.qdev, "pci",
|
260 |
pci_unin_set_irq, pci_unin_map_irq, |
261 |
pic, 11 << 3, 4); |
262 |
|
263 |
pci_create_simple(d->host_state.bus, 11 << 3, "Uni-north main"); |
264 |
|
265 |
sysbus_mmio_map(s, 0, 0xf2800000); |
266 |
sysbus_mmio_map(s, 1, 0xf2c00000); |
267 |
|
268 |
/* DEC 21154 bridge */
|
269 |
#if 0
|
270 |
/* XXX: not activated as PPC BIOS doesn't handle multiple buses properly */
|
271 |
pci_create_simple(d->host_state.bus, 12 << 3, "DEC 21154");
|
272 |
#endif
|
273 |
|
274 |
/* Uninorth AGP bus */
|
275 |
pci_create_simple(d->host_state.bus, 13 << 3, "Uni-north AGP"); |
276 |
|
277 |
/* Uninorth internal bus */
|
278 |
#if 0
|
279 |
/* XXX: not needed for now */
|
280 |
pci_create_simple(d->host_state.bus, 14 << 3, "Uni-north internal");
|
281 |
#endif
|
282 |
|
283 |
return d->host_state.bus;
|
284 |
} |
285 |
|
286 |
static int unin_main_pci_host_init(PCIDevice *d) |
287 |
{ |
288 |
pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_APPLE); |
289 |
pci_config_set_device_id(d->config, PCI_DEVICE_ID_APPLE_UNI_N_PCI); |
290 |
d->config[0x08] = 0x00; // revision |
291 |
pci_config_set_class(d->config, PCI_CLASS_BRIDGE_HOST); |
292 |
d->config[0x0C] = 0x08; // cache_line_size |
293 |
d->config[0x0D] = 0x10; // latency_timer |
294 |
d->config[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type
|
295 |
d->config[0x34] = 0x00; // capabilities_pointer |
296 |
return 0; |
297 |
} |
298 |
|
299 |
static int dec_21154_pci_host_init(PCIDevice *d) |
300 |
{ |
301 |
/* pci-to-pci bridge */
|
302 |
pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_DEC); |
303 |
pci_config_set_device_id(d->config, PCI_DEVICE_ID_DEC_21154); |
304 |
d->config[0x08] = 0x05; // revision |
305 |
pci_config_set_class(d->config, PCI_CLASS_BRIDGE_PCI); |
306 |
d->config[0x0C] = 0x08; // cache_line_size |
307 |
d->config[0x0D] = 0x20; // latency_timer |
308 |
d->config[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_BRIDGE; // header_type
|
309 |
|
310 |
d->config[0x18] = 0x01; // primary_bus |
311 |
d->config[0x19] = 0x02; // secondary_bus |
312 |
d->config[0x1A] = 0x02; // subordinate_bus |
313 |
d->config[0x1B] = 0x20; // secondary_latency_timer |
314 |
d->config[0x1C] = 0x11; // io_base |
315 |
d->config[0x1D] = 0x01; // io_limit |
316 |
d->config[0x20] = 0x00; // memory_base |
317 |
d->config[0x21] = 0x80; |
318 |
d->config[0x22] = 0x00; // memory_limit |
319 |
d->config[0x23] = 0x80; |
320 |
d->config[0x24] = 0x01; // prefetchable_memory_base |
321 |
d->config[0x25] = 0x80; |
322 |
d->config[0x26] = 0xF1; // prefectchable_memory_limit |
323 |
d->config[0x27] = 0x7F; |
324 |
// d->config[0x34] = 0xdc // capabilities_pointer
|
325 |
return 0; |
326 |
} |
327 |
|
328 |
static int unin_agp_pci_host_init(PCIDevice *d) |
329 |
{ |
330 |
pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_APPLE); |
331 |
pci_config_set_device_id(d->config, PCI_DEVICE_ID_APPLE_UNI_N_AGP); |
332 |
d->config[0x08] = 0x00; // revision |
333 |
pci_config_set_class(d->config, PCI_CLASS_BRIDGE_HOST); |
334 |
d->config[0x0C] = 0x08; // cache_line_size |
335 |
d->config[0x0D] = 0x10; // latency_timer |
336 |
d->config[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type
|
337 |
// d->config[0x34] = 0x80; // capabilities_pointer
|
338 |
return 0; |
339 |
} |
340 |
|
341 |
static int unin_internal_pci_host_init(PCIDevice *d) |
342 |
{ |
343 |
pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_APPLE); |
344 |
pci_config_set_device_id(d->config, PCI_DEVICE_ID_APPLE_UNI_N_I_PCI); |
345 |
d->config[0x08] = 0x00; // revision |
346 |
pci_config_set_class(d->config, PCI_CLASS_BRIDGE_HOST); |
347 |
d->config[0x0C] = 0x08; // cache_line_size |
348 |
d->config[0x0D] = 0x10; // latency_timer |
349 |
d->config[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type
|
350 |
d->config[0x34] = 0x00; // capabilities_pointer |
351 |
return 0; |
352 |
} |
353 |
|
354 |
static PCIDeviceInfo unin_main_pci_host_info = {
|
355 |
.qdev.name = "Uni-north main",
|
356 |
.qdev.size = sizeof(PCIDevice),
|
357 |
.init = unin_main_pci_host_init, |
358 |
}; |
359 |
|
360 |
static PCIDeviceInfo dec_21154_pci_host_info = {
|
361 |
.qdev.name = "DEC 21154",
|
362 |
.qdev.size = sizeof(PCIDevice),
|
363 |
.init = dec_21154_pci_host_init, |
364 |
}; |
365 |
|
366 |
static PCIDeviceInfo unin_agp_pci_host_info = {
|
367 |
.qdev.name = "Uni-north AGP",
|
368 |
.qdev.size = sizeof(PCIDevice),
|
369 |
.init = unin_agp_pci_host_init, |
370 |
}; |
371 |
|
372 |
static PCIDeviceInfo unin_internal_pci_host_info = {
|
373 |
.qdev.name = "Uni-north internal",
|
374 |
.qdev.size = sizeof(PCIDevice),
|
375 |
.init = unin_internal_pci_host_init, |
376 |
}; |
377 |
|
378 |
static void unin_register_devices(void) |
379 |
{ |
380 |
sysbus_register_dev("Uni-north main", sizeof(UNINState), |
381 |
pci_unin_main_init_device); |
382 |
pci_qdev_register(&unin_main_pci_host_info); |
383 |
sysbus_register_dev("DEC 21154", sizeof(UNINState), |
384 |
pci_dec_21154_init_device); |
385 |
pci_qdev_register(&dec_21154_pci_host_info); |
386 |
sysbus_register_dev("Uni-north AGP", sizeof(UNINState), |
387 |
pci_unin_agp_init_device); |
388 |
pci_qdev_register(&unin_agp_pci_host_info); |
389 |
sysbus_register_dev("Uni-north internal", sizeof(UNINState), |
390 |
pci_unin_internal_init_device); |
391 |
pci_qdev_register(&unin_internal_pci_host_info); |
392 |
} |
393 |
|
394 |
device_init(unin_register_devices) |