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
25 #include "hw/pci/pci.h"
26 #include "hw/pci-host/apb.h"
27 #include "hw/i386/pc.h"
28 #include "hw/char/serial.h"
29 #include "hw/timer/m48t59.h"
30 #include "hw/block/fdc.h"
32 #include "qemu/timer.h"
33 #include "sysemu/sysemu.h"
34 #include "hw/boards.h"
35 #include "hw/nvram/openbios_firmware_abi.h"
36 #include "hw/nvram/fw_cfg.h"
37 #include "hw/sysbus.h"
39 #include "hw/loader.h"
41 #include "sysemu/block-backend.h"
42 #include "exec/address-spaces.h"
49 #define CPUIRQ_DPRINTF(fmt, ...) \
50 do { printf("CPUIRQ: " fmt , ## __VA_ARGS__); } while (0)
52 #define CPUIRQ_DPRINTF(fmt, ...)
56 #define EBUS_DPRINTF(fmt, ...) \
57 do { printf("EBUS: " fmt , ## __VA_ARGS__); } while (0)
59 #define EBUS_DPRINTF(fmt, ...)
63 #define TIMER_DPRINTF(fmt, ...) \
64 do { printf("TIMER: " fmt , ## __VA_ARGS__); } while (0)
66 #define TIMER_DPRINTF(fmt, ...)
69 #define KERNEL_LOAD_ADDR 0x00404000
70 #define CMDLINE_ADDR 0x003ff000
71 #define PROM_SIZE_MAX (4 * 1024 * 1024)
72 #define PROM_VADDR 0x000ffd00000ULL
73 #define APB_SPECIAL_BASE 0x1fe00000000ULL
74 #define APB_MEM_BASE 0x1ff00000000ULL
75 #define APB_PCI_IO_BASE (APB_SPECIAL_BASE + 0x02000000ULL)
76 #define PROM_FILENAME "openbios-sparc64"
77 #define NVRAM_SIZE 0x2000
79 #define BIOS_CFG_IOPORT 0x510
80 #define FW_CFG_SPARC64_WIDTH (FW_CFG_ARCH_LOCAL + 0x00)
81 #define FW_CFG_SPARC64_HEIGHT (FW_CFG_ARCH_LOCAL + 0x01)
82 #define FW_CFG_SPARC64_DEPTH (FW_CFG_ARCH_LOCAL + 0x02)
86 #define TICK_MAX 0x7fffffffffffffffULL
89 const char * const default_cpu_model
;
92 uint64_t console_serial_base
;
95 typedef struct EbusState
{
101 int DMA_get_channel_mode (int nchan
)
105 int DMA_read_memory (int nchan
, void *buf
, int pos
, int size
)
109 int DMA_write_memory (int nchan
, void *buf
, int pos
, int size
)
113 void DMA_hold_DREQ (int nchan
) {}
114 void DMA_release_DREQ (int nchan
) {}
115 void DMA_schedule(void) {}
117 void DMA_init(int high_page_enable
)
121 void DMA_register_channel (int nchan
,
122 DMA_transfer_handler transfer_handler
,
127 static void fw_cfg_boot_set(void *opaque
, const char *boot_device
,
130 fw_cfg_modify_i16(opaque
, FW_CFG_BOOT_DEVICE
, boot_device
[0]);
133 static int sun4u_NVRAM_set_params(Nvram
*nvram
, uint16_t NVRAM_size
,
134 const char *arch
, ram_addr_t RAM_size
,
135 const char *boot_devices
,
136 uint32_t kernel_image
, uint32_t kernel_size
,
138 uint32_t initrd_image
, uint32_t initrd_size
,
139 uint32_t NVRAM_image
,
140 int width
, int height
, int depth
,
141 const uint8_t *macaddr
)
145 uint8_t image
[0x1ff0];
146 struct OpenBIOS_nvpart_v1
*part_header
;
147 NvramClass
*k
= NVRAM_GET_CLASS(nvram
);
149 memset(image
, '\0', sizeof(image
));
153 // OpenBIOS nvram variables
154 // Variable partition
155 part_header
= (struct OpenBIOS_nvpart_v1
*)&image
[start
];
156 part_header
->signature
= OPENBIOS_PART_SYSTEM
;
157 pstrcpy(part_header
->name
, sizeof(part_header
->name
), "system");
159 end
= start
+ sizeof(struct OpenBIOS_nvpart_v1
);
160 for (i
= 0; i
< nb_prom_envs
; i
++)
161 end
= OpenBIOS_set_var(image
, end
, prom_envs
[i
]);
166 end
= start
+ ((end
- start
+ 15) & ~15);
167 OpenBIOS_finish_partition(part_header
, end
- start
);
171 part_header
= (struct OpenBIOS_nvpart_v1
*)&image
[start
];
172 part_header
->signature
= OPENBIOS_PART_FREE
;
173 pstrcpy(part_header
->name
, sizeof(part_header
->name
), "free");
176 OpenBIOS_finish_partition(part_header
, end
- start
);
178 Sun_init_header((struct Sun_nvram
*)&image
[0x1fd8], macaddr
, 0x80);
180 for (i
= 0; i
< sizeof(image
); i
++) {
181 (k
->write
)(nvram
, i
, image
[i
]);
187 static uint64_t sun4u_load_kernel(const char *kernel_filename
,
188 const char *initrd_filename
,
189 ram_addr_t RAM_size
, uint64_t *initrd_size
,
190 uint64_t *initrd_addr
, uint64_t *kernel_addr
,
191 uint64_t *kernel_entry
)
199 linux_boot
= (kernel_filename
!= NULL
);
210 kernel_size
= load_elf(kernel_filename
, NULL
, NULL
, kernel_entry
,
211 kernel_addr
, &kernel_top
, 1, ELF_MACHINE
, 0);
212 if (kernel_size
< 0) {
213 *kernel_addr
= KERNEL_LOAD_ADDR
;
214 *kernel_entry
= KERNEL_LOAD_ADDR
;
215 kernel_size
= load_aout(kernel_filename
, KERNEL_LOAD_ADDR
,
216 RAM_size
- KERNEL_LOAD_ADDR
, bswap_needed
,
219 if (kernel_size
< 0) {
220 kernel_size
= load_image_targphys(kernel_filename
,
222 RAM_size
- KERNEL_LOAD_ADDR
);
224 if (kernel_size
< 0) {
225 fprintf(stderr
, "qemu: could not load kernel '%s'\n",
229 /* load initrd above kernel */
231 if (initrd_filename
) {
232 *initrd_addr
= TARGET_PAGE_ALIGN(kernel_top
);
234 *initrd_size
= load_image_targphys(initrd_filename
,
236 RAM_size
- *initrd_addr
);
237 if ((int)*initrd_size
< 0) {
238 fprintf(stderr
, "qemu: could not load initial ram disk '%s'\n",
243 if (*initrd_size
> 0) {
244 for (i
= 0; i
< 64 * TARGET_PAGE_SIZE
; i
+= TARGET_PAGE_SIZE
) {
245 ptr
= rom_ptr(*kernel_addr
+ i
);
246 if (ldl_p(ptr
+ 8) == 0x48647253) { /* HdrS */
247 stl_p(ptr
+ 24, *initrd_addr
+ *kernel_addr
);
248 stl_p(ptr
+ 28, *initrd_size
);
257 void cpu_check_irqs(CPUSPARCState
*env
)
260 uint32_t pil
= env
->pil_in
|
261 (env
->softint
& ~(SOFTINT_TIMER
| SOFTINT_STIMER
));
263 /* TT_IVEC has a higher priority (16) than TT_EXTINT (31..17) */
264 if (env
->ivec_status
& 0x20) {
267 cs
= CPU(sparc_env_get_cpu(env
));
268 /* check if TM or SM in SOFTINT are set
269 setting these also causes interrupt 14 */
270 if (env
->softint
& (SOFTINT_TIMER
| SOFTINT_STIMER
)) {
274 /* The bit corresponding to psrpil is (1<< psrpil), the next bit
276 if (pil
< (2 << env
->psrpil
)){
277 if (cs
->interrupt_request
& CPU_INTERRUPT_HARD
) {
278 CPUIRQ_DPRINTF("Reset CPU IRQ (current interrupt %x)\n",
279 env
->interrupt_index
);
280 env
->interrupt_index
= 0;
281 cpu_reset_interrupt(cs
, CPU_INTERRUPT_HARD
);
286 if (cpu_interrupts_enabled(env
)) {
290 for (i
= 15; i
> env
->psrpil
; i
--) {
291 if (pil
& (1 << i
)) {
292 int old_interrupt
= env
->interrupt_index
;
293 int new_interrupt
= TT_EXTINT
| i
;
295 if (unlikely(env
->tl
> 0 && cpu_tsptr(env
)->tt
> new_interrupt
296 && ((cpu_tsptr(env
)->tt
& 0x1f0) == TT_EXTINT
))) {
297 CPUIRQ_DPRINTF("Not setting CPU IRQ: TL=%d "
298 "current %x >= pending %x\n",
299 env
->tl
, cpu_tsptr(env
)->tt
, new_interrupt
);
300 } else if (old_interrupt
!= new_interrupt
) {
301 env
->interrupt_index
= new_interrupt
;
302 CPUIRQ_DPRINTF("Set CPU IRQ %d old=%x new=%x\n", i
,
303 old_interrupt
, new_interrupt
);
304 cpu_interrupt(cs
, CPU_INTERRUPT_HARD
);
309 } else if (cs
->interrupt_request
& CPU_INTERRUPT_HARD
) {
310 CPUIRQ_DPRINTF("Interrupts disabled, pil=%08x pil_in=%08x softint=%08x "
311 "current interrupt %x\n",
312 pil
, env
->pil_in
, env
->softint
, env
->interrupt_index
);
313 env
->interrupt_index
= 0;
314 cpu_reset_interrupt(cs
, CPU_INTERRUPT_HARD
);
318 static void cpu_kick_irq(SPARCCPU
*cpu
)
320 CPUState
*cs
= CPU(cpu
);
321 CPUSPARCState
*env
= &cpu
->env
;
328 static void cpu_set_ivec_irq(void *opaque
, int irq
, int level
)
330 SPARCCPU
*cpu
= opaque
;
331 CPUSPARCState
*env
= &cpu
->env
;
335 if (!(env
->ivec_status
& 0x20)) {
336 CPUIRQ_DPRINTF("Raise IVEC IRQ %d\n", irq
);
339 env
->interrupt_index
= TT_IVEC
;
340 env
->ivec_status
|= 0x20;
341 env
->ivec_data
[0] = (0x1f << 6) | irq
;
342 env
->ivec_data
[1] = 0;
343 env
->ivec_data
[2] = 0;
344 cpu_interrupt(cs
, CPU_INTERRUPT_HARD
);
347 if (env
->ivec_status
& 0x20) {
348 CPUIRQ_DPRINTF("Lower IVEC IRQ %d\n", irq
);
350 env
->ivec_status
&= ~0x20;
351 cpu_reset_interrupt(cs
, CPU_INTERRUPT_HARD
);
356 typedef struct ResetData
{
361 void cpu_put_timer(QEMUFile
*f
, CPUTimer
*s
)
363 qemu_put_be32s(f
, &s
->frequency
);
364 qemu_put_be32s(f
, &s
->disabled
);
365 qemu_put_be64s(f
, &s
->disabled_mask
);
366 qemu_put_sbe64s(f
, &s
->clock_offset
);
368 timer_put(f
, s
->qtimer
);
371 void cpu_get_timer(QEMUFile
*f
, CPUTimer
*s
)
373 qemu_get_be32s(f
, &s
->frequency
);
374 qemu_get_be32s(f
, &s
->disabled
);
375 qemu_get_be64s(f
, &s
->disabled_mask
);
376 qemu_get_sbe64s(f
, &s
->clock_offset
);
378 timer_get(f
, s
->qtimer
);
381 static CPUTimer
*cpu_timer_create(const char *name
, SPARCCPU
*cpu
,
382 QEMUBHFunc
*cb
, uint32_t frequency
,
383 uint64_t disabled_mask
)
385 CPUTimer
*timer
= g_malloc0(sizeof (CPUTimer
));
388 timer
->frequency
= frequency
;
389 timer
->disabled_mask
= disabled_mask
;
392 timer
->clock_offset
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
);
394 timer
->qtimer
= timer_new_ns(QEMU_CLOCK_VIRTUAL
, cb
, cpu
);
399 static void cpu_timer_reset(CPUTimer
*timer
)
402 timer
->clock_offset
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
);
404 timer_del(timer
->qtimer
);
407 static void main_cpu_reset(void *opaque
)
409 ResetData
*s
= (ResetData
*)opaque
;
410 CPUSPARCState
*env
= &s
->cpu
->env
;
411 static unsigned int nr_resets
;
413 cpu_reset(CPU(s
->cpu
));
415 cpu_timer_reset(env
->tick
);
416 cpu_timer_reset(env
->stick
);
417 cpu_timer_reset(env
->hstick
);
419 env
->gregs
[1] = 0; // Memory start
420 env
->gregs
[2] = ram_size
; // Memory size
421 env
->gregs
[3] = 0; // Machine description XXX
422 if (nr_resets
++ == 0) {
424 env
->pc
= s
->prom_addr
+ 0x20ULL
;
426 env
->pc
= s
->prom_addr
+ 0x40ULL
;
428 env
->npc
= env
->pc
+ 4;
431 static void tick_irq(void *opaque
)
433 SPARCCPU
*cpu
= opaque
;
434 CPUSPARCState
*env
= &cpu
->env
;
436 CPUTimer
* timer
= env
->tick
;
438 if (timer
->disabled
) {
439 CPUIRQ_DPRINTF("tick_irq: softint disabled\n");
442 CPUIRQ_DPRINTF("tick: fire\n");
445 env
->softint
|= SOFTINT_TIMER
;
449 static void stick_irq(void *opaque
)
451 SPARCCPU
*cpu
= opaque
;
452 CPUSPARCState
*env
= &cpu
->env
;
454 CPUTimer
* timer
= env
->stick
;
456 if (timer
->disabled
) {
457 CPUIRQ_DPRINTF("stick_irq: softint disabled\n");
460 CPUIRQ_DPRINTF("stick: fire\n");
463 env
->softint
|= SOFTINT_STIMER
;
467 static void hstick_irq(void *opaque
)
469 SPARCCPU
*cpu
= opaque
;
470 CPUSPARCState
*env
= &cpu
->env
;
472 CPUTimer
* timer
= env
->hstick
;
474 if (timer
->disabled
) {
475 CPUIRQ_DPRINTF("hstick_irq: softint disabled\n");
478 CPUIRQ_DPRINTF("hstick: fire\n");
481 env
->softint
|= SOFTINT_STIMER
;
485 static int64_t cpu_to_timer_ticks(int64_t cpu_ticks
, uint32_t frequency
)
487 return muldiv64(cpu_ticks
, get_ticks_per_sec(), frequency
);
490 static uint64_t timer_to_cpu_ticks(int64_t timer_ticks
, uint32_t frequency
)
492 return muldiv64(timer_ticks
, frequency
, get_ticks_per_sec());
495 void cpu_tick_set_count(CPUTimer
*timer
, uint64_t count
)
497 uint64_t real_count
= count
& ~timer
->disabled_mask
;
498 uint64_t disabled_bit
= count
& timer
->disabled_mask
;
500 int64_t vm_clock_offset
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) -
501 cpu_to_timer_ticks(real_count
, timer
->frequency
);
503 TIMER_DPRINTF("%s set_count count=0x%016lx (%s) p=%p\n",
504 timer
->name
, real_count
,
505 timer
->disabled
?"disabled":"enabled", timer
);
507 timer
->disabled
= disabled_bit
? 1 : 0;
508 timer
->clock_offset
= vm_clock_offset
;
511 uint64_t cpu_tick_get_count(CPUTimer
*timer
)
513 uint64_t real_count
= timer_to_cpu_ticks(
514 qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) - timer
->clock_offset
,
517 TIMER_DPRINTF("%s get_count count=0x%016lx (%s) p=%p\n",
518 timer
->name
, real_count
,
519 timer
->disabled
?"disabled":"enabled", timer
);
522 real_count
|= timer
->disabled_mask
;
527 void cpu_tick_set_limit(CPUTimer
*timer
, uint64_t limit
)
529 int64_t now
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
);
531 uint64_t real_limit
= limit
& ~timer
->disabled_mask
;
532 timer
->disabled
= (limit
& timer
->disabled_mask
) ? 1 : 0;
534 int64_t expires
= cpu_to_timer_ticks(real_limit
, timer
->frequency
) +
541 TIMER_DPRINTF("%s set_limit limit=0x%016lx (%s) p=%p "
542 "called with limit=0x%016lx at 0x%016lx (delta=0x%016lx)\n",
543 timer
->name
, real_limit
,
544 timer
->disabled
?"disabled":"enabled",
546 timer_to_cpu_ticks(now
- timer
->clock_offset
,
548 timer_to_cpu_ticks(expires
- now
, timer
->frequency
));
551 TIMER_DPRINTF("%s set_limit limit=ZERO - not starting timer\n",
553 timer_del(timer
->qtimer
);
554 } else if (timer
->disabled
) {
555 timer_del(timer
->qtimer
);
557 timer_mod(timer
->qtimer
, expires
);
561 static void isa_irq_handler(void *opaque
, int n
, int level
)
563 static const int isa_irq_to_ivec
[16] = {
564 [1] = 0x29, /* keyboard */
565 [4] = 0x2b, /* serial */
566 [6] = 0x27, /* floppy */
567 [7] = 0x22, /* parallel */
568 [12] = 0x2a, /* mouse */
570 qemu_irq
*irqs
= opaque
;
574 ivec
= isa_irq_to_ivec
[n
];
575 EBUS_DPRINTF("Set ISA IRQ %d level %d -> ivec 0x%x\n", n
, level
, ivec
);
577 qemu_set_irq(irqs
[ivec
], level
);
581 /* EBUS (Eight bit bus) bridge */
583 pci_ebus_init(PCIBus
*bus
, int devfn
, qemu_irq
*irqs
)
589 pci_dev
= pci_create_simple(bus
, devfn
, "ebus");
590 isa_bus
= ISA_BUS(qdev_get_child_bus(DEVICE(pci_dev
), "isa.0"));
591 isa_irq
= qemu_allocate_irqs(isa_irq_handler
, irqs
, 16);
592 isa_bus_irqs(isa_bus
, isa_irq
);
597 pci_ebus_init1(PCIDevice
*pci_dev
)
599 EbusState
*s
= DO_UPCAST(EbusState
, pci_dev
, pci_dev
);
601 isa_bus_new(DEVICE(pci_dev
), get_system_memory(),
602 pci_address_space_io(pci_dev
));
604 pci_dev
->config
[0x04] = 0x06; // command = bus master, pci mem
605 pci_dev
->config
[0x05] = 0x00;
606 pci_dev
->config
[0x06] = 0xa0; // status = fast back-to-back, 66MHz, no error
607 pci_dev
->config
[0x07] = 0x03; // status = medium devsel
608 pci_dev
->config
[0x09] = 0x00; // programming i/f
609 pci_dev
->config
[0x0D] = 0x0a; // latency_timer
611 memory_region_init_alias(&s
->bar0
, OBJECT(s
), "bar0", get_system_io(),
613 pci_register_bar(pci_dev
, 0, PCI_BASE_ADDRESS_SPACE_MEMORY
, &s
->bar0
);
614 memory_region_init_alias(&s
->bar1
, OBJECT(s
), "bar1", get_system_io(),
616 pci_register_bar(pci_dev
, 1, PCI_BASE_ADDRESS_SPACE_IO
, &s
->bar1
);
620 static void ebus_class_init(ObjectClass
*klass
, void *data
)
622 PCIDeviceClass
*k
= PCI_DEVICE_CLASS(klass
);
624 k
->init
= pci_ebus_init1
;
625 k
->vendor_id
= PCI_VENDOR_ID_SUN
;
626 k
->device_id
= PCI_DEVICE_ID_SUN_EBUS
;
628 k
->class_id
= PCI_CLASS_BRIDGE_OTHER
;
631 static const TypeInfo ebus_info
= {
633 .parent
= TYPE_PCI_DEVICE
,
634 .instance_size
= sizeof(EbusState
),
635 .class_init
= ebus_class_init
,
638 #define TYPE_OPENPROM "openprom"
639 #define OPENPROM(obj) OBJECT_CHECK(PROMState, (obj), TYPE_OPENPROM)
641 typedef struct PROMState
{
642 SysBusDevice parent_obj
;
647 static uint64_t translate_prom_address(void *opaque
, uint64_t addr
)
649 hwaddr
*base_addr
= (hwaddr
*)opaque
;
650 return addr
+ *base_addr
- PROM_VADDR
;
653 /* Boot PROM (OpenBIOS) */
654 static void prom_init(hwaddr addr
, const char *bios_name
)
661 dev
= qdev_create(NULL
, TYPE_OPENPROM
);
662 qdev_init_nofail(dev
);
663 s
= SYS_BUS_DEVICE(dev
);
665 sysbus_mmio_map(s
, 0, addr
);
668 if (bios_name
== NULL
) {
669 bios_name
= PROM_FILENAME
;
671 filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, bios_name
);
673 ret
= load_elf(filename
, translate_prom_address
, &addr
,
674 NULL
, NULL
, NULL
, 1, ELF_MACHINE
, 0);
675 if (ret
< 0 || ret
> PROM_SIZE_MAX
) {
676 ret
= load_image_targphys(filename
, addr
, PROM_SIZE_MAX
);
682 if (ret
< 0 || ret
> PROM_SIZE_MAX
) {
683 fprintf(stderr
, "qemu: could not load prom '%s'\n", bios_name
);
688 static int prom_init1(SysBusDevice
*dev
)
690 PROMState
*s
= OPENPROM(dev
);
692 memory_region_init_ram(&s
->prom
, OBJECT(s
), "sun4u.prom", PROM_SIZE_MAX
,
694 vmstate_register_ram_global(&s
->prom
);
695 memory_region_set_readonly(&s
->prom
, true);
696 sysbus_init_mmio(dev
, &s
->prom
);
700 static Property prom_properties
[] = {
701 {/* end of property list */},
704 static void prom_class_init(ObjectClass
*klass
, void *data
)
706 DeviceClass
*dc
= DEVICE_CLASS(klass
);
707 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
709 k
->init
= prom_init1
;
710 dc
->props
= prom_properties
;
713 static const TypeInfo prom_info
= {
714 .name
= TYPE_OPENPROM
,
715 .parent
= TYPE_SYS_BUS_DEVICE
,
716 .instance_size
= sizeof(PROMState
),
717 .class_init
= prom_class_init
,
721 #define TYPE_SUN4U_MEMORY "memory"
722 #define SUN4U_RAM(obj) OBJECT_CHECK(RamDevice, (obj), TYPE_SUN4U_MEMORY)
724 typedef struct RamDevice
{
725 SysBusDevice parent_obj
;
732 static int ram_init1(SysBusDevice
*dev
)
734 RamDevice
*d
= SUN4U_RAM(dev
);
736 memory_region_init_ram(&d
->ram
, OBJECT(d
), "sun4u.ram", d
->size
,
738 vmstate_register_ram_global(&d
->ram
);
739 sysbus_init_mmio(dev
, &d
->ram
);
743 static void ram_init(hwaddr addr
, ram_addr_t RAM_size
)
750 dev
= qdev_create(NULL
, TYPE_SUN4U_MEMORY
);
751 s
= SYS_BUS_DEVICE(dev
);
755 qdev_init_nofail(dev
);
757 sysbus_mmio_map(s
, 0, addr
);
760 static Property ram_properties
[] = {
761 DEFINE_PROP_UINT64("size", RamDevice
, size
, 0),
762 DEFINE_PROP_END_OF_LIST(),
765 static void ram_class_init(ObjectClass
*klass
, void *data
)
767 DeviceClass
*dc
= DEVICE_CLASS(klass
);
768 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
771 dc
->props
= ram_properties
;
774 static const TypeInfo ram_info
= {
775 .name
= TYPE_SUN4U_MEMORY
,
776 .parent
= TYPE_SYS_BUS_DEVICE
,
777 .instance_size
= sizeof(RamDevice
),
778 .class_init
= ram_class_init
,
781 static SPARCCPU
*cpu_devinit(const char *cpu_model
, const struct hwdef
*hwdef
)
785 ResetData
*reset_info
;
787 uint32_t tick_frequency
= 100*1000000;
788 uint32_t stick_frequency
= 100*1000000;
789 uint32_t hstick_frequency
= 100*1000000;
791 if (cpu_model
== NULL
) {
792 cpu_model
= hwdef
->default_cpu_model
;
794 cpu
= cpu_sparc_init(cpu_model
);
796 fprintf(stderr
, "Unable to find Sparc CPU definition\n");
801 env
->tick
= cpu_timer_create("tick", cpu
, tick_irq
,
802 tick_frequency
, TICK_NPT_MASK
);
804 env
->stick
= cpu_timer_create("stick", cpu
, stick_irq
,
805 stick_frequency
, TICK_INT_DIS
);
807 env
->hstick
= cpu_timer_create("hstick", cpu
, hstick_irq
,
808 hstick_frequency
, TICK_INT_DIS
);
810 reset_info
= g_malloc0(sizeof(ResetData
));
811 reset_info
->cpu
= cpu
;
812 reset_info
->prom_addr
= hwdef
->prom_addr
;
813 qemu_register_reset(main_cpu_reset
, reset_info
);
818 static void sun4uv_init(MemoryRegion
*address_space_mem
,
819 MachineState
*machine
,
820 const struct hwdef
*hwdef
)
825 uint64_t initrd_addr
, initrd_size
, kernel_addr
, kernel_size
, kernel_entry
;
826 PCIBus
*pci_bus
, *pci_bus2
, *pci_bus3
;
829 qemu_irq
*ivec_irqs
, *pbm_irqs
;
830 DriveInfo
*hd
[MAX_IDE_BUS
* MAX_IDE_DEVS
];
831 DriveInfo
*fd
[MAX_FD
];
835 cpu
= cpu_devinit(machine
->cpu_model
, hwdef
);
838 ram_init(0, machine
->ram_size
);
840 prom_init(hwdef
->prom_addr
, bios_name
);
842 ivec_irqs
= qemu_allocate_irqs(cpu_set_ivec_irq
, cpu
, IVEC_MAX
);
843 pci_bus
= pci_apb_init(APB_SPECIAL_BASE
, APB_MEM_BASE
, ivec_irqs
, &pci_bus2
,
844 &pci_bus3
, &pbm_irqs
);
845 pci_vga_init(pci_bus
);
847 // XXX Should be pci_bus3
848 isa_bus
= pci_ebus_init(pci_bus
, -1, pbm_irqs
);
851 if (hwdef
->console_serial_base
) {
852 serial_mm_init(address_space_mem
, hwdef
->console_serial_base
, 0,
853 NULL
, 115200, serial_hds
[i
], DEVICE_BIG_ENDIAN
);
857 serial_hds_isa_init(isa_bus
, MAX_SERIAL_PORTS
);
858 parallel_hds_isa_init(isa_bus
, MAX_PARALLEL_PORTS
);
860 for(i
= 0; i
< nb_nics
; i
++)
861 pci_nic_init_nofail(&nd_table
[i
], pci_bus
, "ne2k_pci", NULL
);
863 ide_drive_get(hd
, ARRAY_SIZE(hd
));
865 pci_cmd646_ide_init(pci_bus
, hd
, 1);
867 isa_create_simple(isa_bus
, "i8042");
868 for(i
= 0; i
< MAX_FD
; i
++) {
869 fd
[i
] = drive_get(IF_FLOPPY
, 0, i
);
871 fdctrl_init_isa(isa_bus
, fd
);
873 /* Map NVRAM into I/O (ebus) space */
874 nvram
= m48t59_init(NULL
, 0, 0, NVRAM_SIZE
, 1968, 59);
875 s
= SYS_BUS_DEVICE(nvram
);
876 memory_region_add_subregion(get_system_io(), 0x2000,
877 sysbus_mmio_get_region(s
, 0));
881 kernel_size
= sun4u_load_kernel(machine
->kernel_filename
,
882 machine
->initrd_filename
,
883 ram_size
, &initrd_size
, &initrd_addr
,
884 &kernel_addr
, &kernel_entry
);
886 sun4u_NVRAM_set_params(nvram
, NVRAM_SIZE
, "Sun4u", machine
->ram_size
,
888 kernel_addr
, kernel_size
,
889 machine
->kernel_cmdline
,
890 initrd_addr
, initrd_size
,
891 /* XXX: need an option to load a NVRAM image */
893 graphic_width
, graphic_height
, graphic_depth
,
894 (uint8_t *)&nd_table
[0].macaddr
);
896 fw_cfg
= fw_cfg_init_io(BIOS_CFG_IOPORT
);
897 fw_cfg_add_i16(fw_cfg
, FW_CFG_MAX_CPUS
, (uint16_t)max_cpus
);
898 fw_cfg_add_i64(fw_cfg
, FW_CFG_RAM_SIZE
, (uint64_t)ram_size
);
899 fw_cfg_add_i16(fw_cfg
, FW_CFG_MACHINE_ID
, hwdef
->machine_id
);
900 fw_cfg_add_i64(fw_cfg
, FW_CFG_KERNEL_ADDR
, kernel_entry
);
901 fw_cfg_add_i64(fw_cfg
, FW_CFG_KERNEL_SIZE
, kernel_size
);
902 if (machine
->kernel_cmdline
) {
903 fw_cfg_add_i32(fw_cfg
, FW_CFG_CMDLINE_SIZE
,
904 strlen(machine
->kernel_cmdline
) + 1);
905 fw_cfg_add_string(fw_cfg
, FW_CFG_CMDLINE_DATA
, machine
->kernel_cmdline
);
907 fw_cfg_add_i32(fw_cfg
, FW_CFG_CMDLINE_SIZE
, 0);
909 fw_cfg_add_i64(fw_cfg
, FW_CFG_INITRD_ADDR
, initrd_addr
);
910 fw_cfg_add_i64(fw_cfg
, FW_CFG_INITRD_SIZE
, initrd_size
);
911 fw_cfg_add_i16(fw_cfg
, FW_CFG_BOOT_DEVICE
, machine
->boot_order
[0]);
913 fw_cfg_add_i16(fw_cfg
, FW_CFG_SPARC64_WIDTH
, graphic_width
);
914 fw_cfg_add_i16(fw_cfg
, FW_CFG_SPARC64_HEIGHT
, graphic_height
);
915 fw_cfg_add_i16(fw_cfg
, FW_CFG_SPARC64_DEPTH
, graphic_depth
);
917 qemu_register_boot_set(fw_cfg_boot_set
, fw_cfg
);
926 static const struct hwdef hwdefs
[] = {
927 /* Sun4u generic PC-like machine */
929 .default_cpu_model
= "TI UltraSparc IIi",
930 .machine_id
= sun4u_id
,
931 .prom_addr
= 0x1fff0000000ULL
,
932 .console_serial_base
= 0,
934 /* Sun4v generic PC-like machine */
936 .default_cpu_model
= "Sun UltraSparc T1",
937 .machine_id
= sun4v_id
,
938 .prom_addr
= 0x1fff0000000ULL
,
939 .console_serial_base
= 0,
941 /* Sun4v generic Niagara machine */
943 .default_cpu_model
= "Sun UltraSparc T1",
944 .machine_id
= niagara_id
,
945 .prom_addr
= 0xfff0000000ULL
,
946 .console_serial_base
= 0xfff0c2c000ULL
,
950 /* Sun4u hardware initialisation */
951 static void sun4u_init(MachineState
*machine
)
953 sun4uv_init(get_system_memory(), machine
, &hwdefs
[0]);
956 /* Sun4v hardware initialisation */
957 static void sun4v_init(MachineState
*machine
)
959 sun4uv_init(get_system_memory(), machine
, &hwdefs
[1]);
962 /* Niagara hardware initialisation */
963 static void niagara_init(MachineState
*machine
)
965 sun4uv_init(get_system_memory(), machine
, &hwdefs
[2]);
968 static QEMUMachine sun4u_machine
= {
970 .desc
= "Sun4u platform",
972 .max_cpus
= 1, // XXX for now
974 .default_boot_order
= "c",
977 static QEMUMachine sun4v_machine
= {
979 .desc
= "Sun4v platform",
981 .max_cpus
= 1, // XXX for now
982 .default_boot_order
= "c",
985 static QEMUMachine niagara_machine
= {
987 .desc
= "Sun4v platform, Niagara",
988 .init
= niagara_init
,
989 .max_cpus
= 1, // XXX for now
990 .default_boot_order
= "c",
993 static void sun4u_register_types(void)
995 type_register_static(&ebus_info
);
996 type_register_static(&prom_info
);
997 type_register_static(&ram_info
);
1000 static void sun4u_machine_init(void)
1002 qemu_register_machine(&sun4u_machine
);
1003 qemu_register_machine(&sun4v_machine
);
1004 qemu_register_machine(&niagara_machine
);
1007 type_init(sun4u_register_types
)
1008 machine_init(sun4u_machine_init
);