]> git.proxmox.com Git - mirror_qemu.git/blame - hw/sun4m.c
Sparc32: convert slavio_misc to qdev
[mirror_qemu.git] / hw / sun4m.c
CommitLineData
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 91struct 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
114struct 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
133struct 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
152int DMA_get_channel_mode (int nchan)
153{
154 return 0;
155}
156int DMA_read_memory (int nchan, void *buf, int pos, int size)
157{
158 return 0;
159}
160int DMA_write_memory (int nchan, void *buf, int pos, int size)
161{
162 return 0;
163}
164void DMA_hold_DREQ (int nchan) {}
165void DMA_release_DREQ (int nchan) {}
166void DMA_schedule(int nchan) {}
6f7e9aec
FB
167void DMA_init (int high_page_enable) {}
168void DMA_register_channel (int nchan,
169 DMA_transfer_handler transfer_handler,
170 void *opaque)
171{
172}
173
513f789f 174static 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 180static 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
227static void *slavio_intctl;
228
376253ec 229void pic_info(Monitor *mon)
e80cfcfc 230{
7d85892b 231 if (slavio_intctl)
376253ec 232 slavio_pic_info(mon, slavio_intctl);
e80cfcfc
FB
233}
234
376253ec 235void 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
241void 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
266static 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
282static void dummy_cpu_set_irq(void *opaque, int irq, int level)
283{
284}
285
3475187d
FB
286static void *slavio_misc;
287
288void qemu_system_powerdown(void)
289{
290 slavio_set_power_fail(slavio_misc, 1);
291}
292
c68ea704
FB
293static void main_cpu_reset(void *opaque)
294{
295 CPUState *env = opaque;
3d29fbef
BS
296
297 cpu_reset(env);
298 env->halted = 0;
299}
300
301static 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
309static 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 315static 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
367static 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 */
386static const uint8_t idreg_data[] = { 0xfe, 0x81, 0x01, 0x03 };
387
388static 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
401static 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
409static 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
418static void idreg_register_devices(void)
419{
420 sysbus_register_withprop(&idreg_info);
421}
422
423device_init(idreg_register_devices);
424
8137cde8 425static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
3ebf5aaf 426 const char *boot_device,
3023f332 427 const char *kernel_filename,
3ebf5aaf
BS
428 const char *kernel_cmdline,
429 const char *initrd_filename, const char *cpu_model)
36cd9210 430
420557e8 431{
ba3c64fb 432 CPUState *env, *envs[MAX_CPUS];
713c45fa 433 unsigned int i;
cfb9de9c 434 void *iommu, *espdma, *ledma, *nvram;
b3a23197 435 qemu_irq *cpu_irqs[MAX_CPUS], *slavio_irq, *slavio_cpu_irq,
d7edfd27 436 *espdma_irq, *ledma_irq;
2d069bab 437 qemu_irq *esp_reset, *le_reset;
2582cfa0 438 qemu_irq fdc_tc;
6d0c293d 439 qemu_irq *cpu_halt;
325f2747 440 ram_addr_t ram_offset, prom_offset;
5c6602c5 441 unsigned long kernel_size;
3ebf5aaf 442 int ret;
5cea8590 443 char *filename;
e4bcb14c 444 BlockDriverState *fd[MAX_FD];
22548760 445 int drive_index;
3cce6243 446 void *fw_cfg;
420557e8 447
ba3c64fb 448 /* init CPUs */
3ebf5aaf
BS
449 if (!cpu_model)
450 cpu_model = hwdef->default_cpu_model;
b3a23197 451
ba3c64fb 452 for(i = 0; i < smp_cpus; i++) {
aaed909a
FB
453 env = cpu_init(cpu_model);
454 if (!env) {
8e82c6a8 455 fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
aaed909a
FB
456 exit(1);
457 }
458 cpu_sparc_set_id(env, i);
ba3c64fb 459 envs[i] = env;
3d29fbef 460 if (i == 0) {
a08d4367 461 qemu_register_reset(main_cpu_reset, env);
3d29fbef 462 } else {
a08d4367 463 qemu_register_reset(secondary_cpu_reset, env);
ba3c64fb 464 env->halted = 1;
3d29fbef 465 }
b3a23197 466 cpu_irqs[i] = qemu_allocate_irqs(cpu_set_irq, envs[i], MAX_PILS);
3ebf5aaf 467 env->prom_addr = hwdef->slavio_base;
ba3c64fb 468 }
b3a23197
BS
469
470 for (i = smp_cpus; i < MAX_CPUS; i++)
471 cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS);
472
3ebf5aaf 473
420557e8 474 /* allocate RAM */
3ebf5aaf 475 if ((uint64_t)RAM_size > hwdef->max_mem) {
77f193da
BS
476 fprintf(stderr,
477 "qemu: Too much memory for this machine: %d, maximum %d\n",
6ef05b95 478 (unsigned int)(RAM_size / (1024 * 1024)),
3ebf5aaf
BS
479 (unsigned int)(hwdef->max_mem / (1024 * 1024)));
480 exit(1);
481 }
5c6602c5
BS
482 ram_offset = qemu_ram_alloc(RAM_size);
483 cpu_register_physical_memory(0, RAM_size, ram_offset);
420557e8 484
3ebf5aaf 485 /* load boot prom */
5c6602c5 486 prom_offset = qemu_ram_alloc(PROM_SIZE_MAX);
3ebf5aaf
BS
487 cpu_register_physical_memory(hwdef->slavio_base,
488 (PROM_SIZE_MAX + TARGET_PAGE_SIZE - 1) &
489 TARGET_PAGE_MASK,
490 prom_offset | IO_MEM_ROM);
491
492 if (bios_name == NULL)
493 bios_name = PROM_FILENAME;
5cea8590
PB
494 filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
495 if (filename) {
496 ret = load_elf(filename, hwdef->slavio_base - PROM_VADDR,
497 NULL, NULL, NULL);
498 if (ret < 0 || ret > PROM_SIZE_MAX)
499 ret = load_image_targphys(filename, hwdef->slavio_base,
500 PROM_SIZE_MAX);
501 qemu_free(filename);
502 } else {
503 ret = -1;
504 }
3ebf5aaf
BS
505 if (ret < 0 || ret > PROM_SIZE_MAX) {
506 fprintf(stderr, "qemu: could not load prom '%s'\n",
5cea8590 507 bios_name);
3ebf5aaf
BS
508 exit(1);
509 }
510
511 /* set up devices */
36cd9210 512 slavio_intctl = slavio_intctl_init(hwdef->intctl_base,
5dcb6b91 513 hwdef->intctl_base + 0x10000ULL,
d537cf6c 514 &hwdef->intbit_to_level[0],
d7edfd27 515 &slavio_irq, &slavio_cpu_irq,
b3a23197 516 cpu_irqs,
d7edfd27 517 hwdef->clock_irq);
b3a23197 518
fe096129 519 if (hwdef->idreg_base) {
325f2747 520 idreg_init(hwdef->idreg_base);
4c2485de
BS
521 }
522
ff403da6
BS
523 iommu = iommu_init(hwdef->iommu_base, hwdef->iommu_version,
524 slavio_irq[hwdef->me_irq]);
525
5aca8c3b 526 espdma = sparc32_dma_init(hwdef->dma_base, slavio_irq[hwdef->esp_irq],
2d069bab
BS
527 iommu, &espdma_irq, &esp_reset);
528
5aca8c3b 529 ledma = sparc32_dma_init(hwdef->dma_base + 16ULL,
2d069bab
BS
530 slavio_irq[hwdef->le_irq], iommu, &ledma_irq,
531 &le_reset);
ba3c64fb 532
eee0b836
BS
533 if (graphic_depth != 8 && graphic_depth != 24) {
534 fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
535 exit (1);
536 }
dc828ca1
PB
537 tcx_init(hwdef->tcx_base, hwdef->vram_size, graphic_width, graphic_height,
538 graphic_depth);
dbe06e18 539
0ae18cee 540 lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);
dbe06e18 541
d537cf6c
PB
542 nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0,
543 hwdef->nvram_size, 8);
81732d19
BS
544
545 slavio_timer_init_all(hwdef->counter_base, slavio_irq[hwdef->clock1_irq],
19f8e5dd 546 slavio_cpu_irq, smp_cpus);
81732d19 547
577390ff 548 slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[hwdef->ms_kb_irq],
993fbfdb 549 display_type == DT_NOGRAPHIC, ESCC_CLOCK, 1);
b81b3b10
FB
550 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
551 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
aeeb69c7
AJ
552 escc_init(hwdef->serial_base, slavio_irq[hwdef->ser_irq], slavio_irq[hwdef->ser_irq],
553 serial_hds[0], serial_hds[1], ESCC_CLOCK, 1);
741402f9 554
6d0c293d 555 cpu_halt = qemu_allocate_irqs(cpu_halt_signal, NULL, 1);
2582cfa0 556 slavio_misc = slavio_misc_init(hwdef->slavio_base,
2be17ebd 557 hwdef->aux1_base, hwdef->aux2_base,
2582cfa0
BS
558 slavio_irq[hwdef->me_irq], fdc_tc);
559 if (hwdef->apc_base) {
560 apc_init(hwdef->apc_base, cpu_halt[0]);
561 }
2be17ebd 562
fe096129 563 if (hwdef->fd_base) {
e4bcb14c 564 /* there is zero or one floppy drive */
309e60bd 565 memset(fd, 0, sizeof(fd));
22548760
BS
566 drive_index = drive_get_index(IF_FLOPPY, 0, 0);
567 if (drive_index != -1)
568 fd[0] = drives_table[drive_index].bdrv;
2d069bab 569
2be17ebd 570 sun4m_fdctrl_init(slavio_irq[hwdef->fd_irq], hwdef->fd_base, fd,
2582cfa0 571 &fdc_tc);
e4bcb14c
TS
572 }
573
574 if (drive_get_max_bus(IF_SCSI) > 0) {
575 fprintf(stderr, "qemu: too many SCSI bus\n");
576 exit(1);
577 }
578
cfb9de9c
PB
579 esp_init(hwdef->esp_base, 2,
580 espdma_memory_read, espdma_memory_write,
581 espdma, *espdma_irq, esp_reset);
f1587550 582
fe096129 583 if (hwdef->cs_base)
803b3c7b 584 cs_init(hwdef->cs_base, hwdef->cs_irq, slavio_intctl);
b3ceef24 585
293f78bc
BS
586 kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
587 RAM_size);
36cd9210 588
36cd9210 589 nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
b3ceef24 590 boot_device, RAM_size, kernel_size, graphic_width,
905fdcb5
BS
591 graphic_height, graphic_depth, hwdef->nvram_machine_id,
592 "Sun4m");
7eb0c8e8 593
fe096129 594 if (hwdef->ecc_base)
e42c20b4
BS
595 ecc_init(hwdef->ecc_base, slavio_irq[hwdef->ecc_irq],
596 hwdef->ecc_version);
3cce6243
BS
597
598 fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
599 fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
905fdcb5
BS
600 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
601 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
fbfcf955 602 fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
513f789f
BS
603 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
604 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
605 if (kernel_cmdline) {
606 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
607 pstrcpy_targphys(CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
608 } else {
609 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
610 }
611 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
612 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
613 fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
614 qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
36cd9210
BS
615}
616
905fdcb5
BS
617enum {
618 ss2_id = 0,
619 ss5_id = 32,
620 vger_id,
621 lx_id,
622 ss4_id,
623 scls_id,
624 sbook_id,
625 ss10_id = 64,
626 ss20_id,
627 ss600mp_id,
628 ss1000_id = 96,
629 ss2000_id,
630};
631
8137cde8 632static const struct sun4m_hwdef sun4m_hwdefs[] = {
36cd9210
BS
633 /* SS-5 */
634 {
635 .iommu_base = 0x10000000,
636 .tcx_base = 0x50000000,
637 .cs_base = 0x6c000000,
384ccb5d 638 .slavio_base = 0x70000000,
36cd9210
BS
639 .ms_kb_base = 0x71000000,
640 .serial_base = 0x71100000,
641 .nvram_base = 0x71200000,
642 .fd_base = 0x71400000,
643 .counter_base = 0x71d00000,
644 .intctl_base = 0x71e00000,
4c2485de 645 .idreg_base = 0x78000000,
36cd9210
BS
646 .dma_base = 0x78400000,
647 .esp_base = 0x78800000,
648 .le_base = 0x78c00000,
127fc407 649 .apc_base = 0x6a000000,
0019ad53
BS
650 .aux1_base = 0x71900000,
651 .aux2_base = 0x71910000,
36cd9210
BS
652 .vram_size = 0x00100000,
653 .nvram_size = 0x2000,
654 .esp_irq = 18,
655 .le_irq = 16,
e3a79bca 656 .clock_irq = 7,
36cd9210
BS
657 .clock1_irq = 19,
658 .ms_kb_irq = 14,
659 .ser_irq = 15,
660 .fd_irq = 22,
661 .me_irq = 30,
662 .cs_irq = 5,
905fdcb5
BS
663 .nvram_machine_id = 0x80,
664 .machine_id = ss5_id,
cf3102ac 665 .iommu_version = 0x05000000,
e0353fe2 666 .intbit_to_level = {
f930d07e
BS
667 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
668 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
e0353fe2 669 },
3ebf5aaf
BS
670 .max_mem = 0x10000000,
671 .default_cpu_model = "Fujitsu MB86904",
e0353fe2
BS
672 },
673 /* SS-10 */
e0353fe2 674 {
5dcb6b91
BS
675 .iommu_base = 0xfe0000000ULL,
676 .tcx_base = 0xe20000000ULL,
5dcb6b91
BS
677 .slavio_base = 0xff0000000ULL,
678 .ms_kb_base = 0xff1000000ULL,
679 .serial_base = 0xff1100000ULL,
680 .nvram_base = 0xff1200000ULL,
681 .fd_base = 0xff1700000ULL,
682 .counter_base = 0xff1300000ULL,
683 .intctl_base = 0xff1400000ULL,
4c2485de 684 .idreg_base = 0xef0000000ULL,
5dcb6b91
BS
685 .dma_base = 0xef0400000ULL,
686 .esp_base = 0xef0800000ULL,
687 .le_base = 0xef0c00000ULL,
0019ad53 688 .apc_base = 0xefa000000ULL, // XXX should not exist
127fc407
BS
689 .aux1_base = 0xff1800000ULL,
690 .aux2_base = 0xff1a01000ULL,
7eb0c8e8
BS
691 .ecc_base = 0xf00000000ULL,
692 .ecc_version = 0x10000000, // version 0, implementation 1
e0353fe2
BS
693 .vram_size = 0x00100000,
694 .nvram_size = 0x2000,
695 .esp_irq = 18,
696 .le_irq = 16,
e3a79bca 697 .clock_irq = 7,
e0353fe2
BS
698 .clock1_irq = 19,
699 .ms_kb_irq = 14,
700 .ser_irq = 15,
701 .fd_irq = 22,
702 .me_irq = 30,
e42c20b4 703 .ecc_irq = 28,
905fdcb5
BS
704 .nvram_machine_id = 0x72,
705 .machine_id = ss10_id,
7fbfb139 706 .iommu_version = 0x03000000,
e0353fe2 707 .intbit_to_level = {
f930d07e
BS
708 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
709 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
e0353fe2 710 },
6ef05b95 711 .max_mem = 0xf00000000ULL,
3ebf5aaf 712 .default_cpu_model = "TI SuperSparc II",
36cd9210 713 },
6a3b9cc9
BS
714 /* SS-600MP */
715 {
716 .iommu_base = 0xfe0000000ULL,
717 .tcx_base = 0xe20000000ULL,
6a3b9cc9
BS
718 .slavio_base = 0xff0000000ULL,
719 .ms_kb_base = 0xff1000000ULL,
720 .serial_base = 0xff1100000ULL,
721 .nvram_base = 0xff1200000ULL,
6a3b9cc9
BS
722 .counter_base = 0xff1300000ULL,
723 .intctl_base = 0xff1400000ULL,
724 .dma_base = 0xef0081000ULL,
725 .esp_base = 0xef0080000ULL,
726 .le_base = 0xef0060000ULL,
0019ad53 727 .apc_base = 0xefa000000ULL, // XXX should not exist
127fc407
BS
728 .aux1_base = 0xff1800000ULL,
729 .aux2_base = 0xff1a01000ULL, // XXX should not exist
7eb0c8e8
BS
730 .ecc_base = 0xf00000000ULL,
731 .ecc_version = 0x00000000, // version 0, implementation 0
6a3b9cc9
BS
732 .vram_size = 0x00100000,
733 .nvram_size = 0x2000,
734 .esp_irq = 18,
735 .le_irq = 16,
e3a79bca 736 .clock_irq = 7,
6a3b9cc9
BS
737 .clock1_irq = 19,
738 .ms_kb_irq = 14,
739 .ser_irq = 15,
740 .fd_irq = 22,
741 .me_irq = 30,
e42c20b4 742 .ecc_irq = 28,
905fdcb5
BS
743 .nvram_machine_id = 0x71,
744 .machine_id = ss600mp_id,
7fbfb139 745 .iommu_version = 0x01000000,
6a3b9cc9
BS
746 .intbit_to_level = {
747 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
748 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
749 },
6ef05b95 750 .max_mem = 0xf00000000ULL,
3ebf5aaf 751 .default_cpu_model = "TI SuperSparc II",
6a3b9cc9 752 },
ae40972f
BS
753 /* SS-20 */
754 {
755 .iommu_base = 0xfe0000000ULL,
756 .tcx_base = 0xe20000000ULL,
ae40972f
BS
757 .slavio_base = 0xff0000000ULL,
758 .ms_kb_base = 0xff1000000ULL,
759 .serial_base = 0xff1100000ULL,
760 .nvram_base = 0xff1200000ULL,
761 .fd_base = 0xff1700000ULL,
762 .counter_base = 0xff1300000ULL,
763 .intctl_base = 0xff1400000ULL,
4c2485de 764 .idreg_base = 0xef0000000ULL,
ae40972f
BS
765 .dma_base = 0xef0400000ULL,
766 .esp_base = 0xef0800000ULL,
767 .le_base = 0xef0c00000ULL,
0019ad53 768 .apc_base = 0xefa000000ULL, // XXX should not exist
577d8dd4
BS
769 .aux1_base = 0xff1800000ULL,
770 .aux2_base = 0xff1a01000ULL,
ae40972f
BS
771 .ecc_base = 0xf00000000ULL,
772 .ecc_version = 0x20000000, // version 0, implementation 2
773 .vram_size = 0x00100000,
774 .nvram_size = 0x2000,
775 .esp_irq = 18,
776 .le_irq = 16,
e3a79bca 777 .clock_irq = 7,
ae40972f
BS
778 .clock1_irq = 19,
779 .ms_kb_irq = 14,
780 .ser_irq = 15,
781 .fd_irq = 22,
782 .me_irq = 30,
e42c20b4 783 .ecc_irq = 28,
905fdcb5
BS
784 .nvram_machine_id = 0x72,
785 .machine_id = ss20_id,
ae40972f
BS
786 .iommu_version = 0x13000000,
787 .intbit_to_level = {
788 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
789 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
790 },
6ef05b95 791 .max_mem = 0xf00000000ULL,
ae40972f
BS
792 .default_cpu_model = "TI SuperSparc II",
793 },
a526a31c
BS
794 /* Voyager */
795 {
796 .iommu_base = 0x10000000,
797 .tcx_base = 0x50000000,
a526a31c
BS
798 .slavio_base = 0x70000000,
799 .ms_kb_base = 0x71000000,
800 .serial_base = 0x71100000,
801 .nvram_base = 0x71200000,
802 .fd_base = 0x71400000,
803 .counter_base = 0x71d00000,
804 .intctl_base = 0x71e00000,
805 .idreg_base = 0x78000000,
806 .dma_base = 0x78400000,
807 .esp_base = 0x78800000,
808 .le_base = 0x78c00000,
809 .apc_base = 0x71300000, // pmc
810 .aux1_base = 0x71900000,
811 .aux2_base = 0x71910000,
a526a31c
BS
812 .vram_size = 0x00100000,
813 .nvram_size = 0x2000,
814 .esp_irq = 18,
815 .le_irq = 16,
816 .clock_irq = 7,
817 .clock1_irq = 19,
818 .ms_kb_irq = 14,
819 .ser_irq = 15,
820 .fd_irq = 22,
821 .me_irq = 30,
905fdcb5
BS
822 .nvram_machine_id = 0x80,
823 .machine_id = vger_id,
a526a31c
BS
824 .iommu_version = 0x05000000,
825 .intbit_to_level = {
826 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
827 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
828 },
829 .max_mem = 0x10000000,
830 .default_cpu_model = "Fujitsu MB86904",
831 },
832 /* LX */
833 {
834 .iommu_base = 0x10000000,
835 .tcx_base = 0x50000000,
a526a31c
BS
836 .slavio_base = 0x70000000,
837 .ms_kb_base = 0x71000000,
838 .serial_base = 0x71100000,
839 .nvram_base = 0x71200000,
840 .fd_base = 0x71400000,
841 .counter_base = 0x71d00000,
842 .intctl_base = 0x71e00000,
843 .idreg_base = 0x78000000,
844 .dma_base = 0x78400000,
845 .esp_base = 0x78800000,
846 .le_base = 0x78c00000,
a526a31c
BS
847 .aux1_base = 0x71900000,
848 .aux2_base = 0x71910000,
a526a31c
BS
849 .vram_size = 0x00100000,
850 .nvram_size = 0x2000,
851 .esp_irq = 18,
852 .le_irq = 16,
853 .clock_irq = 7,
854 .clock1_irq = 19,
855 .ms_kb_irq = 14,
856 .ser_irq = 15,
857 .fd_irq = 22,
858 .me_irq = 30,
905fdcb5
BS
859 .nvram_machine_id = 0x80,
860 .machine_id = lx_id,
a526a31c
BS
861 .iommu_version = 0x04000000,
862 .intbit_to_level = {
863 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
864 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
865 },
866 .max_mem = 0x10000000,
867 .default_cpu_model = "TI MicroSparc I",
868 },
869 /* SS-4 */
870 {
871 .iommu_base = 0x10000000,
872 .tcx_base = 0x50000000,
873 .cs_base = 0x6c000000,
874 .slavio_base = 0x70000000,
875 .ms_kb_base = 0x71000000,
876 .serial_base = 0x71100000,
877 .nvram_base = 0x71200000,
878 .fd_base = 0x71400000,
879 .counter_base = 0x71d00000,
880 .intctl_base = 0x71e00000,
881 .idreg_base = 0x78000000,
882 .dma_base = 0x78400000,
883 .esp_base = 0x78800000,
884 .le_base = 0x78c00000,
885 .apc_base = 0x6a000000,
886 .aux1_base = 0x71900000,
887 .aux2_base = 0x71910000,
a526a31c
BS
888 .vram_size = 0x00100000,
889 .nvram_size = 0x2000,
890 .esp_irq = 18,
891 .le_irq = 16,
892 .clock_irq = 7,
893 .clock1_irq = 19,
894 .ms_kb_irq = 14,
895 .ser_irq = 15,
896 .fd_irq = 22,
897 .me_irq = 30,
898 .cs_irq = 5,
905fdcb5
BS
899 .nvram_machine_id = 0x80,
900 .machine_id = ss4_id,
a526a31c
BS
901 .iommu_version = 0x05000000,
902 .intbit_to_level = {
903 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
904 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
905 },
906 .max_mem = 0x10000000,
907 .default_cpu_model = "Fujitsu MB86904",
908 },
909 /* SPARCClassic */
910 {
911 .iommu_base = 0x10000000,
912 .tcx_base = 0x50000000,
a526a31c
BS
913 .slavio_base = 0x70000000,
914 .ms_kb_base = 0x71000000,
915 .serial_base = 0x71100000,
916 .nvram_base = 0x71200000,
917 .fd_base = 0x71400000,
918 .counter_base = 0x71d00000,
919 .intctl_base = 0x71e00000,
920 .idreg_base = 0x78000000,
921 .dma_base = 0x78400000,
922 .esp_base = 0x78800000,
923 .le_base = 0x78c00000,
924 .apc_base = 0x6a000000,
925 .aux1_base = 0x71900000,
926 .aux2_base = 0x71910000,
a526a31c
BS
927 .vram_size = 0x00100000,
928 .nvram_size = 0x2000,
929 .esp_irq = 18,
930 .le_irq = 16,
931 .clock_irq = 7,
932 .clock1_irq = 19,
933 .ms_kb_irq = 14,
934 .ser_irq = 15,
935 .fd_irq = 22,
936 .me_irq = 30,
905fdcb5
BS
937 .nvram_machine_id = 0x80,
938 .machine_id = scls_id,
a526a31c
BS
939 .iommu_version = 0x05000000,
940 .intbit_to_level = {
941 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
942 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
943 },
944 .max_mem = 0x10000000,
945 .default_cpu_model = "TI MicroSparc I",
946 },
947 /* SPARCbook */
948 {
949 .iommu_base = 0x10000000,
950 .tcx_base = 0x50000000, // XXX
a526a31c
BS
951 .slavio_base = 0x70000000,
952 .ms_kb_base = 0x71000000,
953 .serial_base = 0x71100000,
954 .nvram_base = 0x71200000,
955 .fd_base = 0x71400000,
956 .counter_base = 0x71d00000,
957 .intctl_base = 0x71e00000,
958 .idreg_base = 0x78000000,
959 .dma_base = 0x78400000,
960 .esp_base = 0x78800000,
961 .le_base = 0x78c00000,
962 .apc_base = 0x6a000000,
963 .aux1_base = 0x71900000,
964 .aux2_base = 0x71910000,
a526a31c
BS
965 .vram_size = 0x00100000,
966 .nvram_size = 0x2000,
967 .esp_irq = 18,
968 .le_irq = 16,
969 .clock_irq = 7,
970 .clock1_irq = 19,
971 .ms_kb_irq = 14,
972 .ser_irq = 15,
973 .fd_irq = 22,
974 .me_irq = 30,
905fdcb5
BS
975 .nvram_machine_id = 0x80,
976 .machine_id = sbook_id,
a526a31c
BS
977 .iommu_version = 0x05000000,
978 .intbit_to_level = {
979 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
980 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
981 },
982 .max_mem = 0x10000000,
983 .default_cpu_model = "TI MicroSparc I",
984 },
36cd9210
BS
985};
986
36cd9210 987/* SPARCstation 5 hardware initialisation */
fbe1b595 988static void ss5_init(ram_addr_t RAM_size,
3023f332 989 const char *boot_device,
b881c2c6
BS
990 const char *kernel_filename, const char *kernel_cmdline,
991 const char *initrd_filename, const char *cpu_model)
36cd9210 992{
3023f332 993 sun4m_hw_init(&sun4m_hwdefs[0], RAM_size, boot_device, kernel_filename,
3ebf5aaf 994 kernel_cmdline, initrd_filename, cpu_model);
420557e8 995}
c0e564d5 996
e0353fe2 997/* SPARCstation 10 hardware initialisation */
fbe1b595 998static void ss10_init(ram_addr_t RAM_size,
3023f332 999 const char *boot_device,
b881c2c6
BS
1000 const char *kernel_filename, const char *kernel_cmdline,
1001 const char *initrd_filename, const char *cpu_model)
e0353fe2 1002{
3023f332 1003 sun4m_hw_init(&sun4m_hwdefs[1], RAM_size, boot_device, kernel_filename,
3ebf5aaf 1004 kernel_cmdline, initrd_filename, cpu_model);
e0353fe2
BS
1005}
1006
6a3b9cc9 1007/* SPARCserver 600MP hardware initialisation */
fbe1b595 1008static void ss600mp_init(ram_addr_t RAM_size,
3023f332 1009 const char *boot_device,
77f193da
BS
1010 const char *kernel_filename,
1011 const char *kernel_cmdline,
6a3b9cc9
BS
1012 const char *initrd_filename, const char *cpu_model)
1013{
3023f332 1014 sun4m_hw_init(&sun4m_hwdefs[2], RAM_size, boot_device, kernel_filename,
3ebf5aaf 1015 kernel_cmdline, initrd_filename, cpu_model);
6a3b9cc9
BS
1016}
1017
ae40972f 1018/* SPARCstation 20 hardware initialisation */
fbe1b595 1019static void ss20_init(ram_addr_t RAM_size,
3023f332 1020 const char *boot_device,
ae40972f
BS
1021 const char *kernel_filename, const char *kernel_cmdline,
1022 const char *initrd_filename, const char *cpu_model)
1023{
3023f332 1024 sun4m_hw_init(&sun4m_hwdefs[3], RAM_size, boot_device, kernel_filename,
ee76f82e
BS
1025 kernel_cmdline, initrd_filename, cpu_model);
1026}
1027
a526a31c 1028/* SPARCstation Voyager hardware initialisation */
fbe1b595 1029static void vger_init(ram_addr_t RAM_size,
3023f332 1030 const char *boot_device,
a526a31c
BS
1031 const char *kernel_filename, const char *kernel_cmdline,
1032 const char *initrd_filename, const char *cpu_model)
1033{
3023f332 1034 sun4m_hw_init(&sun4m_hwdefs[4], RAM_size, boot_device, kernel_filename,
a526a31c
BS
1035 kernel_cmdline, initrd_filename, cpu_model);
1036}
1037
1038/* SPARCstation LX hardware initialisation */
fbe1b595 1039static void ss_lx_init(ram_addr_t RAM_size,
3023f332 1040 const char *boot_device,
a526a31c
BS
1041 const char *kernel_filename, const char *kernel_cmdline,
1042 const char *initrd_filename, const char *cpu_model)
1043{
3023f332 1044 sun4m_hw_init(&sun4m_hwdefs[5], RAM_size, boot_device, kernel_filename,
a526a31c
BS
1045 kernel_cmdline, initrd_filename, cpu_model);
1046}
1047
1048/* SPARCstation 4 hardware initialisation */
fbe1b595 1049static void ss4_init(ram_addr_t RAM_size,
3023f332 1050 const char *boot_device,
a526a31c
BS
1051 const char *kernel_filename, const char *kernel_cmdline,
1052 const char *initrd_filename, const char *cpu_model)
1053{
3023f332 1054 sun4m_hw_init(&sun4m_hwdefs[6], RAM_size, boot_device, kernel_filename,
a526a31c
BS
1055 kernel_cmdline, initrd_filename, cpu_model);
1056}
1057
1058/* SPARCClassic hardware initialisation */
fbe1b595 1059static void scls_init(ram_addr_t RAM_size,
3023f332 1060 const char *boot_device,
a526a31c
BS
1061 const char *kernel_filename, const char *kernel_cmdline,
1062 const char *initrd_filename, const char *cpu_model)
1063{
3023f332 1064 sun4m_hw_init(&sun4m_hwdefs[7], RAM_size, boot_device, kernel_filename,
a526a31c
BS
1065 kernel_cmdline, initrd_filename, cpu_model);
1066}
1067
1068/* SPARCbook hardware initialisation */
fbe1b595 1069static void sbook_init(ram_addr_t RAM_size,
3023f332 1070 const char *boot_device,
a526a31c
BS
1071 const char *kernel_filename, const char *kernel_cmdline,
1072 const char *initrd_filename, const char *cpu_model)
1073{
3023f332 1074 sun4m_hw_init(&sun4m_hwdefs[8], RAM_size, boot_device, kernel_filename,
a526a31c
BS
1075 kernel_cmdline, initrd_filename, cpu_model);
1076}
1077
f80f9ec9 1078static QEMUMachine ss5_machine = {
66de733b
BS
1079 .name = "SS-5",
1080 .desc = "Sun4m platform, SPARCstation 5",
1081 .init = ss5_init,
c9b1ae2c 1082 .use_scsi = 1,
0c257437 1083 .is_default = 1,
c0e564d5 1084};
e0353fe2 1085
f80f9ec9 1086static QEMUMachine ss10_machine = {
66de733b
BS
1087 .name = "SS-10",
1088 .desc = "Sun4m platform, SPARCstation 10",
1089 .init = ss10_init,
c9b1ae2c 1090 .use_scsi = 1,
1bcee014 1091 .max_cpus = 4,
e0353fe2 1092};
6a3b9cc9 1093
f80f9ec9 1094static QEMUMachine ss600mp_machine = {
66de733b
BS
1095 .name = "SS-600MP",
1096 .desc = "Sun4m platform, SPARCserver 600MP",
1097 .init = ss600mp_init,
c9b1ae2c 1098 .use_scsi = 1,
1bcee014 1099 .max_cpus = 4,
6a3b9cc9 1100};
ae40972f 1101
f80f9ec9 1102static QEMUMachine ss20_machine = {
66de733b
BS
1103 .name = "SS-20",
1104 .desc = "Sun4m platform, SPARCstation 20",
1105 .init = ss20_init,
c9b1ae2c 1106 .use_scsi = 1,
1bcee014 1107 .max_cpus = 4,
ae40972f
BS
1108};
1109
f80f9ec9 1110static QEMUMachine voyager_machine = {
66de733b
BS
1111 .name = "Voyager",
1112 .desc = "Sun4m platform, SPARCstation Voyager",
1113 .init = vger_init,
c9b1ae2c 1114 .use_scsi = 1,
a526a31c
BS
1115};
1116
f80f9ec9 1117static QEMUMachine ss_lx_machine = {
66de733b
BS
1118 .name = "LX",
1119 .desc = "Sun4m platform, SPARCstation LX",
1120 .init = ss_lx_init,
c9b1ae2c 1121 .use_scsi = 1,
a526a31c
BS
1122};
1123
f80f9ec9 1124static QEMUMachine ss4_machine = {
66de733b
BS
1125 .name = "SS-4",
1126 .desc = "Sun4m platform, SPARCstation 4",
1127 .init = ss4_init,
c9b1ae2c 1128 .use_scsi = 1,
a526a31c
BS
1129};
1130
f80f9ec9 1131static QEMUMachine scls_machine = {
66de733b
BS
1132 .name = "SPARCClassic",
1133 .desc = "Sun4m platform, SPARCClassic",
1134 .init = scls_init,
c9b1ae2c 1135 .use_scsi = 1,
a526a31c
BS
1136};
1137
f80f9ec9 1138static QEMUMachine sbook_machine = {
66de733b
BS
1139 .name = "SPARCbook",
1140 .desc = "Sun4m platform, SPARCbook",
1141 .init = sbook_init,
c9b1ae2c 1142 .use_scsi = 1,
a526a31c
BS
1143};
1144
7d85892b
BS
1145static const struct sun4d_hwdef sun4d_hwdefs[] = {
1146 /* SS-1000 */
1147 {
1148 .iounit_bases = {
1149 0xfe0200000ULL,
1150 0xfe1200000ULL,
1151 0xfe2200000ULL,
1152 0xfe3200000ULL,
1153 -1,
1154 },
1155 .tcx_base = 0x820000000ULL,
1156 .slavio_base = 0xf00000000ULL,
1157 .ms_kb_base = 0xf00240000ULL,
1158 .serial_base = 0xf00200000ULL,
1159 .nvram_base = 0xf00280000ULL,
1160 .counter_base = 0xf00300000ULL,
1161 .espdma_base = 0x800081000ULL,
1162 .esp_base = 0x800080000ULL,
1163 .ledma_base = 0x800040000ULL,
1164 .le_base = 0x800060000ULL,
1165 .sbi_base = 0xf02800000ULL,
c1d00dc0 1166 .vram_size = 0x00100000,
7d85892b
BS
1167 .nvram_size = 0x2000,
1168 .esp_irq = 3,
1169 .le_irq = 4,
1170 .clock_irq = 14,
1171 .clock1_irq = 10,
1172 .ms_kb_irq = 12,
1173 .ser_irq = 12,
905fdcb5
BS
1174 .nvram_machine_id = 0x80,
1175 .machine_id = ss1000_id,
7d85892b 1176 .iounit_version = 0x03000000,
6ef05b95 1177 .max_mem = 0xf00000000ULL,
7d85892b
BS
1178 .default_cpu_model = "TI SuperSparc II",
1179 },
1180 /* SS-2000 */
1181 {
1182 .iounit_bases = {
1183 0xfe0200000ULL,
1184 0xfe1200000ULL,
1185 0xfe2200000ULL,
1186 0xfe3200000ULL,
1187 0xfe4200000ULL,
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 = ss2000_id,
7d85892b 1210 .iounit_version = 0x03000000,
6ef05b95 1211 .max_mem = 0xf00000000ULL,
7d85892b
BS
1212 .default_cpu_model = "TI SuperSparc II",
1213 },
1214};
1215
6ef05b95 1216static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,
7d85892b 1217 const char *boot_device,
3023f332 1218 const char *kernel_filename,
7d85892b
BS
1219 const char *kernel_cmdline,
1220 const char *initrd_filename, const char *cpu_model)
1221{
1222 CPUState *env, *envs[MAX_CPUS];
1223 unsigned int i;
cfb9de9c 1224 void *iounits[MAX_IOUNITS], *espdma, *ledma, *nvram, *sbi;
7d85892b
BS
1225 qemu_irq *cpu_irqs[MAX_CPUS], *sbi_irq, *sbi_cpu_irq,
1226 *espdma_irq, *ledma_irq;
1227 qemu_irq *esp_reset, *le_reset;
dc828ca1 1228 ram_addr_t ram_offset, prom_offset;
5c6602c5 1229 unsigned long kernel_size;
7d85892b 1230 int ret;
5cea8590 1231 char *filename;
3cce6243 1232 void *fw_cfg;
7d85892b
BS
1233
1234 /* init CPUs */
1235 if (!cpu_model)
1236 cpu_model = hwdef->default_cpu_model;
1237
1238 for (i = 0; i < smp_cpus; i++) {
1239 env = cpu_init(cpu_model);
1240 if (!env) {
8e82c6a8 1241 fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
7d85892b
BS
1242 exit(1);
1243 }
1244 cpu_sparc_set_id(env, i);
1245 envs[i] = env;
1246 if (i == 0) {
a08d4367 1247 qemu_register_reset(main_cpu_reset, env);
7d85892b 1248 } else {
a08d4367 1249 qemu_register_reset(secondary_cpu_reset, env);
7d85892b
BS
1250 env->halted = 1;
1251 }
7d85892b
BS
1252 cpu_irqs[i] = qemu_allocate_irqs(cpu_set_irq, envs[i], MAX_PILS);
1253 env->prom_addr = hwdef->slavio_base;
1254 }
1255
1256 for (i = smp_cpus; i < MAX_CPUS; i++)
1257 cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS);
1258
1259 /* allocate RAM */
1260 if ((uint64_t)RAM_size > hwdef->max_mem) {
77f193da
BS
1261 fprintf(stderr,
1262 "qemu: Too much memory for this machine: %d, maximum %d\n",
6ef05b95 1263 (unsigned int)(RAM_size / (1024 * 1024)),
7d85892b
BS
1264 (unsigned int)(hwdef->max_mem / (1024 * 1024)));
1265 exit(1);
1266 }
5c6602c5
BS
1267 ram_offset = qemu_ram_alloc(RAM_size);
1268 cpu_register_physical_memory(0, RAM_size, ram_offset);
7d85892b
BS
1269
1270 /* load boot prom */
5c6602c5 1271 prom_offset = qemu_ram_alloc(PROM_SIZE_MAX);
7d85892b
BS
1272 cpu_register_physical_memory(hwdef->slavio_base,
1273 (PROM_SIZE_MAX + TARGET_PAGE_SIZE - 1) &
1274 TARGET_PAGE_MASK,
1275 prom_offset | IO_MEM_ROM);
1276
1277 if (bios_name == NULL)
1278 bios_name = PROM_FILENAME;
5cea8590
PB
1279 filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
1280 if (filename) {
1281 ret = load_elf(filename, hwdef->slavio_base - PROM_VADDR,
1282 NULL, NULL, NULL);
1283 if (ret < 0 || ret > PROM_SIZE_MAX)
1284 ret = load_image_targphys(filename, hwdef->slavio_base,
1285 PROM_SIZE_MAX);
1286 qemu_free(filename);
1287 } else {
1288 ret = -1;
1289 }
7d85892b
BS
1290 if (ret < 0 || ret > PROM_SIZE_MAX) {
1291 fprintf(stderr, "qemu: could not load prom '%s'\n",
5cea8590 1292 bios_name);
7d85892b
BS
1293 exit(1);
1294 }
1295
1296 /* set up devices */
1297 sbi = sbi_init(hwdef->sbi_base, &sbi_irq, &sbi_cpu_irq, cpu_irqs);
1298
1299 for (i = 0; i < MAX_IOUNITS; i++)
1300 if (hwdef->iounit_bases[i] != (target_phys_addr_t)-1)
ff403da6
BS
1301 iounits[i] = iommu_init(hwdef->iounit_bases[i],
1302 hwdef->iounit_version,
1303 sbi_irq[hwdef->me_irq]);
7d85892b
BS
1304
1305 espdma = sparc32_dma_init(hwdef->espdma_base, sbi_irq[hwdef->esp_irq],
1306 iounits[0], &espdma_irq, &esp_reset);
1307
1308 ledma = sparc32_dma_init(hwdef->ledma_base, sbi_irq[hwdef->le_irq],
1309 iounits[0], &ledma_irq, &le_reset);
1310
1311 if (graphic_depth != 8 && graphic_depth != 24) {
1312 fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
1313 exit (1);
1314 }
dc828ca1
PB
1315 tcx_init(hwdef->tcx_base, hwdef->vram_size, graphic_width, graphic_height,
1316 graphic_depth);
7d85892b 1317
0ae18cee 1318 lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);
7d85892b
BS
1319
1320 nvram = m48t59_init(sbi_irq[0], hwdef->nvram_base, 0,
1321 hwdef->nvram_size, 8);
1322
1323 slavio_timer_init_all(hwdef->counter_base, sbi_irq[hwdef->clock1_irq],
1324 sbi_cpu_irq, smp_cpus);
1325
1326 slavio_serial_ms_kbd_init(hwdef->ms_kb_base, sbi_irq[hwdef->ms_kb_irq],
993fbfdb 1327 display_type == DT_NOGRAPHIC, ESCC_CLOCK, 1);
7d85892b
BS
1328 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
1329 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
aeeb69c7
AJ
1330 escc_init(hwdef->serial_base, sbi_irq[hwdef->ser_irq], sbi_irq[hwdef->ser_irq],
1331 serial_hds[0], serial_hds[1], ESCC_CLOCK, 1);
7d85892b
BS
1332
1333 if (drive_get_max_bus(IF_SCSI) > 0) {
1334 fprintf(stderr, "qemu: too many SCSI bus\n");
1335 exit(1);
1336 }
1337
cfb9de9c
PB
1338 esp_init(hwdef->esp_base, 2,
1339 espdma_memory_read, espdma_memory_write,
1340 espdma, *espdma_irq, esp_reset);
7d85892b 1341
293f78bc
BS
1342 kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
1343 RAM_size);
7d85892b
BS
1344
1345 nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
1346 boot_device, RAM_size, kernel_size, graphic_width,
905fdcb5
BS
1347 graphic_height, graphic_depth, hwdef->nvram_machine_id,
1348 "Sun4d");
3cce6243
BS
1349
1350 fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
1351 fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
905fdcb5
BS
1352 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
1353 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
513f789f
BS
1354 fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
1355 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
1356 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
1357 if (kernel_cmdline) {
1358 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
1359 pstrcpy_targphys(CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
1360 } else {
1361 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
1362 }
1363 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
1364 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
1365 fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
1366 qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
7d85892b
BS
1367}
1368
1369/* SPARCserver 1000 hardware initialisation */
fbe1b595 1370static void ss1000_init(ram_addr_t RAM_size,
3023f332 1371 const char *boot_device,
7d85892b
BS
1372 const char *kernel_filename, const char *kernel_cmdline,
1373 const char *initrd_filename, const char *cpu_model)
1374{
3023f332 1375 sun4d_hw_init(&sun4d_hwdefs[0], RAM_size, boot_device, kernel_filename,
7d85892b
BS
1376 kernel_cmdline, initrd_filename, cpu_model);
1377}
1378
1379/* SPARCcenter 2000 hardware initialisation */
fbe1b595 1380static void ss2000_init(ram_addr_t RAM_size,
3023f332 1381 const char *boot_device,
7d85892b
BS
1382 const char *kernel_filename, const char *kernel_cmdline,
1383 const char *initrd_filename, const char *cpu_model)
1384{
3023f332 1385 sun4d_hw_init(&sun4d_hwdefs[1], RAM_size, boot_device, kernel_filename,
7d85892b
BS
1386 kernel_cmdline, initrd_filename, cpu_model);
1387}
1388
f80f9ec9 1389static QEMUMachine ss1000_machine = {
66de733b
BS
1390 .name = "SS-1000",
1391 .desc = "Sun4d platform, SPARCserver 1000",
1392 .init = ss1000_init,
c9b1ae2c 1393 .use_scsi = 1,
1bcee014 1394 .max_cpus = 8,
7d85892b
BS
1395};
1396
f80f9ec9 1397static QEMUMachine ss2000_machine = {
66de733b
BS
1398 .name = "SS-2000",
1399 .desc = "Sun4d platform, SPARCcenter 2000",
1400 .init = ss2000_init,
c9b1ae2c 1401 .use_scsi = 1,
1bcee014 1402 .max_cpus = 20,
7d85892b 1403};
8137cde8
BS
1404
1405static const struct sun4c_hwdef sun4c_hwdefs[] = {
1406 /* SS-2 */
1407 {
1408 .iommu_base = 0xf8000000,
1409 .tcx_base = 0xfe000000,
8137cde8
BS
1410 .slavio_base = 0xf6000000,
1411 .intctl_base = 0xf5000000,
1412 .counter_base = 0xf3000000,
1413 .ms_kb_base = 0xf0000000,
1414 .serial_base = 0xf1000000,
1415 .nvram_base = 0xf2000000,
1416 .fd_base = 0xf7200000,
1417 .dma_base = 0xf8400000,
1418 .esp_base = 0xf8800000,
1419 .le_base = 0xf8c00000,
8137cde8 1420 .aux1_base = 0xf7400003,
8137cde8
BS
1421 .vram_size = 0x00100000,
1422 .nvram_size = 0x800,
1423 .esp_irq = 2,
1424 .le_irq = 3,
1425 .clock_irq = 5,
1426 .clock1_irq = 7,
1427 .ms_kb_irq = 1,
1428 .ser_irq = 1,
1429 .fd_irq = 1,
1430 .me_irq = 1,
8137cde8
BS
1431 .nvram_machine_id = 0x55,
1432 .machine_id = ss2_id,
1433 .max_mem = 0x10000000,
1434 .default_cpu_model = "Cypress CY7C601",
1435 },
1436};
1437
1438static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,
1439 const char *boot_device,
3023f332 1440 const char *kernel_filename,
8137cde8
BS
1441 const char *kernel_cmdline,
1442 const char *initrd_filename, const char *cpu_model)
1443{
1444 CPUState *env;
cfb9de9c 1445 void *iommu, *espdma, *ledma, *nvram;
8137cde8
BS
1446 qemu_irq *cpu_irqs, *slavio_irq, *espdma_irq, *ledma_irq;
1447 qemu_irq *esp_reset, *le_reset;
2582cfa0 1448 qemu_irq fdc_tc;
dc828ca1 1449 ram_addr_t ram_offset, prom_offset;
5c6602c5 1450 unsigned long kernel_size;
8137cde8 1451 int ret;
5cea8590 1452 char *filename;
8137cde8
BS
1453 BlockDriverState *fd[MAX_FD];
1454 int drive_index;
1455 void *fw_cfg;
1456
1457 /* init CPU */
1458 if (!cpu_model)
1459 cpu_model = hwdef->default_cpu_model;
1460
1461 env = cpu_init(cpu_model);
1462 if (!env) {
1463 fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
1464 exit(1);
1465 }
1466
1467 cpu_sparc_set_id(env, 0);
1468
a08d4367 1469 qemu_register_reset(main_cpu_reset, env);
8137cde8
BS
1470 cpu_irqs = qemu_allocate_irqs(cpu_set_irq, env, MAX_PILS);
1471 env->prom_addr = hwdef->slavio_base;
1472
1473 /* allocate RAM */
1474 if ((uint64_t)RAM_size > hwdef->max_mem) {
1475 fprintf(stderr,
1476 "qemu: Too much memory for this machine: %d, maximum %d\n",
1477 (unsigned int)(RAM_size / (1024 * 1024)),
1478 (unsigned int)(hwdef->max_mem / (1024 * 1024)));
1479 exit(1);
1480 }
5c6602c5
BS
1481 ram_offset = qemu_ram_alloc(RAM_size);
1482 cpu_register_physical_memory(0, RAM_size, ram_offset);
8137cde8
BS
1483
1484 /* load boot prom */
5c6602c5 1485 prom_offset = qemu_ram_alloc(PROM_SIZE_MAX);
8137cde8
BS
1486 cpu_register_physical_memory(hwdef->slavio_base,
1487 (PROM_SIZE_MAX + TARGET_PAGE_SIZE - 1) &
1488 TARGET_PAGE_MASK,
1489 prom_offset | IO_MEM_ROM);
1490
1491 if (bios_name == NULL)
1492 bios_name = PROM_FILENAME;
5cea8590
PB
1493 filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
1494 if (filename) {
1495 ret = load_elf(filename, hwdef->slavio_base - PROM_VADDR,
1496 NULL, NULL, NULL);
1497 if (ret < 0 || ret > PROM_SIZE_MAX)
1498 ret = load_image_targphys(filename, hwdef->slavio_base,
1499 PROM_SIZE_MAX);
1500 qemu_free(filename);
1501 } else {
1502 ret = -1;
1503 }
8137cde8
BS
1504 if (ret < 0 || ret > PROM_SIZE_MAX) {
1505 fprintf(stderr, "qemu: could not load prom '%s'\n",
5cea8590 1506 filename);
8137cde8
BS
1507 exit(1);
1508 }
8137cde8
BS
1509
1510 /* set up devices */
1511 slavio_intctl = sun4c_intctl_init(hwdef->intctl_base,
1512 &slavio_irq, cpu_irqs);
1513
1514 iommu = iommu_init(hwdef->iommu_base, hwdef->iommu_version,
1515 slavio_irq[hwdef->me_irq]);
1516
1517 espdma = sparc32_dma_init(hwdef->dma_base, slavio_irq[hwdef->esp_irq],
1518 iommu, &espdma_irq, &esp_reset);
1519
1520 ledma = sparc32_dma_init(hwdef->dma_base + 16ULL,
1521 slavio_irq[hwdef->le_irq], iommu, &ledma_irq,
1522 &le_reset);
1523
1524 if (graphic_depth != 8 && graphic_depth != 24) {
1525 fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
1526 exit (1);
1527 }
dc828ca1
PB
1528 tcx_init(hwdef->tcx_base, hwdef->vram_size, graphic_width, graphic_height,
1529 graphic_depth);
8137cde8 1530
0ae18cee 1531 lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);
8137cde8
BS
1532
1533 nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0,
1534 hwdef->nvram_size, 2);
1535
1536 slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[hwdef->ms_kb_irq],
993fbfdb 1537 display_type == DT_NOGRAPHIC, ESCC_CLOCK, 1);
8137cde8
BS
1538 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
1539 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
aeeb69c7
AJ
1540 escc_init(hwdef->serial_base, slavio_irq[hwdef->ser_irq],
1541 slavio_irq[hwdef->ser_irq], serial_hds[0], serial_hds[1],
1542 ESCC_CLOCK, 1);
8137cde8 1543
2582cfa0
BS
1544 slavio_misc = slavio_misc_init(0, hwdef->aux1_base, 0,
1545 slavio_irq[hwdef->me_irq], fdc_tc);
8137cde8
BS
1546
1547 if (hwdef->fd_base != (target_phys_addr_t)-1) {
1548 /* there is zero or one floppy drive */
ce802585 1549 memset(fd, 0, sizeof(fd));
8137cde8
BS
1550 drive_index = drive_get_index(IF_FLOPPY, 0, 0);
1551 if (drive_index != -1)
1552 fd[0] = drives_table[drive_index].bdrv;
1553
1554 sun4m_fdctrl_init(slavio_irq[hwdef->fd_irq], hwdef->fd_base, fd,
2582cfa0 1555 &fdc_tc);
8137cde8
BS
1556 }
1557
1558 if (drive_get_max_bus(IF_SCSI) > 0) {
1559 fprintf(stderr, "qemu: too many SCSI bus\n");
1560 exit(1);
1561 }
1562
cfb9de9c
PB
1563 esp_init(hwdef->esp_base, 2,
1564 espdma_memory_read, espdma_memory_write,
1565 espdma, *espdma_irq, esp_reset);
8137cde8
BS
1566
1567 kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
1568 RAM_size);
1569
1570 nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
1571 boot_device, RAM_size, kernel_size, graphic_width,
1572 graphic_height, graphic_depth, hwdef->nvram_machine_id,
1573 "Sun4c");
1574
1575 fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
1576 fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
1577 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
1578 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
513f789f
BS
1579 fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
1580 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
1581 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
1582 if (kernel_cmdline) {
1583 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
1584 pstrcpy_targphys(CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
1585 } else {
1586 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
1587 }
1588 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
1589 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
1590 fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
1591 qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
8137cde8
BS
1592}
1593
1594/* SPARCstation 2 hardware initialisation */
fbe1b595 1595static void ss2_init(ram_addr_t RAM_size,
3023f332 1596 const char *boot_device,
8137cde8
BS
1597 const char *kernel_filename, const char *kernel_cmdline,
1598 const char *initrd_filename, const char *cpu_model)
1599{
3023f332 1600 sun4c_hw_init(&sun4c_hwdefs[0], RAM_size, boot_device, kernel_filename,
8137cde8
BS
1601 kernel_cmdline, initrd_filename, cpu_model);
1602}
1603
f80f9ec9 1604static QEMUMachine ss2_machine = {
8137cde8
BS
1605 .name = "SS-2",
1606 .desc = "Sun4c platform, SPARCstation 2",
1607 .init = ss2_init,
8137cde8 1608 .use_scsi = 1,
8137cde8 1609};
f80f9ec9
AL
1610
1611static void ss2_machine_init(void)
1612{
1613 qemu_register_machine(&ss5_machine);
1614 qemu_register_machine(&ss10_machine);
1615 qemu_register_machine(&ss600mp_machine);
1616 qemu_register_machine(&ss20_machine);
1617 qemu_register_machine(&voyager_machine);
1618 qemu_register_machine(&ss_lx_machine);
1619 qemu_register_machine(&ss4_machine);
1620 qemu_register_machine(&scls_machine);
1621 qemu_register_machine(&sbook_machine);
1622 qemu_register_machine(&ss1000_machine);
1623 qemu_register_machine(&ss2000_machine);
1624 qemu_register_machine(&ss2_machine);
1625}
1626
1627machine_init(ss2_machine_init);