blob: ff9da451c818eba18f7cd90060e304df0acd088b [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;
Elyes HAOUAS3c8b5d02018-05-27 16:57:24 +0200147 struct device *dev = SA_DEV_ROOT;
Shaunak Saha95b61752017-10-04 23:08:40 -0700148 config_t *config = dev->chip_info;
149 int is_s0ix_enable = config->s0ix_enable;
150
151 if (is_s0ix_enable) {
152 *entries = ARRAY_SIZE(cstate_set_s0ix);
153 set = cstate_set_s0ix;
154 } else {
155 *entries = ARRAY_SIZE(cstate_set_non_s0ix);
156 set = cstate_set_non_s0ix;
157 }
158
159 for (i = 0; i < *entries; i++) {
160 memcpy(&map[i], &cstate_map[set[i]], sizeof(acpi_cstate_t));
161 map[i].ctype = i + 1;
162 }
163 return map;
164}
165
166void soc_power_states_generation(int core_id, int cores_per_package)
167{
Elyes HAOUAS3c8b5d02018-05-27 16:57:24 +0200168 struct device *dev = SA_DEV_ROOT;
Shaunak Saha95b61752017-10-04 23:08:40 -0700169 config_t *config = dev->chip_info;
170 if (config->eist_enable)
171 /* Generate P-state tables */
172 generate_p_state_entries(core_id, cores_per_package);
173}
174
Lijian Zhao2b074d92017-08-17 14:25:24 -0700175void soc_fill_fadt(acpi_fadt_t *fadt)
176{
177 const uint16_t pmbase = ACPI_BASE_ADDRESS;
178 const struct device *dev = PCH_DEV_LPC;
179 const struct soc_intel_cannonlake_config *config = dev->chip_info;
180
Duncan Laurie174ca432018-09-13 16:28:13 +0000181 if (!config->PmTimerDisabled) {
182 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;
Elyes HAOUAS8ee161d2019-03-03 12:49:56 +0100187 fadt->x_pm_tmr_blk.access_size = 0;
Duncan Laurie174ca432018-09-13 16:28:13 +0000188 fadt->x_pm_tmr_blk.addrl = pmbase + PM1_TMR;
189 fadt->x_pm_tmr_blk.addrh = 0x0;
190 }
Lijian Zhao2b074d92017-08-17 14:25:24 -0700191
Duncan Laurie174ca432018-09-13 16:28:13 +0000192 if (config->s0ix_enable)
Vaibhav Shankar2da6ec42018-03-19 18:56:38 -0700193 fadt->flags |= ACPI_FADT_LOW_PWR_IDLE_S0;
Lijian Zhao2b074d92017-08-17 14:25:24 -0700194}
195uint32_t soc_read_sci_irq_select(void)
196{
197 uintptr_t pmc_bar = soc_read_pmc_base();
198 return read32((void *)pmc_bar + IRQ_REG);
199}
200
201void acpi_create_gnvs(struct global_nvs_t *gnvs)
202{
203 const struct device *dev = PCH_DEV_LPC;
204 const struct soc_intel_cannonlake_config *config = dev->chip_info;
205
206 /* Set unknown wake source */
207 gnvs->pm1i = -1;
208
209 /* CPU core count */
210 gnvs->pcnt = dev_count_cpu();
211
Julius Wernercd49cce2019-03-05 16:53:33 -0800212 if (CONFIG(CONSOLE_CBMEM))
Lijian Zhao2b074d92017-08-17 14:25:24 -0700213 /* Update the mem console pointer. */
214 gnvs->cbmc = (uintptr_t)cbmem_find(CBMEM_ID_CONSOLE);
215
Julius Wernercd49cce2019-03-05 16:53:33 -0800216 if (CONFIG(CHROMEOS)) {
Lijian Zhao2b074d92017-08-17 14:25:24 -0700217 /* Initialize Verified Boot data */
Joel Kitching6fbd8742018-08-23 14:56:25 +0800218 chromeos_init_chromeos_acpi(&(gnvs->chromeos));
Julius Wernercd49cce2019-03-05 16:53:33 -0800219 if (CONFIG(EC_GOOGLE_CHROMEEC)) {
Lijian Zhao2b074d92017-08-17 14:25:24 -0700220 gnvs->chromeos.vbt2 = google_ec_running_ro() ?
221 ACTIVE_ECFW_RO : ACTIVE_ECFW_RW;
222 } else
223 gnvs->chromeos.vbt2 = ACTIVE_ECFW_RO;
224 }
225
226 /* Enable DPTF based on mainboard configuration */
227 gnvs->dpte = config->dptf_enable;
228
229 /* Fill in the Wifi Region id */
230 gnvs->cid1 = wifi_regulatory_domain();
231
232 /* Set USB2/USB3 wake enable bitmaps. */
233 gnvs->u2we = config->usb2_wake_enable_bitmap;
234 gnvs->u3we = config->usb3_wake_enable_bitmap;
235}
236
237uint32_t acpi_fill_soc_wake(uint32_t generic_pm1_en,
238 const struct chipset_power_state *ps)
239{
240 /*
241 * WAK_STS bit is set when the system is in one of the sleep states
242 * (via the SLP_EN bit) and an enabled wake event occurs. Upon setting
243 * this bit, the PMC will transition the system to the ON state and
244 * can only be set by hardware and can only be cleared by writing a one
245 * to this bit position.
246 */
247
248 generic_pm1_en |= WAK_STS | RTC_EN | PWRBTN_EN;
249 return generic_pm1_en;
250}
251
252int soc_madt_sci_irq_polarity(int sci)
253{
254 return MP_IRQ_POLARITY_HIGH;
255}
Lijian Zhao5ff742c2018-12-27 17:01:09 -0800256
257static int acpigen_soc_gpio_op(const char *op, unsigned int gpio_num)
258{
259 /* op (gpio_num) */
260 acpigen_emit_namestring(op);
261 acpigen_write_integer(gpio_num);
262 return 0;
263}
264
265static int acpigen_soc_get_gpio_state(const char *op, unsigned int gpio_num)
266{
267 /* Store (op (gpio_num), Local0) */
268 acpigen_write_store();
269 acpigen_soc_gpio_op(op, gpio_num);
270 acpigen_emit_byte(LOCAL0_OP);
271 return 0;
272}
273
274int acpigen_soc_read_rx_gpio(unsigned int gpio_num)
275{
276 return acpigen_soc_get_gpio_state("\\_SB.PCI0.GRXS", gpio_num);
277}
278
279int acpigen_soc_get_tx_gpio(unsigned int gpio_num)
280{
281 return acpigen_soc_get_gpio_state("\\_SB.PCI0.GTXS", gpio_num);
282}
283
284int acpigen_soc_set_tx_gpio(unsigned int gpio_num)
285{
286 return acpigen_soc_gpio_op("\\_SB.PCI0.STXS", gpio_num);
287}
288
289int acpigen_soc_clear_tx_gpio(unsigned int gpio_num)
290{
291 return acpigen_soc_gpio_op("\\_SB.PCI0.CTXS", gpio_num);
292}
John Zhaodb3f0e32019-03-15 16:54:27 -0700293
294static unsigned long soc_fill_dmar(unsigned long current)
295{
296 struct device *const igfx_dev = dev_find_slot(0, SA_DEVFN_IGD);
297 uint64_t gfxvtbar = MCHBAR64(GFXVTBAR) & VTBAR_MASK;
298 bool gfxvten = MCHBAR32(GFXVTBAR) & VTBAR_ENABLED;
299
300 if (igfx_dev && igfx_dev->enabled && gfxvtbar && gfxvten) {
301 unsigned long tmp = current;
302
303 current += acpi_create_dmar_drhd(current, 0, 0, gfxvtbar);
304 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
305
306 acpi_dmar_drhd_fixup(tmp, current);
John Zhaodb3f0e32019-03-15 16:54:27 -0700307 }
308
309 struct device *const ipu_dev = dev_find_slot(0, SA_DEVFN_IPU);
310 uint64_t ipuvtbar = MCHBAR64(IPUVTBAR) & VTBAR_MASK;
311 bool ipuvten = MCHBAR32(IPUVTBAR) & VTBAR_ENABLED;
312
313 if (ipu_dev && ipu_dev->enabled && ipuvtbar && ipuvten) {
314 unsigned long tmp = current;
315
316 current += acpi_create_dmar_drhd(current, 0, 0, ipuvtbar);
317 current += acpi_create_dmar_ds_pci(current, 0, 5, 0);
318
319 acpi_dmar_drhd_fixup(tmp, current);
320 }
321
322 uint64_t vtvc0bar = MCHBAR64(VTVC0BAR) & VTBAR_MASK;
323 bool vtvc0en = MCHBAR32(VTVC0BAR) & VTBAR_ENABLED;
324
325 if (vtvc0bar && vtvc0en) {
326 const unsigned long tmp = current;
327
328 current += acpi_create_dmar_drhd(current,
329 DRHD_INCLUDE_PCI_ALL, 0, vtvc0bar);
330 current += acpi_create_dmar_ds_ioapic(current,
331 2, V_P2SB_CFG_IBDF_BUS, V_P2SB_CFG_IBDF_DEV,
332 V_P2SB_CFG_IBDF_FUNC);
333 current += acpi_create_dmar_ds_msi_hpet(current,
334 0, V_P2SB_CFG_HBDF_BUS, V_P2SB_CFG_HBDF_DEV,
335 V_P2SB_CFG_HBDF_FUNC);
336
337 acpi_dmar_drhd_fixup(tmp, current);
338 }
339
John Zhao1159a162019-04-22 10:45:51 -0700340 /* Add RMRR entry */
341 const unsigned long tmp = current;
342 current += acpi_create_dmar_rmrr(current, 0,
343 sa_get_gsm_base(), sa_get_tolud_base() - 1);
344 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
345 acpi_dmar_rmrr_fixup(tmp, current);
346
John Zhaodb3f0e32019-03-15 16:54:27 -0700347 return current;
348}
349
350unsigned long sa_write_acpi_tables(struct device *dev, unsigned long current,
351 struct acpi_rsdp *rsdp)
352{
353 acpi_dmar_t *const dmar = (acpi_dmar_t *)current;
354
355 /* Create DMAR table only if we have VT-d capability
356 * and FSP does not override its feature.
357 */
358 if ((pci_read_config32(dev, CAPID0_A) & VTD_DISABLE) ||
359 !(MCHBAR32(VTVC0BAR) & VTBAR_ENABLED))
360 return current;
361
362 printk(BIOS_DEBUG, "ACPI: * DMAR\n");
363 acpi_create_dmar(dmar, DMAR_INTR_REMAP, soc_fill_dmar);
John Zhao1159a162019-04-22 10:45:51 -0700364
John Zhaodb3f0e32019-03-15 16:54:27 -0700365 current += dmar->header.length;
366 current = acpi_align_current(current);
367 acpi_add_table(rsdp, dmar);
368
369 return current;
370}