blob: 225f4e82112d7045201784b1e97a7b760552d9a4 [file] [log] [blame]
Subrata Banik91e89c52019-11-01 18:30:01 +05301/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2019 Intel Corp.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#include <arch/acpi.h>
17#include <arch/acpigen.h>
18#include <device/mmio.h>
19#include <arch/smp/mpspec.h>
20#include <cbmem.h>
21#include <ec/google/chromeec/ec.h>
22#include <intelblocks/cpulib.h>
23#include <intelblocks/pmclib.h>
24#include <intelblocks/acpi.h>
25#include <soc/cpu.h>
26#include <soc/iomap.h>
27#include <soc/nvs.h>
28#include <soc/pci_devs.h>
29#include <soc/pm.h>
30#include <soc/soc_chip.h>
31#include <string.h>
32#include <wrdd.h>
33
34/*
35 * List of supported C-states in this processor.
36 */
37enum {
38 C_STATE_C0, /* 0 */
39 C_STATE_C1, /* 1 */
40 C_STATE_C1E, /* 2 */
41 C_STATE_C6_SHORT_LAT, /* 3 */
42 C_STATE_C6_LONG_LAT, /* 4 */
43 C_STATE_C7_SHORT_LAT, /* 5 */
44 C_STATE_C7_LONG_LAT, /* 6 */
45 C_STATE_C7S_SHORT_LAT, /* 7 */
46 C_STATE_C7S_LONG_LAT, /* 8 */
47 C_STATE_C8, /* 9 */
48 C_STATE_C9, /* 10 */
49 C_STATE_C10, /* 11 */
50 NUM_C_STATES
51};
52
53#define MWAIT_RES(state, sub_state) \
54 { \
55 .addrl = (((state) << 4) | (sub_state)), \
56 .space_id = ACPI_ADDRESS_SPACE_FIXED, \
57 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL, \
58 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT, \
59 .access_size = ACPI_FFIXEDHW_FLAG_HW_COORD, \
60 }
61
62static const acpi_cstate_t cstate_map[NUM_C_STATES] = {
63 [C_STATE_C0] = {},
64 [C_STATE_C1] = {
65 .latency = 0,
66 .power = C1_POWER,
67 .resource = MWAIT_RES(0, 0),
68 },
69 [C_STATE_C1E] = {
70 .latency = 0,
71 .power = C1_POWER,
72 .resource = MWAIT_RES(0, 1),
73 },
74 [C_STATE_C6_SHORT_LAT] = {
75 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
76 .power = C6_POWER,
77 .resource = MWAIT_RES(2, 0),
78 },
79 [C_STATE_C6_LONG_LAT] = {
80 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
81 .power = C6_POWER,
82 .resource = MWAIT_RES(2, 1),
83 },
84 [C_STATE_C7_SHORT_LAT] = {
85 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
86 .power = C7_POWER,
87 .resource = MWAIT_RES(3, 0),
88 },
89 [C_STATE_C7_LONG_LAT] = {
90 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
91 .power = C7_POWER,
92 .resource = MWAIT_RES(3, 1),
93 },
94 [C_STATE_C7S_SHORT_LAT] = {
95 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
96 .power = C7_POWER,
97 .resource = MWAIT_RES(3, 2),
98 },
99 [C_STATE_C7S_LONG_LAT] = {
100 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
101 .power = C7_POWER,
102 .resource = MWAIT_RES(3, 3),
103 },
104 [C_STATE_C8] = {
105 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
106 .power = C8_POWER,
107 .resource = MWAIT_RES(4, 0),
108 },
109 [C_STATE_C9] = {
110 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
111 .power = C9_POWER,
112 .resource = MWAIT_RES(5, 0),
113 },
114 [C_STATE_C10] = {
115 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
116 .power = C10_POWER,
117 .resource = MWAIT_RES(6, 0),
118 },
119};
120
121static int cstate_set_non_s0ix[] = {
122 C_STATE_C1E,
123 C_STATE_C6_LONG_LAT,
124 C_STATE_C7S_LONG_LAT
125};
126
127static int cstate_set_s0ix[] = {
128 C_STATE_C1E,
129 C_STATE_C7S_LONG_LAT,
130 C_STATE_C10
131};
132
133acpi_cstate_t *soc_get_cstate_map(size_t *entries)
134{
135 static acpi_cstate_t map[MAX(ARRAY_SIZE(cstate_set_s0ix),
136 ARRAY_SIZE(cstate_set_non_s0ix))];
137 int *set;
138 int i;
139
140 config_t *config = config_of_soc();
141
142 int is_s0ix_enable = config->s0ix_enable;
143
144 if (is_s0ix_enable) {
145 *entries = ARRAY_SIZE(cstate_set_s0ix);
146 set = cstate_set_s0ix;
147 } else {
148 *entries = ARRAY_SIZE(cstate_set_non_s0ix);
149 set = cstate_set_non_s0ix;
150 }
151
152 for (i = 0; i < *entries; i++) {
153 memcpy(&map[i], &cstate_map[set[i]], sizeof(acpi_cstate_t));
154 map[i].ctype = i + 1;
155 }
156 return map;
157}
158
159void soc_power_states_generation(int core_id, int cores_per_package)
160{
161 config_t *config = config_of_soc();
162
163 if (config->eist_enable)
164 /* Generate P-state tables */
165 generate_p_state_entries(core_id, cores_per_package);
166}
167
168void soc_fill_fadt(acpi_fadt_t *fadt)
169{
170 const uint16_t pmbase = ACPI_BASE_ADDRESS;
171
172 config_t *config = config_of_soc();
173
174 if (!config->PmTimerDisabled) {
175 fadt->pm_tmr_blk = pmbase + PM1_TMR;
176 fadt->pm_tmr_len = 4;
177 fadt->x_pm_tmr_blk.space_id = 1;
178 fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8;
179 fadt->x_pm_tmr_blk.bit_offset = 0;
180 fadt->x_pm_tmr_blk.access_size = 0;
181 fadt->x_pm_tmr_blk.addrl = pmbase + PM1_TMR;
182 fadt->x_pm_tmr_blk.addrh = 0x0;
183 }
184
185 if (config->s0ix_enable)
186 fadt->flags |= ACPI_FADT_LOW_PWR_IDLE_S0;
187}
188
189uint32_t soc_read_sci_irq_select(void)
190{
191 uintptr_t pmc_bar = soc_read_pmc_base();
192 return read32((void *)pmc_bar + IRQ_REG);
193}
194
195void acpi_create_gnvs(struct global_nvs_t *gnvs)
196{
197 config_t *config = config_of_soc();
198
199 /* Set unknown wake source */
200 gnvs->pm1i = -1;
201
202 /* CPU core count */
203 gnvs->pcnt = dev_count_cpu();
204
205 if (CONFIG(CONSOLE_CBMEM))
206 /* Update the mem console pointer. */
207 gnvs->cbmc = (uintptr_t)cbmem_find(CBMEM_ID_CONSOLE);
208
209 if (CONFIG(CHROMEOS)) {
210 /* Initialize Verified Boot data */
211 chromeos_init_chromeos_acpi(&(gnvs->chromeos));
212 if (CONFIG(EC_GOOGLE_CHROMEEC)) {
213 gnvs->chromeos.vbt2 = google_ec_running_ro() ?
214 ACTIVE_ECFW_RO : ACTIVE_ECFW_RW;
215 } else
216 gnvs->chromeos.vbt2 = ACTIVE_ECFW_RO;
217 }
218
219 /* Enable DPTF based on mainboard configuration */
220 gnvs->dpte = config->dptf_enable;
221
222 /* Fill in the Wifi Region id */
223 gnvs->cid1 = wifi_regulatory_domain();
224
225 /* Set USB2/USB3 wake enable bitmaps. */
226 gnvs->u2we = config->usb2_wake_enable_bitmap;
227 gnvs->u3we = config->usb3_wake_enable_bitmap;
228}
229
230uint32_t acpi_fill_soc_wake(uint32_t generic_pm1_en,
231 const struct chipset_power_state *ps)
232{
233 /*
234 * WAK_STS bit is set when the system is in one of the sleep states
235 * (via the SLP_EN bit) and an enabled wake event occurs. Upon setting
236 * this bit, the PMC will transition the system to the ON state and
237 * can only be set by hardware and can only be cleared by writing a one
238 * to this bit position.
239 */
240
241 generic_pm1_en |= WAK_STS | RTC_EN | PWRBTN_EN;
242 return generic_pm1_en;
243}
244
245int soc_madt_sci_irq_polarity(int sci)
246{
247 return MP_IRQ_POLARITY_HIGH;
248}