From 1baffa46ed7f63e4066da37b0ca136c87d7c798c Mon Sep 17 00:00:00 2001 From: Blue Swirl Date: Tue, 21 Jul 2009 09:58:02 +0000 Subject: Sparc64: convert boot prom to qdev Signed-off-by: Blue Swirl --- hw/sun4u.c | 91 ++++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 62 insertions(+), 29 deletions(-) (limited to 'hw') diff --git a/hw/sun4u.c b/hw/sun4u.c index 9d2a7f5..5f15439 100644 --- a/hw/sun4u.c +++ b/hw/sun4u.c @@ -32,6 +32,7 @@ #include "boards.h" #include "firmware_abi.h" #include "fw_cfg.h" +#include "sysbus.h" //#define DEBUG_IRQ @@ -342,6 +343,64 @@ static void pci_ebus_register(void) device_init(pci_ebus_register); +/* Boot PROM (OpenBIOS) */ +static void prom_init(target_phys_addr_t addr, const char *bios_name) +{ + DeviceState *dev; + SysBusDevice *s; + char *filename; + int ret; + + dev = qdev_create(NULL, "openprom"); + qdev_init(dev); + s = sysbus_from_qdev(dev); + + sysbus_mmio_map(s, 0, addr); + + /* load boot prom */ + if (bios_name == NULL) { + bios_name = PROM_FILENAME; + } + filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); + if (filename) { + ret = load_elf(filename, addr - PROM_VADDR, NULL, NULL, NULL); + if (ret < 0 || ret > PROM_SIZE_MAX) { + ret = load_image_targphys(filename, addr, PROM_SIZE_MAX); + } + qemu_free(filename); + } else { + ret = -1; + } + if (ret < 0 || ret > PROM_SIZE_MAX) { + fprintf(stderr, "qemu: could not load prom '%s'\n", bios_name); + exit(1); + } +} + +static void prom_init1(SysBusDevice *dev) +{ + ram_addr_t prom_offset; + + prom_offset = qemu_ram_alloc(PROM_SIZE_MAX); + sysbus_init_mmio(dev, PROM_SIZE_MAX, prom_offset | IO_MEM_ROM); +} + +static SysBusDeviceInfo prom_info = { + .init = prom_init1, + .qdev.name = "openprom", + .qdev.size = sizeof(SysBusDevice), + .qdev.props = (Property[]) { + {/* end of property list */} + } +}; + +static void prom_register_devices(void) +{ + sysbus_register_withprop(&prom_info); +} + +device_init(prom_register_devices); + static void sun4uv_init(ram_addr_t RAM_size, const char *boot_devices, const char *kernel_filename, const char *kernel_cmdline, @@ -349,11 +408,10 @@ static void sun4uv_init(ram_addr_t RAM_size, const struct hwdef *hwdef) { CPUState *env; - char *filename; m48t59_t *nvram; - int ret, linux_boot; + int linux_boot; unsigned int i; - ram_addr_t ram_offset, prom_offset; + ram_addr_t ram_offset; long initrd_size, kernel_size; PCIBus *pci_bus, *pci_bus2, *pci_bus3; QEMUBH *bh; @@ -400,32 +458,7 @@ static void sun4uv_init(ram_addr_t RAM_size, ram_offset = qemu_ram_alloc(RAM_size); cpu_register_physical_memory(0, RAM_size, ram_offset); - prom_offset = qemu_ram_alloc(PROM_SIZE_MAX); - cpu_register_physical_memory(hwdef->prom_addr, - (PROM_SIZE_MAX + TARGET_PAGE_SIZE) & - TARGET_PAGE_MASK, - prom_offset | IO_MEM_ROM); - - if (bios_name == NULL) - bios_name = PROM_FILENAME; - filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); - if (filename) { - ret = load_elf(filename, hwdef->prom_addr - PROM_VADDR, - NULL, NULL, NULL); - if (ret < 0) { - ret = load_image_targphys(filename, hwdef->prom_addr, - (PROM_SIZE_MAX + TARGET_PAGE_SIZE) & - TARGET_PAGE_MASK); - } - qemu_free(filename); - } else { - ret = -1; - } - if (ret < 0) { - fprintf(stderr, "qemu: could not load prom '%s'\n", - bios_name); - exit(1); - } + prom_init(hwdef->prom_addr, bios_name); kernel_size = 0; initrd_size = 0; -- cgit v1.1