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