My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Classes | Macros | Typedefs | Enumerations | Functions
page_table.h File Reference
#include <sw_types.h>
#include <sw_common_types.h>
#include <sw_list.h>
#include <sw_board.h>

Go to the source code of this file.

Classes

struct  devmap
 
struct  ptable
 
struct  cpu_section
 Section page table entry. More...
 
struct  sw_page_ref
 Page table reference. More...
 

Macros

#define PAGE_TABLE_ENTRIES   4096
 
#define PAGE_TABLE_ENTRY_WIDTH   4
 
#define PAGE_TABLE_SIZE   (PAGE_TABLE_ENTRIES * PAGE_TABLE_ENTRY_WIDTH)
 
#define kva_to_kpa(x)   (((x) - KERN_VA_BASE) + KERN_PA_BASE)
 
#define kpa_to_kva(x)   (((x) - KERN_PA_BASE) + KERN_VA_BASE)
 
#define START_LEVEL   1
 
#define LEVEL0_OFFSET_MASK   0x0000ff8000000000
 
#define LEVEL_OFFSET_BITS   9
 
#define LEVEL_OFFSET_MASK(x)   (LEVEL0_OFFSET_MASK >> (x * LEVEL_OFFSET_BITS))
 
#define LEVEL_OFFSET_SHIFT(x)   ((4 - x) * LEVEL_OFFSET_BITS)
 
#define PT_STAGE_1   0
 
#define SECTION_SIZE   (1 << 20)
 
#define MAP_SIZE   SECTION_SIZE
 
#define ALIGN_MASK   (~(MAP_SIZE - 1))
 
#define SW_EINVAL   -2
 
#define SECURE_ACCESS_DOMAIN   0
 
#define L1_SECTION_AP_MASK   0x3
 
#define L1_EXECUTE_NEVER   1
 
#define L1_EXECUTE_ALLOW   0
 
#define L1_TYPE_MASK   0x3
 
#define L1_TYPE_FAULT   0x0
 
#define L1_TYPE_COARSE   0x1
 
#define L1_TYPE_SECTION   0x2
 
#define L1_SECTION_B_SHIFT   2
 
#define L1_SECTION_C_SHIFT   3
 
#define L1_SECTION_XN_SHIFT   4
 
#define L1_DOMAIN_SHIFT   5
 
#define L1_SECTION_AP_SHIFT   10
 
#define L1_SECTION_TEX_SHIFT   12
 
#define L1_SECTION_AP2_SHIFT   15
 
#define L1_SECTION_S_SHIFT   16
 
#define L1_SECTION_NG_SHIFT   17 /* Non-Global bit*/
 
#define L1_SECTION_NS_SHIFT   19 /* Non-Secure bit*/
 
#define L1_SECTION_NS_MASK   0x1
 
#define L1_SECTION_NS_IDX_MASK   (L1_SECTION_NS_MASK << L1_SECTION_NS_SHIFT)
 
#define L1_DOMAIN_MASK   0xf
 
#define L1_DOMAIN_IDX_MASK   (L1_DOMAIN_MASK << L1_DOMAIN_SHIFT)
 
#define SECTION_BASE_MASK   0xfff00000
 
#define FSR_TYPE_MASK   0x40f
 
#define FSR_ALIGN_FAULT   0x1
 
#define FSR_EXT_ABORT_L1   0xc
 
#define FSR_EXT_ABORT_L2   0xe
 
#define FSR_TRANS_SEC   0x5
 
#define FSR_TRANS_PAGE   0x7
 
#define FSR_DOMAIN_SEC   0x9
 
#define FSR_DOMAIN_PAG   0xb
 
#define FSR_PERM_SEC   0xd
 
#define FSR_PERM_PAGE   0xf
 
#define FSR_DOMAIN_MASK   0xf0
 
#define FSR_WNR_MASK   0x800
 
#define FSR_EXT_MASK   0x1000
 
#define PTF_PROT_KRW   (PRIV_RW_USR_NO)
 
#define PTF_PROT_KRO   (PRIV_RO_USR_NO)
 
#define PTF_PROT_URW   (PRIV_RW_USR_RW)
 
#define PTF_PROT_URO   (PRIV_RW_USR_RO)
 
#define PTF_EXEC   (1 << PTF_EXEC_SHIFT)
 
#define PTF_PROT_MASK   0x7
 
#define PTF_EXEC_MASK   0x8
 
#define PTF_EXEC_SHIFT   0x3
 
#define ptf_to_ap(x)   ((x) & PTF_PROT_MASK)
 
#define ptf_to_xn(x)   ((~(x) & PTF_EXEC_MASK) >> PTF_EXEC_SHIFT)
 
#define kva_to_kpa(x)   (((x) - KERN_VA_BASE) + KERN_PA_BASE)
 
#define kpa_to_kva(x)   (((x) - KERN_PA_BASE) + KERN_VA_BASE)
 

Typedefs

typedef enum mem_access_ctrl ACCESS_TYPE
 

Enumerations

enum  mem_access_ctrl {
  PRIV_NO_USR_NO = 0, PRIV_RW_USR_NO = 1, PRIV_RW_USR_RO = 2, PRIV_RW_USR_RW = 3,
  AP_RESERVED = 4, PRIV_RO_USR_NO = 5, DEPRECATED = 6, PRIV_RO_USR_RO = 7
}
 Memory access control constants. More...
 

Functions

u32 * get_secure_ptd (void)
 Returns the secure page table pointer. More...
 
u32 * map_secure_page_table (void)
 Initialize page table entries. More...
 
int __map_to_ns (pa_t phy_addr, va_t *va_addr)
 Create shared memory mapping between secure and non-secure kernel. More...
 
int ns_map (pa_t phy_addr, va_t *va_addr, pa_t size)
 Wrapper function for __map_to_ns. More...
 
int __unmap_from_ns (va_t va_addr)
 Unmap the non-secure memory from secure page table. More...
 
int mem_ns_unmap (va_t va_addr, pa_t size)
 Wrapper function for __unmap_from_ns. More...
 
int map_device_table (const struct devmap *dt)
 Map device table. More...
 
int map_device (va_t va, pa_t pa, u32 size)
 Map devices. More...
 
int map_user_access_device_table (const struct devmap *dt)
 Map User Access device table. More...
 
int map_user_access_device (va_t va, pa_t pa, u32 size)
 Map user access devices. More...
 
int map_secure_memory (va_t va, pa_t pa, u32 size, u32 ptf)
 Map a range of secure memory. More...
 
int unmap_secure_memory (va_t va, u32 size)
 Unmap a range of secure memory area. More...
 
int map_nsmemsect_normal (va_t, pa_t, u32)
 Map a range of non secure memory area as normal memory with attributes Outer and Inner write back, write allocate. More...
 
int unmap_nsmemsect_normal (va_t, u32)
 Unmap a range of non secure memory area. More...
 
int map_section_entry (u32 *pgd, struct cpu_section *entry)
 Create a section map entry. More...
 
int unmap_section_entry (u32 *pgd, va_t va)
 
int map_ns_section_entry (u32 *pgd, struct cpu_section *entry)
 Map the non-secure memory in secure page table for shared memory access. More...
 
int unmap_ns_section_entry (u32 *pgd, va_t va)
 Unmap the shared section entry from secure page table. More...
 
int map_to_secure (pa_t phy_addr, va_t va_addr)
 
int unmap_from_secure (va_t va_addr)
 
int page_ref_add (u32 l1_pte)
 Increment page table reference of shared memory. More...
 
int page_ref_release (u32 l1_pte)
 Decrement page table reference of shared memory. More...
 
void sw_seterrno (int x)
 
int mem_kunmap (va_t va, va_t size)
 
int mem_kmap (va_t va, pa_t pa, va_t size)
 

Macro Definition Documentation

#define ALIGN_MASK   (~(MAP_SIZE - 1))
#define FSR_ALIGN_FAULT   0x1
#define FSR_DOMAIN_MASK   0xf0
#define FSR_DOMAIN_PAG   0xb
#define FSR_DOMAIN_SEC   0x9
#define FSR_EXT_ABORT_L1   0xc
#define FSR_EXT_ABORT_L2   0xe
#define FSR_EXT_MASK   0x1000
#define FSR_PERM_PAGE   0xf
#define FSR_PERM_SEC   0xd
#define FSR_TRANS_PAGE   0x7
#define FSR_TRANS_SEC   0x5
#define FSR_TYPE_MASK   0x40f
#define FSR_WNR_MASK   0x800
#define kpa_to_kva (   x)    (((x) - KERN_PA_BASE) + KERN_VA_BASE)
#define kpa_to_kva (   x)    (((x) - KERN_PA_BASE) + KERN_VA_BASE)
#define kva_to_kpa (   x)    (((x) - KERN_VA_BASE) + KERN_PA_BASE)
#define kva_to_kpa (   x)    (((x) - KERN_VA_BASE) + KERN_PA_BASE)
#define L1_DOMAIN_IDX_MASK   (L1_DOMAIN_MASK << L1_DOMAIN_SHIFT)
#define L1_DOMAIN_MASK   0xf
#define L1_DOMAIN_SHIFT   5
#define L1_EXECUTE_ALLOW   0
#define L1_EXECUTE_NEVER   1
#define L1_SECTION_AP2_SHIFT   15
#define L1_SECTION_AP_MASK   0x3
#define L1_SECTION_AP_SHIFT   10
#define L1_SECTION_B_SHIFT   2
#define L1_SECTION_C_SHIFT   3
#define L1_SECTION_NG_SHIFT   17 /* Non-Global bit*/
#define L1_SECTION_NS_IDX_MASK   (L1_SECTION_NS_MASK << L1_SECTION_NS_SHIFT)
#define L1_SECTION_NS_MASK   0x1
#define L1_SECTION_NS_SHIFT   19 /* Non-Secure bit*/
#define L1_SECTION_S_SHIFT   16
#define L1_SECTION_TEX_SHIFT   12
#define L1_SECTION_XN_SHIFT   4
#define L1_TYPE_COARSE   0x1
#define L1_TYPE_FAULT   0x0
#define L1_TYPE_MASK   0x3
#define L1_TYPE_SECTION   0x2
#define LEVEL0_OFFSET_MASK   0x0000ff8000000000
#define LEVEL_OFFSET_BITS   9
#define LEVEL_OFFSET_MASK (   x)    (LEVEL0_OFFSET_MASK >> (x * LEVEL_OFFSET_BITS))
#define LEVEL_OFFSET_SHIFT (   x)    ((4 - x) * LEVEL_OFFSET_BITS)
#define MAP_SIZE   SECTION_SIZE
#define PAGE_TABLE_ENTRIES   4096
#define PAGE_TABLE_ENTRY_WIDTH   4
#define PAGE_TABLE_SIZE   (PAGE_TABLE_ENTRIES * PAGE_TABLE_ENTRY_WIDTH)
#define PT_STAGE_1   0
#define PTF_EXEC   (1 << PTF_EXEC_SHIFT)
#define PTF_EXEC_MASK   0x8
#define PTF_EXEC_SHIFT   0x3
#define PTF_PROT_KRO   (PRIV_RO_USR_NO)
#define PTF_PROT_KRW   (PRIV_RW_USR_NO)
#define PTF_PROT_MASK   0x7
#define PTF_PROT_URO   (PRIV_RW_USR_RO)
#define PTF_PROT_URW   (PRIV_RW_USR_RW)
#define ptf_to_ap (   x)    ((x) & PTF_PROT_MASK)
#define ptf_to_xn (   x)    ((~(x) & PTF_EXEC_MASK) >> PTF_EXEC_SHIFT)
#define SECTION_BASE_MASK   0xfff00000
#define SECTION_SIZE   (1 << 20)
#define SECURE_ACCESS_DOMAIN   0
#define START_LEVEL   1
#define SW_EINVAL   -2

Typedef Documentation

Enumeration Type Documentation

Memory access control constants.

Enumerator
PRIV_NO_USR_NO 

Priv no access, usr no access

PRIV_RW_USR_NO 

Priv read/write, usr no access

PRIV_RW_USR_RO 

Priv read/write, usr read only

PRIV_RW_USR_RW 

Priv read/write, usr read/write

AP_RESERVED 

Reserved

PRIV_RO_USR_NO 

Priv read only, usr no access

DEPRECATED 

Deprecated

PRIV_RO_USR_RO 

Priv read only, usr read only

Function Documentation

int __map_to_ns ( pa_t  phy_addr,
va_t *  va_addr 
)

Create shared memory mapping between secure and non-secure kernel.

This function creates the page table entry with ns bit set. So that this section of the non-secure memory act like a shared memory.

Parameters
phy_addrPhysical address of the non-secure memory
va_addrVirtual address of the shared memory
Returns
otz_return_t: OTZ_OK
OTZ_FAIL
int __unmap_from_ns ( va_t  va_addr)

Unmap the non-secure memory from secure page table.

This function unmaps the non-secure memory from secure page table. i.e. set 'NS' bit to zero

Parameters
va_addrVirtual address to be unmapped
Returns
otz_return_t: OTZ_OK
u32* get_secure_ptd ( void  )

Returns the secure page table pointer.

Returns
Pointer to page table

Returns the secure page table pointer.

This function returns the page table pointer

Returns
Pointer to the page table
int map_device ( va_t  va,
pa_t  pa,
u32  size 
)

Map devices.

This function assumes that the start address and size are section aligned.

Parameters
va: virtual address
pa: physical address
size: size
Returns
otz_return_t : OTZ_OK
OTZ_FAIL
int map_device_table ( const struct devmap dt)

Map device table.

Parameters
dtpointer to array of device mappings Array has to terminated with zero.
Returns
otz_return_t: OTZ_OK
OTZ_FAIL
int map_ns_section_entry ( u32 *  pgd,
struct cpu_section entry 
)

Map the non-secure memory in secure page table for shared memory access.

This function creates the section mapping with 'NS' bit set to create a shared memory access.

Parameters
pgdPointer to page table
entryPointer to section entry
Returns
otz_return_t: OTZ_OK
OTZ_FAIL
int map_nsmemsect_normal ( va_t  va,
pa_t  pa,
u32  size 
)

Map a range of non secure memory area as normal memory with attributes Outer and Inner write back, write allocate.

This function assumes that the start address and size are section aligned.

Parameters
vavirtual address
paphysical address
sizesize
Returns
otz_return_t: OTZ_OK
OTZ_FAIL
int map_section_entry ( u32 *  pgd,
struct cpu_section entry 
)

Create a section map entry.

This function creates section map entry in supplied page table

Parameters
pgdPointer to page table
entryPointer to section entry
Returns
otz_return_t: OTZ_OK
OTZ_FAIL
int map_secure_memory ( va_t  va,
pa_t  pa,
u32  size,
u32  ptf 
)

Map a range of secure memory.

This function assumes that the start address and size are section aligned.

Parameters
va: virtual address
pa: physical address
size: size
ptf: page table flag
Returns
otz_return_t : OTZ_OK
OTZ_FAIL
Map a range of secure memory.

This function assumes that the start address and size are section aligned.

Parameters
va: virtual address
pa: physical address
size: size
ptf: page table flag
Returns
otz_return_t : OTZ_OK
OTZ_FAIL
u32* map_secure_page_table ( void  )

Initialize page table entries.

This function creates the initial page table entries for secure kernel

Returns
Pointer to the page table
int map_to_secure ( pa_t  phy_addr,
va_t  va_addr 
)
Parameters
phy_addr
va_addr
Returns
int map_user_access_device ( va_t  va,
pa_t  pa,
u32  size 
)

Map user access devices.

This function assumes that the start address and size are section aligned.

Parameters
va: virtual address
pa: physical address
size: size
Returns
otz_return_t : OTZ_OK
OTZ_FAIL
int map_user_access_device_table ( const struct devmap dt)

Map User Access device table.

Parameters
dtpointer to array of device mappings Array has to terminated with zero.
Returns
otz_return_t: OTZ_OK
OTZ_FAIL
int mem_kmap ( va_t  va,
pa_t  pa,
va_t  size 
)
int mem_kunmap ( va_t  va,
va_t  size 
)
int mem_ns_unmap ( va_t  va_addr,
pa_t  size 
)

Wrapper function for __unmap_from_ns.

Parameters
va_addr
Returns
int ns_map ( pa_t  phy_addr,
va_t *  va_addr,
pa_t  size 
)

Wrapper function for __map_to_ns.

Parameters
phy_addr
va_addr
Returns
int page_ref_add ( u32  l1_pte)

Increment page table reference of shared memory.

This function increment the reference count of mapped shared memory

Parameters
l1_ptePage table entry
Returns
otz_return_t: OTZ_OK
OTZ_FAIL
int page_ref_release ( u32  l1_pte)

Decrement page table reference of shared memory.

This function decrement the reference count of mapped shared memory

Parameters
l1_ptePage table entry
Returns
otz_return_t: OTZ_OK
OTZ_FAIL
void sw_seterrno ( int  x)
int unmap_from_secure ( va_t  va_addr)
Parameters
va_addr
Returns
int unmap_ns_section_entry ( u32 *  pgd,
va_t  va 
)

Unmap the shared section entry from secure page table.

This function unmaps the secure memory section from secure page table. i.e. set 'NS' bit to zero

Parameters
pgdPointer to page table
vaVirtual address to be unmapped
Returns
otz_return_t: OTZ_OK
int unmap_nsmemsect_normal ( va_t  va,
u32  size 
)

Unmap a range of non secure memory area.

This function assumes that the start address and size are section aligned.

Parameters
vavirtual address
sizesize
Returns
otz_return_t: OTZ_OK
OTZ_FAIL
int unmap_section_entry ( u32 *  pgd,
va_t  va 
)
Parameters
pgd
va
Returns
int unmap_secure_memory ( va_t  va,
u32  size 
)

Unmap a range of secure memory area.

This function assumes that the start address and size are section aligned.

Parameters
vavirtual address
sizesize
Returns
otz_return_t: OTZ_OK
OTZ_FAIL