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,2017,2018,2019) |
---|
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_kernel_types.h> |
---|
30 | #include <vfs.h> |
---|
31 | |
---|
32 | /**** Forward declarations ****/ |
---|
33 | |
---|
34 | struct vmm_s; |
---|
35 | |
---|
36 | /******************************************************************************************* |
---|
37 | * This enum defines the vseg types. |
---|
38 | * Note : the KDATA and KDEV types are not used by the TSAR HAL, because the accesses |
---|
39 | * to kernel data or kernel devices are done through the DATA extension address |
---|
40 | * register, but these types are probably required by the I86 HAL [AG]. |
---|
41 | ******************************************************************************************/ |
---|
42 | |
---|
43 | typedef enum |
---|
44 | { |
---|
45 | VSEG_TYPE_CODE = 0, /*! executable user code / private / localized */ |
---|
46 | VSEG_TYPE_DATA = 1, /*! initialized user data / public / distributed */ |
---|
47 | VSEG_TYPE_STACK = 2, /*! execution user stack / private / localized */ |
---|
48 | VSEG_TYPE_ANON = 3, /*! anonymous mmap / public / localized */ |
---|
49 | VSEG_TYPE_FILE = 4, /*! file mmap / public / localized */ |
---|
50 | VSEG_TYPE_REMOTE = 5, /*! remote mmap / public / localized */ |
---|
51 | |
---|
52 | VSEG_TYPE_KCODE = 6, /*! executable kernel code / private / localized */ |
---|
53 | VSEG_TYPE_KDATA = 7, /*! initialized kernel data / private / localized */ |
---|
54 | VSEG_TYPE_KDEV = 8, /*! kernel peripheral device / public / localized */ |
---|
55 | } |
---|
56 | vseg_type_t; |
---|
57 | |
---|
58 | |
---|
59 | /******************************************************************************************* |
---|
60 | * These masks define the vseg generic (hardware independent) flags. |
---|
61 | ******************************************************************************************/ |
---|
62 | |
---|
63 | #define VSEG_USER 0x0001 /*! user accessible */ |
---|
64 | #define VSEG_WRITE 0x0002 /*! writeable */ |
---|
65 | #define VSEG_EXEC 0x0004 /*! executable */ |
---|
66 | #define VSEG_CACHE 0x0008 /*! cachable */ |
---|
67 | #define VSEG_PRIVATE 0x0010 /*! should not be accessed from another cluster */ |
---|
68 | #define VSEG_DISTRIB 0x0020 /*! physically distributed on all clusters */ |
---|
69 | |
---|
70 | /******************************************************************************************* |
---|
71 | * This structure defines a virtual segment descriptor. |
---|
72 | * - The VSL contains only local vsegs, but is implemented as an xlist, because it can be |
---|
73 | * accessed by thread running in a remote cluster. |
---|
74 | * - The zombi list is used by the local MMAP allocator. It is implemented as a local list. |
---|
75 | ******************************************************************************************/ |
---|
76 | |
---|
77 | typedef struct vseg_s |
---|
78 | { |
---|
79 | xlist_entry_t xlist; /*! all vsegs in same VSL */ |
---|
80 | list_entry_t zlist; /*! all vsegs in same zombi list */ |
---|
81 | struct vmm_s * vmm; /*! pointer on associated VM manager */ |
---|
82 | uint32_t type; /*! vseg type */ |
---|
83 | intptr_t min; /*! segment min virtual address */ |
---|
84 | intptr_t max; /*! segment max virtual address (excluded) */ |
---|
85 | vpn_t vpn_base; /*! first page of vseg */ |
---|
86 | vpn_t vpn_size; /*! number of pages occupied */ |
---|
87 | uint32_t flags; /*! vseg attributes */ |
---|
88 | xptr_t mapper_xp; /*! xptr on remote mapper (for types CODE/DATA/FILE) */ |
---|
89 | intptr_t file_offset; /*! vseg offset in file (for types CODE/DATA/FILE) */ |
---|
90 | intptr_t file_size; /*! max segment size in mapper (for type CODE/DATA) */ |
---|
91 | cxy_t cxy; /*! physical mapping (for non distributed vseg) */ |
---|
92 | } |
---|
93 | vseg_t; |
---|
94 | |
---|
95 | /******************************************************************************************* |
---|
96 | * This function returns a printable string for the vseg type. |
---|
97 | ******************************************************************************************* |
---|
98 | * @ vseg_type : type of vseg |
---|
99 | * @ return pointer on string |
---|
100 | ******************************************************************************************/ |
---|
101 | char * vseg_type_str( uint32_t vseg_type ); |
---|
102 | |
---|
103 | /******************************************************************************************* |
---|
104 | * This function allocates physical memory for a new vseg descriptor from the local cluster |
---|
105 | * physical memory allocator. |
---|
106 | ******************************************************************************************* |
---|
107 | * @ return pointer on allocated vseg descriptor if success / return NULL if failure. |
---|
108 | ******************************************************************************************/ |
---|
109 | vseg_t * vseg_alloc( void ); |
---|
110 | |
---|
111 | /******************************************************************************************* |
---|
112 | * This function releases the physical memory allocated for a vseg descriptor |
---|
113 | * to the local cluster physical memory allocator. |
---|
114 | ******************************************************************************************* |
---|
115 | * @ vseg : local pointer on released vseg descriptor. |
---|
116 | ******************************************************************************************/ |
---|
117 | void vseg_free( vseg_t * vseg ); |
---|
118 | |
---|
119 | /******************************************************************************************* |
---|
120 | * This function initializes a local vseg descriptor, from the arguments values. |
---|
121 | * It does NOT register the vseg in the local VMM. |
---|
122 | ******************************************************************************************* |
---|
123 | * @ vseg : pointer on the vseg descriptor. |
---|
124 | * @ base : vseg base address. |
---|
125 | * @ size : vseg size (bytes). |
---|
126 | * @ vpn_base : first page index. |
---|
127 | * @ vpn_size : number of pages. |
---|
128 | * @ type : vseg type. |
---|
129 | * @ cxy : target cluster for physical mapping. |
---|
130 | ******************************************************************************************/ |
---|
131 | void vseg_init( vseg_t * vseg, |
---|
132 | vseg_type_t type, |
---|
133 | intptr_t base, |
---|
134 | uint32_t size, |
---|
135 | vpn_t vpn_base, |
---|
136 | vpn_t vpn_size, |
---|
137 | uint32_t file_offset, |
---|
138 | uint32_t file_size, |
---|
139 | xptr_t mapper_xp, |
---|
140 | cxy_t cxy ); |
---|
141 | |
---|
142 | /******************************************************************************************* |
---|
143 | * This function initializes a local vseg descriptor from values contained in a reference |
---|
144 | * remote vseg descriptor. It does NOT register the vseg in the local VMM. |
---|
145 | ******************************************************************************************* |
---|
146 | * @ vseg : pointer on the vseg descriptor. |
---|
147 | * @ ref_xp : extended pointer on the reference vseg descriptor. |
---|
148 | ******************************************************************************************/ |
---|
149 | void vseg_init_from_ref( vseg_t * vseg, |
---|
150 | xptr_t ref_xp ); |
---|
151 | |
---|
152 | |
---|
153 | #endif /* _VSEG_H_ */ |
---|