| 1 | /* |
| 2 | * ========== Copyright Header Begin ========================================== |
| 3 | * |
| 4 | * Hypervisor Software File: vcpu.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 _VCPU_H |
| 50 | #define _VCPU_H |
| 51 | |
| 52 | #pragma ident "@(#)vcpu.h 1.10 07/07/09 SMI" |
| 53 | |
| 54 | #ifdef __cplusplus |
| 55 | extern "C" { |
| 56 | #endif |
| 57 | |
| 58 | #include <mmu.h> |
| 59 | #include <traps.h> |
| 60 | #include <resource.h> |
| 61 | #include <sun4v/traps.h> /* for MAXPTL */ |
| 62 | #include <resource.h> |
| 63 | #include <config.h> |
| 64 | #include <mau.h> |
| 65 | #include <cwq.h> |
| 66 | |
| 67 | /* |
| 68 | * Size of svc code's per-cpu scratch area in 64-bit words |
| 69 | */ |
| 70 | #define NSVCSCRATCHREGS 6 |
| 71 | |
| 72 | |
| 73 | /* |
| 74 | * Number of per-cpu scratch locations |
| 75 | */ |
| 76 | #define NCPUSCRATCH 8 |
| 77 | |
| 78 | |
| 79 | /* |
| 80 | * hvctl register save size |
| 81 | */ |
| 82 | #define REG_STORE_SZ (28 * 8) |
| 83 | |
| 84 | |
| 85 | #ifndef _ASM |
| 86 | |
| 87 | typedef struct vcpu vcpu_t; |
| 88 | typedef struct mau mau_t; |
| 89 | typedef struct cwq cwq_t; |
| 90 | typedef struct rng rng_t; |
| 91 | typedef struct vcpustate vcpustate_t; |
| 92 | |
| 93 | /* |
| 94 | * vcpu state information |
| 95 | */ |
| 96 | struct rwindow { |
| 97 | uint64_t ins[8]; |
| 98 | uint64_t outs[8]; |
| 99 | }; |
| 100 | |
| 101 | |
| 102 | struct vcpu_trapstate { |
| 103 | uint64_t tpc; |
| 104 | uint64_t tnpc; |
| 105 | uint64_t tstate; |
| 106 | uint64_t tt; |
| 107 | /* |
| 108 | * we preserve htstate for vcpu in case at some point |
| 109 | * we add new "hyperprivileged" features relevent |
| 110 | * to that vcpu - e.g. "trap on level zero" etc. |
| 111 | */ |
| 112 | uint64_t htstate; |
| 113 | }; |
| 114 | |
| 115 | typedef struct vcpu_trapstate vcpu_trapstate_t; |
| 116 | |
| 117 | struct vcpu_globals { |
| 118 | uint64_t g[7]; /* ignore g0 */ |
| 119 | }; |
| 120 | |
| 121 | typedef struct vcpu_globals vcpu_globals_t; |
| 122 | |
| 123 | struct vcpustate { |
| 124 | uint64_t tl; |
| 125 | vcpu_trapstate_t trapstack[MAXTL]; |
| 126 | uint64_t gl; |
| 127 | vcpu_globals_t globals[MAXGL]; |
| 128 | |
| 129 | uint64_t tba; |
| 130 | |
| 131 | uint64_t y; |
| 132 | uint64_t asi; |
| 133 | uint64_t softint; |
| 134 | uint64_t pil; |
| 135 | uint64_t gsr; |
| 136 | |
| 137 | uint64_t tick; |
| 138 | uint64_t stick; |
| 139 | uint64_t stickcompare; |
| 140 | |
| 141 | uint64_t scratchpad[8]; |
| 142 | |
| 143 | uint64_t cwp; |
| 144 | uint64_t wstate; |
| 145 | uint64_t cansave; |
| 146 | uint64_t canrestore; |
| 147 | uint64_t otherwin; |
| 148 | uint64_t cleanwin; |
| 149 | |
| 150 | struct rwindow wins[NWINDOWS]; |
| 151 | |
| 152 | uint16_t cpu_mondo_head; |
| 153 | uint16_t cpu_mondo_tail; |
| 154 | uint16_t dev_mondo_head; |
| 155 | uint16_t dev_mondo_tail; |
| 156 | uint16_t error_resumable_head; |
| 157 | uint16_t error_resumable_tail; |
| 158 | uint16_t error_nonresumable_head; |
| 159 | uint16_t error_nonresumable_tail; |
| 160 | }; |
| 161 | |
| 162 | /* |
| 163 | * Temp staging for info gleaned from MD node. |
| 164 | */ |
| 165 | typedef struct { |
| 166 | resource_t res; |
| 167 | int strand_id; |
| 168 | int vid; |
| 169 | int guestid; |
| 170 | int parttag; |
| 171 | } vcpu_parse_info_t; |
| 172 | |
| 173 | /* |
| 174 | * VCPU utilisation statistics |
| 175 | */ |
| 176 | typedef struct vcpu_util { |
| 177 | uint64_t stick_last; /* last time stats were read */ |
| 178 | volatile uint64_t yield_count; /* total yielded cycles */ |
| 179 | uint64_t yield_start; /* start of yield in progress */ |
| 180 | uint64_t last_yield_count_guest; /* previous guest yield count */ |
| 181 | uint64_t last_yield_count_vcpu; /* previous vcpu yield count */ |
| 182 | } vcpu_util_t; |
| 183 | |
| 184 | /* BEGIN CSTYLED */ |
| 185 | #if NVCPUS > 256 |
| 186 | error IDs for cpus in this HV use 8 bit values if you want more than |
| 187 | error 256 cpus you need to find all these and change to wider types |
| 188 | #endif |
| 189 | /* END CSTYLED */ |
| 190 | |
| 191 | /* |
| 192 | * This is the virtual cpu struct. There's one per virtual cpu. |
| 193 | */ |
| 194 | struct vcpu { |
| 195 | struct guest *guest; /* pointer to owning guest */ |
| 196 | struct config *root; |
| 197 | struct strand *strand; |
| 198 | uint32_t res_id; |
| 199 | uint8_t strand_slot; |
| 200 | uint8_t vid; /* virtual cpu number */ |
| 201 | uint8_t parttag; /* id to use for partition tag reg */ |
| 202 | uint64_t scr[NCPUSCRATCH]; /* scratch space */ |
| 203 | |
| 204 | /* |
| 205 | * Configuration and running status |
| 206 | */ |
| 207 | volatile uint64_t status; |
| 208 | vcpu_parse_info_t pip; |
| 209 | |
| 210 | /* |
| 211 | * Low-level mailbox |
| 212 | */ |
| 213 | uint64_t lastpoke; |
| 214 | uint64_t command; |
| 215 | uint64_t arg0; |
| 216 | uint64_t arg1; |
| 217 | uint64_t arg2; |
| 218 | uint64_t arg3; |
| 219 | uint64_t arg4; |
| 220 | uint64_t arg5; |
| 221 | uint64_t arg6; |
| 222 | uint64_t arg7; |
| 223 | uint64_t vintr; |
| 224 | |
| 225 | /* |
| 226 | * State |
| 227 | */ |
| 228 | uint64_t start_pc; |
| 229 | uint64_t start_arg; |
| 230 | uint64_t rtba; |
| 231 | uint64_t mmu_area; |
| 232 | uint64_t mmu_area_ra; |
| 233 | uint64_t cpuq_base; |
| 234 | uint64_t cpuq_size; |
| 235 | uint64_t cpuq_mask; |
| 236 | uint64_t cpuq_base_ra; |
| 237 | uint64_t devq_base; |
| 238 | uint64_t devq_size; |
| 239 | uint64_t devq_mask; |
| 240 | uint64_t devq_base_ra; |
| 241 | uint64_t devq_lock; |
| 242 | uint64_t devq_shdw_tail; |
| 243 | uint64_t errqnr_base; |
| 244 | uint64_t errqnr_size; |
| 245 | uint64_t errqnr_mask; |
| 246 | uint64_t errqnr_base_ra; |
| 247 | uint64_t errqr_base; |
| 248 | uint64_t errqr_size; |
| 249 | uint64_t errqr_mask; |
| 250 | uint64_t errqr_base_ra; |
| 251 | |
| 252 | /* |
| 253 | * Traptrace support |
| 254 | */ |
| 255 | uint64_t ttrace_offset; |
| 256 | uint64_t ttrace_buf_size; |
| 257 | uint64_t ttrace_buf_ra; |
| 258 | uint64_t ttrace_buf_pa; |
| 259 | |
| 260 | /* |
| 261 | * TSBs |
| 262 | */ |
| 263 | uint64_t ntsbs_ctx0; |
| 264 | uint64_t ntsbs_ctxn; |
| 265 | uint8_t tsbds_ctx0[MAX_NTSB * TSBD_BYTES]; |
| 266 | uint8_t tsbds_ctxn[MAX_NTSB * TSBD_BYTES]; |
| 267 | |
| 268 | /* |
| 269 | * MMU statistic support |
| 270 | */ |
| 271 | uint64_t mmustat_area; |
| 272 | uint64_t mmustat_area_ra; |
| 273 | |
| 274 | #ifdef CONFIG_CRYPTO |
| 275 | /* |
| 276 | * Crypto units |
| 277 | */ |
| 278 | mau_t *maup; |
| 279 | cwq_t *cwqp; |
| 280 | #endif |
| 281 | |
| 282 | rng_t *rng; |
| 283 | |
| 284 | #ifdef CONFIG_SVC |
| 285 | uint64_t svcregs[NSVCSCRATCHREGS]; |
| 286 | #endif |
| 287 | |
| 288 | /* |
| 289 | * LDC interrupt handling/delivery |
| 290 | */ |
| 291 | uint32_t ldc_intr_pend; /* pending flag for synchronization */ |
| 292 | uint64_t ldc_endpoint; /* target endpt structure */ |
| 293 | uint64_t ldc_sp_endpt; /* for save/restore around callbacks */ |
| 294 | uint64_t ldc_sp_arg; /* for save/restore around callbacks */ |
| 295 | uint64_t ldc_sp_arg_pc; /* for save/restore around callbacks */ |
| 296 | uint64_t ldc_cb_scr1; /* scratch reg used in callback */ |
| 297 | uint64_t ldc_cb_scr2; /* scratch reg used in callback */ |
| 298 | |
| 299 | /* |
| 300 | * Virtual CPU state save area |
| 301 | */ |
| 302 | struct vcpustate state_save_area; |
| 303 | uint8_t launch_with_retry; |
| 304 | |
| 305 | /* |
| 306 | * Utilisation statistics area |
| 307 | */ |
| 308 | uint64_t start_stick; |
| 309 | vcpu_util_t util; |
| 310 | }; |
| 311 | |
| 312 | extern vcpu_t vcpus[]; |
| 313 | |
| 314 | extern void init_vcpu(int id); |
| 315 | extern void reset_vcpu_state(vcpu_t *vp); |
| 316 | extern void c_desched_n_stop_vcpu(vcpu_t *vp); |
| 317 | |
| 318 | #endif /* !_ASM */ |
| 319 | |
| 320 | /* |
| 321 | * Per-vcpu low-level mailbox commands, see vcpu.command. |
| 322 | * |
| 323 | * Over time, the list of commands that use the vcpu mailbox |
| 324 | * has dwindled. Everything other than the cpu_mondo_send hcall |
| 325 | * has been converted to use the hvxcall mechanism. Once that |
| 326 | * has been modified to use hvxcalls as well, the vcpu mailbox |
| 327 | * can be removed in its entirety. |
| 328 | */ |
| 329 | #define CPU_CMD_READY 0x0 |
| 330 | #define CPU_CMD_BUSY 0x2 |
| 331 | #define CPU_CMD_GUESTMONDO_READY 0x3 |
| 332 | |
| 333 | #ifdef __cplusplus |
| 334 | } |
| 335 | #endif |
| 336 | |
| 337 | #endif /* _VCPU_H */ |