blob: 19469dc94faeb6e302c0089c33da5134bc9e38d6 [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>
Patrick Georgi39c3d392019-04-23 12:27:22 +020023#include <console/console.h>
John Zhaodb3f0e32019-03-15 16:54:27 -070024#include <device/mmio.h>
25#include <device/pci_ops.h>
Lijian Zhao2b074d92017-08-17 14:25:24 -070026#include <ec/google/chromeec/ec.h>
27#include <intelblocks/cpulib.h>
28#include <intelblocks/pmclib.h>
29#include <intelblocks/acpi.h>
John Zhaodb3f0e32019-03-15 16:54:27 -070030#include <intelblocks/p2sb.h>
Lijian Zhao2b074d92017-08-17 14:25:24 -070031#include <soc/cpu.h>
32#include <soc/iomap.h>
33#include <soc/nvs.h>
34#include <soc/pci_devs.h>
35#include <soc/pm.h>
John Zhaodb3f0e32019-03-15 16:54:27 -070036#include <soc/systemagent.h>
Shaunak Saha95b61752017-10-04 23:08:40 -070037#include <string.h>
Lijian Zhao2b074d92017-08-17 14:25:24 -070038#include <vendorcode/google/chromeos/gnvs.h>
39#include <wrdd.h>
40
Shaunak Saha95b61752017-10-04 23:08:40 -070041/*
42 * List of supported C-states in this processor.
43 */
44enum {
45 C_STATE_C0, /* 0 */
46 C_STATE_C1, /* 1 */
47 C_STATE_C1E, /* 2 */
48 C_STATE_C6_SHORT_LAT, /* 3 */
49 C_STATE_C6_LONG_LAT, /* 4 */
50 C_STATE_C7_SHORT_LAT, /* 5 */
51 C_STATE_C7_LONG_LAT, /* 6 */
52 C_STATE_C7S_SHORT_LAT, /* 7 */
53 C_STATE_C7S_LONG_LAT, /* 8 */
54 C_STATE_C8, /* 9 */
55 C_STATE_C9, /* 10 */
56 C_STATE_C10, /* 11 */
57 NUM_C_STATES
58};
59
60#define MWAIT_RES(state, sub_state) \
61 { \
62 .addrl = (((state) << 4) | (sub_state)), \
63 .space_id = ACPI_ADDRESS_SPACE_FIXED, \
64 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL, \
65 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT, \
66 .access_size = ACPI_FFIXEDHW_FLAG_HW_COORD, \
67 }
68
69static const acpi_cstate_t cstate_map[NUM_C_STATES] = {
70 [C_STATE_C0] = {},
71 [C_STATE_C1] = {
72 .latency = 0,
73 .power = C1_POWER,
74 .resource = MWAIT_RES(0, 0),
75 },
76 [C_STATE_C1E] = {
77 .latency = 0,
78 .power = C1_POWER,
79 .resource = MWAIT_RES(0, 1),
80 },
81 [C_STATE_C6_SHORT_LAT] = {
82 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
83 .power = C6_POWER,
84 .resource = MWAIT_RES(2, 0),
85 },
86 [C_STATE_C6_LONG_LAT] = {
87 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
88 .power = C6_POWER,
89 .resource = MWAIT_RES(2, 1),
90 },
91 [C_STATE_C7_SHORT_LAT] = {
92 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
93 .power = C7_POWER,
94 .resource = MWAIT_RES(3, 0),
95 },
96 [C_STATE_C7_LONG_LAT] = {
97 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
98 .power = C7_POWER,
99 .resource = MWAIT_RES(3, 1),
100 },
101 [C_STATE_C7S_SHORT_LAT] = {
102 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
103 .power = C7_POWER,
104 .resource = MWAIT_RES(3, 2),
105 },
106 [C_STATE_C7S_LONG_LAT] = {
107 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
108 .power = C7_POWER,
109 .resource = MWAIT_RES(3, 3),
110 },
111 [C_STATE_C8] = {
112 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
113 .power = C8_POWER,
114 .resource = MWAIT_RES(4, 0),
115 },
116 [C_STATE_C9] = {
117 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
118 .power = C9_POWER,
119 .resource = MWAIT_RES(5, 0),
120 },
121 [C_STATE_C10] = {
122 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
123 .power = C10_POWER,
124 .resource = MWAIT_RES(6, 0),
125 },
126};
127
Ronak Kanabarc6c4d002019-01-30 18:53:14 +0530128static int cstate_set_non_s0ix[] = {
Shaunak Saha95b61752017-10-04 23:08:40 -0700129 C_STATE_C1E,
130 C_STATE_C6_LONG_LAT,
131 C_STATE_C7S_LONG_LAT
132};
133
Ronak Kanabarc6c4d002019-01-30 18:53:14 +0530134static int cstate_set_s0ix[] = {
Shaunak Saha95b61752017-10-04 23:08:40 -0700135 C_STATE_C1E,
136 C_STATE_C7S_LONG_LAT,
137 C_STATE_C10
138};
139
140acpi_cstate_t *soc_get_cstate_map(size_t *entries)
141{
142 static acpi_cstate_t map[MAX(ARRAY_SIZE(cstate_set_s0ix),
143 ARRAY_SIZE(cstate_set_non_s0ix))];
144 int *set;
145 int i;
Elyes HAOUAS3c8b5d02018-05-27 16:57:24 +0200146 struct device *dev = SA_DEV_ROOT;
Shaunak Saha95b61752017-10-04 23:08:40 -0700147 config_t *config = dev->chip_info;
148 int is_s0ix_enable = config->s0ix_enable;
149
150 if (is_s0ix_enable) {
151 *entries = ARRAY_SIZE(cstate_set_s0ix);
152 set = cstate_set_s0ix;
153 } else {
154 *entries = ARRAY_SIZE(cstate_set_non_s0ix);
155 set = cstate_set_non_s0ix;
156 }
157
158 for (i = 0; i < *entries; i++) {
159 memcpy(&map[i], &cstate_map[set[i]], sizeof(acpi_cstate_t));
160 map[i].ctype = i + 1;
161 }
162 return map;
163}
164
165void soc_power_states_generation(int core_id, int cores_per_package)
166{
Elyes HAOUAS3c8b5d02018-05-27 16:57:24 +0200167 struct device *dev = SA_DEV_ROOT;
Shaunak Saha95b61752017-10-04 23:08:40 -0700168 config_t *config = dev->chip_info;
169 if (config->eist_enable)
170 /* Generate P-state tables */
171 generate_p_state_entries(core_id, cores_per_package);
172}
173
Lijian Zhao2b074d92017-08-17 14:25:24 -0700174void soc_fill_fadt(acpi_fadt_t *fadt)
175{
176 const uint16_t pmbase = ACPI_BASE_ADDRESS;
177 const struct device *dev = PCH_DEV_LPC;
178 const struct soc_intel_cannonlake_config *config = dev->chip_info;
179
Duncan Laurie174ca432018-09-13 16:28:13 +0000180 if (!config->PmTimerDisabled) {
181 fadt->pm_tmr_blk = pmbase + PM1_TMR;
182 fadt->pm_tmr_len = 4;
183 fadt->x_pm_tmr_blk.space_id = 1;
184 fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8;
185 fadt->x_pm_tmr_blk.bit_offset = 0;
Elyes HAOUAS8ee161d2019-03-03 12:49:56 +0100186 fadt->x_pm_tmr_blk.access_size = 0;
Duncan Laurie174ca432018-09-13 16:28:13 +0000187 fadt->x_pm_tmr_blk.addrl = pmbase + PM1_TMR;
188 fadt->x_pm_tmr_blk.addrh = 0x0;
189 }
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{
202 const struct device *dev = PCH_DEV_LPC;
203 const struct soc_intel_cannonlake_config *config = dev->chip_info;
204
205 /* Set unknown wake source */
206 gnvs->pm1i = -1;
207
208 /* CPU core count */
209 gnvs->pcnt = dev_count_cpu();
210
Julius Wernercd49cce2019-03-05 16:53:33 -0800211 if (CONFIG(CONSOLE_CBMEM))
Lijian Zhao2b074d92017-08-17 14:25:24 -0700212 /* Update the mem console pointer. */
213 gnvs->cbmc = (uintptr_t)cbmem_find(CBMEM_ID_CONSOLE);
214
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{
295 struct device *const igfx_dev = dev_find_slot(0, SA_DEVFN_IGD);
296 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);
306
307 /* Add RMRR entry */
308 tmp = current;
309 current += acpi_create_dmar_rmrr(current, 0,
310 sa_get_gsm_base(), sa_get_tolud_base() - 1);
311 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
312 acpi_dmar_rmrr_fixup(tmp, current);
313 }
314
315 struct device *const ipu_dev = dev_find_slot(0, SA_DEVFN_IPU);
316 uint64_t ipuvtbar = MCHBAR64(IPUVTBAR) & VTBAR_MASK;
317 bool ipuvten = MCHBAR32(IPUVTBAR) & VTBAR_ENABLED;
318
319 if (ipu_dev && ipu_dev->enabled && ipuvtbar && ipuvten) {
320 unsigned long tmp = current;
321
322 current += acpi_create_dmar_drhd(current, 0, 0, ipuvtbar);
323 current += acpi_create_dmar_ds_pci(current, 0, 5, 0);
324
325 acpi_dmar_drhd_fixup(tmp, current);
326 }
327
328 uint64_t vtvc0bar = MCHBAR64(VTVC0BAR) & VTBAR_MASK;
329 bool vtvc0en = MCHBAR32(VTVC0BAR) & VTBAR_ENABLED;
330
331 if (vtvc0bar && vtvc0en) {
332 const unsigned long tmp = current;
333
334 current += acpi_create_dmar_drhd(current,
335 DRHD_INCLUDE_PCI_ALL, 0, vtvc0bar);
336 current += acpi_create_dmar_ds_ioapic(current,
337 2, V_P2SB_CFG_IBDF_BUS, V_P2SB_CFG_IBDF_DEV,
338 V_P2SB_CFG_IBDF_FUNC);
339 current += acpi_create_dmar_ds_msi_hpet(current,
340 0, V_P2SB_CFG_HBDF_BUS, V_P2SB_CFG_HBDF_DEV,
341 V_P2SB_CFG_HBDF_FUNC);
342
343 acpi_dmar_drhd_fixup(tmp, current);
344 }
345
346 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);
363 current += dmar->header.length;
364 current = acpi_align_current(current);
365 acpi_add_table(rsdp, dmar);
366
367 return current;
368}