blob: 1faf4331131bf21395b5315ce0480ca4e39936be [file] [log] [blame]
Patrick Georgiac959032020-05-05 22:49:26 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Elyes HAOUASa1e22b82019-03-18 22:49:36 +01002
Eran Mitrani4c9440c2022-11-29 17:46:38 -08003#include <acpi/acpi.h>
Kyösti Mälkki27872372021-01-21 16:05:26 +02004#include <acpi/acpi_pm.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -07005#include <acpi/acpigen.h>
Shaunak Sahabd427802017-07-18 00:19:33 -07006#include <arch/ioapic.h>
7#include <arch/smp/mpspec.h>
Elyes HAOUAS20eaef02019-03-29 17:45:28 +01008#include <console/console.h>
Elyes Haouasdef74aa2022-10-31 13:44:40 +01009#include <cpu/cpu.h>
Michael Niewöhnered21df62020-09-19 00:08:45 +020010#include <cpu/intel/common/common.h>
Elyes Haouasdef74aa2022-10-31 13:44:40 +010011#include <cpu/intel/msr.h>
12#include <cpu/intel/turbo.h>
13#include <cpu/x86/lapic.h>
Kyösti Mälkkica71e132021-01-15 05:06:35 +020014#include <intelblocks/acpi_wake_source.h>
Elyes Haouasdef74aa2022-10-31 13:44:40 +010015#include <intelblocks/acpi.h>
Marc Jones1403b912020-12-02 14:35:27 -070016#include <intelblocks/lpc_lib.h>
Shaunak Sahabd427802017-07-18 00:19:33 -070017#include <intelblocks/pmclib.h>
Michael Niewöhnerb48caad2021-10-17 15:36:45 +020018#include <intelblocks/sgx.h>
Marek Maslanka531c45e2024-01-12 07:24:21 +000019#include <intelblocks/tco.h>
Duncan Laurie93bbd412017-11-11 20:03:29 -080020#include <intelblocks/uart.h>
Shaunak Sahabd427802017-07-18 00:19:33 -070021#include <soc/gpio.h>
Marek Maslanka531c45e2024-01-12 07:24:21 +000022#include <soc/intel/common/tco.h>
Shaunak Sahabd427802017-07-18 00:19:33 -070023#include <soc/iomap.h>
Shaunak Sahabd427802017-07-18 00:19:33 -070024#include <soc/pm.h>
25
Michael Niewöhnered21df62020-09-19 00:08:45 +020026#define CPUID_6_EAX_ISST (1 << 7)
27
Kyösti Mälkkiae1b2d42023-04-10 16:45:39 +030028#define ACPI_SCI_IRQ 9
29
30void ioapic_get_sci_pin(u8 *gsi, u8 *irq, u8 *flags)
Shaunak Sahabd427802017-07-18 00:19:33 -070031{
Kyösti Mälkkiae1b2d42023-04-10 16:45:39 +030032 int sci_irq = ACPI_SCI_IRQ;
Shaunak Sahabd427802017-07-18 00:19:33 -070033 uint32_t scis;
34
35 scis = soc_read_sci_irq_select();
36 scis &= SCI_IRQ_SEL;
37 scis >>= SCI_IRQ_ADJUST;
38
39 /* Determine how SCI is routed. */
40 switch (scis) {
41 case SCIS_IRQ9:
42 case SCIS_IRQ10:
43 case SCIS_IRQ11:
44 sci_irq = scis - SCIS_IRQ9 + 9;
45 break;
46 case SCIS_IRQ20:
47 case SCIS_IRQ21:
48 case SCIS_IRQ22:
49 case SCIS_IRQ23:
50 sci_irq = scis - SCIS_IRQ20 + 20;
51 break;
52 default:
Kyösti Mälkkiae1b2d42023-04-10 16:45:39 +030053 printk(BIOS_DEBUG, "Invalid SCI route! Defaulting to IRQ%d.\n", sci_irq);
Shaunak Sahabd427802017-07-18 00:19:33 -070054 break;
55 }
56
Kyösti Mälkkiae1b2d42023-04-10 16:45:39 +030057 *gsi = sci_irq;
58 *irq = (sci_irq < 16) ? sci_irq : ACPI_SCI_IRQ;
59 *flags = MP_IRQ_TRIGGER_LEVEL | soc_madt_sci_irq_polarity(sci_irq);
60
61 printk(BIOS_DEBUG, "SCI is IRQ %d, GSI %d\n", *irq, *gsi);
Shaunak Sahabd427802017-07-18 00:19:33 -070062}
63
Shaunak Sahabd427802017-07-18 00:19:33 -070064
Arthur Heymans8a3e2b82022-12-02 12:42:27 +010065static const uintptr_t default_ioapic_bases[] = { IO_APIC_ADDR };
66
67__weak size_t soc_get_ioapic_info(const uintptr_t *ioapic_bases[])
Marc Jones847043c2020-12-02 11:24:00 -070068{
Arthur Heymans8a3e2b82022-12-02 12:42:27 +010069 *ioapic_bases = default_ioapic_bases;
70 return ARRAY_SIZE(default_ioapic_bases);
Marc Jones847043c2020-12-02 11:24:00 -070071}
72
Shaunak Sahabd427802017-07-18 00:19:33 -070073unsigned long acpi_fill_madt(unsigned long current)
74{
Arthur Heymans8a3e2b82022-12-02 12:42:27 +010075 const uintptr_t *ioapic_table;
Marc Jones847043c2020-12-02 11:24:00 -070076 size_t ioapic_entries;
77
Shaunak Sahabd427802017-07-18 00:19:33 -070078 /* Local APICs */
Kyösti Mälkki69a13962023-04-08 14:10:48 +030079 if (!CONFIG(ACPI_COMMON_MADT_LAPIC))
Sridhar Siricilla7301cfa2023-01-19 18:50:09 +053080 current = acpi_create_madt_lapics_with_nmis_hybrid(current);
Shaunak Sahabd427802017-07-18 00:19:33 -070081
82 /* IOAPIC */
Arthur Heymans8a3e2b82022-12-02 12:42:27 +010083 ioapic_entries = soc_get_ioapic_info(&ioapic_table);
Shaunak Sahabd427802017-07-18 00:19:33 -070084
Kyösti Mälkki8eac12f2023-04-12 14:04:44 +030085 /* Default SOC IOAPIC entry */
86 ASSERT(ioapic_table[0] == IO_APIC_ADDR);
87
88 for (int i = 1; i < ioapic_entries; i++)
89 current += acpi_create_madt_ioapic_from_hw((void *)current, ioapic_table[i]);
Kyösti Mälkkiae1b2d42023-04-10 16:45:39 +030090
91 return current;
Shaunak Sahabd427802017-07-18 00:19:33 -070092}
93
Shaunak Sahabd427802017-07-18 00:19:33 -070094void acpi_fill_fadt(acpi_fadt_t *fadt)
95{
96 const uint16_t pmbase = ACPI_BASE_ADDRESS;
97
Shaunak Sahabd427802017-07-18 00:19:33 -070098
99 fadt->pm1a_evt_blk = pmbase + PM1_STS;
Shaunak Sahabd427802017-07-18 00:19:33 -0700100 fadt->pm1a_cnt_blk = pmbase + PM1_CNT;
Shaunak Sahabd427802017-07-18 00:19:33 -0700101
102 fadt->gpe0_blk = pmbase + GPE0_STS(0);
103
104 fadt->pm1_evt_len = 4;
105 fadt->pm1_cnt_len = 2;
106
107 /* GPE0 STS/EN pairs each 32 bits wide. */
108 fadt->gpe0_blk_len = 2 * GPE0_REG_MAX * sizeof(uint32_t);
109
Kyösti Mälkki88decca2023-04-28 07:04:34 +0300110 fill_fadt_extended_pm_io(fadt);
Shaunak Sahabd427802017-07-18 00:19:33 -0700111
Angel Ponsa208c6c2020-07-13 00:02:34 +0200112 fadt->flags |= ACPI_FADT_WBINVD | ACPI_FADT_C1_SUPPORTED |
Michael Niewöhner2353cd92021-10-04 16:59:49 +0200113 ACPI_FADT_SLEEP_BUTTON |
Michael Niewöhner5c259642021-09-25 00:40:52 +0200114 ACPI_FADT_SEALED_CASE | ACPI_FADT_S4_RTC_WAKE;
115
Michael Niewöhner586b1be2021-09-27 23:08:59 +0200116 if (CONFIG(USE_PM_ACPI_TIMER))
Michael Niewöhner5c259642021-09-25 00:40:52 +0200117 fadt->flags |= ACPI_FADT_PLATFORM_CLOCK;
Shaunak Sahabd427802017-07-18 00:19:33 -0700118}
119
Furquan Shaikh0f007d82020-04-24 06:41:18 -0700120unsigned long southbridge_write_acpi_tables(const struct device *device,
Shaunak Sahabd427802017-07-18 00:19:33 -0700121 unsigned long current,
122 struct acpi_rsdp *rsdp)
123{
Marc Jones5258f4f2020-12-02 11:29:09 -0700124 if (CONFIG(SOC_INTEL_COMMON_BLOCK_UART)) {
125 current = acpi_write_dbg2_pci_uart(rsdp, current,
126 uart_get_device(),
127 ACPI_ACCESS_SIZE_DWORD_ACCESS);
128 }
129
Shaunak Sahabd427802017-07-18 00:19:33 -0700130 return acpi_write_hpet(device, current, rsdp);
131}
132
Aaron Durbin64031672018-04-21 14:45:32 -0600133__weak
Michael Niewöhner820b9c42021-09-30 21:03:07 +0200134void acpi_fill_soc_wake(uint32_t *pm1_en, uint32_t *gpe0_en,
135 const struct chipset_power_state *ps)
Shaunak Sahabd427802017-07-18 00:19:33 -0700136{
Shaunak Sahabd427802017-07-18 00:19:33 -0700137}
138
139/*
140 * Save wake source information for calculating ACPI _SWS values
141 *
142 * @pm1: PM1_STS register with only enabled events set
143 * @gpe0: GPE0_STS registers with only enabled events set
144 *
Kyösti Mälkkif67e67512021-01-22 19:59:07 +0200145 * return the number of registers in the gpe0 array
Shaunak Sahabd427802017-07-18 00:19:33 -0700146 */
147
Kyösti Mälkkica71e132021-01-15 05:06:35 +0200148int soc_fill_acpi_wake(const struct chipset_power_state *ps, uint32_t *pm1, uint32_t **gpe0)
Shaunak Sahabd427802017-07-18 00:19:33 -0700149{
Shaunak Sahabd427802017-07-18 00:19:33 -0700150 static uint32_t gpe0_sts[GPE0_REG_MAX];
Michael Niewöhner820b9c42021-09-30 21:03:07 +0200151 uint32_t gpe0_en[GPE0_REG_MAX];
Shaunak Sahabd427802017-07-18 00:19:33 -0700152 uint32_t pm1_en;
153 int i;
154
Shaunak Sahabd427802017-07-18 00:19:33 -0700155 /*
156 * PM1_EN to check the basic wake events which can happen through
157 * powerbtn or any other wake source like lidopen, key board press etc.
158 */
159 pm1_en = ps->pm1_en;
Michael Niewöhnerf855b8b2021-10-10 16:56:31 +0200160 pm1_en |= WAK_STS | PWRBTN_EN;
Shaunak Sahabd427802017-07-18 00:19:33 -0700161
Michael Niewöhner820b9c42021-09-30 21:03:07 +0200162 memcpy(gpe0_en, ps->gpe0_en, sizeof(gpe0_en));
163
164 acpi_fill_soc_wake(&pm1_en, gpe0_en, ps);
Shaunak Sahabd427802017-07-18 00:19:33 -0700165
166 *pm1 = ps->pm1_sts & pm1_en;
167
168 /* Mask off GPE0 status bits that are not enabled */
169 *gpe0 = &gpe0_sts[0];
170 for (i = 0; i < GPE0_REG_MAX; i++)
Michael Niewöhner820b9c42021-09-30 21:03:07 +0200171 gpe0_sts[i] = ps->gpe0_sts[i] & gpe0_en[i];
Shaunak Sahabd427802017-07-18 00:19:33 -0700172
173 return GPE0_REG_MAX;
174}
175
Marc Jonesa81703c2020-12-18 10:44:47 -0700176int common_calculate_power_ratio(int tdp, int p1_ratio, int ratio)
Shaunak Sahabd427802017-07-18 00:19:33 -0700177{
178 u32 m;
179 u32 power;
180
181 /*
182 * M = ((1.1 - ((p1_ratio - ratio) * 0.00625)) / 1.1) ^ 2
183 *
184 * Power = (ratio / p1_ratio) * m * tdp
185 */
186
187 m = (110000 - ((p1_ratio - ratio) * 625)) / 11;
188 m = (m * m) / 1000;
189
190 power = ((ratio * 100000 / p1_ratio) / 100);
191 power *= (m / 100) * (tdp / 1000);
192 power /= 1000;
193
194 return power;
195}
196
Shaunak Sahabd427802017-07-18 00:19:33 -0700197static void generate_c_state_entries(void)
198{
Angel Ponse9f10ff2021-10-17 13:28:23 +0200199 const acpi_cstate_t *c_state_map;
Shaunak Sahabd427802017-07-18 00:19:33 -0700200 size_t entries;
201
202 c_state_map = soc_get_cstate_map(&entries);
203
204 /* Generate C-state tables */
205 acpigen_write_CST_package(c_state_map, entries);
206}
207
208void generate_p_state_entries(int core, int cores_per_package)
209{
210 int ratio_min, ratio_max, ratio_turbo, ratio_step;
211 int coord_type, power_max, num_entries;
212 int ratio, power, clock, clock_max;
Julien Viard de Galbertc2540a92018-11-06 09:28:03 +0100213 bool turbo;
Shaunak Sahabd427802017-07-18 00:19:33 -0700214
215 coord_type = cpu_get_coord_type();
216 ratio_min = cpu_get_min_ratio();
217 ratio_max = cpu_get_max_ratio();
218 clock_max = (ratio_max * cpu_get_bus_clock()) / KHz;
Julien Viard de Galbertc2540a92018-11-06 09:28:03 +0100219 turbo = (get_turbo_state() == TURBO_ENABLED);
Shaunak Sahabd427802017-07-18 00:19:33 -0700220
221 /* Calculate CPU TDP in mW */
222 power_max = cpu_get_power_max();
223
224 /* Write _PCT indicating use of FFixedHW */
225 acpigen_write_empty_PCT();
226
227 /* Write _PPC with no limit on supported P-state */
228 acpigen_write_PPC_NVS();
229 /* Write PSD indicating configured coordination type */
230 acpigen_write_PSD_package(core, 1, coord_type);
231
232 /* Add P-state entries in _PSS table */
233 acpigen_write_name("_PSS");
234
235 /* Determine ratio points */
236 ratio_step = PSS_RATIO_STEP;
Julien Viard de Galbertc2540a92018-11-06 09:28:03 +0100237 do {
Shaunak Sahabd427802017-07-18 00:19:33 -0700238 num_entries = ((ratio_max - ratio_min) / ratio_step) + 1;
Julien Viard de Galbertc2540a92018-11-06 09:28:03 +0100239 if (((ratio_max - ratio_min) % ratio_step) > 0)
240 num_entries += 1;
241 if (turbo)
242 num_entries += 1;
243 if (num_entries > PSS_MAX_ENTRIES)
244 ratio_step += 1;
245 } while (num_entries > PSS_MAX_ENTRIES);
246
247 /* _PSS package count depends on Turbo */
248 acpigen_write_package(num_entries);
Shaunak Sahabd427802017-07-18 00:19:33 -0700249
250 /* P[T] is Turbo state if enabled */
Julien Viard de Galbertc2540a92018-11-06 09:28:03 +0100251 if (turbo) {
Shaunak Sahabd427802017-07-18 00:19:33 -0700252 ratio_turbo = cpu_get_max_turbo_ratio();
253
254 /* Add entry for Turbo ratio */
255 acpigen_write_PSS_package(clock_max + 1, /* MHz */
256 power_max, /* mW */
257 PSS_LATENCY_TRANSITION,/* lat1 */
258 PSS_LATENCY_BUSMASTER,/* lat2 */
259 ratio_turbo << 8, /* control */
260 ratio_turbo << 8); /* status */
Julien Viard de Galbertc2540a92018-11-06 09:28:03 +0100261 num_entries -= 1;
Shaunak Sahabd427802017-07-18 00:19:33 -0700262 }
263
264 /* First regular entry is max non-turbo ratio */
265 acpigen_write_PSS_package(clock_max, /* MHz */
266 power_max, /* mW */
267 PSS_LATENCY_TRANSITION,/* lat1 */
268 PSS_LATENCY_BUSMASTER,/* lat2 */
269 ratio_max << 8, /* control */
270 ratio_max << 8); /* status */
Julien Viard de Galbertc2540a92018-11-06 09:28:03 +0100271 num_entries -= 1;
Shaunak Sahabd427802017-07-18 00:19:33 -0700272
273 /* Generate the remaining entries */
274 for (ratio = ratio_min + ((num_entries - 1) * ratio_step);
275 ratio >= ratio_min; ratio -= ratio_step) {
Shaunak Sahabd427802017-07-18 00:19:33 -0700276 /* Calculate power at this ratio */
Marc Jonesa81703c2020-12-18 10:44:47 -0700277 power = common_calculate_power_ratio(power_max, ratio_max, ratio);
Shaunak Sahabd427802017-07-18 00:19:33 -0700278 clock = (ratio * cpu_get_bus_clock()) / KHz;
279
280 acpigen_write_PSS_package(clock, /* MHz */
281 power, /* mW */
282 PSS_LATENCY_TRANSITION,/* lat1 */
283 PSS_LATENCY_BUSMASTER,/* lat2 */
284 ratio << 8, /* control */
285 ratio << 8); /* status */
286 }
287 /* Fix package length */
288 acpigen_pop_len();
289}
290
Elyes Haouasfeb683d2023-09-05 23:15:03 +0200291__weak acpi_tstate_t *soc_get_tss_table(int *entries)
Shaunak Sahabd427802017-07-18 00:19:33 -0700292{
293 *entries = 0;
294 return NULL;
295}
296
297void generate_t_state_entries(int core, int cores_per_package)
298{
299 acpi_tstate_t *soc_tss_table;
300 int entries;
301
302 soc_tss_table = soc_get_tss_table(&entries);
303 if (entries == 0)
304 return;
305
306 /* Indicate SW_ALL coordination for T-states */
307 acpigen_write_TSD_package(core, cores_per_package, SW_ALL);
308
309 /* Indicate FixedHW so OS will use MSR */
310 acpigen_write_empty_PTC();
311
312 /* Set NVS controlled T-state limit */
313 acpigen_write_TPC("\\TLVL");
314
315 /* Write TSS table for MSR access */
316 acpigen_write_TSS_package(entries, soc_tss_table);
317}
318
Michael Niewöhnered21df62020-09-19 00:08:45 +0200319static void generate_cppc_entries(int core_id)
320{
Sridhar Siricilla11736122021-11-15 17:12:49 +0530321 u32 version = CPPC_VERSION_2;
322
323 if (CONFIG(SOC_INTEL_COMMON_BLOCK_ACPI_CPU_HYBRID))
324 version = CPPC_VERSION_3;
325
Michael Niewöhnered21df62020-09-19 00:08:45 +0200326 if (!(CONFIG(SOC_INTEL_COMMON_BLOCK_ACPI_CPPC) &&
327 cpuid_eax(6) & CPUID_6_EAX_ISST))
328 return;
329
330 /* Generate GCPC package in first logical core */
331 if (core_id == 0) {
332 struct cppc_config cppc_config;
Sridhar Siricilla11736122021-11-15 17:12:49 +0530333 cpu_init_cppc_config(&cppc_config, version);
Michael Niewöhnered21df62020-09-19 00:08:45 +0200334 acpigen_write_CPPC_package(&cppc_config);
335 }
336
337 /* Write _CPC entry for each logical core */
Sridhar Siricilla11736122021-11-15 17:12:49 +0530338 if (CONFIG(SOC_INTEL_COMMON_BLOCK_ACPI_CPU_HYBRID))
339 acpigen_write_CPPC_hybrid_method(core_id);
340 else
341 acpigen_write_CPPC_method();
Michael Niewöhnered21df62020-09-19 00:08:45 +0200342}
343
Aaron Durbin64031672018-04-21 14:45:32 -0600344__weak void soc_power_states_generation(int core_id,
Shaunak Sahabd427802017-07-18 00:19:33 -0700345 int cores_per_package)
346{
347}
348
Kyösti Mälkkid521b962023-04-12 21:44:49 +0300349static void generate_cpu_entry(int cpu, int core, int cores_per_package)
350{
351 /* Generate processor \_SB.CPUx */
352 acpigen_write_processor_device(cpu * cores_per_package + core);
353
354 /* Generate C-state tables */
355 generate_c_state_entries();
356
357 generate_cppc_entries(core);
358
359 /* Soc specific power states generation */
360 soc_power_states_generation(core, cores_per_package);
361
362 acpigen_write_processor_device_end();
363}
364
Furquan Shaikh7536a392020-04-24 21:59:21 -0700365void generate_cpu_entries(const struct device *device)
Shaunak Sahabd427802017-07-18 00:19:33 -0700366{
Michael Niewöhner2353cd92021-10-04 16:59:49 +0200367 int core_id, cpu_id;
Shaunak Sahabd427802017-07-18 00:19:33 -0700368 int totalcores = dev_count_cpu();
Patrick Rudolph7a66ffb2020-12-17 14:42:29 +0100369 unsigned int num_virt;
370 unsigned int num_phys;
Shaunak Sahabd427802017-07-18 00:19:33 -0700371
Patrick Rudolph7a66ffb2020-12-17 14:42:29 +0100372 cpu_read_topology(&num_phys, &num_virt);
373
374 int numcpus = totalcores / num_virt;
375
376 printk(BIOS_DEBUG, "Found %d CPU(s) with %d/%d physical/logical core(s) each.\n",
377 numcpus, num_phys, num_virt);
Shaunak Sahabd427802017-07-18 00:19:33 -0700378
Kyösti Mälkkid521b962023-04-12 21:44:49 +0300379 for (cpu_id = 0; cpu_id < numcpus; cpu_id++)
380 for (core_id = 0; core_id < num_virt; core_id++)
381 generate_cpu_entry(cpu_id, core_id, num_virt);
Shaunak Sahabd427802017-07-18 00:19:33 -0700382
Arthur Heymans0ac555e2018-11-28 12:25:54 +0100383 /* PPKG is usually used for thermal management
384 of the first and only package. */
Patrick Rudolph7a66ffb2020-12-17 14:42:29 +0100385 acpigen_write_processor_package("PPKG", 0, num_virt);
Arthur Heymans0ac555e2018-11-28 12:25:54 +0100386
387 /* Add a method to notify processor nodes */
Patrick Rudolph7a66ffb2020-12-17 14:42:29 +0100388 acpigen_write_processor_cnot(num_virt);
Michael Niewöhnerb48caad2021-10-17 15:36:45 +0200389
390 if (CONFIG(SOC_INTEL_COMMON_BLOCK_SGX_ENABLE))
391 sgx_fill_ssdt();
Shaunak Sahabd427802017-07-18 00:19:33 -0700392}
Marek Maslanka531c45e2024-01-12 07:24:21 +0000393
394
395static bool fill_wdat_timeout_entry(acpi_wdat_entry_t *entry)
396{
397 uint16_t tcobase = tco_get_bar();
398
399 if (tcobase == 0)
400 return false;
401
402 memset((void *)entry, 0, sizeof(acpi_wdat_entry_t));
403
404 entry->action = ACPI_WDAT_SET_COUNTDOWN;
405 entry->instruction = ACPI_WDAT_WRITE_COUNTDOWN | ACPI_WDAT_PRESERVE_REGISTER;
406 entry->mask = TCO_TMR_MASK;
407 entry->register_region.space_id = ACPI_ADDRESS_SPACE_IO;
408 entry->register_region.addrl = tcobase + TCO_TMR;
409 entry->register_region.access_size = ACPI_WDAT_ACCESS_SIZE_WORD;
410
411 return true;
412}
413
414static bool fill_wdat_boot_status_entry(acpi_wdat_entry_t *entry, uint8_t action,
415 uint8_t instruction, uint32_t value)
416{
417 uint16_t tcobase = tco_get_bar();
418
419 if (tcobase == 0)
420 return false;
421
422 memset((void *)entry, 0, sizeof(acpi_wdat_entry_t));
423
424 entry->action = action;
425 entry->instruction = instruction;
426 entry->value = value;
427 entry->mask = TCO2_STS_SECOND_TO;
428 entry->register_region.space_id = ACPI_ADDRESS_SPACE_IO;
429 entry->register_region.addrl = tcobase + TCO_MESSAGE1;
430 entry->register_region.access_size = ACPI_WDAT_ACCESS_SIZE_BYTE;
431
432 return true;
433}
434
435static bool fill_wdat_run_state_entry(acpi_wdat_entry_t *entry, uint8_t action,
436 uint8_t instruction, uint32_t value)
437{
438 uint16_t tcobase = tco_get_bar();
439
440 if (tcobase == 0)
441 return false;
442
443 memset((void *)entry, 0, sizeof(acpi_wdat_entry_t));
444
445 entry->action = action;
446 entry->instruction = instruction;
447 entry->value = value;
448 entry->mask = TCO1_TMR_HLT;
449 entry->register_region.space_id = ACPI_ADDRESS_SPACE_IO;
450 entry->register_region.addrl = tcobase + TCO1_CNT;
451 entry->register_region.access_size = ACPI_WDAT_ACCESS_SIZE_WORD;
452
453 return true;
454}
455
456static bool fill_wdat_ping_entry(acpi_wdat_entry_t *entry)
457{
458 uint16_t tcobase = tco_get_bar();
459
460 if (tcobase == 0)
461 return false;
462
463 memset((void *)entry, 0, sizeof(acpi_wdat_entry_t));
464
465 entry->action = ACPI_WDAT_RESET;
466 entry->instruction = ACPI_WDAT_WRITE_VALUE;
467 entry->value = 0x01;
468 entry->mask = 0x01;
469 entry->register_region.space_id = ACPI_ADDRESS_SPACE_IO;
470 entry->register_region.addrl = tcobase + TCO_RLD;
471 entry->register_region.access_size = ACPI_WDAT_ACCESS_SIZE_WORD;
472
473 return true;
474}
475
476unsigned long acpi_soc_fill_wdat(acpi_wdat_t *wdat, unsigned long current)
477{
478 if (!wdat)
479 return current;
480
481 uint16_t tcobase = tco_get_bar();
482
483 if (tcobase == 0)
484 goto out_err;
485
486 wdat->pci_segment = 0xff;
487 wdat->pci_bus = 0xff;
488 wdat->pci_device = 0xff;
489 wdat->pci_function = 0xff;
490
491 wdat->timer_period = tco_get_timer_period();
492 wdat->min_count = tco_get_timer_min_value();
493 wdat->max_count = tco_get_timer_max_value();
494 wdat->flags = ACPI_WDAT_FLAG_ENABLED;
495 wdat->entries = 0;
496
497 acpi_wdat_entry_t *entry = (acpi_wdat_entry_t *)current;
498
499 /* Write countdown */
500 if (!fill_wdat_timeout_entry(entry))
501 goto out_err;
502
503 entry++;
504
505 /* Get boot status */
506 if (!fill_wdat_boot_status_entry(entry, ACPI_WDAT_GET_STATUS,
507 ACPI_WDAT_READ_VALUE, TCO2_STS_SECOND_TO))
508 goto out_err;
509
510 entry++;
511
512 /* Set boot status */
513 if (!fill_wdat_boot_status_entry(entry, ACPI_WDAT_SET_STATUS,
514 ACPI_WDAT_WRITE_VALUE | ACPI_WDAT_PRESERVE_REGISTER,
515 0))
516 goto out_err;
517
518 entry++;
519
520 /* Get running status */
521 if (!fill_wdat_run_state_entry(entry, ACPI_WDAT_GET_RUNNING_STATE,
522 ACPI_WDAT_READ_VALUE, 0))
523 goto out_err;
524
525 entry++;
526
527 /* Start the watchdog */
528 if (!fill_wdat_run_state_entry(entry, ACPI_WDAT_SET_RUNNING_STATE,
529 ACPI_WDAT_WRITE_VALUE | ACPI_WDAT_PRESERVE_REGISTER,
530 0))
531 goto out_err;
532
533 entry++;
534
535 /* Get stopped status */
536 if (!fill_wdat_run_state_entry(entry, ACPI_WDAT_GET_STOPPED_STATE,
537 ACPI_WDAT_READ_VALUE, TCO1_TMR_HLT))
538 goto out_err;
539
540 entry++;
541
542 /* Stop the watchdog */
543 if (!fill_wdat_run_state_entry(entry, ACPI_WDAT_SET_STOPPED_STATE,
544 ACPI_WDAT_WRITE_VALUE | ACPI_WDAT_PRESERVE_REGISTER,
545 TCO1_TMR_HLT))
546 goto out_err;
547
548 entry++;
549
550 /* Ping */
551 if (!fill_wdat_ping_entry(entry))
552 goto out_err;
553
554 entry++;
555
556 wdat->entries = ((unsigned long)entry - current) / sizeof(acpi_wdat_entry_t);
557
558 return (unsigned long)entry;
559
560out_err:
561 wdat->flags = ACPI_WDAT_FLAG_DISABLED;
562 printk(BIOS_ERR, "Fail to populate WDAT ACPI Table");
563
564 return current;
565}