This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / drivers / char / mem.c
1 /*
2  *  linux/drivers/char/mem.c
3  *
4  *  Copyright (C) 1991, 1992  Linus Torvalds
5  *
6  *  Added devfs support. 
7  *    Jan-11-1998, C. Scott Ananian <cananian@alumni.princeton.edu>
8  *  Shared /dev/zero mmaping support, Feb 2000, Kanoj Sarcar <kanoj@sgi.com>
9  */
10
11 #include <linux/config.h>
12 #include <linux/mm.h>
13 #include <linux/miscdevice.h>
14 #include <linux/slab.h>
15 #include <linux/vmalloc.h>
16 #include <linux/mman.h>
17 #include <linux/random.h>
18 #include <linux/init.h>
19 #include <linux/raw.h>
20 #include <linux/tty.h>
21 #include <linux/capability.h>
22 #include <linux/smp_lock.h>
23 #include <linux/devfs_fs_kernel.h>
24 #include <linux/ptrace.h>
25 #include <linux/device.h>
26
27 #include <asm/uaccess.h>
28 #include <asm/io.h>
29
30 #ifdef CONFIG_IA64
31 # include <linux/efi.h>
32 #endif
33
34 #ifdef CONFIG_FB
35 extern void fbmem_init(void);
36 #endif
37 #if defined(CONFIG_S390_TAPE) && defined(CONFIG_S390_TAPE_CHAR)
38 extern void tapechar_init(void);
39 #endif
40
41 /*
42  * Architectures vary in how they handle caching for addresses
43  * outside of main memory.
44  *
45  */
46 static inline int uncached_access(struct file *file, unsigned long addr)
47 {
48 #if defined(__i386__)
49         /*
50          * On the PPro and successors, the MTRRs are used to set
51          * memory types for physical addresses outside main memory,
52          * so blindly setting PCD or PWT on those pages is wrong.
53          * For Pentiums and earlier, the surround logic should disable
54          * caching for the high addresses through the KEN pin, but
55          * we maintain the tradition of paranoia in this code.
56          */
57         if (file->f_flags & O_SYNC)
58                 return 1;
59         return !( test_bit(X86_FEATURE_MTRR, boot_cpu_data.x86_capability) ||
60                   test_bit(X86_FEATURE_K6_MTRR, boot_cpu_data.x86_capability) ||
61                   test_bit(X86_FEATURE_CYRIX_ARR, boot_cpu_data.x86_capability) ||
62                   test_bit(X86_FEATURE_CENTAUR_MCR, boot_cpu_data.x86_capability) )
63           && addr >= __pa(high_memory);
64 #elif defined(__x86_64__)
65         /* 
66          * This is broken because it can generate memory type aliases,
67          * which can cause cache corruptions
68          * But it is only available for root and we have to be bug-to-bug
69          * compatible with i386.
70          */
71         if (file->f_flags & O_SYNC)
72                 return 1;
73         /* same behaviour as i386. PAT always set to cached and MTRRs control the
74            caching behaviour. 
75            Hopefully a full PAT implementation will fix that soon. */      
76         return 0;
77 #elif defined(CONFIG_IA64)
78         /*
79          * On ia64, we ignore O_SYNC because we cannot tolerate memory attribute aliases.
80          */
81         return !(efi_mem_attributes(addr) & EFI_MEMORY_WB);
82 #elif defined(CONFIG_PPC64)
83         /* On PPC64, we always do non-cacheable access to the IO hole and
84          * cacheable elsewhere. Cache paradox can checkstop the CPU and
85          * the high_memory heuristic below is wrong on machines with memory
86          * above the IO hole... Ah, and of course, XFree86 doesn't pass
87          * O_SYNC when mapping us to tap IO space. Surprised ?
88          */
89         return !page_is_ram(addr);
90 #else
91         /*
92          * Accessing memory above the top the kernel knows about or through a file pointer
93          * that was marked O_SYNC will be done non-cached.
94          */
95         if (file->f_flags & O_SYNC)
96                 return 1;
97         return addr >= __pa(high_memory);
98 #endif
99 }
100
101 #ifndef ARCH_HAS_VALID_PHYS_ADDR_RANGE
102 static inline int valid_phys_addr_range(unsigned long addr, size_t *count)
103 {
104         unsigned long end_mem;
105
106         end_mem = __pa(high_memory);
107         if (addr >= end_mem)
108                 return 0;
109
110         if (*count > end_mem - addr)
111                 *count = end_mem - addr;
112
113         return 1;
114 }
115 #endif
116
117 extern int page_is_ram(unsigned long pagenr);
118
119 static inline int page_is_allowed(unsigned long pagenr)
120
121  #ifdef CONFIG_X86
122         if (pagenr <= 256)
123                 return 1;
124         if (!page_is_ram(pagenr))
125                 return 1;
126         printk("Access to 0x%lx by %s denied \n", pagenr << PAGE_SHIFT, current->comm);
127         return 0;
128  #else
129        return 1;
130  #endif
131 }
132
133 static inline int range_is_allowed(unsigned long from, unsigned long to)
134 {
135         unsigned long cursor;
136         
137         cursor = from >> PAGE_SHIFT;
138         while ( (cursor << PAGE_SHIFT) < to) {
139                 if (!page_is_allowed(cursor))
140                         return 0;
141                 cursor++;
142         }
143         return 1;
144 }
145 static ssize_t do_write_mem(void *p, unsigned long realp,
146                             const char __user * buf, size_t count, loff_t *ppos)
147 {
148         ssize_t written;
149         unsigned long copied;
150
151         written = 0;
152 #if defined(__sparc__) || (defined(__mc68000__) && defined(CONFIG_MMU))
153         /* we don't have page 0 mapped on sparc and m68k.. */
154         if (realp < PAGE_SIZE) {
155                 unsigned long sz = PAGE_SIZE-realp;
156                 if (sz > count) sz = count; 
157                 /* Hmm. Do something? */
158                 buf+=sz;
159                 p+=sz;
160                 count-=sz;
161                 written+=sz;
162         }
163 #endif
164         if (!range_is_allowed(realp, realp+count))
165                 return -EFAULT;
166         copied = copy_from_user(p, buf, count);
167         if (copied) {
168                 ssize_t ret = written + (count - copied);
169
170                 if (ret)
171                         return ret;
172                 return -EFAULT;
173         }
174         written += count;
175         *ppos += written;
176         return written;
177 }
178
179
180 /*
181  * This funcion reads the *physical* memory. The f_pos points directly to the 
182  * memory location. 
183  */
184 static ssize_t read_mem(struct file * file, char __user * buf,
185                         size_t count, loff_t *ppos)
186 {
187         unsigned long p = *ppos;
188         ssize_t read;
189
190         if (!valid_phys_addr_range(p, &count))
191                 return -EFAULT;
192         read = 0;
193 #if defined(__sparc__) || (defined(__mc68000__) && defined(CONFIG_MMU))
194         /* we don't have page 0 mapped on sparc and m68k.. */
195         if (p < PAGE_SIZE) {
196                 unsigned long sz = PAGE_SIZE-p;
197                 if (sz > count) 
198                         sz = count; 
199                 if (sz > 0) {
200                         if (clear_user(buf, sz))
201                                 return -EFAULT;
202                         buf += sz; 
203                         p += sz; 
204                         count -= sz; 
205                         read += sz; 
206                 }
207         }
208 #endif
209         if (!range_is_allowed(p, p+count))
210                 return -EFAULT;
211         if (copy_to_user(buf, __va(p), count))
212                 return -EFAULT;
213         read += count;
214         *ppos += read;
215         return read;
216 }
217
218 static ssize_t write_mem(struct file * file, const char __user * buf, 
219                          size_t count, loff_t *ppos)
220 {
221         unsigned long p = *ppos;
222
223         if (!valid_phys_addr_range(p, &count))
224                 return -EFAULT;
225         return do_write_mem(__va(p), p, buf, count, ppos);
226 }
227
228 static int mmap_mem(struct file * file, struct vm_area_struct * vma)
229 {
230         unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
231         int uncached;
232         unsigned long cursor;
233
234         uncached = uncached_access(file, offset);
235 #ifdef pgprot_noncached
236         if (uncached)
237                 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
238 #endif
239
240         /* Don't try to swap out physical pages.. */
241         vma->vm_flags |= VM_RESERVED;
242
243         /*
244          * Don't dump addresses that are not real memory to a core file.
245          */
246         if (uncached)
247                 vma->vm_flags |= VM_IO;
248                 
249         cursor = vma->vm_pgoff;
250         while ((cursor << PAGE_SHIFT) < offset + vma->vm_end-vma->vm_start) {
251                 if (!page_is_allowed(cursor))
252                         return -EFAULT;
253                 cursor++;
254         }
255
256         if (remap_page_range(vma, vma->vm_start, offset, vma->vm_end-vma->vm_start,
257                              vma->vm_page_prot))
258                 return -EAGAIN;
259         return 0;
260 }
261
262 extern long vread(char *buf, char *addr, unsigned long count);
263 extern long vwrite(char *buf, char *addr, unsigned long count);
264
265 /*
266  * This function reads the *virtual* memory as seen by the kernel.
267  */
268 static ssize_t read_kmem(struct file *file, char __user *buf, 
269                          size_t count, loff_t *ppos)
270 {
271         unsigned long p = *ppos;
272         ssize_t read = 0;
273         ssize_t virtr = 0;
274         char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
275         
276         return -EPERM;
277                 
278         if (p < (unsigned long) high_memory) {
279                 read = count;
280                 if (count > (unsigned long) high_memory - p)
281                         read = (unsigned long) high_memory - p;
282
283 #if defined(__sparc__) || (defined(__mc68000__) && defined(CONFIG_MMU))
284                 /* we don't have page 0 mapped on sparc and m68k.. */
285                 if (p < PAGE_SIZE && read > 0) {
286                         size_t tmp = PAGE_SIZE - p;
287                         if (tmp > read) tmp = read;
288                         if (clear_user(buf, tmp))
289                                 return -EFAULT;
290                         buf += tmp;
291                         p += tmp;
292                         read -= tmp;
293                         count -= tmp;
294                 }
295 #endif
296                 if (copy_to_user(buf, (char *)p, read))
297                         return -EFAULT;
298                 p += read;
299                 buf += read;
300                 count -= read;
301         }
302
303         if (count > 0) {
304                 kbuf = (char *)__get_free_page(GFP_KERNEL);
305                 if (!kbuf)
306                         return -ENOMEM;
307                 while (count > 0) {
308                         int len = count;
309
310                         if (len > PAGE_SIZE)
311                                 len = PAGE_SIZE;
312                         len = vread(kbuf, (char *)p, len);
313                         if (!len)
314                                 break;
315                         if (copy_to_user(buf, kbuf, len)) {
316                                 free_page((unsigned long)kbuf);
317                                 return -EFAULT;
318                         }
319                         count -= len;
320                         buf += len;
321                         virtr += len;
322                         p += len;
323                 }
324                 free_page((unsigned long)kbuf);
325         }
326         *ppos = p;
327         return virtr + read;
328 }
329
330 /*
331  * This function writes to the *virtual* memory as seen by the kernel.
332  */
333 static ssize_t write_kmem(struct file * file, const char __user * buf, 
334                           size_t count, loff_t *ppos)
335 {
336         unsigned long p = *ppos;
337         ssize_t wrote = 0;
338         ssize_t virtr = 0;
339         ssize_t written;
340         char * kbuf; /* k-addr because vwrite() takes vmlist_lock rwlock */
341         
342         return -EPERM;
343
344         if (p < (unsigned long) high_memory) {
345
346                 wrote = count;
347                 if (count > (unsigned long) high_memory - p)
348                         wrote = (unsigned long) high_memory - p;
349
350                 written = do_write_mem((void*)p, p, buf, wrote, ppos);
351                 if (written != wrote)
352                         return written;
353                 wrote = written;
354                 p += wrote;
355                 buf += wrote;
356                 count -= wrote;
357         }
358
359         if (count > 0) {
360                 kbuf = (char *)__get_free_page(GFP_KERNEL);
361                 if (!kbuf)
362                         return wrote ? wrote : -ENOMEM;
363                 while (count > 0) {
364                         int len = count;
365
366                         if (len > PAGE_SIZE)
367                                 len = PAGE_SIZE;
368                         if (len) {
369                                 written = copy_from_user(kbuf, buf, len);
370                                 if (written) {
371                                         ssize_t ret;
372
373                                         free_page((unsigned long)kbuf);
374                                         ret = wrote + virtr + (len - written);
375                                         return ret ? ret : -EFAULT;
376                                 }
377                         }
378                         len = vwrite(kbuf, (char *)p, len);
379                         count -= len;
380                         buf += len;
381                         virtr += len;
382                         p += len;
383                 }
384                 free_page((unsigned long)kbuf);
385         }
386
387         *ppos = p;
388         return virtr + wrote;
389 }
390
391 #if defined(CONFIG_ISA) || !defined(__mc68000__)
392 static ssize_t read_port(struct file * file, char __user * buf,
393                          size_t count, loff_t *ppos)
394 {
395         unsigned long i = *ppos;
396         char __user *tmp = buf;
397
398         if (verify_area(VERIFY_WRITE,buf,count))
399                 return -EFAULT; 
400         while (count-- > 0 && i < 65536) {
401                 if (__put_user(inb(i),tmp) < 0) 
402                         return -EFAULT;  
403                 i++;
404                 tmp++;
405         }
406         *ppos = i;
407         return tmp-buf;
408 }
409
410 static ssize_t write_port(struct file * file, const char __user * buf,
411                           size_t count, loff_t *ppos)
412 {
413         unsigned long i = *ppos;
414         const char __user * tmp = buf;
415
416         if (verify_area(VERIFY_READ,buf,count))
417                 return -EFAULT;
418         while (count-- > 0 && i < 65536) {
419                 char c;
420                 if (__get_user(c, tmp)) 
421                         return -EFAULT; 
422                 outb(c,i);
423                 i++;
424                 tmp++;
425         }
426         *ppos = i;
427         return tmp-buf;
428 }
429 #endif
430
431 static ssize_t read_null(struct file * file, char __user * buf,
432                          size_t count, loff_t *ppos)
433 {
434         return 0;
435 }
436
437 static ssize_t write_null(struct file * file, const char __user * buf,
438                           size_t count, loff_t *ppos)
439 {
440         return count;
441 }
442
443 #ifdef CONFIG_MMU
444 /*
445  * For fun, we are using the MMU for this.
446  */
447 static inline size_t read_zero_pagealigned(char __user * buf, size_t size)
448 {
449         struct mm_struct *mm;
450         struct vm_area_struct * vma;
451         unsigned long addr=(unsigned long)buf;
452
453         mm = current->mm;
454         /* Oops, this was forgotten before. -ben */
455         down_read(&mm->mmap_sem);
456
457         /* For private mappings, just map in zero pages. */
458         for (vma = find_vma(mm, addr); vma; vma = vma->vm_next) {
459                 unsigned long count;
460
461                 if (vma->vm_start > addr || (vma->vm_flags & VM_WRITE) == 0)
462                         goto out_up;
463                 if (vma->vm_flags & VM_SHARED)
464                         break;
465                 count = vma->vm_end - addr;
466                 if (count > size)
467                         count = size;
468
469                 zap_page_range(vma, addr, count, NULL);
470                 zeromap_page_range(vma, addr, count, PAGE_COPY);
471
472                 size -= count;
473                 buf += count;
474                 addr += count;
475                 if (size == 0)
476                         goto out_up;
477         }
478
479         up_read(&mm->mmap_sem);
480         
481         /* The shared case is hard. Let's do the conventional zeroing. */ 
482         do {
483                 unsigned long unwritten = clear_user(buf, PAGE_SIZE);
484                 if (unwritten)
485                         return size + unwritten - PAGE_SIZE;
486                 cond_resched();
487                 buf += PAGE_SIZE;
488                 size -= PAGE_SIZE;
489         } while (size);
490
491         return size;
492 out_up:
493         up_read(&mm->mmap_sem);
494         return size;
495 }
496
497 static ssize_t read_zero(struct file * file, char __user * buf, 
498                          size_t count, loff_t *ppos)
499 {
500         unsigned long left, unwritten, written = 0;
501
502         if (!count)
503                 return 0;
504
505         if (!access_ok(VERIFY_WRITE, buf, count))
506                 return -EFAULT;
507
508         left = count;
509
510         /* do we want to be clever? Arbitrary cut-off */
511         if (count >= PAGE_SIZE*4) {
512                 unsigned long partial;
513
514                 /* How much left of the page? */
515                 partial = (PAGE_SIZE-1) & -(unsigned long) buf;
516                 unwritten = clear_user(buf, partial);
517                 written = partial - unwritten;
518                 if (unwritten)
519                         goto out;
520                 left -= partial;
521                 buf += partial;
522                 unwritten = read_zero_pagealigned(buf, left & PAGE_MASK);
523                 written += (left & PAGE_MASK) - unwritten;
524                 if (unwritten)
525                         goto out;
526                 buf += left & PAGE_MASK;
527                 left &= ~PAGE_MASK;
528         }
529         unwritten = clear_user(buf, left);
530         written += left - unwritten;
531 out:
532         return written ? written : -EFAULT;
533 }
534
535 static int mmap_zero(struct file * file, struct vm_area_struct * vma)
536 {
537         if (vma->vm_flags & VM_SHARED)
538                 return shmem_zero_setup(vma);
539         if (zeromap_page_range(vma, vma->vm_start, vma->vm_end - vma->vm_start, vma->vm_page_prot))
540                 return -EAGAIN;
541         return 0;
542 }
543 #else /* CONFIG_MMU */
544 static ssize_t read_zero(struct file * file, char * buf, 
545                          size_t count, loff_t *ppos)
546 {
547         size_t todo = count;
548
549         while (todo) {
550                 size_t chunk = todo;
551
552                 if (chunk > 4096)
553                         chunk = 4096;   /* Just for latency reasons */
554                 if (clear_user(buf, chunk))
555                         return -EFAULT;
556                 buf += chunk;
557                 todo -= chunk;
558                 cond_resched();
559         }
560         return count;
561 }
562
563 static int mmap_zero(struct file * file, struct vm_area_struct * vma)
564 {
565         return -ENOSYS;
566 }
567 #endif /* CONFIG_MMU */
568
569 static ssize_t write_full(struct file * file, const char __user * buf,
570                           size_t count, loff_t *ppos)
571 {
572         return -ENOSPC;
573 }
574
575 /*
576  * Special lseek() function for /dev/null and /dev/zero.  Most notably, you
577  * can fopen() both devices with "a" now.  This was previously impossible.
578  * -- SRB.
579  */
580
581 static loff_t null_lseek(struct file * file, loff_t offset, int orig)
582 {
583         return file->f_pos = 0;
584 }
585
586 /*
587  * The memory devices use the full 32/64 bits of the offset, and so we cannot
588  * check against negative addresses: they are ok. The return value is weird,
589  * though, in that case (0).
590  *
591  * also note that seeking relative to the "end of file" isn't supported:
592  * it has no meaning, so it returns -EINVAL.
593  */
594 static loff_t memory_lseek(struct file * file, loff_t offset, int orig)
595 {
596         loff_t ret;
597
598         down(&file->f_dentry->d_inode->i_sem);
599         switch (orig) {
600                 case 0:
601                         file->f_pos = offset;
602                         ret = file->f_pos;
603                         force_successful_syscall_return();
604                         break;
605                 case 1:
606                         file->f_pos += offset;
607                         ret = file->f_pos;
608                         force_successful_syscall_return();
609                         break;
610                 default:
611                         ret = -EINVAL;
612         }
613         up(&file->f_dentry->d_inode->i_sem);
614         return ret;
615 }
616
617 static int open_port(struct inode * inode, struct file * filp)
618 {
619         return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
620 }
621
622 #define mmap_kmem       mmap_mem
623 #define zero_lseek      null_lseek
624 #define full_lseek      null_lseek
625 #define write_zero      write_null
626 #define read_full       read_zero
627 #define open_mem        open_port
628 #define open_kmem       open_mem
629
630 static struct file_operations mem_fops = {
631         .llseek         = memory_lseek,
632         .read           = read_mem,
633         .write          = write_mem,
634         .mmap           = mmap_mem,
635         .open           = open_mem,
636 };
637
638 static struct file_operations kmem_fops = {
639         .llseek         = memory_lseek,
640         .read           = read_kmem,
641         .write          = write_kmem,
642         .mmap           = mmap_kmem,
643         .open           = open_kmem,
644 };
645
646 static struct file_operations null_fops = {
647         .llseek         = null_lseek,
648         .read           = read_null,
649         .write          = write_null,
650 };
651
652 #if defined(CONFIG_ISA) || !defined(__mc68000__)
653 static struct file_operations port_fops = {
654         .llseek         = memory_lseek,
655         .read           = read_port,
656         .write          = write_port,
657         .open           = open_port,
658 };
659 #endif
660
661 static struct file_operations zero_fops = {
662         .llseek         = zero_lseek,
663         .read           = read_zero,
664         .write          = write_zero,
665         .mmap           = mmap_zero,
666 };
667
668 static struct file_operations full_fops = {
669         .llseek         = full_lseek,
670         .read           = read_full,
671         .write          = write_full,
672 };
673
674 static ssize_t kmsg_write(struct file * file, const char __user * buf,
675                           size_t count, loff_t *ppos)
676 {
677         char *tmp;
678         int ret;
679
680         tmp = kmalloc(count + 1, GFP_KERNEL);
681         if (tmp == NULL)
682                 return -ENOMEM;
683         ret = -EFAULT;
684         if (!copy_from_user(tmp, buf, count)) {
685                 tmp[count] = 0;
686                 ret = printk("%s", tmp);
687         }
688         kfree(tmp);
689         return ret;
690 }
691
692 static struct file_operations kmsg_fops = {
693         .write =        kmsg_write,
694 };
695
696 static int memory_open(struct inode * inode, struct file * filp)
697 {
698         switch (iminor(inode)) {
699                 case 1:
700                         filp->f_op = &mem_fops;
701                         break;
702                 case 2:
703                         filp->f_op = &kmem_fops;
704                         break;
705                 case 3:
706                         filp->f_op = &null_fops;
707                         break;
708 #if defined(CONFIG_ISA) || !defined(__mc68000__)
709                 case 4:
710                         filp->f_op = &port_fops;
711                         break;
712 #endif
713                 case 5:
714                         filp->f_op = &zero_fops;
715                         break;
716                 case 7:
717                         filp->f_op = &full_fops;
718                         break;
719                 case 8:
720                         filp->f_op = &random_fops;
721                         break;
722                 case 9:
723                         filp->f_op = &urandom_fops;
724                         break;
725                 case 11:
726                         filp->f_op = &kmsg_fops;
727                         break;
728                 default:
729                         return -ENXIO;
730         }
731         if (filp->f_op && filp->f_op->open)
732                 return filp->f_op->open(inode,filp);
733         return 0;
734 }
735
736 static struct file_operations memory_fops = {
737         .open           = memory_open,  /* just a selector for the real open */
738 };
739
740 static const struct {
741         unsigned int            minor;
742         char                    *name;
743         umode_t                 mode;
744         struct file_operations  *fops;
745 } devlist[] = { /* list of minor devices */
746         {1, "mem",     S_IRUSR | S_IWUSR | S_IRGRP, &mem_fops},
747         {2, "kmem",    S_IRUSR | S_IWUSR | S_IRGRP, &kmem_fops},
748         {3, "null",    S_IRUGO | S_IWUGO,           &null_fops},
749 #if defined(CONFIG_ISA) || !defined(__mc68000__)
750         {4, "port",    S_IRUSR | S_IWUSR | S_IRGRP, &port_fops},
751 #endif
752         {5, "zero",    S_IRUGO | S_IWUGO,           &zero_fops},
753         {7, "full",    S_IRUGO | S_IWUGO,           &full_fops},
754         {8, "random",  S_IRUGO | S_IWUSR,           &random_fops},
755         {9, "urandom", S_IRUGO | S_IWUSR,           &urandom_fops},
756         {11,"kmsg",    S_IRUGO | S_IWUSR,           &kmsg_fops},
757 };
758
759 static struct class_simple *mem_class;
760
761 static int __init chr_dev_init(void)
762 {
763         int i;
764
765         if (register_chrdev(MEM_MAJOR,"mem",&memory_fops))
766                 printk("unable to get major %d for memory devs\n", MEM_MAJOR);
767
768         mem_class = class_simple_create(THIS_MODULE, "mem");
769         for (i = 0; i < ARRAY_SIZE(devlist); i++) {
770                 class_simple_device_add(mem_class,
771                                         MKDEV(MEM_MAJOR, devlist[i].minor),
772                                         NULL, devlist[i].name);
773                 devfs_mk_cdev(MKDEV(MEM_MAJOR, devlist[i].minor),
774                                 S_IFCHR | devlist[i].mode, devlist[i].name);
775         }
776         
777 #if defined (CONFIG_FB)
778         fbmem_init();
779 #endif
780         return 0;
781 }
782
783 fs_initcall(chr_dev_init);