diff --git a/arch/x86/guest/pm.c b/arch/x86/guest/pm.c index b3fa1bed1..8a32f425c 100644 --- a/arch/x86/guest/pm.c +++ b/arch/x86/guest/pm.c @@ -31,6 +31,7 @@ #include #include #include +#include int validate_pstate(struct vm *vm, uint64_t perf_ctl) { @@ -82,7 +83,35 @@ static void vm_setup_cpu_px(struct vm *vm) } +static void vm_setup_cpu_cx(struct vm *vm) +{ + uint32_t cx_data_size; + + vm->pm.cx_cnt = 0; + memset(vm->pm.cx_data, 0, MAX_CSTATE * sizeof(struct cpu_cx_data)); + + if ((!boot_cpu_data.state_info.cx_cnt) + || (!boot_cpu_data.state_info.cx_data)) { + return; + } + + ASSERT ((boot_cpu_data.state_info.cx_cnt <= MAX_CX_ENTRY), + "failed to setup cpu cx"); + + vm->pm.cx_cnt = boot_cpu_data.state_info.cx_cnt; + + cx_data_size = vm->pm.cx_cnt * sizeof(struct cpu_cx_data); + + /* please note pm.cx_data[0] is a empty space holder, + * pm.cx_data[1...MAX_CX_ENTRY] would be used to store cx entry datas. + */ + memcpy_s(vm->pm.cx_data + 1, cx_data_size, + boot_cpu_data.state_info.cx_data, cx_data_size); + +} + void vm_setup_cpu_state(struct vm *vm) { vm_setup_cpu_px(vm); + vm_setup_cpu_cx(vm); } diff --git a/include/arch/x86/guest/vm.h b/include/arch/x86/guest/vm.h index b766cd6f3..6de56460a 100644 --- a/include/arch/x86/guest/vm.h +++ b/include/arch/x86/guest/vm.h @@ -81,8 +81,10 @@ struct vm_sw_info { }; struct vm_pm_info { - uint8_t px_cnt; + uint8_t px_cnt; /* count of all Px states */ struct cpu_px_data px_data[MAX_PSTATE]; + uint8_t cx_cnt; /* count of all Cx entries */ + struct cpu_cx_data cx_data[MAX_CSTATE]; }; /* VM guest types */