2 * QEMU PowerPC CHRP (currently NewWorld PowerMac) hardware System Emulator
4 * Copyright (c) 2004-2007 Fabrice Bellard
5 * Copyright (c) 2007 Jocelyn Mayer
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28 #include "mac_dbdma.h"
45 #define VGA_BIOS_SIZE 65536
46 #define CFG_ADDR 0xf0000510
52 #define UNIN_DPRINTF(fmt, ...) \
53 do { printf("UNIN: " fmt , ## __VA_ARGS__); } while (0)
55 #define UNIN_DPRINTF(fmt, ...)
59 static void unin_writel (void *opaque
, target_phys_addr_t addr
, uint32_t value
)
61 UNIN_DPRINTF("writel addr " TARGET_FMT_plx
" val %x\n", addr
, value
);
64 static uint32_t unin_readl (void *opaque
, target_phys_addr_t addr
)
69 UNIN_DPRINTF("readl addr " TARGET_FMT_plx
" val %x\n", addr
, value
);
74 static CPUWriteMemoryFunc
* const unin_write
[] = {
80 static CPUReadMemoryFunc
* const unin_read
[] = {
86 static int fw_cfg_boot_set(void *opaque
, const char *boot_device
)
88 fw_cfg_add_i16(opaque
, FW_CFG_BOOT_DEVICE
, boot_device
[0]);
92 /* PowerPC Mac99 hardware initialisation */
93 static void ppc_core99_init (ram_addr_t ram_size
,
94 const char *boot_device
,
95 const char *kernel_filename
,
96 const char *kernel_cmdline
,
97 const char *initrd_filename
,
98 const char *cpu_model
)
100 CPUState
*env
= NULL
, *envs
[MAX_CPUS
];
102 qemu_irq
*pic
, **openpic_irqs
;
105 ram_addr_t ram_offset
, bios_offset
, vga_bios_offset
;
106 uint32_t kernel_base
, kernel_size
, initrd_base
, initrd_size
;
108 MacIONVRAMState
*nvr
;
110 int vga_bios_size
, bios_size
;
111 int pic_mem_index
, dbdma_mem_index
, cuda_mem_index
, escc_mem_index
;
113 DriveInfo
*hd
[MAX_IDE_BUS
* MAX_IDE_DEVS
];
116 uint8_t *vga_bios_ptr
;
119 linux_boot
= (kernel_filename
!= NULL
);
122 if (cpu_model
== NULL
)
128 for (i
= 0; i
< smp_cpus
; i
++) {
129 env
= cpu_init(cpu_model
);
131 fprintf(stderr
, "Unable to find PowerPC CPU definition\n");
134 /* Set time-base frequency to 100 Mhz */
135 cpu_ppc_tb_init(env
, 100UL * 1000UL * 1000UL);
137 env
->osi_call
= vga_osi_call
;
139 qemu_register_reset((QEMUResetHandler
*)&cpu_reset
, env
);
143 /* Make sure all register sets take effect */
144 cpu_synchronize_state(env
);
147 ram_offset
= qemu_ram_alloc(ram_size
);
148 cpu_register_physical_memory(0, ram_size
, ram_offset
);
150 /* allocate and load BIOS */
151 bios_offset
= qemu_ram_alloc(BIOS_SIZE
);
152 if (bios_name
== NULL
)
153 bios_name
= PROM_FILENAME
;
154 filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, bios_name
);
155 cpu_register_physical_memory(PROM_ADDR
, BIOS_SIZE
, bios_offset
| IO_MEM_ROM
);
157 /* Load OpenBIOS (ELF) */
159 bios_size
= load_elf(filename
, 0, NULL
, NULL
, NULL
, 1, ELF_MACHINE
, 0);
165 if (bios_size
< 0 || bios_size
> BIOS_SIZE
) {
166 hw_error("qemu: could not load PowerPC bios '%s'\n", bios_name
);
170 /* allocate and load VGA BIOS */
171 vga_bios_offset
= qemu_ram_alloc(VGA_BIOS_SIZE
);
172 vga_bios_ptr
= qemu_get_ram_ptr(vga_bios_offset
);
173 filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, VGABIOS_FILENAME
);
175 vga_bios_size
= load_image(filename
, vga_bios_ptr
+ 8);
180 if (vga_bios_size
< 0) {
181 /* if no bios is present, we can still work */
182 fprintf(stderr
, "qemu: warning: could not load VGA bios '%s'\n",
186 /* set a specific header (XXX: find real Apple format for NDRV
188 vga_bios_ptr
[0] = 'N';
189 vga_bios_ptr
[1] = 'D';
190 vga_bios_ptr
[2] = 'R';
191 vga_bios_ptr
[3] = 'V';
192 cpu_to_be32w((uint32_t *)(vga_bios_ptr
+ 4), vga_bios_size
);
195 /* Round to page boundary */
196 vga_bios_size
= (vga_bios_size
+ TARGET_PAGE_SIZE
- 1) &
201 uint64_t lowaddr
= 0;
209 kernel_base
= KERNEL_LOAD_ADDR
;
211 /* Now we can load the kernel. The first step tries to load the kernel
212 supposing PhysAddr = 0x00000000. If that was wrong the kernel is
213 loaded again, the new PhysAddr being computed from lowaddr. */
214 kernel_size
= load_elf(kernel_filename
, kernel_base
, NULL
, &lowaddr
, NULL
,
216 if (kernel_size
> 0 && lowaddr
!= KERNEL_LOAD_ADDR
) {
217 kernel_size
= load_elf(kernel_filename
, (2 * kernel_base
) - lowaddr
,
218 NULL
, NULL
, NULL
, 1, ELF_MACHINE
, 0);
221 kernel_size
= load_aout(kernel_filename
, kernel_base
,
222 ram_size
- kernel_base
, bswap_needed
,
225 kernel_size
= load_image_targphys(kernel_filename
,
227 ram_size
- kernel_base
);
228 if (kernel_size
< 0) {
229 hw_error("qemu: could not load kernel '%s'\n", kernel_filename
);
233 if (initrd_filename
) {
234 initrd_base
= INITRD_LOAD_ADDR
;
235 initrd_size
= load_image_targphys(initrd_filename
, initrd_base
,
236 ram_size
- initrd_base
);
237 if (initrd_size
< 0) {
238 hw_error("qemu: could not load initial ram disk '%s'\n",
246 ppc_boot_device
= 'm';
252 ppc_boot_device
= '\0';
253 /* We consider that NewWorld PowerMac never have any floppy drive
254 * For now, OHW cannot boot from the network.
256 for (i
= 0; boot_device
[i
] != '\0'; i
++) {
257 if (boot_device
[i
] >= 'c' && boot_device
[i
] <= 'f') {
258 ppc_boot_device
= boot_device
[i
];
262 if (ppc_boot_device
== '\0') {
263 fprintf(stderr
, "No valid boot device for Mac99 machine\n");
268 isa_mem_base
= 0x80000000;
270 /* Register 8 MB of ISA IO space */
271 isa_mmio_init(0xf2000000, 0x00800000);
274 unin_memory
= cpu_register_io_memory(unin_read
, unin_write
, NULL
);
275 cpu_register_physical_memory(0xf8000000, 0x00001000, unin_memory
);
277 openpic_irqs
= qemu_mallocz(smp_cpus
* sizeof(qemu_irq
*));
279 qemu_mallocz(smp_cpus
* sizeof(qemu_irq
) * OPENPIC_OUTPUT_NB
);
280 for (i
= 0; i
< smp_cpus
; i
++) {
281 /* Mac99 IRQ connection between OpenPIC outputs pins
282 * and PowerPC input pins
284 switch (PPC_INPUT(env
)) {
285 case PPC_FLAGS_INPUT_6xx
:
286 openpic_irqs
[i
] = openpic_irqs
[0] + (i
* OPENPIC_OUTPUT_NB
);
287 openpic_irqs
[i
][OPENPIC_OUTPUT_INT
] =
288 ((qemu_irq
*)env
->irq_inputs
)[PPC6xx_INPUT_INT
];
289 openpic_irqs
[i
][OPENPIC_OUTPUT_CINT
] =
290 ((qemu_irq
*)env
->irq_inputs
)[PPC6xx_INPUT_INT
];
291 openpic_irqs
[i
][OPENPIC_OUTPUT_MCK
] =
292 ((qemu_irq
*)env
->irq_inputs
)[PPC6xx_INPUT_MCP
];
293 /* Not connected ? */
294 openpic_irqs
[i
][OPENPIC_OUTPUT_DEBUG
] = NULL
;
296 openpic_irqs
[i
][OPENPIC_OUTPUT_RESET
] =
297 ((qemu_irq
*)env
->irq_inputs
)[PPC6xx_INPUT_HRESET
];
299 #if defined(TARGET_PPC64)
300 case PPC_FLAGS_INPUT_970
:
301 openpic_irqs
[i
] = openpic_irqs
[0] + (i
* OPENPIC_OUTPUT_NB
);
302 openpic_irqs
[i
][OPENPIC_OUTPUT_INT
] =
303 ((qemu_irq
*)env
->irq_inputs
)[PPC970_INPUT_INT
];
304 openpic_irqs
[i
][OPENPIC_OUTPUT_CINT
] =
305 ((qemu_irq
*)env
->irq_inputs
)[PPC970_INPUT_INT
];
306 openpic_irqs
[i
][OPENPIC_OUTPUT_MCK
] =
307 ((qemu_irq
*)env
->irq_inputs
)[PPC970_INPUT_MCP
];
308 /* Not connected ? */
309 openpic_irqs
[i
][OPENPIC_OUTPUT_DEBUG
] = NULL
;
311 openpic_irqs
[i
][OPENPIC_OUTPUT_RESET
] =
312 ((qemu_irq
*)env
->irq_inputs
)[PPC970_INPUT_HRESET
];
314 #endif /* defined(TARGET_PPC64) */
316 hw_error("Bus model not supported on mac99 machine\n");
320 pic
= openpic_init(NULL
, &pic_mem_index
, smp_cpus
, openpic_irqs
, NULL
);
321 if (PPC_INPUT(env
) == PPC_FLAGS_INPUT_970
) {
322 /* 970 gets a U3 bus */
323 pci_bus
= pci_pmac_u3_init(pic
);
324 machine_arch
= ARCH_MAC99_U3
;
326 pci_bus
= pci_pmac_init(pic
);
327 machine_arch
= ARCH_MAC99
;
329 /* init basic PC hardware */
330 pci_vga_init(pci_bus
, vga_bios_offset
, vga_bios_size
);
332 escc_mem_index
= escc_init(0x80013000, pic
[0x25], pic
[0x24],
333 serial_hds
[0], serial_hds
[1], ESCC_CLOCK
, 4);
335 for(i
= 0; i
< nb_nics
; i
++)
336 pci_nic_init_nofail(&nd_table
[i
], "ne2k_pci", NULL
);
338 if (drive_get_max_bus(IF_IDE
) >= MAX_IDE_BUS
) {
339 fprintf(stderr
, "qemu: too many IDE bus\n");
342 for(i
= 0; i
< MAX_IDE_BUS
* MAX_IDE_DEVS
; i
++) {
343 hd
[i
] = drive_get(IF_IDE
, i
/ MAX_IDE_DEVS
, i
% MAX_IDE_DEVS
);
345 dbdma
= DBDMA_init(&dbdma_mem_index
);
346 pci_cmd646_ide_init(pci_bus
, hd
, 0);
348 /* cuda also initialize ADB */
349 cuda_init(&cuda_mem_index
, pic
[0x19]);
351 adb_kbd_init(&adb_bus
);
352 adb_mouse_init(&adb_bus
);
355 macio_init(pci_bus
, PCI_DEVICE_ID_APPLE_UNI_N_KEYL
, 0, pic_mem_index
,
356 dbdma_mem_index
, cuda_mem_index
, NULL
, 0, NULL
,
360 usb_ohci_init_pci(pci_bus
, -1);
363 if (graphic_depth
!= 15 && graphic_depth
!= 32 && graphic_depth
!= 8)
366 /* The NewWorld NVRAM is not located in the MacIO device */
367 nvr
= macio_nvram_init(&nvram_mem_index
, 0x2000, 1);
368 pmac_format_nvram_partition(nvr
, 0x2000);
369 macio_nvram_map(nvr
, 0xFFF04000);
370 /* No PCI init: the BIOS will do it */
372 fw_cfg
= fw_cfg_init(0, 0, CFG_ADDR
, CFG_ADDR
+ 2);
373 fw_cfg_add_i32(fw_cfg
, FW_CFG_ID
, 1);
374 fw_cfg_add_i64(fw_cfg
, FW_CFG_RAM_SIZE
, (uint64_t)ram_size
);
375 fw_cfg_add_i16(fw_cfg
, FW_CFG_MACHINE_ID
, machine_arch
);
376 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_ADDR
, kernel_base
);
377 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_SIZE
, kernel_size
);
378 if (kernel_cmdline
) {
379 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_CMDLINE
, CMDLINE_ADDR
);
380 pstrcpy_targphys("cmdline", CMDLINE_ADDR
, TARGET_PAGE_SIZE
, kernel_cmdline
);
382 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_CMDLINE
, 0);
384 fw_cfg_add_i32(fw_cfg
, FW_CFG_INITRD_ADDR
, initrd_base
);
385 fw_cfg_add_i32(fw_cfg
, FW_CFG_INITRD_SIZE
, initrd_size
);
386 fw_cfg_add_i16(fw_cfg
, FW_CFG_BOOT_DEVICE
, ppc_boot_device
);
388 fw_cfg_add_i16(fw_cfg
, FW_CFG_PPC_WIDTH
, graphic_width
);
389 fw_cfg_add_i16(fw_cfg
, FW_CFG_PPC_HEIGHT
, graphic_height
);
390 fw_cfg_add_i16(fw_cfg
, FW_CFG_PPC_DEPTH
, graphic_depth
);
392 qemu_register_boot_set(fw_cfg_boot_set
, fw_cfg
);
395 static QEMUMachine core99_machine
= {
397 .desc
= "Mac99 based PowerMAC",
398 .init
= ppc_core99_init
,
399 .max_cpus
= MAX_CPUS
,
405 static void core99_machine_init(void)
407 qemu_register_machine(&core99_machine
);
410 machine_init(core99_machine_init
);