From patchwork Thu Jul 31 06:31:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tiejun Chen X-Patchwork-Id: 375137 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id B7A4414011D for ; Thu, 31 Jul 2014 16:35:52 +1000 (EST) Received: from localhost ([::1]:54482 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XCjxu-0004XH-TZ for incoming@patchwork.ozlabs.org; Thu, 31 Jul 2014 02:35:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41222) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XCjxA-0003TJ-Mm for qemu-devel@nongnu.org; Thu, 31 Jul 2014 02:35:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XCjx4-00088S-ME for qemu-devel@nongnu.org; Thu, 31 Jul 2014 02:35:04 -0400 Received: from mga11.intel.com ([192.55.52.93]:26723) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XCjx4-00088D-Ao for qemu-devel@nongnu.org; Thu, 31 Jul 2014 02:34:58 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP; 30 Jul 2014 23:34:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.01,770,1400050800"; d="scan'208";a="569811600" Received: from tchen0-linux.bj.intel.com ([10.238.154.58]) by fmsmga001.fm.intel.com with ESMTP; 30 Jul 2014 23:34:22 -0700 From: Tiejun Chen To: mst@redhat.com Date: Thu, 31 Jul 2014 14:31:35 +0800 Message-Id: <1406788299-8394-2-git-send-email-tiejun.chen@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1406788299-8394-1-git-send-email-tiejun.chen@intel.com> References: <1406788299-8394-1-git-send-email-tiejun.chen@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.93 Cc: pbonzini@redhat.com, xen-devel@lists.xensource.com, qemu-devel@nongnu.org, stefano.stabellini@eu.citrix.com Subject: [Qemu-devel] [v2][PATCH 1/5] hw:i386:pc_piix: split pc_init1() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org We'd like to split pc_init1 and then we can share something with other stuff. Signed-off-by: Tiejun Chen --- hw/i386/pc_piix.c | 117 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 93 insertions(+), 24 deletions(-) v2: * Fix some coding style diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index 9694f88..ab380d5 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -71,36 +71,29 @@ static bool smbios_legacy_mode; static bool gigabyte_align = true; static bool has_reserved_memory = true; -/* PC hardware initialisation */ -static void pc_init1(MachineState *machine, - int pci_enabled, - int kvmclock_enabled) +static ram_addr_t below_4g_mem_size; +static ram_addr_t above_4g_mem_size; +static void pc_machine_base_init(MachineState *machine, + int pci_enabled, + int kvmclock_enabled, + DeviceState **pc_icc_bridge, + MemoryRegion **pc_ram_memory, + MemoryRegion **pc_pci_memory, + qemu_irq **pc_gsi, + GSIState **pc_gsi_state, + FWCfgState **pc_fw_cfg) { PCMachineState *pc_machine = PC_MACHINE(machine); MemoryRegion *system_memory = get_system_memory(); - MemoryRegion *system_io = get_system_io(); - int i; - ram_addr_t below_4g_mem_size, above_4g_mem_size; - PCIBus *pci_bus; - ISABus *isa_bus; - PCII440FXState *i440fx_state; - int piix3_devfn = -1; - qemu_irq *cpu_irq; - qemu_irq *gsi; - qemu_irq *i8259; - qemu_irq *smi_irq; - GSIState *gsi_state; - DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; - BusState *idebus[MAX_IDE_BUS]; - ISADevice *rtc_state; - ISADevice *floppy; - MemoryRegion *ram_memory; - MemoryRegion *pci_memory; MemoryRegion *rom_memory; - DeviceState *icc_bridge; - FWCfgState *fw_cfg = NULL; PcGuestInfo *guest_info; ram_addr_t lowmem; + DeviceState *icc_bridge; + MemoryRegion *ram_memory; + MemoryRegion *pci_memory; + qemu_irq *gsi; + GSIState *gsi_state; + FWCfgState *fw_cfg; /* Check whether RAM fits below 4G (leaving 1/2 GByte for IO memory). * If it doesn't, we need to split it in chunks below and above 4G. @@ -193,6 +186,31 @@ static void pc_init1(MachineState *machine, gsi = qemu_allocate_irqs(gsi_handler, gsi_state, GSI_NUM_PINS); } + *pc_icc_bridge = icc_bridge; + *pc_ram_memory = ram_memory; + *pc_pci_memory = pci_memory; + *pc_gsi = gsi; + *pc_gsi_state = gsi_state; + *pc_fw_cfg = fw_cfg; +} + +static void pc_machine_pci_bus_init(MachineState *machine, + int pci_enabled, + PCII440FXState **pc_i440fx_state, + int *pc_piix3_devfn, + PCIBus **pc_pci_bus, + ISABus **pc_isa_bus, + qemu_irq *gsi, + MemoryRegion *pci_memory, + MemoryRegion *ram_memory) +{ + MemoryRegion *system_memory = get_system_memory(); + MemoryRegion *system_io = get_system_io(); + PCII440FXState *i440fx_state; + int piix3_devfn; + PCIBus *pci_bus; + ISABus *isa_bus; + if (pci_enabled) { pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, &isa_bus, gsi, system_memory, system_io, machine->ram_size, @@ -205,6 +223,33 @@ static void pc_init1(MachineState *machine, isa_bus = isa_bus_new(NULL, system_io); no_hpet = 1; } + + *pc_i440fx_state = i440fx_state; + *pc_piix3_devfn = piix3_devfn; + *pc_pci_bus = pci_bus; + *pc_isa_bus = isa_bus; +} + +static void pc_machine_device_init(MachineState *machine, + int pci_enabled, + GSIState *gsi_state, + DeviceState *icc_bridge, + int piix3_devfn, + FWCfgState *fw_cfg, + PCIBus *pci_bus, + ISABus *isa_bus, + qemu_irq *gsi) +{ + int i; + DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; + BusState *idebus[MAX_IDE_BUS]; + qemu_irq *smi_irq; + PCMachineState *pc_machine = PC_MACHINE(machine); + qemu_irq *cpu_irq; + qemu_irq *i8259; + ISADevice *rtc_state; + ISADevice *floppy; + isa_bus_irqs(isa_bus, gsi); if (kvm_irqchip_in_kernel()) { @@ -292,6 +337,30 @@ static void pc_init1(MachineState *machine, } } +/* PC hardware initialisation */ +static void pc_init1(MachineState *machine, + int pci_enabled, + int kvmclock_enabled) +{ + PCIBus *pci_bus = NULL; + ISABus *isa_bus = NULL; + PCII440FXState *i440fx_state = NULL; + int piix3_devfn = -1; + qemu_irq *gsi = NULL; + GSIState *gsi_state = NULL; + MemoryRegion *ram_memory = NULL; + MemoryRegion *pci_memory = NULL; + DeviceState *icc_bridge = NULL; + FWCfgState *fw_cfg = NULL; + + pc_machine_base_init(machine, pci_enabled, kvmclock_enabled, &icc_bridge, + &ram_memory, &pci_memory, &gsi, &gsi_state, &fw_cfg); + pc_machine_pci_bus_init(machine, pci_enabled, &i440fx_state, &piix3_devfn, + &pci_bus, &isa_bus, gsi, pci_memory, ram_memory); + pc_machine_device_init(machine, pci_enabled, gsi_state, icc_bridge, + piix3_devfn, fw_cfg, pci_bus, isa_bus, gsi); +} + static void pc_init_pci(MachineState *machine) { pc_init1(machine, 1, 1);