Linux-2.6.12-rc2
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / um / kernel / skas / mem_user.c
blob1310bf1e88d185dfaeaa75b42386691f3066ba79
1 /*
2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
6 #include <errno.h>
7 #include <sys/mman.h>
8 #include "mem_user.h"
9 #include "mem.h"
10 #include "user.h"
11 #include "os.h"
12 #include "proc_mm.h"
14 void map(int fd, unsigned long virt, unsigned long len, int r, int w,
15 int x, int phys_fd, unsigned long long offset)
17 struct proc_mm_op map;
18 int prot, n;
20 prot = (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) |
21 (x ? PROT_EXEC : 0);
23 map = ((struct proc_mm_op) { .op = MM_MMAP,
24 .u =
25 { .mmap =
26 { .addr = virt,
27 .len = len,
28 .prot = prot,
29 .flags = MAP_SHARED |
30 MAP_FIXED,
31 .fd = phys_fd,
32 .offset = offset
33 } } } );
34 n = os_write_file(fd, &map, sizeof(map));
35 if(n != sizeof(map))
36 printk("map : /proc/mm map failed, err = %d\n", -n);
39 int unmap(int fd, void *addr, unsigned long len)
41 struct proc_mm_op unmap;
42 int n;
44 unmap = ((struct proc_mm_op) { .op = MM_MUNMAP,
45 .u =
46 { .munmap =
47 { .addr = (unsigned long) addr,
48 .len = len } } } );
49 n = os_write_file(fd, &unmap, sizeof(unmap));
50 if(n != sizeof(unmap)) {
51 if(n < 0)
52 return(n);
53 else if(n > 0)
54 return(-EIO);
57 return(0);
60 int protect(int fd, unsigned long addr, unsigned long len, int r, int w,
61 int x, int must_succeed)
63 struct proc_mm_op protect;
64 int prot, n;
66 prot = (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) |
67 (x ? PROT_EXEC : 0);
69 protect = ((struct proc_mm_op) { .op = MM_MPROTECT,
70 .u =
71 { .mprotect =
72 { .addr = (unsigned long) addr,
73 .len = len,
74 .prot = prot } } } );
76 n = os_write_file(fd, &protect, sizeof(protect));
77 if(n != sizeof(protect)) {
78 if(n == 0) return(0);
80 if(must_succeed)
81 panic("protect failed, err = %d", -n);
83 return(-EIO);
86 return(0);
89 void before_mem_skas(unsigned long unused)
94 * Overrides for Emacs so that we follow Linus's tabbing style.
95 * Emacs will notice this stuff at the end of the file and automatically
96 * adjust the settings for this buffer only. This must remain at the end
97 * of the file.
98 * ---------------------------------------------------------------------------
99 * Local variables:
100 * c-file-style: "linux"
101 * End: