[PATCH -mm 01/11] add device_dma_parameters structure

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <akpm@...>
Cc: <linux-kernel@...>, <linux-scsi@...>, <James.Bottomley@...>, <jens.axboe@...>, <greg@...>, <jeff@...>, <fujita.tomonori@...>
Date: Wednesday, October 24, 2007 - 6:48 am

iommu code merges scatter/gather segments without considering a low
level driver's restrictions. The problem is that iommu code can't
access to the limitations because they are in request_queue.

This patch adds a new structure, device_dma_parameters, including dma
information. A pointer to device_dma_parameters is added to struct
device.

- there are only max_segment_size and segment_boundary_mask there but
we'll move more dma stuff in struct device (like dma_mask) to struct
device_dma_parameters later. segment_boundary_mask is not supported
yet.

- new accessors for the dma parameters are added. So we can easily
change where to place struct device_dma_parameters in the future.

- dma_get_max_seg_size returns 64K if dma_parms in struct device isn't
set up properly. 64K is the default max_segment_size in the block
layer.

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
---
 include/linux/device.h      |   11 +++++++++++
 include/linux/dma-mapping.h |   15 +++++++++++++++
 2 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/include/linux/device.h b/include/linux/device.h
index 2e15822..9eb883f 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -397,6 +397,15 @@ extern int devres_release_group(struct device *dev, void *id);
 extern void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp);
 extern void devm_kfree(struct device *dev, void *p);
 
+struct device_dma_parameters {
+	/*
+	 * a low level driver may set these to teach IOMMU code about
+	 * sg limitations.
+	 */
+	unsigned int max_segment_size;
+	unsigned long segment_boundary_mask;
+};
+
 struct device {
 	struct klist		klist_children;
 	struct klist_node	knode_parent;		/* node in sibling list */
@@ -432,6 +441,8 @@ struct device {
 					     64 bit addresses for consistent
 					     allocations such descriptors. */
 
+	struct device_dma_parameters *dma_parms;
+
 	struct list_head	dma_pools;	/* dma pools (if dma'ble) */
 
 	struct dma_coherent_mem	*dma_mem; /* internal for coherent mem
diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
index 101a2d4..71972ca 100644
--- a/include/linux/dma-mapping.h
+++ b/include/linux/dma-mapping.h
@@ -60,6 +60,21 @@ static inline int is_device_dma_capable(struct device *dev)
 
 extern u64 dma_get_required_mask(struct device *dev);
 
+static inline unsigned int dma_get_max_seg_size(struct device *dev)
+{
+	return dev->dma_parms ? dev->dma_parms->max_segment_size : 65536;
+}
+
+static inline unsigned int dma_set_max_seg_size(struct device *dev,
+						unsigned int size)
+{
+	if (dev->dma_parms) {
+		dev->dma_parms->max_segment_size = size;
+		return 0;
+	} else
+		return -EIO;
+}
+
 /* flags for the coherent memory api */
 #define	DMA_MEMORY_MAP			0x01
 #define DMA_MEMORY_IO			0x02
-- 
1.5.2.4

-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH -mm 0/11] fix iommu sg merging problem, FUJITA Tomonori, (Wed Oct 24, 6:47 am)
Re: [PATCH -mm 0/11] fix iommu sg merging problem, Jens Axboe, (Wed Oct 24, 9:24 am)
Re: [PATCH -mm 0/11] fix iommu sg merging problem, Jeff Garzik, (Wed Oct 24, 7:40 am)
Re: [PATCH -mm 0/11] fix iommu sg merging problem, FUJITA Tomonori, (Wed Oct 24, 10:32 am)
[PATCH -mm 01/11] add device_dma_parameters structure, FUJITA Tomonori, (Wed Oct 24, 6:48 am)
[PATCH -mm 02/11] PCI: add device_dma_parameters support, FUJITA Tomonori, (Wed Oct 24, 6:48 am)
Re: [PATCH -mm 02/11] PCI: add device_dma_parameters support, FUJITA Tomonori, (Wed Oct 24, 9:41 am)
[PATCH -mm 11/11] aacraid: use pci_set_dma_max_seg_size, FUJITA Tomonori, (Wed Oct 24, 6:48 am)
RE: [PATCH -mm 11/11] aacraid: use pci_set_dma_max_seg_size, FUJITA Tomonori, (Wed Oct 24, 12:21 pm)
Re: [PATCH -mm 11/11] aacraid: use pci_set_dma_max_seg_size, FUJITA Tomonori, (Wed Oct 24, 7:35 am)