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