public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pci: introduce an ioremap_pcibar(pdev, barnr) function
@ 2008-09-26 23:36 Arjan van de Ven
  2008-09-26 23:37 ` [PATCH] pci: introduce users of ioremap_pcibar() Arjan van de Ven
  2008-09-27  2:56 ` [PATCH] pci: introduce an ioremap_pcibar(pdev, barnr) function Matthew Wilcox
  0 siblings, 2 replies; 18+ messages in thread
From: Arjan van de Ven @ 2008-09-26 23:36 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-pci

>From abb4ec6b5b7f22904668fb5de5fe0d7a3a7fd2d5 Mon Sep 17 00:00:00 2001
From: Arjan van de Ven <arjan@linux.intel.com>
Date: Fri, 26 Sep 2008 16:34:52 -0700
Subject: [PATCH] pci: introduce an ioremap_pcibar(pdev, barnr) function

A common thing in many PCI drivers is to ioremap() an entire bar.
This is a slightly fragile thing right now, needing both an address and a size,
and many driver writers do.. various things there.

This patch introduces an ioremap_pcibar() function taking just a PCI device struct
and the bar number as arguments, and figures this all out itself, in one place.
In addition, we can add various sanity checks to this function (the patch already
checks to make sure that the bar in question really is a MEM bar; few to no drivers
do that sort of thing).

Hopefully with this type of API we get less chance of mistakes in drivers with
ioremap() operations.

Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
---
 include/linux/pci.h |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/include/linux/pci.h b/include/linux/pci.h
index e48614b..65c1dbc 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1122,5 +1122,18 @@ static inline void pci_mmcfg_early_init(void) { }
 static inline void pci_mmcfg_late_init(void) { }
 #endif
 
+static inline void * ioremap_pcibar(struct pci_dev *pdev, int bar)
+{
+	/*
+	 * Make sure the BAR is actually a memory resource, not an IO resource
+	 */
+	if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) {
+		WARN_ON(1);
+		return NULL;
+	}
+	return ioremap_nocache(pci_resource_start(pdev, bar),
+				     pci_resource_len(pdev, bar));
+}
+
 #endif /* __KERNEL__ */
 #endif /* LINUX_PCI_H */
-- 
1.5.5.1



-- 
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org

^ permalink raw reply related	[flat|nested] 18+ messages in thread
* Re: [PATCH] pci: introduce users of ioremap_pcibar()
@ 2008-09-29 18:08 Marin Mitov
  0 siblings, 0 replies; 18+ messages in thread
From: Marin Mitov @ 2008-09-29 18:08 UTC (permalink / raw)
  To: linux-kernel

Hi all,

What about: pci_iomap_bar(pdev, bar) that uses pci_iomap
(with the patch of Grant, http://lkml.org/lkml/2008/9/29/172)
and simplifies the arguments of pci_iomap() and makes all
the checks of the proposed by Arjan for ioremap_pcibar()?

Best of both worlds? ;-)
I like the simplification proposed by Arjan.

Regards.

Marin Mitov

P.S. I am not on the list.


^ permalink raw reply	[flat|nested] 18+ messages in thread
* Re: [PATCH] pci: introduce users of ioremap_pcibar()
@ 2008-10-01  6:39 Marin Mitov
  0 siblings, 0 replies; 18+ messages in thread
From: Marin Mitov @ 2008-10-01  6:39 UTC (permalink / raw)
  To: linux-kernel; +Cc: Grant Grundler, Arjan van de Ven

Hi,

Sorry to interfere :-)

> I'm fine with pci_iomap_bar()... it meets my goals
> Would be nice if I'd be allowed to make it only work on MEM bars not IO
> bars (so that drivers don't accidentally end up calling this on an IO
> bar and then using readl() etc)

If have understood the APIs correctly, pci_iomap() is supposed to be used
in conjunction with io{read,write}{8,16,32}(), not with readl() etc.

Regards.

Marin Mitov


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

end of thread, other threads:[~2008-10-01 13:53 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-26 23:36 [PATCH] pci: introduce an ioremap_pcibar(pdev, barnr) function Arjan van de Ven
2008-09-26 23:37 ` [PATCH] pci: introduce users of ioremap_pcibar() Arjan van de Ven
2008-09-29  7:26   ` Grant Grundler
2008-09-29  9:20     ` Alan Cox
2008-09-29 13:42     ` Arjan van de Ven
2008-09-29 17:10       ` Grant Grundler
2008-09-29 17:23         ` Arjan van de Ven
2008-10-01  5:24           ` Grant Grundler
2008-09-30 22:30             ` Arjan van de Ven
2008-10-01 10:33               ` Rolf Eike Beer
2008-10-01 12:42               ` Kyle McMartin
2008-10-01 12:57                 ` Matthew Wilcox
2008-10-01 13:07                   ` Kyle McMartin
2008-10-01 13:53                     ` Arjan van de Ven
2008-09-27  2:56 ` [PATCH] pci: introduce an ioremap_pcibar(pdev, barnr) function Matthew Wilcox
2008-09-27 15:35   ` Arjan van de Ven
  -- strict thread matches above, loose matches on Subject: below --
2008-09-29 18:08 [PATCH] pci: introduce users of ioremap_pcibar() Marin Mitov
2008-10-01  6:39 Marin Mitov

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