[1] | 1 | /* |
---|
| 2 | * vseg.h - virtual segment (vseg) related operations |
---|
| 3 | * |
---|
| 4 | * Authors Ghassan Almaless (2008,2009,2010,2011, 2012) |
---|
| 5 | * Mohamed Lamine Karaoui (2015) |
---|
| 6 | * Alain Greiner (2016) |
---|
| 7 | * |
---|
| 8 | * Copyright (c) UPMC Sorbonne Universites |
---|
| 9 | * |
---|
| 10 | * This file is part of ALMOS-MKH. |
---|
| 11 | * |
---|
| 12 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
| 13 | * under the terms of the GNU General Public License as published by |
---|
| 14 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 15 | * |
---|
| 16 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
| 17 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 19 | * General Public License for more details. |
---|
| 20 | * |
---|
| 21 | * You should have received a copy of the GNU General Public License |
---|
| 22 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
| 23 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #ifndef _VSEG_H_ |
---|
| 27 | #define _VSEG_H_ |
---|
| 28 | |
---|
| 29 | #include <hal_types.h> |
---|
| 30 | #include <spinlock.h> |
---|
| 31 | #include <vfs.h> |
---|
| 32 | |
---|
| 33 | /**** Forward declarations ****/ |
---|
| 34 | |
---|
| 35 | struct vmm_s; |
---|
| 36 | |
---|
[409] | 37 | /******************************************************************************************* |
---|
[407] | 38 | * This enum defines the vseg types for an user process. |
---|
[409] | 39 | ***********************************************************************************VSEG*******/ |
---|
[1] | 40 | |
---|
[407] | 41 | typedef enum |
---|
[1] | 42 | { |
---|
[409] | 43 | VSEG_TYPE_CODE = 0, /*! executable user code / private / localized */ |
---|
| 44 | VSEG_TYPE_DATA = 1, /*! initialized user data / public / distributed */ |
---|
| 45 | VSEG_TYPE_STACK = 2, /*! execution user stack / private / localized */ |
---|
| 46 | VSEG_TYPE_ANON = 3, /*! anonymous mmap / public / localized */ |
---|
| 47 | VSEG_TYPE_FILE = 4, /*! file mmap / public / localized */ |
---|
| 48 | VSEG_TYPE_REMOTE = 5, /*! remote mmap / public / localized */ |
---|
[1] | 49 | |
---|
[407] | 50 | VSEG_TYPE_KDATA = 10, |
---|
| 51 | VSEG_TYPE_KCODE = 11, |
---|
| 52 | VSEG_TYPE_KDEV = 12, |
---|
| 53 | } |
---|
| 54 | vseg_type_t; |
---|
[1] | 55 | |
---|
| 56 | |
---|
[409] | 57 | /******************************************************************************************* |
---|
[18] | 58 | * These masks define the vseg generic (hardware independent) flags. |
---|
[409] | 59 | ******************************************************************************************/ |
---|
[1] | 60 | |
---|
[409] | 61 | #define VSEG_USER 0x0001 /*! user accessible */ |
---|
| 62 | #define VSEG_WRITE 0x0002 /*! writeable */ |
---|
| 63 | #define VSEG_EXEC 0x0004 /*! executable */ |
---|
| 64 | #define VSEG_CACHE 0x0008 /*! cachable */ |
---|
| 65 | #define VSEG_PRIVATE 0x0010 /*! should not be accessed from another cluster */ |
---|
| 66 | #define VSEG_DISTRIB 0x0020 /*! physically distributed on all clusters */ |
---|
| 67 | #define VSEG_IDENT 0x0040 /*! identity mapping */ |
---|
[1] | 68 | |
---|
[409] | 69 | /******************************************************************************************* |
---|
[1] | 70 | * This structure defines a virtual segment descriptor. |
---|
[408] | 71 | * - The VSL contains only local vsegs, but is implemented as an xlist, because it can be |
---|
| 72 | * accessed by thread running in a remote cluster. |
---|
| 73 | * - The zombi list is used by the local MMAP allocator. It is implemented as a local list. |
---|
[409] | 74 | ******************************************************************************************/ |
---|
[1] | 75 | |
---|
| 76 | typedef struct vseg_s |
---|
| 77 | { |
---|
[409] | 78 | xlist_entry_t xlist; /*! all vsegs in same VSL (or same zombi list) */ |
---|
| 79 | list_entry_t zlist; /*! all vsegs in same zombi list */ |
---|
| 80 | struct vmm_s * vmm; /*! pointer on associated VM manager */ |
---|
| 81 | uint32_t type; /*! vseg type */ |
---|
| 82 | intptr_t min; /*! segment min virtual address */ |
---|
| 83 | intptr_t max; /*! segment max virtual address (excluded) */ |
---|
| 84 | vpn_t vpn_base; /*! first page of vseg */ |
---|
| 85 | vpn_t vpn_size; /*! number of pages occupied */ |
---|
| 86 | uint32_t flags; /*! vseg attributes */ |
---|
| 87 | xptr_t mapper_xp; /*! xptr on remote mapper (for types CODE/DATA/FILE) */ |
---|
| 88 | intptr_t file_offset; /*! vseg offset in file (for types CODE/DATA/FILE */ |
---|
| 89 | intptr_t file_size; /*! max segment size in mapper (for type CODE/DATA) */ |
---|
| 90 | cxy_t cxy; /*! physical mapping (for non distributed vseg) */ |
---|
[1] | 91 | } |
---|
| 92 | vseg_t; |
---|
| 93 | |
---|
[409] | 94 | /******************************************************************************************* |
---|
[101] | 95 | * This function returns a printable string for the vseg type. |
---|
[409] | 96 | ******************************************************************************************* |
---|
[101] | 97 | * @ vseg_type : type of vseg |
---|
| 98 | * @ return pointer on string |
---|
[409] | 99 | ******************************************************************************************/ |
---|
[101] | 100 | char * vseg_type_str( uint32_t vseg_type ); |
---|
| 101 | |
---|
[409] | 102 | /******************************************************************************************* |
---|
[1] | 103 | * This function allocates physical memory for a new vseg descriptor from the local cluster |
---|
| 104 | * physical memory allocator. |
---|
[409] | 105 | ******************************************************************************************* |
---|
[1] | 106 | * @ return pointer on allocated vseg descriptor if success / return NULL if failure. |
---|
[409] | 107 | ******************************************************************************************/ |
---|
[1] | 108 | vseg_t * vseg_alloc(); |
---|
| 109 | |
---|
[409] | 110 | /******************************************************************************************* |
---|
| 111 | * This function releases the physical memory allocated for a vseg descriptor |
---|
| 112 | * to the local cluster physical memory allocator. |
---|
| 113 | ******************************************************************************************* |
---|
[1] | 114 | * @ vseg : local pointer on released vseg descriptor. |
---|
[409] | 115 | ******************************************************************************************/ |
---|
[1] | 116 | void vseg_free( vseg_t * vseg ); |
---|
| 117 | |
---|
[409] | 118 | /******************************************************************************************* |
---|
[1] | 119 | * This function initializes a local vseg descriptor, from the arguments values. |
---|
| 120 | * It does NOT register the vseg in the local VMM. |
---|
[409] | 121 | ******************************************************************************************* |
---|
[1] | 122 | * @ vseg : pointer on the vseg descriptor. |
---|
| 123 | * @ base : vseg base address. |
---|
| 124 | * @ size : vseg size (bytes). |
---|
| 125 | * @ vpn_base : first page index. |
---|
| 126 | * @ vpn_size : number of pages. |
---|
| 127 | * @ type : vseg type. |
---|
| 128 | * @ cxy : target cluster for physical mapping. |
---|
[409] | 129 | ******************************************************************************************/ |
---|
[1] | 130 | void vseg_init( vseg_t * vseg, |
---|
[407] | 131 | vseg_type_t type, |
---|
[18] | 132 | intptr_t base, |
---|
[407] | 133 | uint32_t size, |
---|
[1] | 134 | vpn_t vpn_base, |
---|
| 135 | vpn_t vpn_size, |
---|
[407] | 136 | uint32_t file_offset, |
---|
| 137 | uint32_t file_size, |
---|
| 138 | xptr_t mapper_xp, |
---|
[315] | 139 | cxy_t cxy ); |
---|
[1] | 140 | |
---|
[409] | 141 | /******************************************************************************************* |
---|
[1] | 142 | * This function initializes a local vseg descriptor from values contained in a reference |
---|
| 143 | * remote vseg descriptor. It does NOT register the vseg in the local VMM. |
---|
[409] | 144 | ******************************************************************************************* |
---|
[1] | 145 | * @ vseg : pointer on the vseg descriptor. |
---|
[16] | 146 | * @ ref_xp : extended pointer on the reference vseg descriptor. |
---|
[409] | 147 | ******************************************************************************************/ |
---|
[1] | 148 | void vseg_init_from_ref( vseg_t * vseg, |
---|
[16] | 149 | xptr_t ref_xp ); |
---|
[1] | 150 | |
---|
[409] | 151 | /******************************************************************************************* |
---|
[18] | 152 | * This function adds a vseg descriptor in the set of vsegs controlled by a given VMM, |
---|
| 153 | * and updates the vmm field in the vseg descriptor. |
---|
[1] | 154 | * The lock protecting the vsegs list in VMM must be taken by the caller. |
---|
[409] | 155 | ******************************************************************************************* |
---|
[1] | 156 | * @ vmm : pointer on the VMM |
---|
| 157 | * @ vseg : pointer on the vseg descriptor |
---|
[409] | 158 | ******************************************************************************************/ |
---|
[406] | 159 | void vseg_attach( struct vmm_s * vmm, |
---|
| 160 | vseg_t * vseg ); |
---|
[1] | 161 | |
---|
[409] | 162 | /******************************************************************************************* |
---|
[18] | 163 | * This function removes a vseg descriptor from the set of vsegs controlled by a given VMM, |
---|
| 164 | * and updates the vmm field in the vseg descriptor. No memory is released. |
---|
[1] | 165 | * The lock protecting the vsegs list in VMM must be taken by the caller. |
---|
[409] | 166 | ******************************************************************************************* |
---|
[1] | 167 | * @ vmm : pointer on the VMM |
---|
| 168 | * @ vseg : pointer on the vseg descriptor |
---|
[409] | 169 | ******************************************************************************************/ |
---|
[18] | 170 | void vseg_detach( struct vmm_s * vmm, |
---|
[1] | 171 | vseg_t * vseg ); |
---|
| 172 | |
---|
| 173 | |
---|
| 174 | #endif /* _VSEG_H_ */ |
---|