blob: 72cedb916a9c2590243cc28fa016ed99ae6cfe2a [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Andy Shevchenko1b2e98b2013-04-09 14:05:43 +03002/*
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 <andriy.shevchenko@linux.intel.com>
Andy Shevchenko1b2e98b2013-04-09 14:05:43 +03009 */
10
11#ifndef __LINUX_ACPI_DMA_H
12#define __LINUX_ACPI_DMA_H
13
14#include <linux/list.h>
15#include <linux/device.h>
Andy Shevchenko0f6a9282014-02-06 13:25:40 +020016#include <linux/err.h>
Andy Shevchenko1b2e98b2013-04-09 14:05:43 +030017#include <linux/dmaengine.h>
18
19/**
20 * struct acpi_dma_spec - slave device DMA resources
21 * @chan_id: channel unique id
22 * @slave_id: request line unique id
23 * @dev: struct device of the DMA controller to be used in the filter
24 * function
25 */
26struct acpi_dma_spec {
27 int chan_id;
28 int slave_id;
29 struct device *dev;
30};
31
32/**
33 * struct acpi_dma - representation of the registered DMAC
34 * @dma_controllers: linked list node
35 * @dev: struct device of this controller
36 * @acpi_dma_xlate: callback function to find a suitable channel
37 * @data: private data used by a callback function
Andy Shevchenkoee8209f2013-05-08 11:55:48 +030038 * @base_request_line: first supported request line (CSRT)
39 * @end_request_line: last supported request line (CSRT)
Andy Shevchenko1b2e98b2013-04-09 14:05:43 +030040 */
41struct acpi_dma {
42 struct list_head dma_controllers;
43 struct device *dev;
44 struct dma_chan *(*acpi_dma_xlate)
45 (struct acpi_dma_spec *, struct acpi_dma *);
46 void *data;
Andy Shevchenkoee8209f2013-05-08 11:55:48 +030047 unsigned short base_request_line;
48 unsigned short end_request_line;
Andy Shevchenko1b2e98b2013-04-09 14:05:43 +030049};
50
51/* Used with acpi_dma_simple_xlate() */
52struct acpi_dma_filter_info {
53 dma_cap_mask_t dma_cap;
54 dma_filter_fn filter_fn;
55};
56
57#ifdef CONFIG_DMA_ACPI
58
59int acpi_dma_controller_register(struct device *dev,
60 struct dma_chan *(*acpi_dma_xlate)
61 (struct acpi_dma_spec *, struct acpi_dma *),
62 void *data);
63int acpi_dma_controller_free(struct device *dev);
64int devm_acpi_dma_controller_register(struct device *dev,
65 struct dma_chan *(*acpi_dma_xlate)
66 (struct acpi_dma_spec *, struct acpi_dma *),
67 void *data);
68void devm_acpi_dma_controller_free(struct device *dev);
69
70struct dma_chan *acpi_dma_request_slave_chan_by_index(struct device *dev,
71 size_t index);
72struct dma_chan *acpi_dma_request_slave_chan_by_name(struct device *dev,
73 const char *name);
74
75struct dma_chan *acpi_dma_simple_xlate(struct acpi_dma_spec *dma_spec,
76 struct acpi_dma *adma);
77#else
78
79static 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}
86static inline int acpi_dma_controller_free(struct device *dev)
87{
88 return -ENODEV;
89}
90static 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}
97static inline void devm_acpi_dma_controller_free(struct device *dev)
98{
99}
100
101static inline struct dma_chan *acpi_dma_request_slave_chan_by_index(
102 struct device *dev, size_t index)
103{
Andy Shevchenko0f6a9282014-02-06 13:25:40 +0200104 return ERR_PTR(-ENODEV);
Andy Shevchenko1b2e98b2013-04-09 14:05:43 +0300105}
106static inline struct dma_chan *acpi_dma_request_slave_chan_by_name(
107 struct device *dev, const char *name)
108{
Andy Shevchenko0f6a9282014-02-06 13:25:40 +0200109 return ERR_PTR(-ENODEV);
Andy Shevchenko1b2e98b2013-04-09 14:05:43 +0300110}
111
112#define acpi_dma_simple_xlate NULL
113
114#endif
115
116#define acpi_dma_request_slave_channel acpi_dma_request_slave_chan_by_index
117
118#endif /* __LINUX_ACPI_DMA_H */