public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jeff Garzik <jeff@garzik.org>
To: 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 16:21:01 -0400	[thread overview]
Message-ID: <46F0332D.3050704@garzik.org> (raw)
In-Reply-To: <alpine.LFD.0.999.0709181219020.16478@woody.linux-foundation.org>

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

Linus Torvalds wrote:
> Why do people insist on 
> using the old interfaces (and matching them with the new setup)?


readl/writel is [slightly] faster, and possibility of using even-write 
__raw_writel() exists, in the old interface...

  ...but pci_iomap() is a bus-friendly wrapper that handles a few checks 
and function calls for you, even if you know your device is always MMIO.

A new pci_mmio_map() helper, to be used with 100% MMIO hardware, might 
help eliminate confusion.

	Jeff



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

diff --git a/include/asm-generic/iomap.h b/include/asm-generic/iomap.h
index cde592f..69e5390 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_mmio_map(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..c87d7f3 100644
--- a/lib/iomap.c
+++ b/lib/iomap.c
@@ -275,9 +275,32 @@ void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
 	return NULL;
 }
 
+/* for people who wish to use readl/writel exclusively */
+void __iomem *pci_mmio_map(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_mmio_map);
 EXPORT_SYMBOL(pci_iounmap);

  parent reply	other threads:[~2007-09-18 20:21 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 [this message]
2007-09-18 22:20             ` Benjamin Herrenschmidt
2007-09-18 23:08               ` Jeff Garzik
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=46F0332D.3050704@garzik.org \
    --to=jeff@garzik.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --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