21#ifndef _COBALT_RTDM_ANALOGY_BUFFER_H
22#define _COBALT_RTDM_ANALOGY_BUFFER_H
24#include <linux/version.h>
28#include <rtdm/analogy/rtdm_helpers.h>
29#include <rtdm/analogy/context.h>
30#include <rtdm/analogy/command.h>
35#define A4L_BUF_EOBUF_NR 0
36#define A4L_BUF_EOBUF (1 << A4L_BUF_EOBUF_NR)
38#define A4L_BUF_ERROR_NR 1
39#define A4L_BUF_ERROR (1 << A4L_BUF_ERROR_NR)
41#define A4L_BUF_EOA_NR 2
42#define A4L_BUF_EOA (1 << A4L_BUF_EOA_NR)
46#define A4L_BUF_BULK_NR 8
47#define A4L_BUF_BULK (1 << A4L_BUF_BULK_NR)
49#define A4L_BUF_MAP_NR 9
50#define A4L_BUF_MAP (1 << A4L_BUF_MAP_NR)
65 unsigned long *pg_list;
71 unsigned long end_count;
72 unsigned long prd_count;
73 unsigned long cns_count;
74 unsigned long tmp_count;
83 unsigned long mng_count;
87 unsigned long wake_count;
90static inline void __dump_buffer_counters(
struct a4l_buffer *buf)
92 __a4l_dbg(1, core_dbg,
"a4l_buffer=0x%p, p=0x%p \n", buf, buf->buf);
93 __a4l_dbg(1, core_dbg,
"end=%06ld, prd=%06ld, cns=%06ld, tmp=%06ld \n",
94 buf->end_count, buf->prd_count, buf->cns_count, buf->tmp_count);
103static inline int __produce(
struct a4l_device_context *cxt,
104 struct a4l_buffer *buf,
void *pin,
unsigned long count)
106 unsigned long start_ptr = (buf->prd_count % buf->size);
108 unsigned long tmp_cnt = count;
111 while (ret == 0 && tmp_cnt != 0) {
113 unsigned long blk_size = (start_ptr + tmp_cnt > buf->size) ?
114 buf->size - start_ptr : tmp_cnt;
118 memcpy(buf->buf + start_ptr, pin, blk_size);
121 buf->buf + start_ptr,
136static inline int __consume(
struct a4l_device_context *cxt,
137 struct a4l_buffer *buf,
void *pout,
unsigned long count)
139 unsigned long start_ptr = (buf->cns_count % buf->size);
141 unsigned long tmp_cnt = count;
144 while (ret == 0 && tmp_cnt != 0) {
146 unsigned long blk_size = (start_ptr + tmp_cnt > buf->size) ?
147 buf->size - start_ptr : tmp_cnt;
151 memcpy(pout, buf->buf + start_ptr, blk_size);
155 buf->buf + start_ptr,
172 void *,
unsigned long),
173 struct a4l_buffer * buf,
unsigned long count)
175 unsigned long start_ptr = (buf->mng_count % buf->size);
176 unsigned long tmp_cnt = count;
178 while (tmp_cnt != 0) {
180 unsigned long blk_size = (start_ptr + tmp_cnt > buf->size) ?
181 buf->size - start_ptr : tmp_cnt;
184 munge(subd, buf->buf + start_ptr, blk_size);
195static inline int __handle_event(
struct a4l_buffer * buf)
201 if (test_bit(A4L_BUF_EOA_NR, &buf->flags))
204 if (test_bit(A4L_BUF_ERROR_NR, &buf->flags))
243static inline int __pre_abs_put(
struct a4l_buffer * buf,
unsigned long count)
245 if (count - buf->tmp_count > buf->size) {
246 set_bit(A4L_BUF_ERROR_NR, &buf->flags);
250 buf->tmp_count = buf->cns_count;
255static inline int __pre_put(
struct a4l_buffer * buf,
unsigned long count)
257 return __pre_abs_put(buf, buf->tmp_count + count);
260static inline int __pre_abs_get(
struct a4l_buffer * buf,
unsigned long count)
265 if (buf->tmp_count == 0 || buf->cns_count == 0)
273 if (buf->end_count != 0 && (
long)(count - buf->end_count) > 0)
285 if ((
long)(count - buf->tmp_count) > 0) {
286 set_bit(A4L_BUF_ERROR_NR, &buf->flags);
291 buf->tmp_count = buf->prd_count;
296static inline int __pre_get(
struct a4l_buffer * buf,
unsigned long count)
298 return __pre_abs_get(buf, buf->tmp_count + count);
301static inline int __abs_put(
struct a4l_buffer * buf,
unsigned long count)
303 unsigned long old = buf->prd_count;
305 if ((
long)(buf->prd_count - count) >= 0)
308 buf->prd_count = count;
310 if ((old / buf->size) != (count / buf->size))
311 set_bit(A4L_BUF_EOBUF_NR, &buf->flags);
313 if (buf->end_count != 0 && (
long)(count - buf->end_count) >= 0)
314 set_bit(A4L_BUF_EOA_NR, &buf->flags);
319static inline int __put(
struct a4l_buffer * buf,
unsigned long count)
321 return __abs_put(buf, buf->prd_count + count);
324static inline int __abs_get(
struct a4l_buffer * buf,
unsigned long count)
326 unsigned long old = buf->cns_count;
328 if ((
long)(buf->cns_count - count) >= 0)
331 buf->cns_count = count;
333 if ((old / buf->size) != count / buf->size)
334 set_bit(A4L_BUF_EOBUF_NR, &buf->flags);
336 if (buf->end_count != 0 && (
long)(count - buf->end_count) >= 0)
337 set_bit(A4L_BUF_EOA_NR, &buf->flags);
342static inline int __get(
struct a4l_buffer * buf,
unsigned long count)
344 return __abs_get(buf, buf->cns_count + count);
347static inline unsigned long __count_to_put(
struct a4l_buffer * buf)
351 if ((
long) (buf->size + buf->cns_count - buf->prd_count) > 0)
352 ret = buf->size + buf->cns_count - buf->prd_count;
359static inline unsigned long __count_to_get(
struct a4l_buffer * buf)
365 if (buf->end_count == 0 || (
long)(buf->end_count - buf->prd_count) > 0)
366 ret = buf->prd_count;
368 ret = buf->end_count;
370 if ((
long)(ret - buf->cns_count) > 0)
371 ret -= buf->cns_count;
378static inline unsigned long __count_to_end(
struct a4l_buffer * buf)
380 unsigned long ret = buf->end_count - buf->cns_count;
382 if (buf->end_count == 0)
385 return ((
long)ret) < 0 ? 0 : ret;
390int a4l_alloc_buffer(
struct a4l_buffer *buf_desc,
int buf_size);
392void a4l_free_buffer(
struct a4l_buffer *buf_desc);
394void a4l_init_buffer(
struct a4l_buffer * buf_desc);
396void a4l_cleanup_buffer(
struct a4l_buffer * buf_desc);
398int a4l_setup_buffer(
struct a4l_device_context *cxt,
struct a4l_cmd_desc *cmd);
400void a4l_cancel_buffer(
struct a4l_device_context *cxt);
403 unsigned long count);
406 unsigned long count);
409 unsigned long count);
412 unsigned long count);
415 void *bufdata,
unsigned long count);
418 unsigned long count);
421 unsigned long count);
424 unsigned long count);
427 unsigned long count);
430 void *bufdata,
unsigned long count);
432int a4l_buf_evt(
struct a4l_subdevice *subd,
unsigned long evts);
440 return (subd->
buf) ? subd->
buf->cur_cmd : NULL;
449int a4l_ioctl_mmap(
struct a4l_device_context * cxt,
void *arg);
450int a4l_ioctl_bufcfg(
struct a4l_device_context * cxt,
void *arg);
451int a4l_ioctl_bufcfg2(
struct a4l_device_context * cxt,
void *arg);
452int a4l_ioctl_bufinfo(
struct a4l_device_context * cxt,
void *arg);
453int a4l_ioctl_bufinfo2(
struct a4l_device_context * cxt,
void *arg);
454int a4l_ioctl_poll(
struct a4l_device_context * cxt,
void *arg);
455ssize_t a4l_read_buffer(
struct a4l_device_context * cxt,
void *bufdata,
size_t nbytes);
456ssize_t a4l_write_buffer(
struct a4l_device_context * cxt,
const void *bufdata,
size_t nbytes);
457int a4l_select(
struct a4l_device_context *cxt,
458 rtdm_selector_t *selector,
Real-Time Driver Model for Xenomai, driver API header.
static struct rtdm_fd * rtdm_private_to_fd(void *dev_private)
Locate a device file descriptor structure from its driver private area.
Definition driver.h:176
rtdm_selecttype
Definition driver.h:113
int rtdm_safe_copy_to_user(struct rtdm_fd *fd, void __user *dst, const void *src, size_t size)
Check if read/write access to user-space memory block is safe and copy specified buffer to it.
int rtdm_safe_copy_from_user(struct rtdm_fd *fd, void *dst, const void __user *src, size_t size)
Check if read access to user-space memory block and copy it to specified buffer.
Structure describing the asynchronous instruction.
Definition analogy.h:289
Structure describing the subdevice.
Definition subdevice.h:40
struct a4l_buffer * buf
Linked buffer.
Definition subdevice.h:51
Analogy for Linux, subdevice related features.
Analogy for Linux, UAPI bits.