PIO drivers and cache coherency
Subsystems (6)
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
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.
--- 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
@@ -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 */
RFC PATCH v2 2/5 pio-mapping: Add ARM support for the PIO mapping API
In reply to Catalin MarinasThis 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.
--- 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
@@ -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
RFC PATCH v2 3/5 pio-mapping: Use the PIO mapping API in libata-sff.c
In reply to Catalin MarinasThis 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.
--- drivers/ata/libata-sff.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
drivers/ata/libata-sff.c +6 -1
@@ -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;
RFC PATCH v2 4/5 pio-mapping: Use the PIO mapping API in the ISP1760 HCD driver
In reply to Catalin MarinasThis 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.
--- drivers/usb/host/isp1760-hcd.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
drivers/usb/host/isp1760-hcd.c +7 -0
@@ -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
RFC PATCH v2 5/5 pio-mapping: Use the PIO mapping API in the MMCI PL18x driver
In reply to Catalin MarinasThis 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.
--- 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
@@ -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
@@ -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); }