aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/videobuf-dma-sg.c
diff options
context:
space:
mode:
authorPawel Osciak <p.osciak@samsung.com>2010-03-17 03:01:04 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2010-05-17 23:50:25 -0400
commit7a02264ca9ec5409e22b9d41f32b431d08eadbce (patch)
tree4c7cd63a863c10f0fbe8d8ec7927e203e9d7577f /drivers/media/video/videobuf-dma-sg.c
parent85e092190b5f7dfe9b78556440472c5590a32b4e (diff)
V4L/DVB: v4l: videobuf: code cleanup
Make videobuf pass checkpatch; minor code cleanups. Signed-off-by: Pawel Osciak <p.osciak@samsung.com> Reviewed-by: Kyungmin Park <kyungmin.park@samsung.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/videobuf-dma-sg.c')
-rw-r--r--drivers/media/video/videobuf-dma-sg.c276
1 files changed, 140 insertions, 136 deletions
diff --git a/drivers/media/video/videobuf-dma-sg.c b/drivers/media/video/videobuf-dma-sg.c
index fcd045e7a1c1..c9d946a388e8 100644
--- a/drivers/media/video/videobuf-dma-sg.c
+++ b/drivers/media/video/videobuf-dma-sg.c
@@ -37,8 +37,12 @@
37#define MAGIC_DMABUF 0x19721112 37#define MAGIC_DMABUF 0x19721112
38#define MAGIC_SG_MEM 0x17890714 38#define MAGIC_SG_MEM 0x17890714
39 39
40#define MAGIC_CHECK(is,should) if (unlikely((is) != (should))) \ 40#define MAGIC_CHECK(is, should) \
41 { printk(KERN_ERR "magic mismatch: %x (expected %x)\n",is,should); BUG(); } 41 if (unlikely((is) != (should))) { \
42 printk(KERN_ERR "magic mismatch: %x (expected %x)\n", \
43 is, should); \
44 BUG(); \
45 }
42 46
43static int debug; 47static int debug;
44module_param(debug, int, 0644); 48module_param(debug, int, 0644);
@@ -47,13 +51,13 @@ MODULE_DESCRIPTION("helper module to manage video4linux dma sg buffers");
47MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>"); 51MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
48MODULE_LICENSE("GPL"); 52MODULE_LICENSE("GPL");
49 53
50#define dprintk(level, fmt, arg...) if (debug >= level) \ 54#define dprintk(level, fmt, arg...) \
51 printk(KERN_DEBUG "vbuf-sg: " fmt , ## arg) 55 if (debug >= level) \
56 printk(KERN_DEBUG "vbuf-sg: " fmt , ## arg)
52 57
53/* --------------------------------------------------------------------- */ 58/* --------------------------------------------------------------------- */
54 59
55struct scatterlist* 60struct scatterlist *videobuf_vmalloc_to_sg(unsigned char *virt, int nr_pages)
56videobuf_vmalloc_to_sg(unsigned char *virt, int nr_pages)
57{ 61{
58 struct scatterlist *sglist; 62 struct scatterlist *sglist;
59 struct page *pg; 63 struct page *pg;
@@ -73,13 +77,14 @@ videobuf_vmalloc_to_sg(unsigned char *virt, int nr_pages)
73 } 77 }
74 return sglist; 78 return sglist;
75 79
76 err: 80err:
77 vfree(sglist); 81 vfree(sglist);
78 return NULL; 82 return NULL;
79} 83}
84EXPORT_SYMBOL_GPL(videobuf_vmalloc_to_sg);
80 85
81struct scatterlist* 86struct scatterlist *videobuf_pages_to_sg(struct page **pages, int nr_pages,
82videobuf_pages_to_sg(struct page **pages, int nr_pages, int offset) 87 int offset)
83{ 88{
84 struct scatterlist *sglist; 89 struct scatterlist *sglist;
85 int i; 90 int i;
@@ -104,20 +109,20 @@ videobuf_pages_to_sg(struct page **pages, int nr_pages, int offset)
104 } 109 }
105 return sglist; 110 return sglist;
106 111
107 nopage: 112nopage:
108 dprintk(2,"sgl: oops - no page\n"); 113 dprintk(2, "sgl: oops - no page\n");
109 vfree(sglist); 114 vfree(sglist);
110 return NULL; 115 return NULL;
111 116
112 highmem: 117highmem:
113 dprintk(2,"sgl: oops - highmem page\n"); 118 dprintk(2, "sgl: oops - highmem page\n");
114 vfree(sglist); 119 vfree(sglist);
115 return NULL; 120 return NULL;
116} 121}
117 122
118/* --------------------------------------------------------------------- */ 123/* --------------------------------------------------------------------- */
119 124
120struct videobuf_dmabuf *videobuf_to_dma (struct videobuf_buffer *buf) 125struct videobuf_dmabuf *videobuf_to_dma(struct videobuf_buffer *buf)
121{ 126{
122 struct videobuf_dma_sg_memory *mem = buf->priv; 127 struct videobuf_dma_sg_memory *mem = buf->priv;
123 BUG_ON(!mem); 128 BUG_ON(!mem);
@@ -126,17 +131,19 @@ struct videobuf_dmabuf *videobuf_to_dma (struct videobuf_buffer *buf)
126 131
127 return &mem->dma; 132 return &mem->dma;
128} 133}
134EXPORT_SYMBOL_GPL(videobuf_to_dma);
129 135
130void videobuf_dma_init(struct videobuf_dmabuf *dma) 136void videobuf_dma_init(struct videobuf_dmabuf *dma)
131{ 137{
132 memset(dma,0,sizeof(*dma)); 138 memset(dma, 0, sizeof(*dma));
133 dma->magic = MAGIC_DMABUF; 139 dma->magic = MAGIC_DMABUF;
134} 140}
141EXPORT_SYMBOL_GPL(videobuf_dma_init);
135 142
136static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma, 143static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma,
137 int direction, unsigned long data, unsigned long size) 144 int direction, unsigned long data, unsigned long size)
138{ 145{
139 unsigned long first,last; 146 unsigned long first, last;
140 int err, rw = 0; 147 int err, rw = 0;
141 148
142 dma->direction = direction; 149 dma->direction = direction;
@@ -155,21 +162,21 @@ static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma,
155 last = ((data+size-1) & PAGE_MASK) >> PAGE_SHIFT; 162 last = ((data+size-1) & PAGE_MASK) >> PAGE_SHIFT;
156 dma->offset = data & ~PAGE_MASK; 163 dma->offset = data & ~PAGE_MASK;
157 dma->nr_pages = last-first+1; 164 dma->nr_pages = last-first+1;
158 dma->pages = kmalloc(dma->nr_pages * sizeof(struct page*), 165 dma->pages = kmalloc(dma->nr_pages * sizeof(struct page *), GFP_KERNEL);
159 GFP_KERNEL);
160 if (NULL == dma->pages) 166 if (NULL == dma->pages)
161 return -ENOMEM; 167 return -ENOMEM;
162 dprintk(1,"init user [0x%lx+0x%lx => %d pages]\n",
163 data,size,dma->nr_pages);
164 168
165 err = get_user_pages(current,current->mm, 169 dprintk(1, "init user [0x%lx+0x%lx => %d pages]\n",
170 data, size, dma->nr_pages);
171
172 err = get_user_pages(current, current->mm,
166 data & PAGE_MASK, dma->nr_pages, 173 data & PAGE_MASK, dma->nr_pages,
167 rw == READ, 1, /* force */ 174 rw == READ, 1, /* force */
168 dma->pages, NULL); 175 dma->pages, NULL);
169 176
170 if (err != dma->nr_pages) { 177 if (err != dma->nr_pages) {
171 dma->nr_pages = (err >= 0) ? err : 0; 178 dma->nr_pages = (err >= 0) ? err : 0;
172 dprintk(1,"get_user_pages: err=%d [%d]\n",err,dma->nr_pages); 179 dprintk(1, "get_user_pages: err=%d [%d]\n", err, dma->nr_pages);
173 return err < 0 ? err : -EINVAL; 180 return err < 0 ? err : -EINVAL;
174 } 181 }
175 return 0; 182 return 0;
@@ -179,48 +186,58 @@ int videobuf_dma_init_user(struct videobuf_dmabuf *dma, int direction,
179 unsigned long data, unsigned long size) 186 unsigned long data, unsigned long size)
180{ 187{
181 int ret; 188 int ret;
189
182 down_read(&current->mm->mmap_sem); 190 down_read(&current->mm->mmap_sem);
183 ret = videobuf_dma_init_user_locked(dma, direction, data, size); 191 ret = videobuf_dma_init_user_locked(dma, direction, data, size);
184 up_read(&current->mm->mmap_sem); 192 up_read(&current->mm->mmap_sem);
185 193
186 return ret; 194 return ret;
187} 195}
196EXPORT_SYMBOL_GPL(videobuf_dma_init_user);
188 197
189int videobuf_dma_init_kernel(struct videobuf_dmabuf *dma, int direction, 198int videobuf_dma_init_kernel(struct videobuf_dmabuf *dma, int direction,
190 int nr_pages) 199 int nr_pages)
191{ 200{
192 dprintk(1,"init kernel [%d pages]\n",nr_pages); 201 dprintk(1, "init kernel [%d pages]\n", nr_pages);
202
193 dma->direction = direction; 203 dma->direction = direction;
194 dma->vmalloc = vmalloc_32(nr_pages << PAGE_SHIFT); 204 dma->vmalloc = vmalloc_32(nr_pages << PAGE_SHIFT);
195 if (NULL == dma->vmalloc) { 205 if (NULL == dma->vmalloc) {
196 dprintk(1,"vmalloc_32(%d pages) failed\n",nr_pages); 206 dprintk(1, "vmalloc_32(%d pages) failed\n", nr_pages);
197 return -ENOMEM; 207 return -ENOMEM;
198 } 208 }
199 dprintk(1,"vmalloc is at addr 0x%08lx, size=%d\n", 209
210 dprintk(1, "vmalloc is at addr 0x%08lx, size=%d\n",
200 (unsigned long)dma->vmalloc, 211 (unsigned long)dma->vmalloc,
201 nr_pages << PAGE_SHIFT); 212 nr_pages << PAGE_SHIFT);
202 memset(dma->vmalloc,0,nr_pages << PAGE_SHIFT); 213
214 memset(dma->vmalloc, 0, nr_pages << PAGE_SHIFT);
203 dma->nr_pages = nr_pages; 215 dma->nr_pages = nr_pages;
216
204 return 0; 217 return 0;
205} 218}
219EXPORT_SYMBOL_GPL(videobuf_dma_init_kernel);
206 220
207int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction, 221int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction,
208 dma_addr_t addr, int nr_pages) 222 dma_addr_t addr, int nr_pages)
209{ 223{
210 dprintk(1,"init overlay [%d pages @ bus 0x%lx]\n", 224 dprintk(1, "init overlay [%d pages @ bus 0x%lx]\n",
211 nr_pages,(unsigned long)addr); 225 nr_pages, (unsigned long)addr);
212 dma->direction = direction; 226 dma->direction = direction;
227
213 if (0 == addr) 228 if (0 == addr)
214 return -EINVAL; 229 return -EINVAL;
215 230
216 dma->bus_addr = addr; 231 dma->bus_addr = addr;
217 dma->nr_pages = nr_pages; 232 dma->nr_pages = nr_pages;
233
218 return 0; 234 return 0;
219} 235}
236EXPORT_SYMBOL_GPL(videobuf_dma_init_overlay);
220 237
221int videobuf_dma_map(struct videobuf_queue* q, struct videobuf_dmabuf *dma) 238int videobuf_dma_map(struct videobuf_queue *q, struct videobuf_dmabuf *dma)
222{ 239{
223 MAGIC_CHECK(dma->magic,MAGIC_DMABUF); 240 MAGIC_CHECK(dma->magic, MAGIC_DMABUF);
224 BUG_ON(0 == dma->nr_pages); 241 BUG_ON(0 == dma->nr_pages);
225 242
226 if (dma->pages) { 243 if (dma->pages) {
@@ -228,20 +245,21 @@ int videobuf_dma_map(struct videobuf_queue* q, struct videobuf_dmabuf *dma)
228 dma->offset); 245 dma->offset);
229 } 246 }
230 if (dma->vmalloc) { 247 if (dma->vmalloc) {
231 dma->sglist = videobuf_vmalloc_to_sg 248 dma->sglist = videobuf_vmalloc_to_sg(dma->vmalloc,
232 (dma->vmalloc,dma->nr_pages); 249 dma->nr_pages);
233 } 250 }
234 if (dma->bus_addr) { 251 if (dma->bus_addr) {
235 dma->sglist = vmalloc(sizeof(*dma->sglist)); 252 dma->sglist = vmalloc(sizeof(*dma->sglist));
236 if (NULL != dma->sglist) { 253 if (NULL != dma->sglist) {
237 dma->sglen = 1; 254 dma->sglen = 1;
238 sg_dma_address(&dma->sglist[0]) = dma->bus_addr & PAGE_MASK; 255 sg_dma_address(&dma->sglist[0]) = dma->bus_addr
239 dma->sglist[0].offset = dma->bus_addr & ~PAGE_MASK; 256 & PAGE_MASK;
240 sg_dma_len(&dma->sglist[0]) = dma->nr_pages * PAGE_SIZE; 257 dma->sglist[0].offset = dma->bus_addr & ~PAGE_MASK;
258 sg_dma_len(&dma->sglist[0]) = dma->nr_pages * PAGE_SIZE;
241 } 259 }
242 } 260 }
243 if (NULL == dma->sglist) { 261 if (NULL == dma->sglist) {
244 dprintk(1,"scatterlist is NULL\n"); 262 dprintk(1, "scatterlist is NULL\n");
245 return -ENOMEM; 263 return -ENOMEM;
246 } 264 }
247 if (!dma->bus_addr) { 265 if (!dma->bus_addr) {
@@ -249,15 +267,17 @@ int videobuf_dma_map(struct videobuf_queue* q, struct videobuf_dmabuf *dma)
249 dma->nr_pages, dma->direction); 267 dma->nr_pages, dma->direction);
250 if (0 == dma->sglen) { 268 if (0 == dma->sglen) {
251 printk(KERN_WARNING 269 printk(KERN_WARNING
252 "%s: videobuf_map_sg failed\n",__func__); 270 "%s: videobuf_map_sg failed\n", __func__);
253 vfree(dma->sglist); 271 vfree(dma->sglist);
254 dma->sglist = NULL; 272 dma->sglist = NULL;
255 dma->sglen = 0; 273 dma->sglen = 0;
256 return -ENOMEM; 274 return -ENOMEM;
257 } 275 }
258 } 276 }
277
259 return 0; 278 return 0;
260} 279}
280EXPORT_SYMBOL_GPL(videobuf_dma_map);
261 281
262int videobuf_dma_sync(struct videobuf_queue *q, struct videobuf_dmabuf *dma) 282int videobuf_dma_sync(struct videobuf_queue *q, struct videobuf_dmabuf *dma)
263{ 283{
@@ -265,12 +285,15 @@ int videobuf_dma_sync(struct videobuf_queue *q, struct videobuf_dmabuf *dma)
265 BUG_ON(!dma->sglen); 285 BUG_ON(!dma->sglen);
266 286
267 dma_sync_sg_for_cpu(q->dev, dma->sglist, dma->nr_pages, dma->direction); 287 dma_sync_sg_for_cpu(q->dev, dma->sglist, dma->nr_pages, dma->direction);
288
268 return 0; 289 return 0;
269} 290}
291EXPORT_SYMBOL_GPL(videobuf_dma_sync);
270 292
271int videobuf_dma_unmap(struct videobuf_queue* q,struct videobuf_dmabuf *dma) 293int videobuf_dma_unmap(struct videobuf_queue *q, struct videobuf_dmabuf *dma)
272{ 294{
273 MAGIC_CHECK(dma->magic, MAGIC_DMABUF); 295 MAGIC_CHECK(dma->magic, MAGIC_DMABUF);
296
274 if (!dma->sglen) 297 if (!dma->sglen)
275 return 0; 298 return 0;
276 299
@@ -279,17 +302,19 @@ int videobuf_dma_unmap(struct videobuf_queue* q,struct videobuf_dmabuf *dma)
279 vfree(dma->sglist); 302 vfree(dma->sglist);
280 dma->sglist = NULL; 303 dma->sglist = NULL;
281 dma->sglen = 0; 304 dma->sglen = 0;
305
282 return 0; 306 return 0;
283} 307}
308EXPORT_SYMBOL_GPL(videobuf_dma_unmap);
284 309
285int videobuf_dma_free(struct videobuf_dmabuf *dma) 310int videobuf_dma_free(struct videobuf_dmabuf *dma)
286{ 311{
287 MAGIC_CHECK(dma->magic,MAGIC_DMABUF); 312 int i;
313 MAGIC_CHECK(dma->magic, MAGIC_DMABUF);
288 BUG_ON(dma->sglen); 314 BUG_ON(dma->sglen);
289 315
290 if (dma->pages) { 316 if (dma->pages) {
291 int i; 317 for (i = 0; i < dma->nr_pages; i++)
292 for (i=0; i < dma->nr_pages; i++)
293 page_cache_release(dma->pages[i]); 318 page_cache_release(dma->pages[i]);
294 kfree(dma->pages); 319 kfree(dma->pages);
295 dma->pages = NULL; 320 dma->pages = NULL;
@@ -298,12 +323,13 @@ int videobuf_dma_free(struct videobuf_dmabuf *dma)
298 vfree(dma->vmalloc); 323 vfree(dma->vmalloc);
299 dma->vmalloc = NULL; 324 dma->vmalloc = NULL;
300 325
301 if (dma->bus_addr) { 326 if (dma->bus_addr)
302 dma->bus_addr = 0; 327 dma->bus_addr = 0;
303 }
304 dma->direction = DMA_NONE; 328 dma->direction = DMA_NONE;
329
305 return 0; 330 return 0;
306} 331}
332EXPORT_SYMBOL_GPL(videobuf_dma_free);
307 333
308/* --------------------------------------------------------------------- */ 334/* --------------------------------------------------------------------- */
309 335
@@ -315,6 +341,7 @@ int videobuf_sg_dma_map(struct device *dev, struct videobuf_dmabuf *dma)
315 341
316 return videobuf_dma_map(&q, dma); 342 return videobuf_dma_map(&q, dma);
317} 343}
344EXPORT_SYMBOL_GPL(videobuf_sg_dma_map);
318 345
319int videobuf_sg_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma) 346int videobuf_sg_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma)
320{ 347{
@@ -324,49 +351,48 @@ int videobuf_sg_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma)
324 351
325 return videobuf_dma_unmap(&q, dma); 352 return videobuf_dma_unmap(&q, dma);
326} 353}
354EXPORT_SYMBOL_GPL(videobuf_sg_dma_unmap);
327 355
328/* --------------------------------------------------------------------- */ 356/* --------------------------------------------------------------------- */
329 357
330static void 358static void videobuf_vm_open(struct vm_area_struct *vma)
331videobuf_vm_open(struct vm_area_struct *vma)
332{ 359{
333 struct videobuf_mapping *map = vma->vm_private_data; 360 struct videobuf_mapping *map = vma->vm_private_data;
334 361
335 dprintk(2,"vm_open %p [count=%d,vma=%08lx-%08lx]\n",map, 362 dprintk(2, "vm_open %p [count=%d,vma=%08lx-%08lx]\n", map,
336 map->count,vma->vm_start,vma->vm_end); 363 map->count, vma->vm_start, vma->vm_end);
364
337 map->count++; 365 map->count++;
338} 366}
339 367
340static void 368static void videobuf_vm_close(struct vm_area_struct *vma)
341videobuf_vm_close(struct vm_area_struct *vma)
342{ 369{
343 struct videobuf_mapping *map = vma->vm_private_data; 370 struct videobuf_mapping *map = vma->vm_private_data;
344 struct videobuf_queue *q = map->q; 371 struct videobuf_queue *q = map->q;
345 struct videobuf_dma_sg_memory *mem; 372 struct videobuf_dma_sg_memory *mem;
346 int i; 373 int i;
347 374
348 dprintk(2,"vm_close %p [count=%d,vma=%08lx-%08lx]\n",map, 375 dprintk(2, "vm_close %p [count=%d,vma=%08lx-%08lx]\n", map,
349 map->count,vma->vm_start,vma->vm_end); 376 map->count, vma->vm_start, vma->vm_end);
350 377
351 map->count--; 378 map->count--;
352 if (0 == map->count) { 379 if (0 == map->count) {
353 dprintk(1,"munmap %p q=%p\n",map,q); 380 dprintk(1, "munmap %p q=%p\n", map, q);
354 mutex_lock(&q->vb_lock); 381 mutex_lock(&q->vb_lock);
355 for (i = 0; i < VIDEO_MAX_FRAME; i++) { 382 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
356 if (NULL == q->bufs[i]) 383 if (NULL == q->bufs[i])
357 continue; 384 continue;
358 mem=q->bufs[i]->priv; 385 mem = q->bufs[i]->priv;
359
360 if (!mem) 386 if (!mem)
361 continue; 387 continue;
362 388
363 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM); 389 MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
364 390
365 if (q->bufs[i]->map != map) 391 if (q->bufs[i]->map != map)
366 continue; 392 continue;
367 q->bufs[i]->map = NULL; 393 q->bufs[i]->map = NULL;
368 q->bufs[i]->baddr = 0; 394 q->bufs[i]->baddr = 0;
369 q->ops->buf_release(q,q->bufs[i]); 395 q->ops->buf_release(q, q->bufs[i]);
370 } 396 }
371 mutex_unlock(&q->vb_lock); 397 mutex_unlock(&q->vb_lock);
372 kfree(map); 398 kfree(map);
@@ -380,26 +406,27 @@ videobuf_vm_close(struct vm_area_struct *vma)
380 * now ...). Bounce buffers don't work very well for the data rates 406 * now ...). Bounce buffers don't work very well for the data rates
381 * video capture has. 407 * video capture has.
382 */ 408 */
383static int 409static int videobuf_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
384videobuf_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
385{ 410{
386 struct page *page; 411 struct page *page;
387 412
388 dprintk(3,"fault: fault @ %08lx [vma %08lx-%08lx]\n", 413 dprintk(3, "fault: fault @ %08lx [vma %08lx-%08lx]\n",
389 (unsigned long)vmf->virtual_address,vma->vm_start,vma->vm_end); 414 (unsigned long)vmf->virtual_address,
415 vma->vm_start, vma->vm_end);
416
390 page = alloc_page(GFP_USER | __GFP_DMA32); 417 page = alloc_page(GFP_USER | __GFP_DMA32);
391 if (!page) 418 if (!page)
392 return VM_FAULT_OOM; 419 return VM_FAULT_OOM;
393 clear_user_highpage(page, (unsigned long)vmf->virtual_address); 420 clear_user_highpage(page, (unsigned long)vmf->virtual_address);
394 vmf->page = page; 421 vmf->page = page;
422
395 return 0; 423 return 0;
396} 424}
397 425
398static const struct vm_operations_struct videobuf_vm_ops = 426static const struct vm_operations_struct videobuf_vm_ops = {
399{ 427 .open = videobuf_vm_open,
400 .open = videobuf_vm_open, 428 .close = videobuf_vm_close,
401 .close = videobuf_vm_close, 429 .fault = videobuf_vm_fault,
402 .fault = videobuf_vm_fault,
403}; 430};
404 431
405/* --------------------------------------------------------------------- 432/* ---------------------------------------------------------------------
@@ -417,23 +444,23 @@ static void *__videobuf_alloc(size_t size)
417 struct videobuf_dma_sg_memory *mem; 444 struct videobuf_dma_sg_memory *mem;
418 struct videobuf_buffer *vb; 445 struct videobuf_buffer *vb;
419 446
420 vb = kzalloc(size+sizeof(*mem),GFP_KERNEL); 447 vb = kzalloc(size + sizeof(*mem), GFP_KERNEL);
421 if (!vb) 448 if (!vb)
422 return vb; 449 return vb;
423 450
424 mem = vb->priv = ((char *)vb)+size; 451 mem = vb->priv = ((char *)vb) + size;
425 mem->magic=MAGIC_SG_MEM; 452 mem->magic = MAGIC_SG_MEM;
426 453
427 videobuf_dma_init(&mem->dma); 454 videobuf_dma_init(&mem->dma);
428 455
429 dprintk(1,"%s: allocated at %p(%ld+%ld) & %p(%ld)\n", 456 dprintk(1, "%s: allocated at %p(%ld+%ld) & %p(%ld)\n",
430 __func__,vb,(long)sizeof(*vb),(long)size-sizeof(*vb), 457 __func__, vb, (long)sizeof(*vb), (long)size - sizeof(*vb),
431 mem,(long)sizeof(*mem)); 458 mem, (long)sizeof(*mem));
432 459
433 return vb; 460 return vb;
434} 461}
435 462
436static void *__videobuf_to_vmalloc (struct videobuf_buffer *buf) 463static void *__videobuf_to_vmalloc(struct videobuf_buffer *buf)
437{ 464{
438 struct videobuf_dma_sg_memory *mem = buf->priv; 465 struct videobuf_dma_sg_memory *mem = buf->priv;
439 BUG_ON(!mem); 466 BUG_ON(!mem);
@@ -443,11 +470,11 @@ static void *__videobuf_to_vmalloc (struct videobuf_buffer *buf)
443 return mem->dma.vmalloc; 470 return mem->dma.vmalloc;
444} 471}
445 472
446static int __videobuf_iolock (struct videobuf_queue* q, 473static int __videobuf_iolock(struct videobuf_queue *q,
447 struct videobuf_buffer *vb, 474 struct videobuf_buffer *vb,
448 struct v4l2_framebuffer *fbuf) 475 struct v4l2_framebuffer *fbuf)
449{ 476{
450 int err,pages; 477 int err, pages;
451 dma_addr_t bus; 478 dma_addr_t bus;
452 struct videobuf_dma_sg_memory *mem = vb->priv; 479 struct videobuf_dma_sg_memory *mem = vb->priv;
453 BUG_ON(!mem); 480 BUG_ON(!mem);
@@ -460,16 +487,16 @@ static int __videobuf_iolock (struct videobuf_queue* q,
460 if (0 == vb->baddr) { 487 if (0 == vb->baddr) {
461 /* no userspace addr -- kernel bounce buffer */ 488 /* no userspace addr -- kernel bounce buffer */
462 pages = PAGE_ALIGN(vb->size) >> PAGE_SHIFT; 489 pages = PAGE_ALIGN(vb->size) >> PAGE_SHIFT;
463 err = videobuf_dma_init_kernel( &mem->dma, 490 err = videobuf_dma_init_kernel(&mem->dma,
464 DMA_FROM_DEVICE, 491 DMA_FROM_DEVICE,
465 pages ); 492 pages);
466 if (0 != err) 493 if (0 != err)
467 return err; 494 return err;
468 } else if (vb->memory == V4L2_MEMORY_USERPTR) { 495 } else if (vb->memory == V4L2_MEMORY_USERPTR) {
469 /* dma directly to userspace */ 496 /* dma directly to userspace */
470 err = videobuf_dma_init_user( &mem->dma, 497 err = videobuf_dma_init_user(&mem->dma,
471 DMA_FROM_DEVICE, 498 DMA_FROM_DEVICE,
472 vb->baddr,vb->bsize ); 499 vb->baddr, vb->bsize);
473 if (0 != err) 500 if (0 != err)
474 return err; 501 return err;
475 } else { 502 } else {
@@ -516,9 +543,9 @@ static int __videobuf_sync(struct videobuf_queue *q,
516{ 543{
517 struct videobuf_dma_sg_memory *mem = buf->priv; 544 struct videobuf_dma_sg_memory *mem = buf->priv;
518 BUG_ON(!mem); 545 BUG_ON(!mem);
519 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM); 546 MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
520 547
521 return videobuf_dma_sync(q,&mem->dma); 548 return videobuf_dma_sync(q, &mem->dma);
522} 549}
523 550
524static int __videobuf_mmap_free(struct videobuf_queue *q) 551static int __videobuf_mmap_free(struct videobuf_queue *q)
@@ -540,16 +567,16 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
540{ 567{
541 struct videobuf_dma_sg_memory *mem; 568 struct videobuf_dma_sg_memory *mem;
542 struct videobuf_mapping *map; 569 struct videobuf_mapping *map;
543 unsigned int first,last,size,i; 570 unsigned int first, last, size, i;
544 int retval; 571 int retval;
545 572
546 retval = -EINVAL; 573 retval = -EINVAL;
547 if (!(vma->vm_flags & VM_WRITE)) { 574 if (!(vma->vm_flags & VM_WRITE)) {
548 dprintk(1,"mmap app bug: PROT_WRITE please\n"); 575 dprintk(1, "mmap app bug: PROT_WRITE please\n");
549 goto done; 576 goto done;
550 } 577 }
551 if (!(vma->vm_flags & VM_SHARED)) { 578 if (!(vma->vm_flags & VM_SHARED)) {
552 dprintk(1,"mmap app bug: MAP_SHARED please\n"); 579 dprintk(1, "mmap app bug: MAP_SHARED please\n");
553 goto done; 580 goto done;
554 } 581 }
555 582
@@ -565,9 +592,9 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
565 for (first = 0; first < VIDEO_MAX_FRAME; first++) { 592 for (first = 0; first < VIDEO_MAX_FRAME; first++) {
566 if (NULL == q->bufs[first]) 593 if (NULL == q->bufs[first])
567 continue; 594 continue;
568 mem=q->bufs[first]->priv; 595 mem = q->bufs[first]->priv;
569 BUG_ON(!mem); 596 BUG_ON(!mem);
570 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM); 597 MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
571 598
572 if (V4L2_MEMORY_MMAP != q->bufs[first]->memory) 599 if (V4L2_MEMORY_MMAP != q->bufs[first]->memory)
573 continue; 600 continue;
@@ -575,7 +602,7 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
575 break; 602 break;
576 } 603 }
577 if (VIDEO_MAX_FRAME == first) { 604 if (VIDEO_MAX_FRAME == first) {
578 dprintk(1,"mmap app bug: offset invalid [offset=0x%lx]\n", 605 dprintk(1, "mmap app bug: offset invalid [offset=0x%lx]\n",
579 (vma->vm_pgoff << PAGE_SHIFT)); 606 (vma->vm_pgoff << PAGE_SHIFT));
580 goto done; 607 goto done;
581 } 608 }
@@ -595,14 +622,14 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
595 break; 622 break;
596 } 623 }
597 if (VIDEO_MAX_FRAME == last) { 624 if (VIDEO_MAX_FRAME == last) {
598 dprintk(1,"mmap app bug: size invalid [size=0x%lx]\n", 625 dprintk(1, "mmap app bug: size invalid [size=0x%lx]\n",
599 (vma->vm_end - vma->vm_start)); 626 (vma->vm_end - vma->vm_start));
600 goto done; 627 goto done;
601 } 628 }
602 629
603 /* create mapping + update buffer list */ 630 /* create mapping + update buffer list */
604 retval = -ENOMEM; 631 retval = -ENOMEM;
605 map = kmalloc(sizeof(struct videobuf_mapping),GFP_KERNEL); 632 map = kmalloc(sizeof(struct videobuf_mapping), GFP_KERNEL);
606 if (NULL == map) 633 if (NULL == map)
607 goto done; 634 goto done;
608 635
@@ -623,21 +650,21 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
623 vma->vm_flags |= VM_DONTEXPAND | VM_RESERVED; 650 vma->vm_flags |= VM_DONTEXPAND | VM_RESERVED;
624 vma->vm_flags &= ~VM_IO; /* using shared anonymous pages */ 651 vma->vm_flags &= ~VM_IO; /* using shared anonymous pages */
625 vma->vm_private_data = map; 652 vma->vm_private_data = map;
626 dprintk(1,"mmap %p: q=%p %08lx-%08lx pgoff %08lx bufs %d-%d\n", 653 dprintk(1, "mmap %p: q=%p %08lx-%08lx pgoff %08lx bufs %d-%d\n",
627 map,q,vma->vm_start,vma->vm_end,vma->vm_pgoff,first,last); 654 map, q, vma->vm_start, vma->vm_end, vma->vm_pgoff, first, last);
628 retval = 0; 655 retval = 0;
629 656
630 done: 657done:
631 return retval; 658 return retval;
632} 659}
633 660
634static int __videobuf_copy_to_user ( struct videobuf_queue *q, 661static int __videobuf_copy_to_user(struct videobuf_queue *q,
635 char __user *data, size_t count, 662 char __user *data, size_t count,
636 int nonblocking ) 663 int nonblocking)
637{ 664{
638 struct videobuf_dma_sg_memory *mem = q->read_buf->priv; 665 struct videobuf_dma_sg_memory *mem = q->read_buf->priv;
639 BUG_ON(!mem); 666 BUG_ON(!mem);
640 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM); 667 MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
641 668
642 /* copy to userspace */ 669 /* copy to userspace */
643 if (count > q->read_buf->size - q->read_off) 670 if (count > q->read_buf->size - q->read_off)
@@ -649,30 +676,30 @@ static int __videobuf_copy_to_user ( struct videobuf_queue *q,
649 return count; 676 return count;
650} 677}
651 678
652static int __videobuf_copy_stream ( struct videobuf_queue *q, 679static int __videobuf_copy_stream(struct videobuf_queue *q,
653 char __user *data, size_t count, size_t pos, 680 char __user *data, size_t count, size_t pos,
654 int vbihack, int nonblocking ) 681 int vbihack, int nonblocking)
655{ 682{
656 unsigned int *fc; 683 unsigned int *fc;
657 struct videobuf_dma_sg_memory *mem = q->read_buf->priv; 684 struct videobuf_dma_sg_memory *mem = q->read_buf->priv;
658 BUG_ON(!mem); 685 BUG_ON(!mem);
659 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM); 686 MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
660 687
661 if (vbihack) { 688 if (vbihack) {
662 /* dirty, undocumented hack -- pass the frame counter 689 /* dirty, undocumented hack -- pass the frame counter
663 * within the last four bytes of each vbi data block. 690 * within the last four bytes of each vbi data block.
664 * We need that one to maintain backward compatibility 691 * We need that one to maintain backward compatibility
665 * to all vbi decoding software out there ... */ 692 * to all vbi decoding software out there ... */
666 fc = (unsigned int*)mem->dma.vmalloc; 693 fc = (unsigned int *)mem->dma.vmalloc;
667 fc += (q->read_buf->size>>2) -1; 694 fc += (q->read_buf->size >> 2) - 1;
668 *fc = q->read_buf->field_count >> 1; 695 *fc = q->read_buf->field_count >> 1;
669 dprintk(1,"vbihack: %d\n",*fc); 696 dprintk(1, "vbihack: %d\n", *fc);
670 } 697 }
671 698
672 /* copy stuff using the common method */ 699 /* copy stuff using the common method */
673 count = __videobuf_copy_to_user (q,data,count,nonblocking); 700 count = __videobuf_copy_to_user(q, data, count, nonblocking);
674 701
675 if ( (count==-EFAULT) && (0 == pos) ) 702 if ((count == -EFAULT) && (0 == pos))
676 return -EFAULT; 703 return -EFAULT;
677 704
678 return count; 705 return count;
@@ -702,8 +729,9 @@ void *videobuf_sg_alloc(size_t size)
702 729
703 return videobuf_alloc(&q); 730 return videobuf_alloc(&q);
704} 731}
732EXPORT_SYMBOL_GPL(videobuf_sg_alloc);
705 733
706void videobuf_queue_sg_init(struct videobuf_queue* q, 734void videobuf_queue_sg_init(struct videobuf_queue *q,
707 const struct videobuf_queue_ops *ops, 735 const struct videobuf_queue_ops *ops,
708 struct device *dev, 736 struct device *dev,
709 spinlock_t *irqlock, 737 spinlock_t *irqlock,
@@ -715,29 +743,5 @@ void videobuf_queue_sg_init(struct videobuf_queue* q,
715 videobuf_queue_core_init(q, ops, dev, irqlock, type, field, msize, 743 videobuf_queue_core_init(q, ops, dev, irqlock, type, field, msize,
716 priv, &sg_ops); 744 priv, &sg_ops);
717} 745}
718
719/* --------------------------------------------------------------------- */
720
721EXPORT_SYMBOL_GPL(videobuf_vmalloc_to_sg);
722
723EXPORT_SYMBOL_GPL(videobuf_to_dma);
724EXPORT_SYMBOL_GPL(videobuf_dma_init);
725EXPORT_SYMBOL_GPL(videobuf_dma_init_user);
726EXPORT_SYMBOL_GPL(videobuf_dma_init_kernel);
727EXPORT_SYMBOL_GPL(videobuf_dma_init_overlay);
728EXPORT_SYMBOL_GPL(videobuf_dma_map);
729EXPORT_SYMBOL_GPL(videobuf_dma_sync);
730EXPORT_SYMBOL_GPL(videobuf_dma_unmap);
731EXPORT_SYMBOL_GPL(videobuf_dma_free);
732
733EXPORT_SYMBOL_GPL(videobuf_sg_dma_map);
734EXPORT_SYMBOL_GPL(videobuf_sg_dma_unmap);
735EXPORT_SYMBOL_GPL(videobuf_sg_alloc);
736
737EXPORT_SYMBOL_GPL(videobuf_queue_sg_init); 746EXPORT_SYMBOL_GPL(videobuf_queue_sg_init);
738 747
739/*
740 * Local variables:
741 * c-basic-offset: 8
742 * End:
743 */