blob: af837aba5d78e1c69b20eb660d8d8199ab6c3851 [file] [log] [blame]
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -07001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <acpi/acpi.h>
4#include <acpi/acpi_gnvs.h>
5#include <acpi/acpigen.h>
6#include <arch/smp/mpspec.h>
7#include <cbmem.h>
8#include <console/console.h>
9#include <device/device.h>
10#include <device/mmio.h>
11#include <device/pci_ops.h>
12#include <ec/google/chromeec/ec.h>
13#include <intelblocks/acpi.h>
14#include <intelblocks/cpulib.h>
15#include <intelblocks/pmclib.h>
16#include <soc/cpu.h>
17#include <soc/iomap.h>
18#include <soc/nvs.h>
19#include <soc/pci_devs.h>
20#include <soc/pm.h>
21#include <soc/soc_chip.h>
22#include <soc/systemagent.h>
23#include <string.h>
24#include <wrdd.h>
25
26/*
27 * List of supported C-states in this processor.
28 */
29enum {
30 C_STATE_C0, /* 0 */
31 C_STATE_C1, /* 1 */
32 C_STATE_C1E, /* 2 */
33 C_STATE_C6_SHORT_LAT, /* 3 */
34 C_STATE_C6_LONG_LAT, /* 4 */
35 C_STATE_C7_SHORT_LAT, /* 5 */
36 C_STATE_C7_LONG_LAT, /* 6 */
37 C_STATE_C7S_SHORT_LAT, /* 7 */
38 C_STATE_C7S_LONG_LAT, /* 8 */
39 C_STATE_C8, /* 9 */
40 C_STATE_C9, /* 10 */
41 C_STATE_C10, /* 11 */
42 NUM_C_STATES
43};
44
45#define MWAIT_RES(state, sub_state) \
46 { \
47 .addrl = (((state) << 4) | (sub_state)), \
48 .space_id = ACPI_ADDRESS_SPACE_FIXED, \
49 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL, \
50 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT, \
51 .access_size = ACPI_FFIXEDHW_FLAG_HW_COORD, \
52 }
53
54static const acpi_cstate_t cstate_map[NUM_C_STATES] = {
55 [C_STATE_C0] = {},
56 [C_STATE_C1] = {
57 .latency = C1_LATENCY,
58 .power = C1_POWER,
59 .resource = MWAIT_RES(0, 0),
60 },
61 [C_STATE_C1E] = {
62 .latency = C1_LATENCY,
63 .power = C1_POWER,
64 .resource = MWAIT_RES(0, 1),
65 },
66 [C_STATE_C6_SHORT_LAT] = {
67 .latency = C6_LATENCY,
68 .power = C6_POWER,
69 .resource = MWAIT_RES(2, 0),
70 },
71 [C_STATE_C6_LONG_LAT] = {
72 .latency = C6_LATENCY,
73 .power = C6_POWER,
74 .resource = MWAIT_RES(2, 1),
75 },
76 [C_STATE_C7_SHORT_LAT] = {
77 .latency = C7_LATENCY,
78 .power = C7_POWER,
79 .resource = MWAIT_RES(3, 0),
80 },
81 [C_STATE_C7_LONG_LAT] = {
82 .latency = C7_LATENCY,
83 .power = C7_POWER,
84 .resource = MWAIT_RES(3, 1),
85 },
86 [C_STATE_C7S_SHORT_LAT] = {
87 .latency = C7_LATENCY,
88 .power = C7_POWER,
89 .resource = MWAIT_RES(3, 2),
90 },
91 [C_STATE_C7S_LONG_LAT] = {
92 .latency = C7_LATENCY,
93 .power = C7_POWER,
94 .resource = MWAIT_RES(3, 3),
95 },
96 [C_STATE_C8] = {
97 .latency = C8_LATENCY,
98 .power = C8_POWER,
99 .resource = MWAIT_RES(4, 0),
100 },
101 [C_STATE_C9] = {
102 .latency = C9_LATENCY,
103 .power = C9_POWER,
104 .resource = MWAIT_RES(5, 0),
105 },
106 [C_STATE_C10] = {
107 .latency = C10_LATENCY,
108 .power = C10_POWER,
109 .resource = MWAIT_RES(6, 0),
110 },
111};
112
113static int cstate_set_non_s0ix[] = {
114 C_STATE_C1,
115 C_STATE_C6_LONG_LAT,
116 C_STATE_C7S_LONG_LAT
117};
118
119static int cstate_set_s0ix[] = {
120 C_STATE_C1,
121 C_STATE_C7S_LONG_LAT,
122 C_STATE_C10
123};
124
125acpi_cstate_t *soc_get_cstate_map(size_t *entries)
126{
127 static acpi_cstate_t map[MAX(ARRAY_SIZE(cstate_set_s0ix),
128 ARRAY_SIZE(cstate_set_non_s0ix))];
129 int *set;
130 int i;
131
132 config_t *config = config_of_soc();
133
134 int is_s0ix_enable = config->s0ix_enable;
135
136 if (is_s0ix_enable) {
137 *entries = ARRAY_SIZE(cstate_set_s0ix);
138 set = cstate_set_s0ix;
139 } else {
140 *entries = ARRAY_SIZE(cstate_set_non_s0ix);
141 set = cstate_set_non_s0ix;
142 }
143
144 for (i = 0; i < *entries; i++) {
145 memcpy(&map[i], &cstate_map[set[i]], sizeof(acpi_cstate_t));
146 map[i].ctype = i + 1;
147 }
148 return map;
149}
150
151void soc_power_states_generation(int core_id, int cores_per_package)
152{
153 config_t *config = config_of_soc();
154
155 if (config->eist_enable)
156 /* Generate P-state tables */
157 generate_p_state_entries(core_id, cores_per_package);
158}
159
160void soc_fill_fadt(acpi_fadt_t *fadt)
161{
162 const uint16_t pmbase = ACPI_BASE_ADDRESS;
163
164 config_t *config = config_of_soc();
165
166 fadt->pm_tmr_blk = pmbase + PM1_TMR;
167 fadt->pm_tmr_len = 4;
168 fadt->x_pm_tmr_blk.space_id = ACPI_ADDRESS_SPACE_IO;
169 fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8;
170 fadt->x_pm_tmr_blk.bit_offset = 0;
171 fadt->x_pm_tmr_blk.access_size = ACPI_ACCESS_SIZE_UNDEFINED;
172 fadt->x_pm_tmr_blk.addrl = pmbase + PM1_TMR;
173 fadt->x_pm_tmr_blk.addrh = 0x0;
174
175 if (config->s0ix_enable)
176 fadt->flags |= ACPI_FADT_LOW_PWR_IDLE_S0;
177}
178
179uint32_t soc_read_sci_irq_select(void)
180{
181 uintptr_t pmc_bar = soc_read_pmc_base();
182 return read32((void *)pmc_bar + IRQ_REG);
183}
184
185static unsigned long soc_fill_dmar(unsigned long current)
186{
187 const struct device *const igfx_dev = pcidev_path_on_root(SA_DEVFN_IGD);
188 uint64_t gfxvtbar = MCHBAR64(GFXVTBAR) & VTBAR_MASK;
189 bool gfxvten = MCHBAR32(GFXVTBAR) & VTBAR_ENABLED;
190
191 if (is_dev_enabled(igfx_dev) && gfxvtbar && gfxvten) {
192 unsigned long tmp = current;
193
194 current += acpi_create_dmar_drhd(current, 0, 0, gfxvtbar);
195 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
196
197 acpi_dmar_drhd_fixup(tmp, current);
198 }
199
200 uint64_t vtvc0bar = MCHBAR64(VTVC0BAR) & VTBAR_MASK;
201 bool vtvc0en = MCHBAR32(VTVC0BAR) & VTBAR_ENABLED;
202
203 if (vtvc0bar && vtvc0en) {
204 const unsigned long tmp = current;
205
206 current += acpi_create_dmar_drhd(current,
207 DRHD_INCLUDE_PCI_ALL, 0, vtvc0bar);
208 current += acpi_create_dmar_ds_ioapic(current,
209 2, V_P2SB_CFG_IBDF_BUS, V_P2SB_CFG_IBDF_DEV,
210 V_P2SB_CFG_IBDF_FUNC);
211 current += acpi_create_dmar_ds_msi_hpet(current,
212 0, V_P2SB_CFG_HBDF_BUS, V_P2SB_CFG_HBDF_DEV,
213 V_P2SB_CFG_HBDF_FUNC);
214
215 acpi_dmar_drhd_fixup(tmp, current);
216 }
217
218 /* Add RMRR entry */
219 const unsigned long tmp = current;
220 current += acpi_create_dmar_rmrr(current, 0,
221 sa_get_gsm_base(), sa_get_tolud_base() - 1);
222 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
223 acpi_dmar_rmrr_fixup(tmp, current);
224
225 return current;
226}
227
228unsigned long sa_write_acpi_tables(const struct device *dev, unsigned long current,
229 struct acpi_rsdp *rsdp)
230{
231 acpi_dmar_t *const dmar = (acpi_dmar_t *)current;
232
233 /*
234 * Create DMAR table only if we have VT-d capability and FSP does not override its
235 * feature.
236 */
237 if ((pci_read_config32(dev, CAPID0_A) & VTD_DISABLE) ||
238 !(MCHBAR32(VTVC0BAR) & VTBAR_ENABLED))
239 return current;
240
241 printk(BIOS_DEBUG, "ACPI: * DMAR\n");
242 acpi_create_dmar(dmar, DMAR_INTR_REMAP | DMA_CTRL_PLATFORM_OPT_IN_FLAG, soc_fill_dmar);
243 current += dmar->header.length;
244 current = acpi_align_current(current);
245 acpi_add_table(rsdp, dmar);
246
247 return current;
248}
249
250void acpi_create_gnvs(struct global_nvs *gnvs)
251{
252 config_t *config = config_of_soc();
253
254 /* Set unknown wake source */
255 gnvs->pm1i = -1;
256
257 /* CPU core count */
258 gnvs->pcnt = dev_count_cpu();
259
260 if (CONFIG(CONSOLE_CBMEM))
261 /* Update the mem console pointer. */
262 gnvs->cbmc = (uintptr_t)cbmem_find(CBMEM_ID_CONSOLE);
263
264 if (CONFIG(CHROMEOS)) {
265 /* Initialize Verified Boot data */
266 chromeos_init_chromeos_acpi(&(gnvs->chromeos));
267 if (CONFIG(EC_GOOGLE_CHROMEEC)) {
268 gnvs->chromeos.vbt2 = google_ec_running_ro() ?
269 ACTIVE_ECFW_RO : ACTIVE_ECFW_RW;
270 } else
271 gnvs->chromeos.vbt2 = ACTIVE_ECFW_RO;
272 }
273
274 /* Enable DPTF based on mainboard configuration */
275 gnvs->dpte = config->dptf_enable;
276
277 /* Fill in the Wifi Region id */
278 gnvs->cid1 = wifi_regulatory_domain();
279
280 /* Set USB2/USB3 wake enable bitmaps. */
281 gnvs->u2we = config->usb2_wake_enable_bitmap;
282 gnvs->u3we = config->usb3_wake_enable_bitmap;
283
284 /* Fill in Above 4GB MMIO resource */
285 sa_fill_gnvs(gnvs);
286}
287
288uint32_t acpi_fill_soc_wake(uint32_t generic_pm1_en,
289 const struct chipset_power_state *ps)
290{
291 /*
292 * WAK_STS bit is set when the system is in one of the sleep states
293 * (via the SLP_EN bit) and an enabled wake event occurs. Upon setting
294 * this bit, the PMC will transition the system to the ON state and
295 * can only be set by hardware and can only be cleared by writing a one
296 * to this bit position.
297 */
298
299 generic_pm1_en |= WAK_STS | RTC_EN | PWRBTN_EN;
300 return generic_pm1_en;
301}
302
303int soc_madt_sci_irq_polarity(int sci)
304{
305 return MP_IRQ_POLARITY_HIGH;
306}
307
308static int acpigen_soc_gpio_op(const char *op, unsigned int gpio_num)
309{
310 /* op (gpio_num) */
311 acpigen_emit_namestring(op);
312 acpigen_write_integer(gpio_num);
313 return 0;
314}
315
316static int acpigen_soc_get_gpio_state(const char *op, unsigned int gpio_num)
317{
318 /* Store (op (gpio_num), Local0) */
319 acpigen_write_store();
320 acpigen_soc_gpio_op(op, gpio_num);
321 acpigen_emit_byte(LOCAL0_OP);
322 return 0;
323}
324
325int acpigen_soc_read_rx_gpio(unsigned int gpio_num)
326{
327 return acpigen_soc_get_gpio_state("\\_SB.PCI0.GRXS", gpio_num);
328}
329
330int acpigen_soc_get_tx_gpio(unsigned int gpio_num)
331{
332 return acpigen_soc_get_gpio_state("\\_SB.PCI0.GTXS", gpio_num);
333}
334
335int acpigen_soc_set_tx_gpio(unsigned int gpio_num)
336{
337 return acpigen_soc_gpio_op("\\_SB.PCI0.STXS", gpio_num);
338}
339
340int acpigen_soc_clear_tx_gpio(unsigned int gpio_num)
341{
342 return acpigen_soc_gpio_op("\\_SB.PCI0.CTXS", gpio_num);
343}