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