1 /* include this file if the platform implements the dma_ DMA Mapping API
2 * and wants to provide the pci_ DMA Mapping API in terms of it */
3
4 #ifndef _ASM_GENERIC_PCI_DMA_COMPAT_H
5 #define _ASM_GENERIC_PCI_DMA_COMPAT_H
6
7 #include <linux/dma-mapping.h>
8
9 static inline int
pci_dma_supported(struct pci_dev * hwdev,u64 mask)10 pci_dma_supported(struct pci_dev *hwdev, u64 mask)
11 {
12 return dma_supported(hwdev == NULL ? NULL : &hwdev->dev, mask);
13 }
14
15 static inline void *
pci_alloc_consistent(struct pci_dev * hwdev,size_t size,dma_addr_t * dma_handle)16 pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
17 dma_addr_t *dma_handle)
18 {
19 return dma_alloc_coherent(hwdev == NULL ? NULL : &hwdev->dev, size, dma_handle, GFP_ATOMIC);
20 }
21
22 static inline void
pci_free_consistent(struct pci_dev * hwdev,size_t size,void * vaddr,dma_addr_t dma_handle)23 pci_free_consistent(struct pci_dev *hwdev, size_t size,
24 void *vaddr, dma_addr_t dma_handle)
25 {
26 dma_free_coherent(hwdev == NULL ? NULL : &hwdev->dev, size, vaddr, dma_handle);
27 }
28
29 static inline dma_addr_t
pci_map_single(struct pci_dev * hwdev,void * ptr,size_t size,int direction)30 pci_map_single(struct pci_dev *hwdev, void *ptr, size_t size, int direction)
31 {
32 return dma_map_single(hwdev == NULL ? NULL : &hwdev->dev, ptr, size, (enum dma_data_direction)direction);
33 }
34
35 static inline void
pci_unmap_single(struct pci_dev * hwdev,dma_addr_t dma_addr,size_t size,int direction)36 pci_unmap_single(struct pci_dev *hwdev, dma_addr_t dma_addr,
37 size_t size, int direction)
38 {
39 dma_unmap_single(hwdev == NULL ? NULL : &hwdev->dev, dma_addr, size, (enum dma_data_direction)direction);
40 }
41
42 static inline dma_addr_t
pci_map_page(struct pci_dev * hwdev,struct page * page,unsigned long offset,size_t size,int direction)43 pci_map_page(struct pci_dev *hwdev, struct page *page,
44 unsigned long offset, size_t size, int direction)
45 {
46 return dma_map_page(hwdev == NULL ? NULL : &hwdev->dev, page, offset, size, (enum dma_data_direction)direction);
47 }
48
49 static inline void
pci_unmap_page(struct pci_dev * hwdev,dma_addr_t dma_address,size_t size,int direction)50 pci_unmap_page(struct pci_dev *hwdev, dma_addr_t dma_address,
51 size_t size, int direction)
52 {
53 dma_unmap_page(hwdev == NULL ? NULL : &hwdev->dev, dma_address, size, (enum dma_data_direction)direction);
54 }
55
56 static inline int
pci_map_sg(struct pci_dev * hwdev,struct scatterlist * sg,int nents,int direction)57 pci_map_sg(struct pci_dev *hwdev, struct scatterlist *sg,
58 int nents, int direction)
59 {
60 return dma_map_sg(hwdev == NULL ? NULL : &hwdev->dev, sg, nents, (enum dma_data_direction)direction);
61 }
62
63 static inline void
pci_unmap_sg(struct pci_dev * hwdev,struct scatterlist * sg,int nents,int direction)64 pci_unmap_sg(struct pci_dev *hwdev, struct scatterlist *sg,
65 int nents, int direction)
66 {
67 dma_unmap_sg(hwdev == NULL ? NULL : &hwdev->dev, sg, nents, (enum dma_data_direction)direction);
68 }
69
70 static inline void
pci_dma_sync_single_for_cpu(struct pci_dev * hwdev,dma_addr_t dma_handle,size_t size,int direction)71 pci_dma_sync_single_for_cpu(struct pci_dev *hwdev, dma_addr_t dma_handle,
72 size_t size, int direction)
73 {
74 dma_sync_single_for_cpu(hwdev == NULL ? NULL : &hwdev->dev, dma_handle, size, (enum dma_data_direction)direction);
75 }
76
77 static inline void
pci_dma_sync_single_for_device(struct pci_dev * hwdev,dma_addr_t dma_handle,size_t size,int direction)78 pci_dma_sync_single_for_device(struct pci_dev *hwdev, dma_addr_t dma_handle,
79 size_t size, int direction)
80 {
81 dma_sync_single_for_device(hwdev == NULL ? NULL : &hwdev->dev, dma_handle, size, (enum dma_data_direction)direction);
82 }
83
84 static inline void
pci_dma_sync_sg_for_cpu(struct pci_dev * hwdev,struct scatterlist * sg,int nelems,int direction)85 pci_dma_sync_sg_for_cpu(struct pci_dev *hwdev, struct scatterlist *sg,
86 int nelems, int direction)
87 {
88 dma_sync_sg_for_cpu(hwdev == NULL ? NULL : &hwdev->dev, sg, nelems, (enum dma_data_direction)direction);
89 }
90
91 static inline void
pci_dma_sync_sg_for_device(struct pci_dev * hwdev,struct scatterlist * sg,int nelems,int direction)92 pci_dma_sync_sg_for_device(struct pci_dev *hwdev, struct scatterlist *sg,
93 int nelems, int direction)
94 {
95 dma_sync_sg_for_device(hwdev == NULL ? NULL : &hwdev->dev, sg, nelems, (enum dma_data_direction)direction);
96 }
97
98 static inline int
pci_dma_mapping_error(struct pci_dev * pdev,dma_addr_t dma_addr)99 pci_dma_mapping_error(struct pci_dev *pdev, dma_addr_t dma_addr)
100 {
101 return dma_mapping_error(&pdev->dev, dma_addr);
102 }
103
104 #ifdef CONFIG_PCI
pci_set_dma_mask(struct pci_dev * dev,u64 mask)105 static inline int pci_set_dma_mask(struct pci_dev *dev, u64 mask)
106 {
107 return dma_set_mask(&dev->dev, mask);
108 }
109
pci_set_consistent_dma_mask(struct pci_dev * dev,u64 mask)110 static inline int pci_set_consistent_dma_mask(struct pci_dev *dev, u64 mask)
111 {
112 return dma_set_coherent_mask(&dev->dev, mask);
113 }
114 #endif
115
116 #endif
117