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