From patchwork Wed Aug 22 12:30:19 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 179398 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5084E2C0081 for ; Thu, 23 Aug 2012 05:54:41 +1000 (EST) Received: from localhost ([::1]:40848 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T4G5E-0002pW-Ms for incoming@patchwork.ozlabs.org; Wed, 22 Aug 2012 14:55:16 -0400 Received: from eggs.gnu.org ([208.118.235.92]:39927) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T4G4E-0008LD-GQ for qemu-devel@nongnu.org; Wed, 22 Aug 2012 14:54:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T4G4C-0006mp-Uz for qemu-devel@nongnu.org; Wed, 22 Aug 2012 14:54:14 -0400 Received: from smtp02.citrix.com ([66.165.176.63]:29106) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T4G4C-0006mF-MO for qemu-devel@nongnu.org; Wed, 22 Aug 2012 14:54:12 -0400 X-IronPort-AV: E=Sophos;i="4.80,809,1344225600"; d="scan'208";a="205942917" Received: from ftlpmailmx01.citrite.net ([10.13.107.65]) by FTLPIPO02.CITRIX.COM with ESMTP/TLS/RC4-MD5; 22 Aug 2012 14:54:07 -0400 Received: from meteora.cam.xci-test.com (10.80.248.22) by smtprelay.citrix.com (10.13.107.65) with Microsoft SMTP Server id 8.3.213.0; Wed, 22 Aug 2012 14:54:06 -0400 From: Julien Grall To: qemu-devel@nongnu.org Date: Wed, 22 Aug 2012 13:30:19 +0100 Message-ID: <10985f0bc427cc258adb11cb97818a4e7ab133c9.1345637459.git.julien.grall@citrix.com> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: References: MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.63 Cc: Julien Grall , christian.limpach@gmail.com, Stefano.Stabellini@eu.citrix.com, xen-devel@lists.xen.org Subject: [Qemu-devel] [QEMU][RFC V2 06/10] xen-pci: register PCI device in Xen and handle IOREQ_TYPE_PCI_CONFIG 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 With QEMU disaggregation QEMU needs to specify which PCI device it's able to handle. It will use the device place in the topology (domain, bus, device, function). When Xen will trap an access for the config space, it will forge a new ioreq and forward it to the right QEMU. Signed-off-by: Julien Grall --- hw/pci.c | 6 ++++++ hw/xen.h | 1 + xen-all.c | 38 ++++++++++++++++++++++++++++++++++++++ xen-stub.c | 5 +++++ 4 files changed, 50 insertions(+), 0 deletions(-) diff --git a/hw/pci.c b/hw/pci.c index 4d95984..0112edf 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -33,6 +33,7 @@ #include "qmp-commands.h" #include "msi.h" #include "msix.h" +#include "xen.h" //#define DEBUG_PCI #ifdef DEBUG_PCI @@ -781,6 +782,11 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus, pci_dev->devfn = devfn; pstrcpy(pci_dev->name, sizeof(pci_dev->name), name); pci_dev->irq_state = 0; + + if (xen_enabled() && xen_register_pcidev(pci_dev)) { + return NULL; + } + pci_config_alloc(pci_dev); pci_config_set_vendor_id(pci_dev->config, pc->vendor_id); diff --git a/hw/xen.h b/hw/xen.h index e5926b7..663731a 100644 --- a/hw/xen.h +++ b/hw/xen.h @@ -35,6 +35,7 @@ int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num); void xen_piix3_set_irq(void *opaque, int irq_num, int level); void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len); void xen_hvm_inject_msi(uint64_t addr, uint32_t data); +int xen_register_pcidev(PCIDevice *pci_dev); void xen_cmos_set_s3_resume(void *opaque, int irq, int level); qemu_irq *xen_interrupt_controller_init(void); diff --git a/xen-all.c b/xen-all.c index 14e5d3d..485c312 100644 --- a/xen-all.c +++ b/xen-all.c @@ -174,6 +174,16 @@ void xen_piix3_set_irq(void *opaque, int irq_num, int level) irq_num & 3, level); } +int xen_register_pcidev(PCIDevice *pci_dev) +{ + DPRINTF("register pci %x:%x.%x %s\n", 0, (pci_dev->devfn >> 3) & 0x1f, + pci_dev->devfn & 0x7, pci_dev->name); + + return xen_xc_hvm_register_pcidev(xen_xc, xen_domid, serverid, + 0, 0, pci_dev->devfn >> 3, + pci_dev->devfn & 0x7); +} + void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len) { int i; @@ -943,6 +953,29 @@ static void cpu_ioreq_move(ioreq_t *req) } } +#if __XEN_LATEST_INTERFACE_VERSION__ >= 0x00040300 +static void cpu_ioreq_config_space(ioreq_t *req) +{ + uint64_t cf8 = req->addr; + uint32_t tmp = req->size; + uint16_t size = req->size & 0xff; + uint16_t off = req->size >> 16; + + if ((size + off + 0xcfc) > 0xd00) { + hw_error("Invalid ioreq config space size = %u off = %u\n", + size, off); + } + + req->addr = 0xcfc + off; + req->size = size; + + do_outp(0xcf8, 4, cf8); + cpu_ioreq_pio(req); + req->addr = cf8; + req->size = tmp; +} +#endif + static void handle_ioreq(ioreq_t *req) { if (!req->data_is_ptr && (req->dir == IOREQ_WRITE) && @@ -962,6 +995,11 @@ static void handle_ioreq(ioreq_t *req) case IOREQ_TYPE_INVALIDATE: xen_invalidate_map_cache(); break; +#if __XEN_LATEST_INTERFACE_VERSION__ >= 0x00040300 + case IOREQ_TYPE_PCI_CONFIG: + cpu_ioreq_config_space(req); + break; +#endif default: hw_error("Invalid ioreq type 0x%x\n", req->type); } diff --git a/xen-stub.c b/xen-stub.c index 8ff2b79..0128965 100644 --- a/xen-stub.c +++ b/xen-stub.c @@ -25,6 +25,11 @@ void xen_piix3_set_irq(void *opaque, int irq_num, int level) { } +int xen_register_pcidev(PCIDevice *pci_dev) +{ + return 1; +} + void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len) { }