Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | /* |
2 | * ========== Copyright Header Begin ========================================== | |
3 | * | |
4 | * Hypervisor Software File: guest.h | |
5 | * | |
6 | * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
7 | * | |
8 | * - Do no alter or remove copyright notices | |
9 | * | |
10 | * - Redistribution and use of this software in source and binary forms, with | |
11 | * or without modification, are permitted provided that the following | |
12 | * conditions are met: | |
13 | * | |
14 | * - Redistribution of source code must retain the above copyright notice, | |
15 | * this list of conditions and the following disclaimer. | |
16 | * | |
17 | * - Redistribution in binary form must reproduce the above copyright notice, | |
18 | * this list of conditions and the following disclaimer in the | |
19 | * documentation and/or other materials provided with the distribution. | |
20 | * | |
21 | * Neither the name of Sun Microsystems, Inc. or the names of contributors | |
22 | * may be used to endorse or promote products derived from this software | |
23 | * without specific prior written permission. | |
24 | * | |
25 | * This software is provided "AS IS," without a warranty of any kind. | |
26 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, | |
27 | * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A | |
28 | * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN | |
29 | * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR | |
30 | * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR | |
31 | * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN | |
32 | * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR | |
33 | * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE | |
34 | * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, | |
35 | * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF | |
36 | * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. | |
37 | * | |
38 | * You acknowledge that this software is not designed, licensed or | |
39 | * intended for use in the design, construction, operation or maintenance of | |
40 | * any nuclear facility. | |
41 | * | |
42 | * ========== Copyright Header End ============================================ | |
43 | */ | |
44 | /* | |
45 | * Copyright 2007 Sun Microsystems, Inc. All rights reserved. | |
46 | * Use is subject to license terms. | |
47 | */ | |
48 | ||
49 | #ifndef _GUEST_H | |
50 | #define _GUEST_H | |
51 | ||
52 | #pragma ident "@(#)guest.h 1.58 07/06/04 SMI" | |
53 | ||
54 | #ifdef __cplusplus | |
55 | extern "C" { | |
56 | #endif | |
57 | ||
58 | #include <hypervisor.h> | |
59 | #include <sys/htypes.h> | |
60 | #include <vdev_console.h> | |
61 | #ifdef CONFIG_DISK | |
62 | #include <vdev_simdisk.h> | |
63 | #endif /* CONFIG_DISK */ | |
64 | ||
65 | #ifdef T1_FPGA_SNET | |
66 | #include <vdev_snet.h> | |
67 | #endif | |
68 | ||
69 | #include <ldc.h> | |
70 | #include <hvctl.h> | |
71 | #include <platform/guest.h> | |
72 | ||
73 | /* | |
74 | * This file contains definitions of the state structures for guests | |
75 | * and physical processors. | |
76 | */ | |
77 | ||
78 | /* | |
79 | * Value of MAX_LDC_CHANNELS arbitrary number for now, but must | |
80 | * kept in sync with Zeus PRI | |
81 | */ | |
82 | #define MAX_LDC_CHANNELS 256 | |
83 | ||
84 | /* | |
85 | * Value of MAX_LDC_INOS arbitrary number for now, but must | |
86 | * kept in sync with Zeus PRI | |
87 | */ | |
88 | #define MAX_LDC_INOS (2 * MAX_LDC_CHANNELS) | |
89 | ||
90 | /* | |
91 | * Various constants associated with the guest's API version | |
92 | * configuration. | |
93 | * | |
94 | * The guest's hcall table is an array of branch instructions. | |
95 | * Most of the API calls in the table are indexed by the FAST_TRAP | |
96 | * function number associated with the call. The last five | |
97 | * calls are indexed by unique indexes. Here's the overall | |
98 | * layout: | |
99 | * +-----------------------+ -- | |
100 | * | FAST_TRAP function #0 | \ | |
101 | * +-----------------------+ \ | |
102 | * | FAST_TRAP function #1 | \ | |
103 | * +-----------------------+ | | |
104 | * | ... | | | |
105 | * +-----------------------+ | | |
106 | * | MAX_FAST_TRAP_VALUE | | | |
107 | * +-----------------------+ \ | |
108 | * | DIAG_RA2PA_IDX | - NUM_API_CALLS | |
109 | * +-----------------------+ / | |
110 | * | DIAG_HEXEC_IDX | | | |
111 | * +-----------------------+ | | |
112 | * | MMU_MAP_ADDR_IDX | | | |
113 | * +-----------------------+ | | |
114 | * | MMU_UNMAP_ADDR_IDX | / | |
115 | * +-----------------------+ / | |
116 | * | TTRACE_ADDENTRY_IDX | / | |
117 | * +-----------------------+ -- | |
118 | * | |
119 | * Other important constants: | |
120 | * | |
121 | * NUM_API_GROUPS - The size of the "api_versions" table in the | |
122 | * guest structure. One more than the number of entries in the | |
123 | * table in hcall.s, to account for API_GROUP_SUN4V. | |
124 | * (defined in <platform/guest.h> ) | |
125 | * | |
126 | * API_ENTRY_SIZE_SHIFT - | |
127 | * API_ENTRY_SIZE - Size of one entry in the API table. Entries are | |
128 | * unconditional branch instructions, so they occupy 4 bytes. | |
129 | * | |
130 | * HCALL_TABLE_SIZE - Total size in bytes of the hcall table for one | |
131 | * guest. The size is rounded up to align to the L2$ line size. | |
132 | */ | |
133 | ||
134 | #define MAX_FAST_TRAP_VALUE 0x201 | |
135 | #define MMU_MAP_ADDR_IDX (MAX_FAST_TRAP_VALUE+1) | |
136 | #define MMU_UNMAP_ADDR_IDX (MAX_FAST_TRAP_VALUE+2) | |
137 | #define TTRACE_ADDENTRY_IDX (MAX_FAST_TRAP_VALUE+3) | |
138 | #define NUM_API_CALLS (MAX_FAST_TRAP_VALUE+4) | |
139 | ||
140 | #define API_ENTRY_SIZE_SHIFT SHIFT_LONG | |
141 | #define API_ENTRY_SIZE (1 << API_ENTRY_SIZE_SHIFT) | |
142 | ||
143 | /* | |
144 | * ROUNDUP - round "n" up to the next value for which | |
145 | * "(n & (align-1))" is zero. Only works if "align" is a power of | |
146 | * two. | |
147 | */ | |
148 | #define ROUNDUP(n, align) (((n) + (align) - 1) & ~((align)-1)) | |
149 | ||
150 | #define HCALL_TABLE_SIZE \ | |
151 | ROUNDUP(NUM_API_CALLS * API_ENTRY_SIZE, L2_LINE_SIZE) | |
152 | ||
153 | ||
154 | /* | |
155 | * Constants relating to the internal representation of version | |
156 | * numbers. | |
157 | */ | |
158 | #define MAJOR_OFF 0 | |
159 | #define MINOR_OFF 4 | |
160 | #define MAJOR_SHIFT 32 | |
161 | #define MAKE_VERSION(maj, min) (((maj)<<MAJOR_SHIFT)+(min)) | |
162 | ||
163 | ||
164 | #define NVCPU_XWORDS ((NVCPUS + 63) / 64) /* Num words for bit mask */ | |
165 | #define MAPPING_XWORD_SHIFT 6 | |
166 | #define MAPPING_XWORD_BYTE_SHIFT_BITS \ | |
167 | (MAPPING_XWORD_SHIFT-3) /* shift for num bytes in each XWORD */ | |
168 | #define MAPPING_XWORD_SIZE \ | |
169 | (1<<MAPPING_XWORD_BYTE_SHIFT_BITS) /* num bytes in each XWORD */ | |
170 | #define MAPPING_XWORD_MASK \ | |
171 | ((1<<MAPPING_XWORD_SHIFT)-1) /* Mask for bit index in XWORD */ | |
172 | ||
173 | /* | |
174 | * Internal guest states. | |
175 | */ | |
176 | #define GUEST_STATE_STOPPED 0x0 /* dead pending restart */ | |
177 | #define GUEST_STATE_RESETTING 0x1 /* in process of resetting */ | |
178 | #define GUEST_STATE_NORMAL 0x2 /* running normally */ | |
179 | #define GUEST_STATE_SUSPENDED 0x3 /* suspended pending migr. */ | |
180 | #define GUEST_STATE_EXITING 0x4 /* in process of exiting */ | |
181 | #define GUEST_STATE_UNCONFIGURED 0xff /* unused */ | |
182 | ||
183 | ||
184 | /* | |
185 | * Reasons for guest exit. | |
186 | */ | |
187 | #define GUEST_EXIT_STOP 0x1 | |
188 | #define GUEST_EXIT_MACH_EXIT 0x2 | |
189 | #define GUEST_EXIT_MACH_SIR 0x3 | |
190 | ||
191 | #ifndef _ASM | |
192 | ||
193 | typedef struct guest guest_t; | |
194 | ||
195 | /* | |
196 | * API group version information | |
197 | */ | |
198 | struct version { | |
199 | uint64_t version_num; | |
200 | void *verptr; | |
201 | }; | |
202 | ||
203 | ||
204 | struct guest_watchdog { | |
205 | uint64_t ticks; /* ticks of our heartbeat timer, not ms */ | |
206 | }; | |
207 | ||
208 | ||
209 | /* | |
210 | * Permanent mapping state | |
211 | */ | |
212 | struct mapping { | |
213 | union map_entry_aligned { | |
214 | /* | |
215 | * Force 16-byte alignment as VA and TTE are accessed via | |
216 | * quad load. | |
217 | */ | |
218 | struct map_data { | |
219 | uint64_t va; | |
220 | uint64_t tte; | |
221 | } _map_data; | |
222 | long double ld; | |
223 | } _map_entry_aligned; | |
224 | uint64_t icpuset[NVCPU_XWORDS]; | |
225 | uint64_t dcpuset[NVCPU_XWORDS]; | |
226 | }; | |
227 | ||
228 | ||
229 | /* | |
230 | * Utilisation statistics for the guest | |
231 | */ | |
232 | typedef struct guest_util { | |
233 | uint64_t stick_last; | |
234 | uint64_t stopped_cycles; | |
235 | } guest_util_t; | |
236 | ||
237 | ||
238 | struct guest { | |
239 | uint64_t guestid; | |
240 | /* FIXME: this configp is hardly used - remove it */ | |
241 | void *configp; /* global hv configuration */ | |
242 | ||
243 | uint32_t state; | |
244 | volatile uint64_t state_lock; /* protects guest state */ | |
245 | ||
246 | uint8_t soft_state; | |
247 | uint8_t soft_state_str[SOFT_STATE_SIZE]; | |
248 | ||
249 | volatile uint64_t soft_state_lock; /* protects soft state */ | |
250 | ||
251 | uint64_t real_base; /* base of real addr range */ | |
252 | /* | |
253 | * (N.B. limit/offset are required for MMU HWTW) | |
254 | */ | |
255 | uint64_t real_limit; /* limit real address range */ | |
256 | uint64_t mem_offset; /* real address range offset */ | |
257 | ||
258 | /* | |
259 | * ra2pa segments | |
260 | */ | |
261 | struct ra2pa_segment ra2pa_segment[NUM_RA2PA_SEGMENTS]; | |
262 | ||
263 | /* | |
264 | * mapin region - part of address space | |
265 | */ | |
266 | uint64_t ldc_mapin_basera; | |
267 | uint64_t ldc_mapin_size; | |
268 | ||
269 | /* | |
270 | * Permanent mappings | |
271 | */ | |
272 | uint64_t perm_mappings_lock; | |
273 | struct mapping perm_mappings[NPERMMAPPINGS]; | |
274 | #if PERMMAP_STATS | |
275 | uint64_t perm_mappings_count; | |
276 | #endif | |
277 | ||
278 | /* | |
279 | * Per-guest virtualized console state | |
280 | */ | |
281 | struct console console; | |
282 | ||
283 | /* | |
284 | * Misc. Guest state | |
285 | */ | |
286 | uint64_t tod_offset; | |
287 | uint64_t ttrace_freeze; | |
288 | ||
289 | /* | |
290 | * Static configuration data | |
291 | */ | |
292 | vcpu_t *vcpus[NVCPUS]; /* virtual cpu# index */ | |
293 | #ifdef CONFIG_CRYPTO | |
294 | mau_t *maus[NMAUS]; | |
295 | struct cwq *cwqs[NCWQS]; | |
296 | #endif /* CONFIG_CRYPTO */ | |
297 | ||
298 | /* | |
299 | * API version management information | |
300 | */ | |
301 | struct version api_groups[NUM_API_GROUPS]; | |
302 | uint64_t hcall_table; | |
303 | ||
304 | /* | |
305 | * Virtual devices | |
306 | */ | |
307 | uint8_t dev2inst[NDEVIDS]; | |
308 | struct vino2inst vino2inst; | |
309 | struct vdev_state vdev_state; | |
310 | ||
311 | /* | |
312 | * Partition description | |
313 | */ | |
314 | uint64_t md_pa; | |
315 | uint64_t md_size; | |
316 | ||
317 | /* | |
318 | * Debug | |
319 | */ | |
320 | uint64_t dumpbuf_pa; | |
321 | uint64_t dumpbuf_ra; | |
322 | uint64_t dumpbuf_size; | |
323 | ||
324 | /* | |
325 | * Startup configuration | |
326 | */ | |
327 | uint64_t entry; | |
328 | uint64_t rom_base; | |
329 | uint64_t rom_size; | |
330 | ||
331 | /* | |
332 | * Policy settings from Zeus | |
333 | */ | |
334 | uint64_t perfreg_accessible; | |
335 | uint64_t diagpriv; | |
336 | uint64_t reset_reason; | |
337 | uint64_t perfreght_accessible; | |
338 | uint64_t rng_ctl_accessible; | |
339 | ||
340 | /* | |
341 | * Watchdog configuration | |
342 | */ | |
343 | struct guest_watchdog watchdog; | |
344 | ||
345 | #ifdef CONFIG_DISK | |
346 | /* | |
347 | * Simulated disk | |
348 | */ | |
349 | struct hvdisk disk; | |
350 | #endif | |
351 | ||
352 | #ifdef T1_FPGA_SNET | |
353 | /* | |
354 | * Simulated/Simple network | |
355 | */ | |
356 | struct snet_info snet; | |
357 | #endif | |
358 | ||
359 | /* | |
360 | * LDC | |
361 | */ | |
362 | uint64_t ldc_max_channel_idx; /* legit LDC nos are this value */ | |
363 | uint64_t ldc_mapin_free_idx; | |
364 | ||
365 | struct ldc_endpoint ldc_endpoint[MAX_LDC_CHANNELS]; | |
366 | ||
367 | struct ldc_mapin ldc_mapin[LDC_NUM_MAPINS]; | |
368 | struct ldc_ino2endpoint ldc_ino2endpoint[MAX_LDC_INOS]; | |
369 | ||
370 | guest_parse_info_t pip; | |
371 | ||
372 | /* | |
373 | * Asycnhronous messaging | |
374 | */ | |
375 | uint8_t async_busy[HVctl_info_guest_max]; | |
376 | volatile uint64_t async_lock[HVctl_info_guest_max]; | |
377 | uint64_t async_buf[HVCTL_BUF_SIZE]; | |
378 | ||
379 | /* | |
380 | * Utilisation statistics | |
381 | */ | |
382 | uint64_t start_stick; | |
383 | guest_util_t util; | |
384 | ||
385 | /* | |
386 | * Device Management. | |
387 | */ | |
388 | uint64_t vdev_cfghandle; | |
389 | uint64_t cdev_cfghandle; | |
390 | ||
391 | struct machguest guest_m; | |
392 | }; | |
393 | ||
394 | ||
395 | extern guest_t guests[]; | |
396 | ||
397 | extern void init_guest(int); | |
398 | extern bool_t guest_ignition(guest_t *guestp); | |
399 | ||
400 | extern void reset_guest_perm_mappings(guest_t *guestp); | |
401 | extern void reset_api_hcall_table(guest_t *guestp); | |
402 | extern void reset_guest_ldc_mapins(guest_t *guestp); | |
403 | ||
404 | extern void init_ra2pa_segment(ra2pa_segment_t *rsp); | |
405 | extern void assign_ra2pa_segments(guest_t *guestp, uint64_t real_base, | |
406 | uint64_t size, uint64_t ra2pa_offset, uint8_t flags); | |
407 | extern void clear_ra2pa_segments(guest_t *guestp, uint64_t real_base, | |
408 | uint64_t size); | |
409 | ||
410 | extern void config_guest_md(guest_t *guestp); | |
411 | ||
412 | ||
413 | extern void config_a_guest_device_vino(guest_t *guestp, int ino, uint8_t type); | |
414 | extern void unconfig_a_guest_device_vino(guest_t *guestp, int ino, | |
415 | uint8_t type); | |
416 | extern void config_guest_virtual_device(guest_t *guestp, uint64_t cfg_handle); | |
417 | extern void unconfig_guest_virtual_device(guest_t *guestp); | |
418 | extern void config_guest_channel_device(guest_t *guestp, uint64_t cfg_handle); | |
419 | extern void unconfig_guest_channel_device(guest_t *guestp); | |
420 | ||
421 | #endif /* !_ASM */ | |
422 | ||
423 | #define INVALID_GID (-1) | |
424 | ||
425 | #define INVALID_CFGHANDLE 0xdeadbeef | |
426 | ||
427 | #ifdef __cplusplus | |
428 | } | |
429 | #endif | |
430 | ||
431 | #endif /* _GUEST_H */ |