|
| 1 | +/* SPDX-License-Identifier: BSD-3-Clause |
| 2 | + * |
| 3 | + * Copyright (c) 2025, Intel Corporation. |
| 4 | + */ |
| 5 | + |
| 6 | +/* need to use sof-dma.h to avoid syscalls/dma.h name conflict */ |
| 7 | + |
| 8 | +#ifndef SOF_DMA_H |
| 9 | +#define SOF_DMA_H |
| 10 | + |
| 11 | +/** |
| 12 | + * \brief API to request a platform DMAC. |
| 13 | + * |
| 14 | + * Users can request DMAC based on dev type, copy direction, capabilities |
| 15 | + * and access privilege. |
| 16 | + * For exclusive access, ret DMAC with no channels draining. |
| 17 | + * For shared access, ret DMAC with the least number of channels draining. |
| 18 | + */ |
| 19 | +__syscall struct sof_dma *sof_dma_get(uint32_t dir, uint32_t caps, uint32_t dev, uint32_t flags); |
| 20 | + |
| 21 | +struct sof_dma *z_impl_sof_dma_get(uint32_t dir, uint32_t cap, uint32_t dev, uint32_t flags); |
| 22 | + |
| 23 | + |
| 24 | +/** |
| 25 | + * \brief API to release a platform DMAC. |
| 26 | + * |
| 27 | + * @param[in] dma DMAC to release. |
| 28 | + */ |
| 29 | +__syscall void sof_dma_put(struct sof_dma *dma); |
| 30 | + |
| 31 | +void z_impl_sof_dma_put(struct sof_dma *dma); |
| 32 | + |
| 33 | +__syscall int sof_dma_get_attribute(struct sof_dma *dma, uint32_t type, uint32_t *value); |
| 34 | + |
| 35 | +__syscall int sof_dma_request_channel(struct sof_dma *dma, uint32_t stream_tag); |
| 36 | + |
| 37 | +__syscall void sof_dma_release_channel(struct sof_dma *dma, |
| 38 | + uint32_t channel); |
| 39 | + |
| 40 | +__syscall int sof_dma_config(struct sof_dma *dma, uint32_t channel, |
| 41 | + struct dma_config *config); |
| 42 | + |
| 43 | +__syscall int sof_dma_start(struct sof_dma *dma, uint32_t channel); |
| 44 | + |
| 45 | +__syscall int sof_dma_stop(struct sof_dma *dma, uint32_t channel); |
| 46 | + |
| 47 | +__syscall int sof_dma_get_status(struct sof_dma *dma, uint32_t channel, struct dma_status *stat); |
| 48 | + |
| 49 | +__syscall int sof_dma_reload(struct sof_dma *dma, uint32_t channel, size_t size); |
| 50 | + |
| 51 | +static inline int z_impl_sof_dma_get_attribute(struct sof_dma *dma, uint32_t type, uint32_t *value) |
| 52 | +{ |
| 53 | + return dma_get_attribute(dma->z_dev, type, value); |
| 54 | +} |
| 55 | + |
| 56 | +static inline int z_impl_sof_dma_request_channel(struct sof_dma *dma, uint32_t stream_tag) |
| 57 | +{ |
| 58 | + return dma_request_channel(dma->z_dev, &stream_tag); |
| 59 | +} |
| 60 | + |
| 61 | +static inline void z_impl_sof_dma_release_channel(struct sof_dma *dma, |
| 62 | + uint32_t channel) |
| 63 | +{ |
| 64 | + dma_release_channel(dma->z_dev, channel); |
| 65 | +} |
| 66 | + |
| 67 | +static inline int z_impl_sof_dma_config(struct sof_dma *dma, uint32_t channel, |
| 68 | + struct dma_config *config) |
| 69 | +{ |
| 70 | + return dma_config(dma->z_dev, channel, config); |
| 71 | +} |
| 72 | + |
| 73 | + |
| 74 | +static inline int z_impl_sof_dma_start(struct sof_dma *dma, uint32_t channel) |
| 75 | +{ |
| 76 | + return dma_start(dma->z_dev, channel); |
| 77 | +} |
| 78 | + |
| 79 | +static inline int z_impl_sof_dma_stop(struct sof_dma *dma, uint32_t channel) |
| 80 | +{ |
| 81 | + return dma_stop(dma->z_dev, channel); |
| 82 | +} |
| 83 | + |
| 84 | +static inline int z_impl_sof_dma_get_status(struct sof_dma *dma, uint32_t channel, |
| 85 | + struct dma_status *stat) |
| 86 | +{ |
| 87 | + return dma_get_status(dma->z_dev, channel, stat); |
| 88 | +} |
| 89 | + |
| 90 | +static inline int z_impl_sof_dma_reload(struct sof_dma *dma, uint32_t channel, size_t size) |
| 91 | +{ |
| 92 | + return dma_reload(dma->z_dev, channel, 0, 0, size); |
| 93 | +} |
| 94 | + |
| 95 | +#ifdef CONFIG_SOF_USERSPACE_INTERFACE_DMA |
| 96 | + |
| 97 | +/* include definitions from generated file */ |
| 98 | +#include <zephyr/syscalls/sof-dma.h> |
| 99 | + |
| 100 | +#else /* !CONFIG_SOF_USERSPACE_INTERFACE_DMA */ |
| 101 | + |
| 102 | +/* |
| 103 | + * SOF-specific mechanism to allow building SOF with user-space |
| 104 | + * support enabled in Zephyr, but not including all syscall |
| 105 | + * interfaces in the SOF binary. Thee downside is we cannot |
| 106 | + * use the zephyr/syscalls/sof-dma.h boilerplate that is autogenerated |
| 107 | + * but instead need a manual wrapper that is below here. |
| 108 | + * |
| 109 | + * This can be removed if DMA is used in all SOF user-space builds. |
| 110 | + */ |
| 111 | + |
| 112 | +static inline struct sof_dma *sof_dma_get(uint32_t dir, uint32_t caps, uint32_t dev, uint32_t flags) |
| 113 | +{ |
| 114 | + return z_impl_sof_dma_get(dir, caps, dev, flags); |
| 115 | +} |
| 116 | + |
| 117 | +static inline void sof_dma_put(struct sof_dma *dma) |
| 118 | +{ |
| 119 | + return z_impl_sof_dma_put(dma); |
| 120 | +} |
| 121 | + |
| 122 | +static inline int sof_dma_get_attribute(struct sof_dma *dma, uint32_t type, uint32_t *value) |
| 123 | +{ |
| 124 | + return z_impl_sof_dma_get_attribute(dma, type, value); |
| 125 | +} |
| 126 | + |
| 127 | +static inline int sof_dma_request_channel(struct sof_dma *dma, uint32_t stream_tag) |
| 128 | +{ |
| 129 | + return z_impl_sof_dma_request_channel(dma, stream_tag); |
| 130 | +} |
| 131 | + |
| 132 | +static inline void sof_dma_release_channel(struct sof_dma *dma, |
| 133 | + uint32_t channel) |
| 134 | +{ |
| 135 | + return z_impl_sof_dma_release_channel(dma, channel); |
| 136 | +} |
| 137 | + |
| 138 | +static inline int sof_dma_config(struct sof_dma *dma, uint32_t channel, |
| 139 | + struct dma_config *config) |
| 140 | +{ |
| 141 | + return z_impl_sof_dma_config(dma, channel, config); |
| 142 | +} |
| 143 | + |
| 144 | +static inline int sof_dma_start(struct sof_dma *dma, uint32_t channel) |
| 145 | +{ |
| 146 | + return z_impl_sof_dma_start(dma, channel); |
| 147 | +} |
| 148 | + |
| 149 | +static inline int sof_dma_stop(struct sof_dma *dma, uint32_t channel) |
| 150 | +{ |
| 151 | + return z_impl_sof_dma_stop(dma, channel); |
| 152 | +} |
| 153 | + |
| 154 | +static inline int sof_dma_get_status(struct sof_dma *dma, uint32_t channel, struct dma_status *stat) |
| 155 | +{ |
| 156 | + return z_impl_sof_dma_get_status(dma, channel, stat); |
| 157 | +} |
| 158 | + |
| 159 | +static inline int sof_dma_reload(struct sof_dma *dma, uint32_t channel, size_t size) |
| 160 | +{ |
| 161 | + return z_impl_sof_dma_reload(dma, channel, size); |
| 162 | +} |
| 163 | + |
| 164 | +#endif /* CONFIG_SOF_USERSPACE_INTERFACE_DMA */ |
| 165 | + |
| 166 | +#endif |
0 commit comments