blob: 249d4d7fbf185870bed6918769828eb2e6be6244 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/* 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 Helgaasfe537672016-03-07 11:39:16 -060010/* This defines the direction arg to the DMA mapping routines. */
Shunyong Yang546c5962018-07-18 09:40:35 +080011#define PCI_DMA_BIDIRECTIONAL DMA_BIDIRECTIONAL
12#define PCI_DMA_TODEVICE DMA_TO_DEVICE
13#define PCI_DMA_FROMDEVICE DMA_FROM_DEVICE
14#define PCI_DMA_NONE DMA_NONE
Bjorn Helgaasfe537672016-03-07 11:39:16 -060015
Linus Torvalds1da177e2005-04-16 15:20:36 -070016static inline void *
17pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
18 dma_addr_t *dma_handle)
19{
Christoph Hellwig4167b2a2018-01-10 19:03:22 +010020 return dma_alloc_coherent(&hwdev->dev, size, dma_handle, GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -070021}
22
Joe Perches82bf0ba2014-08-08 14:24:08 -070023static inline void *
24pci_zalloc_consistent(struct pci_dev *hwdev, size_t size,
25 dma_addr_t *dma_handle)
26{
Luis Chamberlain750afb02019-01-04 09:23:09 +010027 return dma_alloc_coherent(&hwdev->dev, size, dma_handle, GFP_ATOMIC);
Joe Perches82bf0ba2014-08-08 14:24:08 -070028}
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{
Christoph Hellwig4167b2a2018-01-10 19:03:22 +010034 dma_free_coherent(&hwdev->dev, size, vaddr, dma_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035}
36
37static inline dma_addr_t
38pci_map_single(struct pci_dev *hwdev, void *ptr, size_t size, int direction)
39{
Christoph Hellwig4167b2a2018-01-10 19:03:22 +010040 return dma_map_single(&hwdev->dev, ptr, size, (enum dma_data_direction)direction);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041}
42
43static inline void
44pci_unmap_single(struct pci_dev *hwdev, dma_addr_t dma_addr,
45 size_t size, int direction)
46{
Christoph Hellwig4167b2a2018-01-10 19:03:22 +010047 dma_unmap_single(&hwdev->dev, dma_addr, size, (enum dma_data_direction)direction);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048}
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{
Christoph Hellwig4167b2a2018-01-10 19:03:22 +010054 return dma_map_page(&hwdev->dev, page, offset, size, (enum dma_data_direction)direction);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055}
56
57static inline void
58pci_unmap_page(struct pci_dev *hwdev, dma_addr_t dma_address,
59 size_t size, int direction)
60{
Christoph Hellwig4167b2a2018-01-10 19:03:22 +010061 dma_unmap_page(&hwdev->dev, dma_address, size, (enum dma_data_direction)direction);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062}
63
64static inline int
65pci_map_sg(struct pci_dev *hwdev, struct scatterlist *sg,
66 int nents, int direction)
67{
Christoph Hellwig4167b2a2018-01-10 19:03:22 +010068 return dma_map_sg(&hwdev->dev, sg, nents, (enum dma_data_direction)direction);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069}
70
71static inline void
72pci_unmap_sg(struct pci_dev *hwdev, struct scatterlist *sg,
73 int nents, int direction)
74{
Christoph Hellwig4167b2a2018-01-10 19:03:22 +010075 dma_unmap_sg(&hwdev->dev, sg, nents, (enum dma_data_direction)direction);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076}
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{
Christoph Hellwig4167b2a2018-01-10 19:03:22 +010082 dma_sync_single_for_cpu(&hwdev->dev, dma_handle, size, (enum dma_data_direction)direction);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083}
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{
Christoph Hellwig4167b2a2018-01-10 19:03:22 +010089 dma_sync_single_for_device(&hwdev->dev, dma_handle, size, (enum dma_data_direction)direction);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090}
91
92static inline void
93pci_dma_sync_sg_for_cpu(struct pci_dev *hwdev, struct scatterlist *sg,
94 int nelems, int direction)
95{
Christoph Hellwig4167b2a2018-01-10 19:03:22 +010096 dma_sync_sg_for_cpu(&hwdev->dev, sg, nelems, (enum dma_data_direction)direction);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097}
98
99static inline void
100pci_dma_sync_sg_for_device(struct pci_dev *hwdev, struct scatterlist *sg,
101 int nelems, int direction)
102{
Christoph Hellwig4167b2a2018-01-10 19:03:22 +0100103 dma_sync_sg_for_device(&hwdev->dev, sg, nelems, (enum dma_data_direction)direction);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104}
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}
Bjorn Helgaasfe537672016-03-07 11:39:16 -0600122#else
123static inline int pci_set_dma_mask(struct pci_dev *dev, u64 mask)
124{ return -EIO; }
125static inline int pci_set_consistent_dma_mask(struct pci_dev *dev, u64 mask)
126{ return -EIO; }
FUJITA Tomonori5f3cd1e2010-03-10 15:23:41 -0800127#endif
128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129#endif