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"
39 #include "qdev-addr.h"
44 * Sun4m architecture was used in the following machines:
46 * SPARCserver 6xxMP/xx
47 * SPARCclassic (SPARCclassic Server)(SPARCstation LC) (4/15),
48 * SPARCclassic X (4/10)
49 * SPARCstation LX/ZX (4/30)
50 * SPARCstation Voyager
51 * SPARCstation 10/xx, SPARCserver 10/xx
52 * SPARCstation 5, SPARCserver 5
53 * SPARCstation 20/xx, SPARCserver 20
56 * Sun4d architecture was used in the following machines:
61 * Sun4c architecture was used in the following machines:
62 * SPARCstation 1/1+, SPARCserver 1/1+
68 * See for example: http://www.sunhelp.org/faq/sunref1.html
72 #define DPRINTF(fmt, ...) \
73 do { printf("CPUIRQ: " fmt , ## __VA_ARGS__); } while (0)
75 #define DPRINTF(fmt, ...)
78 #define KERNEL_LOAD_ADDR 0x00004000
79 #define CMDLINE_ADDR 0x007ff000
80 #define INITRD_LOAD_ADDR 0x00800000
81 #define PROM_SIZE_MAX (1024 * 1024)
82 #define PROM_VADDR 0xffd00000
83 #define PROM_FILENAME "openbios-sparc32"
84 #define CFG_ADDR 0xd00000510ULL
85 #define FW_CFG_SUN4M_DEPTH (FW_CFG_ARCH_LOCAL + 0x00)
90 #define ESCC_CLOCK 4915200
93 target_phys_addr_t iommu_base
, slavio_base
;
94 target_phys_addr_t intctl_base
, counter_base
, nvram_base
, ms_kb_base
;
95 target_phys_addr_t serial_base
, fd_base
;
96 target_phys_addr_t idreg_base
, dma_base
, esp_base
, le_base
;
97 target_phys_addr_t tcx_base
, cs_base
, apc_base
, aux1_base
, aux2_base
;
98 target_phys_addr_t ecc_base
;
100 uint8_t nvram_machine_id
;
102 uint32_t iommu_version
;
104 const char * const default_cpu_model
;
107 #define MAX_IOUNITS 5
110 target_phys_addr_t iounit_bases
[MAX_IOUNITS
], slavio_base
;
111 target_phys_addr_t counter_base
, nvram_base
, ms_kb_base
;
112 target_phys_addr_t serial_base
;
113 target_phys_addr_t espdma_base
, esp_base
;
114 target_phys_addr_t ledma_base
, le_base
;
115 target_phys_addr_t tcx_base
;
116 target_phys_addr_t sbi_base
;
117 uint8_t nvram_machine_id
;
119 uint32_t iounit_version
;
121 const char * const default_cpu_model
;
125 target_phys_addr_t iommu_base
, slavio_base
;
126 target_phys_addr_t intctl_base
, counter_base
, nvram_base
, ms_kb_base
;
127 target_phys_addr_t serial_base
, fd_base
;
128 target_phys_addr_t idreg_base
, dma_base
, esp_base
, le_base
;
129 target_phys_addr_t tcx_base
, aux1_base
;
130 uint8_t nvram_machine_id
;
132 uint32_t iommu_version
;
134 const char * const default_cpu_model
;
137 int DMA_get_channel_mode (int nchan
)
141 int DMA_read_memory (int nchan
, void *buf
, int pos
, int size
)
145 int DMA_write_memory (int nchan
, void *buf
, int pos
, int size
)
149 void DMA_hold_DREQ (int nchan
) {}
150 void DMA_release_DREQ (int nchan
) {}
151 void DMA_schedule(int nchan
) {}
152 void DMA_init (int high_page_enable
) {}
153 void DMA_register_channel (int nchan
,
154 DMA_transfer_handler transfer_handler
,
159 static int fw_cfg_boot_set(void *opaque
, const char *boot_device
)
161 fw_cfg_add_i16(opaque
, FW_CFG_BOOT_DEVICE
, boot_device
[0]);
165 static void nvram_init(m48t59_t
*nvram
, uint8_t *macaddr
, const char *cmdline
,
166 const char *boot_devices
, ram_addr_t RAM_size
,
167 uint32_t kernel_size
,
168 int width
, int height
, int depth
,
169 int nvram_machine_id
, const char *arch
)
173 uint8_t image
[0x1ff0];
174 struct OpenBIOS_nvpart_v1
*part_header
;
176 memset(image
, '\0', sizeof(image
));
180 // OpenBIOS nvram variables
181 // Variable partition
182 part_header
= (struct OpenBIOS_nvpart_v1
*)&image
[start
];
183 part_header
->signature
= OPENBIOS_PART_SYSTEM
;
184 pstrcpy(part_header
->name
, sizeof(part_header
->name
), "system");
186 end
= start
+ sizeof(struct OpenBIOS_nvpart_v1
);
187 for (i
= 0; i
< nb_prom_envs
; i
++)
188 end
= OpenBIOS_set_var(image
, end
, prom_envs
[i
]);
193 end
= start
+ ((end
- start
+ 15) & ~15);
194 OpenBIOS_finish_partition(part_header
, end
- start
);
198 part_header
= (struct OpenBIOS_nvpart_v1
*)&image
[start
];
199 part_header
->signature
= OPENBIOS_PART_FREE
;
200 pstrcpy(part_header
->name
, sizeof(part_header
->name
), "free");
203 OpenBIOS_finish_partition(part_header
, end
- start
);
205 Sun_init_header((struct Sun_nvram
*)&image
[0x1fd8], macaddr
,
208 for (i
= 0; i
< sizeof(image
); i
++)
209 m48t59_write(nvram
, i
, image
[i
]);
212 static void *slavio_intctl
;
214 void pic_info(Monitor
*mon
)
217 slavio_pic_info(mon
, slavio_intctl
);
220 void irq_info(Monitor
*mon
)
223 slavio_irq_info(mon
, slavio_intctl
);
226 void cpu_check_irqs(CPUState
*env
)
228 if (env
->pil_in
&& (env
->interrupt_index
== 0 ||
229 (env
->interrupt_index
& ~15) == TT_EXTINT
)) {
232 for (i
= 15; i
> 0; i
--) {
233 if (env
->pil_in
& (1 << i
)) {
234 int old_interrupt
= env
->interrupt_index
;
236 env
->interrupt_index
= TT_EXTINT
| i
;
237 if (old_interrupt
!= env
->interrupt_index
) {
238 DPRINTF("Set CPU IRQ %d\n", i
);
239 cpu_interrupt(env
, CPU_INTERRUPT_HARD
);
244 } else if (!env
->pil_in
&& (env
->interrupt_index
& ~15) == TT_EXTINT
) {
245 DPRINTF("Reset CPU IRQ %d\n", env
->interrupt_index
& 15);
246 env
->interrupt_index
= 0;
247 cpu_reset_interrupt(env
, CPU_INTERRUPT_HARD
);
251 static void cpu_set_irq(void *opaque
, int irq
, int level
)
253 CPUState
*env
= opaque
;
256 DPRINTF("Raise CPU IRQ %d\n", irq
);
258 env
->pil_in
|= 1 << irq
;
261 DPRINTF("Lower CPU IRQ %d\n", irq
);
262 env
->pil_in
&= ~(1 << irq
);
267 static void dummy_cpu_set_irq(void *opaque
, int irq
, int level
)
271 static void main_cpu_reset(void *opaque
)
273 CPUState
*env
= opaque
;
279 static void secondary_cpu_reset(void *opaque
)
281 CPUState
*env
= opaque
;
287 static void cpu_halt_signal(void *opaque
, int irq
, int level
)
289 if (level
&& cpu_single_env
)
290 cpu_interrupt(cpu_single_env
, CPU_INTERRUPT_HALT
);
293 static unsigned long sun4m_load_kernel(const char *kernel_filename
,
294 const char *initrd_filename
,
299 long initrd_size
, kernel_size
;
301 linux_boot
= (kernel_filename
!= NULL
);
305 kernel_size
= load_elf(kernel_filename
, -0xf0000000ULL
, NULL
, NULL
,
308 kernel_size
= load_aout(kernel_filename
, KERNEL_LOAD_ADDR
,
309 RAM_size
- KERNEL_LOAD_ADDR
);
311 kernel_size
= load_image_targphys(kernel_filename
,
313 RAM_size
- KERNEL_LOAD_ADDR
);
314 if (kernel_size
< 0) {
315 fprintf(stderr
, "qemu: could not load kernel '%s'\n",
322 if (initrd_filename
) {
323 initrd_size
= load_image_targphys(initrd_filename
,
325 RAM_size
- INITRD_LOAD_ADDR
);
326 if (initrd_size
< 0) {
327 fprintf(stderr
, "qemu: could not load initial ram disk '%s'\n",
332 if (initrd_size
> 0) {
333 for (i
= 0; i
< 64 * TARGET_PAGE_SIZE
; i
+= TARGET_PAGE_SIZE
) {
334 if (ldl_phys(KERNEL_LOAD_ADDR
+ i
) == 0x48647253) { // HdrS
335 stl_phys(KERNEL_LOAD_ADDR
+ i
+ 16, INITRD_LOAD_ADDR
);
336 stl_phys(KERNEL_LOAD_ADDR
+ i
+ 20, initrd_size
);
345 static void *iommu_init(target_phys_addr_t addr
, uint32_t version
, qemu_irq irq
)
350 dev
= qdev_create(NULL
, "iommu");
351 qdev_prop_set_uint32(dev
, "version", version
);
353 s
= sysbus_from_qdev(dev
);
354 sysbus_connect_irq(s
, 0, irq
);
355 sysbus_mmio_map(s
, 0, addr
);
360 static void *sparc32_dma_init(target_phys_addr_t daddr
, qemu_irq parent_irq
,
361 void *iommu
, qemu_irq
*dev_irq
)
366 dev
= qdev_create(NULL
, "sparc32_dma");
367 qdev_prop_set_ptr(dev
, "iommu_opaque", iommu
);
369 s
= sysbus_from_qdev(dev
);
370 sysbus_connect_irq(s
, 0, parent_irq
);
371 *dev_irq
= qdev_get_gpio_in(dev
, 0);
372 sysbus_mmio_map(s
, 0, daddr
);
377 static void lance_init(NICInfo
*nd
, target_phys_addr_t leaddr
,
378 void *dma_opaque
, qemu_irq irq
)
384 qemu_check_nic_model(&nd_table
[0], "lance");
386 dev
= qdev_create(NULL
, "lance");
388 qdev_prop_set_ptr(dev
, "dma", dma_opaque
);
390 s
= sysbus_from_qdev(dev
);
391 sysbus_mmio_map(s
, 0, leaddr
);
392 sysbus_connect_irq(s
, 0, irq
);
393 reset
= qdev_get_gpio_in(dev
, 0);
394 qdev_connect_gpio_out(dma_opaque
, 0, reset
);
397 static DeviceState
*slavio_intctl_init(target_phys_addr_t addr
,
398 target_phys_addr_t addrg
,
399 qemu_irq
**parent_irq
,
400 unsigned int cputimer
)
406 dev
= qdev_create(NULL
, "slavio_intctl");
407 qdev_prop_set_uint32(dev
, "cputimer_bit", cputimer
);
410 s
= sysbus_from_qdev(dev
);
412 for (i
= 0; i
< MAX_CPUS
; i
++) {
413 for (j
= 0; j
< MAX_PILS
; j
++) {
414 sysbus_connect_irq(s
, i
* MAX_PILS
+ j
, parent_irq
[i
][j
]);
417 sysbus_mmio_map(s
, 0, addrg
);
418 for (i
= 0; i
< MAX_CPUS
; i
++) {
419 sysbus_mmio_map(s
, i
+ 1, addr
+ i
* TARGET_PAGE_SIZE
);
425 #define SYS_TIMER_OFFSET 0x10000ULL
426 #define CPU_TIMER_OFFSET(cpu) (0x1000ULL * cpu)
428 static void slavio_timer_init_all(target_phys_addr_t addr
, qemu_irq master_irq
,
429 qemu_irq
*cpu_irqs
, unsigned int num_cpus
)
435 dev
= qdev_create(NULL
, "slavio_timer");
436 qdev_prop_set_uint32(dev
, "num_cpus", num_cpus
);
438 s
= sysbus_from_qdev(dev
);
439 sysbus_connect_irq(s
, 0, master_irq
);
440 sysbus_mmio_map(s
, 0, addr
+ SYS_TIMER_OFFSET
);
442 for (i
= 0; i
< MAX_CPUS
; i
++) {
443 sysbus_mmio_map(s
, i
+ 1, addr
+ (target_phys_addr_t
)CPU_TIMER_OFFSET(i
));
444 sysbus_connect_irq(s
, i
+ 1, cpu_irqs
[i
]);
448 #define MISC_LEDS 0x01600000
449 #define MISC_CFG 0x01800000
450 #define MISC_DIAG 0x01a00000
451 #define MISC_MDM 0x01b00000
452 #define MISC_SYS 0x01f00000
454 static qemu_irq slavio_powerdown
;
456 void qemu_system_powerdown(void)
458 qemu_irq_raise(slavio_powerdown
);
461 static void slavio_misc_init(target_phys_addr_t base
,
462 target_phys_addr_t aux1_base
,
463 target_phys_addr_t aux2_base
, qemu_irq irq
,
469 dev
= qdev_create(NULL
, "slavio_misc");
471 s
= sysbus_from_qdev(dev
);
473 /* 8 bit registers */
475 sysbus_mmio_map(s
, 0, base
+ MISC_CFG
);
477 sysbus_mmio_map(s
, 1, base
+ MISC_DIAG
);
479 sysbus_mmio_map(s
, 2, base
+ MISC_MDM
);
480 /* 16 bit registers */
481 /* ss600mp diag LEDs */
482 sysbus_mmio_map(s
, 3, base
+ MISC_LEDS
);
483 /* 32 bit registers */
485 sysbus_mmio_map(s
, 4, base
+ MISC_SYS
);
488 /* AUX 1 (Misc System Functions) */
489 sysbus_mmio_map(s
, 5, aux1_base
);
492 /* AUX 2 (Software Powerdown Control) */
493 sysbus_mmio_map(s
, 6, aux2_base
);
495 sysbus_connect_irq(s
, 0, irq
);
496 sysbus_connect_irq(s
, 1, fdc_tc
);
497 slavio_powerdown
= qdev_get_gpio_in(dev
, 0);
500 static void ecc_init(target_phys_addr_t base
, qemu_irq irq
, uint32_t version
)
505 dev
= qdev_create(NULL
, "eccmemctl");
506 qdev_prop_set_uint32(dev
, "version", version
);
508 s
= sysbus_from_qdev(dev
);
509 sysbus_connect_irq(s
, 0, irq
);
510 sysbus_mmio_map(s
, 0, base
);
511 if (version
== 0) { // SS-600MP only
512 sysbus_mmio_map(s
, 1, base
+ 0x1000);
516 static void apc_init(target_phys_addr_t power_base
, qemu_irq cpu_halt
)
521 dev
= qdev_create(NULL
, "apc");
523 s
= sysbus_from_qdev(dev
);
524 /* Power management (APC) XXX: not a Slavio device */
525 sysbus_mmio_map(s
, 0, power_base
);
526 sysbus_connect_irq(s
, 0, cpu_halt
);
529 static void tcx_init(target_phys_addr_t addr
, int vram_size
, int width
,
530 int height
, int depth
)
535 dev
= qdev_create(NULL
, "SUNW,tcx");
536 qdev_prop_set_taddr(dev
, "addr", addr
);
537 qdev_prop_set_uint32(dev
, "vram_size", vram_size
);
538 qdev_prop_set_uint16(dev
, "width", width
);
539 qdev_prop_set_uint16(dev
, "height", height
);
540 qdev_prop_set_uint16(dev
, "depth", depth
);
542 s
= sysbus_from_qdev(dev
);
544 sysbus_mmio_map(s
, 0, addr
+ 0x00800000ULL
);
546 sysbus_mmio_map(s
, 1, addr
+ 0x00200000ULL
);
548 sysbus_mmio_map(s
, 2, addr
+ 0x00700000ULL
);
549 /* THC 24 bit: NetBSD writes here even with 8-bit display: dummy */
550 sysbus_mmio_map(s
, 3, addr
+ 0x00301000ULL
);
553 sysbus_mmio_map(s
, 4, addr
+ 0x02000000ULL
);
555 sysbus_mmio_map(s
, 5, addr
+ 0x0a000000ULL
);
557 /* THC 8 bit (dummy) */
558 sysbus_mmio_map(s
, 4, addr
+ 0x00300000ULL
);
562 /* NCR89C100/MACIO Internal ID register */
563 static const uint8_t idreg_data
[] = { 0xfe, 0x81, 0x01, 0x03 };
565 static void idreg_init(target_phys_addr_t addr
)
570 dev
= qdev_create(NULL
, "macio_idreg");
572 s
= sysbus_from_qdev(dev
);
574 sysbus_mmio_map(s
, 0, addr
);
575 cpu_physical_memory_write_rom(addr
, idreg_data
, sizeof(idreg_data
));
578 static void idreg_init1(SysBusDevice
*dev
)
580 ram_addr_t idreg_offset
;
582 idreg_offset
= qemu_ram_alloc(sizeof(idreg_data
));
583 sysbus_init_mmio(dev
, sizeof(idreg_data
), idreg_offset
| IO_MEM_ROM
);
586 static SysBusDeviceInfo idreg_info
= {
588 .qdev
.name
= "macio_idreg",
589 .qdev
.size
= sizeof(SysBusDevice
),
592 static void idreg_register_devices(void)
594 sysbus_register_withprop(&idreg_info
);
597 device_init(idreg_register_devices
);
599 /* Boot PROM (OpenBIOS) */
600 static void prom_init(target_phys_addr_t addr
, const char *bios_name
)
607 dev
= qdev_create(NULL
, "openprom");
609 s
= sysbus_from_qdev(dev
);
611 sysbus_mmio_map(s
, 0, addr
);
614 if (bios_name
== NULL
) {
615 bios_name
= PROM_FILENAME
;
617 filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, bios_name
);
619 ret
= load_elf(filename
, addr
- PROM_VADDR
, NULL
, NULL
, NULL
);
620 if (ret
< 0 || ret
> PROM_SIZE_MAX
) {
621 ret
= load_image_targphys(filename
, addr
, PROM_SIZE_MAX
);
627 if (ret
< 0 || ret
> PROM_SIZE_MAX
) {
628 fprintf(stderr
, "qemu: could not load prom '%s'\n", bios_name
);
633 static void prom_init1(SysBusDevice
*dev
)
635 ram_addr_t prom_offset
;
637 prom_offset
= qemu_ram_alloc(PROM_SIZE_MAX
);
638 sysbus_init_mmio(dev
, PROM_SIZE_MAX
, prom_offset
| IO_MEM_ROM
);
641 static SysBusDeviceInfo prom_info
= {
643 .qdev
.name
= "openprom",
644 .qdev
.size
= sizeof(SysBusDevice
),
645 .qdev
.props
= (Property
[]) {
646 {/* end of property list */}
650 static void prom_register_devices(void)
652 sysbus_register_withprop(&prom_info
);
655 device_init(prom_register_devices
);
657 typedef struct RamDevice
664 static void ram_init1(SysBusDevice
*dev
)
666 ram_addr_t RAM_size
, ram_offset
;
667 RamDevice
*d
= FROM_SYSBUS(RamDevice
, dev
);
671 ram_offset
= qemu_ram_alloc(RAM_size
);
672 sysbus_init_mmio(dev
, RAM_size
, ram_offset
);
675 static void ram_init(target_phys_addr_t addr
, ram_addr_t RAM_size
,
683 if ((uint64_t)RAM_size
> max_mem
) {
685 "qemu: Too much memory for this machine: %d, maximum %d\n",
686 (unsigned int)(RAM_size
/ (1024 * 1024)),
687 (unsigned int)(max_mem
/ (1024 * 1024)));
690 dev
= qdev_create(NULL
, "memory");
691 s
= sysbus_from_qdev(dev
);
693 d
= FROM_SYSBUS(RamDevice
, s
);
697 sysbus_mmio_map(s
, 0, addr
);
700 static SysBusDeviceInfo ram_info
= {
702 .qdev
.name
= "memory",
703 .qdev
.size
= sizeof(RamDevice
),
704 .qdev
.props
= (Property
[]) {
707 .info
= &qdev_prop_uint64
,
708 .offset
= offsetof(RamDevice
, size
),
710 {/* end of property list */}
714 static void ram_register_devices(void)
716 sysbus_register_withprop(&ram_info
);
719 device_init(ram_register_devices
);
721 static CPUState
*cpu_devinit(const char *cpu_model
, unsigned int id
,
722 uint64_t prom_addr
, qemu_irq
**cpu_irqs
)
726 env
= cpu_init(cpu_model
);
728 fprintf(stderr
, "qemu: Unable to find Sparc CPU definition\n");
732 cpu_sparc_set_id(env
, id
);
734 qemu_register_reset(main_cpu_reset
, env
);
736 qemu_register_reset(secondary_cpu_reset
, env
);
739 *cpu_irqs
= qemu_allocate_irqs(cpu_set_irq
, env
, MAX_PILS
);
740 env
->prom_addr
= prom_addr
;
745 static void sun4m_hw_init(const struct sun4m_hwdef
*hwdef
, ram_addr_t RAM_size
,
746 const char *boot_device
,
747 const char *kernel_filename
,
748 const char *kernel_cmdline
,
749 const char *initrd_filename
, const char *cpu_model
)
751 CPUState
*envs
[MAX_CPUS
];
753 void *iommu
, *espdma
, *ledma
, *nvram
;
754 qemu_irq
*cpu_irqs
[MAX_CPUS
], slavio_irq
[32], slavio_cpu_irq
[MAX_CPUS
],
755 espdma_irq
, ledma_irq
;
759 unsigned long kernel_size
;
760 BlockDriverState
*fd
[MAX_FD
];
767 cpu_model
= hwdef
->default_cpu_model
;
769 for(i
= 0; i
< smp_cpus
; i
++) {
770 envs
[i
] = cpu_devinit(cpu_model
, i
, hwdef
->slavio_base
, &cpu_irqs
[i
]);
773 for (i
= smp_cpus
; i
< MAX_CPUS
; i
++)
774 cpu_irqs
[i
] = qemu_allocate_irqs(dummy_cpu_set_irq
, NULL
, MAX_PILS
);
778 ram_init(0, RAM_size
, hwdef
->max_mem
);
780 prom_init(hwdef
->slavio_base
, bios_name
);
782 dev
= slavio_intctl_init(hwdef
->intctl_base
,
783 hwdef
->intctl_base
+ 0x10000ULL
,
787 for (i
= 0; i
< 32; i
++) {
788 slavio_irq
[i
] = qdev_get_gpio_in(dev
, i
);
790 for (i
= 0; i
< MAX_CPUS
; i
++) {
791 slavio_cpu_irq
[i
] = qdev_get_gpio_in(dev
, 32 + i
);
794 if (hwdef
->idreg_base
) {
795 idreg_init(hwdef
->idreg_base
);
798 iommu
= iommu_init(hwdef
->iommu_base
, hwdef
->iommu_version
,
801 espdma
= sparc32_dma_init(hwdef
->dma_base
, slavio_irq
[18],
804 ledma
= sparc32_dma_init(hwdef
->dma_base
+ 16ULL,
805 slavio_irq
[16], iommu
, &ledma_irq
);
807 if (graphic_depth
!= 8 && graphic_depth
!= 24) {
808 fprintf(stderr
, "qemu: Unsupported depth: %d\n", graphic_depth
);
811 tcx_init(hwdef
->tcx_base
, 0x00100000, graphic_width
, graphic_height
,
814 lance_init(&nd_table
[0], hwdef
->le_base
, ledma
, ledma_irq
);
816 nvram
= m48t59_init(slavio_irq
[0], hwdef
->nvram_base
, 0, 0x2000, 8);
818 slavio_timer_init_all(hwdef
->counter_base
, slavio_irq
[19], slavio_cpu_irq
, smp_cpus
);
820 slavio_serial_ms_kbd_init(hwdef
->ms_kb_base
, slavio_irq
[14],
821 display_type
== DT_NOGRAPHIC
, ESCC_CLOCK
, 1);
822 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
823 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
824 escc_init(hwdef
->serial_base
, slavio_irq
[15], slavio_irq
[15],
825 serial_hds
[0], serial_hds
[1], ESCC_CLOCK
, 1);
827 cpu_halt
= qemu_allocate_irqs(cpu_halt_signal
, NULL
, 1);
828 slavio_misc_init(hwdef
->slavio_base
, hwdef
->aux1_base
, hwdef
->aux2_base
,
829 slavio_irq
[30], fdc_tc
);
831 if (hwdef
->apc_base
) {
832 apc_init(hwdef
->apc_base
, cpu_halt
[0]);
835 if (hwdef
->fd_base
) {
836 /* there is zero or one floppy drive */
837 memset(fd
, 0, sizeof(fd
));
838 dinfo
= drive_get(IF_FLOPPY
, 0, 0);
842 sun4m_fdctrl_init(slavio_irq
[22], hwdef
->fd_base
, fd
,
846 if (drive_get_max_bus(IF_SCSI
) > 0) {
847 fprintf(stderr
, "qemu: too many SCSI bus\n");
851 esp_reset
= qdev_get_gpio_in(espdma
, 0);
852 esp_init(hwdef
->esp_base
, 2,
853 espdma_memory_read
, espdma_memory_write
,
854 espdma
, espdma_irq
, &esp_reset
);
857 if (hwdef
->cs_base
) {
858 sysbus_create_simple("SUNW,CS4231", hwdef
->cs_base
,
862 kernel_size
= sun4m_load_kernel(kernel_filename
, initrd_filename
,
865 nvram_init(nvram
, (uint8_t *)&nd_table
[0].macaddr
, kernel_cmdline
,
866 boot_device
, RAM_size
, kernel_size
, graphic_width
,
867 graphic_height
, graphic_depth
, hwdef
->nvram_machine_id
,
871 ecc_init(hwdef
->ecc_base
, slavio_irq
[28],
874 fw_cfg
= fw_cfg_init(0, 0, CFG_ADDR
, CFG_ADDR
+ 2);
875 fw_cfg_add_i32(fw_cfg
, FW_CFG_ID
, 1);
876 fw_cfg_add_i64(fw_cfg
, FW_CFG_RAM_SIZE
, (uint64_t)ram_size
);
877 fw_cfg_add_i16(fw_cfg
, FW_CFG_MACHINE_ID
, hwdef
->machine_id
);
878 fw_cfg_add_i16(fw_cfg
, FW_CFG_SUN4M_DEPTH
, graphic_depth
);
879 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_ADDR
, KERNEL_LOAD_ADDR
);
880 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_SIZE
, kernel_size
);
881 if (kernel_cmdline
) {
882 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_CMDLINE
, CMDLINE_ADDR
);
883 pstrcpy_targphys(CMDLINE_ADDR
, TARGET_PAGE_SIZE
, kernel_cmdline
);
885 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_CMDLINE
, 0);
887 fw_cfg_add_i32(fw_cfg
, FW_CFG_INITRD_ADDR
, INITRD_LOAD_ADDR
);
888 fw_cfg_add_i32(fw_cfg
, FW_CFG_INITRD_SIZE
, 0); // not used
889 fw_cfg_add_i16(fw_cfg
, FW_CFG_BOOT_DEVICE
, boot_device
[0]);
890 qemu_register_boot_set(fw_cfg_boot_set
, fw_cfg
);
908 static const struct sun4m_hwdef sun4m_hwdefs
[] = {
911 .iommu_base
= 0x10000000,
912 .tcx_base
= 0x50000000,
913 .cs_base
= 0x6c000000,
914 .slavio_base
= 0x70000000,
915 .ms_kb_base
= 0x71000000,
916 .serial_base
= 0x71100000,
917 .nvram_base
= 0x71200000,
918 .fd_base
= 0x71400000,
919 .counter_base
= 0x71d00000,
920 .intctl_base
= 0x71e00000,
921 .idreg_base
= 0x78000000,
922 .dma_base
= 0x78400000,
923 .esp_base
= 0x78800000,
924 .le_base
= 0x78c00000,
925 .apc_base
= 0x6a000000,
926 .aux1_base
= 0x71900000,
927 .aux2_base
= 0x71910000,
928 .nvram_machine_id
= 0x80,
929 .machine_id
= ss5_id
,
930 .iommu_version
= 0x05000000,
931 .max_mem
= 0x10000000,
932 .default_cpu_model
= "Fujitsu MB86904",
936 .iommu_base
= 0xfe0000000ULL
,
937 .tcx_base
= 0xe20000000ULL
,
938 .slavio_base
= 0xff0000000ULL
,
939 .ms_kb_base
= 0xff1000000ULL
,
940 .serial_base
= 0xff1100000ULL
,
941 .nvram_base
= 0xff1200000ULL
,
942 .fd_base
= 0xff1700000ULL
,
943 .counter_base
= 0xff1300000ULL
,
944 .intctl_base
= 0xff1400000ULL
,
945 .idreg_base
= 0xef0000000ULL
,
946 .dma_base
= 0xef0400000ULL
,
947 .esp_base
= 0xef0800000ULL
,
948 .le_base
= 0xef0c00000ULL
,
949 .apc_base
= 0xefa000000ULL
, // XXX should not exist
950 .aux1_base
= 0xff1800000ULL
,
951 .aux2_base
= 0xff1a01000ULL
,
952 .ecc_base
= 0xf00000000ULL
,
953 .ecc_version
= 0x10000000, // version 0, implementation 1
954 .nvram_machine_id
= 0x72,
955 .machine_id
= ss10_id
,
956 .iommu_version
= 0x03000000,
957 .max_mem
= 0xf00000000ULL
,
958 .default_cpu_model
= "TI SuperSparc II",
962 .iommu_base
= 0xfe0000000ULL
,
963 .tcx_base
= 0xe20000000ULL
,
964 .slavio_base
= 0xff0000000ULL
,
965 .ms_kb_base
= 0xff1000000ULL
,
966 .serial_base
= 0xff1100000ULL
,
967 .nvram_base
= 0xff1200000ULL
,
968 .counter_base
= 0xff1300000ULL
,
969 .intctl_base
= 0xff1400000ULL
,
970 .dma_base
= 0xef0081000ULL
,
971 .esp_base
= 0xef0080000ULL
,
972 .le_base
= 0xef0060000ULL
,
973 .apc_base
= 0xefa000000ULL
, // XXX should not exist
974 .aux1_base
= 0xff1800000ULL
,
975 .aux2_base
= 0xff1a01000ULL
, // XXX should not exist
976 .ecc_base
= 0xf00000000ULL
,
977 .ecc_version
= 0x00000000, // version 0, implementation 0
978 .nvram_machine_id
= 0x71,
979 .machine_id
= ss600mp_id
,
980 .iommu_version
= 0x01000000,
981 .max_mem
= 0xf00000000ULL
,
982 .default_cpu_model
= "TI SuperSparc II",
986 .iommu_base
= 0xfe0000000ULL
,
987 .tcx_base
= 0xe20000000ULL
,
988 .slavio_base
= 0xff0000000ULL
,
989 .ms_kb_base
= 0xff1000000ULL
,
990 .serial_base
= 0xff1100000ULL
,
991 .nvram_base
= 0xff1200000ULL
,
992 .fd_base
= 0xff1700000ULL
,
993 .counter_base
= 0xff1300000ULL
,
994 .intctl_base
= 0xff1400000ULL
,
995 .idreg_base
= 0xef0000000ULL
,
996 .dma_base
= 0xef0400000ULL
,
997 .esp_base
= 0xef0800000ULL
,
998 .le_base
= 0xef0c00000ULL
,
999 .apc_base
= 0xefa000000ULL
, // XXX should not exist
1000 .aux1_base
= 0xff1800000ULL
,
1001 .aux2_base
= 0xff1a01000ULL
,
1002 .ecc_base
= 0xf00000000ULL
,
1003 .ecc_version
= 0x20000000, // version 0, implementation 2
1004 .nvram_machine_id
= 0x72,
1005 .machine_id
= ss20_id
,
1006 .iommu_version
= 0x13000000,
1007 .max_mem
= 0xf00000000ULL
,
1008 .default_cpu_model
= "TI SuperSparc II",
1012 .iommu_base
= 0x10000000,
1013 .tcx_base
= 0x50000000,
1014 .slavio_base
= 0x70000000,
1015 .ms_kb_base
= 0x71000000,
1016 .serial_base
= 0x71100000,
1017 .nvram_base
= 0x71200000,
1018 .fd_base
= 0x71400000,
1019 .counter_base
= 0x71d00000,
1020 .intctl_base
= 0x71e00000,
1021 .idreg_base
= 0x78000000,
1022 .dma_base
= 0x78400000,
1023 .esp_base
= 0x78800000,
1024 .le_base
= 0x78c00000,
1025 .apc_base
= 0x71300000, // pmc
1026 .aux1_base
= 0x71900000,
1027 .aux2_base
= 0x71910000,
1028 .nvram_machine_id
= 0x80,
1029 .machine_id
= vger_id
,
1030 .iommu_version
= 0x05000000,
1031 .max_mem
= 0x10000000,
1032 .default_cpu_model
= "Fujitsu MB86904",
1036 .iommu_base
= 0x10000000,
1037 .tcx_base
= 0x50000000,
1038 .slavio_base
= 0x70000000,
1039 .ms_kb_base
= 0x71000000,
1040 .serial_base
= 0x71100000,
1041 .nvram_base
= 0x71200000,
1042 .fd_base
= 0x71400000,
1043 .counter_base
= 0x71d00000,
1044 .intctl_base
= 0x71e00000,
1045 .idreg_base
= 0x78000000,
1046 .dma_base
= 0x78400000,
1047 .esp_base
= 0x78800000,
1048 .le_base
= 0x78c00000,
1049 .aux1_base
= 0x71900000,
1050 .aux2_base
= 0x71910000,
1051 .nvram_machine_id
= 0x80,
1052 .machine_id
= lx_id
,
1053 .iommu_version
= 0x04000000,
1054 .max_mem
= 0x10000000,
1055 .default_cpu_model
= "TI MicroSparc I",
1059 .iommu_base
= 0x10000000,
1060 .tcx_base
= 0x50000000,
1061 .cs_base
= 0x6c000000,
1062 .slavio_base
= 0x70000000,
1063 .ms_kb_base
= 0x71000000,
1064 .serial_base
= 0x71100000,
1065 .nvram_base
= 0x71200000,
1066 .fd_base
= 0x71400000,
1067 .counter_base
= 0x71d00000,
1068 .intctl_base
= 0x71e00000,
1069 .idreg_base
= 0x78000000,
1070 .dma_base
= 0x78400000,
1071 .esp_base
= 0x78800000,
1072 .le_base
= 0x78c00000,
1073 .apc_base
= 0x6a000000,
1074 .aux1_base
= 0x71900000,
1075 .aux2_base
= 0x71910000,
1076 .nvram_machine_id
= 0x80,
1077 .machine_id
= ss4_id
,
1078 .iommu_version
= 0x05000000,
1079 .max_mem
= 0x10000000,
1080 .default_cpu_model
= "Fujitsu MB86904",
1084 .iommu_base
= 0x10000000,
1085 .tcx_base
= 0x50000000,
1086 .slavio_base
= 0x70000000,
1087 .ms_kb_base
= 0x71000000,
1088 .serial_base
= 0x71100000,
1089 .nvram_base
= 0x71200000,
1090 .fd_base
= 0x71400000,
1091 .counter_base
= 0x71d00000,
1092 .intctl_base
= 0x71e00000,
1093 .idreg_base
= 0x78000000,
1094 .dma_base
= 0x78400000,
1095 .esp_base
= 0x78800000,
1096 .le_base
= 0x78c00000,
1097 .apc_base
= 0x6a000000,
1098 .aux1_base
= 0x71900000,
1099 .aux2_base
= 0x71910000,
1100 .nvram_machine_id
= 0x80,
1101 .machine_id
= scls_id
,
1102 .iommu_version
= 0x05000000,
1103 .max_mem
= 0x10000000,
1104 .default_cpu_model
= "TI MicroSparc I",
1108 .iommu_base
= 0x10000000,
1109 .tcx_base
= 0x50000000, // XXX
1110 .slavio_base
= 0x70000000,
1111 .ms_kb_base
= 0x71000000,
1112 .serial_base
= 0x71100000,
1113 .nvram_base
= 0x71200000,
1114 .fd_base
= 0x71400000,
1115 .counter_base
= 0x71d00000,
1116 .intctl_base
= 0x71e00000,
1117 .idreg_base
= 0x78000000,
1118 .dma_base
= 0x78400000,
1119 .esp_base
= 0x78800000,
1120 .le_base
= 0x78c00000,
1121 .apc_base
= 0x6a000000,
1122 .aux1_base
= 0x71900000,
1123 .aux2_base
= 0x71910000,
1124 .nvram_machine_id
= 0x80,
1125 .machine_id
= sbook_id
,
1126 .iommu_version
= 0x05000000,
1127 .max_mem
= 0x10000000,
1128 .default_cpu_model
= "TI MicroSparc I",
1132 /* SPARCstation 5 hardware initialisation */
1133 static void ss5_init(ram_addr_t RAM_size
,
1134 const char *boot_device
,
1135 const char *kernel_filename
, const char *kernel_cmdline
,
1136 const char *initrd_filename
, const char *cpu_model
)
1138 sun4m_hw_init(&sun4m_hwdefs
[0], RAM_size
, boot_device
, kernel_filename
,
1139 kernel_cmdline
, initrd_filename
, cpu_model
);
1142 /* SPARCstation 10 hardware initialisation */
1143 static void ss10_init(ram_addr_t RAM_size
,
1144 const char *boot_device
,
1145 const char *kernel_filename
, const char *kernel_cmdline
,
1146 const char *initrd_filename
, const char *cpu_model
)
1148 sun4m_hw_init(&sun4m_hwdefs
[1], RAM_size
, boot_device
, kernel_filename
,
1149 kernel_cmdline
, initrd_filename
, cpu_model
);
1152 /* SPARCserver 600MP hardware initialisation */
1153 static void ss600mp_init(ram_addr_t RAM_size
,
1154 const char *boot_device
,
1155 const char *kernel_filename
,
1156 const char *kernel_cmdline
,
1157 const char *initrd_filename
, const char *cpu_model
)
1159 sun4m_hw_init(&sun4m_hwdefs
[2], RAM_size
, boot_device
, kernel_filename
,
1160 kernel_cmdline
, initrd_filename
, cpu_model
);
1163 /* SPARCstation 20 hardware initialisation */
1164 static void ss20_init(ram_addr_t RAM_size
,
1165 const char *boot_device
,
1166 const char *kernel_filename
, const char *kernel_cmdline
,
1167 const char *initrd_filename
, const char *cpu_model
)
1169 sun4m_hw_init(&sun4m_hwdefs
[3], RAM_size
, boot_device
, kernel_filename
,
1170 kernel_cmdline
, initrd_filename
, cpu_model
);
1173 /* SPARCstation Voyager hardware initialisation */
1174 static void vger_init(ram_addr_t RAM_size
,
1175 const char *boot_device
,
1176 const char *kernel_filename
, const char *kernel_cmdline
,
1177 const char *initrd_filename
, const char *cpu_model
)
1179 sun4m_hw_init(&sun4m_hwdefs
[4], RAM_size
, boot_device
, kernel_filename
,
1180 kernel_cmdline
, initrd_filename
, cpu_model
);
1183 /* SPARCstation LX hardware initialisation */
1184 static void ss_lx_init(ram_addr_t RAM_size
,
1185 const char *boot_device
,
1186 const char *kernel_filename
, const char *kernel_cmdline
,
1187 const char *initrd_filename
, const char *cpu_model
)
1189 sun4m_hw_init(&sun4m_hwdefs
[5], RAM_size
, boot_device
, kernel_filename
,
1190 kernel_cmdline
, initrd_filename
, cpu_model
);
1193 /* SPARCstation 4 hardware initialisation */
1194 static void ss4_init(ram_addr_t RAM_size
,
1195 const char *boot_device
,
1196 const char *kernel_filename
, const char *kernel_cmdline
,
1197 const char *initrd_filename
, const char *cpu_model
)
1199 sun4m_hw_init(&sun4m_hwdefs
[6], RAM_size
, boot_device
, kernel_filename
,
1200 kernel_cmdline
, initrd_filename
, cpu_model
);
1203 /* SPARCClassic hardware initialisation */
1204 static void scls_init(ram_addr_t RAM_size
,
1205 const char *boot_device
,
1206 const char *kernel_filename
, const char *kernel_cmdline
,
1207 const char *initrd_filename
, const char *cpu_model
)
1209 sun4m_hw_init(&sun4m_hwdefs
[7], RAM_size
, boot_device
, kernel_filename
,
1210 kernel_cmdline
, initrd_filename
, cpu_model
);
1213 /* SPARCbook hardware initialisation */
1214 static void sbook_init(ram_addr_t RAM_size
,
1215 const char *boot_device
,
1216 const char *kernel_filename
, const char *kernel_cmdline
,
1217 const char *initrd_filename
, const char *cpu_model
)
1219 sun4m_hw_init(&sun4m_hwdefs
[8], RAM_size
, boot_device
, kernel_filename
,
1220 kernel_cmdline
, initrd_filename
, cpu_model
);
1223 static QEMUMachine ss5_machine
= {
1225 .desc
= "Sun4m platform, SPARCstation 5",
1231 static QEMUMachine ss10_machine
= {
1233 .desc
= "Sun4m platform, SPARCstation 10",
1239 static QEMUMachine ss600mp_machine
= {
1241 .desc
= "Sun4m platform, SPARCserver 600MP",
1242 .init
= ss600mp_init
,
1247 static QEMUMachine ss20_machine
= {
1249 .desc
= "Sun4m platform, SPARCstation 20",
1255 static QEMUMachine voyager_machine
= {
1257 .desc
= "Sun4m platform, SPARCstation Voyager",
1262 static QEMUMachine ss_lx_machine
= {
1264 .desc
= "Sun4m platform, SPARCstation LX",
1269 static QEMUMachine ss4_machine
= {
1271 .desc
= "Sun4m platform, SPARCstation 4",
1276 static QEMUMachine scls_machine
= {
1277 .name
= "SPARCClassic",
1278 .desc
= "Sun4m platform, SPARCClassic",
1283 static QEMUMachine sbook_machine
= {
1284 .name
= "SPARCbook",
1285 .desc
= "Sun4m platform, SPARCbook",
1290 static const struct sun4d_hwdef sun4d_hwdefs
[] = {
1300 .tcx_base
= 0x820000000ULL
,
1301 .slavio_base
= 0xf00000000ULL
,
1302 .ms_kb_base
= 0xf00240000ULL
,
1303 .serial_base
= 0xf00200000ULL
,
1304 .nvram_base
= 0xf00280000ULL
,
1305 .counter_base
= 0xf00300000ULL
,
1306 .espdma_base
= 0x800081000ULL
,
1307 .esp_base
= 0x800080000ULL
,
1308 .ledma_base
= 0x800040000ULL
,
1309 .le_base
= 0x800060000ULL
,
1310 .sbi_base
= 0xf02800000ULL
,
1311 .nvram_machine_id
= 0x80,
1312 .machine_id
= ss1000_id
,
1313 .iounit_version
= 0x03000000,
1314 .max_mem
= 0xf00000000ULL
,
1315 .default_cpu_model
= "TI SuperSparc II",
1326 .tcx_base
= 0x820000000ULL
,
1327 .slavio_base
= 0xf00000000ULL
,
1328 .ms_kb_base
= 0xf00240000ULL
,
1329 .serial_base
= 0xf00200000ULL
,
1330 .nvram_base
= 0xf00280000ULL
,
1331 .counter_base
= 0xf00300000ULL
,
1332 .espdma_base
= 0x800081000ULL
,
1333 .esp_base
= 0x800080000ULL
,
1334 .ledma_base
= 0x800040000ULL
,
1335 .le_base
= 0x800060000ULL
,
1336 .sbi_base
= 0xf02800000ULL
,
1337 .nvram_machine_id
= 0x80,
1338 .machine_id
= ss2000_id
,
1339 .iounit_version
= 0x03000000,
1340 .max_mem
= 0xf00000000ULL
,
1341 .default_cpu_model
= "TI SuperSparc II",
1345 static DeviceState
*sbi_init(target_phys_addr_t addr
, qemu_irq
**parent_irq
)
1351 dev
= qdev_create(NULL
, "sbi");
1354 s
= sysbus_from_qdev(dev
);
1356 for (i
= 0; i
< MAX_CPUS
; i
++) {
1357 sysbus_connect_irq(s
, i
, *parent_irq
[i
]);
1360 sysbus_mmio_map(s
, 0, addr
);
1365 static void sun4d_hw_init(const struct sun4d_hwdef
*hwdef
, ram_addr_t RAM_size
,
1366 const char *boot_device
,
1367 const char *kernel_filename
,
1368 const char *kernel_cmdline
,
1369 const char *initrd_filename
, const char *cpu_model
)
1371 CPUState
*envs
[MAX_CPUS
];
1373 void *iounits
[MAX_IOUNITS
], *espdma
, *ledma
, *nvram
;
1374 qemu_irq
*cpu_irqs
[MAX_CPUS
], sbi_irq
[32], sbi_cpu_irq
[MAX_CPUS
],
1375 espdma_irq
, ledma_irq
;
1377 unsigned long kernel_size
;
1383 cpu_model
= hwdef
->default_cpu_model
;
1385 for(i
= 0; i
< smp_cpus
; i
++) {
1386 envs
[i
] = cpu_devinit(cpu_model
, i
, hwdef
->slavio_base
, &cpu_irqs
[i
]);
1389 for (i
= smp_cpus
; i
< MAX_CPUS
; i
++)
1390 cpu_irqs
[i
] = qemu_allocate_irqs(dummy_cpu_set_irq
, NULL
, MAX_PILS
);
1392 /* set up devices */
1393 ram_init(0, RAM_size
, hwdef
->max_mem
);
1395 prom_init(hwdef
->slavio_base
, bios_name
);
1397 dev
= sbi_init(hwdef
->sbi_base
, cpu_irqs
);
1399 for (i
= 0; i
< 32; i
++) {
1400 sbi_irq
[i
] = qdev_get_gpio_in(dev
, i
);
1402 for (i
= 0; i
< MAX_CPUS
; i
++) {
1403 sbi_cpu_irq
[i
] = qdev_get_gpio_in(dev
, 32 + i
);
1406 for (i
= 0; i
< MAX_IOUNITS
; i
++)
1407 if (hwdef
->iounit_bases
[i
] != (target_phys_addr_t
)-1)
1408 iounits
[i
] = iommu_init(hwdef
->iounit_bases
[i
],
1409 hwdef
->iounit_version
,
1412 espdma
= sparc32_dma_init(hwdef
->espdma_base
, sbi_irq
[3],
1413 iounits
[0], &espdma_irq
);
1415 ledma
= sparc32_dma_init(hwdef
->ledma_base
, sbi_irq
[4],
1416 iounits
[0], &ledma_irq
);
1418 if (graphic_depth
!= 8 && graphic_depth
!= 24) {
1419 fprintf(stderr
, "qemu: Unsupported depth: %d\n", graphic_depth
);
1422 tcx_init(hwdef
->tcx_base
, 0x00100000, graphic_width
, graphic_height
,
1425 lance_init(&nd_table
[0], hwdef
->le_base
, ledma
, ledma_irq
);
1427 nvram
= m48t59_init(sbi_irq
[0], hwdef
->nvram_base
, 0, 0x2000, 8);
1429 slavio_timer_init_all(hwdef
->counter_base
, sbi_irq
[10], sbi_cpu_irq
, smp_cpus
);
1431 slavio_serial_ms_kbd_init(hwdef
->ms_kb_base
, sbi_irq
[12],
1432 display_type
== DT_NOGRAPHIC
, ESCC_CLOCK
, 1);
1433 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
1434 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
1435 escc_init(hwdef
->serial_base
, sbi_irq
[12], sbi_irq
[12],
1436 serial_hds
[0], serial_hds
[1], ESCC_CLOCK
, 1);
1438 if (drive_get_max_bus(IF_SCSI
) > 0) {
1439 fprintf(stderr
, "qemu: too many SCSI bus\n");
1443 esp_reset
= qdev_get_gpio_in(espdma
, 0);
1444 esp_init(hwdef
->esp_base
, 2,
1445 espdma_memory_read
, espdma_memory_write
,
1446 espdma
, espdma_irq
, &esp_reset
);
1448 kernel_size
= sun4m_load_kernel(kernel_filename
, initrd_filename
,
1451 nvram_init(nvram
, (uint8_t *)&nd_table
[0].macaddr
, kernel_cmdline
,
1452 boot_device
, RAM_size
, kernel_size
, graphic_width
,
1453 graphic_height
, graphic_depth
, hwdef
->nvram_machine_id
,
1456 fw_cfg
= fw_cfg_init(0, 0, CFG_ADDR
, CFG_ADDR
+ 2);
1457 fw_cfg_add_i32(fw_cfg
, FW_CFG_ID
, 1);
1458 fw_cfg_add_i64(fw_cfg
, FW_CFG_RAM_SIZE
, (uint64_t)ram_size
);
1459 fw_cfg_add_i16(fw_cfg
, FW_CFG_MACHINE_ID
, hwdef
->machine_id
);
1460 fw_cfg_add_i16(fw_cfg
, FW_CFG_SUN4M_DEPTH
, graphic_depth
);
1461 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_ADDR
, KERNEL_LOAD_ADDR
);
1462 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_SIZE
, kernel_size
);
1463 if (kernel_cmdline
) {
1464 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_CMDLINE
, CMDLINE_ADDR
);
1465 pstrcpy_targphys(CMDLINE_ADDR
, TARGET_PAGE_SIZE
, kernel_cmdline
);
1467 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_CMDLINE
, 0);
1469 fw_cfg_add_i32(fw_cfg
, FW_CFG_INITRD_ADDR
, INITRD_LOAD_ADDR
);
1470 fw_cfg_add_i32(fw_cfg
, FW_CFG_INITRD_SIZE
, 0); // not used
1471 fw_cfg_add_i16(fw_cfg
, FW_CFG_BOOT_DEVICE
, boot_device
[0]);
1472 qemu_register_boot_set(fw_cfg_boot_set
, fw_cfg
);
1475 /* SPARCserver 1000 hardware initialisation */
1476 static void ss1000_init(ram_addr_t RAM_size
,
1477 const char *boot_device
,
1478 const char *kernel_filename
, const char *kernel_cmdline
,
1479 const char *initrd_filename
, const char *cpu_model
)
1481 sun4d_hw_init(&sun4d_hwdefs
[0], RAM_size
, boot_device
, kernel_filename
,
1482 kernel_cmdline
, initrd_filename
, cpu_model
);
1485 /* SPARCcenter 2000 hardware initialisation */
1486 static void ss2000_init(ram_addr_t RAM_size
,
1487 const char *boot_device
,
1488 const char *kernel_filename
, const char *kernel_cmdline
,
1489 const char *initrd_filename
, const char *cpu_model
)
1491 sun4d_hw_init(&sun4d_hwdefs
[1], RAM_size
, boot_device
, kernel_filename
,
1492 kernel_cmdline
, initrd_filename
, cpu_model
);
1495 static QEMUMachine ss1000_machine
= {
1497 .desc
= "Sun4d platform, SPARCserver 1000",
1498 .init
= ss1000_init
,
1503 static QEMUMachine ss2000_machine
= {
1505 .desc
= "Sun4d platform, SPARCcenter 2000",
1506 .init
= ss2000_init
,
1511 static const struct sun4c_hwdef sun4c_hwdefs
[] = {
1514 .iommu_base
= 0xf8000000,
1515 .tcx_base
= 0xfe000000,
1516 .slavio_base
= 0xf6000000,
1517 .intctl_base
= 0xf5000000,
1518 .counter_base
= 0xf3000000,
1519 .ms_kb_base
= 0xf0000000,
1520 .serial_base
= 0xf1000000,
1521 .nvram_base
= 0xf2000000,
1522 .fd_base
= 0xf7200000,
1523 .dma_base
= 0xf8400000,
1524 .esp_base
= 0xf8800000,
1525 .le_base
= 0xf8c00000,
1526 .aux1_base
= 0xf7400003,
1527 .nvram_machine_id
= 0x55,
1528 .machine_id
= ss2_id
,
1529 .max_mem
= 0x10000000,
1530 .default_cpu_model
= "Cypress CY7C601",
1534 static DeviceState
*sun4c_intctl_init(target_phys_addr_t addr
,
1535 qemu_irq
*parent_irq
)
1541 dev
= qdev_create(NULL
, "sun4c_intctl");
1544 s
= sysbus_from_qdev(dev
);
1546 for (i
= 0; i
< MAX_PILS
; i
++) {
1547 sysbus_connect_irq(s
, i
, parent_irq
[i
]);
1549 sysbus_mmio_map(s
, 0, addr
);
1554 static void sun4c_hw_init(const struct sun4c_hwdef
*hwdef
, ram_addr_t RAM_size
,
1555 const char *boot_device
,
1556 const char *kernel_filename
,
1557 const char *kernel_cmdline
,
1558 const char *initrd_filename
, const char *cpu_model
)
1561 void *iommu
, *espdma
, *ledma
, *nvram
;
1562 qemu_irq
*cpu_irqs
, slavio_irq
[8], espdma_irq
, ledma_irq
;
1565 unsigned long kernel_size
;
1566 BlockDriverState
*fd
[MAX_FD
];
1574 cpu_model
= hwdef
->default_cpu_model
;
1576 env
= cpu_devinit(cpu_model
, 0, hwdef
->slavio_base
, &cpu_irqs
);
1578 /* set up devices */
1579 ram_init(0, RAM_size
, hwdef
->max_mem
);
1581 prom_init(hwdef
->slavio_base
, bios_name
);
1583 dev
= sun4c_intctl_init(hwdef
->intctl_base
, cpu_irqs
);
1585 for (i
= 0; i
< 8; i
++) {
1586 slavio_irq
[i
] = qdev_get_gpio_in(dev
, i
);
1589 iommu
= iommu_init(hwdef
->iommu_base
, hwdef
->iommu_version
,
1592 espdma
= sparc32_dma_init(hwdef
->dma_base
, slavio_irq
[2],
1593 iommu
, &espdma_irq
);
1595 ledma
= sparc32_dma_init(hwdef
->dma_base
+ 16ULL,
1596 slavio_irq
[3], iommu
, &ledma_irq
);
1598 if (graphic_depth
!= 8 && graphic_depth
!= 24) {
1599 fprintf(stderr
, "qemu: Unsupported depth: %d\n", graphic_depth
);
1602 tcx_init(hwdef
->tcx_base
, 0x00100000, graphic_width
, graphic_height
,
1605 lance_init(&nd_table
[0], hwdef
->le_base
, ledma
, ledma_irq
);
1607 nvram
= m48t59_init(slavio_irq
[0], hwdef
->nvram_base
, 0, 0x800, 2);
1609 slavio_serial_ms_kbd_init(hwdef
->ms_kb_base
, slavio_irq
[1],
1610 display_type
== DT_NOGRAPHIC
, ESCC_CLOCK
, 1);
1611 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
1612 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
1613 escc_init(hwdef
->serial_base
, slavio_irq
[1],
1614 slavio_irq
[1], serial_hds
[0], serial_hds
[1],
1617 slavio_misc_init(0, hwdef
->aux1_base
, 0, slavio_irq
[1], fdc_tc
);
1619 if (hwdef
->fd_base
!= (target_phys_addr_t
)-1) {
1620 /* there is zero or one floppy drive */
1621 memset(fd
, 0, sizeof(fd
));
1622 dinfo
= drive_get(IF_FLOPPY
, 0, 0);
1624 fd
[0] = dinfo
->bdrv
;
1626 sun4m_fdctrl_init(slavio_irq
[1], hwdef
->fd_base
, fd
,
1630 if (drive_get_max_bus(IF_SCSI
) > 0) {
1631 fprintf(stderr
, "qemu: too many SCSI bus\n");
1635 esp_reset
= qdev_get_gpio_in(espdma
, 0);
1636 esp_init(hwdef
->esp_base
, 2,
1637 espdma_memory_read
, espdma_memory_write
,
1638 espdma
, espdma_irq
, &esp_reset
);
1640 kernel_size
= sun4m_load_kernel(kernel_filename
, initrd_filename
,
1643 nvram_init(nvram
, (uint8_t *)&nd_table
[0].macaddr
, kernel_cmdline
,
1644 boot_device
, RAM_size
, kernel_size
, graphic_width
,
1645 graphic_height
, graphic_depth
, hwdef
->nvram_machine_id
,
1648 fw_cfg
= fw_cfg_init(0, 0, CFG_ADDR
, CFG_ADDR
+ 2);
1649 fw_cfg_add_i32(fw_cfg
, FW_CFG_ID
, 1);
1650 fw_cfg_add_i64(fw_cfg
, FW_CFG_RAM_SIZE
, (uint64_t)ram_size
);
1651 fw_cfg_add_i16(fw_cfg
, FW_CFG_MACHINE_ID
, hwdef
->machine_id
);
1652 fw_cfg_add_i16(fw_cfg
, FW_CFG_SUN4M_DEPTH
, graphic_depth
);
1653 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_ADDR
, KERNEL_LOAD_ADDR
);
1654 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_SIZE
, kernel_size
);
1655 if (kernel_cmdline
) {
1656 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_CMDLINE
, CMDLINE_ADDR
);
1657 pstrcpy_targphys(CMDLINE_ADDR
, TARGET_PAGE_SIZE
, kernel_cmdline
);
1659 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_CMDLINE
, 0);
1661 fw_cfg_add_i32(fw_cfg
, FW_CFG_INITRD_ADDR
, INITRD_LOAD_ADDR
);
1662 fw_cfg_add_i32(fw_cfg
, FW_CFG_INITRD_SIZE
, 0); // not used
1663 fw_cfg_add_i16(fw_cfg
, FW_CFG_BOOT_DEVICE
, boot_device
[0]);
1664 qemu_register_boot_set(fw_cfg_boot_set
, fw_cfg
);
1667 /* SPARCstation 2 hardware initialisation */
1668 static void ss2_init(ram_addr_t RAM_size
,
1669 const char *boot_device
,
1670 const char *kernel_filename
, const char *kernel_cmdline
,
1671 const char *initrd_filename
, const char *cpu_model
)
1673 sun4c_hw_init(&sun4c_hwdefs
[0], RAM_size
, boot_device
, kernel_filename
,
1674 kernel_cmdline
, initrd_filename
, cpu_model
);
1677 static QEMUMachine ss2_machine
= {
1679 .desc
= "Sun4c platform, SPARCstation 2",
1684 static void ss2_machine_init(void)
1686 qemu_register_machine(&ss5_machine
);
1687 qemu_register_machine(&ss10_machine
);
1688 qemu_register_machine(&ss600mp_machine
);
1689 qemu_register_machine(&ss20_machine
);
1690 qemu_register_machine(&voyager_machine
);
1691 qemu_register_machine(&ss_lx_machine
);
1692 qemu_register_machine(&ss4_machine
);
1693 qemu_register_machine(&scls_machine
);
1694 qemu_register_machine(&sbook_machine
);
1695 qemu_register_machine(&ss1000_machine
);
1696 qemu_register_machine(&ss2000_machine
);
1697 qemu_register_machine(&ss2_machine
);
1700 machine_init(ss2_machine_init
);