]>
Commit | Line | Data |
---|---|---|
64201201 | 1 | /* |
3cbee15b | 2 | * QEMU PowerPC CHRP (currently NewWorld PowerMac) hardware System Emulator |
5fafdf24 | 3 | * |
47103572 | 4 | * Copyright (c) 2004-2007 Fabrice Bellard |
3cbee15b | 5 | * Copyright (c) 2007 Jocelyn Mayer |
5fafdf24 | 6 | * |
64201201 FB |
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" | |
3cbee15b | 26 | #include "ppc_mac.h" |
267002cd | 27 | |
0aa6a4a2 FB |
28 | /* UniN device */ |
29 | static void unin_writel (void *opaque, target_phys_addr_t addr, uint32_t value) | |
30 | { | |
31 | } | |
32 | ||
33 | static uint32_t unin_readl (void *opaque, target_phys_addr_t addr) | |
34 | { | |
35 | return 0; | |
36 | } | |
37 | ||
38 | static CPUWriteMemoryFunc *unin_write[] = { | |
39 | &unin_writel, | |
40 | &unin_writel, | |
41 | &unin_writel, | |
42 | }; | |
43 | ||
44 | static CPUReadMemoryFunc *unin_read[] = { | |
45 | &unin_readl, | |
46 | &unin_readl, | |
47 | &unin_readl, | |
48 | }; | |
49 | ||
3cbee15b JM |
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, | |
53 | int snapshot, | |
54 | const char *kernel_filename, | |
55 | const char *kernel_cmdline, | |
56 | const char *initrd_filename, | |
57 | const char *cpu_model) | |
64201201 | 58 | { |
e9df014c | 59 | CPUState *env, *envs[MAX_CPUS]; |
64201201 | 60 | char buf[1024]; |
e9df014c | 61 | qemu_irq *pic, **openpic_irqs; |
aef445bd | 62 | int unin_memory; |
d5295253 FB |
63 | int linux_boot, i; |
64 | unsigned long bios_offset, vga_bios_offset; | |
b6b8bd18 | 65 | uint32_t kernel_base, kernel_size, initrd_base, initrd_size; |
3fc6c082 | 66 | ppc_def_t *def; |
46e50e9d | 67 | PCIBus *pci_bus; |
3cbee15b JM |
68 | nvram_t nvram; |
69 | #if 0 | |
70 | MacIONVRAMState *nvr; | |
71 | int nvram_mem_index; | |
72 | #endif | |
73 | m48t59_t *m48t59; | |
d5295253 | 74 | int vga_bios_size, bios_size; |
d537cf6c | 75 | qemu_irq *dummy_irq; |
3cbee15b JM |
76 | int pic_mem_index, dbdma_mem_index, cuda_mem_index; |
77 | int ide_mem_index[2]; | |
46e50e9d | 78 | |
64201201 FB |
79 | linux_boot = (kernel_filename != NULL); |
80 | ||
c68ea704 FB |
81 | /* init CPUs */ |
82 | env = cpu_init(); | |
94fc95cd | 83 | if (cpu_model == NULL) |
d12f4c38 | 84 | cpu_model = "default"; |
94fc95cd | 85 | ppc_find_by_name(cpu_model, &def); |
c68ea704 FB |
86 | if (def == NULL) { |
87 | cpu_abort(env, "Unable to find PowerPC CPU definition\n"); | |
88 | } | |
e9df014c JM |
89 | for (i = 0; i < smp_cpus; i++) { |
90 | cpu_ppc_register(env, def); | |
fe33cc71 | 91 | cpu_ppc_reset(env); |
e9df014c JM |
92 | /* Set time-base frequency to 100 Mhz */ |
93 | cpu_ppc_tb_init(env, 100UL * 1000UL * 1000UL); | |
3cbee15b | 94 | #if 0 |
e9df014c | 95 | env->osi_call = vga_osi_call; |
3cbee15b | 96 | #endif |
fe33cc71 JM |
97 | qemu_register_reset(&cpu_ppc_reset, env); |
98 | register_savevm("cpu", 0, 3, cpu_save, cpu_load, env); | |
e9df014c JM |
99 | envs[i] = env; |
100 | } | |
c68ea704 | 101 | |
64201201 FB |
102 | /* allocate RAM */ |
103 | cpu_register_physical_memory(0, ram_size, IO_MEM_RAM); | |
104 | ||
105 | /* allocate and load BIOS */ | |
106 | bios_offset = ram_size + vga_ram_size; | |
1192dad8 JM |
107 | if (bios_name == NULL) |
108 | bios_name = BIOS_FILENAME; | |
109 | snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name); | |
d5295253 FB |
110 | bios_size = load_image(buf, phys_ram_base + bios_offset); |
111 | if (bios_size < 0 || bios_size > BIOS_SIZE) { | |
4a057712 | 112 | cpu_abort(env, "qemu: could not load PowerPC bios '%s'\n", buf); |
64201201 FB |
113 | exit(1); |
114 | } | |
d5295253 | 115 | bios_size = (bios_size + 0xfff) & ~0xfff; |
4a057712 | 116 | cpu_register_physical_memory((uint32_t)(-bios_size), |
d5295253 | 117 | bios_size, bios_offset | IO_MEM_ROM); |
3b46e624 | 118 | |
d5295253 FB |
119 | /* allocate and load VGA BIOS */ |
120 | vga_bios_offset = bios_offset + bios_size; | |
121 | snprintf(buf, sizeof(buf), "%s/%s", bios_dir, VGABIOS_FILENAME); | |
122 | vga_bios_size = load_image(buf, phys_ram_base + vga_bios_offset + 8); | |
123 | if (vga_bios_size < 0) { | |
124 | /* if no bios is present, we can still work */ | |
125 | fprintf(stderr, "qemu: warning: could not load VGA bios '%s'\n", buf); | |
126 | vga_bios_size = 0; | |
127 | } else { | |
128 | /* set a specific header (XXX: find real Apple format for NDRV | |
129 | drivers) */ | |
130 | phys_ram_base[vga_bios_offset] = 'N'; | |
131 | phys_ram_base[vga_bios_offset + 1] = 'D'; | |
132 | phys_ram_base[vga_bios_offset + 2] = 'R'; | |
133 | phys_ram_base[vga_bios_offset + 3] = 'V'; | |
5fafdf24 | 134 | cpu_to_be32w((uint32_t *)(phys_ram_base + vga_bios_offset + 4), |
d5295253 FB |
135 | vga_bios_size); |
136 | vga_bios_size += 8; | |
137 | } | |
138 | vga_bios_size = (vga_bios_size + 0xfff) & ~0xfff; | |
3b46e624 | 139 | |
b6b8bd18 FB |
140 | if (linux_boot) { |
141 | kernel_base = KERNEL_LOAD_ADDR; | |
142 | /* now we can load the kernel */ | |
143 | kernel_size = load_image(kernel_filename, phys_ram_base + kernel_base); | |
144 | if (kernel_size < 0) { | |
4a057712 JM |
145 | cpu_abort(env, "qemu: could not load kernel '%s'\n", |
146 | kernel_filename); | |
b6b8bd18 FB |
147 | exit(1); |
148 | } | |
149 | /* load initrd */ | |
150 | if (initrd_filename) { | |
151 | initrd_base = INITRD_LOAD_ADDR; | |
152 | initrd_size = load_image(initrd_filename, | |
153 | phys_ram_base + initrd_base); | |
154 | if (initrd_size < 0) { | |
4a057712 JM |
155 | cpu_abort(env, "qemu: could not load initial ram disk '%s'\n", |
156 | initrd_filename); | |
b6b8bd18 FB |
157 | exit(1); |
158 | } | |
159 | } else { | |
160 | initrd_base = 0; | |
161 | initrd_size = 0; | |
162 | } | |
163 | boot_device = 'm'; | |
164 | } else { | |
165 | kernel_base = 0; | |
166 | kernel_size = 0; | |
167 | initrd_base = 0; | |
168 | initrd_size = 0; | |
169 | } | |
0aa6a4a2 | 170 | |
3cbee15b | 171 | isa_mem_base = 0x80000000; |
aef445bd | 172 | |
3cbee15b JM |
173 | /* Register 8 MB of ISA IO space */ |
174 | isa_mmio_init(0xf2000000, 0x00800000); | |
3b46e624 | 175 | |
3cbee15b JM |
176 | /* UniN init */ |
177 | unin_memory = cpu_register_io_memory(0, unin_read, unin_write, NULL); | |
178 | cpu_register_physical_memory(0xf8000000, 0x00001000, unin_memory); | |
47103572 | 179 | |
3cbee15b JM |
180 | openpic_irqs = qemu_mallocz(smp_cpus * sizeof(qemu_irq *)); |
181 | openpic_irqs[0] = | |
182 | qemu_mallocz(smp_cpus * sizeof(qemu_irq) * OPENPIC_OUTPUT_NB); | |
183 | for (i = 0; i < smp_cpus; i++) { | |
184 | /* Mac99 IRQ connection between OpenPIC outputs pins | |
185 | * and PowerPC input pins | |
186 | */ | |
187 | switch (PPC_INPUT(env)) { | |
188 | case PPC_FLAGS_INPUT_6xx: | |
189 | openpic_irqs[i] = openpic_irqs[0] + (i * OPENPIC_OUTPUT_NB); | |
190 | openpic_irqs[i][OPENPIC_OUTPUT_INT] = | |
191 | ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_INT]; | |
192 | openpic_irqs[i][OPENPIC_OUTPUT_CINT] = | |
193 | ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_INT]; | |
194 | openpic_irqs[i][OPENPIC_OUTPUT_MCK] = | |
195 | ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_MCP]; | |
196 | /* Not connected ? */ | |
197 | openpic_irqs[i][OPENPIC_OUTPUT_DEBUG] = NULL; | |
198 | /* Check this */ | |
199 | openpic_irqs[i][OPENPIC_OUTPUT_RESET] = | |
200 | ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_HRESET]; | |
201 | break; | |
00af685f | 202 | #if defined(TARGET_PPC64) |
3cbee15b JM |
203 | case PPC_FLAGS_INPUT_970: |
204 | openpic_irqs[i] = openpic_irqs[0] + (i * OPENPIC_OUTPUT_NB); | |
205 | openpic_irqs[i][OPENPIC_OUTPUT_INT] = | |
206 | ((qemu_irq *)env->irq_inputs)[PPC970_INPUT_INT]; | |
207 | openpic_irqs[i][OPENPIC_OUTPUT_CINT] = | |
208 | ((qemu_irq *)env->irq_inputs)[PPC970_INPUT_INT]; | |
209 | openpic_irqs[i][OPENPIC_OUTPUT_MCK] = | |
210 | ((qemu_irq *)env->irq_inputs)[PPC970_INPUT_MCP]; | |
211 | /* Not connected ? */ | |
212 | openpic_irqs[i][OPENPIC_OUTPUT_DEBUG] = NULL; | |
213 | /* Check this */ | |
214 | openpic_irqs[i][OPENPIC_OUTPUT_RESET] = | |
215 | ((qemu_irq *)env->irq_inputs)[PPC970_INPUT_HRESET]; | |
216 | break; | |
00af685f | 217 | #endif /* defined(TARGET_PPC64) */ |
3cbee15b JM |
218 | default: |
219 | cpu_abort(env, "Bus model not supported on mac99 machine\n"); | |
220 | exit(1); | |
0aa6a4a2 | 221 | } |
3cbee15b JM |
222 | } |
223 | pic = openpic_init(NULL, &pic_mem_index, smp_cpus, openpic_irqs, NULL); | |
224 | pci_bus = pci_pmac_init(pic); | |
225 | /* init basic PC hardware */ | |
226 | pci_vga_init(pci_bus, ds, phys_ram_base + ram_size, | |
227 | ram_size, vga_ram_size, | |
228 | vga_bios_offset, vga_bios_size); | |
229 | ||
230 | /* XXX: suppress that */ | |
231 | dummy_irq = i8259_init(NULL); | |
232 | ||
233 | /* XXX: use Mac Serial port */ | |
234 | serial_init(0x3f8, dummy_irq[4], serial_hds[0]); | |
235 | for(i = 0; i < nb_nics; i++) { | |
236 | if (!nd_table[i].model) | |
237 | nd_table[i].model = "ne2k_pci"; | |
238 | pci_nic_init(pci_bus, &nd_table[i], -1); | |
239 | } | |
0aa6a4a2 | 240 | #if 1 |
3cbee15b JM |
241 | ide_mem_index[0] = pmac_ide_init(&bs_table[0], pic[0x13]); |
242 | ide_mem_index[1] = pmac_ide_init(&bs_table[2], pic[0x14]); | |
0aa6a4a2 | 243 | #else |
3cbee15b | 244 | pci_cmd646_ide_init(pci_bus, &bs_table[0], 0); |
0aa6a4a2 | 245 | #endif |
3cbee15b JM |
246 | /* cuda also initialize ADB */ |
247 | cuda_init(&cuda_mem_index, pic[0x19]); | |
248 | ||
249 | adb_kbd_init(&adb_bus); | |
250 | adb_mouse_init(&adb_bus); | |
3b46e624 | 251 | |
3cbee15b | 252 | dbdma_init(&dbdma_mem_index); |
3b46e624 | 253 | |
3cbee15b JM |
254 | macio_init(pci_bus, 0x0022, 0, pic_mem_index, dbdma_mem_index, |
255 | cuda_mem_index, -1, 2, ide_mem_index); | |
0d92ed30 PB |
256 | |
257 | if (usb_enabled) { | |
e24ad6f1 | 258 | usb_ohci_init_pci(pci_bus, 3, -1); |
0d92ed30 PB |
259 | } |
260 | ||
b6b8bd18 FB |
261 | if (graphic_depth != 15 && graphic_depth != 32 && graphic_depth != 8) |
262 | graphic_depth = 15; | |
3cbee15b JM |
263 | #if 0 /* XXX: this is ugly but needed for now, or OHW won't boot */ |
264 | /* The NewWorld NVRAM is not located in the MacIO device */ | |
265 | nvr = macio_nvram_init(&nvram_mem_index); | |
266 | pmac_format_nvram_partition(nvr, 0x2000); | |
267 | cpu_register_physical_memory(0xFFF04000, 0x20000, nvram_mem_index); | |
268 | nvram.opaque = nvr; | |
269 | nvram.read_fn = &macio_nvram_read; | |
270 | nvram.write_fn = &macio_nvram_write; | |
271 | #else | |
272 | m48t59 = m48t59_init(dummy_irq[8], 0xFFF04000, 0x0074, NVRAM_SIZE, 59); | |
273 | nvram.opaque = m48t59; | |
274 | nvram.read_fn = &m48t59_read; | |
275 | nvram.write_fn = &m48t59_write; | |
276 | #endif | |
277 | PPC_NVRAM_set_params(&nvram, NVRAM_SIZE, "MAC99", ram_size, boot_device, | |
b6b8bd18 FB |
278 | kernel_base, kernel_size, |
279 | kernel_cmdline, | |
280 | initrd_base, initrd_size, | |
64201201 | 281 | /* XXX: need an option to load a NVRAM image */ |
b6b8bd18 FB |
282 | 0, |
283 | graphic_width, graphic_height, graphic_depth); | |
284 | /* No PCI init: the BIOS will do it */ | |
0aa6a4a2 FB |
285 | |
286 | /* Special port to get debug messages from Open-Firmware */ | |
287 | register_ioport_write(0x0F00, 4, 1, &PPC_debug_write, NULL); | |
3cbee15b | 288 | } |
0aa6a4a2 FB |
289 | |
290 | QEMUMachine core99_machine = { | |
0289b2c1 FB |
291 | "mac99", |
292 | "Mac99 based PowerMAC", | |
0aa6a4a2 FB |
293 | ppc_core99_init, |
294 | }; |