]>
Commit | Line | Data |
---|---|---|
420557e8 | 1 | /* |
ee76f82e | 2 | * QEMU Sun4m & Sun4d & Sun4c System Emulator |
5fafdf24 | 3 | * |
b81b3b10 | 4 | * Copyright (c) 2003-2005 Fabrice Bellard |
5fafdf24 | 5 | * |
420557e8 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 | */ | |
9d07d757 | 24 | #include "sysbus.h" |
87ecb68b PB |
25 | #include "qemu-timer.h" |
26 | #include "sun4m.h" | |
27 | #include "nvram.h" | |
28 | #include "sparc32_dma.h" | |
29 | #include "fdc.h" | |
30 | #include "sysemu.h" | |
31 | #include "net.h" | |
32 | #include "boards.h" | |
d2c63fc1 | 33 | #include "firmware_abi.h" |
8b17de88 | 34 | #include "scsi.h" |
22548760 BS |
35 | #include "pc.h" |
36 | #include "isa.h" | |
3cce6243 | 37 | #include "fw_cfg.h" |
b4ed08e0 | 38 | #include "escc.h" |
d2c63fc1 | 39 | |
b3a23197 | 40 | //#define DEBUG_IRQ |
420557e8 | 41 | |
36cd9210 BS |
42 | /* |
43 | * Sun4m architecture was used in the following machines: | |
44 | * | |
45 | * SPARCserver 6xxMP/xx | |
77f193da BS |
46 | * SPARCclassic (SPARCclassic Server)(SPARCstation LC) (4/15), |
47 | * SPARCclassic X (4/10) | |
36cd9210 BS |
48 | * SPARCstation LX/ZX (4/30) |
49 | * SPARCstation Voyager | |
50 | * SPARCstation 10/xx, SPARCserver 10/xx | |
51 | * SPARCstation 5, SPARCserver 5 | |
52 | * SPARCstation 20/xx, SPARCserver 20 | |
53 | * SPARCstation 4 | |
54 | * | |
7d85892b BS |
55 | * Sun4d architecture was used in the following machines: |
56 | * | |
57 | * SPARCcenter 2000 | |
58 | * SPARCserver 1000 | |
59 | * | |
ee76f82e BS |
60 | * Sun4c architecture was used in the following machines: |
61 | * SPARCstation 1/1+, SPARCserver 1/1+ | |
62 | * SPARCstation SLC | |
63 | * SPARCstation IPC | |
64 | * SPARCstation ELC | |
65 | * SPARCstation IPX | |
66 | * | |
36cd9210 BS |
67 | * See for example: http://www.sunhelp.org/faq/sunref1.html |
68 | */ | |
69 | ||
b3a23197 | 70 | #ifdef DEBUG_IRQ |
001faf32 BS |
71 | #define DPRINTF(fmt, ...) \ |
72 | do { printf("CPUIRQ: " fmt , ## __VA_ARGS__); } while (0) | |
b3a23197 | 73 | #else |
001faf32 | 74 | #define DPRINTF(fmt, ...) |
b3a23197 BS |
75 | #endif |
76 | ||
420557e8 | 77 | #define KERNEL_LOAD_ADDR 0x00004000 |
b6f479d3 | 78 | #define CMDLINE_ADDR 0x007ff000 |
713c45fa | 79 | #define INITRD_LOAD_ADDR 0x00800000 |
a7227727 | 80 | #define PROM_SIZE_MAX (1024 * 1024) |
40ce0a9a | 81 | #define PROM_VADDR 0xffd00000 |
f930d07e | 82 | #define PROM_FILENAME "openbios-sparc32" |
3cce6243 | 83 | #define CFG_ADDR 0xd00000510ULL |
fbfcf955 | 84 | #define FW_CFG_SUN4M_DEPTH (FW_CFG_ARCH_LOCAL + 0x00) |
b8174937 | 85 | |
ba3c64fb | 86 | #define MAX_CPUS 16 |
b3a23197 | 87 | #define MAX_PILS 16 |
420557e8 | 88 | |
b4ed08e0 BS |
89 | #define ESCC_CLOCK 4915200 |
90 | ||
8137cde8 | 91 | struct sun4m_hwdef { |
5dcb6b91 BS |
92 | target_phys_addr_t iommu_base, slavio_base; |
93 | target_phys_addr_t intctl_base, counter_base, nvram_base, ms_kb_base; | |
94 | target_phys_addr_t serial_base, fd_base; | |
4c2485de | 95 | target_phys_addr_t idreg_base, dma_base, esp_base, le_base; |
0019ad53 | 96 | target_phys_addr_t tcx_base, cs_base, apc_base, aux1_base, aux2_base; |
7eb0c8e8 BS |
97 | target_phys_addr_t ecc_base; |
98 | uint32_t ecc_version; | |
36cd9210 | 99 | long vram_size, nvram_size; |
6341fdcb | 100 | // IRQ numbers are not PIL ones, but master interrupt controller |
e3a79bca | 101 | // register bit numbers |
1572a18c | 102 | int esp_irq, le_irq, clock_irq, clock1_irq; |
e42c20b4 | 103 | int ser_irq, ms_kb_irq, fd_irq, me_irq, cs_irq, ecc_irq; |
905fdcb5 BS |
104 | uint8_t nvram_machine_id; |
105 | uint16_t machine_id; | |
7fbfb139 | 106 | uint32_t iommu_version; |
e0353fe2 | 107 | uint32_t intbit_to_level[32]; |
3ebf5aaf BS |
108 | uint64_t max_mem; |
109 | const char * const default_cpu_model; | |
36cd9210 BS |
110 | }; |
111 | ||
7d85892b BS |
112 | #define MAX_IOUNITS 5 |
113 | ||
114 | struct sun4d_hwdef { | |
115 | target_phys_addr_t iounit_bases[MAX_IOUNITS], slavio_base; | |
116 | target_phys_addr_t counter_base, nvram_base, ms_kb_base; | |
117 | target_phys_addr_t serial_base; | |
118 | target_phys_addr_t espdma_base, esp_base; | |
119 | target_phys_addr_t ledma_base, le_base; | |
120 | target_phys_addr_t tcx_base; | |
121 | target_phys_addr_t sbi_base; | |
122 | unsigned long vram_size, nvram_size; | |
123 | // IRQ numbers are not PIL ones, but SBI register bit numbers | |
124 | int esp_irq, le_irq, clock_irq, clock1_irq; | |
125 | int ser_irq, ms_kb_irq, me_irq; | |
905fdcb5 BS |
126 | uint8_t nvram_machine_id; |
127 | uint16_t machine_id; | |
7d85892b BS |
128 | uint32_t iounit_version; |
129 | uint64_t max_mem; | |
130 | const char * const default_cpu_model; | |
131 | }; | |
132 | ||
8137cde8 BS |
133 | struct sun4c_hwdef { |
134 | target_phys_addr_t iommu_base, slavio_base; | |
135 | target_phys_addr_t intctl_base, counter_base, nvram_base, ms_kb_base; | |
136 | target_phys_addr_t serial_base, fd_base; | |
137 | target_phys_addr_t idreg_base, dma_base, esp_base, le_base; | |
1572a18c | 138 | target_phys_addr_t tcx_base, aux1_base; |
8137cde8 BS |
139 | long vram_size, nvram_size; |
140 | // IRQ numbers are not PIL ones, but master interrupt controller | |
141 | // register bit numbers | |
1572a18c BS |
142 | int esp_irq, le_irq, clock_irq, clock1_irq; |
143 | int ser_irq, ms_kb_irq, fd_irq, me_irq; | |
8137cde8 BS |
144 | uint8_t nvram_machine_id; |
145 | uint16_t machine_id; | |
146 | uint32_t iommu_version; | |
147 | uint32_t intbit_to_level[32]; | |
148 | uint64_t max_mem; | |
149 | const char * const default_cpu_model; | |
150 | }; | |
151 | ||
6f7e9aec FB |
152 | int DMA_get_channel_mode (int nchan) |
153 | { | |
154 | return 0; | |
155 | } | |
156 | int DMA_read_memory (int nchan, void *buf, int pos, int size) | |
157 | { | |
158 | return 0; | |
159 | } | |
160 | int DMA_write_memory (int nchan, void *buf, int pos, int size) | |
161 | { | |
162 | return 0; | |
163 | } | |
164 | void DMA_hold_DREQ (int nchan) {} | |
165 | void DMA_release_DREQ (int nchan) {} | |
166 | void DMA_schedule(int nchan) {} | |
6f7e9aec FB |
167 | void DMA_init (int high_page_enable) {} |
168 | void DMA_register_channel (int nchan, | |
169 | DMA_transfer_handler transfer_handler, | |
170 | void *opaque) | |
171 | { | |
172 | } | |
173 | ||
513f789f | 174 | static int fw_cfg_boot_set(void *opaque, const char *boot_device) |
81864572 | 175 | { |
513f789f | 176 | fw_cfg_add_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]); |
81864572 BS |
177 | return 0; |
178 | } | |
179 | ||
819385c5 | 180 | static void nvram_init(m48t59_t *nvram, uint8_t *macaddr, const char *cmdline, |
6ef05b95 | 181 | const char *boot_devices, ram_addr_t RAM_size, |
f930d07e BS |
182 | uint32_t kernel_size, |
183 | int width, int height, int depth, | |
905fdcb5 | 184 | int nvram_machine_id, const char *arch) |
e80cfcfc | 185 | { |
d2c63fc1 | 186 | unsigned int i; |
66508601 | 187 | uint32_t start, end; |
d2c63fc1 | 188 | uint8_t image[0x1ff0]; |
d2c63fc1 BS |
189 | struct OpenBIOS_nvpart_v1 *part_header; |
190 | ||
191 | memset(image, '\0', sizeof(image)); | |
e80cfcfc | 192 | |
513f789f | 193 | start = 0; |
b6f479d3 | 194 | |
66508601 BS |
195 | // OpenBIOS nvram variables |
196 | // Variable partition | |
d2c63fc1 BS |
197 | part_header = (struct OpenBIOS_nvpart_v1 *)&image[start]; |
198 | part_header->signature = OPENBIOS_PART_SYSTEM; | |
363a37d5 | 199 | pstrcpy(part_header->name, sizeof(part_header->name), "system"); |
66508601 | 200 | |
d2c63fc1 | 201 | end = start + sizeof(struct OpenBIOS_nvpart_v1); |
66508601 | 202 | for (i = 0; i < nb_prom_envs; i++) |
d2c63fc1 BS |
203 | end = OpenBIOS_set_var(image, end, prom_envs[i]); |
204 | ||
205 | // End marker | |
206 | image[end++] = '\0'; | |
66508601 | 207 | |
66508601 | 208 | end = start + ((end - start + 15) & ~15); |
d2c63fc1 | 209 | OpenBIOS_finish_partition(part_header, end - start); |
66508601 BS |
210 | |
211 | // free partition | |
212 | start = end; | |
d2c63fc1 BS |
213 | part_header = (struct OpenBIOS_nvpart_v1 *)&image[start]; |
214 | part_header->signature = OPENBIOS_PART_FREE; | |
363a37d5 | 215 | pstrcpy(part_header->name, sizeof(part_header->name), "free"); |
66508601 BS |
216 | |
217 | end = 0x1fd0; | |
d2c63fc1 BS |
218 | OpenBIOS_finish_partition(part_header, end - start); |
219 | ||
905fdcb5 BS |
220 | Sun_init_header((struct Sun_nvram *)&image[0x1fd8], macaddr, |
221 | nvram_machine_id); | |
d2c63fc1 BS |
222 | |
223 | for (i = 0; i < sizeof(image); i++) | |
224 | m48t59_write(nvram, i, image[i]); | |
e80cfcfc FB |
225 | } |
226 | ||
227 | static void *slavio_intctl; | |
228 | ||
376253ec | 229 | void pic_info(Monitor *mon) |
e80cfcfc | 230 | { |
7d85892b | 231 | if (slavio_intctl) |
376253ec | 232 | slavio_pic_info(mon, slavio_intctl); |
e80cfcfc FB |
233 | } |
234 | ||
376253ec | 235 | void irq_info(Monitor *mon) |
e80cfcfc | 236 | { |
7d85892b | 237 | if (slavio_intctl) |
376253ec | 238 | slavio_irq_info(mon, slavio_intctl); |
e80cfcfc FB |
239 | } |
240 | ||
327ac2e7 BS |
241 | void cpu_check_irqs(CPUState *env) |
242 | { | |
243 | if (env->pil_in && (env->interrupt_index == 0 || | |
244 | (env->interrupt_index & ~15) == TT_EXTINT)) { | |
245 | unsigned int i; | |
246 | ||
247 | for (i = 15; i > 0; i--) { | |
248 | if (env->pil_in & (1 << i)) { | |
249 | int old_interrupt = env->interrupt_index; | |
250 | ||
251 | env->interrupt_index = TT_EXTINT | i; | |
f32d7ec5 BS |
252 | if (old_interrupt != env->interrupt_index) { |
253 | DPRINTF("Set CPU IRQ %d\n", i); | |
327ac2e7 | 254 | cpu_interrupt(env, CPU_INTERRUPT_HARD); |
f32d7ec5 | 255 | } |
327ac2e7 BS |
256 | break; |
257 | } | |
258 | } | |
259 | } else if (!env->pil_in && (env->interrupt_index & ~15) == TT_EXTINT) { | |
f32d7ec5 | 260 | DPRINTF("Reset CPU IRQ %d\n", env->interrupt_index & 15); |
327ac2e7 BS |
261 | env->interrupt_index = 0; |
262 | cpu_reset_interrupt(env, CPU_INTERRUPT_HARD); | |
263 | } | |
264 | } | |
265 | ||
b3a23197 BS |
266 | static void cpu_set_irq(void *opaque, int irq, int level) |
267 | { | |
268 | CPUState *env = opaque; | |
269 | ||
270 | if (level) { | |
271 | DPRINTF("Raise CPU IRQ %d\n", irq); | |
b3a23197 | 272 | env->halted = 0; |
327ac2e7 BS |
273 | env->pil_in |= 1 << irq; |
274 | cpu_check_irqs(env); | |
b3a23197 BS |
275 | } else { |
276 | DPRINTF("Lower CPU IRQ %d\n", irq); | |
327ac2e7 BS |
277 | env->pil_in &= ~(1 << irq); |
278 | cpu_check_irqs(env); | |
b3a23197 BS |
279 | } |
280 | } | |
281 | ||
282 | static void dummy_cpu_set_irq(void *opaque, int irq, int level) | |
283 | { | |
284 | } | |
285 | ||
3475187d FB |
286 | static void *slavio_misc; |
287 | ||
288 | void qemu_system_powerdown(void) | |
289 | { | |
290 | slavio_set_power_fail(slavio_misc, 1); | |
291 | } | |
292 | ||
c68ea704 FB |
293 | static void main_cpu_reset(void *opaque) |
294 | { | |
295 | CPUState *env = opaque; | |
3d29fbef BS |
296 | |
297 | cpu_reset(env); | |
298 | env->halted = 0; | |
299 | } | |
300 | ||
301 | static void secondary_cpu_reset(void *opaque) | |
302 | { | |
303 | CPUState *env = opaque; | |
304 | ||
c68ea704 | 305 | cpu_reset(env); |
3d29fbef | 306 | env->halted = 1; |
c68ea704 FB |
307 | } |
308 | ||
6d0c293d BS |
309 | static void cpu_halt_signal(void *opaque, int irq, int level) |
310 | { | |
311 | if (level && cpu_single_env) | |
312 | cpu_interrupt(cpu_single_env, CPU_INTERRUPT_HALT); | |
313 | } | |
314 | ||
3ebf5aaf | 315 | static unsigned long sun4m_load_kernel(const char *kernel_filename, |
293f78bc BS |
316 | const char *initrd_filename, |
317 | ram_addr_t RAM_size) | |
3ebf5aaf BS |
318 | { |
319 | int linux_boot; | |
320 | unsigned int i; | |
321 | long initrd_size, kernel_size; | |
322 | ||
323 | linux_boot = (kernel_filename != NULL); | |
324 | ||
325 | kernel_size = 0; | |
326 | if (linux_boot) { | |
327 | kernel_size = load_elf(kernel_filename, -0xf0000000ULL, NULL, NULL, | |
328 | NULL); | |
329 | if (kernel_size < 0) | |
293f78bc BS |
330 | kernel_size = load_aout(kernel_filename, KERNEL_LOAD_ADDR, |
331 | RAM_size - KERNEL_LOAD_ADDR); | |
3ebf5aaf | 332 | if (kernel_size < 0) |
293f78bc BS |
333 | kernel_size = load_image_targphys(kernel_filename, |
334 | KERNEL_LOAD_ADDR, | |
335 | RAM_size - KERNEL_LOAD_ADDR); | |
3ebf5aaf BS |
336 | if (kernel_size < 0) { |
337 | fprintf(stderr, "qemu: could not load kernel '%s'\n", | |
338 | kernel_filename); | |
339 | exit(1); | |
340 | } | |
341 | ||
342 | /* load initrd */ | |
343 | initrd_size = 0; | |
344 | if (initrd_filename) { | |
293f78bc BS |
345 | initrd_size = load_image_targphys(initrd_filename, |
346 | INITRD_LOAD_ADDR, | |
347 | RAM_size - INITRD_LOAD_ADDR); | |
3ebf5aaf BS |
348 | if (initrd_size < 0) { |
349 | fprintf(stderr, "qemu: could not load initial ram disk '%s'\n", | |
350 | initrd_filename); | |
351 | exit(1); | |
352 | } | |
353 | } | |
354 | if (initrd_size > 0) { | |
355 | for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) { | |
293f78bc BS |
356 | if (ldl_phys(KERNEL_LOAD_ADDR + i) == 0x48647253) { // HdrS |
357 | stl_phys(KERNEL_LOAD_ADDR + i + 16, INITRD_LOAD_ADDR); | |
358 | stl_phys(KERNEL_LOAD_ADDR + i + 20, initrd_size); | |
3ebf5aaf BS |
359 | break; |
360 | } | |
361 | } | |
362 | } | |
363 | } | |
364 | return kernel_size; | |
365 | } | |
366 | ||
9d07d757 PB |
367 | static void lance_init(NICInfo *nd, target_phys_addr_t leaddr, |
368 | void *dma_opaque, qemu_irq irq, qemu_irq *reset) | |
369 | { | |
370 | DeviceState *dev; | |
371 | SysBusDevice *s; | |
372 | ||
373 | qemu_check_nic_model(&nd_table[0], "lance"); | |
374 | ||
375 | dev = qdev_create(NULL, "lance"); | |
376 | qdev_set_netdev(dev, nd); | |
377 | qdev_set_prop_ptr(dev, "dma", dma_opaque); | |
378 | qdev_init(dev); | |
379 | s = sysbus_from_qdev(dev); | |
380 | sysbus_mmio_map(s, 0, leaddr); | |
381 | sysbus_connect_irq(s, 0, irq); | |
067a3ddc | 382 | *reset = qdev_get_gpio_in(dev, 0); |
9d07d757 PB |
383 | } |
384 | ||
325f2747 BS |
385 | /* NCR89C100/MACIO Internal ID register */ |
386 | static const uint8_t idreg_data[] = { 0xfe, 0x81, 0x01, 0x03 }; | |
387 | ||
388 | static void idreg_init(target_phys_addr_t addr) | |
389 | { | |
390 | DeviceState *dev; | |
391 | SysBusDevice *s; | |
392 | ||
393 | dev = qdev_create(NULL, "macio_idreg"); | |
394 | qdev_init(dev); | |
395 | s = sysbus_from_qdev(dev); | |
396 | ||
397 | sysbus_mmio_map(s, 0, addr); | |
398 | cpu_physical_memory_write_rom(addr, idreg_data, sizeof(idreg_data)); | |
399 | } | |
400 | ||
401 | static void idreg_init1(SysBusDevice *dev) | |
402 | { | |
403 | ram_addr_t idreg_offset; | |
404 | ||
405 | idreg_offset = qemu_ram_alloc(sizeof(idreg_data)); | |
406 | sysbus_init_mmio(dev, sizeof(idreg_data), idreg_offset | IO_MEM_ROM); | |
407 | } | |
408 | ||
409 | static SysBusDeviceInfo idreg_info = { | |
410 | .init = idreg_init1, | |
411 | .qdev.name = "macio_idreg", | |
412 | .qdev.size = sizeof(SysBusDevice), | |
413 | .qdev.props = (DevicePropList[]) { | |
414 | {.name = NULL} | |
415 | } | |
416 | }; | |
417 | ||
418 | static void idreg_register_devices(void) | |
419 | { | |
420 | sysbus_register_withprop(&idreg_info); | |
421 | } | |
422 | ||
423 | device_init(idreg_register_devices); | |
424 | ||
f48f6569 BS |
425 | /* Boot PROM (OpenBIOS) */ |
426 | static void prom_init(target_phys_addr_t addr, const char *bios_name) | |
427 | { | |
428 | DeviceState *dev; | |
429 | SysBusDevice *s; | |
430 | char *filename; | |
431 | int ret; | |
432 | ||
433 | dev = qdev_create(NULL, "openprom"); | |
434 | qdev_init(dev); | |
435 | s = sysbus_from_qdev(dev); | |
436 | ||
437 | sysbus_mmio_map(s, 0, addr); | |
438 | ||
439 | /* load boot prom */ | |
440 | if (bios_name == NULL) { | |
441 | bios_name = PROM_FILENAME; | |
442 | } | |
443 | filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); | |
444 | if (filename) { | |
445 | ret = load_elf(filename, addr - PROM_VADDR, NULL, NULL, NULL); | |
446 | if (ret < 0 || ret > PROM_SIZE_MAX) { | |
447 | ret = load_image_targphys(filename, addr, PROM_SIZE_MAX); | |
448 | } | |
449 | qemu_free(filename); | |
450 | } else { | |
451 | ret = -1; | |
452 | } | |
453 | if (ret < 0 || ret > PROM_SIZE_MAX) { | |
454 | fprintf(stderr, "qemu: could not load prom '%s'\n", bios_name); | |
455 | exit(1); | |
456 | } | |
457 | } | |
458 | ||
459 | static void prom_init1(SysBusDevice *dev) | |
460 | { | |
461 | ram_addr_t prom_offset; | |
462 | ||
463 | prom_offset = qemu_ram_alloc(PROM_SIZE_MAX); | |
464 | sysbus_init_mmio(dev, PROM_SIZE_MAX, prom_offset | IO_MEM_ROM); | |
465 | } | |
466 | ||
467 | static SysBusDeviceInfo prom_info = { | |
468 | .init = prom_init1, | |
469 | .qdev.name = "openprom", | |
470 | .qdev.size = sizeof(SysBusDevice), | |
471 | .qdev.props = (DevicePropList[]) { | |
472 | {.name = NULL} | |
473 | } | |
474 | }; | |
475 | ||
476 | static void prom_register_devices(void) | |
477 | { | |
478 | sysbus_register_withprop(&prom_info); | |
479 | } | |
480 | ||
481 | device_init(prom_register_devices); | |
482 | ||
8137cde8 | 483 | static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size, |
3ebf5aaf | 484 | const char *boot_device, |
3023f332 | 485 | const char *kernel_filename, |
3ebf5aaf BS |
486 | const char *kernel_cmdline, |
487 | const char *initrd_filename, const char *cpu_model) | |
36cd9210 | 488 | |
420557e8 | 489 | { |
ba3c64fb | 490 | CPUState *env, *envs[MAX_CPUS]; |
713c45fa | 491 | unsigned int i; |
cfb9de9c | 492 | void *iommu, *espdma, *ledma, *nvram; |
b3a23197 | 493 | qemu_irq *cpu_irqs[MAX_CPUS], *slavio_irq, *slavio_cpu_irq, |
6f6260c7 | 494 | espdma_irq, ledma_irq; |
2d069bab | 495 | qemu_irq *esp_reset, *le_reset; |
2582cfa0 | 496 | qemu_irq fdc_tc; |
6d0c293d | 497 | qemu_irq *cpu_halt; |
f48f6569 | 498 | ram_addr_t ram_offset; |
5c6602c5 | 499 | unsigned long kernel_size; |
e4bcb14c | 500 | BlockDriverState *fd[MAX_FD]; |
22548760 | 501 | int drive_index; |
3cce6243 | 502 | void *fw_cfg; |
420557e8 | 503 | |
ba3c64fb | 504 | /* init CPUs */ |
3ebf5aaf BS |
505 | if (!cpu_model) |
506 | cpu_model = hwdef->default_cpu_model; | |
b3a23197 | 507 | |
ba3c64fb | 508 | for(i = 0; i < smp_cpus; i++) { |
aaed909a FB |
509 | env = cpu_init(cpu_model); |
510 | if (!env) { | |
8e82c6a8 | 511 | fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n"); |
aaed909a FB |
512 | exit(1); |
513 | } | |
514 | cpu_sparc_set_id(env, i); | |
ba3c64fb | 515 | envs[i] = env; |
3d29fbef | 516 | if (i == 0) { |
a08d4367 | 517 | qemu_register_reset(main_cpu_reset, env); |
3d29fbef | 518 | } else { |
a08d4367 | 519 | qemu_register_reset(secondary_cpu_reset, env); |
ba3c64fb | 520 | env->halted = 1; |
3d29fbef | 521 | } |
b3a23197 | 522 | cpu_irqs[i] = qemu_allocate_irqs(cpu_set_irq, envs[i], MAX_PILS); |
3ebf5aaf | 523 | env->prom_addr = hwdef->slavio_base; |
ba3c64fb | 524 | } |
b3a23197 BS |
525 | |
526 | for (i = smp_cpus; i < MAX_CPUS; i++) | |
527 | cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS); | |
528 | ||
3ebf5aaf | 529 | |
420557e8 | 530 | /* allocate RAM */ |
3ebf5aaf | 531 | if ((uint64_t)RAM_size > hwdef->max_mem) { |
77f193da BS |
532 | fprintf(stderr, |
533 | "qemu: Too much memory for this machine: %d, maximum %d\n", | |
6ef05b95 | 534 | (unsigned int)(RAM_size / (1024 * 1024)), |
3ebf5aaf BS |
535 | (unsigned int)(hwdef->max_mem / (1024 * 1024))); |
536 | exit(1); | |
537 | } | |
5c6602c5 BS |
538 | ram_offset = qemu_ram_alloc(RAM_size); |
539 | cpu_register_physical_memory(0, RAM_size, ram_offset); | |
420557e8 | 540 | |
3ebf5aaf | 541 | /* set up devices */ |
f48f6569 BS |
542 | prom_init(hwdef->slavio_base, bios_name); |
543 | ||
36cd9210 | 544 | slavio_intctl = slavio_intctl_init(hwdef->intctl_base, |
5dcb6b91 | 545 | hwdef->intctl_base + 0x10000ULL, |
d537cf6c | 546 | &hwdef->intbit_to_level[0], |
d7edfd27 | 547 | &slavio_irq, &slavio_cpu_irq, |
b3a23197 | 548 | cpu_irqs, |
d7edfd27 | 549 | hwdef->clock_irq); |
b3a23197 | 550 | |
fe096129 | 551 | if (hwdef->idreg_base) { |
325f2747 | 552 | idreg_init(hwdef->idreg_base); |
4c2485de BS |
553 | } |
554 | ||
ff403da6 BS |
555 | iommu = iommu_init(hwdef->iommu_base, hwdef->iommu_version, |
556 | slavio_irq[hwdef->me_irq]); | |
557 | ||
5aca8c3b | 558 | espdma = sparc32_dma_init(hwdef->dma_base, slavio_irq[hwdef->esp_irq], |
2d069bab BS |
559 | iommu, &espdma_irq, &esp_reset); |
560 | ||
5aca8c3b | 561 | ledma = sparc32_dma_init(hwdef->dma_base + 16ULL, |
2d069bab BS |
562 | slavio_irq[hwdef->le_irq], iommu, &ledma_irq, |
563 | &le_reset); | |
ba3c64fb | 564 | |
eee0b836 BS |
565 | if (graphic_depth != 8 && graphic_depth != 24) { |
566 | fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth); | |
567 | exit (1); | |
568 | } | |
dc828ca1 PB |
569 | tcx_init(hwdef->tcx_base, hwdef->vram_size, graphic_width, graphic_height, |
570 | graphic_depth); | |
dbe06e18 | 571 | |
6f6260c7 | 572 | lance_init(&nd_table[0], hwdef->le_base, ledma, ledma_irq, le_reset); |
dbe06e18 | 573 | |
d537cf6c PB |
574 | nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0, |
575 | hwdef->nvram_size, 8); | |
81732d19 BS |
576 | |
577 | slavio_timer_init_all(hwdef->counter_base, slavio_irq[hwdef->clock1_irq], | |
19f8e5dd | 578 | slavio_cpu_irq, smp_cpus); |
81732d19 | 579 | |
577390ff | 580 | slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[hwdef->ms_kb_irq], |
993fbfdb | 581 | display_type == DT_NOGRAPHIC, ESCC_CLOCK, 1); |
b81b3b10 FB |
582 | // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device |
583 | // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device | |
aeeb69c7 AJ |
584 | escc_init(hwdef->serial_base, slavio_irq[hwdef->ser_irq], slavio_irq[hwdef->ser_irq], |
585 | serial_hds[0], serial_hds[1], ESCC_CLOCK, 1); | |
741402f9 | 586 | |
6d0c293d | 587 | cpu_halt = qemu_allocate_irqs(cpu_halt_signal, NULL, 1); |
2582cfa0 | 588 | slavio_misc = slavio_misc_init(hwdef->slavio_base, |
2be17ebd | 589 | hwdef->aux1_base, hwdef->aux2_base, |
2582cfa0 BS |
590 | slavio_irq[hwdef->me_irq], fdc_tc); |
591 | if (hwdef->apc_base) { | |
592 | apc_init(hwdef->apc_base, cpu_halt[0]); | |
593 | } | |
2be17ebd | 594 | |
fe096129 | 595 | if (hwdef->fd_base) { |
e4bcb14c | 596 | /* there is zero or one floppy drive */ |
309e60bd | 597 | memset(fd, 0, sizeof(fd)); |
22548760 BS |
598 | drive_index = drive_get_index(IF_FLOPPY, 0, 0); |
599 | if (drive_index != -1) | |
600 | fd[0] = drives_table[drive_index].bdrv; | |
2d069bab | 601 | |
2be17ebd | 602 | sun4m_fdctrl_init(slavio_irq[hwdef->fd_irq], hwdef->fd_base, fd, |
2582cfa0 | 603 | &fdc_tc); |
e4bcb14c TS |
604 | } |
605 | ||
606 | if (drive_get_max_bus(IF_SCSI) > 0) { | |
607 | fprintf(stderr, "qemu: too many SCSI bus\n"); | |
608 | exit(1); | |
609 | } | |
610 | ||
cfb9de9c PB |
611 | esp_init(hwdef->esp_base, 2, |
612 | espdma_memory_read, espdma_memory_write, | |
6f6260c7 | 613 | espdma, espdma_irq, esp_reset); |
f1587550 | 614 | |
fa28ec52 BS |
615 | if (hwdef->cs_base) { |
616 | sysbus_create_simple("SUNW,CS4231", hwdef->cs_base, | |
617 | slavio_irq[hwdef->cs_irq]); | |
618 | } | |
b3ceef24 | 619 | |
293f78bc BS |
620 | kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename, |
621 | RAM_size); | |
36cd9210 | 622 | |
36cd9210 | 623 | nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline, |
b3ceef24 | 624 | boot_device, RAM_size, kernel_size, graphic_width, |
905fdcb5 BS |
625 | graphic_height, graphic_depth, hwdef->nvram_machine_id, |
626 | "Sun4m"); | |
7eb0c8e8 | 627 | |
fe096129 | 628 | if (hwdef->ecc_base) |
e42c20b4 BS |
629 | ecc_init(hwdef->ecc_base, slavio_irq[hwdef->ecc_irq], |
630 | hwdef->ecc_version); | |
3cce6243 BS |
631 | |
632 | fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2); | |
633 | fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1); | |
905fdcb5 BS |
634 | fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size); |
635 | fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id); | |
fbfcf955 | 636 | fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth); |
513f789f BS |
637 | fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR); |
638 | fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size); | |
639 | if (kernel_cmdline) { | |
640 | fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR); | |
641 | pstrcpy_targphys(CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline); | |
642 | } else { | |
643 | fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0); | |
644 | } | |
645 | fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR); | |
646 | fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used | |
647 | fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]); | |
648 | qemu_register_boot_set(fw_cfg_boot_set, fw_cfg); | |
36cd9210 BS |
649 | } |
650 | ||
905fdcb5 BS |
651 | enum { |
652 | ss2_id = 0, | |
653 | ss5_id = 32, | |
654 | vger_id, | |
655 | lx_id, | |
656 | ss4_id, | |
657 | scls_id, | |
658 | sbook_id, | |
659 | ss10_id = 64, | |
660 | ss20_id, | |
661 | ss600mp_id, | |
662 | ss1000_id = 96, | |
663 | ss2000_id, | |
664 | }; | |
665 | ||
8137cde8 | 666 | static const struct sun4m_hwdef sun4m_hwdefs[] = { |
36cd9210 BS |
667 | /* SS-5 */ |
668 | { | |
669 | .iommu_base = 0x10000000, | |
670 | .tcx_base = 0x50000000, | |
671 | .cs_base = 0x6c000000, | |
384ccb5d | 672 | .slavio_base = 0x70000000, |
36cd9210 BS |
673 | .ms_kb_base = 0x71000000, |
674 | .serial_base = 0x71100000, | |
675 | .nvram_base = 0x71200000, | |
676 | .fd_base = 0x71400000, | |
677 | .counter_base = 0x71d00000, | |
678 | .intctl_base = 0x71e00000, | |
4c2485de | 679 | .idreg_base = 0x78000000, |
36cd9210 BS |
680 | .dma_base = 0x78400000, |
681 | .esp_base = 0x78800000, | |
682 | .le_base = 0x78c00000, | |
127fc407 | 683 | .apc_base = 0x6a000000, |
0019ad53 BS |
684 | .aux1_base = 0x71900000, |
685 | .aux2_base = 0x71910000, | |
36cd9210 BS |
686 | .vram_size = 0x00100000, |
687 | .nvram_size = 0x2000, | |
688 | .esp_irq = 18, | |
689 | .le_irq = 16, | |
e3a79bca | 690 | .clock_irq = 7, |
36cd9210 BS |
691 | .clock1_irq = 19, |
692 | .ms_kb_irq = 14, | |
693 | .ser_irq = 15, | |
694 | .fd_irq = 22, | |
695 | .me_irq = 30, | |
696 | .cs_irq = 5, | |
905fdcb5 BS |
697 | .nvram_machine_id = 0x80, |
698 | .machine_id = ss5_id, | |
cf3102ac | 699 | .iommu_version = 0x05000000, |
e0353fe2 | 700 | .intbit_to_level = { |
f930d07e BS |
701 | 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12, |
702 | 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0, | |
e0353fe2 | 703 | }, |
3ebf5aaf BS |
704 | .max_mem = 0x10000000, |
705 | .default_cpu_model = "Fujitsu MB86904", | |
e0353fe2 BS |
706 | }, |
707 | /* SS-10 */ | |
e0353fe2 | 708 | { |
5dcb6b91 BS |
709 | .iommu_base = 0xfe0000000ULL, |
710 | .tcx_base = 0xe20000000ULL, | |
5dcb6b91 BS |
711 | .slavio_base = 0xff0000000ULL, |
712 | .ms_kb_base = 0xff1000000ULL, | |
713 | .serial_base = 0xff1100000ULL, | |
714 | .nvram_base = 0xff1200000ULL, | |
715 | .fd_base = 0xff1700000ULL, | |
716 | .counter_base = 0xff1300000ULL, | |
717 | .intctl_base = 0xff1400000ULL, | |
4c2485de | 718 | .idreg_base = 0xef0000000ULL, |
5dcb6b91 BS |
719 | .dma_base = 0xef0400000ULL, |
720 | .esp_base = 0xef0800000ULL, | |
721 | .le_base = 0xef0c00000ULL, | |
0019ad53 | 722 | .apc_base = 0xefa000000ULL, // XXX should not exist |
127fc407 BS |
723 | .aux1_base = 0xff1800000ULL, |
724 | .aux2_base = 0xff1a01000ULL, | |
7eb0c8e8 BS |
725 | .ecc_base = 0xf00000000ULL, |
726 | .ecc_version = 0x10000000, // version 0, implementation 1 | |
e0353fe2 BS |
727 | .vram_size = 0x00100000, |
728 | .nvram_size = 0x2000, | |
729 | .esp_irq = 18, | |
730 | .le_irq = 16, | |
e3a79bca | 731 | .clock_irq = 7, |
e0353fe2 BS |
732 | .clock1_irq = 19, |
733 | .ms_kb_irq = 14, | |
734 | .ser_irq = 15, | |
735 | .fd_irq = 22, | |
736 | .me_irq = 30, | |
e42c20b4 | 737 | .ecc_irq = 28, |
905fdcb5 BS |
738 | .nvram_machine_id = 0x72, |
739 | .machine_id = ss10_id, | |
7fbfb139 | 740 | .iommu_version = 0x03000000, |
e0353fe2 | 741 | .intbit_to_level = { |
f930d07e BS |
742 | 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12, |
743 | 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0, | |
e0353fe2 | 744 | }, |
6ef05b95 | 745 | .max_mem = 0xf00000000ULL, |
3ebf5aaf | 746 | .default_cpu_model = "TI SuperSparc II", |
36cd9210 | 747 | }, |
6a3b9cc9 BS |
748 | /* SS-600MP */ |
749 | { | |
750 | .iommu_base = 0xfe0000000ULL, | |
751 | .tcx_base = 0xe20000000ULL, | |
6a3b9cc9 BS |
752 | .slavio_base = 0xff0000000ULL, |
753 | .ms_kb_base = 0xff1000000ULL, | |
754 | .serial_base = 0xff1100000ULL, | |
755 | .nvram_base = 0xff1200000ULL, | |
6a3b9cc9 BS |
756 | .counter_base = 0xff1300000ULL, |
757 | .intctl_base = 0xff1400000ULL, | |
758 | .dma_base = 0xef0081000ULL, | |
759 | .esp_base = 0xef0080000ULL, | |
760 | .le_base = 0xef0060000ULL, | |
0019ad53 | 761 | .apc_base = 0xefa000000ULL, // XXX should not exist |
127fc407 BS |
762 | .aux1_base = 0xff1800000ULL, |
763 | .aux2_base = 0xff1a01000ULL, // XXX should not exist | |
7eb0c8e8 BS |
764 | .ecc_base = 0xf00000000ULL, |
765 | .ecc_version = 0x00000000, // version 0, implementation 0 | |
6a3b9cc9 BS |
766 | .vram_size = 0x00100000, |
767 | .nvram_size = 0x2000, | |
768 | .esp_irq = 18, | |
769 | .le_irq = 16, | |
e3a79bca | 770 | .clock_irq = 7, |
6a3b9cc9 BS |
771 | .clock1_irq = 19, |
772 | .ms_kb_irq = 14, | |
773 | .ser_irq = 15, | |
774 | .fd_irq = 22, | |
775 | .me_irq = 30, | |
e42c20b4 | 776 | .ecc_irq = 28, |
905fdcb5 BS |
777 | .nvram_machine_id = 0x71, |
778 | .machine_id = ss600mp_id, | |
7fbfb139 | 779 | .iommu_version = 0x01000000, |
6a3b9cc9 BS |
780 | .intbit_to_level = { |
781 | 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12, | |
782 | 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0, | |
783 | }, | |
6ef05b95 | 784 | .max_mem = 0xf00000000ULL, |
3ebf5aaf | 785 | .default_cpu_model = "TI SuperSparc II", |
6a3b9cc9 | 786 | }, |
ae40972f BS |
787 | /* SS-20 */ |
788 | { | |
789 | .iommu_base = 0xfe0000000ULL, | |
790 | .tcx_base = 0xe20000000ULL, | |
ae40972f BS |
791 | .slavio_base = 0xff0000000ULL, |
792 | .ms_kb_base = 0xff1000000ULL, | |
793 | .serial_base = 0xff1100000ULL, | |
794 | .nvram_base = 0xff1200000ULL, | |
795 | .fd_base = 0xff1700000ULL, | |
796 | .counter_base = 0xff1300000ULL, | |
797 | .intctl_base = 0xff1400000ULL, | |
4c2485de | 798 | .idreg_base = 0xef0000000ULL, |
ae40972f BS |
799 | .dma_base = 0xef0400000ULL, |
800 | .esp_base = 0xef0800000ULL, | |
801 | .le_base = 0xef0c00000ULL, | |
0019ad53 | 802 | .apc_base = 0xefa000000ULL, // XXX should not exist |
577d8dd4 BS |
803 | .aux1_base = 0xff1800000ULL, |
804 | .aux2_base = 0xff1a01000ULL, | |
ae40972f BS |
805 | .ecc_base = 0xf00000000ULL, |
806 | .ecc_version = 0x20000000, // version 0, implementation 2 | |
807 | .vram_size = 0x00100000, | |
808 | .nvram_size = 0x2000, | |
809 | .esp_irq = 18, | |
810 | .le_irq = 16, | |
e3a79bca | 811 | .clock_irq = 7, |
ae40972f BS |
812 | .clock1_irq = 19, |
813 | .ms_kb_irq = 14, | |
814 | .ser_irq = 15, | |
815 | .fd_irq = 22, | |
816 | .me_irq = 30, | |
e42c20b4 | 817 | .ecc_irq = 28, |
905fdcb5 BS |
818 | .nvram_machine_id = 0x72, |
819 | .machine_id = ss20_id, | |
ae40972f BS |
820 | .iommu_version = 0x13000000, |
821 | .intbit_to_level = { | |
822 | 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12, | |
823 | 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0, | |
824 | }, | |
6ef05b95 | 825 | .max_mem = 0xf00000000ULL, |
ae40972f BS |
826 | .default_cpu_model = "TI SuperSparc II", |
827 | }, | |
a526a31c BS |
828 | /* Voyager */ |
829 | { | |
830 | .iommu_base = 0x10000000, | |
831 | .tcx_base = 0x50000000, | |
a526a31c BS |
832 | .slavio_base = 0x70000000, |
833 | .ms_kb_base = 0x71000000, | |
834 | .serial_base = 0x71100000, | |
835 | .nvram_base = 0x71200000, | |
836 | .fd_base = 0x71400000, | |
837 | .counter_base = 0x71d00000, | |
838 | .intctl_base = 0x71e00000, | |
839 | .idreg_base = 0x78000000, | |
840 | .dma_base = 0x78400000, | |
841 | .esp_base = 0x78800000, | |
842 | .le_base = 0x78c00000, | |
843 | .apc_base = 0x71300000, // pmc | |
844 | .aux1_base = 0x71900000, | |
845 | .aux2_base = 0x71910000, | |
a526a31c BS |
846 | .vram_size = 0x00100000, |
847 | .nvram_size = 0x2000, | |
848 | .esp_irq = 18, | |
849 | .le_irq = 16, | |
850 | .clock_irq = 7, | |
851 | .clock1_irq = 19, | |
852 | .ms_kb_irq = 14, | |
853 | .ser_irq = 15, | |
854 | .fd_irq = 22, | |
855 | .me_irq = 30, | |
905fdcb5 BS |
856 | .nvram_machine_id = 0x80, |
857 | .machine_id = vger_id, | |
a526a31c BS |
858 | .iommu_version = 0x05000000, |
859 | .intbit_to_level = { | |
860 | 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12, | |
861 | 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0, | |
862 | }, | |
863 | .max_mem = 0x10000000, | |
864 | .default_cpu_model = "Fujitsu MB86904", | |
865 | }, | |
866 | /* LX */ | |
867 | { | |
868 | .iommu_base = 0x10000000, | |
869 | .tcx_base = 0x50000000, | |
a526a31c BS |
870 | .slavio_base = 0x70000000, |
871 | .ms_kb_base = 0x71000000, | |
872 | .serial_base = 0x71100000, | |
873 | .nvram_base = 0x71200000, | |
874 | .fd_base = 0x71400000, | |
875 | .counter_base = 0x71d00000, | |
876 | .intctl_base = 0x71e00000, | |
877 | .idreg_base = 0x78000000, | |
878 | .dma_base = 0x78400000, | |
879 | .esp_base = 0x78800000, | |
880 | .le_base = 0x78c00000, | |
a526a31c BS |
881 | .aux1_base = 0x71900000, |
882 | .aux2_base = 0x71910000, | |
a526a31c BS |
883 | .vram_size = 0x00100000, |
884 | .nvram_size = 0x2000, | |
885 | .esp_irq = 18, | |
886 | .le_irq = 16, | |
887 | .clock_irq = 7, | |
888 | .clock1_irq = 19, | |
889 | .ms_kb_irq = 14, | |
890 | .ser_irq = 15, | |
891 | .fd_irq = 22, | |
892 | .me_irq = 30, | |
905fdcb5 BS |
893 | .nvram_machine_id = 0x80, |
894 | .machine_id = lx_id, | |
a526a31c BS |
895 | .iommu_version = 0x04000000, |
896 | .intbit_to_level = { | |
897 | 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12, | |
898 | 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0, | |
899 | }, | |
900 | .max_mem = 0x10000000, | |
901 | .default_cpu_model = "TI MicroSparc I", | |
902 | }, | |
903 | /* SS-4 */ | |
904 | { | |
905 | .iommu_base = 0x10000000, | |
906 | .tcx_base = 0x50000000, | |
907 | .cs_base = 0x6c000000, | |
908 | .slavio_base = 0x70000000, | |
909 | .ms_kb_base = 0x71000000, | |
910 | .serial_base = 0x71100000, | |
911 | .nvram_base = 0x71200000, | |
912 | .fd_base = 0x71400000, | |
913 | .counter_base = 0x71d00000, | |
914 | .intctl_base = 0x71e00000, | |
915 | .idreg_base = 0x78000000, | |
916 | .dma_base = 0x78400000, | |
917 | .esp_base = 0x78800000, | |
918 | .le_base = 0x78c00000, | |
919 | .apc_base = 0x6a000000, | |
920 | .aux1_base = 0x71900000, | |
921 | .aux2_base = 0x71910000, | |
a526a31c BS |
922 | .vram_size = 0x00100000, |
923 | .nvram_size = 0x2000, | |
924 | .esp_irq = 18, | |
925 | .le_irq = 16, | |
926 | .clock_irq = 7, | |
927 | .clock1_irq = 19, | |
928 | .ms_kb_irq = 14, | |
929 | .ser_irq = 15, | |
930 | .fd_irq = 22, | |
931 | .me_irq = 30, | |
932 | .cs_irq = 5, | |
905fdcb5 BS |
933 | .nvram_machine_id = 0x80, |
934 | .machine_id = ss4_id, | |
a526a31c BS |
935 | .iommu_version = 0x05000000, |
936 | .intbit_to_level = { | |
937 | 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12, | |
938 | 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0, | |
939 | }, | |
940 | .max_mem = 0x10000000, | |
941 | .default_cpu_model = "Fujitsu MB86904", | |
942 | }, | |
943 | /* SPARCClassic */ | |
944 | { | |
945 | .iommu_base = 0x10000000, | |
946 | .tcx_base = 0x50000000, | |
a526a31c BS |
947 | .slavio_base = 0x70000000, |
948 | .ms_kb_base = 0x71000000, | |
949 | .serial_base = 0x71100000, | |
950 | .nvram_base = 0x71200000, | |
951 | .fd_base = 0x71400000, | |
952 | .counter_base = 0x71d00000, | |
953 | .intctl_base = 0x71e00000, | |
954 | .idreg_base = 0x78000000, | |
955 | .dma_base = 0x78400000, | |
956 | .esp_base = 0x78800000, | |
957 | .le_base = 0x78c00000, | |
958 | .apc_base = 0x6a000000, | |
959 | .aux1_base = 0x71900000, | |
960 | .aux2_base = 0x71910000, | |
a526a31c BS |
961 | .vram_size = 0x00100000, |
962 | .nvram_size = 0x2000, | |
963 | .esp_irq = 18, | |
964 | .le_irq = 16, | |
965 | .clock_irq = 7, | |
966 | .clock1_irq = 19, | |
967 | .ms_kb_irq = 14, | |
968 | .ser_irq = 15, | |
969 | .fd_irq = 22, | |
970 | .me_irq = 30, | |
905fdcb5 BS |
971 | .nvram_machine_id = 0x80, |
972 | .machine_id = scls_id, | |
a526a31c BS |
973 | .iommu_version = 0x05000000, |
974 | .intbit_to_level = { | |
975 | 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12, | |
976 | 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0, | |
977 | }, | |
978 | .max_mem = 0x10000000, | |
979 | .default_cpu_model = "TI MicroSparc I", | |
980 | }, | |
981 | /* SPARCbook */ | |
982 | { | |
983 | .iommu_base = 0x10000000, | |
984 | .tcx_base = 0x50000000, // XXX | |
a526a31c BS |
985 | .slavio_base = 0x70000000, |
986 | .ms_kb_base = 0x71000000, | |
987 | .serial_base = 0x71100000, | |
988 | .nvram_base = 0x71200000, | |
989 | .fd_base = 0x71400000, | |
990 | .counter_base = 0x71d00000, | |
991 | .intctl_base = 0x71e00000, | |
992 | .idreg_base = 0x78000000, | |
993 | .dma_base = 0x78400000, | |
994 | .esp_base = 0x78800000, | |
995 | .le_base = 0x78c00000, | |
996 | .apc_base = 0x6a000000, | |
997 | .aux1_base = 0x71900000, | |
998 | .aux2_base = 0x71910000, | |
a526a31c BS |
999 | .vram_size = 0x00100000, |
1000 | .nvram_size = 0x2000, | |
1001 | .esp_irq = 18, | |
1002 | .le_irq = 16, | |
1003 | .clock_irq = 7, | |
1004 | .clock1_irq = 19, | |
1005 | .ms_kb_irq = 14, | |
1006 | .ser_irq = 15, | |
1007 | .fd_irq = 22, | |
1008 | .me_irq = 30, | |
905fdcb5 BS |
1009 | .nvram_machine_id = 0x80, |
1010 | .machine_id = sbook_id, | |
a526a31c BS |
1011 | .iommu_version = 0x05000000, |
1012 | .intbit_to_level = { | |
1013 | 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12, | |
1014 | 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0, | |
1015 | }, | |
1016 | .max_mem = 0x10000000, | |
1017 | .default_cpu_model = "TI MicroSparc I", | |
1018 | }, | |
36cd9210 BS |
1019 | }; |
1020 | ||
36cd9210 | 1021 | /* SPARCstation 5 hardware initialisation */ |
fbe1b595 | 1022 | static void ss5_init(ram_addr_t RAM_size, |
3023f332 | 1023 | const char *boot_device, |
b881c2c6 BS |
1024 | const char *kernel_filename, const char *kernel_cmdline, |
1025 | const char *initrd_filename, const char *cpu_model) | |
36cd9210 | 1026 | { |
3023f332 | 1027 | sun4m_hw_init(&sun4m_hwdefs[0], RAM_size, boot_device, kernel_filename, |
3ebf5aaf | 1028 | kernel_cmdline, initrd_filename, cpu_model); |
420557e8 | 1029 | } |
c0e564d5 | 1030 | |
e0353fe2 | 1031 | /* SPARCstation 10 hardware initialisation */ |
fbe1b595 | 1032 | static void ss10_init(ram_addr_t RAM_size, |
3023f332 | 1033 | const char *boot_device, |
b881c2c6 BS |
1034 | const char *kernel_filename, const char *kernel_cmdline, |
1035 | const char *initrd_filename, const char *cpu_model) | |
e0353fe2 | 1036 | { |
3023f332 | 1037 | sun4m_hw_init(&sun4m_hwdefs[1], RAM_size, boot_device, kernel_filename, |
3ebf5aaf | 1038 | kernel_cmdline, initrd_filename, cpu_model); |
e0353fe2 BS |
1039 | } |
1040 | ||
6a3b9cc9 | 1041 | /* SPARCserver 600MP hardware initialisation */ |
fbe1b595 | 1042 | static void ss600mp_init(ram_addr_t RAM_size, |
3023f332 | 1043 | const char *boot_device, |
77f193da BS |
1044 | const char *kernel_filename, |
1045 | const char *kernel_cmdline, | |
6a3b9cc9 BS |
1046 | const char *initrd_filename, const char *cpu_model) |
1047 | { | |
3023f332 | 1048 | sun4m_hw_init(&sun4m_hwdefs[2], RAM_size, boot_device, kernel_filename, |
3ebf5aaf | 1049 | kernel_cmdline, initrd_filename, cpu_model); |
6a3b9cc9 BS |
1050 | } |
1051 | ||
ae40972f | 1052 | /* SPARCstation 20 hardware initialisation */ |
fbe1b595 | 1053 | static void ss20_init(ram_addr_t RAM_size, |
3023f332 | 1054 | const char *boot_device, |
ae40972f BS |
1055 | const char *kernel_filename, const char *kernel_cmdline, |
1056 | const char *initrd_filename, const char *cpu_model) | |
1057 | { | |
3023f332 | 1058 | sun4m_hw_init(&sun4m_hwdefs[3], RAM_size, boot_device, kernel_filename, |
ee76f82e BS |
1059 | kernel_cmdline, initrd_filename, cpu_model); |
1060 | } | |
1061 | ||
a526a31c | 1062 | /* SPARCstation Voyager hardware initialisation */ |
fbe1b595 | 1063 | static void vger_init(ram_addr_t RAM_size, |
3023f332 | 1064 | const char *boot_device, |
a526a31c BS |
1065 | const char *kernel_filename, const char *kernel_cmdline, |
1066 | const char *initrd_filename, const char *cpu_model) | |
1067 | { | |
3023f332 | 1068 | sun4m_hw_init(&sun4m_hwdefs[4], RAM_size, boot_device, kernel_filename, |
a526a31c BS |
1069 | kernel_cmdline, initrd_filename, cpu_model); |
1070 | } | |
1071 | ||
1072 | /* SPARCstation LX hardware initialisation */ | |
fbe1b595 | 1073 | static void ss_lx_init(ram_addr_t RAM_size, |
3023f332 | 1074 | const char *boot_device, |
a526a31c BS |
1075 | const char *kernel_filename, const char *kernel_cmdline, |
1076 | const char *initrd_filename, const char *cpu_model) | |
1077 | { | |
3023f332 | 1078 | sun4m_hw_init(&sun4m_hwdefs[5], RAM_size, boot_device, kernel_filename, |
a526a31c BS |
1079 | kernel_cmdline, initrd_filename, cpu_model); |
1080 | } | |
1081 | ||
1082 | /* SPARCstation 4 hardware initialisation */ | |
fbe1b595 | 1083 | static void ss4_init(ram_addr_t RAM_size, |
3023f332 | 1084 | const char *boot_device, |
a526a31c BS |
1085 | const char *kernel_filename, const char *kernel_cmdline, |
1086 | const char *initrd_filename, const char *cpu_model) | |
1087 | { | |
3023f332 | 1088 | sun4m_hw_init(&sun4m_hwdefs[6], RAM_size, boot_device, kernel_filename, |
a526a31c BS |
1089 | kernel_cmdline, initrd_filename, cpu_model); |
1090 | } | |
1091 | ||
1092 | /* SPARCClassic hardware initialisation */ | |
fbe1b595 | 1093 | static void scls_init(ram_addr_t RAM_size, |
3023f332 | 1094 | const char *boot_device, |
a526a31c BS |
1095 | const char *kernel_filename, const char *kernel_cmdline, |
1096 | const char *initrd_filename, const char *cpu_model) | |
1097 | { | |
3023f332 | 1098 | sun4m_hw_init(&sun4m_hwdefs[7], RAM_size, boot_device, kernel_filename, |
a526a31c BS |
1099 | kernel_cmdline, initrd_filename, cpu_model); |
1100 | } | |
1101 | ||
1102 | /* SPARCbook hardware initialisation */ | |
fbe1b595 | 1103 | static void sbook_init(ram_addr_t RAM_size, |
3023f332 | 1104 | const char *boot_device, |
a526a31c BS |
1105 | const char *kernel_filename, const char *kernel_cmdline, |
1106 | const char *initrd_filename, const char *cpu_model) | |
1107 | { | |
3023f332 | 1108 | sun4m_hw_init(&sun4m_hwdefs[8], RAM_size, boot_device, kernel_filename, |
a526a31c BS |
1109 | kernel_cmdline, initrd_filename, cpu_model); |
1110 | } | |
1111 | ||
f80f9ec9 | 1112 | static QEMUMachine ss5_machine = { |
66de733b BS |
1113 | .name = "SS-5", |
1114 | .desc = "Sun4m platform, SPARCstation 5", | |
1115 | .init = ss5_init, | |
c9b1ae2c | 1116 | .use_scsi = 1, |
0c257437 | 1117 | .is_default = 1, |
c0e564d5 | 1118 | }; |
e0353fe2 | 1119 | |
f80f9ec9 | 1120 | static QEMUMachine ss10_machine = { |
66de733b BS |
1121 | .name = "SS-10", |
1122 | .desc = "Sun4m platform, SPARCstation 10", | |
1123 | .init = ss10_init, | |
c9b1ae2c | 1124 | .use_scsi = 1, |
1bcee014 | 1125 | .max_cpus = 4, |
e0353fe2 | 1126 | }; |
6a3b9cc9 | 1127 | |
f80f9ec9 | 1128 | static QEMUMachine ss600mp_machine = { |
66de733b BS |
1129 | .name = "SS-600MP", |
1130 | .desc = "Sun4m platform, SPARCserver 600MP", | |
1131 | .init = ss600mp_init, | |
c9b1ae2c | 1132 | .use_scsi = 1, |
1bcee014 | 1133 | .max_cpus = 4, |
6a3b9cc9 | 1134 | }; |
ae40972f | 1135 | |
f80f9ec9 | 1136 | static QEMUMachine ss20_machine = { |
66de733b BS |
1137 | .name = "SS-20", |
1138 | .desc = "Sun4m platform, SPARCstation 20", | |
1139 | .init = ss20_init, | |
c9b1ae2c | 1140 | .use_scsi = 1, |
1bcee014 | 1141 | .max_cpus = 4, |
ae40972f BS |
1142 | }; |
1143 | ||
f80f9ec9 | 1144 | static QEMUMachine voyager_machine = { |
66de733b BS |
1145 | .name = "Voyager", |
1146 | .desc = "Sun4m platform, SPARCstation Voyager", | |
1147 | .init = vger_init, | |
c9b1ae2c | 1148 | .use_scsi = 1, |
a526a31c BS |
1149 | }; |
1150 | ||
f80f9ec9 | 1151 | static QEMUMachine ss_lx_machine = { |
66de733b BS |
1152 | .name = "LX", |
1153 | .desc = "Sun4m platform, SPARCstation LX", | |
1154 | .init = ss_lx_init, | |
c9b1ae2c | 1155 | .use_scsi = 1, |
a526a31c BS |
1156 | }; |
1157 | ||
f80f9ec9 | 1158 | static QEMUMachine ss4_machine = { |
66de733b BS |
1159 | .name = "SS-4", |
1160 | .desc = "Sun4m platform, SPARCstation 4", | |
1161 | .init = ss4_init, | |
c9b1ae2c | 1162 | .use_scsi = 1, |
a526a31c BS |
1163 | }; |
1164 | ||
f80f9ec9 | 1165 | static QEMUMachine scls_machine = { |
66de733b BS |
1166 | .name = "SPARCClassic", |
1167 | .desc = "Sun4m platform, SPARCClassic", | |
1168 | .init = scls_init, | |
c9b1ae2c | 1169 | .use_scsi = 1, |
a526a31c BS |
1170 | }; |
1171 | ||
f80f9ec9 | 1172 | static QEMUMachine sbook_machine = { |
66de733b BS |
1173 | .name = "SPARCbook", |
1174 | .desc = "Sun4m platform, SPARCbook", | |
1175 | .init = sbook_init, | |
c9b1ae2c | 1176 | .use_scsi = 1, |
a526a31c BS |
1177 | }; |
1178 | ||
7d85892b BS |
1179 | static const struct sun4d_hwdef sun4d_hwdefs[] = { |
1180 | /* SS-1000 */ | |
1181 | { | |
1182 | .iounit_bases = { | |
1183 | 0xfe0200000ULL, | |
1184 | 0xfe1200000ULL, | |
1185 | 0xfe2200000ULL, | |
1186 | 0xfe3200000ULL, | |
1187 | -1, | |
1188 | }, | |
1189 | .tcx_base = 0x820000000ULL, | |
1190 | .slavio_base = 0xf00000000ULL, | |
1191 | .ms_kb_base = 0xf00240000ULL, | |
1192 | .serial_base = 0xf00200000ULL, | |
1193 | .nvram_base = 0xf00280000ULL, | |
1194 | .counter_base = 0xf00300000ULL, | |
1195 | .espdma_base = 0x800081000ULL, | |
1196 | .esp_base = 0x800080000ULL, | |
1197 | .ledma_base = 0x800040000ULL, | |
1198 | .le_base = 0x800060000ULL, | |
1199 | .sbi_base = 0xf02800000ULL, | |
c1d00dc0 | 1200 | .vram_size = 0x00100000, |
7d85892b BS |
1201 | .nvram_size = 0x2000, |
1202 | .esp_irq = 3, | |
1203 | .le_irq = 4, | |
1204 | .clock_irq = 14, | |
1205 | .clock1_irq = 10, | |
1206 | .ms_kb_irq = 12, | |
1207 | .ser_irq = 12, | |
905fdcb5 BS |
1208 | .nvram_machine_id = 0x80, |
1209 | .machine_id = ss1000_id, | |
7d85892b | 1210 | .iounit_version = 0x03000000, |
6ef05b95 | 1211 | .max_mem = 0xf00000000ULL, |
7d85892b BS |
1212 | .default_cpu_model = "TI SuperSparc II", |
1213 | }, | |
1214 | /* SS-2000 */ | |
1215 | { | |
1216 | .iounit_bases = { | |
1217 | 0xfe0200000ULL, | |
1218 | 0xfe1200000ULL, | |
1219 | 0xfe2200000ULL, | |
1220 | 0xfe3200000ULL, | |
1221 | 0xfe4200000ULL, | |
1222 | }, | |
1223 | .tcx_base = 0x820000000ULL, | |
1224 | .slavio_base = 0xf00000000ULL, | |
1225 | .ms_kb_base = 0xf00240000ULL, | |
1226 | .serial_base = 0xf00200000ULL, | |
1227 | .nvram_base = 0xf00280000ULL, | |
1228 | .counter_base = 0xf00300000ULL, | |
1229 | .espdma_base = 0x800081000ULL, | |
1230 | .esp_base = 0x800080000ULL, | |
1231 | .ledma_base = 0x800040000ULL, | |
1232 | .le_base = 0x800060000ULL, | |
1233 | .sbi_base = 0xf02800000ULL, | |
c1d00dc0 | 1234 | .vram_size = 0x00100000, |
7d85892b BS |
1235 | .nvram_size = 0x2000, |
1236 | .esp_irq = 3, | |
1237 | .le_irq = 4, | |
1238 | .clock_irq = 14, | |
1239 | .clock1_irq = 10, | |
1240 | .ms_kb_irq = 12, | |
1241 | .ser_irq = 12, | |
905fdcb5 BS |
1242 | .nvram_machine_id = 0x80, |
1243 | .machine_id = ss2000_id, | |
7d85892b | 1244 | .iounit_version = 0x03000000, |
6ef05b95 | 1245 | .max_mem = 0xf00000000ULL, |
7d85892b BS |
1246 | .default_cpu_model = "TI SuperSparc II", |
1247 | }, | |
1248 | }; | |
1249 | ||
6ef05b95 | 1250 | static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size, |
7d85892b | 1251 | const char *boot_device, |
3023f332 | 1252 | const char *kernel_filename, |
7d85892b BS |
1253 | const char *kernel_cmdline, |
1254 | const char *initrd_filename, const char *cpu_model) | |
1255 | { | |
1256 | CPUState *env, *envs[MAX_CPUS]; | |
1257 | unsigned int i; | |
cfb9de9c | 1258 | void *iounits[MAX_IOUNITS], *espdma, *ledma, *nvram, *sbi; |
7d85892b | 1259 | qemu_irq *cpu_irqs[MAX_CPUS], *sbi_irq, *sbi_cpu_irq, |
6f6260c7 | 1260 | espdma_irq, ledma_irq; |
7d85892b | 1261 | qemu_irq *esp_reset, *le_reset; |
f48f6569 | 1262 | ram_addr_t ram_offset; |
5c6602c5 | 1263 | unsigned long kernel_size; |
3cce6243 | 1264 | void *fw_cfg; |
7d85892b BS |
1265 | |
1266 | /* init CPUs */ | |
1267 | if (!cpu_model) | |
1268 | cpu_model = hwdef->default_cpu_model; | |
1269 | ||
1270 | for (i = 0; i < smp_cpus; i++) { | |
1271 | env = cpu_init(cpu_model); | |
1272 | if (!env) { | |
8e82c6a8 | 1273 | fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n"); |
7d85892b BS |
1274 | exit(1); |
1275 | } | |
1276 | cpu_sparc_set_id(env, i); | |
1277 | envs[i] = env; | |
1278 | if (i == 0) { | |
a08d4367 | 1279 | qemu_register_reset(main_cpu_reset, env); |
7d85892b | 1280 | } else { |
a08d4367 | 1281 | qemu_register_reset(secondary_cpu_reset, env); |
7d85892b BS |
1282 | env->halted = 1; |
1283 | } | |
7d85892b BS |
1284 | cpu_irqs[i] = qemu_allocate_irqs(cpu_set_irq, envs[i], MAX_PILS); |
1285 | env->prom_addr = hwdef->slavio_base; | |
1286 | } | |
1287 | ||
1288 | for (i = smp_cpus; i < MAX_CPUS; i++) | |
1289 | cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS); | |
1290 | ||
1291 | /* allocate RAM */ | |
1292 | if ((uint64_t)RAM_size > hwdef->max_mem) { | |
77f193da BS |
1293 | fprintf(stderr, |
1294 | "qemu: Too much memory for this machine: %d, maximum %d\n", | |
6ef05b95 | 1295 | (unsigned int)(RAM_size / (1024 * 1024)), |
7d85892b BS |
1296 | (unsigned int)(hwdef->max_mem / (1024 * 1024))); |
1297 | exit(1); | |
1298 | } | |
5c6602c5 BS |
1299 | ram_offset = qemu_ram_alloc(RAM_size); |
1300 | cpu_register_physical_memory(0, RAM_size, ram_offset); | |
7d85892b | 1301 | |
7d85892b | 1302 | /* set up devices */ |
f48f6569 BS |
1303 | prom_init(hwdef->slavio_base, bios_name); |
1304 | ||
7d85892b BS |
1305 | sbi = sbi_init(hwdef->sbi_base, &sbi_irq, &sbi_cpu_irq, cpu_irqs); |
1306 | ||
1307 | for (i = 0; i < MAX_IOUNITS; i++) | |
1308 | if (hwdef->iounit_bases[i] != (target_phys_addr_t)-1) | |
ff403da6 BS |
1309 | iounits[i] = iommu_init(hwdef->iounit_bases[i], |
1310 | hwdef->iounit_version, | |
1311 | sbi_irq[hwdef->me_irq]); | |
7d85892b BS |
1312 | |
1313 | espdma = sparc32_dma_init(hwdef->espdma_base, sbi_irq[hwdef->esp_irq], | |
1314 | iounits[0], &espdma_irq, &esp_reset); | |
1315 | ||
1316 | ledma = sparc32_dma_init(hwdef->ledma_base, sbi_irq[hwdef->le_irq], | |
1317 | iounits[0], &ledma_irq, &le_reset); | |
1318 | ||
1319 | if (graphic_depth != 8 && graphic_depth != 24) { | |
1320 | fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth); | |
1321 | exit (1); | |
1322 | } | |
dc828ca1 PB |
1323 | tcx_init(hwdef->tcx_base, hwdef->vram_size, graphic_width, graphic_height, |
1324 | graphic_depth); | |
7d85892b | 1325 | |
6f6260c7 | 1326 | lance_init(&nd_table[0], hwdef->le_base, ledma, ledma_irq, le_reset); |
7d85892b BS |
1327 | |
1328 | nvram = m48t59_init(sbi_irq[0], hwdef->nvram_base, 0, | |
1329 | hwdef->nvram_size, 8); | |
1330 | ||
1331 | slavio_timer_init_all(hwdef->counter_base, sbi_irq[hwdef->clock1_irq], | |
1332 | sbi_cpu_irq, smp_cpus); | |
1333 | ||
1334 | slavio_serial_ms_kbd_init(hwdef->ms_kb_base, sbi_irq[hwdef->ms_kb_irq], | |
993fbfdb | 1335 | display_type == DT_NOGRAPHIC, ESCC_CLOCK, 1); |
7d85892b BS |
1336 | // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device |
1337 | // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device | |
aeeb69c7 AJ |
1338 | escc_init(hwdef->serial_base, sbi_irq[hwdef->ser_irq], sbi_irq[hwdef->ser_irq], |
1339 | serial_hds[0], serial_hds[1], ESCC_CLOCK, 1); | |
7d85892b BS |
1340 | |
1341 | if (drive_get_max_bus(IF_SCSI) > 0) { | |
1342 | fprintf(stderr, "qemu: too many SCSI bus\n"); | |
1343 | exit(1); | |
1344 | } | |
1345 | ||
cfb9de9c PB |
1346 | esp_init(hwdef->esp_base, 2, |
1347 | espdma_memory_read, espdma_memory_write, | |
6f6260c7 | 1348 | espdma, espdma_irq, esp_reset); |
7d85892b | 1349 | |
293f78bc BS |
1350 | kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename, |
1351 | RAM_size); | |
7d85892b BS |
1352 | |
1353 | nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline, | |
1354 | boot_device, RAM_size, kernel_size, graphic_width, | |
905fdcb5 BS |
1355 | graphic_height, graphic_depth, hwdef->nvram_machine_id, |
1356 | "Sun4d"); | |
3cce6243 BS |
1357 | |
1358 | fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2); | |
1359 | fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1); | |
905fdcb5 BS |
1360 | fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size); |
1361 | fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id); | |
513f789f BS |
1362 | fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth); |
1363 | fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR); | |
1364 | fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size); | |
1365 | if (kernel_cmdline) { | |
1366 | fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR); | |
1367 | pstrcpy_targphys(CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline); | |
1368 | } else { | |
1369 | fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0); | |
1370 | } | |
1371 | fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR); | |
1372 | fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used | |
1373 | fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]); | |
1374 | qemu_register_boot_set(fw_cfg_boot_set, fw_cfg); | |
7d85892b BS |
1375 | } |
1376 | ||
1377 | /* SPARCserver 1000 hardware initialisation */ | |
fbe1b595 | 1378 | static void ss1000_init(ram_addr_t RAM_size, |
3023f332 | 1379 | const char *boot_device, |
7d85892b BS |
1380 | const char *kernel_filename, const char *kernel_cmdline, |
1381 | const char *initrd_filename, const char *cpu_model) | |
1382 | { | |
3023f332 | 1383 | sun4d_hw_init(&sun4d_hwdefs[0], RAM_size, boot_device, kernel_filename, |
7d85892b BS |
1384 | kernel_cmdline, initrd_filename, cpu_model); |
1385 | } | |
1386 | ||
1387 | /* SPARCcenter 2000 hardware initialisation */ | |
fbe1b595 | 1388 | static void ss2000_init(ram_addr_t RAM_size, |
3023f332 | 1389 | const char *boot_device, |
7d85892b BS |
1390 | const char *kernel_filename, const char *kernel_cmdline, |
1391 | const char *initrd_filename, const char *cpu_model) | |
1392 | { | |
3023f332 | 1393 | sun4d_hw_init(&sun4d_hwdefs[1], RAM_size, boot_device, kernel_filename, |
7d85892b BS |
1394 | kernel_cmdline, initrd_filename, cpu_model); |
1395 | } | |
1396 | ||
f80f9ec9 | 1397 | static QEMUMachine ss1000_machine = { |
66de733b BS |
1398 | .name = "SS-1000", |
1399 | .desc = "Sun4d platform, SPARCserver 1000", | |
1400 | .init = ss1000_init, | |
c9b1ae2c | 1401 | .use_scsi = 1, |
1bcee014 | 1402 | .max_cpus = 8, |
7d85892b BS |
1403 | }; |
1404 | ||
f80f9ec9 | 1405 | static QEMUMachine ss2000_machine = { |
66de733b BS |
1406 | .name = "SS-2000", |
1407 | .desc = "Sun4d platform, SPARCcenter 2000", | |
1408 | .init = ss2000_init, | |
c9b1ae2c | 1409 | .use_scsi = 1, |
1bcee014 | 1410 | .max_cpus = 20, |
7d85892b | 1411 | }; |
8137cde8 BS |
1412 | |
1413 | static const struct sun4c_hwdef sun4c_hwdefs[] = { | |
1414 | /* SS-2 */ | |
1415 | { | |
1416 | .iommu_base = 0xf8000000, | |
1417 | .tcx_base = 0xfe000000, | |
8137cde8 BS |
1418 | .slavio_base = 0xf6000000, |
1419 | .intctl_base = 0xf5000000, | |
1420 | .counter_base = 0xf3000000, | |
1421 | .ms_kb_base = 0xf0000000, | |
1422 | .serial_base = 0xf1000000, | |
1423 | .nvram_base = 0xf2000000, | |
1424 | .fd_base = 0xf7200000, | |
1425 | .dma_base = 0xf8400000, | |
1426 | .esp_base = 0xf8800000, | |
1427 | .le_base = 0xf8c00000, | |
8137cde8 | 1428 | .aux1_base = 0xf7400003, |
8137cde8 BS |
1429 | .vram_size = 0x00100000, |
1430 | .nvram_size = 0x800, | |
1431 | .esp_irq = 2, | |
1432 | .le_irq = 3, | |
1433 | .clock_irq = 5, | |
1434 | .clock1_irq = 7, | |
1435 | .ms_kb_irq = 1, | |
1436 | .ser_irq = 1, | |
1437 | .fd_irq = 1, | |
1438 | .me_irq = 1, | |
8137cde8 BS |
1439 | .nvram_machine_id = 0x55, |
1440 | .machine_id = ss2_id, | |
1441 | .max_mem = 0x10000000, | |
1442 | .default_cpu_model = "Cypress CY7C601", | |
1443 | }, | |
1444 | }; | |
1445 | ||
1446 | static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size, | |
1447 | const char *boot_device, | |
3023f332 | 1448 | const char *kernel_filename, |
8137cde8 BS |
1449 | const char *kernel_cmdline, |
1450 | const char *initrd_filename, const char *cpu_model) | |
1451 | { | |
1452 | CPUState *env; | |
cfb9de9c | 1453 | void *iommu, *espdma, *ledma, *nvram; |
6f6260c7 | 1454 | qemu_irq *cpu_irqs, *slavio_irq, espdma_irq, ledma_irq; |
8137cde8 | 1455 | qemu_irq *esp_reset, *le_reset; |
2582cfa0 | 1456 | qemu_irq fdc_tc; |
f48f6569 | 1457 | ram_addr_t ram_offset; |
5c6602c5 | 1458 | unsigned long kernel_size; |
8137cde8 BS |
1459 | BlockDriverState *fd[MAX_FD]; |
1460 | int drive_index; | |
1461 | void *fw_cfg; | |
1462 | ||
1463 | /* init CPU */ | |
1464 | if (!cpu_model) | |
1465 | cpu_model = hwdef->default_cpu_model; | |
1466 | ||
1467 | env = cpu_init(cpu_model); | |
1468 | if (!env) { | |
1469 | fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n"); | |
1470 | exit(1); | |
1471 | } | |
1472 | ||
1473 | cpu_sparc_set_id(env, 0); | |
1474 | ||
a08d4367 | 1475 | qemu_register_reset(main_cpu_reset, env); |
8137cde8 BS |
1476 | cpu_irqs = qemu_allocate_irqs(cpu_set_irq, env, MAX_PILS); |
1477 | env->prom_addr = hwdef->slavio_base; | |
1478 | ||
1479 | /* allocate RAM */ | |
1480 | if ((uint64_t)RAM_size > hwdef->max_mem) { | |
1481 | fprintf(stderr, | |
1482 | "qemu: Too much memory for this machine: %d, maximum %d\n", | |
1483 | (unsigned int)(RAM_size / (1024 * 1024)), | |
1484 | (unsigned int)(hwdef->max_mem / (1024 * 1024))); | |
1485 | exit(1); | |
1486 | } | |
5c6602c5 BS |
1487 | ram_offset = qemu_ram_alloc(RAM_size); |
1488 | cpu_register_physical_memory(0, RAM_size, ram_offset); | |
8137cde8 | 1489 | |
8137cde8 | 1490 | /* set up devices */ |
f48f6569 BS |
1491 | prom_init(hwdef->slavio_base, bios_name); |
1492 | ||
8137cde8 BS |
1493 | slavio_intctl = sun4c_intctl_init(hwdef->intctl_base, |
1494 | &slavio_irq, cpu_irqs); | |
1495 | ||
1496 | iommu = iommu_init(hwdef->iommu_base, hwdef->iommu_version, | |
1497 | slavio_irq[hwdef->me_irq]); | |
1498 | ||
1499 | espdma = sparc32_dma_init(hwdef->dma_base, slavio_irq[hwdef->esp_irq], | |
1500 | iommu, &espdma_irq, &esp_reset); | |
1501 | ||
1502 | ledma = sparc32_dma_init(hwdef->dma_base + 16ULL, | |
1503 | slavio_irq[hwdef->le_irq], iommu, &ledma_irq, | |
1504 | &le_reset); | |
1505 | ||
1506 | if (graphic_depth != 8 && graphic_depth != 24) { | |
1507 | fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth); | |
1508 | exit (1); | |
1509 | } | |
dc828ca1 PB |
1510 | tcx_init(hwdef->tcx_base, hwdef->vram_size, graphic_width, graphic_height, |
1511 | graphic_depth); | |
8137cde8 | 1512 | |
6f6260c7 | 1513 | lance_init(&nd_table[0], hwdef->le_base, ledma, ledma_irq, le_reset); |
8137cde8 BS |
1514 | |
1515 | nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0, | |
1516 | hwdef->nvram_size, 2); | |
1517 | ||
1518 | slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[hwdef->ms_kb_irq], | |
993fbfdb | 1519 | display_type == DT_NOGRAPHIC, ESCC_CLOCK, 1); |
8137cde8 BS |
1520 | // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device |
1521 | // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device | |
aeeb69c7 AJ |
1522 | escc_init(hwdef->serial_base, slavio_irq[hwdef->ser_irq], |
1523 | slavio_irq[hwdef->ser_irq], serial_hds[0], serial_hds[1], | |
1524 | ESCC_CLOCK, 1); | |
8137cde8 | 1525 | |
2582cfa0 BS |
1526 | slavio_misc = slavio_misc_init(0, hwdef->aux1_base, 0, |
1527 | slavio_irq[hwdef->me_irq], fdc_tc); | |
8137cde8 BS |
1528 | |
1529 | if (hwdef->fd_base != (target_phys_addr_t)-1) { | |
1530 | /* there is zero or one floppy drive */ | |
ce802585 | 1531 | memset(fd, 0, sizeof(fd)); |
8137cde8 BS |
1532 | drive_index = drive_get_index(IF_FLOPPY, 0, 0); |
1533 | if (drive_index != -1) | |
1534 | fd[0] = drives_table[drive_index].bdrv; | |
1535 | ||
1536 | sun4m_fdctrl_init(slavio_irq[hwdef->fd_irq], hwdef->fd_base, fd, | |
2582cfa0 | 1537 | &fdc_tc); |
8137cde8 BS |
1538 | } |
1539 | ||
1540 | if (drive_get_max_bus(IF_SCSI) > 0) { | |
1541 | fprintf(stderr, "qemu: too many SCSI bus\n"); | |
1542 | exit(1); | |
1543 | } | |
1544 | ||
cfb9de9c PB |
1545 | esp_init(hwdef->esp_base, 2, |
1546 | espdma_memory_read, espdma_memory_write, | |
6f6260c7 | 1547 | espdma, espdma_irq, esp_reset); |
8137cde8 BS |
1548 | |
1549 | kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename, | |
1550 | RAM_size); | |
1551 | ||
1552 | nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline, | |
1553 | boot_device, RAM_size, kernel_size, graphic_width, | |
1554 | graphic_height, graphic_depth, hwdef->nvram_machine_id, | |
1555 | "Sun4c"); | |
1556 | ||
1557 | fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2); | |
1558 | fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1); | |
1559 | fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size); | |
1560 | fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id); | |
513f789f BS |
1561 | fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth); |
1562 | fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR); | |
1563 | fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size); | |
1564 | if (kernel_cmdline) { | |
1565 | fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR); | |
1566 | pstrcpy_targphys(CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline); | |
1567 | } else { | |
1568 | fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0); | |
1569 | } | |
1570 | fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR); | |
1571 | fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used | |
1572 | fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]); | |
1573 | qemu_register_boot_set(fw_cfg_boot_set, fw_cfg); | |
8137cde8 BS |
1574 | } |
1575 | ||
1576 | /* SPARCstation 2 hardware initialisation */ | |
fbe1b595 | 1577 | static void ss2_init(ram_addr_t RAM_size, |
3023f332 | 1578 | const char *boot_device, |
8137cde8 BS |
1579 | const char *kernel_filename, const char *kernel_cmdline, |
1580 | const char *initrd_filename, const char *cpu_model) | |
1581 | { | |
3023f332 | 1582 | sun4c_hw_init(&sun4c_hwdefs[0], RAM_size, boot_device, kernel_filename, |
8137cde8 BS |
1583 | kernel_cmdline, initrd_filename, cpu_model); |
1584 | } | |
1585 | ||
f80f9ec9 | 1586 | static QEMUMachine ss2_machine = { |
8137cde8 BS |
1587 | .name = "SS-2", |
1588 | .desc = "Sun4c platform, SPARCstation 2", | |
1589 | .init = ss2_init, | |
8137cde8 | 1590 | .use_scsi = 1, |
8137cde8 | 1591 | }; |
f80f9ec9 AL |
1592 | |
1593 | static void ss2_machine_init(void) | |
1594 | { | |
1595 | qemu_register_machine(&ss5_machine); | |
1596 | qemu_register_machine(&ss10_machine); | |
1597 | qemu_register_machine(&ss600mp_machine); | |
1598 | qemu_register_machine(&ss20_machine); | |
1599 | qemu_register_machine(&voyager_machine); | |
1600 | qemu_register_machine(&ss_lx_machine); | |
1601 | qemu_register_machine(&ss4_machine); | |
1602 | qemu_register_machine(&scls_machine); | |
1603 | qemu_register_machine(&sbook_machine); | |
1604 | qemu_register_machine(&ss1000_machine); | |
1605 | qemu_register_machine(&ss2000_machine); | |
1606 | qemu_register_machine(&ss2_machine); | |
1607 | } | |
1608 | ||
1609 | machine_init(ss2_machine_init); |