blob: b8fa9a7eeaa478698478ac55ea38d4bd63e8b8c2 [file] [log] [blame]
Angel Ponsf5627e82020-04-05 15:46:52 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Lijian Zhao2b074d92017-08-17 14:25:24 -07002
Furquan Shaikh76cedd22020-05-02 10:24:23 -07003#include <acpi/acpi.h>
Kyösti Mälkki0c1dd9c2020-06-17 23:37:49 +03004#include <acpi/acpi_gnvs.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -07005#include <acpi/acpigen.h>
Lijian Zhao2b074d92017-08-17 14:25:24 -07006#include <arch/smp/mpspec.h>
7#include <cbmem.h>
Patrick Georgi39c3d392019-04-23 12:27:22 +02008#include <console/console.h>
John Zhaodb3f0e32019-03-15 16:54:27 -07009#include <device/mmio.h>
10#include <device/pci_ops.h>
Lijian Zhao2b074d92017-08-17 14:25:24 -070011#include <intelblocks/cpulib.h>
12#include <intelblocks/pmclib.h>
13#include <intelblocks/acpi.h>
John Zhaodb3f0e32019-03-15 16:54:27 -070014#include <intelblocks/p2sb.h>
Lijian Zhao2b074d92017-08-17 14:25:24 -070015#include <soc/cpu.h>
16#include <soc/iomap.h>
17#include <soc/nvs.h>
18#include <soc/pci_devs.h>
19#include <soc/pm.h>
John Zhaodb3f0e32019-03-15 16:54:27 -070020#include <soc/systemagent.h>
Shaunak Saha95b61752017-10-04 23:08:40 -070021#include <string.h>
Lijian Zhao2b074d92017-08-17 14:25:24 -070022#include <wrdd.h>
23
Elyes HAOUASc3385072019-03-21 15:38:06 +010024#include "chip.h"
25
Shaunak Saha95b61752017-10-04 23:08:40 -070026/*
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 = 0,
58 .power = C1_POWER,
59 .resource = MWAIT_RES(0, 0),
60 },
61 [C_STATE_C1E] = {
62 .latency = 0,
63 .power = C1_POWER,
64 .resource = MWAIT_RES(0, 1),
65 },
66 [C_STATE_C6_SHORT_LAT] = {
67 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
68 .power = C6_POWER,
69 .resource = MWAIT_RES(2, 0),
70 },
71 [C_STATE_C6_LONG_LAT] = {
72 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
73 .power = C6_POWER,
74 .resource = MWAIT_RES(2, 1),
75 },
76 [C_STATE_C7_SHORT_LAT] = {
77 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
78 .power = C7_POWER,
79 .resource = MWAIT_RES(3, 0),
80 },
81 [C_STATE_C7_LONG_LAT] = {
82 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
83 .power = C7_POWER,
84 .resource = MWAIT_RES(3, 1),
85 },
86 [C_STATE_C7S_SHORT_LAT] = {
87 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
88 .power = C7_POWER,
89 .resource = MWAIT_RES(3, 2),
90 },
91 [C_STATE_C7S_LONG_LAT] = {
92 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
93 .power = C7_POWER,
94 .resource = MWAIT_RES(3, 3),
95 },
96 [C_STATE_C8] = {
97 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
98 .power = C8_POWER,
99 .resource = MWAIT_RES(4, 0),
100 },
101 [C_STATE_C9] = {
102 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
103 .power = C9_POWER,
104 .resource = MWAIT_RES(5, 0),
105 },
106 [C_STATE_C10] = {
107 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
108 .power = C10_POWER,
109 .resource = MWAIT_RES(6, 0),
110 },
111};
112
Ronak Kanabarc6c4d002019-01-30 18:53:14 +0530113static int cstate_set_non_s0ix[] = {
Shaunak Saha95b61752017-10-04 23:08:40 -0700114 C_STATE_C1E,
115 C_STATE_C6_LONG_LAT,
116 C_STATE_C7S_LONG_LAT
117};
118
Ronak Kanabarc6c4d002019-01-30 18:53:14 +0530119static int cstate_set_s0ix[] = {
Shaunak Saha95b61752017-10-04 23:08:40 -0700120 C_STATE_C1E,
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;
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300131
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +0300132 config_t *config = config_of_soc();
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300133
Shaunak Saha95b61752017-10-04 23:08:40 -0700134 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{
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +0300153 config_t *config = config_of_soc();
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300154
155 /* Generate P-state tables */
Shaunak Saha95b61752017-10-04 23:08:40 -0700156 if (config->eist_enable)
Shaunak Saha95b61752017-10-04 23:08:40 -0700157 generate_p_state_entries(core_id, cores_per_package);
158}
159
Lijian Zhao2b074d92017-08-17 14:25:24 -0700160void soc_fill_fadt(acpi_fadt_t *fadt)
161{
162 const uint16_t pmbase = ACPI_BASE_ADDRESS;
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300163 const struct soc_intel_cannonlake_config *config;
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +0300164 config = config_of_soc();
Lijian Zhao2b074d92017-08-17 14:25:24 -0700165
Meera Ravindranath48c78702019-12-12 10:37:49 +0530166 fadt->pm_tmr_blk = pmbase + PM1_TMR;
167 fadt->pm_tmr_len = 4;
Elyes HAOUAS04071f42020-07-20 17:05:24 +0200168 fadt->x_pm_tmr_blk.space_id = ACPI_ADDRESS_SPACE_IO;
Meera Ravindranath48c78702019-12-12 10:37:49 +0530169 fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8;
170 fadt->x_pm_tmr_blk.bit_offset = 0;
Patrick Rudolphc02bda02020-02-28 10:19:41 +0100171 fadt->x_pm_tmr_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
Meera Ravindranath48c78702019-12-12 10:37:49 +0530172 fadt->x_pm_tmr_blk.addrl = pmbase + PM1_TMR;
173 fadt->x_pm_tmr_blk.addrh = 0x0;
Lijian Zhao2b074d92017-08-17 14:25:24 -0700174
Duncan Laurie174ca432018-09-13 16:28:13 +0000175 if (config->s0ix_enable)
Vaibhav Shankar2da6ec42018-03-19 18:56:38 -0700176 fadt->flags |= ACPI_FADT_LOW_PWR_IDLE_S0;
Lijian Zhao2b074d92017-08-17 14:25:24 -0700177}
178uint32_t soc_read_sci_irq_select(void)
179{
180 uintptr_t pmc_bar = soc_read_pmc_base();
181 return read32((void *)pmc_bar + IRQ_REG);
182}
183
Kyösti Mälkkic2b0a4f2020-06-28 22:39:59 +0300184void soc_fill_gnvs(struct global_nvs *gnvs)
Lijian Zhao2b074d92017-08-17 14:25:24 -0700185{
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300186 const struct soc_intel_cannonlake_config *config;
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +0300187 config = config_of_soc();
Lijian Zhao2b074d92017-08-17 14:25:24 -0700188
189 /* Set unknown wake source */
190 gnvs->pm1i = -1;
191
192 /* CPU core count */
193 gnvs->pcnt = dev_count_cpu();
194
Lijian Zhao2b074d92017-08-17 14:25:24 -0700195 /* Enable DPTF based on mainboard configuration */
196 gnvs->dpte = config->dptf_enable;
197
198 /* Fill in the Wifi Region id */
199 gnvs->cid1 = wifi_regulatory_domain();
200
201 /* Set USB2/USB3 wake enable bitmaps. */
202 gnvs->u2we = config->usb2_wake_enable_bitmap;
203 gnvs->u3we = config->usb3_wake_enable_bitmap;
Subrata Banikb6df6b02020-01-03 15:29:02 +0530204
205 /* Fill in Above 4GB MMIO resource */
206 sa_fill_gnvs(gnvs);
Lijian Zhao2b074d92017-08-17 14:25:24 -0700207}
208
209uint32_t acpi_fill_soc_wake(uint32_t generic_pm1_en,
210 const struct chipset_power_state *ps)
211{
212 /*
213 * WAK_STS bit is set when the system is in one of the sleep states
214 * (via the SLP_EN bit) and an enabled wake event occurs. Upon setting
215 * this bit, the PMC will transition the system to the ON state and
216 * can only be set by hardware and can only be cleared by writing a one
217 * to this bit position.
218 */
219
220 generic_pm1_en |= WAK_STS | RTC_EN | PWRBTN_EN;
221 return generic_pm1_en;
222}
223
224int soc_madt_sci_irq_polarity(int sci)
225{
226 return MP_IRQ_POLARITY_HIGH;
227}
Lijian Zhao5ff742c2018-12-27 17:01:09 -0800228
229static int acpigen_soc_gpio_op(const char *op, unsigned int gpio_num)
230{
231 /* op (gpio_num) */
232 acpigen_emit_namestring(op);
233 acpigen_write_integer(gpio_num);
234 return 0;
235}
236
237static int acpigen_soc_get_gpio_state(const char *op, unsigned int gpio_num)
238{
239 /* Store (op (gpio_num), Local0) */
240 acpigen_write_store();
241 acpigen_soc_gpio_op(op, gpio_num);
242 acpigen_emit_byte(LOCAL0_OP);
243 return 0;
244}
245
246int acpigen_soc_read_rx_gpio(unsigned int gpio_num)
247{
248 return acpigen_soc_get_gpio_state("\\_SB.PCI0.GRXS", gpio_num);
249}
250
251int acpigen_soc_get_tx_gpio(unsigned int gpio_num)
252{
253 return acpigen_soc_get_gpio_state("\\_SB.PCI0.GTXS", gpio_num);
254}
255
256int acpigen_soc_set_tx_gpio(unsigned int gpio_num)
257{
258 return acpigen_soc_gpio_op("\\_SB.PCI0.STXS", gpio_num);
259}
260
261int acpigen_soc_clear_tx_gpio(unsigned int gpio_num)
262{
263 return acpigen_soc_gpio_op("\\_SB.PCI0.CTXS", gpio_num);
264}
John Zhaodb3f0e32019-03-15 16:54:27 -0700265
266static unsigned long soc_fill_dmar(unsigned long current)
267{
Kyösti Mälkki903b40a2019-07-03 07:25:59 +0300268 struct device *const igfx_dev = pcidev_path_on_root(SA_DEVFN_IGD);
John Zhaodb3f0e32019-03-15 16:54:27 -0700269 uint64_t gfxvtbar = MCHBAR64(GFXVTBAR) & VTBAR_MASK;
270 bool gfxvten = MCHBAR32(GFXVTBAR) & VTBAR_ENABLED;
Patrick Rudolpha9eec2c2020-07-28 12:05:17 +0200271 const bool emit_igd = igfx_dev && igfx_dev->enabled && gfxvtbar && gfxvten;
272 if (emit_igd) {
John Zhaodb3f0e32019-03-15 16:54:27 -0700273 unsigned long tmp = current;
274
275 current += acpi_create_dmar_drhd(current, 0, 0, gfxvtbar);
276 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
277
278 acpi_dmar_drhd_fixup(tmp, current);
John Zhaodb3f0e32019-03-15 16:54:27 -0700279 }
280
Kyösti Mälkki903b40a2019-07-03 07:25:59 +0300281 struct device *const ipu_dev = pcidev_path_on_root(SA_DEVFN_IPU);
John Zhaodb3f0e32019-03-15 16:54:27 -0700282 uint64_t ipuvtbar = MCHBAR64(IPUVTBAR) & VTBAR_MASK;
283 bool ipuvten = MCHBAR32(IPUVTBAR) & VTBAR_ENABLED;
284
285 if (ipu_dev && ipu_dev->enabled && ipuvtbar && ipuvten) {
286 unsigned long tmp = current;
287
288 current += acpi_create_dmar_drhd(current, 0, 0, ipuvtbar);
289 current += acpi_create_dmar_ds_pci(current, 0, 5, 0);
290
291 acpi_dmar_drhd_fixup(tmp, current);
292 }
293
294 uint64_t vtvc0bar = MCHBAR64(VTVC0BAR) & VTBAR_MASK;
295 bool vtvc0en = MCHBAR32(VTVC0BAR) & VTBAR_ENABLED;
296
297 if (vtvc0bar && vtvc0en) {
298 const unsigned long tmp = current;
299
300 current += acpi_create_dmar_drhd(current,
301 DRHD_INCLUDE_PCI_ALL, 0, vtvc0bar);
302 current += acpi_create_dmar_ds_ioapic(current,
303 2, V_P2SB_CFG_IBDF_BUS, V_P2SB_CFG_IBDF_DEV,
304 V_P2SB_CFG_IBDF_FUNC);
305 current += acpi_create_dmar_ds_msi_hpet(current,
306 0, V_P2SB_CFG_HBDF_BUS, V_P2SB_CFG_HBDF_DEV,
307 V_P2SB_CFG_HBDF_FUNC);
308
309 acpi_dmar_drhd_fixup(tmp, current);
310 }
311
Patrick Rudolpha9eec2c2020-07-28 12:05:17 +0200312 /* Add RMRR entry after all DRHD entries */
313 if (emit_igd) {
314 const unsigned long tmp = current;
315
316 current += acpi_create_dmar_rmrr(current, 0,
317 sa_get_gsm_base(), sa_get_tolud_base() - 1);
318 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
319 acpi_dmar_rmrr_fixup(tmp, current);
320 }
John Zhao1159a162019-04-22 10:45:51 -0700321
John Zhaodb3f0e32019-03-15 16:54:27 -0700322 return current;
323}
324
Furquan Shaikh0f007d82020-04-24 06:41:18 -0700325unsigned long sa_write_acpi_tables(const struct device *dev, unsigned long current,
John Zhaodb3f0e32019-03-15 16:54:27 -0700326 struct acpi_rsdp *rsdp)
327{
328 acpi_dmar_t *const dmar = (acpi_dmar_t *)current;
329
330 /* Create DMAR table only if we have VT-d capability
331 * and FSP does not override its feature.
332 */
333 if ((pci_read_config32(dev, CAPID0_A) & VTD_DISABLE) ||
334 !(MCHBAR32(VTVC0BAR) & VTBAR_ENABLED))
335 return current;
336
337 printk(BIOS_DEBUG, "ACPI: * DMAR\n");
338 acpi_create_dmar(dmar, DMAR_INTR_REMAP, soc_fill_dmar);
John Zhao1159a162019-04-22 10:45:51 -0700339
John Zhaodb3f0e32019-03-15 16:54:27 -0700340 current += dmar->header.length;
341 current = acpi_align_current(current);
342 acpi_add_table(rsdp, dmar);
343
344 return current;
345}