1 /*
2  * Copyright (C) 2018-2022 Intel Corporation.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef VCR_H
8 #define VCR_H
9 
10 /**
11  * @file virtual_cr.h
12  *
13  * @brief public APIs for vCR operations
14  */
15 uint64_t get_cr4_reserved_bits(void);
16 void init_cr0_cr4_host_guest_mask(void);
17 
18 /**
19  * @brief vCR from vcpu
20  *
21  * @defgroup vCR ACRN
22  * @{
23  */
24 
25 /**
26  * @brief get vcpu CR0 value
27  *
28  * Get & cache target vCPU's CR0 in run_context.
29  *
30  * @param[in] vcpu pointer to vcpu data structure
31  *
32  * @return the value of CR0.
33  */
34 uint64_t vcpu_get_cr0(struct acrn_vcpu *vcpu);
35 
36 /**
37  * @brief set vcpu CR0 value
38  *
39  * Update target vCPU's CR0 in run_context.
40  *
41  * @param[inout] vcpu pointer to vcpu data structure
42  * @param[in] val the value set CR0
43  */
44 void vcpu_set_cr0(struct acrn_vcpu *vcpu, uint64_t val);
45 
46 /**
47  * @brief get vcpu CR2 value
48  *
49  * Get & cache target vCPU's CR2 in run_context.
50  *
51  * @param[in] vcpu pointer to vcpu data structure
52  *
53  * @return the value of CR2.
54  */
55 uint64_t vcpu_get_cr2(const struct acrn_vcpu *vcpu);
56 
57 /**
58  * @brief set vcpu CR2 value
59  *
60  * Update target vCPU's CR2 in run_context.
61  *
62  * @param[inout] vcpu pointer to vcpu data structure
63  * @param[in] val the value set CR2
64  */
65 void vcpu_set_cr2(struct acrn_vcpu *vcpu, uint64_t val);
66 
67 /**
68  * @brief get vcpu CR4 value
69  *
70  * Get & cache target vCPU's CR4 in run_context.
71  *
72  * @param[in] vcpu pointer to vcpu data structure
73  *
74  * @return the value of CR4.
75  */
76 uint64_t vcpu_get_cr4(struct acrn_vcpu *vcpu);
77 
78 /**
79  * @brief set vcpu CR4 value
80  *
81  * Update target vCPU's CR4 in run_context.
82  *
83  * @param[inout] vcpu pointer to vcpu data structure
84  * @param[in] val the value set CR4
85  */
86 void vcpu_set_cr4(struct acrn_vcpu *vcpu, uint64_t val);
87 
88 /**
89  * @}
90  */
91 /* End of vCR */
92 
93 int32_t cr_access_vmexit_handler(struct acrn_vcpu *vcpu);
94 
95 #endif /* VCR_H */
96