1 #include <linux/version.h>
2 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36))
3 #include_next <linux/kfifo.h>
6 * A generic kernel FIFO implementation
8 * Copyright (C) 2009/2010 Stefani Seibold <stefani@seibold.net>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #ifndef _LINUX_KFIFO_H
27 #define _LINUX_KFIFO_H
30 * How to porting drivers to the new generic FIFO API:
32 * - Modify the declaration of the "struct kfifo *" object into a
33 * in-place "struct kfifo" object
34 * - Init the in-place object with kfifo_alloc() or kfifo_init()
35 * Note: The address of the in-place "struct kfifo" object must be
36 * passed as the first argument to this functions
37 * - Replace the use of __kfifo_put into kfifo_in and __kfifo_get
39 * - Replace the use of kfifo_put into kfifo_in_spinlocked and kfifo_get
40 * into kfifo_out_spinlocked
41 * Note: the spinlock pointer formerly passed to kfifo_init/kfifo_alloc
42 * must be passed now to the kfifo_in_spinlocked and kfifo_out_spinlocked
43 * as the last parameter
44 * - The formerly __kfifo_* functions are renamed into kfifo_*
48 * Note about locking : There is no locking required until only * one reader
49 * and one writer is using the fifo and no kfifo_reset() will be * called
50 * kfifo_reset_out() can be safely used, until it will be only called
51 * in the reader thread.
52 * For multiple writer and one reader there is only a need to lock the writer.
53 * And vice versa for only one writer and multiple reader there is only a need
57 #include <linux/kernel.h>
58 #include <linux/spinlock.h>
59 #include <linux/stddef.h>
60 #include <linux/scatterlist.h>
70 #define __STRUCT_KFIFO_COMMON(datatype, recsize, ptrtype) \
72 struct __kfifo kfifo; \
74 char (*rectype)[recsize]; \
76 const ptrtype *ptr_const; \
79 #define __STRUCT_KFIFO(type, size, recsize, ptrtype) \
81 __STRUCT_KFIFO_COMMON(type, recsize, ptrtype); \
82 type buf[((size < 2) || (size & (size - 1))) ? -1 : size]; \
85 #define STRUCT_KFIFO(type, size) \
86 struct __STRUCT_KFIFO(type, size, 0, type)
88 #define __STRUCT_KFIFO_PTR(type, recsize, ptrtype) \
90 __STRUCT_KFIFO_COMMON(type, recsize, ptrtype); \
94 #define STRUCT_KFIFO_PTR(type) \
95 struct __STRUCT_KFIFO_PTR(type, 0, type)
98 * define compatibility "struct kfifo" for dynamic allocated fifos
100 struct kfifo __STRUCT_KFIFO_PTR(unsigned char, 0, void);
102 #define STRUCT_KFIFO_REC_1(size) \
103 struct __STRUCT_KFIFO(unsigned char, size, 1, void)
105 #define STRUCT_KFIFO_REC_2(size) \
106 struct __STRUCT_KFIFO(unsigned char, size, 2, void)
109 * define kfifo_rec types
111 struct kfifo_rec_ptr_1 __STRUCT_KFIFO_PTR(unsigned char, 1, void);
112 struct kfifo_rec_ptr_2 __STRUCT_KFIFO_PTR(unsigned char, 2, void);
115 * helper macro to distinguish between real in place fifo where the fifo
116 * array is a part of the structure and the fifo type where the array is
117 * outside of the fifo structure.
119 #define __is_kfifo_ptr(fifo) (sizeof(*fifo) == sizeof(struct __kfifo))
122 * DECLARE_KFIFO_PTR - macro to declare a fifo pointer object
123 * @fifo: name of the declared fifo
124 * @type: type of the fifo elements
126 #define DECLARE_KFIFO_PTR(fifo, type) STRUCT_KFIFO_PTR(type) fifo
129 * DECLARE_KFIFO - macro to declare a fifo object
130 * @fifo: name of the declared fifo
131 * @type: type of the fifo elements
132 * @size: the number of elements in the fifo, this must be a power of 2
134 #define DECLARE_KFIFO(fifo, type, size) STRUCT_KFIFO(type, size) fifo
137 * INIT_KFIFO - Initialize a fifo declared by DECLARE_KFIFO
138 * @fifo: name of the declared fifo datatype
140 #define INIT_KFIFO(fifo) \
142 typeof(&(fifo)) __tmp = &(fifo); \
143 struct __kfifo *__kfifo = &__tmp->kfifo; \
146 __kfifo->mask = __is_kfifo_ptr(__tmp) ? 0 : ARRAY_SIZE(__tmp->buf) - 1;\
147 __kfifo->esize = sizeof(*__tmp->buf); \
148 __kfifo->data = __is_kfifo_ptr(__tmp) ? NULL : __tmp->buf; \
152 * DEFINE_KFIFO - macro to define and initialize a fifo
153 * @fifo: name of the declared fifo datatype
154 * @type: type of the fifo elements
155 * @size: the number of elements in the fifo, this must be a power of 2
157 * Note: the macro can be used for global and local fifo data type variables.
159 #define DEFINE_KFIFO(fifo, type, size) \
160 DECLARE_KFIFO(fifo, type, size) = \
166 .mask = __is_kfifo_ptr(&(fifo)) ? \
168 ARRAY_SIZE((fifo).buf) - 1, \
169 .esize = sizeof(*(fifo).buf), \
170 .data = __is_kfifo_ptr(&(fifo)) ? \
178 static inline unsigned int __must_check
179 __kfifo_uint_must_check_helper(unsigned int val)
184 static inline int __must_check
185 __kfifo_int_must_check_helper(int val)
191 * kfifo_initialized - Check if the fifo is initialized
192 * @fifo: address of the fifo to check
194 * Return %true if fifo is initialized, otherwise %false.
195 * Assumes the fifo was 0 before.
197 #define kfifo_initialized(fifo) ((fifo)->kfifo.mask)
200 * kfifo_esize - returns the size of the element managed by the fifo
201 * @fifo: address of the fifo to be used
203 #define kfifo_esize(fifo) ((fifo)->kfifo.esize)
206 * kfifo_recsize - returns the size of the record length field
207 * @fifo: address of the fifo to be used
209 #define kfifo_recsize(fifo) (sizeof(*(fifo)->rectype))
212 * kfifo_size - returns the size of the fifo in elements
213 * @fifo: address of the fifo to be used
215 #define kfifo_size(fifo) ((fifo)->kfifo.mask + 1)
218 * kfifo_reset - removes the entire fifo content
219 * @fifo: address of the fifo to be used
221 * Note: usage of kfifo_reset() is dangerous. It should be only called when the
222 * fifo is exclusived locked or when it is secured that no other thread is
223 * accessing the fifo.
225 #define kfifo_reset(fifo) \
227 typeof((fifo) + 1) __tmp = (fifo); \
228 __tmp->kfifo.in = __tmp->kfifo.out = 0; \
232 * kfifo_reset_out - skip fifo content
233 * @fifo: address of the fifo to be used
235 * Note: The usage of kfifo_reset_out() is safe until it will be only called
236 * from the reader thread and there is only one concurrent reader. Otherwise
237 * it is dangerous and must be handled in the same way as kfifo_reset().
239 #define kfifo_reset_out(fifo) \
241 typeof((fifo) + 1) __tmp = (fifo); \
242 __tmp->kfifo.out = __tmp->kfifo.in; \
246 * kfifo_len - returns the number of used elements in the fifo
247 * @fifo: address of the fifo to be used
249 #define kfifo_len(fifo) \
251 typeof((fifo) + 1) __tmpl = (fifo); \
252 __tmpl->kfifo.in - __tmpl->kfifo.out; \
256 * kfifo_is_empty - returns true if the fifo is empty
257 * @fifo: address of the fifo to be used
259 #define kfifo_is_empty(fifo) \
261 typeof((fifo) + 1) __tmpq = (fifo); \
262 __tmpq->kfifo.in == __tmpq->kfifo.out; \
266 * kfifo_is_full - returns true if the fifo is full
267 * @fifo: address of the fifo to be used
269 #define kfifo_is_full(fifo) \
271 typeof((fifo) + 1) __tmpq = (fifo); \
272 kfifo_len(__tmpq) > __tmpq->kfifo.mask; \
276 * kfifo_avail - returns the number of unused elements in the fifo
277 * @fifo: address of the fifo to be used
279 #define kfifo_avail(fifo) \
280 __kfifo_uint_must_check_helper( \
282 typeof((fifo) + 1) __tmpq = (fifo); \
283 const size_t __recsize = sizeof(*__tmpq->rectype); \
284 unsigned int __avail = kfifo_size(__tmpq) - kfifo_len(__tmpq); \
285 (__recsize) ? ((__avail <= __recsize) ? 0 : \
286 __kfifo_max_r(__avail - __recsize, __recsize)) : \
292 * kfifo_skip - skip output data
293 * @fifo: address of the fifo to be used
295 #define kfifo_skip(fifo) \
297 typeof((fifo) + 1) __tmp = (fifo); \
298 const size_t __recsize = sizeof(*__tmp->rectype); \
299 struct __kfifo *__kfifo = &__tmp->kfifo; \
301 __kfifo_skip_r(__kfifo, __recsize); \
307 * kfifo_peek_len - gets the size of the next fifo record
308 * @fifo: address of the fifo to be used
310 * This function returns the size of the next fifo record in number of bytes.
312 #define kfifo_peek_len(fifo) \
313 __kfifo_uint_must_check_helper( \
315 typeof((fifo) + 1) __tmp = (fifo); \
316 const size_t __recsize = sizeof(*__tmp->rectype); \
317 struct __kfifo *__kfifo = &__tmp->kfifo; \
318 (!__recsize) ? kfifo_len(__tmp) * sizeof(*__tmp->type) : \
319 __kfifo_len_r(__kfifo, __recsize); \
324 * kfifo_alloc - dynamically allocates a new fifo buffer
325 * @fifo: pointer to the fifo
326 * @size: the number of elements in the fifo, this must be a power of 2
327 * @gfp_mask: get_free_pages mask, passed to kmalloc()
329 * This macro dynamically allocates a new fifo buffer.
331 * The numer of elements will be rounded-up to a power of 2.
332 * The fifo will be release with kfifo_free().
333 * Return 0 if no error, otherwise an error code.
335 #define kfifo_alloc(fifo, size, gfp_mask) \
336 __kfifo_int_must_check_helper( \
338 typeof((fifo) + 1) __tmp = (fifo); \
339 struct __kfifo *__kfifo = &__tmp->kfifo; \
340 __is_kfifo_ptr(__tmp) ? \
341 __kfifo_alloc(__kfifo, size, sizeof(*__tmp->type), gfp_mask) : \
347 * kfifo_free - frees the fifo
348 * @fifo: the fifo to be freed
350 #define kfifo_free(fifo) \
352 typeof((fifo) + 1) __tmp = (fifo); \
353 struct __kfifo *__kfifo = &__tmp->kfifo; \
354 if (__is_kfifo_ptr(__tmp)) \
355 __kfifo_free(__kfifo); \
359 * kfifo_init - initialize a fifo using a preallocated buffer
360 * @fifo: the fifo to assign the buffer
361 * @buffer: the preallocated buffer to be used
362 * @size: the size of the internal buffer, this have to be a power of 2
364 * This macro initialize a fifo using a preallocated buffer.
366 * The numer of elements will be rounded-up to a power of 2.
367 * Return 0 if no error, otherwise an error code.
369 #define kfifo_init(fifo, buffer, size) \
371 typeof((fifo) + 1) __tmp = (fifo); \
372 struct __kfifo *__kfifo = &__tmp->kfifo; \
373 __is_kfifo_ptr(__tmp) ? \
374 __kfifo_init(__kfifo, buffer, size, sizeof(*__tmp->type)) : \
379 * kfifo_put - put data into the fifo
380 * @fifo: address of the fifo to be used
381 * @val: the data to be added
383 * This macro copies the given value into the fifo.
384 * It returns 0 if the fifo was full. Otherwise it returns the number
385 * processed elements.
387 * Note that with only one concurrent reader and one concurrent
388 * writer, you don't need extra locking to use these macro.
390 #define kfifo_put(fifo, val) \
392 typeof((fifo) + 1) __tmp = (fifo); \
393 typeof((val) + 1) __val = (val); \
394 unsigned int __ret; \
395 const size_t __recsize = sizeof(*__tmp->rectype); \
396 struct __kfifo *__kfifo = &__tmp->kfifo; \
398 typeof(__tmp->ptr_const) __dummy __attribute__ ((unused)); \
399 __dummy = (typeof(__val))NULL; \
402 __ret = __kfifo_in_r(__kfifo, __val, sizeof(*__val), \
405 __ret = !kfifo_is_full(__tmp); \
407 (__is_kfifo_ptr(__tmp) ? \
408 ((typeof(__tmp->type))__kfifo->data) : \
410 )[__kfifo->in & __tmp->kfifo.mask] = \
411 *(typeof(__tmp->type))__val; \
420 * kfifo_get - get data from the fifo
421 * @fifo: address of the fifo to be used
422 * @val: the var where to store the data to be added
424 * This macro reads the data from the fifo.
425 * It returns 0 if the fifo was empty. Otherwise it returns the number
426 * processed elements.
428 * Note that with only one concurrent reader and one concurrent
429 * writer, you don't need extra locking to use these macro.
431 #define kfifo_get(fifo, val) \
432 __kfifo_uint_must_check_helper( \
434 typeof((fifo) + 1) __tmp = (fifo); \
435 typeof((val) + 1) __val = (val); \
436 unsigned int __ret; \
437 const size_t __recsize = sizeof(*__tmp->rectype); \
438 struct __kfifo *__kfifo = &__tmp->kfifo; \
440 __val = (typeof(__tmp->ptr))0; \
442 __ret = __kfifo_out_r(__kfifo, __val, sizeof(*__val), \
445 __ret = !kfifo_is_empty(__tmp); \
447 *(typeof(__tmp->type))__val = \
448 (__is_kfifo_ptr(__tmp) ? \
449 ((typeof(__tmp->type))__kfifo->data) : \
451 )[__kfifo->out & __tmp->kfifo.mask]; \
461 * kfifo_peek - get data from the fifo without removing
462 * @fifo: address of the fifo to be used
463 * @val: the var where to store the data to be added
465 * This reads the data from the fifo without removing it from the fifo.
466 * It returns 0 if the fifo was empty. Otherwise it returns the number
467 * processed elements.
469 * Note that with only one concurrent reader and one concurrent
470 * writer, you don't need extra locking to use these macro.
472 #define kfifo_peek(fifo, val) \
473 __kfifo_uint_must_check_helper( \
475 typeof((fifo) + 1) __tmp = (fifo); \
476 typeof((val) + 1) __val = (val); \
477 unsigned int __ret; \
478 const size_t __recsize = sizeof(*__tmp->rectype); \
479 struct __kfifo *__kfifo = &__tmp->kfifo; \
481 __val = (typeof(__tmp->ptr))NULL; \
483 __ret = __kfifo_out_peek_r(__kfifo, __val, sizeof(*__val), \
486 __ret = !kfifo_is_empty(__tmp); \
488 *(typeof(__tmp->type))__val = \
489 (__is_kfifo_ptr(__tmp) ? \
490 ((typeof(__tmp->type))__kfifo->data) : \
492 )[__kfifo->out & __tmp->kfifo.mask]; \
501 * kfifo_in - put data into the fifo
502 * @fifo: address of the fifo to be used
503 * @buf: the data to be added
504 * @n: number of elements to be added
506 * This macro copies the given buffer into the fifo and returns the
507 * number of copied elements.
509 * Note that with only one concurrent reader and one concurrent
510 * writer, you don't need extra locking to use these macro.
512 #define kfifo_in(fifo, buf, n) \
514 typeof((fifo) + 1) __tmp = (fifo); \
515 typeof((buf) + 1) __buf = (buf); \
516 unsigned long __n = (n); \
517 const size_t __recsize = sizeof(*__tmp->rectype); \
518 struct __kfifo *__kfifo = &__tmp->kfifo; \
520 typeof(__tmp->ptr_const) __dummy __attribute__ ((unused)); \
521 __dummy = (typeof(__buf))NULL; \
524 __kfifo_in_r(__kfifo, __buf, __n, __recsize) : \
525 __kfifo_in(__kfifo, __buf, __n); \
529 * kfifo_in_spinlocked - put data into the fifo using a spinlock for locking
530 * @fifo: address of the fifo to be used
531 * @buf: the data to be added
532 * @n: number of elements to be added
533 * @lock: pointer to the spinlock to use for locking
535 * This macro copies the given values buffer into the fifo and returns the
536 * number of copied elements.
538 #define kfifo_in_spinlocked(fifo, buf, n, lock) \
540 unsigned long __flags; \
541 unsigned int __ret; \
542 spin_lock_irqsave(lock, __flags); \
543 __ret = kfifo_in(fifo, buf, n); \
544 spin_unlock_irqrestore(lock, __flags); \
548 /* alias for kfifo_in_spinlocked, will be removed in a future release */
549 #define kfifo_in_locked(fifo, buf, n, lock) \
550 kfifo_in_spinlocked(fifo, buf, n, lock)
553 * kfifo_out - get data from the fifo
554 * @fifo: address of the fifo to be used
555 * @buf: pointer to the storage buffer
556 * @n: max. number of elements to get
558 * This macro get some data from the fifo and return the numbers of elements
561 * Note that with only one concurrent reader and one concurrent
562 * writer, you don't need extra locking to use these macro.
564 #define kfifo_out(fifo, buf, n) \
565 __kfifo_uint_must_check_helper( \
567 typeof((fifo) + 1) __tmp = (fifo); \
568 typeof((buf) + 1) __buf = (buf); \
569 unsigned long __n = (n); \
570 const size_t __recsize = sizeof(*__tmp->rectype); \
571 struct __kfifo *__kfifo = &__tmp->kfifo; \
573 typeof(__tmp->ptr) __dummy = NULL; \
577 __kfifo_out_r(__kfifo, __buf, __n, __recsize) : \
578 __kfifo_out(__kfifo, __buf, __n); \
583 * kfifo_out_spinlocked - get data from the fifo using a spinlock for locking
584 * @fifo: address of the fifo to be used
585 * @buf: pointer to the storage buffer
586 * @n: max. number of elements to get
587 * @lock: pointer to the spinlock to use for locking
589 * This macro get the data from the fifo and return the numbers of elements
592 #define kfifo_out_spinlocked(fifo, buf, n, lock) \
593 __kfifo_uint_must_check_helper( \
595 unsigned long __flags; \
596 unsigned int __ret; \
597 spin_lock_irqsave(lock, __flags); \
598 __ret = kfifo_out(fifo, buf, n); \
599 spin_unlock_irqrestore(lock, __flags); \
604 /* alias for kfifo_out_spinlocked, will be removed in a future release */
605 #define kfifo_out_locked(fifo, buf, n, lock) \
606 kfifo_out_spinlocked(fifo, buf, n, lock)
609 * kfifo_from_user - puts some data from user space into the fifo
610 * @fifo: address of the fifo to be used
611 * @from: pointer to the data to be added
612 * @len: the length of the data to be added
613 * @copied: pointer to output variable to store the number of copied bytes
615 * This macro copies at most @len bytes from the @from into the
616 * fifo, depending of the available space and returns -EFAULT/0.
618 * Note that with only one concurrent reader and one concurrent
619 * writer, you don't need extra locking to use these macro.
621 #define kfifo_from_user(fifo, from, len, copied) \
622 __kfifo_uint_must_check_helper( \
624 typeof((fifo) + 1) __tmp = (fifo); \
625 const void __user *__from = (from); \
626 unsigned int __len = (len); \
627 unsigned int *__copied = (copied); \
628 const size_t __recsize = sizeof(*__tmp->rectype); \
629 struct __kfifo *__kfifo = &__tmp->kfifo; \
631 __kfifo_from_user_r(__kfifo, __from, __len, __copied, __recsize) : \
632 __kfifo_from_user(__kfifo, __from, __len, __copied); \
637 * kfifo_to_user - copies data from the fifo into user space
638 * @fifo: address of the fifo to be used
639 * @to: where the data must be copied
640 * @len: the size of the destination buffer
641 * @copied: pointer to output variable to store the number of copied bytes
643 * This macro copies at most @len bytes from the fifo into the
644 * @to buffer and returns -EFAULT/0.
646 * Note that with only one concurrent reader and one concurrent
647 * writer, you don't need extra locking to use these macro.
649 #define kfifo_to_user(fifo, to, len, copied) \
650 __kfifo_uint_must_check_helper( \
652 typeof((fifo) + 1) __tmp = (fifo); \
653 void __user *__to = (to); \
654 unsigned int __len = (len); \
655 unsigned int *__copied = (copied); \
656 const size_t __recsize = sizeof(*__tmp->rectype); \
657 struct __kfifo *__kfifo = &__tmp->kfifo; \
659 __kfifo_to_user_r(__kfifo, __to, __len, __copied, __recsize) : \
660 __kfifo_to_user(__kfifo, __to, __len, __copied); \
665 * kfifo_dma_in_prepare - setup a scatterlist for DMA input
666 * @fifo: address of the fifo to be used
667 * @sgl: pointer to the scatterlist array
668 * @nents: number of entries in the scatterlist array
669 * @len: number of elements to transfer
671 * This macro fills a scatterlist for DMA input.
672 * It returns the number entries in the scatterlist array.
674 * Note that with only one concurrent reader and one concurrent
675 * writer, you don't need extra locking to use these macros.
677 #define kfifo_dma_in_prepare(fifo, sgl, nents, len) \
679 typeof((fifo) + 1) __tmp = (fifo); \
680 struct scatterlist *__sgl = (sgl); \
681 int __nents = (nents); \
682 unsigned int __len = (len); \
683 const size_t __recsize = sizeof(*__tmp->rectype); \
684 struct __kfifo *__kfifo = &__tmp->kfifo; \
686 __kfifo_dma_in_prepare_r(__kfifo, __sgl, __nents, __len, __recsize) : \
687 __kfifo_dma_in_prepare(__kfifo, __sgl, __nents, __len); \
691 * kfifo_dma_in_finish - finish a DMA IN operation
692 * @fifo: address of the fifo to be used
693 * @len: number of bytes to received
695 * This macro finish a DMA IN operation. The in counter will be updated by
696 * the len parameter. No error checking will be done.
698 * Note that with only one concurrent reader and one concurrent
699 * writer, you don't need extra locking to use these macros.
701 #define kfifo_dma_in_finish(fifo, len) \
703 typeof((fifo) + 1) __tmp = (fifo); \
704 unsigned int __len = (len); \
705 const size_t __recsize = sizeof(*__tmp->rectype); \
706 struct __kfifo *__kfifo = &__tmp->kfifo; \
708 __kfifo_dma_in_finish_r(__kfifo, __len, __recsize); \
710 __kfifo->in += __len / sizeof(*__tmp->type); \
714 * kfifo_dma_out_prepare - setup a scatterlist for DMA output
715 * @fifo: address of the fifo to be used
716 * @sgl: pointer to the scatterlist array
717 * @nents: number of entries in the scatterlist array
718 * @len: number of elements to transfer
720 * This macro fills a scatterlist for DMA output which at most @len bytes
722 * It returns the number entries in the scatterlist array.
723 * A zero means there is no space available and the scatterlist is not filled.
725 * Note that with only one concurrent reader and one concurrent
726 * writer, you don't need extra locking to use these macros.
728 #define kfifo_dma_out_prepare(fifo, sgl, nents, len) \
730 typeof((fifo) + 1) __tmp = (fifo); \
731 struct scatterlist *__sgl = (sgl); \
732 int __nents = (nents); \
733 unsigned int __len = (len); \
734 const size_t __recsize = sizeof(*__tmp->rectype); \
735 struct __kfifo *__kfifo = &__tmp->kfifo; \
737 __kfifo_dma_out_prepare_r(__kfifo, __sgl, __nents, __len, __recsize) : \
738 __kfifo_dma_out_prepare(__kfifo, __sgl, __nents, __len); \
742 * kfifo_dma_out_finish - finish a DMA OUT operation
743 * @fifo: address of the fifo to be used
744 * @len: number of bytes transferd
746 * This macro finish a DMA OUT operation. The out counter will be updated by
747 * the len parameter. No error checking will be done.
749 * Note that with only one concurrent reader and one concurrent
750 * writer, you don't need extra locking to use these macros.
752 #define kfifo_dma_out_finish(fifo, len) \
754 typeof((fifo) + 1) __tmp = (fifo); \
755 unsigned int __len = (len); \
756 const size_t __recsize = sizeof(*__tmp->rectype); \
757 struct __kfifo *__kfifo = &__tmp->kfifo; \
759 __kfifo_dma_out_finish_r(__kfifo, __recsize); \
761 __kfifo->out += __len / sizeof(*__tmp->type); \
765 * kfifo_out_peek - gets some data from the fifo
766 * @fifo: address of the fifo to be used
767 * @buf: pointer to the storage buffer
768 * @n: max. number of elements to get
770 * This macro get the data from the fifo and return the numbers of elements
771 * copied. The data is not removed from the fifo.
773 * Note that with only one concurrent reader and one concurrent
774 * writer, you don't need extra locking to use these macro.
776 #define kfifo_out_peek(fifo, buf, n) \
777 __kfifo_uint_must_check_helper( \
779 typeof((fifo) + 1) __tmp = (fifo); \
780 typeof((buf) + 1) __buf = (buf); \
781 unsigned long __n = (n); \
782 const size_t __recsize = sizeof(*__tmp->rectype); \
783 struct __kfifo *__kfifo = &__tmp->kfifo; \
785 typeof(__tmp->ptr) __dummy __attribute__ ((unused)) = NULL; \
789 __kfifo_out_peek_r(__kfifo, __buf, __n, __recsize) : \
790 __kfifo_out_peek(__kfifo, __buf, __n); \
794 extern int __kfifo_alloc(struct __kfifo *fifo, unsigned int size,
795 size_t esize, gfp_t gfp_mask);
797 extern void __kfifo_free(struct __kfifo *fifo);
799 extern int __kfifo_init(struct __kfifo *fifo, void *buffer,
800 unsigned int size, size_t esize);
802 extern unsigned int __kfifo_in(struct __kfifo *fifo,
803 const void *buf, unsigned int len);
805 extern unsigned int __kfifo_out(struct __kfifo *fifo,
806 void *buf, unsigned int len);
808 extern int __kfifo_from_user(struct __kfifo *fifo,
809 const void __user *from, unsigned long len, unsigned int *copied);
811 extern int __kfifo_to_user(struct __kfifo *fifo,
812 void __user *to, unsigned long len, unsigned int *copied);
814 extern unsigned int __kfifo_dma_in_prepare(struct __kfifo *fifo,
815 struct scatterlist *sgl, int nents, unsigned int len);
817 extern unsigned int __kfifo_dma_out_prepare(struct __kfifo *fifo,
818 struct scatterlist *sgl, int nents, unsigned int len);
820 extern unsigned int __kfifo_out_peek(struct __kfifo *fifo,
821 void *buf, unsigned int len);
823 extern unsigned int __kfifo_in_r(struct __kfifo *fifo,
824 const void *buf, unsigned int len, size_t recsize);
826 extern unsigned int __kfifo_out_r(struct __kfifo *fifo,
827 void *buf, unsigned int len, size_t recsize);
829 extern int __kfifo_from_user_r(struct __kfifo *fifo,
830 const void __user *from, unsigned long len, unsigned int *copied,
833 extern int __kfifo_to_user_r(struct __kfifo *fifo, void __user *to,
834 unsigned long len, unsigned int *copied, size_t recsize);
836 extern unsigned int __kfifo_dma_in_prepare_r(struct __kfifo *fifo,
837 struct scatterlist *sgl, int nents, unsigned int len, size_t recsize);
839 extern void __kfifo_dma_in_finish_r(struct __kfifo *fifo,
840 unsigned int len, size_t recsize);
842 extern unsigned int __kfifo_dma_out_prepare_r(struct __kfifo *fifo,
843 struct scatterlist *sgl, int nents, unsigned int len, size_t recsize);
845 extern void __kfifo_dma_out_finish_r(struct __kfifo *fifo, size_t recsize);
847 extern unsigned int __kfifo_len_r(struct __kfifo *fifo, size_t recsize);
849 extern void __kfifo_skip_r(struct __kfifo *fifo, size_t recsize);
851 extern unsigned int __kfifo_out_peek_r(struct __kfifo *fifo,
852 void *buf, unsigned int len, size_t recsize);
854 extern unsigned int __kfifo_max_r(unsigned int len, size_t recsize);
857 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36)) */