My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
page_table.h
Go to the documentation of this file.
1 /*
2  * OpenVirtualization:
3  * For additional details and support contact developer@sierraware.com.
4  * Additional documentation can be found at www.openvirtualization.org
5  *
6  * Copyright (C) 2010-2014 SierraWare
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  *
22  */
23 /*
24  * Header for secure page table initalization
25  */
26 
27 #ifndef __CPU_PAGETABLE_H__
28 #define __CPU_PAGETABLE_H__
29 
30 #include <sw_types.h>
31 #include <sw_common_types.h>
32 #include <sw_list.h>
33 #include <sw_board.h>
34 
35 #define PAGE_TABLE_ENTRIES 4096
36 #define PAGE_TABLE_ENTRY_WIDTH 4
37 #define PAGE_TABLE_SIZE (PAGE_TABLE_ENTRIES * PAGE_TABLE_ENTRY_WIDTH)
38 
39 
40 
41 
42 
43 
44 
45 
46 #define kva_to_kpa(x) \
47  (((x) - KERN_VA_BASE) + KERN_PA_BASE)
48 
49 #define kpa_to_kva(x) \
50  (((x) - KERN_PA_BASE) + KERN_VA_BASE)
51 
52 
53 #define START_LEVEL 1
54 
55 #define LEVEL0_OFFSET_MASK 0x0000ff8000000000
56 #define LEVEL_OFFSET_BITS 9
57 
58 
59 #define LEVEL_OFFSET_MASK(x) \
60  (LEVEL0_OFFSET_MASK >> (x * LEVEL_OFFSET_BITS))
61 #define LEVEL_OFFSET_SHIFT(x) \
62  ((4 - x) * LEVEL_OFFSET_BITS)
63 
64 #define PT_STAGE_1 0
65 
66 
67 #define SECTION_SIZE (1 << 20)
68 
69 
70 #define MAP_SIZE SECTION_SIZE
71 #define ALIGN_MASK (~(MAP_SIZE - 1))
72 
73 
74 
75 
76 
77 #define SW_EINVAL -2
78 
79 
80 
81 
82 
83 
84 
85 
86 
87 
88 
89 
90 #define SECURE_ACCESS_DOMAIN 0
91 //#define SECTION_SIZE 1 << 20
92 
93 
94 #define L1_SECTION_AP_MASK 0x3
95 
96 
97 /* XN Bit Values */
98 #define L1_EXECUTE_NEVER 1
99 #define L1_EXECUTE_ALLOW 0
100 
101 #define L1_TYPE_MASK 0x3
102 #define L1_TYPE_FAULT 0x0
103 #define L1_TYPE_COARSE 0x1
104 #define L1_TYPE_SECTION 0x2
105 
106 #define L1_SECTION_B_SHIFT 2
107 #define L1_SECTION_C_SHIFT 3
108 #define L1_SECTION_XN_SHIFT 4
109 #define L1_DOMAIN_SHIFT 5
110 #define L1_SECTION_AP_SHIFT 10
111 #define L1_SECTION_TEX_SHIFT 12
112 #define L1_SECTION_AP2_SHIFT 15
113 #define L1_SECTION_S_SHIFT 16
114 #define L1_SECTION_NG_SHIFT 17 /* Non-Global bit*/
115 #define L1_SECTION_NS_SHIFT 19 /* Non-Secure bit*/
116 #define L1_SECTION_NS_MASK 0x1
117 #define L1_SECTION_NS_IDX_MASK (L1_SECTION_NS_MASK << L1_SECTION_NS_SHIFT)
118 #define L1_DOMAIN_MASK 0xf
119 #define L1_DOMAIN_IDX_MASK (L1_DOMAIN_MASK << L1_DOMAIN_SHIFT)
120 
121 #define SECTION_BASE_MASK 0xfff00000
122 
123 #define FSR_TYPE_MASK 0x40f
124 #define FSR_ALIGN_FAULT 0x1
125 #define FSR_EXT_ABORT_L1 0xc
126 #define FSR_EXT_ABORT_L2 0xe
127 #define FSR_TRANS_SEC 0x5
128 #define FSR_TRANS_PAGE 0x7
129 #define FSR_DOMAIN_SEC 0x9
130 #define FSR_DOMAIN_PAG 0xb
131 #define FSR_PERM_SEC 0xd
132 #define FSR_PERM_PAGE 0xf
133 
134 #define FSR_DOMAIN_MASK 0xf0
135 #define FSR_WNR_MASK 0x800
136 #define FSR_EXT_MASK 0x1000
137 
138 /*
139  * Page table flags used by memory mapping APIs
140  * 0 - 2 : protection
141  * 3 : exec flag
142  * 4 - 31: unused
143  */
144 #define PTF_PROT_KRW (PRIV_RW_USR_NO)
145 #define PTF_PROT_KRO (PRIV_RO_USR_NO)
146 #define PTF_PROT_URW (PRIV_RW_USR_RW)
147 #define PTF_PROT_URO (PRIV_RW_USR_RO)
148 #define PTF_EXEC (1 << PTF_EXEC_SHIFT)
149 
150 
151 #define PTF_PROT_MASK 0x7
152 #define PTF_EXEC_MASK 0x8
153 #define PTF_EXEC_SHIFT 0x3
154 
155 #define ptf_to_ap(x) ((x) & PTF_PROT_MASK)
156 #define ptf_to_xn(x) ((~(x) & PTF_EXEC_MASK) >> PTF_EXEC_SHIFT)
157 
158 
159 #define kva_to_kpa(x) \
160  (((x) - KERN_VA_BASE) + KERN_PA_BASE)
161 
162 #define kpa_to_kva(x) \
163  (((x) - KERN_PA_BASE) + KERN_VA_BASE)
164 
165 
166 
167 
168 struct devmap {
169  va_t dv_va;
170  pa_t dv_pa;
171  u32 dv_size;
172 };
173 
174 struct ptable {
175  u32 pt_base;
176  int pt_type;
177 };
178 
179 
180 
185 {
202 };
204 
208 struct cpu_section {
210  va_t va;
212  pa_t pa;
214  size_t sz;
216  u32 ns:1;
218  u32 ng:1;
220  u32 s:1;
222  u32 tex:3;
224  u32 ap:3;
226  u32 imp:1;
228  u32 dom:4;
230  u32 xn:1;
232  u32 c:1;
234  u32 b:1;
236  u32 pad:15;
237 };
238 
242 struct sw_page_ref {
244  struct list head;
246  u32 l1_pte;
248  u32 ref_cnt;
249 };
250 
256 u32* get_secure_ptd(void);
263 u32* map_secure_page_table(void);
277 int __map_to_ns(pa_t phy_addr, va_t *va_addr);
278 
287 int ns_map(pa_t phy_addr, va_t *va_addr,pa_t size);
288 
300 int __unmap_from_ns(va_t va_addr);
308 int mem_ns_unmap(va_t va_addr,pa_t size);
309 
322 int map_device_table(const struct devmap *dt);
323 
324 
337 int map_device(va_t va, pa_t pa, u32 size);
338 
351 int map_user_access_device_table(const struct devmap *dt);
352 
353 
367 int map_user_access_device(va_t va, pa_t pa, u32 size);
368 
369 
384 int map_secure_memory(va_t va, pa_t pa, u32 size, u32 ptf);
385 
399 int unmap_secure_memory(va_t va, u32 size);
400 
401 
402 
418 int map_nsmemsect_normal(va_t, pa_t, u32);
419 
420 
434 int unmap_nsmemsect_normal(va_t, u32);
435 
448 int map_section_entry(u32 *pgd, struct cpu_section *entry);
449 
458 int unmap_section_entry(u32* pgd, va_t va);
459 
474 int map_ns_section_entry(u32 *pgd, struct cpu_section *entry);
475 
488 int unmap_ns_section_entry(u32 *pgd, va_t va);
489 
490 
499 int map_to_secure(pa_t phy_addr, va_t va_addr);
500 
508 int unmap_from_secure(va_t va_addr);
509 
521 int page_ref_add(u32 l1_pte);
522 
534 int page_ref_release(u32 l1_pte);
535 
536 
537 
538 
539 
540 
541 
542 
543 //u32 ptf_to_mattr(unsigned int ptf);
544 
545 
546 
547 
548 void sw_seterrno(int x);
549 
550 int mem_kunmap(va_t va, va_t size);
551 int mem_kmap(va_t va, pa_t pa, va_t size);
552 
553 
554 #endif
Section page table entry.
Definition: page_table.h:208
va_t dv_va
Definition: page_table.h:169
int ns_map(pa_t phy_addr, va_t *va_addr, pa_t size)
Wrapper function for __map_to_ns.
Definition: page_table.c:239
u32 c
Definition: page_table.h:232
pa_t pa
Definition: page_table.h:212
Definition: page_table.h:197
u32 pt_base
Definition: page_table.h:175
int unmap_secure_memory(va_t va, u32 size)
Unmap a range of secure memory area.
Definition: page_table.c:497
Definition: page_table.h:174
u32 * get_secure_ptd(void)
Returns the secure page table pointer.
Definition: page_table.c:59
int mem_ns_unmap(va_t va_addr, pa_t size)
Wrapper function for __unmap_from_ns.
Definition: page_table.c:827
Definition: page_table.h:191
int map_secure_memory(va_t va, pa_t pa, u32 size, u32 ptf)
Map a range of secure memory.
Definition: page_table.c:427
u32 xn
Definition: page_table.h:230
u32 ref_cnt
Definition: page_table.h:248
int map_user_access_device_table(const struct devmap *dt)
Map User Access device table.
Definition: page_table.c:402
u32 ap
Definition: page_table.h:224
struct list head
Definition: page_table.h:244
int mem_kunmap(va_t va, va_t size)
Definition: page_table.c:79
u32 ng
Definition: page_table.h:218
int map_user_access_device(va_t va, pa_t pa, u32 size)
Map user access devices.
Definition: page_table.c:321
int mem_kmap(va_t va, pa_t pa, va_t size)
Definition: page_table.c:108
int __map_to_ns(pa_t phy_addr, va_t *va_addr)
Create shared memory mapping between secure and non-secure kernel.
Definition: page_table.c:202
int unmap_from_secure(va_t va_addr)
Definition: page_table.c:795
va_t va
Definition: page_table.h:210
u32 b
Definition: page_table.h:234
int map_ns_section_entry(u32 *pgd, struct cpu_section *entry)
Map the non-secure memory in secure page table for shared memory access.
Definition: page_table.c:672
void sw_seterrno(int x)
Definition: page_table.c:65
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...
Definition: page_table.c:530
u32 * map_secure_page_table(void)
Initialize page table entries.
Definition: page_table.c:146
int page_ref_release(u32 l1_pte)
Decrement page table reference of shared memory.
Definition: page_table.c:896
Definition: page_table.h:195
enum mem_access_ctrl ACCESS_TYPE
Definition: page_table.h:203
Page table reference.
Definition: page_table.h:242
int pt_type
Definition: page_table.h:176
Definition: page_table.h:168
Definition: page_table.h:201
u32 dom
Definition: page_table.h:228
int page_ref_add(u32 l1_pte)
Increment page table reference of shared memory.
Definition: page_table.c:849
int map_section_entry(u32 *pgd, struct cpu_section *entry)
Create a section map entry.
Definition: page_table.c:617
u32 tex
Definition: page_table.h:222
int map_device_table(const struct devmap *dt)
Map device table.
Definition: page_table.c:380
Definition: page_table.h:187
pa_t dv_pa
Definition: page_table.h:170
int unmap_section_entry(u32 *pgd, va_t va)
Definition: page_table.c:725
u32 s
Definition: page_table.h:220
Definition: page_table.h:193
u32 pad
Definition: page_table.h:236
Definition: page_table.h:199
u32 ns
Definition: page_table.h:216
int unmap_nsmemsect_normal(va_t, u32)
Unmap a range of non secure memory area.
Definition: page_table.c:586
Definition: sw_list.h:56
mem_access_ctrl
Memory access control constants.
Definition: page_table.h:184
u32 l1_pte
Definition: page_table.h:246
size_t sz
Definition: page_table.h:214
int map_device(va_t va, pa_t pa, u32 size)
Map devices.
Definition: page_table.c:262
Definition: page_table.h:189
int __unmap_from_ns(va_t va_addr)
Unmap the non-secure memory from secure page table.
Definition: page_table.c:813
int unmap_ns_section_entry(u32 *pgd, va_t va)
Unmap the shared section entry from secure page table.
Definition: page_table.c:761
u32 imp
Definition: page_table.h:226
int map_to_secure(pa_t phy_addr, va_t va_addr)
Definition: page_table.c:165
u32 dv_size
Definition: page_table.h:171