Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 301321 | Differences between
and this patch

Collapse All | Expand All

(-)drivers/lirc_dev/lirc_dev.h (-21 / +99 lines)
Lines 4-10 Link Here
4
 * (L) by Artur Lipowski <alipowski@interia.pl>
4
 * (L) by Artur Lipowski <alipowski@interia.pl>
5
 *        This code is licensed under GNU GPL
5
 *        This code is licensed under GNU GPL
6
 *
6
 *
7
 * $Id: lirc_dev.h,v 1.37 2009/03/15 09:34:00 lirc Exp $
7
 * $Id: lirc_dev.h,v 1.39 2010/01/23 16:28:07 lirc Exp $
8
 *
8
 *
9
 */
9
 */
10
10
Lines 30-43 Link Here
30
30
31
struct lirc_buffer {
31
struct lirc_buffer {
32
	wait_queue_head_t wait_poll;
32
	wait_queue_head_t wait_poll;
33
	spinlock_t lock;
33
	spinlock_t fifo_lock;
34
	unsigned int chunk_size;
34
	unsigned int chunk_size;
35
	unsigned int size; /* in chunks */
35
	unsigned int size; /* in chunks */
36
	/* Using chunks instead of bytes pretends to simplify boundary checking
36
	/* Using chunks instead of bytes pretends to simplify boundary checking
37
	 * And should allow for some performance fine tunning later */
37
	 * And should allow for some performance fine tunning later */
38
#ifdef LIRC_HAVE_KFIFO
38
#ifdef LIRC_HAVE_KFIFO
39
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
39
	struct kfifo *fifo;
40
	struct kfifo *fifo;
40
#else
41
#else
42
	struct kfifo fifo;
43
	u8 fifo_initialized;
44
#endif
45
#else
41
	unsigned int fill; /* in chunks */
46
	unsigned int fill; /* in chunks */
42
	int head, tail;    /* in chunks */
47
	int head, tail;    /* in chunks */
43
	unsigned char *data;
48
	unsigned char *data;
Lines 47-58 Link Here
47
static inline void lirc_buffer_lock(struct lirc_buffer *buf,
52
static inline void lirc_buffer_lock(struct lirc_buffer *buf,
48
				    unsigned long *flags)
53
				    unsigned long *flags)
49
{
54
{
50
	spin_lock_irqsave(&buf->lock, *flags);
55
	spin_lock_irqsave(&buf->fifo_lock, *flags);
51
}
56
}
52
static inline void lirc_buffer_unlock(struct lirc_buffer *buf,
57
static inline void lirc_buffer_unlock(struct lirc_buffer *buf,
53
				      unsigned long *flags)
58
				      unsigned long *flags)
54
{
59
{
55
	spin_unlock_irqrestore(&buf->lock, *flags);
60
	spin_unlock_irqrestore(&buf->fifo_lock, *flags);
56
}
61
}
57
static inline void _lirc_buffer_clear(struct lirc_buffer *buf)
62
static inline void _lirc_buffer_clear(struct lirc_buffer *buf)
58
{
63
{
Lines 64-73 Link Here
64
static inline void lirc_buffer_clear(struct lirc_buffer *buf)
69
static inline void lirc_buffer_clear(struct lirc_buffer *buf)
65
{
70
{
66
#ifdef LIRC_HAVE_KFIFO
71
#ifdef LIRC_HAVE_KFIFO
72
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
67
	if (buf->fifo)
73
	if (buf->fifo)
68
		kfifo_reset(buf->fifo);
74
		kfifo_reset(buf->fifo);
69
#else
75
#else
70
	unsigned long flags;
76
	unsigned long flags;
77
78
	if (buf->fifo_initialized) {
79
		spin_lock_irqsave(&buf->fifo_lock, flags);
80
		kfifo_reset(&buf->fifo);
81
		spin_unlock_irqrestore(&buf->fifo_lock, flags);
82
	}
83
#endif
84
#else
85
	unsigned long flags;
86
71
	lirc_buffer_lock(buf, &flags);
87
	lirc_buffer_lock(buf, &flags);
72
	_lirc_buffer_clear(buf);
88
	_lirc_buffer_clear(buf);
73
	lirc_buffer_unlock(buf, &flags);
89
	lirc_buffer_unlock(buf, &flags);
Lines 77-107 Link Here
77
				    unsigned int chunk_size,
93
				    unsigned int chunk_size,
78
				    unsigned int size)
94
				    unsigned int size)
79
{
95
{
96
	int ret = 0;
97
80
	init_waitqueue_head(&buf->wait_poll);
98
	init_waitqueue_head(&buf->wait_poll);
81
	spin_lock_init(&buf->lock);
99
	spin_lock_init(&buf->fifo_lock);
82
#ifndef LIRC_HAVE_KFIFO
100
#ifndef LIRC_HAVE_KFIFO
83
	_lirc_buffer_clear(buf);
101
	_lirc_buffer_clear(buf);
84
#endif
102
#endif
85
	buf->chunk_size = chunk_size;
103
	buf->chunk_size = chunk_size;
86
	buf->size = size;
104
	buf->size = size;
87
#ifdef LIRC_HAVE_KFIFO
105
#ifdef LIRC_HAVE_KFIFO
88
	buf->fifo = kfifo_alloc(size*chunk_size, GFP_KERNEL, &buf->lock);
106
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
107
	buf->fifo = kfifo_alloc(size*chunk_size, GFP_KERNEL, &buf->fifo_lock);
89
	if (!buf->fifo)
108
	if (!buf->fifo)
90
		return -ENOMEM;
109
		return -ENOMEM;
91
#else
110
#else
111
	ret = kfifo_alloc(&buf->fifo, size * chunk_size, GFP_KERNEL);
112
	if (ret == 0)
113
		buf->fifo_initialized = 1;
114
#endif
115
#else
92
	buf->data = kmalloc(size*chunk_size, GFP_KERNEL);
116
	buf->data = kmalloc(size*chunk_size, GFP_KERNEL);
93
	if (buf->data == NULL)
117
	if (buf->data == NULL)
94
		return -ENOMEM;
118
		return -ENOMEM;
95
	memset(buf->data, 0, size*chunk_size);
119
	memset(buf->data, 0, size*chunk_size);
96
#endif
120
#endif
97
	return 0;
121
122
	return ret;
98
}
123
}
99
static inline void lirc_buffer_free(struct lirc_buffer *buf)
124
static inline void lirc_buffer_free(struct lirc_buffer *buf)
100
{
125
{
101
#ifdef LIRC_HAVE_KFIFO
126
#ifdef LIRC_HAVE_KFIFO
127
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
102
	if (buf->fifo)
128
	if (buf->fifo)
103
		kfifo_free(buf->fifo);
129
		kfifo_free(buf->fifo);
104
#else
130
#else
131
	if (buf->fifo_initialized) {
132
		kfifo_free(&buf->fifo);
133
		buf->fifo_initialized = 0;
134
	}
135
#endif
136
#else
105
	kfree(buf->data);
137
	kfree(buf->data);
106
	buf->data = NULL;
138
	buf->data = NULL;
107
	buf->head = 0;
139
	buf->head = 0;
Lines 111-116 Link Here
111
	buf->size = 0;
143
	buf->size = 0;
112
#endif
144
#endif
113
}
145
}
146
147
#ifdef LIRC_HAVE_KFIFO
148
static inline int lirc_buffer_len(struct lirc_buffer *buf)
149
{
150
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
151
	return kfifo_len(buf->fifo);
152
#else
153
	int len;
154
	unsigned long flags;
155
156
	spin_lock_irqsave(&buf->fifo_lock, flags);
157
	len = kfifo_len(&buf->fifo);
158
	spin_unlock_irqrestore(&buf->fifo_lock, flags);
159
160
	return len;
161
#endif
162
}
163
#endif
164
114
#ifndef LIRC_HAVE_KFIFO
165
#ifndef LIRC_HAVE_KFIFO
115
static inline int  _lirc_buffer_full(struct lirc_buffer *buf)
166
static inline int  _lirc_buffer_full(struct lirc_buffer *buf)
116
{
167
{
Lines 120-126 Link Here
120
static inline int  lirc_buffer_full(struct lirc_buffer *buf)
171
static inline int  lirc_buffer_full(struct lirc_buffer *buf)
121
{
172
{
122
#ifdef LIRC_HAVE_KFIFO
173
#ifdef LIRC_HAVE_KFIFO
123
	return kfifo_len(buf->fifo) == buf->size * buf->chunk_size;
174
	return lirc_buffer_len(buf) == buf->size * buf->chunk_size;
124
#else
175
#else
125
	unsigned long flags;
176
	unsigned long flags;
126
	int ret;
177
	int ret;
Lines 139-145 Link Here
139
static inline int  lirc_buffer_empty(struct lirc_buffer *buf)
190
static inline int  lirc_buffer_empty(struct lirc_buffer *buf)
140
{
191
{
141
#ifdef LIRC_HAVE_KFIFO
192
#ifdef LIRC_HAVE_KFIFO
142
	return !kfifo_len(buf->fifo);
193
	return !lirc_buffer_len(buf);
143
#else
194
#else
144
	unsigned long flags;
195
	unsigned long flags;
145
	int ret;
196
	int ret;
Lines 158-164 Link Here
158
static inline int  lirc_buffer_available(struct lirc_buffer *buf)
209
static inline int  lirc_buffer_available(struct lirc_buffer *buf)
159
{
210
{
160
#ifdef LIRC_HAVE_KFIFO
211
#ifdef LIRC_HAVE_KFIFO
161
	return buf->size - (kfifo_len(buf->fifo) / buf->chunk_size);
212
	return buf->size - (lirc_buffer_len(buf) / buf->chunk_size);
162
#else
213
#else
163
	unsigned long flags;
214
	unsigned long flags;
164
	int ret;
215
	int ret;
Lines 177-197 Link Here
177
	buf->fill -= 1;
228
	buf->fill -= 1;
178
}
229
}
179
#endif
230
#endif
180
static inline void lirc_buffer_read(struct lirc_buffer *buf,
231
static inline unsigned int lirc_buffer_read(struct lirc_buffer *buf,
181
				    unsigned char *dest)
232
					    unsigned char *dest)
182
{
233
{
234
	unsigned int ret = 0;
235
183
#ifdef LIRC_HAVE_KFIFO
236
#ifdef LIRC_HAVE_KFIFO
184
	if (kfifo_len(buf->fifo) >= buf->chunk_size)
237
	if (lirc_buffer_len(buf) >= buf->chunk_size)
185
		kfifo_get(buf->fifo, dest, buf->chunk_size);
238
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
239
		ret = kfifo_get(buf->fifo, dest, buf->chunk_size);
240
#else
241
		ret = kfifo_out_locked(&buf->fifo, dest, buf->chunk_size,
242
				       &buf->fifo_lock);
243
#endif
186
#else
244
#else
187
	unsigned long flags;
245
	unsigned long flags;
188
	lirc_buffer_lock(buf, &flags);
246
	lirc_buffer_lock(buf, &flags);
189
	_lirc_buffer_read_1(buf, dest);
247
	_lirc_buffer_read_1(buf, dest);
190
	lirc_buffer_unlock(buf, &flags);
248
	lirc_buffer_unlock(buf, &flags);
191
#endif
249
#endif
250
251
	return ret;
192
}
252
}
193
#ifndef LIRC_HAVE_KFIFO
253
#ifndef LIRC_HAVE_KFIFO
194
static inline void _lirc_buffer_write_1(struct lirc_buffer *buf,
254
static inline  _lirc_buffer_write_1(struct lirc_buffer *buf,
195
				      unsigned char *orig)
255
				      unsigned char *orig)
196
{
256
{
197
	memcpy(&buf->data[buf->tail*buf->chunk_size], orig, buf->chunk_size);
257
	memcpy(&buf->data[buf->tail*buf->chunk_size], orig, buf->chunk_size);
Lines 199-215 Link Here
199
	buf->fill++;
259
	buf->fill++;
200
}
260
}
201
#endif
261
#endif
202
static inline void lirc_buffer_write(struct lirc_buffer *buf,
262
static inline unsigned int lirc_buffer_write(struct lirc_buffer *buf,
203
				     unsigned char *orig)
263
					     unsigned char *orig)
204
{
264
{
265
	unsigned int ret = 0;
266
205
#ifdef LIRC_HAVE_KFIFO
267
#ifdef LIRC_HAVE_KFIFO
206
	kfifo_put(buf->fifo, orig, buf->chunk_size);
268
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
269
	ret = kfifo_put(buf->fifo, orig, buf->chunk_size);
270
#else
271
	ret = kfifo_in_locked(&buf->fifo, orig, buf->chunk_size,
272
			      &buf->fifo_lock);
273
#endif
207
#else
274
#else
208
	unsigned long flags;
275
	unsigned long flags;
209
	lirc_buffer_lock(buf, &flags);
276
	lirc_buffer_lock(buf, &flags);
210
	_lirc_buffer_write_1(buf, orig);
277
	_lirc_buffer_write_1(buf, orig);
211
	lirc_buffer_unlock(buf, &flags);
278
	lirc_buffer_unlock(buf, &flags);
212
#endif
279
#endif
280
281
	return ret;
213
}
282
}
214
#ifndef LIRC_HAVE_KFIFO
283
#ifndef LIRC_HAVE_KFIFO
215
static inline void _lirc_buffer_write_n(struct lirc_buffer *buf,
284
static inline void _lirc_buffer_write_n(struct lirc_buffer *buf,
Lines 234-250 Link Here
234
	buf->fill += count;
303
	buf->fill += count;
235
}
304
}
236
#endif
305
#endif
237
static inline void lirc_buffer_write_n(struct lirc_buffer *buf,
306
static inline unsigned int lirc_buffer_write_n(struct lirc_buffer *buf,
238
				       unsigned char *orig, int count)
307
					       unsigned char *orig, int count)
239
{
308
{
309
	unsigned int ret = 0;
310
240
#ifdef LIRC_HAVE_KFIFO
311
#ifdef LIRC_HAVE_KFIFO
241
	kfifo_put(buf->fifo, orig, count * buf->chunk_size);
312
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
313
	ret = kfifo_put(buf->fifo, orig, count * buf->chunk_size);
314
#else
315
	ret = kfifo_in_locked(&buf->fifo, orig, count * buf->chunk_size,
316
			      &buf->fifo_lock);
317
#endif
242
#else
318
#else
243
	unsigned long flags;
319
	unsigned long flags;
244
	lirc_buffer_lock(buf, &flags);
320
	lirc_buffer_lock(buf, &flags);
245
	_lirc_buffer_write_n(buf, orig, count);
321
	_lirc_buffer_write_n(buf, orig, count);
246
	lirc_buffer_unlock(buf, &flags);
322
	lirc_buffer_unlock(buf, &flags);
247
#endif
323
#endif
324
325
	return ret;
248
}
326
}
249
327
250
struct lirc_driver {
328
struct lirc_driver {

Return to bug 301321