summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/arm/cpu/mmu.c30
-rw-r--r--arch/arm/include/asm/mmu.h23
-rw-r--r--arch/blackfin/include/asm/mmu.h14
-rw-r--r--arch/mips/include/asm/mmu.h14
-rw-r--r--arch/nios2/include/asm/mmu.h14
-rw-r--r--arch/openrisc/include/asm/mmu.h14
-rw-r--r--arch/ppc/cpu-85xx/mmu.c26
-rw-r--r--arch/ppc/include/asm/mmu.h24
-rw-r--r--arch/sandbox/include/asm/mmu.h14
-rw-r--r--arch/x86/include/asm/mmu.h14
-rw-r--r--commands/memtest.c45
-rw-r--r--common/memtest.c5
-rw-r--r--drivers/video/imx-ipu-fb.c5
-rw-r--r--drivers/video/omap.c5
-rw-r--r--drivers/video/stm.c5
-rw-r--r--include/mmu.h41
16 files changed, 120 insertions, 173 deletions
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index 470b448..81c2394 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -20,7 +20,7 @@
#include <common.h>
#include <dma-dir.h>
#include <init.h>
-#include <asm/mmu.h>
+#include <mmu.h>
#include <errno.h>
#include <linux/sizes.h>
#include <asm/memory.h>
@@ -81,16 +81,6 @@ static uint32_t pte_flags_uncached;
#define PTE_MASK ((1 << 12) - 1)
-uint32_t mmu_get_pte_cached_flags()
-{
- return pte_flags_cached;
-}
-
-uint32_t mmu_get_pte_uncached_flags()
-{
- return pte_flags_uncached;
-}
-
static void arm_mmu_not_initialized_error(void)
{
/*
@@ -173,24 +163,38 @@ static void dma_inv_range(unsigned long start, unsigned long end)
__dma_inv_range(start, end);
}
-void remap_range(void *_start, size_t size, uint32_t flags)
+int arch_remap_range(void *_start, size_t size, unsigned flags)
{
unsigned long start = (unsigned long)_start;
u32 *p;
int numentries, i;
+ u32 pte_flags;
+
+ switch (flags) {
+ case MAP_CACHED:
+ pte_flags = pte_flags_cached;
+ break;
+ case MAP_UNCACHED:
+ pte_flags = pte_flags_uncached;
+ break;
+ default:
+ return -EINVAL;
+ }
numentries = size >> PAGE_SHIFT;
p = find_pte(start);
for (i = 0; i < numentries; i++) {
p[i] &= ~PTE_MASK;
- p[i] |= flags | PTE_TYPE_SMALL;
+ p[i] |= pte_flags | PTE_TYPE_SMALL;
}
dma_flush_range((unsigned long)p,
(unsigned long)p + numentries * sizeof(u32));
tlb_invalidate();
+
+ return 0;
}
void *map_io_sections(unsigned long phys, void *_start, size_t size)
diff --git a/arch/arm/include/asm/mmu.h b/arch/arm/include/asm/mmu.h
index 3b19e9e..8de6544 100644
--- a/arch/arm/include/asm/mmu.h
+++ b/arch/arm/include/asm/mmu.h
@@ -27,32 +27,17 @@ static inline void setup_dma_coherent(unsigned long offset)
}
#ifdef CONFIG_MMU
-void remap_range(void *_start, size_t size, uint32_t flags);
+#define ARCH_HAS_REMAP
+#define MAP_ARCH_DEFAULT MAP_CACHED
+int arch_remap_range(void *_start, size_t size, unsigned flags);
void *map_io_sections(unsigned long physaddr, void *start, size_t size);
-uint32_t mmu_get_pte_cached_flags(void);
-uint32_t mmu_get_pte_uncached_flags(void);
-
#else
-
-static inline void remap_range(void *_start, size_t size, uint32_t flags)
-{
-}
-
+#define MAP_ARCH_DEFAULT MAP_UNCACHED
static inline void *map_io_sections(unsigned long phys, void *start, size_t size)
{
return (void *)phys;
}
-static inline uint32_t mmu_get_pte_cached_flags(void)
-{
- return 0;
-}
-
-static inline uint32_t mmu_get_pte_uncached_flags(void)
-{
- return 0;
-}
-
#endif
#ifdef CONFIG_CACHE_L2X0
diff --git a/arch/blackfin/include/asm/mmu.h b/arch/blackfin/include/asm/mmu.h
index bf65420..95af871 100644
--- a/arch/blackfin/include/asm/mmu.h
+++ b/arch/blackfin/include/asm/mmu.h
@@ -1,18 +1,6 @@
#ifndef __ASM_MMU_H
#define __ASM_MMU_H
-static inline void remap_range(void *_start, size_t size, uint32_t flags)
-{
-}
-
-static inline uint32_t mmu_get_pte_cached_flags(void)
-{
- return 0;
-}
-
-static inline uint32_t mmu_get_pte_uncached_flags(void)
-{
- return 0;
-}
+#define MAP_ARCH_DEFAULT MAP_UNCACHED
#endif /* __ASM_MMU_H */
diff --git a/arch/mips/include/asm/mmu.h b/arch/mips/include/asm/mmu.h
index bf65420..95af871 100644
--- a/arch/mips/include/asm/mmu.h
+++ b/arch/mips/include/asm/mmu.h
@@ -1,18 +1,6 @@
#ifndef __ASM_MMU_H
#define __ASM_MMU_H
-static inline void remap_range(void *_start, size_t size, uint32_t flags)
-{
-}
-
-static inline uint32_t mmu_get_pte_cached_flags(void)
-{
- return 0;
-}
-
-static inline uint32_t mmu_get_pte_uncached_flags(void)
-{
- return 0;
-}
+#define MAP_ARCH_DEFAULT MAP_UNCACHED
#endif /* __ASM_MMU_H */
diff --git a/arch/nios2/include/asm/mmu.h b/arch/nios2/include/asm/mmu.h
index bf65420..95af871 100644
--- a/arch/nios2/include/asm/mmu.h
+++ b/arch/nios2/include/asm/mmu.h
@@ -1,18 +1,6 @@
#ifndef __ASM_MMU_H
#define __ASM_MMU_H
-static inline void remap_range(void *_start, size_t size, uint32_t flags)
-{
-}
-
-static inline uint32_t mmu_get_pte_cached_flags(void)
-{
- return 0;
-}
-
-static inline uint32_t mmu_get_pte_uncached_flags(void)
-{
- return 0;
-}
+#define MAP_ARCH_DEFAULT MAP_UNCACHED
#endif /* __ASM_MMU_H */
diff --git a/arch/openrisc/include/asm/mmu.h b/arch/openrisc/include/asm/mmu.h
index bf65420..95af871 100644
--- a/arch/openrisc/include/asm/mmu.h
+++ b/arch/openrisc/include/asm/mmu.h
@@ -1,18 +1,6 @@
#ifndef __ASM_MMU_H
#define __ASM_MMU_H
-static inline void remap_range(void *_start, size_t size, uint32_t flags)
-{
-}
-
-static inline uint32_t mmu_get_pte_cached_flags(void)
-{
- return 0;
-}
-
-static inline uint32_t mmu_get_pte_uncached_flags(void)
-{
- return 0;
-}
+#define MAP_ARCH_DEFAULT MAP_UNCACHED
#endif /* __ASM_MMU_H */
diff --git a/arch/ppc/cpu-85xx/mmu.c b/arch/ppc/cpu-85xx/mmu.c
index 7e86e6b..6b93c3e 100644
--- a/arch/ppc/cpu-85xx/mmu.c
+++ b/arch/ppc/cpu-85xx/mmu.c
@@ -14,17 +14,29 @@
#include <common.h>
#include <asm/cache.h>
+#include <mmu.h>
#include <mach/mmu.h>
-void remap_range(void *_start, size_t size, uint32_t flags)
+int arch_remap_range(void *_start, size_t size, unsigned flags)
{
- uint32_t ptr, start, tsize, valid, wimge;
+ uint32_t ptr, start, tsize, valid, wimge, pte_flags;
unsigned long epn;
phys_addr_t rpn = 0;
int esel = 0;
+ switch (flags) {
+ case MAP_UNCACHED:
+ pte_flags = MAS2_I;
+ break;
+ case MAP_CACHED:
+ pte_flags = 0;
+ break;
+ default:
+ return -EINVAL;
+ }
+
ptr = start = (uint32_t)_start;
- wimge = flags | MAS2_M;
+ wimge = pte_flags | MAS2_M;
while (ptr < (start + size)) {
esel = e500_find_tlb_idx((void *)ptr, 1);
@@ -41,14 +53,6 @@ void remap_range(void *_start, size_t size, uint32_t flags)
/* convert tsize to bytes to increment address. */
ptr += (1ULL << ((tsize) + 10));
}
-}
-uint32_t mmu_get_pte_cached_flags(void)
-{
return 0;
}
-
-uint32_t mmu_get_pte_uncached_flags(void)
-{
- return MAS2_I;
-}
diff --git a/arch/ppc/include/asm/mmu.h b/arch/ppc/include/asm/mmu.h
index 6e15975..c691de1 100644
--- a/arch/ppc/include/asm/mmu.h
+++ b/arch/ppc/include/asm/mmu.h
@@ -557,25 +557,13 @@ extern int write_bat(ppc_bat_t bat, unsigned long upper, unsigned long lower);
#ifndef __ASSEMBLY__
+#define MAP_ARCH_DEFAULT MAP_CACHED
+
#ifdef CONFIG_MMU
-void remap_range(void *_start, size_t size, uint32_t flags);
-uint32_t mmu_get_pte_cached_flags(void);
-uint32_t mmu_get_pte_uncached_flags(void);
-#else
-static inline void remap_range(void *_start, size_t size, uint32_t flags)
-{
-}
-
-static inline uint32_t mmu_get_pte_cached_flags(void)
-{
- return 0;
-}
-
-static inline uint32_t mmu_get_pte_uncached_flags(void)
-{
- return 0;
-}
-#endif /* CONFIG_MMU */
+#define ARCH_HAS_REMAP
+int arch_remap_range(void *_start, size_t size, unsigned flags);
+#endif
+
#endif
#endif /* _PPC_MMU_H_ */
diff --git a/arch/sandbox/include/asm/mmu.h b/arch/sandbox/include/asm/mmu.h
index bf65420..95af871 100644
--- a/arch/sandbox/include/asm/mmu.h
+++ b/arch/sandbox/include/asm/mmu.h
@@ -1,18 +1,6 @@
#ifndef __ASM_MMU_H
#define __ASM_MMU_H
-static inline void remap_range(void *_start, size_t size, uint32_t flags)
-{
-}
-
-static inline uint32_t mmu_get_pte_cached_flags(void)
-{
- return 0;
-}
-
-static inline uint32_t mmu_get_pte_uncached_flags(void)
-{
- return 0;
-}
+#define MAP_ARCH_DEFAULT MAP_UNCACHED
#endif /* __ASM_MMU_H */
diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
index bf65420..95af871 100644
--- a/arch/x86/include/asm/mmu.h
+++ b/arch/x86/include/asm/mmu.h
@@ -1,18 +1,6 @@
#ifndef __ASM_MMU_H
#define __ASM_MMU_H
-static inline void remap_range(void *_start, size_t size, uint32_t flags)
-{
-}
-
-static inline uint32_t mmu_get_pte_cached_flags(void)
-{
- return 0;
-}
-
-static inline uint32_t mmu_get_pte_uncached_flags(void)
-{
- return 0;
-}
+#define MAP_ARCH_DEFAULT MAP_UNCACHED
#endif /* __ASM_MMU_H */
diff --git a/commands/memtest.c b/commands/memtest.c
index 531b8e0..db9e3db 100644
--- a/commands/memtest.c
+++ b/commands/memtest.c
@@ -21,15 +21,15 @@
#include <command.h>
#include <getopt.h>
-#include <asm/mmu.h>
#include <memory.h>
#include <malloc.h>
#include <common.h>
#include <errno.h>
#include <memtest.h>
+#include <mmu.h>
static int __do_memtest(struct list_head *memtest_regions,
- int bus_only, uint32_t cache_flag)
+ int bus_only, unsigned cache_flag)
{
struct mem_test_resource *r;
int ret;
@@ -53,7 +53,7 @@ static int __do_memtest(struct list_head *memtest_regions,
static int do_memtest(int argc, char *argv[])
{
int bus_only = 0, ret, opt;
- uint32_t i, max_i = 1, pte_flags_cached, pte_flags_uncached;
+ uint32_t i, max_i = 1;
struct list_head memtest_used_regions;
while ((opt = getopt(argc, argv, "i:b")) > 0) {
@@ -72,12 +72,6 @@ static int do_memtest(int argc, char *argv[])
if (optind > argc)
return COMMAND_ERROR_USAGE;
- /*
- * Get pte flags for enable and disable cache support on page.
- */
- pte_flags_cached = mmu_get_pte_cached_flags();
- pte_flags_uncached = mmu_get_pte_uncached_flags();
-
INIT_LIST_HEAD(&memtest_used_regions);
ret = mem_test_request_regions(&memtest_used_regions);
@@ -87,24 +81,31 @@ static int do_memtest(int argc, char *argv[])
for (i = 1; (i <= max_i) || !max_i; i++) {
if (max_i)
printf("Start iteration %u of %u.\n", i, max_i);
- /*
- * First try a memtest with caching enabled.
- */
- if (IS_ENABLED(CONFIG_MMU)) {
+
+ if (arch_can_remap()) {
+ /*
+ * First try a memtest with caching enabled.
+ */
printf("Do memtest with caching enabled.\n");
ret = __do_memtest(&memtest_used_regions,
- bus_only, pte_flags_cached);
+ bus_only, MAP_CACHED);
+ if (ret < 0)
+ goto out;
+
+ /*
+ * Second try a memtest with caching disabled.
+ */
+ printf("Do memtest with caching disabled.\n");
+ ret = __do_memtest(&memtest_used_regions,
+ bus_only, MAP_UNCACHED);
+ if (ret < 0)
+ goto out;
+ } else {
+ ret = __do_memtest(&memtest_used_regions,
+ bus_only, MAP_DEFAULT);
if (ret < 0)
goto out;
}
- /*
- * Second try a memtest with caching disabled.
- */
- printf("Do memtest with caching disabled.\n");
- ret = __do_memtest(&memtest_used_regions,
- bus_only, pte_flags_uncached);
- if (ret < 0)
- goto out;
}
out:
diff --git a/common/memtest.c b/common/memtest.c
index fc71e91..467eea5 100644
--- a/common/memtest.c
+++ b/common/memtest.c
@@ -28,7 +28,7 @@
#include <errno.h>
#include <memtest.h>
#include <malloc.h>
-#include <asm/mmu.h>
+#include <mmu.h>
static int alloc_memtest_region(struct list_head *list,
resource_size_t start, resource_size_t size)
@@ -126,14 +126,13 @@ int mem_test_request_regions(struct list_head *list)
void mem_test_release_regions(struct list_head *list)
{
struct mem_test_resource *r, *r_tmp;
- uint32_t pte_flags_cached = mmu_get_pte_cached_flags();
list_for_each_entry_safe(r, r_tmp, list, list) {
/*
* Ensure to leave with a cached on non used sdram regions.
*/
remap_range((void *)r->r->start, r->r->end -
- r->r->start + 1, pte_flags_cached);
+ r->r->start + 1, MAP_DEFAULT);
release_sdram_region(r->r);
free(r);
diff --git a/drivers/video/imx-ipu-fb.c b/drivers/video/imx-ipu-fb.c
index a87e720..03d191a 100644
--- a/drivers/video/imx-ipu-fb.c
+++ b/drivers/video/imx-ipu-fb.c
@@ -27,7 +27,7 @@
#include <malloc.h>
#include <errno.h>
#include <asm-generic/div64.h>
-#include <asm/mmu.h>
+#include <mmu.h>
#include <mach/imx-ipu-fb.h>
#include <linux/clk.h>
#include <linux/err.h>
@@ -1030,8 +1030,7 @@ static int imxfb_probe(struct device_d *dev)
fbi->info.screen_base = pdata->framebuffer;
if (fbi->info.screen_base) {
remap_range(fbi->info.screen_base,
- fbi->info.screen_size,
- mmu_get_pte_uncached_flags());
+ fbi->info.screen_size, MAP_UNCACHED);
} else {
fbi->info.screen_base = dma_alloc_coherent(fbi->info.screen_size,
DMA_ADDRESS_BROKEN);
diff --git a/drivers/video/omap.c b/drivers/video/omap.c
index 3603ad2..884365f 100644
--- a/drivers/video/omap.c
+++ b/drivers/video/omap.c
@@ -35,7 +35,7 @@
#include <mach/omap4-silicon.h>
#include <mach/omap-fb.h>
-#include <asm/mmu.h>
+#include <mmu.h>
#include "omap.h"
@@ -487,8 +487,7 @@ static int omapfb_probe(struct device_d *dev)
(void __iomem *)pdata->screen->start;
fbi->prealloc_screen.size = resource_size(pdata->screen);
remap_range(fbi->prealloc_screen.addr,
- fbi->prealloc_screen.size,
- mmu_get_pte_uncached_flags());
+ fbi->prealloc_screen.size, MAP_UNCACHED);
}
rc = omapfb_reset(fbi);
diff --git a/drivers/video/stm.c b/drivers/video/stm.c
index 1b42a18..e5c1ef3 100644
--- a/drivers/video/stm.c
+++ b/drivers/video/stm.c
@@ -25,7 +25,7 @@
#include <xfuncs.h>
#include <io.h>
#include <dma.h>
-#include <asm/mmu.h>
+#include <mmu.h>
#include <stmp-device.h>
#include <linux/clk.h>
#include <linux/err.h>
@@ -332,8 +332,7 @@ static int stmfb_activate_var(struct fb_info *fb_info)
fb_info->screen_base = fbi->fixed_screen;
fbi->memory_size = fbi->fixed_screen_size;
remap_range(fbi->fixed_screen,
- fbi->fixed_screen_size,
- mmu_get_pte_uncached_flags());
+ fbi->fixed_screen_size, MAP_UNCACHED);
} else {
fb_info->screen_base = dma_alloc_coherent(size, NULL);
if (!fb_info->screen_base)
diff --git a/include/mmu.h b/include/mmu.h
new file mode 100644
index 0000000..66b246f
--- /dev/null
+++ b/include/mmu.h
@@ -0,0 +1,41 @@
+#ifndef __MMU_H
+#define __MMU_H
+
+#define MAP_UNCACHED 0
+#define MAP_CACHED 1
+
+/*
+ * Depending on the architecture the default mapping can be
+ * cached or uncached. Without ARCH_HAS_REMAP being set this
+ * is mapping type is the only one supported.
+ */
+#define MAP_DEFAULT MAP_ARCH_DEFAULT
+
+#include <asm/mmu.h>
+
+#ifndef ARCH_HAS_REMAP
+static inline int arch_remap_range(void *start, size_t size, unsigned flags)
+{
+ if (flags == MAP_ARCH_DEFAULT)
+ return 0;
+
+ return -EINVAL;
+}
+
+static inline bool arch_can_remap(void)
+{
+ return false;
+}
+#else
+static inline bool arch_can_remap(void)
+{
+ return true;
+}
+#endif
+
+static inline int remap_range(void *start, size_t size, unsigned flags)
+{
+ return arch_remap_range(start, size, flags);
+}
+
+#endif