diff options
Diffstat (limited to 'drivers/ieee1394/video1394.c')
-rw-r--r-- | drivers/ieee1394/video1394.c | 106 |
1 files changed, 28 insertions, 78 deletions
diff --git a/drivers/ieee1394/video1394.c b/drivers/ieee1394/video1394.c index 23911da50154..608479b2df14 100644 --- a/drivers/ieee1394/video1394.c +++ b/drivers/ieee1394/video1394.c | |||
@@ -19,12 +19,6 @@ | |||
19 | * | 19 | * |
20 | * NOTES: | 20 | * NOTES: |
21 | * | 21 | * |
22 | * jds -- add private data to file to keep track of iso contexts associated | ||
23 | * with each open -- so release won't kill all iso transfers. | ||
24 | * | ||
25 | * Damien Douxchamps: Fix failure when the number of DMA pages per frame is | ||
26 | * one. | ||
27 | * | ||
28 | * ioctl return codes: | 22 | * ioctl return codes: |
29 | * EFAULT is only for invalid address for the argp | 23 | * EFAULT is only for invalid address for the argp |
30 | * EINVAL for out of range values | 24 | * EINVAL for out of range values |
@@ -34,12 +28,6 @@ | |||
34 | * ENOTTY for unsupported ioctl request | 28 | * ENOTTY for unsupported ioctl request |
35 | * | 29 | * |
36 | */ | 30 | */ |
37 | |||
38 | /* Markus Tavenrath <speedygoo@speedygoo.de> : | ||
39 | - fixed checks for valid buffer-numbers in video1394_icotl | ||
40 | - changed the ways the dma prg's are used, now it's possible to use | ||
41 | even a single dma buffer | ||
42 | */ | ||
43 | #include <linux/config.h> | 31 | #include <linux/config.h> |
44 | #include <linux/kernel.h> | 32 | #include <linux/kernel.h> |
45 | #include <linux/list.h> | 33 | #include <linux/list.h> |
@@ -77,14 +65,6 @@ | |||
77 | 65 | ||
78 | #define ISO_CHANNELS 64 | 66 | #define ISO_CHANNELS 64 |
79 | 67 | ||
80 | #ifndef virt_to_page | ||
81 | #define virt_to_page(x) MAP_NR(x) | ||
82 | #endif | ||
83 | |||
84 | #ifndef vmalloc_32 | ||
85 | #define vmalloc_32(x) vmalloc(x) | ||
86 | #endif | ||
87 | |||
88 | struct it_dma_prg { | 68 | struct it_dma_prg { |
89 | struct dma_cmd begin; | 69 | struct dma_cmd begin; |
90 | quadlet_t data[4]; | 70 | quadlet_t data[4]; |
@@ -206,14 +186,12 @@ alloc_dma_iso_ctx(struct ti_ohci *ohci, int type, int num_desc, | |||
206 | struct dma_iso_ctx *d; | 186 | struct dma_iso_ctx *d; |
207 | int i; | 187 | int i; |
208 | 188 | ||
209 | d = kmalloc(sizeof(struct dma_iso_ctx), GFP_KERNEL); | 189 | d = kzalloc(sizeof(*d), GFP_KERNEL); |
210 | if (d == NULL) { | 190 | if (!d) { |
211 | PRINT(KERN_ERR, ohci->host->id, "Failed to allocate dma_iso_ctx"); | 191 | PRINT(KERN_ERR, ohci->host->id, "Failed to allocate dma_iso_ctx"); |
212 | return NULL; | 192 | return NULL; |
213 | } | 193 | } |
214 | 194 | ||
215 | memset(d, 0, sizeof *d); | ||
216 | |||
217 | d->ohci = ohci; | 195 | d->ohci = ohci; |
218 | d->type = type; | 196 | d->type = type; |
219 | d->channel = channel; | 197 | d->channel = channel; |
@@ -251,9 +229,8 @@ alloc_dma_iso_ctx(struct ti_ohci *ohci, int type, int num_desc, | |||
251 | } | 229 | } |
252 | d->ctx = d->iso_tasklet.context; | 230 | d->ctx = d->iso_tasklet.context; |
253 | 231 | ||
254 | d->prg_reg = kmalloc(d->num_desc * sizeof(struct dma_prog_region), | 232 | d->prg_reg = kmalloc(d->num_desc * sizeof(*d->prg_reg), GFP_KERNEL); |
255 | GFP_KERNEL); | 233 | if (!d->prg_reg) { |
256 | if (d->prg_reg == NULL) { | ||
257 | PRINT(KERN_ERR, ohci->host->id, "Failed to allocate ir prg regs"); | 234 | PRINT(KERN_ERR, ohci->host->id, "Failed to allocate ir prg regs"); |
258 | free_dma_iso_ctx(d); | 235 | free_dma_iso_ctx(d); |
259 | return NULL; | 236 | return NULL; |
@@ -268,15 +245,14 @@ alloc_dma_iso_ctx(struct ti_ohci *ohci, int type, int num_desc, | |||
268 | d->cmdPtr = OHCI1394_IsoRcvCommandPtr+32*d->ctx; | 245 | d->cmdPtr = OHCI1394_IsoRcvCommandPtr+32*d->ctx; |
269 | d->ctxMatch = OHCI1394_IsoRcvContextMatch+32*d->ctx; | 246 | d->ctxMatch = OHCI1394_IsoRcvContextMatch+32*d->ctx; |
270 | 247 | ||
271 | d->ir_prg = kmalloc(d->num_desc * sizeof(struct dma_cmd *), | 248 | d->ir_prg = kzalloc(d->num_desc * sizeof(*d->ir_prg), |
272 | GFP_KERNEL); | 249 | GFP_KERNEL); |
273 | 250 | ||
274 | if (d->ir_prg == NULL) { | 251 | if (!d->ir_prg) { |
275 | PRINT(KERN_ERR, ohci->host->id, "Failed to allocate dma ir prg"); | 252 | PRINT(KERN_ERR, ohci->host->id, "Failed to allocate dma ir prg"); |
276 | free_dma_iso_ctx(d); | 253 | free_dma_iso_ctx(d); |
277 | return NULL; | 254 | return NULL; |
278 | } | 255 | } |
279 | memset(d->ir_prg, 0, d->num_desc * sizeof(struct dma_cmd *)); | ||
280 | 256 | ||
281 | d->nb_cmd = d->buf_size / PAGE_SIZE + 1; | 257 | d->nb_cmd = d->buf_size / PAGE_SIZE + 1; |
282 | d->left_size = (d->frame_size % PAGE_SIZE) ? | 258 | d->left_size = (d->frame_size % PAGE_SIZE) ? |
@@ -297,16 +273,15 @@ alloc_dma_iso_ctx(struct ti_ohci *ohci, int type, int num_desc, | |||
297 | d->ctrlClear = OHCI1394_IsoXmitContextControlClear+16*d->ctx; | 273 | d->ctrlClear = OHCI1394_IsoXmitContextControlClear+16*d->ctx; |
298 | d->cmdPtr = OHCI1394_IsoXmitCommandPtr+16*d->ctx; | 274 | d->cmdPtr = OHCI1394_IsoXmitCommandPtr+16*d->ctx; |
299 | 275 | ||
300 | d->it_prg = kmalloc(d->num_desc * sizeof(struct it_dma_prg *), | 276 | d->it_prg = kzalloc(d->num_desc * sizeof(*d->it_prg), |
301 | GFP_KERNEL); | 277 | GFP_KERNEL); |
302 | 278 | ||
303 | if (d->it_prg == NULL) { | 279 | if (!d->it_prg) { |
304 | PRINT(KERN_ERR, ohci->host->id, | 280 | PRINT(KERN_ERR, ohci->host->id, |
305 | "Failed to allocate dma it prg"); | 281 | "Failed to allocate dma it prg"); |
306 | free_dma_iso_ctx(d); | 282 | free_dma_iso_ctx(d); |
307 | return NULL; | 283 | return NULL; |
308 | } | 284 | } |
309 | memset(d->it_prg, 0, d->num_desc*sizeof(struct it_dma_prg *)); | ||
310 | 285 | ||
311 | d->packet_size = packet_size; | 286 | d->packet_size = packet_size; |
312 | 287 | ||
@@ -337,47 +312,24 @@ alloc_dma_iso_ctx(struct ti_ohci *ohci, int type, int num_desc, | |||
337 | } | 312 | } |
338 | } | 313 | } |
339 | 314 | ||
340 | d->buffer_status = kmalloc(d->num_desc * sizeof(unsigned int), | 315 | d->buffer_status = |
341 | GFP_KERNEL); | 316 | kzalloc(d->num_desc * sizeof(*d->buffer_status), GFP_KERNEL); |
342 | d->buffer_prg_assignment = kmalloc(d->num_desc * sizeof(unsigned int), | 317 | d->buffer_prg_assignment = |
343 | GFP_KERNEL); | 318 | kzalloc(d->num_desc * sizeof(*d->buffer_prg_assignment), GFP_KERNEL); |
344 | d->buffer_time = kmalloc(d->num_desc * sizeof(struct timeval), | 319 | d->buffer_time = |
345 | GFP_KERNEL); | 320 | kzalloc(d->num_desc * sizeof(*d->buffer_time), GFP_KERNEL); |
346 | d->last_used_cmd = kmalloc(d->num_desc * sizeof(unsigned int), | 321 | d->last_used_cmd = |
347 | GFP_KERNEL); | 322 | kzalloc(d->num_desc * sizeof(*d->last_used_cmd), GFP_KERNEL); |
348 | d->next_buffer = kmalloc(d->num_desc * sizeof(int), | 323 | d->next_buffer = |
349 | GFP_KERNEL); | 324 | kzalloc(d->num_desc * sizeof(*d->next_buffer), GFP_KERNEL); |
350 | 325 | ||
351 | if (d->buffer_status == NULL) { | 326 | if (!d->buffer_status || !d->buffer_prg_assignment || !d->buffer_time || |
352 | PRINT(KERN_ERR, ohci->host->id, "Failed to allocate buffer_status"); | 327 | !d->last_used_cmd || !d->next_buffer) { |
353 | free_dma_iso_ctx(d); | 328 | PRINT(KERN_ERR, ohci->host->id, |
354 | return NULL; | 329 | "Failed to allocate dma_iso_ctx member"); |
355 | } | ||
356 | if (d->buffer_prg_assignment == NULL) { | ||
357 | PRINT(KERN_ERR, ohci->host->id, "Failed to allocate buffer_prg_assignment"); | ||
358 | free_dma_iso_ctx(d); | ||
359 | return NULL; | ||
360 | } | ||
361 | if (d->buffer_time == NULL) { | ||
362 | PRINT(KERN_ERR, ohci->host->id, "Failed to allocate buffer_time"); | ||
363 | free_dma_iso_ctx(d); | ||
364 | return NULL; | ||
365 | } | ||
366 | if (d->last_used_cmd == NULL) { | ||
367 | PRINT(KERN_ERR, ohci->host->id, "Failed to allocate last_used_cmd"); | ||
368 | free_dma_iso_ctx(d); | ||
369 | return NULL; | ||
370 | } | ||
371 | if (d->next_buffer == NULL) { | ||
372 | PRINT(KERN_ERR, ohci->host->id, "Failed to allocate next_buffer"); | ||
373 | free_dma_iso_ctx(d); | 330 | free_dma_iso_ctx(d); |
374 | return NULL; | 331 | return NULL; |
375 | } | 332 | } |
376 | memset(d->buffer_status, 0, d->num_desc * sizeof(unsigned int)); | ||
377 | memset(d->buffer_prg_assignment, 0, d->num_desc * sizeof(unsigned int)); | ||
378 | memset(d->buffer_time, 0, d->num_desc * sizeof(struct timeval)); | ||
379 | memset(d->last_used_cmd, 0, d->num_desc * sizeof(unsigned int)); | ||
380 | memset(d->next_buffer, -1, d->num_desc * sizeof(int)); | ||
381 | 333 | ||
382 | spin_lock_init(&d->lock); | 334 | spin_lock_init(&d->lock); |
383 | 335 | ||
@@ -539,7 +491,7 @@ static void wakeup_dma_ir_ctx(unsigned long l) | |||
539 | if (d->ir_prg[i][d->nb_cmd-1].status & cpu_to_le32(0xFFFF0000)) { | 491 | if (d->ir_prg[i][d->nb_cmd-1].status & cpu_to_le32(0xFFFF0000)) { |
540 | reset_ir_status(d, i); | 492 | reset_ir_status(d, i); |
541 | d->buffer_status[d->buffer_prg_assignment[i]] = VIDEO1394_BUFFER_READY; | 493 | d->buffer_status[d->buffer_prg_assignment[i]] = VIDEO1394_BUFFER_READY; |
542 | do_gettimeofday(&d->buffer_time[i]); | 494 | do_gettimeofday(&d->buffer_time[d->buffer_prg_assignment[i]]); |
543 | } | 495 | } |
544 | } | 496 | } |
545 | 497 | ||
@@ -1046,7 +998,6 @@ static int __video1394_ioctl(struct file *file, | |||
1046 | 998 | ||
1047 | /* set time of buffer */ | 999 | /* set time of buffer */ |
1048 | v.filltime = d->buffer_time[v.buffer]; | 1000 | v.filltime = d->buffer_time[v.buffer]; |
1049 | // printk("Buffer %d time %d\n", v.buffer, (d->buffer_time[v.buffer]).tv_usec); | ||
1050 | 1001 | ||
1051 | /* | 1002 | /* |
1052 | * Look ahead to see how many more buffers have been received | 1003 | * Look ahead to see how many more buffers have been received |
@@ -1085,7 +1036,7 @@ static int __video1394_ioctl(struct file *file, | |||
1085 | } | 1036 | } |
1086 | 1037 | ||
1087 | if (d->flags & VIDEO1394_VARIABLE_PACKET_SIZE) { | 1038 | if (d->flags & VIDEO1394_VARIABLE_PACKET_SIZE) { |
1088 | int buf_size = d->nb_cmd * sizeof(unsigned int); | 1039 | int buf_size = d->nb_cmd * sizeof(*psizes); |
1089 | struct video1394_queue_variable __user *p = argp; | 1040 | struct video1394_queue_variable __user *p = argp; |
1090 | unsigned int __user *qv; | 1041 | unsigned int __user *qv; |
1091 | 1042 | ||
@@ -1104,7 +1055,7 @@ static int __video1394_ioctl(struct file *file, | |||
1104 | 1055 | ||
1105 | spin_lock_irqsave(&d->lock,flags); | 1056 | spin_lock_irqsave(&d->lock,flags); |
1106 | 1057 | ||
1107 | // last_buffer is last_prg | 1058 | /* last_buffer is last_prg */ |
1108 | next_prg = (d->last_buffer + 1) % d->num_desc; | 1059 | next_prg = (d->last_buffer + 1) % d->num_desc; |
1109 | if (d->buffer_status[v.buffer]!=VIDEO1394_BUFFER_FREE) { | 1060 | if (d->buffer_status[v.buffer]!=VIDEO1394_BUFFER_FREE) { |
1110 | PRINT(KERN_ERR, ohci->host->id, | 1061 | PRINT(KERN_ERR, ohci->host->id, |
@@ -1251,13 +1202,12 @@ static int video1394_open(struct inode *inode, struct file *file) | |||
1251 | if (ohci == NULL) | 1202 | if (ohci == NULL) |
1252 | return -EIO; | 1203 | return -EIO; |
1253 | 1204 | ||
1254 | ctx = kmalloc(sizeof(struct file_ctx), GFP_KERNEL); | 1205 | ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); |
1255 | if (ctx == NULL) { | 1206 | if (!ctx) { |
1256 | PRINT(KERN_ERR, ohci->host->id, "Cannot malloc file_ctx"); | 1207 | PRINT(KERN_ERR, ohci->host->id, "Cannot malloc file_ctx"); |
1257 | return -ENOMEM; | 1208 | return -ENOMEM; |
1258 | } | 1209 | } |
1259 | 1210 | ||
1260 | memset(ctx, 0, sizeof(struct file_ctx)); | ||
1261 | ctx->ohci = ohci; | 1211 | ctx->ohci = ohci; |
1262 | INIT_LIST_HEAD(&ctx->context_list); | 1212 | INIT_LIST_HEAD(&ctx->context_list); |
1263 | ctx->current_ctx = NULL; | 1213 | ctx->current_ctx = NULL; |