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