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