blob: 0c4ff81e8298f1456f5f1eed7ae23afca91e1401 [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/smp/mpspec.h>
Lance Zhao1bd0c0c2016-04-19 18:04:21 -070023#include <cbmem.h>
Lance Zhaoe904c7c2015-11-10 19:00:18 -080024#include <cpu/x86/smm.h>
Shaunak Sahabd427802017-07-18 00:19:33 -070025#include <gpio.h>
26#include <intelblocks/acpi.h>
27#include <intelblocks/pmclib.h>
Pratik Prajapatid06c7642017-10-11 11:52:16 -070028#include <intelblocks/sgx.h>
Lance Zhaoe904c7c2015-11-10 19:00:18 -080029#include <soc/iomap.h>
30#include <soc/pm.h>
Lance Zhao1bd0c0c2016-04-19 18:04:21 -070031#include <soc/nvs.h>
Shaunak Sahacd9e1e42016-07-12 01:22:33 -070032#include <soc/pci_devs.h>
Aaron Durbin9e815402016-09-13 12:31:57 -050033#include <string.h>
Shaunak Sahacd9e1e42016-07-12 01:22:33 -070034#include "chip.h"
Lance Zhaof51b1272015-11-09 17:06:34 -080035
Hannah Williams0f61da82016-04-18 13:47:08 -070036#define CSTATE_RES(address_space, width, offset, address) \
37 { \
38 .space_id = address_space, \
39 .bit_width = width, \
40 .bit_offset = offset, \
41 .addrl = address, \
42 }
43
Shaunak Sahabd427802017-07-18 00:19:33 -070044static acpi_cstate_t cstate_map[] = {
45 {
46 /* C1 */
47 .ctype = 1, /* ACPI C1 */
48 .latency = 1,
49 .power = 1000,
50 .resource = CSTATE_RES(ACPI_ADDRESS_SPACE_FIXED, 0, 0, 0),
51 },
52 {
53 .ctype = 2, /* ACPI C2 */
54 .latency = 50,
55 .power = 10,
56 .resource = CSTATE_RES(ACPI_ADDRESS_SPACE_IO, 8, 0, 0x415),
57 },
58 {
59 .ctype = 3, /* ACPI C3 */
60 .latency = 150,
61 .power = 10,
62 .resource = CSTATE_RES(ACPI_ADDRESS_SPACE_IO, 8, 0, 0x419),
63 }
64};
65
66uint32_t soc_read_sci_irq_select(void)
Lance Zhaof51b1272015-11-09 17:06:34 -080067{
Shaunak Sahabd427802017-07-18 00:19:33 -070068 uintptr_t pmc_bar = soc_read_pmc_base();
69 return read32((void *)pmc_bar + IRQ_REG);
Lance Zhaof51b1272015-11-09 17:06:34 -080070}
Lance Zhaoe904c7c2015-11-10 19:00:18 -080071
Mario Scheithauer841416f2017-09-18 17:08:48 +020072void soc_write_sci_irq_select(uint32_t scis)
73{
74 uintptr_t pmc_bar = soc_read_pmc_base();
75 write32((void *)pmc_bar + IRQ_REG, scis);
76}
77
Shaunak Sahabd427802017-07-18 00:19:33 -070078acpi_cstate_t *soc_get_cstate_map(size_t *entries)
Lance Zhaoe904c7c2015-11-10 19:00:18 -080079{
Shaunak Sahabd427802017-07-18 00:19:33 -070080 *entries = ARRAY_SIZE(cstate_map);
81 return cstate_map;
Lance Zhaoe904c7c2015-11-10 19:00:18 -080082}
83
Shaunak Sahabd427802017-07-18 00:19:33 -070084void acpi_create_gnvs(struct global_nvs_t *gnvs)
Lance Zhao1bd0c0c2016-04-19 18:04:21 -070085{
Shaunak Sahacd9e1e42016-07-12 01:22:33 -070086 struct soc_intel_apollolake_config *cfg;
Subrata Banik2ee54db2017-03-05 12:37:00 +053087 struct device *dev = SA_DEV_ROOT;
Shaunak Sahacd9e1e42016-07-12 01:22:33 -070088
Aaron Durbin9e815402016-09-13 12:31:57 -050089 /* Clear out GNVS. */
90 memset(gnvs, 0, sizeof(*gnvs));
Shaunak Sahacd9e1e42016-07-12 01:22:33 -070091
Furquan Shaikhd01f5a02016-06-13 22:23:49 -070092 if (IS_ENABLED(CONFIG_CONSOLE_CBMEM))
Shaunak Sahabd427802017-07-18 00:19:33 -070093 gnvs->cbmc = (uintptr_t) cbmem_find(CBMEM_ID_CONSOLE);
Furquan Shaikhd01f5a02016-06-13 22:23:49 -070094
Lance Zhao1bd0c0c2016-04-19 18:04:21 -070095 if (IS_ENABLED(CONFIG_CHROMEOS)) {
96 /* Initialize Verified Boot data */
Joel Kitching6fbd8742018-08-23 14:56:25 +080097 chromeos_init_chromeos_acpi(&gnvs->chromeos);
Lance Zhao1bd0c0c2016-04-19 18:04:21 -070098 gnvs->chromeos.vbt2 = ACTIVE_ECFW_RO;
99 }
Shaunak Sahacd9e1e42016-07-12 01:22:33 -0700100
Shaunak Saha60b46182016-08-02 17:25:13 -0700101 /* Set unknown wake source */
102 gnvs->pm1i = ~0ULL;
Aaron Durbin9e815402016-09-13 12:31:57 -0500103
Duncan Laurie1d359b52016-09-21 18:30:44 -0700104 /* CPU core count */
105 gnvs->pcnt = dev_count_cpu();
106
Aaron Durbin9e815402016-09-13 12:31:57 -0500107 if (!dev || !dev->chip_info) {
108 printk(BIOS_ERR, "BUG! Could not find SOC devicetree config\n");
109 return;
110 }
111 cfg = dev->chip_info;
112
113 /* Enable DPTF based on mainboard configuration */
114 gnvs->dpte = cfg->dptf_enable;
Vaibhav Shankaref8deaf2016-08-23 17:56:17 -0700115
116 /* Assign address of PERST_0 if GPIO is defined in devicetree */
117 if (cfg->prt0_gpio != GPIO_PRT0_UDEF)
Shaunak Sahabd427802017-07-18 00:19:33 -0700118 gnvs->prt0 = (uintptr_t) gpio_dwx_address(cfg->prt0_gpio);
Venkateswarlu Vinjamuri6dd7b402017-02-24 15:37:30 -0800119
Venkateswarlu Vinjamuri99ce8a92017-03-22 18:24:52 -0700120 /* Get sdcard cd GPIO portid if GPIO is defined in devicetree.
121 * Get offset of sdcard cd pin.
122 */
123 if (cfg->sdcard_cd_gpio) {
124 gnvs->scdp = gpio_get_pad_portid(cfg->sdcard_cd_gpio);
125 gnvs->scdo = gpio_acpi_pin(cfg->sdcard_cd_gpio);
126 }
Pratik Prajapatid06c7642017-10-11 11:52:16 -0700127
128 if (IS_ENABLED(CONFIG_SOC_INTEL_COMMON_BLOCK_SGX))
129 sgx_fill_gnvs(gnvs);
Shaunak Saha60b46182016-08-02 17:25:13 -0700130}
131
Shaunak Sahabd427802017-07-18 00:19:33 -0700132uint32_t acpi_fill_soc_wake(uint32_t generic_pm1_en,
133 const struct chipset_power_state *ps)
Shaunak Saha60b46182016-08-02 17:25:13 -0700134{
Shaunak Saha60b46182016-08-02 17:25:13 -0700135 /*
Shaunak Saha60b46182016-08-02 17:25:13 -0700136 * WAK_STS bit is set when the system is in one of the sleep states
137 * (via the SLP_EN bit) and an enabled wake event occurs. Upon setting
138 * this bit, the PMC will transition the system to the ON state and
139 * can only be set by hardware and can only be cleared by writing a one
140 * to this bit position.
141 */
Shaunak Saha60b46182016-08-02 17:25:13 -0700142
Shaunak Sahabd427802017-07-18 00:19:33 -0700143 generic_pm1_en |= WAK_STS | RTC_EN | PWRBTN_EN;
144 return generic_pm1_en;
Lance Zhao1bd0c0c2016-04-19 18:04:21 -0700145}
146
Shaunak Sahabd427802017-07-18 00:19:33 -0700147int soc_madt_sci_irq_polarity(int sci)
Lance Zhao1bd0c0c2016-04-19 18:04:21 -0700148{
Shaunak Sahabd427802017-07-18 00:19:33 -0700149 return MP_IRQ_POLARITY_LOW;
Hannah Williams0f61da82016-04-18 13:47:08 -0700150}
151
Shaunak Sahabd427802017-07-18 00:19:33 -0700152void soc_fill_fadt(acpi_fadt_t *fadt)
Hannah Williams0f61da82016-04-18 13:47:08 -0700153{
Shaunak Saha7210ec02017-12-13 09:37:05 -0800154 const struct soc_intel_apollolake_config *cfg;
155 struct device *dev = SA_DEV_ROOT;
156
Shaunak Sahabd427802017-07-18 00:19:33 -0700157 fadt->pm_tmr_blk = ACPI_BASE_ADDRESS + PM1_TMR;
158
159 fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED;
160 fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED;
161
162 fadt->pm_tmr_len = 4;
163 fadt->duty_width = 3;
164
165 fadt->iapc_boot_arch = ACPI_FADT_LEGACY_DEVICES | ACPI_FADT_8042;
166
167 fadt->x_pm_tmr_blk.space_id = 1;
168 fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8;
169 fadt->x_pm_tmr_blk.addrl = ACPI_BASE_ADDRESS + PM1_TMR;
Shaunak Saha7210ec02017-12-13 09:37:05 -0800170
171 if (!dev || !dev->chip_info) {
172 printk(BIOS_ERR, "BUG! Could not find SOC devicetree config\n");
173 return;
174 }
Elyes HAOUAS88607a42018-10-05 10:36:45 +0200175 cfg = dev->chip_info;
Shaunak Saha7210ec02017-12-13 09:37:05 -0800176
177 if(cfg->lpss_s0ix_enable)
178 fadt->flags |= ACPI_FADT_LOW_PWR_IDLE_S0;
Shaunak Sahabd427802017-07-18 00:19:33 -0700179}
180
181void soc_power_states_generation(int core_id, int cores_per_package)
182{
183 /* Generate P-state tables */
184 generate_p_state_entries(core_id, cores_per_package);
185
186 /* Generate T-state tables */
187 generate_t_state_entries(core_id, cores_per_package);
Hannah Williams0f61da82016-04-18 13:47:08 -0700188}
Furquan Shaikh00a9e382016-10-20 22:45:26 -0700189
190static void acpigen_soc_get_dw0_in_local5(uintptr_t addr)
191{
192 /*
193 * Store (\_SB.GPC0 (addr), Local5)
194 * \_SB.GPC0 is used to read cfg0 value from dw0. It is defined in
195 * gpiolib.asl.
196 */
197 acpigen_write_store();
198 acpigen_emit_namestring("\\_SB.GPC0");
199 acpigen_write_integer(addr);
200 acpigen_emit_byte(LOCAL5_OP);
201}
202
203static int acpigen_soc_get_gpio_val(unsigned int gpio_num, uint32_t mask)
204{
Lee Leahyd8fb3622017-03-09 10:10:25 -0800205 assert(gpio_num < TOTAL_PADS);
Shaunak Sahabd427802017-07-18 00:19:33 -0700206 uintptr_t addr = (uintptr_t) gpio_dwx_address(gpio_num);
Furquan Shaikh00a9e382016-10-20 22:45:26 -0700207
208 acpigen_soc_get_dw0_in_local5(addr);
209
210 /* If (And (Local5, mask)) */
211 acpigen_write_if_and(LOCAL5_OP, mask);
212
213 /* Store (One, Local0) */
214 acpigen_write_store_ops(ONE_OP, LOCAL0_OP);
215
216 acpigen_pop_len(); /* If */
217
218 /* Else */
219 acpigen_write_else();
220
221 /* Store (Zero, Local0) */
222 acpigen_write_store_ops(ZERO_OP, LOCAL0_OP);
223
224 acpigen_pop_len(); /* Else */
225
226 return 0;
227}
228
229static int acpigen_soc_set_gpio_val(unsigned int gpio_num, uint32_t val)
230{
Lee Leahyd8fb3622017-03-09 10:10:25 -0800231 assert(gpio_num < TOTAL_PADS);
Shaunak Sahabd427802017-07-18 00:19:33 -0700232 uintptr_t addr = (uintptr_t) gpio_dwx_address(gpio_num);
Furquan Shaikh00a9e382016-10-20 22:45:26 -0700233
234 acpigen_soc_get_dw0_in_local5(addr);
235
236 if (val) {
237 /* Or (Local5, PAD_CFG0_TX_STATE, Local5) */
238 acpigen_write_or(LOCAL5_OP, PAD_CFG0_TX_STATE, LOCAL5_OP);
239 } else {
240 /* Not (PAD_CFG0_TX_STATE, Local6) */
241 acpigen_write_not(PAD_CFG0_TX_STATE, LOCAL6_OP);
242
243 /* And (Local5, Local6, Local5) */
244 acpigen_write_and(LOCAL5_OP, LOCAL6_OP, LOCAL5_OP);
245 }
246
247 /*
248 * \_SB.SPC0 (addr, Local5)
249 * \_SB.SPC0 is used to write cfg0 value in dw0. It is defined in
250 * gpiolib.asl.
251 */
252 acpigen_emit_namestring("\\_SB.SPC0");
253 acpigen_write_integer(addr);
254 acpigen_emit_byte(LOCAL5_OP);
255
256 return 0;
257}
258
259int acpigen_soc_read_rx_gpio(unsigned int gpio_num)
260{
261 return acpigen_soc_get_gpio_val(gpio_num, PAD_CFG0_RX_STATE);
262}
263
264int acpigen_soc_get_tx_gpio(unsigned int gpio_num)
265{
266 return acpigen_soc_get_gpio_val(gpio_num, PAD_CFG0_TX_STATE);
267}
268
269int acpigen_soc_set_tx_gpio(unsigned int gpio_num)
270{
271 return acpigen_soc_set_gpio_val(gpio_num, 1);
272}
273
274int acpigen_soc_clear_tx_gpio(unsigned int gpio_num)
275{
276 return acpigen_soc_set_gpio_val(gpio_num, 0);
277}