ia64/xen-unstable

view linux-2.6.8.1-xen-sparse/drivers/char/mem.c @ 2360:7479be6635eb

bitkeeper revision 1.1159.53.6 (412f02a2L7sRmDm5FXr063kbMCR24Q)

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