2 * QEMU PPC CHRP/PMAC hardware System Emulator
4 * Copyright (c) 2004 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
26 #define BIOS_FILENAME "ppc_rom.bin"
27 #define NVRAM_SIZE 0x2000
29 #define KERNEL_LOAD_ADDR 0x01000000
30 #define INITRD_LOAD_ADDR 0x01800000
32 /* MacIO devices (mapped inside the MacIO address space): CUDA, DBDMA,
33 NVRAM (not implemented). */
35 static int dbdma_mem_index;
36 static int cuda_mem_index;
37 static int ide0_mem_index = -1;
38 static int ide1_mem_index = -1;
39 static int openpic_mem_index = -1;
40 static int heathrow_pic_mem_index = -1;
42 /* DBDMA: currently no op - should suffice right now */
44 static void dbdma_writeb (void *opaque, target_phys_addr_t addr, uint32_t value)
46 printf("%s: 0x%08x <= 0x%08x\n", __func__, addr, value);
49 static void dbdma_writew (void *opaque, target_phys_addr_t addr, uint32_t value)
53 static void dbdma_writel (void *opaque, target_phys_addr_t addr, uint32_t value)
57 static uint32_t dbdma_readb (void *opaque, target_phys_addr_t addr)
59 printf("%s: 0x%08x => 0x00000000\n", __func__, addr);
63 static uint32_t dbdma_readw (void *opaque, target_phys_addr_t addr)
68 static uint32_t dbdma_readl (void *opaque, target_phys_addr_t addr)
73 static CPUWriteMemoryFunc *dbdma_write[] = {
79 static CPUReadMemoryFunc *dbdma_read[] = {
85 static void macio_map(PCIDevice *pci_dev, int region_num,
86 uint32_t addr, uint32_t size, int type)
88 if (heathrow_pic_mem_index >= 0) {
89 cpu_register_physical_memory(addr + 0x00000, 0x1000,
90 heathrow_pic_mem_index);
92 cpu_register_physical_memory(addr + 0x08000, 0x1000, dbdma_mem_index);
93 cpu_register_physical_memory(addr + 0x16000, 0x2000, cuda_mem_index);
94 if (ide0_mem_index >= 0)
95 cpu_register_physical_memory(addr + 0x1f000, 0x1000, ide0_mem_index);
96 if (ide1_mem_index >= 0)
97 cpu_register_physical_memory(addr + 0x20000, 0x1000, ide1_mem_index);
98 if (openpic_mem_index >= 0) {
99 cpu_register_physical_memory(addr + 0x40000, 0x40000,
104 static void macio_init(PCIBus *bus)
108 d = pci_register_device(bus, "macio", sizeof(PCIDevice),
110 /* Note: this code is strongly inspirated from the corresponding code
112 d->config[0x00] = 0x6b; // vendor_id
113 d->config[0x01] = 0x10;
114 d->config[0x02] = 0x22;
115 d->config[0x03] = 0x00;
117 d->config[0x0a] = 0x00; // class_sub = pci2pci
118 d->config[0x0b] = 0xff; // class_base = bridge
119 d->config[0x0e] = 0x00; // header_type
121 d->config[0x3d] = 0x01; // interrupt on pin 1
123 dbdma_mem_index = cpu_register_io_memory(0, dbdma_read, dbdma_write, NULL);
125 pci_register_io_region(d, 0, 0x80000,
126 PCI_ADDRESS_SPACE_MEM, macio_map);
130 static void unin_writel (void *opaque, target_phys_addr_t addr, uint32_t value)
134 static uint32_t unin_readl (void *opaque, target_phys_addr_t addr)
139 static CPUWriteMemoryFunc *unin_write[] = {
145 static CPUReadMemoryFunc *unin_read[] = {
151 /* temporary frame buffer OSI calls for the video.x driver. The right
152 solution is to modify the driver to use VGA PCI I/Os */
153 static int vga_osi_call(CPUState *env)
155 static int vga_vbl_enabled;
158 // printf("osi_call R5=%d\n", env->gpr[5]);
160 /* same handler as PearPC, coming from the original MOL video
162 switch(env->gpr[5]) {
165 case 28: /* set_vmode */
166 if (env->gpr[6] != 1 || env->gpr[7] != 0)
171 case 29: /* get_vmode_info */
172 if (env->gpr[6] != 0) {
173 if (env->gpr[6] != 1 || env->gpr[7] != 0) {
179 env->gpr[4] = (1 << 16) | 1; /* num_vmodes, cur_vmode */
180 env->gpr[5] = (1 << 16) | 0; /* num_depths, cur_depth_mode */
181 env->gpr[6] = (graphic_width << 16) | graphic_height; /* w, h */
182 env->gpr[7] = 85 << 16; /* refresh rate */
183 env->gpr[8] = (graphic_depth + 7) & ~7; /* depth (round to byte) */
184 linesize = ((graphic_depth + 7) >> 3) * graphic_width;
185 linesize = (linesize + 3) & ~3;
186 env->gpr[9] = (linesize << 16) | 0; /* row_bytes, offset */
188 case 31: /* set_video power */
191 case 39: /* video_ctrl */
192 if (env->gpr[6] == 0 || env->gpr[6] == 1)
193 vga_vbl_enabled = env->gpr[6];
198 case 59: /* set_color */
199 /* R6 = index, R7 = RGB */
202 case 64: /* get color */
206 case 116: /* set hwcursor */
207 /* R6 = x, R7 = y, R8 = visible, R9 = data */
210 fprintf(stderr, "unsupported OSI call R5=%08x\n", env->gpr[5]);
213 return 1; /* osi_call handled */
216 /* PowerPC CHRP hardware initialisation */
217 static void ppc_chrp_init(int ram_size, int vga_ram_size, int boot_device,
218 DisplayState *ds, const char **fd_filename,
220 const char *kernel_filename,
221 const char *kernel_cmdline,
222 const char *initrd_filename,
229 int PPC_io_memory, unin_memory;
230 int ret, linux_boot, i;
231 unsigned long bios_offset;
232 uint32_t kernel_base, kernel_size, initrd_base, initrd_size;
234 const char *arch_name;
236 linux_boot = (kernel_filename != NULL);
239 cpu_register_physical_memory(0, ram_size, IO_MEM_RAM);
241 /* allocate and load BIOS */
242 bios_offset = ram_size + vga_ram_size;
243 snprintf(buf, sizeof(buf), "%s/%s", bios_dir, BIOS_FILENAME);
244 ret = load_image(buf, phys_ram_base + bios_offset);
245 if (ret != BIOS_SIZE) {
246 fprintf(stderr, "qemu: could not load PPC PREP bios '%s'\n", buf);
249 cpu_register_physical_memory((uint32_t)(-BIOS_SIZE),
250 BIOS_SIZE, bios_offset | IO_MEM_ROM);
251 cpu_single_env->nip = 0xfffffffc;
254 kernel_base = KERNEL_LOAD_ADDR;
255 /* now we can load the kernel */
256 kernel_size = load_image(kernel_filename, phys_ram_base + kernel_base);
257 if (kernel_size < 0) {
258 fprintf(stderr, "qemu: could not load kernel '%s'\n",
263 if (initrd_filename) {
264 initrd_base = INITRD_LOAD_ADDR;
265 initrd_size = load_image(initrd_filename,
266 phys_ram_base + initrd_base);
267 if (initrd_size < 0) {
268 fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
283 /* Register CPU as a 74x/75x */
284 cpu_ppc_register(cpu_single_env, 0x00080000);
285 /* Set time-base frequency to 10 Mhz */
286 cpu_ppc_tb_init(cpu_single_env, 10UL * 1000UL * 1000UL);
288 cpu_single_env->osi_call = vga_osi_call;
291 isa_mem_base = 0x80000000;
292 pci_bus = pci_grackle_init(0xfec00000);
294 /* Register 2 MB of ISA IO space */
295 PPC_io_memory = cpu_register_io_memory(0, PPC_io_read, PPC_io_write, NULL);
296 cpu_register_physical_memory(0xfe000000, 0x00200000, PPC_io_memory);
298 /* init basic PC hardware */
299 vga_initialize(pci_bus, ds, phys_ram_base + ram_size, ram_size,
301 pic = heathrow_pic_init(&heathrow_pic_mem_index);
302 set_irq = heathrow_pic_set_irq;
303 pci_set_pic(pci_bus, set_irq, pic);
305 /* XXX: suppress that */
308 /* XXX: use Mac Serial port */
309 serial_init(0x3f8, 4, serial_hds[0]);
311 for(i = 0; i < nb_nics; i++) {
312 pci_ne2000_init(pci_bus, &nd_table[i]);
315 pci_cmd646_ide_init(pci_bus, &bs_table[0], 0);
317 /* cuda also initialize ADB */
318 cuda_mem_index = cuda_init(set_irq, pic, 0x12);
320 adb_kbd_init(&adb_bus);
321 adb_mouse_init(&adb_bus);
325 nvram = m48t59_init(8, 0xFFF04000, 0x0074, NVRAM_SIZE);
327 arch_name = "HEATHROW";
329 isa_mem_base = 0x80000000;
330 pci_bus = pci_pmac_init();
332 /* Register 8 MB of ISA IO space */
333 PPC_io_memory = cpu_register_io_memory(0, PPC_io_read, PPC_io_write, NULL);
334 cpu_register_physical_memory(0xF2000000, 0x00800000, PPC_io_memory);
337 unin_memory = cpu_register_io_memory(0, unin_read, unin_write, NULL);
338 cpu_register_physical_memory(0xf8000000, 0x00001000, unin_memory);
340 /* init basic PC hardware */
341 vga_initialize(pci_bus, ds, phys_ram_base + ram_size, ram_size,
343 pic = openpic_init(NULL, &openpic_mem_index, 1);
344 set_irq = openpic_set_irq;
345 pci_set_pic(pci_bus, set_irq, pic);
347 /* XXX: suppress that */
350 /* XXX: use Mac Serial port */
351 serial_init(0x3f8, 4, serial_hds[0]);
353 for(i = 0; i < nb_nics; i++) {
354 pci_ne2000_init(pci_bus, &nd_table[i]);
358 ide0_mem_index = pmac_ide_init(&bs_table[0], set_irq, pic, 0x13);
359 ide1_mem_index = pmac_ide_init(&bs_table[2], set_irq, pic, 0x14);
361 pci_cmd646_ide_init(pci_bus, &bs_table[0], 0);
363 /* cuda also initialize ADB */
364 cuda_mem_index = cuda_init(set_irq, pic, 0x19);
366 adb_kbd_init(&adb_bus);
367 adb_mouse_init(&adb_bus);
371 nvram = m48t59_init(8, 0xFFF04000, 0x0074, NVRAM_SIZE);
376 if (graphic_depth != 15 && graphic_depth != 32 && graphic_depth != 8)
379 PPC_NVRAM_set_params(nvram, NVRAM_SIZE, arch_name, ram_size, boot_device,
380 kernel_base, kernel_size,
382 initrd_base, initrd_size,
383 /* XXX: need an option to load a NVRAM image */
385 graphic_width, graphic_height, graphic_depth);
386 /* No PCI init: the BIOS will do it */
388 /* Special port to get debug messages from Open-Firmware */
389 register_ioport_write(0x0F00, 4, 1, &PPC_debug_write, NULL);
392 static void ppc_core99_init(int ram_size, int vga_ram_size, int boot_device,
393 DisplayState *ds, const char **fd_filename,
395 const char *kernel_filename,
396 const char *kernel_cmdline,
397 const char *initrd_filename)
399 ppc_chrp_init(ram_size, vga_ram_size, boot_device,
400 ds, fd_filename, snapshot,
401 kernel_filename, kernel_cmdline,
405 static void ppc_heathrow_init(int ram_size, int vga_ram_size, int boot_device,
406 DisplayState *ds, const char **fd_filename,
408 const char *kernel_filename,
409 const char *kernel_cmdline,
410 const char *initrd_filename)
412 ppc_chrp_init(ram_size, vga_ram_size, boot_device,
413 ds, fd_filename, snapshot,
414 kernel_filename, kernel_cmdline,
418 QEMUMachine core99_machine = {
420 "Core99 based PowerMAC",
424 QEMUMachine heathrow_machine = {
426 "Heathrow based PowerMAC",