blob: 6d1970bafa359857bfc961a8b614ccd4301992f2 [file] [log] [blame]
Lijian Zhao2b074d92017-08-17 14:25:24 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2009 coresystems GmbH
5 * Copyright (C) 2014 Google Inc.
Lijian Zhao5ff742c2018-12-27 17:01:09 -08006 * Copyright (C) 2017-2018 Intel Corporation.
Lijian Zhao2b074d92017-08-17 14:25:24 -07007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
18#include <arch/acpi.h>
19#include <arch/acpigen.h>
Lijian Zhao2b074d92017-08-17 14:25:24 -070020#include <arch/smp/mpspec.h>
21#include <cbmem.h>
Patrick Georgi39c3d392019-04-23 12:27:22 +020022#include <console/console.h>
John Zhaodb3f0e32019-03-15 16:54:27 -070023#include <device/mmio.h>
24#include <device/pci_ops.h>
Lijian Zhao2b074d92017-08-17 14:25:24 -070025#include <ec/google/chromeec/ec.h>
26#include <intelblocks/cpulib.h>
27#include <intelblocks/pmclib.h>
28#include <intelblocks/acpi.h>
John Zhaodb3f0e32019-03-15 16:54:27 -070029#include <intelblocks/p2sb.h>
Lijian Zhao2b074d92017-08-17 14:25:24 -070030#include <soc/cpu.h>
31#include <soc/iomap.h>
32#include <soc/nvs.h>
33#include <soc/pci_devs.h>
34#include <soc/pm.h>
John Zhaodb3f0e32019-03-15 16:54:27 -070035#include <soc/systemagent.h>
Shaunak Saha95b61752017-10-04 23:08:40 -070036#include <string.h>
Lijian Zhao2b074d92017-08-17 14:25:24 -070037#include <vendorcode/google/chromeos/gnvs.h>
38#include <wrdd.h>
39
Elyes HAOUASc3385072019-03-21 15:38:06 +010040#include "chip.h"
41
Shaunak Saha95b61752017-10-04 23:08:40 -070042/*
43 * List of supported C-states in this processor.
44 */
45enum {
46 C_STATE_C0, /* 0 */
47 C_STATE_C1, /* 1 */
48 C_STATE_C1E, /* 2 */
49 C_STATE_C6_SHORT_LAT, /* 3 */
50 C_STATE_C6_LONG_LAT, /* 4 */
51 C_STATE_C7_SHORT_LAT, /* 5 */
52 C_STATE_C7_LONG_LAT, /* 6 */
53 C_STATE_C7S_SHORT_LAT, /* 7 */
54 C_STATE_C7S_LONG_LAT, /* 8 */
55 C_STATE_C8, /* 9 */
56 C_STATE_C9, /* 10 */
57 C_STATE_C10, /* 11 */
58 NUM_C_STATES
59};
60
61#define MWAIT_RES(state, sub_state) \
62 { \
63 .addrl = (((state) << 4) | (sub_state)), \
64 .space_id = ACPI_ADDRESS_SPACE_FIXED, \
65 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL, \
66 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT, \
67 .access_size = ACPI_FFIXEDHW_FLAG_HW_COORD, \
68 }
69
70static const acpi_cstate_t cstate_map[NUM_C_STATES] = {
71 [C_STATE_C0] = {},
72 [C_STATE_C1] = {
73 .latency = 0,
74 .power = C1_POWER,
75 .resource = MWAIT_RES(0, 0),
76 },
77 [C_STATE_C1E] = {
78 .latency = 0,
79 .power = C1_POWER,
80 .resource = MWAIT_RES(0, 1),
81 },
82 [C_STATE_C6_SHORT_LAT] = {
83 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
84 .power = C6_POWER,
85 .resource = MWAIT_RES(2, 0),
86 },
87 [C_STATE_C6_LONG_LAT] = {
88 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
89 .power = C6_POWER,
90 .resource = MWAIT_RES(2, 1),
91 },
92 [C_STATE_C7_SHORT_LAT] = {
93 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
94 .power = C7_POWER,
95 .resource = MWAIT_RES(3, 0),
96 },
97 [C_STATE_C7_LONG_LAT] = {
98 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
99 .power = C7_POWER,
100 .resource = MWAIT_RES(3, 1),
101 },
102 [C_STATE_C7S_SHORT_LAT] = {
103 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
104 .power = C7_POWER,
105 .resource = MWAIT_RES(3, 2),
106 },
107 [C_STATE_C7S_LONG_LAT] = {
108 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
109 .power = C7_POWER,
110 .resource = MWAIT_RES(3, 3),
111 },
112 [C_STATE_C8] = {
113 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
114 .power = C8_POWER,
115 .resource = MWAIT_RES(4, 0),
116 },
117 [C_STATE_C9] = {
118 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
119 .power = C9_POWER,
120 .resource = MWAIT_RES(5, 0),
121 },
122 [C_STATE_C10] = {
123 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
124 .power = C10_POWER,
125 .resource = MWAIT_RES(6, 0),
126 },
127};
128
Ronak Kanabarc6c4d002019-01-30 18:53:14 +0530129static int cstate_set_non_s0ix[] = {
Shaunak Saha95b61752017-10-04 23:08:40 -0700130 C_STATE_C1E,
131 C_STATE_C6_LONG_LAT,
132 C_STATE_C7S_LONG_LAT
133};
134
Ronak Kanabarc6c4d002019-01-30 18:53:14 +0530135static int cstate_set_s0ix[] = {
Shaunak Saha95b61752017-10-04 23:08:40 -0700136 C_STATE_C1E,
137 C_STATE_C7S_LONG_LAT,
138 C_STATE_C10
139};
140
141acpi_cstate_t *soc_get_cstate_map(size_t *entries)
142{
143 static acpi_cstate_t map[MAX(ARRAY_SIZE(cstate_set_s0ix),
144 ARRAY_SIZE(cstate_set_non_s0ix))];
145 int *set;
146 int i;
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300147
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +0300148 config_t *config = config_of_soc();
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300149
Shaunak Saha95b61752017-10-04 23:08:40 -0700150 int is_s0ix_enable = config->s0ix_enable;
151
152 if (is_s0ix_enable) {
153 *entries = ARRAY_SIZE(cstate_set_s0ix);
154 set = cstate_set_s0ix;
155 } else {
156 *entries = ARRAY_SIZE(cstate_set_non_s0ix);
157 set = cstate_set_non_s0ix;
158 }
159
160 for (i = 0; i < *entries; i++) {
161 memcpy(&map[i], &cstate_map[set[i]], sizeof(acpi_cstate_t));
162 map[i].ctype = i + 1;
163 }
164 return map;
165}
166
167void soc_power_states_generation(int core_id, int cores_per_package)
168{
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +0300169 config_t *config = config_of_soc();
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300170
171 /* Generate P-state tables */
Shaunak Saha95b61752017-10-04 23:08:40 -0700172 if (config->eist_enable)
Shaunak Saha95b61752017-10-04 23:08:40 -0700173 generate_p_state_entries(core_id, cores_per_package);
174}
175
Lijian Zhao2b074d92017-08-17 14:25:24 -0700176void soc_fill_fadt(acpi_fadt_t *fadt)
177{
178 const uint16_t pmbase = ACPI_BASE_ADDRESS;
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300179 const struct soc_intel_cannonlake_config *config;
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +0300180 config = config_of_soc();
Lijian Zhao2b074d92017-08-17 14:25:24 -0700181
Meera Ravindranath48c78702019-12-12 10:37:49 +0530182 fadt->pm_tmr_blk = pmbase + PM1_TMR;
183 fadt->pm_tmr_len = 4;
184 fadt->x_pm_tmr_blk.space_id = 1;
185 fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8;
186 fadt->x_pm_tmr_blk.bit_offset = 0;
187 fadt->x_pm_tmr_blk.access_size = 0;
188 fadt->x_pm_tmr_blk.addrl = pmbase + PM1_TMR;
189 fadt->x_pm_tmr_blk.addrh = 0x0;
Lijian Zhao2b074d92017-08-17 14:25:24 -0700190
Duncan Laurie174ca432018-09-13 16:28:13 +0000191 if (config->s0ix_enable)
Vaibhav Shankar2da6ec42018-03-19 18:56:38 -0700192 fadt->flags |= ACPI_FADT_LOW_PWR_IDLE_S0;
Lijian Zhao2b074d92017-08-17 14:25:24 -0700193}
194uint32_t soc_read_sci_irq_select(void)
195{
196 uintptr_t pmc_bar = soc_read_pmc_base();
197 return read32((void *)pmc_bar + IRQ_REG);
198}
199
200void acpi_create_gnvs(struct global_nvs_t *gnvs)
201{
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300202 const struct soc_intel_cannonlake_config *config;
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +0300203 config = config_of_soc();
Lijian Zhao2b074d92017-08-17 14:25:24 -0700204
205 /* Set unknown wake source */
206 gnvs->pm1i = -1;
207
208 /* CPU core count */
209 gnvs->pcnt = dev_count_cpu();
210
Lijian Zhao2b074d92017-08-17 14:25:24 -0700211 /* Update the mem console pointer. */
Kyösti Mälkki6eccc992019-07-13 10:45:59 +0300212 if (CONFIG(CONSOLE_CBMEM))
213 gnvs->cbmc = (uintptr_t)cbmem_find(CBMEM_ID_CONSOLE);
Lijian Zhao2b074d92017-08-17 14:25:24 -0700214
Julius Wernercd49cce2019-03-05 16:53:33 -0800215 if (CONFIG(CHROMEOS)) {
Lijian Zhao2b074d92017-08-17 14:25:24 -0700216 /* Initialize Verified Boot data */
Joel Kitching6fbd8742018-08-23 14:56:25 +0800217 chromeos_init_chromeos_acpi(&(gnvs->chromeos));
Julius Wernercd49cce2019-03-05 16:53:33 -0800218 if (CONFIG(EC_GOOGLE_CHROMEEC)) {
Lijian Zhao2b074d92017-08-17 14:25:24 -0700219 gnvs->chromeos.vbt2 = google_ec_running_ro() ?
220 ACTIVE_ECFW_RO : ACTIVE_ECFW_RW;
221 } else
222 gnvs->chromeos.vbt2 = ACTIVE_ECFW_RO;
223 }
224
225 /* Enable DPTF based on mainboard configuration */
226 gnvs->dpte = config->dptf_enable;
227
228 /* Fill in the Wifi Region id */
229 gnvs->cid1 = wifi_regulatory_domain();
230
231 /* Set USB2/USB3 wake enable bitmaps. */
232 gnvs->u2we = config->usb2_wake_enable_bitmap;
233 gnvs->u3we = config->usb3_wake_enable_bitmap;
234}
235
236uint32_t acpi_fill_soc_wake(uint32_t generic_pm1_en,
237 const struct chipset_power_state *ps)
238{
239 /*
240 * WAK_STS bit is set when the system is in one of the sleep states
241 * (via the SLP_EN bit) and an enabled wake event occurs. Upon setting
242 * this bit, the PMC will transition the system to the ON state and
243 * can only be set by hardware and can only be cleared by writing a one
244 * to this bit position.
245 */
246
247 generic_pm1_en |= WAK_STS | RTC_EN | PWRBTN_EN;
248 return generic_pm1_en;
249}
250
251int soc_madt_sci_irq_polarity(int sci)
252{
253 return MP_IRQ_POLARITY_HIGH;
254}
Lijian Zhao5ff742c2018-12-27 17:01:09 -0800255
256static int acpigen_soc_gpio_op(const char *op, unsigned int gpio_num)
257{
258 /* op (gpio_num) */
259 acpigen_emit_namestring(op);
260 acpigen_write_integer(gpio_num);
261 return 0;
262}
263
264static int acpigen_soc_get_gpio_state(const char *op, unsigned int gpio_num)
265{
266 /* Store (op (gpio_num), Local0) */
267 acpigen_write_store();
268 acpigen_soc_gpio_op(op, gpio_num);
269 acpigen_emit_byte(LOCAL0_OP);
270 return 0;
271}
272
273int acpigen_soc_read_rx_gpio(unsigned int gpio_num)
274{
275 return acpigen_soc_get_gpio_state("\\_SB.PCI0.GRXS", gpio_num);
276}
277
278int acpigen_soc_get_tx_gpio(unsigned int gpio_num)
279{
280 return acpigen_soc_get_gpio_state("\\_SB.PCI0.GTXS", gpio_num);
281}
282
283int acpigen_soc_set_tx_gpio(unsigned int gpio_num)
284{
285 return acpigen_soc_gpio_op("\\_SB.PCI0.STXS", gpio_num);
286}
287
288int acpigen_soc_clear_tx_gpio(unsigned int gpio_num)
289{
290 return acpigen_soc_gpio_op("\\_SB.PCI0.CTXS", gpio_num);
291}
John Zhaodb3f0e32019-03-15 16:54:27 -0700292
293static unsigned long soc_fill_dmar(unsigned long current)
294{
Kyösti Mälkki903b40a2019-07-03 07:25:59 +0300295 struct device *const igfx_dev = pcidev_path_on_root(SA_DEVFN_IGD);
John Zhaodb3f0e32019-03-15 16:54:27 -0700296 uint64_t gfxvtbar = MCHBAR64(GFXVTBAR) & VTBAR_MASK;
297 bool gfxvten = MCHBAR32(GFXVTBAR) & VTBAR_ENABLED;
298
299 if (igfx_dev && igfx_dev->enabled && gfxvtbar && gfxvten) {
300 unsigned long tmp = current;
301
302 current += acpi_create_dmar_drhd(current, 0, 0, gfxvtbar);
303 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
304
305 acpi_dmar_drhd_fixup(tmp, current);
John Zhaodb3f0e32019-03-15 16:54:27 -0700306 }
307
Kyösti Mälkki903b40a2019-07-03 07:25:59 +0300308 struct device *const ipu_dev = pcidev_path_on_root(SA_DEVFN_IPU);
John Zhaodb3f0e32019-03-15 16:54:27 -0700309 uint64_t ipuvtbar = MCHBAR64(IPUVTBAR) & VTBAR_MASK;
310 bool ipuvten = MCHBAR32(IPUVTBAR) & VTBAR_ENABLED;
311
312 if (ipu_dev && ipu_dev->enabled && ipuvtbar && ipuvten) {
313 unsigned long tmp = current;
314
315 current += acpi_create_dmar_drhd(current, 0, 0, ipuvtbar);
316 current += acpi_create_dmar_ds_pci(current, 0, 5, 0);
317
318 acpi_dmar_drhd_fixup(tmp, current);
319 }
320
321 uint64_t vtvc0bar = MCHBAR64(VTVC0BAR) & VTBAR_MASK;
322 bool vtvc0en = MCHBAR32(VTVC0BAR) & VTBAR_ENABLED;
323
324 if (vtvc0bar && vtvc0en) {
325 const unsigned long tmp = current;
326
327 current += acpi_create_dmar_drhd(current,
328 DRHD_INCLUDE_PCI_ALL, 0, vtvc0bar);
329 current += acpi_create_dmar_ds_ioapic(current,
330 2, V_P2SB_CFG_IBDF_BUS, V_P2SB_CFG_IBDF_DEV,
331 V_P2SB_CFG_IBDF_FUNC);
332 current += acpi_create_dmar_ds_msi_hpet(current,
333 0, V_P2SB_CFG_HBDF_BUS, V_P2SB_CFG_HBDF_DEV,
334 V_P2SB_CFG_HBDF_FUNC);
335
336 acpi_dmar_drhd_fixup(tmp, current);
337 }
338
John Zhao1159a162019-04-22 10:45:51 -0700339 /* Add RMRR entry */
340 const unsigned long tmp = current;
341 current += acpi_create_dmar_rmrr(current, 0,
342 sa_get_gsm_base(), sa_get_tolud_base() - 1);
343 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
344 acpi_dmar_rmrr_fixup(tmp, current);
345
John Zhaodb3f0e32019-03-15 16:54:27 -0700346 return current;
347}
348
349unsigned long sa_write_acpi_tables(struct device *dev, unsigned long current,
350 struct acpi_rsdp *rsdp)
351{
352 acpi_dmar_t *const dmar = (acpi_dmar_t *)current;
353
354 /* Create DMAR table only if we have VT-d capability
355 * and FSP does not override its feature.
356 */
357 if ((pci_read_config32(dev, CAPID0_A) & VTD_DISABLE) ||
358 !(MCHBAR32(VTVC0BAR) & VTBAR_ENABLED))
359 return current;
360
361 printk(BIOS_DEBUG, "ACPI: * DMAR\n");
362 acpi_create_dmar(dmar, DMAR_INTR_REMAP, soc_fill_dmar);
John Zhao1159a162019-04-22 10:45:51 -0700363
John Zhaodb3f0e32019-03-15 16:54:27 -0700364 current += dmar->header.length;
365 current = acpi_align_current(current);
366 acpi_add_table(rsdp, dmar);
367
368 return current;
369}