blob: eeb2aa36949ab1d88de662dcc072ade8dffec5bb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _ASM_IA64_DMA_MAPPING_H
2#define _ASM_IA64_DMA_MAPPING_H
3
4/*
5 * Copyright (C) 2003-2004 Hewlett-Packard Co
6 * David Mosberger-Tang <davidm@hpl.hp.com>
7 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <asm/machvec.h>
Jens Axboe9b6eccf2007-10-16 11:27:26 +02009#include <linux/scatterlist.h>
Fenghua Yu62fdd762008-10-17 12:14:13 -070010#include <asm/swiotlb.h>
11
12struct dma_mapping_ops {
13 int (*mapping_error)(struct device *dev,
14 dma_addr_t dma_addr);
15 void* (*alloc_coherent)(struct device *dev, size_t size,
16 dma_addr_t *dma_handle, gfp_t gfp);
17 void (*free_coherent)(struct device *dev, size_t size,
18 void *vaddr, dma_addr_t dma_handle);
19 dma_addr_t (*map_single)(struct device *hwdev, unsigned long ptr,
20 size_t size, int direction);
21 void (*unmap_single)(struct device *dev, dma_addr_t addr,
22 size_t size, int direction);
FUJITA Tomonorie751ab32009-01-05 23:36:06 +090023 dma_addr_t (*map_single_attrs)(struct device *dev, void *cpu_addr,
24 size_t size, int direction,
25 struct dma_attrs *attrs);
26 void (*unmap_single_attrs)(struct device *dev,
27 dma_addr_t dma_addr,
28 size_t size, int direction,
29 struct dma_attrs *attrs);
Fenghua Yu62fdd762008-10-17 12:14:13 -070030 void (*sync_single_for_cpu)(struct device *hwdev,
31 dma_addr_t dma_handle, size_t size,
32 int direction);
33 void (*sync_single_for_device)(struct device *hwdev,
34 dma_addr_t dma_handle, size_t size,
35 int direction);
36 void (*sync_single_range_for_cpu)(struct device *hwdev,
37 dma_addr_t dma_handle, unsigned long offset,
38 size_t size, int direction);
39 void (*sync_single_range_for_device)(struct device *hwdev,
40 dma_addr_t dma_handle, unsigned long offset,
41 size_t size, int direction);
42 void (*sync_sg_for_cpu)(struct device *hwdev,
43 struct scatterlist *sg, int nelems,
44 int direction);
45 void (*sync_sg_for_device)(struct device *hwdev,
46 struct scatterlist *sg, int nelems,
47 int direction);
48 int (*map_sg)(struct device *hwdev, struct scatterlist *sg,
49 int nents, int direction);
50 void (*unmap_sg)(struct device *hwdev,
51 struct scatterlist *sg, int nents,
52 int direction);
FUJITA Tomonorie751ab32009-01-05 23:36:06 +090053 int (*map_sg_attrs)(struct device *dev,
54 struct scatterlist *sg, int nents,
55 int direction, struct dma_attrs *attrs);
56 void (*unmap_sg_attrs)(struct device *dev,
57 struct scatterlist *sg, int nents,
58 int direction,
59 struct dma_attrs *attrs);
Fenghua Yu62fdd762008-10-17 12:14:13 -070060 int (*dma_supported_op)(struct device *hwdev, u64 mask);
61 int is_phys;
62};
63
64extern struct dma_mapping_ops *dma_ops;
65extern struct ia64_machine_vector ia64_mv;
66extern void set_iommu_machvec(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
FUJITA Tomonori3a80b6a2008-09-08 18:10:10 +090068#define dma_alloc_coherent(dev, size, handle, gfp) \
69 platform_dma_alloc_coherent(dev, size, handle, (gfp) | GFP_DMA)
70
Roland Dreierb7de8e72007-02-14 00:32:53 -080071/* coherent mem. is cheap */
72static inline void *
73dma_alloc_noncoherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
74 gfp_t flag)
75{
76 return dma_alloc_coherent(dev, size, dma_handle, flag);
77}
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#define dma_free_coherent platform_dma_free_coherent
Roland Dreierb7de8e72007-02-14 00:32:53 -080079static inline void
80dma_free_noncoherent(struct device *dev, size_t size, void *cpu_addr,
81 dma_addr_t dma_handle)
82{
83 dma_free_coherent(dev, size, cpu_addr, dma_handle);
84}
Arthur Kepner309df0c2008-04-29 01:00:32 -070085#define dma_map_single_attrs platform_dma_map_single_attrs
86static inline dma_addr_t dma_map_single(struct device *dev, void *cpu_addr,
87 size_t size, int dir)
88{
89 return dma_map_single_attrs(dev, cpu_addr, size, dir, NULL);
90}
91#define dma_map_sg_attrs platform_dma_map_sg_attrs
92static inline int dma_map_sg(struct device *dev, struct scatterlist *sgl,
93 int nents, int dir)
94{
95 return dma_map_sg_attrs(dev, sgl, nents, dir, NULL);
96}
97#define dma_unmap_single_attrs platform_dma_unmap_single_attrs
98static inline void dma_unmap_single(struct device *dev, dma_addr_t cpu_addr,
99 size_t size, int dir)
100{
101 return dma_unmap_single_attrs(dev, cpu_addr, size, dir, NULL);
102}
103#define dma_unmap_sg_attrs platform_dma_unmap_sg_attrs
104static inline void dma_unmap_sg(struct device *dev, struct scatterlist *sgl,
105 int nents, int dir)
106{
107 return dma_unmap_sg_attrs(dev, sgl, nents, dir, NULL);
108}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109#define dma_sync_single_for_cpu platform_dma_sync_single_for_cpu
110#define dma_sync_sg_for_cpu platform_dma_sync_sg_for_cpu
111#define dma_sync_single_for_device platform_dma_sync_single_for_device
112#define dma_sync_sg_for_device platform_dma_sync_sg_for_device
113#define dma_mapping_error platform_dma_mapping_error
114
115#define dma_map_page(dev, pg, off, size, dir) \
116 dma_map_single(dev, page_address(pg) + (off), (size), (dir))
117#define dma_unmap_page(dev, dma_addr, size, dir) \
118 dma_unmap_single(dev, dma_addr, size, dir)
119
120/*
121 * Rest of this file is part of the "Advanced DMA API". Use at your own risk.
122 * See Documentation/DMA-API.txt for details.
123 */
124
125#define dma_sync_single_range_for_cpu(dev, dma_handle, offset, size, dir) \
126 dma_sync_single_for_cpu(dev, dma_handle, size, dir)
127#define dma_sync_single_range_for_device(dev, dma_handle, offset, size, dir) \
128 dma_sync_single_for_device(dev, dma_handle, size, dir)
129
130#define dma_supported platform_dma_supported
131
132static inline int
133dma_set_mask (struct device *dev, u64 mask)
134{
135 if (!dev->dma_mask || !dma_supported(dev, mask))
136 return -EIO;
137 *dev->dma_mask = mask;
138 return 0;
139}
140
John W. Linvillee1531b42005-11-07 00:57:54 -0800141extern int dma_get_cache_alignment(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143static inline void
Ralf Baechled3fa72e2006-12-06 20:38:56 -0800144dma_cache_sync (struct device *dev, void *vaddr, size_t size,
145 enum dma_data_direction dir)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146{
147 /*
148 * IA-64 is cache-coherent, so this is mostly a no-op. However, we do need to
149 * ensure that dma_cache_sync() enforces order, hence the mb().
150 */
151 mb();
152}
153
Ralf Baechlef67637e2006-12-06 20:38:54 -0800154#define dma_is_consistent(d, h) (1) /* all we do is coherent memory... */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Fenghua Yu62fdd762008-10-17 12:14:13 -0700156static inline struct dma_mapping_ops *get_dma_ops(struct device *dev)
157{
158 return dma_ops;
159}
160
161
162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163#endif /* _ASM_IA64_DMA_MAPPING_H */