blob: d6eff5f4c4bf0c5b71899c91a5316ab01ea2a1d1 [file] [log] [blame]
Marc Jones392bcca2020-09-28 11:19:39 -06001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <acpi/acpi_gnvs.h>
4#include <acpi/acpigen.h>
5#include <arch/smp/mpspec.h>
6#include <assert.h>
7#include <cbmem.h>
8#include <cpu/intel/turbo.h>
9#include <device/mmio.h>
10#include <device/pci.h>
Marc Jones63e2a842020-12-02 11:33:02 -070011#include <intelblocks/acpi.h>
Marc Jonesc987e652020-12-02 16:25:16 -070012#include <intelblocks/cpulib.h>
Marc Jones392bcca2020-09-28 11:19:39 -060013#include <soc/acpi.h>
14#include <soc/cpu.h>
15#include <soc/iomap.h>
16#include <soc/msr.h>
17#include <soc/pci_devs.h>
18#include <soc/pm.h>
19#include <soc/soc_util.h>
Arthur Heymans6408ada2020-11-12 17:33:00 +010020#include <soc/util.h>
Marc Jones392bcca2020-09-28 11:19:39 -060021
Marc Jones392bcca2020-09-28 11:19:39 -060022/* TODO: Check if the common/acpi weak function can be used */
23unsigned long acpi_fill_mcfg(unsigned long current)
24{
25 current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *)current,
26 CONFIG_MMCONF_BASE_ADDRESS, 0, 0, 255);
27 return current;
28}
29
30void acpi_create_gnvs(struct global_nvs *gnvs)
31{
32 /* CPU core count */
33 gnvs->pcnt = dev_count_cpu();
34 printk(BIOS_DEBUG, "%s gnvs->pcnt: %d\n", __func__, gnvs->pcnt);
35}
36
37int soc_madt_sci_irq_polarity(int sci)
38{
39 if (sci >= 20)
40 return MP_IRQ_POLARITY_LOW;
41 else
42 return MP_IRQ_POLARITY_HIGH;
43}
44
Marc Jones70ddbd82020-09-28 12:25:03 -060045uint32_t soc_read_sci_irq_select(void)
46{
47 struct device *dev = PCH_DEV_PMC;
48
49 if (!dev)
50 return 0;
51
52 return pci_read_config32(dev, PMC_ACPI_CNT);
53}
54
Marc Jones2560ad32020-09-28 15:23:35 -060055void soc_fill_fadt(acpi_fadt_t *fadt)
56{
57 /* Clear flags set by common/block/acpi/acpi.c acpi_fill_fadt() */
Morgan Jang160cb332020-10-27 11:34:43 +080058 fadt->flags &= ~(ACPI_FADT_SEALED_CASE | ACPI_FADT_S4_RTC_WAKE);
Marc Jones2560ad32020-09-28 15:23:35 -060059}
60
Marc Jones521a03f2020-10-19 13:46:59 -060061void uncore_inject_dsdt(const struct device *device)
Marc Jones392bcca2020-09-28 11:19:39 -060062{
63 struct iiostack_resource stack_info = {0};
64
Marc Jones2c707162020-10-31 15:29:14 -060065 /* Only add RTxx entries once. */
66 if (device->bus->secondary != 0)
67 return;
68
Marc Jones392bcca2020-09-28 11:19:39 -060069 get_iiostack_info(&stack_info);
70
71 acpigen_write_scope("\\_SB");
72
73 for (uint8_t stack = 0; stack < stack_info.no_of_stacks; ++stack) {
74 const STACK_RES *ri = &stack_info.res[stack];
75 char rtname[16];
76
77 snprintf(rtname, sizeof(rtname), "RT%02x", stack);
78
79 acpigen_write_name(rtname);
80 printk(BIOS_DEBUG, "\tCreating ResourceTemplate %s for stack: %d\n",
81 rtname, stack);
82
83 acpigen_write_resourcetemplate_header();
84
85 /* bus resource */
86 acpigen_resource_word(2, 0xc, 0, 0, ri->BusBase, ri->BusLimit,
87 0x0, (ri->BusLimit - ri->BusBase + 1));
88
89 /* additional io resources on socket 0 bus 0 */
90 if (stack == 0) {
91 /* ACPI 6.4.2.5 I/O Port Descriptor */
92 acpigen_write_io16(0xCF8, 0xCFF, 0x1, 0x8, 1);
93
94 /* IO decode CF8-CFF */
95 acpigen_resource_word(1, 0xc, 0x3, 0, 0x0000, 0x03AF, 0, 0x03B0);
96 acpigen_resource_word(1, 0xc, 0x3, 0, 0x03E0, 0x0CF7, 0, 0x0918);
97 acpigen_resource_word(1, 0xc, 0x3, 0, 0x03B0, 0x03BB, 0, 0x000C);
98 acpigen_resource_word(1, 0xc, 0x3, 0, 0x03C0, 0x03DF, 0, 0x0020);
99 }
100
101 /* IO resource */
102 acpigen_resource_word(1, 0xc, 0x3, 0, ri->PciResourceIoBase,
103 ri->PciResourceIoLimit, 0x0,
104 (ri->PciResourceIoLimit - ri->PciResourceIoBase + 1));
105
106 /* additional mem32 resources on socket 0 bus 0 */
107 if (stack == 0) {
108 acpigen_resource_dword(0, 0xc, 3, 0, VGA_BASE_ADDRESS,
109 (VGA_BASE_ADDRESS + VGA_BASE_SIZE - 1), 0x0,
110 VGA_BASE_SIZE);
111 acpigen_resource_dword(0, 0xc, 1, 0, SPI_BASE_ADDRESS,
112 (SPI_BASE_ADDRESS + SPI_BASE_SIZE - 1), 0x0,
113 SPI_BASE_SIZE);
114 }
115
116 /* Mem32 resource */
117 acpigen_resource_dword(0, 0xc, 1, 0, ri->PciResourceMem32Base,
118 ri->PciResourceMem32Limit, 0x0,
119 (ri->PciResourceMem32Limit - ri->PciResourceMem32Base + 1));
120
121 /* Mem64 resource */
122 acpigen_resource_qword(0, 0xc, 1, 0, ri->PciResourceMem64Base,
123 ri->PciResourceMem64Limit, 0x0,
124 (ri->PciResourceMem64Limit - ri->PciResourceMem64Base + 1));
125
126 acpigen_write_resourcetemplate_footer();
127 }
128 acpigen_pop_len();
129}
130
Marc Jones7a25fb82020-10-19 16:32:05 -0600131/* TODO: See if we can use the common generate_p_state_entries */
132void soc_power_states_generation(int core, int cores_per_package)
Marc Jones392bcca2020-09-28 11:19:39 -0600133{
134 int ratio_min, ratio_max, ratio_turbo, ratio_step;
135 int coord_type, power_max, power_unit, num_entries;
136 int ratio, power, clock, clock_max;
137 msr_t msr;
138
139 /* Determine P-state coordination type from MISC_PWR_MGMT[0] */
140 msr = rdmsr(MSR_MISC_PWR_MGMT);
141 if (msr.lo & MISC_PWR_MGMT_EIST_HW_DIS)
142 coord_type = SW_ANY;
143 else
144 coord_type = HW_ALL;
145
146 /* Get bus ratio limits and calculate clock speeds */
147 msr = rdmsr(MSR_PLATFORM_INFO);
148 ratio_min = (msr.hi >> (40-32)) & 0xff; /* Max Efficiency Ratio */
149
150 /* Determine if this CPU has configurable TDP */
151 if (cpu_config_tdp_levels()) {
152 /* Set max ratio to nominal TDP ratio */
153 msr = rdmsr(MSR_CONFIG_TDP_NOMINAL);
154 ratio_max = msr.lo & 0xff;
155 } else {
156 /* Max Non-Turbo Ratio */
157 ratio_max = (msr.lo >> 8) & 0xff;
158 }
159 clock_max = ratio_max * CONFIG_CPU_BCLK_MHZ;
160
161 /* Calculate CPU TDP in mW */
162 msr = rdmsr(MSR_PKG_POWER_SKU_UNIT);
163 power_unit = 2 << ((msr.lo & 0xf) - 1);
164 msr = rdmsr(MSR_PKG_POWER_SKU);
165 power_max = ((msr.lo & 0x7fff) / power_unit) * 1000;
166
167 /* Write _PCT indicating use of FFixedHW */
168 acpigen_write_empty_PCT();
169
170 /* Write _PPC with no limit on supported P-state */
171 acpigen_write_PPC_NVS();
172
173 /* Write PSD indicating configured coordination type */
174 acpigen_write_PSD_package(core, 1, coord_type);
175
176 /* Add P-state entries in _PSS table */
177 acpigen_write_name("_PSS");
178
179 /* Determine ratio points */
180 ratio_step = PSS_RATIO_STEP;
181 num_entries = ((ratio_max - ratio_min) / ratio_step) + 1;
182 if (num_entries > PSS_MAX_ENTRIES) {
183 ratio_step += 1;
184 num_entries = ((ratio_max - ratio_min) / ratio_step) + 1;
185 }
186
187 /* P[T] is Turbo state if enabled */
188 if (get_turbo_state() == TURBO_ENABLED) {
189 /* _PSS package count including Turbo */
190 acpigen_write_package(num_entries + 2);
191
192 msr = rdmsr(MSR_TURBO_RATIO_LIMIT);
193 ratio_turbo = msr.lo & 0xff;
194
195 /* Add entry for Turbo ratio */
196 acpigen_write_PSS_package(
197 clock_max + 1, /* MHz */
198 power_max, /* mW */
199 PSS_LATENCY_TRANSITION, /* lat1 */
200 PSS_LATENCY_BUSMASTER, /* lat2 */
201 ratio_turbo << 8, /* control */
202 ratio_turbo << 8); /* status */
203 } else {
204 /* _PSS package count without Turbo */
205 acpigen_write_package(num_entries + 1);
206 }
207
208 /* First regular entry is max non-turbo ratio */
209 acpigen_write_PSS_package(
210 clock_max, /* MHz */
211 power_max, /* mW */
212 PSS_LATENCY_TRANSITION, /* lat1 */
213 PSS_LATENCY_BUSMASTER, /* lat2 */
214 ratio_max << 8, /* control */
215 ratio_max << 8); /* status */
216
217 /* Generate the remaining entries */
218 for (ratio = ratio_min + ((num_entries - 1) * ratio_step);
219 ratio >= ratio_min; ratio -= ratio_step) {
220
221 /* Calculate power at this ratio */
Marc Jones63e2a842020-12-02 11:33:02 -0700222 power = common_calculate_power_ratio(power_max, ratio_max, ratio);
Marc Jones392bcca2020-09-28 11:19:39 -0600223 clock = ratio * CONFIG_CPU_BCLK_MHZ;
224 //clock = 1;
225 acpigen_write_PSS_package(
226 clock, /* MHz */
227 power, /* mW */
228 PSS_LATENCY_TRANSITION, /* lat1 */
229 PSS_LATENCY_BUSMASTER, /* lat2 */
230 ratio << 8, /* control */
231 ratio << 8); /* status */
232 }
233
234 /* Fix package length */
235 acpigen_pop_len();
236}
237
238unsigned long xeonsp_acpi_create_madt_lapics(unsigned long current)
239{
240 struct device *cpu;
241 uint8_t num_cpus = 0;
242
243 for (cpu = all_devices; cpu; cpu = cpu->next) {
244 if ((cpu->path.type != DEVICE_PATH_APIC) ||
245 (cpu->bus->dev->path.type != DEVICE_PATH_CPU_CLUSTER)) {
246 continue;
247 }
248 if (!cpu->enabled)
249 continue;
250 current += acpi_create_madt_lapic((acpi_madt_lapic_t *)current,
251 num_cpus, cpu->path.apic.apic_id);
252 num_cpus++;
253 }
254
255 return current;
256}