Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Release 1.0
[palacios.git] / palacios / include / palacios / vmm_mem.h
1 /*
2  * This file is part of the Palacios Virtual Machine Monitor developed
3  * by the V3VEE Project with funding from the United States National 
4  * Science Foundation and the Department of Energy.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
10  * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu> 
11  * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
12  * All rights reserved.
13  *
14  * Author: Jack Lange <jarusl@cs.northwestern.edu>
15  *
16  * This is free software.  You are permitted to use,
17  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
18  */
19
20
21 #ifndef __VMM_MEM_H
22 #define __VMM_MEM_H
23
24
25 #ifdef __V3VEE__ 
26
27
28 #include <palacios/vmm_types.h>
29
30 #include <palacios/vmm_paging.h>
31
32 struct guest_info;
33
34
35 /*
36
37         Guest                  Shadow                 Host
38   Virtual   Physical    Virtual     Physical   Virtual     Physical
39                OK                      OK
40                OK                      NOK
41                NOK                     OK
42                NOK                     NOK
43
44 */
45
46 // These are the types of physical memory address regions
47 // from the perspective of the guest
48 typedef enum guest_region_type { 
49   GUEST_REGION_NOTHING, 
50   GUEST_REGION_PHYSICAL_MEMORY, 
51   GUEST_REGION_MEMORY_MAPPED_DEVICE} guest_region_type_t;
52
53 // These are the types of physical memory address regions
54 // from the perspective of the HOST
55 typedef enum host_region_type { 
56   HOST_REGION_INVALID,                    // This region is INVALID (this is a return type, to denote errors)
57   HOST_REGION_HOOK,                       // This region is mapped as not present (always generate page faults)
58   HOST_REGION_PHYSICAL_MEMORY,            // Region is a section of host memory
59   HOST_REGION_MEMORY_MAPPED_DEVICE,       // Region is allocated for DMA
60   HOST_REGION_UNALLOCATED,                // Region is mapped on demand
61   HOST_REGION_REMOTE,                     // Region is located on a remote machine
62   HOST_REGION_SWAPPED,                    // Region is swapped
63 } host_region_type_t;
64
65
66
67 #define shadow_mem_type_t host_region_type_t
68
69 struct shadow_region {
70   guest_region_type_t     guest_type;
71   addr_t                  guest_start; 
72   addr_t                  guest_end; 
73
74   host_region_type_t      host_type;
75   addr_t                  host_addr; // This either points to a host address mapping, 
76                                      // or a structure holding the map info 
77
78   struct shadow_region *next, *prev;
79 };
80
81
82
83 struct shadow_map {
84   uint_t num_regions;
85
86   struct shadow_region * head;
87 };
88
89
90 void init_shadow_region(struct shadow_region * entry,
91                            addr_t               guest_addr_start,
92                            addr_t               guest_addr_end,
93                            guest_region_type_t  guest_region_type,
94                            host_region_type_t   host_region_type);
95
96 /*
97 void init_shadow_region_physical(struct shadow_region * entry,
98                                     addr_t               guest_addr_start,
99                                     addr_t               guest_addr_end,
100                                     guest_region_type_t  guest_region_type,
101                                     addr_t               host_addr_start,
102                                     host_region_type_t   host_region_type);
103 */
104
105 int add_shadow_region_passthrough(struct guest_info * guest_info, 
106                                   addr_t guest_addr_start,
107                                   addr_t guest_addr_end,
108                                   addr_t host_addr);
109
110 void init_shadow_map(struct guest_info * info);
111 void free_shadow_map(struct shadow_map * map);
112
113 struct shadow_region * get_shadow_region_by_addr(struct shadow_map * map, addr_t guest_addr);
114
115 struct shadow_region * get_shadow_region_by_index(struct shadow_map * map, uint_t index);
116
117 host_region_type_t lookup_shadow_map_addr(struct shadow_map * map, addr_t guest_addr, addr_t * host_addr);
118
119 host_region_type_t get_shadow_addr_type(struct guest_info * info, addr_t guest_addr);
120 addr_t get_shadow_addr(struct guest_info * info, addr_t guest_addr);
121
122 // Semantics:
123 // Adding a region that overlaps with an existing region results is undefined
124 // and will probably fail
125 int add_shadow_region(struct shadow_map * map, struct shadow_region * entry);
126
127 // Semantics:
128 // Deletions result in splitting
129 int delete_shadow_region(struct shadow_map * map,
130                              addr_t guest_start, 
131                              addr_t guest_end);
132
133
134 void print_shadow_map(struct shadow_map * map);
135
136
137
138 struct vmm_mem_hook {
139   // Called when data is read from a memory page
140   int (*read)(addr_t guest_addr, void * dst, uint_t length, void * priv_data);
141   
142   // Called when data is written to a memory page
143   int (*write)(addr_t guest_addr, void * src, uint_t length, void * priv_data);
144
145   void * priv_data;
146   struct shadow_region * region;
147 };
148
149
150
151 struct vmm_mem_hook * get_mem_hook(struct guest_info * info, addr_t guest_addr);
152
153 int hook_guest_mem(struct guest_info * info, addr_t guest_addr_start, addr_t guest_addr_end,
154                    int (*read)(addr_t guest_addr, void * dst, uint_t length, void * priv_data),
155                    int (*write)(addr_t guest_addr, void * src, uint_t length, void * priv_data),
156                    void * priv_data);
157 int unhook_guest_mem(struct guest_info * info, addr_t guest_addr);
158
159
160
161
162 int handle_special_page_fault(struct guest_info * info, addr_t fault_addr, addr_t gp_addr, pf_error_t access_info);
163
164
165 #endif // ! __V3VEE__
166
167
168 #endif