blob: c110843fc53b3f80174496148df8798c866db1b5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* 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
Linus Torvalds1da177e2005-04-16 15:20:36 -07009static inline int
10pci_dma_supported(struct pci_dev *hwdev, u64 mask)
11{
12 return dma_supported(hwdev == NULL ? NULL : &hwdev->dev, mask);
13}
14
15static inline void *
16pci_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
Joe Perches82bf0ba2014-08-08 14:24:08 -070022static inline void *
23pci_zalloc_consistent(struct pci_dev *hwdev, size_t size,
24 dma_addr_t *dma_handle)
25{
26 return dma_zalloc_coherent(hwdev == NULL ? NULL : &hwdev->dev,
27 size, dma_handle, GFP_ATOMIC);
28}
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030static inline void
31pci_free_consistent(struct pci_dev *hwdev, size_t size,
32 void *vaddr, dma_addr_t dma_handle)
33{
34 dma_free_coherent(hwdev == NULL ? NULL : &hwdev->dev, size, vaddr, dma_handle);
35}
36
37static inline dma_addr_t
38pci_map_single(struct pci_dev *hwdev, void *ptr, size_t size, int direction)
39{
40 return dma_map_single(hwdev == NULL ? NULL : &hwdev->dev, ptr, size, (enum dma_data_direction)direction);
41}
42
43static inline void
44pci_unmap_single(struct pci_dev *hwdev, dma_addr_t dma_addr,
45 size_t size, int direction)
46{
47 dma_unmap_single(hwdev == NULL ? NULL : &hwdev->dev, dma_addr, size, (enum dma_data_direction)direction);
48}
49
50static inline dma_addr_t
51pci_map_page(struct pci_dev *hwdev, struct page *page,
52 unsigned long offset, size_t size, int direction)
53{
54 return dma_map_page(hwdev == NULL ? NULL : &hwdev->dev, page, offset, size, (enum dma_data_direction)direction);
55}
56
57static inline void
58pci_unmap_page(struct pci_dev *hwdev, dma_addr_t dma_address,
59 size_t size, int direction)
60{
61 dma_unmap_page(hwdev == NULL ? NULL : &hwdev->dev, dma_address, size, (enum dma_data_direction)direction);
62}
63
64static inline int
65pci_map_sg(struct pci_dev *hwdev, struct scatterlist *sg,
66 int nents, int direction)
67{
68 return dma_map_sg(hwdev == NULL ? NULL : &hwdev->dev, sg, nents, (enum dma_data_direction)direction);
69}
70
71static inline void
72pci_unmap_sg(struct pci_dev *hwdev, struct scatterlist *sg,
73 int nents, int direction)
74{
75 dma_unmap_sg(hwdev == NULL ? NULL : &hwdev->dev, sg, nents, (enum dma_data_direction)direction);
76}
77
78static inline void
79pci_dma_sync_single_for_cpu(struct pci_dev *hwdev, dma_addr_t dma_handle,
80 size_t size, int direction)
81{
82 dma_sync_single_for_cpu(hwdev == NULL ? NULL : &hwdev->dev, dma_handle, size, (enum dma_data_direction)direction);
83}
84
85static inline void
86pci_dma_sync_single_for_device(struct pci_dev *hwdev, dma_addr_t dma_handle,
87 size_t size, int direction)
88{
89 dma_sync_single_for_device(hwdev == NULL ? NULL : &hwdev->dev, dma_handle, size, (enum dma_data_direction)direction);
90}
91
92static inline void
93pci_dma_sync_sg_for_cpu(struct pci_dev *hwdev, struct scatterlist *sg,
94 int nelems, int direction)
95{
96 dma_sync_sg_for_cpu(hwdev == NULL ? NULL : &hwdev->dev, sg, nelems, (enum dma_data_direction)direction);
97}
98
99static inline void
100pci_dma_sync_sg_for_device(struct pci_dev *hwdev, struct scatterlist *sg,
101 int nelems, int direction)
102{
103 dma_sync_sg_for_device(hwdev == NULL ? NULL : &hwdev->dev, sg, nelems, (enum dma_data_direction)direction);
104}
105
106static inline int
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700107pci_dma_mapping_error(struct pci_dev *pdev, dma_addr_t dma_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108{
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700109 return dma_mapping_error(&pdev->dev, dma_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110}
111
FUJITA Tomonori5f3cd1e2010-03-10 15:23:41 -0800112#ifdef CONFIG_PCI
113static inline int pci_set_dma_mask(struct pci_dev *dev, u64 mask)
114{
115 return dma_set_mask(&dev->dev, mask);
116}
117
118static inline int pci_set_consistent_dma_mask(struct pci_dev *dev, u64 mask)
119{
120 return dma_set_coherent_mask(&dev->dev, mask);
121}
122#endif
123
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124#endif