coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
acpi.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <types.h>
4 #include <console/console.h>
5 #include <acpi/acpi.h>
6 #include <acpi/acpigen.h>
7 #include <arch/cpu.h>
8 #include <cpu/x86/msr.h>
9 #include <cpu/intel/speedstep.h>
10 #include <cpu/intel/turbo.h>
11 #include <device/device.h>
12 #include "model_2065x.h"
13 #include "chip.h"
14 
15 static int get_cores_per_package(void)
16 {
17  struct cpuinfo_x86 c;
18  struct cpuid_result result;
19  int cores = 1;
20 
21  get_fms(&c, cpuid_eax(1));
22  if (c.x86 != 6)
23  return 1;
24 
25  result = cpuid_ext(0xb, 1);
26  cores = result.ebx & 0xff;
27 
28  return cores;
29 }
30 
31 static void generate_C_state_entries(void)
32 {
33  /* TODO */
34 }
35 
37  { 100, 1000, 0, 0x00, 0 },
38  { 94, 940, 0, 0x1f, 0 },
39  { 88, 880, 0, 0x1e, 0 },
40  { 82, 820, 0, 0x1d, 0 },
41  { 75, 760, 0, 0x1c, 0 },
42  { 69, 700, 0, 0x1b, 0 },
43  { 63, 640, 0, 0x1a, 0 },
44  { 57, 580, 0, 0x19, 0 },
45  { 50, 520, 0, 0x18, 0 },
46  { 44, 460, 0, 0x17, 0 },
47  { 38, 400, 0, 0x16, 0 },
48  { 32, 340, 0, 0x15, 0 },
49  { 25, 280, 0, 0x14, 0 },
50  { 19, 220, 0, 0x13, 0 },
51  { 13, 160, 0, 0x12, 0 },
52 };
53 
55  { 100, 1000, 0, 0x00, 0 },
56  { 88, 875, 0, 0x1f, 0 },
57  { 75, 750, 0, 0x1e, 0 },
58  { 63, 625, 0, 0x1d, 0 },
59  { 50, 500, 0, 0x1c, 0 },
60  { 38, 375, 0, 0x1b, 0 },
61  { 25, 250, 0, 0x1a, 0 },
62  { 13, 125, 0, 0x19, 0 },
63 };
64 
65 static void generate_T_state_entries(int core, int cores_per_package)
66 {
67  /* Indicate SW_ALL coordination for T-states */
68  acpigen_write_TSD_package(core, cores_per_package, SW_ALL);
69 
70  /* Indicate FFixedHW so OS will use MSR */
72 
73  /* Set a T-state limit that can be modified in NVS */
74  acpigen_write_TPC("\\TLVL");
75 
76  /*
77  * CPUID.(EAX=6):EAX[5] indicates support
78  * for extended throttle levels.
79  */
80  if (cpuid_eax(6) & (1 << 5))
83  else
86 }
87 
88 static int calculate_power(int tdp, int p1_ratio, int ratio)
89 {
90  u32 m;
91  u32 power;
92 
93  /*
94  * M = ((1.1 - ((p1_ratio - ratio) * 0.00625)) / 1.1) ^ 2
95  *
96  * Power = (ratio / p1_ratio) * m * tdp
97  */
98 
99  m = (110000 - ((p1_ratio - ratio) * 625)) / 11;
100  m = (m * m) / 1000;
101 
102  power = ((ratio * 100000 / p1_ratio) / 100);
103  power *= (m / 100) * (tdp / 1000);
104  power /= 1000;
105 
106  return (int)power;
107 }
108 
109 static void generate_P_state_entries(int core, int cores_per_package)
110 {
111  int ratio_min, ratio_max, ratio_turbo, ratio_step;
112  int coord_type, power_max, num_entries;
113  int ratio, power, clock, clock_max;
114  msr_t msr;
115 
116  /* Determine P-state coordination type from MISC_PWR_MGMT[0] */
117  msr = rdmsr(MSR_MISC_PWR_MGMT);
118  if (msr.lo & MISC_PWR_MGMT_EIST_HW_DIS)
119  coord_type = SW_ANY;
120  else
121  coord_type = HW_ALL;
122 
123  /* Get bus ratio limits and calculate clock speeds */
124  msr = rdmsr(MSR_PLATFORM_INFO);
125  ratio_min = (msr.hi >> (40-32)) & 0xff; /* Max Efficiency Ratio */
126 
127  /* Max Non-Turbo Ratio */
128  ratio_max = (msr.lo >> 8) & 0xff;
129 
130  clock_max = ratio_max * IRONLAKE_BCLK + ratio_max / 3;
131 
132  /* Calculate CPU TDP in mW */
133  power_max = 25000;
134 
135  /* Write _PCT indicating use of FFixedHW */
137 
138  /* Write _PPC with no limit on supported P-state */
140 
141  /* Write PSD indicating configured coordination type */
142  acpigen_write_PSD_package(core, cores_per_package, coord_type);
143 
144  /* Add P-state entries in _PSS table */
145  acpigen_write_name("_PSS");
146 
147  /* Determine ratio points */
148  ratio_step = PSS_RATIO_STEP;
149  num_entries = (ratio_max - ratio_min) / ratio_step;
150  while (num_entries > PSS_MAX_ENTRIES-1) {
151  ratio_step <<= 1;
152  num_entries >>= 1;
153  }
154 
155  /* P[T] is Turbo state if enabled */
156  if (get_turbo_state() == TURBO_ENABLED) {
157  /* _PSS package count including Turbo */
158  acpigen_write_package(num_entries + 2);
159 
161  ratio_turbo = msr.lo & 0xff;
162 
163  /* Add entry for Turbo ratio */
165  clock_max + 1, /*MHz*/
166  power_max, /*mW*/
167  PSS_LATENCY_TRANSITION, /*lat1*/
168  PSS_LATENCY_BUSMASTER, /*lat2*/
169  ratio_turbo, /*control*/
170  ratio_turbo); /*status*/
171  } else {
172  /* _PSS package count without Turbo */
173  acpigen_write_package(num_entries + 1);
174  }
175 
176  /* First regular entry is max non-turbo ratio */
178  clock_max, /*MHz*/
179  power_max, /*mW*/
180  PSS_LATENCY_TRANSITION, /*lat1*/
181  PSS_LATENCY_BUSMASTER, /*lat2*/
182  ratio_max, /*control*/
183  ratio_max); /*status*/
184 
185  /* Generate the remaining entries */
186  for (ratio = ratio_min + ((num_entries - 1) * ratio_step);
187  ratio >= ratio_min; ratio -= ratio_step) {
188 
189  /* Calculate power at this ratio */
190  power = calculate_power(power_max, ratio_max, ratio);
191  clock = ratio * IRONLAKE_BCLK + ratio / 3;
192 
194  clock, /*MHz*/
195  power, /*mW*/
196  PSS_LATENCY_TRANSITION, /*lat1*/
197  PSS_LATENCY_BUSMASTER, /*lat2*/
198  ratio, /*control*/
199  ratio); /*status*/
200  }
201 
202  /* Fix package length */
203  acpigen_pop_len();
204 }
205 
206 void generate_cpu_entries(const struct device *device)
207 {
208  int coreID, cpuID;
209  int totalcores = dev_count_cpu();
210  int cores_per_package = get_cores_per_package();
211  int numcpus = totalcores/cores_per_package;
212 
213  printk(BIOS_DEBUG, "Found %d CPU(s) with %d core(s) each.\n",
214  numcpus, cores_per_package);
215 
216  for (cpuID = 1; cpuID <= numcpus; cpuID++) {
217  for (coreID = 1; coreID <= cores_per_package; coreID++) {
218  /* Generate processor \_SB.CPUx */
220  (cpuID-1)*cores_per_package+coreID-1, 0, 0);
221 
222  /* Generate P-state tables */
224  cpuID-1, cores_per_package);
225 
226  /* Generate C-state tables */
228 
229  /* Generate T-state tables */
231  cpuID-1, cores_per_package);
232 
233  acpigen_pop_len();
234  }
235  }
236 
237  /* PPKG is usually used for thermal management
238  of the first and only package. */
239  acpigen_write_processor_package("PPKG", 0, cores_per_package);
240 
241  /* Add a method to notify processor nodes */
242  acpigen_write_processor_cnot(cores_per_package);
243 }
244 
246  CHIP_NAME("Intel Arrandale CPU")
247 };
void acpigen_pop_len(void)
Definition: acpigen.c:37
void acpigen_write_TSS_package(int entries, acpi_tstate_t *tstate_list)
Definition: acpigen.c:1027
void acpigen_write_empty_PTC(void)
Definition: acpigen.c:704
void acpigen_write_PPC_NVS(void)
Definition: acpigen.c:899
void acpigen_write_PSS_package(u32 coreFreq, u32 power, u32 transLat, u32 busmLat, u32 control, u32 status)
Definition: acpigen.c:941
void acpigen_write_TPC(const char *gnvs_tpc_limit)
Definition: acpigen.c:914
void acpigen_write_empty_PCT(void)
Definition: acpigen.c:662
void acpigen_write_processor(u8 cpuindex, u32 pblock_addr, u8 pblock_len)
Definition: acpigen.c:391
char * acpigen_write_package(int nr_el)
Definition: acpigen.c:86
void acpigen_write_processor_package(const char *const name, const unsigned int first_core, const unsigned int core_count)
Definition: acpigen.c:409
void acpigen_write_processor_cnot(const unsigned int number_of_cores)
Definition: acpigen.c:425
void acpigen_write_PSD_package(u32 domain, u32 numprocs, PSD_coord coordtype)
Definition: acpigen.c:974
void acpigen_write_TSD_package(u32 domain, u32 numprocs, PSD_coord coordtype)
Definition: acpigen.c:1057
void acpigen_write_name(const char *name)
Definition: acpigen.c:320
static unsigned int cpuid_eax(unsigned int op)
Definition: cpu.h:79
static struct cpuid_result cpuid_ext(int op, unsigned int ecx)
Definition: cpu.h:59
static void get_fms(struct cpuinfo_x86 *c, uint32_t tfms)
Definition: cpu.h:278
#define ARRAY_SIZE(a)
Definition: helpers.h:12
#define printk(level,...)
Definition: stdlib.h:16
void generate_cpu_entries(const struct device *device)
Definition: acpi.c:334
#define MSR_MISC_PWR_MGMT
Definition: haswell.h:51
#define PSS_LATENCY_BUSMASTER
Definition: haswell.h:127
#define MSR_TURBO_RATIO_LIMIT
Definition: haswell.h:53
#define PSS_RATIO_STEP
Definition: haswell.h:125
#define PSS_MAX_ENTRIES
Definition: haswell.h:124
#define PSS_LATENCY_TRANSITION
Definition: haswell.h:126
#define MISC_PWR_MGMT_EIST_HW_DIS
Definition: haswell.h:52
static int calculate_power(int tdp, int p1_ratio, int ratio)
Definition: acpi.c:88
static acpi_tstate_t tss_table_fine[]
Definition: acpi.c:36
struct chip_operations cpu_intel_model_2065x_ops
Definition: acpi.c:245
static void generate_C_state_entries(void)
Definition: acpi.c:31
static void generate_T_state_entries(int core, int cores_per_package)
Definition: acpi.c:65
static void generate_P_state_entries(int core, int cores_per_package)
Definition: acpi.c:109
static acpi_tstate_t tss_table_coarse[]
Definition: acpi.c:54
static int get_cores_per_package(void)
Definition: acpi.c:15
int dev_count_cpu(void)
Definition: device_util.c:907
#define MSR_PLATFORM_INFO
Definition: fsb.c:16
@ HW_ALL
Definition: acpigen.h:375
@ SW_ALL
Definition: acpigen.h:375
@ SW_ANY
Definition: acpigen.h:375
static __always_inline msr_t rdmsr(unsigned int index)
Definition: msr.h:146
#define CHIP_NAME(X)
Definition: device.h:32
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define IRONLAKE_BCLK
Definition: model_2065x.h:7
result
Definition: mrc_cache.c:35
static const struct pnpconfig power[]
Definition: pnpconfig.c:14
uint32_t u32
Definition: stdint.h:51
Definition: device.h:107
unsigned int hi
Definition: msr.h:112
unsigned int lo
Definition: msr.h:111
#define m(clkreg, src_bits, pmcreg, dst_bits)
#define c(value, pmcreg, dst_bits)
int get_turbo_state(void)
Definition: turbo.c:75
@ TURBO_ENABLED
Definition: turbo.h:18