My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
mmap.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 #ifndef __MMAP_H__
24 #define __MMAP_H__
25 #include <pagetable.h>
26 #include <sw_debug.h>
27 
28 
29 /* Kernel page table hook */
30 extern struct ptable pt_kernel;
31 
32 static inline int is_block_aligned(unsigned long x)
33 {
34  return !(x & (BLOCK_SIZE - 1));
35 }
36 
37 static inline int is_page_aligned(unsigned long x)
38 {
39  return !(x & (PAGE_SIZE - 1));
40 }
41 void sw_seterrno(int x);
42 
43 #define kpa_to_kva_guest(x) \
44  (((x) - KERN_PA_BASE) + KERN_GUEST_BASE)
45 
46 #define round_next_page_size(x) \
47  x = (((x % 0x1000) == 0) ? ((x / 0x1000) * 0x1000) : (((x / 0x1000) + 1) * 0x1000))
48 
49 #define kpa_map_4k(x) \
50  x = (((x % 0x1000) == 0) ? x : ( x - (x % 0x1000)))
51 
52 /* Machine dependent page table APIs exported to mmap layer */
63 int ptable_block_map(struct ptable *, unsigned long, pa_t,
64  unsigned int);
65 
74 int ptable_block_unmap(struct ptable *, unsigned long);
75 
86 int ptable_page_map(struct ptable *, unsigned long, pa_t,
87  unsigned int);
88 
97 int ptable_page_unmap(struct ptable *, unsigned long);
98 
102 void ptable_ptf_init(void);
103 
104 /* Machine Independent mmap APIs */
116 int mmap_block_map_generic(struct ptable *, unsigned long, pa_t,
117  unsigned long, unsigned int);
118 
128 int mmap_block_unmap_generic(struct ptable *, unsigned long, unsigned long);
129 
141 int mmap_page_map_generic(struct ptable *, unsigned long, pa_t,
142  unsigned long, unsigned int);
143 
153 int mmap_page_unmap_generic(struct ptable *, unsigned long, unsigned long);
154 
155 /* Device virtual address allocator */
162 void dev_va_pool_init(unsigned long, unsigned long);
163 
171 unsigned long dev_va_alloc(unsigned long);
172 
173 /* Wrapper functions for mapping kernel text and data */
183 static inline int ktext_map(unsigned long va,
184  pa_t pa, unsigned long size)
185 {
186  return mmap_block_map_generic(&pt_kernel, va, pa, size,
187  PTF_KERN_TEXT);
188 }
189 
199 static inline int kdata_map(unsigned long va,
200  pa_t pa, unsigned long size)
201 {
202  return mmap_block_map_generic(&pt_kernel, va, pa, size,
203  PTF_KERN_DATA);
204 }
205 
206 
207 /*Wrapper functions for mapping kernel pages*/
217 static inline int mem_kmap(unsigned long va,
218  pa_t pa, unsigned long size)
219 {
220 
221  return mmap_page_map_generic(&pt_kernel, va, pa, size,
222  PTF_KERN_DATA);
223 }
224 
225 
234 static inline int mem_kunmap(unsigned long va, unsigned long size)
235 {
236 
237  return mmap_page_unmap_generic(&pt_kernel, va, size);
238 }
239 
240 
241 
242 /*Wrapper functions for mapping pages as non-secure */
243 /* pa to va is one to one mapping va = pa*/
253 static inline int ns_map(pa_t pa,pa_t *va,
254  pa_t size)
255 {
256  int ret;
257  pa_t orig_pa;
258  orig_pa = pa;
259  kpa_map_4k(pa); /*round off physical address to least nearest 4k address*/
260  size = (orig_pa + size) - pa; /*round off size to largest 4k address*/
261  *va = kpa_to_kva_guest(pa); /*pa to va conversion since physical address is in range of EL0 it
262  will look into ttbr0 register it will throw fault so va is converted
263  so that it will look into TTBR1 register*/
265  PTF_KERN_DATA);
266  *va = *va + (orig_pa - pa); /*va for given pa*/
267  return ret;
268 }
269 
278 static inline int mem_ns_unmap(unsigned long va, unsigned long size)
279 {
280  pa_t orig_va;
281  orig_va = va;
282  sw_printk("unmap addr 0x%x%x size 0x%x\n", (unsigned int)(va >> 32), (unsigned int)va, size);
283  kpa_map_4k(va);
284  size = (orig_va + size) - va;
286 }
287 
288 /* Wrapper functions for device mappings */
297 static inline unsigned long dev_kmap(pa_t pa, unsigned long size)
298 {
299  unsigned long va;
300 
301  va = dev_va_alloc(size);
302 
303  if (va == NULL) {
304  return NULL;
305  }
306 
308  return va;
309 }
310 
318 static inline unsigned long page_align_adjust(unsigned long x)
319 {
320 
321  if(!is_page_aligned(x)) {
322  x &= ~PAGE_MASK;
323  x += PAGE_SIZE;
324  }
325 
326  return x;
327 }
328 
329 #endif /* __MMAP_H__ */
unsigned long dev_va_alloc(unsigned long)
Definition: mmap.c:252
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
int mmap_block_unmap_generic(struct ptable *, unsigned long, unsigned long)
Definition: mmap.c:112
void sw_seterrno(int x)
Definition: page_table.c:65
Definition: page_table.h:174
int mem_ns_unmap(va_t va_addr, pa_t size)
Wrapper function for __unmap_from_ns.
Definition: page_table.c:827
#define PAGE_MASK
Definition: pagetable.h:38
int mem_kunmap(va_t va, va_t size)
Definition: page_table.c:79
u32 sw_printk(const char *fmt,...)
Writes directly to device, with no permission check.
Definition: sw_debug.c:71
void ptable_ptf_init(void)
Definition: pagetable.c:429
int mem_kmap(va_t va, pa_t pa, va_t size)
Definition: page_table.c:108
int mmap_page_unmap_generic(struct ptable *, unsigned long, unsigned long)
Definition: mmap.c:204
#define kpa_to_kva_guest(x)
Definition: mmap.h:43
struct ptable pt_kernel
Definition: arch_main.c:28
#define round_next_page_size(x)
Definition: mmap.h:46
int ptable_page_map(struct ptable *, unsigned long, pa_t, unsigned int)
Definition: pagetable.c:347
int ptable_block_map(struct ptable *, unsigned long, pa_t, unsigned int)
Definition: pagetable.c:257
#define PAGE_SIZE
Definition: pt_p4k_a39.h:26
int mmap_page_map_generic(struct ptable *, unsigned long, pa_t, unsigned long, unsigned int)
Definition: mmap.c:161
Definition: ptf.h:30
int mmap_block_map_generic(struct ptable *, unsigned long, pa_t, unsigned long, unsigned int)
Definition: mmap.c:62
Definition: ptf.h:31
#define NULL
Definition: sw_types.h:40
#define kpa_map_4k(x)
Definition: mmap.h:49
void dev_va_pool_init(unsigned long, unsigned long)
Definition: mmap.c:238
int ptable_block_unmap(struct ptable *, unsigned long)
Definition: pagetable.c:303
Definition: ptf.h:29
int ptable_page_unmap(struct ptable *, unsigned long)
Definition: pagetable.c:394
#define BLOCK_SIZE
Definition: pt_p4k_a39.h:31