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.


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