1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * ACPI helpers for DMA request / controller
4 *
5 * Based on of_dma.h
6 *
7 * Copyright (C) 2013, Intel Corporation
8 * Author: Andy Shevchenko <[email protected]>
9 */
10
11 #ifndef __LINUX_ACPI_DMA_H
12 #define __LINUX_ACPI_DMA_H
13
14 #include <linux/err.h>
15 #include <linux/dmaengine.h>
16 #include <linux/types.h>
17
18 struct device;
19
20 /**
21 * struct acpi_dma_spec - slave device DMA resources
22 * @chan_id: channel unique id
23 * @slave_id: request line unique id
24 * @dev: struct device of the DMA controller to be used in the filter
25 * function
26 */
27 struct acpi_dma_spec {
28 int chan_id;
29 int slave_id;
30 struct device *dev;
31 };
32
33 /**
34 * struct acpi_dma - representation of the registered DMAC
35 * @dma_controllers: linked list node
36 * @dev: struct device of this controller
37 * @acpi_dma_xlate: callback function to find a suitable channel
38 * @data: private data used by a callback function
39 * @base_request_line: first supported request line (CSRT)
40 * @end_request_line: last supported request line (CSRT)
41 */
42 struct acpi_dma {
43 struct list_head dma_controllers;
44 struct device *dev;
45 struct dma_chan *(*acpi_dma_xlate)
46 (struct acpi_dma_spec *, struct acpi_dma *);
47 void *data;
48 unsigned short base_request_line;
49 unsigned short end_request_line;
50 };
51
52 /* Used with acpi_dma_simple_xlate() */
53 struct acpi_dma_filter_info {
54 dma_cap_mask_t dma_cap;
55 dma_filter_fn filter_fn;
56 };
57
58 #ifdef CONFIG_DMA_ACPI
59
60 int acpi_dma_controller_register(struct device *dev,
61 struct dma_chan *(*acpi_dma_xlate)
62 (struct acpi_dma_spec *, struct acpi_dma *),
63 void *data);
64 int acpi_dma_controller_free(struct device *dev);
65 int devm_acpi_dma_controller_register(struct device *dev,
66 struct dma_chan *(*acpi_dma_xlate)
67 (struct acpi_dma_spec *, struct acpi_dma *),
68 void *data);
69
70 struct dma_chan *acpi_dma_request_slave_chan_by_index(struct device *dev,
71 size_t index);
72 struct dma_chan *acpi_dma_request_slave_chan_by_name(struct device *dev,
73 const char *name);
74
75 struct dma_chan *acpi_dma_simple_xlate(struct acpi_dma_spec *dma_spec,
76 struct acpi_dma *adma);
77 #else
78
acpi_dma_controller_register(struct device * dev,struct dma_chan * (* acpi_dma_xlate)(struct acpi_dma_spec *,struct acpi_dma *),void * data)79 static inline int acpi_dma_controller_register(struct device *dev,
80 struct dma_chan *(*acpi_dma_xlate)
81 (struct acpi_dma_spec *, struct acpi_dma *),
82 void *data)
83 {
84 return -ENODEV;
85 }
acpi_dma_controller_free(struct device * dev)86 static inline int acpi_dma_controller_free(struct device *dev)
87 {
88 return -ENODEV;
89 }
devm_acpi_dma_controller_register(struct device * dev,struct dma_chan * (* acpi_dma_xlate)(struct acpi_dma_spec *,struct acpi_dma *),void * data)90 static inline int devm_acpi_dma_controller_register(struct device *dev,
91 struct dma_chan *(*acpi_dma_xlate)
92 (struct acpi_dma_spec *, struct acpi_dma *),
93 void *data)
94 {
95 return -ENODEV;
96 }
97
acpi_dma_request_slave_chan_by_index(struct device * dev,size_t index)98 static inline struct dma_chan *acpi_dma_request_slave_chan_by_index(
99 struct device *dev, size_t index)
100 {
101 return ERR_PTR(-ENODEV);
102 }
acpi_dma_request_slave_chan_by_name(struct device * dev,const char * name)103 static inline struct dma_chan *acpi_dma_request_slave_chan_by_name(
104 struct device *dev, const char *name)
105 {
106 return ERR_PTR(-ENODEV);
107 }
108
109 #define acpi_dma_simple_xlate NULL
110
111 #endif
112
113 #define acpi_dma_request_slave_channel acpi_dma_request_slave_chan_by_index
114
115 #endif /* __LINUX_ACPI_DMA_H */
116