Skip to contentSkip to conversation

PIO drivers and cache coherency

RFC PATCH New Catalin Marinas 1 participant 6 messages Feb 11, 2010

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

v2 cover PIO drivers and cache coherency

Hi,

These set of patches is the 2nd attempt at an API for PIO drivers. Following James' suggestion on a kmap-like API, the pio_* functions no longer look like the dma_map_* API.

There are situations where the page structure isn't available (the USB HCD drivers) and I introduced the pio_begin()/pio_end() functions that take care of the cache flushing.

I added another example for the mmci.c driver that is currently using flush_dcache_page().

Thanks.

Catalin Marinas (5):
pio-mapping: Add generic support for PIO mapping API
pio-mapping: Add ARM support for the PIO mapping API
pio-mapping: Use the PIO mapping API in libata-sff.c
pio-mapping: Use the PIO mapping API in the ISP1760 HCD driver
pio-mapping: Use the PIO mapping API in the MMCI PL18x driver

 arch/arm/Kconfig                   |    3 ++
 arch/arm/include/asm/pio-mapping.h |   66 ++++++++++++++++++++++++++++++++++++
 drivers/ata/libata-sff.c           |    7 +++-
 drivers/mmc/host/mmci.c            |   17 ++++-----
 drivers/mmc/host/mmci.h            |   13 +++++--
 drivers/usb/host/isp1760-hcd.c     |    7 ++++
 include/linux/pio-mapping.h        |   65 +++++++++++++++++++++++++++++++++++
 7 files changed, 164 insertions(+), 14 deletions(-)
 create mode 100644 arch/arm/include/asm/pio-mapping.h
 create mode 100644 include/linux/pio-mapping.h
Signature · 1 line
Catalin
#1 lore raw

RFC PATCH v2 1/5 pio-mapping: Add generic support for PIO mapping API

Implement partial support for PIO mapping API similar to the kmap API used for highmem. These functions are intended to be used by device drivers doing PIO to page cache pages that may potentially be mapped in user space and cause cache coherency issues.

Cc James Bottomley <[email protected]>
Cc Russell King <[email protected]>
---
 include/linux/pio-mapping.h |   65 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 65 insertions(+), 0 deletions(-)
 create mode 100644 include/linux/pio-mapping.h
include/linux/pio-mapping.h new file +65 -0
new file mode 100644
index 0000000..5b216fb
@@ -0,0 +1,65 @@
+/*
+ * include/linux/pio-mapping.h
+ *
+ * Copyright (C) 2010 ARM Ltd.
+ * Written by Catalin Marinas <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef PIO_MAPPING_H
+#define PIO_MAPPING_H
+
+#include <linux/highmem.h>
+#include <linux/dma-mapping.h>
+
+#ifdef CONFIG_HAVE_ARCH_PIO
+#include <asm/pio-mapping.h>
+#else
+
+static inline void *pio_kmap(struct page *page, enum dma_data_direction dir)
+{
+	return kmap(page);
+}
+
+static inline void pio_kunmap(struct page *page, enum dma_data_direction dir)
+{
+	kunmap(page);
+}
+
+static inline void *pio_kmap_atomic(struct page *page, enum km_type idx,
+				    enum dma_data_direction dir)
+{
+	return kmap_atomic(page, idx);
+}
+
+static inline void pio_kunmap_atomic(void *addr, enum km_type idx,
+				     enum dma_data_direction dir)
+{
+	kunmap_atomic(addr, idx);
+}
+
+static inline void pio_begin(void *addr, size_t size,
+			     enum dma_data_direction dir)
+{
+}
+
+static inline void pio_end(void *addr, size_t size,
+			   enum dma_data_direction dir)
+{
+}
+
+#endif	/* CONFIG_HAVE_ARCH_PIO */
+
+#endif	/* PIO_MAPPING_H */
#2 lore raw

RFC PATCH v2 2/5 pio-mapping: Add ARM support for the PIO mapping API

In reply to Catalin Marinas

This patch introduces support for the PIO mapping API on the ARM architecture. It is currently only meant as an example for discussions and it can be further optimised.

Cc James Bottomley <[email protected]>
Cc Russell King <[email protected]>
---
 arch/arm/Kconfig                   |    3 ++
 arch/arm/include/asm/pio-mapping.h |   66 ++++++++++++++++++++++++++++++++++++
 2 files changed, 69 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/include/asm/pio-mapping.h
arch/arm/Kconfig +3 -0
index 4c33ca8..e48adcf 100644
@@ -161,6 +161,9 @@ config ARCH_MTD_XIP
 config GENERIC_HARDIRQS_NO__DO_IRQ
 	def_bool y
 
+config HAVE_ARCH_PIO
+	def_bool y
+
 if OPROFILE
 
 config OPROFILE_ARMV6
arch/arm/include/asm/pio-mapping.h new file +66 -0

66 lines not on this page · raw message

#3 lore raw

RFC PATCH v2 3/5 pio-mapping: Use the PIO mapping API in libata-sff.c

In reply to Catalin Marinas

This patch shows an example of PIO API usage for non-highmem pages. It currently only modifies the !highmem case. While it is indicated to no longer differentiate between these, there is a benefit for the !highmem case to use the non-atomic kmap API.

Cc James Bottomley <[email protected]>
Cc Russell King <[email protected]>
---
 drivers/ata/libata-sff.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
drivers/ata/libata-sff.c +6 -1
index 741065c..02a3be9 100644
@@ -36,6 +36,7 @@
 #include <linux/pci.h>
 #include <linux/libata.h>
 #include <linux/highmem.h>
+#include <linux/pio-mapping.h>
 
 #include "libata.h"
 
@@ -888,9 +889,13 @@ static void ata_pio_sector(struct ata_queued_cmd *qc)
 		kunmap_atomic(buf, KM_IRQ0);
 		local_irq_restore(flags);
 	} else {
-		buf = page_address(page);
+		enum dma_data_direction dir = do_write ?
+			DMA_TO_DEVICE : DMA_FROM_DEVICE;
+
+		buf = pio_kmap(page, dir);
 		ap->ops->sff_data_xfer(qc->dev, buf + offset, qc->sect_size,
 				       do_write);
+		pio_kunmap(page, dir);
 	}
 
 	qc->curbytes += qc->sect_size;
#4 lore raw

RFC PATCH v2 4/5 pio-mapping: Use the PIO mapping API in the ISP1760 HCD driver

In reply to Catalin Marinas

This patch provides another example of PIO API usage. In this case, there is no struct page information in the HCD driver and the pio_begin()/pio_end() functions are used.

Cc James Bottomley <[email protected]>
Cc Russell King <[email protected]>
---
 drivers/usb/host/isp1760-hcd.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
drivers/usb/host/isp1760-hcd.c +7 -0
index 27b8f7c..402f676 100644
@@ -17,6 +17,7 @@
 #include <linux/debugfs.h>
 #include <linux/uaccess.h>
 #include <linux/io.h>
+#include <linux/pio-mapping.h>
 #include <asm/unaligned.h>
 
 #include "../core/hcd.h"
@@ -904,6 +905,9 @@ __acquires(priv->lock)
 			status = 0;
 	}
 
+	pio_end(urb->transfer_buffer, urb->transfer_buffer_length,
+		usb_pipein(urb->pipe) ? DMA_FROM_DEVICE : DMA_TO_DEVICE);
+
 	/* complete() can reenter this HCD */
 	usb_hcd_unlink_urb_from_ep(priv_to_hcd(priv), urb);
 	spin_unlock(&priv->lock);
@@ -1538,6 +1542,9 @@ static struct list_head *qh_urb_transaction(struct isp1760_hcd *priv,
 	 */
 	buf = urb->transfer_buffer;
 
+	pio_begin(buf, urb->transfer_buffer_length,
+		  usb_pipein(urb->pipe) ? DMA_FROM_DEVICE : DMA_TO_DEVICE);
+
 	if (is_input)
 		token |= IN_PID;
 	else
#5 lore raw

RFC PATCH v2 5/5 pio-mapping: Use the PIO mapping API in the MMCI PL18x driver

In reply to Catalin Marinas

This driver currently uses kmap + flush_dcache_page. This patch changes the code to the pio_kmap/pio_kunmap without the additional flush_dcache_page call.

Cc James Bottomley <[email protected]>
Cc Russell King <[email protected]>
---
 drivers/mmc/host/mmci.c |   17 ++++++++---------
 drivers/mmc/host/mmci.h |   13 +++++++++----
 2 files changed, 17 insertions(+), 13 deletions(-)
drivers/mmc/host/mmci.c +8 -9
index 90d168a..a72aa80 100644
@@ -313,6 +313,7 @@ static irqreturn_t mmci_pio_irq(int irq, void *dev_id)
 		unsigned long flags;
 		unsigned int remain, len;
 		char *buffer;
+		enum dma_data_direction dir = DMA_NONE;
 
 		/*
 		 * For write, we only need to test the half-empty flag
@@ -324,10 +325,15 @@ static irqreturn_t mmci_pio_irq(int irq, void *dev_id)
 		if (!(status & (MCI_TXFIFOHALFEMPTY|MCI_RXDATAAVLBL)))
 			break;
 
+		if (status & MCI_RXACTIVE)
+			dir = DMA_FROM_DEVICE;
+		if (status & MCI_TXACTIVE)
+			dir = DMA_TO_DEVICE;
+
 		/*
 		 * Map the current scatter buffer.
 		 */
-		buffer = mmci_kmap_atomic(host, &flags) + host->sg_off;
+		buffer = mmci_kmap_atomic(host, &flags, dir) + host->sg_off;
 		remain = host->sg_ptr->length - host->sg_off;
 
 		len = 0;
@@ -339,7 +345,7 @@ static irqreturn_t mmci_pio_irq(int irq, void *dev_id)
 		/*
 		 * Unmap the buffer.
 		 */
-		mmci_kunmap_atomic(host, buffer, &flags);
+		mmci_kunmap_atomic(host, buffer, &flags, dir);
 
 		host->sg_off += len;
 		host->size -= len;
@@ -348,13 +354,6 @@ static irqreturn_t mmci_pio_irq(int irq, void *dev_id)
 		if (remain)
 			break;
 
-		/*
-		 * If we were reading, and we have completed this
-		 * page, ensure that the data cache is coherent.
-		 */
-		if (status & MCI_RXACTIVE)
-			flush_dcache_page(sg_page(host->sg_ptr));
-
 		if (!mmci_next_sg(host))
 			break;
 
drivers/mmc/host/mmci.h +9 -4
index 1ceb9a9..0f19e18 100644
@@ -7,6 +7,9 @@
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  */
+
+#include <linux/pio-mapping.h>
+
 #define MMCIPOWER		0x000
 #define MCI_PWR_OFF		0x00
 #define MCI_PWR_UP		0x02
@@ -195,16 +198,18 @@ static inline int mmci_next_sg(struct mmci_host *host)
 	return --host->sg_len;
 }
 
-static inline char *mmci_kmap_atomic(struct mmci_host *host, unsigned long *flags)
+static inline char *mmci_kmap_atomic(struct mmci_host *host, unsigned long *flags,
+				     enum dma_data_direction dir)
 {
 	struct scatterlist *sg = host->sg_ptr;
 
 	local_irq_save(*flags);
-	return kmap_atomic(sg_page(sg), KM_BIO_SRC_IRQ) + sg->offset;
+	return pio_kmap_atomic(sg_page(sg), KM_BIO_SRC_IRQ, dir) + sg->offset;
 }
 
-static inline void mmci_kunmap_atomic(struct mmci_host *host, void *buffer, unsigned long *flags)
+static inline void mmci_kunmap_atomic(struct mmci_host *host, void *buffer, unsigned long *flags,
+				      enum dma_data_direction dir)
 {
-	kunmap_atomic(buffer, KM_BIO_SRC_IRQ);
+	pio_kunmap_atomic(buffer, KM_BIO_SRC_IRQ, dir);
 	local_irq_restore(*flags);
 }