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
29 static void unin_writel (void *opaque, target_phys_addr_t addr, uint32_t value)
33 static uint32_t unin_readl (void *opaque, target_phys_addr_t addr)
38 static CPUWriteMemoryFunc *unin_write[] = {
44 static CPUReadMemoryFunc *unin_read[] = {
50 /* PowerPC Mac99 hardware initialisation */
51 static void ppc_core99_init (int ram_size, int vga_ram_size, int boot_device,
52 DisplayState *ds, const char **fd_filename,
54 const char *kernel_filename,
55 const char *kernel_cmdline,
56 const char *initrd_filename,
57 const char *cpu_model)
59 CPUState *env, *envs[MAX_CPUS];
61 qemu_irq *pic, **openpic_irqs;
64 unsigned long bios_offset, vga_bios_offset;
65 uint32_t kernel_base, kernel_size, initrd_base, initrd_size;
74 int vga_bios_size, bios_size;
76 int pic_mem_index, dbdma_mem_index, cuda_mem_index;
79 linux_boot = (kernel_filename != NULL);
83 if (cpu_model == NULL)
84 cpu_model = "default";
85 ppc_find_by_name(cpu_model, &def);
87 cpu_abort(env, "Unable to find PowerPC CPU definition\n");
89 for (i = 0; i < smp_cpus; i++) {
90 cpu_ppc_register(env, def);
92 /* Set time-base frequency to 100 Mhz */
93 cpu_ppc_tb_init(env, 100UL * 1000UL * 1000UL);
95 env->osi_call = vga_osi_call;
97 qemu_register_reset(&cpu_ppc_reset, env);
98 register_savevm("cpu", 0, 3, cpu_save, cpu_load, env);
101 if (env->nip < 0xFFF80000) {
102 /* Special test for PowerPC 601:
103 * the boot vector is at 0xFFF00100, then we need a 1MB BIOS.
104 * But the NVRAM is located at 0xFFF04000...
106 cpu_abort(env, "Mac99 hardware can not handle 1 MB BIOS\n");
110 cpu_register_physical_memory(0, ram_size, IO_MEM_RAM);
112 /* allocate and load BIOS */
113 bios_offset = ram_size + vga_ram_size;
114 if (bios_name == NULL)
115 bios_name = BIOS_FILENAME;
116 snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
117 bios_size = load_image(buf, phys_ram_base + bios_offset);
118 if (bios_size < 0 || bios_size > BIOS_SIZE) {
119 cpu_abort(env, "qemu: could not load PowerPC bios '%s'\n", buf);
122 bios_size = (bios_size + 0xfff) & ~0xfff;
123 if (bios_size > 0x00080000) {
124 /* As the NVRAM is located at 0xFFF04000, we cannot use 1 MB BIOSes */
125 cpu_abort(env, "Mac99 hardware can not handle 1 MB BIOS\n");
127 cpu_register_physical_memory((uint32_t)(-bios_size),
128 bios_size, bios_offset | IO_MEM_ROM);
130 /* allocate and load VGA BIOS */
131 vga_bios_offset = bios_offset + bios_size;
132 snprintf(buf, sizeof(buf), "%s/%s", bios_dir, VGABIOS_FILENAME);
133 vga_bios_size = load_image(buf, phys_ram_base + vga_bios_offset + 8);
134 if (vga_bios_size < 0) {
135 /* if no bios is present, we can still work */
136 fprintf(stderr, "qemu: warning: could not load VGA bios '%s'\n", buf);
139 /* set a specific header (XXX: find real Apple format for NDRV
141 phys_ram_base[vga_bios_offset] = 'N';
142 phys_ram_base[vga_bios_offset + 1] = 'D';
143 phys_ram_base[vga_bios_offset + 2] = 'R';
144 phys_ram_base[vga_bios_offset + 3] = 'V';
145 cpu_to_be32w((uint32_t *)(phys_ram_base + vga_bios_offset + 4),
149 vga_bios_size = (vga_bios_size + 0xfff) & ~0xfff;
152 kernel_base = KERNEL_LOAD_ADDR;
153 /* now we can load the kernel */
154 kernel_size = load_image(kernel_filename, phys_ram_base + kernel_base);
155 if (kernel_size < 0) {
156 cpu_abort(env, "qemu: could not load kernel '%s'\n",
161 if (initrd_filename) {
162 initrd_base = INITRD_LOAD_ADDR;
163 initrd_size = load_image(initrd_filename,
164 phys_ram_base + initrd_base);
165 if (initrd_size < 0) {
166 cpu_abort(env, "qemu: could not load initial ram disk '%s'\n",
182 isa_mem_base = 0x80000000;
184 /* Register 8 MB of ISA IO space */
185 isa_mmio_init(0xf2000000, 0x00800000);
188 unin_memory = cpu_register_io_memory(0, unin_read, unin_write, NULL);
189 cpu_register_physical_memory(0xf8000000, 0x00001000, unin_memory);
191 openpic_irqs = qemu_mallocz(smp_cpus * sizeof(qemu_irq *));
193 qemu_mallocz(smp_cpus * sizeof(qemu_irq) * OPENPIC_OUTPUT_NB);
194 for (i = 0; i < smp_cpus; i++) {
195 /* Mac99 IRQ connection between OpenPIC outputs pins
196 * and PowerPC input pins
198 switch (PPC_INPUT(env)) {
199 case PPC_FLAGS_INPUT_6xx:
200 openpic_irqs[i] = openpic_irqs[0] + (i * OPENPIC_OUTPUT_NB);
201 openpic_irqs[i][OPENPIC_OUTPUT_INT] =
202 ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_INT];
203 openpic_irqs[i][OPENPIC_OUTPUT_CINT] =
204 ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_INT];
205 openpic_irqs[i][OPENPIC_OUTPUT_MCK] =
206 ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_MCP];
207 /* Not connected ? */
208 openpic_irqs[i][OPENPIC_OUTPUT_DEBUG] = NULL;
210 openpic_irqs[i][OPENPIC_OUTPUT_RESET] =
211 ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_HRESET];
213 #if defined(TARGET_PPC64)
214 case PPC_FLAGS_INPUT_970:
215 openpic_irqs[i] = openpic_irqs[0] + (i * OPENPIC_OUTPUT_NB);
216 openpic_irqs[i][OPENPIC_OUTPUT_INT] =
217 ((qemu_irq *)env->irq_inputs)[PPC970_INPUT_INT];
218 openpic_irqs[i][OPENPIC_OUTPUT_CINT] =
219 ((qemu_irq *)env->irq_inputs)[PPC970_INPUT_INT];
220 openpic_irqs[i][OPENPIC_OUTPUT_MCK] =
221 ((qemu_irq *)env->irq_inputs)[PPC970_INPUT_MCP];
222 /* Not connected ? */
223 openpic_irqs[i][OPENPIC_OUTPUT_DEBUG] = NULL;
225 openpic_irqs[i][OPENPIC_OUTPUT_RESET] =
226 ((qemu_irq *)env->irq_inputs)[PPC970_INPUT_HRESET];
228 #endif /* defined(TARGET_PPC64) */
230 cpu_abort(env, "Bus model not supported on mac99 machine\n");
234 pic = openpic_init(NULL, &pic_mem_index, smp_cpus, openpic_irqs, NULL);
235 pci_bus = pci_pmac_init(pic);
236 /* init basic PC hardware */
237 pci_vga_init(pci_bus, ds, phys_ram_base + ram_size,
238 ram_size, vga_ram_size,
239 vga_bios_offset, vga_bios_size);
241 /* XXX: suppress that */
242 dummy_irq = i8259_init(NULL);
244 /* XXX: use Mac Serial port */
245 serial_init(0x3f8, dummy_irq[4], serial_hds[0]);
246 for(i = 0; i < nb_nics; i++) {
247 if (!nd_table[i].model)
248 nd_table[i].model = "ne2k_pci";
249 pci_nic_init(pci_bus, &nd_table[i], -1);
252 ide_mem_index[0] = pmac_ide_init(&bs_table[0], pic[0x13]);
253 ide_mem_index[1] = pmac_ide_init(&bs_table[2], pic[0x14]);
255 pci_cmd646_ide_init(pci_bus, &bs_table[0], 0);
257 /* cuda also initialize ADB */
258 cuda_init(&cuda_mem_index, pic[0x19]);
260 adb_kbd_init(&adb_bus);
261 adb_mouse_init(&adb_bus);
263 dbdma_init(&dbdma_mem_index);
265 macio_init(pci_bus, 0x0022, 0, pic_mem_index, dbdma_mem_index,
266 cuda_mem_index, -1, 2, ide_mem_index);
269 usb_ohci_init_pci(pci_bus, 3, -1);
272 if (graphic_depth != 15 && graphic_depth != 32 && graphic_depth != 8)
274 #if 0 /* XXX: this is ugly but needed for now, or OHW won't boot */
275 /* The NewWorld NVRAM is not located in the MacIO device */
276 nvr = macio_nvram_init(&nvram_mem_index);
277 pmac_format_nvram_partition(nvr, 0x2000);
278 cpu_register_physical_memory(0xFFF04000, 0x20000, nvram_mem_index);
280 nvram.read_fn = &macio_nvram_read;
281 nvram.write_fn = &macio_nvram_write;
283 m48t59 = m48t59_init(dummy_irq[8], 0xFFF04000, 0x0074, NVRAM_SIZE, 59);
284 nvram.opaque = m48t59;
285 nvram.read_fn = &m48t59_read;
286 nvram.write_fn = &m48t59_write;
288 PPC_NVRAM_set_params(&nvram, NVRAM_SIZE, "MAC99", ram_size, boot_device,
289 kernel_base, kernel_size,
291 initrd_base, initrd_size,
292 /* XXX: need an option to load a NVRAM image */
294 graphic_width, graphic_height, graphic_depth);
295 /* No PCI init: the BIOS will do it */
297 /* Special port to get debug messages from Open-Firmware */
298 register_ioport_write(0x0F00, 4, 1, &PPC_debug_write, NULL);
301 QEMUMachine core99_machine = {
303 "Mac99 based PowerMAC",