ARM: add memory types for the TCMs
PATCH 1/2 ARM: add memory types for the TCMs
The earlier TCM memory regions were mapped as MT_MEMORY_UNCACHED which doesn't really work on platforms supporting the new v6 features like the NX bit. Add unique MT_MEMORY_[I|D]TCM types instead.
---
Need help to get this right, so CC:in Russell and Nicolas on this, since they usually knows about these things.
The settings here work fine, code executes nicely from ITCM and data, variables and constants can be stored and retrieved.
I'm especially in the dark about the usage of the L_PTE_* stuff, and when to use DOMAIN_KERNEL, DOMAIN_USER and DOMAIN_IO. For
example: does DOMAIN_KERNEL imply kernel usage? DOMAIN_KERNEL for ITCM makes the code non-executable. Does DOMAIN_USER imply that L_PTE_USER shall also be set?
I tried reading the map.h and ARM manuals already but I don't find my way out so might as well ask.
--- arch/arm/include/asm/mach/map.h | 2 ++ arch/arm/kernel/tcm.c | 5 ++--- arch/arm/mm/mmu.c | 13 +++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-)
arch/arm/include/asm/mach/map.h +2 -0
@@ -27,6 +27,8 @@ struct map_desc {#define MT_MEMORY 9#define MT_ROM 10#define MT_MEMORY_NONCACHED 11 +#define MT_MEMORY_DTCM 12 +#define MT_MEMORY_ITCM 13#ifdef CONFIG_MMU extern void iotable_init (struct map_desc *,int );
arch/arm/kernel/tcm.c +2 -3
@@ -13,7 +13,6 @@#include <linux/ioport.h> #include <linux/genalloc.h> #include <linux/string.h> /* memcpy */ -#include <asm/page.h> /* PAGE_SHIFT */ #include <asm/cputype.h> #include <asm/mach/map.h> #include <mach/memory.h>
@@ -53,7 +52,7 @@ static struct map_desc dtcm_iomap[] __initdata = { .virtual = DTCM_OFFSET, .pfn = __phys_to_pfn(DTCM_OFFSET), .length = (DTCM_END - DTCM_OFFSET + 1), - .type = MT_UNCACHED + .type = MT_MEMORY_DTCM } };
@@ -62,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = { .virtual = ITCM_OFFSET, .pfn = __phys_to_pfn(ITCM_OFFSET), .length = (ITCM_END - ITCM_OFFSET + 1), - .type = MT_UNCACHED + .type = MT_MEMORY_ITCM } };
arch/arm/mm/mmu.c +13 -0
@@ -257,6 +257,19 @@ static struct mem_type mem_types[] = { .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE, .domain = DOMAIN_KERNEL, }, + [MT_MEMORY_DTCM] = { + .prot_pte =L_PTE_PRESENT |L_PTE_YOUNG | + L_PTE_DIRTY | L_PTE_WRITE, + .prot_l1 = PMD_TYPE_TABLE, + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN, + .domain = DOMAIN_KERNEL, + }, + [MT_MEMORY_ITCM] = { + .prot_pte =L_PTE_PRESENT |L_PTE_YOUNG |L_PTE_DIRTY | + L_PTE_USER | L_PTE_EXEC, + .prot_l1 = PMD_TYPE_TABLE, + .domain = DOMAIN_IO, + }, };const struct mem_type *get_mem_type (unsigned int type)
Signature · 1 line
1.7.1
PATCH 1/2 ARM: add memory types for the TCMs
Quoted 5 lines · Linus Walleij
I'm especially in the dark about the usage of the L_PTE_* stuff, and when to use
DOMAIN_KERNEL,DOMAIN_USERandDOMAIN_IO. For
example: doesDOMAIN_KERNELimply kernel usage?DOMAIN_KERNELfor ITCM makes the code non-executable. DoesDOMAIN_USERimply thatL_PTE_USERshall also be set?
Sorry, should've replied to this much earlier. We now have a problem in that this stuff for the ITCM entry is wrong (identified via Santosh's MT_MEMORY problems).
L_PTE_* define what ends up in the PTE entries. L_PTE_USER and L_PTE_WRITE operate together:
- None set, page is read-only in SVC mode, inaccessible in user mode.
- L_PTE_WRITE, page is read-write in SVC mode, inaccessible in user mode.
- L_PTE_USER, page is read-write in SVC mode, read-only in user mode.
- L_PTE_USER|L_PTE_WRITE, page is read-write in both SVC and user mode.
The domain stuff determines how these permissions are modified when set_fs(KERNEL_DS) is in effect.
DOMAIN_IO covers any statically allocated IO device, and is always in client mode. This means the permissions are never bypassed.
DOMAIN_USER covers userspace mappings, and likewise is always in client mode.
DOMAIN_KERNEL covers the kernel direct-mapped RAM, vmalloc and ioremap space. This is normally in client mode when set_fs(USER_DS) is in effect. When set_fs(KERNEL_DS) is set (which happens when we want to use user-accessing functions such as get_user() on data in kernel space) this domain is switched to manager mode, thereby bypassing the normal MMU protections.
IO stuff in kernel space should be mapped without L_PTE_USER and DOMAIN_IO. Everything else in kernel space should be mapped without L_PTE_USER and DOMAIN_KERNEL, with the exception of the user-accessible high vectors page.
PATCH 1/2 ARM: add memory types for the TCMs
Quoted 11 lines · Russell King - ARM Linux
Quoted 5 lines · Linus Walleij
I'm especially in the dark about the usage of the L_PTE_* stuff, and when to use
DOMAIN_KERNEL,DOMAIN_USERandDOMAIN_IO. For
example: doesDOMAIN_KERNELimply kernel usage?DOMAIN_KERNELfor ITCM makes the code non-executable. DoesDOMAIN_USERimply thatL_PTE_USERshall also be set?Sorry, should've replied to this much earlier. We now have a problem in that this stuff for the ITCM entry is wrong (identified via Santosh's
MT_MEMORYproblems).
Quoted 6 lines
L_PTE_* define what ends up in the PTE entries.
L_PTE_USERandL_PTE_WRITEoperate together:- None set, page is read-only in SVC mode, inaccessible in user mode.
-L_PTE_WRITE, page is read-write in SVC mode, inaccessible in user mode.
-L_PTE_USER, page is read-write in SVC mode, read-only in user mode.
Just a small addition - with the domains removal patch on ARMv7, this becomes read-only for both SVC and user modes.
Signature · 1 line
Catalin