diff options
author | venkatesh.pallipadi@intel.com <venkatesh.pallipadi@intel.com> | 2008-03-18 20:00:20 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-04-24 17:40:47 -0400 |
commit | f0970c13b6a5b01189aeb196ebb573cf87d95839 (patch) | |
tree | c33836b693ca066c19dc8986165aee5849fbcdd9 /drivers | |
parent | e045fb2a988a9a1964059b0d33dbaf18d12f925f (diff) |
x86: PAT phys_mem_access_prot_allowed for dev/mem mmap
Introduce phys_mem_access_prot_allowed(), which checks whether the mapping
is possible, without any conflicts and returns success or failure based on that.
phys_mem_access_prot() by itself does not allow failure case. This ability
to return error is needed for PAT where we may have aliasing conflicts.
x86 setup __HAVE_PHYS_MEM_ACCESS_PROT and move x86 specific code out of
/dev/mem into arch specific area.
Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/char/mem.c | 41 |
1 files changed, 11 insertions, 30 deletions
diff --git a/drivers/char/mem.c b/drivers/char/mem.c index 83495885ada0..56b2fb4fbc93 100644 --- a/drivers/char/mem.c +++ b/drivers/char/mem.c | |||
@@ -41,36 +41,7 @@ | |||
41 | */ | 41 | */ |
42 | static inline int uncached_access(struct file *file, unsigned long addr) | 42 | static inline int uncached_access(struct file *file, unsigned long addr) |
43 | { | 43 | { |
44 | #if defined(__i386__) && !defined(__arch_um__) | 44 | #if defined(CONFIG_IA64) |
45 | /* | ||
46 | * On the PPro and successors, the MTRRs are used to set | ||
47 | * memory types for physical addresses outside main memory, | ||
48 | * so blindly setting PCD or PWT on those pages is wrong. | ||
49 | * For Pentiums and earlier, the surround logic should disable | ||
50 | * caching for the high addresses through the KEN pin, but | ||
51 | * we maintain the tradition of paranoia in this code. | ||
52 | */ | ||
53 | if (file->f_flags & O_SYNC) | ||
54 | return 1; | ||
55 | return !( test_bit(X86_FEATURE_MTRR, boot_cpu_data.x86_capability) || | ||
56 | test_bit(X86_FEATURE_K6_MTRR, boot_cpu_data.x86_capability) || | ||
57 | test_bit(X86_FEATURE_CYRIX_ARR, boot_cpu_data.x86_capability) || | ||
58 | test_bit(X86_FEATURE_CENTAUR_MCR, boot_cpu_data.x86_capability) ) | ||
59 | && addr >= __pa(high_memory); | ||
60 | #elif defined(__x86_64__) && !defined(__arch_um__) | ||
61 | /* | ||
62 | * This is broken because it can generate memory type aliases, | ||
63 | * which can cause cache corruptions | ||
64 | * But it is only available for root and we have to be bug-to-bug | ||
65 | * compatible with i386. | ||
66 | */ | ||
67 | if (file->f_flags & O_SYNC) | ||
68 | return 1; | ||
69 | /* same behaviour as i386. PAT always set to cached and MTRRs control the | ||
70 | caching behaviour. | ||
71 | Hopefully a full PAT implementation will fix that soon. */ | ||
72 | return 0; | ||
73 | #elif defined(CONFIG_IA64) | ||
74 | /* | 45 | /* |
75 | * On ia64, we ignore O_SYNC because we cannot tolerate memory attribute aliases. | 46 | * On ia64, we ignore O_SYNC because we cannot tolerate memory attribute aliases. |
76 | */ | 47 | */ |
@@ -283,6 +254,12 @@ static ssize_t write_mem(struct file * file, const char __user * buf, | |||
283 | return written; | 254 | return written; |
284 | } | 255 | } |
285 | 256 | ||
257 | int __attribute__((weak)) phys_mem_access_prot_allowed(struct file *file, | ||
258 | unsigned long pfn, unsigned long size, pgprot_t *vma_prot) | ||
259 | { | ||
260 | return 1; | ||
261 | } | ||
262 | |||
286 | #ifndef __HAVE_PHYS_MEM_ACCESS_PROT | 263 | #ifndef __HAVE_PHYS_MEM_ACCESS_PROT |
287 | static pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, | 264 | static pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, |
288 | unsigned long size, pgprot_t vma_prot) | 265 | unsigned long size, pgprot_t vma_prot) |
@@ -336,6 +313,10 @@ static int mmap_mem(struct file * file, struct vm_area_struct * vma) | |||
336 | if (!range_is_allowed(vma->vm_pgoff, size)) | 313 | if (!range_is_allowed(vma->vm_pgoff, size)) |
337 | return -EPERM; | 314 | return -EPERM; |
338 | 315 | ||
316 | if (!phys_mem_access_prot_allowed(file, vma->vm_pgoff, size, | ||
317 | &vma->vm_page_prot)) | ||
318 | return -EINVAL; | ||
319 | |||
339 | vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_pgoff, | 320 | vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_pgoff, |
340 | size, | 321 | size, |
341 | vma->vm_page_prot); | 322 | vma->vm_page_prot); |