driver: add dev_name inline
[barebox-mini2440.git] / include / kfifo.h
blob6f8be10f678431e974c060820ba023725bbb9030
1 /*
2 * A simple kernel FIFO implementation.
4 * Copyright (C) 2004 Stelian Pop <stelian@popies.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #ifndef _LINUX_KFIFO_H
22 #define _LINUX_KFIFO_H
24 struct kfifo {
25 unsigned char *buffer; /* the buffer holding the data */
26 unsigned int size; /* the size of the allocated buffer */
27 unsigned int in; /* data is added at offset (in % size) */
28 unsigned int out; /* data is extracted from off. (out % size) */
31 struct kfifo *kfifo_init(unsigned char *buffer, unsigned int size);
32 struct kfifo *kfifo_alloc(unsigned int size);
33 void kfifo_free(struct kfifo *fifo);
35 /**
36 * kfifo_put - puts some data into the FIFO
37 * @fifo: the fifo to be used.
38 * @buffer: the data to be added.
39 * @len: the length of the data to be added.
41 * This function copies at most @len bytes from the @buffer into
42 * the FIFO depending on the free space, and returns the number of
43 * bytes copied.
45 unsigned int kfifo_put(struct kfifo *fifo,
46 unsigned char *buffer, unsigned int len);
48 /**
49 * kfifo_get - gets some data from the FIFO
50 * @fifo: the fifo to be used.
51 * @buffer: where the data must be copied.
52 * @len: the size of the destination buffer.
54 * This function copies at most @len bytes from the FIFO into the
55 * @buffer and returns the number of copied bytes.
57 unsigned int kfifo_get(struct kfifo *fifo,
58 unsigned char *buffer, unsigned int len);
60 /**
61 * kfifo_reset - removes the entire FIFO contents
62 * @fifo: the fifo to be emptied.
64 static inline void kfifo_reset(struct kfifo *fifo)
66 fifo->in = fifo->out = 0;
70 /**
71 * kfifo_len - returns the number of bytes available in the FIFO.
72 * @fifo: the fifo to be used.
74 static inline unsigned int kfifo_len(struct kfifo *fifo)
76 return fifo->in - fifo->out;
79 void kfifo_putc(struct kfifo *fifo, unsigned char c);
80 unsigned int kfifo_getc(struct kfifo *fifo, unsigned char *c);
82 #endif