linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jon Derrick <jonathan.derrick@intel.com>
To: Bjorn Helgaas <helgaas@kernel.org>,
	Keith Busch <keith.busch@intel.com>, <linux-pci@vger.kernel.org>
Cc: Joerg Roedel <jroedel@suse.de>,
	Myron Stowe <myron.stowe@redhat.com>,
	Dave Fugate <david.fugate@intel.com>,
	Scott Bauer <scott.bauer@intel.com>,
	Jon Derrick <jonathan.derrick@intel.com>
Subject: [RFC PATCH 1/4] PCI/VMD: Assign membar addresses from shadow registers
Date: Thu, 10 May 2018 18:49:00 -0600	[thread overview]
Message-ID: <20180511004903.19892-2-jonathan.derrick@intel.com> (raw)
In-Reply-To: <20180511004903.19892-1-jonathan.derrick@intel.com>

The new VMD device has registers within membar 2 which may shadow the
membar 1 and membar 2 addresses. These are intended to be used in
virtualization, where assigning a guest address wouldn't be translated
in the assignment to root port and child devices because the addresses
exist within the assignment message.

These values will only reflect the membars when enabled in the BIOS, as
determined by a register in the VMD device.

Signed-off-by: Jon Derrick <jonathan.derrick@intel.com>
---
 drivers/pci/host/vmd.c | 52 +++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 43 insertions(+), 9 deletions(-)

diff --git a/drivers/pci/host/vmd.c b/drivers/pci/host/vmd.c
index 930a8fa08bd6..62270aeb7a2e 100644
--- a/drivers/pci/host/vmd.c
+++ b/drivers/pci/host/vmd.c
@@ -24,6 +24,9 @@
 #define VMD_MEMBAR1	2
 #define VMD_MEMBAR2	4
 
+#define PCI_REG_VMLOCK		0x70
+#define MB2_SHADOW_EN(vmlock)	(vmlock & 0x2)
+
 /*
  * Lock for manipulating VMD IRQ lists.
  */
@@ -551,9 +554,9 @@ static int vmd_enable_domain(struct vmd_dev *vmd)
 	struct pci_sysdata *sd = &vmd->sysdata;
 	struct fwnode_handle *fn;
 	struct resource *res;
-	u32 upper_bits;
 	unsigned long flags;
 	LIST_HEAD(resources);
+	resource_size_t start, end, membar2_offset;
 
 	res = &vmd->dev->resource[VMD_CFGBAR];
 	vmd->resources[0] = (struct resource) {
@@ -581,27 +584,34 @@ static int vmd_enable_domain(struct vmd_dev *vmd)
 	 * according to the platform needs.
 	 */
 	res = &vmd->dev->resource[VMD_MEMBAR1];
-	upper_bits = upper_32_bits(res->end);
+	start = vmd->resources[1].start;
+	end = start + resource_size(res) - 1;
 	flags = res->flags & ~IORESOURCE_SIZEALIGN;
-	if (!upper_bits)
+	if (upper_32_bits(end))
+		flags |= IORESOURCE_MEM_64;
+	else
 		flags &= ~IORESOURCE_MEM_64;
 	vmd->resources[1] = (struct resource) {
 		.name  = "VMD MEMBAR1",
-		.start = res->start,
-		.end   = res->end,
+		.start = start,
+		.end   = end,
 		.flags = flags,
 		.parent = res,
 	};
 
 	res = &vmd->dev->resource[VMD_MEMBAR2];
-	upper_bits = upper_32_bits(res->end);
+	start = vmd->resources[2].start;
+	end = start + resource_size(res) - 1;
 	flags = res->flags & ~IORESOURCE_SIZEALIGN;
-	if (!upper_bits)
+	if (upper_32_bits(end))
+		flags |= IORESOURCE_MEM_64;
+	else
 		flags &= ~IORESOURCE_MEM_64;
+	membar2_offset = (vmd->dev->device == 0x28c0) ? 0x2018 : 0x2000;
 	vmd->resources[2] = (struct resource) {
 		.name  = "VMD MEMBAR2",
-		.start = res->start + 0x2000,
-		.end   = res->end,
+		.start = start + membar2_offset,
+		.end   = end,
 		.flags = flags,
 		.parent = res,
 	};
@@ -662,6 +672,7 @@ static int vmd_probe(struct pci_dev *dev, const struct pci_device_id *id)
 {
 	struct vmd_dev *vmd;
 	int i, err;
+	u32 vmlock = 0;
 
 	if (resource_size(&dev->resource[VMD_CFGBAR]) < (1 << 20))
 		return -ENOMEM;
@@ -711,6 +722,29 @@ static int vmd_probe(struct pci_dev *dev, const struct pci_device_id *id)
 			return err;
 	}
 
+	/*
+	 * For the new VMD device id, shadow registers exist within the MEMBAR2
+	 * which allow guests to correctly assign host physical addresses to
+	 * the root ports and child devices. These registers will either return
+	 * the host value or 0, depending on an enable bit in the VMD device.
+	 */
+	if (id->device == 0x28c0)
+		pci_read_config_dword(dev, PCI_REG_VMLOCK, &vmlock);
+
+	if (MB2_SHADOW_EN(vmlock)) {
+		void __iomem *membar2;
+
+		membar2 = pci_iomap(dev, VMD_MEMBAR2, 0);
+		if (!membar2)
+			return -ENOMEM;
+		vmd->resources[1].start = readq(membar2 + 0x2008);
+		vmd->resources[2].start = readq(membar2 + 0x2010);
+		pci_iounmap(dev, membar2);
+	} else {
+		vmd->resources[1].start = vmd->dev->resource[VMD_MEMBAR1].start;
+		vmd->resources[2].start = vmd->dev->resource[VMD_MEMBAR2].start;
+	}
+
 	spin_lock_init(&vmd->cfg_lock);
 	pci_set_drvdata(dev, vmd);
 	err = vmd_enable_domain(vmd);
-- 
2.14.3

  reply	other threads:[~2018-05-11  0:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-11  0:48 [RFC PATCH 0/4] Enable new VMD device Jon Derrick
2018-05-11  0:49 ` Jon Derrick [this message]
2018-05-14 14:23   ` [RFC PATCH 1/4] PCI/VMD: Assign membar addresses from shadow registers Christoph Hellwig
2018-05-11  0:49 ` [RFC PATCH 2/4] PCI/VMD: Add offset to bus numbers if necessary Jon Derrick
2018-05-11  0:49 ` [RFC PATCH 3/4] x86/PCI: Add new VMD device root ports to VMD AER quirk Jon Derrick
2018-05-11  0:49 ` [RFC PATCH 4/4] PCI/VMD: Add new VMD device id to driver device id table Jon Derrick

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=20180511004903.19892-2-jonathan.derrick@intel.com \
    --to=jonathan.derrick@intel.com \
    --cc=david.fugate@intel.com \
    --cc=helgaas@kernel.org \
    --cc=jroedel@suse.de \
    --cc=keith.busch@intel.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=myron.stowe@redhat.com \
    --cc=scott.bauer@intel.com \
    /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).