blob: bf93ef40a8cf05a7713b8fe7573cf27ab972c2a8 [file] [log] [blame]
Lance Zhaof51b1272015-11-09 17:06:34 -08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2016 Intel Corp.
Mario Scheithauera39aede2017-11-06 16:47:27 +01005 * Copyright (C) 2017 Siemens AG
Lance Zhaoe904c7c2015-11-10 19:00:18 -08006 * (Written by Lance Zhao <lijian.zhao@intel.com> for Intel Corp.)
Lance Zhaof51b1272015-11-09 17:06:34 -08007 *
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; either version 2 of the License, or
11 * (at your option) any later version.
Martin Rothebabfad2016-04-10 11:09:16 -060012 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
Lance Zhaof51b1272015-11-09 17:06:34 -080017 */
18
19#include <arch/acpi.h>
Lance Zhao1bd0c0c2016-04-19 18:04:21 -070020#include <arch/acpigen.h>
Shaunak Sahabd427802017-07-18 00:19:33 -070021#include <arch/io.h>
Lance Zhao2fc82d62015-11-16 18:33:21 -080022#include <arch/ioapic.h>
23#include <arch/smp/mpspec.h>
Lance Zhao1bd0c0c2016-04-19 18:04:21 -070024#include <cbmem.h>
Lance Zhaoe904c7c2015-11-10 19:00:18 -080025#include <cpu/x86/smm.h>
Aaron Durbin1ee6f0b2016-06-10 15:50:34 -050026#include <cpu/cpu.h>
Shaunak Sahabd427802017-07-18 00:19:33 -070027#include <gpio.h>
28#include <intelblocks/acpi.h>
29#include <intelblocks/pmclib.h>
Pratik Prajapatid06c7642017-10-11 11:52:16 -070030#include <intelblocks/sgx.h>
Lance Zhaoe904c7c2015-11-10 19:00:18 -080031#include <soc/iomap.h>
32#include <soc/pm.h>
Lance Zhao1bd0c0c2016-04-19 18:04:21 -070033#include <soc/nvs.h>
Shaunak Sahacd9e1e42016-07-12 01:22:33 -070034#include <soc/pci_devs.h>
Aaron Durbin9e815402016-09-13 12:31:57 -050035#include <string.h>
Shaunak Sahacd9e1e42016-07-12 01:22:33 -070036#include "chip.h"
Lance Zhaof51b1272015-11-09 17:06:34 -080037
Hannah Williams0f61da82016-04-18 13:47:08 -070038#define CSTATE_RES(address_space, width, offset, address) \
39 { \
40 .space_id = address_space, \
41 .bit_width = width, \
42 .bit_offset = offset, \
43 .addrl = address, \
44 }
45
Shaunak Sahabd427802017-07-18 00:19:33 -070046static acpi_cstate_t cstate_map[] = {
47 {
48 /* C1 */
49 .ctype = 1, /* ACPI C1 */
50 .latency = 1,
51 .power = 1000,
52 .resource = CSTATE_RES(ACPI_ADDRESS_SPACE_FIXED, 0, 0, 0),
53 },
54 {
55 .ctype = 2, /* ACPI C2 */
56 .latency = 50,
57 .power = 10,
58 .resource = CSTATE_RES(ACPI_ADDRESS_SPACE_IO, 8, 0, 0x415),
59 },
60 {
61 .ctype = 3, /* ACPI C3 */
62 .latency = 150,
63 .power = 10,
64 .resource = CSTATE_RES(ACPI_ADDRESS_SPACE_IO, 8, 0, 0x419),
65 }
66};
67
68uint32_t soc_read_sci_irq_select(void)
Lance Zhaof51b1272015-11-09 17:06:34 -080069{
Shaunak Sahabd427802017-07-18 00:19:33 -070070 uintptr_t pmc_bar = soc_read_pmc_base();
71 return read32((void *)pmc_bar + IRQ_REG);
Lance Zhaof51b1272015-11-09 17:06:34 -080072}
Lance Zhaoe904c7c2015-11-10 19:00:18 -080073
Mario Scheithauer841416f2017-09-18 17:08:48 +020074void soc_write_sci_irq_select(uint32_t scis)
75{
76 uintptr_t pmc_bar = soc_read_pmc_base();
77 write32((void *)pmc_bar + IRQ_REG, scis);
78}
79
Shaunak Sahabd427802017-07-18 00:19:33 -070080acpi_cstate_t *soc_get_cstate_map(size_t *entries)
Lance Zhaoe904c7c2015-11-10 19:00:18 -080081{
Shaunak Sahabd427802017-07-18 00:19:33 -070082 *entries = ARRAY_SIZE(cstate_map);
83 return cstate_map;
Lance Zhaoe904c7c2015-11-10 19:00:18 -080084}
85
Shaunak Sahabd427802017-07-18 00:19:33 -070086void acpi_create_gnvs(struct global_nvs_t *gnvs)
Lance Zhao1bd0c0c2016-04-19 18:04:21 -070087{
Shaunak Sahacd9e1e42016-07-12 01:22:33 -070088 struct soc_intel_apollolake_config *cfg;
Subrata Banik2ee54db2017-03-05 12:37:00 +053089 struct device *dev = SA_DEV_ROOT;
Shaunak Sahacd9e1e42016-07-12 01:22:33 -070090
Aaron Durbin9e815402016-09-13 12:31:57 -050091 /* Clear out GNVS. */
92 memset(gnvs, 0, sizeof(*gnvs));
Shaunak Sahacd9e1e42016-07-12 01:22:33 -070093
Furquan Shaikhd01f5a02016-06-13 22:23:49 -070094 if (IS_ENABLED(CONFIG_CONSOLE_CBMEM))
Shaunak Sahabd427802017-07-18 00:19:33 -070095 gnvs->cbmc = (uintptr_t) cbmem_find(CBMEM_ID_CONSOLE);
Furquan Shaikhd01f5a02016-06-13 22:23:49 -070096
Lance Zhao1bd0c0c2016-04-19 18:04:21 -070097 if (IS_ENABLED(CONFIG_CHROMEOS)) {
98 /* Initialize Verified Boot data */
Joel Kitching6fbd8742018-08-23 14:56:25 +080099 chromeos_init_chromeos_acpi(&gnvs->chromeos);
Lance Zhao1bd0c0c2016-04-19 18:04:21 -0700100 gnvs->chromeos.vbt2 = ACTIVE_ECFW_RO;
101 }
Shaunak Sahacd9e1e42016-07-12 01:22:33 -0700102
Shaunak Saha60b46182016-08-02 17:25:13 -0700103 /* Set unknown wake source */
104 gnvs->pm1i = ~0ULL;
Aaron Durbin9e815402016-09-13 12:31:57 -0500105
Duncan Laurie1d359b52016-09-21 18:30:44 -0700106 /* CPU core count */
107 gnvs->pcnt = dev_count_cpu();
108
Aaron Durbin9e815402016-09-13 12:31:57 -0500109 if (!dev || !dev->chip_info) {
110 printk(BIOS_ERR, "BUG! Could not find SOC devicetree config\n");
111 return;
112 }
113 cfg = dev->chip_info;
114
115 /* Enable DPTF based on mainboard configuration */
116 gnvs->dpte = cfg->dptf_enable;
Vaibhav Shankaref8deaf2016-08-23 17:56:17 -0700117
118 /* Assign address of PERST_0 if GPIO is defined in devicetree */
119 if (cfg->prt0_gpio != GPIO_PRT0_UDEF)
Shaunak Sahabd427802017-07-18 00:19:33 -0700120 gnvs->prt0 = (uintptr_t) gpio_dwx_address(cfg->prt0_gpio);
Venkateswarlu Vinjamuri6dd7b402017-02-24 15:37:30 -0800121
Venkateswarlu Vinjamuri99ce8a92017-03-22 18:24:52 -0700122 /* Get sdcard cd GPIO portid if GPIO is defined in devicetree.
123 * Get offset of sdcard cd pin.
124 */
125 if (cfg->sdcard_cd_gpio) {
126 gnvs->scdp = gpio_get_pad_portid(cfg->sdcard_cd_gpio);
127 gnvs->scdo = gpio_acpi_pin(cfg->sdcard_cd_gpio);
128 }
Pratik Prajapatid06c7642017-10-11 11:52:16 -0700129
130 if (IS_ENABLED(CONFIG_SOC_INTEL_COMMON_BLOCK_SGX))
131 sgx_fill_gnvs(gnvs);
Shaunak Saha60b46182016-08-02 17:25:13 -0700132}
133
Shaunak Sahabd427802017-07-18 00:19:33 -0700134uint32_t acpi_fill_soc_wake(uint32_t generic_pm1_en,
135 const struct chipset_power_state *ps)
Shaunak Saha60b46182016-08-02 17:25:13 -0700136{
Shaunak Saha60b46182016-08-02 17:25:13 -0700137 /*
Shaunak Saha60b46182016-08-02 17:25:13 -0700138 * WAK_STS bit is set when the system is in one of the sleep states
139 * (via the SLP_EN bit) and an enabled wake event occurs. Upon setting
140 * this bit, the PMC will transition the system to the ON state and
141 * can only be set by hardware and can only be cleared by writing a one
142 * to this bit position.
143 */
Shaunak Saha60b46182016-08-02 17:25:13 -0700144
Shaunak Sahabd427802017-07-18 00:19:33 -0700145 generic_pm1_en |= WAK_STS | RTC_EN | PWRBTN_EN;
146 return generic_pm1_en;
Lance Zhao1bd0c0c2016-04-19 18:04:21 -0700147}
148
Shaunak Sahabd427802017-07-18 00:19:33 -0700149int soc_madt_sci_irq_polarity(int sci)
Lance Zhao1bd0c0c2016-04-19 18:04:21 -0700150{
Shaunak Sahabd427802017-07-18 00:19:33 -0700151 return MP_IRQ_POLARITY_LOW;
Hannah Williams0f61da82016-04-18 13:47:08 -0700152}
153
Shaunak Sahabd427802017-07-18 00:19:33 -0700154void soc_fill_fadt(acpi_fadt_t *fadt)
Hannah Williams0f61da82016-04-18 13:47:08 -0700155{
Shaunak Saha7210ec02017-12-13 09:37:05 -0800156 const struct soc_intel_apollolake_config *cfg;
157 struct device *dev = SA_DEV_ROOT;
158
Shaunak Sahabd427802017-07-18 00:19:33 -0700159 fadt->pm_tmr_blk = ACPI_BASE_ADDRESS + PM1_TMR;
160
161 fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED;
162 fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED;
163
164 fadt->pm_tmr_len = 4;
165 fadt->duty_width = 3;
166
167 fadt->iapc_boot_arch = ACPI_FADT_LEGACY_DEVICES | ACPI_FADT_8042;
168
169 fadt->x_pm_tmr_blk.space_id = 1;
170 fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8;
171 fadt->x_pm_tmr_blk.addrl = ACPI_BASE_ADDRESS + PM1_TMR;
Shaunak Saha7210ec02017-12-13 09:37:05 -0800172
173 if (!dev || !dev->chip_info) {
174 printk(BIOS_ERR, "BUG! Could not find SOC devicetree config\n");
175 return;
176 }
177 cfg = dev->chip_info;
178
179 if(cfg->lpss_s0ix_enable)
180 fadt->flags |= ACPI_FADT_LOW_PWR_IDLE_S0;
Shaunak Sahabd427802017-07-18 00:19:33 -0700181}
182
183void soc_power_states_generation(int core_id, int cores_per_package)
184{
185 /* Generate P-state tables */
186 generate_p_state_entries(core_id, cores_per_package);
187
188 /* Generate T-state tables */
189 generate_t_state_entries(core_id, cores_per_package);
Hannah Williams0f61da82016-04-18 13:47:08 -0700190}
Furquan Shaikh00a9e382016-10-20 22:45:26 -0700191
192static void acpigen_soc_get_dw0_in_local5(uintptr_t addr)
193{
194 /*
195 * Store (\_SB.GPC0 (addr), Local5)
196 * \_SB.GPC0 is used to read cfg0 value from dw0. It is defined in
197 * gpiolib.asl.
198 */
199 acpigen_write_store();
200 acpigen_emit_namestring("\\_SB.GPC0");
201 acpigen_write_integer(addr);
202 acpigen_emit_byte(LOCAL5_OP);
203}
204
205static int acpigen_soc_get_gpio_val(unsigned int gpio_num, uint32_t mask)
206{
Lee Leahyd8fb3622017-03-09 10:10:25 -0800207 assert(gpio_num < TOTAL_PADS);
Shaunak Sahabd427802017-07-18 00:19:33 -0700208 uintptr_t addr = (uintptr_t) gpio_dwx_address(gpio_num);
Furquan Shaikh00a9e382016-10-20 22:45:26 -0700209
210 acpigen_soc_get_dw0_in_local5(addr);
211
212 /* If (And (Local5, mask)) */
213 acpigen_write_if_and(LOCAL5_OP, mask);
214
215 /* Store (One, Local0) */
216 acpigen_write_store_ops(ONE_OP, LOCAL0_OP);
217
218 acpigen_pop_len(); /* If */
219
220 /* Else */
221 acpigen_write_else();
222
223 /* Store (Zero, Local0) */
224 acpigen_write_store_ops(ZERO_OP, LOCAL0_OP);
225
226 acpigen_pop_len(); /* Else */
227
228 return 0;
229}
230
231static int acpigen_soc_set_gpio_val(unsigned int gpio_num, uint32_t val)
232{
Lee Leahyd8fb3622017-03-09 10:10:25 -0800233 assert(gpio_num < TOTAL_PADS);
Shaunak Sahabd427802017-07-18 00:19:33 -0700234 uintptr_t addr = (uintptr_t) gpio_dwx_address(gpio_num);
Furquan Shaikh00a9e382016-10-20 22:45:26 -0700235
236 acpigen_soc_get_dw0_in_local5(addr);
237
238 if (val) {
239 /* Or (Local5, PAD_CFG0_TX_STATE, Local5) */
240 acpigen_write_or(LOCAL5_OP, PAD_CFG0_TX_STATE, LOCAL5_OP);
241 } else {
242 /* Not (PAD_CFG0_TX_STATE, Local6) */
243 acpigen_write_not(PAD_CFG0_TX_STATE, LOCAL6_OP);
244
245 /* And (Local5, Local6, Local5) */
246 acpigen_write_and(LOCAL5_OP, LOCAL6_OP, LOCAL5_OP);
247 }
248
249 /*
250 * \_SB.SPC0 (addr, Local5)
251 * \_SB.SPC0 is used to write cfg0 value in dw0. It is defined in
252 * gpiolib.asl.
253 */
254 acpigen_emit_namestring("\\_SB.SPC0");
255 acpigen_write_integer(addr);
256 acpigen_emit_byte(LOCAL5_OP);
257
258 return 0;
259}
260
261int acpigen_soc_read_rx_gpio(unsigned int gpio_num)
262{
263 return acpigen_soc_get_gpio_val(gpio_num, PAD_CFG0_RX_STATE);
264}
265
266int acpigen_soc_get_tx_gpio(unsigned int gpio_num)
267{
268 return acpigen_soc_get_gpio_val(gpio_num, PAD_CFG0_TX_STATE);
269}
270
271int acpigen_soc_set_tx_gpio(unsigned int gpio_num)
272{
273 return acpigen_soc_set_gpio_val(gpio_num, 1);
274}
275
276int acpigen_soc_clear_tx_gpio(unsigned int gpio_num)
277{
278 return acpigen_soc_set_gpio_val(gpio_num, 0);
279}