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;
90 static 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);
103 static 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,
136 static 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);
195 static 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))
243 static 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;
255 static inline int __pre_put(
struct a4l_buffer * buf,
unsigned long count)
257 return __pre_abs_put(buf, buf->tmp_count + count);
260 static 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;
296 static inline int __pre_get(
struct a4l_buffer * buf,
unsigned long count)
298 return __pre_abs_get(buf, buf->tmp_count + count);
301 static 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);
319 static inline int __put(
struct a4l_buffer * buf,
unsigned long count)
321 return __abs_put(buf, buf->prd_count + count);
324 static 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);
342 static inline int __get(
struct a4l_buffer * buf,
unsigned long count)
344 return __abs_get(buf, buf->cns_count + count);
347 static 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;
359 static 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;
378 static 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;
390 int a4l_alloc_buffer(
struct a4l_buffer *buf_desc,
int buf_size);
392 void a4l_free_buffer(
struct a4l_buffer *buf_desc);
394 void a4l_init_buffer(
struct a4l_buffer * buf_desc);
396 void a4l_cleanup_buffer(
struct a4l_buffer * buf_desc);
398 int a4l_setup_buffer(
struct a4l_device_context *cxt,
struct a4l_cmd_desc *cmd);
400 void 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);
440 return (subd->
buf) ? subd->
buf->cur_cmd : NULL;
449 int a4l_ioctl_mmap(
struct a4l_device_context * cxt,
void *arg);
450 int a4l_ioctl_bufcfg(
struct a4l_device_context * cxt,
void *arg);
451 int a4l_ioctl_bufcfg2(
struct a4l_device_context * cxt,
void *arg);
452 int a4l_ioctl_bufinfo(
struct a4l_device_context * cxt,
void *arg);
453 int a4l_ioctl_bufinfo2(
struct a4l_device_context * cxt,
void *arg);
454 int a4l_ioctl_poll(
struct a4l_device_context * cxt,
void *arg);
455 ssize_t a4l_read_buffer(
struct a4l_device_context * cxt,
void *bufdata,
size_t nbytes);
456 ssize_t a4l_write_buffer(
struct a4l_device_context * cxt,
const void *bufdata,
size_t nbytes);
457 int a4l_select(
struct a4l_device_context *cxt,
458 rtdm_selector_t *selector,
struct a4l_buffer * buf
Linked buffer.
Definition: subdevice.h:51
Structure describing the asynchronous instruction.
Definition: analogy.h:289
Analogy for Linux, subdevice related features.
Real-Time Driver Model for Xenomai, driver API header.
int a4l_get_chan(struct a4l_subdevice *subd)
Get the channel index according to its type.
Definition: buffer.c:202
int a4l_buf_prepare_put(struct a4l_subdevice *subd, unsigned long count)
Set the count of data which is to be sent to the buffer at the next DMA shot.
Definition: buffer.c:277
struct a4l_cmd_desc * a4l_get_cmd(struct a4l_subdevice *subd)
Get the current Analogy command descriptor.
rtdm_selecttype
Definition: driver.h:111
int a4l_buf_prepare_get(struct a4l_subdevice *subd, unsigned long count)
Set the count of data which is to be sent from the buffer to the device at the next DMA shot...
Definition: buffer.c:352
int a4l_buf_commit_get(struct a4l_subdevice *subd, unsigned long count)
Set the count of data sent from the buffer to the device during the last completed DMA shots...
Definition: buffer.c:365
Structure describing the subdevice.
Definition: subdevice.h:40
int a4l_buf_get(struct a4l_subdevice *subd, void *bufdata, unsigned long count)
Copy some data from the buffer to the device driver.
Definition: buffer.c:380
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 a4l_buf_evt(struct a4l_subdevice *subd, unsigned long evts)
Signal some event(s) to a user-space program involved in some read / write operation.
Definition: buffer.c:407
unsigned long a4l_buf_count(struct a4l_subdevice *subd)
Get the data amount available in the Analogy buffer.
Definition: buffer.c:446
int a4l_buf_prepare_absget(struct a4l_subdevice *subd, unsigned long count)
Update the absolute count of data sent from the buffer to the device since the start of the acquisiti...
Definition: buffer.c:326
int a4l_buf_commit_absput(struct a4l_subdevice *subd, unsigned long count)
Set the absolute count of data which was sent from the device to the buffer since the start of the ac...
Definition: buffer.c:264
int a4l_buf_prepare_absput(struct a4l_subdevice *subd, unsigned long count)
Update the absolute count of data sent from the device to the buffer since the start of the acquisiti...
Definition: buffer.c:250
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:174
Analogy for Linux, UAPI bits.
int a4l_buf_commit_put(struct a4l_subdevice *subd, unsigned long count)
Set the count of data sent to the buffer during the last completed DMA shots.
Definition: buffer.c:290
int a4l_buf_put(struct a4l_subdevice *subd, void *bufdata, unsigned long count)
Copy some data from the device driver to the buffer.
Definition: buffer.c:303
int a4l_buf_commit_absget(struct a4l_subdevice *subd, unsigned long count)
Set the absolute count of data which was sent from the buffer to the device since the start of the ac...
Definition: buffer.c:339
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 ...