diff options
author | Trent Piepho <xyzzy@speakeasy.org> | 2009-03-10 22:28:16 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-03-30 11:43:16 -0400 |
commit | 1159b7f19f324db0c61d1277987374865690ec06 (patch) | |
tree | b88bf3ac1f0bee322cdb16272df676cdb271e0a7 | |
parent | ce904bcba41d0b4b809e9573ca43f391e5ffcf4b (diff) |
V4L/DVB (10930): zoran: Unify buffer descriptors
The zoran driver had two kinds of buffer descriptors, one for jpg buffers
and one for raw buffers. They were mostly the same with only a couple
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r-- | drivers/media/video/zoran/zoran.h | 59 | ||||
-rw-r--r-- | drivers/media/video/zoran/zoran_device.c | 12 | ||||
-rw-r--r-- | drivers/media/video/zoran/zoran_driver.c | 829 |
3 files changed, 386 insertions, 514 deletions
diff --git a/drivers/media/video/zoran/zoran.h b/drivers/media/video/zoran/zoran.h index 8beada9613f6..afecf32f1a87 100644 --- a/drivers/media/video/zoran/zoran.h +++ b/drivers/media/video/zoran/zoran.h | |||
@@ -172,6 +172,8 @@ Private IOCTL to set up for displaying MJPEG | |||
172 | #endif | 172 | #endif |
173 | #define V4L_MASK_FRAME (V4L_MAX_FRAME - 1) | 173 | #define V4L_MASK_FRAME (V4L_MAX_FRAME - 1) |
174 | 174 | ||
175 | #define MAX_FRAME (BUZ_MAX_FRAME > VIDEO_MAX_FRAME ? BUZ_MAX_FRAME : VIDEO_MAX_FRAME) | ||
176 | |||
175 | #include "zr36057.h" | 177 | #include "zr36057.h" |
176 | 178 | ||
177 | enum card_type { | 179 | enum card_type { |
@@ -280,21 +282,21 @@ struct zoran_mapping { | |||
280 | int count; | 282 | int count; |
281 | }; | 283 | }; |
282 | 284 | ||
283 | struct zoran_jpg_buffer { | 285 | struct zoran_buffer { |
284 | struct zoran_mapping *map; | ||
285 | __le32 *frag_tab; /* addresses of frag table */ | ||
286 | u32 frag_tab_bus; /* same value cached to save time in ISR */ | ||
287 | enum zoran_buffer_state state; /* non-zero if corresponding buffer is in use in grab queue */ | ||
288 | struct zoran_sync bs; /* DONE: info to return to application */ | ||
289 | }; | ||
290 | |||
291 | struct zoran_v4l_buffer { | ||
292 | struct zoran_mapping *map; | 286 | struct zoran_mapping *map; |
293 | char *fbuffer; /* virtual address of frame buffer */ | 287 | enum zoran_buffer_state state; /* state: unused/pending/dma/done */ |
294 | unsigned long fbuffer_phys; /* physical address of frame buffer */ | 288 | struct zoran_sync bs; /* DONE: info to return to application */ |
295 | unsigned long fbuffer_bus; /* bus address of frame buffer */ | 289 | union { |
296 | enum zoran_buffer_state state; /* state: unused/pending/done */ | 290 | struct { |
297 | struct zoran_sync bs; /* DONE: info to return to application */ | 291 | __le32 *frag_tab; /* addresses of frag table */ |
292 | u32 frag_tab_bus; /* same value cached to save time in ISR */ | ||
293 | } jpg; | ||
294 | struct { | ||
295 | char *fbuffer; /* virtual address of frame buffer */ | ||
296 | unsigned long fbuffer_phys;/* physical address of frame buffer */ | ||
297 | unsigned long fbuffer_bus;/* bus address of frame buffer */ | ||
298 | } v4l; | ||
299 | }; | ||
298 | }; | 300 | }; |
299 | 301 | ||
300 | enum zoran_lock_activity { | 302 | enum zoran_lock_activity { |
@@ -304,19 +306,13 @@ enum zoran_lock_activity { | |||
304 | }; | 306 | }; |
305 | 307 | ||
306 | /* buffer collections */ | 308 | /* buffer collections */ |
307 | struct zoran_jpg_struct { | 309 | struct zoran_buffer_col { |
308 | enum zoran_lock_activity active; /* feature currently in use? */ | 310 | enum zoran_lock_activity active; /* feature currently in use? */ |
309 | struct zoran_jpg_buffer buffer[BUZ_MAX_FRAME]; /* buffers */ | 311 | unsigned int num_buffers, buffer_size; |
310 | int num_buffers, buffer_size; | 312 | struct zoran_buffer buffer[MAX_FRAME]; /* buffers */ |
311 | u8 allocated; /* Flag if buffers are allocated */ | 313 | u8 allocated; /* Flag if buffers are allocated */ |
312 | u8 need_contiguous; /* Flag if contiguous buffers are needed */ | 314 | u8 need_contiguous; /* Flag if contiguous buffers are needed */ |
313 | }; | 315 | /* only applies to jpg buffers, raw buffers are always contiguous */ |
314 | |||
315 | struct zoran_v4l_struct { | ||
316 | enum zoran_lock_activity active; /* feature currently in use? */ | ||
317 | struct zoran_v4l_buffer buffer[VIDEO_MAX_FRAME]; /* buffers */ | ||
318 | int num_buffers, buffer_size; | ||
319 | u8 allocated; /* Flag if buffers are allocated */ | ||
320 | }; | 316 | }; |
321 | 317 | ||
322 | struct zoran; | 318 | struct zoran; |
@@ -325,17 +321,16 @@ struct zoran; | |||
325 | struct zoran_fh { | 321 | struct zoran_fh { |
326 | struct zoran *zr; | 322 | struct zoran *zr; |
327 | 323 | ||
328 | enum zoran_map_mode map_mode; /* Flag which bufferset will map by next mmap() */ | 324 | enum zoran_map_mode map_mode; /* Flag which bufferset will map by next mmap() */ |
329 | 325 | ||
330 | struct zoran_overlay_settings overlay_settings; | 326 | struct zoran_overlay_settings overlay_settings; |
331 | u32 *overlay_mask; /* overlay mask */ | 327 | u32 *overlay_mask; /* overlay mask */ |
332 | enum zoran_lock_activity overlay_active; /* feature currently in use? */ | 328 | enum zoran_lock_activity overlay_active;/* feature currently in use? */ |
333 | 329 | ||
334 | struct zoran_v4l_settings v4l_settings; /* structure with a lot of things to play with */ | 330 | struct zoran_buffer_col buffers; /* buffers' info */ |
335 | struct zoran_v4l_struct v4l_buffers; /* V4L buffers' info */ | ||
336 | 331 | ||
332 | struct zoran_v4l_settings v4l_settings; /* structure with a lot of things to play with */ | ||
337 | struct zoran_jpg_settings jpg_settings; /* structure with a lot of things to play with */ | 333 | struct zoran_jpg_settings jpg_settings; /* structure with a lot of things to play with */ |
338 | struct zoran_jpg_struct jpg_buffers; /* MJPEG buffers' info */ | ||
339 | }; | 334 | }; |
340 | 335 | ||
341 | struct card_info { | 336 | struct card_info { |
@@ -434,7 +429,7 @@ struct zoran { | |||
434 | unsigned long v4l_pend_tail; | 429 | unsigned long v4l_pend_tail; |
435 | unsigned long v4l_sync_tail; | 430 | unsigned long v4l_sync_tail; |
436 | int v4l_pend[V4L_MAX_FRAME]; | 431 | int v4l_pend[V4L_MAX_FRAME]; |
437 | struct zoran_v4l_struct v4l_buffers; /* V4L buffers' info */ | 432 | struct zoran_buffer_col v4l_buffers; /* V4L buffers' info */ |
438 | 433 | ||
439 | /* Buz MJPEG parameters */ | 434 | /* Buz MJPEG parameters */ |
440 | enum zoran_codec_mode codec_mode; /* status of codec */ | 435 | enum zoran_codec_mode codec_mode; /* status of codec */ |
@@ -461,7 +456,7 @@ struct zoran { | |||
461 | int jpg_pend[BUZ_MAX_FRAME]; | 456 | int jpg_pend[BUZ_MAX_FRAME]; |
462 | 457 | ||
463 | /* array indexed by frame number */ | 458 | /* array indexed by frame number */ |
464 | struct zoran_jpg_struct jpg_buffers; /* MJPEG buffers' info */ | 459 | struct zoran_buffer_col jpg_buffers; /* MJPEG buffers' info */ |
465 | 460 | ||
466 | /* Additional stuff for testing */ | 461 | /* Additional stuff for testing */ |
467 | #ifdef CONFIG_PROC_FS | 462 | #ifdef CONFIG_PROC_FS |
diff --git a/drivers/media/video/zoran/zoran_device.c b/drivers/media/video/zoran/zoran_device.c index 49e91b2ed552..4dc951322ef4 100644 --- a/drivers/media/video/zoran/zoran_device.c +++ b/drivers/media/video/zoran/zoran_device.c | |||
@@ -1125,7 +1125,7 @@ zoran_feed_stat_com (struct zoran *zr) | |||
1125 | if (!(zr->stat_com[i] & cpu_to_le32(1))) | 1125 | if (!(zr->stat_com[i] & cpu_to_le32(1))) |
1126 | break; | 1126 | break; |
1127 | zr->stat_com[i] = | 1127 | zr->stat_com[i] = |
1128 | cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus); | 1128 | cpu_to_le32(zr->jpg_buffers.buffer[frame].jpg.frag_tab_bus); |
1129 | } else { | 1129 | } else { |
1130 | /* fill 2 stat_com entries */ | 1130 | /* fill 2 stat_com entries */ |
1131 | i = ((zr->jpg_dma_head - | 1131 | i = ((zr->jpg_dma_head - |
@@ -1133,9 +1133,9 @@ zoran_feed_stat_com (struct zoran *zr) | |||
1133 | if (!(zr->stat_com[i] & cpu_to_le32(1))) | 1133 | if (!(zr->stat_com[i] & cpu_to_le32(1))) |
1134 | break; | 1134 | break; |
1135 | zr->stat_com[i] = | 1135 | zr->stat_com[i] = |
1136 | cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus); | 1136 | cpu_to_le32(zr->jpg_buffers.buffer[frame].jpg.frag_tab_bus); |
1137 | zr->stat_com[i + 1] = | 1137 | zr->stat_com[i + 1] = |
1138 | cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus); | 1138 | cpu_to_le32(zr->jpg_buffers.buffer[frame].jpg.frag_tab_bus); |
1139 | } | 1139 | } |
1140 | zr->jpg_buffers.buffer[frame].state = BUZ_STATE_DMA; | 1140 | zr->jpg_buffers.buffer[frame].state = BUZ_STATE_DMA; |
1141 | zr->jpg_dma_head++; | 1141 | zr->jpg_dma_head++; |
@@ -1155,7 +1155,7 @@ zoran_reap_stat_com (struct zoran *zr) | |||
1155 | u32 stat_com; | 1155 | u32 stat_com; |
1156 | unsigned int seq; | 1156 | unsigned int seq; |
1157 | unsigned int dif; | 1157 | unsigned int dif; |
1158 | struct zoran_jpg_buffer *buffer; | 1158 | struct zoran_buffer *buffer; |
1159 | int frame; | 1159 | int frame; |
1160 | 1160 | ||
1161 | /* In motion decompress we don't have a hardware frame counter, | 1161 | /* In motion decompress we don't have a hardware frame counter, |
@@ -1298,7 +1298,7 @@ error_handler (struct zoran *zr, | |||
1298 | printk(KERN_INFO "stat_com frames:"); | 1298 | printk(KERN_INFO "stat_com frames:"); |
1299 | for (j = 0; j < BUZ_NUM_STAT_COM; j++) { | 1299 | for (j = 0; j < BUZ_NUM_STAT_COM; j++) { |
1300 | for (i = 0; i < zr->jpg_buffers.num_buffers; i++) { | 1300 | for (i = 0; i < zr->jpg_buffers.num_buffers; i++) { |
1301 | if (le32_to_cpu(zr->stat_com[j]) == zr->jpg_buffers.buffer[i].frag_tab_bus) | 1301 | if (le32_to_cpu(zr->stat_com[j]) == zr->jpg_buffers.buffer[i].jpg.frag_tab_bus) |
1302 | printk(KERN_CONT "% d->%d", j, i); | 1302 | printk(KERN_CONT "% d->%d", j, i); |
1303 | } | 1303 | } |
1304 | } | 1304 | } |
@@ -1437,7 +1437,7 @@ zoran_irq (int irq, | |||
1437 | 1437 | ||
1438 | /* Buffer address */ | 1438 | /* Buffer address */ |
1439 | 1439 | ||
1440 | reg = zr->v4l_buffers.buffer[frame].fbuffer_bus; | 1440 | reg = zr->v4l_buffers.buffer[frame].v4l.fbuffer_bus; |
1441 | btwrite(reg, ZR36057_VDTR); | 1441 | btwrite(reg, ZR36057_VDTR); |
1442 | if (zr->v4l_settings.height > BUZ_MAX_HEIGHT / 2) | 1442 | if (zr->v4l_settings.height > BUZ_MAX_HEIGHT / 2) |
1443 | reg += zr->v4l_settings.bytesperline; | 1443 | reg += zr->v4l_settings.bytesperline; |
diff --git a/drivers/media/video/zoran/zoran_driver.c b/drivers/media/video/zoran/zoran_driver.c index b7f03d163730..26be1a8908a3 100644 --- a/drivers/media/video/zoran/zoran_driver.c +++ b/drivers/media/video/zoran/zoran_driver.c | |||
@@ -193,6 +193,24 @@ zoran_v4l2_calc_bufsize (struct zoran_jpg_settings *settings) | |||
193 | static void v4l_fbuffer_free(struct file *file); | 193 | static void v4l_fbuffer_free(struct file *file); |
194 | static void jpg_fbuffer_free(struct file *file); | 194 | static void jpg_fbuffer_free(struct file *file); |
195 | 195 | ||
196 | /* Set mapping mode */ | ||
197 | static void map_mode_raw(struct zoran_fh *fh) | ||
198 | { | ||
199 | fh->map_mode = ZORAN_MAP_MODE_RAW; | ||
200 | fh->buffers.buffer_size = v4l_bufsize; | ||
201 | fh->buffers.num_buffers = v4l_nbufs; | ||
202 | } | ||
203 | static void map_mode_jpg(struct zoran_fh *fh, int play) | ||
204 | { | ||
205 | fh->map_mode = play ? ZORAN_MAP_MODE_JPG_PLAY : ZORAN_MAP_MODE_JPG_REC; | ||
206 | fh->buffers.buffer_size = jpg_bufsize; | ||
207 | fh->buffers.num_buffers = jpg_nbufs; | ||
208 | } | ||
209 | static inline const char *mode_name(enum zoran_map_mode mode) | ||
210 | { | ||
211 | return mode == ZORAN_MAP_MODE_RAW ? "V4L" : "JPG"; | ||
212 | } | ||
213 | |||
196 | /* | 214 | /* |
197 | * Allocate the V4L grab buffers | 215 | * Allocate the V4L grab buffers |
198 | * | 216 | * |
@@ -207,15 +225,15 @@ v4l_fbuffer_alloc (struct file *file) | |||
207 | int i, off; | 225 | int i, off; |
208 | unsigned char *mem; | 226 | unsigned char *mem; |
209 | 227 | ||
210 | for (i = 0; i < fh->v4l_buffers.num_buffers; i++) { | 228 | for (i = 0; i < fh->buffers.num_buffers; i++) { |
211 | if (fh->v4l_buffers.buffer[i].fbuffer) | 229 | if (fh->buffers.buffer[i].v4l.fbuffer) |
212 | dprintk(2, | 230 | dprintk(2, |
213 | KERN_WARNING | 231 | KERN_WARNING |
214 | "%s: v4l_fbuffer_alloc() - buffer %d already allocated!?\n", | 232 | "%s: v4l_fbuffer_alloc() - buffer %d already allocated!?\n", |
215 | ZR_DEVNAME(zr), i); | 233 | ZR_DEVNAME(zr), i); |
216 | 234 | ||
217 | //udelay(20); | 235 | //udelay(20); |
218 | mem = kmalloc(fh->v4l_buffers.buffer_size, GFP_KERNEL); | 236 | mem = kmalloc(fh->buffers.buffer_size, GFP_KERNEL); |
219 | if (!mem) { | 237 | if (!mem) { |
220 | dprintk(1, | 238 | dprintk(1, |
221 | KERN_ERR | 239 | KERN_ERR |
@@ -224,12 +242,10 @@ v4l_fbuffer_alloc (struct file *file) | |||
224 | v4l_fbuffer_free(file); | 242 | v4l_fbuffer_free(file); |
225 | return -ENOBUFS; | 243 | return -ENOBUFS; |
226 | } | 244 | } |
227 | fh->v4l_buffers.buffer[i].fbuffer = mem; | 245 | fh->buffers.buffer[i].v4l.fbuffer = mem; |
228 | fh->v4l_buffers.buffer[i].fbuffer_phys = | 246 | fh->buffers.buffer[i].v4l.fbuffer_phys = virt_to_phys(mem); |
229 | virt_to_phys(mem); | 247 | fh->buffers.buffer[i].v4l.fbuffer_bus = virt_to_bus(mem); |
230 | fh->v4l_buffers.buffer[i].fbuffer_bus = | 248 | for (off = 0; off < fh->buffers.buffer_size; |
231 | virt_to_bus(mem); | ||
232 | for (off = 0; off < fh->v4l_buffers.buffer_size; | ||
233 | off += PAGE_SIZE) | 249 | off += PAGE_SIZE) |
234 | SetPageReserved(virt_to_page(mem + off)); | 250 | SetPageReserved(virt_to_page(mem + off)); |
235 | dprintk(4, | 251 | dprintk(4, |
@@ -239,7 +255,7 @@ v4l_fbuffer_alloc (struct file *file) | |||
239 | virt_to_bus(mem)); | 255 | virt_to_bus(mem)); |
240 | } | 256 | } |
241 | 257 | ||
242 | fh->v4l_buffers.allocated = 1; | 258 | fh->buffers.allocated = 1; |
243 | 259 | ||
244 | return 0; | 260 | return 0; |
245 | } | 261 | } |
@@ -255,19 +271,19 @@ v4l_fbuffer_free (struct file *file) | |||
255 | 271 | ||
256 | dprintk(4, KERN_INFO "%s: v4l_fbuffer_free()\n", ZR_DEVNAME(zr)); | 272 | dprintk(4, KERN_INFO "%s: v4l_fbuffer_free()\n", ZR_DEVNAME(zr)); |
257 | 273 | ||
258 | for (i = 0; i < fh->v4l_buffers.num_buffers; i++) { | 274 | for (i = 0; i < fh->buffers.num_buffers; i++) { |
259 | if (!fh->v4l_buffers.buffer[i].fbuffer) | 275 | if (!fh->buffers.buffer[i].v4l.fbuffer) |
260 | continue; | 276 | continue; |
261 | 277 | ||
262 | mem = fh->v4l_buffers.buffer[i].fbuffer; | 278 | mem = fh->buffers.buffer[i].v4l.fbuffer; |
263 | for (off = 0; off < fh->v4l_buffers.buffer_size; | 279 | for (off = 0; off < fh->buffers.buffer_size; |
264 | off += PAGE_SIZE) | 280 | off += PAGE_SIZE) |
265 | ClearPageReserved(virt_to_page(mem + off)); | 281 | ClearPageReserved(virt_to_page(mem + off)); |
266 | kfree((void *) fh->v4l_buffers.buffer[i].fbuffer); | 282 | kfree(fh->buffers.buffer[i].v4l.fbuffer); |
267 | fh->v4l_buffers.buffer[i].fbuffer = NULL; | 283 | fh->buffers.buffer[i].v4l.fbuffer = NULL; |
268 | } | 284 | } |
269 | 285 | ||
270 | fh->v4l_buffers.allocated = 0; | 286 | fh->buffers.allocated = 0; |
271 | } | 287 | } |
272 | 288 | ||
273 | /* | 289 | /* |
@@ -304,10 +320,10 @@ jpg_fbuffer_alloc (struct file *file) | |||
304 | struct zoran_fh *fh = file->private_data; | 320 | struct zoran_fh *fh = file->private_data; |
305 | struct zoran *zr = fh->zr; | 321 | struct zoran *zr = fh->zr; |
306 | int i, j, off; | 322 | int i, j, off; |
307 | unsigned long mem; | 323 | u8 *mem; |
308 | 324 | ||
309 | for (i = 0; i < fh->jpg_buffers.num_buffers; i++) { | 325 | for (i = 0; i < fh->buffers.num_buffers; i++) { |
310 | if (fh->jpg_buffers.buffer[i].frag_tab) | 326 | if (fh->buffers.buffer[i].jpg.frag_tab) |
311 | dprintk(2, | 327 | dprintk(2, |
312 | KERN_WARNING | 328 | KERN_WARNING |
313 | "%s: jpg_fbuffer_alloc() - buffer %d already allocated!?\n", | 329 | "%s: jpg_fbuffer_alloc() - buffer %d already allocated!?\n", |
@@ -315,7 +331,7 @@ jpg_fbuffer_alloc (struct file *file) | |||
315 | 331 | ||
316 | /* Allocate fragment table for this buffer */ | 332 | /* Allocate fragment table for this buffer */ |
317 | 333 | ||
318 | mem = get_zeroed_page(GFP_KERNEL); | 334 | mem = (void *)get_zeroed_page(GFP_KERNEL); |
319 | if (mem == 0) { | 335 | if (mem == 0) { |
320 | dprintk(1, | 336 | dprintk(1, |
321 | KERN_ERR | 337 | KERN_ERR |
@@ -324,17 +340,12 @@ jpg_fbuffer_alloc (struct file *file) | |||
324 | jpg_fbuffer_free(file); | 340 | jpg_fbuffer_free(file); |
325 | return -ENOBUFS; | 341 | return -ENOBUFS; |
326 | } | 342 | } |
327 | fh->jpg_buffers.buffer[i].frag_tab = (__le32 *) mem; | 343 | fh->buffers.buffer[i].jpg.frag_tab = (__le32 *)mem; |
328 | fh->jpg_buffers.buffer[i].frag_tab_bus = | 344 | fh->buffers.buffer[i].jpg.frag_tab_bus = virt_to_bus(mem); |
329 | virt_to_bus((void *) mem); | 345 | |
330 | 346 | if (fh->buffers.need_contiguous) { | |
331 | //if (alloc_contig) { | 347 | mem = kmalloc(fh->buffers.buffer_size, GFP_KERNEL); |
332 | if (fh->jpg_buffers.need_contiguous) { | 348 | if (mem == NULL) { |
333 | mem = | ||
334 | (unsigned long) kmalloc(fh->jpg_buffers. | ||
335 | buffer_size, | ||
336 | GFP_KERNEL); | ||
337 | if (mem == 0) { | ||
338 | dprintk(1, | 349 | dprintk(1, |
339 | KERN_ERR | 350 | KERN_ERR |
340 | "%s: jpg_fbuffer_alloc() - kmalloc failed for buffer %d\n", | 351 | "%s: jpg_fbuffer_alloc() - kmalloc failed for buffer %d\n", |
@@ -342,20 +353,17 @@ jpg_fbuffer_alloc (struct file *file) | |||
342 | jpg_fbuffer_free(file); | 353 | jpg_fbuffer_free(file); |
343 | return -ENOBUFS; | 354 | return -ENOBUFS; |
344 | } | 355 | } |
345 | fh->jpg_buffers.buffer[i].frag_tab[0] = | 356 | fh->buffers.buffer[i].jpg.frag_tab[0] = |
346 | cpu_to_le32(virt_to_bus((void *) mem)); | 357 | cpu_to_le32(virt_to_bus(mem)); |
347 | fh->jpg_buffers.buffer[i].frag_tab[1] = | 358 | fh->buffers.buffer[i].jpg.frag_tab[1] = |
348 | cpu_to_le32(((fh->jpg_buffers.buffer_size / 4) << 1) | 1); | 359 | cpu_to_le32((fh->buffers.buffer_size >> 1) | 1); |
349 | for (off = 0; off < fh->jpg_buffers.buffer_size; | 360 | for (off = 0; off < fh->buffers.buffer_size; off += PAGE_SIZE) |
350 | off += PAGE_SIZE) | ||
351 | SetPageReserved(virt_to_page(mem + off)); | 361 | SetPageReserved(virt_to_page(mem + off)); |
352 | } else { | 362 | } else { |
353 | /* jpg_bufsize is already page aligned */ | 363 | /* jpg_bufsize is already page aligned */ |
354 | for (j = 0; | 364 | for (j = 0; j < fh->buffers.buffer_size / PAGE_SIZE; j++) { |
355 | j < fh->jpg_buffers.buffer_size / PAGE_SIZE; | 365 | mem = (void *)get_zeroed_page(GFP_KERNEL); |
356 | j++) { | 366 | if (mem == NULL) { |
357 | mem = get_zeroed_page(GFP_KERNEL); | ||
358 | if (mem == 0) { | ||
359 | dprintk(1, | 367 | dprintk(1, |
360 | KERN_ERR | 368 | KERN_ERR |
361 | "%s: jpg_fbuffer_alloc() - get_zeroed_page failed for buffer %d\n", | 369 | "%s: jpg_fbuffer_alloc() - get_zeroed_page failed for buffer %d\n", |
@@ -364,25 +372,23 @@ jpg_fbuffer_alloc (struct file *file) | |||
364 | return -ENOBUFS; | 372 | return -ENOBUFS; |
365 | } | 373 | } |
366 | 374 | ||
367 | fh->jpg_buffers.buffer[i].frag_tab[2 * j] = | 375 | fh->buffers.buffer[i].jpg.frag_tab[2 * j] = |
368 | cpu_to_le32(virt_to_bus((void *) mem)); | 376 | cpu_to_le32(virt_to_bus(mem)); |
369 | fh->jpg_buffers.buffer[i].frag_tab[2 * j + | 377 | fh->buffers.buffer[i].jpg.frag_tab[2 * j + 1] = |
370 | 1] = | 378 | cpu_to_le32((PAGE_SIZE >> 2) << 1); |
371 | cpu_to_le32((PAGE_SIZE / 4) << 1); | ||
372 | SetPageReserved(virt_to_page(mem)); | 379 | SetPageReserved(virt_to_page(mem)); |
373 | } | 380 | } |
374 | 381 | ||
375 | fh->jpg_buffers.buffer[i].frag_tab[2 * j - 1] |= cpu_to_le32(1); | 382 | fh->buffers.buffer[i].jpg.frag_tab[2 * j - 1] |= cpu_to_le32(1); |
376 | } | 383 | } |
377 | } | 384 | } |
378 | 385 | ||
379 | dprintk(4, | 386 | dprintk(4, |
380 | KERN_DEBUG "%s: jpg_fbuffer_alloc() - %d KB allocated\n", | 387 | KERN_DEBUG "%s: jpg_fbuffer_alloc() - %d KB allocated\n", |
381 | ZR_DEVNAME(zr), | 388 | ZR_DEVNAME(zr), |
382 | (fh->jpg_buffers.num_buffers * | 389 | (fh->buffers.num_buffers * fh->buffers.buffer_size) >> 10); |
383 | fh->jpg_buffers.buffer_size) >> 10); | ||
384 | 390 | ||
385 | fh->jpg_buffers.allocated = 1; | 391 | fh->buffers.allocated = 1; |
386 | 392 | ||
387 | return 0; | 393 | return 0; |
388 | } | 394 | } |
@@ -396,42 +402,44 @@ jpg_fbuffer_free (struct file *file) | |||
396 | int i, j, off; | 402 | int i, j, off; |
397 | unsigned char *mem; | 403 | unsigned char *mem; |
398 | __le32 frag_tab; | 404 | __le32 frag_tab; |
405 | struct zoran_buffer *buffer; | ||
399 | 406 | ||
400 | dprintk(4, KERN_DEBUG "%s: jpg_fbuffer_free()\n", ZR_DEVNAME(zr)); | 407 | dprintk(4, KERN_DEBUG "%s: jpg_fbuffer_free()\n", ZR_DEVNAME(zr)); |
401 | 408 | ||
402 | for (i = 0; i < fh->jpg_buffers.num_buffers; i++) { | 409 | for (i = 0, buffer = &fh->buffers.buffer[0]; |
403 | if (!fh->jpg_buffers.buffer[i].frag_tab) | 410 | i < fh->buffers.num_buffers; i++, buffer++) { |
411 | if (!buffer->jpg.frag_tab) | ||
404 | continue; | 412 | continue; |
405 | 413 | ||
406 | if (fh->jpg_buffers.need_contiguous) { | 414 | if (fh->buffers.need_contiguous) { |
407 | frag_tab = fh->jpg_buffers.buffer[i].frag_tab[0]; | 415 | frag_tab = buffer->jpg.frag_tab[0]; |
408 | 416 | ||
409 | if (frag_tab) { | 417 | if (frag_tab) { |
410 | mem = (unsigned char *)bus_to_virt(le32_to_cpu(frag_tab)); | 418 | mem = bus_to_virt(le32_to_cpu(frag_tab)); |
411 | for (off = 0; off < fh->jpg_buffers.buffer_size; off += PAGE_SIZE) | 419 | for (off = 0; off < fh->buffers.buffer_size; off += PAGE_SIZE) |
412 | ClearPageReserved(virt_to_page(mem + off)); | 420 | ClearPageReserved(virt_to_page(mem + off)); |
413 | kfree(mem); | 421 | kfree(mem); |
414 | fh->jpg_buffers.buffer[i].frag_tab[0] = 0; | 422 | buffer->jpg.frag_tab[0] = 0; |
415 | fh->jpg_buffers.buffer[i].frag_tab[1] = 0; | 423 | buffer->jpg.frag_tab[1] = 0; |
416 | } | 424 | } |
417 | } else { | 425 | } else { |
418 | for (j = 0; j < fh->jpg_buffers.buffer_size / PAGE_SIZE; j++) { | 426 | for (j = 0; j < fh->buffers.buffer_size / PAGE_SIZE; j++) { |
419 | frag_tab = fh->jpg_buffers.buffer[i].frag_tab[2 * j]; | 427 | frag_tab = buffer->jpg.frag_tab[2 * j]; |
420 | 428 | ||
421 | if (!frag_tab) | 429 | if (!frag_tab) |
422 | break; | 430 | break; |
423 | ClearPageReserved(virt_to_page(bus_to_virt(le32_to_cpu(frag_tab)))); | 431 | ClearPageReserved(virt_to_page(bus_to_virt(le32_to_cpu(frag_tab)))); |
424 | free_page((unsigned long)bus_to_virt(le32_to_cpu(frag_tab))); | 432 | free_page((unsigned long)bus_to_virt(le32_to_cpu(frag_tab))); |
425 | fh->jpg_buffers.buffer[i].frag_tab[2 * j] = 0; | 433 | buffer->jpg.frag_tab[2 * j] = 0; |
426 | fh->jpg_buffers.buffer[i].frag_tab[2 * j + 1] = 0; | 434 | buffer->jpg.frag_tab[2 * j + 1] = 0; |
427 | } | 435 | } |
428 | } | 436 | } |
429 | 437 | ||
430 | free_page((unsigned long)fh->jpg_buffers.buffer[i].frag_tab); | 438 | free_page((unsigned long)buffer->jpg.frag_tab); |
431 | fh->jpg_buffers.buffer[i].frag_tab = NULL; | 439 | buffer->jpg.frag_tab = NULL; |
432 | } | 440 | } |
433 | 441 | ||
434 | fh->jpg_buffers.allocated = 0; | 442 | fh->buffers.allocated = 0; |
435 | } | 443 | } |
436 | 444 | ||
437 | /* | 445 | /* |
@@ -439,12 +447,11 @@ jpg_fbuffer_free (struct file *file) | |||
439 | */ | 447 | */ |
440 | 448 | ||
441 | static int | 449 | static int |
442 | zoran_v4l_set_format (struct file *file, | 450 | zoran_v4l_set_format (struct zoran_fh *fh, |
443 | int width, | 451 | int width, |
444 | int height, | 452 | int height, |
445 | const struct zoran_format *format) | 453 | const struct zoran_format *format) |
446 | { | 454 | { |
447 | struct zoran_fh *fh = file->private_data; | ||
448 | struct zoran *zr = fh->zr; | 455 | struct zoran *zr = fh->zr; |
449 | int bpp; | 456 | int bpp; |
450 | 457 | ||
@@ -462,11 +469,11 @@ zoran_v4l_set_format (struct file *file, | |||
462 | bpp = (format->depth + 7) / 8; | 469 | bpp = (format->depth + 7) / 8; |
463 | 470 | ||
464 | /* Check against available buffer size */ | 471 | /* Check against available buffer size */ |
465 | if (height * width * bpp > fh->v4l_buffers.buffer_size) { | 472 | if (height * width * bpp > fh->buffers.buffer_size) { |
466 | dprintk(1, | 473 | dprintk(1, |
467 | KERN_ERR | 474 | KERN_ERR |
468 | "%s: v4l_set_format() - video buffer size (%d kB) is too small\n", | 475 | "%s: v4l_set_format() - video buffer size (%d kB) is too small\n", |
469 | ZR_DEVNAME(zr), fh->v4l_buffers.buffer_size >> 10); | 476 | ZR_DEVNAME(zr), fh->buffers.buffer_size >> 10); |
470 | return -EINVAL; | 477 | return -EINVAL; |
471 | } | 478 | } |
472 | 479 | ||
@@ -497,7 +504,7 @@ zoran_v4l_queue_frame (struct file *file, | |||
497 | unsigned long flags; | 504 | unsigned long flags; |
498 | int res = 0; | 505 | int res = 0; |
499 | 506 | ||
500 | if (!fh->v4l_buffers.allocated) { | 507 | if (!fh->buffers.allocated) { |
501 | dprintk(1, | 508 | dprintk(1, |
502 | KERN_ERR | 509 | KERN_ERR |
503 | "%s: v4l_queue_frame() - buffers not yet allocated\n", | 510 | "%s: v4l_queue_frame() - buffers not yet allocated\n", |
@@ -506,7 +513,7 @@ zoran_v4l_queue_frame (struct file *file, | |||
506 | } | 513 | } |
507 | 514 | ||
508 | /* No grabbing outside the buffer range! */ | 515 | /* No grabbing outside the buffer range! */ |
509 | if (num >= fh->v4l_buffers.num_buffers || num < 0) { | 516 | if (num >= fh->buffers.num_buffers || num < 0) { |
510 | dprintk(1, | 517 | dprintk(1, |
511 | KERN_ERR | 518 | KERN_ERR |
512 | "%s: v4l_queue_frame() - buffer %d is out of range\n", | 519 | "%s: v4l_queue_frame() - buffer %d is out of range\n", |
@@ -516,10 +523,10 @@ zoran_v4l_queue_frame (struct file *file, | |||
516 | 523 | ||
517 | spin_lock_irqsave(&zr->spinlock, flags); | 524 | spin_lock_irqsave(&zr->spinlock, flags); |
518 | 525 | ||
519 | if (fh->v4l_buffers.active == ZORAN_FREE) { | 526 | if (fh->buffers.active == ZORAN_FREE) { |
520 | if (zr->v4l_buffers.active == ZORAN_FREE) { | 527 | if (zr->v4l_buffers.active == ZORAN_FREE) { |
521 | zr->v4l_buffers = fh->v4l_buffers; | 528 | zr->v4l_buffers = fh->buffers; |
522 | fh->v4l_buffers.active = ZORAN_ACTIVE; | 529 | fh->buffers.active = ZORAN_ACTIVE; |
523 | } else { | 530 | } else { |
524 | dprintk(1, | 531 | dprintk(1, |
525 | KERN_ERR | 532 | KERN_ERR |
@@ -535,7 +542,7 @@ zoran_v4l_queue_frame (struct file *file, | |||
535 | default: | 542 | default: |
536 | case BUZ_STATE_PEND: | 543 | case BUZ_STATE_PEND: |
537 | if (zr->v4l_buffers.active == ZORAN_FREE) { | 544 | if (zr->v4l_buffers.active == ZORAN_FREE) { |
538 | fh->v4l_buffers.active = ZORAN_FREE; | 545 | fh->buffers.active = ZORAN_FREE; |
539 | zr->v4l_buffers.allocated = 0; | 546 | zr->v4l_buffers.allocated = 0; |
540 | } | 547 | } |
541 | res = -EBUSY; /* what are you doing? */ | 548 | res = -EBUSY; /* what are you doing? */ |
@@ -548,14 +555,12 @@ zoran_v4l_queue_frame (struct file *file, | |||
548 | case BUZ_STATE_USER: | 555 | case BUZ_STATE_USER: |
549 | /* since there is at least one unused buffer there's room for at least | 556 | /* since there is at least one unused buffer there's room for at least |
550 | * one more pend[] entry */ | 557 | * one more pend[] entry */ |
551 | zr->v4l_pend[zr->v4l_pend_head++ & | 558 | zr->v4l_pend[zr->v4l_pend_head++ & V4L_MASK_FRAME] = num; |
552 | V4L_MASK_FRAME] = num; | ||
553 | zr->v4l_buffers.buffer[num].state = BUZ_STATE_PEND; | 559 | zr->v4l_buffers.buffer[num].state = BUZ_STATE_PEND; |
554 | zr->v4l_buffers.buffer[num].bs.length = | 560 | zr->v4l_buffers.buffer[num].bs.length = |
555 | fh->v4l_settings.bytesperline * | 561 | fh->v4l_settings.bytesperline * |
556 | zr->v4l_settings.height; | 562 | zr->v4l_settings.height; |
557 | fh->v4l_buffers.buffer[num] = | 563 | fh->buffers.buffer[num] = zr->v4l_buffers.buffer[num]; |
558 | zr->v4l_buffers.buffer[num]; | ||
559 | break; | 564 | break; |
560 | } | 565 | } |
561 | } | 566 | } |
@@ -563,7 +568,7 @@ zoran_v4l_queue_frame (struct file *file, | |||
563 | spin_unlock_irqrestore(&zr->spinlock, flags); | 568 | spin_unlock_irqrestore(&zr->spinlock, flags); |
564 | 569 | ||
565 | if (!res && zr->v4l_buffers.active == ZORAN_FREE) | 570 | if (!res && zr->v4l_buffers.active == ZORAN_FREE) |
566 | zr->v4l_buffers.active = fh->v4l_buffers.active; | 571 | zr->v4l_buffers.active = fh->buffers.active; |
567 | 572 | ||
568 | return res; | 573 | return res; |
569 | } | 574 | } |
@@ -580,7 +585,7 @@ v4l_sync (struct file *file, | |||
580 | struct zoran *zr = fh->zr; | 585 | struct zoran *zr = fh->zr; |
581 | unsigned long flags; | 586 | unsigned long flags; |
582 | 587 | ||
583 | if (fh->v4l_buffers.active == ZORAN_FREE) { | 588 | if (fh->buffers.active == ZORAN_FREE) { |
584 | dprintk(1, | 589 | dprintk(1, |
585 | KERN_ERR | 590 | KERN_ERR |
586 | "%s: v4l_sync() - no grab active for this session\n", | 591 | "%s: v4l_sync() - no grab active for this session\n", |
@@ -589,7 +594,7 @@ v4l_sync (struct file *file, | |||
589 | } | 594 | } |
590 | 595 | ||
591 | /* check passed-in frame number */ | 596 | /* check passed-in frame number */ |
592 | if (frame >= fh->v4l_buffers.num_buffers || frame < 0) { | 597 | if (frame >= fh->buffers.num_buffers || frame < 0) { |
593 | dprintk(1, | 598 | dprintk(1, |
594 | KERN_ERR "%s: v4l_sync() - frame %d is invalid\n", | 599 | KERN_ERR "%s: v4l_sync() - frame %d is invalid\n", |
595 | ZR_DEVNAME(zr), frame); | 600 | ZR_DEVNAME(zr), frame); |
@@ -607,8 +612,7 @@ v4l_sync (struct file *file, | |||
607 | 612 | ||
608 | /* wait on this buffer to get ready */ | 613 | /* wait on this buffer to get ready */ |
609 | if (!wait_event_interruptible_timeout(zr->v4l_capq, | 614 | if (!wait_event_interruptible_timeout(zr->v4l_capq, |
610 | (zr->v4l_buffers.buffer[frame].state != BUZ_STATE_PEND), | 615 | (zr->v4l_buffers.buffer[frame].state != BUZ_STATE_PEND), 10*HZ)) |
611 | 10*HZ)) | ||
612 | return -ETIME; | 616 | return -ETIME; |
613 | if (signal_pending(current)) | 617 | if (signal_pending(current)) |
614 | return -ERESTARTSYS; | 618 | return -ERESTARTSYS; |
@@ -620,7 +624,7 @@ v4l_sync (struct file *file, | |||
620 | ZR_DEVNAME(zr)); | 624 | ZR_DEVNAME(zr)); |
621 | 625 | ||
622 | zr->v4l_buffers.buffer[frame].state = BUZ_STATE_USER; | 626 | zr->v4l_buffers.buffer[frame].state = BUZ_STATE_USER; |
623 | fh->v4l_buffers.buffer[frame] = zr->v4l_buffers.buffer[frame]; | 627 | fh->buffers.buffer[frame] = zr->v4l_buffers.buffer[frame]; |
624 | 628 | ||
625 | spin_lock_irqsave(&zr->spinlock, flags); | 629 | spin_lock_irqsave(&zr->spinlock, flags); |
626 | 630 | ||
@@ -628,8 +632,7 @@ v4l_sync (struct file *file, | |||
628 | if (zr->v4l_pend_tail == zr->v4l_pend_head) { | 632 | if (zr->v4l_pend_tail == zr->v4l_pend_head) { |
629 | zr36057_set_memgrab(zr, 0); | 633 | zr36057_set_memgrab(zr, 0); |
630 | if (zr->v4l_buffers.active == ZORAN_ACTIVE) { | 634 | if (zr->v4l_buffers.active == ZORAN_ACTIVE) { |
631 | fh->v4l_buffers.active = zr->v4l_buffers.active = | 635 | fh->buffers.active = zr->v4l_buffers.active = ZORAN_FREE; |
632 | ZORAN_FREE; | ||
633 | zr->v4l_buffers.allocated = 0; | 636 | zr->v4l_buffers.allocated = 0; |
634 | } | 637 | } |
635 | } | 638 | } |
@@ -654,7 +657,7 @@ zoran_jpg_queue_frame (struct file *file, | |||
654 | int res = 0; | 657 | int res = 0; |
655 | 658 | ||
656 | /* Check if buffers are allocated */ | 659 | /* Check if buffers are allocated */ |
657 | if (!fh->jpg_buffers.allocated) { | 660 | if (!fh->buffers.allocated) { |
658 | dprintk(1, | 661 | dprintk(1, |
659 | KERN_ERR | 662 | KERN_ERR |
660 | "%s: jpg_queue_frame() - buffers not yet allocated\n", | 663 | "%s: jpg_queue_frame() - buffers not yet allocated\n", |
@@ -663,7 +666,7 @@ zoran_jpg_queue_frame (struct file *file, | |||
663 | } | 666 | } |
664 | 667 | ||
665 | /* No grabbing outside the buffer range! */ | 668 | /* No grabbing outside the buffer range! */ |
666 | if (num >= fh->jpg_buffers.num_buffers || num < 0) { | 669 | if (num >= fh->buffers.num_buffers || num < 0) { |
667 | dprintk(1, | 670 | dprintk(1, |
668 | KERN_ERR | 671 | KERN_ERR |
669 | "%s: jpg_queue_frame() - buffer %d out of range\n", | 672 | "%s: jpg_queue_frame() - buffer %d out of range\n", |
@@ -683,10 +686,10 @@ zoran_jpg_queue_frame (struct file *file, | |||
683 | return -EINVAL; | 686 | return -EINVAL; |
684 | } | 687 | } |
685 | 688 | ||
686 | if (fh->jpg_buffers.active == ZORAN_FREE) { | 689 | if (fh->buffers.active == ZORAN_FREE) { |
687 | if (zr->jpg_buffers.active == ZORAN_FREE) { | 690 | if (zr->jpg_buffers.active == ZORAN_FREE) { |
688 | zr->jpg_buffers = fh->jpg_buffers; | 691 | zr->jpg_buffers = fh->buffers; |
689 | fh->jpg_buffers.active = ZORAN_ACTIVE; | 692 | fh->buffers.active = ZORAN_ACTIVE; |
690 | } else { | 693 | } else { |
691 | dprintk(1, | 694 | dprintk(1, |
692 | KERN_ERR | 695 | KERN_ERR |
@@ -713,18 +716,16 @@ zoran_jpg_queue_frame (struct file *file, | |||
713 | case BUZ_STATE_USER: | 716 | case BUZ_STATE_USER: |
714 | /* since there is at least one unused buffer there's room for at | 717 | /* since there is at least one unused buffer there's room for at |
715 | *least one more pend[] entry */ | 718 | *least one more pend[] entry */ |
716 | zr->jpg_pend[zr->jpg_que_head++ & BUZ_MASK_FRAME] = | 719 | zr->jpg_pend[zr->jpg_que_head++ & BUZ_MASK_FRAME] = num; |
717 | num; | ||
718 | zr->jpg_buffers.buffer[num].state = BUZ_STATE_PEND; | 720 | zr->jpg_buffers.buffer[num].state = BUZ_STATE_PEND; |
719 | fh->jpg_buffers.buffer[num] = | 721 | fh->buffers.buffer[num] = zr->jpg_buffers.buffer[num]; |
720 | zr->jpg_buffers.buffer[num]; | ||
721 | zoran_feed_stat_com(zr); | 722 | zoran_feed_stat_com(zr); |
722 | break; | 723 | break; |
723 | default: | 724 | default: |
724 | case BUZ_STATE_DMA: | 725 | case BUZ_STATE_DMA: |
725 | case BUZ_STATE_PEND: | 726 | case BUZ_STATE_PEND: |
726 | if (zr->jpg_buffers.active == ZORAN_FREE) { | 727 | if (zr->jpg_buffers.active == ZORAN_FREE) { |
727 | fh->jpg_buffers.active = ZORAN_FREE; | 728 | fh->buffers.active = ZORAN_FREE; |
728 | zr->jpg_buffers.allocated = 0; | 729 | zr->jpg_buffers.allocated = 0; |
729 | } | 730 | } |
730 | res = -EBUSY; /* what are you doing? */ | 731 | res = -EBUSY; /* what are you doing? */ |
@@ -734,9 +735,8 @@ zoran_jpg_queue_frame (struct file *file, | |||
734 | 735 | ||
735 | spin_unlock_irqrestore(&zr->spinlock, flags); | 736 | spin_unlock_irqrestore(&zr->spinlock, flags); |
736 | 737 | ||
737 | if (!res && zr->jpg_buffers.active == ZORAN_FREE) { | 738 | if (!res && zr->jpg_buffers.active == ZORAN_FREE) |
738 | zr->jpg_buffers.active = fh->jpg_buffers.active; | 739 | zr->jpg_buffers.active = fh->buffers.active; |
739 | } | ||
740 | 740 | ||
741 | return res; | 741 | return res; |
742 | } | 742 | } |
@@ -753,15 +753,14 @@ jpg_qbuf (struct file *file, | |||
753 | /* Does the user want to stop streaming? */ | 753 | /* Does the user want to stop streaming? */ |
754 | if (frame < 0) { | 754 | if (frame < 0) { |
755 | if (zr->codec_mode == mode) { | 755 | if (zr->codec_mode == mode) { |
756 | if (fh->jpg_buffers.active == ZORAN_FREE) { | 756 | if (fh->buffers.active == ZORAN_FREE) { |
757 | dprintk(1, | 757 | dprintk(1, |
758 | KERN_ERR | 758 | KERN_ERR |
759 | "%s: jpg_qbuf(-1) - session not active\n", | 759 | "%s: jpg_qbuf(-1) - session not active\n", |
760 | ZR_DEVNAME(zr)); | 760 | ZR_DEVNAME(zr)); |
761 | return -EINVAL; | 761 | return -EINVAL; |
762 | } | 762 | } |
763 | fh->jpg_buffers.active = zr->jpg_buffers.active = | 763 | fh->buffers.active = zr->jpg_buffers.active = ZORAN_FREE; |
764 | ZORAN_FREE; | ||
765 | zr->jpg_buffers.allocated = 0; | 764 | zr->jpg_buffers.allocated = 0; |
766 | zr36057_enable_jpg(zr, BUZ_MODE_IDLE); | 765 | zr36057_enable_jpg(zr, BUZ_MODE_IDLE); |
767 | return 0; | 766 | return 0; |
@@ -797,7 +796,7 @@ jpg_sync (struct file *file, | |||
797 | unsigned long flags; | 796 | unsigned long flags; |
798 | int frame; | 797 | int frame; |
799 | 798 | ||
800 | if (fh->jpg_buffers.active == ZORAN_FREE) { | 799 | if (fh->buffers.active == ZORAN_FREE) { |
801 | dprintk(1, | 800 | dprintk(1, |
802 | KERN_ERR | 801 | KERN_ERR |
803 | "%s: jpg_sync() - capture is not currently active\n", | 802 | "%s: jpg_sync() - capture is not currently active\n", |
@@ -849,7 +848,7 @@ jpg_sync (struct file *file, | |||
849 | *bs = zr->jpg_buffers.buffer[frame].bs; | 848 | *bs = zr->jpg_buffers.buffer[frame].bs; |
850 | bs->frame = frame; | 849 | bs->frame = frame; |
851 | zr->jpg_buffers.buffer[frame].state = BUZ_STATE_USER; | 850 | zr->jpg_buffers.buffer[frame].state = BUZ_STATE_USER; |
852 | fh->jpg_buffers.buffer[frame] = zr->jpg_buffers.buffer[frame]; | 851 | fh->buffers.buffer[frame] = zr->jpg_buffers.buffer[frame]; |
853 | 852 | ||
854 | spin_unlock_irqrestore(&zr->spinlock, flags); | 853 | spin_unlock_irqrestore(&zr->spinlock, flags); |
855 | 854 | ||
@@ -864,7 +863,7 @@ zoran_open_init_session (struct file *file) | |||
864 | struct zoran *zr = fh->zr; | 863 | struct zoran *zr = fh->zr; |
865 | 864 | ||
866 | /* Per default, map the V4L Buffers */ | 865 | /* Per default, map the V4L Buffers */ |
867 | fh->map_mode = ZORAN_MAP_MODE_RAW; | 866 | map_mode_raw(fh); |
868 | 867 | ||
869 | /* take over the card's current settings */ | 868 | /* take over the card's current settings */ |
870 | fh->overlay_settings = zr->overlay_settings; | 869 | fh->overlay_settings = zr->overlay_settings; |
@@ -874,32 +873,17 @@ zoran_open_init_session (struct file *file) | |||
874 | 873 | ||
875 | /* v4l settings */ | 874 | /* v4l settings */ |
876 | fh->v4l_settings = zr->v4l_settings; | 875 | fh->v4l_settings = zr->v4l_settings; |
877 | |||
878 | /* v4l_buffers */ | ||
879 | memset(&fh->v4l_buffers, 0, sizeof(struct zoran_v4l_struct)); | ||
880 | for (i = 0; i < VIDEO_MAX_FRAME; i++) { | ||
881 | fh->v4l_buffers.buffer[i].state = BUZ_STATE_USER; /* nothing going on */ | ||
882 | fh->v4l_buffers.buffer[i].bs.frame = i; | ||
883 | } | ||
884 | fh->v4l_buffers.allocated = 0; | ||
885 | fh->v4l_buffers.active = ZORAN_FREE; | ||
886 | fh->v4l_buffers.buffer_size = v4l_bufsize; | ||
887 | fh->v4l_buffers.num_buffers = v4l_nbufs; | ||
888 | |||
889 | /* jpg settings */ | 876 | /* jpg settings */ |
890 | fh->jpg_settings = zr->jpg_settings; | 877 | fh->jpg_settings = zr->jpg_settings; |
891 | 878 | ||
892 | /* jpg_buffers */ | 879 | /* buffers */ |
893 | memset(&fh->jpg_buffers, 0, sizeof(struct zoran_jpg_struct)); | 880 | memset(&fh->buffers, 0, sizeof(fh->buffers)); |
894 | for (i = 0; i < BUZ_MAX_FRAME; i++) { | 881 | for (i = 0; i < MAX_FRAME; i++) { |
895 | fh->jpg_buffers.buffer[i].state = BUZ_STATE_USER; /* nothing going on */ | 882 | fh->buffers.buffer[i].state = BUZ_STATE_USER; /* nothing going on */ |
896 | fh->jpg_buffers.buffer[i].bs.frame = i; | 883 | fh->buffers.buffer[i].bs.frame = i; |
897 | } | 884 | } |
898 | fh->jpg_buffers.need_contiguous = zr->jpg_buffers.need_contiguous; | 885 | fh->buffers.allocated = 0; |
899 | fh->jpg_buffers.allocated = 0; | 886 | fh->buffers.active = ZORAN_FREE; |
900 | fh->jpg_buffers.active = ZORAN_FREE; | ||
901 | fh->jpg_buffers.buffer_size = jpg_bufsize; | ||
902 | fh->jpg_buffers.num_buffers = jpg_nbufs; | ||
903 | } | 887 | } |
904 | 888 | ||
905 | static void | 889 | static void |
@@ -917,33 +901,33 @@ zoran_close_end_session (struct file *file) | |||
917 | zr->overlay_mask = NULL; | 901 | zr->overlay_mask = NULL; |
918 | } | 902 | } |
919 | 903 | ||
920 | /* v4l capture */ | 904 | if (fh->map_mode == ZORAN_MAP_MODE_RAW) { |
921 | if (fh->v4l_buffers.active != ZORAN_FREE) { | 905 | /* v4l capture */ |
922 | unsigned long flags; | 906 | if (fh->buffers.active != ZORAN_FREE) { |
907 | unsigned long flags; | ||
923 | 908 | ||
924 | spin_lock_irqsave(&zr->spinlock, flags); | 909 | spin_lock_irqsave(&zr->spinlock, flags); |
925 | zr36057_set_memgrab(zr, 0); | 910 | zr36057_set_memgrab(zr, 0); |
926 | zr->v4l_buffers.allocated = 0; | 911 | zr->v4l_buffers.allocated = 0; |
927 | zr->v4l_buffers.active = fh->v4l_buffers.active = | 912 | zr->v4l_buffers.active = fh->buffers.active = ZORAN_FREE; |
928 | ZORAN_FREE; | 913 | spin_unlock_irqrestore(&zr->spinlock, flags); |
929 | spin_unlock_irqrestore(&zr->spinlock, flags); | 914 | } |
930 | } | ||
931 | 915 | ||
932 | /* v4l buffers */ | 916 | /* v4l buffers */ |
933 | if (fh->v4l_buffers.allocated) | 917 | if (fh->buffers.allocated) |
934 | v4l_fbuffer_free(file); | 918 | v4l_fbuffer_free(file); |
919 | } else { | ||
920 | /* jpg capture */ | ||
921 | if (fh->buffers.active != ZORAN_FREE) { | ||
922 | zr36057_enable_jpg(zr, BUZ_MODE_IDLE); | ||
923 | zr->jpg_buffers.allocated = 0; | ||
924 | zr->jpg_buffers.active = fh->buffers.active = ZORAN_FREE; | ||
925 | } | ||
935 | 926 | ||
936 | /* jpg capture */ | 927 | /* jpg buffers */ |
937 | if (fh->jpg_buffers.active != ZORAN_FREE) { | 928 | if (fh->buffers.allocated) |
938 | zr36057_enable_jpg(zr, BUZ_MODE_IDLE); | 929 | jpg_fbuffer_free(file); |
939 | zr->jpg_buffers.allocated = 0; | ||
940 | zr->jpg_buffers.active = fh->jpg_buffers.active = | ||
941 | ZORAN_FREE; | ||
942 | } | 930 | } |
943 | |||
944 | /* jpg buffers */ | ||
945 | if (fh->jpg_buffers.allocated) | ||
946 | jpg_fbuffer_free(file); | ||
947 | } | 931 | } |
948 | 932 | ||
949 | /* | 933 | /* |
@@ -1382,15 +1366,15 @@ zoran_v4l2_buffer_status (struct zoran_fh *fh, | |||
1382 | int num) | 1366 | int num) |
1383 | { | 1367 | { |
1384 | struct zoran *zr = fh->zr; | 1368 | struct zoran *zr = fh->zr; |
1369 | unsigned long flags; | ||
1385 | 1370 | ||
1386 | buf->flags = V4L2_BUF_FLAG_MAPPED; | 1371 | buf->flags = V4L2_BUF_FLAG_MAPPED; |
1387 | 1372 | ||
1388 | switch (fh->map_mode) { | 1373 | switch (fh->map_mode) { |
1389 | case ZORAN_MAP_MODE_RAW: | 1374 | case ZORAN_MAP_MODE_RAW: |
1390 | |||
1391 | /* check range */ | 1375 | /* check range */ |
1392 | if (num < 0 || num >= fh->v4l_buffers.num_buffers || | 1376 | if (num < 0 || num >= fh->buffers.num_buffers || |
1393 | !fh->v4l_buffers.allocated) { | 1377 | !fh->buffers.allocated) { |
1394 | dprintk(1, | 1378 | dprintk(1, |
1395 | KERN_ERR | 1379 | KERN_ERR |
1396 | "%s: v4l2_buffer_status() - wrong number or buffers not allocated\n", | 1380 | "%s: v4l2_buffer_status() - wrong number or buffers not allocated\n", |
@@ -1398,17 +1382,26 @@ zoran_v4l2_buffer_status (struct zoran_fh *fh, | |||
1398 | return -EINVAL; | 1382 | return -EINVAL; |
1399 | } | 1383 | } |
1400 | 1384 | ||
1385 | spin_lock_irqsave(&zr->spinlock, flags); | ||
1386 | dprintk(3, | ||
1387 | KERN_DEBUG | ||
1388 | "%s: %s() - raw active=%c, buffer %d: state=%c, map=%c\n", | ||
1389 | ZR_DEVNAME(zr), __func__, | ||
1390 | "FAL"[fh->buffers.active], num, | ||
1391 | "UPMD"[zr->v4l_buffers.buffer[num].state], | ||
1392 | fh->buffers.buffer[num].map ? 'Y' : 'N'); | ||
1393 | spin_unlock_irqrestore(&zr->spinlock, flags); | ||
1394 | |||
1401 | buf->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; | 1395 | buf->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
1402 | buf->length = fh->v4l_buffers.buffer_size; | 1396 | buf->length = fh->buffers.buffer_size; |
1403 | 1397 | ||
1404 | /* get buffer */ | 1398 | /* get buffer */ |
1405 | buf->bytesused = fh->v4l_buffers.buffer[num].bs.length; | 1399 | buf->bytesused = fh->buffers.buffer[num].bs.length; |
1406 | if (fh->v4l_buffers.buffer[num].state == BUZ_STATE_DONE || | 1400 | if (fh->buffers.buffer[num].state == BUZ_STATE_DONE || |
1407 | fh->v4l_buffers.buffer[num].state == BUZ_STATE_USER) { | 1401 | fh->buffers.buffer[num].state == BUZ_STATE_USER) { |
1408 | buf->sequence = fh->v4l_buffers.buffer[num].bs.seq; | 1402 | buf->sequence = fh->buffers.buffer[num].bs.seq; |
1409 | buf->flags |= V4L2_BUF_FLAG_DONE; | 1403 | buf->flags |= V4L2_BUF_FLAG_DONE; |
1410 | buf->timestamp = | 1404 | buf->timestamp = fh->buffers.buffer[num].bs.timestamp; |
1411 | fh->v4l_buffers.buffer[num].bs.timestamp; | ||
1412 | } else { | 1405 | } else { |
1413 | buf->flags |= V4L2_BUF_FLAG_QUEUED; | 1406 | buf->flags |= V4L2_BUF_FLAG_QUEUED; |
1414 | } | 1407 | } |
@@ -1424,8 +1417,8 @@ zoran_v4l2_buffer_status (struct zoran_fh *fh, | |||
1424 | case ZORAN_MAP_MODE_JPG_PLAY: | 1417 | case ZORAN_MAP_MODE_JPG_PLAY: |
1425 | 1418 | ||
1426 | /* check range */ | 1419 | /* check range */ |
1427 | if (num < 0 || num >= fh->jpg_buffers.num_buffers || | 1420 | if (num < 0 || num >= fh->buffers.num_buffers || |
1428 | !fh->jpg_buffers.allocated) { | 1421 | !fh->buffers.allocated) { |
1429 | dprintk(1, | 1422 | dprintk(1, |
1430 | KERN_ERR | 1423 | KERN_ERR |
1431 | "%s: v4l2_buffer_status() - wrong number or buffers not allocated\n", | 1424 | "%s: v4l2_buffer_status() - wrong number or buffers not allocated\n", |
@@ -1436,16 +1429,14 @@ zoran_v4l2_buffer_status (struct zoran_fh *fh, | |||
1436 | buf->type = (fh->map_mode == ZORAN_MAP_MODE_JPG_REC) ? | 1429 | buf->type = (fh->map_mode == ZORAN_MAP_MODE_JPG_REC) ? |
1437 | V4L2_BUF_TYPE_VIDEO_CAPTURE : | 1430 | V4L2_BUF_TYPE_VIDEO_CAPTURE : |
1438 | V4L2_BUF_TYPE_VIDEO_OUTPUT; | 1431 | V4L2_BUF_TYPE_VIDEO_OUTPUT; |
1439 | buf->length = fh->jpg_buffers.buffer_size; | 1432 | buf->length = fh->buffers.buffer_size; |
1440 | 1433 | ||
1441 | /* these variables are only written after frame has been captured */ | 1434 | /* these variables are only written after frame has been captured */ |
1442 | if (fh->jpg_buffers.buffer[num].state == BUZ_STATE_DONE || | 1435 | if (fh->buffers.buffer[num].state == BUZ_STATE_DONE || |
1443 | fh->jpg_buffers.buffer[num].state == BUZ_STATE_USER) { | 1436 | fh->buffers.buffer[num].state == BUZ_STATE_USER) { |
1444 | buf->sequence = fh->jpg_buffers.buffer[num].bs.seq; | 1437 | buf->sequence = fh->buffers.buffer[num].bs.seq; |
1445 | buf->timestamp = | 1438 | buf->timestamp = fh->buffers.buffer[num].bs.timestamp; |
1446 | fh->jpg_buffers.buffer[num].bs.timestamp; | 1439 | buf->bytesused = fh->buffers.buffer[num].bs.length; |
1447 | buf->bytesused = | ||
1448 | fh->jpg_buffers.buffer[num].bs.length; | ||
1449 | buf->flags |= V4L2_BUF_FLAG_DONE; | 1440 | buf->flags |= V4L2_BUF_FLAG_DONE; |
1450 | } else { | 1441 | } else { |
1451 | buf->flags |= V4L2_BUF_FLAG_QUEUED; | 1442 | buf->flags |= V4L2_BUF_FLAG_QUEUED; |
@@ -1453,14 +1444,11 @@ zoran_v4l2_buffer_status (struct zoran_fh *fh, | |||
1453 | 1444 | ||
1454 | /* which fields are these? */ | 1445 | /* which fields are these? */ |
1455 | if (fh->jpg_settings.TmpDcm != 1) | 1446 | if (fh->jpg_settings.TmpDcm != 1) |
1456 | buf->field = | 1447 | buf->field = fh->jpg_settings.odd_even ? |
1457 | fh->jpg_settings. | 1448 | V4L2_FIELD_TOP : V4L2_FIELD_BOTTOM; |
1458 | odd_even ? V4L2_FIELD_TOP : V4L2_FIELD_BOTTOM; | ||
1459 | else | 1449 | else |
1460 | buf->field = | 1450 | buf->field = fh->jpg_settings.odd_even ? |
1461 | fh->jpg_settings. | 1451 | V4L2_FIELD_SEQ_TB : V4L2_FIELD_SEQ_BT; |
1462 | odd_even ? V4L2_FIELD_SEQ_TB : | ||
1463 | V4L2_FIELD_SEQ_BT; | ||
1464 | 1452 | ||
1465 | break; | 1453 | break; |
1466 | 1454 | ||
@@ -1743,7 +1731,7 @@ sparams_unlock_and_return: | |||
1743 | 1731 | ||
1744 | mutex_lock(&zr->resource_lock); | 1732 | mutex_lock(&zr->resource_lock); |
1745 | 1733 | ||
1746 | if (fh->jpg_buffers.allocated || fh->v4l_buffers.allocated) { | 1734 | if (fh->buffers.allocated) { |
1747 | dprintk(1, | 1735 | dprintk(1, |
1748 | KERN_ERR | 1736 | KERN_ERR |
1749 | "%s: BUZIOC_REQBUFS - buffers already allocated\n", | 1737 | "%s: BUZIOC_REQBUFS - buffers already allocated\n", |
@@ -1752,17 +1740,17 @@ sparams_unlock_and_return: | |||
1752 | goto jpgreqbuf_unlock_and_return; | 1740 | goto jpgreqbuf_unlock_and_return; |
1753 | } | 1741 | } |
1754 | 1742 | ||
1755 | fh->jpg_buffers.num_buffers = breq->count; | 1743 | /* The next mmap will map the MJPEG buffers - could |
1756 | fh->jpg_buffers.buffer_size = breq->size; | 1744 | * also be *_PLAY, but it doesn't matter here */ |
1745 | map_mode_jpg(fh, 0); | ||
1746 | fh->buffers.num_buffers = breq->count; | ||
1747 | fh->buffers.buffer_size = breq->size; | ||
1757 | 1748 | ||
1758 | if (jpg_fbuffer_alloc(file)) { | 1749 | if (jpg_fbuffer_alloc(file)) { |
1759 | res = -ENOMEM; | 1750 | res = -ENOMEM; |
1760 | goto jpgreqbuf_unlock_and_return; | 1751 | goto jpgreqbuf_unlock_and_return; |
1761 | } | 1752 | } |
1762 | 1753 | ||
1763 | /* The next mmap will map the MJPEG buffers - could | ||
1764 | * also be *_PLAY, but it doesn't matter here */ | ||
1765 | fh->map_mode = ZORAN_MAP_MODE_JPG_REC; | ||
1766 | jpgreqbuf_unlock_and_return: | 1754 | jpgreqbuf_unlock_and_return: |
1767 | mutex_unlock(&zr->resource_lock); | 1755 | mutex_unlock(&zr->resource_lock); |
1768 | 1756 | ||
@@ -1805,7 +1793,15 @@ jpgreqbuf_unlock_and_return: | |||
1805 | dprintk(3, KERN_DEBUG "%s: BUZIOC_SYNC\n", ZR_DEVNAME(zr)); | 1793 | dprintk(3, KERN_DEBUG "%s: BUZIOC_SYNC\n", ZR_DEVNAME(zr)); |
1806 | 1794 | ||
1807 | mutex_lock(&zr->resource_lock); | 1795 | mutex_lock(&zr->resource_lock); |
1808 | res = jpg_sync(file, bsync); | 1796 | |
1797 | if (fh->map_mode == ZORAN_MAP_MODE_RAW) { | ||
1798 | dprintk(2, KERN_WARNING | ||
1799 | "%s: %s - not in jpg capture mode\n", | ||
1800 | ZR_DEVNAME(zr), __func__); | ||
1801 | res = -EINVAL; | ||
1802 | } else { | ||
1803 | res = jpg_sync(file, bsync); | ||
1804 | } | ||
1809 | mutex_unlock(&zr->resource_lock); | 1805 | mutex_unlock(&zr->resource_lock); |
1810 | 1806 | ||
1811 | return res; | 1807 | return res; |
@@ -1884,18 +1880,10 @@ static int zoran_vidiocgmbuf(struct file *file, void *__fh, struct video_mbuf *v | |||
1884 | struct zoran *zr = fh->zr; | 1880 | struct zoran *zr = fh->zr; |
1885 | int i, res = 0; | 1881 | int i, res = 0; |
1886 | 1882 | ||
1887 | vmbuf->size = | ||
1888 | fh->v4l_buffers.num_buffers * | ||
1889 | fh->v4l_buffers.buffer_size; | ||
1890 | vmbuf->frames = fh->v4l_buffers.num_buffers; | ||
1891 | for (i = 0; i < vmbuf->frames; i++) { | ||
1892 | vmbuf->offsets[i] = | ||
1893 | i * fh->v4l_buffers.buffer_size; | ||
1894 | } | ||
1895 | 1883 | ||
1896 | mutex_lock(&zr->resource_lock); | 1884 | mutex_lock(&zr->resource_lock); |
1897 | 1885 | ||
1898 | if (fh->jpg_buffers.allocated || fh->v4l_buffers.allocated) { | 1886 | if (fh->buffers.allocated) { |
1899 | dprintk(1, | 1887 | dprintk(1, |
1900 | KERN_ERR | 1888 | KERN_ERR |
1901 | "%s: VIDIOCGMBUF - buffers already allocated\n", | 1889 | "%s: VIDIOCGMBUF - buffers already allocated\n", |
@@ -1904,13 +1892,19 @@ static int zoran_vidiocgmbuf(struct file *file, void *__fh, struct video_mbuf *v | |||
1904 | goto v4l1reqbuf_unlock_and_return; | 1892 | goto v4l1reqbuf_unlock_and_return; |
1905 | } | 1893 | } |
1906 | 1894 | ||
1895 | /* The next mmap will map the V4L buffers */ | ||
1896 | map_mode_raw(fh); | ||
1897 | |||
1907 | if (v4l_fbuffer_alloc(file)) { | 1898 | if (v4l_fbuffer_alloc(file)) { |
1908 | res = -ENOMEM; | 1899 | res = -ENOMEM; |
1909 | goto v4l1reqbuf_unlock_and_return; | 1900 | goto v4l1reqbuf_unlock_and_return; |
1910 | } | 1901 | } |
1911 | 1902 | ||
1912 | /* The next mmap will map the V4L buffers */ | 1903 | vmbuf->size = fh->buffers.num_buffers * fh->buffers.buffer_size; |
1913 | fh->map_mode = ZORAN_MAP_MODE_RAW; | 1904 | vmbuf->frames = fh->buffers.num_buffers; |
1905 | for (i = 0; i < vmbuf->frames; i++) | ||
1906 | vmbuf->offsets[i] = i * fh->buffers.buffer_size; | ||
1907 | |||
1914 | v4l1reqbuf_unlock_and_return: | 1908 | v4l1reqbuf_unlock_and_return: |
1915 | mutex_unlock(&zr->resource_lock); | 1909 | mutex_unlock(&zr->resource_lock); |
1916 | 1910 | ||
@@ -2223,15 +2217,15 @@ static int zoran_s_fmt_vid_out(struct file *file, void *__fh, | |||
2223 | 2217 | ||
2224 | mutex_lock(&zr->resource_lock); | 2218 | mutex_lock(&zr->resource_lock); |
2225 | 2219 | ||
2226 | settings = fh->jpg_settings; | 2220 | if (fh->buffers.allocated) { |
2227 | |||
2228 | if (fh->v4l_buffers.allocated || fh->jpg_buffers.allocated) { | ||
2229 | dprintk(1, KERN_ERR "%s: VIDIOC_S_FMT - cannot change capture mode\n", | 2221 | dprintk(1, KERN_ERR "%s: VIDIOC_S_FMT - cannot change capture mode\n", |
2230 | ZR_DEVNAME(zr)); | 2222 | ZR_DEVNAME(zr)); |
2231 | res = -EBUSY; | 2223 | res = -EBUSY; |
2232 | goto sfmtjpg_unlock_and_return; | 2224 | goto sfmtjpg_unlock_and_return; |
2233 | } | 2225 | } |
2234 | 2226 | ||
2227 | settings = fh->jpg_settings; | ||
2228 | |||
2235 | /* we actually need to set 'real' parameters now */ | 2229 | /* we actually need to set 'real' parameters now */ |
2236 | if (fmt->fmt.pix.height * 2 > BUZ_MAX_HEIGHT) | 2230 | if (fmt->fmt.pix.height * 2 > BUZ_MAX_HEIGHT) |
2237 | settings.TmpDcm = 1; | 2231 | settings.TmpDcm = 1; |
@@ -2269,6 +2263,9 @@ static int zoran_s_fmt_vid_out(struct file *file, void *__fh, | |||
2269 | /* it's ok, so set them */ | 2263 | /* it's ok, so set them */ |
2270 | fh->jpg_settings = settings; | 2264 | fh->jpg_settings = settings; |
2271 | 2265 | ||
2266 | map_mode_jpg(fh, fmt->type == V4L2_BUF_TYPE_VIDEO_OUTPUT); | ||
2267 | fh->buffers.buffer_size = zoran_v4l2_calc_bufsize(&fh->jpg_settings); | ||
2268 | |||
2272 | /* tell the user what we actually did */ | 2269 | /* tell the user what we actually did */ |
2273 | fmt->fmt.pix.width = settings.img_width / settings.HorDcm; | 2270 | fmt->fmt.pix.width = settings.img_width / settings.HorDcm; |
2274 | fmt->fmt.pix.height = settings.img_height * 2 / | 2271 | fmt->fmt.pix.height = settings.img_height * 2 / |
@@ -2279,15 +2276,10 @@ static int zoran_s_fmt_vid_out(struct file *file, void *__fh, | |||
2279 | else | 2276 | else |
2280 | fmt->fmt.pix.field = (fh->jpg_settings.odd_even ? | 2277 | fmt->fmt.pix.field = (fh->jpg_settings.odd_even ? |
2281 | V4L2_FIELD_TOP : V4L2_FIELD_BOTTOM); | 2278 | V4L2_FIELD_TOP : V4L2_FIELD_BOTTOM); |
2282 | fh->jpg_buffers.buffer_size = zoran_v4l2_calc_bufsize(&fh->jpg_settings); | ||
2283 | fmt->fmt.pix.bytesperline = 0; | 2279 | fmt->fmt.pix.bytesperline = 0; |
2284 | fmt->fmt.pix.sizeimage = fh->jpg_buffers.buffer_size; | 2280 | fmt->fmt.pix.sizeimage = fh->buffers.buffer_size; |
2285 | fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; | 2281 | fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
2286 | 2282 | ||
2287 | /* we hereby abuse this variable to show that | ||
2288 | * we're gonna do mjpeg capture */ | ||
2289 | fh->map_mode = (fmt->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) ? | ||
2290 | ZORAN_MAP_MODE_JPG_REC : ZORAN_MAP_MODE_JPG_PLAY; | ||
2291 | sfmtjpg_unlock_and_return: | 2283 | sfmtjpg_unlock_and_return: |
2292 | mutex_unlock(&zr->resource_lock); | 2284 | mutex_unlock(&zr->resource_lock); |
2293 | return res; | 2285 | return res; |
@@ -2312,9 +2304,11 @@ static int zoran_s_fmt_vid_cap(struct file *file, void *__fh, | |||
2312 | ZR_DEVNAME(zr), fmt->fmt.pix.pixelformat); | 2304 | ZR_DEVNAME(zr), fmt->fmt.pix.pixelformat); |
2313 | return -EINVAL; | 2305 | return -EINVAL; |
2314 | } | 2306 | } |
2307 | |||
2315 | mutex_lock(&zr->resource_lock); | 2308 | mutex_lock(&zr->resource_lock); |
2316 | if (fh->jpg_buffers.allocated || | 2309 | |
2317 | (fh->v4l_buffers.allocated && fh->v4l_buffers.active != ZORAN_FREE)) { | 2310 | if ((fh->map_mode != ZORAN_MAP_MODE_RAW && fh->buffers.allocated) || |
2311 | fh->buffers.active != ZORAN_FREE) { | ||
2318 | dprintk(1, KERN_ERR "%s: VIDIOC_S_FMT - cannot change capture mode\n", | 2312 | dprintk(1, KERN_ERR "%s: VIDIOC_S_FMT - cannot change capture mode\n", |
2319 | ZR_DEVNAME(zr)); | 2313 | ZR_DEVNAME(zr)); |
2320 | res = -EBUSY; | 2314 | res = -EBUSY; |
@@ -2325,13 +2319,14 @@ static int zoran_s_fmt_vid_cap(struct file *file, void *__fh, | |||
2325 | if (fmt->fmt.pix.width > BUZ_MAX_WIDTH) | 2319 | if (fmt->fmt.pix.width > BUZ_MAX_WIDTH) |
2326 | fmt->fmt.pix.width = BUZ_MAX_WIDTH; | 2320 | fmt->fmt.pix.width = BUZ_MAX_WIDTH; |
2327 | 2321 | ||
2328 | res = zoran_v4l_set_format(file, fmt->fmt.pix.width, | 2322 | map_mode_raw(fh); |
2329 | fmt->fmt.pix.height, &zoran_formats[i]); | 2323 | |
2324 | res = zoran_v4l_set_format(fh, fmt->fmt.pix.width, fmt->fmt.pix.height, | ||
2325 | &zoran_formats[i]); | ||
2330 | if (res) | 2326 | if (res) |
2331 | goto sfmtv4l_unlock_and_return; | 2327 | goto sfmtv4l_unlock_and_return; |
2332 | 2328 | ||
2333 | /* tell the user the | 2329 | /* tell the user the results/missing stuff */ |
2334 | * results/missing stuff */ | ||
2335 | fmt->fmt.pix.bytesperline = fh->v4l_settings.bytesperline; | 2330 | fmt->fmt.pix.bytesperline = fh->v4l_settings.bytesperline; |
2336 | fmt->fmt.pix.sizeimage = fh->v4l_settings.height * fh->v4l_settings.bytesperline; | 2331 | fmt->fmt.pix.sizeimage = fh->v4l_settings.height * fh->v4l_settings.bytesperline; |
2337 | fmt->fmt.pix.colorspace = fh->v4l_settings.format->colorspace; | 2332 | fmt->fmt.pix.colorspace = fh->v4l_settings.format->colorspace; |
@@ -2340,7 +2335,6 @@ static int zoran_s_fmt_vid_cap(struct file *file, void *__fh, | |||
2340 | else | 2335 | else |
2341 | fmt->fmt.pix.field = V4L2_FIELD_TOP; | 2336 | fmt->fmt.pix.field = V4L2_FIELD_TOP; |
2342 | 2337 | ||
2343 | fh->map_mode = ZORAN_MAP_MODE_RAW; | ||
2344 | sfmtv4l_unlock_and_return: | 2338 | sfmtv4l_unlock_and_return: |
2345 | mutex_unlock(&zr->resource_lock); | 2339 | mutex_unlock(&zr->resource_lock); |
2346 | return res; | 2340 | return res; |
@@ -2429,7 +2423,7 @@ static int zoran_reqbufs(struct file *file, void *__fh, struct v4l2_requestbuffe | |||
2429 | return zoran_streamoff(file, fh, req->type); | 2423 | return zoran_streamoff(file, fh, req->type); |
2430 | 2424 | ||
2431 | mutex_lock(&zr->resource_lock); | 2425 | mutex_lock(&zr->resource_lock); |
2432 | if (fh->v4l_buffers.allocated || fh->jpg_buffers.allocated) { | 2426 | if (fh->buffers.allocated) { |
2433 | dprintk(2, | 2427 | dprintk(2, |
2434 | KERN_ERR | 2428 | KERN_ERR |
2435 | "%s: VIDIOC_REQBUFS - buffers already allocated\n", | 2429 | "%s: VIDIOC_REQBUFS - buffers already allocated\n", |
@@ -2439,46 +2433,38 @@ static int zoran_reqbufs(struct file *file, void *__fh, struct v4l2_requestbuffe | |||
2439 | } | 2433 | } |
2440 | 2434 | ||
2441 | if (fh->map_mode == ZORAN_MAP_MODE_RAW && | 2435 | if (fh->map_mode == ZORAN_MAP_MODE_RAW && |
2442 | req->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { | 2436 | req->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { |
2443 | |||
2444 | /* control user input */ | 2437 | /* control user input */ |
2445 | if (req->count < 2) | 2438 | if (req->count < 2) |
2446 | req->count = 2; | 2439 | req->count = 2; |
2447 | if (req->count > v4l_nbufs) | 2440 | if (req->count > v4l_nbufs) |
2448 | req->count = v4l_nbufs; | 2441 | req->count = v4l_nbufs; |
2449 | fh->v4l_buffers.num_buffers = req->count; | 2442 | |
2443 | /* The next mmap will map the V4L buffers */ | ||
2444 | map_mode_raw(fh); | ||
2445 | fh->buffers.num_buffers = req->count; | ||
2450 | 2446 | ||
2451 | if (v4l_fbuffer_alloc(file)) { | 2447 | if (v4l_fbuffer_alloc(file)) { |
2452 | res = -ENOMEM; | 2448 | res = -ENOMEM; |
2453 | goto v4l2reqbuf_unlock_and_return; | 2449 | goto v4l2reqbuf_unlock_and_return; |
2454 | } | 2450 | } |
2455 | |||
2456 | /* The next mmap will map the V4L buffers */ | ||
2457 | fh->map_mode = ZORAN_MAP_MODE_RAW; | ||
2458 | |||
2459 | } else if (fh->map_mode == ZORAN_MAP_MODE_JPG_REC || | 2451 | } else if (fh->map_mode == ZORAN_MAP_MODE_JPG_REC || |
2460 | fh->map_mode == ZORAN_MAP_MODE_JPG_PLAY) { | 2452 | fh->map_mode == ZORAN_MAP_MODE_JPG_PLAY) { |
2461 | |||
2462 | /* we need to calculate size ourselves now */ | 2453 | /* we need to calculate size ourselves now */ |
2463 | if (req->count < 4) | 2454 | if (req->count < 4) |
2464 | req->count = 4; | 2455 | req->count = 4; |
2465 | if (req->count > jpg_nbufs) | 2456 | if (req->count > jpg_nbufs) |
2466 | req->count = jpg_nbufs; | 2457 | req->count = jpg_nbufs; |
2467 | fh->jpg_buffers.num_buffers = req->count; | 2458 | |
2468 | fh->jpg_buffers.buffer_size = | 2459 | /* The next mmap will map the MJPEG buffers */ |
2469 | zoran_v4l2_calc_bufsize(&fh->jpg_settings); | 2460 | map_mode_jpg(fh, req->type == V4L2_BUF_TYPE_VIDEO_OUTPUT); |
2461 | fh->buffers.num_buffers = req->count; | ||
2462 | fh->buffers.buffer_size = zoran_v4l2_calc_bufsize(&fh->jpg_settings); | ||
2470 | 2463 | ||
2471 | if (jpg_fbuffer_alloc(file)) { | 2464 | if (jpg_fbuffer_alloc(file)) { |
2472 | res = -ENOMEM; | 2465 | res = -ENOMEM; |
2473 | goto v4l2reqbuf_unlock_and_return; | 2466 | goto v4l2reqbuf_unlock_and_return; |
2474 | } | 2467 | } |
2475 | |||
2476 | /* The next mmap will map the MJPEG buffers */ | ||
2477 | if (req->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) | ||
2478 | fh->map_mode = ZORAN_MAP_MODE_JPG_REC; | ||
2479 | else | ||
2480 | fh->map_mode = ZORAN_MAP_MODE_JPG_PLAY; | ||
2481 | |||
2482 | } else { | 2468 | } else { |
2483 | dprintk(1, | 2469 | dprintk(1, |
2484 | KERN_ERR | 2470 | KERN_ERR |
@@ -2527,8 +2513,7 @@ static int zoran_qbuf(struct file *file, void *__fh, struct v4l2_buffer *buf) | |||
2527 | res = zoran_v4l_queue_frame(file, buf->index); | 2513 | res = zoran_v4l_queue_frame(file, buf->index); |
2528 | if (res) | 2514 | if (res) |
2529 | goto qbuf_unlock_and_return; | 2515 | goto qbuf_unlock_and_return; |
2530 | if (!zr->v4l_memgrab_active && | 2516 | if (!zr->v4l_memgrab_active && fh->buffers.active == ZORAN_LOCKED) |
2531 | fh->v4l_buffers.active == ZORAN_LOCKED) | ||
2532 | zr36057_set_memgrab(zr, 1); | 2517 | zr36057_set_memgrab(zr, 1); |
2533 | break; | 2518 | break; |
2534 | 2519 | ||
@@ -2555,9 +2540,9 @@ static int zoran_qbuf(struct file *file, void *__fh, struct v4l2_buffer *buf) | |||
2555 | if (res != 0) | 2540 | if (res != 0) |
2556 | goto qbuf_unlock_and_return; | 2541 | goto qbuf_unlock_and_return; |
2557 | if (zr->codec_mode == BUZ_MODE_IDLE && | 2542 | if (zr->codec_mode == BUZ_MODE_IDLE && |
2558 | fh->jpg_buffers.active == ZORAN_LOCKED) { | 2543 | fh->buffers.active == ZORAN_LOCKED) |
2559 | zr36057_enable_jpg(zr, codec_mode); | 2544 | zr36057_enable_jpg(zr, codec_mode); |
2560 | } | 2545 | |
2561 | break; | 2546 | break; |
2562 | 2547 | ||
2563 | default: | 2548 | default: |
@@ -2660,12 +2645,12 @@ static int zoran_streamon(struct file *file, void *__fh, enum v4l2_buf_type type | |||
2660 | switch (fh->map_mode) { | 2645 | switch (fh->map_mode) { |
2661 | case ZORAN_MAP_MODE_RAW: /* raw capture */ | 2646 | case ZORAN_MAP_MODE_RAW: /* raw capture */ |
2662 | if (zr->v4l_buffers.active != ZORAN_ACTIVE || | 2647 | if (zr->v4l_buffers.active != ZORAN_ACTIVE || |
2663 | fh->v4l_buffers.active != ZORAN_ACTIVE) { | 2648 | fh->buffers.active != ZORAN_ACTIVE) { |
2664 | res = -EBUSY; | 2649 | res = -EBUSY; |
2665 | goto strmon_unlock_and_return; | 2650 | goto strmon_unlock_and_return; |
2666 | } | 2651 | } |
2667 | 2652 | ||
2668 | zr->v4l_buffers.active = fh->v4l_buffers.active = ZORAN_LOCKED; | 2653 | zr->v4l_buffers.active = fh->buffers.active = ZORAN_LOCKED; |
2669 | zr->v4l_settings = fh->v4l_settings; | 2654 | zr->v4l_settings = fh->v4l_settings; |
2670 | 2655 | ||
2671 | zr->v4l_sync_tail = zr->v4l_pend_tail; | 2656 | zr->v4l_sync_tail = zr->v4l_pend_tail; |
@@ -2679,12 +2664,12 @@ static int zoran_streamon(struct file *file, void *__fh, enum v4l2_buf_type type | |||
2679 | case ZORAN_MAP_MODE_JPG_PLAY: | 2664 | case ZORAN_MAP_MODE_JPG_PLAY: |
2680 | /* what is the codec mode right now? */ | 2665 | /* what is the codec mode right now? */ |
2681 | if (zr->jpg_buffers.active != ZORAN_ACTIVE || | 2666 | if (zr->jpg_buffers.active != ZORAN_ACTIVE || |
2682 | fh->jpg_buffers.active != ZORAN_ACTIVE) { | 2667 | fh->buffers.active != ZORAN_ACTIVE) { |
2683 | res = -EBUSY; | 2668 | res = -EBUSY; |
2684 | goto strmon_unlock_and_return; | 2669 | goto strmon_unlock_and_return; |
2685 | } | 2670 | } |
2686 | 2671 | ||
2687 | zr->jpg_buffers.active = fh->jpg_buffers.active = ZORAN_LOCKED; | 2672 | zr->jpg_buffers.active = fh->buffers.active = ZORAN_LOCKED; |
2688 | 2673 | ||
2689 | if (zr->jpg_que_head != zr->jpg_que_tail) { | 2674 | if (zr->jpg_que_head != zr->jpg_que_tail) { |
2690 | /* Start the jpeg codec when the first frame is queued */ | 2675 | /* Start the jpeg codec when the first frame is queued */ |
@@ -2711,12 +2696,13 @@ static int zoran_streamoff(struct file *file, void *__fh, enum v4l2_buf_type typ | |||
2711 | struct zoran_fh *fh = __fh; | 2696 | struct zoran_fh *fh = __fh; |
2712 | struct zoran *zr = fh->zr; | 2697 | struct zoran *zr = fh->zr; |
2713 | int i, res = 0; | 2698 | int i, res = 0; |
2699 | unsigned long flags; | ||
2714 | 2700 | ||
2715 | mutex_lock(&zr->resource_lock); | 2701 | mutex_lock(&zr->resource_lock); |
2716 | 2702 | ||
2717 | switch (fh->map_mode) { | 2703 | switch (fh->map_mode) { |
2718 | case ZORAN_MAP_MODE_RAW: /* raw capture */ | 2704 | case ZORAN_MAP_MODE_RAW: /* raw capture */ |
2719 | if (fh->v4l_buffers.active == ZORAN_FREE && | 2705 | if (fh->buffers.active == ZORAN_FREE && |
2720 | zr->v4l_buffers.active != ZORAN_FREE) { | 2706 | zr->v4l_buffers.active != ZORAN_FREE) { |
2721 | res = -EPERM; /* stay off other's settings! */ | 2707 | res = -EPERM; /* stay off other's settings! */ |
2722 | goto strmoff_unlock_and_return; | 2708 | goto strmoff_unlock_and_return; |
@@ -2724,30 +2710,30 @@ static int zoran_streamoff(struct file *file, void *__fh, enum v4l2_buf_type typ | |||
2724 | if (zr->v4l_buffers.active == ZORAN_FREE) | 2710 | if (zr->v4l_buffers.active == ZORAN_FREE) |
2725 | goto strmoff_unlock_and_return; | 2711 | goto strmoff_unlock_and_return; |
2726 | 2712 | ||
2713 | spin_lock_irqsave(&zr->spinlock, flags); | ||
2727 | /* unload capture */ | 2714 | /* unload capture */ |
2728 | if (zr->v4l_memgrab_active) { | 2715 | if (zr->v4l_memgrab_active) { |
2729 | unsigned long flags; | ||
2730 | 2716 | ||
2731 | spin_lock_irqsave(&zr->spinlock, flags); | ||
2732 | zr36057_set_memgrab(zr, 0); | 2717 | zr36057_set_memgrab(zr, 0); |
2733 | spin_unlock_irqrestore(&zr->spinlock, flags); | ||
2734 | } | 2718 | } |
2735 | 2719 | ||
2736 | for (i = 0; i < fh->v4l_buffers.num_buffers; i++) | 2720 | for (i = 0; i < fh->buffers.num_buffers; i++) |
2737 | zr->v4l_buffers.buffer[i].state = BUZ_STATE_USER; | 2721 | zr->v4l_buffers.buffer[i].state = BUZ_STATE_USER; |
2738 | fh->v4l_buffers = zr->v4l_buffers; | 2722 | fh->buffers = zr->v4l_buffers; |
2739 | 2723 | ||
2740 | zr->v4l_buffers.active = fh->v4l_buffers.active = ZORAN_FREE; | 2724 | zr->v4l_buffers.active = fh->buffers.active = ZORAN_FREE; |
2741 | 2725 | ||
2742 | zr->v4l_grab_seq = 0; | 2726 | zr->v4l_grab_seq = 0; |
2743 | zr->v4l_pend_head = zr->v4l_pend_tail = 0; | 2727 | zr->v4l_pend_head = zr->v4l_pend_tail = 0; |
2744 | zr->v4l_sync_tail = 0; | 2728 | zr->v4l_sync_tail = 0; |
2745 | 2729 | ||
2730 | spin_unlock_irqrestore(&zr->spinlock, flags); | ||
2731 | |||
2746 | break; | 2732 | break; |
2747 | 2733 | ||
2748 | case ZORAN_MAP_MODE_JPG_REC: | 2734 | case ZORAN_MAP_MODE_JPG_REC: |
2749 | case ZORAN_MAP_MODE_JPG_PLAY: | 2735 | case ZORAN_MAP_MODE_JPG_PLAY: |
2750 | if (fh->jpg_buffers.active == ZORAN_FREE && | 2736 | if (fh->buffers.active == ZORAN_FREE && |
2751 | zr->jpg_buffers.active != ZORAN_FREE) { | 2737 | zr->jpg_buffers.active != ZORAN_FREE) { |
2752 | res = -EPERM; /* stay off other's settings! */ | 2738 | res = -EPERM; /* stay off other's settings! */ |
2753 | goto strmoff_unlock_and_return; | 2739 | goto strmoff_unlock_and_return; |
@@ -3016,7 +3002,7 @@ static int zoran_s_crop(struct file *file, void *__fh, struct v4l2_crop *crop) | |||
3016 | 3002 | ||
3017 | mutex_lock(&zr->resource_lock); | 3003 | mutex_lock(&zr->resource_lock); |
3018 | 3004 | ||
3019 | if (fh->jpg_buffers.allocated || fh->v4l_buffers.allocated) { | 3005 | if (fh->buffers.allocated) { |
3020 | dprintk(1, KERN_ERR | 3006 | dprintk(1, KERN_ERR |
3021 | "%s: VIDIOC_S_CROP - cannot change settings while active\n", | 3007 | "%s: VIDIOC_S_CROP - cannot change settings while active\n", |
3022 | ZR_DEVNAME(zr)); | 3008 | ZR_DEVNAME(zr)); |
@@ -3094,8 +3080,7 @@ static int zoran_s_jpegcomp(struct file *file, void *__fh, | |||
3094 | 3080 | ||
3095 | mutex_lock(&zr->resource_lock); | 3081 | mutex_lock(&zr->resource_lock); |
3096 | 3082 | ||
3097 | if (fh->v4l_buffers.active != ZORAN_FREE || | 3083 | if (fh->buffers.active != ZORAN_FREE) { |
3098 | fh->jpg_buffers.active != ZORAN_FREE) { | ||
3099 | dprintk(1, KERN_WARNING | 3084 | dprintk(1, KERN_WARNING |
3100 | "%s: VIDIOC_S_JPEGCOMP called while in playback/capture mode\n", | 3085 | "%s: VIDIOC_S_JPEGCOMP called while in playback/capture mode\n", |
3101 | ZR_DEVNAME(zr)); | 3086 | ZR_DEVNAME(zr)); |
@@ -3106,9 +3091,9 @@ static int zoran_s_jpegcomp(struct file *file, void *__fh, | |||
3106 | res = zoran_check_jpg_settings(zr, &settings, 0); | 3091 | res = zoran_check_jpg_settings(zr, &settings, 0); |
3107 | if (res) | 3092 | if (res) |
3108 | goto sjpegc_unlock_and_return; | 3093 | goto sjpegc_unlock_and_return; |
3109 | if (!fh->jpg_buffers.allocated) | 3094 | if (!fh->buffers.allocated) |
3110 | fh->jpg_buffers.buffer_size = | 3095 | fh->buffers.buffer_size = |
3111 | zoran_v4l2_calc_bufsize(&fh->jpg_settings); | 3096 | zoran_v4l2_calc_bufsize(&fh->jpg_settings); |
3112 | fh->jpg_settings.jpg_comp = *params = settings.jpg_comp; | 3097 | fh->jpg_settings.jpg_comp = *params = settings.jpg_comp; |
3113 | sjpegc_unlock_and_return: | 3098 | sjpegc_unlock_and_return: |
3114 | mutex_unlock(&zr->resource_lock); | 3099 | mutex_unlock(&zr->resource_lock); |
@@ -3145,11 +3130,11 @@ zoran_poll (struct file *file, | |||
3145 | KERN_DEBUG | 3130 | KERN_DEBUG |
3146 | "%s: %s() raw - active=%c, sync_tail=%lu/%c, pend_tail=%lu, pend_head=%lu\n", | 3131 | "%s: %s() raw - active=%c, sync_tail=%lu/%c, pend_tail=%lu, pend_head=%lu\n", |
3147 | ZR_DEVNAME(zr), __func__, | 3132 | ZR_DEVNAME(zr), __func__, |
3148 | "FAL"[fh->v4l_buffers.active], zr->v4l_sync_tail, | 3133 | "FAL"[fh->buffers.active], zr->v4l_sync_tail, |
3149 | "UPMD"[zr->v4l_buffers.buffer[frame].state], | 3134 | "UPMD"[zr->v4l_buffers.buffer[frame].state], |
3150 | zr->v4l_pend_tail, zr->v4l_pend_head); | 3135 | zr->v4l_pend_tail, zr->v4l_pend_head); |
3151 | /* Process is the one capturing? */ | 3136 | /* Process is the one capturing? */ |
3152 | if (fh->v4l_buffers.active != ZORAN_FREE && | 3137 | if (fh->buffers.active != ZORAN_FREE && |
3153 | /* Buffer ready to DQBUF? */ | 3138 | /* Buffer ready to DQBUF? */ |
3154 | zr->v4l_buffers.buffer[frame].state == BUZ_STATE_DONE) | 3139 | zr->v4l_buffers.buffer[frame].state == BUZ_STATE_DONE) |
3155 | res = POLLIN | POLLRDNORM; | 3140 | res = POLLIN | POLLRDNORM; |
@@ -3167,10 +3152,10 @@ zoran_poll (struct file *file, | |||
3167 | KERN_DEBUG | 3152 | KERN_DEBUG |
3168 | "%s: %s() jpg - active=%c, que_tail=%lu/%c, que_head=%lu, dma=%lu/%lu\n", | 3153 | "%s: %s() jpg - active=%c, que_tail=%lu/%c, que_head=%lu, dma=%lu/%lu\n", |
3169 | ZR_DEVNAME(zr), __func__, | 3154 | ZR_DEVNAME(zr), __func__, |
3170 | "FAL"[fh->jpg_buffers.active], zr->jpg_que_tail, | 3155 | "FAL"[fh->buffers.active], zr->jpg_que_tail, |
3171 | "UPMD"[zr->jpg_buffers.buffer[frame].state], | 3156 | "UPMD"[zr->jpg_buffers.buffer[frame].state], |
3172 | zr->jpg_que_head, zr->jpg_dma_tail, zr->jpg_dma_head); | 3157 | zr->jpg_que_head, zr->jpg_dma_tail, zr->jpg_dma_head); |
3173 | if (fh->jpg_buffers.active != ZORAN_FREE && | 3158 | if (fh->buffers.active != ZORAN_FREE && |
3174 | zr->jpg_buffers.buffer[frame].state == BUZ_STATE_DONE) { | 3159 | zr->jpg_buffers.buffer[frame].state == BUZ_STATE_DONE) { |
3175 | if (fh->map_mode == ZORAN_MAP_MODE_JPG_REC) | 3160 | if (fh->map_mode == ZORAN_MAP_MODE_JPG_REC) |
3176 | res = POLLIN | POLLRDNORM; | 3161 | res = POLLIN | POLLRDNORM; |
@@ -3224,87 +3209,49 @@ zoran_vm_close (struct vm_area_struct *vma) | |||
3224 | struct zoran *zr = fh->zr; | 3209 | struct zoran *zr = fh->zr; |
3225 | int i; | 3210 | int i; |
3226 | 3211 | ||
3227 | map->count--; | 3212 | if (--map->count > 0) |
3228 | if (map->count == 0) { | 3213 | return; |
3229 | switch (fh->map_mode) { | ||
3230 | case ZORAN_MAP_MODE_JPG_REC: | ||
3231 | case ZORAN_MAP_MODE_JPG_PLAY: | ||
3232 | |||
3233 | dprintk(3, KERN_INFO "%s: munmap(MJPEG)\n", | ||
3234 | ZR_DEVNAME(zr)); | ||
3235 | |||
3236 | for (i = 0; i < fh->jpg_buffers.num_buffers; i++) { | ||
3237 | if (fh->jpg_buffers.buffer[i].map == map) { | ||
3238 | fh->jpg_buffers.buffer[i].map = | ||
3239 | NULL; | ||
3240 | } | ||
3241 | } | ||
3242 | kfree(map); | ||
3243 | |||
3244 | for (i = 0; i < fh->jpg_buffers.num_buffers; i++) | ||
3245 | if (fh->jpg_buffers.buffer[i].map) | ||
3246 | break; | ||
3247 | if (i == fh->jpg_buffers.num_buffers) { | ||
3248 | mutex_lock(&zr->resource_lock); | ||
3249 | |||
3250 | if (fh->jpg_buffers.active != ZORAN_FREE) { | ||
3251 | jpg_qbuf(file, -1, zr->codec_mode); | ||
3252 | zr->jpg_buffers.allocated = 0; | ||
3253 | zr->jpg_buffers.active = | ||
3254 | fh->jpg_buffers.active = | ||
3255 | ZORAN_FREE; | ||
3256 | } | ||
3257 | jpg_fbuffer_free(file); | ||
3258 | mutex_unlock(&zr->resource_lock); | ||
3259 | } | ||
3260 | 3214 | ||
3261 | break; | 3215 | dprintk(3, KERN_INFO "%s: %s - munmap(%s)\n", ZR_DEVNAME(zr), |
3216 | __func__, mode_name(fh->map_mode)); | ||
3262 | 3217 | ||
3263 | case ZORAN_MAP_MODE_RAW: | 3218 | for (i = 0; i < fh->buffers.num_buffers; i++) { |
3219 | if (fh->buffers.buffer[i].map == map) | ||
3220 | fh->buffers.buffer[i].map = NULL; | ||
3221 | } | ||
3222 | kfree(map); | ||
3264 | 3223 | ||
3265 | dprintk(3, KERN_INFO "%s: munmap(V4L)\n", | 3224 | /* Any buffers still mapped? */ |
3266 | ZR_DEVNAME(zr)); | 3225 | for (i = 0; i < fh->buffers.num_buffers; i++) |
3226 | if (fh->buffers.buffer[i].map) | ||
3227 | return; | ||
3267 | 3228 | ||
3268 | for (i = 0; i < fh->v4l_buffers.num_buffers; i++) { | 3229 | dprintk(3, KERN_INFO "%s: %s - free %s buffers\n", ZR_DEVNAME(zr), |
3269 | if (fh->v4l_buffers.buffer[i].map == map) { | 3230 | __func__, mode_name(fh->map_mode)); |
3270 | /* unqueue/unmap */ | ||
3271 | fh->v4l_buffers.buffer[i].map = | ||
3272 | NULL; | ||
3273 | } | ||
3274 | } | ||
3275 | kfree(map); | ||
3276 | 3231 | ||
3277 | for (i = 0; i < fh->v4l_buffers.num_buffers; i++) | 3232 | mutex_lock(&zr->resource_lock); |
3278 | if (fh->v4l_buffers.buffer[i].map) | ||
3279 | break; | ||
3280 | if (i == fh->v4l_buffers.num_buffers) { | ||
3281 | mutex_lock(&zr->resource_lock); | ||
3282 | |||
3283 | if (fh->v4l_buffers.active != ZORAN_FREE) { | ||
3284 | unsigned long flags; | ||
3285 | |||
3286 | spin_lock_irqsave(&zr->spinlock, flags); | ||
3287 | zr36057_set_memgrab(zr, 0); | ||
3288 | zr->v4l_buffers.allocated = 0; | ||
3289 | zr->v4l_buffers.active = | ||
3290 | fh->v4l_buffers.active = | ||
3291 | ZORAN_FREE; | ||
3292 | spin_unlock_irqrestore(&zr->spinlock, flags); | ||
3293 | } | ||
3294 | v4l_fbuffer_free(file); | ||
3295 | mutex_unlock(&zr->resource_lock); | ||
3296 | } | ||
3297 | |||
3298 | break; | ||
3299 | 3233 | ||
3300 | default: | 3234 | if (fh->map_mode == ZORAN_MAP_MODE_RAW) { |
3301 | printk(KERN_ERR | 3235 | if (fh->buffers.active != ZORAN_FREE) { |
3302 | "%s: munmap() - internal error - unknown map mode %d\n", | 3236 | unsigned long flags; |
3303 | ZR_DEVNAME(zr), fh->map_mode); | ||
3304 | break; | ||
3305 | 3237 | ||
3238 | spin_lock_irqsave(&zr->spinlock, flags); | ||
3239 | zr36057_set_memgrab(zr, 0); | ||
3240 | zr->v4l_buffers.allocated = 0; | ||
3241 | zr->v4l_buffers.active = fh->buffers.active = ZORAN_FREE; | ||
3242 | spin_unlock_irqrestore(&zr->spinlock, flags); | ||
3243 | } | ||
3244 | v4l_fbuffer_free(file); | ||
3245 | } else { | ||
3246 | if (fh->buffers.active != ZORAN_FREE) { | ||
3247 | jpg_qbuf(file, -1, zr->codec_mode); | ||
3248 | zr->jpg_buffers.allocated = 0; | ||
3249 | zr->jpg_buffers.active = fh->buffers.active = ZORAN_FREE; | ||
3306 | } | 3250 | } |
3251 | jpg_fbuffer_free(file); | ||
3307 | } | 3252 | } |
3253 | |||
3254 | mutex_unlock(&zr->resource_lock); | ||
3308 | } | 3255 | } |
3309 | 3256 | ||
3310 | static struct vm_operations_struct zoran_vm_ops = { | 3257 | static struct vm_operations_struct zoran_vm_ops = { |
@@ -3329,8 +3276,7 @@ zoran_mmap (struct file *file, | |||
3329 | dprintk(3, | 3276 | dprintk(3, |
3330 | KERN_INFO "%s: mmap(%s) of 0x%08lx-0x%08lx (size=%lu)\n", | 3277 | KERN_INFO "%s: mmap(%s) of 0x%08lx-0x%08lx (size=%lu)\n", |
3331 | ZR_DEVNAME(zr), | 3278 | ZR_DEVNAME(zr), |
3332 | fh->map_mode == ZORAN_MAP_MODE_RAW ? "V4L" : "MJPEG", | 3279 | mode_name(fh->map_mode), vma->vm_start, vma->vm_end, size); |
3333 | vma->vm_start, vma->vm_end, size); | ||
3334 | 3280 | ||
3335 | if (!(vma->vm_flags & VM_SHARED) || !(vma->vm_flags & VM_READ) || | 3281 | if (!(vma->vm_flags & VM_SHARED) || !(vma->vm_flags & VM_READ) || |
3336 | !(vma->vm_flags & VM_WRITE)) { | 3282 | !(vma->vm_flags & VM_WRITE)) { |
@@ -3341,76 +3287,93 @@ zoran_mmap (struct file *file, | |||
3341 | return -EINVAL; | 3287 | return -EINVAL; |
3342 | } | 3288 | } |
3343 | 3289 | ||
3344 | switch (fh->map_mode) { | 3290 | mutex_lock(&zr->resource_lock); |
3345 | 3291 | ||
3346 | case ZORAN_MAP_MODE_JPG_REC: | 3292 | if (!fh->buffers.allocated) { |
3347 | case ZORAN_MAP_MODE_JPG_PLAY: | 3293 | dprintk(1, |
3294 | KERN_ERR | ||
3295 | "%s: zoran_mmap(%s) - buffers not yet allocated\n", | ||
3296 | ZR_DEVNAME(zr), mode_name(fh->map_mode)); | ||
3297 | res = -ENOMEM; | ||
3298 | goto mmap_unlock_and_return; | ||
3299 | } | ||
3348 | 3300 | ||
3349 | /* lock */ | 3301 | first = offset / fh->buffers.buffer_size; |
3350 | mutex_lock(&zr->resource_lock); | 3302 | last = first - 1 + size / fh->buffers.buffer_size; |
3303 | if (offset % fh->buffers.buffer_size != 0 || | ||
3304 | size % fh->buffers.buffer_size != 0 || first < 0 || | ||
3305 | last < 0 || first >= fh->buffers.num_buffers || | ||
3306 | last >= fh->buffers.buffer_size) { | ||
3307 | dprintk(1, | ||
3308 | KERN_ERR | ||
3309 | "%s: mmap(%s) - offset=%lu or size=%lu invalid for bufsize=%d and numbufs=%d\n", | ||
3310 | ZR_DEVNAME(zr), mode_name(fh->map_mode), offset, size, | ||
3311 | fh->buffers.buffer_size, | ||
3312 | fh->buffers.num_buffers); | ||
3313 | res = -EINVAL; | ||
3314 | goto mmap_unlock_and_return; | ||
3315 | } | ||
3351 | 3316 | ||
3352 | /* Map the MJPEG buffers */ | 3317 | /* Check if any buffers are already mapped */ |
3353 | if (!fh->jpg_buffers.allocated) { | 3318 | for (i = first; i <= last; i++) { |
3319 | if (fh->buffers.buffer[i].map) { | ||
3354 | dprintk(1, | 3320 | dprintk(1, |
3355 | KERN_ERR | 3321 | KERN_ERR |
3356 | "%s: zoran_mmap(MJPEG) - buffers not yet allocated\n", | 3322 | "%s: mmap(%s) - buffer %d already mapped\n", |
3357 | ZR_DEVNAME(zr)); | 3323 | ZR_DEVNAME(zr), mode_name(fh->map_mode), i); |
3358 | res = -ENOMEM; | 3324 | res = -EBUSY; |
3359 | goto jpg_mmap_unlock_and_return; | 3325 | goto mmap_unlock_and_return; |
3360 | } | 3326 | } |
3327 | } | ||
3361 | 3328 | ||
3362 | first = offset / fh->jpg_buffers.buffer_size; | 3329 | /* map these buffers */ |
3363 | last = first - 1 + size / fh->jpg_buffers.buffer_size; | 3330 | map = kmalloc(sizeof(struct zoran_mapping), GFP_KERNEL); |
3364 | if (offset % fh->jpg_buffers.buffer_size != 0 || | 3331 | if (!map) { |
3365 | size % fh->jpg_buffers.buffer_size != 0 || first < 0 || | 3332 | res = -ENOMEM; |
3366 | last < 0 || first >= fh->jpg_buffers.num_buffers || | 3333 | goto mmap_unlock_and_return; |
3367 | last >= fh->jpg_buffers.num_buffers) { | 3334 | } |
3368 | dprintk(1, | 3335 | map->file = file; |
3369 | KERN_ERR | 3336 | map->count = 1; |
3370 | "%s: mmap(MJPEG) - offset=%lu or size=%lu invalid for bufsize=%d and numbufs=%d\n", | 3337 | |
3371 | ZR_DEVNAME(zr), offset, size, | 3338 | vma->vm_ops = &zoran_vm_ops; |
3372 | fh->jpg_buffers.buffer_size, | 3339 | vma->vm_flags |= VM_DONTEXPAND; |
3373 | fh->jpg_buffers.num_buffers); | 3340 | vma->vm_private_data = map; |
3374 | res = -EINVAL; | 3341 | |
3375 | goto jpg_mmap_unlock_and_return; | 3342 | if (fh->map_mode == ZORAN_MAP_MODE_RAW) { |
3376 | } | ||
3377 | for (i = first; i <= last; i++) { | 3343 | for (i = first; i <= last; i++) { |
3378 | if (fh->jpg_buffers.buffer[i].map) { | 3344 | todo = size; |
3345 | if (todo > fh->buffers.buffer_size) | ||
3346 | todo = fh->buffers.buffer_size; | ||
3347 | page = fh->buffers.buffer[i].v4l.fbuffer_phys; | ||
3348 | if (remap_pfn_range(vma, start, page >> PAGE_SHIFT, | ||
3349 | todo, PAGE_SHARED)) { | ||
3379 | dprintk(1, | 3350 | dprintk(1, |
3380 | KERN_ERR | 3351 | KERN_ERR |
3381 | "%s: mmap(MJPEG) - buffer %d already mapped\n", | 3352 | "%s: zoran_mmap(V4L) - remap_pfn_range failed\n", |
3382 | ZR_DEVNAME(zr), i); | 3353 | ZR_DEVNAME(zr)); |
3383 | res = -EBUSY; | 3354 | res = -EAGAIN; |
3384 | goto jpg_mmap_unlock_and_return; | 3355 | goto mmap_unlock_and_return; |
3385 | } | 3356 | } |
3357 | size -= todo; | ||
3358 | start += todo; | ||
3359 | fh->buffers.buffer[i].map = map; | ||
3360 | if (size == 0) | ||
3361 | break; | ||
3386 | } | 3362 | } |
3387 | 3363 | } else { | |
3388 | /* map these buffers (v4l_buffers[i]) */ | ||
3389 | map = kmalloc(sizeof(struct zoran_mapping), GFP_KERNEL); | ||
3390 | if (!map) { | ||
3391 | res = -ENOMEM; | ||
3392 | goto jpg_mmap_unlock_and_return; | ||
3393 | } | ||
3394 | map->file = file; | ||
3395 | map->count = 1; | ||
3396 | |||
3397 | vma->vm_ops = &zoran_vm_ops; | ||
3398 | vma->vm_flags |= VM_DONTEXPAND; | ||
3399 | vma->vm_private_data = map; | ||
3400 | |||
3401 | for (i = first; i <= last; i++) { | 3364 | for (i = first; i <= last; i++) { |
3402 | for (j = 0; | 3365 | for (j = 0; |
3403 | j < fh->jpg_buffers.buffer_size / PAGE_SIZE; | 3366 | j < fh->buffers.buffer_size / PAGE_SIZE; |
3404 | j++) { | 3367 | j++) { |
3405 | fraglen = | 3368 | fraglen = |
3406 | (le32_to_cpu(fh->jpg_buffers.buffer[i]. | 3369 | (le32_to_cpu(fh->buffers.buffer[i].jpg. |
3407 | frag_tab[2 * j + 1]) & ~1) << 1; | 3370 | frag_tab[2 * j + 1]) & ~1) << 1; |
3408 | todo = size; | 3371 | todo = size; |
3409 | if (todo > fraglen) | 3372 | if (todo > fraglen) |
3410 | todo = fraglen; | 3373 | todo = fraglen; |
3411 | pos = | 3374 | pos = |
3412 | le32_to_cpu(fh->jpg_buffers. | 3375 | le32_to_cpu(fh->buffers. |
3413 | buffer[i].frag_tab[2 * j]); | 3376 | buffer[i].jpg.frag_tab[2 * j]); |
3414 | /* should just be pos on i386 */ | 3377 | /* should just be pos on i386 */ |
3415 | page = virt_to_phys(bus_to_virt(pos)) | 3378 | page = virt_to_phys(bus_to_virt(pos)) |
3416 | >> PAGE_SHIFT; | 3379 | >> PAGE_SHIFT; |
@@ -3421,112 +3384,26 @@ zoran_mmap (struct file *file, | |||
3421 | "%s: zoran_mmap(V4L) - remap_pfn_range failed\n", | 3384 | "%s: zoran_mmap(V4L) - remap_pfn_range failed\n", |
3422 | ZR_DEVNAME(zr)); | 3385 | ZR_DEVNAME(zr)); |
3423 | res = -EAGAIN; | 3386 | res = -EAGAIN; |
3424 | goto jpg_mmap_unlock_and_return; | 3387 | goto mmap_unlock_and_return; |
3425 | } | 3388 | } |
3426 | size -= todo; | 3389 | size -= todo; |
3427 | start += todo; | 3390 | start += todo; |
3428 | if (size == 0) | 3391 | if (size == 0) |
3429 | break; | 3392 | break; |
3430 | if (le32_to_cpu(fh->jpg_buffers.buffer[i]. | 3393 | if (le32_to_cpu(fh->buffers.buffer[i].jpg. |
3431 | frag_tab[2 * j + 1]) & 1) | 3394 | frag_tab[2 * j + 1]) & 1) |
3432 | break; /* was last fragment */ | 3395 | break; /* was last fragment */ |
3433 | } | 3396 | } |
3434 | fh->jpg_buffers.buffer[i].map = map; | 3397 | fh->buffers.buffer[i].map = map; |
3435 | if (size == 0) | 3398 | if (size == 0) |
3436 | break; | 3399 | break; |
3437 | 3400 | ||
3438 | } | 3401 | } |
3439 | jpg_mmap_unlock_and_return: | ||
3440 | mutex_unlock(&zr->resource_lock); | ||
3441 | |||
3442 | break; | ||
3443 | |||
3444 | case ZORAN_MAP_MODE_RAW: | ||
3445 | |||
3446 | mutex_lock(&zr->resource_lock); | ||
3447 | |||
3448 | /* Map the V4L buffers */ | ||
3449 | if (!fh->v4l_buffers.allocated) { | ||
3450 | dprintk(1, | ||
3451 | KERN_ERR | ||
3452 | "%s: zoran_mmap(V4L) - buffers not yet allocated\n", | ||
3453 | ZR_DEVNAME(zr)); | ||
3454 | res = -ENOMEM; | ||
3455 | goto v4l_mmap_unlock_and_return; | ||
3456 | } | ||
3457 | |||
3458 | first = offset / fh->v4l_buffers.buffer_size; | ||
3459 | last = first - 1 + size / fh->v4l_buffers.buffer_size; | ||
3460 | if (offset % fh->v4l_buffers.buffer_size != 0 || | ||
3461 | size % fh->v4l_buffers.buffer_size != 0 || first < 0 || | ||
3462 | last < 0 || first >= fh->v4l_buffers.num_buffers || | ||
3463 | last >= fh->v4l_buffers.buffer_size) { | ||
3464 | dprintk(1, | ||
3465 | KERN_ERR | ||
3466 | "%s: mmap(V4L) - offset=%lu or size=%lu invalid for bufsize=%d and numbufs=%d\n", | ||
3467 | ZR_DEVNAME(zr), offset, size, | ||
3468 | fh->v4l_buffers.buffer_size, | ||
3469 | fh->v4l_buffers.num_buffers); | ||
3470 | res = -EINVAL; | ||
3471 | goto v4l_mmap_unlock_and_return; | ||
3472 | } | ||
3473 | for (i = first; i <= last; i++) { | ||
3474 | if (fh->v4l_buffers.buffer[i].map) { | ||
3475 | dprintk(1, | ||
3476 | KERN_ERR | ||
3477 | "%s: mmap(V4L) - buffer %d already mapped\n", | ||
3478 | ZR_DEVNAME(zr), i); | ||
3479 | res = -EBUSY; | ||
3480 | goto v4l_mmap_unlock_and_return; | ||
3481 | } | ||
3482 | } | ||
3483 | |||
3484 | /* map these buffers (v4l_buffers[i]) */ | ||
3485 | map = kmalloc(sizeof(struct zoran_mapping), GFP_KERNEL); | ||
3486 | if (!map) { | ||
3487 | res = -ENOMEM; | ||
3488 | goto v4l_mmap_unlock_and_return; | ||
3489 | } | ||
3490 | map->file = file; | ||
3491 | map->count = 1; | ||
3492 | |||
3493 | vma->vm_ops = &zoran_vm_ops; | ||
3494 | vma->vm_flags |= VM_DONTEXPAND; | ||
3495 | vma->vm_private_data = map; | ||
3496 | |||
3497 | for (i = first; i <= last; i++) { | ||
3498 | todo = size; | ||
3499 | if (todo > fh->v4l_buffers.buffer_size) | ||
3500 | todo = fh->v4l_buffers.buffer_size; | ||
3501 | page = fh->v4l_buffers.buffer[i].fbuffer_phys; | ||
3502 | if (remap_pfn_range(vma, start, page >> PAGE_SHIFT, | ||
3503 | todo, PAGE_SHARED)) { | ||
3504 | dprintk(1, | ||
3505 | KERN_ERR | ||
3506 | "%s: zoran_mmap(V4L)i - remap_pfn_range failed\n", | ||
3507 | ZR_DEVNAME(zr)); | ||
3508 | res = -EAGAIN; | ||
3509 | goto v4l_mmap_unlock_and_return; | ||
3510 | } | ||
3511 | size -= todo; | ||
3512 | start += todo; | ||
3513 | fh->v4l_buffers.buffer[i].map = map; | ||
3514 | if (size == 0) | ||
3515 | break; | ||
3516 | } | ||
3517 | v4l_mmap_unlock_and_return: | ||
3518 | mutex_unlock(&zr->resource_lock); | ||
3519 | |||
3520 | break; | ||
3521 | |||
3522 | default: | ||
3523 | dprintk(1, | ||
3524 | KERN_ERR | ||
3525 | "%s: zoran_mmap() - internal error - unknown map mode %d\n", | ||
3526 | ZR_DEVNAME(zr), fh->map_mode); | ||
3527 | break; | ||
3528 | } | 3402 | } |
3529 | 3403 | ||
3404 | mmap_unlock_and_return: | ||
3405 | mutex_unlock(&zr->resource_lock); | ||
3406 | |||
3530 | return 0; | 3407 | return 0; |
3531 | } | 3408 | } |
3532 | 3409 | ||