All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yu Zhao <yu.zhao@intel.com>
To: "linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>
Cc: "jbarnes@virtuousgeek.org" <jbarnes@virtuousgeek.org>,
	"randy.dunlap@oracle.com" <randy.dunlap@oracle.com>,
	"grundler@parisc-linux.org" <grundler@parisc-linux.org>,
	"achiang@hp.com" <achiang@hp.com>,
	"matthew@wil.cx" <matthew@wil.cx>,
	"rdreier@cisco.com" <rdreier@cisco.com>,
	"greg@kroah.com" <greg@kroah.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"virtualization@lists.linux-foundation.org" 
	<virtualization@lists.linux-foundation.org>
Subject: [PATCH 9/15 v5] PCI: add boot option to align MMIO resource
Date: Tue, 21 Oct 2008 19:50:34 +0800	[thread overview]
Message-ID: <20081021115034.GJ3185@yzhao12-linux.sh.intel.com> (raw)
In-Reply-To: <20081021114056.GA3185@yzhao12-linux.sh.intel.com>

This patch adds boot option to align MMIO resource for a device.
The alignment is a bigger value between the PAGE_SIZE and the
resource size.

The boot option can be used as:
pci=align-mmio=0000:01:02.3;04:05.6
'0000:01:02.3' and '04:05.6' are domain, bus, device and function numbers.

Cc: Jesse Barnes <jbarnes@virtuousgeek.org>
Cc: Randy Dunlap <randy.dunlap@oracle.com>
Cc: Grant Grundler <grundler@parisc-linux.org>
Cc: Alex Chiang <achiang@hp.com>
Cc: Matthew Wilcox <matthew@wil.cx>
Cc: Roland Dreier <rdreier@cisco.com>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: Yu Zhao <yu.zhao@intel.com>

---
 arch/x86/pci/common.c |   37 +++++++++++++++++++++++++++++++++++++
 drivers/pci/pci.c     |   20 ++++++++++++++++++--
 include/linux/pci.h   |    1 +
 3 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/arch/x86/pci/common.c b/arch/x86/pci/common.c
index 0774a67..c1821e3 100644
--- a/arch/x86/pci/common.c
+++ b/arch/x86/pci/common.c
@@ -139,6 +139,7 @@ static void __devinit pcibios_fixup_device_resources(struct pci_dev *dev)
 
 static char *pci_assign_pio;
 static char *pci_assign_mmio;
+static char *pci_align_mmio;
 
 static int pcibios_bus_resource_needs_fixup(struct pci_bus *bus)
 {
@@ -190,6 +191,36 @@ static void __devinit pcibios_fixup_bus_resources(struct pci_bus *bus)
 	}
 }
 
+int pcibios_resource_alignment(struct pci_dev *dev, int resno)
+{
+	int domain, busnr, slot, func;
+	char *str = pci_align_mmio;
+
+	if (dev->resource[resno].flags & IORESOURCE_IO)
+		return 0;
+
+	while (str && *str) {
+		if (sscanf(str, "%04x:%02x:%02x.%d",
+				&domain, &busnr, &slot, &func) != 4) {
+			if (sscanf(str, "%02x:%02x.%d",
+					&busnr, &slot, &func) != 3)
+				break;
+			domain = 0;
+		}
+
+		if (pci_domain_nr(dev->bus) == domain &&
+		    dev->bus->number == busnr &&
+		    dev->devfn == PCI_DEVFN(slot, func))
+			return PAGE_SIZE;
+
+		str = strchr(str, ';');
+		if (str)
+			str++;
+	}
+
+	return 0;
+}
+
 int pcibios_resource_needs_fixup(struct pci_dev *dev, int resno)
 {
 	struct pci_bus *bus;
@@ -198,6 +229,9 @@ int pcibios_resource_needs_fixup(struct pci_dev *dev, int resno)
 		if (pcibios_bus_resource_needs_fixup(bus))
 			return 1;
 
+	if (pcibios_resource_alignment(dev, resno))
+			return 1;
+
 	return 0;
 }
 
@@ -590,6 +624,9 @@ char * __devinit  pcibios_setup(char *str)
 	} else if (!strncmp(str, "assign-mmio=", 12)) {
 		pci_assign_mmio = str + 12;
 		return NULL;
+	} else if (!strncmp(str, "align-mmio=", 11)) {
+		pci_align_mmio = str + 11;
+		return NULL;
 	}
 	return str;
 }
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index b02167a..11ecd6f 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1015,6 +1015,20 @@ int __attribute__ ((weak)) pcibios_set_pcie_reset_state(struct pci_dev *dev,
 }
 
 /**
+ * pcibios_resource_alignment - get resource alignment requirement
+ * @dev: the PCI device
+ * @resno: resource number
+ *
+ * Queries the resource alignment from PCI low level code. Returns positive
+ * if there is alignment requirement of the resource, or 0 otherwise.
+ */
+int __attribute__ ((weak)) pcibios_resource_alignment(struct pci_dev *dev,
+						      int resno)
+{
+	return 0;
+}
+
+/**
  * pci_set_pcie_reset_state - set reset state for device dev
  * @dev: the PCI-E device reset
  * @state: Reset state to enter into
@@ -1913,12 +1927,14 @@ int pci_select_bars(struct pci_dev *dev, unsigned long flags)
  */
 int pci_resource_alignment(struct pci_dev *dev, int resno)
 {
-	resource_size_t align;
+	resource_size_t align, bios_align;
 	struct resource *res = dev->resource + resno;
 
+	bios_align = pcibios_resource_alignment(dev, resno);
+
 	align = resource_alignment(res);
 	if (align)
-		return align;
+		return align > bios_align ? align : bios_align;
 
 	dev_err(&dev->dev, "alignment: invalid resource #%d\n", resno);
 	return 0;
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 2ada2b6..6ac69af 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1121,6 +1121,7 @@ int pcibios_add_platform_entries(struct pci_dev *dev);
 void pcibios_disable_device(struct pci_dev *dev);
 int pcibios_set_pcie_reset_state(struct pci_dev *dev,
 				 enum pcie_reset_state state);
+int pcibios_resource_alignment(struct pci_dev *dev, int resno);
 
 #ifdef CONFIG_PCI_MMCONFIG
 extern void __init pci_mmcfg_early_init(void);
-- 
1.5.6.4


  parent reply	other threads:[~2008-10-21 12:45 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-21 11:40 [PATCH 0/15 v5] PCI: Linux kernel SR-IOV support Yu Zhao
2008-10-21 11:44 ` [PATCH 1/15 v5] PCI: remove unnecessary arg of pci_update_resource() Yu Zhao
2008-10-21 11:44 ` Yu Zhao
2008-10-21 11:44 ` [PATCH 2/15 v5] PCI: define PCI resource names in an 'enum' Yu Zhao
2008-10-21 11:44 ` Yu Zhao
2008-10-21 11:45 ` [PATCH 3/15 v5] PCI: export __pci_read_base Yu Zhao
2008-10-21 11:45 ` Yu Zhao
2008-10-21 11:47 ` [PATCH 4/15 v5] PCI: make pci_alloc_child_bus() be able to handle NULL bridge Yu Zhao
2008-10-21 11:47 ` Yu Zhao
2008-10-21 11:48 ` [PATCH 5/15 v5] PCI: add a wrapper for resource_alignment() Yu Zhao
2008-10-21 11:48 ` Yu Zhao
2008-10-21 11:48 ` [PATCH 6/15 v5] PCI: add a new function to map BAR offset Yu Zhao
2008-10-21 11:48 ` Yu Zhao
2008-10-21 11:48 ` [PATCH 7/15 v5] PCI: cleanup pcibios_allocate_resources() Yu Zhao
2008-10-21 11:48 ` Yu Zhao
2008-10-21 11:49 ` [PATCH 8/15 v5] PCI: add boot options to reassign resources Yu Zhao
2008-10-21 11:49 ` Yu Zhao
2008-10-22  7:19   ` Ingo Molnar
2008-10-22  7:19   ` Ingo Molnar
2008-10-21 11:50 ` [PATCH 9/15 v5] PCI: add boot option to align MMIO resource Yu Zhao
2008-10-21 11:50 ` Yu Zhao [this message]
2008-10-21 11:51 ` [PATCH 10/15 v5] PCI: cleanup pci_bus_add_devices() Yu Zhao
2008-10-21 11:51 ` Yu Zhao
2008-10-21 11:52 ` [PATCH 11/15 v5] PCI: split a new function from pci_bus_add_devices() Yu Zhao
2008-10-21 11:52 ` Yu Zhao
2008-10-21 11:53 ` [PATCH 12/15 v5] PCI: support the SR-IOV capability Yu Zhao
2008-10-21 11:53 ` Yu Zhao
2008-10-21 16:50   ` Greg KH
2008-10-21 16:50   ` Greg KH
2008-10-22  3:05     ` Zhao, Yu
2008-10-22  3:05     ` Zhao, Yu
2008-10-21 11:53 ` [PATCH 13/15 v5] PCI: reserve bus range for the SR-IOV device Yu Zhao
2008-10-21 11:53 ` Yu Zhao
2008-10-21 11:54 ` [PATCH 14/15 v5] PCI: document the SR-IOV Yu Zhao
2008-10-21 11:54 ` Yu Zhao
2008-10-21 11:54 ` [PATCH 15/15 v5] PCI: document the new PCI boot parameters Yu Zhao
2008-10-21 11:54 ` Yu Zhao

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=20081021115034.GJ3185@yzhao12-linux.sh.intel.com \
    --to=yu.zhao@intel.com \
    --cc=achiang@hp.com \
    --cc=greg@kroah.com \
    --cc=grundler@parisc-linux.org \
    --cc=jbarnes@virtuousgeek.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=matthew@wil.cx \
    --cc=randy.dunlap@oracle.com \
    --cc=rdreier@cisco.com \
    --cc=virtualization@lists.linux-foundation.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.