blob: 43d91d3f83e7df5dcd7cca402371fb1d8f49e777 [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>
22#include <chip.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
Shaunak Saha95b61752017-10-04 23:08:40 -070040/*
41 * List of supported C-states in this processor.
42 */
43enum {
44 C_STATE_C0, /* 0 */
45 C_STATE_C1, /* 1 */
46 C_STATE_C1E, /* 2 */
47 C_STATE_C6_SHORT_LAT, /* 3 */
48 C_STATE_C6_LONG_LAT, /* 4 */
49 C_STATE_C7_SHORT_LAT, /* 5 */
50 C_STATE_C7_LONG_LAT, /* 6 */
51 C_STATE_C7S_SHORT_LAT, /* 7 */
52 C_STATE_C7S_LONG_LAT, /* 8 */
53 C_STATE_C8, /* 9 */
54 C_STATE_C9, /* 10 */
55 C_STATE_C10, /* 11 */
56 NUM_C_STATES
57};
58
59#define MWAIT_RES(state, sub_state) \
60 { \
61 .addrl = (((state) << 4) | (sub_state)), \
62 .space_id = ACPI_ADDRESS_SPACE_FIXED, \
63 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL, \
64 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT, \
65 .access_size = ACPI_FFIXEDHW_FLAG_HW_COORD, \
66 }
67
68static const acpi_cstate_t cstate_map[NUM_C_STATES] = {
69 [C_STATE_C0] = {},
70 [C_STATE_C1] = {
71 .latency = 0,
72 .power = C1_POWER,
73 .resource = MWAIT_RES(0, 0),
74 },
75 [C_STATE_C1E] = {
76 .latency = 0,
77 .power = C1_POWER,
78 .resource = MWAIT_RES(0, 1),
79 },
80 [C_STATE_C6_SHORT_LAT] = {
81 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
82 .power = C6_POWER,
83 .resource = MWAIT_RES(2, 0),
84 },
85 [C_STATE_C6_LONG_LAT] = {
86 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
87 .power = C6_POWER,
88 .resource = MWAIT_RES(2, 1),
89 },
90 [C_STATE_C7_SHORT_LAT] = {
91 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
92 .power = C7_POWER,
93 .resource = MWAIT_RES(3, 0),
94 },
95 [C_STATE_C7_LONG_LAT] = {
96 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
97 .power = C7_POWER,
98 .resource = MWAIT_RES(3, 1),
99 },
100 [C_STATE_C7S_SHORT_LAT] = {
101 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
102 .power = C7_POWER,
103 .resource = MWAIT_RES(3, 2),
104 },
105 [C_STATE_C7S_LONG_LAT] = {
106 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
107 .power = C7_POWER,
108 .resource = MWAIT_RES(3, 3),
109 },
110 [C_STATE_C8] = {
111 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
112 .power = C8_POWER,
113 .resource = MWAIT_RES(4, 0),
114 },
115 [C_STATE_C9] = {
116 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
117 .power = C9_POWER,
118 .resource = MWAIT_RES(5, 0),
119 },
120 [C_STATE_C10] = {
121 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
122 .power = C10_POWER,
123 .resource = MWAIT_RES(6, 0),
124 },
125};
126
Ronak Kanabarc6c4d002019-01-30 18:53:14 +0530127static int cstate_set_non_s0ix[] = {
Shaunak Saha95b61752017-10-04 23:08:40 -0700128 C_STATE_C1E,
129 C_STATE_C6_LONG_LAT,
130 C_STATE_C7S_LONG_LAT
131};
132
Ronak Kanabarc6c4d002019-01-30 18:53:14 +0530133static int cstate_set_s0ix[] = {
Shaunak Saha95b61752017-10-04 23:08:40 -0700134 C_STATE_C1E,
135 C_STATE_C7S_LONG_LAT,
136 C_STATE_C10
137};
138
139acpi_cstate_t *soc_get_cstate_map(size_t *entries)
140{
141 static acpi_cstate_t map[MAX(ARRAY_SIZE(cstate_set_s0ix),
142 ARRAY_SIZE(cstate_set_non_s0ix))];
143 int *set;
144 int i;
Elyes HAOUAS3c8b5d02018-05-27 16:57:24 +0200145 struct device *dev = SA_DEV_ROOT;
Shaunak Saha95b61752017-10-04 23:08:40 -0700146 config_t *config = dev->chip_info;
147 int is_s0ix_enable = config->s0ix_enable;
148
149 if (is_s0ix_enable) {
150 *entries = ARRAY_SIZE(cstate_set_s0ix);
151 set = cstate_set_s0ix;
152 } else {
153 *entries = ARRAY_SIZE(cstate_set_non_s0ix);
154 set = cstate_set_non_s0ix;
155 }
156
157 for (i = 0; i < *entries; i++) {
158 memcpy(&map[i], &cstate_map[set[i]], sizeof(acpi_cstate_t));
159 map[i].ctype = i + 1;
160 }
161 return map;
162}
163
164void soc_power_states_generation(int core_id, int cores_per_package)
165{
Elyes HAOUAS3c8b5d02018-05-27 16:57:24 +0200166 struct device *dev = SA_DEV_ROOT;
Shaunak Saha95b61752017-10-04 23:08:40 -0700167 config_t *config = dev->chip_info;
168 if (config->eist_enable)
169 /* Generate P-state tables */
170 generate_p_state_entries(core_id, cores_per_package);
171}
172
Lijian Zhao2b074d92017-08-17 14:25:24 -0700173void soc_fill_fadt(acpi_fadt_t *fadt)
174{
175 const uint16_t pmbase = ACPI_BASE_ADDRESS;
176 const struct device *dev = PCH_DEV_LPC;
177 const struct soc_intel_cannonlake_config *config = dev->chip_info;
178
Duncan Laurie174ca432018-09-13 16:28:13 +0000179 if (!config->PmTimerDisabled) {
180 fadt->pm_tmr_blk = pmbase + PM1_TMR;
181 fadt->pm_tmr_len = 4;
182 fadt->x_pm_tmr_blk.space_id = 1;
183 fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8;
184 fadt->x_pm_tmr_blk.bit_offset = 0;
Elyes HAOUAS8ee161d2019-03-03 12:49:56 +0100185 fadt->x_pm_tmr_blk.access_size = 0;
Duncan Laurie174ca432018-09-13 16:28:13 +0000186 fadt->x_pm_tmr_blk.addrl = pmbase + PM1_TMR;
187 fadt->x_pm_tmr_blk.addrh = 0x0;
188 }
Lijian Zhao2b074d92017-08-17 14:25:24 -0700189
Duncan Laurie174ca432018-09-13 16:28:13 +0000190 if (config->s0ix_enable)
Vaibhav Shankar2da6ec42018-03-19 18:56:38 -0700191 fadt->flags |= ACPI_FADT_LOW_PWR_IDLE_S0;
Lijian Zhao2b074d92017-08-17 14:25:24 -0700192}
193uint32_t soc_read_sci_irq_select(void)
194{
195 uintptr_t pmc_bar = soc_read_pmc_base();
196 return read32((void *)pmc_bar + IRQ_REG);
197}
198
199void acpi_create_gnvs(struct global_nvs_t *gnvs)
200{
201 const struct device *dev = PCH_DEV_LPC;
202 const struct soc_intel_cannonlake_config *config = dev->chip_info;
203
204 /* Set unknown wake source */
205 gnvs->pm1i = -1;
206
207 /* CPU core count */
208 gnvs->pcnt = dev_count_cpu();
209
Julius Wernercd49cce2019-03-05 16:53:33 -0800210 if (CONFIG(CONSOLE_CBMEM))
Lijian Zhao2b074d92017-08-17 14:25:24 -0700211 /* Update the mem console pointer. */
212 gnvs->cbmc = (uintptr_t)cbmem_find(CBMEM_ID_CONSOLE);
213
Julius Wernercd49cce2019-03-05 16:53:33 -0800214 if (CONFIG(CHROMEOS)) {
Lijian Zhao2b074d92017-08-17 14:25:24 -0700215 /* Initialize Verified Boot data */
Joel Kitching6fbd8742018-08-23 14:56:25 +0800216 chromeos_init_chromeos_acpi(&(gnvs->chromeos));
Julius Wernercd49cce2019-03-05 16:53:33 -0800217 if (CONFIG(EC_GOOGLE_CHROMEEC)) {
Lijian Zhao2b074d92017-08-17 14:25:24 -0700218 gnvs->chromeos.vbt2 = google_ec_running_ro() ?
219 ACTIVE_ECFW_RO : ACTIVE_ECFW_RW;
220 } else
221 gnvs->chromeos.vbt2 = ACTIVE_ECFW_RO;
222 }
223
224 /* Enable DPTF based on mainboard configuration */
225 gnvs->dpte = config->dptf_enable;
226
227 /* Fill in the Wifi Region id */
228 gnvs->cid1 = wifi_regulatory_domain();
229
230 /* Set USB2/USB3 wake enable bitmaps. */
231 gnvs->u2we = config->usb2_wake_enable_bitmap;
232 gnvs->u3we = config->usb3_wake_enable_bitmap;
233}
234
235uint32_t acpi_fill_soc_wake(uint32_t generic_pm1_en,
236 const struct chipset_power_state *ps)
237{
238 /*
239 * WAK_STS bit is set when the system is in one of the sleep states
240 * (via the SLP_EN bit) and an enabled wake event occurs. Upon setting
241 * this bit, the PMC will transition the system to the ON state and
242 * can only be set by hardware and can only be cleared by writing a one
243 * to this bit position.
244 */
245
246 generic_pm1_en |= WAK_STS | RTC_EN | PWRBTN_EN;
247 return generic_pm1_en;
248}
249
250int soc_madt_sci_irq_polarity(int sci)
251{
252 return MP_IRQ_POLARITY_HIGH;
253}
Lijian Zhao5ff742c2018-12-27 17:01:09 -0800254
255static int acpigen_soc_gpio_op(const char *op, unsigned int gpio_num)
256{
257 /* op (gpio_num) */
258 acpigen_emit_namestring(op);
259 acpigen_write_integer(gpio_num);
260 return 0;
261}
262
263static int acpigen_soc_get_gpio_state(const char *op, unsigned int gpio_num)
264{
265 /* Store (op (gpio_num), Local0) */
266 acpigen_write_store();
267 acpigen_soc_gpio_op(op, gpio_num);
268 acpigen_emit_byte(LOCAL0_OP);
269 return 0;
270}
271
272int acpigen_soc_read_rx_gpio(unsigned int gpio_num)
273{
274 return acpigen_soc_get_gpio_state("\\_SB.PCI0.GRXS", gpio_num);
275}
276
277int acpigen_soc_get_tx_gpio(unsigned int gpio_num)
278{
279 return acpigen_soc_get_gpio_state("\\_SB.PCI0.GTXS", gpio_num);
280}
281
282int acpigen_soc_set_tx_gpio(unsigned int gpio_num)
283{
284 return acpigen_soc_gpio_op("\\_SB.PCI0.STXS", gpio_num);
285}
286
287int acpigen_soc_clear_tx_gpio(unsigned int gpio_num)
288{
289 return acpigen_soc_gpio_op("\\_SB.PCI0.CTXS", gpio_num);
290}
John Zhaodb3f0e32019-03-15 16:54:27 -0700291
292static unsigned long soc_fill_dmar(unsigned long current)
293{
294 struct device *const igfx_dev = dev_find_slot(0, SA_DEVFN_IGD);
295 uint64_t gfxvtbar = MCHBAR64(GFXVTBAR) & VTBAR_MASK;
296 bool gfxvten = MCHBAR32(GFXVTBAR) & VTBAR_ENABLED;
297
298 if (igfx_dev && igfx_dev->enabled && gfxvtbar && gfxvten) {
299 unsigned long tmp = current;
300
301 current += acpi_create_dmar_drhd(current, 0, 0, gfxvtbar);
302 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
303
304 acpi_dmar_drhd_fixup(tmp, current);
305
306 /* Add RMRR entry */
307 tmp = current;
308 current += acpi_create_dmar_rmrr(current, 0,
309 sa_get_gsm_base(), sa_get_tolud_base() - 1);
310 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
311 acpi_dmar_rmrr_fixup(tmp, current);
312 }
313
314 struct device *const ipu_dev = dev_find_slot(0, SA_DEVFN_IPU);
315 uint64_t ipuvtbar = MCHBAR64(IPUVTBAR) & VTBAR_MASK;
316 bool ipuvten = MCHBAR32(IPUVTBAR) & VTBAR_ENABLED;
317
318 if (ipu_dev && ipu_dev->enabled && ipuvtbar && ipuvten) {
319 unsigned long tmp = current;
320
321 current += acpi_create_dmar_drhd(current, 0, 0, ipuvtbar);
322 current += acpi_create_dmar_ds_pci(current, 0, 5, 0);
323
324 acpi_dmar_drhd_fixup(tmp, current);
325 }
326
327 uint64_t vtvc0bar = MCHBAR64(VTVC0BAR) & VTBAR_MASK;
328 bool vtvc0en = MCHBAR32(VTVC0BAR) & VTBAR_ENABLED;
329
330 if (vtvc0bar && vtvc0en) {
331 const unsigned long tmp = current;
332
333 current += acpi_create_dmar_drhd(current,
334 DRHD_INCLUDE_PCI_ALL, 0, vtvc0bar);
335 current += acpi_create_dmar_ds_ioapic(current,
336 2, V_P2SB_CFG_IBDF_BUS, V_P2SB_CFG_IBDF_DEV,
337 V_P2SB_CFG_IBDF_FUNC);
338 current += acpi_create_dmar_ds_msi_hpet(current,
339 0, V_P2SB_CFG_HBDF_BUS, V_P2SB_CFG_HBDF_DEV,
340 V_P2SB_CFG_HBDF_FUNC);
341
342 acpi_dmar_drhd_fixup(tmp, current);
343 }
344
345 return current;
346}
347
348unsigned long sa_write_acpi_tables(struct device *dev, unsigned long current,
349 struct acpi_rsdp *rsdp)
350{
351 acpi_dmar_t *const dmar = (acpi_dmar_t *)current;
352
353 /* Create DMAR table only if we have VT-d capability
354 * and FSP does not override its feature.
355 */
356 if ((pci_read_config32(dev, CAPID0_A) & VTD_DISABLE) ||
357 !(MCHBAR32(VTVC0BAR) & VTBAR_ENABLED))
358 return current;
359
360 printk(BIOS_DEBUG, "ACPI: * DMAR\n");
361 acpi_create_dmar(dmar, DMAR_INTR_REMAP, soc_fill_dmar);
362 current += dmar->header.length;
363 current = acpi_align_current(current);
364 acpi_add_table(rsdp, dmar);
365
366 return current;
367}