blob: 39f3fe1de6840f715424dcfe8367310b80f34cf5 [file] [log] [blame]
Angel Ponsf5627e82020-04-05 15:46:52 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Lijian Zhao2b074d92017-08-17 14:25:24 -07003
4#include <arch/acpi.h>
5#include <arch/acpigen.h>
Lijian Zhao2b074d92017-08-17 14:25:24 -07006#include <arch/smp/mpspec.h>
7#include <cbmem.h>
Patrick Georgi39c3d392019-04-23 12:27:22 +02008#include <console/console.h>
John Zhaodb3f0e32019-03-15 16:54:27 -07009#include <device/mmio.h>
10#include <device/pci_ops.h>
Lijian Zhao2b074d92017-08-17 14:25:24 -070011#include <ec/google/chromeec/ec.h>
12#include <intelblocks/cpulib.h>
13#include <intelblocks/pmclib.h>
14#include <intelblocks/acpi.h>
John Zhaodb3f0e32019-03-15 16:54:27 -070015#include <intelblocks/p2sb.h>
Lijian Zhao2b074d92017-08-17 14:25:24 -070016#include <soc/cpu.h>
17#include <soc/iomap.h>
18#include <soc/nvs.h>
19#include <soc/pci_devs.h>
20#include <soc/pm.h>
John Zhaodb3f0e32019-03-15 16:54:27 -070021#include <soc/systemagent.h>
Shaunak Saha95b61752017-10-04 23:08:40 -070022#include <string.h>
Lijian Zhao2b074d92017-08-17 14:25:24 -070023#include <vendorcode/google/chromeos/gnvs.h>
24#include <wrdd.h>
25
Elyes HAOUASc3385072019-03-21 15:38:06 +010026#include "chip.h"
27
Shaunak Saha95b61752017-10-04 23:08:40 -070028/*
29 * List of supported C-states in this processor.
30 */
31enum {
32 C_STATE_C0, /* 0 */
33 C_STATE_C1, /* 1 */
34 C_STATE_C1E, /* 2 */
35 C_STATE_C6_SHORT_LAT, /* 3 */
36 C_STATE_C6_LONG_LAT, /* 4 */
37 C_STATE_C7_SHORT_LAT, /* 5 */
38 C_STATE_C7_LONG_LAT, /* 6 */
39 C_STATE_C7S_SHORT_LAT, /* 7 */
40 C_STATE_C7S_LONG_LAT, /* 8 */
41 C_STATE_C8, /* 9 */
42 C_STATE_C9, /* 10 */
43 C_STATE_C10, /* 11 */
44 NUM_C_STATES
45};
46
47#define MWAIT_RES(state, sub_state) \
48 { \
49 .addrl = (((state) << 4) | (sub_state)), \
50 .space_id = ACPI_ADDRESS_SPACE_FIXED, \
51 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL, \
52 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT, \
53 .access_size = ACPI_FFIXEDHW_FLAG_HW_COORD, \
54 }
55
56static const acpi_cstate_t cstate_map[NUM_C_STATES] = {
57 [C_STATE_C0] = {},
58 [C_STATE_C1] = {
59 .latency = 0,
60 .power = C1_POWER,
61 .resource = MWAIT_RES(0, 0),
62 },
63 [C_STATE_C1E] = {
64 .latency = 0,
65 .power = C1_POWER,
66 .resource = MWAIT_RES(0, 1),
67 },
68 [C_STATE_C6_SHORT_LAT] = {
69 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
70 .power = C6_POWER,
71 .resource = MWAIT_RES(2, 0),
72 },
73 [C_STATE_C6_LONG_LAT] = {
74 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
75 .power = C6_POWER,
76 .resource = MWAIT_RES(2, 1),
77 },
78 [C_STATE_C7_SHORT_LAT] = {
79 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
80 .power = C7_POWER,
81 .resource = MWAIT_RES(3, 0),
82 },
83 [C_STATE_C7_LONG_LAT] = {
84 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
85 .power = C7_POWER,
86 .resource = MWAIT_RES(3, 1),
87 },
88 [C_STATE_C7S_SHORT_LAT] = {
89 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
90 .power = C7_POWER,
91 .resource = MWAIT_RES(3, 2),
92 },
93 [C_STATE_C7S_LONG_LAT] = {
94 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
95 .power = C7_POWER,
96 .resource = MWAIT_RES(3, 3),
97 },
98 [C_STATE_C8] = {
99 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
100 .power = C8_POWER,
101 .resource = MWAIT_RES(4, 0),
102 },
103 [C_STATE_C9] = {
104 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
105 .power = C9_POWER,
106 .resource = MWAIT_RES(5, 0),
107 },
108 [C_STATE_C10] = {
109 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
110 .power = C10_POWER,
111 .resource = MWAIT_RES(6, 0),
112 },
113};
114
Ronak Kanabarc6c4d002019-01-30 18:53:14 +0530115static int cstate_set_non_s0ix[] = {
Shaunak Saha95b61752017-10-04 23:08:40 -0700116 C_STATE_C1E,
117 C_STATE_C6_LONG_LAT,
118 C_STATE_C7S_LONG_LAT
119};
120
Ronak Kanabarc6c4d002019-01-30 18:53:14 +0530121static int cstate_set_s0ix[] = {
Shaunak Saha95b61752017-10-04 23:08:40 -0700122 C_STATE_C1E,
123 C_STATE_C7S_LONG_LAT,
124 C_STATE_C10
125};
126
127acpi_cstate_t *soc_get_cstate_map(size_t *entries)
128{
129 static acpi_cstate_t map[MAX(ARRAY_SIZE(cstate_set_s0ix),
130 ARRAY_SIZE(cstate_set_non_s0ix))];
131 int *set;
132 int i;
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300133
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +0300134 config_t *config = config_of_soc();
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300135
Shaunak Saha95b61752017-10-04 23:08:40 -0700136 int is_s0ix_enable = config->s0ix_enable;
137
138 if (is_s0ix_enable) {
139 *entries = ARRAY_SIZE(cstate_set_s0ix);
140 set = cstate_set_s0ix;
141 } else {
142 *entries = ARRAY_SIZE(cstate_set_non_s0ix);
143 set = cstate_set_non_s0ix;
144 }
145
146 for (i = 0; i < *entries; i++) {
147 memcpy(&map[i], &cstate_map[set[i]], sizeof(acpi_cstate_t));
148 map[i].ctype = i + 1;
149 }
150 return map;
151}
152
153void soc_power_states_generation(int core_id, int cores_per_package)
154{
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +0300155 config_t *config = config_of_soc();
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300156
157 /* Generate P-state tables */
Shaunak Saha95b61752017-10-04 23:08:40 -0700158 if (config->eist_enable)
Shaunak Saha95b61752017-10-04 23:08:40 -0700159 generate_p_state_entries(core_id, cores_per_package);
160}
161
Lijian Zhao2b074d92017-08-17 14:25:24 -0700162void soc_fill_fadt(acpi_fadt_t *fadt)
163{
164 const uint16_t pmbase = ACPI_BASE_ADDRESS;
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300165 const struct soc_intel_cannonlake_config *config;
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +0300166 config = config_of_soc();
Lijian Zhao2b074d92017-08-17 14:25:24 -0700167
Meera Ravindranath48c78702019-12-12 10:37:49 +0530168 fadt->pm_tmr_blk = pmbase + PM1_TMR;
169 fadt->pm_tmr_len = 4;
170 fadt->x_pm_tmr_blk.space_id = 1;
171 fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8;
172 fadt->x_pm_tmr_blk.bit_offset = 0;
Patrick Rudolphc02bda02020-02-28 10:19:41 +0100173 fadt->x_pm_tmr_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
Meera Ravindranath48c78702019-12-12 10:37:49 +0530174 fadt->x_pm_tmr_blk.addrl = pmbase + PM1_TMR;
175 fadt->x_pm_tmr_blk.addrh = 0x0;
Lijian Zhao2b074d92017-08-17 14:25:24 -0700176
Duncan Laurie174ca432018-09-13 16:28:13 +0000177 if (config->s0ix_enable)
Vaibhav Shankar2da6ec42018-03-19 18:56:38 -0700178 fadt->flags |= ACPI_FADT_LOW_PWR_IDLE_S0;
Lijian Zhao2b074d92017-08-17 14:25:24 -0700179}
180uint32_t soc_read_sci_irq_select(void)
181{
182 uintptr_t pmc_bar = soc_read_pmc_base();
183 return read32((void *)pmc_bar + IRQ_REG);
184}
185
186void acpi_create_gnvs(struct global_nvs_t *gnvs)
187{
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300188 const struct soc_intel_cannonlake_config *config;
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +0300189 config = config_of_soc();
Lijian Zhao2b074d92017-08-17 14:25:24 -0700190
191 /* Set unknown wake source */
192 gnvs->pm1i = -1;
193
194 /* CPU core count */
195 gnvs->pcnt = dev_count_cpu();
196
Lijian Zhao2b074d92017-08-17 14:25:24 -0700197 /* Update the mem console pointer. */
Kyösti Mälkki6eccc992019-07-13 10:45:59 +0300198 if (CONFIG(CONSOLE_CBMEM))
199 gnvs->cbmc = (uintptr_t)cbmem_find(CBMEM_ID_CONSOLE);
Lijian Zhao2b074d92017-08-17 14:25:24 -0700200
Julius Wernercd49cce2019-03-05 16:53:33 -0800201 if (CONFIG(CHROMEOS)) {
Lijian Zhao2b074d92017-08-17 14:25:24 -0700202 /* Initialize Verified Boot data */
Joel Kitching6fbd8742018-08-23 14:56:25 +0800203 chromeos_init_chromeos_acpi(&(gnvs->chromeos));
Julius Wernercd49cce2019-03-05 16:53:33 -0800204 if (CONFIG(EC_GOOGLE_CHROMEEC)) {
Lijian Zhao2b074d92017-08-17 14:25:24 -0700205 gnvs->chromeos.vbt2 = google_ec_running_ro() ?
206 ACTIVE_ECFW_RO : ACTIVE_ECFW_RW;
207 } else
208 gnvs->chromeos.vbt2 = ACTIVE_ECFW_RO;
209 }
210
211 /* Enable DPTF based on mainboard configuration */
212 gnvs->dpte = config->dptf_enable;
213
214 /* Fill in the Wifi Region id */
215 gnvs->cid1 = wifi_regulatory_domain();
216
217 /* Set USB2/USB3 wake enable bitmaps. */
218 gnvs->u2we = config->usb2_wake_enable_bitmap;
219 gnvs->u3we = config->usb3_wake_enable_bitmap;
Subrata Banikb6df6b02020-01-03 15:29:02 +0530220
221 /* Fill in Above 4GB MMIO resource */
222 sa_fill_gnvs(gnvs);
Lijian Zhao2b074d92017-08-17 14:25:24 -0700223}
224
225uint32_t acpi_fill_soc_wake(uint32_t generic_pm1_en,
226 const struct chipset_power_state *ps)
227{
228 /*
229 * WAK_STS bit is set when the system is in one of the sleep states
230 * (via the SLP_EN bit) and an enabled wake event occurs. Upon setting
231 * this bit, the PMC will transition the system to the ON state and
232 * can only be set by hardware and can only be cleared by writing a one
233 * to this bit position.
234 */
235
236 generic_pm1_en |= WAK_STS | RTC_EN | PWRBTN_EN;
237 return generic_pm1_en;
238}
239
240int soc_madt_sci_irq_polarity(int sci)
241{
242 return MP_IRQ_POLARITY_HIGH;
243}
Lijian Zhao5ff742c2018-12-27 17:01:09 -0800244
245static int acpigen_soc_gpio_op(const char *op, unsigned int gpio_num)
246{
247 /* op (gpio_num) */
248 acpigen_emit_namestring(op);
249 acpigen_write_integer(gpio_num);
250 return 0;
251}
252
253static int acpigen_soc_get_gpio_state(const char *op, unsigned int gpio_num)
254{
255 /* Store (op (gpio_num), Local0) */
256 acpigen_write_store();
257 acpigen_soc_gpio_op(op, gpio_num);
258 acpigen_emit_byte(LOCAL0_OP);
259 return 0;
260}
261
262int acpigen_soc_read_rx_gpio(unsigned int gpio_num)
263{
264 return acpigen_soc_get_gpio_state("\\_SB.PCI0.GRXS", gpio_num);
265}
266
267int acpigen_soc_get_tx_gpio(unsigned int gpio_num)
268{
269 return acpigen_soc_get_gpio_state("\\_SB.PCI0.GTXS", gpio_num);
270}
271
272int acpigen_soc_set_tx_gpio(unsigned int gpio_num)
273{
274 return acpigen_soc_gpio_op("\\_SB.PCI0.STXS", gpio_num);
275}
276
277int acpigen_soc_clear_tx_gpio(unsigned int gpio_num)
278{
279 return acpigen_soc_gpio_op("\\_SB.PCI0.CTXS", gpio_num);
280}
John Zhaodb3f0e32019-03-15 16:54:27 -0700281
282static unsigned long soc_fill_dmar(unsigned long current)
283{
Kyösti Mälkki903b40a2019-07-03 07:25:59 +0300284 struct device *const igfx_dev = pcidev_path_on_root(SA_DEVFN_IGD);
John Zhaodb3f0e32019-03-15 16:54:27 -0700285 uint64_t gfxvtbar = MCHBAR64(GFXVTBAR) & VTBAR_MASK;
286 bool gfxvten = MCHBAR32(GFXVTBAR) & VTBAR_ENABLED;
287
288 if (igfx_dev && igfx_dev->enabled && gfxvtbar && gfxvten) {
289 unsigned long tmp = current;
290
291 current += acpi_create_dmar_drhd(current, 0, 0, gfxvtbar);
292 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
293
294 acpi_dmar_drhd_fixup(tmp, current);
John Zhaodb3f0e32019-03-15 16:54:27 -0700295 }
296
Kyösti Mälkki903b40a2019-07-03 07:25:59 +0300297 struct device *const ipu_dev = pcidev_path_on_root(SA_DEVFN_IPU);
John Zhaodb3f0e32019-03-15 16:54:27 -0700298 uint64_t ipuvtbar = MCHBAR64(IPUVTBAR) & VTBAR_MASK;
299 bool ipuvten = MCHBAR32(IPUVTBAR) & VTBAR_ENABLED;
300
301 if (ipu_dev && ipu_dev->enabled && ipuvtbar && ipuvten) {
302 unsigned long tmp = current;
303
304 current += acpi_create_dmar_drhd(current, 0, 0, ipuvtbar);
305 current += acpi_create_dmar_ds_pci(current, 0, 5, 0);
306
307 acpi_dmar_drhd_fixup(tmp, current);
308 }
309
310 uint64_t vtvc0bar = MCHBAR64(VTVC0BAR) & VTBAR_MASK;
311 bool vtvc0en = MCHBAR32(VTVC0BAR) & VTBAR_ENABLED;
312
313 if (vtvc0bar && vtvc0en) {
314 const unsigned long tmp = current;
315
316 current += acpi_create_dmar_drhd(current,
317 DRHD_INCLUDE_PCI_ALL, 0, vtvc0bar);
318 current += acpi_create_dmar_ds_ioapic(current,
319 2, V_P2SB_CFG_IBDF_BUS, V_P2SB_CFG_IBDF_DEV,
320 V_P2SB_CFG_IBDF_FUNC);
321 current += acpi_create_dmar_ds_msi_hpet(current,
322 0, V_P2SB_CFG_HBDF_BUS, V_P2SB_CFG_HBDF_DEV,
323 V_P2SB_CFG_HBDF_FUNC);
324
325 acpi_dmar_drhd_fixup(tmp, current);
326 }
327
John Zhao1159a162019-04-22 10:45:51 -0700328 /* Add RMRR entry */
329 const unsigned long tmp = current;
330 current += acpi_create_dmar_rmrr(current, 0,
331 sa_get_gsm_base(), sa_get_tolud_base() - 1);
332 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
333 acpi_dmar_rmrr_fixup(tmp, current);
334
John Zhaodb3f0e32019-03-15 16:54:27 -0700335 return current;
336}
337
Furquan Shaikh0f007d82020-04-24 06:41:18 -0700338unsigned long sa_write_acpi_tables(const struct device *dev, unsigned long current,
John Zhaodb3f0e32019-03-15 16:54:27 -0700339 struct acpi_rsdp *rsdp)
340{
341 acpi_dmar_t *const dmar = (acpi_dmar_t *)current;
342
343 /* Create DMAR table only if we have VT-d capability
344 * and FSP does not override its feature.
345 */
346 if ((pci_read_config32(dev, CAPID0_A) & VTD_DISABLE) ||
347 !(MCHBAR32(VTVC0BAR) & VTBAR_ENABLED))
348 return current;
349
350 printk(BIOS_DEBUG, "ACPI: * DMAR\n");
351 acpi_create_dmar(dmar, DMAR_INTR_REMAP, soc_fill_dmar);
John Zhao1159a162019-04-22 10:45:51 -0700352
John Zhaodb3f0e32019-03-15 16:54:27 -0700353 current += dmar->header.length;
354 current = acpi_align_current(current);
355 acpi_add_table(rsdp, dmar);
356
357 return current;
358}