• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
3  * Licensed under the Mulan PSL v2.
4  * You can use this software according to the terms and conditions of the Mulan PSL v2.
5  * You may obtain a copy of Mulan PSL v2 at:
6  *     http://license.coscl.org.cn/MulanPSL2
7  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
8  * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
9  * PURPOSE.
10  * See the Mulan PSL v2 for more details.
11  */
12 #include <common/types.h>
13 #include <mm/vmspace.h>
14 #include <mm/kmalloc.h>
15 #include <mm/mm.h>
16 
17 /*
18  * ASID:
19  * An ASID is a 16-bit identifer.
20  * The current ASID is the value of bits 63:48 of TTBR0_EL1.
21  * To prevent misunderstanding, we use 'pcid' here instead of 'asid'.
22  *
23  * ASID configuration is configured in el1_mmu_activate
24  */
25 #define ASID_SHIFT 48
26 
arch_vmspace_init(struct vmspace * vmspace)27 void arch_vmspace_init(struct vmspace *vmspace)
28 {
29     /* In aarch64, this function is not needed. */
30 }
31 
create_idle_vmspace(void)32 struct vmspace *create_idle_vmspace(void)
33 {
34     struct vmspace *vmspace;
35 
36     vmspace = (struct vmspace *)kzalloc(sizeof(*vmspace));
37     /*
38      * An idle thread on aarch64 does not require a pgtbl
39      * for user-space.
40      */
41     return vmspace;
42 }
43 
44 /* Change vmspace to the target one */
switch_vmspace_to(struct vmspace * vmspace)45 void switch_vmspace_to(struct vmspace *vmspace)
46 {
47     paddr_t pa;
48 
49     pa = virt_to_phys(vmspace->pgtbl);
50     /* The upper 16 bits of TTBR0_EL1 represent ASID */
51     pa |= (u64)(vmspace->pcid) << ASID_SHIFT;
52     set_page_table(pa);
53 }
54