Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* include this file if the platform implements the dma_ DMA Mapping API |
| 3 | * and wants to provide the pci_ DMA Mapping API in terms of it */ |
| 4 | |
| 5 | #ifndef _ASM_GENERIC_PCI_DMA_COMPAT_H |
| 6 | #define _ASM_GENERIC_PCI_DMA_COMPAT_H |
| 7 | |
| 8 | #include <linux/dma-mapping.h> |
| 9 | |
Bjorn Helgaas | fe53767 | 2016-03-07 11:39:16 -0600 | [diff] [blame] | 10 | /* This defines the direction arg to the DMA mapping routines. */ |
| 11 | #define PCI_DMA_BIDIRECTIONAL 0 |
| 12 | #define PCI_DMA_TODEVICE 1 |
| 13 | #define PCI_DMA_FROMDEVICE 2 |
| 14 | #define PCI_DMA_NONE 3 |
| 15 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | static inline void * |
| 17 | pci_alloc_consistent(struct pci_dev *hwdev, size_t size, |
| 18 | dma_addr_t *dma_handle) |
| 19 | { |
Christoph Hellwig | 4167b2a | 2018-01-10 19:03:22 +0100 | [diff] [blame] | 20 | return dma_alloc_coherent(&hwdev->dev, size, dma_handle, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | } |
| 22 | |
Joe Perches | 82bf0ba | 2014-08-08 14:24:08 -0700 | [diff] [blame] | 23 | static inline void * |
| 24 | pci_zalloc_consistent(struct pci_dev *hwdev, size_t size, |
| 25 | dma_addr_t *dma_handle) |
| 26 | { |
Christoph Hellwig | 4167b2a | 2018-01-10 19:03:22 +0100 | [diff] [blame] | 27 | return dma_zalloc_coherent(&hwdev->dev, size, dma_handle, GFP_ATOMIC); |
Joe Perches | 82bf0ba | 2014-08-08 14:24:08 -0700 | [diff] [blame] | 28 | } |
| 29 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | static inline void |
| 31 | pci_free_consistent(struct pci_dev *hwdev, size_t size, |
| 32 | void *vaddr, dma_addr_t dma_handle) |
| 33 | { |
Christoph Hellwig | 4167b2a | 2018-01-10 19:03:22 +0100 | [diff] [blame] | 34 | dma_free_coherent(&hwdev->dev, size, vaddr, dma_handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | static inline dma_addr_t |
| 38 | pci_map_single(struct pci_dev *hwdev, void *ptr, size_t size, int direction) |
| 39 | { |
Christoph Hellwig | 4167b2a | 2018-01-10 19:03:22 +0100 | [diff] [blame] | 40 | return dma_map_single(&hwdev->dev, ptr, size, (enum dma_data_direction)direction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | static inline void |
| 44 | pci_unmap_single(struct pci_dev *hwdev, dma_addr_t dma_addr, |
| 45 | size_t size, int direction) |
| 46 | { |
Christoph Hellwig | 4167b2a | 2018-01-10 19:03:22 +0100 | [diff] [blame] | 47 | dma_unmap_single(&hwdev->dev, dma_addr, size, (enum dma_data_direction)direction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | static inline dma_addr_t |
| 51 | pci_map_page(struct pci_dev *hwdev, struct page *page, |
| 52 | unsigned long offset, size_t size, int direction) |
| 53 | { |
Christoph Hellwig | 4167b2a | 2018-01-10 19:03:22 +0100 | [diff] [blame] | 54 | return dma_map_page(&hwdev->dev, page, offset, size, (enum dma_data_direction)direction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | static inline void |
| 58 | pci_unmap_page(struct pci_dev *hwdev, dma_addr_t dma_address, |
| 59 | size_t size, int direction) |
| 60 | { |
Christoph Hellwig | 4167b2a | 2018-01-10 19:03:22 +0100 | [diff] [blame] | 61 | dma_unmap_page(&hwdev->dev, dma_address, size, (enum dma_data_direction)direction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | static inline int |
| 65 | pci_map_sg(struct pci_dev *hwdev, struct scatterlist *sg, |
| 66 | int nents, int direction) |
| 67 | { |
Christoph Hellwig | 4167b2a | 2018-01-10 19:03:22 +0100 | [diff] [blame] | 68 | return dma_map_sg(&hwdev->dev, sg, nents, (enum dma_data_direction)direction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static inline void |
| 72 | pci_unmap_sg(struct pci_dev *hwdev, struct scatterlist *sg, |
| 73 | int nents, int direction) |
| 74 | { |
Christoph Hellwig | 4167b2a | 2018-01-10 19:03:22 +0100 | [diff] [blame] | 75 | dma_unmap_sg(&hwdev->dev, sg, nents, (enum dma_data_direction)direction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | static inline void |
| 79 | pci_dma_sync_single_for_cpu(struct pci_dev *hwdev, dma_addr_t dma_handle, |
| 80 | size_t size, int direction) |
| 81 | { |
Christoph Hellwig | 4167b2a | 2018-01-10 19:03:22 +0100 | [diff] [blame] | 82 | dma_sync_single_for_cpu(&hwdev->dev, dma_handle, size, (enum dma_data_direction)direction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | static inline void |
| 86 | pci_dma_sync_single_for_device(struct pci_dev *hwdev, dma_addr_t dma_handle, |
| 87 | size_t size, int direction) |
| 88 | { |
Christoph Hellwig | 4167b2a | 2018-01-10 19:03:22 +0100 | [diff] [blame] | 89 | dma_sync_single_for_device(&hwdev->dev, dma_handle, size, (enum dma_data_direction)direction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | static inline void |
| 93 | pci_dma_sync_sg_for_cpu(struct pci_dev *hwdev, struct scatterlist *sg, |
| 94 | int nelems, int direction) |
| 95 | { |
Christoph Hellwig | 4167b2a | 2018-01-10 19:03:22 +0100 | [diff] [blame] | 96 | dma_sync_sg_for_cpu(&hwdev->dev, sg, nelems, (enum dma_data_direction)direction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | static inline void |
| 100 | pci_dma_sync_sg_for_device(struct pci_dev *hwdev, struct scatterlist *sg, |
| 101 | int nelems, int direction) |
| 102 | { |
Christoph Hellwig | 4167b2a | 2018-01-10 19:03:22 +0100 | [diff] [blame] | 103 | dma_sync_sg_for_device(&hwdev->dev, sg, nelems, (enum dma_data_direction)direction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | static inline int |
FUJITA Tomonori | 8d8bb39 | 2008-07-25 19:44:49 -0700 | [diff] [blame] | 107 | pci_dma_mapping_error(struct pci_dev *pdev, dma_addr_t dma_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | { |
FUJITA Tomonori | 8d8bb39 | 2008-07-25 19:44:49 -0700 | [diff] [blame] | 109 | return dma_mapping_error(&pdev->dev, dma_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | } |
| 111 | |
FUJITA Tomonori | 5f3cd1e | 2010-03-10 15:23:41 -0800 | [diff] [blame] | 112 | #ifdef CONFIG_PCI |
| 113 | static inline int pci_set_dma_mask(struct pci_dev *dev, u64 mask) |
| 114 | { |
| 115 | return dma_set_mask(&dev->dev, mask); |
| 116 | } |
| 117 | |
| 118 | static inline int pci_set_consistent_dma_mask(struct pci_dev *dev, u64 mask) |
| 119 | { |
| 120 | return dma_set_coherent_mask(&dev->dev, mask); |
| 121 | } |
Bjorn Helgaas | fe53767 | 2016-03-07 11:39:16 -0600 | [diff] [blame] | 122 | |
| 123 | static inline int pci_set_dma_max_seg_size(struct pci_dev *dev, |
| 124 | unsigned int size) |
| 125 | { |
| 126 | return dma_set_max_seg_size(&dev->dev, size); |
| 127 | } |
| 128 | |
| 129 | static inline int pci_set_dma_seg_boundary(struct pci_dev *dev, |
| 130 | unsigned long mask) |
| 131 | { |
| 132 | return dma_set_seg_boundary(&dev->dev, mask); |
| 133 | } |
| 134 | #else |
| 135 | static inline int pci_set_dma_mask(struct pci_dev *dev, u64 mask) |
| 136 | { return -EIO; } |
| 137 | static inline int pci_set_consistent_dma_mask(struct pci_dev *dev, u64 mask) |
| 138 | { return -EIO; } |
| 139 | static inline int pci_set_dma_max_seg_size(struct pci_dev *dev, |
| 140 | unsigned int size) |
| 141 | { return -EIO; } |
| 142 | static inline int pci_set_dma_seg_boundary(struct pci_dev *dev, |
| 143 | unsigned long mask) |
| 144 | { return -EIO; } |
FUJITA Tomonori | 5f3cd1e | 2010-03-10 15:23:41 -0800 | [diff] [blame] | 145 | #endif |
| 146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | #endif |