Debian Codegraph @

src/soc/intel/xeon_sp/spr/soc_acpi.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <acpi/acpigen.h>
4 #include <arch/smp/mpspec.h>
5 #include <arch/vga.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>
11 #include <intelblocks/pmclib.h>
12 #include <soc/acpi.h>
13 #include <soc/iomap.h>
14 #include <soc/numa.h>
15 #include <soc/msr.h>
16 #include <soc/pci_devs.h>
17 #include <soc/pm.h>
18 #include <soc/soc_util.h>
19 #include <soc/util.h>
20 #include <hob_iiouds.h>
21
22 int soc_madt_sci_irq_polarity(int sci)
23 {
24 if (sci >= 20)
25 return MP_IRQ_POLARITY_LOW;
26 else
27 return MP_IRQ_POLARITY_HIGH;
28 }
29
30 uint32_t soc_read_sci_irq_select(void)
31 {
32 /* PMC controller is hidden - hence PWRMBASE can't be accessbile using PCI cfg space */
33 uintptr_t pmc_bar = PCH_PWRM_BASE_ADDRESS;
34 return read32((void *)pmc_bar + PMC_ACPI_CNT);
35 }
36
37 void soc_fill_fadt(acpi_fadt_t *fadt)
38 {
39 const uint16_t pmbase = ACPI_BASE_ADDRESS;
40
41 fadt->FADT_MinorVersion = 1;
42 fadt->pm_tmr_blk = pmbase + PM1_TMR;
43 fadt->pm_tmr_len = 4;
44 /* Clear flags set by common/block/acpi/acpi.c acpi_fill_fadt() */
45 fadt->flags &= ~ACPI_FADT_SEALED_CASE;
46
47 fadt->preferred_pm_profile = PM_ENTERPRISE_SERVER;
48 fadt->pm2_cnt_blk = pmbase + PM2_CNT;
49 fadt->pm2_cnt_len = 1;
50
51 /* PM Extended Registers */
52 fill_fadt_extended_pm_io(fadt);
53 }
54
55 /* TODO: See if we can use the common generate_p_state_entries */
56 void soc_power_states_generation(int core, int cores_per_package)
57 {
58 int ratio_min, ratio_max, ratio_turbo, ratio_step;
59 int coord_type, power_max, power_unit, num_entries;
60 int ratio, power, clock, clock_max;
61 msr_t msr;
62
63 /* Determine P-state coordination type from MISC_PWR_MGMT[0] */
64 msr = rdmsr(MSR_MISC_PWR_MGMT);
65 if (msr.lo & MISC_PWR_MGMT_EIST_HW_DIS)
66 coord_type = SW_ANY;
67 else
68 coord_type = HW_ALL;
69
70 /* Get bus ratio limits and calculate clock speeds */
71 msr = rdmsr(MSR_PLATFORM_INFO);
72 ratio_min = (msr.hi >> (40 - 32)) & 0xff; /* Max Efficiency Ratio */
73
74 /* Determine if this CPU has configurable TDP */
75 if (cpu_config_tdp_levels()) {
76 /* Set max ratio to nominal TDP ratio */
77 msr = rdmsr(MSR_CONFIG_TDP_NOMINAL);
78 ratio_max = msr.lo & 0xff;
79 } else {
80 /* Max Non-Turbo Ratio */
81 ratio_max = (msr.lo >> 8) & 0xff;
82 }
83 clock_max = ratio_max * CONFIG_CPU_BCLK_MHZ;
84
85 /* Calculate CPU TDP in mW */
86 msr = rdmsr(MSR_PKG_POWER_SKU_UNIT);
87 power_unit = 2 << ((msr.lo & 0xf) - 1);
88 msr = rdmsr(MSR_PKG_POWER_SKU);
89 power_max = ((msr.lo & 0x7fff) / power_unit) * 1000;
90
91 /* Write _PCT indicating use of FFixedHW */
92 acpigen_write_empty_PCT();
93
94 /* Write _PPC with no limit on supported P-state */
95 acpigen_write_PPC_NVS();
96
97 /* Write PSD indicating configured coordination type */
98 acpigen_write_PSD_package(core, 1, coord_type);
99
100 /* Add P-state entries in _PSS table */
101 acpigen_write_name("_PSS");
102
103 /* Determine ratio points */
104 ratio_step = PSS_RATIO_STEP;
105 num_entries = ((ratio_max - ratio_min) / ratio_step) + 1;
106 if (num_entries > PSS_MAX_ENTRIES) {
107 ratio_step += 1;
108 num_entries = ((ratio_max - ratio_min) / ratio_step) + 1;
109 }
110
111 /* P[T] is Turbo state if enabled */
112 if (get_turbo_state() == TURBO_ENABLED) {
113 /* _PSS package count including Turbo */
114 acpigen_write_package(num_entries + 2);
115
116 msr = rdmsr(MSR_TURBO_RATIO_LIMIT);
117 ratio_turbo = msr.lo & 0xff;
118
119 /* Add entry for Turbo ratio */
120 acpigen_write_PSS_package(clock_max + 1, /* MHz */
121 power_max, /* mW */
122 PSS_LATENCY_TRANSITION, /* lat1 */
123 PSS_LATENCY_BUSMASTER, /* lat2 */
124 ratio_turbo << 8, /* control */
125 ratio_turbo << 8); /* status */
126 } else {
127 /* _PSS package count without Turbo */
128 acpigen_write_package(num_entries + 1);
129 }
130
131 /* First regular entry is max non-turbo ratio */
132 acpigen_write_PSS_package(clock_max, /* MHz */
133 power_max, /* mW */
134 PSS_LATENCY_TRANSITION, /* lat1 */
135 PSS_LATENCY_BUSMASTER, /* lat2 */
136 ratio_max << 8, /* control */
137 ratio_max << 8); /* status */
138
139 /* Generate the remaining entries */
140 for (ratio = ratio_min + ((num_entries - 1) * ratio_step); ratio >= ratio_min;
141 ratio -= ratio_step) {
142 /* Calculate power at this ratio */
143 power = common_calculate_power_ratio(power_max, ratio_max, ratio);
144 clock = ratio * CONFIG_CPU_BCLK_MHZ;
145 // clock = 1;
146 acpigen_write_PSS_package(clock, /* MHz */
147 power, /* mW */
148 PSS_LATENCY_TRANSITION, /* lat1 */
149 PSS_LATENCY_BUSMASTER, /* lat2 */
150 ratio << 8, /* control */
151 ratio << 8); /* status */
152 }
153
154 /* Fix package length */
155 acpigen_pop_len();
156 }
157
158 unsigned long acpi_fill_cedt(unsigned long current)
159 {
160 const IIO_UDS *hob = get_iio_uds();
161 union uid {
162 uint32_t data;
163 struct {
164 uint8_t byte0;
165 uint8_t byte1;
166 uint8_t byte2;
167 uint8_t byte3;
168 };
169 } cxl_uid;
170 u32 cxl_ver;
171 u64 base;
172
173 cxl_uid.byte0 = 'C';
174 cxl_uid.byte1 = 'X';
175 /* Loop through all sockets and stacks, add CHBS for each CXL IIO stack */
176 for (uint8_t socket = 0, iio = 0; iio < hob->PlatformData.numofIIO; ++socket) {
177 if (!soc_cpu_is_enabled(socket))
178 continue;
179 iio++;
180 for (int x = 0; x < MAX_LOGIC_IIO_STACK; ++x) {
181 const STACK_RES *ri;
182 ri = &hob->PlatformData.IIO_resource[socket].StackRes[x];
183 if (!is_iio_cxl_stack_res(ri))
184 continue;
185 /* uid needs to match with ACPI CXL device ID, eg. acpi/iiostack.asl */
186 cxl_uid.byte2 = socket + '0';
187 cxl_uid.byte3 = x + '0';
188 cxl_ver = ACPI_CEDT_CHBS_CXL_VER_1_1;
189 base = ri->Mmio32Base; /* DP RCRB base */
190 current += acpi_create_cedt_chbs((acpi_cedt_chbs_t *)current,
191 cxl_uid.data, cxl_ver, base);
192 }
193 }
194
195 return current;
196 }