source: trunk/hal/tsar_mips32/hal_gpt.h @ 6

Last change on this file since 6 was 1, checked in by alain, 8 years ago

First import

File size: 8.9 KB
RevLine 
[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//
32// It is specified as a simple (one dimensionnal) array indexed by the VPN (vpn_t type),
33// even if implementations can use a more sophisticated organistion (two-levels or more).
34// - The number of entries (number of pages in a virtual space) is architecture
35//   dependant, 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,
37//   defined as masks on a 32 bits-vector.
38//
39// Any arch-specific implementation must implement this API.
40/////////////////////////////////////////////////////////////////////////////////////////
41
42/****  Forward declarations  ****/
43
44struct page_s;
45
46/****************************************************************************************
47 * These global variables defines the masks for the Generic Page Table Entry attributes.
48 * The actual values must be defined in the implementation (hal_gpt.c file).
49 ***************************************************************************************/
50
51extern uint32_t  GPT_MAPPED;         /*! PTE is mapepd                                 */
52extern uint32_t  GPT_SMALL;          /*! PTE is a small page                           */
53extern uint32_t  GPT_READABLE;       /*! PTE is readable                               */
54extern uint32_t  GPT_WRITABLE;       /*! PTE is writable                               */
55extern uint32_t  GPT_EXECUTABLE;     /*! PTE is executable                             */
56extern uint32_t  GPT_CACHABLE;       /*! PTE can be cached                             */
57extern uint32_t  GPT_USER;           /*! PTE is user accessible                        */
58extern uint32_t  GPT_DIRTY;          /*! PTE has been "recently" written               */
59extern uint32_t  GPT_ACCESSED;       /*! PTE has been "recently" accessed              */
60extern uint32_t  GPT_GLOBAL;         /*! PTE is kept in TLB at context swtch           */
61extern uint32_t  GPT_COW;            /*! PTE must be copied on write                   */
62extern uint32_t  GPT_SWAP;           /*! PTE swaped on disk (non implemented yet)      */
63extern uint32_t  GPT_LOCKED;         /*! PTE is protected against concurrent access    */
64
65/****************************************************************************************
66 * This structure define the Generic Page Table descriptor.
67 ***************************************************************************************/
68
69typedef struct gpt_s
70{
71        void           * ptr;    /*! pointer on GPT root (must be page aligned)            */
72        ppn_t            ppn;    /*! PPN of GPT root                                       */
73    struct page_s  * page;   /*! pointer on page descriptor for GPT root               */
74}
75gpt_t;
76
77
78/****************************************************************************************
79 * This function allocates physical memory for PT1 and initialize page table descriptor.
80 ****************************************************************************************
81 * @ gpt     : pointer on generic page table descriptor.
82 * @ returns 0 if success / returns ENOMEM if error.
83 ***************************************************************************************/
84error_t hal_gpt_create( gpt_t * gpt );
85
86/****************************************************************************************
87 * This function releases all memory dynamically allocated for a generic page table.
88 * For a multi-levels radix tree implementation, it includes all nodes in the tree.
89 * If the calling thread is running in the reference cluster, it checks that user PTE
90 * entries are unmapped, and release the mapped physical pages.
91 * The kernel pages are not released.
92 ****************************************************************************************
93 * @ gpt     : pointer on generic page table descriptor.
94 ***************************************************************************************/
95void hal_gpt_destroy( gpt_t * gpt);
96
97/****************************************************************************************
98 * This function print on the kernel terminal the content of a generic page table.
99 ****************************************************************************************
100 * @ gpt     : pointer on generic page table descriptor.
101 ***************************************************************************************/
102void hal_gpt_print( gpt_t * gpt);
103
104/****************************************************************************************
105 * This blocking fonction get a lock on a PTE (page Table Entry) identified
106 * by its VPN, and returns only when the PTE has been successfully locked.
107 * If the target PTE is not present, it allocates and map a physical page.
108 * A big page cannot be locked.
109 ****************************************************************************************
110 * @ gpt     : pointer on the generic page table
111 * @ vpn     : virtual page number of the target PTE.
112 * @ returns 0 if success / return ENOMEM or EINVAL if error. 
113 ***************************************************************************************/
114error_t hal_gpt_lock_pte( gpt_t * gpt,
115                          vpn_t   vpn );
116
117/****************************************************************************************
118 * This function releases the lock on a PTE identified by its VPN.
119 ****************************************************************************************
120 * @ gpt     : pointer on the generic page table
121 * @ vpn     : virtual page number of the target PTE.
122 * @ returns 0 if success / returns EINVAL if error. 
123 ***************************************************************************************/
124error_t hal_gpt_unlock_pte( gpt_t * gpt, 
125                            vpn_t   vpn ); 
126
127/****************************************************************************************
128 * This function map a page table entry identified by its VPN, from values defined
129 * by the ppn and attr arguments. It allocates physical memory for the local generic
130 * page table itself if required.
131 ****************************************************************************************
132 * @ gpt       : [in] pointer on the page table
133 * @ vpn       : [in] virtual page number
134 * @ ppn       : [in] physical page number
135 * @ attr      : [in] generic attributes
136 * @ returns 0 if success / returns ENOMEM if error
137 ***************************************************************************************/
138error_t hal_gpt_set_pte( gpt_t    * gpt,
139                         vpn_t      vpn,
140                         ppn_t      ppn,
141                         uint32_t   attr );
142
143/****************************************************************************************
144 * This function unmap a page table entry identified by its VPN.
145 * If the calling thread is running in the reference cluster, it send a broadcast RPC
146 * to update all others page table copies.
147 ****************************************************************************************
148 * @ gpt       : [in] pointer on the page table
149 * @ vpn       : [in] virtual page number
150 ***************************************************************************************/
151void hal_gpt_reset_pte( gpt_t * gpt,
152                        vpn_t   vpn );
153
154/****************************************************************************************
155 * This function returns in the ppn and attr arguments the value of a page table
156 * entry identified by its VPN.  It returns attr == 0 if the page is not mapped.
157 ****************************************************************************************
158 * @ gpt       : [in]  pointer on the page table
159 * @ vpn       : [in]  virtual page number
160 * @ attr      : [out] generic attributes
161 * @ ppn       : [out] physical page number
162 ***************************************************************************************/
163void hal_gpt_get_pte( gpt_t    * gpt,
164                      vpn_t      vpn,
165                      uint32_t * attr,
166                      ppn_t    * ppn );
167 
168
169#endif  /* _GPT_H_ */
Note: See TracBrowser for help on using the repository browser.