Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 93409
b: refs/heads/master
c: e045fb2
h: refs/heads/master
i:
  93407: a464326
v: v3
  • Loading branch information
venkatesh.pallipadi@intel.com authored and Ingo Molnar committed Apr 24, 2008
1 parent 7c403d0 commit 131fba6
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 18 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: e2beb3eae627211b67e456c53f946cede2ac10d7
refs/heads/master: e045fb2a988a9a1964059b0d33dbaf18d12f925f
29 changes: 29 additions & 0 deletions trunk/arch/x86/mm/ioremap.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,35 @@ void iounmap(volatile void __iomem *addr)
}
EXPORT_SYMBOL(iounmap);

/*
* Convert a physical pointer to a virtual kernel pointer for /dev/mem
* access
*/
void *xlate_dev_mem_ptr(unsigned long phys)
{
void *addr;
unsigned long start = phys & PAGE_MASK;

/* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
if (page_is_ram(start >> PAGE_SHIFT))
return __va(phys);

addr = (void *)ioremap(start, PAGE_SIZE);
if (addr)
addr = (void *)((unsigned long)addr | (phys & ~PAGE_MASK));

return addr;
}

void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
{
if (page_is_ram(phys >> PAGE_SHIFT))
return;

iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
return;
}

#ifdef CONFIG_X86_32

int __initdata early_ioremap_debug;
Expand Down
32 changes: 27 additions & 5 deletions trunk/drivers/char/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
}
#endif

void __attribute__((weak)) unxlate_dev_mem_ptr(unsigned long phys, void *addr)
{
}

/*
* This funcion reads the *physical* memory. The f_pos points directly to the
* memory location.
Expand Down Expand Up @@ -176,17 +180,25 @@ static ssize_t read_mem(struct file * file, char __user * buf,

sz = min_t(unsigned long, sz, count);

if (!range_is_allowed(p >> PAGE_SHIFT, count))
return -EPERM;

/*
* On ia64 if a page has been mapped somewhere as
* uncached, then it must also be accessed uncached
* by the kernel or data corruption may occur
*/
ptr = xlate_dev_mem_ptr(p);
if (!ptr)
return -EFAULT;

if (!range_is_allowed(p >> PAGE_SHIFT, count))
return -EPERM;
if (copy_to_user(buf, ptr, sz))
if (copy_to_user(buf, ptr, sz)) {
unxlate_dev_mem_ptr(p, ptr);
return -EFAULT;
}

unxlate_dev_mem_ptr(p, ptr);

buf += sz;
p += sz;
count -= sz;
Expand Down Expand Up @@ -235,22 +247,32 @@ static ssize_t write_mem(struct file * file, const char __user * buf,

sz = min_t(unsigned long, sz, count);

if (!range_is_allowed(p >> PAGE_SHIFT, sz))
return -EPERM;

/*
* On ia64 if a page has been mapped somewhere as
* uncached, then it must also be accessed uncached
* by the kernel or data corruption may occur
*/
ptr = xlate_dev_mem_ptr(p);
if (!ptr) {
if (written)
break;
return -EFAULT;
}

if (!range_is_allowed(p >> PAGE_SHIFT, sz))
return -EPERM;
copied = copy_from_user(ptr, buf, sz);
if (copied) {
written += sz - copied;
unxlate_dev_mem_ptr(p, ptr);
if (written)
break;
return -EFAULT;
}

unxlate_dev_mem_ptr(p, ptr);

buf += sz;
p += sz;
count -= sz;
Expand Down
8 changes: 8 additions & 0 deletions trunk/include/asm-x86/io.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
#ifndef _ASM_X86_IO_H
#define _ASM_X86_IO_H

#define ARCH_HAS_IOREMAP_WC

#ifdef CONFIG_X86_32
# include "io_32.h"
#else
# include "io_64.h"
#endif

extern void *xlate_dev_mem_ptr(unsigned long phys);
extern void unxlate_dev_mem_ptr(unsigned long phys, void *addr);

extern int ioremap_change_attr(unsigned long vaddr, unsigned long size,
unsigned long prot_val);
extern void __iomem *ioremap_wc(unsigned long offset, unsigned long size);

#endif /* _ASM_X86_IO_H */
6 changes: 0 additions & 6 deletions trunk/include/asm-x86/io_32.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@

#include <linux/vmalloc.h>

/*
* Convert a physical pointer to a virtual kernel pointer for /dev/mem
* access
*/
#define xlate_dev_mem_ptr(p) __va(p)

/*
* Convert a virtual cached pointer to an uncached pointer
*/
Expand Down
6 changes: 0 additions & 6 deletions trunk/include/asm-x86/io_64.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,6 @@ void memset_io(volatile void __iomem *a, int b, size_t c);
extern int iommu_bio_merge;
#define BIO_VMERGE_BOUNDARY iommu_bio_merge

/*
* Convert a physical pointer to a virtual kernel pointer for /dev/mem
* access
*/
#define xlate_dev_mem_ptr(p) __va(p)

/*
* Convert a virtual cached pointer to an uncached pointer
*/
Expand Down

0 comments on commit 131fba6

Please sign in to comment.