Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]

Diff markup

Differences between /linux/drivers/media/video/videocodec.c (Version 2.6.25.8) and /linux/drivers/media/video/videocodec.c (Version 2.6.31.13)


  1 /*                                                  1 
  2  * VIDEO MOTION CODECs internal API for video     
  3  *                                                
  4  * Interface for MJPEG (and maybe later MPEG/W    
  5  * bound to a master device.                      
  6  *                                                
  7  * (c) 2002 Wolfgang Scherr <scherr@net4you.at    
  8  *                                                
  9  * $Id: videocodec.c,v 1.1.2.8 2003/03/29 07:1    
 10  *                                                
 11  * -------------------------------------------    
 12  *                                                
 13  * This program is free software; you can redi    
 14  * it under the terms of the GNU General Publi    
 15  * the Free Software Foundation; either versio    
 16  * (at your option) any later version.            
 17  *                                                
 18  * This program is distributed in the hope tha    
 19  * but WITHOUT ANY WARRANTY; without even the     
 20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR    
 21  * GNU General Public License for more details    
 22  *                                                
 23  * You should have received a copy of the GNU     
 24  * along with this program; if not, write to t    
 25  * Foundation, Inc., 675 Mass Ave, Cambridge,     
 26  *                                                
 27  * -------------------------------------------    
 28  */                                               
 29                                                   
 30 #define VIDEOCODEC_VERSION "v0.2"                 
 31                                                   
 32 #include <linux/kernel.h>                         
 33 #include <linux/module.h>                         
 34 #include <linux/init.h>                           
 35 #include <linux/types.h>                          
 36 #include <linux/slab.h>                           
 37                                                   
 38 // kernel config is here (procfs flag)            
 39                                                   
 40 #ifdef CONFIG_PROC_FS                             
 41 #include <linux/proc_fs.h>                        
 42 #include <asm/uaccess.h>                          
 43 #endif                                            
 44                                                   
 45 #include "videocodec.h"                           
 46                                                   
 47 static int debug = 0;                             
 48 module_param(debug, int, 0);                      
 49 MODULE_PARM_DESC(debug, "Debug level (0-4)");     
 50                                                   
 51 #define dprintk(num, format, args...) \           
 52         do { \                                    
 53                 if (debug >= num) \               
 54                         printk(format, ##args)    
 55         } while (0)                               
 56                                                   
 57 struct attached_list {                            
 58         struct videocodec *codec;                 
 59         struct attached_list *next;               
 60 };                                                
 61                                                   
 62 struct codec_list {                               
 63         const struct videocodec *codec;           
 64         int attached;                             
 65         struct attached_list *list;               
 66         struct codec_list *next;                  
 67 };                                                
 68                                                   
 69 static struct codec_list *codeclist_top = NULL    
 70                                                   
 71 /* ===========================================    
 72 /* function prototypes of the master/slave int    
 73 /* ===========================================    
 74                                                   
 75 struct videocodec *                               
 76 videocodec_attach (struct videocodec_master *m    
 77 {                                                 
 78         struct codec_list *h = codeclist_top;     
 79         struct attached_list *a, *ptr;            
 80         struct videocodec *codec;                 
 81         int res;                                  
 82                                                   
 83         if (!master) {                            
 84                 dprintk(1, KERN_ERR "videocode    
 85                 return NULL;                      
 86         }                                         
 87                                                   
 88         dprintk(2,                                
 89                 "videocodec_attach: '%s', flag    
 90                 master->name, master->flags, m    
 91                                                   
 92         if (!h) {                                 
 93                 dprintk(1,                        
 94                         KERN_ERR                  
 95                         "videocodec_attach: no    
 96                 return NULL;                      
 97         }                                         
 98                                                   
 99         while (h) {                               
100                 // attach only if the slave ha    
101                 // expected by the master         
102                 if ((master->flags & h->codec-    
103                         dprintk(4, "videocodec    
104                                 h->codec->name    
105                                                   
106                         if (!try_module_get(h-    
107                                 return NULL;      
108                                                   
109                         codec =                   
110                             kmalloc(sizeof(str    
111                         if (!codec) {             
112                                 dprintk(1,        
113                                         KERN_E    
114                                         "video    
115                                 goto out_modul    
116                         }                         
117                         memcpy(codec, h->codec    
118                                                   
119                         snprintf(codec->name,     
120                                  "%s[%d]", cod    
121                         codec->master_data = m    
122                         res = codec->setup(cod    
123                         if (res == 0) {           
124                                 dprintk(3, "vi    
125                                         codec-    
126                                 ptr = kzalloc(    
127                                 if (!ptr) {       
128                                         dprint    
129                                                   
130                                                   
131                                         goto o    
132                                 }                 
133                                 ptr->codec = c    
134                                                   
135                                 a = h->list;      
136                                 if (!a) {         
137                                         h->lis    
138                                         dprint    
139                                                   
140                                 } else {          
141                                         while     
142                                                   
143                                         a->nex    
144                                         dprint    
145                                                   
146                                                   
147                                 }                 
148                                                   
149                                 h->attached +=    
150                                 return codec;     
151                         } else {                  
152                                 kfree(codec);     
153                         }                         
154                 }                                 
155                 h = h->next;                      
156         }                                         
157                                                   
158         dprintk(1, KERN_ERR "videocodec_attach    
159         return NULL;                              
160                                                   
161  out_module_put:                                  
162         module_put(h->codec->owner);              
163  out_kfree:                                       
164         kfree(codec);                             
165         return NULL;                              
166 }                                                 
167                                                   
168 int                                               
169 videocodec_detach (struct videocodec *codec)      
170 {                                                 
171         struct codec_list *h = codeclist_top;     
172         struct attached_list *a, *prev;           
173         int res;                                  
174                                                   
175         if (!codec) {                             
176                 dprintk(1, KERN_ERR "videocode    
177                 return -EINVAL;                   
178         }                                         
179                                                   
180         dprintk(2,                                
181                 "videocodec_detach: '%s', type    
182                 codec->name, codec->type, code    
183                                                   
184         if (!h) {                                 
185                 dprintk(1,                        
186                         KERN_ERR "videocodec_d    
187                 return -ENXIO;                    
188         }                                         
189                                                   
190         while (h) {                               
191                 a = h->list;                      
192                 prev = NULL;                      
193                 while (a) {                       
194                         if (codec == a->codec)    
195                                 res = a->codec    
196                                 if (res >= 0)     
197                                         dprint    
198                                                   
199                                                   
200                                         a->cod    
201                                 } else {          
202                                         dprint    
203                                                   
204                                                   
205                                                   
206                                         a->cod    
207                                 }                 
208                                 if (prev == NU    
209                                         h->lis    
210                                         dprint    
211                                                   
212                                 } else {          
213                                         prev->    
214                                         dprint    
215                                                   
216                                 }                 
217                                 module_put(a->    
218                                 kfree(a->codec    
219                                 kfree(a);         
220                                 h->attached -=    
221                                 return 0;         
222                         }                         
223                         prev = a;                 
224                         a = a->next;              
225                 }                                 
226                 h = h->next;                      
227         }                                         
228                                                   
229         dprintk(1, KERN_ERR "videocodec_detach    
230         return -EINVAL;                           
231 }                                                 
232                                                   
233 int                                               
234 videocodec_register (const struct videocodec *    
235 {                                                 
236         struct codec_list *ptr, *h = codeclist    
237                                                   
238         if (!codec) {                             
239                 dprintk(1, KERN_ERR "videocode    
240                 return -EINVAL;                   
241         }                                         
242                                                   
243         dprintk(2,                                
244                 "videocodec: register '%s', ty    
245                 codec->name, codec->type, code    
246                                                   
247         ptr = kzalloc(sizeof(struct codec_list    
248         if (!ptr) {                               
249                 dprintk(1, KERN_ERR "videocode    
250                 return -ENOMEM;                   
251         }                                         
252         ptr->codec = codec;                       
253                                                   
254         if (!h) {                                 
255                 codeclist_top = ptr;              
256                 dprintk(4, "videocodec: hooked    
257         } else {                                  
258                 while (h->next)                   
259                         h = h->next;    // fin    
260                 h->next = ptr;                    
261                 dprintk(4, "videocodec: hooked    
262                         h->codec->name);          
263         }                                         
264                                                   
265         return 0;                                 
266 }                                                 
267                                                   
268 int                                               
269 videocodec_unregister (const struct videocodec    
270 {                                                 
271         struct codec_list *prev = NULL, *h = c    
272                                                   
273         if (!codec) {                             
274                 dprintk(1, KERN_ERR "videocode    
275                 return -EINVAL;                   
276         }                                         
277                                                   
278         dprintk(2,                                
279                 "videocodec: unregister '%s',     
280                 codec->name, codec->type, code    
281                                                   
282         if (!h) {                                 
283                 dprintk(1,                        
284                         KERN_ERR                  
285                         "videocodec_unregister    
286                 return -ENXIO;                    
287         }                                         
288                                                   
289         while (h) {                               
290                 if (codec == h->codec) {          
291                         if (h->attached) {        
292                                 dprintk(1,        
293                                         KERN_E    
294                                         "video    
295                                         h->cod    
296                                 return -EBUSY;    
297                         }                         
298                         dprintk(3, "videocodec    
299                                 h->codec->name    
300                         if (prev == NULL) {       
301                                 codeclist_top     
302                                 dprintk(4,        
303                                         "video    
304                         } else {                  
305                                 prev->next = h    
306                                 dprintk(4,        
307                                         "video    
308                         }                         
309                         kfree(h);                 
310                         return 0;                 
311                 }                                 
312                 prev = h;                         
313                 h = h->next;                      
314         }                                         
315                                                   
316         dprintk(1,                                
317                 KERN_ERR                          
318                 "videocodec_unregister: given     
319         return -EINVAL;                           
320 }                                                 
321                                                   
322 #ifdef CONFIG_PROC_FS                             
323 /* ============ */                                
324 /* procfs stuff */                                
325 /* ============ */                                
326                                                   
327 static char *videocodec_buf = NULL;               
328 static int videocodec_bufsize = 0;                
329                                                   
330 static int                                        
331 videocodec_build_table (void)                     
332 {                                                 
333         struct codec_list *h = codeclist_top;     
334         struct attached_list *a;                  
335         int i = 0, size;                          
336                                                   
337         // sum up amount of slaves plus their     
338         while (h) {                               
339                 i += h->attached + 1;             
340                 h = h->next;                      
341         }                                         
342 #define LINESIZE 100                              
343         size = LINESIZE * (i + 1);                
344                                                   
345         dprintk(3, "videocodec_build table: %d    
346                 size);                            
347                                                   
348         kfree(videocodec_buf);                    
349         videocodec_buf = kmalloc(size, GFP_KER    
350                                                   
351         if (!videocodec_buf)                      
352                 return 0;                         
353                                                   
354         i = 0;                                    
355         i += scnprintf(videocodec_buf + i, siz    
356                       "<S>lave or attached <M>    
357         i += scnprintf(videocodec_buf + i, siz    
358                                                   
359         h = codeclist_top;                        
360         while (h) {                               
361                 if (i > (size - LINESIZE))        
362                         break;  // security ch    
363                 i += scnprintf(videocodec_buf     
364                               "S %32s %04x %08    
365                               h->codec->name,     
366                               h->codec->flags,    
367                 a = h->list;                      
368                 while (a) {                       
369                         if (i > (size - LINESI    
370                                 break;  // sec    
371                         i += scnprintf(videoco    
372                                       "M %32s     
373                                       a->codec    
374                                       a->codec    
375                                       a->codec    
376                                       a->codec    
377                                       a->codec    
378                         a = a->next;              
379                 }                                 
380                 h = h->next;                      
381         }                                         
382                                                   
383         return i;                                 
384 }                                                 
385                                                   
386 //The definition:                                 
387 //typedef int (read_proc_t)(char *page, char *    
388 //                          int count, int *eo    
389                                                   
390 static int                                        
391 videocodec_info (char  *buffer,                   
392                  char **buffer_location,          
393                  off_t  offset,                   
394                  int    buffer_length,            
395                  int   *eof,                      
396                  void  *data)                     
397 {                                                 
398         int size;                                 
399                                                   
400         dprintk(3, "videocodec_info: offset: %    
401                 offset, buffer_length, videoco    
402                                                   
403         if (offset == 0) {                        
404                 videocodec_bufsize = videocode    
405         }                                         
406         if ((offset < 0) || (offset >= videoco    
407                 dprintk(4,                        
408                         "videocodec_info: call    
409                 *eof = 1;                         
410                 return 0;                         
411         }                                         
412                                                   
413         if (buffer_length < (videocodec_bufsiz    
414                 dprintk(4, "videocodec_info: %    
415                         videocodec_bufsize - o    
416                 size = buffer_length;             
417         } else {                                  
418                 dprintk(4, "videocodec_info: l    
419                         videocodec_bufsize - o    
420                 size = videocodec_bufsize - of    
421                 *eof = 1;                         
422         }                                         
423                                                   
424         memcpy(buffer, videocodec_buf + offset    
425         /* doesn't work...                        
426         /* copy_to_user(buffer, videocodec_buf    
427         /* *buffer_location = videocodec_buf+o    
428                                                   
429         return size;                              
430 }                                                 
431 #endif                                            
432                                                   
433 /* ===================== */                       
434 /* hook in driver module */                       
435 /* ===================== */                       
436 static int __init                                 
437 videocodec_init (void)                            
438 {                                                 
439 #ifdef CONFIG_PROC_FS                             
440         static struct proc_dir_entry *videocod    
441 #endif                                            
442                                                   
443         printk(KERN_INFO "Linux video codec in    
444                VIDEOCODEC_VERSION);               
445                                                   
446 #ifdef CONFIG_PROC_FS                             
447         videocodec_buf = NULL;                    
448         videocodec_bufsize = 0;                   
449                                                   
450         videocodec_proc_entry = create_proc_en    
451         if (videocodec_proc_entry) {              
452                 videocodec_proc_entry->read_pr    
453                 videocodec_proc_entry->write_p    
454                 videocodec_proc_entry->data =     
455                 videocodec_proc_entry->owner =    
456         } else {                                  
457                 dprintk(1, KERN_ERR "videocode    
458         }                                         
459 #endif                                            
460         return 0;                                 
461 }                                                 
462                                                   
463 static void __exit                                
464 videocodec_exit (void)                            
465 {                                                 
466 #ifdef CONFIG_PROC_FS                             
467         remove_proc_entry("videocodecs", NULL)    
468         kfree(videocodec_buf);                    
469 #endif                                            
470 }                                                 
471                                                   
472 EXPORT_SYMBOL(videocodec_attach);                 
473 EXPORT_SYMBOL(videocodec_detach);                 
474 EXPORT_SYMBOL(videocodec_register);               
475 EXPORT_SYMBOL(videocodec_unregister);             
476                                                   
477 module_init(videocodec_init);                     
478 module_exit(videocodec_exit);                     
479                                                   
480 MODULE_AUTHOR("Wolfgang Scherr <scherr@net4you    
481 MODULE_DESCRIPTION("Intermediate API module fo    
482                    VIDEOCODEC_VERSION);           
483 MODULE_LICENSE("GPL");                            
484                                                   
  This page was automatically generated by the LXR engine.