Skip to content

Commit c885011

Browse files
mgcaodbkinder
authored andcommitted
HV: add main vcpu API comments for document
This patch adds comments to the main public functions of vCPU in the hypervisor. The comments are in doxygen-style for document generation. Tracked-On: #1595 Signed-off-by: Minggui Cao <minggui.cao@intel.com>
1 parent 277c933 commit c885011

File tree

2 files changed

+281
-5
lines changed

2 files changed

+281
-5
lines changed

hypervisor/include/arch/x86/guest/vcpu.h

Lines changed: 278 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
* SPDX-License-Identifier: BSD-3-Clause
55
*/
66

7+
/**
8+
* @file vcpu.h
9+
*
10+
* @brief public APIs for vcpu operations
11+
*/
12+
713
#ifndef VCPU_H
814
#define VCPU_H
915

@@ -48,6 +54,13 @@
4854

4955
#include <guest.h>
5056

57+
/**
58+
* @brief vcpu
59+
*
60+
* @defgroup acrn_vcpu ACRN vcpu
61+
* @{
62+
*/
63+
5164
enum vcpu_state {
5265
VCPU_INIT,
5366
VCPU_RUNNING,
@@ -71,12 +84,15 @@ struct segment_sel {
7184
uint32_t attr;
7285
};
7386

87+
/**
88+
* @brief registers info saved for vcpu running context
89+
*/
7490
struct run_context {
7591
/* Contains the guest register set.
7692
* NOTE: This must be the first element in the structure, so that the offsets
7793
* in vmx_asm.S match
7894
*/
79-
union {
95+
union guest_cpu_regs_t {
8096
struct acrn_gp_regs regs;
8197
uint64_t longs[NUM_GPRS];
8298
} guest_cpu_regs;
@@ -266,26 +282,207 @@ vcpu_vlapic(struct vcpu *vcpu)
266282
}
267283

268284
/* External Interfaces */
285+
286+
/**
287+
* @brief get vcpu register value
288+
*
289+
* Get target vCPU's general purpose registers value in run_context.
290+
*
291+
* @param[in] vcpu pointer to vcpu data structure
292+
* @param[in] reg register of the vcpu
293+
*
294+
* @return the value of the register.
295+
*/
269296
uint64_t vcpu_get_gpreg(const struct vcpu *vcpu, uint32_t reg);
297+
298+
/**
299+
* @brief set vcpu register value
300+
*
301+
* Set target vCPU's general purpose registers value in run_context.
302+
*
303+
* @param[inout] vcpu pointer to vcpu data structure
304+
* @param[in] reg register of the vcpu
305+
* @param[in] val the value set the register of the vcpu
306+
*/
270307
void vcpu_set_gpreg(struct vcpu *vcpu, uint32_t reg, uint64_t val);
308+
309+
/**
310+
* @brief get vcpu RIP value
311+
*
312+
* Get & cache target vCPU's RIP in run_context.
313+
*
314+
* @param[in] vcpu pointer to vcpu data structure
315+
*
316+
* @return the value of RIP.
317+
*/
271318
uint64_t vcpu_get_rip(struct vcpu *vcpu);
319+
320+
/**
321+
* @brief set vcpu RIP value
322+
*
323+
* Update target vCPU's RIP in run_context.
324+
*
325+
* @param[inout] vcpu pointer to vcpu data structure
326+
* @param[in] val the value set RIP
327+
*/
272328
void vcpu_set_rip(struct vcpu *vcpu, uint64_t val);
329+
330+
/**
331+
* @brief get vcpu RSP value
332+
*
333+
* Get & cache target vCPU's RSP in run_context.
334+
*
335+
* @param[in] vcpu pointer to vcpu data structure
336+
*
337+
* @return the value of RSP.
338+
*/
273339
uint64_t vcpu_get_rsp(struct vcpu *vcpu);
340+
341+
/**
342+
* @brief set vcpu RSP value
343+
*
344+
* Update target vCPU's RSP in run_context.
345+
*
346+
* @param[inout] vcpu pointer to vcpu data structure
347+
* @param[in] val the value set RSP
348+
*/
274349
void vcpu_set_rsp(struct vcpu *vcpu, uint64_t val);
350+
351+
/**
352+
* @brief get vcpu EFER value
353+
*
354+
* Get & cache target vCPU's EFER in run_context.
355+
*
356+
* @param[in] vcpu pointer to vcpu data structure
357+
*
358+
* @return the value of EFER.
359+
*/
275360
uint64_t vcpu_get_efer(struct vcpu *vcpu);
361+
362+
/**
363+
* @brief set vcpu EFER value
364+
*
365+
* Update target vCPU's EFER in run_context.
366+
*
367+
* @param[inout] vcpu pointer to vcpu data structure
368+
* @param[in] val the value set EFER
369+
*/
276370
void vcpu_set_efer(struct vcpu *vcpu, uint64_t val);
371+
372+
/**
373+
* @brief get vcpu RFLAG value
374+
*
375+
* Get & cache target vCPU's RFLAGS in run_context.
376+
*
377+
* @param[in] vcpu pointer to vcpu data structure
378+
*
379+
* @return the value of RFLAGS.
380+
*/
277381
uint64_t vcpu_get_rflags(struct vcpu *vcpu);
382+
383+
/**
384+
* @brief set vcpu RFLAGS value
385+
*
386+
* Update target vCPU's RFLAGS in run_context.
387+
*
388+
* @param[inout] vcpu pointer to vcpu data structure
389+
* @param[in] val the value set RFLAGS
390+
*/
278391
void vcpu_set_rflags(struct vcpu *vcpu, uint64_t val);
392+
393+
/**
394+
* @brief get vcpu CR0 value
395+
*
396+
* Get & cache target vCPU's CR0 in run_context.
397+
*
398+
* @param[in] vcpu pointer to vcpu data structure
399+
*
400+
* @return the value of CR0.
401+
*/
279402
uint64_t vcpu_get_cr0(struct vcpu *vcpu);
403+
404+
/**
405+
* @brief set vcpu CR0 value
406+
*
407+
* Update target vCPU's CR0 in run_context.
408+
*
409+
* @param[inout] vcpu pointer to vcpu data structure
410+
* @param[in] val the value set CR0
411+
*/
280412
void vcpu_set_cr0(struct vcpu *vcpu, uint64_t val);
413+
414+
/**
415+
* @brief get vcpu CR2 value
416+
*
417+
* Get & cache target vCPU's CR2 in run_context.
418+
*
419+
* @param[in] vcpu pointer to vcpu data structure
420+
*
421+
* @return the value of CR2.
422+
*/
281423
uint64_t vcpu_get_cr2(struct vcpu *vcpu);
424+
425+
/**
426+
* @brief set vcpu CR2 value
427+
*
428+
* Update target vCPU's CR2 in run_context.
429+
*
430+
* @param[inout] vcpu pointer to vcpu data structure
431+
* @param[in] val the value set CR2
432+
*/
282433
void vcpu_set_cr2(struct vcpu *vcpu, uint64_t val);
434+
435+
/**
436+
* @brief get vcpu CR4 value
437+
*
438+
* Get & cache target vCPU's CR4 in run_context.
439+
*
440+
* @param[in] vcpu pointer to vcpu data structure
441+
*
442+
* @return the value of CR4.
443+
*/
283444
uint64_t vcpu_get_cr4(struct vcpu *vcpu);
445+
446+
/**
447+
* @brief set vcpu CR4 value
448+
*
449+
* Update target vCPU's CR4 in run_context.
450+
*
451+
* @param[inout] vcpu pointer to vcpu data structure
452+
* @param[in] val the value set CR4
453+
*/
284454
void vcpu_set_cr4(struct vcpu *vcpu, uint64_t val);
455+
285456
uint64_t vcpu_get_pat_ext(const struct vcpu *vcpu);
286457
void vcpu_set_pat_ext(struct vcpu *vcpu, uint64_t val);
458+
459+
/**
460+
* @brief set all the vcpu registers
461+
*
462+
* Update target vCPU's all registers in run_context.
463+
*
464+
* @param[inout] vcpu pointer to vcpu data structure
465+
* @param[in] vcpu_regs all the registers' value
466+
*/
287467
void set_vcpu_regs(struct vcpu *vcpu, struct acrn_vcpu_regs *vcpu_regs);
468+
469+
/**
470+
* @brief reset all the vcpu registers
471+
*
472+
* Reset target vCPU's all registers in run_context to initial values.
473+
*
474+
* @param[inout] vcpu pointer to vcpu data structure
475+
*/
288476
void reset_vcpu_regs(struct vcpu *vcpu);
477+
478+
/**
479+
* @brief set the vcpu AP entry
480+
*
481+
* Set target vCPU's AP running entry in run_context.
482+
*
483+
* @param[inout] vcpu pointer to vcpu data structure
484+
* @param[in] entry the entry value for AP
485+
*/
289486
void set_ap_entry(struct vcpu *vcpu, uint64_t entry);
290487

291488
static inline bool is_long_mode(struct vcpu *vcpu)
@@ -304,26 +501,102 @@ static inline bool is_pae(struct vcpu *vcpu)
304501
}
305502

306503
struct vcpu* get_ever_run_vcpu(uint16_t pcpu_id);
504+
505+
/**
506+
* @brief create a vcpu for the target vm
507+
*
508+
* Creates/allocates a vCPU instance, with initialization for its vcpu_id,
509+
* vpid, vmcs, vlapic, etc. It sets the init vCPU state to VCPU_INIT
510+
*
511+
* @param[in] pcpu_id created vcpu will run on this pcpu
512+
* @param[in] vm pointer to vm data structure, this vcpu will owned by this vm.
513+
* @param[out] rtn_vcpu_handle pointer to the created vcpu
514+
*
515+
* @return 0: vcpu created successfully, other values failed.
516+
*/
307517
int create_vcpu(uint16_t pcpu_id, struct vm *vm, struct vcpu **rtn_vcpu_handle);
308-
/*
309-
* @pre vcpu != NULL
518+
519+
/**
520+
* @brief run into non-root mode based on vcpu setting
521+
*
522+
* An interface in vCPU thread to implement VM entry and VM exit.
523+
* A CPU switches between VMX root mode and non-root mode based on it.
524+
*
525+
* @param[inout] vcpu pointer to vcpu data structure
526+
* @pre vcpu != NULL
527+
*
528+
* @return 0: vcpu run successfully, other values failed.
310529
*/
311530
int run_vcpu(struct vcpu *vcpu);
531+
312532
int shutdown_vcpu(struct vcpu *vcpu);
313-
/*
314-
* @pre vcpu != NULL
533+
534+
/**
535+
* @brief unmap the vcpu with pcpu and free its vlapic
536+
*
537+
* Unmap the vcpu with pcpu and free its vlapic, and set the vcpu state to offline
538+
*
539+
* @param[inout] vcpu pointer to vcpu data structure
540+
* @pre vcpu != NULL
315541
*/
316542
void offline_vcpu(struct vcpu *vcpu);
317543

544+
/**
545+
* @brief reset vcpu state and values
546+
*
547+
* Reset all fields in a vCPU instance, the vCPU state is reset to VCPU_INIT.
548+
*
549+
* @param[inout] vcpu pointer to vcpu data structure
550+
*/
318551
void reset_vcpu(struct vcpu *vcpu);
552+
553+
/**
554+
* @brief pause the vcpu and set new state
555+
*
556+
* Change a vCPU state to VCPU_PAUSED or VCPU_ZOMBIE, and make a reschedule request for it.
557+
*
558+
* @param[inout] vcpu pointer to vcpu data structure
559+
* @param[in] new_state the state to set vcpu
560+
*/
319561
void pause_vcpu(struct vcpu *vcpu, enum vcpu_state new_state);
562+
563+
/**
564+
* @brief resume the vcpu
565+
*
566+
* Change a vCPU state to VCPU_RUNNING, and make a reschedule request for it.
567+
*
568+
* @param[inout] vcpu pointer to vcpu data structure
569+
*/
320570
void resume_vcpu(struct vcpu *vcpu);
571+
572+
/**
573+
* @brief set the vcpu to running state, then it will be scheculed.
574+
*
575+
* Adds a vCPU into the run queue and make a reschedule request for it. It sets the vCPU state to VCPU_RUNNING.
576+
*
577+
* @param[inout] vcpu pointer to vcpu data structure
578+
*/
321579
void schedule_vcpu(struct vcpu *vcpu);
580+
581+
/**
582+
* @brief create a vcpu for the vm and mapped to the pcpu.
583+
*
584+
* Create a vcpu for the vm, and mapped to the pcpu.
585+
*
586+
* @param[inout] vm pointer to vm data structure
587+
* @param[in] pcpu_id which the vcpu will be mapped
588+
*/
322589
int prepare_vcpu(struct vm *vm, uint16_t pcpu_id);
323590

324591
void request_vcpu_pre_work(struct vcpu *vcpu, uint16_t pre_work_id);
325592

326593
void vcpu_dumpreg(void *data);
594+
595+
/**
596+
* @}
597+
*/
598+
/* End of acrn_vcpu */
599+
327600
#endif /* ASSEMBLER */
328601

329602
#endif /* VCPU_H */

hypervisor/include/public/acrn_common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ struct acrn_descriptor_ptr {
280280
uint16_t reserved[3]; /* align struct size to 64bit */
281281
} __attribute__((packed));
282282

283+
/**
284+
* @brief registers info for vcpu.
285+
*/
283286
struct acrn_vcpu_regs {
284287
struct acrn_gp_regs gprs;
285288
struct acrn_descriptor_ptr gdt;

0 commit comments

Comments
 (0)