]> git.proxmox.com Git - mirror_qemu.git/blame - hw/ppc_oldworld.c
sd.c build fix.
[mirror_qemu.git] / hw / ppc_oldworld.c
CommitLineData
3cbee15b
JM
1/*
2 * QEMU OldWorld PowerMac (currently ~G3 B&W) hardware System Emulator
3 *
4 * Copyright (c) 2004-2007 Fabrice Bellard
5 * Copyright (c) 2007 Jocelyn Mayer
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
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
23 * THE SOFTWARE.
24 */
25#include "vl.h"
26#include "ppc_mac.h"
27
28/* temporary frame buffer OSI calls for the video.x driver. The right
29 solution is to modify the driver to use VGA PCI I/Os */
30/* XXX: to be removed. This is no way related to emulation */
31static int vga_osi_call (CPUState *env)
32{
33 static int vga_vbl_enabled;
34 int linesize;
35
36 // printf("osi_call R5=%d\n", env->gpr[5]);
37
38 /* same handler as PearPC, coming from the original MOL video
39 driver. */
40 switch(env->gpr[5]) {
41 case 4:
42 break;
43 case 28: /* set_vmode */
44 if (env->gpr[6] != 1 || env->gpr[7] != 0)
45 env->gpr[3] = 1;
46 else
47 env->gpr[3] = 0;
48 break;
49 case 29: /* get_vmode_info */
50 if (env->gpr[6] != 0) {
51 if (env->gpr[6] != 1 || env->gpr[7] != 0) {
52 env->gpr[3] = 1;
53 break;
54 }
55 }
56 env->gpr[3] = 0;
57 env->gpr[4] = (1 << 16) | 1; /* num_vmodes, cur_vmode */
58 env->gpr[5] = (1 << 16) | 0; /* num_depths, cur_depth_mode */
59 env->gpr[6] = (graphic_width << 16) | graphic_height; /* w, h */
60 env->gpr[7] = 85 << 16; /* refresh rate */
61 env->gpr[8] = (graphic_depth + 7) & ~7; /* depth (round to byte) */
62 linesize = ((graphic_depth + 7) >> 3) * graphic_width;
63 linesize = (linesize + 3) & ~3;
64 env->gpr[9] = (linesize << 16) | 0; /* row_bytes, offset */
65 break;
66 case 31: /* set_video power */
67 env->gpr[3] = 0;
68 break;
69 case 39: /* video_ctrl */
70 if (env->gpr[6] == 0 || env->gpr[6] == 1)
71 vga_vbl_enabled = env->gpr[6];
72 env->gpr[3] = 0;
73 break;
74 case 47:
75 break;
76 case 59: /* set_color */
77 /* R6 = index, R7 = RGB */
78 env->gpr[3] = 0;
79 break;
80 case 64: /* get color */
81 /* R6 = index */
82 env->gpr[3] = 0;
83 break;
84 case 116: /* set hwcursor */
85 /* R6 = x, R7 = y, R8 = visible, R9 = data */
86 break;
87 default:
88 fprintf(stderr, "unsupported OSI call R5=" REGX "\n", env->gpr[5]);
89 break;
90 }
91
92 return 1; /* osi_call handled */
93}
94
6ac0e82d
AZ
95static void ppc_heathrow_init (int ram_size, int vga_ram_size,
96 const char *boot_device, DisplayState *ds,
97 const char **fd_filename, int snapshot,
3cbee15b
JM
98 const char *kernel_filename,
99 const char *kernel_cmdline,
100 const char *initrd_filename,
101 const char *cpu_model)
102{
aaed909a 103 CPUState *env = NULL, *envs[MAX_CPUS];
3cbee15b
JM
104 char buf[1024];
105 qemu_irq *pic, **heathrow_irqs;
106 nvram_t nvram;
107 m48t59_t *m48t59;
108 int linux_boot, i;
109 unsigned long bios_offset, vga_bios_offset;
110 uint32_t kernel_base, kernel_size, initrd_base, initrd_size;
3cbee15b
JM
111 PCIBus *pci_bus;
112 MacIONVRAMState *nvr;
113 int vga_bios_size, bios_size;
114 qemu_irq *dummy_irq;
115 int pic_mem_index, nvram_mem_index, dbdma_mem_index, cuda_mem_index;
0d913fdb 116 int ide_mem_index[2];
28c5af54 117 int ppc_boot_device;
3cbee15b
JM
118
119 linux_boot = (kernel_filename != NULL);
120
121 /* init CPUs */
3cbee15b
JM
122 if (cpu_model == NULL)
123 cpu_model = "default";
3cbee15b 124 for (i = 0; i < smp_cpus; i++) {
aaed909a
FB
125 env = cpu_init(cpu_model);
126 if (!env) {
127 fprintf(stderr, "Unable to find PowerPC CPU definition\n");
128 exit(1);
129 }
3cbee15b
JM
130 /* Set time-base frequency to 100 Mhz */
131 cpu_ppc_tb_init(env, 100UL * 1000UL * 1000UL);
132 env->osi_call = vga_osi_call;
133 qemu_register_reset(&cpu_ppc_reset, env);
134 register_savevm("cpu", 0, 3, cpu_save, cpu_load, env);
135 envs[i] = env;
136 }
4c823cff
JM
137 if (env->nip < 0xFFF80000) {
138 /* Special test for PowerPC 601:
139 * the boot vector is at 0xFFF00100, then we need a 1MB BIOS.
140 * But the NVRAM is located at 0xFFF04000...
141 */
142 cpu_abort(env, "G3BW Mac hardware can not handle 1 MB BIOS\n");
143 }
3cbee15b
JM
144
145 /* allocate RAM */
146 cpu_register_physical_memory(0, ram_size, IO_MEM_RAM);
147
148 /* allocate and load BIOS */
149 bios_offset = ram_size + vga_ram_size;
150 if (bios_name == NULL)
151 bios_name = BIOS_FILENAME;
152 snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
153 bios_size = load_image(buf, phys_ram_base + bios_offset);
154 if (bios_size < 0 || bios_size > BIOS_SIZE) {
155 cpu_abort(env, "qemu: could not load PowerPC bios '%s'\n", buf);
156 exit(1);
157 }
158 bios_size = (bios_size + 0xfff) & ~0xfff;
4c823cff
JM
159 if (bios_size > 0x00080000) {
160 /* As the NVRAM is located at 0xFFF04000, we cannot use 1 MB BIOSes */
161 cpu_abort(env, "G3BW Mac hardware can not handle 1 MB BIOS\n");
162 }
3cbee15b
JM
163 cpu_register_physical_memory((uint32_t)(-bios_size),
164 bios_size, bios_offset | IO_MEM_ROM);
165
166 /* allocate and load VGA BIOS */
167 vga_bios_offset = bios_offset + bios_size;
168 snprintf(buf, sizeof(buf), "%s/%s", bios_dir, VGABIOS_FILENAME);
169 vga_bios_size = load_image(buf, phys_ram_base + vga_bios_offset + 8);
170 if (vga_bios_size < 0) {
171 /* if no bios is present, we can still work */
172 fprintf(stderr, "qemu: warning: could not load VGA bios '%s'\n", buf);
173 vga_bios_size = 0;
174 } else {
175 /* set a specific header (XXX: find real Apple format for NDRV
176 drivers) */
177 phys_ram_base[vga_bios_offset] = 'N';
178 phys_ram_base[vga_bios_offset + 1] = 'D';
179 phys_ram_base[vga_bios_offset + 2] = 'R';
180 phys_ram_base[vga_bios_offset + 3] = 'V';
181 cpu_to_be32w((uint32_t *)(phys_ram_base + vga_bios_offset + 4),
182 vga_bios_size);
183 vga_bios_size += 8;
184 }
185 vga_bios_size = (vga_bios_size + 0xfff) & ~0xfff;
186
187 if (linux_boot) {
188 kernel_base = KERNEL_LOAD_ADDR;
189 /* now we can load the kernel */
190 kernel_size = load_image(kernel_filename, phys_ram_base + kernel_base);
191 if (kernel_size < 0) {
192 cpu_abort(env, "qemu: could not load kernel '%s'\n",
193 kernel_filename);
194 exit(1);
195 }
196 /* load initrd */
197 if (initrd_filename) {
198 initrd_base = INITRD_LOAD_ADDR;
199 initrd_size = load_image(initrd_filename,
200 phys_ram_base + initrd_base);
201 if (initrd_size < 0) {
202 cpu_abort(env, "qemu: could not load initial ram disk '%s'\n",
203 initrd_filename);
204 exit(1);
205 }
206 } else {
207 initrd_base = 0;
208 initrd_size = 0;
209 }
6ac0e82d 210 ppc_boot_device = 'm';
3cbee15b
JM
211 } else {
212 kernel_base = 0;
213 kernel_size = 0;
214 initrd_base = 0;
215 initrd_size = 0;
28c5af54 216 ppc_boot_device = '\0';
0d913fdb 217 for (i = 0; boot_device[i] != '\0'; i++) {
28c5af54 218 /* TOFIX: for now, the second IDE channel is not properly
0d913fdb 219 * used by OHW. The Mac floppy disk are not emulated.
28c5af54
JM
220 * For now, OHW cannot boot from the network.
221 */
222#if 0
0d913fdb
JM
223 if (boot_device[i] >= 'a' && boot_device[i] <= 'f') {
224 ppc_boot_device = boot_device[i];
28c5af54 225 break;
0d913fdb 226 }
28c5af54 227#else
0d913fdb
JM
228 if (boot_device[i] >= 'c' && boot_device[i] <= 'd') {
229 ppc_boot_device = boot_device[i];
28c5af54 230 break;
0d913fdb 231 }
28c5af54
JM
232#endif
233 }
234 if (ppc_boot_device == '\0') {
235 fprintf(stderr, "No valid boot device for Mac99 machine\n");
236 exit(1);
237 }
3cbee15b
JM
238 }
239
240 isa_mem_base = 0x80000000;
241
242 /* Register 2 MB of ISA IO space */
243 isa_mmio_init(0xfe000000, 0x00200000);
244
245 /* XXX: we register only 1 output pin for heathrow PIC */
246 heathrow_irqs = qemu_mallocz(smp_cpus * sizeof(qemu_irq *));
247 heathrow_irqs[0] =
248 qemu_mallocz(smp_cpus * sizeof(qemu_irq) * 1);
249 /* Connect the heathrow PIC outputs to the 6xx bus */
250 for (i = 0; i < smp_cpus; i++) {
251 switch (PPC_INPUT(env)) {
252 case PPC_FLAGS_INPUT_6xx:
253 heathrow_irqs[i] = heathrow_irqs[0] + (i * 1);
254 heathrow_irqs[i][0] =
255 ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_INT];
256 break;
257 default:
258 cpu_abort(env, "Bus model not supported on OldWorld Mac machine\n");
259 exit(1);
260 }
261 }
262
263 /* init basic PC hardware */
264 if (PPC_INPUT(env) != PPC_FLAGS_INPUT_6xx) {
265 cpu_abort(env, "Only 6xx bus is supported on heathrow machine\n");
266 exit(1);
267 }
268 pic = heathrow_pic_init(&pic_mem_index, 1, heathrow_irqs);
269 pci_bus = pci_grackle_init(0xfec00000, pic);
270 pci_vga_init(pci_bus, ds, phys_ram_base + ram_size,
271 ram_size, vga_ram_size,
272 vga_bios_offset, vga_bios_size);
273
274 /* XXX: suppress that */
275 dummy_irq = i8259_init(NULL);
276
277 /* XXX: use Mac Serial port */
278 serial_init(0x3f8, dummy_irq[4], serial_hds[0]);
279
280 for(i = 0; i < nb_nics; i++) {
281 if (!nd_table[i].model)
282 nd_table[i].model = "ne2k_pci";
283 pci_nic_init(pci_bus, &nd_table[i], -1);
284 }
0d913fdb
JM
285
286 /* First IDE channel is a CMD646 on the PCI bus */
3cbee15b 287 pci_cmd646_ide_init(pci_bus, &bs_table[0], 0);
0d913fdb
JM
288 /* Second IDE channel is a MAC IDE on the MacIO bus */
289 ide_mem_index[0] = -1;
290 ide_mem_index[1] = pmac_ide_init(&bs_table[2], pic[0x0D]);
3cbee15b
JM
291
292 /* cuda also initialize ADB */
293 cuda_init(&cuda_mem_index, pic[0x12]);
294
295 adb_kbd_init(&adb_bus);
296 adb_mouse_init(&adb_bus);
297
74e91155 298 nvr = macio_nvram_init(&nvram_mem_index, 0x2000);
3cbee15b
JM
299 pmac_format_nvram_partition(nvr, 0x2000);
300
301 dbdma_init(&dbdma_mem_index);
28c5af54 302
3cbee15b 303 macio_init(pci_bus, 0x0017, 1, pic_mem_index, dbdma_mem_index,
0d913fdb 304 cuda_mem_index, nvr, 2, ide_mem_index);
3cbee15b
JM
305
306 if (usb_enabled) {
307 usb_ohci_init_pci(pci_bus, 3, -1);
308 }
309
310 if (graphic_depth != 15 && graphic_depth != 32 && graphic_depth != 8)
311 graphic_depth = 15;
312
313 m48t59 = m48t59_init(dummy_irq[8], 0xFFF04000, 0x0074, NVRAM_SIZE, 59);
314 nvram.opaque = m48t59;
315 nvram.read_fn = &m48t59_read;
316 nvram.write_fn = &m48t59_write;
6ac0e82d
AZ
317 PPC_NVRAM_set_params(&nvram, NVRAM_SIZE, "HEATHROW", ram_size,
318 ppc_boot_device, kernel_base, kernel_size,
3cbee15b
JM
319 kernel_cmdline,
320 initrd_base, initrd_size,
321 /* XXX: need an option to load a NVRAM image */
322 0,
323 graphic_width, graphic_height, graphic_depth);
324 /* No PCI init: the BIOS will do it */
325
326 /* Special port to get debug messages from Open-Firmware */
327 register_ioport_write(0x0F00, 4, 1, &PPC_debug_write, NULL);
328}
329
330QEMUMachine heathrow_machine = {
331 "g3bw",
332 "Heathrow based PowerMAC",
333 ppc_heathrow_init,
334};