1 |
/* |
2 |
* Cisco 7200 (Predator) simulation platform. |
3 |
* Copyright (c) 2005,2006 Christophe Fillot (cf@utc.fr) |
4 |
* |
5 |
* Virtual Machines. |
6 |
*/ |
7 |
|
8 |
#ifndef __VM_H__ |
9 |
#define __VM_H__ |
10 |
|
11 |
#include <pthread.h> |
12 |
|
13 |
#include "mips64.h" |
14 |
#include "dynamips.h" |
15 |
#include "memory.h" |
16 |
#include "cpu.h" |
17 |
#include "dev_vtty.h" |
18 |
|
19 |
#define VM_PCI_POOL_SIZE 32 |
20 |
|
21 |
/* VM instance status */ |
22 |
enum { |
23 |
VM_STATUS_HALTED = 0, /* VM is halted and no HW resources are used */ |
24 |
VM_STATUS_SHUTDOWN, /* Shutdown procedure engaged */ |
25 |
VM_STATUS_RUNNING, /* VM is running */ |
26 |
VM_STATUS_SUSPENDED, /* VM is suspended */ |
27 |
}; |
28 |
|
29 |
/* VM types */ |
30 |
enum { |
31 |
VM_TYPE_C7200 = 0, |
32 |
VM_TYPE_C3600, |
33 |
VM_TYPE_C2691, |
34 |
VM_TYPE_C3725, |
35 |
VM_TYPE_C3745, |
36 |
}; |
37 |
|
38 |
/* Ghost RAM status */ |
39 |
enum { |
40 |
VM_GHOST_RAM_NONE = 0, |
41 |
VM_GHOST_RAM_GENERATE, |
42 |
VM_GHOST_RAM_USE, |
43 |
}; |
44 |
|
45 |
/* Timer IRQ check interval */ |
46 |
#define VM_TIMER_IRQ_CHECK_ITV 1000 |
47 |
|
48 |
/* forward declarations */ |
49 |
typedef struct vm_obj vm_obj_t; |
50 |
|
51 |
/* Shutdown function prototype for an object */ |
52 |
typedef void *(*vm_shutdown_t)(vm_instance_t *vm,void *data); |
53 |
|
54 |
/* VM object, used to keep track of devices and various things */ |
55 |
struct vm_obj { |
56 |
char *name; |
57 |
void *data; |
58 |
struct vm_obj *next,**pprev; |
59 |
vm_shutdown_t shutdown; |
60 |
}; |
61 |
|
62 |
/* VM instance */ |
63 |
struct vm_instance { |
64 |
char *name; |
65 |
int type; /* C7200, C3600, ... */ |
66 |
int status; /* Instance status */ |
67 |
int instance_id; /* Instance Identifier */ |
68 |
char *lock_file; /* Lock file */ |
69 |
char *log_file; /* Log file */ |
70 |
u_int ram_size,rom_size; /* RAM and ROM size in Mb */ |
71 |
u_int iomem_size; /* IOMEM size in Mb */ |
72 |
u_int nvram_size; /* NVRAM size in Kb */ |
73 |
u_int pcmcia_disk_size[2]; /* PCMCIA disk0 and disk1 sizes (in Mb) */ |
74 |
u_int conf_reg,conf_reg_setup; /* Config register */ |
75 |
u_int clock_divisor; /* Clock Divisor (see cp0.c) */ |
76 |
u_int ram_mmap; /* Memory-mapped RAM ? */ |
77 |
u_int restart_ios; /* Restart IOS on reload ? */ |
78 |
u_int elf_machine_id; /* ELF machine identifier */ |
79 |
u_int exec_area_size; /* Size of execution area for CPU */ |
80 |
m_uint32_t ios_entry_point; /* IOS entry point */ |
81 |
char *ios_image; /* IOS image filename */ |
82 |
char *ios_config; /* IOS configuration file */ |
83 |
char *rom_filename; /* ROM filename */ |
84 |
char *sym_filename; /* Symbol filename */ |
85 |
FILE *lock_fd,*log_fd; /* Lock/Log file descriptors */ |
86 |
int debug_level; /* Debugging Level */ |
87 |
int jit_use; /* CPUs use JIT */ |
88 |
|
89 |
/* Basic hardware: system CPU, PCI busses and PCI I/O space */ |
90 |
cpu_group_t *cpu_group; |
91 |
cpu_mips_t *boot_cpu; |
92 |
struct pci_bus *pci_bus[2]; |
93 |
struct pci_bus *pci_bus_pool[VM_PCI_POOL_SIZE]; |
94 |
struct pci_io_data *pci_io_space; |
95 |
|
96 |
/* Memory mapped devices */ |
97 |
struct vdevice *dev_list; |
98 |
struct vdevice *dev_array[MIPS64_DEVICE_MAX]; |
99 |
|
100 |
/* Filename for ghosted RAM */ |
101 |
char *ghost_ram_filename; |
102 |
|
103 |
/* Ghost RAM image handling */ |
104 |
int ghost_status; |
105 |
|
106 |
/* "idling" pointer counter */ |
107 |
m_uint64_t idle_pc; |
108 |
|
109 |
/* Timer IRQ interval check */ |
110 |
u_int timer_irq_check_itv; |
111 |
|
112 |
/* Console and AUX port VTTY type and parameters */ |
113 |
int vtty_con_type,vtty_aux_type; |
114 |
int vtty_con_tcp_port,vtty_aux_tcp_port; |
115 |
vtty_serial_option_t vtty_con_serial_option,vtty_aux_serial_option; |
116 |
|
117 |
/* Virtual TTY for Console and AUX ports */ |
118 |
vtty_t *vtty_con,*vtty_aux; |
119 |
|
120 |
/* Space reserved in NVRAM by ROM monitor */ |
121 |
u_int nvram_rom_space; |
122 |
|
123 |
/* Extract and push IOS configuration */ |
124 |
ssize_t (*nvram_extract_config)(vm_instance_t *vm,char **buffer); |
125 |
int (*nvram_push_config)(vm_instance_t *vm,char *buffer,size_t len); |
126 |
|
127 |
/* Specific hardware data */ |
128 |
void *hw_data; |
129 |
|
130 |
/* VM objects */ |
131 |
struct vm_obj *vm_object_list; |
132 |
}; |
133 |
|
134 |
#define VM_C7200(vm) ((c7200_t *)vm->hw_data) |
135 |
#define VM_C3600(vm) ((c3600_t *)vm->hw_data) |
136 |
#define VM_C2691(vm) ((c2691_t *)vm->hw_data) |
137 |
#define VM_C3725(vm) ((c3725_t *)vm->hw_data) |
138 |
#define VM_C3745(vm) ((c3745_t *)vm->hw_data) |
139 |
|
140 |
extern int vm_file_naming_type; |
141 |
|
142 |
/* Initialize a VM object */ |
143 |
void vm_object_init(vm_obj_t *obj); |
144 |
|
145 |
/* Add a VM object to an instance */ |
146 |
void vm_object_add(vm_instance_t *vm,vm_obj_t *obj); |
147 |
|
148 |
/* Remove a VM object from an instance */ |
149 |
void vm_object_remove(vm_instance_t *vm,vm_obj_t *obj); |
150 |
|
151 |
/* Find an object given its name */ |
152 |
vm_obj_t *vm_object_find(vm_instance_t *vm,char *name); |
153 |
|
154 |
/* Check that a mandatory object is present */ |
155 |
int vm_object_check(vm_instance_t *vm,char *name); |
156 |
|
157 |
/* Dump the object list of an instance */ |
158 |
void vm_object_dump(vm_instance_t *vm); |
159 |
|
160 |
/* Get VM type */ |
161 |
char *vm_get_type(vm_instance_t *vm); |
162 |
|
163 |
/* Get MAC address MSB */ |
164 |
u_int vm_get_mac_addr_msb(vm_instance_t *vm); |
165 |
|
166 |
/* Generate a filename for use by the instance */ |
167 |
char *vm_build_filename(vm_instance_t *vm,char *name); |
168 |
|
169 |
/* Check that an instance lock file doesn't already exist */ |
170 |
int vm_get_lock(vm_instance_t *vm); |
171 |
|
172 |
/* Erase lock file */ |
173 |
void vm_release_lock(vm_instance_t *vm,int erase); |
174 |
|
175 |
/* Log a message */ |
176 |
void vm_flog(vm_instance_t *vm,char *module,char *format,va_list ap); |
177 |
|
178 |
/* Log a message */ |
179 |
void vm_log(vm_instance_t *vm,char *module,char *format,...); |
180 |
|
181 |
/* Close the log file */ |
182 |
int vm_close_log(vm_instance_t *vm); |
183 |
|
184 |
/* Create the log file */ |
185 |
int vm_create_log(vm_instance_t *vm); |
186 |
|
187 |
/* Error message */ |
188 |
void vm_error(vm_instance_t *vm,char *format,...); |
189 |
|
190 |
/* Create a new VM instance */ |
191 |
vm_instance_t *vm_create(char *name,int instance_id,int machine_type); |
192 |
|
193 |
/* Shutdown hardware resources used by a VM */ |
194 |
int vm_hardware_shutdown(vm_instance_t *vm); |
195 |
|
196 |
/* Free resources used by a VM */ |
197 |
void vm_free(vm_instance_t *vm); |
198 |
|
199 |
/* Get an instance given a name */ |
200 |
vm_instance_t *vm_acquire(char *name); |
201 |
|
202 |
/* Release a VM (decrement reference count) */ |
203 |
int vm_release(vm_instance_t *vm); |
204 |
|
205 |
/* Initialize RAM */ |
206 |
int vm_ram_init(vm_instance_t *vm,m_uint64_t paddr); |
207 |
|
208 |
/* Initialize VTTY */ |
209 |
int vm_init_vtty(vm_instance_t *vm); |
210 |
|
211 |
/* Delete VTTY */ |
212 |
void vm_delete_vtty(vm_instance_t *vm); |
213 |
|
214 |
/* Bind a device to a virtual machine */ |
215 |
int vm_bind_device(vm_instance_t *vm,struct vdevice *dev); |
216 |
|
217 |
/* Unbind a device from a virtual machine */ |
218 |
int vm_unbind_device(vm_instance_t *vm,struct vdevice *dev); |
219 |
|
220 |
/* Map a device at the specified physical address */ |
221 |
int vm_map_device(vm_instance_t *vm,struct vdevice *dev,m_uint64_t base_addr); |
222 |
|
223 |
/* Set an IRQ for a VM */ |
224 |
void vm_set_irq(vm_instance_t *vm,u_int irq); |
225 |
|
226 |
/* Clear an IRQ for a VM */ |
227 |
void vm_clear_irq(vm_instance_t *vm,u_int irq); |
228 |
|
229 |
/* Suspend a VM instance */ |
230 |
int vm_suspend(vm_instance_t *vm); |
231 |
|
232 |
/* Resume a VM instance */ |
233 |
int vm_resume(vm_instance_t *vm); |
234 |
|
235 |
/* Stop an instance */ |
236 |
int vm_stop(vm_instance_t *vm); |
237 |
|
238 |
/* Monitor an instance periodically */ |
239 |
void vm_monitor(vm_instance_t *vm); |
240 |
|
241 |
/* Open a VM file and map it in memory */ |
242 |
int vm_mmap_open_file(vm_instance_t *vm,char *name, |
243 |
u_char **ptr,off_t *fsize); |
244 |
|
245 |
/* Open/Create a VM file and map it in memory */ |
246 |
int vm_mmap_create_file(vm_instance_t *vm,char *name,size_t len,u_char **ptr); |
247 |
|
248 |
/* Close a memory mapped file */ |
249 |
int vm_mmap_close_file(int fd,u_char *ptr,size_t len); |
250 |
|
251 |
/* Save the Cisco IOS configuration from NVRAM */ |
252 |
int vm_ios_save_config(vm_instance_t *vm); |
253 |
|
254 |
/* Set Cisco IOS image to use */ |
255 |
int vm_ios_set_image(vm_instance_t *vm,char *ios_image); |
256 |
|
257 |
/* Unset a Cisco IOS configuration file */ |
258 |
void vm_ios_unset_config(vm_instance_t *vm); |
259 |
|
260 |
/* Set Cisco IOS configuration file to use */ |
261 |
int vm_ios_set_config(vm_instance_t *vm,char *ios_config); |
262 |
|
263 |
/* Extract IOS configuration from NVRAM and write it to a file */ |
264 |
int vm_nvram_extract_config(vm_instance_t *vm,char *filename); |
265 |
|
266 |
/* Read an IOS configuraton from a file and push it to NVRAM */ |
267 |
int vm_nvram_push_config(vm_instance_t *vm,char *filename); |
268 |
|
269 |
/* Save general VM configuration into the specified file */ |
270 |
void vm_save_config(vm_instance_t *vm,FILE *fd); |
271 |
|
272 |
#endif |