From patchwork Fri Jan 22 13:21:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Mammedov X-Patchwork-Id: 8090111 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 74017BEEE5 for ; Fri, 22 Jan 2016 13:28:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AFB8E2045E for ; Fri, 22 Jan 2016 13:28:31 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CFA8920457 for ; Fri, 22 Jan 2016 13:28:30 +0000 (UTC) Received: from localhost ([::1]:53723 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMbih-0008Rw-N8 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 22 Jan 2016 08:25:43 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43600) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMbeY-0000pA-R3 for qemu-devel@nongnu.org; Fri, 22 Jan 2016 08:21:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aMbeX-0002Rs-Gv for qemu-devel@nongnu.org; Fri, 22 Jan 2016 08:21:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49621) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMbeX-0002Rg-8k for qemu-devel@nongnu.org; Fri, 22 Jan 2016 08:21:25 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id E8F1C113700 for ; Fri, 22 Jan 2016 13:21:24 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.34.112.60]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u0MDL5gM021584; Fri, 22 Jan 2016 08:21:23 -0500 From: Igor Mammedov To: qemu-devel@nongnu.org Date: Fri, 22 Jan 2016 14:21:01 +0100 Message-Id: <1453468862-118912-9-git-send-email-imammedo@redhat.com> In-Reply-To: <1453468862-118912-1-git-send-email-imammedo@redhat.com> References: <1453468862-118912-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: ehabkost@redhat.com, mst@redhat.com, ghammer@redhat.com, lersek@redhat.com, lcapitulino@redhat.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH v18 8/9] pc: put PIIX3 in slot 1 explicitly and cleanup functions assignment 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP currently slot for PIIX3 bridge is selected dynamically but it's always in slot 1 for existing machine types. However it's easy to regress if another PCI device were added before PIIX3 is created and also requires passing around devfn of the created bridge. Replace dynamic slot assignment with a static one like it's done for ICH9_LPC, explicitly setting slot # for the bridge. While at it cleanup IDE/USB/PIIX4_PM functions assignment, replacing magic offsets with defines. Signed-off-by: Igor Mammedov --- Static assignment will help with adding other functions to multifunction bridge in following patch. --- hw/i386/pc_piix.c | 17 ++++++++++------- hw/pci-host/piix.c | 9 ++++----- include/hw/i386/pc.h | 8 +++++++- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index bc74557..2ea3d84 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -73,7 +73,6 @@ static void pc_init1(MachineState *machine, PCIBus *pci_bus; ISABus *isa_bus; PCII440FXState *i440fx_state; - int piix3_devfn = -1; qemu_irq *gsi; qemu_irq *i8259; qemu_irq smi_irq; @@ -179,7 +178,7 @@ static void pc_init1(MachineState *machine, if (pcmc->pci_enabled) { pci_bus = i440fx_init(host_type, pci_type, - &i440fx_state, &piix3_devfn, &isa_bus, gsi, + &i440fx_state, &isa_bus, gsi, system_memory, system_io, machine->ram_size, pcms->below_4g_mem_size, pcms->above_4g_mem_size, @@ -229,9 +228,11 @@ static void pc_init1(MachineState *machine, if (pcmc->pci_enabled) { PCIDevice *dev; if (xen_enabled()) { - dev = pci_piix3_xen_ide_init(pci_bus, hd, piix3_devfn + 1); + dev = pci_piix3_xen_ide_init(pci_bus, hd, + PCI_DEVFN(PIIX3_PCI_SLOT, PIIX3_IDE_FUNC)); } else { - dev = pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1); + dev = pci_piix3_ide_init(pci_bus, hd, + PCI_DEVFN(PIIX3_PCI_SLOT, PIIX3_IDE_FUNC)); } idebus[0] = qdev_get_child_bus(&dev->qdev, "ide.0"); idebus[1] = qdev_get_child_bus(&dev->qdev, "ide.1"); @@ -254,7 +255,8 @@ static void pc_init1(MachineState *machine, pc_cmos_init(pcms, idebus[0], idebus[1], rtc_state); if (pcmc->pci_enabled && usb_enabled()) { - pci_create_simple(pci_bus, piix3_devfn + 2, "piix3-usb-uhci"); + pci_create_simple(pci_bus, PCI_DEVFN(PIIX3_PCI_SLOT, PIIX3_USB_FUNC), + "piix3-usb-uhci"); } if (pcmc->pci_enabled && acpi_enabled) { @@ -263,8 +265,9 @@ static void pc_init1(MachineState *machine, smi_irq = qemu_allocate_irq(pc_acpi_smi_interrupt, first_cpu, 0); /* TODO: Populate SPD eeprom data. */ - smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100, - gsi[9], smi_irq, + smbus = piix4_pm_init(pci_bus, + PCI_DEVFN(PIIX3_PCI_SLOT, PIIX3_PIIX4_PM_FUNC), + 0xb100, gsi[9], smi_irq, pc_machine_is_smm_enabled(pcms), &piix4_pm); smbus_eeprom_init(smbus, 8, NULL, 0); diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c index b0d7e31..b8bf1fc 100644 --- a/hw/pci-host/piix.c +++ b/hw/pci-host/piix.c @@ -310,7 +310,6 @@ static void i440fx_realize(PCIDevice *dev, Error **errp) PCIBus *i440fx_init(const char *host_type, const char *pci_type, PCII440FXState **pi440fx_state, - int *piix3_devfn, ISABus **isa_bus, qemu_irq *pic, MemoryRegion *address_space_mem, MemoryRegion *address_space_io, @@ -382,13 +381,15 @@ PCIBus *i440fx_init(const char *host_type, const char *pci_type, * These additional routes can be discovered through ACPI. */ if (xen_enabled()) { PCIDevice *pci_dev = pci_create_simple_multifunction(b, - -1, true, "PIIX3-xen"); + PCI_DEVFN(PIIX3_PCI_SLOT, PIIX3_PCI_FUNC), + true, "PIIX3-xen"); piix3 = PIIX3_PCI_DEVICE(pci_dev); pci_bus_irqs(b, xen_piix3_set_irq, xen_pci_slot_get_pirq, piix3, XEN_PIIX_NUM_PIRQS); } else { PCIDevice *pci_dev = pci_create_simple_multifunction(b, - -1, true, "PIIX3"); + PCI_DEVFN(PIIX3_PCI_SLOT, PIIX3_PCI_FUNC), + true, "PIIX3"); piix3 = PIIX3_PCI_DEVICE(pci_dev); pci_bus_irqs(b, piix3_set_irq, pci_slot_get_pirq, piix3, PIIX_NUM_PIRQS); @@ -397,8 +398,6 @@ PCIBus *i440fx_init(const char *host_type, const char *pci_type, piix3->pic = pic; *isa_bus = ISA_BUS(qdev_get_child_bus(DEVICE(piix3), "isa.0")); - *piix3_devfn = piix3->dev.devfn; - ram_size = ram_size / 8 / 1024 / 1024; if (ram_size > 255) { ram_size = 255; diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 5bac03d..4da5178 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -291,8 +291,14 @@ typedef struct PCII440FXState PCII440FXState; #define TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE "igd-passthrough-i440FX" +#define PIIX3_PCI_SLOT 1 +#define PIIX3_PCI_FUNC 0 +#define PIIX3_IDE_FUNC 1 +#define PIIX3_USB_FUNC 2 +#define PIIX3_PIIX4_PM_FUNC 3 + PCIBus *i440fx_init(const char *host_type, const char *pci_type, - PCII440FXState **pi440fx_state, int *piix_devfn, + PCII440FXState **pi440fx_state, ISABus **isa_bus, qemu_irq *pic, MemoryRegion *address_space_mem, MemoryRegion *address_space_io,