source: trunk/kernel/mm/vseg.h @ 485

Last change on this file since 485 was 473, checked in by alain, 6 years ago

Fix several GCC warning related to the -Wextra compilation option.

File size: 8.8 KB
RevLine 
[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
[457]29#include <hal_kernel_types.h>
[1]30#include <spinlock.h>
31#include <vfs.h>
32
33/****  Forward declarations  ****/
34
35struct vmm_s;
36
[409]37/*******************************************************************************************
[407]38 * This enum defines the vseg types for an user process.
[409]39 ***********************************************************************************VSEG*******/
[1]40
[407]41typedef 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       */
[407]49}
50vseg_type_t;
[1]51
52
[409]53/*******************************************************************************************
[18]54 * These masks define the vseg generic (hardware independent) flags.
[409]55 ******************************************************************************************/
[1]56
[409]57#define VSEG_USER     0x0001       /*! user accessible                                    */
58#define VSEG_WRITE    0x0002       /*! writeable                                          */
59#define VSEG_EXEC     0x0004       /*! executable                                         */
60#define VSEG_CACHE    0x0008       /*! cachable                                           */
61#define VSEG_PRIVATE  0x0010       /*! should not be accessed from another cluster        */
62#define VSEG_DISTRIB  0x0020       /*! physically distributed on all clusters             */
63#define VSEG_IDENT    0x0040       /*! identity mapping                                   */
[1]64
[409]65/*******************************************************************************************
[1]66 * This structure defines a virtual segment descriptor.
[408]67 * - The VSL contains only local vsegs, but is implemented as an xlist, because it can be
68 *   accessed by thread running in a remote cluster.
69 * - The zombi list is used by the local MMAP allocator. It is implemented as a local list.
[409]70 ******************************************************************************************/
[1]71
72typedef struct vseg_s
73{
[454]74    xlist_entry_t     xlist;        /*! all vsegs in same VSL (or same zombi list)        */
75    list_entry_t      zlist;        /*! all vsegs in same zombi list                      */
76    struct vmm_s    * vmm;          /*! pointer on associated VM manager                  */
[409]77    uint32_t          type;         /*! vseg type                                         */
[454]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                                */
81    vpn_t             vpn_size;     /*! number of pages occupied                          */
82    uint32_t          flags;        /*! vseg attributes                                   */
83    xptr_t            mapper_xp;    /*! xptr on remote mapper (for types CODE/DATA/FILE)  */
84    intptr_t          file_offset;  /*! vseg offset in file (for types CODE/DATA/FILE)    */
[409]85    intptr_t          file_size;    /*! max segment size in mapper (for type CODE/DATA)   */
86    cxy_t             cxy;          /*! physical mapping (for non distributed vseg)       */ 
[1]87}
88vseg_t;
89
[409]90/*******************************************************************************************
[101]91 * This function returns a printable string for the vseg type.
[409]92 *******************************************************************************************
[101]93 * @ vseg_type  : type of vseg
94 * @ return pointer on string
[409]95 ******************************************************************************************/
[101]96char * vseg_type_str( uint32_t vseg_type );
97
[409]98/*******************************************************************************************
[1]99 * This function allocates physical memory for a new vseg descriptor from the local cluster
100 * physical memory allocator.
[409]101 *******************************************************************************************
[1]102 * @ return pointer on allocated vseg descriptor if success / return NULL if failure.
[409]103 ******************************************************************************************/
[1]104vseg_t * vseg_alloc();
105
[409]106/*******************************************************************************************
107 * This function releases the physical memory allocated for a vseg descriptor
108 * to the local cluster physical memory allocator.
109 *******************************************************************************************
[1]110 * @ vseg   : local pointer on released vseg descriptor.
[409]111 ******************************************************************************************/
[1]112void vseg_free( vseg_t * vseg );
113
[409]114/*******************************************************************************************
[1]115 * This function initializes a local vseg descriptor, from the arguments values.
116 * It does NOT register the vseg in the local VMM.
[409]117 *******************************************************************************************
[1]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.
[409]125 ******************************************************************************************/
[1]126void vseg_init( vseg_t      * vseg,
[407]127                    vseg_type_t   type,
[18]128                intptr_t      base,
[407]129                    uint32_t      size,
[1]130                vpn_t         vpn_base,
131                vpn_t         vpn_size,
[407]132                uint32_t      file_offset,
133                uint32_t      file_size,
134                xptr_t        mapper_xp,
[315]135                cxy_t         cxy );
[1]136
[409]137/*******************************************************************************************
[1]138 * This function initializes a local vseg descriptor from values contained in a reference
139 * remote vseg descriptor. It does NOT register the vseg in the local VMM.
[409]140 *******************************************************************************************
[1]141 * @ vseg      : pointer on the vseg descriptor.
[16]142 * @ ref_xp    : extended pointer on the reference vseg descriptor.
[409]143 ******************************************************************************************/
[1]144void vseg_init_from_ref( vseg_t * vseg,
[16]145                         xptr_t   ref_xp );
[1]146
[409]147/*******************************************************************************************
[18]148 * This function adds a vseg descriptor in the set of vsegs controlled by a given VMM,
149 * and updates the vmm field in the vseg descriptor.
[1]150 * The lock protecting the vsegs list in VMM must be taken by the caller.
[409]151 *******************************************************************************************
[1]152 * @ vmm       : pointer on the VMM
153 * @ vseg      : pointer on the vseg descriptor
[409]154 ******************************************************************************************/
[406]155void vseg_attach( struct vmm_s  * vmm,
156                  vseg_t        * vseg );
[1]157
[409]158/*******************************************************************************************
[18]159 * This function removes a vseg descriptor from the set of vsegs controlled by a given VMM,
160 * and updates the vmm field in the vseg descriptor. No memory is released.
[1]161 * The lock protecting the vsegs list in VMM must be taken by the caller.
[409]162 *******************************************************************************************
[1]163 * @ vseg      : pointer on the vseg descriptor
[409]164 ******************************************************************************************/
[473]165void vseg_detach( vseg_t        * vseg );
[1]166
167
168#endif /* _VSEG_H_ */
Note: See TracBrowser for help on using the repository browser.