1
## Description: add some description
2
## Origin/Author: add some origin or author
4
Index: lirc/drivers/lirc_dev/lirc_dev.h
5
===================================================================
6
--- lirc.orig/drivers/lirc_dev/lirc_dev.h 2010-03-27 23:44:10.259225130 -0500
7
+++ lirc/drivers/lirc_dev/lirc_dev.h 2010-03-27 23:44:08.163236533 -0500
9
* (L) by Artur Lipowski <alipowski@interia.pl>
10
* This code is licensed under GNU GPL
12
- * $Id: lirc_dev.h,v 1.37 2009/03/15 09:34:00 lirc Exp $
13
+ * $Id: lirc_dev.h,v 1.39 2010/01/23 16:28:07 lirc Exp $
20
wait_queue_head_t wait_poll;
22
+ spinlock_t fifo_lock;
23
unsigned int chunk_size;
24
unsigned int size; /* in chunks */
25
/* Using chunks instead of bytes pretends to simplify boundary checking
26
* And should allow for some performance fine tunning later */
27
#ifdef LIRC_HAVE_KFIFO
28
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
32
+ u8 fifo_initialized;
35
unsigned int fill; /* in chunks */
36
int head, tail; /* in chunks */
39
static inline void lirc_buffer_lock(struct lirc_buffer *buf,
42
- spin_lock_irqsave(&buf->lock, *flags);
43
+ spin_lock_irqsave(&buf->fifo_lock, *flags);
45
static inline void lirc_buffer_unlock(struct lirc_buffer *buf,
48
- spin_unlock_irqrestore(&buf->lock, *flags);
49
+ spin_unlock_irqrestore(&buf->fifo_lock, *flags);
51
static inline void _lirc_buffer_clear(struct lirc_buffer *buf)
54
static inline void lirc_buffer_clear(struct lirc_buffer *buf)
56
#ifdef LIRC_HAVE_KFIFO
57
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
59
kfifo_reset(buf->fifo);
63
+ if (buf->fifo_initialized) {
64
+ spin_lock_irqsave(&buf->fifo_lock, flags);
65
+ kfifo_reset(&buf->fifo);
66
+ spin_unlock_irqrestore(&buf->fifo_lock, flags);
70
+ unsigned long flags;
72
lirc_buffer_lock(buf, &flags);
73
_lirc_buffer_clear(buf);
74
lirc_buffer_unlock(buf, &flags);
76
unsigned int chunk_size,
81
init_waitqueue_head(&buf->wait_poll);
82
- spin_lock_init(&buf->lock);
83
+ spin_lock_init(&buf->fifo_lock);
84
#ifndef LIRC_HAVE_KFIFO
85
_lirc_buffer_clear(buf);
87
buf->chunk_size = chunk_size;
89
#ifdef LIRC_HAVE_KFIFO
90
- buf->fifo = kfifo_alloc(size*chunk_size, GFP_KERNEL, &buf->lock);
91
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
92
+ buf->fifo = kfifo_alloc(size*chunk_size, GFP_KERNEL, &buf->fifo_lock);
96
+ ret = kfifo_alloc(&buf->fifo, size * chunk_size, GFP_KERNEL);
98
+ buf->fifo_initialized = 1;
101
buf->data = kmalloc(size*chunk_size, GFP_KERNEL);
102
if (buf->data == NULL)
104
memset(buf->data, 0, size*chunk_size);
110
static inline void lirc_buffer_free(struct lirc_buffer *buf)
112
#ifdef LIRC_HAVE_KFIFO
113
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
115
kfifo_free(buf->fifo);
117
+ if (buf->fifo_initialized) {
118
+ kfifo_free(&buf->fifo);
119
+ buf->fifo_initialized = 0;
131
+#ifdef LIRC_HAVE_KFIFO
132
+static inline int lirc_buffer_len(struct lirc_buffer *buf)
134
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
135
+ return kfifo_len(buf->fifo);
138
+ unsigned long flags;
140
+ spin_lock_irqsave(&buf->fifo_lock, flags);
141
+ len = kfifo_len(&buf->fifo);
142
+ spin_unlock_irqrestore(&buf->fifo_lock, flags);
149
#ifndef LIRC_HAVE_KFIFO
150
static inline int _lirc_buffer_full(struct lirc_buffer *buf)
153
static inline int lirc_buffer_full(struct lirc_buffer *buf)
155
#ifdef LIRC_HAVE_KFIFO
156
- return kfifo_len(buf->fifo) == buf->size * buf->chunk_size;
157
+ return lirc_buffer_len(buf) == buf->size * buf->chunk_size;
162
static inline int lirc_buffer_empty(struct lirc_buffer *buf)
164
#ifdef LIRC_HAVE_KFIFO
165
- return !kfifo_len(buf->fifo);
166
+ return !lirc_buffer_len(buf);
171
static inline int lirc_buffer_available(struct lirc_buffer *buf)
173
#ifdef LIRC_HAVE_KFIFO
174
- return buf->size - (kfifo_len(buf->fifo) / buf->chunk_size);
175
+ return buf->size - (lirc_buffer_len(buf) / buf->chunk_size);
179
@@ -177,21 +228,30 @@
183
-static inline void lirc_buffer_read(struct lirc_buffer *buf,
184
- unsigned char *dest)
185
+static inline unsigned int lirc_buffer_read(struct lirc_buffer *buf,
186
+ unsigned char *dest)
188
+ unsigned int ret = 0;
190
#ifdef LIRC_HAVE_KFIFO
191
- if (kfifo_len(buf->fifo) >= buf->chunk_size)
192
- kfifo_get(buf->fifo, dest, buf->chunk_size);
193
+ if (lirc_buffer_len(buf) >= buf->chunk_size)
194
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
195
+ ret = kfifo_get(buf->fifo, dest, buf->chunk_size);
197
+ ret = kfifo_out_locked(&buf->fifo, dest, buf->chunk_size,
202
lirc_buffer_lock(buf, &flags);
203
_lirc_buffer_read_1(buf, dest);
204
lirc_buffer_unlock(buf, &flags);
209
#ifndef LIRC_HAVE_KFIFO
210
-static inline void _lirc_buffer_write_1(struct lirc_buffer *buf,
211
+static inline _lirc_buffer_write_1(struct lirc_buffer *buf,
214
memcpy(&buf->data[buf->tail*buf->chunk_size], orig, buf->chunk_size);
215
@@ -199,17 +259,26 @@
219
-static inline void lirc_buffer_write(struct lirc_buffer *buf,
220
- unsigned char *orig)
221
+static inline unsigned int lirc_buffer_write(struct lirc_buffer *buf,
222
+ unsigned char *orig)
224
+ unsigned int ret = 0;
226
#ifdef LIRC_HAVE_KFIFO
227
- kfifo_put(buf->fifo, orig, buf->chunk_size);
228
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
229
+ ret = kfifo_put(buf->fifo, orig, buf->chunk_size);
231
+ ret = kfifo_in_locked(&buf->fifo, orig, buf->chunk_size,
236
lirc_buffer_lock(buf, &flags);
237
_lirc_buffer_write_1(buf, orig);
238
lirc_buffer_unlock(buf, &flags);
243
#ifndef LIRC_HAVE_KFIFO
244
static inline void _lirc_buffer_write_n(struct lirc_buffer *buf,
245
@@ -234,17 +303,26 @@
249
-static inline void lirc_buffer_write_n(struct lirc_buffer *buf,
250
- unsigned char *orig, int count)
251
+static inline unsigned int lirc_buffer_write_n(struct lirc_buffer *buf,
252
+ unsigned char *orig, int count)
254
+ unsigned int ret = 0;
256
#ifdef LIRC_HAVE_KFIFO
257
- kfifo_put(buf->fifo, orig, count * buf->chunk_size);
258
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
259
+ ret = kfifo_put(buf->fifo, orig, count * buf->chunk_size);
261
+ ret = kfifo_in_locked(&buf->fifo, orig, count * buf->chunk_size,
266
lirc_buffer_lock(buf, &flags);
267
_lirc_buffer_write_n(buf, orig, count);
268
lirc_buffer_unlock(buf, &flags);