2 * QEMU Uninorth PCI host (for all Mac99 and newer machines)
4 * Copyright (c) 2006 Fabrice Bellard
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
32 #define UNIN_DPRINTF(fmt, ...) \
33 do { printf("UNIN: " fmt , ## __VA_ARGS__); } while (0)
35 #define UNIN_DPRINTF(fmt, ...)
38 typedef target_phys_addr_t pci_addr_t
;
41 typedef struct UNINState
{
43 PCIHostState host_state
;
46 static void pci_unin_main_config_writel (void *opaque
, target_phys_addr_t addr
,
49 UNINState
*s
= opaque
;
51 UNIN_DPRINTF("config_writel addr " TARGET_FMT_plx
" val %x\n", addr
, val
);
52 #ifdef TARGET_WORDS_BIGENDIAN
56 s
->host_state
.config_reg
= val
;
59 static uint32_t pci_unin_main_config_readl (void *opaque
,
60 target_phys_addr_t addr
)
62 UNINState
*s
= opaque
;
65 val
= s
->host_state
.config_reg
;
66 #ifdef TARGET_WORDS_BIGENDIAN
69 UNIN_DPRINTF("config_readl addr " TARGET_FMT_plx
" val %x\n", addr
, val
);
74 static CPUWriteMemoryFunc
*pci_unin_main_config_write
[] = {
75 &pci_unin_main_config_writel
,
76 &pci_unin_main_config_writel
,
77 &pci_unin_main_config_writel
,
80 static CPUReadMemoryFunc
*pci_unin_main_config_read
[] = {
81 &pci_unin_main_config_readl
,
82 &pci_unin_main_config_readl
,
83 &pci_unin_main_config_readl
,
86 static CPUWriteMemoryFunc
*pci_unin_main_write
[] = {
87 &pci_host_data_writeb
,
88 &pci_host_data_writew
,
89 &pci_host_data_writel
,
92 static CPUReadMemoryFunc
*pci_unin_main_read
[] = {
98 static void pci_unin_config_writel (void *opaque
, target_phys_addr_t addr
,
101 UNINState
*s
= opaque
;
103 s
->host_state
.config_reg
= val
;
106 static uint32_t pci_unin_config_readl (void *opaque
,
107 target_phys_addr_t addr
)
109 UNINState
*s
= opaque
;
111 return s
->host_state
.config_reg
;
114 static CPUWriteMemoryFunc
*pci_unin_config_write
[] = {
115 &pci_unin_config_writel
,
116 &pci_unin_config_writel
,
117 &pci_unin_config_writel
,
120 static CPUReadMemoryFunc
*pci_unin_config_read
[] = {
121 &pci_unin_config_readl
,
122 &pci_unin_config_readl
,
123 &pci_unin_config_readl
,
126 static CPUWriteMemoryFunc
*pci_unin_write
[] = {
127 &pci_host_data_writeb
,
128 &pci_host_data_writew
,
129 &pci_host_data_writel
,
132 static CPUReadMemoryFunc
*pci_unin_read
[] = {
133 &pci_host_data_readb
,
134 &pci_host_data_readw
,
135 &pci_host_data_readl
,
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
)
141 return (irq_num
+ (pci_dev
->devfn
>> 3)) & 3;
144 static void pci_unin_set_irq(qemu_irq
*pic
, int irq_num
, int level
)
146 qemu_set_irq(pic
[irq_num
+ 8], level
);
149 static void pci_unin_save(QEMUFile
* f
, void *opaque
)
151 PCIDevice
*d
= opaque
;
153 pci_device_save(d
, f
);
156 static int pci_unin_load(QEMUFile
* f
, void *opaque
, int version_id
)
158 PCIDevice
*d
= opaque
;
163 return pci_device_load(d
, f
);
166 static void pci_unin_reset(void *opaque
)
170 static void pci_unin_main_init_device(SysBusDevice
*dev
)
173 int pci_mem_config
, pci_mem_data
;
175 /* Use values found on a real PowerMac */
176 /* Uninorth main bus */
177 s
= FROM_SYSBUS(UNINState
, dev
);
179 pci_mem_config
= cpu_register_io_memory(pci_unin_main_config_read
,
180 pci_unin_main_config_write
, s
);
181 pci_mem_data
= cpu_register_io_memory(pci_unin_main_read
,
182 pci_unin_main_write
, &s
->host_state
);
184 sysbus_init_mmio(dev
, 0x1000, pci_mem_config
);
185 sysbus_init_mmio(dev
, 0x1000, pci_mem_data
);
187 register_savevm("uninorth", 0, 1, pci_unin_save
, pci_unin_load
, &s
->host_state
);
188 qemu_register_reset(pci_unin_reset
, &s
->host_state
);
189 pci_unin_reset(&s
->host_state
);
192 static void pci_dec_21154_init_device(SysBusDevice
*dev
)
195 int pci_mem_config
, pci_mem_data
;
197 /* Uninorth bridge */
198 s
= FROM_SYSBUS(UNINState
, dev
);
200 // XXX: s = &pci_bridge[2];
201 pci_mem_config
= cpu_register_io_memory(pci_unin_config_read
,
202 pci_unin_config_write
, s
);
203 pci_mem_data
= cpu_register_io_memory(pci_unin_main_read
,
204 pci_unin_main_write
, &s
->host_state
);
205 sysbus_init_mmio(dev
, 0x1000, pci_mem_config
);
206 sysbus_init_mmio(dev
, 0x1000, pci_mem_data
);
209 static void pci_unin_agp_init_device(SysBusDevice
*dev
)
212 int pci_mem_config
, pci_mem_data
;
214 /* Uninorth AGP bus */
215 s
= FROM_SYSBUS(UNINState
, dev
);
217 pci_mem_config
= cpu_register_io_memory(pci_unin_config_read
,
218 pci_unin_config_write
, s
);
219 pci_mem_data
= cpu_register_io_memory(pci_unin_main_read
,
220 pci_unin_main_write
, &s
->host_state
);
221 sysbus_init_mmio(dev
, 0x1000, pci_mem_config
);
222 sysbus_init_mmio(dev
, 0x1000, pci_mem_data
);
225 static void pci_unin_internal_init_device(SysBusDevice
*dev
)
228 int pci_mem_config
, pci_mem_data
;
230 /* Uninorth internal bus */
231 s
= FROM_SYSBUS(UNINState
, dev
);
233 pci_mem_config
= cpu_register_io_memory(pci_unin_config_read
,
234 pci_unin_config_write
, s
);
235 pci_mem_data
= cpu_register_io_memory(pci_unin_read
,
237 sysbus_init_mmio(dev
, 0x1000, pci_mem_config
);
238 sysbus_init_mmio(dev
, 0x1000, pci_mem_data
);
241 PCIBus
*pci_pmac_init(qemu_irq
*pic
)
247 /* Use values found on a real PowerMac */
248 /* Uninorth main bus */
249 dev
= qdev_create(NULL
, "Uni-north main");
251 s
= sysbus_from_qdev(dev
);
252 d
= FROM_SYSBUS(UNINState
, s
);
253 d
->host_state
.bus
= pci_register_bus(NULL
, "pci",
254 pci_unin_set_irq
, pci_unin_map_irq
,
257 pci_create_simple(d
->host_state
.bus
, 11 << 3, "Uni-north main");
259 sysbus_mmio_map(s
, 0, 0xf2800000);
260 sysbus_mmio_map(s
, 1, 0xf2c00000);
262 /* DEC 21154 bridge */
264 /* XXX: not activated as PPC BIOS doesn't handle multiple buses properly */
265 pci_create_simple(d
->host_state
.bus
, 12 << 3, "DEC 21154");
268 /* Uninorth AGP bus */
269 pci_create_simple(d
->host_state
.bus
, 13 << 3, "Uni-north AGP");
271 /* Uninorth internal bus */
273 /* XXX: not needed for now */
274 pci_create_simple(d
->host_state
.bus
, 14 << 3, "Uni-north internal");
277 return d
->host_state
.bus
;
280 static void unin_main_pci_host_init(PCIDevice
*d
)
282 pci_config_set_vendor_id(d
->config
, PCI_VENDOR_ID_APPLE
);
283 pci_config_set_device_id(d
->config
, PCI_DEVICE_ID_APPLE_UNI_N_PCI
);
284 d
->config
[0x08] = 0x00; // revision
285 pci_config_set_class(d
->config
, PCI_CLASS_BRIDGE_HOST
);
286 d
->config
[0x0C] = 0x08; // cache_line_size
287 d
->config
[0x0D] = 0x10; // latency_timer
288 d
->config
[PCI_HEADER_TYPE
] = PCI_HEADER_TYPE_NORMAL
; // header_type
289 d
->config
[0x34] = 0x00; // capabilities_pointer
292 static void dec_21154_pci_host_init(PCIDevice
*d
)
294 /* pci-to-pci bridge */
295 pci_config_set_vendor_id(d
->config
, PCI_VENDOR_ID_DEC
);
296 pci_config_set_device_id(d
->config
, PCI_DEVICE_ID_DEC_21154
);
297 d
->config
[0x08] = 0x05; // revision
298 pci_config_set_class(d
->config
, PCI_CLASS_BRIDGE_PCI
);
299 d
->config
[0x0C] = 0x08; // cache_line_size
300 d
->config
[0x0D] = 0x20; // latency_timer
301 d
->config
[PCI_HEADER_TYPE
] = PCI_HEADER_TYPE_BRIDGE
; // header_type
303 d
->config
[0x18] = 0x01; // primary_bus
304 d
->config
[0x19] = 0x02; // secondary_bus
305 d
->config
[0x1A] = 0x02; // subordinate_bus
306 d
->config
[0x1B] = 0x20; // secondary_latency_timer
307 d
->config
[0x1C] = 0x11; // io_base
308 d
->config
[0x1D] = 0x01; // io_limit
309 d
->config
[0x20] = 0x00; // memory_base
310 d
->config
[0x21] = 0x80;
311 d
->config
[0x22] = 0x00; // memory_limit
312 d
->config
[0x23] = 0x80;
313 d
->config
[0x24] = 0x01; // prefetchable_memory_base
314 d
->config
[0x25] = 0x80;
315 d
->config
[0x26] = 0xF1; // prefectchable_memory_limit
316 d
->config
[0x27] = 0x7F;
317 // d->config[0x34] = 0xdc // capabilities_pointer
320 static void unin_agp_pci_host_init(PCIDevice
*d
)
322 pci_config_set_vendor_id(d
->config
, PCI_VENDOR_ID_APPLE
);
323 pci_config_set_device_id(d
->config
, PCI_DEVICE_ID_APPLE_UNI_N_AGP
);
324 d
->config
[0x08] = 0x00; // revision
325 pci_config_set_class(d
->config
, PCI_CLASS_BRIDGE_HOST
);
326 d
->config
[0x0C] = 0x08; // cache_line_size
327 d
->config
[0x0D] = 0x10; // latency_timer
328 d
->config
[PCI_HEADER_TYPE
] = PCI_HEADER_TYPE_NORMAL
; // header_type
329 // d->config[0x34] = 0x80; // capabilities_pointer
332 static void unin_internal_pci_host_init(PCIDevice
*d
)
334 pci_config_set_vendor_id(d
->config
, PCI_VENDOR_ID_APPLE
);
335 pci_config_set_device_id(d
->config
, PCI_DEVICE_ID_APPLE_UNI_N_I_PCI
);
336 d
->config
[0x08] = 0x00; // revision
337 pci_config_set_class(d
->config
, PCI_CLASS_BRIDGE_HOST
);
338 d
->config
[0x0C] = 0x08; // cache_line_size
339 d
->config
[0x0D] = 0x10; // latency_timer
340 d
->config
[PCI_HEADER_TYPE
] = PCI_HEADER_TYPE_NORMAL
; // header_type
341 d
->config
[0x34] = 0x00; // capabilities_pointer
344 static PCIDeviceInfo unin_main_pci_host_info
= {
345 .qdev
.name
= "Uni-north main",
346 .qdev
.size
= sizeof(PCIDevice
),
347 .init
= unin_main_pci_host_init
,
350 static PCIDeviceInfo dec_21154_pci_host_info
= {
351 .qdev
.name
= "DEC 21154",
352 .qdev
.size
= sizeof(PCIDevice
),
353 .init
= dec_21154_pci_host_init
,
356 static PCIDeviceInfo unin_agp_pci_host_info
= {
357 .qdev
.name
= "Uni-north AGP",
358 .qdev
.size
= sizeof(PCIDevice
),
359 .init
= unin_agp_pci_host_init
,
362 static PCIDeviceInfo unin_internal_pci_host_info
= {
363 .qdev
.name
= "Uni-north internal",
364 .qdev
.size
= sizeof(PCIDevice
),
365 .init
= unin_internal_pci_host_init
,
368 static void unin_register_devices(void)
370 sysbus_register_dev("Uni-north main", sizeof(UNINState
),
371 pci_unin_main_init_device
);
372 pci_qdev_register(&unin_main_pci_host_info
);
373 sysbus_register_dev("DEC 21154", sizeof(UNINState
),
374 pci_dec_21154_init_device
);
375 pci_qdev_register(&dec_21154_pci_host_info
);
376 sysbus_register_dev("Uni-north AGP", sizeof(UNINState
),
377 pci_unin_agp_init_device
);
378 pci_qdev_register(&unin_agp_pci_host_info
);
379 sysbus_register_dev("Uni-north internal", sizeof(UNINState
),
380 pci_unin_internal_init_device
);
381 pci_qdev_register(&unin_internal_pci_host_info
);
384 device_init(unin_register_devices
)