blob: 967fe284bda035eb92cd0a83a3eacb9fd6d9b4e4 [file] [log] [blame]
Aamir Bohra3ee54bb2018-10-17 11:55:01 +05301/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2018 Intel Corp.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#include <arch/acpi.h>
17#include <arch/acpigen.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020018#include <device/mmio.h>
Aamir Bohra3ee54bb2018-10-17 11:55:01 +053019#include <arch/smp/mpspec.h>
20#include <cbmem.h>
21#include <chip.h>
Aamir Bohra3ee54bb2018-10-17 11:55:01 +053022#include <ec/google/chromeec/ec.h>
23#include <intelblocks/cpulib.h>
24#include <intelblocks/pmclib.h>
25#include <intelblocks/acpi.h>
26#include <soc/cpu.h>
27#include <soc/iomap.h>
28#include <soc/nvs.h>
29#include <soc/pci_devs.h>
30#include <soc/pm.h>
31#include <string.h>
32#include <vendorcode/google/chromeos/gnvs.h>
33#include <wrdd.h>
34
35/*
36 * List of supported C-states in this processor.
37 */
38enum {
39 C_STATE_C0, /* 0 */
40 C_STATE_C1, /* 1 */
41 C_STATE_C1E, /* 2 */
42 C_STATE_C6_SHORT_LAT, /* 3 */
43 C_STATE_C6_LONG_LAT, /* 4 */
44 C_STATE_C7_SHORT_LAT, /* 5 */
45 C_STATE_C7_LONG_LAT, /* 6 */
46 C_STATE_C7S_SHORT_LAT, /* 7 */
47 C_STATE_C7S_LONG_LAT, /* 8 */
48 C_STATE_C8, /* 9 */
49 C_STATE_C9, /* 10 */
50 C_STATE_C10, /* 11 */
51 NUM_C_STATES
52};
53
54#define MWAIT_RES(state, sub_state) \
55 { \
56 .addrl = (((state) << 4) | (sub_state)), \
57 .space_id = ACPI_ADDRESS_SPACE_FIXED, \
58 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL, \
59 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT, \
60 .access_size = ACPI_FFIXEDHW_FLAG_HW_COORD, \
61 }
62
63static const acpi_cstate_t cstate_map[NUM_C_STATES] = {
64 [C_STATE_C0] = {},
65 [C_STATE_C1] = {
66 .latency = 0,
67 .power = C1_POWER,
68 .resource = MWAIT_RES(0, 0),
69 },
70 [C_STATE_C1E] = {
71 .latency = 0,
72 .power = C1_POWER,
73 .resource = MWAIT_RES(0, 1),
74 },
75 [C_STATE_C6_SHORT_LAT] = {
76 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
77 .power = C6_POWER,
78 .resource = MWAIT_RES(2, 0),
79 },
80 [C_STATE_C6_LONG_LAT] = {
81 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
82 .power = C6_POWER,
83 .resource = MWAIT_RES(2, 1),
84 },
85 [C_STATE_C7_SHORT_LAT] = {
86 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
87 .power = C7_POWER,
88 .resource = MWAIT_RES(3, 0),
89 },
90 [C_STATE_C7_LONG_LAT] = {
91 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
92 .power = C7_POWER,
93 .resource = MWAIT_RES(3, 1),
94 },
95 [C_STATE_C7S_SHORT_LAT] = {
96 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
97 .power = C7_POWER,
98 .resource = MWAIT_RES(3, 2),
99 },
100 [C_STATE_C7S_LONG_LAT] = {
101 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
102 .power = C7_POWER,
103 .resource = MWAIT_RES(3, 3),
104 },
105 [C_STATE_C8] = {
106 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
107 .power = C8_POWER,
108 .resource = MWAIT_RES(4, 0),
109 },
110 [C_STATE_C9] = {
111 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
112 .power = C9_POWER,
113 .resource = MWAIT_RES(5, 0),
114 },
115 [C_STATE_C10] = {
116 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
117 .power = C10_POWER,
118 .resource = MWAIT_RES(6, 0),
119 },
120};
121
Subrata Banik3f559d962019-01-30 18:44:09 +0530122static int cstate_set_non_s0ix[] = {
Aamir Bohra3ee54bb2018-10-17 11:55:01 +0530123 C_STATE_C1E,
124 C_STATE_C6_LONG_LAT,
125 C_STATE_C7S_LONG_LAT
126};
127
Subrata Banik3f559d962019-01-30 18:44:09 +0530128static int cstate_set_s0ix[] = {
Aamir Bohra3ee54bb2018-10-17 11:55:01 +0530129 C_STATE_C1E,
130 C_STATE_C7S_LONG_LAT,
131 C_STATE_C10
132};
133
134acpi_cstate_t *soc_get_cstate_map(size_t *entries)
135{
136 static acpi_cstate_t map[MAX(ARRAY_SIZE(cstate_set_s0ix),
137 ARRAY_SIZE(cstate_set_non_s0ix))];
138 int *set;
139 int i;
140 struct device *dev = SA_DEV_ROOT;
141 config_t *config = dev->chip_info;
142 int is_s0ix_enable = config->s0ix_enable;
143
144 if (is_s0ix_enable) {
145 *entries = ARRAY_SIZE(cstate_set_s0ix);
146 set = cstate_set_s0ix;
147 } else {
148 *entries = ARRAY_SIZE(cstate_set_non_s0ix);
149 set = cstate_set_non_s0ix;
150 }
151
152 for (i = 0; i < *entries; i++) {
153 memcpy(&map[i], &cstate_map[set[i]], sizeof(acpi_cstate_t));
154 map[i].ctype = i + 1;
155 }
156 return map;
157}
158
159void soc_power_states_generation(int core_id, int cores_per_package)
160{
161 struct device *dev = SA_DEV_ROOT;
162 config_t *config = dev->chip_info;
163 if (config->eist_enable)
164 /* Generate P-state tables */
165 generate_p_state_entries(core_id, cores_per_package);
166}
167
168void soc_fill_fadt(acpi_fadt_t *fadt)
169{
170 const uint16_t pmbase = ACPI_BASE_ADDRESS;
171 const struct device *dev = PCH_DEV_LPC;
172 const struct soc_intel_icelake_config *config = dev->chip_info;
173
174 if (!config->PmTimerDisabled) {
175 fadt->pm_tmr_blk = pmbase + PM1_TMR;
176 fadt->pm_tmr_len = 4;
177 fadt->x_pm_tmr_blk.space_id = 1;
178 fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8;
179 fadt->x_pm_tmr_blk.bit_offset = 0;
Elyes HAOUAS8ee161d2019-03-03 12:49:56 +0100180 fadt->x_pm_tmr_blk.access_size = 0;
Aamir Bohra3ee54bb2018-10-17 11:55:01 +0530181 fadt->x_pm_tmr_blk.addrl = pmbase + PM1_TMR;
182 fadt->x_pm_tmr_blk.addrh = 0x0;
183 }
184
185 if (config->s0ix_enable)
186 fadt->flags |= ACPI_FADT_LOW_PWR_IDLE_S0;
187}
188uint32_t soc_read_sci_irq_select(void)
189{
190 uintptr_t pmc_bar = soc_read_pmc_base();
191 return read32((void *)pmc_bar + IRQ_REG);
192}
193
194void acpi_create_gnvs(struct global_nvs_t *gnvs)
195{
196 const struct device *dev = PCH_DEV_LPC;
197 const struct soc_intel_icelake_config *config = dev->chip_info;
198
199 /* Set unknown wake source */
200 gnvs->pm1i = -1;
201
202 /* CPU core count */
203 gnvs->pcnt = dev_count_cpu();
204
205 if (IS_ENABLED(CONFIG_CONSOLE_CBMEM))
206 /* Update the mem console pointer. */
207 gnvs->cbmc = (uintptr_t)cbmem_find(CBMEM_ID_CONSOLE);
208
209 if (IS_ENABLED(CONFIG_CHROMEOS)) {
210 /* Initialize Verified Boot data */
211 chromeos_init_chromeos_acpi(&(gnvs->chromeos));
212 if (IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC)) {
213 gnvs->chromeos.vbt2 = google_ec_running_ro() ?
214 ACTIVE_ECFW_RO : ACTIVE_ECFW_RW;
215 } else
216 gnvs->chromeos.vbt2 = ACTIVE_ECFW_RO;
217 }
218
219 /* Enable DPTF based on mainboard configuration */
220 gnvs->dpte = config->dptf_enable;
221
222 /* Fill in the Wifi Region id */
223 gnvs->cid1 = wifi_regulatory_domain();
224
225 /* Set USB2/USB3 wake enable bitmaps. */
226 gnvs->u2we = config->usb2_wake_enable_bitmap;
227 gnvs->u3we = config->usb3_wake_enable_bitmap;
228}
229
230uint32_t acpi_fill_soc_wake(uint32_t generic_pm1_en,
231 const struct chipset_power_state *ps)
232{
233 /*
234 * WAK_STS bit is set when the system is in one of the sleep states
235 * (via the SLP_EN bit) and an enabled wake event occurs. Upon setting
236 * this bit, the PMC will transition the system to the ON state and
237 * can only be set by hardware and can only be cleared by writing a one
238 * to this bit position.
239 */
240
241 generic_pm1_en |= WAK_STS | RTC_EN | PWRBTN_EN;
242 return generic_pm1_en;
243}
244
245int soc_madt_sci_irq_polarity(int sci)
246{
247 return MP_IRQ_POLARITY_HIGH;
248}