Generic Linux architectural discussions
 help / color / mirror / Atom feed
* [PATCH RFC 3/5] pci: add pci_iomap_range
       [not found] <1418326570-9541-1-git-send-email-mst@redhat.com>
@ 2014-12-11 19:37 ` Michael S. Tsirkin
  2014-12-11 19:37   ` Michael S. Tsirkin
  2014-12-11 22:27   ` Arnd Bergmann
  0 siblings, 2 replies; 6+ messages in thread
From: Michael S. Tsirkin @ 2014-12-11 19:37 UTC (permalink / raw)
  To: linux-kernel
  Cc: Rusty Russell, virtualization, cornelia.huck, Michael S Tsirkin,
	Arnd Bergmann, linux-arch

From: Michael S Tsirkin <mst@redhat.com>

Virtio drivers should map the part of the range they need, not necessarily
all of it. They also need non-cacheable mapping even for
prefetchable BARs.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
 include/asm-generic/pci_iomap.h |  5 +++++
 lib/pci_iomap.c                 | 46 +++++++++++++++++++++++++++++++++++------
 2 files changed, 45 insertions(+), 6 deletions(-)

diff --git a/include/asm-generic/pci_iomap.h b/include/asm-generic/pci_iomap.h
index ce37349..8777331 100644
--- a/include/asm-generic/pci_iomap.h
+++ b/include/asm-generic/pci_iomap.h
@@ -15,6 +15,11 @@ struct pci_dev;
 #ifdef CONFIG_PCI
 /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
 extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
+extern void __iomem *pci_iomap_range(struct pci_dev *dev, int bar,
+				     unsigned offset,
+				     unsigned long minlen,
+				     unsigned long maxlen,
+				     bool force_nocache);
 /* Create a virtual mapping cookie for a port on a given PCI device.
  * Do not call this directly, it exists to make it easier for architectures
  * to override */
diff --git a/lib/pci_iomap.c b/lib/pci_iomap.c
index 0d83ea8..1ac4def 100644
--- a/lib/pci_iomap.c
+++ b/lib/pci_iomap.c
@@ -10,33 +10,47 @@
 
 #ifdef CONFIG_PCI
 /**
- * pci_iomap - create a virtual mapping cookie for a PCI BAR
+ * pci_iomap_range - create a virtual mapping cookie for a PCI BAR
  * @dev: PCI device that owns the BAR
  * @bar: BAR number
- * @maxlen: length of the memory to map
+ * @offset: map memory at the given offset in BAR
+ * @minlen: min length of the memory to map
+ * @maxlen: max length of the memory to map
  *
  * Using this function you will get a __iomem address to your device BAR.
  * You can access it using ioread*() and iowrite*(). These functions hide
  * the details if this is a MMIO or PIO address space and will just do what
  * you expect from them in the correct way.
  *
+ * @minlen specifies the minimum length to map. We check that BAR is
+ * large enough.
  * @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.
+ * the complete BAR from offset to the end, pass %0 here.
+ * @force_nocache makes the mapping noncacheable even if the BAR
+ * is prefetcheable. It has no effect otherwise.
  * */
-void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
+void __iomem *pci_iomap_range(struct pci_dev *dev, int bar,
+			      unsigned offset,
+			      unsigned long minlen,
+			      unsigned long maxlen,
+			      bool force_nocache)
 {
 	resource_size_t start = pci_resource_start(dev, bar);
 	resource_size_t len = pci_resource_len(dev, bar);
 	unsigned long flags = pci_resource_flags(dev, bar);
 
-	if (!len || !start)
+	if (len <= offset || !start)
+		return NULL;
+	len -= offset;
+	start += offset;
+	if (len < minlen)
 		return NULL;
 	if (maxlen && len > maxlen)
 		len = maxlen;
 	if (flags & IORESOURCE_IO)
 		return __pci_ioport_map(dev, start, len);
 	if (flags & IORESOURCE_MEM) {
-		if (flags & IORESOURCE_CACHEABLE)
+		if (!force_nocache && (flags & IORESOURCE_CACHEABLE))
 			return ioremap(start, len);
 		return ioremap_nocache(start, len);
 	}
@@ -44,5 +58,25 @@ void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
 	return NULL;
 }
 
+/**
+ * pci_iomap - create a virtual mapping cookie for a PCI BAR
+ * @dev: PCI device that owns the BAR
+ * @bar: BAR number
+ * @maxlen: length of the memory to map
+ *
+ * Using this function you will get a __iomem address to your device BAR.
+ * You can access it using ioread*() and iowrite*(). These functions hide
+ * the details if this is a MMIO or PIO address space and will just do what
+ * you expect from them in the correct way.
+ *
+ * @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_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
+{
+	return pci_iomap_range(dev, bar, 0, 0, maxlen, false);
+}
+
 EXPORT_SYMBOL(pci_iomap);
+EXPORT_SYMBOL(pci_iomap_range);
 #endif /* CONFIG_PCI */
-- 
MST

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

* [PATCH RFC 3/5] pci: add pci_iomap_range
  2014-12-11 19:37 ` [PATCH RFC 3/5] pci: add pci_iomap_range Michael S. Tsirkin
@ 2014-12-11 19:37   ` Michael S. Tsirkin
  2014-12-11 22:27   ` Arnd Bergmann
  1 sibling, 0 replies; 6+ messages in thread
From: Michael S. Tsirkin @ 2014-12-11 19:37 UTC (permalink / raw)
  To: linux-kernel
  Cc: Rusty Russell, virtualization, cornelia.huck, Michael S Tsirkin,
	Arnd Bergmann, linux-arch

From: Michael S Tsirkin <mst@redhat.com>

Virtio drivers should map the part of the range they need, not necessarily
all of it. They also need non-cacheable mapping even for
prefetchable BARs.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
 include/asm-generic/pci_iomap.h |  5 +++++
 lib/pci_iomap.c                 | 46 +++++++++++++++++++++++++++++++++++------
 2 files changed, 45 insertions(+), 6 deletions(-)

diff --git a/include/asm-generic/pci_iomap.h b/include/asm-generic/pci_iomap.h
index ce37349..8777331 100644
--- a/include/asm-generic/pci_iomap.h
+++ b/include/asm-generic/pci_iomap.h
@@ -15,6 +15,11 @@ struct pci_dev;
 #ifdef CONFIG_PCI
 /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
 extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
+extern void __iomem *pci_iomap_range(struct pci_dev *dev, int bar,
+				     unsigned offset,
+				     unsigned long minlen,
+				     unsigned long maxlen,
+				     bool force_nocache);
 /* Create a virtual mapping cookie for a port on a given PCI device.
  * Do not call this directly, it exists to make it easier for architectures
  * to override */
diff --git a/lib/pci_iomap.c b/lib/pci_iomap.c
index 0d83ea8..1ac4def 100644
--- a/lib/pci_iomap.c
+++ b/lib/pci_iomap.c
@@ -10,33 +10,47 @@
 
 #ifdef CONFIG_PCI
 /**
- * pci_iomap - create a virtual mapping cookie for a PCI BAR
+ * pci_iomap_range - create a virtual mapping cookie for a PCI BAR
  * @dev: PCI device that owns the BAR
  * @bar: BAR number
- * @maxlen: length of the memory to map
+ * @offset: map memory at the given offset in BAR
+ * @minlen: min length of the memory to map
+ * @maxlen: max length of the memory to map
  *
  * Using this function you will get a __iomem address to your device BAR.
  * You can access it using ioread*() and iowrite*(). These functions hide
  * the details if this is a MMIO or PIO address space and will just do what
  * you expect from them in the correct way.
  *
+ * @minlen specifies the minimum length to map. We check that BAR is
+ * large enough.
  * @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.
+ * the complete BAR from offset to the end, pass %0 here.
+ * @force_nocache makes the mapping noncacheable even if the BAR
+ * is prefetcheable. It has no effect otherwise.
  * */
-void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
+void __iomem *pci_iomap_range(struct pci_dev *dev, int bar,
+			      unsigned offset,
+			      unsigned long minlen,
+			      unsigned long maxlen,
+			      bool force_nocache)
 {
 	resource_size_t start = pci_resource_start(dev, bar);
 	resource_size_t len = pci_resource_len(dev, bar);
 	unsigned long flags = pci_resource_flags(dev, bar);
 
-	if (!len || !start)
+	if (len <= offset || !start)
+		return NULL;
+	len -= offset;
+	start += offset;
+	if (len < minlen)
 		return NULL;
 	if (maxlen && len > maxlen)
 		len = maxlen;
 	if (flags & IORESOURCE_IO)
 		return __pci_ioport_map(dev, start, len);
 	if (flags & IORESOURCE_MEM) {
-		if (flags & IORESOURCE_CACHEABLE)
+		if (!force_nocache && (flags & IORESOURCE_CACHEABLE))
 			return ioremap(start, len);
 		return ioremap_nocache(start, len);
 	}
@@ -44,5 +58,25 @@ void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
 	return NULL;
 }
 
+/**
+ * pci_iomap - create a virtual mapping cookie for a PCI BAR
+ * @dev: PCI device that owns the BAR
+ * @bar: BAR number
+ * @maxlen: length of the memory to map
+ *
+ * Using this function you will get a __iomem address to your device BAR.
+ * You can access it using ioread*() and iowrite*(). These functions hide
+ * the details if this is a MMIO or PIO address space and will just do what
+ * you expect from them in the correct way.
+ *
+ * @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_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
+{
+	return pci_iomap_range(dev, bar, 0, 0, maxlen, false);
+}
+
 EXPORT_SYMBOL(pci_iomap);
+EXPORT_SYMBOL(pci_iomap_range);
 #endif /* CONFIG_PCI */
-- 
MST


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

* Re: [PATCH RFC 3/5] pci: add pci_iomap_range
  2014-12-11 19:37 ` [PATCH RFC 3/5] pci: add pci_iomap_range Michael S. Tsirkin
  2014-12-11 19:37   ` Michael S. Tsirkin
@ 2014-12-11 22:27   ` Arnd Bergmann
  2014-12-11 22:27     ` Arnd Bergmann
  2014-12-11 23:49     ` Michael S. Tsirkin
  1 sibling, 2 replies; 6+ messages in thread
From: Arnd Bergmann @ 2014-12-11 22:27 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: linux-arch, linux-kernel, virtualization

On Thursday 11 December 2014 21:37:34 Michael S. Tsirkin wrote:
>         if (flags & IORESOURCE_MEM) {
> -               if (flags & IORESOURCE_CACHEABLE)
> +               if (!force_nocache && (flags & IORESOURCE_CACHEABLE))
>                         return ioremap(start, len);
>                 return ioremap_nocache(start, len);
>         }
> 

ioremap is the same as ioremap_nocache, so this doesn't really make any
sense. IORESOURCE_CACHEABLE is practically only set for ROM bars, which
we rarely map.

	Arnd

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

* Re: [PATCH RFC 3/5] pci: add pci_iomap_range
  2014-12-11 22:27   ` Arnd Bergmann
@ 2014-12-11 22:27     ` Arnd Bergmann
  2014-12-11 23:49     ` Michael S. Tsirkin
  1 sibling, 0 replies; 6+ messages in thread
From: Arnd Bergmann @ 2014-12-11 22:27 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: linux-kernel, Rusty Russell, virtualization, cornelia.huck,
	linux-arch

On Thursday 11 December 2014 21:37:34 Michael S. Tsirkin wrote:
>         if (flags & IORESOURCE_MEM) {
> -               if (flags & IORESOURCE_CACHEABLE)
> +               if (!force_nocache && (flags & IORESOURCE_CACHEABLE))
>                         return ioremap(start, len);
>                 return ioremap_nocache(start, len);
>         }
> 

ioremap is the same as ioremap_nocache, so this doesn't really make any
sense. IORESOURCE_CACHEABLE is practically only set for ROM bars, which
we rarely map.

	Arnd

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

* Re: [PATCH RFC 3/5] pci: add pci_iomap_range
  2014-12-11 22:27   ` Arnd Bergmann
  2014-12-11 22:27     ` Arnd Bergmann
@ 2014-12-11 23:49     ` Michael S. Tsirkin
  2014-12-11 23:49       ` Michael S. Tsirkin
  1 sibling, 1 reply; 6+ messages in thread
From: Michael S. Tsirkin @ 2014-12-11 23:49 UTC (permalink / raw)
  To: Arnd Bergmann; +Cc: linux-arch, linux-kernel, virtualization

On Thu, Dec 11, 2014 at 11:27:54PM +0100, Arnd Bergmann wrote:
> On Thursday 11 December 2014 21:37:34 Michael S. Tsirkin wrote:
> >         if (flags & IORESOURCE_MEM) {
> > -               if (flags & IORESOURCE_CACHEABLE)
> > +               if (!force_nocache && (flags & IORESOURCE_CACHEABLE))
> >                         return ioremap(start, len);
> >                 return ioremap_nocache(start, len);
> >         }
> > 
> 
> ioremap is the same as ioremap_nocache, so this doesn't really make any
> sense. IORESOURCE_CACHEABLE is practically only set for ROM bars, which
> we rarely map.
> 
> 	Arnd

Hmm I think you are right.
It's an old patch - I think at one point in time we did set it when we
now set IORESOURCE_PREFETCH.
I'll drop this parameter.

-- 
MST

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

* Re: [PATCH RFC 3/5] pci: add pci_iomap_range
  2014-12-11 23:49     ` Michael S. Tsirkin
@ 2014-12-11 23:49       ` Michael S. Tsirkin
  0 siblings, 0 replies; 6+ messages in thread
From: Michael S. Tsirkin @ 2014-12-11 23:49 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: linux-kernel, Rusty Russell, virtualization, cornelia.huck,
	linux-arch

On Thu, Dec 11, 2014 at 11:27:54PM +0100, Arnd Bergmann wrote:
> On Thursday 11 December 2014 21:37:34 Michael S. Tsirkin wrote:
> >         if (flags & IORESOURCE_MEM) {
> > -               if (flags & IORESOURCE_CACHEABLE)
> > +               if (!force_nocache && (flags & IORESOURCE_CACHEABLE))
> >                         return ioremap(start, len);
> >                 return ioremap_nocache(start, len);
> >         }
> > 
> 
> ioremap is the same as ioremap_nocache, so this doesn't really make any
> sense. IORESOURCE_CACHEABLE is practically only set for ROM bars, which
> we rarely map.
> 
> 	Arnd

Hmm I think you are right.
It's an old patch - I think at one point in time we did set it when we
now set IORESOURCE_PREFETCH.
I'll drop this parameter.

-- 
MST

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

end of thread, other threads:[~2014-12-11 23:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1418326570-9541-1-git-send-email-mst@redhat.com>
2014-12-11 19:37 ` [PATCH RFC 3/5] pci: add pci_iomap_range Michael S. Tsirkin
2014-12-11 19:37   ` Michael S. Tsirkin
2014-12-11 22:27   ` Arnd Bergmann
2014-12-11 22:27     ` Arnd Bergmann
2014-12-11 23:49     ` Michael S. Tsirkin
2014-12-11 23:49       ` Michael S. Tsirkin

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