2 * QEMU Sun4u/Sun4v System Emulator
4 * Copyright (c) 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
24 #include "qemu/osdep.h"
25 #include "qapi/error.h"
27 #include "hw/pci/pci.h"
28 #include "hw/pci-host/apb.h"
29 #include "hw/i386/pc.h"
30 #include "hw/char/serial.h"
31 #include "hw/timer/m48t59.h"
32 #include "hw/block/fdc.h"
34 #include "qemu/timer.h"
35 #include "sysemu/sysemu.h"
36 #include "hw/boards.h"
37 #include "hw/nvram/openbios_firmware_abi.h"
38 #include "hw/nvram/fw_cfg.h"
39 #include "hw/sysbus.h"
41 #include "hw/loader.h"
43 #include "sysemu/block-backend.h"
44 #include "exec/address-spaces.h"
51 #define CPUIRQ_DPRINTF(fmt, ...) \
52 do { printf("CPUIRQ: " fmt , ## __VA_ARGS__); } while (0)
54 #define CPUIRQ_DPRINTF(fmt, ...)
58 #define EBUS_DPRINTF(fmt, ...) \
59 do { printf("EBUS: " fmt , ## __VA_ARGS__); } while (0)
61 #define EBUS_DPRINTF(fmt, ...)
65 #define TIMER_DPRINTF(fmt, ...) \
66 do { printf("TIMER: " fmt , ## __VA_ARGS__); } while (0)
68 #define TIMER_DPRINTF(fmt, ...)
71 #define KERNEL_LOAD_ADDR 0x00404000
72 #define CMDLINE_ADDR 0x003ff000
73 #define PROM_SIZE_MAX (4 * 1024 * 1024)
74 #define PROM_VADDR 0x000ffd00000ULL
75 #define APB_SPECIAL_BASE 0x1fe00000000ULL
76 #define APB_MEM_BASE 0x1ff00000000ULL
77 #define APB_PCI_IO_BASE (APB_SPECIAL_BASE + 0x02000000ULL)
78 #define PROM_FILENAME "openbios-sparc64"
79 #define NVRAM_SIZE 0x2000
81 #define BIOS_CFG_IOPORT 0x510
82 #define FW_CFG_SPARC64_WIDTH (FW_CFG_ARCH_LOCAL + 0x00)
83 #define FW_CFG_SPARC64_HEIGHT (FW_CFG_ARCH_LOCAL + 0x01)
84 #define FW_CFG_SPARC64_DEPTH (FW_CFG_ARCH_LOCAL + 0x02)
88 #define TICK_MAX 0x7fffffffffffffffULL
91 const char * const default_cpu_model
;
94 uint64_t console_serial_base
;
97 typedef struct EbusState
{
103 void DMA_init(ISABus
*bus
, int high_page_enable
)
107 static void fw_cfg_boot_set(void *opaque
, const char *boot_device
,
110 fw_cfg_modify_i16(opaque
, FW_CFG_BOOT_DEVICE
, boot_device
[0]);
113 static int sun4u_NVRAM_set_params(Nvram
*nvram
, uint16_t NVRAM_size
,
114 const char *arch
, ram_addr_t RAM_size
,
115 const char *boot_devices
,
116 uint32_t kernel_image
, uint32_t kernel_size
,
118 uint32_t initrd_image
, uint32_t initrd_size
,
119 uint32_t NVRAM_image
,
120 int width
, int height
, int depth
,
121 const uint8_t *macaddr
)
125 uint8_t image
[0x1ff0];
126 struct OpenBIOS_nvpart_v1
*part_header
;
127 NvramClass
*k
= NVRAM_GET_CLASS(nvram
);
129 memset(image
, '\0', sizeof(image
));
133 // OpenBIOS nvram variables
134 // Variable partition
135 part_header
= (struct OpenBIOS_nvpart_v1
*)&image
[start
];
136 part_header
->signature
= OPENBIOS_PART_SYSTEM
;
137 pstrcpy(part_header
->name
, sizeof(part_header
->name
), "system");
139 end
= start
+ sizeof(struct OpenBIOS_nvpart_v1
);
140 for (i
= 0; i
< nb_prom_envs
; i
++)
141 end
= OpenBIOS_set_var(image
, end
, prom_envs
[i
]);
146 end
= start
+ ((end
- start
+ 15) & ~15);
147 OpenBIOS_finish_partition(part_header
, end
- start
);
151 part_header
= (struct OpenBIOS_nvpart_v1
*)&image
[start
];
152 part_header
->signature
= OPENBIOS_PART_FREE
;
153 pstrcpy(part_header
->name
, sizeof(part_header
->name
), "free");
156 OpenBIOS_finish_partition(part_header
, end
- start
);
158 Sun_init_header((struct Sun_nvram
*)&image
[0x1fd8], macaddr
, 0x80);
160 for (i
= 0; i
< sizeof(image
); i
++) {
161 (k
->write
)(nvram
, i
, image
[i
]);
167 static uint64_t sun4u_load_kernel(const char *kernel_filename
,
168 const char *initrd_filename
,
169 ram_addr_t RAM_size
, uint64_t *initrd_size
,
170 uint64_t *initrd_addr
, uint64_t *kernel_addr
,
171 uint64_t *kernel_entry
)
179 linux_boot
= (kernel_filename
!= NULL
);
190 kernel_size
= load_elf(kernel_filename
, NULL
, NULL
, kernel_entry
,
191 kernel_addr
, &kernel_top
, 1, EM_SPARCV9
, 0, 0);
192 if (kernel_size
< 0) {
193 *kernel_addr
= KERNEL_LOAD_ADDR
;
194 *kernel_entry
= KERNEL_LOAD_ADDR
;
195 kernel_size
= load_aout(kernel_filename
, KERNEL_LOAD_ADDR
,
196 RAM_size
- KERNEL_LOAD_ADDR
, bswap_needed
,
199 if (kernel_size
< 0) {
200 kernel_size
= load_image_targphys(kernel_filename
,
202 RAM_size
- KERNEL_LOAD_ADDR
);
204 if (kernel_size
< 0) {
205 fprintf(stderr
, "qemu: could not load kernel '%s'\n",
209 /* load initrd above kernel */
211 if (initrd_filename
) {
212 *initrd_addr
= TARGET_PAGE_ALIGN(kernel_top
);
214 *initrd_size
= load_image_targphys(initrd_filename
,
216 RAM_size
- *initrd_addr
);
217 if ((int)*initrd_size
< 0) {
218 fprintf(stderr
, "qemu: could not load initial ram disk '%s'\n",
223 if (*initrd_size
> 0) {
224 for (i
= 0; i
< 64 * TARGET_PAGE_SIZE
; i
+= TARGET_PAGE_SIZE
) {
225 ptr
= rom_ptr(*kernel_addr
+ i
);
226 if (ldl_p(ptr
+ 8) == 0x48647253) { /* HdrS */
227 stl_p(ptr
+ 24, *initrd_addr
+ *kernel_addr
);
228 stl_p(ptr
+ 28, *initrd_size
);
237 void cpu_check_irqs(CPUSPARCState
*env
)
240 uint32_t pil
= env
->pil_in
|
241 (env
->softint
& ~(SOFTINT_TIMER
| SOFTINT_STIMER
));
243 /* TT_IVEC has a higher priority (16) than TT_EXTINT (31..17) */
244 if (env
->ivec_status
& 0x20) {
247 cs
= CPU(sparc_env_get_cpu(env
));
248 /* check if TM or SM in SOFTINT are set
249 setting these also causes interrupt 14 */
250 if (env
->softint
& (SOFTINT_TIMER
| SOFTINT_STIMER
)) {
254 /* The bit corresponding to psrpil is (1<< psrpil), the next bit
256 if (pil
< (2 << env
->psrpil
)){
257 if (cs
->interrupt_request
& CPU_INTERRUPT_HARD
) {
258 CPUIRQ_DPRINTF("Reset CPU IRQ (current interrupt %x)\n",
259 env
->interrupt_index
);
260 env
->interrupt_index
= 0;
261 cpu_reset_interrupt(cs
, CPU_INTERRUPT_HARD
);
266 if (cpu_interrupts_enabled(env
)) {
270 for (i
= 15; i
> env
->psrpil
; i
--) {
271 if (pil
& (1 << i
)) {
272 int old_interrupt
= env
->interrupt_index
;
273 int new_interrupt
= TT_EXTINT
| i
;
275 if (unlikely(env
->tl
> 0 && cpu_tsptr(env
)->tt
> new_interrupt
276 && ((cpu_tsptr(env
)->tt
& 0x1f0) == TT_EXTINT
))) {
277 CPUIRQ_DPRINTF("Not setting CPU IRQ: TL=%d "
278 "current %x >= pending %x\n",
279 env
->tl
, cpu_tsptr(env
)->tt
, new_interrupt
);
280 } else if (old_interrupt
!= new_interrupt
) {
281 env
->interrupt_index
= new_interrupt
;
282 CPUIRQ_DPRINTF("Set CPU IRQ %d old=%x new=%x\n", i
,
283 old_interrupt
, new_interrupt
);
284 cpu_interrupt(cs
, CPU_INTERRUPT_HARD
);
289 } else if (cs
->interrupt_request
& CPU_INTERRUPT_HARD
) {
290 CPUIRQ_DPRINTF("Interrupts disabled, pil=%08x pil_in=%08x softint=%08x "
291 "current interrupt %x\n",
292 pil
, env
->pil_in
, env
->softint
, env
->interrupt_index
);
293 env
->interrupt_index
= 0;
294 cpu_reset_interrupt(cs
, CPU_INTERRUPT_HARD
);
298 static void cpu_kick_irq(SPARCCPU
*cpu
)
300 CPUState
*cs
= CPU(cpu
);
301 CPUSPARCState
*env
= &cpu
->env
;
308 static void cpu_set_ivec_irq(void *opaque
, int irq
, int level
)
310 SPARCCPU
*cpu
= opaque
;
311 CPUSPARCState
*env
= &cpu
->env
;
315 if (!(env
->ivec_status
& 0x20)) {
316 CPUIRQ_DPRINTF("Raise IVEC IRQ %d\n", irq
);
319 env
->interrupt_index
= TT_IVEC
;
320 env
->ivec_status
|= 0x20;
321 env
->ivec_data
[0] = (0x1f << 6) | irq
;
322 env
->ivec_data
[1] = 0;
323 env
->ivec_data
[2] = 0;
324 cpu_interrupt(cs
, CPU_INTERRUPT_HARD
);
327 if (env
->ivec_status
& 0x20) {
328 CPUIRQ_DPRINTF("Lower IVEC IRQ %d\n", irq
);
330 env
->ivec_status
&= ~0x20;
331 cpu_reset_interrupt(cs
, CPU_INTERRUPT_HARD
);
336 typedef struct ResetData
{
341 static CPUTimer
*cpu_timer_create(const char *name
, SPARCCPU
*cpu
,
342 QEMUBHFunc
*cb
, uint32_t frequency
,
343 uint64_t disabled_mask
, uint64_t npt_mask
)
345 CPUTimer
*timer
= g_malloc0(sizeof (CPUTimer
));
348 timer
->frequency
= frequency
;
349 timer
->disabled_mask
= disabled_mask
;
350 timer
->npt_mask
= npt_mask
;
354 timer
->clock_offset
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
);
356 timer
->qtimer
= timer_new_ns(QEMU_CLOCK_VIRTUAL
, cb
, cpu
);
361 static void cpu_timer_reset(CPUTimer
*timer
)
364 timer
->clock_offset
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
);
366 timer_del(timer
->qtimer
);
369 static void main_cpu_reset(void *opaque
)
371 ResetData
*s
= (ResetData
*)opaque
;
372 CPUSPARCState
*env
= &s
->cpu
->env
;
373 static unsigned int nr_resets
;
375 cpu_reset(CPU(s
->cpu
));
377 cpu_timer_reset(env
->tick
);
378 cpu_timer_reset(env
->stick
);
379 cpu_timer_reset(env
->hstick
);
381 env
->gregs
[1] = 0; // Memory start
382 env
->gregs
[2] = ram_size
; // Memory size
383 env
->gregs
[3] = 0; // Machine description XXX
384 if (nr_resets
++ == 0) {
386 env
->pc
= s
->prom_addr
+ 0x20ULL
;
388 env
->pc
= s
->prom_addr
+ 0x40ULL
;
390 env
->npc
= env
->pc
+ 4;
393 static void tick_irq(void *opaque
)
395 SPARCCPU
*cpu
= opaque
;
396 CPUSPARCState
*env
= &cpu
->env
;
398 CPUTimer
* timer
= env
->tick
;
400 if (timer
->disabled
) {
401 CPUIRQ_DPRINTF("tick_irq: softint disabled\n");
404 CPUIRQ_DPRINTF("tick: fire\n");
407 env
->softint
|= SOFTINT_TIMER
;
411 static void stick_irq(void *opaque
)
413 SPARCCPU
*cpu
= opaque
;
414 CPUSPARCState
*env
= &cpu
->env
;
416 CPUTimer
* timer
= env
->stick
;
418 if (timer
->disabled
) {
419 CPUIRQ_DPRINTF("stick_irq: softint disabled\n");
422 CPUIRQ_DPRINTF("stick: fire\n");
425 env
->softint
|= SOFTINT_STIMER
;
429 static void hstick_irq(void *opaque
)
431 SPARCCPU
*cpu
= opaque
;
432 CPUSPARCState
*env
= &cpu
->env
;
434 CPUTimer
* timer
= env
->hstick
;
436 if (timer
->disabled
) {
437 CPUIRQ_DPRINTF("hstick_irq: softint disabled\n");
440 CPUIRQ_DPRINTF("hstick: fire\n");
443 env
->softint
|= SOFTINT_STIMER
;
447 static int64_t cpu_to_timer_ticks(int64_t cpu_ticks
, uint32_t frequency
)
449 return muldiv64(cpu_ticks
, get_ticks_per_sec(), frequency
);
452 static uint64_t timer_to_cpu_ticks(int64_t timer_ticks
, uint32_t frequency
)
454 return muldiv64(timer_ticks
, frequency
, get_ticks_per_sec());
457 void cpu_tick_set_count(CPUTimer
*timer
, uint64_t count
)
459 uint64_t real_count
= count
& ~timer
->npt_mask
;
460 uint64_t npt_bit
= count
& timer
->npt_mask
;
462 int64_t vm_clock_offset
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) -
463 cpu_to_timer_ticks(real_count
, timer
->frequency
);
465 TIMER_DPRINTF("%s set_count count=0x%016lx (npt %s) p=%p\n",
466 timer
->name
, real_count
,
467 timer
->npt
? "disabled" : "enabled", timer
);
469 timer
->npt
= npt_bit
? 1 : 0;
470 timer
->clock_offset
= vm_clock_offset
;
473 uint64_t cpu_tick_get_count(CPUTimer
*timer
)
475 uint64_t real_count
= timer_to_cpu_ticks(
476 qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) - timer
->clock_offset
,
479 TIMER_DPRINTF("%s get_count count=0x%016lx (npt %s) p=%p\n",
480 timer
->name
, real_count
,
481 timer
->npt
? "disabled" : "enabled", timer
);
484 real_count
|= timer
->npt_mask
;
490 void cpu_tick_set_limit(CPUTimer
*timer
, uint64_t limit
)
492 int64_t now
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
);
494 uint64_t real_limit
= limit
& ~timer
->disabled_mask
;
495 timer
->disabled
= (limit
& timer
->disabled_mask
) ? 1 : 0;
497 int64_t expires
= cpu_to_timer_ticks(real_limit
, timer
->frequency
) +
504 TIMER_DPRINTF("%s set_limit limit=0x%016lx (%s) p=%p "
505 "called with limit=0x%016lx at 0x%016lx (delta=0x%016lx)\n",
506 timer
->name
, real_limit
,
507 timer
->disabled
?"disabled":"enabled",
509 timer_to_cpu_ticks(now
- timer
->clock_offset
,
511 timer_to_cpu_ticks(expires
- now
, timer
->frequency
));
514 TIMER_DPRINTF("%s set_limit limit=ZERO - not starting timer\n",
516 timer_del(timer
->qtimer
);
517 } else if (timer
->disabled
) {
518 timer_del(timer
->qtimer
);
520 timer_mod(timer
->qtimer
, expires
);
524 static void isa_irq_handler(void *opaque
, int n
, int level
)
526 static const int isa_irq_to_ivec
[16] = {
527 [1] = 0x29, /* keyboard */
528 [4] = 0x2b, /* serial */
529 [6] = 0x27, /* floppy */
530 [7] = 0x22, /* parallel */
531 [12] = 0x2a, /* mouse */
533 qemu_irq
*irqs
= opaque
;
537 ivec
= isa_irq_to_ivec
[n
];
538 EBUS_DPRINTF("Set ISA IRQ %d level %d -> ivec 0x%x\n", n
, level
, ivec
);
540 qemu_set_irq(irqs
[ivec
], level
);
544 /* EBUS (Eight bit bus) bridge */
546 pci_ebus_init(PCIBus
*bus
, int devfn
, qemu_irq
*irqs
)
552 pci_dev
= pci_create_simple(bus
, devfn
, "ebus");
553 isa_bus
= ISA_BUS(qdev_get_child_bus(DEVICE(pci_dev
), "isa.0"));
554 isa_irq
= qemu_allocate_irqs(isa_irq_handler
, irqs
, 16);
555 isa_bus_irqs(isa_bus
, isa_irq
);
559 static void pci_ebus_realize(PCIDevice
*pci_dev
, Error
**errp
)
561 EbusState
*s
= DO_UPCAST(EbusState
, pci_dev
, pci_dev
);
563 if (!isa_bus_new(DEVICE(pci_dev
), get_system_memory(),
564 pci_address_space_io(pci_dev
), errp
)) {
568 pci_dev
->config
[0x04] = 0x06; // command = bus master, pci mem
569 pci_dev
->config
[0x05] = 0x00;
570 pci_dev
->config
[0x06] = 0xa0; // status = fast back-to-back, 66MHz, no error
571 pci_dev
->config
[0x07] = 0x03; // status = medium devsel
572 pci_dev
->config
[0x09] = 0x00; // programming i/f
573 pci_dev
->config
[0x0D] = 0x0a; // latency_timer
575 memory_region_init_alias(&s
->bar0
, OBJECT(s
), "bar0", get_system_io(),
577 pci_register_bar(pci_dev
, 0, PCI_BASE_ADDRESS_SPACE_MEMORY
, &s
->bar0
);
578 memory_region_init_alias(&s
->bar1
, OBJECT(s
), "bar1", get_system_io(),
580 pci_register_bar(pci_dev
, 1, PCI_BASE_ADDRESS_SPACE_IO
, &s
->bar1
);
583 static void ebus_class_init(ObjectClass
*klass
, void *data
)
585 PCIDeviceClass
*k
= PCI_DEVICE_CLASS(klass
);
587 k
->realize
= pci_ebus_realize
;
588 k
->vendor_id
= PCI_VENDOR_ID_SUN
;
589 k
->device_id
= PCI_DEVICE_ID_SUN_EBUS
;
591 k
->class_id
= PCI_CLASS_BRIDGE_OTHER
;
594 static const TypeInfo ebus_info
= {
596 .parent
= TYPE_PCI_DEVICE
,
597 .instance_size
= sizeof(EbusState
),
598 .class_init
= ebus_class_init
,
601 #define TYPE_OPENPROM "openprom"
602 #define OPENPROM(obj) OBJECT_CHECK(PROMState, (obj), TYPE_OPENPROM)
604 typedef struct PROMState
{
605 SysBusDevice parent_obj
;
610 static uint64_t translate_prom_address(void *opaque
, uint64_t addr
)
612 hwaddr
*base_addr
= (hwaddr
*)opaque
;
613 return addr
+ *base_addr
- PROM_VADDR
;
616 /* Boot PROM (OpenBIOS) */
617 static void prom_init(hwaddr addr
, const char *bios_name
)
624 dev
= qdev_create(NULL
, TYPE_OPENPROM
);
625 qdev_init_nofail(dev
);
626 s
= SYS_BUS_DEVICE(dev
);
628 sysbus_mmio_map(s
, 0, addr
);
631 if (bios_name
== NULL
) {
632 bios_name
= PROM_FILENAME
;
634 filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, bios_name
);
636 ret
= load_elf(filename
, translate_prom_address
, &addr
,
637 NULL
, NULL
, NULL
, 1, EM_SPARCV9
, 0, 0);
638 if (ret
< 0 || ret
> PROM_SIZE_MAX
) {
639 ret
= load_image_targphys(filename
, addr
, PROM_SIZE_MAX
);
645 if (ret
< 0 || ret
> PROM_SIZE_MAX
) {
646 fprintf(stderr
, "qemu: could not load prom '%s'\n", bios_name
);
651 static int prom_init1(SysBusDevice
*dev
)
653 PROMState
*s
= OPENPROM(dev
);
655 memory_region_init_ram(&s
->prom
, OBJECT(s
), "sun4u.prom", PROM_SIZE_MAX
,
657 vmstate_register_ram_global(&s
->prom
);
658 memory_region_set_readonly(&s
->prom
, true);
659 sysbus_init_mmio(dev
, &s
->prom
);
663 static Property prom_properties
[] = {
664 {/* end of property list */},
667 static void prom_class_init(ObjectClass
*klass
, void *data
)
669 DeviceClass
*dc
= DEVICE_CLASS(klass
);
670 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
672 k
->init
= prom_init1
;
673 dc
->props
= prom_properties
;
676 static const TypeInfo prom_info
= {
677 .name
= TYPE_OPENPROM
,
678 .parent
= TYPE_SYS_BUS_DEVICE
,
679 .instance_size
= sizeof(PROMState
),
680 .class_init
= prom_class_init
,
684 #define TYPE_SUN4U_MEMORY "memory"
685 #define SUN4U_RAM(obj) OBJECT_CHECK(RamDevice, (obj), TYPE_SUN4U_MEMORY)
687 typedef struct RamDevice
{
688 SysBusDevice parent_obj
;
695 static int ram_init1(SysBusDevice
*dev
)
697 RamDevice
*d
= SUN4U_RAM(dev
);
699 memory_region_init_ram(&d
->ram
, OBJECT(d
), "sun4u.ram", d
->size
,
701 vmstate_register_ram_global(&d
->ram
);
702 sysbus_init_mmio(dev
, &d
->ram
);
706 static void ram_init(hwaddr addr
, ram_addr_t RAM_size
)
713 dev
= qdev_create(NULL
, TYPE_SUN4U_MEMORY
);
714 s
= SYS_BUS_DEVICE(dev
);
718 qdev_init_nofail(dev
);
720 sysbus_mmio_map(s
, 0, addr
);
723 static Property ram_properties
[] = {
724 DEFINE_PROP_UINT64("size", RamDevice
, size
, 0),
725 DEFINE_PROP_END_OF_LIST(),
728 static void ram_class_init(ObjectClass
*klass
, void *data
)
730 DeviceClass
*dc
= DEVICE_CLASS(klass
);
731 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
734 dc
->props
= ram_properties
;
737 static const TypeInfo ram_info
= {
738 .name
= TYPE_SUN4U_MEMORY
,
739 .parent
= TYPE_SYS_BUS_DEVICE
,
740 .instance_size
= sizeof(RamDevice
),
741 .class_init
= ram_class_init
,
744 static SPARCCPU
*cpu_devinit(const char *cpu_model
, const struct hwdef
*hwdef
)
748 ResetData
*reset_info
;
750 uint32_t tick_frequency
= 100*1000000;
751 uint32_t stick_frequency
= 100*1000000;
752 uint32_t hstick_frequency
= 100*1000000;
754 if (cpu_model
== NULL
) {
755 cpu_model
= hwdef
->default_cpu_model
;
757 cpu
= cpu_sparc_init(cpu_model
);
759 fprintf(stderr
, "Unable to find Sparc CPU definition\n");
764 env
->tick
= cpu_timer_create("tick", cpu
, tick_irq
,
765 tick_frequency
, TICK_INT_DIS
,
768 env
->stick
= cpu_timer_create("stick", cpu
, stick_irq
,
769 stick_frequency
, TICK_INT_DIS
,
772 env
->hstick
= cpu_timer_create("hstick", cpu
, hstick_irq
,
773 hstick_frequency
, TICK_INT_DIS
,
776 reset_info
= g_malloc0(sizeof(ResetData
));
777 reset_info
->cpu
= cpu
;
778 reset_info
->prom_addr
= hwdef
->prom_addr
;
779 qemu_register_reset(main_cpu_reset
, reset_info
);
784 static void sun4uv_init(MemoryRegion
*address_space_mem
,
785 MachineState
*machine
,
786 const struct hwdef
*hwdef
)
791 uint64_t initrd_addr
, initrd_size
, kernel_addr
, kernel_size
, kernel_entry
;
792 PCIBus
*pci_bus
, *pci_bus2
, *pci_bus3
;
795 qemu_irq
*ivec_irqs
, *pbm_irqs
;
796 DriveInfo
*hd
[MAX_IDE_BUS
* MAX_IDE_DEVS
];
797 DriveInfo
*fd
[MAX_FD
];
802 cpu
= cpu_devinit(machine
->cpu_model
, hwdef
);
805 ram_init(0, machine
->ram_size
);
807 prom_init(hwdef
->prom_addr
, bios_name
);
809 ivec_irqs
= qemu_allocate_irqs(cpu_set_ivec_irq
, cpu
, IVEC_MAX
);
810 pci_bus
= pci_apb_init(APB_SPECIAL_BASE
, APB_MEM_BASE
, ivec_irqs
, &pci_bus2
,
811 &pci_bus3
, &pbm_irqs
);
812 pci_vga_init(pci_bus
);
814 // XXX Should be pci_bus3
815 isa_bus
= pci_ebus_init(pci_bus
, -1, pbm_irqs
);
818 if (hwdef
->console_serial_base
) {
819 serial_mm_init(address_space_mem
, hwdef
->console_serial_base
, 0,
820 NULL
, 115200, serial_hds
[i
], DEVICE_BIG_ENDIAN
);
824 serial_hds_isa_init(isa_bus
, MAX_SERIAL_PORTS
);
825 parallel_hds_isa_init(isa_bus
, MAX_PARALLEL_PORTS
);
827 for(i
= 0; i
< nb_nics
; i
++)
828 pci_nic_init_nofail(&nd_table
[i
], pci_bus
, "ne2k_pci", NULL
);
830 ide_drive_get(hd
, ARRAY_SIZE(hd
));
832 pci_cmd646_ide_init(pci_bus
, hd
, 1);
834 isa_create_simple(isa_bus
, "i8042");
837 for(i
= 0; i
< MAX_FD
; i
++) {
838 fd
[i
] = drive_get(IF_FLOPPY
, 0, i
);
840 dev
= DEVICE(isa_create(isa_bus
, TYPE_ISA_FDC
));
842 qdev_prop_set_drive(dev
, "driveA", blk_by_legacy_dinfo(fd
[0]),
846 qdev_prop_set_drive(dev
, "driveB", blk_by_legacy_dinfo(fd
[1]),
849 qdev_prop_set_uint32(dev
, "dma", -1);
850 qdev_init_nofail(dev
);
852 /* Map NVRAM into I/O (ebus) space */
853 nvram
= m48t59_init(NULL
, 0, 0, NVRAM_SIZE
, 1968, 59);
854 s
= SYS_BUS_DEVICE(nvram
);
855 memory_region_add_subregion(get_system_io(), 0x2000,
856 sysbus_mmio_get_region(s
, 0));
860 kernel_size
= sun4u_load_kernel(machine
->kernel_filename
,
861 machine
->initrd_filename
,
862 ram_size
, &initrd_size
, &initrd_addr
,
863 &kernel_addr
, &kernel_entry
);
865 sun4u_NVRAM_set_params(nvram
, NVRAM_SIZE
, "Sun4u", machine
->ram_size
,
867 kernel_addr
, kernel_size
,
868 machine
->kernel_cmdline
,
869 initrd_addr
, initrd_size
,
870 /* XXX: need an option to load a NVRAM image */
872 graphic_width
, graphic_height
, graphic_depth
,
873 (uint8_t *)&nd_table
[0].macaddr
);
875 fw_cfg
= fw_cfg_init_io(BIOS_CFG_IOPORT
);
876 fw_cfg_add_i16(fw_cfg
, FW_CFG_MAX_CPUS
, (uint16_t)max_cpus
);
877 fw_cfg_add_i64(fw_cfg
, FW_CFG_RAM_SIZE
, (uint64_t)ram_size
);
878 fw_cfg_add_i16(fw_cfg
, FW_CFG_MACHINE_ID
, hwdef
->machine_id
);
879 fw_cfg_add_i64(fw_cfg
, FW_CFG_KERNEL_ADDR
, kernel_entry
);
880 fw_cfg_add_i64(fw_cfg
, FW_CFG_KERNEL_SIZE
, kernel_size
);
881 if (machine
->kernel_cmdline
) {
882 fw_cfg_add_i32(fw_cfg
, FW_CFG_CMDLINE_SIZE
,
883 strlen(machine
->kernel_cmdline
) + 1);
884 fw_cfg_add_string(fw_cfg
, FW_CFG_CMDLINE_DATA
, machine
->kernel_cmdline
);
886 fw_cfg_add_i32(fw_cfg
, FW_CFG_CMDLINE_SIZE
, 0);
888 fw_cfg_add_i64(fw_cfg
, FW_CFG_INITRD_ADDR
, initrd_addr
);
889 fw_cfg_add_i64(fw_cfg
, FW_CFG_INITRD_SIZE
, initrd_size
);
890 fw_cfg_add_i16(fw_cfg
, FW_CFG_BOOT_DEVICE
, machine
->boot_order
[0]);
892 fw_cfg_add_i16(fw_cfg
, FW_CFG_SPARC64_WIDTH
, graphic_width
);
893 fw_cfg_add_i16(fw_cfg
, FW_CFG_SPARC64_HEIGHT
, graphic_height
);
894 fw_cfg_add_i16(fw_cfg
, FW_CFG_SPARC64_DEPTH
, graphic_depth
);
896 qemu_register_boot_set(fw_cfg_boot_set
, fw_cfg
);
905 static const struct hwdef hwdefs
[] = {
906 /* Sun4u generic PC-like machine */
908 .default_cpu_model
= "TI UltraSparc IIi",
909 .machine_id
= sun4u_id
,
910 .prom_addr
= 0x1fff0000000ULL
,
911 .console_serial_base
= 0,
913 /* Sun4v generic PC-like machine */
915 .default_cpu_model
= "Sun UltraSparc T1",
916 .machine_id
= sun4v_id
,
917 .prom_addr
= 0x1fff0000000ULL
,
918 .console_serial_base
= 0,
920 /* Sun4v generic Niagara machine */
922 .default_cpu_model
= "Sun UltraSparc T1",
923 .machine_id
= niagara_id
,
924 .prom_addr
= 0xfff0000000ULL
,
925 .console_serial_base
= 0xfff0c2c000ULL
,
929 /* Sun4u hardware initialisation */
930 static void sun4u_init(MachineState
*machine
)
932 sun4uv_init(get_system_memory(), machine
, &hwdefs
[0]);
935 /* Sun4v hardware initialisation */
936 static void sun4v_init(MachineState
*machine
)
938 sun4uv_init(get_system_memory(), machine
, &hwdefs
[1]);
941 /* Niagara hardware initialisation */
942 static void niagara_init(MachineState
*machine
)
944 sun4uv_init(get_system_memory(), machine
, &hwdefs
[2]);
947 static void sun4u_class_init(ObjectClass
*oc
, void *data
)
949 MachineClass
*mc
= MACHINE_CLASS(oc
);
951 mc
->desc
= "Sun4u platform";
952 mc
->init
= sun4u_init
;
953 mc
->max_cpus
= 1; /* XXX for now */
955 mc
->default_boot_order
= "c";
958 static const TypeInfo sun4u_type
= {
959 .name
= MACHINE_TYPE_NAME("sun4u"),
960 .parent
= TYPE_MACHINE
,
961 .class_init
= sun4u_class_init
,
964 static void sun4v_class_init(ObjectClass
*oc
, void *data
)
966 MachineClass
*mc
= MACHINE_CLASS(oc
);
968 mc
->desc
= "Sun4v platform";
969 mc
->init
= sun4v_init
;
970 mc
->max_cpus
= 1; /* XXX for now */
971 mc
->default_boot_order
= "c";
974 static const TypeInfo sun4v_type
= {
975 .name
= MACHINE_TYPE_NAME("sun4v"),
976 .parent
= TYPE_MACHINE
,
977 .class_init
= sun4v_class_init
,
980 static void niagara_class_init(ObjectClass
*oc
, void *data
)
982 MachineClass
*mc
= MACHINE_CLASS(oc
);
984 mc
->desc
= "Sun4v platform, Niagara";
985 mc
->init
= niagara_init
;
986 mc
->max_cpus
= 1; /* XXX for now */
987 mc
->default_boot_order
= "c";
990 static const TypeInfo niagara_type
= {
991 .name
= MACHINE_TYPE_NAME("Niagara"),
992 .parent
= TYPE_MACHINE
,
993 .class_init
= niagara_class_init
,
996 static void sun4u_register_types(void)
998 type_register_static(&ebus_info
);
999 type_register_static(&prom_info
);
1000 type_register_static(&ram_info
);
1002 type_register_static(&sun4u_type
);
1003 type_register_static(&sun4v_type
);
1004 type_register_static(&niagara_type
);
1007 type_init(sun4u_register_types
)