1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <acpi/acpigen.h>
4 #include <arch/smp/mpspec.h>
6 #include <cpu/intel/turbo.h>
7 #include <device/mmio.h>
8 #include <device/pci.h>
9 #include <intelblocks/acpi.h>
10 #include <intelblocks/cpulib.h>
12 #include <soc/iomap.h>
14 #include <soc/pci_devs.h>
16 #include <soc/soc_util.h>
19 int soc_madt_sci_irq_polarity(int sci
)
22 return MP_IRQ_POLARITY_LOW
;
24 return MP_IRQ_POLARITY_HIGH
;
27 uint32_t soc_read_sci_irq_select(void)
29 struct device
*dev
= PCH_DEV_PMC
;
34 return pci_read_config32(dev
, PMC_ACPI_CNT
);
37 void soc_fill_fadt(acpi_fadt_t
*fadt
)
39 /* Clear flags set by common/block/acpi/acpi.c acpi_fill_fadt() */
40 fadt
->flags
&= ~(ACPI_FADT_SEALED_CASE
| ACPI_FADT_S4_RTC_WAKE
);
43 /* TODO: See if we can use the common generate_p_state_entries */
44 void soc_power_states_generation(int core
, int cores_per_package
)
46 int ratio_min
, ratio_max
, ratio_turbo
, ratio_step
;
47 int coord_type
, power_max
, power_unit
, num_entries
;
48 int ratio
, power
, clock
, clock_max
;
51 /* Determine P-state coordination type from MISC_PWR_MGMT[0] */
52 msr
= rdmsr(MSR_MISC_PWR_MGMT
);
53 if (msr
.lo
& MISC_PWR_MGMT_EIST_HW_DIS
)
58 /* Get bus ratio limits and calculate clock speeds */
59 msr
= rdmsr(MSR_PLATFORM_INFO
);
60 ratio_min
= (msr
.hi
>> (40-32)) & 0xff; /* Max Efficiency Ratio */
62 /* Determine if this CPU has configurable TDP */
63 if (cpu_config_tdp_levels()) {
64 /* Set max ratio to nominal TDP ratio */
65 msr
= rdmsr(MSR_CONFIG_TDP_NOMINAL
);
66 ratio_max
= msr
.lo
& 0xff;
68 /* Max Non-Turbo Ratio */
69 ratio_max
= (msr
.lo
>> 8) & 0xff;
71 clock_max
= ratio_max
* CONFIG_CPU_BCLK_MHZ
;
73 /* Calculate CPU TDP in mW */
74 msr
= rdmsr(MSR_PKG_POWER_SKU_UNIT
);
75 power_unit
= 2 << ((msr
.lo
& 0xf) - 1);
76 msr
= rdmsr(MSR_PKG_POWER_SKU
);
77 power_max
= ((msr
.lo
& 0x7fff) / power_unit
) * 1000;
79 /* Write _PCT indicating use of FFixedHW */
80 acpigen_write_empty_PCT();
82 /* Write _PPC with no limit on supported P-state */
83 acpigen_write_PPC_NVS();
85 /* Write PSD indicating configured coordination type */
86 acpigen_write_PSD_package(core
, 1, coord_type
);
88 /* Add P-state entries in _PSS table */
89 acpigen_write_name("_PSS");
91 /* Determine ratio points */
92 ratio_step
= PSS_RATIO_STEP
;
93 num_entries
= ((ratio_max
- ratio_min
) / ratio_step
) + 1;
94 if (num_entries
> PSS_MAX_ENTRIES
) {
96 num_entries
= ((ratio_max
- ratio_min
) / ratio_step
) + 1;
99 /* P[T] is Turbo state if enabled */
100 if (get_turbo_state() == TURBO_ENABLED
) {
101 /* _PSS package count including Turbo */
102 acpigen_write_package(num_entries
+ 2);
104 msr
= rdmsr(MSR_TURBO_RATIO_LIMIT
);
105 ratio_turbo
= msr
.lo
& 0xff;
107 /* Add entry for Turbo ratio */
108 acpigen_write_PSS_package(
109 clock_max
+ 1, /* MHz */
111 PSS_LATENCY_TRANSITION
, /* lat1 */
112 PSS_LATENCY_BUSMASTER
, /* lat2 */
113 ratio_turbo
<< 8, /* control */
114 ratio_turbo
<< 8); /* status */
116 /* _PSS package count without Turbo */
117 acpigen_write_package(num_entries
+ 1);
120 /* First regular entry is max non-turbo ratio */
121 acpigen_write_PSS_package(
124 PSS_LATENCY_TRANSITION
, /* lat1 */
125 PSS_LATENCY_BUSMASTER
, /* lat2 */
126 ratio_max
<< 8, /* control */
127 ratio_max
<< 8); /* status */
129 /* Generate the remaining entries */
130 for (ratio
= ratio_min
+ ((num_entries
- 1) * ratio_step
);
131 ratio
>= ratio_min
; ratio
-= ratio_step
) {
132 /* Calculate power at this ratio */
133 power
= common_calculate_power_ratio(power_max
, ratio_max
, ratio
);
134 clock
= ratio
* CONFIG_CPU_BCLK_MHZ
;
136 acpigen_write_PSS_package(
139 PSS_LATENCY_TRANSITION
, /* lat1 */
140 PSS_LATENCY_BUSMASTER
, /* lat2 */
141 ratio
<< 8, /* control */
142 ratio
<< 8); /* status */
145 /* Fix package length */