mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-08-13 22:06:49 +00:00
hv: vcpuid: reduce the cyclomatic complexity of function guest_cpuid
This patch reduces the cyclomatic complexity of the function guest_cpuid. Tracked-On: #2834 Signed-off-by: Binbin Wu <binbin.wu@intel.com>
This commit is contained in:
parent
f0d06165d3
commit
ef19ed8961
@ -294,33 +294,16 @@ int32_t set_vcpuid_entries(struct acrn_vm *vm)
|
||||
return result;
|
||||
}
|
||||
|
||||
void guest_cpuid(struct acrn_vcpu *vcpu, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
|
||||
static inline bool is_percpu_related(uint32_t leaf)
|
||||
{
|
||||
uint32_t leaf = *eax;
|
||||
uint32_t subleaf = *ecx;
|
||||
|
||||
/* vm related */
|
||||
if ((leaf != 0x1U) && (leaf != 0xbU) && (leaf != 0xdU)) {
|
||||
const struct vcpuid_entry *entry = find_vcpuid_entry(vcpu, leaf, subleaf);
|
||||
|
||||
if (entry != NULL) {
|
||||
*eax = entry->eax;
|
||||
*ebx = entry->ebx;
|
||||
*ecx = entry->ecx;
|
||||
*edx = entry->edx;
|
||||
} else {
|
||||
*eax = 0U;
|
||||
*ebx = 0U;
|
||||
*ecx = 0U;
|
||||
*edx = 0U;
|
||||
return ((leaf == 0x1U) || (leaf == 0xbU) || (leaf == 0xdU));
|
||||
}
|
||||
} else {
|
||||
/* percpu related */
|
||||
switch (leaf) {
|
||||
case 0x01U:
|
||||
|
||||
static void guest_cpuid_01h(struct acrn_vcpu *vcpu, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
|
||||
{
|
||||
cpuid(leaf, eax, ebx, ecx, edx);
|
||||
uint32_t apicid = vlapic_get_apicid(vcpu_vlapic(vcpu));
|
||||
|
||||
cpuid(0x1U, eax, ebx, ecx, edx);
|
||||
/* Patching initial APIC ID */
|
||||
*ebx &= ~APIC_ID_MASK;
|
||||
*ebx |= (apicid << APIC_ID_SHIFT);
|
||||
@ -368,10 +351,13 @@ void guest_cpuid(struct acrn_vcpu *vcpu, uint32_t *eax, uint32_t *ebx, uint32_t
|
||||
|
||||
/* mask Debug Store feature */
|
||||
*edx &= ~CPUID_EDX_DTES;
|
||||
|
||||
break;
|
||||
}
|
||||
case 0x0bU:
|
||||
|
||||
static void guest_cpuid_0bh(struct acrn_vcpu *vcpu, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
|
||||
{
|
||||
uint32_t leaf = 0x0bU;
|
||||
uint32_t subleaf = *ecx;
|
||||
|
||||
/* Patching X2APIC */
|
||||
if (is_lapic_pt(vcpu->vm)) {
|
||||
/* for VM with LAPIC_PT, eg. PRE_LAUNCHED_VM or POST_LAUNCHED_VM with LAPIC_PT*/
|
||||
@ -404,16 +390,19 @@ void guest_cpuid(struct acrn_vcpu *vcpu, uint32_t *eax, uint32_t *ebx, uint32_t
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
static void guest_cpuid_0dh(__unused struct acrn_vcpu *vcpu, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
|
||||
{
|
||||
uint32_t subleaf = *ecx;
|
||||
|
||||
case 0x0dU:
|
||||
if (!pcpu_has_cap(X86_FEATURE_OSXSAVE)) {
|
||||
*eax = 0U;
|
||||
*ebx = 0U;
|
||||
*ecx = 0U;
|
||||
*edx = 0U;
|
||||
} else {
|
||||
cpuid_subleaf(leaf, subleaf, eax, ebx, ecx, edx);
|
||||
cpuid_subleaf(0x0dU, subleaf, eax, ebx, ecx, edx);
|
||||
if (subleaf == 0U) {
|
||||
/* SDM Vol.1 17-2, On processors that do not support Intel MPX,
|
||||
* CPUID.(EAX=0DH,ECX=0):EAX[3] and
|
||||
@ -422,6 +411,41 @@ void guest_cpuid(struct acrn_vcpu *vcpu, uint32_t *eax, uint32_t *ebx, uint32_t
|
||||
*eax &= ~ CPUID_EAX_XCR0_BNDCSR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void guest_cpuid(struct acrn_vcpu *vcpu, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
|
||||
{
|
||||
uint32_t leaf = *eax;
|
||||
uint32_t subleaf = *ecx;
|
||||
|
||||
/* vm related */
|
||||
if (!is_percpu_related(leaf)) {
|
||||
const struct vcpuid_entry *entry = find_vcpuid_entry(vcpu, leaf, subleaf);
|
||||
|
||||
if (entry != NULL) {
|
||||
*eax = entry->eax;
|
||||
*ebx = entry->ebx;
|
||||
*ecx = entry->ecx;
|
||||
*edx = entry->edx;
|
||||
} else {
|
||||
*eax = 0U;
|
||||
*ebx = 0U;
|
||||
*ecx = 0U;
|
||||
*edx = 0U;
|
||||
}
|
||||
} else {
|
||||
/* percpu related */
|
||||
switch (leaf) {
|
||||
case 0x01U:
|
||||
guest_cpuid_01h(vcpu, eax, ebx, ecx, edx);
|
||||
break;
|
||||
|
||||
case 0x0bU:
|
||||
guest_cpuid_0bh(vcpu, eax, ebx, ecx, edx);
|
||||
break;
|
||||
|
||||
case 0x0dU:
|
||||
guest_cpuid_0dh(vcpu, eax, ebx, ecx, edx);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user