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.


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