Lines Matching full:fifo

3  * A generic kernel FIFO implementation
17 * internal helper to calculate the unused elements in a fifo
19 static inline unsigned int kfifo_unused(struct __kfifo *fifo) in kfifo_unused() argument
21 return (fifo->mask + 1) - (fifo->in - fifo->out); in kfifo_unused()
24 int __kfifo_alloc(struct __kfifo *fifo, unsigned int size, in __kfifo_alloc() argument
33 fifo->in = 0; in __kfifo_alloc()
34 fifo->out = 0; in __kfifo_alloc()
35 fifo->esize = esize; in __kfifo_alloc()
38 fifo->data = NULL; in __kfifo_alloc()
39 fifo->mask = 0; in __kfifo_alloc()
43 fifo->data = kmalloc_array(esize, size, gfp_mask); in __kfifo_alloc()
45 if (!fifo->data) { in __kfifo_alloc()
46 fifo->mask = 0; in __kfifo_alloc()
49 fifo->mask = size - 1; in __kfifo_alloc()
55 void __kfifo_free(struct __kfifo *fifo) in __kfifo_free() argument
57 kfree(fifo->data); in __kfifo_free()
58 fifo->in = 0; in __kfifo_free()
59 fifo->out = 0; in __kfifo_free()
60 fifo->esize = 0; in __kfifo_free()
61 fifo->data = NULL; in __kfifo_free()
62 fifo->mask = 0; in __kfifo_free()
66 int __kfifo_init(struct __kfifo *fifo, void *buffer, in __kfifo_init() argument
74 fifo->in = 0; in __kfifo_init()
75 fifo->out = 0; in __kfifo_init()
76 fifo->esize = esize; in __kfifo_init()
77 fifo->data = buffer; in __kfifo_init()
80 fifo->mask = 0; in __kfifo_init()
83 fifo->mask = size - 1; in __kfifo_init()
89 static void kfifo_copy_in(struct __kfifo *fifo, const void *src, in kfifo_copy_in() argument
92 unsigned int size = fifo->mask + 1; in kfifo_copy_in()
93 unsigned int esize = fifo->esize; in kfifo_copy_in()
96 off &= fifo->mask; in kfifo_copy_in()
104 memcpy(fifo->data + off, src, l); in kfifo_copy_in()
105 memcpy(fifo->data, src + l, len - l); in kfifo_copy_in()
107 * make sure that the data in the fifo is up to date before in kfifo_copy_in()
108 * incrementing the fifo->in index counter in kfifo_copy_in()
113 unsigned int __kfifo_in(struct __kfifo *fifo, in __kfifo_in() argument
118 l = kfifo_unused(fifo); in __kfifo_in()
122 kfifo_copy_in(fifo, buf, len, fifo->in); in __kfifo_in()
123 fifo->in += len; in __kfifo_in()
128 static void kfifo_copy_out(struct __kfifo *fifo, void *dst, in kfifo_copy_out() argument
131 unsigned int size = fifo->mask + 1; in kfifo_copy_out()
132 unsigned int esize = fifo->esize; in kfifo_copy_out()
135 off &= fifo->mask; in kfifo_copy_out()
143 memcpy(dst, fifo->data + off, l); in kfifo_copy_out()
144 memcpy(dst + l, fifo->data, len - l); in kfifo_copy_out()
147 * incrementing the fifo->out index counter in kfifo_copy_out()
152 unsigned int __kfifo_out_peek(struct __kfifo *fifo, in __kfifo_out_peek() argument
157 l = fifo->in - fifo->out; in __kfifo_out_peek()
161 kfifo_copy_out(fifo, buf, len, fifo->out); in __kfifo_out_peek()
166 unsigned int __kfifo_out(struct __kfifo *fifo, in __kfifo_out() argument
169 len = __kfifo_out_peek(fifo, buf, len); in __kfifo_out()
170 fifo->out += len; in __kfifo_out()
175 static unsigned long kfifo_copy_from_user(struct __kfifo *fifo, in kfifo_copy_from_user() argument
179 unsigned int size = fifo->mask + 1; in kfifo_copy_from_user()
180 unsigned int esize = fifo->esize; in kfifo_copy_from_user()
184 off &= fifo->mask; in kfifo_copy_from_user()
192 ret = copy_from_user(fifo->data + off, from, l); in kfifo_copy_from_user()
196 ret = copy_from_user(fifo->data, from + l, len - l); in kfifo_copy_from_user()
201 * make sure that the data in the fifo is up to date before in kfifo_copy_from_user()
202 * incrementing the fifo->in index counter in kfifo_copy_from_user()
210 int __kfifo_from_user(struct __kfifo *fifo, const void __user *from, in __kfifo_from_user() argument
215 unsigned int esize = fifo->esize; in __kfifo_from_user()
221 l = kfifo_unused(fifo); in __kfifo_from_user()
225 ret = kfifo_copy_from_user(fifo, from, len, fifo->in, copied); in __kfifo_from_user()
231 fifo->in += len; in __kfifo_from_user()
236 static unsigned long kfifo_copy_to_user(struct __kfifo *fifo, void __user *to, in kfifo_copy_to_user() argument
241 unsigned int size = fifo->mask + 1; in kfifo_copy_to_user()
242 unsigned int esize = fifo->esize; in kfifo_copy_to_user()
244 off &= fifo->mask; in kfifo_copy_to_user()
252 ret = copy_to_user(to, fifo->data + off, l); in kfifo_copy_to_user()
256 ret = copy_to_user(to + l, fifo->data, len - l); in kfifo_copy_to_user()
262 * incrementing the fifo->out index counter in kfifo_copy_to_user()
270 int __kfifo_to_user(struct __kfifo *fifo, void __user *to, in __kfifo_to_user() argument
275 unsigned int esize = fifo->esize; in __kfifo_to_user()
281 l = fifo->in - fifo->out; in __kfifo_to_user()
284 ret = kfifo_copy_to_user(fifo, to, len, fifo->out, copied); in __kfifo_to_user()
290 fifo->out += len; in __kfifo_to_user()
334 static unsigned int setup_sgl(struct __kfifo *fifo, struct scatterlist *sgl, in setup_sgl() argument
337 unsigned int size = fifo->mask + 1; in setup_sgl()
338 unsigned int esize = fifo->esize; in setup_sgl()
342 off &= fifo->mask; in setup_sgl()
350 n = setup_sgl_buf(sgl, fifo->data + off, nents, l); in setup_sgl()
351 n += setup_sgl_buf(sgl + n, fifo->data, nents - n, len - l); in setup_sgl()
356 unsigned int __kfifo_dma_in_prepare(struct __kfifo *fifo, in __kfifo_dma_in_prepare() argument
361 l = kfifo_unused(fifo); in __kfifo_dma_in_prepare()
365 return setup_sgl(fifo, sgl, nents, len, fifo->in); in __kfifo_dma_in_prepare()
369 unsigned int __kfifo_dma_out_prepare(struct __kfifo *fifo, in __kfifo_dma_out_prepare() argument
374 l = fifo->in - fifo->out; in __kfifo_dma_out_prepare()
378 return setup_sgl(fifo, sgl, nents, len, fifo->out); in __kfifo_dma_out_prepare()
396 * the next record in the fifo
398 static unsigned int __kfifo_peek_n(struct __kfifo *fifo, size_t recsize) in __kfifo_peek_n() argument
401 unsigned int mask = fifo->mask; in __kfifo_peek_n()
402 unsigned char *data = fifo->data; in __kfifo_peek_n()
404 l = __KFIFO_PEEK(data, fifo->out, mask); in __kfifo_peek_n()
407 l |= __KFIFO_PEEK(data, fifo->out + 1, mask) << 8; in __kfifo_peek_n()
419 * the record into the fifo
421 static void __kfifo_poke_n(struct __kfifo *fifo, unsigned int n, size_t recsize) in __kfifo_poke_n() argument
423 unsigned int mask = fifo->mask; in __kfifo_poke_n()
424 unsigned char *data = fifo->data; in __kfifo_poke_n()
426 __KFIFO_POKE(data, fifo->in, mask, n); in __kfifo_poke_n()
429 __KFIFO_POKE(data, fifo->in + 1, mask, n >> 8); in __kfifo_poke_n()
432 unsigned int __kfifo_len_r(struct __kfifo *fifo, size_t recsize) in __kfifo_len_r() argument
434 return __kfifo_peek_n(fifo, recsize); in __kfifo_len_r()
438 unsigned int __kfifo_in_r(struct __kfifo *fifo, const void *buf, in __kfifo_in_r() argument
441 if (len + recsize > kfifo_unused(fifo)) in __kfifo_in_r()
444 __kfifo_poke_n(fifo, len, recsize); in __kfifo_in_r()
446 kfifo_copy_in(fifo, buf, len, fifo->in + recsize); in __kfifo_in_r()
447 fifo->in += len + recsize; in __kfifo_in_r()
452 static unsigned int kfifo_out_copy_r(struct __kfifo *fifo, in kfifo_out_copy_r() argument
455 *n = __kfifo_peek_n(fifo, recsize); in kfifo_out_copy_r()
460 kfifo_copy_out(fifo, buf, len, fifo->out + recsize); in kfifo_out_copy_r()
464 unsigned int __kfifo_out_peek_r(struct __kfifo *fifo, void *buf, in __kfifo_out_peek_r() argument
469 if (fifo->in == fifo->out) in __kfifo_out_peek_r()
472 return kfifo_out_copy_r(fifo, buf, len, recsize, &n); in __kfifo_out_peek_r()
476 unsigned int __kfifo_out_r(struct __kfifo *fifo, void *buf, in __kfifo_out_r() argument
481 if (fifo->in == fifo->out) in __kfifo_out_r()
484 len = kfifo_out_copy_r(fifo, buf, len, recsize, &n); in __kfifo_out_r()
485 fifo->out += n + recsize; in __kfifo_out_r()
490 void __kfifo_skip_r(struct __kfifo *fifo, size_t recsize) in __kfifo_skip_r() argument
494 n = __kfifo_peek_n(fifo, recsize); in __kfifo_skip_r()
495 fifo->out += n + recsize; in __kfifo_skip_r()
499 int __kfifo_from_user_r(struct __kfifo *fifo, const void __user *from, in __kfifo_from_user_r() argument
506 if (len + recsize > kfifo_unused(fifo)) { in __kfifo_from_user_r()
511 __kfifo_poke_n(fifo, len, recsize); in __kfifo_from_user_r()
513 ret = kfifo_copy_from_user(fifo, from, len, fifo->in + recsize, copied); in __kfifo_from_user_r()
518 fifo->in += len + recsize; in __kfifo_from_user_r()
523 int __kfifo_to_user_r(struct __kfifo *fifo, void __user *to, in __kfifo_to_user_r() argument
529 if (fifo->in == fifo->out) { in __kfifo_to_user_r()
534 n = __kfifo_peek_n(fifo, recsize); in __kfifo_to_user_r()
538 ret = kfifo_copy_to_user(fifo, to, len, fifo->out + recsize, copied); in __kfifo_to_user_r()
543 fifo->out += n + recsize; in __kfifo_to_user_r()
548 unsigned int __kfifo_dma_in_prepare_r(struct __kfifo *fifo, in __kfifo_dma_in_prepare_r() argument
555 if (len + recsize > kfifo_unused(fifo)) in __kfifo_dma_in_prepare_r()
558 return setup_sgl(fifo, sgl, nents, len, fifo->in + recsize); in __kfifo_dma_in_prepare_r()
562 void __kfifo_dma_in_finish_r(struct __kfifo *fifo, in __kfifo_dma_in_finish_r() argument
566 __kfifo_poke_n(fifo, len, recsize); in __kfifo_dma_in_finish_r()
567 fifo->in += len + recsize; in __kfifo_dma_in_finish_r()
571 unsigned int __kfifo_dma_out_prepare_r(struct __kfifo *fifo, in __kfifo_dma_out_prepare_r() argument
578 if (len + recsize > fifo->in - fifo->out) in __kfifo_dma_out_prepare_r()
581 return setup_sgl(fifo, sgl, nents, len, fifo->out + recsize); in __kfifo_dma_out_prepare_r()
585 void __kfifo_dma_out_finish_r(struct __kfifo *fifo, size_t recsize) in __kfifo_dma_out_finish_r() argument
589 len = __kfifo_peek_n(fifo, recsize); in __kfifo_dma_out_finish_r()
590 fifo->out += len + recsize; in __kfifo_dma_out_finish_r()