aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/media/dvb/dvb-core/dmxdev.c650
1 files changed, 321 insertions, 329 deletions
diff --git a/drivers/media/dvb/dvb-core/dmxdev.c b/drivers/media/dvb/dvb-core/dmxdev.c
index 5cd2f98290ae..f6932d6c62e3 100644
--- a/drivers/media/dvb/dvb-core/dmxdev.c
+++ b/drivers/media/dvb/dvb-core/dmxdev.c
@@ -1,9 +1,8 @@
1/* 1/*
2 * dmxdev.c - DVB demultiplexer device 2 * dmxdev.c - DVB demultiplexer device
3 * 3 *
4 * Copyright (C) 2000 Ralph Metzler <ralph@convergence.de> 4 * Copyright (C) 2000 Ralph Metzler & Marcus Metzler
5 * & Marcus Metzler <marcus@convergence.de> 5 * for convergence integrated media GmbH
6 for convergence integrated media GmbH
7 * 6 *
8 * This program is free software; you can redistribute it and/or 7 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License 8 * modify it under the terms of the GNU Lesser General Public License
@@ -32,7 +31,6 @@
32#include <linux/wait.h> 31#include <linux/wait.h>
33#include <asm/uaccess.h> 32#include <asm/uaccess.h>
34#include <asm/system.h> 33#include <asm/system.h>
35
36#include "dmxdev.h" 34#include "dmxdev.h"
37 35
38static int debug; 36static int debug;
@@ -44,15 +42,16 @@ MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
44 42
45static inline void dvb_dmxdev_buffer_init(struct dmxdev_buffer *buffer) 43static inline void dvb_dmxdev_buffer_init(struct dmxdev_buffer *buffer)
46{ 44{
47 buffer->data=NULL; 45 buffer->data = NULL;
48 buffer->size=8192; 46 buffer->size = 8192;
49 buffer->pread=0; 47 buffer->pread = 0;
50 buffer->pwrite=0; 48 buffer->pwrite = 0;
51 buffer->error=0; 49 buffer->error = 0;
52 init_waitqueue_head(&buffer->queue); 50 init_waitqueue_head(&buffer->queue);
53} 51}
54 52
55static inline int dvb_dmxdev_buffer_write(struct dmxdev_buffer *buf, const u8 *src, int len) 53static inline int dvb_dmxdev_buffer_write(struct dmxdev_buffer *buf,
54 const u8 *src, int len)
56{ 55{
57 int split; 56 int split;
58 int free; 57 int free;
@@ -63,98 +62,99 @@ static inline int dvb_dmxdev_buffer_write(struct dmxdev_buffer *buf, const u8 *s
63 if (!buf->data) 62 if (!buf->data)
64 return 0; 63 return 0;
65 64
66 free=buf->pread-buf->pwrite; 65 free = buf->pread - buf->pwrite;
67 split=0; 66 split = 0;
68 if (free<=0) { 67 if (free <= 0) {
69 free+=buf->size; 68 free += buf->size;
70 split=buf->size-buf->pwrite; 69 split = buf->size - buf->pwrite;
71 } 70 }
72 if (len>=free) { 71 if (len >= free) {
73 dprintk("dmxdev: buffer overflow\n"); 72 dprintk("dmxdev: buffer overflow\n");
74 return -1; 73 return -1;
75 } 74 }
76 if (split>=len) 75 if (split >= len)
77 split=0; 76 split = 0;
78 todo=len; 77 todo = len;
79 if (split) { 78 if (split) {
80 memcpy(buf->data + buf->pwrite, src, split); 79 memcpy(buf->data + buf->pwrite, src, split);
81 todo-=split; 80 todo -= split;
82 buf->pwrite=0; 81 buf->pwrite = 0;
83 } 82 }
84 memcpy(buf->data + buf->pwrite, src+split, todo); 83 memcpy(buf->data + buf->pwrite, src + split, todo);
85 buf->pwrite=(buf->pwrite+todo)%buf->size; 84 buf->pwrite = (buf->pwrite + todo) % buf->size;
86 return len; 85 return len;
87} 86}
88 87
89static ssize_t dvb_dmxdev_buffer_read(struct dmxdev_buffer *src, 88static ssize_t dvb_dmxdev_buffer_read(struct dmxdev_buffer *src,
90 int non_blocking, char __user *buf, size_t count, loff_t *ppos) 89 int non_blocking, char __user *buf,
90 size_t count, loff_t *ppos)
91{ 91{
92 unsigned long todo=count; 92 unsigned long todo = count;
93 int split, avail, error; 93 int split, avail, error;
94 94
95 if (!src->data) 95 if (!src->data)
96 return 0; 96 return 0;
97 97
98 if ((error=src->error)) { 98 if ((error = src->error)) {
99 src->pwrite=src->pread; 99 src->pwrite = src->pread;
100 src->error=0; 100 src->error = 0;
101 return error; 101 return error;
102 } 102 }
103 103
104 if (non_blocking && (src->pwrite==src->pread)) 104 if (non_blocking && (src->pwrite == src->pread))
105 return -EWOULDBLOCK; 105 return -EWOULDBLOCK;
106 106
107 while (todo>0) { 107 while (todo > 0) {
108 if (non_blocking && (src->pwrite==src->pread)) 108 if (non_blocking && (src->pwrite == src->pread))
109 return (count-todo) ? (count-todo) : -EWOULDBLOCK; 109 return (count - todo) ? (count - todo) : -EWOULDBLOCK;
110 110
111 if (wait_event_interruptible(src->queue, 111 if (wait_event_interruptible(src->queue,
112 (src->pread!=src->pwrite) || 112 (src->pread != src->pwrite) ||
113 (src->error))<0) 113 (src->error)) < 0)
114 return count-todo; 114 return count - todo;
115 115
116 if ((error=src->error)) { 116 if ((error = src->error)) {
117 src->pwrite=src->pread; 117 src->pwrite = src->pread;
118 src->error=0; 118 src->error = 0;
119 return error; 119 return error;
120 } 120 }
121 121
122 split=src->size; 122 split = src->size;
123 avail=src->pwrite - src->pread; 123 avail = src->pwrite - src->pread;
124 if (avail<0) { 124 if (avail < 0) {
125 avail+=src->size; 125 avail += src->size;
126 split=src->size - src->pread; 126 split = src->size - src->pread;
127 } 127 }
128 if (avail>todo) 128 if (avail > todo)
129 avail=todo; 129 avail = todo;
130 if (split<avail) { 130 if (split < avail) {
131 if (copy_to_user(buf, src->data+src->pread, split)) 131 if (copy_to_user(buf, src->data + src->pread, split))
132 return -EFAULT; 132 return -EFAULT;
133 buf+=split; 133 buf += split;
134 src->pread=0; 134 src->pread = 0;
135 todo-=split; 135 todo -= split;
136 avail-=split; 136 avail -= split;
137 } 137 }
138 if (avail) { 138 if (avail) {
139 if (copy_to_user(buf, src->data+src->pread, avail)) 139 if (copy_to_user(buf, src->data + src->pread, avail))
140 return -EFAULT; 140 return -EFAULT;
141 src->pread = (src->pread + avail) % src->size; 141 src->pread = (src->pread + avail) % src->size;
142 todo-=avail; 142 todo -= avail;
143 buf+=avail; 143 buf += avail;
144 } 144 }
145 } 145 }
146 return count; 146 return count;
147} 147}
148 148
149static struct dmx_frontend * get_fe(struct dmx_demux *demux, int type) 149static struct dmx_frontend *get_fe(struct dmx_demux *demux, int type)
150{ 150{
151 struct list_head *head, *pos; 151 struct list_head *head, *pos;
152 152
153 head=demux->get_frontends(demux); 153 head = demux->get_frontends(demux);
154 if (!head) 154 if (!head)
155 return NULL; 155 return NULL;
156 list_for_each(pos, head) 156 list_for_each(pos, head)
157 if (DMX_FE_ENTRY(pos)->source==type) 157 if (DMX_FE_ENTRY(pos)->source == type)
158 return DMX_FE_ENTRY(pos); 158 return DMX_FE_ENTRY(pos);
159 159
160 return NULL; 160 return NULL;
@@ -166,37 +166,37 @@ static int dvb_dvr_open(struct inode *inode, struct file *file)
166 struct dmxdev *dmxdev = dvbdev->priv; 166 struct dmxdev *dmxdev = dvbdev->priv;
167 struct dmx_frontend *front; 167 struct dmx_frontend *front;
168 168
169 dprintk ("function : %s\n", __FUNCTION__); 169 dprintk("function : %s\n", __FUNCTION__);
170 170
171 if (mutex_lock_interruptible(&dmxdev->mutex)) 171 if (mutex_lock_interruptible(&dmxdev->mutex))
172 return -ERESTARTSYS; 172 return -ERESTARTSYS;
173 173
174 if ((file->f_flags&O_ACCMODE)==O_RDWR) { 174 if ((file->f_flags & O_ACCMODE) == O_RDWR) {
175 if (!(dmxdev->capabilities&DMXDEV_CAP_DUPLEX)) { 175 if (!(dmxdev->capabilities & DMXDEV_CAP_DUPLEX)) {
176 mutex_unlock(&dmxdev->mutex); 176 mutex_unlock(&dmxdev->mutex);
177 return -EOPNOTSUPP; 177 return -EOPNOTSUPP;
178 } 178 }
179 } 179 }
180 180
181 if ((file->f_flags&O_ACCMODE)==O_RDONLY) { 181 if ((file->f_flags & O_ACCMODE) == O_RDONLY) {
182 dvb_dmxdev_buffer_init(&dmxdev->dvr_buffer); 182 dvb_dmxdev_buffer_init(&dmxdev->dvr_buffer);
183 dmxdev->dvr_buffer.size=DVR_BUFFER_SIZE; 183 dmxdev->dvr_buffer.size = DVR_BUFFER_SIZE;
184 dmxdev->dvr_buffer.data=vmalloc(DVR_BUFFER_SIZE); 184 dmxdev->dvr_buffer.data = vmalloc(DVR_BUFFER_SIZE);
185 if (!dmxdev->dvr_buffer.data) { 185 if (!dmxdev->dvr_buffer.data) {
186 mutex_unlock(&dmxdev->mutex); 186 mutex_unlock(&dmxdev->mutex);
187 return -ENOMEM; 187 return -ENOMEM;
188 } 188 }
189 } 189 }
190 190
191 if ((file->f_flags&O_ACCMODE)==O_WRONLY) { 191 if ((file->f_flags & O_ACCMODE) == O_WRONLY) {
192 dmxdev->dvr_orig_fe=dmxdev->demux->frontend; 192 dmxdev->dvr_orig_fe = dmxdev->demux->frontend;
193 193
194 if (!dmxdev->demux->write) { 194 if (!dmxdev->demux->write) {
195 mutex_unlock(&dmxdev->mutex); 195 mutex_unlock(&dmxdev->mutex);
196 return -EOPNOTSUPP; 196 return -EOPNOTSUPP;
197 } 197 }
198 198
199 front=get_fe(dmxdev->demux, DMX_MEMORY_FE); 199 front = get_fe(dmxdev->demux, DMX_MEMORY_FE);
200 200
201 if (!front) { 201 if (!front) {
202 mutex_unlock(&dmxdev->mutex); 202 mutex_unlock(&dmxdev->mutex);
@@ -217,17 +217,17 @@ static int dvb_dvr_release(struct inode *inode, struct file *file)
217 if (mutex_lock_interruptible(&dmxdev->mutex)) 217 if (mutex_lock_interruptible(&dmxdev->mutex))
218 return -ERESTARTSYS; 218 return -ERESTARTSYS;
219 219
220 if ((file->f_flags&O_ACCMODE)==O_WRONLY) { 220 if ((file->f_flags & O_ACCMODE) == O_WRONLY) {
221 dmxdev->demux->disconnect_frontend(dmxdev->demux); 221 dmxdev->demux->disconnect_frontend(dmxdev->demux);
222 dmxdev->demux->connect_frontend(dmxdev->demux, 222 dmxdev->demux->connect_frontend(dmxdev->demux,
223 dmxdev->dvr_orig_fe); 223 dmxdev->dvr_orig_fe);
224 } 224 }
225 if ((file->f_flags&O_ACCMODE)==O_RDONLY) { 225 if ((file->f_flags & O_ACCMODE) == O_RDONLY) {
226 if (dmxdev->dvr_buffer.data) { 226 if (dmxdev->dvr_buffer.data) {
227 void *mem=dmxdev->dvr_buffer.data; 227 void *mem = dmxdev->dvr_buffer.data;
228 mb(); 228 mb();
229 spin_lock_irq(&dmxdev->lock); 229 spin_lock_irq(&dmxdev->lock);
230 dmxdev->dvr_buffer.data=NULL; 230 dmxdev->dvr_buffer.data = NULL;
231 spin_unlock_irq(&dmxdev->lock); 231 spin_unlock_irq(&dmxdev->lock);
232 vfree(mem); 232 vfree(mem);
233 } 233 }
@@ -237,7 +237,7 @@ static int dvb_dvr_release(struct inode *inode, struct file *file)
237} 237}
238 238
239static ssize_t dvb_dvr_write(struct file *file, const char __user *buf, 239static ssize_t dvb_dvr_write(struct file *file, const char __user *buf,
240 size_t count, loff_t *ppos) 240 size_t count, loff_t *ppos)
241{ 241{
242 struct dvb_device *dvbdev = file->private_data; 242 struct dvb_device *dvbdev = file->private_data;
243 struct dmxdev *dmxdev = dvbdev->priv; 243 struct dmxdev *dmxdev = dvbdev->priv;
@@ -245,60 +245,62 @@ static ssize_t dvb_dvr_write(struct file *file, const char __user *buf,
245 245
246 if (!dmxdev->demux->write) 246 if (!dmxdev->demux->write)
247 return -EOPNOTSUPP; 247 return -EOPNOTSUPP;
248 if ((file->f_flags&O_ACCMODE)!=O_WRONLY) 248 if ((file->f_flags & O_ACCMODE) != O_WRONLY)
249 return -EINVAL; 249 return -EINVAL;
250 if (mutex_lock_interruptible(&dmxdev->mutex)) 250 if (mutex_lock_interruptible(&dmxdev->mutex))
251 return -ERESTARTSYS; 251 return -ERESTARTSYS;
252 ret=dmxdev->demux->write(dmxdev->demux, buf, count); 252 ret = dmxdev->demux->write(dmxdev->demux, buf, count);
253 mutex_unlock(&dmxdev->mutex); 253 mutex_unlock(&dmxdev->mutex);
254 return ret; 254 return ret;
255} 255}
256 256
257static ssize_t dvb_dvr_read(struct file *file, char __user *buf, size_t count, 257static ssize_t dvb_dvr_read(struct file *file, char __user *buf, size_t count,
258 loff_t *ppos) 258 loff_t *ppos)
259{ 259{
260 struct dvb_device *dvbdev = file->private_data; 260 struct dvb_device *dvbdev = file->private_data;
261 struct dmxdev *dmxdev = dvbdev->priv; 261 struct dmxdev *dmxdev = dvbdev->priv;
262 int ret; 262 int ret;
263 263
264 //mutex_lock(&dmxdev->mutex); 264 //mutex_lock(&dmxdev->mutex);
265 ret= dvb_dmxdev_buffer_read(&dmxdev->dvr_buffer, 265 ret = dvb_dmxdev_buffer_read(&dmxdev->dvr_buffer,
266 file->f_flags&O_NONBLOCK, 266 file->f_flags & O_NONBLOCK,
267 buf, count, ppos); 267 buf, count, ppos);
268 //mutex_unlock(&dmxdev->mutex); 268 //mutex_unlock(&dmxdev->mutex);
269 return ret; 269 return ret;
270} 270}
271 271
272static inline void dvb_dmxdev_filter_state_set(struct dmxdev_filter *dmxdevfilter, int state) 272static inline void dvb_dmxdev_filter_state_set(struct dmxdev_filter
273 *dmxdevfilter, int state)
273{ 274{
274 spin_lock_irq(&dmxdevfilter->dev->lock); 275 spin_lock_irq(&dmxdevfilter->dev->lock);
275 dmxdevfilter->state=state; 276 dmxdevfilter->state = state;
276 spin_unlock_irq(&dmxdevfilter->dev->lock); 277 spin_unlock_irq(&dmxdevfilter->dev->lock);
277} 278}
278 279
279static int dvb_dmxdev_set_buffer_size(struct dmxdev_filter *dmxdevfilter, unsigned long size) 280static int dvb_dmxdev_set_buffer_size(struct dmxdev_filter *dmxdevfilter,
281 unsigned long size)
280{ 282{
281 struct dmxdev_buffer *buf=&dmxdevfilter->buffer; 283 struct dmxdev_buffer *buf = &dmxdevfilter->buffer;
282 void *mem; 284 void *mem;
283 285
284 if (buf->size==size) 286 if (buf->size == size)
285 return 0; 287 return 0;
286 if (dmxdevfilter->state>=DMXDEV_STATE_GO) 288 if (dmxdevfilter->state >= DMXDEV_STATE_GO)
287 return -EBUSY; 289 return -EBUSY;
288 spin_lock_irq(&dmxdevfilter->dev->lock); 290 spin_lock_irq(&dmxdevfilter->dev->lock);
289 mem=buf->data; 291 mem = buf->data;
290 buf->data=NULL; 292 buf->data = NULL;
291 buf->size=size; 293 buf->size = size;
292 buf->pwrite=buf->pread=0; 294 buf->pwrite = buf->pread = 0;
293 spin_unlock_irq(&dmxdevfilter->dev->lock); 295 spin_unlock_irq(&dmxdevfilter->dev->lock);
294 vfree(mem); 296 vfree(mem);
295 297
296 if (buf->size) { 298 if (buf->size) {
297 mem=vmalloc(dmxdevfilter->buffer.size); 299 mem = vmalloc(dmxdevfilter->buffer.size);
298 if (!mem) 300 if (!mem)
299 return -ENOMEM; 301 return -ENOMEM;
300 spin_lock_irq(&dmxdevfilter->dev->lock); 302 spin_lock_irq(&dmxdevfilter->dev->lock);
301 buf->data=mem; 303 buf->data = mem;
302 spin_unlock_irq(&dmxdevfilter->dev->lock); 304 spin_unlock_irq(&dmxdevfilter->dev->lock);
303 } 305 }
304 return 0; 306 return 0;
@@ -306,31 +308,33 @@ static int dvb_dmxdev_set_buffer_size(struct dmxdev_filter *dmxdevfilter, unsign
306 308
307static void dvb_dmxdev_filter_timeout(unsigned long data) 309static void dvb_dmxdev_filter_timeout(unsigned long data)
308{ 310{
309 struct dmxdev_filter *dmxdevfilter=(struct dmxdev_filter *)data; 311 struct dmxdev_filter *dmxdevfilter = (struct dmxdev_filter *)data;
310 312
311 dmxdevfilter->buffer.error=-ETIMEDOUT; 313 dmxdevfilter->buffer.error = -ETIMEDOUT;
312 spin_lock_irq(&dmxdevfilter->dev->lock); 314 spin_lock_irq(&dmxdevfilter->dev->lock);
313 dmxdevfilter->state=DMXDEV_STATE_TIMEDOUT; 315 dmxdevfilter->state = DMXDEV_STATE_TIMEDOUT;
314 spin_unlock_irq(&dmxdevfilter->dev->lock); 316 spin_unlock_irq(&dmxdevfilter->dev->lock);
315 wake_up(&dmxdevfilter->buffer.queue); 317 wake_up(&dmxdevfilter->buffer.queue);
316} 318}
317 319
318static void dvb_dmxdev_filter_timer(struct dmxdev_filter *dmxdevfilter) 320static void dvb_dmxdev_filter_timer(struct dmxdev_filter *dmxdevfilter)
319{ 321{
320 struct dmx_sct_filter_params *para=&dmxdevfilter->params.sec; 322 struct dmx_sct_filter_params *para = &dmxdevfilter->params.sec;
321 323
322 del_timer(&dmxdevfilter->timer); 324 del_timer(&dmxdevfilter->timer);
323 if (para->timeout) { 325 if (para->timeout) {
324 dmxdevfilter->timer.function=dvb_dmxdev_filter_timeout; 326 dmxdevfilter->timer.function = dvb_dmxdev_filter_timeout;
325 dmxdevfilter->timer.data=(unsigned long) dmxdevfilter; 327 dmxdevfilter->timer.data = (unsigned long)dmxdevfilter;
326 dmxdevfilter->timer.expires=jiffies+1+(HZ/2+HZ*para->timeout)/1000; 328 dmxdevfilter->timer.expires =
329 jiffies + 1 + (HZ / 2 + HZ * para->timeout) / 1000;
327 add_timer(&dmxdevfilter->timer); 330 add_timer(&dmxdevfilter->timer);
328 } 331 }
329} 332}
330 333
331static int dvb_dmxdev_section_callback(const u8 *buffer1, size_t buffer1_len, 334static int dvb_dmxdev_section_callback(const u8 *buffer1, size_t buffer1_len,
332 const u8 *buffer2, size_t buffer2_len, 335 const u8 *buffer2, size_t buffer2_len,
333 struct dmx_section_filter *filter, enum dmx_success success) 336 struct dmx_section_filter *filter,
337 enum dmx_success success)
334{ 338{
335 struct dmxdev_filter *dmxdevfilter = filter->priv; 339 struct dmxdev_filter *dmxdevfilter = filter->priv;
336 int ret; 340 int ret;
@@ -340,68 +344,68 @@ static int dvb_dmxdev_section_callback(const u8 *buffer1, size_t buffer1_len,
340 return 0; 344 return 0;
341 } 345 }
342 spin_lock(&dmxdevfilter->dev->lock); 346 spin_lock(&dmxdevfilter->dev->lock);
343 if (dmxdevfilter->state!=DMXDEV_STATE_GO) { 347 if (dmxdevfilter->state != DMXDEV_STATE_GO) {
344 spin_unlock(&dmxdevfilter->dev->lock); 348 spin_unlock(&dmxdevfilter->dev->lock);
345 return 0; 349 return 0;
346 } 350 }
347 del_timer(&dmxdevfilter->timer); 351 del_timer(&dmxdevfilter->timer);
348 dprintk("dmxdev: section callback %02x %02x %02x %02x %02x %02x\n", 352 dprintk("dmxdev: section callback %02x %02x %02x %02x %02x %02x\n",
349 buffer1[0], buffer1[1], 353 buffer1[0], buffer1[1],
350 buffer1[2], buffer1[3], 354 buffer1[2], buffer1[3], buffer1[4], buffer1[5]);
351 buffer1[4], buffer1[5]); 355 ret = dvb_dmxdev_buffer_write(&dmxdevfilter->buffer, buffer1,
352 ret=dvb_dmxdev_buffer_write(&dmxdevfilter->buffer, buffer1, buffer1_len); 356 buffer1_len);
353 if (ret==buffer1_len) { 357 if (ret == buffer1_len) {
354 ret=dvb_dmxdev_buffer_write(&dmxdevfilter->buffer, buffer2, buffer2_len); 358 ret = dvb_dmxdev_buffer_write(&dmxdevfilter->buffer, buffer2,
359 buffer2_len);
355 } 360 }
356 if (ret<0) { 361 if (ret < 0) {
357 dmxdevfilter->buffer.pwrite=dmxdevfilter->buffer.pread; 362 dmxdevfilter->buffer.pwrite = dmxdevfilter->buffer.pread;
358 dmxdevfilter->buffer.error=-EOVERFLOW; 363 dmxdevfilter->buffer.error = -EOVERFLOW;
359 } 364 }
360 if (dmxdevfilter->params.sec.flags&DMX_ONESHOT) 365 if (dmxdevfilter->params.sec.flags & DMX_ONESHOT)
361 dmxdevfilter->state=DMXDEV_STATE_DONE; 366 dmxdevfilter->state = DMXDEV_STATE_DONE;
362 spin_unlock(&dmxdevfilter->dev->lock); 367 spin_unlock(&dmxdevfilter->dev->lock);
363 wake_up(&dmxdevfilter->buffer.queue); 368 wake_up(&dmxdevfilter->buffer.queue);
364 return 0; 369 return 0;
365} 370}
366 371
367static int dvb_dmxdev_ts_callback(const u8 *buffer1, size_t buffer1_len, 372static int dvb_dmxdev_ts_callback(const u8 *buffer1, size_t buffer1_len,
368 const u8 *buffer2, size_t buffer2_len, 373 const u8 *buffer2, size_t buffer2_len,
369 struct dmx_ts_feed *feed, enum dmx_success success) 374 struct dmx_ts_feed *feed,
375 enum dmx_success success)
370{ 376{
371 struct dmxdev_filter *dmxdevfilter = feed->priv; 377 struct dmxdev_filter *dmxdevfilter = feed->priv;
372 struct dmxdev_buffer *buffer; 378 struct dmxdev_buffer *buffer;
373 int ret; 379 int ret;
374 380
375 spin_lock(&dmxdevfilter->dev->lock); 381 spin_lock(&dmxdevfilter->dev->lock);
376 if (dmxdevfilter->params.pes.output==DMX_OUT_DECODER) { 382 if (dmxdevfilter->params.pes.output == DMX_OUT_DECODER) {
377 spin_unlock(&dmxdevfilter->dev->lock); 383 spin_unlock(&dmxdevfilter->dev->lock);
378 return 0; 384 return 0;
379 } 385 }
380 386
381 if (dmxdevfilter->params.pes.output==DMX_OUT_TAP) 387 if (dmxdevfilter->params.pes.output == DMX_OUT_TAP)
382 buffer=&dmxdevfilter->buffer; 388 buffer = &dmxdevfilter->buffer;
383 else 389 else
384 buffer=&dmxdevfilter->dev->dvr_buffer; 390 buffer = &dmxdevfilter->dev->dvr_buffer;
385 if (buffer->error) { 391 if (buffer->error) {
386 spin_unlock(&dmxdevfilter->dev->lock); 392 spin_unlock(&dmxdevfilter->dev->lock);
387 wake_up(&buffer->queue); 393 wake_up(&buffer->queue);
388 return 0; 394 return 0;
389 } 395 }
390 ret=dvb_dmxdev_buffer_write(buffer, buffer1, buffer1_len); 396 ret = dvb_dmxdev_buffer_write(buffer, buffer1, buffer1_len);
391 if (ret==buffer1_len) 397 if (ret == buffer1_len)
392 ret=dvb_dmxdev_buffer_write(buffer, buffer2, buffer2_len); 398 ret = dvb_dmxdev_buffer_write(buffer, buffer2, buffer2_len);
393 if (ret<0) { 399 if (ret < 0) {
394 buffer->pwrite=buffer->pread; 400 buffer->pwrite = buffer->pread;
395 buffer->error=-EOVERFLOW; 401 buffer->error = -EOVERFLOW;
396 } 402 }
397 spin_unlock(&dmxdevfilter->dev->lock); 403 spin_unlock(&dmxdevfilter->dev->lock);
398 wake_up(&buffer->queue); 404 wake_up(&buffer->queue);
399 return 0; 405 return 0;
400} 406}
401 407
402
403/* stop feed but only mark the specified filter as stopped (state set) */ 408/* stop feed but only mark the specified filter as stopped (state set) */
404
405static int dvb_dmxdev_feed_stop(struct dmxdev_filter *dmxdevfilter) 409static int dvb_dmxdev_feed_stop(struct dmxdev_filter *dmxdevfilter)
406{ 410{
407 dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_SET); 411 dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_SET);
@@ -420,20 +424,16 @@ static int dvb_dmxdev_feed_stop(struct dmxdev_filter *dmxdevfilter)
420 return 0; 424 return 0;
421} 425}
422 426
423
424/* start feed associated with the specified filter */ 427/* start feed associated with the specified filter */
425
426static int dvb_dmxdev_feed_start(struct dmxdev_filter *filter) 428static int dvb_dmxdev_feed_start(struct dmxdev_filter *filter)
427{ 429{
428 dvb_dmxdev_filter_state_set (filter, DMXDEV_STATE_GO); 430 dvb_dmxdev_filter_state_set(filter, DMXDEV_STATE_GO);
429 431
430 switch (filter->type) { 432 switch (filter->type) {
431 case DMXDEV_TYPE_SEC: 433 case DMXDEV_TYPE_SEC:
432 return filter->feed.sec->start_filtering(filter->feed.sec); 434 return filter->feed.sec->start_filtering(filter->feed.sec);
433 break;
434 case DMXDEV_TYPE_PES: 435 case DMXDEV_TYPE_PES:
435 return filter->feed.ts->start_filtering(filter->feed.ts); 436 return filter->feed.ts->start_filtering(filter->feed.ts);
436 break;
437 default: 437 default:
438 return -EINVAL; 438 return -EINVAL;
439 } 439 }
@@ -441,32 +441,31 @@ static int dvb_dmxdev_feed_start(struct dmxdev_filter *filter)
441 return 0; 441 return 0;
442} 442}
443 443
444
445/* restart section feed if it has filters left associated with it, 444/* restart section feed if it has filters left associated with it,
446 otherwise release the feed */ 445 otherwise release the feed */
447
448static int dvb_dmxdev_feed_restart(struct dmxdev_filter *filter) 446static int dvb_dmxdev_feed_restart(struct dmxdev_filter *filter)
449{ 447{
450 int i; 448 int i;
451 struct dmxdev *dmxdev = filter->dev; 449 struct dmxdev *dmxdev = filter->dev;
452 u16 pid = filter->params.sec.pid; 450 u16 pid = filter->params.sec.pid;
453 451
454 for (i=0; i<dmxdev->filternum; i++) 452 for (i = 0; i < dmxdev->filternum; i++)
455 if (dmxdev->filter[i].state>=DMXDEV_STATE_GO && 453 if (dmxdev->filter[i].state >= DMXDEV_STATE_GO &&
456 dmxdev->filter[i].type==DMXDEV_TYPE_SEC && 454 dmxdev->filter[i].type == DMXDEV_TYPE_SEC &&
457 dmxdev->filter[i].params.sec.pid==pid) { 455 dmxdev->filter[i].params.sec.pid == pid) {
458 dvb_dmxdev_feed_start(&dmxdev->filter[i]); 456 dvb_dmxdev_feed_start(&dmxdev->filter[i]);
459 return 0; 457 return 0;
460 } 458 }
461 459
462 filter->dev->demux->release_section_feed(dmxdev->demux, filter->feed.sec); 460 filter->dev->demux->release_section_feed(dmxdev->demux,
461 filter->feed.sec);
463 462
464 return 0; 463 return 0;
465} 464}
466 465
467static int dvb_dmxdev_filter_stop(struct dmxdev_filter *dmxdevfilter) 466static int dvb_dmxdev_filter_stop(struct dmxdev_filter *dmxdevfilter)
468{ 467{
469 if (dmxdevfilter->state<DMXDEV_STATE_GO) 468 if (dmxdevfilter->state < DMXDEV_STATE_GO)
470 return 0; 469 return 0;
471 470
472 switch (dmxdevfilter->type) { 471 switch (dmxdevfilter->type) {
@@ -476,35 +475,35 @@ static int dvb_dmxdev_filter_stop(struct dmxdev_filter *dmxdevfilter)
476 dvb_dmxdev_feed_stop(dmxdevfilter); 475 dvb_dmxdev_feed_stop(dmxdevfilter);
477 if (dmxdevfilter->filter.sec) 476 if (dmxdevfilter->filter.sec)
478 dmxdevfilter->feed.sec-> 477 dmxdevfilter->feed.sec->
479 release_filter(dmxdevfilter->feed.sec, 478 release_filter(dmxdevfilter->feed.sec,
480 dmxdevfilter->filter.sec); 479 dmxdevfilter->filter.sec);
481 dvb_dmxdev_feed_restart(dmxdevfilter); 480 dvb_dmxdev_feed_restart(dmxdevfilter);
482 dmxdevfilter->feed.sec=NULL; 481 dmxdevfilter->feed.sec = NULL;
483 break; 482 break;
484 case DMXDEV_TYPE_PES: 483 case DMXDEV_TYPE_PES:
485 if (!dmxdevfilter->feed.ts) 484 if (!dmxdevfilter->feed.ts)
486 break; 485 break;
487 dvb_dmxdev_feed_stop(dmxdevfilter); 486 dvb_dmxdev_feed_stop(dmxdevfilter);
488 dmxdevfilter->dev->demux-> 487 dmxdevfilter->dev->demux->
489 release_ts_feed(dmxdevfilter->dev->demux, 488 release_ts_feed(dmxdevfilter->dev->demux,
490 dmxdevfilter->feed.ts); 489 dmxdevfilter->feed.ts);
491 dmxdevfilter->feed.ts=NULL; 490 dmxdevfilter->feed.ts = NULL;
492 break; 491 break;
493 default: 492 default:
494 if (dmxdevfilter->state==DMXDEV_STATE_ALLOCATED) 493 if (dmxdevfilter->state == DMXDEV_STATE_ALLOCATED)
495 return 0; 494 return 0;
496 return -EINVAL; 495 return -EINVAL;
497 } 496 }
498 dmxdevfilter->buffer.pwrite=dmxdevfilter->buffer.pread=0; 497 dmxdevfilter->buffer.pwrite = dmxdevfilter->buffer.pread = 0;
499 return 0; 498 return 0;
500} 499}
501 500
502static inline int dvb_dmxdev_filter_reset(struct dmxdev_filter *dmxdevfilter) 501static inline int dvb_dmxdev_filter_reset(struct dmxdev_filter *dmxdevfilter)
503{ 502{
504 if (dmxdevfilter->state<DMXDEV_STATE_SET) 503 if (dmxdevfilter->state < DMXDEV_STATE_SET)
505 return 0; 504 return 0;
506 505
507 dmxdevfilter->type=DMXDEV_TYPE_NONE; 506 dmxdevfilter->type = DMXDEV_TYPE_NONE;
508 dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_ALLOCATED); 507 dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_ALLOCATED);
509 return 0; 508 return 0;
510} 509}
@@ -524,7 +523,7 @@ static int dvb_dmxdev_filter_start(struct dmxdev_filter *filter)
524 if (!(mem = filter->buffer.data)) { 523 if (!(mem = filter->buffer.data)) {
525 mem = vmalloc(filter->buffer.size); 524 mem = vmalloc(filter->buffer.size);
526 spin_lock_irq(&filter->dev->lock); 525 spin_lock_irq(&filter->dev->lock);
527 filter->buffer.data=mem; 526 filter->buffer.data = mem;
528 spin_unlock_irq(&filter->dev->lock); 527 spin_unlock_irq(&filter->dev->lock);
529 if (!filter->buffer.data) 528 if (!filter->buffer.data)
530 return -ENOMEM; 529 return -ENOMEM;
@@ -535,15 +534,16 @@ static int dvb_dmxdev_filter_start(struct dmxdev_filter *filter)
535 switch (filter->type) { 534 switch (filter->type) {
536 case DMXDEV_TYPE_SEC: 535 case DMXDEV_TYPE_SEC:
537 { 536 {
538 struct dmx_sct_filter_params *para=&filter->params.sec; 537 struct dmx_sct_filter_params *para = &filter->params.sec;
539 struct dmx_section_filter **secfilter=&filter->filter.sec; 538 struct dmx_section_filter **secfilter = &filter->filter.sec;
540 struct dmx_section_feed **secfeed=&filter->feed.sec; 539 struct dmx_section_feed **secfeed = &filter->feed.sec;
540
541 *secfilter = NULL;
542 *secfeed = NULL;
541 543
542 *secfilter=NULL;
543 *secfeed=NULL;
544 544
545 /* find active filter/feed with same PID */ 545 /* find active filter/feed with same PID */
546 for (i=0; i<dmxdev->filternum; i++) { 546 for (i = 0; i < dmxdev->filternum; i++) {
547 if (dmxdev->filter[i].state >= DMXDEV_STATE_GO && 547 if (dmxdev->filter[i].state >= DMXDEV_STATE_GO &&
548 dmxdev->filter[i].type == DMXDEV_TYPE_SEC && 548 dmxdev->filter[i].type == DMXDEV_TYPE_SEC &&
549 dmxdev->filter[i].params.sec.pid == para->pid) { 549 dmxdev->filter[i].params.sec.pid == para->pid) {
@@ -554,21 +554,20 @@ static int dvb_dmxdev_filter_start(struct dmxdev_filter *filter)
554 554
555 /* if no feed found, try to allocate new one */ 555 /* if no feed found, try to allocate new one */
556 if (!*secfeed) { 556 if (!*secfeed) {
557 ret=dmxdev->demux->allocate_section_feed(dmxdev->demux, 557 ret = dmxdev->demux->allocate_section_feed(dmxdev->demux,
558 secfeed, 558 secfeed,
559 dvb_dmxdev_section_callback); 559 dvb_dmxdev_section_callback);
560 if (ret<0) { 560 if (ret < 0) {
561 printk ("DVB (%s): could not alloc feed\n", 561 printk("DVB (%s): could not alloc feed\n",
562 __FUNCTION__); 562 __FUNCTION__);
563 return ret; 563 return ret;
564 } 564 }
565 565
566 ret=(*secfeed)->set(*secfeed, para->pid, 32768, 566 ret = (*secfeed)->set(*secfeed, para->pid, 32768,
567 (para->flags & DMX_CHECK_CRC) ? 1 : 0); 567 (para->flags & DMX_CHECK_CRC) ? 1 : 0);
568 568 if (ret < 0) {
569 if (ret<0) { 569 printk("DVB (%s): could not set feed\n",
570 printk ("DVB (%s): could not set feed\n", 570 __FUNCTION__);
571 __FUNCTION__);
572 dvb_dmxdev_feed_restart(filter); 571 dvb_dmxdev_feed_restart(filter);
573 return ret; 572 return ret;
574 } 573 }
@@ -576,41 +575,38 @@ static int dvb_dmxdev_filter_start(struct dmxdev_filter *filter)
576 dvb_dmxdev_feed_stop(filter); 575 dvb_dmxdev_feed_stop(filter);
577 } 576 }
578 577
579 ret=(*secfeed)->allocate_filter(*secfeed, secfilter); 578 ret = (*secfeed)->allocate_filter(*secfeed, secfilter);
580
581 if (ret < 0) { 579 if (ret < 0) {
582 dvb_dmxdev_feed_restart(filter); 580 dvb_dmxdev_feed_restart(filter);
583 filter->feed.sec->start_filtering(*secfeed); 581 filter->feed.sec->start_filtering(*secfeed);
584 dprintk ("could not get filter\n"); 582 dprintk("could not get filter\n");
585 return ret; 583 return ret;
586 } 584 }
587 585
588 (*secfilter)->priv = filter; 586 (*secfilter)->priv = filter;
589 587
590 memcpy(&((*secfilter)->filter_value[3]), 588 memcpy(&((*secfilter)->filter_value[3]),
591 &(para->filter.filter[1]), DMX_FILTER_SIZE-1); 589 &(para->filter.filter[1]), DMX_FILTER_SIZE - 1);
592 memcpy(&(*secfilter)->filter_mask[3], 590 memcpy(&(*secfilter)->filter_mask[3],
593 &para->filter.mask[1], DMX_FILTER_SIZE-1); 591 &para->filter.mask[1], DMX_FILTER_SIZE - 1);
594 memcpy(&(*secfilter)->filter_mode[3], 592 memcpy(&(*secfilter)->filter_mode[3],
595 &para->filter.mode[1], DMX_FILTER_SIZE-1); 593 &para->filter.mode[1], DMX_FILTER_SIZE - 1);
596 594
597 (*secfilter)->filter_value[0]=para->filter.filter[0]; 595 (*secfilter)->filter_value[0] = para->filter.filter[0];
598 (*secfilter)->filter_mask[0]=para->filter.mask[0]; 596 (*secfilter)->filter_mask[0] = para->filter.mask[0];
599 (*secfilter)->filter_mode[0]=para->filter.mode[0]; 597 (*secfilter)->filter_mode[0] = para->filter.mode[0];
600 (*secfilter)->filter_mask[1]=0; 598 (*secfilter)->filter_mask[1] = 0;
601 (*secfilter)->filter_mask[2]=0; 599 (*secfilter)->filter_mask[2] = 0;
602 600
603 filter->todo = 0; 601 filter->todo = 0;
604 602
605 ret = filter->feed.sec->start_filtering (filter->feed.sec); 603 ret = filter->feed.sec->start_filtering(filter->feed.sec);
606
607 if (ret < 0) 604 if (ret < 0)
608 return ret; 605 return ret;
609 606
610 dvb_dmxdev_filter_timer(filter); 607 dvb_dmxdev_filter_timer(filter);
611 break; 608 break;
612 } 609 }
613
614 case DMXDEV_TYPE_PES: 610 case DMXDEV_TYPE_PES:
615 { 611 {
616 struct timespec timeout = { 0 }; 612 struct timespec timeout = { 0 };
@@ -622,41 +618,41 @@ static int dvb_dmxdev_filter_start(struct dmxdev_filter *filter)
622 struct dmx_ts_feed **tsfeed = &filter->feed.ts; 618 struct dmx_ts_feed **tsfeed = &filter->feed.ts;
623 619
624 filter->feed.ts = NULL; 620 filter->feed.ts = NULL;
625 otype=para->output; 621 otype = para->output;
626 622
627 ts_pes=(enum dmx_ts_pes) para->pes_type; 623 ts_pes = (enum dmx_ts_pes)para->pes_type;
628 624
629 if (ts_pes<DMX_PES_OTHER) 625 if (ts_pes < DMX_PES_OTHER)
630 ts_type=TS_DECODER; 626 ts_type = TS_DECODER;
631 else 627 else
632 ts_type=0; 628 ts_type = 0;
633 629
634 if (otype == DMX_OUT_TS_TAP) 630 if (otype == DMX_OUT_TS_TAP)
635 ts_type |= TS_PACKET; 631 ts_type |= TS_PACKET;
636 632
637 if (otype == DMX_OUT_TAP) 633 if (otype == DMX_OUT_TAP)
638 ts_type |= TS_PAYLOAD_ONLY|TS_PACKET; 634 ts_type |= TS_PAYLOAD_ONLY | TS_PACKET;
639 635
640 ret=dmxdev->demux->allocate_ts_feed(dmxdev->demux, 636 ret = dmxdev->demux->allocate_ts_feed(dmxdev->demux,
641 tsfeed, 637 tsfeed,
642 dvb_dmxdev_ts_callback); 638 dvb_dmxdev_ts_callback);
643 if (ret<0) 639 if (ret < 0)
644 return ret; 640 return ret;
645 641
646 (*tsfeed)->priv = (void *) filter; 642 (*tsfeed)->priv = filter;
647 643
648 ret = (*tsfeed)->set(*tsfeed, para->pid, ts_type, ts_pes, 644 ret = (*tsfeed)->set(*tsfeed, para->pid, ts_type, ts_pes,
649 32768, timeout); 645 32768, timeout);
650
651 if (ret < 0) { 646 if (ret < 0) {
652 dmxdev->demux->release_ts_feed(dmxdev->demux, *tsfeed); 647 dmxdev->demux->release_ts_feed(dmxdev->demux,
648 *tsfeed);
653 return ret; 649 return ret;
654 } 650 }
655 651
656 ret = filter->feed.ts->start_filtering(filter->feed.ts); 652 ret = filter->feed.ts->start_filtering(filter->feed.ts);
657
658 if (ret < 0) { 653 if (ret < 0) {
659 dmxdev->demux->release_ts_feed(dmxdev->demux, *tsfeed); 654 dmxdev->demux->release_ts_feed(dmxdev->demux,
655 *tsfeed);
660 return ret; 656 return ret;
661 } 657 }
662 658
@@ -683,31 +679,31 @@ static int dvb_demux_open(struct inode *inode, struct file *file)
683 if (mutex_lock_interruptible(&dmxdev->mutex)) 679 if (mutex_lock_interruptible(&dmxdev->mutex))
684 return -ERESTARTSYS; 680 return -ERESTARTSYS;
685 681
686 for (i=0; i<dmxdev->filternum; i++) 682 for (i = 0; i < dmxdev->filternum; i++)
687 if (dmxdev->filter[i].state==DMXDEV_STATE_FREE) 683 if (dmxdev->filter[i].state == DMXDEV_STATE_FREE)
688 break; 684 break;
689 685
690 if (i==dmxdev->filternum) { 686 if (i == dmxdev->filternum) {
691 mutex_unlock(&dmxdev->mutex); 687 mutex_unlock(&dmxdev->mutex);
692 return -EMFILE; 688 return -EMFILE;
693 } 689 }
694 690
695 dmxdevfilter=&dmxdev->filter[i]; 691 dmxdevfilter = &dmxdev->filter[i];
696 mutex_init(&dmxdevfilter->mutex); 692 mutex_init(&dmxdevfilter->mutex);
697 file->private_data=dmxdevfilter; 693 file->private_data = dmxdevfilter;
698 694
699 dvb_dmxdev_buffer_init(&dmxdevfilter->buffer); 695 dvb_dmxdev_buffer_init(&dmxdevfilter->buffer);
700 dmxdevfilter->type=DMXDEV_TYPE_NONE; 696 dmxdevfilter->type = DMXDEV_TYPE_NONE;
701 dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_ALLOCATED); 697 dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_ALLOCATED);
702 dmxdevfilter->feed.ts=NULL; 698 dmxdevfilter->feed.ts = NULL;
703 init_timer(&dmxdevfilter->timer); 699 init_timer(&dmxdevfilter->timer);
704 700
705 mutex_unlock(&dmxdev->mutex); 701 mutex_unlock(&dmxdev->mutex);
706 return 0; 702 return 0;
707} 703}
708 704
709 705static int dvb_dmxdev_filter_free(struct dmxdev *dmxdev,
710static int dvb_dmxdev_filter_free(struct dmxdev *dmxdev, struct dmxdev_filter *dmxdevfilter) 706 struct dmxdev_filter *dmxdevfilter)
711{ 707{
712 if (mutex_lock_interruptible(&dmxdev->mutex)) 708 if (mutex_lock_interruptible(&dmxdev->mutex))
713 return -ERESTARTSYS; 709 return -ERESTARTSYS;
@@ -721,10 +717,10 @@ static int dvb_dmxdev_filter_free(struct dmxdev *dmxdev, struct dmxdev_filter *d
721 dvb_dmxdev_filter_reset(dmxdevfilter); 717 dvb_dmxdev_filter_reset(dmxdevfilter);
722 718
723 if (dmxdevfilter->buffer.data) { 719 if (dmxdevfilter->buffer.data) {
724 void *mem=dmxdevfilter->buffer.data; 720 void *mem = dmxdevfilter->buffer.data;
725 721
726 spin_lock_irq(&dmxdev->lock); 722 spin_lock_irq(&dmxdev->lock);
727 dmxdevfilter->buffer.data=NULL; 723 dmxdevfilter->buffer.data = NULL;
728 spin_unlock_irq(&dmxdev->lock); 724 spin_unlock_irq(&dmxdev->lock);
729 vfree(mem); 725 vfree(mem);
730 } 726 }
@@ -740,118 +736,120 @@ static inline void invert_mode(dmx_filter_t *filter)
740{ 736{
741 int i; 737 int i;
742 738
743 for (i=0; i<DMX_FILTER_SIZE; i++) 739 for (i = 0; i < DMX_FILTER_SIZE; i++)
744 filter->mode[i]^=0xff; 740 filter->mode[i] ^= 0xff;
745} 741}
746 742
747
748static int dvb_dmxdev_filter_set(struct dmxdev *dmxdev, 743static int dvb_dmxdev_filter_set(struct dmxdev *dmxdev,
749 struct dmxdev_filter *dmxdevfilter, 744 struct dmxdev_filter *dmxdevfilter,
750 struct dmx_sct_filter_params *params) 745 struct dmx_sct_filter_params *params)
751{ 746{
752 dprintk ("function : %s\n", __FUNCTION__); 747 dprintk("function : %s\n", __FUNCTION__);
753 748
754 dvb_dmxdev_filter_stop(dmxdevfilter); 749 dvb_dmxdev_filter_stop(dmxdevfilter);
755 750
756 dmxdevfilter->type=DMXDEV_TYPE_SEC; 751 dmxdevfilter->type = DMXDEV_TYPE_SEC;
757 memcpy(&dmxdevfilter->params.sec, 752 memcpy(&dmxdevfilter->params.sec,
758 params, sizeof(struct dmx_sct_filter_params)); 753 params, sizeof(struct dmx_sct_filter_params));
759 invert_mode(&dmxdevfilter->params.sec.filter); 754 invert_mode(&dmxdevfilter->params.sec.filter);
760 dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_SET); 755 dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_SET);
761 756
762 if (params->flags&DMX_IMMEDIATE_START) 757 if (params->flags & DMX_IMMEDIATE_START)
763 return dvb_dmxdev_filter_start(dmxdevfilter); 758 return dvb_dmxdev_filter_start(dmxdevfilter);
764 759
765 return 0; 760 return 0;
766} 761}
767 762
768static int dvb_dmxdev_pes_filter_set(struct dmxdev *dmxdev, 763static int dvb_dmxdev_pes_filter_set(struct dmxdev *dmxdev,
769 struct dmxdev_filter *dmxdevfilter, 764 struct dmxdev_filter *dmxdevfilter,
770 struct dmx_pes_filter_params *params) 765 struct dmx_pes_filter_params *params)
771{ 766{
772 dvb_dmxdev_filter_stop(dmxdevfilter); 767 dvb_dmxdev_filter_stop(dmxdevfilter);
773 768
774 if (params->pes_type>DMX_PES_OTHER || params->pes_type<0) 769 if (params->pes_type > DMX_PES_OTHER || params->pes_type < 0)
775 return -EINVAL; 770 return -EINVAL;
776 771
777 dmxdevfilter->type=DMXDEV_TYPE_PES; 772 dmxdevfilter->type = DMXDEV_TYPE_PES;
778 memcpy(&dmxdevfilter->params, params, sizeof(struct dmx_pes_filter_params)); 773 memcpy(&dmxdevfilter->params, params,
774 sizeof(struct dmx_pes_filter_params));
779 775
780 dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_SET); 776 dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_SET);
781 777
782 if (params->flags&DMX_IMMEDIATE_START) 778 if (params->flags & DMX_IMMEDIATE_START)
783 return dvb_dmxdev_filter_start(dmxdevfilter); 779 return dvb_dmxdev_filter_start(dmxdevfilter);
784 780
785 return 0; 781 return 0;
786} 782}
787 783
788static ssize_t dvb_dmxdev_read_sec(struct dmxdev_filter *dfil, 784static ssize_t dvb_dmxdev_read_sec(struct dmxdev_filter *dfil,
789 struct file *file, char __user *buf, size_t count, loff_t *ppos) 785 struct file *file, char __user *buf,
786 size_t count, loff_t *ppos)
790{ 787{
791 int result, hcount; 788 int result, hcount;
792 int done=0; 789 int done = 0;
793 790
794 if (dfil->todo<=0) { 791 if (dfil->todo <= 0) {
795 hcount=3+dfil->todo; 792 hcount = 3 + dfil->todo;
796 if (hcount>count) 793 if (hcount > count)
797 hcount=count; 794 hcount = count;
798 result=dvb_dmxdev_buffer_read(&dfil->buffer, file->f_flags&O_NONBLOCK, 795 result = dvb_dmxdev_buffer_read(&dfil->buffer,
799 buf, hcount, ppos); 796 file->f_flags & O_NONBLOCK,
800 if (result<0) { 797 buf, hcount, ppos);
801 dfil->todo=0; 798 if (result < 0) {
799 dfil->todo = 0;
802 return result; 800 return result;
803 } 801 }
804 if (copy_from_user(dfil->secheader-dfil->todo, buf, result)) 802 if (copy_from_user(dfil->secheader - dfil->todo, buf, result))
805 return -EFAULT; 803 return -EFAULT;
806 buf+=result; 804 buf += result;
807 done=result; 805 done = result;
808 count-=result; 806 count -= result;
809 dfil->todo-=result; 807 dfil->todo -= result;
810 if (dfil->todo>-3) 808 if (dfil->todo > -3)
811 return done; 809 return done;
812 dfil->todo=((dfil->secheader[1]<<8)|dfil->secheader[2])&0xfff; 810 dfil->todo = ((dfil->secheader[1] << 8) | dfil->secheader[2]) & 0xfff;
813 if (!count) 811 if (!count)
814 return done; 812 return done;
815 } 813 }
816 if (count>dfil->todo) 814 if (count > dfil->todo)
817 count=dfil->todo; 815 count = dfil->todo;
818 result=dvb_dmxdev_buffer_read(&dfil->buffer, file->f_flags&O_NONBLOCK, 816 result = dvb_dmxdev_buffer_read(&dfil->buffer,
819 buf, count, ppos); 817 file->f_flags & O_NONBLOCK,
820 if (result<0) 818 buf, count, ppos);
819 if (result < 0)
821 return result; 820 return result;
822 dfil->todo-=result; 821 dfil->todo -= result;
823 return (result+done); 822 return (result + done);
824} 823}
825 824
826
827static ssize_t 825static ssize_t
828dvb_demux_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) 826dvb_demux_read(struct file *file, char __user *buf, size_t count,
827 loff_t *ppos)
829{ 828{
830 struct dmxdev_filter *dmxdevfilter= file->private_data; 829 struct dmxdev_filter *dmxdevfilter = file->private_data;
831 int ret=0; 830 int ret;
832 831
833 if (mutex_lock_interruptible(&dmxdevfilter->mutex)) 832 if (mutex_lock_interruptible(&dmxdevfilter->mutex))
834 return -ERESTARTSYS; 833 return -ERESTARTSYS;
835 834
836 if (dmxdevfilter->type==DMXDEV_TYPE_SEC) 835 if (dmxdevfilter->type == DMXDEV_TYPE_SEC)
837 ret=dvb_dmxdev_read_sec(dmxdevfilter, file, buf, count, ppos); 836 ret = dvb_dmxdev_read_sec(dmxdevfilter, file, buf, count, ppos);
838 else 837 else
839 ret=dvb_dmxdev_buffer_read(&dmxdevfilter->buffer, 838 ret = dvb_dmxdev_buffer_read(&dmxdevfilter->buffer,
840 file->f_flags&O_NONBLOCK, 839 file->f_flags & O_NONBLOCK,
841 buf, count, ppos); 840 buf, count, ppos);
842 841
843 mutex_unlock(&dmxdevfilter->mutex); 842 mutex_unlock(&dmxdevfilter->mutex);
844 return ret; 843 return ret;
845} 844}
846 845
847
848static int dvb_demux_do_ioctl(struct inode *inode, struct file *file, 846static int dvb_demux_do_ioctl(struct inode *inode, struct file *file,
849 unsigned int cmd, void *parg) 847 unsigned int cmd, void *parg)
850{ 848{
851 struct dmxdev_filter *dmxdevfilter = file->private_data; 849 struct dmxdev_filter *dmxdevfilter = file->private_data;
852 struct dmxdev *dmxdev=dmxdevfilter->dev; 850 struct dmxdev *dmxdev = dmxdevfilter->dev;
853 unsigned long arg=(unsigned long) parg; 851 unsigned long arg = (unsigned long)parg;
854 int ret=0; 852 int ret = 0;
855 853
856 if (mutex_lock_interruptible(&dmxdev->mutex)) 854 if (mutex_lock_interruptible(&dmxdev->mutex))
857 return -ERESTARTSYS; 855 return -ERESTARTSYS;
@@ -862,7 +860,7 @@ static int dvb_demux_do_ioctl(struct inode *inode, struct file *file,
862 mutex_unlock(&dmxdev->mutex); 860 mutex_unlock(&dmxdev->mutex);
863 return -ERESTARTSYS; 861 return -ERESTARTSYS;
864 } 862 }
865 if (dmxdevfilter->state<DMXDEV_STATE_SET) 863 if (dmxdevfilter->state < DMXDEV_STATE_SET)
866 ret = -EINVAL; 864 ret = -EINVAL;
867 else 865 else
868 ret = dvb_dmxdev_filter_start(dmxdevfilter); 866 ret = dvb_dmxdev_filter_start(dmxdevfilter);
@@ -874,7 +872,7 @@ static int dvb_demux_do_ioctl(struct inode *inode, struct file *file,
874 mutex_unlock(&dmxdev->mutex); 872 mutex_unlock(&dmxdev->mutex);
875 return -ERESTARTSYS; 873 return -ERESTARTSYS;
876 } 874 }
877 ret=dvb_dmxdev_filter_stop(dmxdevfilter); 875 ret = dvb_dmxdev_filter_stop(dmxdevfilter);
878 mutex_unlock(&dmxdevfilter->mutex); 876 mutex_unlock(&dmxdevfilter->mutex);
879 break; 877 break;
880 878
@@ -883,8 +881,7 @@ static int dvb_demux_do_ioctl(struct inode *inode, struct file *file,
883 mutex_unlock(&dmxdev->mutex); 881 mutex_unlock(&dmxdev->mutex);
884 return -ERESTARTSYS; 882 return -ERESTARTSYS;
885 } 883 }
886 ret = dvb_dmxdev_filter_set(dmxdev, dmxdevfilter, 884 ret = dvb_dmxdev_filter_set(dmxdev, dmxdevfilter, parg);
887 (struct dmx_sct_filter_params *)parg);
888 mutex_unlock(&dmxdevfilter->mutex); 885 mutex_unlock(&dmxdevfilter->mutex);
889 break; 886 break;
890 887
@@ -893,8 +890,7 @@ static int dvb_demux_do_ioctl(struct inode *inode, struct file *file,
893 mutex_unlock(&dmxdev->mutex); 890 mutex_unlock(&dmxdev->mutex);
894 return -ERESTARTSYS; 891 return -ERESTARTSYS;
895 } 892 }
896 ret=dvb_dmxdev_pes_filter_set(dmxdev, dmxdevfilter, 893 ret = dvb_dmxdev_pes_filter_set(dmxdev, dmxdevfilter, parg);
897 (struct dmx_pes_filter_params *)parg);
898 mutex_unlock(&dmxdevfilter->mutex); 894 mutex_unlock(&dmxdevfilter->mutex);
899 break; 895 break;
900 896
@@ -903,7 +899,7 @@ static int dvb_demux_do_ioctl(struct inode *inode, struct file *file,
903 mutex_unlock(&dmxdev->mutex); 899 mutex_unlock(&dmxdev->mutex);
904 return -ERESTARTSYS; 900 return -ERESTARTSYS;
905 } 901 }
906 ret=dvb_dmxdev_set_buffer_size(dmxdevfilter, arg); 902 ret = dvb_dmxdev_set_buffer_size(dmxdevfilter, arg);
907 mutex_unlock(&dmxdevfilter->mutex); 903 mutex_unlock(&dmxdevfilter->mutex);
908 break; 904 break;
909 905
@@ -912,10 +908,10 @@ static int dvb_demux_do_ioctl(struct inode *inode, struct file *file,
912 908
913 case DMX_GET_PES_PIDS: 909 case DMX_GET_PES_PIDS:
914 if (!dmxdev->demux->get_pes_pids) { 910 if (!dmxdev->demux->get_pes_pids) {
915 ret=-EINVAL; 911 ret = -EINVAL;
916 break; 912 break;
917 } 913 }
918 dmxdev->demux->get_pes_pids(dmxdev->demux, (u16 *)parg); 914 dmxdev->demux->get_pes_pids(dmxdev->demux, parg);
919 break; 915 break;
920 916
921 case DMX_GET_CAPS: 917 case DMX_GET_CAPS:
@@ -936,17 +932,18 @@ static int dvb_demux_do_ioctl(struct inode *inode, struct file *file,
936 932
937 case DMX_GET_STC: 933 case DMX_GET_STC:
938 if (!dmxdev->demux->get_stc) { 934 if (!dmxdev->demux->get_stc) {
939 ret=-EINVAL; 935 ret = -EINVAL;
940 break; 936 break;
941 } 937 }
942 ret = dmxdev->demux->get_stc(dmxdev->demux, 938 ret = dmxdev->demux->get_stc(dmxdev->demux,
943 ((struct dmx_stc *)parg)->num, 939 ((struct dmx_stc *)parg)->num,
944 &((struct dmx_stc *)parg)->stc, 940 &((struct dmx_stc *)parg)->stc,
945 &((struct dmx_stc *)parg)->base); 941 &((struct dmx_stc *)parg)->base);
946 break; 942 break;
947 943
948 default: 944 default:
949 ret=-EINVAL; 945 ret = -EINVAL;
946 break;
950 } 947 }
951 mutex_unlock(&dmxdev->mutex); 948 mutex_unlock(&dmxdev->mutex);
952 return ret; 949 return ret;
@@ -958,8 +955,7 @@ static int dvb_demux_ioctl(struct inode *inode, struct file *file,
958 return dvb_usercopy(inode, file, cmd, arg, dvb_demux_do_ioctl); 955 return dvb_usercopy(inode, file, cmd, arg, dvb_demux_do_ioctl);
959} 956}
960 957
961 958static unsigned int dvb_demux_poll(struct file *file, poll_table *wait)
962static unsigned int dvb_demux_poll (struct file *file, poll_table *wait)
963{ 959{
964 struct dmxdev_filter *dmxdevfilter = file->private_data; 960 struct dmxdev_filter *dmxdevfilter = file->private_data;
965 unsigned int mask = 0; 961 unsigned int mask = 0;
@@ -983,7 +979,6 @@ static unsigned int dvb_demux_poll (struct file *file, poll_table *wait)
983 return mask; 979 return mask;
984} 980}
985 981
986
987static int dvb_demux_release(struct inode *inode, struct file *file) 982static int dvb_demux_release(struct inode *inode, struct file *file)
988{ 983{
989 struct dmxdev_filter *dmxdevfilter = file->private_data; 984 struct dmxdev_filter *dmxdevfilter = file->private_data;
@@ -992,32 +987,28 @@ static int dvb_demux_release(struct inode *inode, struct file *file)
992 return dvb_dmxdev_filter_free(dmxdev, dmxdevfilter); 987 return dvb_dmxdev_filter_free(dmxdev, dmxdevfilter);
993} 988}
994 989
995
996static struct file_operations dvb_demux_fops = { 990static struct file_operations dvb_demux_fops = {
997 .owner = THIS_MODULE, 991 .owner = THIS_MODULE,
998 .read = dvb_demux_read, 992 .read = dvb_demux_read,
999 .ioctl = dvb_demux_ioctl, 993 .ioctl = dvb_demux_ioctl,
1000 .open = dvb_demux_open, 994 .open = dvb_demux_open,
1001 .release = dvb_demux_release, 995 .release = dvb_demux_release,
1002 .poll = dvb_demux_poll, 996 .poll = dvb_demux_poll,
1003}; 997};
1004 998
1005
1006static struct dvb_device dvbdev_demux = { 999static struct dvb_device dvbdev_demux = {
1007 .priv = NULL, 1000 .priv = NULL,
1008 .users = 1, 1001 .users = 1,
1009 .writers = 1, 1002 .writers = 1,
1010 .fops = &dvb_demux_fops 1003 .fops = &dvb_demux_fops
1011}; 1004};
1012 1005
1013
1014static int dvb_dvr_do_ioctl(struct inode *inode, struct file *file, 1006static int dvb_dvr_do_ioctl(struct inode *inode, struct file *file,
1015 unsigned int cmd, void *parg) 1007 unsigned int cmd, void *parg)
1016{ 1008{
1017 struct dvb_device *dvbdev = file->private_data; 1009 struct dvb_device *dvbdev = file->private_data;
1018 struct dmxdev *dmxdev = dvbdev->priv; 1010 struct dmxdev *dmxdev = dvbdev->priv;
1019 1011 int ret;
1020 int ret=0;
1021 1012
1022 if (mutex_lock_interruptible(&dmxdev->mutex)) 1013 if (mutex_lock_interruptible(&dmxdev->mutex))
1023 return -ERESTARTSYS; 1014 return -ERESTARTSYS;
@@ -1025,39 +1016,38 @@ static int dvb_dvr_do_ioctl(struct inode *inode, struct file *file,
1025 switch (cmd) { 1016 switch (cmd) {
1026 case DMX_SET_BUFFER_SIZE: 1017 case DMX_SET_BUFFER_SIZE:
1027 // FIXME: implement 1018 // FIXME: implement
1028 ret=0; 1019 ret = 0;
1029 break; 1020 break;
1030 1021
1031 default: 1022 default:
1032 ret=-EINVAL; 1023 ret = -EINVAL;
1024 break;
1033 } 1025 }
1034 mutex_unlock(&dmxdev->mutex); 1026 mutex_unlock(&dmxdev->mutex);
1035 return ret; 1027 return ret;
1036} 1028}
1037 1029
1038
1039static int dvb_dvr_ioctl(struct inode *inode, struct file *file, 1030static int dvb_dvr_ioctl(struct inode *inode, struct file *file,
1040 unsigned int cmd, unsigned long arg) 1031 unsigned int cmd, unsigned long arg)
1041{ 1032{
1042 return dvb_usercopy(inode, file, cmd, arg, dvb_dvr_do_ioctl); 1033 return dvb_usercopy(inode, file, cmd, arg, dvb_dvr_do_ioctl);
1043} 1034}
1044 1035
1045 1036static unsigned int dvb_dvr_poll(struct file *file, poll_table *wait)
1046static unsigned int dvb_dvr_poll (struct file *file, poll_table *wait)
1047{ 1037{
1048 struct dvb_device *dvbdev = file->private_data; 1038 struct dvb_device *dvbdev = file->private_data;
1049 struct dmxdev *dmxdev = dvbdev->priv; 1039 struct dmxdev *dmxdev = dvbdev->priv;
1050 unsigned int mask = 0; 1040 unsigned int mask = 0;
1051 1041
1052 dprintk ("function : %s\n", __FUNCTION__); 1042 dprintk("function : %s\n", __FUNCTION__);
1053 1043
1054 poll_wait(file, &dmxdev->dvr_buffer.queue, wait); 1044 poll_wait(file, &dmxdev->dvr_buffer.queue, wait);
1055 1045
1056 if ((file->f_flags&O_ACCMODE) == O_RDONLY) { 1046 if ((file->f_flags & O_ACCMODE) == O_RDONLY) {
1057 if (dmxdev->dvr_buffer.error) 1047 if (dmxdev->dvr_buffer.error)
1058 mask |= (POLLIN | POLLRDNORM | POLLPRI | POLLERR); 1048 mask |= (POLLIN | POLLRDNORM | POLLPRI | POLLERR);
1059 1049
1060 if (dmxdev->dvr_buffer.pread!=dmxdev->dvr_buffer.pwrite) 1050 if (dmxdev->dvr_buffer.pread != dmxdev->dvr_buffer.pwrite)
1061 mask |= (POLLIN | POLLRDNORM | POLLPRI); 1051 mask |= (POLLIN | POLLRDNORM | POLLPRI);
1062 } else 1052 } else
1063 mask |= (POLLOUT | POLLWRNORM | POLLPRI); 1053 mask |= (POLLOUT | POLLWRNORM | POLLPRI);
@@ -1065,61 +1055,63 @@ static unsigned int dvb_dvr_poll (struct file *file, poll_table *wait)
1065 return mask; 1055 return mask;
1066} 1056}
1067 1057
1068
1069static struct file_operations dvb_dvr_fops = { 1058static struct file_operations dvb_dvr_fops = {
1070 .owner = THIS_MODULE, 1059 .owner = THIS_MODULE,
1071 .read = dvb_dvr_read, 1060 .read = dvb_dvr_read,
1072 .write = dvb_dvr_write, 1061 .write = dvb_dvr_write,
1073 .ioctl = dvb_dvr_ioctl, 1062 .ioctl = dvb_dvr_ioctl,
1074 .open = dvb_dvr_open, 1063 .open = dvb_dvr_open,
1075 .release = dvb_dvr_release, 1064 .release = dvb_dvr_release,
1076 .poll = dvb_dvr_poll, 1065 .poll = dvb_dvr_poll,
1077}; 1066};
1078 1067
1079static struct dvb_device dvbdev_dvr = { 1068static struct dvb_device dvbdev_dvr = {
1080 .priv = NULL, 1069 .priv = NULL,
1081 .users = 1, 1070 .users = 1,
1082 .writers = 1, 1071 .writers = 1,
1083 .fops = &dvb_dvr_fops 1072 .fops = &dvb_dvr_fops
1084}; 1073};
1085 1074
1086int 1075int dvb_dmxdev_init(struct dmxdev *dmxdev, struct dvb_adapter *dvb_adapter)
1087dvb_dmxdev_init(struct dmxdev *dmxdev, struct dvb_adapter *dvb_adapter)
1088{ 1076{
1089 int i; 1077 int i;
1090 1078
1091 if (dmxdev->demux->open(dmxdev->demux) < 0) 1079 if (dmxdev->demux->open(dmxdev->demux) < 0)
1092 return -EUSERS; 1080 return -EUSERS;
1093 1081
1094 dmxdev->filter = vmalloc(dmxdev->filternum*sizeof(struct dmxdev_filter)); 1082 dmxdev->filter = vmalloc(dmxdev->filternum * sizeof(struct dmxdev_filter));
1095 if (!dmxdev->filter) 1083 if (!dmxdev->filter)
1096 return -ENOMEM; 1084 return -ENOMEM;
1097 1085
1098 mutex_init(&dmxdev->mutex); 1086 mutex_init(&dmxdev->mutex);
1099 spin_lock_init(&dmxdev->lock); 1087 spin_lock_init(&dmxdev->lock);
1100 for (i=0; i<dmxdev->filternum; i++) { 1088 for (i = 0; i < dmxdev->filternum; i++) {
1101 dmxdev->filter[i].dev=dmxdev; 1089 dmxdev->filter[i].dev = dmxdev;
1102 dmxdev->filter[i].buffer.data=NULL; 1090 dmxdev->filter[i].buffer.data = NULL;
1103 dvb_dmxdev_filter_state_set(&dmxdev->filter[i], DMXDEV_STATE_FREE); 1091 dvb_dmxdev_filter_state_set(&dmxdev->filter[i],
1092 DMXDEV_STATE_FREE);
1104 } 1093 }
1105 1094
1106 dvb_register_device(dvb_adapter, &dmxdev->dvbdev, &dvbdev_demux, dmxdev, DVB_DEVICE_DEMUX); 1095 dvb_register_device(dvb_adapter, &dmxdev->dvbdev, &dvbdev_demux, dmxdev,
1107 dvb_register_device(dvb_adapter, &dmxdev->dvr_dvbdev, &dvbdev_dvr, dmxdev, DVB_DEVICE_DVR); 1096 DVB_DEVICE_DEMUX);
1097 dvb_register_device(dvb_adapter, &dmxdev->dvr_dvbdev, &dvbdev_dvr,
1098 dmxdev, DVB_DEVICE_DVR);
1108 1099
1109 dvb_dmxdev_buffer_init(&dmxdev->dvr_buffer); 1100 dvb_dmxdev_buffer_init(&dmxdev->dvr_buffer);
1110 1101
1111 return 0; 1102 return 0;
1112} 1103}
1104
1113EXPORT_SYMBOL(dvb_dmxdev_init); 1105EXPORT_SYMBOL(dvb_dmxdev_init);
1114 1106
1115void 1107void dvb_dmxdev_release(struct dmxdev *dmxdev)
1116dvb_dmxdev_release(struct dmxdev *dmxdev)
1117{ 1108{
1118 dvb_unregister_device(dmxdev->dvbdev); 1109 dvb_unregister_device(dmxdev->dvbdev);
1119 dvb_unregister_device(dmxdev->dvr_dvbdev); 1110 dvb_unregister_device(dmxdev->dvr_dvbdev);
1120 1111
1121 vfree(dmxdev->filter); 1112 vfree(dmxdev->filter);
1122 dmxdev->filter=NULL; 1113 dmxdev->filter = NULL;
1123 dmxdev->demux->close(dmxdev->demux); 1114 dmxdev->demux->close(dmxdev->demux);
1124} 1115}
1116
1125EXPORT_SYMBOL(dvb_dmxdev_release); 1117EXPORT_SYMBOL(dvb_dmxdev_release);