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 "qemu/units.h"
26 #include "qemu/error-report.h"
27 #include "qapi/error.h"
28 #include "qemu-common.h"
31 #include "hw/pci/pci.h"
32 #include "hw/pci/pci_bridge.h"
33 #include "hw/pci/pci_bus.h"
34 #include "hw/pci/pci_host.h"
35 #include "hw/pci-host/sabre.h"
36 #include "hw/i386/pc.h"
37 #include "hw/char/serial.h"
38 #include "hw/char/parallel.h"
39 #include "hw/timer/m48t59.h"
40 #include "hw/input/i8042.h"
41 #include "hw/block/fdc.h"
43 #include "qemu/timer.h"
44 #include "sysemu/sysemu.h"
45 #include "hw/boards.h"
46 #include "hw/nvram/sun_nvram.h"
47 #include "hw/nvram/chrp_nvram.h"
48 #include "hw/sparc/sparc64.h"
49 #include "hw/nvram/fw_cfg.h"
50 #include "hw/sysbus.h"
52 #include "hw/ide/pci.h"
53 #include "hw/loader.h"
54 #include "hw/fw-path-provider.h"
58 #define KERNEL_LOAD_ADDR 0x00404000
59 #define CMDLINE_ADDR 0x003ff000
60 #define PROM_SIZE_MAX (4 * MiB)
61 #define PROM_VADDR 0x000ffd00000ULL
62 #define PBM_SPECIAL_BASE 0x1fe00000000ULL
63 #define PBM_MEM_BASE 0x1ff00000000ULL
64 #define PBM_PCI_IO_BASE (PBM_SPECIAL_BASE + 0x02000000ULL)
65 #define PROM_FILENAME "openbios-sparc64"
66 #define NVRAM_SIZE 0x2000
68 #define BIOS_CFG_IOPORT 0x510
69 #define FW_CFG_SPARC64_WIDTH (FW_CFG_ARCH_LOCAL + 0x00)
70 #define FW_CFG_SPARC64_HEIGHT (FW_CFG_ARCH_LOCAL + 0x01)
71 #define FW_CFG_SPARC64_DEPTH (FW_CFG_ARCH_LOCAL + 0x02)
78 uint64_t console_serial_base
;
81 typedef struct EbusState
{
86 qemu_irq isa_bus_irqs
[ISA_NUM_IRQS
];
87 uint64_t console_serial_base
;
92 #define TYPE_EBUS "ebus"
93 #define EBUS(obj) OBJECT_CHECK(EbusState, (obj), TYPE_EBUS)
95 static void fw_cfg_boot_set(void *opaque
, const char *boot_device
,
98 fw_cfg_modify_i16(opaque
, FW_CFG_BOOT_DEVICE
, boot_device
[0]);
101 static int sun4u_NVRAM_set_params(Nvram
*nvram
, uint16_t NVRAM_size
,
102 const char *arch
, ram_addr_t RAM_size
,
103 const char *boot_devices
,
104 uint32_t kernel_image
, uint32_t kernel_size
,
106 uint32_t initrd_image
, uint32_t initrd_size
,
107 uint32_t NVRAM_image
,
108 int width
, int height
, int depth
,
109 const uint8_t *macaddr
)
113 uint8_t image
[0x1ff0];
114 NvramClass
*k
= NVRAM_GET_CLASS(nvram
);
116 memset(image
, '\0', sizeof(image
));
118 /* OpenBIOS nvram variables partition */
119 sysp_end
= chrp_nvram_create_system_partition(image
, 0);
121 /* Free space partition */
122 chrp_nvram_create_free_partition(&image
[sysp_end
], 0x1fd0 - sysp_end
);
124 Sun_init_header((struct Sun_nvram
*)&image
[0x1fd8], macaddr
, 0x80);
126 for (i
= 0; i
< sizeof(image
); i
++) {
127 (k
->write
)(nvram
, i
, image
[i
]);
133 static uint64_t sun4u_load_kernel(const char *kernel_filename
,
134 const char *initrd_filename
,
135 ram_addr_t RAM_size
, uint64_t *initrd_size
,
136 uint64_t *initrd_addr
, uint64_t *kernel_addr
,
137 uint64_t *kernel_entry
)
143 uint64_t kernel_top
= 0;
145 linux_boot
= (kernel_filename
!= NULL
);
156 kernel_size
= load_elf(kernel_filename
, NULL
, NULL
, kernel_entry
,
157 kernel_addr
, &kernel_top
, 1, EM_SPARCV9
, 0, 0);
158 if (kernel_size
< 0) {
159 *kernel_addr
= KERNEL_LOAD_ADDR
;
160 *kernel_entry
= KERNEL_LOAD_ADDR
;
161 kernel_size
= load_aout(kernel_filename
, KERNEL_LOAD_ADDR
,
162 RAM_size
- KERNEL_LOAD_ADDR
, bswap_needed
,
165 if (kernel_size
< 0) {
166 kernel_size
= load_image_targphys(kernel_filename
,
168 RAM_size
- KERNEL_LOAD_ADDR
);
170 if (kernel_size
< 0) {
171 error_report("could not load kernel '%s'", kernel_filename
);
174 /* load initrd above kernel */
176 if (initrd_filename
&& kernel_top
) {
177 *initrd_addr
= TARGET_PAGE_ALIGN(kernel_top
);
179 *initrd_size
= load_image_targphys(initrd_filename
,
181 RAM_size
- *initrd_addr
);
182 if ((int)*initrd_size
< 0) {
183 error_report("could not load initial ram disk '%s'",
188 if (*initrd_size
> 0) {
189 for (i
= 0; i
< 64 * TARGET_PAGE_SIZE
; i
+= TARGET_PAGE_SIZE
) {
190 ptr
= rom_ptr(*kernel_addr
+ i
, 32);
191 if (ptr
&& ldl_p(ptr
+ 8) == 0x48647253) { /* HdrS */
192 stl_p(ptr
+ 24, *initrd_addr
+ *kernel_addr
);
193 stl_p(ptr
+ 28, *initrd_size
);
202 typedef struct ResetData
{
207 #define TYPE_SUN4U_POWER "power"
208 #define SUN4U_POWER(obj) OBJECT_CHECK(PowerDevice, (obj), TYPE_SUN4U_POWER)
210 typedef struct PowerDevice
{
211 SysBusDevice parent_obj
;
213 MemoryRegion power_mmio
;
217 static void power_mem_write(void *opaque
, hwaddr addr
,
218 uint64_t val
, unsigned size
)
220 /* According to a real Ultra 5, bit 24 controls the power */
221 if (val
& 0x1000000) {
222 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN
);
226 static const MemoryRegionOps power_mem_ops
= {
227 .write
= power_mem_write
,
228 .endianness
= DEVICE_NATIVE_ENDIAN
,
230 .min_access_size
= 4,
231 .max_access_size
= 4,
235 static void power_realize(DeviceState
*dev
, Error
**errp
)
237 PowerDevice
*d
= SUN4U_POWER(dev
);
238 SysBusDevice
*sbd
= SYS_BUS_DEVICE(dev
);
240 memory_region_init_io(&d
->power_mmio
, OBJECT(dev
), &power_mem_ops
, d
,
241 "power", sizeof(uint32_t));
243 sysbus_init_mmio(sbd
, &d
->power_mmio
);
246 static void power_class_init(ObjectClass
*klass
, void *data
)
248 DeviceClass
*dc
= DEVICE_CLASS(klass
);
250 dc
->realize
= power_realize
;
253 static const TypeInfo power_info
= {
254 .name
= TYPE_SUN4U_POWER
,
255 .parent
= TYPE_SYS_BUS_DEVICE
,
256 .instance_size
= sizeof(PowerDevice
),
257 .class_init
= power_class_init
,
260 static void ebus_isa_irq_handler(void *opaque
, int n
, int level
)
262 EbusState
*s
= EBUS(opaque
);
263 qemu_irq irq
= s
->isa_bus_irqs
[n
];
265 /* Pass ISA bus IRQs onto their gpio equivalent */
266 trace_ebus_isa_irq_handler(n
, level
);
268 qemu_set_irq(irq
, level
);
272 /* EBUS (Eight bit bus) bridge */
273 static void ebus_realize(PCIDevice
*pci_dev
, Error
**errp
)
275 EbusState
*s
= EBUS(pci_dev
);
279 DriveInfo
*fd
[MAX_FD
];
282 s
->isa_bus
= isa_bus_new(DEVICE(pci_dev
), get_system_memory(),
283 pci_address_space_io(pci_dev
), errp
);
285 error_setg(errp
, "unable to instantiate EBUS ISA bus");
290 isa_irq
= qemu_allocate_irqs(ebus_isa_irq_handler
, s
, ISA_NUM_IRQS
);
291 isa_bus_irqs(s
->isa_bus
, isa_irq
);
292 qdev_init_gpio_out_named(DEVICE(s
), s
->isa_bus_irqs
, "isa-irq",
297 if (s
->console_serial_base
) {
298 serial_mm_init(pci_address_space(pci_dev
), s
->console_serial_base
,
299 0, NULL
, 115200, serial_hd(i
), DEVICE_BIG_ENDIAN
);
302 serial_hds_isa_init(s
->isa_bus
, i
, MAX_ISA_SERIAL_PORTS
);
305 parallel_hds_isa_init(s
->isa_bus
, MAX_PARALLEL_PORTS
);
308 isa_create_simple(s
->isa_bus
, "i8042");
311 for (i
= 0; i
< MAX_FD
; i
++) {
312 fd
[i
] = drive_get(IF_FLOPPY
, 0, i
);
314 dev
= DEVICE(isa_create(s
->isa_bus
, TYPE_ISA_FDC
));
316 qdev_prop_set_drive(dev
, "driveA", blk_by_legacy_dinfo(fd
[0]),
320 qdev_prop_set_drive(dev
, "driveB", blk_by_legacy_dinfo(fd
[1]),
323 qdev_prop_set_uint32(dev
, "dma", -1);
324 qdev_init_nofail(dev
);
327 dev
= qdev_create(NULL
, TYPE_SUN4U_POWER
);
328 qdev_init_nofail(dev
);
329 sbd
= SYS_BUS_DEVICE(dev
);
330 memory_region_add_subregion(pci_address_space_io(pci_dev
), 0x7240,
331 sysbus_mmio_get_region(sbd
, 0));
334 pci_dev
->config
[0x04] = 0x06; // command = bus master, pci mem
335 pci_dev
->config
[0x05] = 0x00;
336 pci_dev
->config
[0x06] = 0xa0; // status = fast back-to-back, 66MHz, no error
337 pci_dev
->config
[0x07] = 0x03; // status = medium devsel
338 pci_dev
->config
[0x09] = 0x00; // programming i/f
339 pci_dev
->config
[0x0D] = 0x0a; // latency_timer
341 memory_region_init_alias(&s
->bar0
, OBJECT(s
), "bar0", get_system_io(),
343 pci_register_bar(pci_dev
, 0, PCI_BASE_ADDRESS_SPACE_MEMORY
, &s
->bar0
);
344 memory_region_init_alias(&s
->bar1
, OBJECT(s
), "bar1", get_system_io(),
346 pci_register_bar(pci_dev
, 1, PCI_BASE_ADDRESS_SPACE_IO
, &s
->bar1
);
349 static Property ebus_properties
[] = {
350 DEFINE_PROP_UINT64("console-serial-base", EbusState
,
351 console_serial_base
, 0),
352 DEFINE_PROP_END_OF_LIST(),
355 static void ebus_class_init(ObjectClass
*klass
, void *data
)
357 PCIDeviceClass
*k
= PCI_DEVICE_CLASS(klass
);
358 DeviceClass
*dc
= DEVICE_CLASS(klass
);
360 k
->realize
= ebus_realize
;
361 k
->vendor_id
= PCI_VENDOR_ID_SUN
;
362 k
->device_id
= PCI_DEVICE_ID_SUN_EBUS
;
364 k
->class_id
= PCI_CLASS_BRIDGE_OTHER
;
365 dc
->props
= ebus_properties
;
368 static const TypeInfo ebus_info
= {
370 .parent
= TYPE_PCI_DEVICE
,
371 .class_init
= ebus_class_init
,
372 .instance_size
= sizeof(EbusState
),
373 .interfaces
= (InterfaceInfo
[]) {
374 { INTERFACE_CONVENTIONAL_PCI_DEVICE
},
379 #define TYPE_OPENPROM "openprom"
380 #define OPENPROM(obj) OBJECT_CHECK(PROMState, (obj), TYPE_OPENPROM)
382 typedef struct PROMState
{
383 SysBusDevice parent_obj
;
388 static uint64_t translate_prom_address(void *opaque
, uint64_t addr
)
390 hwaddr
*base_addr
= (hwaddr
*)opaque
;
391 return addr
+ *base_addr
- PROM_VADDR
;
394 /* Boot PROM (OpenBIOS) */
395 static void prom_init(hwaddr addr
, const char *bios_name
)
402 dev
= qdev_create(NULL
, TYPE_OPENPROM
);
403 qdev_init_nofail(dev
);
404 s
= SYS_BUS_DEVICE(dev
);
406 sysbus_mmio_map(s
, 0, addr
);
409 if (bios_name
== NULL
) {
410 bios_name
= PROM_FILENAME
;
412 filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, bios_name
);
414 ret
= load_elf(filename
, translate_prom_address
, &addr
,
415 NULL
, NULL
, NULL
, 1, EM_SPARCV9
, 0, 0);
416 if (ret
< 0 || ret
> PROM_SIZE_MAX
) {
417 ret
= load_image_targphys(filename
, addr
, PROM_SIZE_MAX
);
423 if (ret
< 0 || ret
> PROM_SIZE_MAX
) {
424 error_report("could not load prom '%s'", bios_name
);
429 static void prom_realize(DeviceState
*ds
, Error
**errp
)
431 PROMState
*s
= OPENPROM(ds
);
432 SysBusDevice
*dev
= SYS_BUS_DEVICE(ds
);
433 Error
*local_err
= NULL
;
435 memory_region_init_ram_nomigrate(&s
->prom
, OBJECT(ds
), "sun4u.prom",
436 PROM_SIZE_MAX
, &local_err
);
438 error_propagate(errp
, local_err
);
442 vmstate_register_ram_global(&s
->prom
);
443 memory_region_set_readonly(&s
->prom
, true);
444 sysbus_init_mmio(dev
, &s
->prom
);
447 static Property prom_properties
[] = {
448 {/* end of property list */},
451 static void prom_class_init(ObjectClass
*klass
, void *data
)
453 DeviceClass
*dc
= DEVICE_CLASS(klass
);
455 dc
->props
= prom_properties
;
456 dc
->realize
= prom_realize
;
459 static const TypeInfo prom_info
= {
460 .name
= TYPE_OPENPROM
,
461 .parent
= TYPE_SYS_BUS_DEVICE
,
462 .instance_size
= sizeof(PROMState
),
463 .class_init
= prom_class_init
,
467 #define TYPE_SUN4U_MEMORY "memory"
468 #define SUN4U_RAM(obj) OBJECT_CHECK(RamDevice, (obj), TYPE_SUN4U_MEMORY)
470 typedef struct RamDevice
{
471 SysBusDevice parent_obj
;
478 static void ram_realize(DeviceState
*dev
, Error
**errp
)
480 RamDevice
*d
= SUN4U_RAM(dev
);
481 SysBusDevice
*sbd
= SYS_BUS_DEVICE(dev
);
483 memory_region_init_ram_nomigrate(&d
->ram
, OBJECT(d
), "sun4u.ram", d
->size
,
485 vmstate_register_ram_global(&d
->ram
);
486 sysbus_init_mmio(sbd
, &d
->ram
);
489 static void ram_init(hwaddr addr
, ram_addr_t RAM_size
)
496 dev
= qdev_create(NULL
, TYPE_SUN4U_MEMORY
);
497 s
= SYS_BUS_DEVICE(dev
);
501 qdev_init_nofail(dev
);
503 sysbus_mmio_map(s
, 0, addr
);
506 static Property ram_properties
[] = {
507 DEFINE_PROP_UINT64("size", RamDevice
, size
, 0),
508 DEFINE_PROP_END_OF_LIST(),
511 static void ram_class_init(ObjectClass
*klass
, void *data
)
513 DeviceClass
*dc
= DEVICE_CLASS(klass
);
515 dc
->realize
= ram_realize
;
516 dc
->props
= ram_properties
;
519 static const TypeInfo ram_info
= {
520 .name
= TYPE_SUN4U_MEMORY
,
521 .parent
= TYPE_SYS_BUS_DEVICE
,
522 .instance_size
= sizeof(RamDevice
),
523 .class_init
= ram_class_init
,
526 static void sun4uv_init(MemoryRegion
*address_space_mem
,
527 MachineState
*machine
,
528 const struct hwdef
*hwdef
)
533 uint64_t initrd_addr
, initrd_size
, kernel_addr
, kernel_size
, kernel_entry
;
535 PCIBus
*pci_bus
, *pci_busA
, *pci_busB
;
536 PCIDevice
*ebus
, *pci_dev
;
538 DriveInfo
*hd
[MAX_IDE_BUS
* MAX_IDE_DEVS
];
539 DeviceState
*iommu
, *dev
;
546 cpu
= sparc64_cpu_devinit(machine
->cpu_type
, hwdef
->prom_addr
);
549 iommu
= qdev_create(NULL
, TYPE_SUN4U_IOMMU
);
550 qdev_init_nofail(iommu
);
553 ram_init(0, machine
->ram_size
);
555 prom_init(hwdef
->prom_addr
, bios_name
);
557 /* Init sabre (PCI host bridge) */
558 sabre
= SABRE_DEVICE(qdev_create(NULL
, TYPE_SABRE
));
559 qdev_prop_set_uint64(DEVICE(sabre
), "special-base", PBM_SPECIAL_BASE
);
560 qdev_prop_set_uint64(DEVICE(sabre
), "mem-base", PBM_MEM_BASE
);
561 object_property_set_link(OBJECT(sabre
), OBJECT(iommu
), "iommu",
563 qdev_init_nofail(DEVICE(sabre
));
565 /* Wire up PCI interrupts to CPU */
566 for (i
= 0; i
< IVEC_MAX
; i
++) {
567 qdev_connect_gpio_out_named(DEVICE(sabre
), "ivec-irq", i
,
568 qdev_get_gpio_in_named(DEVICE(cpu
), "ivec-irq", i
));
571 pci_bus
= PCI_HOST_BRIDGE(sabre
)->bus
;
572 pci_busA
= pci_bridge_get_sec_bus(sabre
->bridgeA
);
573 pci_busB
= pci_bridge_get_sec_bus(sabre
->bridgeB
);
575 /* Only in-built Simba APBs can exist on the root bus, slot 0 on busA is
576 reserved (leaving no slots free after on-board devices) however slots
577 0-3 are free on busB */
578 pci_bus
->slot_reserved_mask
= 0xfffffffc;
579 pci_busA
->slot_reserved_mask
= 0xfffffff1;
580 pci_busB
->slot_reserved_mask
= 0xfffffff0;
582 ebus
= pci_create_multifunction(pci_busA
, PCI_DEVFN(1, 0), true, TYPE_EBUS
);
583 qdev_prop_set_uint64(DEVICE(ebus
), "console-serial-base",
584 hwdef
->console_serial_base
);
585 qdev_init_nofail(DEVICE(ebus
));
587 /* Wire up "well-known" ISA IRQs to PBM legacy obio IRQs */
588 qdev_connect_gpio_out_named(DEVICE(ebus
), "isa-irq", 7,
589 qdev_get_gpio_in_named(DEVICE(sabre
), "pbm-irq", OBIO_LPT_IRQ
));
590 qdev_connect_gpio_out_named(DEVICE(ebus
), "isa-irq", 6,
591 qdev_get_gpio_in_named(DEVICE(sabre
), "pbm-irq", OBIO_FDD_IRQ
));
592 qdev_connect_gpio_out_named(DEVICE(ebus
), "isa-irq", 1,
593 qdev_get_gpio_in_named(DEVICE(sabre
), "pbm-irq", OBIO_KBD_IRQ
));
594 qdev_connect_gpio_out_named(DEVICE(ebus
), "isa-irq", 12,
595 qdev_get_gpio_in_named(DEVICE(sabre
), "pbm-irq", OBIO_MSE_IRQ
));
596 qdev_connect_gpio_out_named(DEVICE(ebus
), "isa-irq", 4,
597 qdev_get_gpio_in_named(DEVICE(sabre
), "pbm-irq", OBIO_SER_IRQ
));
599 pci_dev
= pci_create_simple(pci_busA
, PCI_DEVFN(2, 0), "VGA");
601 memset(&macaddr
, 0, sizeof(MACAddr
));
603 for (i
= 0; i
< nb_nics
; i
++) {
606 if (!nd
->model
|| strcmp(nd
->model
, "sunhme") == 0) {
608 pci_dev
= pci_create_multifunction(pci_busA
, PCI_DEVFN(1, 1),
610 memcpy(&macaddr
, &nd
->macaddr
.a
, sizeof(MACAddr
));
613 pci_dev
= pci_create(pci_busB
, -1, "sunhme");
616 pci_dev
= pci_create(pci_busB
, -1, nd
->model
);
619 dev
= &pci_dev
->qdev
;
620 qdev_set_nic_properties(dev
, nd
);
621 qdev_init_nofail(dev
);
624 /* If we don't have an onboard NIC, grab a default MAC address so that
625 * we have a valid machine id */
627 qemu_macaddr_default_if_unset(&macaddr
);
630 ide_drive_get(hd
, ARRAY_SIZE(hd
));
632 pci_dev
= pci_create(pci_busA
, PCI_DEVFN(3, 0), "cmd646-ide");
633 qdev_prop_set_uint32(&pci_dev
->qdev
, "secondary", 1);
634 qdev_init_nofail(&pci_dev
->qdev
);
635 pci_ide_create_devs(pci_dev
, hd
);
637 /* Map NVRAM into I/O (ebus) space */
638 nvram
= m48t59_init(NULL
, 0, 0, NVRAM_SIZE
, 1968, 59);
639 s
= SYS_BUS_DEVICE(nvram
);
640 memory_region_add_subregion(pci_address_space_io(ebus
), 0x2000,
641 sysbus_mmio_get_region(s
, 0));
645 kernel_size
= sun4u_load_kernel(machine
->kernel_filename
,
646 machine
->initrd_filename
,
647 ram_size
, &initrd_size
, &initrd_addr
,
648 &kernel_addr
, &kernel_entry
);
650 sun4u_NVRAM_set_params(nvram
, NVRAM_SIZE
, "Sun4u", machine
->ram_size
,
652 kernel_addr
, kernel_size
,
653 machine
->kernel_cmdline
,
654 initrd_addr
, initrd_size
,
655 /* XXX: need an option to load a NVRAM image */
657 graphic_width
, graphic_height
, graphic_depth
,
658 (uint8_t *)&macaddr
);
660 dev
= qdev_create(NULL
, TYPE_FW_CFG_IO
);
661 qdev_prop_set_bit(dev
, "dma_enabled", false);
662 object_property_add_child(OBJECT(ebus
), TYPE_FW_CFG
, OBJECT(dev
), NULL
);
663 qdev_init_nofail(dev
);
664 memory_region_add_subregion(pci_address_space_io(ebus
), BIOS_CFG_IOPORT
,
665 &FW_CFG_IO(dev
)->comb_iomem
);
667 fw_cfg
= FW_CFG(dev
);
668 fw_cfg_add_i16(fw_cfg
, FW_CFG_NB_CPUS
, (uint16_t)smp_cpus
);
669 fw_cfg_add_i16(fw_cfg
, FW_CFG_MAX_CPUS
, (uint16_t)max_cpus
);
670 fw_cfg_add_i64(fw_cfg
, FW_CFG_RAM_SIZE
, (uint64_t)ram_size
);
671 fw_cfg_add_i16(fw_cfg
, FW_CFG_MACHINE_ID
, hwdef
->machine_id
);
672 fw_cfg_add_i64(fw_cfg
, FW_CFG_KERNEL_ADDR
, kernel_entry
);
673 fw_cfg_add_i64(fw_cfg
, FW_CFG_KERNEL_SIZE
, kernel_size
);
674 if (machine
->kernel_cmdline
) {
675 fw_cfg_add_i32(fw_cfg
, FW_CFG_CMDLINE_SIZE
,
676 strlen(machine
->kernel_cmdline
) + 1);
677 fw_cfg_add_string(fw_cfg
, FW_CFG_CMDLINE_DATA
, machine
->kernel_cmdline
);
679 fw_cfg_add_i32(fw_cfg
, FW_CFG_CMDLINE_SIZE
, 0);
681 fw_cfg_add_i64(fw_cfg
, FW_CFG_INITRD_ADDR
, initrd_addr
);
682 fw_cfg_add_i64(fw_cfg
, FW_CFG_INITRD_SIZE
, initrd_size
);
683 fw_cfg_add_i16(fw_cfg
, FW_CFG_BOOT_DEVICE
, machine
->boot_order
[0]);
685 fw_cfg_add_i16(fw_cfg
, FW_CFG_SPARC64_WIDTH
, graphic_width
);
686 fw_cfg_add_i16(fw_cfg
, FW_CFG_SPARC64_HEIGHT
, graphic_height
);
687 fw_cfg_add_i16(fw_cfg
, FW_CFG_SPARC64_DEPTH
, graphic_depth
);
689 qemu_register_boot_set(fw_cfg_boot_set
, fw_cfg
);
698 * Implementation of an interface to adjust firmware path
699 * for the bootindex property handling.
701 static char *sun4u_fw_dev_path(FWPathProvider
*p
, BusState
*bus
,
709 if (!strcmp(object_get_typename(OBJECT(dev
)), "pbm-bridge")) {
710 pci
= PCI_DEVICE(dev
);
712 if (PCI_FUNC(pci
->devfn
)) {
713 return g_strdup_printf("pci@%x,%x", PCI_SLOT(pci
->devfn
),
714 PCI_FUNC(pci
->devfn
));
716 return g_strdup_printf("pci@%x", PCI_SLOT(pci
->devfn
));
720 if (!strcmp(object_get_typename(OBJECT(dev
)), "ide-drive")) {
721 ide_bus
= IDE_BUS(qdev_get_parent_bus(dev
));
722 ide_s
= idebus_active_if(ide_bus
);
723 bus_id
= ide_bus
->bus_id
;
725 if (ide_s
->drive_kind
== IDE_CD
) {
726 return g_strdup_printf("ide@%x/cdrom", bus_id
);
729 return g_strdup_printf("ide@%x/disk", bus_id
);
732 if (!strcmp(object_get_typename(OBJECT(dev
)), "ide-hd")) {
733 return g_strdup("disk");
736 if (!strcmp(object_get_typename(OBJECT(dev
)), "ide-cd")) {
737 return g_strdup("cdrom");
740 if (!strcmp(object_get_typename(OBJECT(dev
)), "virtio-blk-device")) {
741 return g_strdup("disk");
747 static const struct hwdef hwdefs
[] = {
748 /* Sun4u generic PC-like machine */
750 .machine_id
= sun4u_id
,
751 .prom_addr
= 0x1fff0000000ULL
,
752 .console_serial_base
= 0,
754 /* Sun4v generic PC-like machine */
756 .machine_id
= sun4v_id
,
757 .prom_addr
= 0x1fff0000000ULL
,
758 .console_serial_base
= 0,
762 /* Sun4u hardware initialisation */
763 static void sun4u_init(MachineState
*machine
)
765 sun4uv_init(get_system_memory(), machine
, &hwdefs
[0]);
768 /* Sun4v hardware initialisation */
769 static void sun4v_init(MachineState
*machine
)
771 sun4uv_init(get_system_memory(), machine
, &hwdefs
[1]);
774 static void sun4u_class_init(ObjectClass
*oc
, void *data
)
776 MachineClass
*mc
= MACHINE_CLASS(oc
);
777 FWPathProviderClass
*fwc
= FW_PATH_PROVIDER_CLASS(oc
);
779 mc
->desc
= "Sun4u platform";
780 mc
->init
= sun4u_init
;
781 mc
->block_default_type
= IF_IDE
;
782 mc
->max_cpus
= 1; /* XXX for now */
784 mc
->default_boot_order
= "c";
785 mc
->default_cpu_type
= SPARC_CPU_TYPE_NAME("TI-UltraSparc-IIi");
786 mc
->ignore_boot_device_suffixes
= true;
787 fwc
->get_dev_path
= sun4u_fw_dev_path
;
790 static const TypeInfo sun4u_type
= {
791 .name
= MACHINE_TYPE_NAME("sun4u"),
792 .parent
= TYPE_MACHINE
,
793 .class_init
= sun4u_class_init
,
794 .interfaces
= (InterfaceInfo
[]) {
795 { TYPE_FW_PATH_PROVIDER
},
800 static void sun4v_class_init(ObjectClass
*oc
, void *data
)
802 MachineClass
*mc
= MACHINE_CLASS(oc
);
804 mc
->desc
= "Sun4v platform";
805 mc
->init
= sun4v_init
;
806 mc
->block_default_type
= IF_IDE
;
807 mc
->max_cpus
= 1; /* XXX for now */
808 mc
->default_boot_order
= "c";
809 mc
->default_cpu_type
= SPARC_CPU_TYPE_NAME("Sun-UltraSparc-T1");
812 static const TypeInfo sun4v_type
= {
813 .name
= MACHINE_TYPE_NAME("sun4v"),
814 .parent
= TYPE_MACHINE
,
815 .class_init
= sun4v_class_init
,
818 static void sun4u_register_types(void)
820 type_register_static(&power_info
);
821 type_register_static(&ebus_info
);
822 type_register_static(&prom_info
);
823 type_register_static(&ram_info
);
825 type_register_static(&sun4u_type
);
826 type_register_static(&sun4v_type
);
829 type_init(sun4u_register_types
)