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 "empty_slot.h"
40 #include "qdev-addr.h"
47 * Sun4m architecture was used in the following machines:
49 * SPARCserver 6xxMP/xx
50 * SPARCclassic (SPARCclassic Server)(SPARCstation LC) (4/15),
51 * SPARCclassic X (4/10)
52 * SPARCstation LX/ZX (4/30)
53 * SPARCstation Voyager
54 * SPARCstation 10/xx, SPARCserver 10/xx
55 * SPARCstation 5, SPARCserver 5
56 * SPARCstation 20/xx, SPARCserver 20
59 * Sun4d architecture was used in the following machines:
64 * Sun4c architecture was used in the following machines:
65 * SPARCstation 1/1+, SPARCserver 1/1+
71 * See for example: http://www.sunhelp.org/faq/sunref1.html
74 #define KERNEL_LOAD_ADDR 0x00004000
75 #define CMDLINE_ADDR 0x007ff000
76 #define INITRD_LOAD_ADDR 0x00800000
77 #define PROM_SIZE_MAX (1024 * 1024)
78 #define PROM_VADDR 0xffd00000
79 #define PROM_FILENAME "openbios-sparc32"
80 #define CFG_ADDR 0xd00000510ULL
81 #define FW_CFG_SUN4M_DEPTH (FW_CFG_ARCH_LOCAL + 0x00)
87 #define ESCC_CLOCK 4915200
90 hwaddr iommu_base
, iommu_pad_base
, iommu_pad_len
, slavio_base
;
91 hwaddr intctl_base
, counter_base
, nvram_base
, ms_kb_base
;
92 hwaddr serial_base
, fd_base
;
93 hwaddr afx_base
, idreg_base
, dma_base
, esp_base
, le_base
;
94 hwaddr tcx_base
, cs_base
, apc_base
, aux1_base
, aux2_base
;
95 hwaddr bpp_base
, dbri_base
, sx_base
;
97 hwaddr reg_base
, vram_base
;
101 const char * const default_cpu_model
;
102 uint32_t ecc_version
;
103 uint32_t iommu_version
;
105 uint8_t nvram_machine_id
;
108 #define MAX_IOUNITS 5
111 hwaddr iounit_bases
[MAX_IOUNITS
], slavio_base
;
112 hwaddr counter_base
, nvram_base
, ms_kb_base
;
114 hwaddr espdma_base
, esp_base
;
115 hwaddr ledma_base
, le_base
;
119 const char * const default_cpu_model
;
120 uint32_t iounit_version
;
122 uint8_t nvram_machine_id
;
126 hwaddr iommu_base
, slavio_base
;
127 hwaddr intctl_base
, counter_base
, nvram_base
, ms_kb_base
;
128 hwaddr serial_base
, fd_base
;
129 hwaddr idreg_base
, dma_base
, esp_base
, le_base
;
130 hwaddr tcx_base
, aux1_base
;
132 const char * const default_cpu_model
;
133 uint32_t iommu_version
;
135 uint8_t nvram_machine_id
;
138 int DMA_get_channel_mode (int nchan
)
142 int DMA_read_memory (int nchan
, void *buf
, int pos
, int size
)
146 int DMA_write_memory (int nchan
, void *buf
, int pos
, int size
)
150 void DMA_hold_DREQ (int nchan
) {}
151 void DMA_release_DREQ (int nchan
) {}
152 void DMA_schedule(int nchan
) {}
154 void DMA_init(int high_page_enable
, qemu_irq
*cpu_request_exit
)
158 void DMA_register_channel (int nchan
,
159 DMA_transfer_handler transfer_handler
,
164 static int fw_cfg_boot_set(void *opaque
, const char *boot_device
)
166 fw_cfg_add_i16(opaque
, FW_CFG_BOOT_DEVICE
, boot_device
[0]);
170 static void nvram_init(M48t59State
*nvram
, uint8_t *macaddr
,
171 const char *cmdline
, const char *boot_devices
,
172 ram_addr_t RAM_size
, uint32_t kernel_size
,
173 int width
, int height
, int depth
,
174 int nvram_machine_id
, const char *arch
)
178 uint8_t image
[0x1ff0];
179 struct OpenBIOS_nvpart_v1
*part_header
;
181 memset(image
, '\0', sizeof(image
));
185 // OpenBIOS nvram variables
186 // Variable partition
187 part_header
= (struct OpenBIOS_nvpart_v1
*)&image
[start
];
188 part_header
->signature
= OPENBIOS_PART_SYSTEM
;
189 pstrcpy(part_header
->name
, sizeof(part_header
->name
), "system");
191 end
= start
+ sizeof(struct OpenBIOS_nvpart_v1
);
192 for (i
= 0; i
< nb_prom_envs
; i
++)
193 end
= OpenBIOS_set_var(image
, end
, prom_envs
[i
]);
198 end
= start
+ ((end
- start
+ 15) & ~15);
199 OpenBIOS_finish_partition(part_header
, end
- start
);
203 part_header
= (struct OpenBIOS_nvpart_v1
*)&image
[start
];
204 part_header
->signature
= OPENBIOS_PART_FREE
;
205 pstrcpy(part_header
->name
, sizeof(part_header
->name
), "free");
208 OpenBIOS_finish_partition(part_header
, end
- start
);
210 Sun_init_header((struct Sun_nvram
*)&image
[0x1fd8], macaddr
,
213 for (i
= 0; i
< sizeof(image
); i
++)
214 m48t59_write(nvram
, i
, image
[i
]);
217 static DeviceState
*slavio_intctl
;
219 void sun4m_pic_info(Monitor
*mon
)
222 slavio_pic_info(mon
, slavio_intctl
);
225 void sun4m_irq_info(Monitor
*mon
)
228 slavio_irq_info(mon
, slavio_intctl
);
231 void cpu_check_irqs(CPUSPARCState
*env
)
233 if (env
->pil_in
&& (env
->interrupt_index
== 0 ||
234 (env
->interrupt_index
& ~15) == TT_EXTINT
)) {
237 for (i
= 15; i
> 0; i
--) {
238 if (env
->pil_in
& (1 << i
)) {
239 int old_interrupt
= env
->interrupt_index
;
241 env
->interrupt_index
= TT_EXTINT
| i
;
242 if (old_interrupt
!= env
->interrupt_index
) {
243 trace_sun4m_cpu_interrupt(i
);
244 cpu_interrupt(env
, CPU_INTERRUPT_HARD
);
249 } else if (!env
->pil_in
&& (env
->interrupt_index
& ~15) == TT_EXTINT
) {
250 trace_sun4m_cpu_reset_interrupt(env
->interrupt_index
& 15);
251 env
->interrupt_index
= 0;
252 cpu_reset_interrupt(env
, CPU_INTERRUPT_HARD
);
256 static void cpu_kick_irq(SPARCCPU
*cpu
)
258 CPUSPARCState
*env
= &cpu
->env
;
262 qemu_cpu_kick(CPU(cpu
));
265 static void cpu_set_irq(void *opaque
, int irq
, int level
)
267 SPARCCPU
*cpu
= opaque
;
268 CPUSPARCState
*env
= &cpu
->env
;
271 trace_sun4m_cpu_set_irq_raise(irq
);
272 env
->pil_in
|= 1 << irq
;
275 trace_sun4m_cpu_set_irq_lower(irq
);
276 env
->pil_in
&= ~(1 << irq
);
281 static void dummy_cpu_set_irq(void *opaque
, int irq
, int level
)
285 static void main_cpu_reset(void *opaque
)
287 SPARCCPU
*cpu
= opaque
;
288 CPUSPARCState
*env
= &cpu
->env
;
294 static void secondary_cpu_reset(void *opaque
)
296 SPARCCPU
*cpu
= opaque
;
297 CPUSPARCState
*env
= &cpu
->env
;
303 static void cpu_halt_signal(void *opaque
, int irq
, int level
)
305 if (level
&& cpu_single_env
)
306 cpu_interrupt(cpu_single_env
, CPU_INTERRUPT_HALT
);
309 static uint64_t translate_kernel_address(void *opaque
, uint64_t addr
)
311 return addr
- 0xf0000000ULL
;
314 static unsigned long sun4m_load_kernel(const char *kernel_filename
,
315 const char *initrd_filename
,
320 long initrd_size
, kernel_size
;
323 linux_boot
= (kernel_filename
!= NULL
);
334 kernel_size
= load_elf(kernel_filename
, translate_kernel_address
, NULL
,
335 NULL
, NULL
, NULL
, 1, ELF_MACHINE
, 0);
337 kernel_size
= load_aout(kernel_filename
, KERNEL_LOAD_ADDR
,
338 RAM_size
- KERNEL_LOAD_ADDR
, bswap_needed
,
341 kernel_size
= load_image_targphys(kernel_filename
,
343 RAM_size
- KERNEL_LOAD_ADDR
);
344 if (kernel_size
< 0) {
345 fprintf(stderr
, "qemu: could not load kernel '%s'\n",
352 if (initrd_filename
) {
353 initrd_size
= load_image_targphys(initrd_filename
,
355 RAM_size
- INITRD_LOAD_ADDR
);
356 if (initrd_size
< 0) {
357 fprintf(stderr
, "qemu: could not load initial ram disk '%s'\n",
362 if (initrd_size
> 0) {
363 for (i
= 0; i
< 64 * TARGET_PAGE_SIZE
; i
+= TARGET_PAGE_SIZE
) {
364 ptr
= rom_ptr(KERNEL_LOAD_ADDR
+ i
);
365 if (ldl_p(ptr
) == 0x48647253) { // HdrS
366 stl_p(ptr
+ 16, INITRD_LOAD_ADDR
);
367 stl_p(ptr
+ 20, initrd_size
);
376 static void *iommu_init(hwaddr addr
, uint32_t version
, qemu_irq irq
)
381 dev
= qdev_create(NULL
, "iommu");
382 qdev_prop_set_uint32(dev
, "version", version
);
383 qdev_init_nofail(dev
);
384 s
= sysbus_from_qdev(dev
);
385 sysbus_connect_irq(s
, 0, irq
);
386 sysbus_mmio_map(s
, 0, addr
);
391 static void *sparc32_dma_init(hwaddr daddr
, qemu_irq parent_irq
,
392 void *iommu
, qemu_irq
*dev_irq
, int is_ledma
)
397 dev
= qdev_create(NULL
, "sparc32_dma");
398 qdev_prop_set_ptr(dev
, "iommu_opaque", iommu
);
399 qdev_prop_set_uint32(dev
, "is_ledma", is_ledma
);
400 qdev_init_nofail(dev
);
401 s
= sysbus_from_qdev(dev
);
402 sysbus_connect_irq(s
, 0, parent_irq
);
403 *dev_irq
= qdev_get_gpio_in(dev
, 0);
404 sysbus_mmio_map(s
, 0, daddr
);
409 static void lance_init(NICInfo
*nd
, hwaddr leaddr
,
410 void *dma_opaque
, qemu_irq irq
)
416 qemu_check_nic_model(&nd_table
[0], "lance");
418 dev
= qdev_create(NULL
, "lance");
419 qdev_set_nic_properties(dev
, nd
);
420 qdev_prop_set_ptr(dev
, "dma", dma_opaque
);
421 qdev_init_nofail(dev
);
422 s
= sysbus_from_qdev(dev
);
423 sysbus_mmio_map(s
, 0, leaddr
);
424 sysbus_connect_irq(s
, 0, irq
);
425 reset
= qdev_get_gpio_in(dev
, 0);
426 qdev_connect_gpio_out(dma_opaque
, 0, reset
);
429 static DeviceState
*slavio_intctl_init(hwaddr addr
,
431 qemu_irq
**parent_irq
)
437 dev
= qdev_create(NULL
, "slavio_intctl");
438 qdev_init_nofail(dev
);
440 s
= sysbus_from_qdev(dev
);
442 for (i
= 0; i
< MAX_CPUS
; i
++) {
443 for (j
= 0; j
< MAX_PILS
; j
++) {
444 sysbus_connect_irq(s
, i
* MAX_PILS
+ j
, parent_irq
[i
][j
]);
447 sysbus_mmio_map(s
, 0, addrg
);
448 for (i
= 0; i
< MAX_CPUS
; i
++) {
449 sysbus_mmio_map(s
, i
+ 1, addr
+ i
* TARGET_PAGE_SIZE
);
455 #define SYS_TIMER_OFFSET 0x10000ULL
456 #define CPU_TIMER_OFFSET(cpu) (0x1000ULL * cpu)
458 static void slavio_timer_init_all(hwaddr addr
, qemu_irq master_irq
,
459 qemu_irq
*cpu_irqs
, unsigned int num_cpus
)
465 dev
= qdev_create(NULL
, "slavio_timer");
466 qdev_prop_set_uint32(dev
, "num_cpus", num_cpus
);
467 qdev_init_nofail(dev
);
468 s
= sysbus_from_qdev(dev
);
469 sysbus_connect_irq(s
, 0, master_irq
);
470 sysbus_mmio_map(s
, 0, addr
+ SYS_TIMER_OFFSET
);
472 for (i
= 0; i
< MAX_CPUS
; i
++) {
473 sysbus_mmio_map(s
, i
+ 1, addr
+ (hwaddr
)CPU_TIMER_OFFSET(i
));
474 sysbus_connect_irq(s
, i
+ 1, cpu_irqs
[i
]);
478 static qemu_irq slavio_system_powerdown
;
480 static void slavio_powerdown_req(Notifier
*n
, void *opaque
)
482 qemu_irq_raise(slavio_system_powerdown
);
485 static Notifier slavio_system_powerdown_notifier
= {
486 .notify
= slavio_powerdown_req
489 #define MISC_LEDS 0x01600000
490 #define MISC_CFG 0x01800000
491 #define MISC_DIAG 0x01a00000
492 #define MISC_MDM 0x01b00000
493 #define MISC_SYS 0x01f00000
495 static void slavio_misc_init(hwaddr base
,
497 hwaddr aux2_base
, qemu_irq irq
,
503 dev
= qdev_create(NULL
, "slavio_misc");
504 qdev_init_nofail(dev
);
505 s
= sysbus_from_qdev(dev
);
507 /* 8 bit registers */
509 sysbus_mmio_map(s
, 0, base
+ MISC_CFG
);
511 sysbus_mmio_map(s
, 1, base
+ MISC_DIAG
);
513 sysbus_mmio_map(s
, 2, base
+ MISC_MDM
);
514 /* 16 bit registers */
515 /* ss600mp diag LEDs */
516 sysbus_mmio_map(s
, 3, base
+ MISC_LEDS
);
517 /* 32 bit registers */
519 sysbus_mmio_map(s
, 4, base
+ MISC_SYS
);
522 /* AUX 1 (Misc System Functions) */
523 sysbus_mmio_map(s
, 5, aux1_base
);
526 /* AUX 2 (Software Powerdown Control) */
527 sysbus_mmio_map(s
, 6, aux2_base
);
529 sysbus_connect_irq(s
, 0, irq
);
530 sysbus_connect_irq(s
, 1, fdc_tc
);
531 slavio_system_powerdown
= qdev_get_gpio_in(dev
, 0);
532 qemu_register_powerdown_notifier(&slavio_system_powerdown_notifier
);
535 static void ecc_init(hwaddr base
, qemu_irq irq
, uint32_t version
)
540 dev
= qdev_create(NULL
, "eccmemctl");
541 qdev_prop_set_uint32(dev
, "version", version
);
542 qdev_init_nofail(dev
);
543 s
= sysbus_from_qdev(dev
);
544 sysbus_connect_irq(s
, 0, irq
);
545 sysbus_mmio_map(s
, 0, base
);
546 if (version
== 0) { // SS-600MP only
547 sysbus_mmio_map(s
, 1, base
+ 0x1000);
551 static void apc_init(hwaddr power_base
, qemu_irq cpu_halt
)
556 dev
= qdev_create(NULL
, "apc");
557 qdev_init_nofail(dev
);
558 s
= sysbus_from_qdev(dev
);
559 /* Power management (APC) XXX: not a Slavio device */
560 sysbus_mmio_map(s
, 0, power_base
);
561 sysbus_connect_irq(s
, 0, cpu_halt
);
564 static void tcx_init(hwaddr addr
, int vram_size
, int width
,
565 int height
, int depth
)
570 dev
= qdev_create(NULL
, "SUNW,tcx");
571 qdev_prop_set_taddr(dev
, "addr", addr
);
572 qdev_prop_set_uint32(dev
, "vram_size", vram_size
);
573 qdev_prop_set_uint16(dev
, "width", width
);
574 qdev_prop_set_uint16(dev
, "height", height
);
575 qdev_prop_set_uint16(dev
, "depth", depth
);
576 qdev_init_nofail(dev
);
577 s
= sysbus_from_qdev(dev
);
579 sysbus_mmio_map(s
, 0, addr
+ 0x00800000ULL
);
581 sysbus_mmio_map(s
, 1, addr
+ 0x00200000ULL
);
583 sysbus_mmio_map(s
, 2, addr
+ 0x00700000ULL
);
584 /* THC 24 bit: NetBSD writes here even with 8-bit display: dummy */
585 sysbus_mmio_map(s
, 3, addr
+ 0x00301000ULL
);
588 sysbus_mmio_map(s
, 4, addr
+ 0x02000000ULL
);
590 sysbus_mmio_map(s
, 5, addr
+ 0x0a000000ULL
);
592 /* THC 8 bit (dummy) */
593 sysbus_mmio_map(s
, 4, addr
+ 0x00300000ULL
);
597 /* NCR89C100/MACIO Internal ID register */
598 static const uint8_t idreg_data
[] = { 0xfe, 0x81, 0x01, 0x03 };
600 static void idreg_init(hwaddr addr
)
605 dev
= qdev_create(NULL
, "macio_idreg");
606 qdev_init_nofail(dev
);
607 s
= sysbus_from_qdev(dev
);
609 sysbus_mmio_map(s
, 0, addr
);
610 cpu_physical_memory_write_rom(addr
, idreg_data
, sizeof(idreg_data
));
613 typedef struct IDRegState
{
618 static int idreg_init1(SysBusDevice
*dev
)
620 IDRegState
*s
= FROM_SYSBUS(IDRegState
, dev
);
622 memory_region_init_ram(&s
->mem
, "sun4m.idreg", sizeof(idreg_data
));
623 vmstate_register_ram_global(&s
->mem
);
624 memory_region_set_readonly(&s
->mem
, true);
625 sysbus_init_mmio(dev
, &s
->mem
);
629 static void idreg_class_init(ObjectClass
*klass
, void *data
)
631 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
633 k
->init
= idreg_init1
;
636 static TypeInfo idreg_info
= {
637 .name
= "macio_idreg",
638 .parent
= TYPE_SYS_BUS_DEVICE
,
639 .instance_size
= sizeof(IDRegState
),
640 .class_init
= idreg_class_init
,
643 typedef struct AFXState
{
648 /* SS-5 TCX AFX register */
649 static void afx_init(hwaddr addr
)
654 dev
= qdev_create(NULL
, "tcx_afx");
655 qdev_init_nofail(dev
);
656 s
= sysbus_from_qdev(dev
);
658 sysbus_mmio_map(s
, 0, addr
);
661 static int afx_init1(SysBusDevice
*dev
)
663 AFXState
*s
= FROM_SYSBUS(AFXState
, dev
);
665 memory_region_init_ram(&s
->mem
, "sun4m.afx", 4);
666 vmstate_register_ram_global(&s
->mem
);
667 sysbus_init_mmio(dev
, &s
->mem
);
671 static void afx_class_init(ObjectClass
*klass
, void *data
)
673 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
678 static TypeInfo afx_info
= {
680 .parent
= TYPE_SYS_BUS_DEVICE
,
681 .instance_size
= sizeof(AFXState
),
682 .class_init
= afx_class_init
,
685 typedef struct PROMState
{
690 /* Boot PROM (OpenBIOS) */
691 static uint64_t translate_prom_address(void *opaque
, uint64_t addr
)
693 hwaddr
*base_addr
= (hwaddr
*)opaque
;
694 return addr
+ *base_addr
- PROM_VADDR
;
697 static void prom_init(hwaddr addr
, const char *bios_name
)
704 dev
= qdev_create(NULL
, "openprom");
705 qdev_init_nofail(dev
);
706 s
= sysbus_from_qdev(dev
);
708 sysbus_mmio_map(s
, 0, addr
);
711 if (bios_name
== NULL
) {
712 bios_name
= PROM_FILENAME
;
714 filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, bios_name
);
716 ret
= load_elf(filename
, translate_prom_address
, &addr
, NULL
,
717 NULL
, NULL
, 1, ELF_MACHINE
, 0);
718 if (ret
< 0 || ret
> PROM_SIZE_MAX
) {
719 ret
= load_image_targphys(filename
, addr
, PROM_SIZE_MAX
);
725 if (ret
< 0 || ret
> PROM_SIZE_MAX
) {
726 fprintf(stderr
, "qemu: could not load prom '%s'\n", bios_name
);
731 static int prom_init1(SysBusDevice
*dev
)
733 PROMState
*s
= FROM_SYSBUS(PROMState
, dev
);
735 memory_region_init_ram(&s
->prom
, "sun4m.prom", PROM_SIZE_MAX
);
736 vmstate_register_ram_global(&s
->prom
);
737 memory_region_set_readonly(&s
->prom
, true);
738 sysbus_init_mmio(dev
, &s
->prom
);
742 static Property prom_properties
[] = {
743 {/* end of property list */},
746 static void prom_class_init(ObjectClass
*klass
, void *data
)
748 DeviceClass
*dc
= DEVICE_CLASS(klass
);
749 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
751 k
->init
= prom_init1
;
752 dc
->props
= prom_properties
;
755 static TypeInfo prom_info
= {
757 .parent
= TYPE_SYS_BUS_DEVICE
,
758 .instance_size
= sizeof(PROMState
),
759 .class_init
= prom_class_init
,
762 typedef struct RamDevice
770 static int ram_init1(SysBusDevice
*dev
)
772 RamDevice
*d
= FROM_SYSBUS(RamDevice
, dev
);
774 memory_region_init_ram(&d
->ram
, "sun4m.ram", d
->size
);
775 vmstate_register_ram_global(&d
->ram
);
776 sysbus_init_mmio(dev
, &d
->ram
);
780 static void ram_init(hwaddr addr
, ram_addr_t RAM_size
,
788 if ((uint64_t)RAM_size
> max_mem
) {
790 "qemu: Too much memory for this machine: %d, maximum %d\n",
791 (unsigned int)(RAM_size
/ (1024 * 1024)),
792 (unsigned int)(max_mem
/ (1024 * 1024)));
795 dev
= qdev_create(NULL
, "memory");
796 s
= sysbus_from_qdev(dev
);
798 d
= FROM_SYSBUS(RamDevice
, s
);
800 qdev_init_nofail(dev
);
802 sysbus_mmio_map(s
, 0, addr
);
805 static Property ram_properties
[] = {
806 DEFINE_PROP_UINT64("size", RamDevice
, size
, 0),
807 DEFINE_PROP_END_OF_LIST(),
810 static void ram_class_init(ObjectClass
*klass
, void *data
)
812 DeviceClass
*dc
= DEVICE_CLASS(klass
);
813 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
816 dc
->props
= ram_properties
;
819 static TypeInfo ram_info
= {
821 .parent
= TYPE_SYS_BUS_DEVICE
,
822 .instance_size
= sizeof(RamDevice
),
823 .class_init
= ram_class_init
,
826 static void cpu_devinit(const char *cpu_model
, unsigned int id
,
827 uint64_t prom_addr
, qemu_irq
**cpu_irqs
)
832 cpu
= cpu_sparc_init(cpu_model
);
834 fprintf(stderr
, "qemu: Unable to find Sparc CPU definition\n");
839 cpu_sparc_set_id(env
, id
);
841 qemu_register_reset(main_cpu_reset
, cpu
);
843 qemu_register_reset(secondary_cpu_reset
, cpu
);
846 *cpu_irqs
= qemu_allocate_irqs(cpu_set_irq
, cpu
, MAX_PILS
);
847 env
->prom_addr
= prom_addr
;
850 static void dummy_fdc_tc(void *opaque
, int irq
, int level
)
854 static void sun4m_hw_init(const struct sun4m_hwdef
*hwdef
, ram_addr_t RAM_size
,
855 const char *boot_device
,
856 const char *kernel_filename
,
857 const char *kernel_cmdline
,
858 const char *initrd_filename
, const char *cpu_model
)
861 void *iommu
, *espdma
, *ledma
, *nvram
;
862 qemu_irq
*cpu_irqs
[MAX_CPUS
], slavio_irq
[32], slavio_cpu_irq
[MAX_CPUS
],
863 espdma_irq
, ledma_irq
;
864 qemu_irq esp_reset
, dma_enable
;
867 unsigned long kernel_size
;
868 DriveInfo
*fd
[MAX_FD
];
870 unsigned int num_vsimms
;
874 cpu_model
= hwdef
->default_cpu_model
;
876 for(i
= 0; i
< smp_cpus
; i
++) {
877 cpu_devinit(cpu_model
, i
, hwdef
->slavio_base
, &cpu_irqs
[i
]);
880 for (i
= smp_cpus
; i
< MAX_CPUS
; i
++)
881 cpu_irqs
[i
] = qemu_allocate_irqs(dummy_cpu_set_irq
, NULL
, MAX_PILS
);
885 ram_init(0, RAM_size
, hwdef
->max_mem
);
886 /* models without ECC don't trap when missing ram is accessed */
887 if (!hwdef
->ecc_base
) {
888 empty_slot_init(RAM_size
, hwdef
->max_mem
- RAM_size
);
891 prom_init(hwdef
->slavio_base
, bios_name
);
893 slavio_intctl
= slavio_intctl_init(hwdef
->intctl_base
,
894 hwdef
->intctl_base
+ 0x10000ULL
,
897 for (i
= 0; i
< 32; i
++) {
898 slavio_irq
[i
] = qdev_get_gpio_in(slavio_intctl
, i
);
900 for (i
= 0; i
< MAX_CPUS
; i
++) {
901 slavio_cpu_irq
[i
] = qdev_get_gpio_in(slavio_intctl
, 32 + i
);
904 if (hwdef
->idreg_base
) {
905 idreg_init(hwdef
->idreg_base
);
908 if (hwdef
->afx_base
) {
909 afx_init(hwdef
->afx_base
);
912 iommu
= iommu_init(hwdef
->iommu_base
, hwdef
->iommu_version
,
915 if (hwdef
->iommu_pad_base
) {
916 /* On the real hardware (SS-5, LX) the MMU is not padded, but aliased.
917 Software shouldn't use aliased addresses, neither should it crash
918 when does. Using empty_slot instead of aliasing can help with
919 debugging such accesses */
920 empty_slot_init(hwdef
->iommu_pad_base
,hwdef
->iommu_pad_len
);
923 espdma
= sparc32_dma_init(hwdef
->dma_base
, slavio_irq
[18],
924 iommu
, &espdma_irq
, 0);
926 ledma
= sparc32_dma_init(hwdef
->dma_base
+ 16ULL,
927 slavio_irq
[16], iommu
, &ledma_irq
, 1);
929 if (graphic_depth
!= 8 && graphic_depth
!= 24) {
930 fprintf(stderr
, "qemu: Unsupported depth: %d\n", graphic_depth
);
934 if (num_vsimms
== 0) {
935 tcx_init(hwdef
->tcx_base
, 0x00100000, graphic_width
, graphic_height
,
939 for (i
= num_vsimms
; i
< MAX_VSIMMS
; i
++) {
940 /* vsimm registers probed by OBP */
941 if (hwdef
->vsimm
[i
].reg_base
) {
942 empty_slot_init(hwdef
->vsimm
[i
].reg_base
, 0x2000);
946 if (hwdef
->sx_base
) {
947 empty_slot_init(hwdef
->sx_base
, 0x2000);
950 lance_init(&nd_table
[0], hwdef
->le_base
, ledma
, ledma_irq
);
952 nvram
= m48t59_init(slavio_irq
[0], hwdef
->nvram_base
, 0, 0x2000, 8);
954 slavio_timer_init_all(hwdef
->counter_base
, slavio_irq
[19], slavio_cpu_irq
, smp_cpus
);
956 slavio_serial_ms_kbd_init(hwdef
->ms_kb_base
, slavio_irq
[14],
957 display_type
== DT_NOGRAPHIC
, ESCC_CLOCK
, 1);
958 /* Slavio TTYA (base+4, Linux ttyS0) is the first QEMU serial device
959 Slavio TTYB (base+0, Linux ttyS1) is the second QEMU serial device */
960 escc_init(hwdef
->serial_base
, slavio_irq
[15], slavio_irq
[15],
961 serial_hds
[0], serial_hds
[1], ESCC_CLOCK
, 1);
963 cpu_halt
= qemu_allocate_irqs(cpu_halt_signal
, NULL
, 1);
964 if (hwdef
->apc_base
) {
965 apc_init(hwdef
->apc_base
, cpu_halt
[0]);
968 if (hwdef
->fd_base
) {
969 /* there is zero or one floppy drive */
970 memset(fd
, 0, sizeof(fd
));
971 fd
[0] = drive_get(IF_FLOPPY
, 0, 0);
972 sun4m_fdctrl_init(slavio_irq
[22], hwdef
->fd_base
, fd
,
975 fdc_tc
= *qemu_allocate_irqs(dummy_fdc_tc
, NULL
, 1);
978 slavio_misc_init(hwdef
->slavio_base
, hwdef
->aux1_base
, hwdef
->aux2_base
,
979 slavio_irq
[30], fdc_tc
);
981 if (drive_get_max_bus(IF_SCSI
) > 0) {
982 fprintf(stderr
, "qemu: too many SCSI bus\n");
986 esp_init(hwdef
->esp_base
, 2,
987 espdma_memory_read
, espdma_memory_write
,
988 espdma
, espdma_irq
, &esp_reset
, &dma_enable
);
990 qdev_connect_gpio_out(espdma
, 0, esp_reset
);
991 qdev_connect_gpio_out(espdma
, 1, dma_enable
);
993 if (hwdef
->cs_base
) {
994 sysbus_create_simple("SUNW,CS4231", hwdef
->cs_base
,
998 if (hwdef
->dbri_base
) {
999 /* ISDN chip with attached CS4215 audio codec */
1001 empty_slot_init(hwdef
->dbri_base
+0x1000, 0x30);
1003 empty_slot_init(hwdef
->dbri_base
+0x10000, 0x100);
1006 if (hwdef
->bpp_base
) {
1008 empty_slot_init(hwdef
->bpp_base
, 0x20);
1011 kernel_size
= sun4m_load_kernel(kernel_filename
, initrd_filename
,
1014 nvram_init(nvram
, (uint8_t *)&nd_table
[0].macaddr
, kernel_cmdline
,
1015 boot_device
, RAM_size
, kernel_size
, graphic_width
,
1016 graphic_height
, graphic_depth
, hwdef
->nvram_machine_id
,
1019 if (hwdef
->ecc_base
)
1020 ecc_init(hwdef
->ecc_base
, slavio_irq
[28],
1021 hwdef
->ecc_version
);
1023 fw_cfg
= fw_cfg_init(0, 0, CFG_ADDR
, CFG_ADDR
+ 2);
1024 fw_cfg_add_i32(fw_cfg
, FW_CFG_ID
, 1);
1025 fw_cfg_add_i64(fw_cfg
, FW_CFG_RAM_SIZE
, (uint64_t)ram_size
);
1026 fw_cfg_add_i16(fw_cfg
, FW_CFG_MACHINE_ID
, hwdef
->machine_id
);
1027 fw_cfg_add_i16(fw_cfg
, FW_CFG_SUN4M_DEPTH
, graphic_depth
);
1028 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_ADDR
, KERNEL_LOAD_ADDR
);
1029 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_SIZE
, kernel_size
);
1030 if (kernel_cmdline
) {
1031 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_CMDLINE
, CMDLINE_ADDR
);
1032 pstrcpy_targphys("cmdline", CMDLINE_ADDR
, TARGET_PAGE_SIZE
, kernel_cmdline
);
1033 fw_cfg_add_bytes(fw_cfg
, FW_CFG_CMDLINE_DATA
,
1034 (uint8_t*)strdup(kernel_cmdline
),
1035 strlen(kernel_cmdline
) + 1);
1036 fw_cfg_add_i32(fw_cfg
, FW_CFG_CMDLINE_SIZE
,
1037 strlen(kernel_cmdline
) + 1);
1039 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_CMDLINE
, 0);
1040 fw_cfg_add_i32(fw_cfg
, FW_CFG_CMDLINE_SIZE
, 0);
1042 fw_cfg_add_i32(fw_cfg
, FW_CFG_INITRD_ADDR
, INITRD_LOAD_ADDR
);
1043 fw_cfg_add_i32(fw_cfg
, FW_CFG_INITRD_SIZE
, 0); // not used
1044 fw_cfg_add_i16(fw_cfg
, FW_CFG_BOOT_DEVICE
, boot_device
[0]);
1045 qemu_register_boot_set(fw_cfg_boot_set
, fw_cfg
);
1063 static const struct sun4m_hwdef sun4m_hwdefs
[] = {
1066 .iommu_base
= 0x10000000,
1067 .iommu_pad_base
= 0x10004000,
1068 .iommu_pad_len
= 0x0fffb000,
1069 .tcx_base
= 0x50000000,
1070 .cs_base
= 0x6c000000,
1071 .slavio_base
= 0x70000000,
1072 .ms_kb_base
= 0x71000000,
1073 .serial_base
= 0x71100000,
1074 .nvram_base
= 0x71200000,
1075 .fd_base
= 0x71400000,
1076 .counter_base
= 0x71d00000,
1077 .intctl_base
= 0x71e00000,
1078 .idreg_base
= 0x78000000,
1079 .dma_base
= 0x78400000,
1080 .esp_base
= 0x78800000,
1081 .le_base
= 0x78c00000,
1082 .apc_base
= 0x6a000000,
1083 .afx_base
= 0x6e000000,
1084 .aux1_base
= 0x71900000,
1085 .aux2_base
= 0x71910000,
1086 .nvram_machine_id
= 0x80,
1087 .machine_id
= ss5_id
,
1088 .iommu_version
= 0x05000000,
1089 .max_mem
= 0x10000000,
1090 .default_cpu_model
= "Fujitsu MB86904",
1094 .iommu_base
= 0xfe0000000ULL
,
1095 .tcx_base
= 0xe20000000ULL
,
1096 .slavio_base
= 0xff0000000ULL
,
1097 .ms_kb_base
= 0xff1000000ULL
,
1098 .serial_base
= 0xff1100000ULL
,
1099 .nvram_base
= 0xff1200000ULL
,
1100 .fd_base
= 0xff1700000ULL
,
1101 .counter_base
= 0xff1300000ULL
,
1102 .intctl_base
= 0xff1400000ULL
,
1103 .idreg_base
= 0xef0000000ULL
,
1104 .dma_base
= 0xef0400000ULL
,
1105 .esp_base
= 0xef0800000ULL
,
1106 .le_base
= 0xef0c00000ULL
,
1107 .apc_base
= 0xefa000000ULL
, // XXX should not exist
1108 .aux1_base
= 0xff1800000ULL
,
1109 .aux2_base
= 0xff1a01000ULL
,
1110 .ecc_base
= 0xf00000000ULL
,
1111 .ecc_version
= 0x10000000, // version 0, implementation 1
1112 .nvram_machine_id
= 0x72,
1113 .machine_id
= ss10_id
,
1114 .iommu_version
= 0x03000000,
1115 .max_mem
= 0xf00000000ULL
,
1116 .default_cpu_model
= "TI SuperSparc II",
1120 .iommu_base
= 0xfe0000000ULL
,
1121 .tcx_base
= 0xe20000000ULL
,
1122 .slavio_base
= 0xff0000000ULL
,
1123 .ms_kb_base
= 0xff1000000ULL
,
1124 .serial_base
= 0xff1100000ULL
,
1125 .nvram_base
= 0xff1200000ULL
,
1126 .counter_base
= 0xff1300000ULL
,
1127 .intctl_base
= 0xff1400000ULL
,
1128 .dma_base
= 0xef0081000ULL
,
1129 .esp_base
= 0xef0080000ULL
,
1130 .le_base
= 0xef0060000ULL
,
1131 .apc_base
= 0xefa000000ULL
, // XXX should not exist
1132 .aux1_base
= 0xff1800000ULL
,
1133 .aux2_base
= 0xff1a01000ULL
, // XXX should not exist
1134 .ecc_base
= 0xf00000000ULL
,
1135 .ecc_version
= 0x00000000, // version 0, implementation 0
1136 .nvram_machine_id
= 0x71,
1137 .machine_id
= ss600mp_id
,
1138 .iommu_version
= 0x01000000,
1139 .max_mem
= 0xf00000000ULL
,
1140 .default_cpu_model
= "TI SuperSparc II",
1144 .iommu_base
= 0xfe0000000ULL
,
1145 .tcx_base
= 0xe20000000ULL
,
1146 .slavio_base
= 0xff0000000ULL
,
1147 .ms_kb_base
= 0xff1000000ULL
,
1148 .serial_base
= 0xff1100000ULL
,
1149 .nvram_base
= 0xff1200000ULL
,
1150 .fd_base
= 0xff1700000ULL
,
1151 .counter_base
= 0xff1300000ULL
,
1152 .intctl_base
= 0xff1400000ULL
,
1153 .idreg_base
= 0xef0000000ULL
,
1154 .dma_base
= 0xef0400000ULL
,
1155 .esp_base
= 0xef0800000ULL
,
1156 .le_base
= 0xef0c00000ULL
,
1157 .bpp_base
= 0xef4800000ULL
,
1158 .apc_base
= 0xefa000000ULL
, // XXX should not exist
1159 .aux1_base
= 0xff1800000ULL
,
1160 .aux2_base
= 0xff1a01000ULL
,
1161 .dbri_base
= 0xee0000000ULL
,
1162 .sx_base
= 0xf80000000ULL
,
1165 .reg_base
= 0x9c000000ULL
,
1166 .vram_base
= 0xfc000000ULL
1168 .reg_base
= 0x90000000ULL
,
1169 .vram_base
= 0xf0000000ULL
1171 .reg_base
= 0x94000000ULL
1173 .reg_base
= 0x98000000ULL
1176 .ecc_base
= 0xf00000000ULL
,
1177 .ecc_version
= 0x20000000, // version 0, implementation 2
1178 .nvram_machine_id
= 0x72,
1179 .machine_id
= ss20_id
,
1180 .iommu_version
= 0x13000000,
1181 .max_mem
= 0xf00000000ULL
,
1182 .default_cpu_model
= "TI SuperSparc II",
1186 .iommu_base
= 0x10000000,
1187 .tcx_base
= 0x50000000,
1188 .slavio_base
= 0x70000000,
1189 .ms_kb_base
= 0x71000000,
1190 .serial_base
= 0x71100000,
1191 .nvram_base
= 0x71200000,
1192 .fd_base
= 0x71400000,
1193 .counter_base
= 0x71d00000,
1194 .intctl_base
= 0x71e00000,
1195 .idreg_base
= 0x78000000,
1196 .dma_base
= 0x78400000,
1197 .esp_base
= 0x78800000,
1198 .le_base
= 0x78c00000,
1199 .apc_base
= 0x71300000, // pmc
1200 .aux1_base
= 0x71900000,
1201 .aux2_base
= 0x71910000,
1202 .nvram_machine_id
= 0x80,
1203 .machine_id
= vger_id
,
1204 .iommu_version
= 0x05000000,
1205 .max_mem
= 0x10000000,
1206 .default_cpu_model
= "Fujitsu MB86904",
1210 .iommu_base
= 0x10000000,
1211 .iommu_pad_base
= 0x10004000,
1212 .iommu_pad_len
= 0x0fffb000,
1213 .tcx_base
= 0x50000000,
1214 .slavio_base
= 0x70000000,
1215 .ms_kb_base
= 0x71000000,
1216 .serial_base
= 0x71100000,
1217 .nvram_base
= 0x71200000,
1218 .fd_base
= 0x71400000,
1219 .counter_base
= 0x71d00000,
1220 .intctl_base
= 0x71e00000,
1221 .idreg_base
= 0x78000000,
1222 .dma_base
= 0x78400000,
1223 .esp_base
= 0x78800000,
1224 .le_base
= 0x78c00000,
1225 .aux1_base
= 0x71900000,
1226 .aux2_base
= 0x71910000,
1227 .nvram_machine_id
= 0x80,
1228 .machine_id
= lx_id
,
1229 .iommu_version
= 0x04000000,
1230 .max_mem
= 0x10000000,
1231 .default_cpu_model
= "TI MicroSparc I",
1235 .iommu_base
= 0x10000000,
1236 .tcx_base
= 0x50000000,
1237 .cs_base
= 0x6c000000,
1238 .slavio_base
= 0x70000000,
1239 .ms_kb_base
= 0x71000000,
1240 .serial_base
= 0x71100000,
1241 .nvram_base
= 0x71200000,
1242 .fd_base
= 0x71400000,
1243 .counter_base
= 0x71d00000,
1244 .intctl_base
= 0x71e00000,
1245 .idreg_base
= 0x78000000,
1246 .dma_base
= 0x78400000,
1247 .esp_base
= 0x78800000,
1248 .le_base
= 0x78c00000,
1249 .apc_base
= 0x6a000000,
1250 .aux1_base
= 0x71900000,
1251 .aux2_base
= 0x71910000,
1252 .nvram_machine_id
= 0x80,
1253 .machine_id
= ss4_id
,
1254 .iommu_version
= 0x05000000,
1255 .max_mem
= 0x10000000,
1256 .default_cpu_model
= "Fujitsu MB86904",
1260 .iommu_base
= 0x10000000,
1261 .tcx_base
= 0x50000000,
1262 .slavio_base
= 0x70000000,
1263 .ms_kb_base
= 0x71000000,
1264 .serial_base
= 0x71100000,
1265 .nvram_base
= 0x71200000,
1266 .fd_base
= 0x71400000,
1267 .counter_base
= 0x71d00000,
1268 .intctl_base
= 0x71e00000,
1269 .idreg_base
= 0x78000000,
1270 .dma_base
= 0x78400000,
1271 .esp_base
= 0x78800000,
1272 .le_base
= 0x78c00000,
1273 .apc_base
= 0x6a000000,
1274 .aux1_base
= 0x71900000,
1275 .aux2_base
= 0x71910000,
1276 .nvram_machine_id
= 0x80,
1277 .machine_id
= scls_id
,
1278 .iommu_version
= 0x05000000,
1279 .max_mem
= 0x10000000,
1280 .default_cpu_model
= "TI MicroSparc I",
1284 .iommu_base
= 0x10000000,
1285 .tcx_base
= 0x50000000, // XXX
1286 .slavio_base
= 0x70000000,
1287 .ms_kb_base
= 0x71000000,
1288 .serial_base
= 0x71100000,
1289 .nvram_base
= 0x71200000,
1290 .fd_base
= 0x71400000,
1291 .counter_base
= 0x71d00000,
1292 .intctl_base
= 0x71e00000,
1293 .idreg_base
= 0x78000000,
1294 .dma_base
= 0x78400000,
1295 .esp_base
= 0x78800000,
1296 .le_base
= 0x78c00000,
1297 .apc_base
= 0x6a000000,
1298 .aux1_base
= 0x71900000,
1299 .aux2_base
= 0x71910000,
1300 .nvram_machine_id
= 0x80,
1301 .machine_id
= sbook_id
,
1302 .iommu_version
= 0x05000000,
1303 .max_mem
= 0x10000000,
1304 .default_cpu_model
= "TI MicroSparc I",
1308 /* SPARCstation 5 hardware initialisation */
1309 static void ss5_init(QEMUMachineInitArgs
*args
)
1311 ram_addr_t RAM_size
= args
->ram_size
;
1312 const char *cpu_model
= args
->cpu_model
;
1313 const char *kernel_filename
= args
->kernel_filename
;
1314 const char *kernel_cmdline
= args
->kernel_cmdline
;
1315 const char *initrd_filename
= args
->initrd_filename
;
1316 const char *boot_device
= args
->boot_device
;
1317 sun4m_hw_init(&sun4m_hwdefs
[0], RAM_size
, boot_device
, kernel_filename
,
1318 kernel_cmdline
, initrd_filename
, cpu_model
);
1321 /* SPARCstation 10 hardware initialisation */
1322 static void ss10_init(QEMUMachineInitArgs
*args
)
1324 ram_addr_t RAM_size
= args
->ram_size
;
1325 const char *cpu_model
= args
->cpu_model
;
1326 const char *kernel_filename
= args
->kernel_filename
;
1327 const char *kernel_cmdline
= args
->kernel_cmdline
;
1328 const char *initrd_filename
= args
->initrd_filename
;
1329 const char *boot_device
= args
->boot_device
;
1330 sun4m_hw_init(&sun4m_hwdefs
[1], RAM_size
, boot_device
, kernel_filename
,
1331 kernel_cmdline
, initrd_filename
, cpu_model
);
1334 /* SPARCserver 600MP hardware initialisation */
1335 static void ss600mp_init(QEMUMachineInitArgs
*args
)
1337 ram_addr_t RAM_size
= args
->ram_size
;
1338 const char *cpu_model
= args
->cpu_model
;
1339 const char *kernel_filename
= args
->kernel_filename
;
1340 const char *kernel_cmdline
= args
->kernel_cmdline
;
1341 const char *initrd_filename
= args
->initrd_filename
;
1342 const char *boot_device
= args
->boot_device
;
1343 sun4m_hw_init(&sun4m_hwdefs
[2], RAM_size
, boot_device
, kernel_filename
,
1344 kernel_cmdline
, initrd_filename
, cpu_model
);
1347 /* SPARCstation 20 hardware initialisation */
1348 static void ss20_init(QEMUMachineInitArgs
*args
)
1350 ram_addr_t RAM_size
= args
->ram_size
;
1351 const char *cpu_model
= args
->cpu_model
;
1352 const char *kernel_filename
= args
->kernel_filename
;
1353 const char *kernel_cmdline
= args
->kernel_cmdline
;
1354 const char *initrd_filename
= args
->initrd_filename
;
1355 const char *boot_device
= args
->boot_device
;
1356 sun4m_hw_init(&sun4m_hwdefs
[3], RAM_size
, boot_device
, kernel_filename
,
1357 kernel_cmdline
, initrd_filename
, cpu_model
);
1360 /* SPARCstation Voyager hardware initialisation */
1361 static void vger_init(QEMUMachineInitArgs
*args
)
1363 ram_addr_t RAM_size
= args
->ram_size
;
1364 const char *cpu_model
= args
->cpu_model
;
1365 const char *kernel_filename
= args
->kernel_filename
;
1366 const char *kernel_cmdline
= args
->kernel_cmdline
;
1367 const char *initrd_filename
= args
->initrd_filename
;
1368 const char *boot_device
= args
->boot_device
;
1369 sun4m_hw_init(&sun4m_hwdefs
[4], RAM_size
, boot_device
, kernel_filename
,
1370 kernel_cmdline
, initrd_filename
, cpu_model
);
1373 /* SPARCstation LX hardware initialisation */
1374 static void ss_lx_init(QEMUMachineInitArgs
*args
)
1376 ram_addr_t RAM_size
= args
->ram_size
;
1377 const char *cpu_model
= args
->cpu_model
;
1378 const char *kernel_filename
= args
->kernel_filename
;
1379 const char *kernel_cmdline
= args
->kernel_cmdline
;
1380 const char *initrd_filename
= args
->initrd_filename
;
1381 const char *boot_device
= args
->boot_device
;
1382 sun4m_hw_init(&sun4m_hwdefs
[5], RAM_size
, boot_device
, kernel_filename
,
1383 kernel_cmdline
, initrd_filename
, cpu_model
);
1386 /* SPARCstation 4 hardware initialisation */
1387 static void ss4_init(QEMUMachineInitArgs
*args
)
1389 ram_addr_t RAM_size
= args
->ram_size
;
1390 const char *cpu_model
= args
->cpu_model
;
1391 const char *kernel_filename
= args
->kernel_filename
;
1392 const char *kernel_cmdline
= args
->kernel_cmdline
;
1393 const char *initrd_filename
= args
->initrd_filename
;
1394 const char *boot_device
= args
->boot_device
;
1395 sun4m_hw_init(&sun4m_hwdefs
[6], RAM_size
, boot_device
, kernel_filename
,
1396 kernel_cmdline
, initrd_filename
, cpu_model
);
1399 /* SPARCClassic hardware initialisation */
1400 static void scls_init(QEMUMachineInitArgs
*args
)
1402 ram_addr_t RAM_size
= args
->ram_size
;
1403 const char *cpu_model
= args
->cpu_model
;
1404 const char *kernel_filename
= args
->kernel_filename
;
1405 const char *kernel_cmdline
= args
->kernel_cmdline
;
1406 const char *initrd_filename
= args
->initrd_filename
;
1407 const char *boot_device
= args
->boot_device
;
1408 sun4m_hw_init(&sun4m_hwdefs
[7], RAM_size
, boot_device
, kernel_filename
,
1409 kernel_cmdline
, initrd_filename
, cpu_model
);
1412 /* SPARCbook hardware initialisation */
1413 static void sbook_init(QEMUMachineInitArgs
*args
)
1415 ram_addr_t RAM_size
= args
->ram_size
;
1416 const char *cpu_model
= args
->cpu_model
;
1417 const char *kernel_filename
= args
->kernel_filename
;
1418 const char *kernel_cmdline
= args
->kernel_cmdline
;
1419 const char *initrd_filename
= args
->initrd_filename
;
1420 const char *boot_device
= args
->boot_device
;
1421 sun4m_hw_init(&sun4m_hwdefs
[8], RAM_size
, boot_device
, kernel_filename
,
1422 kernel_cmdline
, initrd_filename
, cpu_model
);
1425 static QEMUMachine ss5_machine
= {
1427 .desc
= "Sun4m platform, SPARCstation 5",
1433 static QEMUMachine ss10_machine
= {
1435 .desc
= "Sun4m platform, SPARCstation 10",
1441 static QEMUMachine ss600mp_machine
= {
1443 .desc
= "Sun4m platform, SPARCserver 600MP",
1444 .init
= ss600mp_init
,
1449 static QEMUMachine ss20_machine
= {
1451 .desc
= "Sun4m platform, SPARCstation 20",
1457 static QEMUMachine voyager_machine
= {
1459 .desc
= "Sun4m platform, SPARCstation Voyager",
1464 static QEMUMachine ss_lx_machine
= {
1466 .desc
= "Sun4m platform, SPARCstation LX",
1471 static QEMUMachine ss4_machine
= {
1473 .desc
= "Sun4m platform, SPARCstation 4",
1478 static QEMUMachine scls_machine
= {
1479 .name
= "SPARCClassic",
1480 .desc
= "Sun4m platform, SPARCClassic",
1485 static QEMUMachine sbook_machine
= {
1486 .name
= "SPARCbook",
1487 .desc
= "Sun4m platform, SPARCbook",
1492 static const struct sun4d_hwdef sun4d_hwdefs
[] = {
1502 .tcx_base
= 0x820000000ULL
,
1503 .slavio_base
= 0xf00000000ULL
,
1504 .ms_kb_base
= 0xf00240000ULL
,
1505 .serial_base
= 0xf00200000ULL
,
1506 .nvram_base
= 0xf00280000ULL
,
1507 .counter_base
= 0xf00300000ULL
,
1508 .espdma_base
= 0x800081000ULL
,
1509 .esp_base
= 0x800080000ULL
,
1510 .ledma_base
= 0x800040000ULL
,
1511 .le_base
= 0x800060000ULL
,
1512 .sbi_base
= 0xf02800000ULL
,
1513 .nvram_machine_id
= 0x80,
1514 .machine_id
= ss1000_id
,
1515 .iounit_version
= 0x03000000,
1516 .max_mem
= 0xf00000000ULL
,
1517 .default_cpu_model
= "TI SuperSparc II",
1528 .tcx_base
= 0x820000000ULL
,
1529 .slavio_base
= 0xf00000000ULL
,
1530 .ms_kb_base
= 0xf00240000ULL
,
1531 .serial_base
= 0xf00200000ULL
,
1532 .nvram_base
= 0xf00280000ULL
,
1533 .counter_base
= 0xf00300000ULL
,
1534 .espdma_base
= 0x800081000ULL
,
1535 .esp_base
= 0x800080000ULL
,
1536 .ledma_base
= 0x800040000ULL
,
1537 .le_base
= 0x800060000ULL
,
1538 .sbi_base
= 0xf02800000ULL
,
1539 .nvram_machine_id
= 0x80,
1540 .machine_id
= ss2000_id
,
1541 .iounit_version
= 0x03000000,
1542 .max_mem
= 0xf00000000ULL
,
1543 .default_cpu_model
= "TI SuperSparc II",
1547 static DeviceState
*sbi_init(hwaddr addr
, qemu_irq
**parent_irq
)
1553 dev
= qdev_create(NULL
, "sbi");
1554 qdev_init_nofail(dev
);
1556 s
= sysbus_from_qdev(dev
);
1558 for (i
= 0; i
< MAX_CPUS
; i
++) {
1559 sysbus_connect_irq(s
, i
, *parent_irq
[i
]);
1562 sysbus_mmio_map(s
, 0, addr
);
1567 static void sun4d_hw_init(const struct sun4d_hwdef
*hwdef
, ram_addr_t RAM_size
,
1568 const char *boot_device
,
1569 const char *kernel_filename
,
1570 const char *kernel_cmdline
,
1571 const char *initrd_filename
, const char *cpu_model
)
1574 void *iounits
[MAX_IOUNITS
], *espdma
, *ledma
, *nvram
;
1575 qemu_irq
*cpu_irqs
[MAX_CPUS
], sbi_irq
[32], sbi_cpu_irq
[MAX_CPUS
],
1576 espdma_irq
, ledma_irq
;
1577 qemu_irq esp_reset
, dma_enable
;
1578 unsigned long kernel_size
;
1584 cpu_model
= hwdef
->default_cpu_model
;
1586 for(i
= 0; i
< smp_cpus
; i
++) {
1587 cpu_devinit(cpu_model
, i
, hwdef
->slavio_base
, &cpu_irqs
[i
]);
1590 for (i
= smp_cpus
; i
< MAX_CPUS
; i
++)
1591 cpu_irqs
[i
] = qemu_allocate_irqs(dummy_cpu_set_irq
, NULL
, MAX_PILS
);
1593 /* set up devices */
1594 ram_init(0, RAM_size
, hwdef
->max_mem
);
1596 prom_init(hwdef
->slavio_base
, bios_name
);
1598 dev
= sbi_init(hwdef
->sbi_base
, cpu_irqs
);
1600 for (i
= 0; i
< 32; i
++) {
1601 sbi_irq
[i
] = qdev_get_gpio_in(dev
, i
);
1603 for (i
= 0; i
< MAX_CPUS
; i
++) {
1604 sbi_cpu_irq
[i
] = qdev_get_gpio_in(dev
, 32 + i
);
1607 for (i
= 0; i
< MAX_IOUNITS
; i
++)
1608 if (hwdef
->iounit_bases
[i
] != (hwaddr
)-1)
1609 iounits
[i
] = iommu_init(hwdef
->iounit_bases
[i
],
1610 hwdef
->iounit_version
,
1613 espdma
= sparc32_dma_init(hwdef
->espdma_base
, sbi_irq
[3],
1614 iounits
[0], &espdma_irq
, 0);
1616 /* should be lebuffer instead */
1617 ledma
= sparc32_dma_init(hwdef
->ledma_base
, sbi_irq
[4],
1618 iounits
[0], &ledma_irq
, 0);
1620 if (graphic_depth
!= 8 && graphic_depth
!= 24) {
1621 fprintf(stderr
, "qemu: Unsupported depth: %d\n", graphic_depth
);
1624 tcx_init(hwdef
->tcx_base
, 0x00100000, graphic_width
, graphic_height
,
1627 lance_init(&nd_table
[0], hwdef
->le_base
, ledma
, ledma_irq
);
1629 nvram
= m48t59_init(sbi_irq
[0], hwdef
->nvram_base
, 0, 0x2000, 8);
1631 slavio_timer_init_all(hwdef
->counter_base
, sbi_irq
[10], sbi_cpu_irq
, smp_cpus
);
1633 slavio_serial_ms_kbd_init(hwdef
->ms_kb_base
, sbi_irq
[12],
1634 display_type
== DT_NOGRAPHIC
, ESCC_CLOCK
, 1);
1635 /* Slavio TTYA (base+4, Linux ttyS0) is the first QEMU serial device
1636 Slavio TTYB (base+0, Linux ttyS1) is the second QEMU serial device */
1637 escc_init(hwdef
->serial_base
, sbi_irq
[12], sbi_irq
[12],
1638 serial_hds
[0], serial_hds
[1], ESCC_CLOCK
, 1);
1640 if (drive_get_max_bus(IF_SCSI
) > 0) {
1641 fprintf(stderr
, "qemu: too many SCSI bus\n");
1645 esp_init(hwdef
->esp_base
, 2,
1646 espdma_memory_read
, espdma_memory_write
,
1647 espdma
, espdma_irq
, &esp_reset
, &dma_enable
);
1649 qdev_connect_gpio_out(espdma
, 0, esp_reset
);
1650 qdev_connect_gpio_out(espdma
, 1, dma_enable
);
1652 kernel_size
= sun4m_load_kernel(kernel_filename
, initrd_filename
,
1655 nvram_init(nvram
, (uint8_t *)&nd_table
[0].macaddr
, kernel_cmdline
,
1656 boot_device
, RAM_size
, kernel_size
, graphic_width
,
1657 graphic_height
, graphic_depth
, hwdef
->nvram_machine_id
,
1660 fw_cfg
= fw_cfg_init(0, 0, CFG_ADDR
, CFG_ADDR
+ 2);
1661 fw_cfg_add_i32(fw_cfg
, FW_CFG_ID
, 1);
1662 fw_cfg_add_i64(fw_cfg
, FW_CFG_RAM_SIZE
, (uint64_t)ram_size
);
1663 fw_cfg_add_i16(fw_cfg
, FW_CFG_MACHINE_ID
, hwdef
->machine_id
);
1664 fw_cfg_add_i16(fw_cfg
, FW_CFG_SUN4M_DEPTH
, graphic_depth
);
1665 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_ADDR
, KERNEL_LOAD_ADDR
);
1666 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_SIZE
, kernel_size
);
1667 if (kernel_cmdline
) {
1668 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_CMDLINE
, CMDLINE_ADDR
);
1669 pstrcpy_targphys("cmdline", CMDLINE_ADDR
, TARGET_PAGE_SIZE
, kernel_cmdline
);
1670 fw_cfg_add_bytes(fw_cfg
, FW_CFG_CMDLINE_DATA
,
1671 (uint8_t*)strdup(kernel_cmdline
),
1672 strlen(kernel_cmdline
) + 1);
1674 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_CMDLINE
, 0);
1676 fw_cfg_add_i32(fw_cfg
, FW_CFG_INITRD_ADDR
, INITRD_LOAD_ADDR
);
1677 fw_cfg_add_i32(fw_cfg
, FW_CFG_INITRD_SIZE
, 0); // not used
1678 fw_cfg_add_i16(fw_cfg
, FW_CFG_BOOT_DEVICE
, boot_device
[0]);
1679 qemu_register_boot_set(fw_cfg_boot_set
, fw_cfg
);
1682 /* SPARCserver 1000 hardware initialisation */
1683 static void ss1000_init(QEMUMachineInitArgs
*args
)
1685 ram_addr_t RAM_size
= args
->ram_size
;
1686 const char *cpu_model
= args
->cpu_model
;
1687 const char *kernel_filename
= args
->kernel_filename
;
1688 const char *kernel_cmdline
= args
->kernel_cmdline
;
1689 const char *initrd_filename
= args
->initrd_filename
;
1690 const char *boot_device
= args
->boot_device
;
1691 sun4d_hw_init(&sun4d_hwdefs
[0], RAM_size
, boot_device
, kernel_filename
,
1692 kernel_cmdline
, initrd_filename
, cpu_model
);
1695 /* SPARCcenter 2000 hardware initialisation */
1696 static void ss2000_init(QEMUMachineInitArgs
*args
)
1698 ram_addr_t RAM_size
= args
->ram_size
;
1699 const char *cpu_model
= args
->cpu_model
;
1700 const char *kernel_filename
= args
->kernel_filename
;
1701 const char *kernel_cmdline
= args
->kernel_cmdline
;
1702 const char *initrd_filename
= args
->initrd_filename
;
1703 const char *boot_device
= args
->boot_device
;
1704 sun4d_hw_init(&sun4d_hwdefs
[1], RAM_size
, boot_device
, kernel_filename
,
1705 kernel_cmdline
, initrd_filename
, cpu_model
);
1708 static QEMUMachine ss1000_machine
= {
1710 .desc
= "Sun4d platform, SPARCserver 1000",
1711 .init
= ss1000_init
,
1716 static QEMUMachine ss2000_machine
= {
1718 .desc
= "Sun4d platform, SPARCcenter 2000",
1719 .init
= ss2000_init
,
1724 static const struct sun4c_hwdef sun4c_hwdefs
[] = {
1727 .iommu_base
= 0xf8000000,
1728 .tcx_base
= 0xfe000000,
1729 .slavio_base
= 0xf6000000,
1730 .intctl_base
= 0xf5000000,
1731 .counter_base
= 0xf3000000,
1732 .ms_kb_base
= 0xf0000000,
1733 .serial_base
= 0xf1000000,
1734 .nvram_base
= 0xf2000000,
1735 .fd_base
= 0xf7200000,
1736 .dma_base
= 0xf8400000,
1737 .esp_base
= 0xf8800000,
1738 .le_base
= 0xf8c00000,
1739 .aux1_base
= 0xf7400003,
1740 .nvram_machine_id
= 0x55,
1741 .machine_id
= ss2_id
,
1742 .max_mem
= 0x10000000,
1743 .default_cpu_model
= "Cypress CY7C601",
1747 static DeviceState
*sun4c_intctl_init(hwaddr addr
,
1748 qemu_irq
*parent_irq
)
1754 dev
= qdev_create(NULL
, "sun4c_intctl");
1755 qdev_init_nofail(dev
);
1757 s
= sysbus_from_qdev(dev
);
1759 for (i
= 0; i
< MAX_PILS
; i
++) {
1760 sysbus_connect_irq(s
, i
, parent_irq
[i
]);
1762 sysbus_mmio_map(s
, 0, addr
);
1767 static void sun4c_hw_init(const struct sun4c_hwdef
*hwdef
, ram_addr_t RAM_size
,
1768 const char *boot_device
,
1769 const char *kernel_filename
,
1770 const char *kernel_cmdline
,
1771 const char *initrd_filename
, const char *cpu_model
)
1773 void *iommu
, *espdma
, *ledma
, *nvram
;
1774 qemu_irq
*cpu_irqs
, slavio_irq
[8], espdma_irq
, ledma_irq
;
1775 qemu_irq esp_reset
, dma_enable
;
1777 unsigned long kernel_size
;
1778 DriveInfo
*fd
[MAX_FD
];
1785 cpu_model
= hwdef
->default_cpu_model
;
1787 cpu_devinit(cpu_model
, 0, hwdef
->slavio_base
, &cpu_irqs
);
1789 /* set up devices */
1790 ram_init(0, RAM_size
, hwdef
->max_mem
);
1792 prom_init(hwdef
->slavio_base
, bios_name
);
1794 dev
= sun4c_intctl_init(hwdef
->intctl_base
, cpu_irqs
);
1796 for (i
= 0; i
< 8; i
++) {
1797 slavio_irq
[i
] = qdev_get_gpio_in(dev
, i
);
1800 iommu
= iommu_init(hwdef
->iommu_base
, hwdef
->iommu_version
,
1803 espdma
= sparc32_dma_init(hwdef
->dma_base
, slavio_irq
[2],
1804 iommu
, &espdma_irq
, 0);
1806 ledma
= sparc32_dma_init(hwdef
->dma_base
+ 16ULL,
1807 slavio_irq
[3], iommu
, &ledma_irq
, 1);
1809 if (graphic_depth
!= 8 && graphic_depth
!= 24) {
1810 fprintf(stderr
, "qemu: Unsupported depth: %d\n", graphic_depth
);
1813 tcx_init(hwdef
->tcx_base
, 0x00100000, graphic_width
, graphic_height
,
1816 lance_init(&nd_table
[0], hwdef
->le_base
, ledma
, ledma_irq
);
1818 nvram
= m48t59_init(slavio_irq
[0], hwdef
->nvram_base
, 0, 0x800, 2);
1820 slavio_serial_ms_kbd_init(hwdef
->ms_kb_base
, slavio_irq
[1],
1821 display_type
== DT_NOGRAPHIC
, ESCC_CLOCK
, 1);
1822 /* Slavio TTYA (base+4, Linux ttyS0) is the first QEMU serial device
1823 Slavio TTYB (base+0, Linux ttyS1) is the second QEMU serial device */
1824 escc_init(hwdef
->serial_base
, slavio_irq
[1],
1825 slavio_irq
[1], serial_hds
[0], serial_hds
[1],
1828 if (hwdef
->fd_base
!= (hwaddr
)-1) {
1829 /* there is zero or one floppy drive */
1830 memset(fd
, 0, sizeof(fd
));
1831 fd
[0] = drive_get(IF_FLOPPY
, 0, 0);
1832 sun4m_fdctrl_init(slavio_irq
[1], hwdef
->fd_base
, fd
,
1835 fdc_tc
= *qemu_allocate_irqs(dummy_fdc_tc
, NULL
, 1);
1838 slavio_misc_init(0, hwdef
->aux1_base
, 0, slavio_irq
[1], fdc_tc
);
1840 if (drive_get_max_bus(IF_SCSI
) > 0) {
1841 fprintf(stderr
, "qemu: too many SCSI bus\n");
1845 esp_init(hwdef
->esp_base
, 2,
1846 espdma_memory_read
, espdma_memory_write
,
1847 espdma
, espdma_irq
, &esp_reset
, &dma_enable
);
1849 qdev_connect_gpio_out(espdma
, 0, esp_reset
);
1850 qdev_connect_gpio_out(espdma
, 1, dma_enable
);
1852 kernel_size
= sun4m_load_kernel(kernel_filename
, initrd_filename
,
1855 nvram_init(nvram
, (uint8_t *)&nd_table
[0].macaddr
, kernel_cmdline
,
1856 boot_device
, RAM_size
, kernel_size
, graphic_width
,
1857 graphic_height
, graphic_depth
, hwdef
->nvram_machine_id
,
1860 fw_cfg
= fw_cfg_init(0, 0, CFG_ADDR
, CFG_ADDR
+ 2);
1861 fw_cfg_add_i32(fw_cfg
, FW_CFG_ID
, 1);
1862 fw_cfg_add_i64(fw_cfg
, FW_CFG_RAM_SIZE
, (uint64_t)ram_size
);
1863 fw_cfg_add_i16(fw_cfg
, FW_CFG_MACHINE_ID
, hwdef
->machine_id
);
1864 fw_cfg_add_i16(fw_cfg
, FW_CFG_SUN4M_DEPTH
, graphic_depth
);
1865 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_ADDR
, KERNEL_LOAD_ADDR
);
1866 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_SIZE
, kernel_size
);
1867 if (kernel_cmdline
) {
1868 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_CMDLINE
, CMDLINE_ADDR
);
1869 pstrcpy_targphys("cmdline", CMDLINE_ADDR
, TARGET_PAGE_SIZE
, kernel_cmdline
);
1870 fw_cfg_add_bytes(fw_cfg
, FW_CFG_CMDLINE_DATA
,
1871 (uint8_t*)strdup(kernel_cmdline
),
1872 strlen(kernel_cmdline
) + 1);
1874 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_CMDLINE
, 0);
1876 fw_cfg_add_i32(fw_cfg
, FW_CFG_INITRD_ADDR
, INITRD_LOAD_ADDR
);
1877 fw_cfg_add_i32(fw_cfg
, FW_CFG_INITRD_SIZE
, 0); // not used
1878 fw_cfg_add_i16(fw_cfg
, FW_CFG_BOOT_DEVICE
, boot_device
[0]);
1879 qemu_register_boot_set(fw_cfg_boot_set
, fw_cfg
);
1882 /* SPARCstation 2 hardware initialisation */
1883 static void ss2_init(QEMUMachineInitArgs
*args
)
1885 ram_addr_t RAM_size
= args
->ram_size
;
1886 const char *cpu_model
= args
->cpu_model
;
1887 const char *kernel_filename
= args
->kernel_filename
;
1888 const char *kernel_cmdline
= args
->kernel_cmdline
;
1889 const char *initrd_filename
= args
->initrd_filename
;
1890 const char *boot_device
= args
->boot_device
;
1891 sun4c_hw_init(&sun4c_hwdefs
[0], RAM_size
, boot_device
, kernel_filename
,
1892 kernel_cmdline
, initrd_filename
, cpu_model
);
1895 static QEMUMachine ss2_machine
= {
1897 .desc
= "Sun4c platform, SPARCstation 2",
1902 static void sun4m_register_types(void)
1904 type_register_static(&idreg_info
);
1905 type_register_static(&afx_info
);
1906 type_register_static(&prom_info
);
1907 type_register_static(&ram_info
);
1910 static void ss2_machine_init(void)
1912 qemu_register_machine(&ss5_machine
);
1913 qemu_register_machine(&ss10_machine
);
1914 qemu_register_machine(&ss600mp_machine
);
1915 qemu_register_machine(&ss20_machine
);
1916 qemu_register_machine(&voyager_machine
);
1917 qemu_register_machine(&ss_lx_machine
);
1918 qemu_register_machine(&ss4_machine
);
1919 qemu_register_machine(&scls_machine
);
1920 qemu_register_machine(&sbook_machine
);
1921 qemu_register_machine(&ss1000_machine
);
1922 qemu_register_machine(&ss2000_machine
);
1923 qemu_register_machine(&ss2_machine
);
1926 type_init(sun4m_register_types
)
1927 machine_init(ss2_machine_init
);