2 * QEMU Sun4m & Sun4d & Sun4c System Emulator
4 * Copyright (c) 2003-2005 Fabrice Bellard
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
25 #include "qemu-timer.h"
28 #include "sparc32_dma.h"
33 #include "firmware_abi.h"
42 * Sun4m architecture was used in the following machines:
44 * SPARCserver 6xxMP/xx
45 * SPARCclassic (SPARCclassic Server)(SPARCstation LC) (4/15),
46 * SPARCclassic X (4/10)
47 * SPARCstation LX/ZX (4/30)
48 * SPARCstation Voyager
49 * SPARCstation 10/xx, SPARCserver 10/xx
50 * SPARCstation 5, SPARCserver 5
51 * SPARCstation 20/xx, SPARCserver 20
54 * Sun4d architecture was used in the following machines:
59 * Sun4c architecture was used in the following machines:
60 * SPARCstation 1/1+, SPARCserver 1/1+
66 * See for example: http://www.sunhelp.org/faq/sunref1.html
70 #define DPRINTF(fmt, args...) \
71 do { printf("CPUIRQ: " fmt , ##args); } while (0)
73 #define DPRINTF(fmt, args...)
76 #define KERNEL_LOAD_ADDR 0x00004000
77 #define CMDLINE_ADDR 0x007ff000
78 #define INITRD_LOAD_ADDR 0x00800000
79 #define PROM_SIZE_MAX (512 * 1024)
80 #define PROM_VADDR 0xffd00000
81 #define PROM_FILENAME "openbios-sparc32"
82 #define CFG_ADDR 0xd00000510ULL
83 #define FW_CFG_SUN4M_DEPTH (FW_CFG_ARCH_LOCAL + 0x00)
85 // Control plane, 8-bit and 24-bit planes
86 #define TCX_SIZE (9 * 1024 * 1024)
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;
95 target_phys_addr_t idreg_base, dma_base, esp_base, le_base;
96 target_phys_addr_t tcx_base, cs_base, apc_base, aux1_base, aux2_base;
97 target_phys_addr_t ecc_base;
99 long vram_size, nvram_size;
100 // IRQ numbers are not PIL ones, but master interrupt controller
101 // register bit numbers
102 int esp_irq, le_irq, clock_irq, clock1_irq;
103 int ser_irq, ms_kb_irq, fd_irq, me_irq, cs_irq, ecc_irq;
104 uint8_t nvram_machine_id;
106 uint32_t iommu_version;
107 uint32_t intbit_to_level[32];
109 const char * const default_cpu_model;
112 #define MAX_IOUNITS 5
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;
126 uint8_t nvram_machine_id;
128 uint32_t iounit_version;
130 const char * const default_cpu_model;
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;
138 target_phys_addr_t tcx_base, aux1_base;
139 long vram_size, nvram_size;
140 // IRQ numbers are not PIL ones, but master interrupt controller
141 // register bit numbers
142 int esp_irq, le_irq, clock_irq, clock1_irq;
143 int ser_irq, ms_kb_irq, fd_irq, me_irq;
144 uint8_t nvram_machine_id;
146 uint32_t iommu_version;
147 uint32_t intbit_to_level[32];
149 const char * const default_cpu_model;
152 int DMA_get_channel_mode (int nchan)
156 int DMA_read_memory (int nchan, void *buf, int pos, int size)
160 int DMA_write_memory (int nchan, void *buf, int pos, int size)
164 void DMA_hold_DREQ (int nchan) {}
165 void DMA_release_DREQ (int nchan) {}
166 void DMA_schedule(int nchan) {}
167 void DMA_init (int high_page_enable) {}
168 void DMA_register_channel (int nchan,
169 DMA_transfer_handler transfer_handler,
174 static int nvram_boot_set(void *opaque, const char *boot_device)
177 uint8_t image[sizeof(ohwcfg_v3_t)];
178 ohwcfg_v3_t *header = (ohwcfg_v3_t *)ℑ
179 m48t59_t *nvram = (m48t59_t *)opaque;
181 for (i = 0; i < sizeof(image); i++)
182 image[i] = m48t59_read(nvram, i) & 0xff;
184 pstrcpy((char *)header->boot_devices, sizeof(header->boot_devices),
186 header->nboot_devices = strlen(boot_device) & 0xff;
187 header->crc = cpu_to_be16(OHW_compute_crc(header, 0x00, 0xF8));
189 for (i = 0; i < sizeof(image); i++)
190 m48t59_write(nvram, i, image[i]);
195 static void nvram_init(m48t59_t *nvram, uint8_t *macaddr, const char *cmdline,
196 const char *boot_devices, ram_addr_t RAM_size,
197 uint32_t kernel_size,
198 int width, int height, int depth,
199 int nvram_machine_id, const char *arch)
203 uint8_t image[0x1ff0];
204 ohwcfg_v3_t *header = (ohwcfg_v3_t *)ℑ
205 struct sparc_arch_cfg *sparc_header;
206 struct OpenBIOS_nvpart_v1 *part_header;
208 memset(image, '\0', sizeof(image));
210 // Try to match PPC NVRAM
211 pstrcpy((char *)header->struct_ident, sizeof(header->struct_ident),
213 header->struct_version = cpu_to_be32(3); /* structure v3 */
215 header->nvram_size = cpu_to_be16(0x2000);
216 header->nvram_arch_ptr = cpu_to_be16(sizeof(ohwcfg_v3_t));
217 header->nvram_arch_size = cpu_to_be16(sizeof(struct sparc_arch_cfg));
218 pstrcpy((char *)header->arch, sizeof(header->arch), arch);
219 header->nb_cpus = smp_cpus & 0xff;
220 header->RAM0_base = 0;
221 header->RAM0_size = cpu_to_be64((uint64_t)RAM_size);
222 pstrcpy((char *)header->boot_devices, sizeof(header->boot_devices),
224 header->nboot_devices = strlen(boot_devices) & 0xff;
225 header->kernel_image = cpu_to_be64((uint64_t)KERNEL_LOAD_ADDR);
226 header->kernel_size = cpu_to_be64((uint64_t)kernel_size);
228 pstrcpy_targphys(CMDLINE_ADDR, TARGET_PAGE_SIZE, cmdline);
229 header->cmdline = cpu_to_be64((uint64_t)CMDLINE_ADDR);
230 header->cmdline_size = cpu_to_be64((uint64_t)strlen(cmdline));
232 // XXX add initrd_image, initrd_size
233 header->width = cpu_to_be16(width);
234 header->height = cpu_to_be16(height);
235 header->depth = cpu_to_be16(depth);
237 header->graphic_flags = cpu_to_be16(OHW_GF_NOGRAPHICS);
239 header->crc = cpu_to_be16(OHW_compute_crc(header, 0x00, 0xF8));
241 // Architecture specific header
242 start = sizeof(ohwcfg_v3_t);
243 sparc_header = (struct sparc_arch_cfg *)&image[start];
244 sparc_header->valid = 0;
245 start += sizeof(struct sparc_arch_cfg);
247 // OpenBIOS nvram variables
248 // Variable partition
249 part_header = (struct OpenBIOS_nvpart_v1 *)&image[start];
250 part_header->signature = OPENBIOS_PART_SYSTEM;
251 pstrcpy(part_header->name, sizeof(part_header->name), "system");
253 end = start + sizeof(struct OpenBIOS_nvpart_v1);
254 for (i = 0; i < nb_prom_envs; i++)
255 end = OpenBIOS_set_var(image, end, prom_envs[i]);
260 end = start + ((end - start + 15) & ~15);
261 OpenBIOS_finish_partition(part_header, end - start);
265 part_header = (struct OpenBIOS_nvpart_v1 *)&image[start];
266 part_header->signature = OPENBIOS_PART_FREE;
267 pstrcpy(part_header->name, sizeof(part_header->name), "free");
270 OpenBIOS_finish_partition(part_header, end - start);
272 Sun_init_header((struct Sun_nvram *)&image[0x1fd8], macaddr,
275 for (i = 0; i < sizeof(image); i++)
276 m48t59_write(nvram, i, image[i]);
278 qemu_register_boot_set(nvram_boot_set, nvram);
281 static void *slavio_intctl;
286 slavio_pic_info(slavio_intctl);
292 slavio_irq_info(slavio_intctl);
295 void cpu_check_irqs(CPUState *env)
297 if (env->pil_in && (env->interrupt_index == 0 ||
298 (env->interrupt_index & ~15) == TT_EXTINT)) {
301 for (i = 15; i > 0; i--) {
302 if (env->pil_in & (1 << i)) {
303 int old_interrupt = env->interrupt_index;
305 env->interrupt_index = TT_EXTINT | i;
306 if (old_interrupt != env->interrupt_index) {
307 DPRINTF("Set CPU IRQ %d\n", i);
308 cpu_interrupt(env, CPU_INTERRUPT_HARD);
313 } else if (!env->pil_in && (env->interrupt_index & ~15) == TT_EXTINT) {
314 DPRINTF("Reset CPU IRQ %d\n", env->interrupt_index & 15);
315 env->interrupt_index = 0;
316 cpu_reset_interrupt(env, CPU_INTERRUPT_HARD);
320 static void cpu_set_irq(void *opaque, int irq, int level)
322 CPUState *env = opaque;
325 DPRINTF("Raise CPU IRQ %d\n", irq);
327 env->pil_in |= 1 << irq;
330 DPRINTF("Lower CPU IRQ %d\n", irq);
331 env->pil_in &= ~(1 << irq);
336 static void dummy_cpu_set_irq(void *opaque, int irq, int level)
340 static void *slavio_misc;
342 void qemu_system_powerdown(void)
344 slavio_set_power_fail(slavio_misc, 1);
347 static void main_cpu_reset(void *opaque)
349 CPUState *env = opaque;
355 static void secondary_cpu_reset(void *opaque)
357 CPUState *env = opaque;
363 static void cpu_halt_signal(void *opaque, int irq, int level)
365 if (level && cpu_single_env)
366 cpu_interrupt(cpu_single_env, CPU_INTERRUPT_HALT);
369 static unsigned long sun4m_load_kernel(const char *kernel_filename,
370 const char *initrd_filename,
375 long initrd_size, kernel_size;
377 linux_boot = (kernel_filename != NULL);
381 kernel_size = load_elf(kernel_filename, -0xf0000000ULL, NULL, NULL,
384 kernel_size = load_aout(kernel_filename, KERNEL_LOAD_ADDR,
385 RAM_size - KERNEL_LOAD_ADDR);
387 kernel_size = load_image_targphys(kernel_filename,
389 RAM_size - KERNEL_LOAD_ADDR);
390 if (kernel_size < 0) {
391 fprintf(stderr, "qemu: could not load kernel '%s'\n",
398 if (initrd_filename) {
399 initrd_size = load_image_targphys(initrd_filename,
401 RAM_size - INITRD_LOAD_ADDR);
402 if (initrd_size < 0) {
403 fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
408 if (initrd_size > 0) {
409 for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) {
410 if (ldl_phys(KERNEL_LOAD_ADDR + i) == 0x48647253) { // HdrS
411 stl_phys(KERNEL_LOAD_ADDR + i + 16, INITRD_LOAD_ADDR);
412 stl_phys(KERNEL_LOAD_ADDR + i + 20, initrd_size);
421 static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
422 const char *boot_device,
423 DisplayState *ds, const char *kernel_filename,
424 const char *kernel_cmdline,
425 const char *initrd_filename, const char *cpu_model)
428 CPUState *env, *envs[MAX_CPUS];
430 void *iommu, *espdma, *ledma, *main_esp, *nvram;
431 qemu_irq *cpu_irqs[MAX_CPUS], *slavio_irq, *slavio_cpu_irq,
432 *espdma_irq, *ledma_irq;
433 qemu_irq *esp_reset, *le_reset;
436 unsigned long prom_offset, kernel_size;
439 BlockDriverState *fd[MAX_FD];
445 cpu_model = hwdef->default_cpu_model;
447 for(i = 0; i < smp_cpus; i++) {
448 env = cpu_init(cpu_model);
450 fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
453 cpu_sparc_set_id(env, i);
456 qemu_register_reset(main_cpu_reset, env);
458 qemu_register_reset(secondary_cpu_reset, env);
461 cpu_irqs[i] = qemu_allocate_irqs(cpu_set_irq, envs[i], MAX_PILS);
462 env->prom_addr = hwdef->slavio_base;
465 for (i = smp_cpus; i < MAX_CPUS; i++)
466 cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS);
470 if ((uint64_t)RAM_size > hwdef->max_mem) {
472 "qemu: Too much memory for this machine: %d, maximum %d\n",
473 (unsigned int)(RAM_size / (1024 * 1024)),
474 (unsigned int)(hwdef->max_mem / (1024 * 1024)));
477 cpu_register_physical_memory(0, RAM_size, 0);
480 prom_offset = RAM_size + hwdef->vram_size;
481 cpu_register_physical_memory(hwdef->slavio_base,
482 (PROM_SIZE_MAX + TARGET_PAGE_SIZE - 1) &
484 prom_offset | IO_MEM_ROM);
486 if (bios_name == NULL)
487 bios_name = PROM_FILENAME;
488 snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
489 ret = load_elf(buf, hwdef->slavio_base - PROM_VADDR, NULL, NULL, NULL);
490 if (ret < 0 || ret > PROM_SIZE_MAX)
491 ret = load_image_targphys(buf, hwdef->slavio_base, PROM_SIZE_MAX);
492 if (ret < 0 || ret > PROM_SIZE_MAX) {
493 fprintf(stderr, "qemu: could not load prom '%s'\n",
497 prom_offset += (ret + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK;
500 slavio_intctl = slavio_intctl_init(hwdef->intctl_base,
501 hwdef->intctl_base + 0x10000ULL,
502 &hwdef->intbit_to_level[0],
503 &slavio_irq, &slavio_cpu_irq,
507 if (hwdef->idreg_base != (target_phys_addr_t)-1) {
508 static const uint8_t idreg_data[] = { 0xfe, 0x81, 0x01, 0x03 };
510 cpu_register_physical_memory(hwdef->idreg_base, sizeof(idreg_data),
511 prom_offset | IO_MEM_ROM);
512 cpu_physical_memory_write_rom(hwdef->idreg_base, idreg_data,
516 iommu = iommu_init(hwdef->iommu_base, hwdef->iommu_version,
517 slavio_irq[hwdef->me_irq]);
519 espdma = sparc32_dma_init(hwdef->dma_base, slavio_irq[hwdef->esp_irq],
520 iommu, &espdma_irq, &esp_reset);
522 ledma = sparc32_dma_init(hwdef->dma_base + 16ULL,
523 slavio_irq[hwdef->le_irq], iommu, &ledma_irq,
526 if (graphic_depth != 8 && graphic_depth != 24) {
527 fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
530 tcx_init(ds, hwdef->tcx_base, phys_ram_base + RAM_size, RAM_size,
531 hwdef->vram_size, graphic_width, graphic_height, graphic_depth);
533 if (nd_table[0].model == NULL
534 || strcmp(nd_table[0].model, "lance") == 0) {
535 lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);
536 } else if (strcmp(nd_table[0].model, "?") == 0) {
537 fprintf(stderr, "qemu: Supported NICs: lance\n");
540 fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd_table[0].model);
544 nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0,
545 hwdef->nvram_size, 8);
547 slavio_timer_init_all(hwdef->counter_base, slavio_irq[hwdef->clock1_irq],
548 slavio_cpu_irq, smp_cpus);
550 slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[hwdef->ms_kb_irq],
552 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
553 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
554 slavio_serial_init(hwdef->serial_base, slavio_irq[hwdef->ser_irq],
555 serial_hds[1], serial_hds[0]);
557 cpu_halt = qemu_allocate_irqs(cpu_halt_signal, NULL, 1);
558 slavio_misc = slavio_misc_init(hwdef->slavio_base, hwdef->apc_base,
559 hwdef->aux1_base, hwdef->aux2_base,
560 slavio_irq[hwdef->me_irq], cpu_halt[0],
563 if (hwdef->fd_base != (target_phys_addr_t)-1) {
564 /* there is zero or one floppy drive */
565 memset(fd, 0, sizeof(fd));
566 drive_index = drive_get_index(IF_FLOPPY, 0, 0);
567 if (drive_index != -1)
568 fd[0] = drives_table[drive_index].bdrv;
570 sun4m_fdctrl_init(slavio_irq[hwdef->fd_irq], hwdef->fd_base, fd,
574 if (drive_get_max_bus(IF_SCSI) > 0) {
575 fprintf(stderr, "qemu: too many SCSI bus\n");
579 main_esp = esp_init(hwdef->esp_base, 2,
580 espdma_memory_read, espdma_memory_write,
581 espdma, *espdma_irq, esp_reset);
583 for (i = 0; i < ESP_MAX_DEVS; i++) {
584 drive_index = drive_get_index(IF_SCSI, 0, i);
585 if (drive_index == -1)
587 esp_scsi_attach(main_esp, drives_table[drive_index].bdrv, i);
590 if (hwdef->cs_base != (target_phys_addr_t)-1)
591 cs_init(hwdef->cs_base, hwdef->cs_irq, slavio_intctl);
593 kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
596 nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
597 boot_device, RAM_size, kernel_size, graphic_width,
598 graphic_height, graphic_depth, hwdef->nvram_machine_id,
601 if (hwdef->ecc_base != (target_phys_addr_t)-1)
602 ecc_init(hwdef->ecc_base, slavio_irq[hwdef->ecc_irq],
605 fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
606 fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
607 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
608 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
609 fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
627 static const struct sun4m_hwdef sun4m_hwdefs[] = {
630 .iommu_base = 0x10000000,
631 .tcx_base = 0x50000000,
632 .cs_base = 0x6c000000,
633 .slavio_base = 0x70000000,
634 .ms_kb_base = 0x71000000,
635 .serial_base = 0x71100000,
636 .nvram_base = 0x71200000,
637 .fd_base = 0x71400000,
638 .counter_base = 0x71d00000,
639 .intctl_base = 0x71e00000,
640 .idreg_base = 0x78000000,
641 .dma_base = 0x78400000,
642 .esp_base = 0x78800000,
643 .le_base = 0x78c00000,
644 .apc_base = 0x6a000000,
645 .aux1_base = 0x71900000,
646 .aux2_base = 0x71910000,
648 .vram_size = 0x00100000,
649 .nvram_size = 0x2000,
659 .nvram_machine_id = 0x80,
660 .machine_id = ss5_id,
661 .iommu_version = 0x05000000,
663 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
664 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
666 .max_mem = 0x10000000,
667 .default_cpu_model = "Fujitsu MB86904",
671 .iommu_base = 0xfe0000000ULL,
672 .tcx_base = 0xe20000000ULL,
674 .slavio_base = 0xff0000000ULL,
675 .ms_kb_base = 0xff1000000ULL,
676 .serial_base = 0xff1100000ULL,
677 .nvram_base = 0xff1200000ULL,
678 .fd_base = 0xff1700000ULL,
679 .counter_base = 0xff1300000ULL,
680 .intctl_base = 0xff1400000ULL,
681 .idreg_base = 0xef0000000ULL,
682 .dma_base = 0xef0400000ULL,
683 .esp_base = 0xef0800000ULL,
684 .le_base = 0xef0c00000ULL,
685 .apc_base = 0xefa000000ULL, // XXX should not exist
686 .aux1_base = 0xff1800000ULL,
687 .aux2_base = 0xff1a01000ULL,
688 .ecc_base = 0xf00000000ULL,
689 .ecc_version = 0x10000000, // version 0, implementation 1
690 .vram_size = 0x00100000,
691 .nvram_size = 0x2000,
702 .nvram_machine_id = 0x72,
703 .machine_id = ss10_id,
704 .iommu_version = 0x03000000,
706 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
707 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
709 .max_mem = 0xf00000000ULL,
710 .default_cpu_model = "TI SuperSparc II",
714 .iommu_base = 0xfe0000000ULL,
715 .tcx_base = 0xe20000000ULL,
717 .slavio_base = 0xff0000000ULL,
718 .ms_kb_base = 0xff1000000ULL,
719 .serial_base = 0xff1100000ULL,
720 .nvram_base = 0xff1200000ULL,
722 .counter_base = 0xff1300000ULL,
723 .intctl_base = 0xff1400000ULL,
725 .dma_base = 0xef0081000ULL,
726 .esp_base = 0xef0080000ULL,
727 .le_base = 0xef0060000ULL,
728 .apc_base = 0xefa000000ULL, // XXX should not exist
729 .aux1_base = 0xff1800000ULL,
730 .aux2_base = 0xff1a01000ULL, // XXX should not exist
731 .ecc_base = 0xf00000000ULL,
732 .ecc_version = 0x00000000, // version 0, implementation 0
733 .vram_size = 0x00100000,
734 .nvram_size = 0x2000,
745 .nvram_machine_id = 0x71,
746 .machine_id = ss600mp_id,
747 .iommu_version = 0x01000000,
749 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
750 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
752 .max_mem = 0xf00000000ULL,
753 .default_cpu_model = "TI SuperSparc II",
757 .iommu_base = 0xfe0000000ULL,
758 .tcx_base = 0xe20000000ULL,
760 .slavio_base = 0xff0000000ULL,
761 .ms_kb_base = 0xff1000000ULL,
762 .serial_base = 0xff1100000ULL,
763 .nvram_base = 0xff1200000ULL,
764 .fd_base = 0xff1700000ULL,
765 .counter_base = 0xff1300000ULL,
766 .intctl_base = 0xff1400000ULL,
767 .idreg_base = 0xef0000000ULL,
768 .dma_base = 0xef0400000ULL,
769 .esp_base = 0xef0800000ULL,
770 .le_base = 0xef0c00000ULL,
771 .apc_base = 0xefa000000ULL, // XXX should not exist
772 .aux1_base = 0xff1800000ULL,
773 .aux2_base = 0xff1a01000ULL,
774 .ecc_base = 0xf00000000ULL,
775 .ecc_version = 0x20000000, // version 0, implementation 2
776 .vram_size = 0x00100000,
777 .nvram_size = 0x2000,
788 .nvram_machine_id = 0x72,
789 .machine_id = ss20_id,
790 .iommu_version = 0x13000000,
792 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
793 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
795 .max_mem = 0xf00000000ULL,
796 .default_cpu_model = "TI SuperSparc II",
800 .iommu_base = 0x10000000,
801 .tcx_base = 0x50000000,
803 .slavio_base = 0x70000000,
804 .ms_kb_base = 0x71000000,
805 .serial_base = 0x71100000,
806 .nvram_base = 0x71200000,
807 .fd_base = 0x71400000,
808 .counter_base = 0x71d00000,
809 .intctl_base = 0x71e00000,
810 .idreg_base = 0x78000000,
811 .dma_base = 0x78400000,
812 .esp_base = 0x78800000,
813 .le_base = 0x78c00000,
814 .apc_base = 0x71300000, // pmc
815 .aux1_base = 0x71900000,
816 .aux2_base = 0x71910000,
818 .vram_size = 0x00100000,
819 .nvram_size = 0x2000,
829 .nvram_machine_id = 0x80,
830 .machine_id = vger_id,
831 .iommu_version = 0x05000000,
833 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
834 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
836 .max_mem = 0x10000000,
837 .default_cpu_model = "Fujitsu MB86904",
841 .iommu_base = 0x10000000,
842 .tcx_base = 0x50000000,
844 .slavio_base = 0x70000000,
845 .ms_kb_base = 0x71000000,
846 .serial_base = 0x71100000,
847 .nvram_base = 0x71200000,
848 .fd_base = 0x71400000,
849 .counter_base = 0x71d00000,
850 .intctl_base = 0x71e00000,
851 .idreg_base = 0x78000000,
852 .dma_base = 0x78400000,
853 .esp_base = 0x78800000,
854 .le_base = 0x78c00000,
856 .aux1_base = 0x71900000,
857 .aux2_base = 0x71910000,
859 .vram_size = 0x00100000,
860 .nvram_size = 0x2000,
870 .nvram_machine_id = 0x80,
872 .iommu_version = 0x04000000,
874 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
875 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
877 .max_mem = 0x10000000,
878 .default_cpu_model = "TI MicroSparc I",
882 .iommu_base = 0x10000000,
883 .tcx_base = 0x50000000,
884 .cs_base = 0x6c000000,
885 .slavio_base = 0x70000000,
886 .ms_kb_base = 0x71000000,
887 .serial_base = 0x71100000,
888 .nvram_base = 0x71200000,
889 .fd_base = 0x71400000,
890 .counter_base = 0x71d00000,
891 .intctl_base = 0x71e00000,
892 .idreg_base = 0x78000000,
893 .dma_base = 0x78400000,
894 .esp_base = 0x78800000,
895 .le_base = 0x78c00000,
896 .apc_base = 0x6a000000,
897 .aux1_base = 0x71900000,
898 .aux2_base = 0x71910000,
900 .vram_size = 0x00100000,
901 .nvram_size = 0x2000,
911 .nvram_machine_id = 0x80,
912 .machine_id = ss4_id,
913 .iommu_version = 0x05000000,
915 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
916 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
918 .max_mem = 0x10000000,
919 .default_cpu_model = "Fujitsu MB86904",
923 .iommu_base = 0x10000000,
924 .tcx_base = 0x50000000,
926 .slavio_base = 0x70000000,
927 .ms_kb_base = 0x71000000,
928 .serial_base = 0x71100000,
929 .nvram_base = 0x71200000,
930 .fd_base = 0x71400000,
931 .counter_base = 0x71d00000,
932 .intctl_base = 0x71e00000,
933 .idreg_base = 0x78000000,
934 .dma_base = 0x78400000,
935 .esp_base = 0x78800000,
936 .le_base = 0x78c00000,
937 .apc_base = 0x6a000000,
938 .aux1_base = 0x71900000,
939 .aux2_base = 0x71910000,
941 .vram_size = 0x00100000,
942 .nvram_size = 0x2000,
952 .nvram_machine_id = 0x80,
953 .machine_id = scls_id,
954 .iommu_version = 0x05000000,
956 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
957 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
959 .max_mem = 0x10000000,
960 .default_cpu_model = "TI MicroSparc I",
964 .iommu_base = 0x10000000,
965 .tcx_base = 0x50000000, // XXX
967 .slavio_base = 0x70000000,
968 .ms_kb_base = 0x71000000,
969 .serial_base = 0x71100000,
970 .nvram_base = 0x71200000,
971 .fd_base = 0x71400000,
972 .counter_base = 0x71d00000,
973 .intctl_base = 0x71e00000,
974 .idreg_base = 0x78000000,
975 .dma_base = 0x78400000,
976 .esp_base = 0x78800000,
977 .le_base = 0x78c00000,
978 .apc_base = 0x6a000000,
979 .aux1_base = 0x71900000,
980 .aux2_base = 0x71910000,
982 .vram_size = 0x00100000,
983 .nvram_size = 0x2000,
993 .nvram_machine_id = 0x80,
994 .machine_id = sbook_id,
995 .iommu_version = 0x05000000,
997 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
998 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
1000 .max_mem = 0x10000000,
1001 .default_cpu_model = "TI MicroSparc I",
1005 /* SPARCstation 5 hardware initialisation */
1006 static void ss5_init(ram_addr_t RAM_size, int vga_ram_size,
1007 const char *boot_device, DisplayState *ds,
1008 const char *kernel_filename, const char *kernel_cmdline,
1009 const char *initrd_filename, const char *cpu_model)
1011 sun4m_hw_init(&sun4m_hwdefs[0], RAM_size, boot_device, ds, kernel_filename,
1012 kernel_cmdline, initrd_filename, cpu_model);
1015 /* SPARCstation 10 hardware initialisation */
1016 static void ss10_init(ram_addr_t RAM_size, int vga_ram_size,
1017 const char *boot_device, DisplayState *ds,
1018 const char *kernel_filename, const char *kernel_cmdline,
1019 const char *initrd_filename, const char *cpu_model)
1021 sun4m_hw_init(&sun4m_hwdefs[1], RAM_size, boot_device, ds, kernel_filename,
1022 kernel_cmdline, initrd_filename, cpu_model);
1025 /* SPARCserver 600MP hardware initialisation */
1026 static void ss600mp_init(ram_addr_t RAM_size, int vga_ram_size,
1027 const char *boot_device, DisplayState *ds,
1028 const char *kernel_filename,
1029 const char *kernel_cmdline,
1030 const char *initrd_filename, const char *cpu_model)
1032 sun4m_hw_init(&sun4m_hwdefs[2], RAM_size, boot_device, ds, kernel_filename,
1033 kernel_cmdline, initrd_filename, cpu_model);
1036 /* SPARCstation 20 hardware initialisation */
1037 static void ss20_init(ram_addr_t RAM_size, int vga_ram_size,
1038 const char *boot_device, DisplayState *ds,
1039 const char *kernel_filename, const char *kernel_cmdline,
1040 const char *initrd_filename, const char *cpu_model)
1042 sun4m_hw_init(&sun4m_hwdefs[3], RAM_size, boot_device, ds, kernel_filename,
1043 kernel_cmdline, initrd_filename, cpu_model);
1046 /* SPARCstation Voyager hardware initialisation */
1047 static void vger_init(ram_addr_t RAM_size, int vga_ram_size,
1048 const char *boot_device, DisplayState *ds,
1049 const char *kernel_filename, const char *kernel_cmdline,
1050 const char *initrd_filename, const char *cpu_model)
1052 sun4m_hw_init(&sun4m_hwdefs[4], RAM_size, boot_device, ds, kernel_filename,
1053 kernel_cmdline, initrd_filename, cpu_model);
1056 /* SPARCstation LX hardware initialisation */
1057 static void ss_lx_init(ram_addr_t RAM_size, int vga_ram_size,
1058 const char *boot_device, DisplayState *ds,
1059 const char *kernel_filename, const char *kernel_cmdline,
1060 const char *initrd_filename, const char *cpu_model)
1062 sun4m_hw_init(&sun4m_hwdefs[5], RAM_size, boot_device, ds, kernel_filename,
1063 kernel_cmdline, initrd_filename, cpu_model);
1066 /* SPARCstation 4 hardware initialisation */
1067 static void ss4_init(ram_addr_t RAM_size, int vga_ram_size,
1068 const char *boot_device, DisplayState *ds,
1069 const char *kernel_filename, const char *kernel_cmdline,
1070 const char *initrd_filename, const char *cpu_model)
1072 sun4m_hw_init(&sun4m_hwdefs[6], RAM_size, boot_device, ds, kernel_filename,
1073 kernel_cmdline, initrd_filename, cpu_model);
1076 /* SPARCClassic hardware initialisation */
1077 static void scls_init(ram_addr_t RAM_size, int vga_ram_size,
1078 const char *boot_device, DisplayState *ds,
1079 const char *kernel_filename, const char *kernel_cmdline,
1080 const char *initrd_filename, const char *cpu_model)
1082 sun4m_hw_init(&sun4m_hwdefs[7], RAM_size, boot_device, ds, kernel_filename,
1083 kernel_cmdline, initrd_filename, cpu_model);
1086 /* SPARCbook hardware initialisation */
1087 static void sbook_init(ram_addr_t RAM_size, int vga_ram_size,
1088 const char *boot_device, DisplayState *ds,
1089 const char *kernel_filename, const char *kernel_cmdline,
1090 const char *initrd_filename, const char *cpu_model)
1092 sun4m_hw_init(&sun4m_hwdefs[8], RAM_size, boot_device, ds, kernel_filename,
1093 kernel_cmdline, initrd_filename, cpu_model);
1096 QEMUMachine ss5_machine = {
1098 .desc = "Sun4m platform, SPARCstation 5",
1100 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1106 QEMUMachine ss10_machine = {
1108 .desc = "Sun4m platform, SPARCstation 10",
1110 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1116 QEMUMachine ss600mp_machine = {
1118 .desc = "Sun4m platform, SPARCserver 600MP",
1119 .init = ss600mp_init,
1120 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1126 QEMUMachine ss20_machine = {
1128 .desc = "Sun4m platform, SPARCstation 20",
1130 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1136 QEMUMachine voyager_machine = {
1138 .desc = "Sun4m platform, SPARCstation Voyager",
1140 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1146 QEMUMachine ss_lx_machine = {
1148 .desc = "Sun4m platform, SPARCstation LX",
1150 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1156 QEMUMachine ss4_machine = {
1158 .desc = "Sun4m platform, SPARCstation 4",
1160 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1166 QEMUMachine scls_machine = {
1167 .name = "SPARCClassic",
1168 .desc = "Sun4m platform, SPARCClassic",
1170 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1176 QEMUMachine sbook_machine = {
1177 .name = "SPARCbook",
1178 .desc = "Sun4m platform, SPARCbook",
1180 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1186 static const struct sun4d_hwdef sun4d_hwdefs[] = {
1196 .tcx_base = 0x820000000ULL,
1197 .slavio_base = 0xf00000000ULL,
1198 .ms_kb_base = 0xf00240000ULL,
1199 .serial_base = 0xf00200000ULL,
1200 .nvram_base = 0xf00280000ULL,
1201 .counter_base = 0xf00300000ULL,
1202 .espdma_base = 0x800081000ULL,
1203 .esp_base = 0x800080000ULL,
1204 .ledma_base = 0x800040000ULL,
1205 .le_base = 0x800060000ULL,
1206 .sbi_base = 0xf02800000ULL,
1207 .vram_size = 0x00100000,
1208 .nvram_size = 0x2000,
1215 .nvram_machine_id = 0x80,
1216 .machine_id = ss1000_id,
1217 .iounit_version = 0x03000000,
1218 .max_mem = 0xf00000000ULL,
1219 .default_cpu_model = "TI SuperSparc II",
1230 .tcx_base = 0x820000000ULL,
1231 .slavio_base = 0xf00000000ULL,
1232 .ms_kb_base = 0xf00240000ULL,
1233 .serial_base = 0xf00200000ULL,
1234 .nvram_base = 0xf00280000ULL,
1235 .counter_base = 0xf00300000ULL,
1236 .espdma_base = 0x800081000ULL,
1237 .esp_base = 0x800080000ULL,
1238 .ledma_base = 0x800040000ULL,
1239 .le_base = 0x800060000ULL,
1240 .sbi_base = 0xf02800000ULL,
1241 .vram_size = 0x00100000,
1242 .nvram_size = 0x2000,
1249 .nvram_machine_id = 0x80,
1250 .machine_id = ss2000_id,
1251 .iounit_version = 0x03000000,
1252 .max_mem = 0xf00000000ULL,
1253 .default_cpu_model = "TI SuperSparc II",
1257 static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,
1258 const char *boot_device,
1259 DisplayState *ds, const char *kernel_filename,
1260 const char *kernel_cmdline,
1261 const char *initrd_filename, const char *cpu_model)
1263 CPUState *env, *envs[MAX_CPUS];
1265 void *iounits[MAX_IOUNITS], *espdma, *ledma, *main_esp, *nvram, *sbi;
1266 qemu_irq *cpu_irqs[MAX_CPUS], *sbi_irq, *sbi_cpu_irq,
1267 *espdma_irq, *ledma_irq;
1268 qemu_irq *esp_reset, *le_reset;
1269 unsigned long prom_offset, kernel_size;
1277 cpu_model = hwdef->default_cpu_model;
1279 for (i = 0; i < smp_cpus; i++) {
1280 env = cpu_init(cpu_model);
1282 fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
1285 cpu_sparc_set_id(env, i);
1288 qemu_register_reset(main_cpu_reset, env);
1290 qemu_register_reset(secondary_cpu_reset, env);
1293 cpu_irqs[i] = qemu_allocate_irqs(cpu_set_irq, envs[i], MAX_PILS);
1294 env->prom_addr = hwdef->slavio_base;
1297 for (i = smp_cpus; i < MAX_CPUS; i++)
1298 cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS);
1301 if ((uint64_t)RAM_size > hwdef->max_mem) {
1303 "qemu: Too much memory for this machine: %d, maximum %d\n",
1304 (unsigned int)(RAM_size / (1024 * 1024)),
1305 (unsigned int)(hwdef->max_mem / (1024 * 1024)));
1308 cpu_register_physical_memory(0, RAM_size, 0);
1310 /* load boot prom */
1311 prom_offset = RAM_size + hwdef->vram_size;
1312 cpu_register_physical_memory(hwdef->slavio_base,
1313 (PROM_SIZE_MAX + TARGET_PAGE_SIZE - 1) &
1315 prom_offset | IO_MEM_ROM);
1317 if (bios_name == NULL)
1318 bios_name = PROM_FILENAME;
1319 snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
1320 ret = load_elf(buf, hwdef->slavio_base - PROM_VADDR, NULL, NULL, NULL);
1321 if (ret < 0 || ret > PROM_SIZE_MAX)
1322 ret = load_image_targphys(buf, hwdef->slavio_base, PROM_SIZE_MAX);
1323 if (ret < 0 || ret > PROM_SIZE_MAX) {
1324 fprintf(stderr, "qemu: could not load prom '%s'\n",
1329 /* set up devices */
1330 sbi = sbi_init(hwdef->sbi_base, &sbi_irq, &sbi_cpu_irq, cpu_irqs);
1332 for (i = 0; i < MAX_IOUNITS; i++)
1333 if (hwdef->iounit_bases[i] != (target_phys_addr_t)-1)
1334 iounits[i] = iommu_init(hwdef->iounit_bases[i],
1335 hwdef->iounit_version,
1336 sbi_irq[hwdef->me_irq]);
1338 espdma = sparc32_dma_init(hwdef->espdma_base, sbi_irq[hwdef->esp_irq],
1339 iounits[0], &espdma_irq, &esp_reset);
1341 ledma = sparc32_dma_init(hwdef->ledma_base, sbi_irq[hwdef->le_irq],
1342 iounits[0], &ledma_irq, &le_reset);
1344 if (graphic_depth != 8 && graphic_depth != 24) {
1345 fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
1348 tcx_init(ds, hwdef->tcx_base, phys_ram_base + RAM_size, RAM_size,
1349 hwdef->vram_size, graphic_width, graphic_height, graphic_depth);
1351 if (nd_table[0].model == NULL
1352 || strcmp(nd_table[0].model, "lance") == 0) {
1353 lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);
1354 } else if (strcmp(nd_table[0].model, "?") == 0) {
1355 fprintf(stderr, "qemu: Supported NICs: lance\n");
1358 fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd_table[0].model);
1362 nvram = m48t59_init(sbi_irq[0], hwdef->nvram_base, 0,
1363 hwdef->nvram_size, 8);
1365 slavio_timer_init_all(hwdef->counter_base, sbi_irq[hwdef->clock1_irq],
1366 sbi_cpu_irq, smp_cpus);
1368 slavio_serial_ms_kbd_init(hwdef->ms_kb_base, sbi_irq[hwdef->ms_kb_irq],
1370 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
1371 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
1372 slavio_serial_init(hwdef->serial_base, sbi_irq[hwdef->ser_irq],
1373 serial_hds[1], serial_hds[0]);
1375 if (drive_get_max_bus(IF_SCSI) > 0) {
1376 fprintf(stderr, "qemu: too many SCSI bus\n");
1380 main_esp = esp_init(hwdef->esp_base, 2,
1381 espdma_memory_read, espdma_memory_write,
1382 espdma, *espdma_irq, esp_reset);
1384 for (i = 0; i < ESP_MAX_DEVS; i++) {
1385 drive_index = drive_get_index(IF_SCSI, 0, i);
1386 if (drive_index == -1)
1388 esp_scsi_attach(main_esp, drives_table[drive_index].bdrv, i);
1391 kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
1394 nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
1395 boot_device, RAM_size, kernel_size, graphic_width,
1396 graphic_height, graphic_depth, hwdef->nvram_machine_id,
1399 fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
1400 fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
1401 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
1402 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
1405 /* SPARCserver 1000 hardware initialisation */
1406 static void ss1000_init(ram_addr_t RAM_size, int vga_ram_size,
1407 const char *boot_device, DisplayState *ds,
1408 const char *kernel_filename, const char *kernel_cmdline,
1409 const char *initrd_filename, const char *cpu_model)
1411 sun4d_hw_init(&sun4d_hwdefs[0], RAM_size, boot_device, ds, kernel_filename,
1412 kernel_cmdline, initrd_filename, cpu_model);
1415 /* SPARCcenter 2000 hardware initialisation */
1416 static void ss2000_init(ram_addr_t RAM_size, int vga_ram_size,
1417 const char *boot_device, DisplayState *ds,
1418 const char *kernel_filename, const char *kernel_cmdline,
1419 const char *initrd_filename, const char *cpu_model)
1421 sun4d_hw_init(&sun4d_hwdefs[1], RAM_size, boot_device, ds, kernel_filename,
1422 kernel_cmdline, initrd_filename, cpu_model);
1425 QEMUMachine ss1000_machine = {
1427 .desc = "Sun4d platform, SPARCserver 1000",
1428 .init = ss1000_init,
1429 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1435 QEMUMachine ss2000_machine = {
1437 .desc = "Sun4d platform, SPARCcenter 2000",
1438 .init = ss2000_init,
1439 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1445 static const struct sun4c_hwdef sun4c_hwdefs[] = {
1448 .iommu_base = 0xf8000000,
1449 .tcx_base = 0xfe000000,
1450 .slavio_base = 0xf6000000,
1451 .intctl_base = 0xf5000000,
1452 .counter_base = 0xf3000000,
1453 .ms_kb_base = 0xf0000000,
1454 .serial_base = 0xf1000000,
1455 .nvram_base = 0xf2000000,
1456 .fd_base = 0xf7200000,
1457 .dma_base = 0xf8400000,
1458 .esp_base = 0xf8800000,
1459 .le_base = 0xf8c00000,
1460 .aux1_base = 0xf7400003,
1461 .vram_size = 0x00100000,
1462 .nvram_size = 0x800,
1471 .nvram_machine_id = 0x55,
1472 .machine_id = ss2_id,
1473 .max_mem = 0x10000000,
1474 .default_cpu_model = "Cypress CY7C601",
1478 static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,
1479 const char *boot_device,
1480 DisplayState *ds, const char *kernel_filename,
1481 const char *kernel_cmdline,
1482 const char *initrd_filename, const char *cpu_model)
1486 void *iommu, *espdma, *ledma, *main_esp, *nvram;
1487 qemu_irq *cpu_irqs, *slavio_irq, *espdma_irq, *ledma_irq;
1488 qemu_irq *esp_reset, *le_reset;
1490 unsigned long prom_offset, kernel_size;
1493 BlockDriverState *fd[MAX_FD];
1499 cpu_model = hwdef->default_cpu_model;
1501 env = cpu_init(cpu_model);
1503 fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
1507 cpu_sparc_set_id(env, 0);
1509 qemu_register_reset(main_cpu_reset, env);
1510 cpu_irqs = qemu_allocate_irqs(cpu_set_irq, env, MAX_PILS);
1511 env->prom_addr = hwdef->slavio_base;
1514 if ((uint64_t)RAM_size > hwdef->max_mem) {
1516 "qemu: Too much memory for this machine: %d, maximum %d\n",
1517 (unsigned int)(RAM_size / (1024 * 1024)),
1518 (unsigned int)(hwdef->max_mem / (1024 * 1024)));
1521 cpu_register_physical_memory(0, RAM_size, 0);
1523 /* load boot prom */
1524 prom_offset = RAM_size + hwdef->vram_size;
1525 cpu_register_physical_memory(hwdef->slavio_base,
1526 (PROM_SIZE_MAX + TARGET_PAGE_SIZE - 1) &
1528 prom_offset | IO_MEM_ROM);
1530 if (bios_name == NULL)
1531 bios_name = PROM_FILENAME;
1532 snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
1533 ret = load_elf(buf, hwdef->slavio_base - PROM_VADDR, NULL, NULL, NULL);
1534 if (ret < 0 || ret > PROM_SIZE_MAX)
1535 ret = load_image_targphys(buf, hwdef->slavio_base, PROM_SIZE_MAX);
1536 if (ret < 0 || ret > PROM_SIZE_MAX) {
1537 fprintf(stderr, "qemu: could not load prom '%s'\n",
1541 prom_offset += (ret + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK;
1543 /* set up devices */
1544 slavio_intctl = sun4c_intctl_init(hwdef->intctl_base,
1545 &slavio_irq, cpu_irqs);
1547 iommu = iommu_init(hwdef->iommu_base, hwdef->iommu_version,
1548 slavio_irq[hwdef->me_irq]);
1550 espdma = sparc32_dma_init(hwdef->dma_base, slavio_irq[hwdef->esp_irq],
1551 iommu, &espdma_irq, &esp_reset);
1553 ledma = sparc32_dma_init(hwdef->dma_base + 16ULL,
1554 slavio_irq[hwdef->le_irq], iommu, &ledma_irq,
1557 if (graphic_depth != 8 && graphic_depth != 24) {
1558 fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
1561 tcx_init(ds, hwdef->tcx_base, phys_ram_base + RAM_size, RAM_size,
1562 hwdef->vram_size, graphic_width, graphic_height, graphic_depth);
1564 if (nd_table[0].model == NULL
1565 || strcmp(nd_table[0].model, "lance") == 0) {
1566 lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);
1567 } else if (strcmp(nd_table[0].model, "?") == 0) {
1568 fprintf(stderr, "qemu: Supported NICs: lance\n");
1571 fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd_table[0].model);
1575 nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0,
1576 hwdef->nvram_size, 2);
1578 slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[hwdef->ms_kb_irq],
1580 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
1581 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
1582 slavio_serial_init(hwdef->serial_base, slavio_irq[hwdef->ser_irq],
1583 serial_hds[1], serial_hds[0]);
1585 slavio_misc = slavio_misc_init(0, -1, hwdef->aux1_base, -1,
1586 slavio_irq[hwdef->me_irq], NULL, &fdc_tc);
1588 if (hwdef->fd_base != (target_phys_addr_t)-1) {
1589 /* there is zero or one floppy drive */
1590 fd[1] = fd[0] = NULL;
1591 drive_index = drive_get_index(IF_FLOPPY, 0, 0);
1592 if (drive_index != -1)
1593 fd[0] = drives_table[drive_index].bdrv;
1595 sun4m_fdctrl_init(slavio_irq[hwdef->fd_irq], hwdef->fd_base, fd,
1599 if (drive_get_max_bus(IF_SCSI) > 0) {
1600 fprintf(stderr, "qemu: too many SCSI bus\n");
1604 main_esp = esp_init(hwdef->esp_base, 2,
1605 espdma_memory_read, espdma_memory_write,
1606 espdma, *espdma_irq, esp_reset);
1608 for (i = 0; i < ESP_MAX_DEVS; i++) {
1609 drive_index = drive_get_index(IF_SCSI, 0, i);
1610 if (drive_index == -1)
1612 esp_scsi_attach(main_esp, drives_table[drive_index].bdrv, i);
1615 kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
1618 nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
1619 boot_device, RAM_size, kernel_size, graphic_width,
1620 graphic_height, graphic_depth, hwdef->nvram_machine_id,
1623 fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
1624 fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
1625 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
1626 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
1629 /* SPARCstation 2 hardware initialisation */
1630 static void ss2_init(ram_addr_t RAM_size, int vga_ram_size,
1631 const char *boot_device, DisplayState *ds,
1632 const char *kernel_filename, const char *kernel_cmdline,
1633 const char *initrd_filename, const char *cpu_model)
1635 sun4c_hw_init(&sun4c_hwdefs[0], RAM_size, boot_device, ds, kernel_filename,
1636 kernel_cmdline, initrd_filename, cpu_model);
1639 QEMUMachine ss2_machine = {
1641 .desc = "Sun4c platform, SPARCstation 2",
1643 .ram_require = PROM_SIZE_MAX + TCX_SIZE,