From patchwork Wed Oct 18 11:40:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 10014429 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BF60460211 for ; Wed, 18 Oct 2017 11:43:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE01C28B09 for ; Wed, 18 Oct 2017 11:43:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B2E1028B27; Wed, 18 Oct 2017 11:43:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 498EB28B09 for ; Wed, 18 Oct 2017 11:43:03 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e4miL-0003v1-5F; Wed, 18 Oct 2017 11:40:45 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e4miK-0003uF-C1 for xen-devel@lists.xenproject.org; Wed, 18 Oct 2017 11:40:44 +0000 Received: from [85.158.137.68] by server-8.bemta-3.messagelabs.com id D4/45-00983-BBD37E95; Wed, 18 Oct 2017 11:40:43 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrOIsWRWlGSWpSXmKPExsXitHRDpO4u2+e RBjvOMFl83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBlb161kL/imUvHz8W22BsY50l2MnBwSAv4S R7bdZQWx2QR0JC7O3cnWxcjBISKgInF7r0EXIxcHs8B0ZokP/6exgdQIC3hIzF60ggXEZhFQl ej9fooRxOYVsJT4eesVO0ivhICexI/thiBhTgEriclzGphAbCGgkqsXG6DKBSVOznwCNoZZQF OidftvdghbXqJ562xmiHpFif55D9gmMPLNQtIyC0nLLCQtCxiZVzGqF6cWlaUW6ZrqJRVlpme U5CZm5ugaGhjr5aYWFyemp+YkJhXrJefnbmIEBlo9AwPjDsbLX50OMUpyMCmJ8uoeeBYpxJeU n1KZkVicEV9UmpNafIhRhoNDSYL3hM3zSCHBotT01Iq0zBxgyMOkJTh4lER4V1sDpXmLCxJzi zPTIVKnGHU5Om7e/cMkxJKXn5cqJc47F2SGAEhRRmke3AhY/F1ilJUS5mVkYGAQ4ilILcrNLE GVf8UozsGoJMz7AGQKT2ZeCdymV0BHMAEdsc7pCcgRJYkIKakGxpj1uurPCs1f72FlT1bLvL9 B7N1kGWsHrd9O9SUffx2Ke7lu1Tbt+W9le8IrDnywPrEngeeB3aYXDyeFTlSpENpXp3dgD+cb +39HWtc91v+beEdARn/SFbNXvW8YN1vKX+ZWsb5llbgtKcxiztykd88vnt4nesSfadJs/fDu+ hsrIrfl9qe0/1ViKc5INNRiLipOBACtPUYPugIAAA== X-Env-Sender: prvs=457281bb7=roger.pau@citrix.com X-Msg-Ref: server-3.tower-31.messagelabs.com!1508326838!110824534!2 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 26424 invoked from network); 18 Oct 2017 11:40:41 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-3.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 18 Oct 2017 11:40:41 -0000 X-IronPort-AV: E=Sophos;i="5.43,396,1503360000"; d="scan'208";a="446854104" From: Roger Pau Monne To: Date: Wed, 18 Oct 2017 12:40:24 +0100 Message-ID: <20171018114034.36587-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.13.5 (Apple Git-94) In-Reply-To: <20171018114034.36587-1-roger.pau@citrix.com> References: <20171018114034.36587-1-roger.pau@citrix.com> MIME-Version: 1.0 Cc: Stefano Stabellini , Wei Liu , konrad.wilk@oracle.com, George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Paul Durrant , Jan Beulich , boris.ostrovsky@oracle.com, Roger Pau Monne Subject: [Xen-devel] [PATCH v7 for-next 02/12] pci: introduce a type to store a SBDF X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP That provides direct access to all the members that constitute a SBDF. The only function switched to use it is hvm_pci_decode_addr, because it makes following patches simpler. Suggested-by: Andrew Cooper Signed-off-by: Roger Pau Monné Reviewed-by: Paul Durrant Acked-by: Jan Beulich Reviewed-by: Wei Liu --- Cc: Paul Durrant Cc: Jan Beulich Cc: Andrew Cooper Cc: George Dunlap Cc: Ian Jackson Cc: Konrad Rzeszutek Wilk Cc: Stefano Stabellini Cc: Tim Deegan Cc: Wei Liu --- Changes since v6: - Use sbdf instead of bdf as variable name. - Explicitly set the segment to 0. Changes since v5: - New in this version. --- xen/arch/x86/hvm/io.c | 11 +++-------- xen/arch/x86/hvm/ioreq.c | 12 +++++------- xen/include/asm-x86/hvm/io.h | 4 ++-- xen/include/xen/pci.h | 20 ++++++++++++++++++++ 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/xen/arch/x86/hvm/io.c b/xen/arch/x86/hvm/io.c index 10e1e2db45..6579e119ff 100644 --- a/xen/arch/x86/hvm/io.c +++ b/xen/arch/x86/hvm/io.c @@ -265,17 +265,12 @@ void register_g2m_portio_handler(struct domain *d) } unsigned int hvm_pci_decode_addr(unsigned int cf8, unsigned int addr, - unsigned int *bus, unsigned int *slot, - unsigned int *func) + pci_sbdf_t *sbdf) { - unsigned int bdf; - ASSERT(CF8_ENABLED(cf8)); - bdf = CF8_BDF(cf8); - *bus = PCI_BUS(bdf); - *slot = PCI_SLOT(bdf); - *func = PCI_FUNC(bdf); + sbdf->bdf = CF8_BDF(cf8); + sbdf->seg = 0; /* * NB: the lower 2 bits of the register address are fetched from the * offset into the 0xcfc register when reading/writing to it. diff --git a/xen/arch/x86/hvm/ioreq.c b/xen/arch/x86/hvm/ioreq.c index d5afe20cc8..ec9b31ffc4 100644 --- a/xen/arch/x86/hvm/ioreq.c +++ b/xen/arch/x86/hvm/ioreq.c @@ -1183,17 +1183,15 @@ struct hvm_ioreq_server *hvm_select_ioreq_server(struct domain *d, (p->addr & ~3) == 0xcfc && CF8_ENABLED(cf8) ) { - uint32_t sbdf, x86_fam; - unsigned int bus, slot, func, reg; + uint32_t x86_fam; + pci_sbdf_t sbdf; + unsigned int reg; - reg = hvm_pci_decode_addr(cf8, p->addr, &bus, &slot, &func); + reg = hvm_pci_decode_addr(cf8, p->addr, &sbdf); /* PCI config data cycle */ - - sbdf = XEN_DMOP_PCI_SBDF(0, bus, slot, func); - type = XEN_DMOP_IO_RANGE_PCI; - addr = ((uint64_t)sbdf << 32) | reg; + addr = ((uint64_t)sbdf.sbdf << 32) | reg; /* AMD extended configuration space access? */ if ( CF8_ADDR_HI(cf8) && d->arch.cpuid->x86_vendor == X86_VENDOR_AMD && diff --git a/xen/include/asm-x86/hvm/io.h b/xen/include/asm-x86/hvm/io.h index 51659b6c7f..707665fbba 100644 --- a/xen/include/asm-x86/hvm/io.h +++ b/xen/include/asm-x86/hvm/io.h @@ -20,6 +20,7 @@ #define __ASM_X86_HVM_IO_H__ #include +#include #include #include #include @@ -151,8 +152,7 @@ extern void hvm_dpci_msi_eoi(struct domain *d, int vector); /* Decode a PCI port IO access into a bus/slot/func/reg. */ unsigned int hvm_pci_decode_addr(unsigned int cf8, unsigned int addr, - unsigned int *bus, unsigned int *slot, - unsigned int *func); + pci_sbdf_t *sbdf); /* * HVM port IO handler that performs forwarding of guest IO ports into machine diff --git a/xen/include/xen/pci.h b/xen/include/xen/pci.h index 43f21251a5..dd5ec43a70 100644 --- a/xen/include/xen/pci.h +++ b/xen/include/xen/pci.h @@ -38,6 +38,26 @@ #define PCI_SBDF2(s,bdf) ((((s) & 0xffff) << 16) | ((bdf) & 0xffff)) #define PCI_SBDF3(s,b,df) ((((s) & 0xffff) << 16) | PCI_BDF2(b, df)) +typedef union { + uint32_t sbdf; + struct { + union { + uint16_t bdf; + struct { + union { + struct { + uint8_t func : 3, + dev : 5; + }; + uint8_t extfunc; + }; + uint8_t bus; + }; + }; + uint16_t seg; + }; +} pci_sbdf_t; + struct pci_dev_info { /* * VF's 'is_extfn' field is used to indicate whether its PF is an extended