blob: 88bd0d899bdbedfac95bfc99450f9f6fbcc00ca0 [file] [log] [blame]
Aurelien Jacquiot14aa7e82011-10-04 12:17:19 -04001/*
2 * Port on Texas Instruments TMS320C6x architecture
3 *
4 * Copyright (C) 2004, 2009, 2010, 2011 Texas Instruments Incorporated
5 * Author: Aurelien Jacquiot <aurelien.jacquiot@ti.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 */
12#ifndef _ASM_C6X_DMA_MAPPING_H
13#define _ASM_C6X_DMA_MAPPING_H
14
15#include <linux/dma-debug.h>
16#include <asm-generic/dma-coherent.h>
17
18#define dma_supported(d, m) 1
19
20static inline int dma_set_mask(struct device *dev, u64 dma_mask)
21{
22 if (!dev->dma_mask || !dma_supported(dev, dma_mask))
23 return -EIO;
24
25 *dev->dma_mask = dma_mask;
26
27 return 0;
28}
29
30/*
31 * DMA errors are defined by all-bits-set in the DMA address.
32 */
33static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
34{
Shuah Khanad154882012-11-23 14:32:06 -070035 debug_dma_mapping_error(dev, dma_addr);
Aurelien Jacquiot14aa7e82011-10-04 12:17:19 -040036 return dma_addr == ~0;
37}
38
39extern dma_addr_t dma_map_single(struct device *dev, void *cpu_addr,
40 size_t size, enum dma_data_direction dir);
41
42extern void dma_unmap_single(struct device *dev, dma_addr_t handle,
43 size_t size, enum dma_data_direction dir);
44
45extern int dma_map_sg(struct device *dev, struct scatterlist *sglist,
46 int nents, enum dma_data_direction direction);
47
48extern void dma_unmap_sg(struct device *dev, struct scatterlist *sglist,
49 int nents, enum dma_data_direction direction);
50
51static inline dma_addr_t dma_map_page(struct device *dev, struct page *page,
52 unsigned long offset, size_t size,
53 enum dma_data_direction dir)
54{
55 dma_addr_t handle;
56
57 handle = dma_map_single(dev, page_address(page) + offset, size, dir);
58
59 debug_dma_map_page(dev, page, offset, size, dir, handle, false);
60
61 return handle;
62}
63
64static inline void dma_unmap_page(struct device *dev, dma_addr_t handle,
65 size_t size, enum dma_data_direction dir)
66{
67 dma_unmap_single(dev, handle, size, dir);
68
69 debug_dma_unmap_page(dev, handle, size, dir, false);
70}
71
72extern void dma_sync_single_for_cpu(struct device *dev, dma_addr_t handle,
73 size_t size, enum dma_data_direction dir);
74
75extern void dma_sync_single_for_device(struct device *dev, dma_addr_t handle,
76 size_t size,
77 enum dma_data_direction dir);
78
79extern void dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
80 int nents, enum dma_data_direction dir);
81
82extern void dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
83 int nents, enum dma_data_direction dir);
84
85extern void coherent_mem_init(u32 start, u32 size);
86extern void *dma_alloc_coherent(struct device *, size_t, dma_addr_t *, gfp_t);
87extern void dma_free_coherent(struct device *, size_t, void *, dma_addr_t);
88
89#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent((d), (s), (h), (f))
90#define dma_free_noncoherent(d, s, v, h) dma_free_coherent((d), (s), (v), (h))
91
Geert Uytterhoeven18180652013-01-27 09:33:22 +000092/* Not supported for now */
93static inline int dma_mmap_coherent(struct device *dev,
94 struct vm_area_struct *vma, void *cpu_addr,
95 dma_addr_t dma_addr, size_t size)
96{
97 return -EINVAL;
98}
99
100static inline int dma_get_sgtable(struct device *dev, struct sg_table *sgt,
101 void *cpu_addr, dma_addr_t dma_addr,
102 size_t size)
103{
104 return -EINVAL;
105}
106
Aurelien Jacquiot14aa7e82011-10-04 12:17:19 -0400107#endif /* _ASM_C6X_DMA_MAPPING_H */