Root/
Source at commit dc637c9 created 12 years 4 months ago. By Xiangfu Liu, xburst: ben nanonote: first add WPAN(atben,atusb) driver take from qi-kernel.git thanks to Werner | |
---|---|
1 | From ab59753a9df09b990822b15d2593c5c98905684c Mon Sep 17 00:00:00 2001 |
2 | From: Xiangfu Liu <xiangfu@macbook.openmobilefree.net> |
3 | Date: Wed, 14 Sep 2011 14:29:51 +0800 |
4 | Subject: [PATCH 27/32] Add DEVMEM support |
5 | |
6 | --- |
7 | drivers/char/Kconfig | 10 ++++++++++ |
8 | drivers/char/mem.c | 17 +++++++++++++++++ |
9 | 2 files changed, 27 insertions(+), 0 deletions(-) |
10 | |
11 | diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig |
12 | index 49502bc..770f678 100644 |
13 | --- a/drivers/char/Kconfig |
14 | +++ b/drivers/char/Kconfig |
15 | @@ -6,6 +6,16 @@ menu "Character devices" |
16 | |
17 | source "drivers/tty/Kconfig" |
18 | |
19 | +config DEVMEM |
20 | + bool "/dev/mem virtual device support" |
21 | + default y |
22 | + help |
23 | + Say Y here if you want to support the /dev/mem device. |
24 | + Some X server drivers access the video hardware using this device. |
25 | + Accessing hardware directly from user space can be useful in some |
26 | + cases, but it is not without risks. |
27 | + When in doubt, say "N". |
28 | + |
29 | config DEVKMEM |
30 | bool "/dev/kmem virtual device support" |
31 | default y |
32 | diff --git a/drivers/char/mem.c b/drivers/char/mem.c |
33 | index 8fc04b4..eb78f37 100644 |
34 | --- a/drivers/char/mem.c |
35 | +++ b/drivers/char/mem.c |
36 | @@ -86,6 +86,8 @@ void __weak unxlate_dev_mem_ptr(unsigned long phys, void *addr) |
37 | { |
38 | } |
39 | |
40 | +#ifdef CONFIG_DEVMEM |
41 | + |
42 | /* |
43 | * This funcion reads the *physical* memory. The f_pos points directly to the |
44 | * memory location. |
45 | @@ -209,6 +211,10 @@ static ssize_t write_mem(struct file *file, const char __user *buf, |
46 | return written; |
47 | } |
48 | |
49 | +#endif |
50 | + |
51 | +#if defined(CONFIG_DEVMEM) || defined(CONFIG_DEVKMEM) |
52 | + |
53 | int __weak phys_mem_access_prot_allowed(struct file *file, |
54 | unsigned long pfn, unsigned long size, pgprot_t *vma_prot) |
55 | { |
56 | @@ -330,6 +336,8 @@ static int mmap_mem(struct file *file, struct vm_area_struct *vma) |
57 | return 0; |
58 | } |
59 | |
60 | +#endif |
61 | + |
62 | #ifdef CONFIG_DEVKMEM |
63 | static int mmap_kmem(struct file *file, struct vm_area_struct *vma) |
64 | { |
65 | @@ -693,6 +701,7 @@ static loff_t null_lseek(struct file *file, loff_t offset, int orig) |
66 | return file->f_pos = 0; |
67 | } |
68 | |
69 | +#if defined(CONFIG_DEVMEM) || defined(CONFIG_DEVKMEM) || defined(CONFIG_DEVPORT) |
70 | /* |
71 | * The memory devices use the full 32/64 bits of the offset, and so we cannot |
72 | * check against negative addresses: they are ok. The return value is weird, |
73 | @@ -725,11 +734,15 @@ static loff_t memory_lseek(struct file *file, loff_t offset, int orig) |
74 | mutex_unlock(&file->f_path.dentry->d_inode->i_mutex); |
75 | return ret; |
76 | } |
77 | +#endif |
78 | |
79 | +#if defined(CONFIG_DEVMEM) || defined(CONFIG_DEVKMEM) || \ |
80 | + defined(CONFIG_DEVPORT) || defined(CONFIG_CRASH_DUMP) |
81 | static int open_port(struct inode * inode, struct file * filp) |
82 | { |
83 | return capable(CAP_SYS_RAWIO) ? 0 : -EPERM; |
84 | } |
85 | +#endif |
86 | |
87 | #define zero_lseek null_lseek |
88 | #define full_lseek null_lseek |
89 | @@ -739,6 +752,7 @@ static int open_port(struct inode * inode, struct file * filp) |
90 | #define open_kmem open_mem |
91 | #define open_oldmem open_mem |
92 | |
93 | +#ifdef CONFIG_DEVMEM |
94 | static const struct file_operations mem_fops = { |
95 | .llseek = memory_lseek, |
96 | .read = read_mem, |
97 | @@ -747,6 +761,7 @@ static const struct file_operations mem_fops = { |
98 | .open = open_mem, |
99 | .get_unmapped_area = get_unmapped_area_mem, |
100 | }; |
101 | +#endif |
102 | |
103 | #ifdef CONFIG_DEVKMEM |
104 | static const struct file_operations kmem_fops = { |
105 | @@ -850,7 +865,9 @@ static const struct memdev { |
106 | const struct file_operations *fops; |
107 | struct backing_dev_info *dev_info; |
108 | } devlist[] = { |
109 | +#ifdef CONFIG_DEVMEM |
110 | [1] = { "mem", 0, &mem_fops, &directly_mappable_cdev_bdi }, |
111 | +#endif |
112 | #ifdef CONFIG_DEVKMEM |
113 | [2] = { "kmem", 0, &kmem_fops, &directly_mappable_cdev_bdi }, |
114 | #endif |
115 | -- |
116 | 1.7.4.1 |
117 | |
118 |