[1] | 1 | /* |
---|
| 2 | * hal_gpt.h - Generic Page Table API definition. |
---|
| 3 | * |
---|
| 4 | * Authors Alain Greiner (2016) |
---|
| 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 | #ifndef _GPT_H_ |
---|
| 25 | #define _GPT_H_ |
---|
| 26 | |
---|
| 27 | #include <hal_types.h> |
---|
| 28 | |
---|
| 29 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 30 | // Generic Page Table Definition (implementation in hal_gpt.c) |
---|
| 31 | // |
---|
[17] | 32 | // It is specified as a simple (one dimensional) array indexed by the VPN (vpn_t type), |
---|
| 33 | // even if implementations can use a more sophisticated organisation (two-levels or more). |
---|
| 34 | // - The number of entries (number of pages in a virtual space) is architecture |
---|
| 35 | // dependent, and is defined as (CONFIG_USER_SPACE_SIZE / CONFIG_PPM_PAGE_SIZE). |
---|
| 36 | // - Each entry contains a Physical Page Number (ppn_t type), and a set of attributes, |
---|
[1] | 37 | // defined as masks on a 32 bits-vector. |
---|
| 38 | // |
---|
[17] | 39 | // Any arch-specific implementation must implement this API. |
---|
[1] | 40 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 41 | |
---|
| 42 | /**** Forward declarations ****/ |
---|
| 43 | |
---|
| 44 | struct page_s; |
---|
| 45 | |
---|
| 46 | /**************************************************************************************** |
---|
[41] | 47 | * These global variables define the masks for the Generic Page Table Entry attributes. |
---|
[1] | 48 | * The actual values must be defined in the implementation (hal_gpt.c file). |
---|
| 49 | ***************************************************************************************/ |
---|
| 50 | |
---|
[41] | 51 | extern uint32_t GPT_MAPPED; /*! PTE is mapped */ |
---|
[1] | 52 | extern uint32_t GPT_SMALL; /*! PTE is a small page */ |
---|
| 53 | extern uint32_t GPT_READABLE; /*! PTE is readable */ |
---|
| 54 | extern uint32_t GPT_WRITABLE; /*! PTE is writable */ |
---|
| 55 | extern uint32_t GPT_EXECUTABLE; /*! PTE is executable */ |
---|
| 56 | extern uint32_t GPT_CACHABLE; /*! PTE can be cached */ |
---|
| 57 | extern uint32_t GPT_USER; /*! PTE is user accessible */ |
---|
| 58 | extern uint32_t GPT_DIRTY; /*! PTE has been "recently" written */ |
---|
| 59 | extern uint32_t GPT_ACCESSED; /*! PTE has been "recently" accessed */ |
---|
[41] | 60 | extern uint32_t GPT_GLOBAL; /*! PTE is kept in TLB at context switch */ |
---|
[1] | 61 | extern uint32_t GPT_COW; /*! PTE must be copied on write */ |
---|
[41] | 62 | extern uint32_t GPT_SWAP; /*! PTE swapped on disk (not implemented yet) */ |
---|
[1] | 63 | extern uint32_t GPT_LOCKED; /*! PTE is protected against concurrent access */ |
---|
| 64 | |
---|
| 65 | /**************************************************************************************** |
---|
[41] | 66 | * This structure defines the Generic Page Table descriptor. |
---|
[1] | 67 | ***************************************************************************************/ |
---|
| 68 | |
---|
| 69 | typedef struct gpt_s |
---|
| 70 | { |
---|
[315] | 71 | void * ptr; /*! local pointer on GPT root */ |
---|
[1] | 72 | ppn_t ppn; /*! PPN of GPT root */ |
---|
[315] | 73 | struct page_s * page; /*! local pointer on GPT root page descriptor */ |
---|
[1] | 74 | } |
---|
| 75 | gpt_t; |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | /**************************************************************************************** |
---|
[41] | 79 | * This function allocates physical memory for first level page table (PT1), |
---|
[17] | 80 | * and initializes the page table descriptor. |
---|
[1] | 81 | **************************************************************************************** |
---|
| 82 | * @ gpt : pointer on generic page table descriptor. |
---|
| 83 | * @ returns 0 if success / returns ENOMEM if error. |
---|
| 84 | ***************************************************************************************/ |
---|
| 85 | error_t hal_gpt_create( gpt_t * gpt ); |
---|
| 86 | |
---|
| 87 | /**************************************************************************************** |
---|
| 88 | * This function releases all memory dynamically allocated for a generic page table. |
---|
| 89 | * For a multi-levels radix tree implementation, it includes all nodes in the tree. |
---|
[17] | 90 | * If the calling thread is running in the reference cluster, it checks that user PTE |
---|
[41] | 91 | * entries are unmapped, and releases the mapped physical pages. |
---|
[1] | 92 | * The kernel pages are not released. |
---|
| 93 | **************************************************************************************** |
---|
| 94 | * @ gpt : pointer on generic page table descriptor. |
---|
| 95 | ***************************************************************************************/ |
---|
| 96 | void hal_gpt_destroy( gpt_t * gpt); |
---|
| 97 | |
---|
| 98 | /**************************************************************************************** |
---|
[41] | 99 | * This function prints on the kernel terminal the content of a generic page table. |
---|
[1] | 100 | **************************************************************************************** |
---|
| 101 | * @ gpt : pointer on generic page table descriptor. |
---|
| 102 | ***************************************************************************************/ |
---|
| 103 | void hal_gpt_print( gpt_t * gpt); |
---|
| 104 | |
---|
| 105 | /**************************************************************************************** |
---|
[41] | 106 | * This blocking function gets a lock on a PTE (Page Table Entry) identified |
---|
[1] | 107 | * by its VPN, and returns only when the PTE has been successfully locked. |
---|
[17] | 108 | * If the target PTE is not present, it allocates and maps a physical page. |
---|
[1] | 109 | * A big page cannot be locked. |
---|
| 110 | **************************************************************************************** |
---|
[17] | 111 | * @ gpt : pointer on the generic page table |
---|
[1] | 112 | * @ vpn : virtual page number of the target PTE. |
---|
[17] | 113 | * @ returns 0 if success / return ENOMEM or EINVAL if error. |
---|
[1] | 114 | ***************************************************************************************/ |
---|
| 115 | error_t hal_gpt_lock_pte( gpt_t * gpt, |
---|
| 116 | vpn_t vpn ); |
---|
| 117 | |
---|
| 118 | /**************************************************************************************** |
---|
| 119 | * This function releases the lock on a PTE identified by its VPN. |
---|
| 120 | **************************************************************************************** |
---|
[17] | 121 | * @ gpt : pointer on the generic page table |
---|
[1] | 122 | * @ vpn : virtual page number of the target PTE. |
---|
[17] | 123 | * @ returns 0 if success / returns EINVAL if error. |
---|
[1] | 124 | ***************************************************************************************/ |
---|
[17] | 125 | error_t hal_gpt_unlock_pte( gpt_t * gpt, |
---|
| 126 | vpn_t vpn ); |
---|
[1] | 127 | |
---|
| 128 | /**************************************************************************************** |
---|
[17] | 129 | * This function maps a page table entry identified by its VPN, from values defined |
---|
[1] | 130 | * by the ppn and attr arguments. It allocates physical memory for the local generic |
---|
| 131 | * page table itself if required. |
---|
| 132 | **************************************************************************************** |
---|
| 133 | * @ gpt : [in] pointer on the page table |
---|
| 134 | * @ vpn : [in] virtual page number |
---|
[17] | 135 | * @ ppn : [in] physical page number |
---|
[1] | 136 | * @ attr : [in] generic attributes |
---|
| 137 | * @ returns 0 if success / returns ENOMEM if error |
---|
| 138 | ***************************************************************************************/ |
---|
| 139 | error_t hal_gpt_set_pte( gpt_t * gpt, |
---|
| 140 | vpn_t vpn, |
---|
| 141 | ppn_t ppn, |
---|
| 142 | uint32_t attr ); |
---|
| 143 | |
---|
| 144 | /**************************************************************************************** |
---|
[17] | 145 | * This function unmaps a page table entry identified by its VPN. |
---|
| 146 | * If the calling thread is running in the reference cluster, it sends a broadcast RPC |
---|
| 147 | * to update all other page table copies. |
---|
[1] | 148 | **************************************************************************************** |
---|
| 149 | * @ gpt : [in] pointer on the page table |
---|
| 150 | * @ vpn : [in] virtual page number |
---|
| 151 | ***************************************************************************************/ |
---|
| 152 | void hal_gpt_reset_pte( gpt_t * gpt, |
---|
| 153 | vpn_t vpn ); |
---|
| 154 | |
---|
| 155 | /**************************************************************************************** |
---|
| 156 | * This function returns in the ppn and attr arguments the value of a page table |
---|
| 157 | * entry identified by its VPN. It returns attr == 0 if the page is not mapped. |
---|
| 158 | **************************************************************************************** |
---|
| 159 | * @ gpt : [in] pointer on the page table |
---|
| 160 | * @ vpn : [in] virtual page number |
---|
| 161 | * @ attr : [out] generic attributes |
---|
[17] | 162 | * @ ppn : [out] physical page number |
---|
[1] | 163 | ***************************************************************************************/ |
---|
| 164 | void hal_gpt_get_pte( gpt_t * gpt, |
---|
| 165 | vpn_t vpn, |
---|
| 166 | uint32_t * attr, |
---|
| 167 | ppn_t * ppn ); |
---|
[41] | 168 | |
---|
[23] | 169 | /**************************************************************************************** |
---|
[313] | 170 | * This function copies all valid entries from the source <src_gpt> to the <dst_gpt>. |
---|
[23] | 171 | * The <src_gpt> and the <dst_gpt> point on the same physical pages. |
---|
| 172 | * If the <cow> argument is true, the GPT_WRITABLE attribute is reset for all writable |
---|
| 173 | * entries in both <src_gpt> and <dst_gpt>, and the PG_COW flag is registered in all |
---|
| 174 | * writable physical page descriptors, to support the Copy-On-Write mechanism. |
---|
| 175 | **************************************************************************************** |
---|
| 176 | * @ dst_gpt : [in] pointer on the destination GPT. |
---|
| 177 | * @ src_gpt : [in] pointer on the source GPT. |
---|
| 178 | * @ cow : [in] activate the COPY-On-Write mechanism if true. |
---|
| 179 | ***************************************************************************************/ |
---|
| 180 | error_t hal_gpt_copy( gpt_t * dst_gpt, |
---|
| 181 | gpt_t * src_gpt, |
---|
| 182 | bool_t cow ); |
---|
[1] | 183 | |
---|
[17] | 184 | |
---|
[1] | 185 | #endif /* _GPT_H_ */ |
---|