1 | /* |
---|
2 | * hal_vmm.c - Virtual Memory Manager Initialisation for TSAR |
---|
3 | * |
---|
4 | * Authors Alain Greiner (2016,2017) |
---|
5 | * |
---|
6 | * Copyright (c) UPMC Sorbonne Universites |
---|
7 | * |
---|
8 | * This file is part of ALMOS-MKH. |
---|
9 | * |
---|
10 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
11 | * under the terms of the GNU General Public License as published by |
---|
12 | * the Free Software Foundation; version 2.0 of the License. |
---|
13 | * |
---|
14 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
17 | * General Public License for more details. |
---|
18 | * |
---|
19 | * You should have received a copy of the GNU General Public License |
---|
20 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
22 | */ |
---|
23 | |
---|
24 | #include <kernel_config.h> |
---|
25 | #include <hal_kernel_types.h> |
---|
26 | #include <hal_vmm.h> |
---|
27 | #include <hal_gpt.h> |
---|
28 | #include <vseg.h> |
---|
29 | #include <xlist.h> |
---|
30 | #include <vmm.h> |
---|
31 | #include <remote_rwlock.h> |
---|
32 | |
---|
33 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
34 | // This file contains the TSAR specific code to initialize the Virtual Memory Manager. |
---|
35 | // The "kentry" vseg contains the kernel code executed when a core enter/exit the kernel, |
---|
36 | // in case of Interrupt, Exception, or Syscall. |
---|
37 | // For the TSAR architecture, the kernel uses physical addresses, and this code must be |
---|
38 | // identity mapped. The following function is called by the generic vmm_init() function |
---|
39 | // and identity map all pages of the "kentry" vseg. |
---|
40 | // We dont take the locks protecting the VSL and the GPT, because there is no concurrent |
---|
41 | // accesses to VMM during VMM initialization. |
---|
42 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
43 | |
---|
44 | //////////////////////////////////// |
---|
45 | error_t hal_vmm_init( vmm_t * vmm ) |
---|
46 | { |
---|
47 | error_t error; |
---|
48 | |
---|
49 | // map all pages of "kentry" vseg |
---|
50 | uint32_t vpn; |
---|
51 | uint32_t attr; |
---|
52 | attr = GPT_MAPPED | GPT_SMALL | GPT_EXECUTABLE | GPT_CACHABLE | GPT_GLOBAL; |
---|
53 | for( vpn = CONFIG_VMM_KENTRY_BASE; |
---|
54 | vpn < (CONFIG_VMM_KENTRY_BASE + CONFIG_VMM_KENTRY_SIZE); vpn++ ) |
---|
55 | { |
---|
56 | error = hal_gpt_set_pte( XPTR( local_cxy , &vmm->gpt ), |
---|
57 | vpn, |
---|
58 | attr, |
---|
59 | (local_cxy<<20) | (vpn & 0xFFFFF) ); |
---|
60 | |
---|
61 | if( error ) return error; |
---|
62 | } |
---|
63 | |
---|
64 | // scan the VSL to found the "kentry" vseg |
---|
65 | xptr_t root_xp = XPTR( local_cxy , &vmm->vsegs_root ); |
---|
66 | xptr_t iter_xp; |
---|
67 | xptr_t vseg_xp; |
---|
68 | vseg_t * vseg; |
---|
69 | bool_t found = false; |
---|
70 | |
---|
71 | XLIST_FOREACH( root_xp , iter_xp ) |
---|
72 | { |
---|
73 | vseg_xp = XLIST_ELEMENT( iter_xp , vseg_t , xlist ); |
---|
74 | vseg = (vseg_t *)GET_PTR( vseg_xp ); |
---|
75 | |
---|
76 | // set the IDENT flag in "kentry" vseg descriptor |
---|
77 | if( vseg->vpn_base == CONFIG_VMM_KENTRY_BASE ) |
---|
78 | { |
---|
79 | vseg->flags |= VSEG_IDENT; |
---|
80 | found = true; |
---|
81 | break; |
---|
82 | } |
---|
83 | } |
---|
84 | |
---|
85 | if( found == false ) return 0XFFFFFFFF; |
---|
86 | |
---|
87 | return 0; |
---|
88 | |
---|
89 | } // end hal_vmm_init() |
---|
90 | |
---|
91 | |
---|