Skip to content

Commit a28fbd1

Browse files
jsun26inteljren1
authored andcommitted
HV: load cpu px data in boot
The patch takes Intel ATOM A3960 as example that hard code all Px info which is needed for Px control into Acrn HV and load it in boot process. Signed-off-by: Victor Sun <victor.sun@intel.com> Acked-by: Kevin Tian <kevin.tian@intel.com>
1 parent 4cd2717 commit a28fbd1

File tree

6 files changed

+170
-0
lines changed

6 files changed

+170
-0
lines changed

hypervisor/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ C_SRCS += arch/x86/vmexit.c
104104
C_SRCS += arch/x86/vmx.c
105105
C_SRCS += arch/x86/assign.c
106106
C_SRCS += arch/x86/trusty.c
107+
C_SRCS += arch/x86/cpu_state_tbl.c
107108
C_SRCS += arch/x86/guest/vcpu.c
108109
C_SRCS += arch/x86/guest/vm.c
109110
C_SRCS += arch/x86/guest/instr_emul_wrapper.c

hypervisor/arch/x86/cpu.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <schedule.h>
3737
#include <version.h>
3838
#include <hv_debug.h>
39+
#include <cpu_state_tbl.h>
3940

4041
#ifdef CONFIG_EFI_STUB
4142
extern uint32_t efi_physical_available_ap_bitmap;
@@ -398,6 +399,8 @@ void bsp_boot_init(void)
398399

399400
get_cpu_name();
400401

402+
load_cpu_state_data();
403+
401404
/* Initialize the hypervisor paging */
402405
init_paging();
403406

hypervisor/arch/x86/cpu_state_tbl.c

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright (C) 2018 Intel Corporation. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
*
8+
* * Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* * Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in
12+
* the documentation and/or other materials provided with the
13+
* distribution.
14+
* * Neither the name of Intel Corporation nor the names of its
15+
* contributors may be used to endorse or promote products derived
16+
* from this software without specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
#include <hv_lib.h>
32+
#include <cpu.h>
33+
#include <acrn_common.h>
34+
#include <cpu_state_tbl.h>
35+
36+
/* The table includes cpu px info of Intel A3960 SoC */
37+
struct cpu_px_data px_a3960[] = {
38+
{0x960, 0, 0xA, 0xA, 0x1800, 0x1800}, /* P0 */
39+
{0x8FC, 0, 0xA, 0xA, 0x1700, 0x1700}, /* P1 */
40+
{0x898, 0, 0xA, 0xA, 0x1600, 0x1600}, /* P2 */
41+
{0x834, 0, 0xA, 0xA, 0x1500, 0x1500}, /* P3 */
42+
{0x7D0, 0, 0xA, 0xA, 0x1400, 0x1400}, /* P4 */
43+
{0x76C, 0, 0xA, 0xA, 0x1300, 0x1300}, /* P5 */
44+
{0x708, 0, 0xA, 0xA, 0x1200, 0x1200}, /* P6 */
45+
{0x6A4, 0, 0xA, 0xA, 0x1100, 0x1100}, /* P7 */
46+
{0x640, 0, 0xA, 0xA, 0x1000, 0x1000}, /* P8 */
47+
{0x5DC, 0, 0xA, 0xA, 0x0F00, 0x0F00}, /* P9 */
48+
{0x578, 0, 0xA, 0xA, 0x0E00, 0x0E00}, /* P10 */
49+
{0x514, 0, 0xA, 0xA, 0x0D00, 0x0D00}, /* P11 */
50+
{0x4B0, 0, 0xA, 0xA, 0x0C00, 0x0C00}, /* P12 */
51+
{0x44C, 0, 0xA, 0xA, 0x0B00, 0x0B00}, /* P13 */
52+
{0x3E8, 0, 0xA, 0xA, 0x0A00, 0x0A00}, /* P14 */
53+
{0x384, 0, 0xA, 0xA, 0x0900, 0x0900}, /* P15 */
54+
{0x320, 0, 0xA, 0xA, 0x0800, 0x0800} /* P16 */
55+
};
56+
57+
struct cpu_state_table cpu_state_tbl[] = {
58+
{"Intel(R) Atom(TM) Processor A3960 @ 1.90GHz", 17, px_a3960}
59+
};
60+
61+
static int get_state_tbl_idx(char *cpuname)
62+
{
63+
int i;
64+
int count = ARRAY_SIZE(cpu_state_tbl);
65+
66+
if (!cpuname) {
67+
return -1;
68+
}
69+
70+
for (i = 0; i < count; i++) {
71+
if (!strcmp((cpu_state_tbl[i].model_name),
72+
cpuname)) {
73+
return i;
74+
}
75+
}
76+
77+
return -1;
78+
}
79+
80+
void load_cpu_state_data(void)
81+
{
82+
int tbl_idx;
83+
84+
boot_cpu_data.px_cnt = 0;
85+
boot_cpu_data.px_data = NULL;
86+
87+
tbl_idx = get_state_tbl_idx(boot_cpu_data.model_name);
88+
if (tbl_idx < 0) {
89+
/* The state table is not found. */
90+
return;
91+
}
92+
93+
if (!((cpu_state_tbl + tbl_idx)->px_cnt)
94+
|| !((cpu_state_tbl + tbl_idx)->px_data)) {
95+
/* The state table must be wrong. */
96+
return;
97+
}
98+
99+
if ((cpu_state_tbl + tbl_idx)->px_cnt > MAX_PSTATE) {
100+
boot_cpu_data.px_cnt = MAX_PSTATE;
101+
} else {
102+
boot_cpu_data.px_cnt = (cpu_state_tbl + tbl_idx)->px_cnt;
103+
}
104+
105+
boot_cpu_data.px_data = (cpu_state_tbl + tbl_idx)->px_data;
106+
107+
}

hypervisor/include/arch/x86/cpu.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,14 @@ struct cpuinfo_x86 {
237237
uint64_t physical_address_mask;
238238
uint32_t cpuid_leaves[FEATURE_WORDS];
239239
char model_name[64];
240+
uint8_t px_cnt;
241+
struct cpu_px_data *px_data;
240242
};
241243

242244
extern struct cpuinfo_x86 boot_cpu_data;
243245

246+
#define MAX_PSTATE 20
247+
244248
/* Function prototypes */
245249
void cpu_halt(uint32_t logical_id);
246250
uint64_t cpu_cycles_per_second(void);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (C) 2018 Intel Corporation. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
*
8+
* * Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* * Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in
12+
* the documentation and/or other materials provided with the
13+
* distribution.
14+
* * Neither the name of Intel Corporation nor the names of its
15+
* contributors may be used to endorse or promote products derived
16+
* from this software without specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
#ifndef CPU_STATE_TBL_H
32+
#define CPU_STATE_TBL_H
33+
34+
struct cpu_state_table {
35+
char model_name[64];
36+
uint8_t px_cnt;
37+
struct cpu_px_data *px_data;
38+
};
39+
40+
void load_cpu_state_data(void);
41+
42+
#endif /* CPU_STATE_TBL_H */

hypervisor/include/public/acrn_common.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,19 @@ struct acrn_vm_pci_msix_remap {
288288
*/
289289
#define GUEST_CFG_OFFSET 0xd0000
290290

291+
/**
292+
* @brief Info The power state data of a VCPU.
293+
*
294+
*/
295+
struct cpu_px_data {
296+
uint64_t core_frequency; /* megahertz */
297+
uint64_t power; /* milliWatts */
298+
uint64_t transition_latency; /* microseconds */
299+
uint64_t bus_master_latency; /* microseconds */
300+
uint64_t control; /* control value */
301+
uint64_t status; /* success indicator */
302+
} __attribute__((aligned(8)));
303+
291304
/**
292305
* @}
293306
*/

0 commit comments

Comments
 (0)