aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHaavard Skinnemoen <hskinnemoen@atmel.com>2006-10-01 02:29:12 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-10-01 03:39:31 -0400
commit74588d8ba34ff1bda027cfa737972af01ab00c8b (patch)
tree5e889e96d29c96e9c54ff72933de0612c61e9835
parentbc03613decef0cc4d2f3a24f19fa5a868745715f (diff)
[PATCH] Generic ioremap_page_range: implementation
This patch adds a generic implementation of ioremap_page_range() in lib/ioremap.c based on the i386 implementation. It differs from the i386 version in the following ways: * The PTE flags are passed as a pgprot_t argument and must be determined up front by the arch-specific code. No additional PTE flags are added. * Uses set_pte_at() instead of set_pte() [bunk@stusta.de: warning fix] ]dhowells@redhat.com: nommu build fix] Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com> Cc: Richard Henderson <rth@twiddle.net> Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru> Cc: Russell King <rmk@arm.linux.org.uk> Cc: Mikael Starvik <starvik@axis.com> Cc: Andi Kleen <ak@suse.de> Cc: <linux-m32r@ml.linux-m32r.org> Cc: Ralf Baechle <ralf@linux-mips.org> Cc: Kyle McMartin <kyle@parisc-linux.org> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Paul Mundt <lethal@linux-sh.org> Signed-off-by: Adrian Bunk <bunk@stusta.de> Signed-off-by: David Howells <dhowells@redhat.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r--include/linux/io.h4
-rw-r--r--lib/Makefile1
-rw-r--r--lib/ioremap.c94
3 files changed, 99 insertions, 0 deletions
diff --git a/include/linux/io.h b/include/linux/io.h
index 420e2fdf26f6..aa3f5af670b5 100644
--- a/include/linux/io.h
+++ b/include/linux/io.h
@@ -19,8 +19,12 @@
19#define _LINUX_IO_H 19#define _LINUX_IO_H
20 20
21#include <asm/io.h> 21#include <asm/io.h>
22#include <asm/page.h>
22 23
23void __iowrite32_copy(void __iomem *to, const void *from, size_t count); 24void __iowrite32_copy(void __iomem *to, const void *from, size_t count);
24void __iowrite64_copy(void __iomem *to, const void *from, size_t count); 25void __iowrite64_copy(void __iomem *to, const void *from, size_t count);
25 26
27int ioremap_page_range(unsigned long addr, unsigned long end,
28 unsigned long phys_addr, pgprot_t prot);
29
26#endif /* _LINUX_IO_H */ 30#endif /* _LINUX_IO_H */
diff --git a/lib/Makefile b/lib/Makefile
index 402762fead70..ddf3e676e1f4 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -7,6 +7,7 @@ lib-y := errno.o ctype.o string.o vsprintf.o cmdline.o \
7 idr.o div64.o int_sqrt.o bitmap.o extable.o prio_tree.o \ 7 idr.o div64.o int_sqrt.o bitmap.o extable.o prio_tree.o \
8 sha1.o 8 sha1.o
9 9
10lib-$(CONFIG_MMU) += ioremap.o
10lib-$(CONFIG_SMP) += cpumask.o 11lib-$(CONFIG_SMP) += cpumask.o
11 12
12lib-y += kobject.o kref.o kobject_uevent.o klist.o 13lib-y += kobject.o kref.o kobject_uevent.o klist.o
diff --git a/lib/ioremap.c b/lib/ioremap.c
new file mode 100644
index 000000000000..29c810ec9813
--- /dev/null
+++ b/lib/ioremap.c
@@ -0,0 +1,94 @@
1/*
2 * Re-map IO memory to kernel address space so that we can access it.
3 * This is needed for high PCI addresses that aren't mapped in the
4 * 640k-1MB IO memory area on PC's
5 *
6 * (C) Copyright 1995 1996 Linus Torvalds
7 */
8#include <linux/io.h>
9#include <linux/vmalloc.h>
10#include <linux/mm.h>
11
12#include <asm/cacheflush.h>
13#include <asm/pgtable.h>
14
15static int ioremap_pte_range(pmd_t *pmd, unsigned long addr,
16 unsigned long end, unsigned long phys_addr, pgprot_t prot)
17{
18 pte_t *pte;
19 unsigned long pfn;
20
21 pfn = phys_addr >> PAGE_SHIFT;
22 pte = pte_alloc_kernel(pmd, addr);
23 if (!pte)
24 return -ENOMEM;
25 do {
26 BUG_ON(!pte_none(*pte));
27 set_pte_at(&init_mm, addr, pte, pfn_pte(pfn, prot));
28 pfn++;
29 } while (pte++, addr += PAGE_SIZE, addr != end);
30 return 0;
31}
32
33static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
34 unsigned long end, unsigned long phys_addr, pgprot_t prot)
35{
36 pmd_t *pmd;
37 unsigned long next;
38
39 phys_addr -= addr;
40 pmd = pmd_alloc(&init_mm, pud, addr);
41 if (!pmd)
42 return -ENOMEM;
43 do {
44 next = pmd_addr_end(addr, end);
45 if (ioremap_pte_range(pmd, addr, next, phys_addr + addr, prot))
46 return -ENOMEM;
47 } while (pmd++, addr = next, addr != end);
48 return 0;
49}
50
51static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
52 unsigned long end, unsigned long phys_addr, pgprot_t prot)
53{
54 pud_t *pud;
55 unsigned long next;
56
57 phys_addr -= addr;
58 pud = pud_alloc(&init_mm, pgd, addr);
59 if (!pud)
60 return -ENOMEM;
61 do {
62 next = pud_addr_end(addr, end);
63 if (ioremap_pmd_range(pud, addr, next, phys_addr + addr, prot))
64 return -ENOMEM;
65 } while (pud++, addr = next, addr != end);
66 return 0;
67}
68
69int ioremap_page_range(unsigned long addr,
70 unsigned long end, unsigned long phys_addr, pgprot_t prot)
71{
72 pgd_t *pgd;
73 unsigned long start;
74 unsigned long next;
75 int err;
76
77 BUG_ON(addr >= end);
78
79 flush_cache_all();
80
81 start = addr;
82 phys_addr -= addr;
83 pgd = pgd_offset_k(addr);
84 do {
85 next = pgd_addr_end(addr, end);
86 err = ioremap_pud_range(pgd, addr, next, phys_addr+addr, prot);
87 if (err)
88 break;
89 } while (pgd++, addr = next, addr != end);
90
91 flush_tlb_all();
92
93 return err;
94}