xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Roger Pau Monne <roger.pau@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: Stefano Stabellini <sstabellini@kernel.org>,
	Wei Liu <wei.liu2@citrix.com>,
	konrad.wilk@oracle.com,
	George Dunlap <George.Dunlap@eu.citrix.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Ian Jackson <ian.jackson@eu.citrix.com>, Tim Deegan <tim@xen.org>,
	Paul Durrant <paul.durrant@citrix.com>,
	Jan Beulich <jbeulich@suse.com>,
	boris.ostrovsky@oracle.com,
	Roger Pau Monne <roger.pau@citrix.com>
Subject: [PATCH v7 for-next 02/12] pci: introduce a type to store a SBDF
Date: Wed, 18 Oct 2017 12:40:24 +0100	[thread overview]
Message-ID: <20171018114034.36587-3-roger.pau@citrix.com> (raw)
In-Reply-To: <20171018114034.36587-1-roger.pau@citrix.com>

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 <andrew.cooper3@citrix.com>
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Paul Durrant <paul.durrant@citrix.com>
---
Cc: Paul Durrant <paul.durrant@citrix.com>
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: George Dunlap <George.Dunlap@eu.citrix.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Tim Deegan <tim@xen.org>
Cc: Wei Liu <wei.liu2@citrix.com>
---
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 <xen/mm.h>
+#include <xen/pci.h>
 #include <asm/hvm/vpic.h>
 #include <asm/hvm/vioapic.h>
 #include <public/hvm/ioreq.h>
@@ -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
-- 
2.13.5 (Apple Git-94)


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  parent reply	other threads:[~2017-10-18 11:40 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-18 11:40 [PATCH v7 for-next 00/12] vpci: PCI config space emulation Roger Pau Monne
2017-10-18 11:40 ` [PATCH v7 for-next 01/12] x86/pio: allow internal PIO handlers to return RETRY Roger Pau Monne
2017-10-20  9:28   ` Paul Durrant
2017-10-18 11:40 ` Roger Pau Monne [this message]
2017-10-26 15:57   ` [PATCH v7 for-next 02/12] pci: introduce a type to store a SBDF Jan Beulich
2017-10-31 10:50   ` Wei Liu
2017-10-18 11:40 ` [PATCH v7 for-next 03/12] vpci: introduce basic handlers to trap accesses to the PCI config space Roger Pau Monne
2017-10-20  9:34   ` Paul Durrant
2017-12-12 16:17   ` Jan Beulich
2017-10-18 11:40 ` [PATCH v7 for-next 04/12] x86/mmcfg: add handlers for the PVH Dom0 MMCFG areas Roger Pau Monne
2017-10-20  9:47   ` Paul Durrant
2017-12-12 16:25   ` Jan Beulich
2017-10-18 11:40 ` [PATCH v7 for-next 05/12] x86/physdev: enable PHYSDEVOP_pci_mmcfg_reserved for PVH Dom0 Roger Pau Monne
2017-12-15 10:45   ` Jan Beulich
2017-10-18 11:40 ` [PATCH v7 for-next 06/12] pci: split code to size BARs from pci_add_device Roger Pau Monne
2017-12-15 10:54   ` Jan Beulich
2017-10-18 11:40 ` [PATCH v7 for-next 07/12] pci: add support to size ROM BARs to pci_size_mem_bar Roger Pau Monne
2017-10-18 11:40 ` [PATCH v7 for-next 08/12] xen: introduce rangeset_consume_ranges Roger Pau Monne
2017-10-31 10:50   ` Wei Liu
2017-10-18 11:40 ` [PATCH v7 for-next 09/12] vpci/bars: add handlers to map the BARs Roger Pau Monne
2017-12-15 11:43   ` Jan Beulich
2018-01-19 15:47     ` Roger Pau Monné
2018-01-19 16:16       ` Jan Beulich
2018-01-19 16:57         ` Roger Pau Monné
2017-10-18 11:40 ` [PATCH v7 for-next 10/12] vpci/msi: add MSI handlers Roger Pau Monne
2017-10-20  9:58   ` Paul Durrant
2017-12-15 12:07   ` Jan Beulich
2018-01-22 12:48     ` Roger Pau Monné
2018-01-22 12:58       ` Jan Beulich
2018-01-22 14:55         ` Roger Pau Monné
2017-10-18 11:40 ` [PATCH v7 for-next 11/12] vpci: add a priority parameter to the vPCI register initializer Roger Pau Monne
2017-10-18 11:40 ` [PATCH v7 for-next 12/12] vpci/msix: add MSI-X handlers Roger Pau Monne
2017-12-20 16:13   ` Jan Beulich
2018-01-23 10:38     ` Roger Pau Monné

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171018114034.36587-3-roger.pau@citrix.com \
    --to=roger.pau@citrix.com \
    --cc=George.Dunlap@eu.citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=konrad.wilk@oracle.com \
    --cc=paul.durrant@citrix.com \
    --cc=sstabellini@kernel.org \
    --cc=tim@xen.org \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).