Skip to contentSkip to conversation

pci: introduce an pci_ioremap(pdev, barnr) function

PATCH Applied Arjan van de Ven 4 participants 8 messages Sep 28, 2008 – Oct 2, 2008 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/19 pci: introduce an pci_ioremap(pdev, barnr) function

The patch below introduces a pci_ioremap() function that should make it easier for driver authors to do the right thing for the simple, common case.

There's also 18 patches that introduce users of this; to reduce lkml noise I've only stuck them in a git tree at
git://git.kernel.org/pub/scm/linux/kernel/git/arjan/linux-2.6-pci_ioremap.git
(http://git.kernel.org/?p=linux/kernel/git/arjan/linux-2.6-pci_ioremap.git;a=summary)

Quoted 1 line

From fef1dd836bc7dc07962a0ae4019af9efd373c76f Mon Sep 17 00:00:00 2001

From: Arjan van de Ven <[email protected]>
Date: Fri, 26 Sep 2008 16:34:52 -0700
Subject: [PATCH 01/19] pci: introduce an pci_ioremap(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 pci_ioremap() 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.

---
 include/linux/pci.h |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
include/linux/pci.h +13 -0
index 709b8d4..3f8ce81 100644
@@ -1127,5 +1127,18 @@ static inline void pci_mmcfg_early_init(void) { }
 static inline void pci_mmcfg_late_init(void) { }
 #endif
 
+static inline void * pci_ioremap_bar(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 */
Signature · 8 lines
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
#1 lore raw
Quoted 21 lines · Arjan van de Ven

The patch below introduces a pci_ioremap() function that should make it easier for driver authors to do the right thing for the simple, common case.

There's also 18 patches that introduce users of this; to reduce lkml noise I've only stuck them in a git tree at
git://git.kernel.org/pub/scm/linux/kernel/git/arjan/linux-2.6-pci_ioremap.g
it
(http://git.kernel.org/?p=linux/kernel/git/arjan/linux-2.6-pci_ioremap.git;
a=summary)

From fef1dd836bc7dc07962a0ae4019af9efd373c76f Mon Sep 17 00:00:00 2001
From: Arjan van de Ven <[email protected]>
Date: Fri, 26 Sep 2008 16:34:52 -0700
Subject: [PATCH 01/19] pci: introduce an pci_ioremap(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.

Quoted 5 lines

This patch introduces an pci_ioremap() 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).

This is the same like pci_iomap(pdev, number, 0), no?

Greetings,

Eike

#2 lore raw
Quoted 23 lines · Rolf Eike Beer
Quoted 22 lines · Arjan van de Ven

The patch below introduces a pci_ioremap() function that should make it easier for driver authors to do the right thing for the simple, common case.

There's also 18 patches that introduce users of this; to reduce lkml noise I've only stuck them in a git tree at
git://git.kernel.org/pub/scm/linux/kernel/git/arjan/linux-2.6-pci_ioremap
.g it
(http://git.kernel.org/?p=linux/kernel/git/arjan/linux-2.6-pci_ioremap.gi
t; a=summary)

From fef1dd836bc7dc07962a0ae4019af9efd373c76f Mon Sep 17 00:00:00 2001
From: Arjan van de Ven <[email protected]>
Date: Fri, 26 Sep 2008 16:34:52 -0700
Subject: [PATCH 01/19] pci: introduce an pci_ioremap(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.

Quoted 7 lines
Quoted 5 lines

This patch introduces an pci_ioremap() 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).

This is the same like pci_iomap(pdev, number, 0), no?

Yeah... Looks like that function isn't that widely used though. Is the maxlen param really needed? Looks like the drivers that use it often pass 0 or the BAR length anyway, and Arjan converted existing drivers too, which is where the real work is.

Jesse

#3 lore raw
Quoted 4 lines
Quoted 1 line

This is the same like pci_iomap(pdev, number, 0), no?

Yeah... Looks like that function isn't that widely used though. Is the maxlen param really needed? Looks like the drivers that use it often pass 0 or the

In some cases yes you do need the length.

Quoted 2 lines

BAR length anyway, and Arjan converted existing drivers too, which is where the real work is.

He could have converted them to the existing perfectly good API not invented another one. He still can - I'm sure its a perl one liner to redo them in terms of pci_iomap()

Alan

#4 lore raw
Quoted 7 lines · On Mon, 29 Sep 2008 18:45:19 +0100 Alan Cox <[email protected]> wrote:
Quoted 5 lines
Quoted 1 line

This is the same like pci_iomap(pdev, number, 0), no?

Yeah... Looks like that function isn't that widely used though. Is the maxlen param really needed? Looks like the drivers that use it often pass 0 or the

In some cases yes you do need the length.

so we should have a 2nd api for those "some cases", that's ok.

Quoted 7 lines
Quoted 3 lines

BAR length anyway, and Arjan converted existing drivers too, which is where the real work is.

He could have converted them to the existing perfectly good API not invented another one. He still can - I'm sure its a perl one liner to redo them in terms of pci_iomap()

pci_iomap() assumes you're using the rest of the iomap API as well!

most drivers do not do that.

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#5 lore raw
Quoted 5 lines · Arjan van de Ven

On Mon, 29 Sep 2008 18:45:19 +0100

Quoted 2 lines · Alan Cox
Quoted 2 lines
Quoted 1 line

This is the same like pci_iomap(pdev, number, 0), no?

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Yeah... Looks like that function isn't that widely used though. Is the maxlen param really needed? Looks like the drivers that use it often pass 0 or the

In some cases yes you do need the length.

so we should have a 2nd api for those "some cases", that's ok.

Right, I'm definitely not suggesting that we don't provide a way to provide length, but if 90+% of callers don't need it, we should probably have a simpler API that does the bare minimum.

Jesse

Applied
#6 lore raw
In reply to Arjan van de Ven
Quoted 27 lines · Arjan van de Ven

The patch below introduces a pci_ioremap() function that should make it easier for driver authors to do the right thing for the simple, common case.

There's also 18 patches that introduce users of this; to reduce lkml noise I've only stuck them in a git tree at
git://git.kernel.org/pub/scm/linux/kernel/git/arjan/linux-2.6-pci_ioremap.g
it
(http://git.kernel.org/?p=linux/kernel/git/arjan/linux-2.6-pci_ioremap.git;
a=summary)

From fef1dd836bc7dc07962a0ae4019af9efd373c76f Mon Sep 17 00:00:00 2001
From: Arjan van de Ven <[email protected]>
Date: Fri, 26 Sep 2008 16:34:52 -0700
Subject: [PATCH 01/19] pci: introduce an pci_ioremap(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 pci_ioremap() 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).

Quoted 4 lines

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

Applied to my linux-next branch, thanks. I assume you'll have Linus pull the driver updates later?

Thanks,
Jesse

#7 lore raw
Quoted 8 lines · On Thu, 2 Oct 2008 11:53:40 -0700 Jesse Barnes <[email protected]> wrote:
Quoted 5 lines

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

Applied to my linux-next branch, thanks. I assume you'll have Linus pull the driver updates later?

yeah I either need to do an akpm-like "spray the maintainers" or just do one big pull, haven't figure it out yet
(would be nice if I could just dump the patches on Andrew who then does the bombard-the-maintainers thing)

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