2 * This file is part of the coreboot project.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include <arch/acpi.h>
16 #include <arch/acpigen.h>
17 #include <arch/smp/mpspec.h>
19 #include <console/console.h>
20 #include <device/mmio.h>
21 #include <device/pci_ops.h>
22 #include <ec/google/chromeec/ec.h>
23 #include <intelblocks/cpulib.h>
24 #include <intelblocks/pmclib.h>
25 #include <intelblocks/acpi.h>
26 #include <intelblocks/p2sb.h>
28 #include <soc/iomap.h>
30 #include <soc/pci_devs.h>
32 #include <soc/systemagent.h>
34 #include <vendorcode/google/chromeos/gnvs.h>
40 * List of supported C-states in this processor.
46 C_STATE_C6_SHORT_LAT
, /* 3 */
47 C_STATE_C6_LONG_LAT
, /* 4 */
48 C_STATE_C7_SHORT_LAT
, /* 5 */
49 C_STATE_C7_LONG_LAT
, /* 6 */
50 C_STATE_C7S_SHORT_LAT
, /* 7 */
51 C_STATE_C7S_LONG_LAT
, /* 8 */
58 #define MWAIT_RES(state, sub_state) \
60 .addrl = (((state) << 4) | (sub_state)), \
61 .space_id = ACPI_ADDRESS_SPACE_FIXED, \
62 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL, \
63 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT, \
64 .access_size = ACPI_FFIXEDHW_FLAG_HW_COORD, \
67 static const acpi_cstate_t cstate_map
[NUM_C_STATES
] = {
72 .resource
= MWAIT_RES(0, 0),
77 .resource
= MWAIT_RES(0, 1),
79 [C_STATE_C6_SHORT_LAT
] = {
80 .latency
= C_STATE_LATENCY_FROM_LAT_REG(0),
82 .resource
= MWAIT_RES(2, 0),
84 [C_STATE_C6_LONG_LAT
] = {
85 .latency
= C_STATE_LATENCY_FROM_LAT_REG(0),
87 .resource
= MWAIT_RES(2, 1),
89 [C_STATE_C7_SHORT_LAT
] = {
90 .latency
= C_STATE_LATENCY_FROM_LAT_REG(0),
92 .resource
= MWAIT_RES(3, 0),
94 [C_STATE_C7_LONG_LAT
] = {
95 .latency
= C_STATE_LATENCY_FROM_LAT_REG(0),
97 .resource
= MWAIT_RES(3, 1),
99 [C_STATE_C7S_SHORT_LAT
] = {
100 .latency
= C_STATE_LATENCY_FROM_LAT_REG(0),
102 .resource
= MWAIT_RES(3, 2),
104 [C_STATE_C7S_LONG_LAT
] = {
105 .latency
= C_STATE_LATENCY_FROM_LAT_REG(0),
107 .resource
= MWAIT_RES(3, 3),
110 .latency
= C_STATE_LATENCY_FROM_LAT_REG(0),
112 .resource
= MWAIT_RES(4, 0),
115 .latency
= C_STATE_LATENCY_FROM_LAT_REG(0),
117 .resource
= MWAIT_RES(5, 0),
120 .latency
= C_STATE_LATENCY_FROM_LAT_REG(0),
122 .resource
= MWAIT_RES(6, 0),
126 static int cstate_set_non_s0ix
[] = {
132 static int cstate_set_s0ix
[] = {
134 C_STATE_C7S_LONG_LAT
,
138 acpi_cstate_t
*soc_get_cstate_map(size_t *entries
)
140 static acpi_cstate_t map
[MAX(ARRAY_SIZE(cstate_set_s0ix
),
141 ARRAY_SIZE(cstate_set_non_s0ix
))];
145 config_t
*config
= config_of_soc();
147 int is_s0ix_enable
= config
->s0ix_enable
;
149 if (is_s0ix_enable
) {
150 *entries
= ARRAY_SIZE(cstate_set_s0ix
);
151 set
= cstate_set_s0ix
;
153 *entries
= ARRAY_SIZE(cstate_set_non_s0ix
);
154 set
= cstate_set_non_s0ix
;
157 for (i
= 0; i
< *entries
; i
++) {
158 memcpy(&map
[i
], &cstate_map
[set
[i
]], sizeof(acpi_cstate_t
));
159 map
[i
].ctype
= i
+ 1;
164 void soc_power_states_generation(int core_id
, int cores_per_package
)
166 config_t
*config
= config_of_soc();
168 /* Generate P-state tables */
169 if (config
->eist_enable
)
170 generate_p_state_entries(core_id
, cores_per_package
);
173 void soc_fill_fadt(acpi_fadt_t
*fadt
)
175 const uint16_t pmbase
= ACPI_BASE_ADDRESS
;
176 const struct soc_intel_cannonlake_config
*config
;
177 config
= config_of_soc();
179 fadt
->pm_tmr_blk
= pmbase
+ PM1_TMR
;
180 fadt
->pm_tmr_len
= 4;
181 fadt
->x_pm_tmr_blk
.space_id
= 1;
182 fadt
->x_pm_tmr_blk
.bit_width
= fadt
->pm_tmr_len
* 8;
183 fadt
->x_pm_tmr_blk
.bit_offset
= 0;
184 fadt
->x_pm_tmr_blk
.access_size
= 0;
185 fadt
->x_pm_tmr_blk
.addrl
= pmbase
+ PM1_TMR
;
186 fadt
->x_pm_tmr_blk
.addrh
= 0x0;
188 if (config
->s0ix_enable
)
189 fadt
->flags
|= ACPI_FADT_LOW_PWR_IDLE_S0
;
191 uint32_t soc_read_sci_irq_select(void)
193 uintptr_t pmc_bar
= soc_read_pmc_base();
194 return read32((void *)pmc_bar
+ IRQ_REG
);
197 void acpi_create_gnvs(struct global_nvs_t
*gnvs
)
199 const struct soc_intel_cannonlake_config
*config
;
200 config
= config_of_soc();
202 /* Set unknown wake source */
206 gnvs
->pcnt
= dev_count_cpu();
208 /* Update the mem console pointer. */
209 if (CONFIG(CONSOLE_CBMEM
))
210 gnvs
->cbmc
= (uintptr_t)cbmem_find(CBMEM_ID_CONSOLE
);
212 if (CONFIG(CHROMEOS
)) {
213 /* Initialize Verified Boot data */
214 chromeos_init_chromeos_acpi(&(gnvs
->chromeos
));
215 if (CONFIG(EC_GOOGLE_CHROMEEC
)) {
216 gnvs
->chromeos
.vbt2
= google_ec_running_ro() ?
217 ACTIVE_ECFW_RO
: ACTIVE_ECFW_RW
;
219 gnvs
->chromeos
.vbt2
= ACTIVE_ECFW_RO
;
222 /* Enable DPTF based on mainboard configuration */
223 gnvs
->dpte
= config
->dptf_enable
;
225 /* Fill in the Wifi Region id */
226 gnvs
->cid1
= wifi_regulatory_domain();
228 /* Set USB2/USB3 wake enable bitmaps. */
229 gnvs
->u2we
= config
->usb2_wake_enable_bitmap
;
230 gnvs
->u3we
= config
->usb3_wake_enable_bitmap
;
232 /* Fill in Above 4GB MMIO resource */
236 uint32_t acpi_fill_soc_wake(uint32_t generic_pm1_en
,
237 const struct chipset_power_state
*ps
)
240 * WAK_STS bit is set when the system is in one of the sleep states
241 * (via the SLP_EN bit) and an enabled wake event occurs. Upon setting
242 * this bit, the PMC will transition the system to the ON state and
243 * can only be set by hardware and can only be cleared by writing a one
244 * to this bit position.
247 generic_pm1_en
|= WAK_STS
| RTC_EN
| PWRBTN_EN
;
248 return generic_pm1_en
;
251 int soc_madt_sci_irq_polarity(int sci
)
253 return MP_IRQ_POLARITY_HIGH
;
256 static int acpigen_soc_gpio_op(const char *op
, unsigned int gpio_num
)
259 acpigen_emit_namestring(op
);
260 acpigen_write_integer(gpio_num
);
264 static int acpigen_soc_get_gpio_state(const char *op
, unsigned int gpio_num
)
266 /* Store (op (gpio_num), Local0) */
267 acpigen_write_store();
268 acpigen_soc_gpio_op(op
, gpio_num
);
269 acpigen_emit_byte(LOCAL0_OP
);
273 int acpigen_soc_read_rx_gpio(unsigned int gpio_num
)
275 return acpigen_soc_get_gpio_state("\\_SB.PCI0.GRXS", gpio_num
);
278 int acpigen_soc_get_tx_gpio(unsigned int gpio_num
)
280 return acpigen_soc_get_gpio_state("\\_SB.PCI0.GTXS", gpio_num
);
283 int acpigen_soc_set_tx_gpio(unsigned int gpio_num
)
285 return acpigen_soc_gpio_op("\\_SB.PCI0.STXS", gpio_num
);
288 int acpigen_soc_clear_tx_gpio(unsigned int gpio_num
)
290 return acpigen_soc_gpio_op("\\_SB.PCI0.CTXS", gpio_num
);
293 static unsigned long soc_fill_dmar(unsigned long current
)
295 struct device
*const igfx_dev
= pcidev_path_on_root(SA_DEVFN_IGD
);
296 uint64_t gfxvtbar
= MCHBAR64(GFXVTBAR
) & VTBAR_MASK
;
297 bool gfxvten
= MCHBAR32(GFXVTBAR
) & VTBAR_ENABLED
;
299 if (igfx_dev
&& igfx_dev
->enabled
&& gfxvtbar
&& gfxvten
) {
300 unsigned long tmp
= current
;
302 current
+= acpi_create_dmar_drhd(current
, 0, 0, gfxvtbar
);
303 current
+= acpi_create_dmar_ds_pci(current
, 0, 2, 0);
305 acpi_dmar_drhd_fixup(tmp
, current
);
308 struct device
*const ipu_dev
= pcidev_path_on_root(SA_DEVFN_IPU
);
309 uint64_t ipuvtbar
= MCHBAR64(IPUVTBAR
) & VTBAR_MASK
;
310 bool ipuvten
= MCHBAR32(IPUVTBAR
) & VTBAR_ENABLED
;
312 if (ipu_dev
&& ipu_dev
->enabled
&& ipuvtbar
&& ipuvten
) {
313 unsigned long tmp
= current
;
315 current
+= acpi_create_dmar_drhd(current
, 0, 0, ipuvtbar
);
316 current
+= acpi_create_dmar_ds_pci(current
, 0, 5, 0);
318 acpi_dmar_drhd_fixup(tmp
, current
);
321 uint64_t vtvc0bar
= MCHBAR64(VTVC0BAR
) & VTBAR_MASK
;
322 bool vtvc0en
= MCHBAR32(VTVC0BAR
) & VTBAR_ENABLED
;
324 if (vtvc0bar
&& vtvc0en
) {
325 const unsigned long tmp
= current
;
327 current
+= acpi_create_dmar_drhd(current
,
328 DRHD_INCLUDE_PCI_ALL
, 0, vtvc0bar
);
329 current
+= acpi_create_dmar_ds_ioapic(current
,
330 2, V_P2SB_CFG_IBDF_BUS
, V_P2SB_CFG_IBDF_DEV
,
331 V_P2SB_CFG_IBDF_FUNC
);
332 current
+= acpi_create_dmar_ds_msi_hpet(current
,
333 0, V_P2SB_CFG_HBDF_BUS
, V_P2SB_CFG_HBDF_DEV
,
334 V_P2SB_CFG_HBDF_FUNC
);
336 acpi_dmar_drhd_fixup(tmp
, current
);
340 const unsigned long tmp
= current
;
341 current
+= acpi_create_dmar_rmrr(current
, 0,
342 sa_get_gsm_base(), sa_get_tolud_base() - 1);
343 current
+= acpi_create_dmar_ds_pci(current
, 0, 2, 0);
344 acpi_dmar_rmrr_fixup(tmp
, current
);
349 unsigned long sa_write_acpi_tables(struct device
*dev
, unsigned long current
,
350 struct acpi_rsdp
*rsdp
)
352 acpi_dmar_t
*const dmar
= (acpi_dmar_t
*)current
;
354 /* Create DMAR table only if we have VT-d capability
355 * and FSP does not override its feature.
357 if ((pci_read_config32(dev
, CAPID0_A
) & VTD_DISABLE
) ||
358 !(MCHBAR32(VTVC0BAR
) & VTBAR_ENABLED
))
361 printk(BIOS_DEBUG
, "ACPI: * DMAR\n");
362 acpi_create_dmar(dmar
, DMAR_INTR_REMAP
, soc_fill_dmar
);
364 current
+= dmar
->header
.length
;
365 current
= acpi_align_current(current
);
366 acpi_add_table(rsdp
, dmar
);