From patchwork Fri Dec 7 12:50:25 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cornelia Huck X-Patchwork-Id: 1850751 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 93F2FDF5B1 for ; Fri, 7 Dec 2012 12:51:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030204Ab2LGMuk (ORCPT ); Fri, 7 Dec 2012 07:50:40 -0500 Received: from e06smtp15.uk.ibm.com ([195.75.94.111]:53170 "EHLO e06smtp15.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965049Ab2LGMug (ORCPT ); Fri, 7 Dec 2012 07:50:36 -0500 Received: from /spool/local by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 7 Dec 2012 12:50:26 -0000 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp15.uk.ibm.com (192.168.101.145) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 7 Dec 2012 12:50:24 -0000 Received: from d06av07.portsmouth.uk.ibm.com (d06av07.portsmouth.uk.ibm.com [9.149.37.248]) by b06cxnps3075.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id qB7CoOQs58851330; Fri, 7 Dec 2012 12:50:24 GMT Received: from d06av07.portsmouth.uk.ibm.com (d06av07.portsmouth.uk.ibm.com [127.0.0.1]) by d06av07.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id qB7C2QSa021114; Fri, 7 Dec 2012 07:02:27 -0500 Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d06av07.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id qB7C2MBe020912; Fri, 7 Dec 2012 07:02:26 -0500 From: Cornelia Huck To: qemu-devel , KVM , linux-s390 Cc: Marcelo Tosatti , Gleb Natapov , Anthony Liguori , Christian Borntraeger , Carsten Otte , Alexander Graf , Heiko Carstens , Martin Schwidefsky , Sebastian Ott Subject: [PATCH 7/8] s390-virtio: Factor out some initialization code. Date: Fri, 7 Dec 2012 13:50:25 +0100 Message-Id: <1354884626-15060-8-git-send-email-cornelia.huck@de.ibm.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1354884626-15060-1-git-send-email-cornelia.huck@de.ibm.com> References: <1354884626-15060-1-git-send-email-cornelia.huck@de.ibm.com> x-cbid: 12120712-0342-0000-0000-0000039D1FEF Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Some of the machine initialization for s390-virtio will be reused by virtio-ccw. Signed-off-by: Cornelia Huck --- hw/s390-virtio.c | 132 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 79 insertions(+), 53 deletions(-) diff --git a/hw/s390-virtio.c b/hw/s390-virtio.c index 685cb54..9e1afb2 100644 --- a/hw/s390-virtio.c +++ b/hw/s390-virtio.c @@ -151,60 +151,12 @@ unsigned s390_del_running_cpu(CPUS390XState *env) return s390_running_cpus; } -/* PC hardware initialisation */ -static void s390_init(QEMUMachineInitArgs *args) +static CPUS390XState *s390_init_cpus(const char *cpu_model, + uint8_t *storage_keys) { - ram_addr_t my_ram_size = args->ram_size; - ram_addr_t ram_size = args->ram_size; - 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; CPUS390XState *env = NULL; - MemoryRegion *sysmem = get_system_memory(); - MemoryRegion *ram = g_new(MemoryRegion, 1); - ram_addr_t kernel_size = 0; - ram_addr_t initrd_offset; - ram_addr_t initrd_size = 0; - int shift = 0; - uint8_t *storage_keys; - void *virtio_region; - hwaddr virtio_region_len; - hwaddr virtio_region_start; int i; - /* s390x ram size detection needs a 16bit multiplier + an increment. So - guests > 64GB can be specified in 2MB steps etc. */ - while ((my_ram_size >> (20 + shift)) > 65535) { - shift++; - } - my_ram_size = my_ram_size >> (20 + shift) << (20 + shift); - - /* lets propagate the changed ram size into the global variable. */ - ram_size = my_ram_size; - - /* get a BUS */ - s390_bus = s390_virtio_bus_init(&my_ram_size); - s390_sclp_init(); - - /* allocate RAM */ - memory_region_init_ram(ram, "s390.ram", my_ram_size); - vmstate_register_ram_global(ram); - memory_region_add_subregion(sysmem, 0, ram); - - /* clear virtio region */ - virtio_region_len = my_ram_size - ram_size; - virtio_region_start = ram_size; - virtio_region = cpu_physical_memory_map(virtio_region_start, - &virtio_region_len, true); - memset(virtio_region, 0, virtio_region_len); - cpu_physical_memory_unmap(virtio_region, virtio_region_len, 1, - virtio_region_len); - - /* allocate storage keys */ - storage_keys = g_malloc0(my_ram_size / TARGET_PAGE_SIZE); - - /* init CPUs */ if (cpu_model == NULL) { cpu_model = "host"; } @@ -225,6 +177,17 @@ static void s390_init(QEMUMachineInitArgs *args) tmp_env->exception_index = EXCP_HLT; tmp_env->storage_keys = storage_keys; } + return env; +} + +static void s390_set_up_kernel(CPUS390XState *env, + const char *kernel_filename, + const char *kernel_cmdline, + const char *initrd_filename) +{ + ram_addr_t kernel_size = 0; + ram_addr_t initrd_offset; + ram_addr_t initrd_size = 0; /* One CPU has to run */ s390_add_running_cpu(env); @@ -296,9 +259,13 @@ static void s390_init(QEMUMachineInitArgs *args) memcpy(rom_ptr(KERN_PARM_AREA), kernel_cmdline, strlen(kernel_cmdline) + 1); } +} - /* Create VirtIO network adapters */ - for(i = 0; i < nb_nics; i++) { +static void s390_create_virtio_net(BusState *bus, const char *name) +{ + int i; + + for (i = 0; i < nb_nics; i++) { NICInfo *nd = &nd_table[i]; DeviceState *dev; @@ -311,10 +278,69 @@ static void s390_init(QEMUMachineInitArgs *args) exit(1); } - dev = qdev_create((BusState *)s390_bus, "virtio-net-s390"); + dev = qdev_create(bus, name); qdev_set_nic_properties(dev, nd); qdev_init_nofail(dev); } +} + +/* PC hardware initialisation */ +static void s390_init(QEMUMachineInitArgs *args) +{ + ram_addr_t my_ram_size = args->ram_size; + ram_addr_t ram_size = args->ram_size; + 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; + CPUS390XState *env = NULL; + MemoryRegion *sysmem = get_system_memory(); + MemoryRegion *ram = g_new(MemoryRegion, 1); + int shift = 0; + uint8_t *storage_keys; + void *virtio_region; + hwaddr virtio_region_len; + hwaddr virtio_region_start; + int i; + + /* s390x ram size detection needs a 16bit multiplier + an increment. So + guests > 64GB can be specified in 2MB steps etc. */ + while ((my_ram_size >> (20 + shift)) > 65535) { + shift++; + } + my_ram_size = my_ram_size >> (20 + shift) << (20 + shift); + + /* lets propagate the changed ram size into the global variable. */ + ram_size = my_ram_size; + + /* get a BUS */ + s390_bus = s390_virtio_bus_init(&my_ram_size); + s390_sclp_init(); + + /* allocate RAM */ + memory_region_init_ram(ram, "s390.ram", my_ram_size); + vmstate_register_ram_global(ram); + memory_region_add_subregion(sysmem, 0, ram); + + /* clear virtio region */ + virtio_region_len = my_ram_size - ram_size; + virtio_region_start = ram_size; + virtio_region = cpu_physical_memory_map(virtio_region_start, + &virtio_region_len, true); + memset(virtio_region, 0, virtio_region_len); + cpu_physical_memory_unmap(virtio_region, virtio_region_len, 1, + virtio_region_len); + + /* allocate storage keys */ + storage_keys = g_malloc0(my_ram_size / TARGET_PAGE_SIZE); + + /* init CPUs */ + env = s390_init_cpus(cpu_model, storage_keys); + + s390_set_up_kernel(env, kernel_filename, kernel_cmdline, initrd_filename); + + /* Create VirtIO network adapters */ + s390_create_virtio_net((BusState *)s390_bus, "virtio-net-s390"); /* Create VirtIO disk drives */ for(i = 0; i < MAX_BLK_DEVS; i++) {