buffer_impl.h (7ae9fb1b7ecbb5d85d07857943f677fd1a559b18) buffer_impl.h (3e26d9f08fbe0b73e951a5e810fdb7a332b7e37f)
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _IIO_BUFFER_GENERIC_IMPL_H_
3#define _IIO_BUFFER_GENERIC_IMPL_H_
4#include <linux/sysfs.h>
5#include <linux/kref.h>
6
7#ifdef CONFIG_IIO_BUFFER
8
9#include <uapi/linux/iio/buffer.h>
10#include <linux/iio/buffer.h>
11
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _IIO_BUFFER_GENERIC_IMPL_H_
3#define _IIO_BUFFER_GENERIC_IMPL_H_
4#include <linux/sysfs.h>
5#include <linux/kref.h>
6
7#ifdef CONFIG_IIO_BUFFER
8
9#include <uapi/linux/iio/buffer.h>
10#include <linux/iio/buffer.h>
11
12struct dma_buf_attachment;
13struct dma_fence;
12struct iio_dev;
14struct iio_dev;
15struct iio_dma_buffer_block;
13struct iio_buffer;
16struct iio_buffer;
17struct sg_table;
14
15/**
16 * INDIO_BUFFER_FLAG_FIXED_WATERMARK - Watermark level of the buffer can not be
17 * configured. It has a fixed value which will be buffer specific.
18 */
19#define INDIO_BUFFER_FLAG_FIXED_WATERMARK BIT(0)
20
21/**

--- 12 unchanged lines hidden (view full) ---

34 * @set_length: set number of datums in buffer
35 * @enable: called if the buffer is attached to a device and the
36 * device starts sampling. Calls are balanced with
37 * @disable.
38 * @disable: called if the buffer is attached to a device and the
39 * device stops sampling. Calles are balanced with @enable.
40 * @release: called when the last reference to the buffer is dropped,
41 * should free all resources allocated by the buffer.
18
19/**
20 * INDIO_BUFFER_FLAG_FIXED_WATERMARK - Watermark level of the buffer can not be
21 * configured. It has a fixed value which will be buffer specific.
22 */
23#define INDIO_BUFFER_FLAG_FIXED_WATERMARK BIT(0)
24
25/**

--- 12 unchanged lines hidden (view full) ---

38 * @set_length: set number of datums in buffer
39 * @enable: called if the buffer is attached to a device and the
40 * device starts sampling. Calls are balanced with
41 * @disable.
42 * @disable: called if the buffer is attached to a device and the
43 * device stops sampling. Calles are balanced with @enable.
44 * @release: called when the last reference to the buffer is dropped,
45 * should free all resources allocated by the buffer.
46 * @attach_dmabuf: called from userspace via ioctl to attach one external
47 * DMABUF.
48 * @detach_dmabuf: called from userspace via ioctl to detach one previously
49 * attached DMABUF.
50 * @enqueue_dmabuf: called from userspace via ioctl to queue this DMABUF
51 * object to this buffer. Requires a valid DMABUF fd, that
52 * was previouly attached to this buffer.
53 * @lock_queue: called when the core needs to lock the buffer queue;
54 * it is used when enqueueing DMABUF objects.
55 * @unlock_queue: used to unlock a previously locked buffer queue
42 * @modes: Supported operating modes by this buffer type
43 * @flags: A bitmask combination of INDIO_BUFFER_FLAG_*
44 *
45 * The purpose of this structure is to make the buffer element
46 * modular as event for a given driver, different usecases may require
47 * different buffer designs (space efficiency vs speed for example).
48 *
49 * It is worth noting that a given buffer implementation may only support a

--- 13 unchanged lines hidden (view full) ---

63 int (*set_bytes_per_datum)(struct iio_buffer *buffer, size_t bpd);
64 int (*set_length)(struct iio_buffer *buffer, unsigned int length);
65
66 int (*enable)(struct iio_buffer *buffer, struct iio_dev *indio_dev);
67 int (*disable)(struct iio_buffer *buffer, struct iio_dev *indio_dev);
68
69 void (*release)(struct iio_buffer *buffer);
70
56 * @modes: Supported operating modes by this buffer type
57 * @flags: A bitmask combination of INDIO_BUFFER_FLAG_*
58 *
59 * The purpose of this structure is to make the buffer element
60 * modular as event for a given driver, different usecases may require
61 * different buffer designs (space efficiency vs speed for example).
62 *
63 * It is worth noting that a given buffer implementation may only support a

--- 13 unchanged lines hidden (view full) ---

77 int (*set_bytes_per_datum)(struct iio_buffer *buffer, size_t bpd);
78 int (*set_length)(struct iio_buffer *buffer, unsigned int length);
79
80 int (*enable)(struct iio_buffer *buffer, struct iio_dev *indio_dev);
81 int (*disable)(struct iio_buffer *buffer, struct iio_dev *indio_dev);
82
83 void (*release)(struct iio_buffer *buffer);
84
85 struct iio_dma_buffer_block * (*attach_dmabuf)(struct iio_buffer *buffer,
86 struct dma_buf_attachment *attach);
87 void (*detach_dmabuf)(struct iio_buffer *buffer,
88 struct iio_dma_buffer_block *block);
89 int (*enqueue_dmabuf)(struct iio_buffer *buffer,
90 struct iio_dma_buffer_block *block,
91 struct dma_fence *fence, struct sg_table *sgt,
92 size_t size, bool cyclic);
93 void (*lock_queue)(struct iio_buffer *buffer);
94 void (*unlock_queue)(struct iio_buffer *buffer);
95
71 unsigned int modes;
72 unsigned int flags;
73};
74
75/**
76 * struct iio_buffer - general buffer structure
77 *
78 * Note that the internals of this structure should only be of interest to

--- 52 unchanged lines hidden (view full) ---

131 /* @attached_entry: Entry in the devices list of buffers attached by the driver. */
132 struct list_head attached_entry;
133
134 /* @buffer_list: Entry in the devices list of current buffers. */
135 struct list_head buffer_list;
136
137 /* @ref: Reference count of the buffer. */
138 struct kref ref;
96 unsigned int modes;
97 unsigned int flags;
98};
99
100/**
101 * struct iio_buffer - general buffer structure
102 *
103 * Note that the internals of this structure should only be of interest to

--- 52 unchanged lines hidden (view full) ---

156 /* @attached_entry: Entry in the devices list of buffers attached by the driver. */
157 struct list_head attached_entry;
158
159 /* @buffer_list: Entry in the devices list of current buffers. */
160 struct list_head buffer_list;
161
162 /* @ref: Reference count of the buffer. */
163 struct kref ref;
164
165 /* @dmabufs: List of DMABUF attachments */
166 struct list_head dmabufs; /* P: dmabufs_mutex */
167
168 /* @dmabufs_mutex: Protects dmabufs */
169 struct mutex dmabufs_mutex;
139};
140
141/**
142 * iio_update_buffers() - add or remove buffer from active list
143 * @indio_dev: device to add buffer to
144 * @insert_buffer: buffer to insert
145 * @remove_buffer: buffer_to_remove
146 *

--- 7 unchanged lines hidden (view full) ---

154 * iio_buffer_init() - Initialize the buffer structure
155 * @buffer: buffer to be initialized
156 **/
157void iio_buffer_init(struct iio_buffer *buffer);
158
159struct iio_buffer *iio_buffer_get(struct iio_buffer *buffer);
160void iio_buffer_put(struct iio_buffer *buffer);
161
170};
171
172/**
173 * iio_update_buffers() - add or remove buffer from active list
174 * @indio_dev: device to add buffer to
175 * @insert_buffer: buffer to insert
176 * @remove_buffer: buffer_to_remove
177 *

--- 7 unchanged lines hidden (view full) ---

185 * iio_buffer_init() - Initialize the buffer structure
186 * @buffer: buffer to be initialized
187 **/
188void iio_buffer_init(struct iio_buffer *buffer);
189
190struct iio_buffer *iio_buffer_get(struct iio_buffer *buffer);
191void iio_buffer_put(struct iio_buffer *buffer);
192
193void iio_buffer_signal_dmabuf_done(struct dma_fence *fence, int ret);
194
162#else /* CONFIG_IIO_BUFFER */
163
164static inline void iio_buffer_get(struct iio_buffer *buffer) {}
165static inline void iio_buffer_put(struct iio_buffer *buffer) {}
166
167#endif /* CONFIG_IIO_BUFFER */
168#endif /* _IIO_BUFFER_GENERIC_IMPL_H_ */
195#else /* CONFIG_IIO_BUFFER */
196
197static inline void iio_buffer_get(struct iio_buffer *buffer) {}
198static inline void iio_buffer_put(struct iio_buffer *buffer) {}
199
200#endif /* CONFIG_IIO_BUFFER */
201#endif /* _IIO_BUFFER_GENERIC_IMPL_H_ */