]>
Commit | Line | Data |
---|---|---|
64201201 FB |
1 | /* |
2 | * QEMU PPC CHRP/PMAC hardware System Emulator | |
5fafdf24 | 3 | * |
47103572 | 4 | * Copyright (c) 2004-2007 Fabrice Bellard |
5fafdf24 | 5 | * |
64201201 FB |
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 "vl.h" | |
25 | ||
e9df014c JM |
26 | /* SMP is not enabled, for now */ |
27 | #define MAX_CPUS 1 | |
28 | ||
64201201 | 29 | #define BIOS_FILENAME "ppc_rom.bin" |
d5295253 | 30 | #define VGABIOS_FILENAME "video.x" |
64201201 FB |
31 | #define NVRAM_SIZE 0x2000 |
32 | ||
b6b8bd18 FB |
33 | #define KERNEL_LOAD_ADDR 0x01000000 |
34 | #define INITRD_LOAD_ADDR 0x01800000 | |
35 | ||
267002cd | 36 | /* MacIO devices (mapped inside the MacIO address space): CUDA, DBDMA, |
e5733356 | 37 | NVRAM */ |
267002cd FB |
38 | |
39 | static int dbdma_mem_index; | |
40 | static int cuda_mem_index; | |
0aa6a4a2 FB |
41 | static int ide0_mem_index = -1; |
42 | static int ide1_mem_index = -1; | |
43 | static int openpic_mem_index = -1; | |
44 | static int heathrow_pic_mem_index = -1; | |
e5733356 | 45 | static int macio_nvram_mem_index = -1; |
267002cd FB |
46 | |
47 | /* DBDMA: currently no op - should suffice right now */ | |
48 | ||
36081602 JM |
49 | static void dbdma_writeb (void *opaque, |
50 | target_phys_addr_t addr, uint32_t value) | |
267002cd | 51 | { |
e96efcfc | 52 | printf("%s: 0x" PADDRX " <= 0x%08x\n", __func__, addr, value); |
267002cd FB |
53 | } |
54 | ||
36081602 JM |
55 | static void dbdma_writew (void *opaque, |
56 | target_phys_addr_t addr, uint32_t value) | |
267002cd FB |
57 | { |
58 | } | |
59 | ||
36081602 JM |
60 | static void dbdma_writel (void *opaque, |
61 | target_phys_addr_t addr, uint32_t value) | |
267002cd FB |
62 | { |
63 | } | |
64 | ||
65 | static uint32_t dbdma_readb (void *opaque, target_phys_addr_t addr) | |
66 | { | |
e96efcfc | 67 | printf("%s: 0x" PADDRX " => 0x00000000\n", __func__, addr); |
36081602 | 68 | |
267002cd FB |
69 | return 0; |
70 | } | |
71 | ||
72 | static uint32_t dbdma_readw (void *opaque, target_phys_addr_t addr) | |
73 | { | |
74 | return 0; | |
75 | } | |
76 | ||
77 | static uint32_t dbdma_readl (void *opaque, target_phys_addr_t addr) | |
78 | { | |
79 | return 0; | |
80 | } | |
81 | ||
82 | static CPUWriteMemoryFunc *dbdma_write[] = { | |
83 | &dbdma_writeb, | |
84 | &dbdma_writew, | |
85 | &dbdma_writel, | |
86 | }; | |
87 | ||
88 | static CPUReadMemoryFunc *dbdma_read[] = { | |
89 | &dbdma_readb, | |
90 | &dbdma_readw, | |
91 | &dbdma_readl, | |
92 | }; | |
93 | ||
e5733356 FB |
94 | /* macio style NVRAM device */ |
95 | typedef struct MacIONVRAMState { | |
96 | uint8_t data[0x2000]; | |
97 | } MacIONVRAMState; | |
98 | ||
36081602 JM |
99 | static void macio_nvram_writeb (void *opaque, |
100 | target_phys_addr_t addr, uint32_t value) | |
e5733356 FB |
101 | { |
102 | MacIONVRAMState *s = opaque; | |
103 | addr = (addr >> 4) & 0x1fff; | |
104 | s->data[addr] = value; | |
105 | // printf("macio_nvram_writeb %04x = %02x\n", addr, value); | |
106 | } | |
107 | ||
108 | static uint32_t macio_nvram_readb (void *opaque, target_phys_addr_t addr) | |
109 | { | |
110 | MacIONVRAMState *s = opaque; | |
111 | uint32_t value; | |
112 | ||
113 | addr = (addr >> 4) & 0x1fff; | |
114 | value = s->data[addr]; | |
115 | // printf("macio_nvram_readb %04x = %02x\n", addr, value); | |
36081602 | 116 | |
e5733356 FB |
117 | return value; |
118 | } | |
119 | ||
120 | static CPUWriteMemoryFunc *macio_nvram_write[] = { | |
121 | &macio_nvram_writeb, | |
122 | &macio_nvram_writeb, | |
123 | &macio_nvram_writeb, | |
124 | }; | |
125 | ||
126 | static CPUReadMemoryFunc *macio_nvram_read[] = { | |
127 | &macio_nvram_readb, | |
128 | &macio_nvram_readb, | |
129 | &macio_nvram_readb, | |
130 | }; | |
131 | ||
36081602 | 132 | static MacIONVRAMState *macio_nvram_init (void) |
e5733356 FB |
133 | { |
134 | MacIONVRAMState *s; | |
135 | s = qemu_mallocz(sizeof(MacIONVRAMState)); | |
136 | if (!s) | |
137 | return NULL; | |
5fafdf24 | 138 | macio_nvram_mem_index = cpu_register_io_memory(0, macio_nvram_read, |
e5733356 | 139 | macio_nvram_write, s); |
36081602 | 140 | |
e5733356 FB |
141 | return s; |
142 | } | |
143 | ||
36081602 JM |
144 | static void macio_map (PCIDevice *pci_dev, int region_num, |
145 | uint32_t addr, uint32_t size, int type) | |
267002cd | 146 | { |
0aa6a4a2 | 147 | if (heathrow_pic_mem_index >= 0) { |
5fafdf24 | 148 | cpu_register_physical_memory(addr + 0x00000, 0x1000, |
0aa6a4a2 FB |
149 | heathrow_pic_mem_index); |
150 | } | |
267002cd FB |
151 | cpu_register_physical_memory(addr + 0x08000, 0x1000, dbdma_mem_index); |
152 | cpu_register_physical_memory(addr + 0x16000, 0x2000, cuda_mem_index); | |
0aa6a4a2 FB |
153 | if (ide0_mem_index >= 0) |
154 | cpu_register_physical_memory(addr + 0x1f000, 0x1000, ide0_mem_index); | |
155 | if (ide1_mem_index >= 0) | |
156 | cpu_register_physical_memory(addr + 0x20000, 0x1000, ide1_mem_index); | |
157 | if (openpic_mem_index >= 0) { | |
5fafdf24 | 158 | cpu_register_physical_memory(addr + 0x40000, 0x40000, |
0aa6a4a2 FB |
159 | openpic_mem_index); |
160 | } | |
e5733356 | 161 | if (macio_nvram_mem_index >= 0) |
36081602 JM |
162 | cpu_register_physical_memory(addr + 0x60000, 0x20000, |
163 | macio_nvram_mem_index); | |
267002cd FB |
164 | } |
165 | ||
36081602 | 166 | static void macio_init (PCIBus *bus, int device_id) |
267002cd FB |
167 | { |
168 | PCIDevice *d; | |
169 | ||
46e50e9d FB |
170 | d = pci_register_device(bus, "macio", sizeof(PCIDevice), |
171 | -1, NULL, NULL); | |
267002cd FB |
172 | /* Note: this code is strongly inspirated from the corresponding code |
173 | in PearPC */ | |
174 | d->config[0x00] = 0x6b; // vendor_id | |
175 | d->config[0x01] = 0x10; | |
e5733356 FB |
176 | d->config[0x02] = device_id; |
177 | d->config[0x03] = device_id >> 8; | |
267002cd FB |
178 | |
179 | d->config[0x0a] = 0x00; // class_sub = pci2pci | |
180 | d->config[0x0b] = 0xff; // class_base = bridge | |
181 | d->config[0x0e] = 0x00; // header_type | |
182 | ||
183 | d->config[0x3d] = 0x01; // interrupt on pin 1 | |
3b46e624 | 184 | |
267002cd FB |
185 | dbdma_mem_index = cpu_register_io_memory(0, dbdma_read, dbdma_write, NULL); |
186 | ||
5fafdf24 | 187 | pci_register_io_region(d, 0, 0x80000, |
267002cd FB |
188 | PCI_ADDRESS_SPACE_MEM, macio_map); |
189 | } | |
190 | ||
0aa6a4a2 FB |
191 | /* UniN device */ |
192 | static void unin_writel (void *opaque, target_phys_addr_t addr, uint32_t value) | |
193 | { | |
194 | } | |
195 | ||
196 | static uint32_t unin_readl (void *opaque, target_phys_addr_t addr) | |
197 | { | |
198 | return 0; | |
199 | } | |
200 | ||
201 | static CPUWriteMemoryFunc *unin_write[] = { | |
202 | &unin_writel, | |
203 | &unin_writel, | |
204 | &unin_writel, | |
205 | }; | |
206 | ||
207 | static CPUReadMemoryFunc *unin_read[] = { | |
208 | &unin_readl, | |
209 | &unin_readl, | |
210 | &unin_readl, | |
211 | }; | |
212 | ||
213 | /* temporary frame buffer OSI calls for the video.x driver. The right | |
214 | solution is to modify the driver to use VGA PCI I/Os */ | |
36081602 JM |
215 | /* XXX: to be removed. This is no way related to emulation */ |
216 | static int vga_osi_call (CPUState *env) | |
0aa6a4a2 FB |
217 | { |
218 | static int vga_vbl_enabled; | |
219 | int linesize; | |
3b46e624 | 220 | |
0aa6a4a2 FB |
221 | // printf("osi_call R5=%d\n", env->gpr[5]); |
222 | ||
223 | /* same handler as PearPC, coming from the original MOL video | |
224 | driver. */ | |
225 | switch(env->gpr[5]) { | |
226 | case 4: | |
227 | break; | |
228 | case 28: /* set_vmode */ | |
229 | if (env->gpr[6] != 1 || env->gpr[7] != 0) | |
230 | env->gpr[3] = 1; | |
231 | else | |
232 | env->gpr[3] = 0; | |
233 | break; | |
234 | case 29: /* get_vmode_info */ | |
235 | if (env->gpr[6] != 0) { | |
236 | if (env->gpr[6] != 1 || env->gpr[7] != 0) { | |
237 | env->gpr[3] = 1; | |
238 | break; | |
239 | } | |
240 | } | |
5fafdf24 | 241 | env->gpr[3] = 0; |
0aa6a4a2 FB |
242 | env->gpr[4] = (1 << 16) | 1; /* num_vmodes, cur_vmode */ |
243 | env->gpr[5] = (1 << 16) | 0; /* num_depths, cur_depth_mode */ | |
244 | env->gpr[6] = (graphic_width << 16) | graphic_height; /* w, h */ | |
245 | env->gpr[7] = 85 << 16; /* refresh rate */ | |
246 | env->gpr[8] = (graphic_depth + 7) & ~7; /* depth (round to byte) */ | |
247 | linesize = ((graphic_depth + 7) >> 3) * graphic_width; | |
248 | linesize = (linesize + 3) & ~3; | |
249 | env->gpr[9] = (linesize << 16) | 0; /* row_bytes, offset */ | |
250 | break; | |
251 | case 31: /* set_video power */ | |
252 | env->gpr[3] = 0; | |
253 | break; | |
254 | case 39: /* video_ctrl */ | |
255 | if (env->gpr[6] == 0 || env->gpr[6] == 1) | |
256 | vga_vbl_enabled = env->gpr[6]; | |
257 | env->gpr[3] = 0; | |
258 | break; | |
259 | case 47: | |
260 | break; | |
261 | case 59: /* set_color */ | |
262 | /* R6 = index, R7 = RGB */ | |
263 | env->gpr[3] = 0; | |
264 | break; | |
265 | case 64: /* get color */ | |
266 | /* R6 = index */ | |
5fafdf24 | 267 | env->gpr[3] = 0; |
0aa6a4a2 FB |
268 | break; |
269 | case 116: /* set hwcursor */ | |
270 | /* R6 = x, R7 = y, R8 = visible, R9 = data */ | |
271 | break; | |
272 | default: | |
e96efcfc | 273 | fprintf(stderr, "unsupported OSI call R5=" REGX "\n", env->gpr[5]); |
0aa6a4a2 FB |
274 | break; |
275 | } | |
36081602 | 276 | |
0aa6a4a2 FB |
277 | return 1; /* osi_call handled */ |
278 | } | |
279 | ||
36081602 | 280 | static uint8_t nvram_chksum (const uint8_t *buf, int n) |
e5733356 FB |
281 | { |
282 | int sum, i; | |
283 | sum = 0; | |
284 | for(i = 0; i < n; i++) | |
285 | sum += buf[i]; | |
286 | return (sum & 0xff) + (sum >> 8); | |
287 | } | |
288 | ||
289 | /* set a free Mac OS NVRAM partition */ | |
36081602 | 290 | void pmac_format_nvram_partition (uint8_t *buf, int len) |
e5733356 FB |
291 | { |
292 | char partition_name[12] = "wwwwwwwwwwww"; | |
3b46e624 | 293 | |
e5733356 FB |
294 | buf[0] = 0x7f; /* free partition magic */ |
295 | buf[1] = 0; /* checksum */ | |
296 | buf[2] = len >> 8; | |
297 | buf[3] = len; | |
298 | memcpy(buf + 4, partition_name, 12); | |
299 | buf[1] = nvram_chksum(buf, 16); | |
3b46e624 | 300 | } |
e5733356 | 301 | |
0aa6a4a2 | 302 | /* PowerPC CHRP hardware initialisation */ |
94fc95cd JM |
303 | static void ppc_chrp_init (int ram_size, int vga_ram_size, int boot_device, |
304 | DisplayState *ds, const char **fd_filename, | |
305 | int snapshot, | |
306 | const char *kernel_filename, | |
307 | const char *kernel_cmdline, | |
308 | const char *initrd_filename, | |
309 | const char *cpu_model, | |
310 | int is_heathrow) | |
64201201 | 311 | { |
e9df014c | 312 | CPUState *env, *envs[MAX_CPUS]; |
64201201 | 313 | char buf[1024]; |
e9df014c | 314 | qemu_irq *pic, **openpic_irqs; |
64201201 | 315 | m48t59_t *nvram; |
aef445bd | 316 | int unin_memory; |
d5295253 FB |
317 | int linux_boot, i; |
318 | unsigned long bios_offset, vga_bios_offset; | |
b6b8bd18 | 319 | uint32_t kernel_base, kernel_size, initrd_base, initrd_size; |
3fc6c082 | 320 | ppc_def_t *def; |
46e50e9d | 321 | PCIBus *pci_bus; |
0aa6a4a2 | 322 | const char *arch_name; |
d5295253 | 323 | int vga_bios_size, bios_size; |
d537cf6c | 324 | qemu_irq *dummy_irq; |
46e50e9d | 325 | |
64201201 FB |
326 | linux_boot = (kernel_filename != NULL); |
327 | ||
c68ea704 FB |
328 | /* init CPUs */ |
329 | env = cpu_init(); | |
94fc95cd | 330 | if (cpu_model == NULL) |
d12f4c38 | 331 | cpu_model = "default"; |
94fc95cd | 332 | ppc_find_by_name(cpu_model, &def); |
c68ea704 FB |
333 | if (def == NULL) { |
334 | cpu_abort(env, "Unable to find PowerPC CPU definition\n"); | |
335 | } | |
e9df014c JM |
336 | for (i = 0; i < smp_cpus; i++) { |
337 | cpu_ppc_register(env, def); | |
fe33cc71 | 338 | cpu_ppc_reset(env); |
e9df014c JM |
339 | /* Set time-base frequency to 100 Mhz */ |
340 | cpu_ppc_tb_init(env, 100UL * 1000UL * 1000UL); | |
341 | env->osi_call = vga_osi_call; | |
fe33cc71 JM |
342 | qemu_register_reset(&cpu_ppc_reset, env); |
343 | register_savevm("cpu", 0, 3, cpu_save, cpu_load, env); | |
e9df014c JM |
344 | envs[i] = env; |
345 | } | |
c68ea704 | 346 | |
64201201 FB |
347 | /* allocate RAM */ |
348 | cpu_register_physical_memory(0, ram_size, IO_MEM_RAM); | |
349 | ||
350 | /* allocate and load BIOS */ | |
351 | bios_offset = ram_size + vga_ram_size; | |
352 | snprintf(buf, sizeof(buf), "%s/%s", bios_dir, BIOS_FILENAME); | |
d5295253 FB |
353 | bios_size = load_image(buf, phys_ram_base + bios_offset); |
354 | if (bios_size < 0 || bios_size > BIOS_SIZE) { | |
4a057712 | 355 | cpu_abort(env, "qemu: could not load PowerPC bios '%s'\n", buf); |
64201201 FB |
356 | exit(1); |
357 | } | |
d5295253 | 358 | bios_size = (bios_size + 0xfff) & ~0xfff; |
4a057712 | 359 | cpu_register_physical_memory((uint32_t)(-bios_size), |
d5295253 | 360 | bios_size, bios_offset | IO_MEM_ROM); |
3b46e624 | 361 | |
d5295253 FB |
362 | /* allocate and load VGA BIOS */ |
363 | vga_bios_offset = bios_offset + bios_size; | |
364 | snprintf(buf, sizeof(buf), "%s/%s", bios_dir, VGABIOS_FILENAME); | |
365 | vga_bios_size = load_image(buf, phys_ram_base + vga_bios_offset + 8); | |
366 | if (vga_bios_size < 0) { | |
367 | /* if no bios is present, we can still work */ | |
368 | fprintf(stderr, "qemu: warning: could not load VGA bios '%s'\n", buf); | |
369 | vga_bios_size = 0; | |
370 | } else { | |
371 | /* set a specific header (XXX: find real Apple format for NDRV | |
372 | drivers) */ | |
373 | phys_ram_base[vga_bios_offset] = 'N'; | |
374 | phys_ram_base[vga_bios_offset + 1] = 'D'; | |
375 | phys_ram_base[vga_bios_offset + 2] = 'R'; | |
376 | phys_ram_base[vga_bios_offset + 3] = 'V'; | |
5fafdf24 | 377 | cpu_to_be32w((uint32_t *)(phys_ram_base + vga_bios_offset + 4), |
d5295253 FB |
378 | vga_bios_size); |
379 | vga_bios_size += 8; | |
380 | } | |
381 | vga_bios_size = (vga_bios_size + 0xfff) & ~0xfff; | |
3b46e624 | 382 | |
b6b8bd18 FB |
383 | if (linux_boot) { |
384 | kernel_base = KERNEL_LOAD_ADDR; | |
385 | /* now we can load the kernel */ | |
386 | kernel_size = load_image(kernel_filename, phys_ram_base + kernel_base); | |
387 | if (kernel_size < 0) { | |
4a057712 JM |
388 | cpu_abort(env, "qemu: could not load kernel '%s'\n", |
389 | kernel_filename); | |
b6b8bd18 FB |
390 | exit(1); |
391 | } | |
392 | /* load initrd */ | |
393 | if (initrd_filename) { | |
394 | initrd_base = INITRD_LOAD_ADDR; | |
395 | initrd_size = load_image(initrd_filename, | |
396 | phys_ram_base + initrd_base); | |
397 | if (initrd_size < 0) { | |
4a057712 JM |
398 | cpu_abort(env, "qemu: could not load initial ram disk '%s'\n", |
399 | initrd_filename); | |
b6b8bd18 FB |
400 | exit(1); |
401 | } | |
402 | } else { | |
403 | initrd_base = 0; | |
404 | initrd_size = 0; | |
405 | } | |
406 | boot_device = 'm'; | |
407 | } else { | |
408 | kernel_base = 0; | |
409 | kernel_size = 0; | |
410 | initrd_base = 0; | |
411 | initrd_size = 0; | |
412 | } | |
0aa6a4a2 FB |
413 | |
414 | if (is_heathrow) { | |
415 | isa_mem_base = 0x80000000; | |
dd37a5e4 | 416 | |
0aa6a4a2 | 417 | /* Register 2 MB of ISA IO space */ |
aef445bd PB |
418 | isa_mmio_init(0xfe000000, 0x00200000); |
419 | ||
0aa6a4a2 | 420 | /* init basic PC hardware */ |
dd37a5e4 JM |
421 | if (PPC_INPUT(env) != PPC_FLAGS_INPUT_6xx) { |
422 | cpu_abort(env, "Only 6xx bus is supported on heathrow machine\n"); | |
423 | exit(1); | |
424 | } | |
502a5395 | 425 | pic = heathrow_pic_init(&heathrow_pic_mem_index); |
502a5395 | 426 | pci_bus = pci_grackle_init(0xfec00000, pic); |
dd37a5e4 | 427 | pci_vga_init(pci_bus, ds, phys_ram_base + ram_size, |
89b6b508 FB |
428 | ram_size, vga_ram_size, |
429 | vga_bios_offset, vga_bios_size); | |
0aa6a4a2 FB |
430 | |
431 | /* XXX: suppress that */ | |
d537cf6c | 432 | dummy_irq = i8259_init(NULL); |
3b46e624 | 433 | |
0aa6a4a2 | 434 | /* XXX: use Mac Serial port */ |
d537cf6c | 435 | serial_init(0x3f8, dummy_irq[4], serial_hds[0]); |
3b46e624 | 436 | |
0aa6a4a2 | 437 | for(i = 0; i < nb_nics; i++) { |
a41b2ff2 PB |
438 | if (!nd_table[i].model) |
439 | nd_table[i].model = "ne2k_pci"; | |
abcebc7e | 440 | pci_nic_init(pci_bus, &nd_table[i], -1); |
0aa6a4a2 | 441 | } |
3b46e624 | 442 | |
0aa6a4a2 FB |
443 | pci_cmd646_ide_init(pci_bus, &bs_table[0], 0); |
444 | ||
445 | /* cuda also initialize ADB */ | |
d537cf6c | 446 | cuda_mem_index = cuda_init(pic[0x12]); |
3b46e624 | 447 | |
0aa6a4a2 FB |
448 | adb_kbd_init(&adb_bus); |
449 | adb_mouse_init(&adb_bus); | |
3b46e624 | 450 | |
e5733356 FB |
451 | { |
452 | MacIONVRAMState *nvr; | |
453 | nvr = macio_nvram_init(); | |
454 | pmac_format_nvram_partition(nvr->data, 0x2000); | |
455 | } | |
456 | ||
457 | macio_init(pci_bus, 0x0017); | |
47103572 | 458 | |
d537cf6c | 459 | nvram = m48t59_init(dummy_irq[8], 0xFFF04000, 0x0074, NVRAM_SIZE, 59); |
47103572 | 460 | |
0aa6a4a2 FB |
461 | arch_name = "HEATHROW"; |
462 | } else { | |
463 | isa_mem_base = 0x80000000; | |
47103572 | 464 | |
0aa6a4a2 | 465 | /* Register 8 MB of ISA IO space */ |
aef445bd | 466 | isa_mmio_init(0xf2000000, 0x00800000); |
47103572 | 467 | |
0aa6a4a2 FB |
468 | /* UniN init */ |
469 | unin_memory = cpu_register_io_memory(0, unin_read, unin_write, NULL); | |
470 | cpu_register_physical_memory(0xf8000000, 0x00001000, unin_memory); | |
471 | ||
e9df014c JM |
472 | openpic_irqs = qemu_mallocz(smp_cpus * sizeof(qemu_irq *)); |
473 | openpic_irqs[0] = | |
474 | qemu_mallocz(smp_cpus * sizeof(qemu_irq) * OPENPIC_OUTPUT_NB); | |
475 | for (i = 0; i < smp_cpus; i++) { | |
476 | /* Mac99 IRQ connection between OpenPIC outputs pins | |
477 | * and PowerPC input pins | |
478 | */ | |
dd37a5e4 JM |
479 | switch (PPC_INPUT(env)) { |
480 | case PPC_FLAGS_INPUT_6xx: | |
481 | openpic_irqs[i] = openpic_irqs[0] + (i * OPENPIC_OUTPUT_NB); | |
482 | openpic_irqs[i][OPENPIC_OUTPUT_INT] = | |
483 | ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_INT]; | |
484 | openpic_irqs[i][OPENPIC_OUTPUT_CINT] = | |
485 | ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_INT]; | |
486 | openpic_irqs[i][OPENPIC_OUTPUT_MCK] = | |
487 | ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_MCP]; | |
488 | /* Not connected ? */ | |
489 | openpic_irqs[i][OPENPIC_OUTPUT_DEBUG] = NULL; | |
490 | /* Check this */ | |
491 | openpic_irqs[i][OPENPIC_OUTPUT_RESET] = | |
492 | ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_HRESET]; | |
493 | break; | |
00af685f | 494 | #if defined(TARGET_PPC64) |
dd37a5e4 JM |
495 | case PPC_FLAGS_INPUT_970: |
496 | openpic_irqs[i] = openpic_irqs[0] + (i * OPENPIC_OUTPUT_NB); | |
497 | openpic_irqs[i][OPENPIC_OUTPUT_INT] = | |
498 | ((qemu_irq *)env->irq_inputs)[PPC970_INPUT_INT]; | |
499 | openpic_irqs[i][OPENPIC_OUTPUT_CINT] = | |
500 | ((qemu_irq *)env->irq_inputs)[PPC970_INPUT_INT]; | |
501 | openpic_irqs[i][OPENPIC_OUTPUT_MCK] = | |
502 | ((qemu_irq *)env->irq_inputs)[PPC970_INPUT_MCP]; | |
503 | /* Not connected ? */ | |
504 | openpic_irqs[i][OPENPIC_OUTPUT_DEBUG] = NULL; | |
505 | /* Check this */ | |
506 | openpic_irqs[i][OPENPIC_OUTPUT_RESET] = | |
507 | ((qemu_irq *)env->irq_inputs)[PPC970_INPUT_HRESET]; | |
508 | break; | |
00af685f | 509 | #endif /* defined(TARGET_PPC64) */ |
dd37a5e4 | 510 | default: |
36081602 | 511 | cpu_abort(env, "Bus model not supported on mac99 machine\n"); |
dd37a5e4 JM |
512 | exit(1); |
513 | } | |
e9df014c JM |
514 | } |
515 | pic = openpic_init(NULL, &openpic_mem_index, smp_cpus, | |
516 | openpic_irqs, NULL); | |
502a5395 | 517 | pci_bus = pci_pmac_init(pic); |
0aa6a4a2 | 518 | /* init basic PC hardware */ |
89b6b508 FB |
519 | pci_vga_init(pci_bus, ds, phys_ram_base + ram_size, |
520 | ram_size, vga_ram_size, | |
521 | vga_bios_offset, vga_bios_size); | |
0aa6a4a2 FB |
522 | |
523 | /* XXX: suppress that */ | |
d537cf6c | 524 | dummy_irq = i8259_init(NULL); |
3079c59a | 525 | |
0aa6a4a2 | 526 | /* XXX: use Mac Serial port */ |
d537cf6c | 527 | serial_init(0x3f8, dummy_irq[4], serial_hds[0]); |
0aa6a4a2 | 528 | for(i = 0; i < nb_nics; i++) { |
3079c59a JM |
529 | if (!nd_table[i].model) |
530 | nd_table[i].model = "ne2k_pci"; | |
531 | pci_nic_init(pci_bus, &nd_table[i], -1); | |
0aa6a4a2 | 532 | } |
0aa6a4a2 | 533 | #if 1 |
d537cf6c PB |
534 | ide0_mem_index = pmac_ide_init(&bs_table[0], pic[0x13]); |
535 | ide1_mem_index = pmac_ide_init(&bs_table[2], pic[0x14]); | |
0aa6a4a2 FB |
536 | #else |
537 | pci_cmd646_ide_init(pci_bus, &bs_table[0], 0); | |
538 | #endif | |
539 | /* cuda also initialize ADB */ | |
d537cf6c | 540 | cuda_mem_index = cuda_init(pic[0x19]); |
3b46e624 | 541 | |
0aa6a4a2 FB |
542 | adb_kbd_init(&adb_bus); |
543 | adb_mouse_init(&adb_bus); | |
3b46e624 | 544 | |
e5733356 | 545 | macio_init(pci_bus, 0x0022); |
3b46e624 | 546 | |
d537cf6c | 547 | nvram = m48t59_init(dummy_irq[8], 0xFFF04000, 0x0074, NVRAM_SIZE, 59); |
3b46e624 | 548 | |
0aa6a4a2 | 549 | arch_name = "MAC99"; |
64201201 | 550 | } |
0d92ed30 PB |
551 | |
552 | if (usb_enabled) { | |
e24ad6f1 | 553 | usb_ohci_init_pci(pci_bus, 3, -1); |
0d92ed30 PB |
554 | } |
555 | ||
b6b8bd18 FB |
556 | if (graphic_depth != 15 && graphic_depth != 32 && graphic_depth != 8) |
557 | graphic_depth = 15; | |
64201201 | 558 | |
0aa6a4a2 | 559 | PPC_NVRAM_set_params(nvram, NVRAM_SIZE, arch_name, ram_size, boot_device, |
b6b8bd18 FB |
560 | kernel_base, kernel_size, |
561 | kernel_cmdline, | |
562 | initrd_base, initrd_size, | |
64201201 | 563 | /* XXX: need an option to load a NVRAM image */ |
b6b8bd18 FB |
564 | 0, |
565 | graphic_width, graphic_height, graphic_depth); | |
566 | /* No PCI init: the BIOS will do it */ | |
0aa6a4a2 FB |
567 | |
568 | /* Special port to get debug messages from Open-Firmware */ | |
569 | register_ioport_write(0x0F00, 4, 1, &PPC_debug_write, NULL); | |
570 | } | |
571 | ||
94fc95cd JM |
572 | static void ppc_core99_init (int ram_size, int vga_ram_size, int boot_device, |
573 | DisplayState *ds, const char **fd_filename, | |
574 | int snapshot, | |
575 | const char *kernel_filename, | |
576 | const char *kernel_cmdline, | |
577 | const char *initrd_filename, | |
578 | const char *cpu_model) | |
0aa6a4a2 FB |
579 | { |
580 | ppc_chrp_init(ram_size, vga_ram_size, boot_device, | |
581 | ds, fd_filename, snapshot, | |
582 | kernel_filename, kernel_cmdline, | |
94fc95cd | 583 | initrd_filename, cpu_model, 0); |
64201201 | 584 | } |
3b46e624 | 585 | |
94fc95cd JM |
586 | static void ppc_heathrow_init (int ram_size, int vga_ram_size, int boot_device, |
587 | DisplayState *ds, const char **fd_filename, | |
588 | int snapshot, | |
589 | const char *kernel_filename, | |
590 | const char *kernel_cmdline, | |
591 | const char *initrd_filename, | |
592 | const char *cpu_model) | |
0aa6a4a2 FB |
593 | { |
594 | ppc_chrp_init(ram_size, vga_ram_size, boot_device, | |
595 | ds, fd_filename, snapshot, | |
596 | kernel_filename, kernel_cmdline, | |
94fc95cd | 597 | initrd_filename, cpu_model, 1); |
0aa6a4a2 FB |
598 | } |
599 | ||
600 | QEMUMachine core99_machine = { | |
0289b2c1 FB |
601 | "mac99", |
602 | "Mac99 based PowerMAC", | |
0aa6a4a2 FB |
603 | ppc_core99_init, |
604 | }; | |
605 | ||
606 | QEMUMachine heathrow_machine = { | |
0289b2c1 | 607 | "g3bw", |
0aa6a4a2 FB |
608 | "Heathrow based PowerMAC", |
609 | ppc_heathrow_init, | |
610 | }; |