public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] PCI: Add pci_read_base() API
@ 2008-08-01  6:58 Eric Anholt
  2008-08-01  6:58 ` [PATCH] Export shmem_file_setup and shmem_getpage for DRM-GEM Eric Anholt
  0 siblings, 1 reply; 60+ messages in thread
From: Eric Anholt @ 2008-08-01  6:58 UTC (permalink / raw)
  To: linux-kernel; +Cc: keithp, Matthew Wilcox, Matthew Wilcox

From: Matthew Wilcox <matthew@wil.cx>

Some devices have a BAR at a non-standard address.  The pci_read_base()
API allows us to probe these BARs and fill in a resource for it as if
they were standard BARs.

Signed-off-by: Matthew Wilcox <willy@linux.intel.com>
---
 drivers/pci/probe.c |   47 ++++++++++++++++++++++++++++++++++++++++-------
 include/linux/pci.h |   10 ++++++++++
 2 files changed, 50 insertions(+), 7 deletions(-)

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 7098dfb..1518c4f 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -181,13 +181,6 @@ static u64 pci_size(u64 base, u64 maxbase, u64 mask)
 	return size;
 }
 
-enum pci_bar_type {
-	pci_bar_unknown,	/* Standard PCI BAR probe */
-	pci_bar_io,		/* An io port BAR */
-	pci_bar_mem32,		/* A 32-bit memory BAR */
-	pci_bar_mem64,		/* A 64-bit memory BAR */
-};
-
 static inline enum pci_bar_type decode_bar(struct resource *res, u32 bar)
 {
 	if ((bar & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_IO) {
@@ -300,6 +293,46 @@ static int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
 	goto out;
 }
 
+/**
+ * pci_read_base - Read a BAR from a specified location
+ * @dev: The PCI device to read
+ * @type: The type of BAR to read
+ * @res: A struct resource to be filled in
+ * @reg: The address in PCI config space to read the BAR from.
+ *
+ * Some devices have BARs in unusual places.  This function lets a driver ask
+ * the PCI subsystem to read it and place it in the resource tree.  If it is
+ * like a ROM BAR with an enable in bit 0, the caller should specify a @type
+ * of io, mem32 or mem64.  If it's like a normal BAR with memory type in the
+ * low bits, specify unknown, even if the caller knows what kind of BAR it is.
+ *
+ * Returns -ENXIO if the BAR was not successfully read.  If the BAR is read,
+ * but no suitable parent resource can be found for the BAR, this function
+ * returns -ENODEV.  If the resource cannot be inserted into the resource tree,
+ * it will return -EBUSY.  Note that the resource is still 'live' for these
+ * last two cases; the caller should set res->flags to 0 if this is not wanted.
+ */
+int pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
+					struct resource *res, unsigned int reg)
+{
+	struct pci_bus_region region;
+	struct resource *parent;
+
+	__pci_read_base(dev, type, res, reg);
+	if (!res->flags)
+		return -ENXIO;
+
+	region.start = res->start;
+	region.end = res->end;
+	pcibios_bus_to_resource(dev, res, &region);
+
+	parent = pci_find_parent_resource(dev, res);
+	if (!parent)
+		return -ENODEV;
+	return request_resource(parent, res);
+}
+EXPORT_SYMBOL_GPL(pci_read_base);
+
 static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom)
 {
 	unsigned int pos, reg;
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 825be38..fa7e10a 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -312,6 +312,16 @@ struct pci_bus {
 #define pci_bus_b(n)	list_entry(n, struct pci_bus, node)
 #define to_pci_bus(n)	container_of(n, struct pci_bus, dev)
 
+enum pci_bar_type {
+	pci_bar_unknown,	/* Standard PCI BAR probe */
+	pci_bar_io,		/* An io port BAR */
+	pci_bar_mem32,		/* A 32-bit memory BAR */
+	pci_bar_mem64,		/* A 64-bit memory BAR */
+};
+
+int pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
+					struct resource *res, unsigned int reg);
+
 /*
  * Error values that may be returned by PCI functions.
  */
-- 
1.5.6.3


^ permalink raw reply related	[flat|nested] 60+ messages in thread

end of thread, other threads:[~2008-08-21 16:15 UTC | newest]

Thread overview: 60+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-01  6:58 [PATCH] PCI: Add pci_read_base() API Eric Anholt
2008-08-01  6:58 ` [PATCH] Export shmem_file_setup and shmem_getpage for DRM-GEM Eric Anholt
2008-08-01  6:58   ` [PATCH] drm: Add GEM ("graphics execution manager") to i915 driver Eric Anholt
2008-08-01 15:44     ` Randy Dunlap
2008-08-01 18:11       ` Keith Packard
2008-08-06  1:11       ` Eric Anholt
2008-08-01  7:10   ` [PATCH] Export shmem_file_setup and shmem_getpage for DRM-GEM Eric Anholt
2008-08-01 10:57   ` Hugh Dickins
2008-08-01 18:06     ` Keith Packard
2008-08-01 20:50   ` Christoph Hellwig
2008-08-01 23:01     ` Keith Packard
2008-08-03 12:49       ` John Stoffel
2008-08-03 17:52         ` Keith Packard
2008-08-03 23:35           ` files/process scaling problem? (was: [PATCH] Export shmem_file_setup and shmem_getpage for DRM-GEM) Ingo Oeser
2008-08-04  0:19             ` Keith Packard
2008-08-04  8:19               ` Alan Cox
2008-08-04 13:51                 ` Arjan van de Ven
2008-08-04 14:11                   ` Alan Cox
2008-08-04 16:38                     ` Arjan van de Ven
2008-08-04 16:58                     ` Keith Packard
2008-08-04 21:46                       ` Ingo Oeser
2008-08-04 22:20                         ` Dave Airlie
2008-08-05  0:34                         ` Keith Packard
2008-08-11  1:23       ` [PATCH] Export shmem_file_setup and shmem_getpage for DRM-GEM Christoph Hellwig
2008-08-11  3:03         ` [PATCH] Export shmem_file_setup " Keith Packard
2008-08-04  1:54     ` [PATCH] Export shmem_file_setup and shmem_getpage " Keith Packard
2008-08-04  9:02       ` Nick Piggin
2008-08-04 10:26         ` Keith Packard
2008-08-04 10:43           ` Nick Piggin
2008-08-04 11:45             ` Keith Packard
2008-08-04 17:09               ` Hugh Dickins
2008-08-04 17:25                 ` Keith Packard
2008-08-04 18:39                   ` Hugh Dickins
2008-08-04 19:20                     ` Keith Packard
2008-08-04 19:55                       ` Hugh Dickins
2008-08-04 21:37                         ` Keith Packard
2008-08-05  2:25                         ` John Stoffel
2008-08-05  4:28                           ` Keith Packard
2008-08-06 16:20                             ` Stephane Marchesin
2008-08-06 17:24                               ` Arjan van de Ven
2008-08-06 17:32                                 ` Stephane Marchesin
2008-08-06 17:56                                   ` Keith Packard
2008-08-06 18:09                                     ` Stephane Marchesin
2008-08-06 21:22                                       ` Keith Packard
2008-08-07  2:16                                 ` Stephane Marchesin
2008-08-07  2:57                                   ` Keith Packard
2008-08-11  1:34                                 ` Christoph Hellwig
2008-08-05  4:28                 ` Nick Piggin
2008-08-11  1:30                 ` Christoph Hellwig
2008-08-04 21:58         ` Keith Packard
2008-08-04 22:22           ` Dave Airlie
2008-08-05  4:43           ` Nick Piggin
2008-08-05  5:19             ` Keith Packard
2008-08-07  0:45             ` Jesse Barnes
2008-08-19  1:17             ` Dave Airlie
2008-08-19 10:00               ` Nick Piggin
2008-08-19 16:46                 ` Keith Packard
2008-08-19 18:50                   ` Jesse Barnes
2008-08-21 13:42                     ` Jerome Glisse
2008-08-21 16:15                       ` Jesse Barnes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox