blob: 4dab3342f7796e27043b6c5361a8c48c287b93d8 [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/io.h>
Lijian Zhao2b074d92017-08-17 14:25:24 -070021#include <arch/smp/mpspec.h>
22#include <cbmem.h>
23#include <chip.h>
Lijian Zhao2b074d92017-08-17 14:25:24 -070024#include <ec/google/chromeec/ec.h>
25#include <intelblocks/cpulib.h>
26#include <intelblocks/pmclib.h>
27#include <intelblocks/acpi.h>
28#include <soc/cpu.h>
29#include <soc/iomap.h>
30#include <soc/nvs.h>
31#include <soc/pci_devs.h>
32#include <soc/pm.h>
Shaunak Saha95b61752017-10-04 23:08:40 -070033#include <string.h>
Lijian Zhao2b074d92017-08-17 14:25:24 -070034#include <vendorcode/google/chromeos/gnvs.h>
35#include <wrdd.h>
36
Shaunak Saha95b61752017-10-04 23:08:40 -070037/*
38 * List of supported C-states in this processor.
39 */
40enum {
41 C_STATE_C0, /* 0 */
42 C_STATE_C1, /* 1 */
43 C_STATE_C1E, /* 2 */
44 C_STATE_C6_SHORT_LAT, /* 3 */
45 C_STATE_C6_LONG_LAT, /* 4 */
46 C_STATE_C7_SHORT_LAT, /* 5 */
47 C_STATE_C7_LONG_LAT, /* 6 */
48 C_STATE_C7S_SHORT_LAT, /* 7 */
49 C_STATE_C7S_LONG_LAT, /* 8 */
50 C_STATE_C8, /* 9 */
51 C_STATE_C9, /* 10 */
52 C_STATE_C10, /* 11 */
53 NUM_C_STATES
54};
55
56#define MWAIT_RES(state, sub_state) \
57 { \
58 .addrl = (((state) << 4) | (sub_state)), \
59 .space_id = ACPI_ADDRESS_SPACE_FIXED, \
60 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL, \
61 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT, \
62 .access_size = ACPI_FFIXEDHW_FLAG_HW_COORD, \
63 }
64
65static const acpi_cstate_t cstate_map[NUM_C_STATES] = {
66 [C_STATE_C0] = {},
67 [C_STATE_C1] = {
68 .latency = 0,
69 .power = C1_POWER,
70 .resource = MWAIT_RES(0, 0),
71 },
72 [C_STATE_C1E] = {
73 .latency = 0,
74 .power = C1_POWER,
75 .resource = MWAIT_RES(0, 1),
76 },
77 [C_STATE_C6_SHORT_LAT] = {
78 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
79 .power = C6_POWER,
80 .resource = MWAIT_RES(2, 0),
81 },
82 [C_STATE_C6_LONG_LAT] = {
83 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
84 .power = C6_POWER,
85 .resource = MWAIT_RES(2, 1),
86 },
87 [C_STATE_C7_SHORT_LAT] = {
88 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
89 .power = C7_POWER,
90 .resource = MWAIT_RES(3, 0),
91 },
92 [C_STATE_C7_LONG_LAT] = {
93 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
94 .power = C7_POWER,
95 .resource = MWAIT_RES(3, 1),
96 },
97 [C_STATE_C7S_SHORT_LAT] = {
98 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
99 .power = C7_POWER,
100 .resource = MWAIT_RES(3, 2),
101 },
102 [C_STATE_C7S_LONG_LAT] = {
103 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
104 .power = C7_POWER,
105 .resource = MWAIT_RES(3, 3),
106 },
107 [C_STATE_C8] = {
108 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
109 .power = C8_POWER,
110 .resource = MWAIT_RES(4, 0),
111 },
112 [C_STATE_C9] = {
113 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
114 .power = C9_POWER,
115 .resource = MWAIT_RES(5, 0),
116 },
117 [C_STATE_C10] = {
118 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
119 .power = C10_POWER,
120 .resource = MWAIT_RES(6, 0),
121 },
122};
123
124static int cstate_set_s0ix[] = {
125 C_STATE_C1E,
126 C_STATE_C6_LONG_LAT,
127 C_STATE_C7S_LONG_LAT
128};
129
130static int cstate_set_non_s0ix[] = {
131 C_STATE_C1E,
132 C_STATE_C7S_LONG_LAT,
133 C_STATE_C10
134};
135
136acpi_cstate_t *soc_get_cstate_map(size_t *entries)
137{
138 static acpi_cstate_t map[MAX(ARRAY_SIZE(cstate_set_s0ix),
139 ARRAY_SIZE(cstate_set_non_s0ix))];
140 int *set;
141 int i;
Elyes HAOUAS3c8b5d02018-05-27 16:57:24 +0200142 struct device *dev = SA_DEV_ROOT;
Shaunak Saha95b61752017-10-04 23:08:40 -0700143 config_t *config = dev->chip_info;
144 int is_s0ix_enable = config->s0ix_enable;
145
146 if (is_s0ix_enable) {
147 *entries = ARRAY_SIZE(cstate_set_s0ix);
148 set = cstate_set_s0ix;
149 } else {
150 *entries = ARRAY_SIZE(cstate_set_non_s0ix);
151 set = cstate_set_non_s0ix;
152 }
153
154 for (i = 0; i < *entries; i++) {
155 memcpy(&map[i], &cstate_map[set[i]], sizeof(acpi_cstate_t));
156 map[i].ctype = i + 1;
157 }
158 return map;
159}
160
161void soc_power_states_generation(int core_id, int cores_per_package)
162{
Elyes HAOUAS3c8b5d02018-05-27 16:57:24 +0200163 struct device *dev = SA_DEV_ROOT;
Shaunak Saha95b61752017-10-04 23:08:40 -0700164 config_t *config = dev->chip_info;
165 if (config->eist_enable)
166 /* Generate P-state tables */
167 generate_p_state_entries(core_id, cores_per_package);
168}
169
Lijian Zhao2b074d92017-08-17 14:25:24 -0700170void soc_fill_fadt(acpi_fadt_t *fadt)
171{
172 const uint16_t pmbase = ACPI_BASE_ADDRESS;
173 const struct device *dev = PCH_DEV_LPC;
174 const struct soc_intel_cannonlake_config *config = dev->chip_info;
175
Duncan Laurie174ca432018-09-13 16:28:13 +0000176 if (!config->PmTimerDisabled) {
177 fadt->pm_tmr_blk = pmbase + PM1_TMR;
178 fadt->pm_tmr_len = 4;
179 fadt->x_pm_tmr_blk.space_id = 1;
180 fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8;
181 fadt->x_pm_tmr_blk.bit_offset = 0;
182 fadt->x_pm_tmr_blk.resv = 0;
183 fadt->x_pm_tmr_blk.addrl = pmbase + PM1_TMR;
184 fadt->x_pm_tmr_blk.addrh = 0x0;
185 }
Lijian Zhao2b074d92017-08-17 14:25:24 -0700186
Duncan Laurie174ca432018-09-13 16:28:13 +0000187 if (config->s0ix_enable)
Vaibhav Shankar2da6ec42018-03-19 18:56:38 -0700188 fadt->flags |= ACPI_FADT_LOW_PWR_IDLE_S0;
Lijian Zhao2b074d92017-08-17 14:25:24 -0700189}
190uint32_t soc_read_sci_irq_select(void)
191{
192 uintptr_t pmc_bar = soc_read_pmc_base();
193 return read32((void *)pmc_bar + IRQ_REG);
194}
195
196void acpi_create_gnvs(struct global_nvs_t *gnvs)
197{
198 const struct device *dev = PCH_DEV_LPC;
199 const struct soc_intel_cannonlake_config *config = dev->chip_info;
200
201 /* Set unknown wake source */
202 gnvs->pm1i = -1;
203
204 /* CPU core count */
205 gnvs->pcnt = dev_count_cpu();
206
207 if (IS_ENABLED(CONFIG_CONSOLE_CBMEM))
208 /* Update the mem console pointer. */
209 gnvs->cbmc = (uintptr_t)cbmem_find(CBMEM_ID_CONSOLE);
210
211 if (IS_ENABLED(CONFIG_CHROMEOS)) {
212 /* Initialize Verified Boot data */
Joel Kitching6fbd8742018-08-23 14:56:25 +0800213 chromeos_init_chromeos_acpi(&(gnvs->chromeos));
Lijian Zhao2b074d92017-08-17 14:25:24 -0700214 if (IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC)) {
215 gnvs->chromeos.vbt2 = google_ec_running_ro() ?
216 ACTIVE_ECFW_RO : ACTIVE_ECFW_RW;
217 } else
218 gnvs->chromeos.vbt2 = ACTIVE_ECFW_RO;
219 }
220
221 /* Enable DPTF based on mainboard configuration */
222 gnvs->dpte = config->dptf_enable;
223
224 /* Fill in the Wifi Region id */
225 gnvs->cid1 = wifi_regulatory_domain();
226
227 /* Set USB2/USB3 wake enable bitmaps. */
228 gnvs->u2we = config->usb2_wake_enable_bitmap;
229 gnvs->u3we = config->usb3_wake_enable_bitmap;
230}
231
232uint32_t acpi_fill_soc_wake(uint32_t generic_pm1_en,
233 const struct chipset_power_state *ps)
234{
235 /*
236 * WAK_STS bit is set when the system is in one of the sleep states
237 * (via the SLP_EN bit) and an enabled wake event occurs. Upon setting
238 * this bit, the PMC will transition the system to the ON state and
239 * can only be set by hardware and can only be cleared by writing a one
240 * to this bit position.
241 */
242
243 generic_pm1_en |= WAK_STS | RTC_EN | PWRBTN_EN;
244 return generic_pm1_en;
245}
246
247int soc_madt_sci_irq_polarity(int sci)
248{
249 return MP_IRQ_POLARITY_HIGH;
250}
Lijian Zhao5ff742c2018-12-27 17:01:09 -0800251
252static int acpigen_soc_gpio_op(const char *op, unsigned int gpio_num)
253{
254 /* op (gpio_num) */
255 acpigen_emit_namestring(op);
256 acpigen_write_integer(gpio_num);
257 return 0;
258}
259
260static int acpigen_soc_get_gpio_state(const char *op, unsigned int gpio_num)
261{
262 /* Store (op (gpio_num), Local0) */
263 acpigen_write_store();
264 acpigen_soc_gpio_op(op, gpio_num);
265 acpigen_emit_byte(LOCAL0_OP);
266 return 0;
267}
268
269int acpigen_soc_read_rx_gpio(unsigned int gpio_num)
270{
271 return acpigen_soc_get_gpio_state("\\_SB.PCI0.GRXS", gpio_num);
272}
273
274int acpigen_soc_get_tx_gpio(unsigned int gpio_num)
275{
276 return acpigen_soc_get_gpio_state("\\_SB.PCI0.GTXS", gpio_num);
277}
278
279int acpigen_soc_set_tx_gpio(unsigned int gpio_num)
280{
281 return acpigen_soc_gpio_op("\\_SB.PCI0.STXS", gpio_num);
282}
283
284int acpigen_soc_clear_tx_gpio(unsigned int gpio_num)
285{
286 return acpigen_soc_gpio_op("\\_SB.PCI0.CTXS", gpio_num);
287}