public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jeff Garzik <jeff@garzik.org>
To: Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Cc: "Luis R. Rodriguez" <mcgrof@gmail.com>,
	Alan Cox <alan@lxorguk.ukuu.org.uk>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	"John W. Linville" <linville@tuxdriver.com>,
	linux-wireless <linux-wireless@vger.kernel.org>
Subject: Re: [PATCH] Clarify pci_iomap() usage for MMIO-only devices
Date: Tue, 18 Sep 2007 19:08:36 -0400	[thread overview]
Message-ID: <46F05A74.2000005@garzik.org> (raw)
In-Reply-To: <1190154053.6403.125.camel@localhost.localdomain>

[-- Attachment #1: Type: text/plain, Size: 426 bytes --]

Benjamin Herrenschmidt wrote:
> On Tue, 2007-09-18 at 16:21 -0400, Jeff Garzik wrote:
>> A new pci_mmio_map() helper, to be used with 100% MMIO hardware, might
>> help eliminate confusion. 
> 
> Maybe not the best name in theory but at least would show that it
> relates to existing ioremap would be pci_ioremap()


Easy enough... 'pcimap' branch of
git://git.kernel.org/pub/scm/linux/kernel/git/jgarzik/misc-2.6.git

	Jeff



[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 2495 bytes --]

commit 6e09c71822f76c618353682bf295fc7588284521
Author: Jeff Garzik <jeff@garzik.org>
Date:   Tue Sep 18 19:06:08 2007 -0400

    Add pci_ioremap() to generic iomap lib.
    
    (arches that don't wish to use lib/iomap.c's version may fill in their own)
    
    Signed-off-by: Jeff Garzik <jeff@garzik.org>

 include/asm-generic/iomap.h |    1 +
 lib/iomap.c                 |   34 ++++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)

6e09c71822f76c618353682bf295fc7588284521
diff --git a/include/asm-generic/iomap.h b/include/asm-generic/iomap.h
index cde592f..611e6cf 100644
--- a/include/asm-generic/iomap.h
+++ b/include/asm-generic/iomap.h
@@ -63,6 +63,7 @@ extern void ioport_unmap(void __iomem *);
 /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
 struct pci_dev;
 extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
+extern void __iomem *pci_ioremap(struct pci_dev *dev, int bar, unsigned long max);
 extern void pci_iounmap(struct pci_dev *dev, void __iomem *);
 
 #endif
diff --git a/lib/iomap.c b/lib/iomap.c
index 864f2ec..0338da0 100644
--- a/lib/iomap.c
+++ b/lib/iomap.c
@@ -275,9 +275,43 @@ void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
 	return NULL;
 }
 
+/**
+ * pci_ioremap - create a virtual mapping cookie for a memory-based PCI BAR
+ * @dev: PCI device that owns the BAR
+ * @bar: BAR number
+ * @maxlen: length of MMIO memory to map
+ *
+ * Using this function you will get a __iomem address to your device BAR.
+ * You can access it using read*() and write*().
+ *
+ * @maxlen specifies the maximum length to map. If you want to get access to
+ * the complete BAR without checking for its length first, pass %0 here.
+ * */
+void __iomem *pci_ioremap(struct pci_dev *dev, int bar, unsigned long maxlen)
+{
+	unsigned long start = pci_resource_start(dev, bar);
+	unsigned long len = pci_resource_len(dev, bar);
+	unsigned long flags = pci_resource_flags(dev, bar);
+
+	if (!len || !start)
+		return NULL;
+	if (maxlen && len > maxlen)
+		len = maxlen;
+	if (flags & IORESOURCE_IO)
+		return NULL;
+	if (flags & IORESOURCE_MEM) {
+		if (flags & IORESOURCE_CACHEABLE)
+			return ioremap(start, len);
+		return ioremap_nocache(start, len);
+	}
+	/* What? */
+	return NULL;
+}
+
 void pci_iounmap(struct pci_dev *dev, void __iomem * addr)
 {
 	IO_COND(addr, /* nothing */, iounmap(addr));
 }
 EXPORT_SYMBOL(pci_iomap);
+EXPORT_SYMBOL(pci_ioremap);
 EXPORT_SYMBOL(pci_iounmap);

  reply	other threads:[~2007-09-18 23:08 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-17 20:22 [PATCH] Clarify pci_iomap() usage for MMIO-only devices Luis R. Rodriguez
2007-09-18 10:34 ` Alan Cox
2007-09-18 18:46   ` Luis R. Rodriguez
2007-09-18 19:03     ` Linus Torvalds
2007-09-18 19:07       ` Luis R. Rodriguez
2007-09-18 19:22         ` Linus Torvalds
2007-09-18 20:12           ` Luis R. Rodriguez
2007-09-18 20:30             ` Linus Torvalds
2007-09-18 21:02               ` Luis R. Rodriguez
2007-09-18 21:14                 ` Linus Torvalds
2007-09-18 21:30                   ` Jeff Garzik
2007-09-18 21:42                     ` Linus Torvalds
2007-09-18 22:25                       ` Linus Torvalds
2007-09-18 22:21               ` Benjamin Herrenschmidt
2007-09-18 22:36                 ` Linus Torvalds
2007-09-18 20:21           ` Jeff Garzik
2007-09-18 22:20             ` Benjamin Herrenschmidt
2007-09-18 23:08               ` Jeff Garzik [this message]
2007-09-18 23:27                 ` Linus Torvalds
2007-09-18 22:16       ` Benjamin Herrenschmidt
2007-09-18 22:25       ` Alan Cox
2007-09-19 15:07         ` Nick Kossifidis

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=46F05A74.2000005@garzik.org \
    --to=jeff@garzik.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=benh@kernel.crashing.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linville@tuxdriver.com \
    --cc=mcgrof@gmail.com \
    --cc=torvalds@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox