22 #ifndef _COBALT_RTDM_ANALOGY_BUFFER_H
23 #define _COBALT_RTDM_ANALOGY_BUFFER_H
25 #include <linux/version.h>
31 #include <rtdm/analogy/command.h>
36 #define A4L_BUF_EOBUF_NR 0
37 #define A4L_BUF_EOBUF (1 << A4L_BUF_EOBUF_NR)
39 #define A4L_BUF_ERROR_NR 1
40 #define A4L_BUF_ERROR (1 << A4L_BUF_ERROR_NR)
42 #define A4L_BUF_EOA_NR 2
43 #define A4L_BUF_EOA (1 << A4L_BUF_EOA_NR)
47 #define A4L_BUF_BULK_NR 8
48 #define A4L_BUF_BULK (1 << A4L_BUF_BULK_NR)
50 #define A4L_BUF_MAP_NR 9
51 #define A4L_BUF_MAP (1 << A4L_BUF_MAP_NR)
66 unsigned long *pg_list;
72 unsigned long end_count;
73 unsigned long prd_count;
74 unsigned long cns_count;
75 unsigned long tmp_count;
84 unsigned long mng_count;
88 unsigned long wake_count;
91 static inline void __dump_buffer_counters(
struct a4l_buffer *buf)
93 __a4l_dbg(1, core_dbg,
"a4l_buffer=0x%p, p=0x%p \n", buf, buf->buf);
94 __a4l_dbg(1, core_dbg,
"end=%06ld, prd=%06ld, cns=%06ld, tmp=%06ld \n",
95 buf->end_count, buf->prd_count, buf->cns_count, buf->tmp_count);
104 static inline int __produce(
struct a4l_device_context *cxt,
105 struct a4l_buffer *buf,
void *pin,
unsigned long count)
107 unsigned long start_ptr = (buf->prd_count % buf->size);
109 unsigned long tmp_cnt = count;
112 while (ret == 0 && tmp_cnt != 0) {
114 unsigned long blk_size = (start_ptr + tmp_cnt > buf->size) ?
115 buf->size - start_ptr : tmp_cnt;
119 memcpy(buf->buf + start_ptr, pin, blk_size);
122 buf->buf + start_ptr,
137 static inline int __consume(
struct a4l_device_context *cxt,
138 struct a4l_buffer *buf,
void *pout,
unsigned long count)
140 unsigned long start_ptr = (buf->cns_count % buf->size);
142 unsigned long tmp_cnt = count;
145 while (ret == 0 && tmp_cnt != 0) {
147 unsigned long blk_size = (start_ptr + tmp_cnt > buf->size) ?
148 buf->size - start_ptr : tmp_cnt;
152 memcpy(pout, buf->buf + start_ptr, blk_size);
156 buf->buf + start_ptr,
173 void *,
unsigned long),
174 struct a4l_buffer * buf,
unsigned long count)
176 unsigned long start_ptr = (buf->mng_count % buf->size);
177 unsigned long tmp_cnt = count;
179 while (tmp_cnt != 0) {
181 unsigned long blk_size = (start_ptr + tmp_cnt > buf->size) ?
182 buf->size - start_ptr : tmp_cnt;
185 munge(subd, buf->buf + start_ptr, blk_size);
196 static inline int __handle_event(
struct a4l_buffer * buf)
202 if (test_bit(A4L_BUF_EOA_NR, &buf->flags))
205 if (test_bit(A4L_BUF_ERROR_NR, &buf->flags))
244 static inline int __pre_abs_put(
struct a4l_buffer * buf,
unsigned long count)
246 if (count - buf->tmp_count > buf->size) {
247 set_bit(A4L_BUF_ERROR_NR, &buf->flags);
251 buf->tmp_count = buf->cns_count;
256 static inline int __pre_put(
struct a4l_buffer * buf,
unsigned long count)
258 return __pre_abs_put(buf, buf->tmp_count + count);
261 static inline int __pre_abs_get(
struct a4l_buffer * buf,
unsigned long count)
266 if (buf->tmp_count == 0 || buf->cns_count == 0)
274 if (buf->end_count != 0 && (
long)(count - buf->end_count) > 0)
286 if ((
long)(count - buf->tmp_count) > 0) {
287 set_bit(A4L_BUF_ERROR_NR, &buf->flags);
292 buf->tmp_count = buf->prd_count;
297 static inline int __pre_get(
struct a4l_buffer * buf,
unsigned long count)
299 return __pre_abs_get(buf, buf->tmp_count + count);
302 static inline int __abs_put(
struct a4l_buffer * buf,
unsigned long count)
304 unsigned long old = buf->prd_count;
306 if ((
long)(buf->prd_count - count) >= 0)
309 buf->prd_count = count;
311 if ((old / buf->size) != (count / buf->size))
312 set_bit(A4L_BUF_EOBUF_NR, &buf->flags);
314 if (buf->end_count != 0 && (
long)(count - buf->end_count) >= 0)
315 set_bit(A4L_BUF_EOA_NR, &buf->flags);
320 static inline int __put(
struct a4l_buffer * buf,
unsigned long count)
322 return __abs_put(buf, buf->prd_count + count);
325 static inline int __abs_get(
struct a4l_buffer * buf,
unsigned long count)
327 unsigned long old = buf->cns_count;
329 if ((
long)(buf->cns_count - count) >= 0)
332 buf->cns_count = count;
334 if ((old / buf->size) != count / buf->size)
335 set_bit(A4L_BUF_EOBUF_NR, &buf->flags);
337 if (buf->end_count != 0 && (
long)(count - buf->end_count) >= 0)
338 set_bit(A4L_BUF_EOA_NR, &buf->flags);
343 static inline int __get(
struct a4l_buffer * buf,
unsigned long count)
345 return __abs_get(buf, buf->cns_count + count);
348 static inline unsigned long __count_to_put(
struct a4l_buffer * buf)
352 if ((
long) (buf->size + buf->cns_count - buf->prd_count) > 0)
353 ret = buf->size + buf->cns_count - buf->prd_count;
360 static inline unsigned long __count_to_get(
struct a4l_buffer * buf)
366 if (buf->end_count == 0 || (
long)(buf->end_count - buf->prd_count) > 0)
367 ret = buf->prd_count;
369 ret = buf->end_count;
371 if ((
long)(ret - buf->cns_count) > 0)
372 ret -= buf->cns_count;
379 static inline unsigned long __count_to_end(
struct a4l_buffer * buf)
381 unsigned long ret = buf->end_count - buf->cns_count;
383 if (buf->end_count == 0)
386 return ((
long)ret) < 0 ? 0 : ret;
391 int a4l_alloc_buffer(
struct a4l_buffer *buf_desc,
int buf_size);
393 void a4l_free_buffer(
struct a4l_buffer *buf_desc);
395 void a4l_init_buffer(
struct a4l_buffer * buf_desc);
397 void a4l_cleanup_buffer(
struct a4l_buffer * buf_desc);
399 int a4l_setup_buffer(
struct a4l_device_context *cxt,
struct a4l_cmd_desc *cmd);
401 void a4l_cancel_buffer(
struct a4l_device_context *cxt);
404 unsigned long count);
407 unsigned long count);
410 unsigned long count);
413 unsigned long count);
416 void *bufdata,
unsigned long count);
419 unsigned long count);
422 unsigned long count);
425 unsigned long count);
428 unsigned long count);
431 void *bufdata,
unsigned long count);
433 int a4l_buf_evt(
struct a4l_subdevice *subd,
unsigned long evts);
441 return (subd->
buf) ? subd->
buf->cur_cmd : NULL;
450 int a4l_ioctl_mmap(
struct a4l_device_context * cxt,
void *arg);
451 int a4l_ioctl_bufcfg(
struct a4l_device_context * cxt,
void *arg);
452 int a4l_ioctl_bufcfg2(
struct a4l_device_context * cxt,
void *arg);
453 int a4l_ioctl_bufinfo(
struct a4l_device_context * cxt,
void *arg);
454 int a4l_ioctl_bufinfo2(
struct a4l_device_context * cxt,
void *arg);
455 int a4l_ioctl_poll(
struct a4l_device_context * cxt,
void *arg);
456 ssize_t a4l_read_buffer(
struct a4l_device_context * cxt,
void *bufdata,
size_t nbytes);
457 ssize_t a4l_write_buffer(
struct a4l_device_context * cxt,
const void *bufdata,
size_t nbytes);
458 int a4l_select(
struct a4l_device_context *cxt,
459 rtdm_selector_t *selector,
struct a4l_buffer * buf
Linked buffer.
Definition: subdevice.h:51
Analogy for Linux, context structure / macros declarations.
Structure describing the asynchronous instruction.
Definition: analogy.h:289
Analogy for Linux, subdevice related features.
Real-Time Driver Model for Xenomai, driver API header.
struct a4l_cmd_desc * a4l_get_cmd(struct a4l_subdevice *subd)
Get the current Analogy command descriptor.
Analogy for Linux, Operation system facilities.
rtdm_selecttype
Definition: driver.h:108
Structure describing the subdevice.
Definition: subdevice.h:40
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...
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:171
Analogy for Linux, UAPI bits.
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.