[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 | |
---|
| 37 | /********************************************************************************************** |
---|
| 38 | * This enum defines the vseg types |
---|
| 39 | *********************************************************************************************/ |
---|
| 40 | |
---|
| 41 | enum |
---|
| 42 | { |
---|
| 43 | VSEG_TYPE_CODE = 0, /*! executable code / private / localized */ |
---|
| 44 | VSEG_TYPE_DATA = 1, /*! initialized data / public / distributed */ |
---|
| 45 | VSEG_TYPE_HEAP = 2, /*! standard malloc / public / distributed */ |
---|
| 46 | VSEG_TYPE_STACK = 3, /*! execution stack / private / localized */ |
---|
| 47 | VSEG_TYPE_ANON = 4, /*! anonymous mmap / public / localized */ |
---|
| 48 | VSEG_TYPE_FILE = 5, /*! file mmap / public / localized */ |
---|
| 49 | VSEG_TYPE_REMOTE = 6, /*! remote mmap / public / localized */ |
---|
| 50 | VSEG_TYPE_KCODE = 7, /*! kernel code / private / localized */ |
---|
| 51 | VSEG_TYPE_KDATA = 8, /*! kernel data / private / localized */ |
---|
| 52 | VSEG_TYPE_KDEV = 9, /*! device segment / public / localized */ |
---|
| 53 | |
---|
| 54 | VSEG_TYPES_NR = 10, |
---|
| 55 | }; |
---|
| 56 | |
---|
| 57 | |
---|
| 58 | /********************************************************************************************** |
---|
[18] | 59 | * These masks define the vseg generic (hardware independent) flags. |
---|
[1] | 60 | *********************************************************************************************/ |
---|
| 61 | |
---|
| 62 | #define VSEG_USER 0x0001 /*! user accessible */ |
---|
| 63 | #define VSEG_WRITE 0x0002 /*! writeable */ |
---|
| 64 | #define VSEG_EXEC 0x0004 /*! executable */ |
---|
| 65 | #define VSEG_CACHE 0x0008 /*! cachable */ |
---|
| 66 | #define VSEG_PRIVATE 0x0010 /*! should not be accessed from another cluster */ |
---|
| 67 | #define VSEG_DISTRIB 0x0020 /*! physically distributed on all clusters */ |
---|
| 68 | |
---|
| 69 | /********************************************************************************************** |
---|
| 70 | * This structure defines a virtual segment descriptor. |
---|
| 71 | *********************************************************************************************/ |
---|
| 72 | |
---|
| 73 | typedef struct vseg_s |
---|
| 74 | { |
---|
| 75 | list_entry_t list; /*! all vsegs in same process / same free list if mmap */ |
---|
| 76 | struct vmm_s * vmm; /*! pointer on associated VM manager */ |
---|
| 77 | uint32_t type; /*! vseg type */ |
---|
| 78 | intptr_t min; /*! segment min virtual address */ |
---|
| 79 | intptr_t max; /*! segment max virtual address (excluded) */ |
---|
| 80 | vpn_t vpn_base; /*! first page of vseg */ |
---|
[18] | 81 | vpn_t vpn_size; /*! number of pages occupied */ |
---|
[1] | 82 | uint32_t flags; /*! vseg attributes */ |
---|
| 83 | xptr_t mapper; /*! extended pointer on associated mapper */ |
---|
| 84 | fdid_t fdid; /*! associated fdid for a VSEG_TYPE_FILE */ |
---|
| 85 | uint32_t offset; /*! offset in file for a VSEG_TYPE_FILE */ |
---|
| 86 | cxy_t cxy; /*! target cluster for physical mapping */ |
---|
| 87 | } |
---|
| 88 | vseg_t; |
---|
| 89 | |
---|
| 90 | /********************************************************************************************** |
---|
[101] | 91 | * This function returns a printable string for the vseg type. |
---|
| 92 | ********************************************************************************************** |
---|
| 93 | * @ vseg_type : type of vseg |
---|
| 94 | * @ return pointer on string |
---|
| 95 | *********************************************************************************************/ |
---|
| 96 | char * vseg_type_str( uint32_t vseg_type ); |
---|
| 97 | |
---|
| 98 | /********************************************************************************************** |
---|
[1] | 99 | * This function allocates physical memory for a new vseg descriptor from the local cluster |
---|
| 100 | * physical memory allocator. |
---|
| 101 | ********************************************************************************************** |
---|
| 102 | * @ return pointer on allocated vseg descriptor if success / return NULL if failure. |
---|
| 103 | *********************************************************************************************/ |
---|
| 104 | vseg_t * vseg_alloc(); |
---|
| 105 | |
---|
| 106 | /********************************************************************************************** |
---|
| 107 | * This function releases physical memory allocated for a vseg descriptor to the local cluster |
---|
| 108 | * physical memory allocator. |
---|
| 109 | ********************************************************************************************** |
---|
| 110 | * @ vseg : local pointer on released vseg descriptor. |
---|
| 111 | *********************************************************************************************/ |
---|
| 112 | void vseg_free( vseg_t * vseg ); |
---|
| 113 | |
---|
| 114 | /********************************************************************************************** |
---|
| 115 | * This function initializes a local vseg descriptor, from the arguments values. |
---|
| 116 | * It does NOT register the vseg in the local VMM. |
---|
| 117 | ********************************************************************************************** |
---|
| 118 | * @ vseg : pointer on the vseg descriptor. |
---|
| 119 | * @ base : vseg base address. |
---|
| 120 | * @ size : vseg size (bytes). |
---|
| 121 | * @ vpn_base : first page index. |
---|
| 122 | * @ vpn_size : number of pages. |
---|
| 123 | * @ type : vseg type. |
---|
| 124 | * @ cxy : target cluster for physical mapping. |
---|
| 125 | * @ fdid : file descriptor index if VSEG_TYPE_FILE. |
---|
| 126 | * @ offset : offset in file if VSEG_TYPE_FILE. |
---|
| 127 | *********************************************************************************************/ |
---|
| 128 | void vseg_init( vseg_t * vseg, |
---|
[18] | 129 | intptr_t base, |
---|
| 130 | intptr_t size, |
---|
[1] | 131 | vpn_t vpn_base, |
---|
| 132 | vpn_t vpn_size, |
---|
| 133 | uint32_t type, |
---|
| 134 | cxy_t cxy, |
---|
| 135 | fdid_t fdid, |
---|
| 136 | uint32_t offset ); |
---|
| 137 | |
---|
| 138 | /********************************************************************************************** |
---|
| 139 | * This function initializes a local vseg descriptor from values contained in a reference |
---|
| 140 | * remote vseg descriptor. It does NOT register the vseg in the local VMM. |
---|
| 141 | ********************************************************************************************** |
---|
| 142 | * @ vseg : pointer on the vseg descriptor. |
---|
[16] | 143 | * @ ref_xp : extended pointer on the reference vseg descriptor. |
---|
[1] | 144 | *********************************************************************************************/ |
---|
| 145 | void vseg_init_from_ref( vseg_t * vseg, |
---|
[16] | 146 | xptr_t ref_xp ); |
---|
[1] | 147 | |
---|
| 148 | /********************************************************************************************** |
---|
[18] | 149 | * This function adds a vseg descriptor in the set of vsegs controlled by a given VMM, |
---|
| 150 | * and updates the vmm field in the vseg descriptor. |
---|
[1] | 151 | * The lock protecting the vsegs list in VMM must be taken by the caller. |
---|
| 152 | ********************************************************************************************** |
---|
| 153 | * @ vmm : pointer on the VMM |
---|
| 154 | * @ vseg : pointer on the vseg descriptor |
---|
| 155 | * @ returns 0 if success / returns ENOMEM if failure. |
---|
| 156 | *********************************************************************************************/ |
---|
[18] | 157 | error_t vseg_attach( struct vmm_s * vmm, |
---|
[1] | 158 | vseg_t * vseg ); |
---|
| 159 | |
---|
| 160 | /********************************************************************************************** |
---|
[18] | 161 | * This function removes a vseg descriptor from the set of vsegs controlled by a given VMM, |
---|
| 162 | * and updates the vmm field in the vseg descriptor. No memory is released. |
---|
[1] | 163 | * The lock protecting the vsegs list in VMM must be taken by the caller. |
---|
| 164 | ********************************************************************************************** |
---|
| 165 | * @ vmm : pointer on the VMM |
---|
| 166 | * @ vseg : pointer on the vseg descriptor |
---|
| 167 | *********************************************************************************************/ |
---|
[18] | 168 | void vseg_detach( struct vmm_s * vmm, |
---|
[1] | 169 | vseg_t * vseg ); |
---|
| 170 | |
---|
| 171 | |
---|
| 172 | #endif /* _VSEG_H_ */ |
---|