1 | /* |
---|
2 | * hal_vmm.c - Generic 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 for the Virtual Memory Manager. |
---|
35 | // |
---|
36 | // The "kentry" vseg contains the kernel code executed when a core enter/exit the kernel, |
---|
37 | // in case of Interrupt, Exception, or Syscall. |
---|
38 | // For the TSAR architecture, the kernel uses physical addresses, and this code must be |
---|
39 | // identity mapped. The following function is called by the generic vmm_init() function |
---|
40 | // and identity map all pages of the "kentry" vseg. |
---|
41 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
42 | |
---|
43 | //////////////////////////////////// |
---|
44 | error_t hal_vmm_init( vmm_t * vmm ) |
---|
45 | { |
---|
46 | error_t error; |
---|
47 | |
---|
48 | // get pointer on GPT |
---|
49 | gpt_t * gpt = &vmm->gpt; |
---|
50 | |
---|
51 | // map all pages of "kentry" vseg |
---|
52 | uint32_t vpn; |
---|
53 | uint32_t attr; |
---|
54 | attr = GPT_MAPPED | GPT_SMALL | GPT_EXECUTABLE | GPT_CACHABLE | GPT_GLOBAL; |
---|
55 | for( vpn = CONFIG_VMM_KENTRY_BASE; |
---|
56 | vpn < (CONFIG_VMM_KENTRY_BASE + CONFIG_VMM_KENTRY_SIZE); vpn++ ) |
---|
57 | { |
---|
58 | error = hal_gpt_set_pte( gpt, |
---|
59 | vpn, |
---|
60 | attr, |
---|
61 | (local_cxy<<20) | (vpn & 0xFFFFF) ); |
---|
62 | |
---|
63 | if( error ) return error; |
---|
64 | } |
---|
65 | |
---|
66 | // get lock protecting the VSL to found the "kentry" vseg |
---|
67 | remote_rwlock_wr_lock( XPTR( local_cxy , &vmm->vsegs_lock ) ); |
---|
68 | |
---|
69 | // scan the VSL |
---|
70 | xptr_t root_xp = XPTR( local_cxy , &vmm->vsegs_root ); |
---|
71 | xptr_t iter_xp; |
---|
72 | xptr_t vseg_xp; |
---|
73 | vseg_t * vseg; |
---|
74 | bool_t found = false; |
---|
75 | XLIST_FOREACH( root_xp , iter_xp ) |
---|
76 | { |
---|
77 | vseg_xp = XLIST_ELEMENT( iter_xp , vseg_t , xlist ); |
---|
78 | vseg = (vseg_t *)GET_PTR( vseg_xp ); |
---|
79 | |
---|
80 | // set the IDENT flag in "kentry" vseg descriptor |
---|
81 | if( vseg->vpn_base == CONFIG_VMM_KENTRY_BASE ) |
---|
82 | { |
---|
83 | vseg->flags |= VSEG_IDENT; |
---|
84 | found = true; |
---|
85 | break; |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | // release the lock protecting the VSL |
---|
90 | remote_rwlock_wr_unlock( XPTR( local_cxy , &vmm->vsegs_lock ) ); |
---|
91 | |
---|
92 | if( found == false ) return error; |
---|
93 | |
---|
94 | return 0; |
---|
95 | |
---|
96 | } // end hal_vmm_init() |
---|
97 | |
---|
98 | |
---|