1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2016 Intel Corp.
4 * Copyright (C) 2017-2019 Siemens AG
5 * (Written by Lance Zhao <lijian.zhao@intel.com> for Intel Corp.)
6 * Copyright 2019 Google LLC
8 * Modified from coreboot apollolake/acpi.c
11 #define LOG_CATEGORY LOGC_ACPI
19 #include <acpi/acpigen.h>
20 #include <acpi/acpi_s3.h>
21 #include <asm/acpi_table.h>
22 #include <asm/cpu_common.h>
23 #include <asm/intel_acpi.h>
24 #include <asm/intel_gnvs.h>
25 #include <asm/intel_pinctrl.h>
26 #include <asm/intel_pinctrl_defs.h>
27 #include <asm/intel_regs.h>
29 #include <asm/mpspec.h>
30 #include <asm/tables.h>
31 #include <asm/arch/iomap.h>
32 #include <asm/arch/gpio.h>
33 #include <asm/arch/pm.h>
34 #include <asm/arch/systemagent.h>
36 #include <dm/uclass-internal.h>
37 #include <power/acpi_pmc.h>
39 int arch_read_sci_irq_select(void)
41 struct acpi_pmc_upriv *upriv;
45 ret = uclass_first_device_err(UCLASS_ACPI_PMC, &dev);
47 return log_msg_ret("pmc", ret);
48 upriv = dev_get_uclass_priv(dev);
50 return readl(upriv->pmc_bar0 + IRQ_REG);
53 int arch_write_sci_irq_select(uint scis)
55 struct acpi_pmc_upriv *upriv;
59 ret = uclass_first_device_err(UCLASS_ACPI_PMC, &dev);
61 return log_msg_ret("pmc", ret);
62 upriv = dev_get_uclass_priv(dev);
63 writel(scis, upriv->pmc_bar0 + IRQ_REG);
69 * chromeos_init_acpi() - Initialise basic data to boot Chrome OS
71 * This tells Chrome OS to boot in developer mode
73 * @cros: Structure to initialise
75 static void chromeos_init_acpi(struct chromeos_acpi_gnvs *cros)
77 cros->active_main_fw = 1;
78 cros->active_main_fw = 1; /* A */
79 cros->switches = CHSW_DEVELOPER_SWITCH;
80 cros->main_fw_type = 2; /* Developer */
83 int acpi_create_gnvs(struct acpi_global_nvs *gnvs)
89 memset(gnvs, '\0', sizeof(*gnvs));
91 /* TODO(sjg@chromium.org): Add the console log to gnvs->cbmc */
93 if (IS_ENABLED(CONFIG_CHROMEOS))
94 chromeos_init_acpi(&gnvs->chromeos);
96 /* Set unknown wake source */
101 ret = uclass_find_first_device(UCLASS_CPU, &cpu);
103 ret = cpu_get_count(cpu);
113 uint32_t acpi_fill_soc_wake(uint32_t generic_pm1_en)
116 * WAK_STS bit is set when the system is in one of the sleep states
117 * (via the SLP_EN bit) and an enabled wake event occurs. Upon setting
118 * this bit, the PMC will transition the system to the ON state and
119 * can only be set by hardware and can only be cleared by writing a one
120 * to this bit position.
122 generic_pm1_en |= WAK_STS | RTC_EN | PWRBTN_EN;
124 return generic_pm1_en;
127 int arch_madt_sci_irq_polarity(int sci)
129 return MP_IRQ_POLARITY_LOW;
132 void fill_fadt(struct acpi_fadt *fadt)
134 fadt->pm_tmr_blk = IOMAP_ACPI_BASE + PM1_TMR;
136 fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED;
137 fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED;
139 fadt->pm_tmr_len = 4;
140 fadt->duty_width = 3;
142 fadt->iapc_boot_arch = ACPI_FADT_LEGACY_DEVICES | ACPI_FADT_8042;
144 fadt->x_pm_tmr_blk.space_id = 1;
145 fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8;
146 fadt->x_pm_tmr_blk.addrl = IOMAP_ACPI_BASE + PM1_TMR;
149 void acpi_create_fadt(struct acpi_fadt *fadt, struct acpi_facs *facs,
152 struct acpi_table_header *header = &fadt->header;
154 acpi_fadt_common(fadt, facs, dsdt);
155 intel_acpi_fill_fadt(fadt);
157 header->checksum = table_compute_checksum(fadt, header->length);
160 int apl_acpi_fill_dmar(struct acpi_ctx *ctx)
162 struct udevice *dev, *sa_dev;
163 u64 gfxvtbar = readq(MCHBAR_REG(GFXVTBAR)) & VTBAR_MASK;
164 u64 defvtbar = readq(MCHBAR_REG(DEFVTBAR)) & VTBAR_MASK;
165 bool gfxvten = readl(MCHBAR_REG(GFXVTBAR)) & VTBAR_ENABLED;
166 bool defvten = readl(MCHBAR_REG(DEFVTBAR)) & VTBAR_ENABLED;
170 uclass_find_first_device(UCLASS_VIDEO, &dev);
171 ret = uclass_first_device_err(UCLASS_NORTHBRIDGE, &sa_dev);
173 return log_msg_ret("no sa", ret);
175 /* IGD has to be enabled, GFXVTBAR set and enabled */
176 if (dev && device_active(dev) && gfxvtbar && gfxvten) {
179 acpi_create_dmar_drhd(ctx, 0, 0, gfxvtbar);
180 ret = acpi_create_dmar_ds_pci(ctx, PCI_BDF(0, 2, 0));
182 return log_msg_ret("ds_pci", ret);
183 acpi_dmar_drhd_fixup(ctx, tmp);
187 acpi_create_dmar_rmrr(ctx->current, 0, sa_get_gsm_base(sa_dev),
188 sa_get_tolud_base(sa_dev) - 1);
189 acpi_create_dmar_ds_pci(ctx->current, PCI_BDF(0, 2, 0));
190 acpi_dmar_rmrr_fixup(ctx, tmp);
193 /* DEFVTBAR has to be set and enabled */
194 if (defvtbar && defvten) {
195 struct udevice *p2sb_dev;
202 * P2SB may already be hidden. There's no clear rule, when.
203 * It is needed to get bus, device and function for IOAPIC and
204 * HPET device which is stored in P2SB device. So unhide it to
205 * get the info and hide it again when done.
207 * TODO(sjg@chromium.org): p2sb_unhide() ?
209 ret = uclass_first_device_err(UCLASS_P2SB, &p2sb_dev);
211 return log_msg_ret("p2sb", ret);
213 dm_pci_read_config16(p2sb_dev, PCH_P2SB_IBDF, &ibdf);
214 ioapic = PCI_TO_BDF(ibdf);
215 dm_pci_read_config16(p2sb_dev, PCH_P2SB_HBDF, &hbdf);
216 hpet = PCI_TO_BDF(hbdf);
217 /* TODO(sjg@chromium.org): p2sb_hide() ? */
219 acpi_create_dmar_drhd(ctx, DRHD_INCLUDE_PCI_ALL, 0, defvtbar);
220 acpi_create_dmar_ds_ioapic(ctx, 2, ioapic);
221 acpi_create_dmar_ds_msi_hpet(ctx, 0, hpet);
222 acpi_dmar_drhd_fixup(tmp, ctx->current);