sun4: Don't prematurely explode QEMUMachineInitArgs

Don't explode QEMUMachineInitArgs before passing it to
sun4m_hw_init(), sun4uv_init().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
Markus Armbruster 2013-08-16 13:13:47 +02:00 committed by Michael S. Tsirkin
parent 4b38e989b4
commit 6b63ef4d0f
2 changed files with 40 additions and 125 deletions

View File

@ -836,12 +836,10 @@ static void dummy_fdc_tc(void *opaque, int irq, int level)
{ {
} }
static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size, static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
const char *boot_device, QEMUMachineInitArgs *args)
const char *kernel_filename,
const char *kernel_cmdline,
const char *initrd_filename, const char *cpu_model)
{ {
const char *cpu_model = args->cpu_model;
unsigned int i; unsigned int i;
void *iommu, *espdma, *ledma, *nvram; void *iommu, *espdma, *ledma, *nvram;
qemu_irq *cpu_irqs[MAX_CPUS], slavio_irq[32], slavio_cpu_irq[MAX_CPUS], qemu_irq *cpu_irqs[MAX_CPUS], slavio_irq[32], slavio_cpu_irq[MAX_CPUS],
@ -867,10 +865,10 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
/* set up devices */ /* set up devices */
ram_init(0, RAM_size, hwdef->max_mem); ram_init(0, args->ram_size, hwdef->max_mem);
/* models without ECC don't trap when missing ram is accessed */ /* models without ECC don't trap when missing ram is accessed */
if (!hwdef->ecc_base) { if (!hwdef->ecc_base) {
empty_slot_init(RAM_size, hwdef->max_mem - RAM_size); empty_slot_init(args->ram_size, hwdef->max_mem - args->ram_size);
} }
prom_init(hwdef->slavio_base, bios_name); prom_init(hwdef->slavio_base, bios_name);
@ -993,11 +991,12 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
empty_slot_init(hwdef->bpp_base, 0x20); empty_slot_init(hwdef->bpp_base, 0x20);
} }
kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename, kernel_size = sun4m_load_kernel(args->kernel_filename,
RAM_size); args->initrd_filename,
args->ram_size);
nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline, nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, args->kernel_cmdline,
boot_device, RAM_size, kernel_size, graphic_width, args->boot_device, args->ram_size, kernel_size, graphic_width,
graphic_height, graphic_depth, hwdef->nvram_machine_id, graphic_height, graphic_depth, hwdef->nvram_machine_id,
"Sun4m"); "Sun4m");
@ -1015,19 +1014,20 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_HEIGHT, graphic_height); fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_HEIGHT, graphic_height);
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR); fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size); fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
if (kernel_cmdline) { if (args->kernel_cmdline) {
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR); fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline); pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE,
fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA, kernel_cmdline); args->kernel_cmdline);
fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA, args->kernel_cmdline);
fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE,
strlen(kernel_cmdline) + 1); strlen(args->kernel_cmdline) + 1);
} else { } else {
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0); fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, 0); fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, 0);
} }
fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR); fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]); fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, args->boot_device[0]);
qemu_register_boot_set(fw_cfg_boot_set, fw_cfg); qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
} }
@ -1291,118 +1291,55 @@ static const struct sun4m_hwdef sun4m_hwdefs[] = {
/* SPARCstation 5 hardware initialisation */ /* SPARCstation 5 hardware initialisation */
static void ss5_init(QEMUMachineInitArgs *args) static void ss5_init(QEMUMachineInitArgs *args)
{ {
ram_addr_t RAM_size = args->ram_size; sun4m_hw_init(&sun4m_hwdefs[0], args);
const char *cpu_model = args->cpu_model;
const char *kernel_filename = args->kernel_filename;
const char *kernel_cmdline = args->kernel_cmdline;
const char *initrd_filename = args->initrd_filename;
const char *boot_device = args->boot_device;
sun4m_hw_init(&sun4m_hwdefs[0], RAM_size, boot_device, kernel_filename,
kernel_cmdline, initrd_filename, cpu_model);
} }
/* SPARCstation 10 hardware initialisation */ /* SPARCstation 10 hardware initialisation */
static void ss10_init(QEMUMachineInitArgs *args) static void ss10_init(QEMUMachineInitArgs *args)
{ {
ram_addr_t RAM_size = args->ram_size; sun4m_hw_init(&sun4m_hwdefs[1], args);
const char *cpu_model = args->cpu_model;
const char *kernel_filename = args->kernel_filename;
const char *kernel_cmdline = args->kernel_cmdline;
const char *initrd_filename = args->initrd_filename;
const char *boot_device = args->boot_device;
sun4m_hw_init(&sun4m_hwdefs[1], RAM_size, boot_device, kernel_filename,
kernel_cmdline, initrd_filename, cpu_model);
} }
/* SPARCserver 600MP hardware initialisation */ /* SPARCserver 600MP hardware initialisation */
static void ss600mp_init(QEMUMachineInitArgs *args) static void ss600mp_init(QEMUMachineInitArgs *args)
{ {
ram_addr_t RAM_size = args->ram_size; sun4m_hw_init(&sun4m_hwdefs[2], args);
const char *cpu_model = args->cpu_model;
const char *kernel_filename = args->kernel_filename;
const char *kernel_cmdline = args->kernel_cmdline;
const char *initrd_filename = args->initrd_filename;
const char *boot_device = args->boot_device;
sun4m_hw_init(&sun4m_hwdefs[2], RAM_size, boot_device, kernel_filename,
kernel_cmdline, initrd_filename, cpu_model);
} }
/* SPARCstation 20 hardware initialisation */ /* SPARCstation 20 hardware initialisation */
static void ss20_init(QEMUMachineInitArgs *args) static void ss20_init(QEMUMachineInitArgs *args)
{ {
ram_addr_t RAM_size = args->ram_size; sun4m_hw_init(&sun4m_hwdefs[3], args);
const char *cpu_model = args->cpu_model;
const char *kernel_filename = args->kernel_filename;
const char *kernel_cmdline = args->kernel_cmdline;
const char *initrd_filename = args->initrd_filename;
const char *boot_device = args->boot_device;
sun4m_hw_init(&sun4m_hwdefs[3], RAM_size, boot_device, kernel_filename,
kernel_cmdline, initrd_filename, cpu_model);
} }
/* SPARCstation Voyager hardware initialisation */ /* SPARCstation Voyager hardware initialisation */
static void vger_init(QEMUMachineInitArgs *args) static void vger_init(QEMUMachineInitArgs *args)
{ {
ram_addr_t RAM_size = args->ram_size; sun4m_hw_init(&sun4m_hwdefs[4], args);
const char *cpu_model = args->cpu_model;
const char *kernel_filename = args->kernel_filename;
const char *kernel_cmdline = args->kernel_cmdline;
const char *initrd_filename = args->initrd_filename;
const char *boot_device = args->boot_device;
sun4m_hw_init(&sun4m_hwdefs[4], RAM_size, boot_device, kernel_filename,
kernel_cmdline, initrd_filename, cpu_model);
} }
/* SPARCstation LX hardware initialisation */ /* SPARCstation LX hardware initialisation */
static void ss_lx_init(QEMUMachineInitArgs *args) static void ss_lx_init(QEMUMachineInitArgs *args)
{ {
ram_addr_t RAM_size = args->ram_size; sun4m_hw_init(&sun4m_hwdefs[5], args);
const char *cpu_model = args->cpu_model;
const char *kernel_filename = args->kernel_filename;
const char *kernel_cmdline = args->kernel_cmdline;
const char *initrd_filename = args->initrd_filename;
const char *boot_device = args->boot_device;
sun4m_hw_init(&sun4m_hwdefs[5], RAM_size, boot_device, kernel_filename,
kernel_cmdline, initrd_filename, cpu_model);
} }
/* SPARCstation 4 hardware initialisation */ /* SPARCstation 4 hardware initialisation */
static void ss4_init(QEMUMachineInitArgs *args) static void ss4_init(QEMUMachineInitArgs *args)
{ {
ram_addr_t RAM_size = args->ram_size; sun4m_hw_init(&sun4m_hwdefs[6], args);
const char *cpu_model = args->cpu_model;
const char *kernel_filename = args->kernel_filename;
const char *kernel_cmdline = args->kernel_cmdline;
const char *initrd_filename = args->initrd_filename;
const char *boot_device = args->boot_device;
sun4m_hw_init(&sun4m_hwdefs[6], RAM_size, boot_device, kernel_filename,
kernel_cmdline, initrd_filename, cpu_model);
} }
/* SPARCClassic hardware initialisation */ /* SPARCClassic hardware initialisation */
static void scls_init(QEMUMachineInitArgs *args) static void scls_init(QEMUMachineInitArgs *args)
{ {
ram_addr_t RAM_size = args->ram_size; sun4m_hw_init(&sun4m_hwdefs[7], args);
const char *cpu_model = args->cpu_model;
const char *kernel_filename = args->kernel_filename;
const char *kernel_cmdline = args->kernel_cmdline;
const char *initrd_filename = args->initrd_filename;
const char *boot_device = args->boot_device;
sun4m_hw_init(&sun4m_hwdefs[7], RAM_size, boot_device, kernel_filename,
kernel_cmdline, initrd_filename, cpu_model);
} }
/* SPARCbook hardware initialisation */ /* SPARCbook hardware initialisation */
static void sbook_init(QEMUMachineInitArgs *args) static void sbook_init(QEMUMachineInitArgs *args)
{ {
ram_addr_t RAM_size = args->ram_size; sun4m_hw_init(&sun4m_hwdefs[8], args);
const char *cpu_model = args->cpu_model;
const char *kernel_filename = args->kernel_filename;
const char *kernel_cmdline = args->kernel_cmdline;
const char *initrd_filename = args->initrd_filename;
const char *boot_device = args->boot_device;
sun4m_hw_init(&sun4m_hwdefs[8], RAM_size, boot_device, kernel_filename,
kernel_cmdline, initrd_filename, cpu_model);
} }
static QEMUMachine ss5_machine = { static QEMUMachine ss5_machine = {

View File

@ -811,10 +811,7 @@ static SPARCCPU *cpu_devinit(const char *cpu_model, const struct hwdef *hwdef)
} }
static void sun4uv_init(MemoryRegion *address_space_mem, static void sun4uv_init(MemoryRegion *address_space_mem,
ram_addr_t RAM_size, QEMUMachineInitArgs *args,
const char *boot_devices,
const char *kernel_filename, const char *kernel_cmdline,
const char *initrd_filename, const char *cpu_model,
const struct hwdef *hwdef) const struct hwdef *hwdef)
{ {
SPARCCPU *cpu; SPARCCPU *cpu;
@ -829,10 +826,10 @@ static void sun4uv_init(MemoryRegion *address_space_mem,
FWCfgState *fw_cfg; FWCfgState *fw_cfg;
/* init CPUs */ /* init CPUs */
cpu = cpu_devinit(cpu_model, hwdef); cpu = cpu_devinit(args->cpu_model, hwdef);
/* set up devices */ /* set up devices */
ram_init(0, RAM_size); ram_init(0, args->ram_size);
prom_init(hwdef->prom_addr, bios_name); prom_init(hwdef->prom_addr, bios_name);
@ -878,13 +875,15 @@ static void sun4uv_init(MemoryRegion *address_space_mem,
initrd_size = 0; initrd_size = 0;
initrd_addr = 0; initrd_addr = 0;
kernel_size = sun4u_load_kernel(kernel_filename, initrd_filename, kernel_size = sun4u_load_kernel(args->kernel_filename,
args->initrd_filename,
ram_size, &initrd_size, &initrd_addr, ram_size, &initrd_size, &initrd_addr,
&kernel_addr, &kernel_entry); &kernel_addr, &kernel_entry);
sun4u_NVRAM_set_params(nvram, NVRAM_SIZE, "Sun4u", RAM_size, boot_devices, sun4u_NVRAM_set_params(nvram, NVRAM_SIZE, "Sun4u", args->ram_size,
args->boot_device,
kernel_addr, kernel_size, kernel_addr, kernel_size,
kernel_cmdline, args->kernel_cmdline,
initrd_addr, initrd_size, initrd_addr, initrd_size,
/* XXX: need an option to load a NVRAM image */ /* XXX: need an option to load a NVRAM image */
0, 0,
@ -898,16 +897,16 @@ static void sun4uv_init(MemoryRegion *address_space_mem,
fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id); fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
fw_cfg_add_i64(fw_cfg, FW_CFG_KERNEL_ADDR, kernel_entry); fw_cfg_add_i64(fw_cfg, FW_CFG_KERNEL_ADDR, kernel_entry);
fw_cfg_add_i64(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size); fw_cfg_add_i64(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
if (kernel_cmdline) { if (args->kernel_cmdline) {
fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE,
strlen(kernel_cmdline) + 1); strlen(args->kernel_cmdline) + 1);
fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA, kernel_cmdline); fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA, args->kernel_cmdline);
} else { } else {
fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, 0); fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, 0);
} }
fw_cfg_add_i64(fw_cfg, FW_CFG_INITRD_ADDR, initrd_addr); fw_cfg_add_i64(fw_cfg, FW_CFG_INITRD_ADDR, initrd_addr);
fw_cfg_add_i64(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size); fw_cfg_add_i64(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_devices[0]); fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, args->boot_device[0]);
fw_cfg_add_i16(fw_cfg, FW_CFG_SPARC64_WIDTH, graphic_width); fw_cfg_add_i16(fw_cfg, FW_CFG_SPARC64_WIDTH, graphic_width);
fw_cfg_add_i16(fw_cfg, FW_CFG_SPARC64_HEIGHT, graphic_height); fw_cfg_add_i16(fw_cfg, FW_CFG_SPARC64_HEIGHT, graphic_height);
@ -949,40 +948,19 @@ static const struct hwdef hwdefs[] = {
/* Sun4u hardware initialisation */ /* Sun4u hardware initialisation */
static void sun4u_init(QEMUMachineInitArgs *args) static void sun4u_init(QEMUMachineInitArgs *args)
{ {
ram_addr_t RAM_size = args->ram_size; sun4uv_init(get_system_memory(), args, &hwdefs[0]);
const char *cpu_model = args->cpu_model;
const char *kernel_filename = args->kernel_filename;
const char *kernel_cmdline = args->kernel_cmdline;
const char *initrd_filename = args->initrd_filename;
const char *boot_devices = args->boot_device;
sun4uv_init(get_system_memory(), RAM_size, boot_devices, kernel_filename,
kernel_cmdline, initrd_filename, cpu_model, &hwdefs[0]);
} }
/* Sun4v hardware initialisation */ /* Sun4v hardware initialisation */
static void sun4v_init(QEMUMachineInitArgs *args) static void sun4v_init(QEMUMachineInitArgs *args)
{ {
ram_addr_t RAM_size = args->ram_size; sun4uv_init(get_system_memory(), args, &hwdefs[1]);
const char *cpu_model = args->cpu_model;
const char *kernel_filename = args->kernel_filename;
const char *kernel_cmdline = args->kernel_cmdline;
const char *initrd_filename = args->initrd_filename;
const char *boot_devices = args->boot_device;
sun4uv_init(get_system_memory(), RAM_size, boot_devices, kernel_filename,
kernel_cmdline, initrd_filename, cpu_model, &hwdefs[1]);
} }
/* Niagara hardware initialisation */ /* Niagara hardware initialisation */
static void niagara_init(QEMUMachineInitArgs *args) static void niagara_init(QEMUMachineInitArgs *args)
{ {
ram_addr_t RAM_size = args->ram_size; sun4uv_init(get_system_memory(), args, &hwdefs[2]);
const char *cpu_model = args->cpu_model;
const char *kernel_filename = args->kernel_filename;
const char *kernel_cmdline = args->kernel_cmdline;
const char *initrd_filename = args->initrd_filename;
const char *boot_devices = args->boot_device;
sun4uv_init(get_system_memory(), RAM_size, boot_devices, kernel_filename,
kernel_cmdline, initrd_filename, cpu_model, &hwdefs[2]);
} }
static QEMUMachine sun4u_machine = { static QEMUMachine sun4u_machine = {