RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
dma.h
浏览该文件的文档.
1/*
2 * Copyright (c) 2006-2023, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2023-02-25 GuEe-GUI the first version
9 */
10
11#ifndef __DMA_H__
12#define __DMA_H__
13
14#include <rtthread.h>
15#include <drivers/ofw.h>
16#include <drivers/misc.h>
17#include <drivers/core/dm.h>
18
19#include <mmu.h>
20#include <mm_page.h>
21#include <bitmap.h>
22
23struct rt_dma_chan;
25
35
51
66
77
90
92{
93 struct rt_dma_chan *(*request_chan)(struct rt_dma_controller *ctrl,
94 struct rt_device *slave, void *fw_data);
96
97 rt_err_t (*start)(struct rt_dma_chan *chan);
98 rt_err_t (*stop)(struct rt_dma_chan *chan);
99 rt_err_t (*config)(struct rt_dma_chan *chan, struct rt_dma_slave_config *conf);
100
102 rt_ubase_t dma_addr_src, rt_ubase_t dma_addr_dst, rt_size_t len);
103
105 rt_ubase_t dma_buf_addr, rt_size_t buf_len, rt_size_t period_len,
107
109 rt_ubase_t dma_buf_addr, rt_size_t buf_len,
111};
112
130
132{
133 rt_region_t region;
134
136
138
139 rt_bitmap_t *map;
142
143 struct rt_device *dev;
144};
145
147{
148 void *(*alloc)(struct rt_device *dev, rt_size_t size,
149 rt_ubase_t *dma_handle, rt_ubase_t flags);
150 void (*free)(struct rt_device *dev, rt_size_t size,
151 void *cpu_addr, rt_ubase_t dma_handle, rt_ubase_t flags);
152 rt_err_t (*sync_out_data)(struct rt_device *dev, void *data, rt_size_t size,
153 rt_ubase_t *dma_handle, rt_ubase_t flags);
154 rt_err_t (*sync_in_data)(struct rt_device *dev, void *out_data, rt_size_t size,
155 rt_ubase_t dma_handle, rt_ubase_t flags);
156};
157
160{
161 RT_ASSERT(ctrl != RT_NULL);
163
164 rt_bitmap_set_bit(ctrl->dir_cap, dir);
165}
166
169
173 struct rt_dma_slave_config *conf);
175
177 struct rt_dma_slave_transfer *transfer);
179 struct rt_dma_slave_transfer *transfer);
181 struct rt_dma_slave_transfer *transfer);
182
183struct rt_dma_chan *rt_dma_chan_request(struct rt_device *dev, const char *name);
185
186#define RT_DMA_F_LINEAR RT_BIT(0)
187#define RT_DMA_F_32BITS RT_BIT(1)
188#define RT_DMA_F_NOCACHE RT_BIT(2)
189#define RT_DMA_F_DEVICE RT_BIT(3)
190#define RT_DMA_F_NOMAP RT_BIT(4)
191
192#define RT_DMA_PAGE_SIZE ARCH_PAGE_SIZE
193
194void *rt_dma_alloc(struct rt_device *dev, rt_size_t size,
195 rt_ubase_t *dma_handle, rt_ubase_t flags);
196
197void rt_dma_free(struct rt_device *dev, rt_size_t size,
198 void *cpu_addr, rt_ubase_t dma_handle, rt_ubase_t flags);
199
200rt_inline void *rt_dma_alloc_coherent(struct rt_device *dev, rt_size_t size,
201 rt_ubase_t *dma_handle)
202{
203 return rt_dma_alloc(dev, size, dma_handle,
205}
206
207rt_inline void rt_dma_free_coherent(struct rt_device *dev, rt_size_t size,
208 void *cpu_addr, rt_ubase_t dma_handle)
209{
210 rt_dma_free(dev, size, cpu_addr, dma_handle,
212}
213
214rt_err_t rt_dma_sync_out_data(struct rt_device *dev, void *data, rt_size_t size,
215 rt_ubase_t *dma_handle, rt_ubase_t flags);
216rt_err_t rt_dma_sync_in_data(struct rt_device *dev, void *out_data, rt_size_t size,
217 rt_ubase_t dma_handle, rt_ubase_t flags);
218
220{
221 return rt_dm_dev_prop_read_bool(dev, "dma-coherent");
222}
223
224rt_inline void rt_dma_device_set_ops(struct rt_device *dev,
225 const struct rt_dma_map_ops *ops)
226{
227 dev->dma_ops = ops;
228}
229
231rt_err_t rt_dma_pool_extract(rt_region_t *region_list, rt_size_t list_len,
232 rt_size_t cma_size, rt_size_t coherent_pool_size);
233
234#endif /* __DMA_H__ */
#define RT_DMA_F_LINEAR
定义 dma.h:186
void * rt_dma_alloc(struct rt_device *dev, rt_size_t size, rt_ubase_t *dma_handle, rt_ubase_t flags)
rt_dma_transfer_direction
定义 dma.h:27
@ RT_DMA_DEV_TO_DEV
定义 dma.h:31
@ RT_DMA_DEV_TO_MEM
定义 dma.h:30
@ RT_DMA_MEM_TO_MEM
定义 dma.h:28
@ RT_DMA_DIR_MAX
定义 dma.h:33
@ RT_DMA_MEM_TO_DEV
定义 dma.h:29
rt_err_t rt_dma_controller_register(struct rt_dma_controller *ctrl)
struct rt_dma_chan * rt_dma_chan_request(struct rt_device *dev, const char *name)
rt_err_t rt_dma_chan_release(struct rt_dma_chan *chan)
rt_err_t rt_dma_prep_memcpy(struct rt_dma_chan *chan, struct rt_dma_slave_transfer *transfer)
rt_err_t rt_dma_chan_done(struct rt_dma_chan *chan, rt_size_t size)
#define RT_DMA_F_NOCACHE
定义 dma.h:188
rt_inline void rt_dma_controller_add_direction(struct rt_dma_controller *ctrl, enum rt_dma_transfer_direction dir)
定义 dma.h:158
rt_err_t rt_dma_chan_stop(struct rt_dma_chan *chan)
rt_dma_slave_buswidth
定义 dma.h:37
@ RT_DMA_SLAVE_BUSWIDTH_2_BYTES
定义 dma.h:40
@ RT_DMA_SLAVE_BUSWIDTH_64_BYTES
定义 dma.h:46
@ RT_DMA_SLAVE_BUSWIDTH_UNDEFINED
定义 dma.h:38
@ RT_DMA_SLAVE_BUSWIDTH_BYTES_MAX
定义 dma.h:49
@ RT_DMA_SLAVE_BUSWIDTH_32_BYTES
定义 dma.h:45
@ RT_DMA_SLAVE_BUSWIDTH_8_BYTES
定义 dma.h:43
@ RT_DMA_SLAVE_BUSWIDTH_1_BYTE
定义 dma.h:39
@ RT_DMA_SLAVE_BUSWIDTH_3_BYTES
定义 dma.h:41
@ RT_DMA_SLAVE_BUSWIDTH_4_BYTES
定义 dma.h:42
@ RT_DMA_SLAVE_BUSWIDTH_128_BYTES
定义 dma.h:47
@ RT_DMA_SLAVE_BUSWIDTH_16_BYTES
定义 dma.h:44
rt_inline void rt_dma_device_set_ops(struct rt_device *dev, const struct rt_dma_map_ops *ops)
定义 dma.h:224
rt_err_t rt_dma_controller_unregister(struct rt_dma_controller *ctrl)
rt_err_t rt_dma_prep_single(struct rt_dma_chan *chan, struct rt_dma_slave_transfer *transfer)
rt_inline void * rt_dma_alloc_coherent(struct rt_device *dev, rt_size_t size, rt_ubase_t *dma_handle)
定义 dma.h:200
struct rt_dma_pool * rt_dma_pool_install(rt_region_t *region)
void rt_dma_free(struct rt_device *dev, rt_size_t size, void *cpu_addr, rt_ubase_t dma_handle, rt_ubase_t flags)
rt_err_t rt_dma_chan_config(struct rt_dma_chan *chan, struct rt_dma_slave_config *conf)
rt_err_t rt_dma_sync_in_data(struct rt_device *dev, void *out_data, rt_size_t size, rt_ubase_t dma_handle, rt_ubase_t flags)
rt_err_t rt_dma_sync_out_data(struct rt_device *dev, void *data, rt_size_t size, rt_ubase_t *dma_handle, rt_ubase_t flags)
rt_err_t rt_dma_pool_extract(rt_region_t *region_list, rt_size_t list_len, rt_size_t cma_size, rt_size_t coherent_pool_size)
rt_err_t rt_dma_prep_cyclic(struct rt_dma_chan *chan, struct rt_dma_slave_transfer *transfer)
rt_err_t rt_dma_chan_start(struct rt_dma_chan *chan)
rt_inline void rt_dma_free_coherent(struct rt_device *dev, rt_size_t size, void *cpu_addr, rt_ubase_t dma_handle)
定义 dma.h:207
rt_inline rt_bool_t rt_dma_device_is_coherent(struct rt_device *dev)
定义 dma.h:219
#define RT_ASSERT(EX)
int rt_bool_t
rt_base_t rt_err_t
rt_ubase_t rt_size_t
struct rt_list_node rt_list_t
unsigned int rt_uint32_t
rt_uint32_t rt_ubase_t
#define RT_NULL
rt_list_t list
定义 dma.h:120
struct rt_dma_slave_config conf
定义 dma.h:123
rt_err_t prep_err
定义 dma.h:122
void(* callback)(struct rt_dma_chan *chan, rt_size_t size)
定义 dma.h:126
struct rt_device * slave
定义 dma.h:118
struct rt_dma_slave_transfer transfer
定义 dma.h:124
const char * name
定义 dma.h:115
rt_err_t conf_err
定义 dma.h:121
struct rt_dma_controller * ctrl
定义 dma.h:117
void * priv
定义 dma.h:128
rt_err_t(* config)(struct rt_dma_chan *chan, struct rt_dma_slave_config *conf)
定义 dma.h:99
rt_err_t(* stop)(struct rt_dma_chan *chan)
定义 dma.h:98
rt_err_t(* prep_single)(struct rt_dma_chan *chan, rt_ubase_t dma_buf_addr, rt_size_t buf_len, enum rt_dma_transfer_direction dir)
定义 dma.h:108
rt_err_t(* prep_memcpy)(struct rt_dma_chan *chan, rt_ubase_t dma_addr_src, rt_ubase_t dma_addr_dst, rt_size_t len)
定义 dma.h:101
rt_err_t(* release_chan)(struct rt_dma_chan *chan)
定义 dma.h:95
rt_err_t(* prep_cyclic)(struct rt_dma_chan *chan, rt_ubase_t dma_buf_addr, rt_size_t buf_len, rt_size_t period_len, enum rt_dma_transfer_direction dir)
定义 dma.h:104
rt_err_t(* start)(struct rt_dma_chan *chan)
定义 dma.h:97
const struct rt_dma_controller_ops * ops
定义 dma.h:85
RT_BITMAP_DECLARE(dir_cap, RT_DMA_DIR_MAX)
struct rt_device * dev
定义 dma.h:82
rt_list_t list
定义 dma.h:80
struct rt_mutex mutex
定义 dma.h:88
rt_list_t channels_nodes
定义 dma.h:87
rt_err_t(* sync_in_data)(struct rt_device *dev, void *out_data, rt_size_t size, rt_ubase_t dma_handle, rt_ubase_t flags)
定义 dma.h:154
void(* free)(struct rt_device *dev, rt_size_t size, void *cpu_addr, rt_ubase_t dma_handle, rt_ubase_t flags)
定义 dma.h:150
rt_err_t(* sync_out_data)(struct rt_device *dev, void *data, rt_size_t size, rt_ubase_t *dma_handle, rt_ubase_t flags)
定义 dma.h:152
rt_ubase_t flags
定义 dma.h:137
rt_bitmap_t * map
定义 dma.h:139
rt_region_t region
定义 dma.h:133
rt_ubase_t start
定义 dma.h:141
struct rt_device * dev
定义 dma.h:143
rt_list_t list
定义 dma.h:135
rt_size_t bits
定义 dma.h:140
enum rt_dma_transfer_direction direction
定义 dma.h:54
rt_uint32_t dst_port_window_size
定义 dma.h:64
rt_uint32_t src_maxburst
定义 dma.h:61
rt_ubase_t dst_addr
定义 dma.h:59
rt_uint32_t src_port_window_size
定义 dma.h:63
enum rt_dma_slave_buswidth dst_addr_width
定义 dma.h:56
rt_ubase_t src_addr
定义 dma.h:58
enum rt_dma_slave_buswidth src_addr_width
定义 dma.h:55
rt_uint32_t dst_maxburst
定义 dma.h:62
rt_ubase_t dst_addr
定义 dma.h:70
rt_ubase_t src_addr
定义 dma.h:69
rt_ubase_t dma_handle
定义 dma.h:73