blob: 76230aea837d9051179ad730ad4a2103cc88c3bf [file] [log] [blame]
Simon Glassb16dbec2020-09-22 12:45:19 -06001// SPDX-License-Identifier: GPL-2.0+
2/*
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
7 *
8 * Modified from coreboot apollolake/acpi.c
9 */
10
11#define LOG_CATEGORY LOGC_ACPI
12
Simon Glassb16dbec2020-09-22 12:45:19 -060013#include <cpu.h>
14#include <dm.h>
15#include <log.h>
16#include <p2sb.h>
17#include <pci.h>
18#include <acpi/acpigen.h>
19#include <acpi/acpi_s3.h>
20#include <asm/acpi_table.h>
21#include <asm/cpu_common.h>
22#include <asm/intel_acpi.h>
23#include <asm/intel_gnvs.h>
24#include <asm/intel_pinctrl.h>
25#include <asm/intel_pinctrl_defs.h>
26#include <asm/intel_regs.h>
27#include <asm/io.h>
28#include <asm/mpspec.h>
29#include <asm/tables.h>
30#include <asm/arch/iomap.h>
31#include <asm/arch/gpio.h>
32#include <asm/arch/pm.h>
33#include <asm/arch/systemagent.h>
34#include <dm/acpi.h>
35#include <dm/uclass-internal.h>
36#include <power/acpi_pmc.h>
37
38int arch_read_sci_irq_select(void)
39{
40 struct acpi_pmc_upriv *upriv;
41 struct udevice *dev;
42 int ret;
43
44 ret = uclass_first_device_err(UCLASS_ACPI_PMC, &dev);
45 if (ret)
46 return log_msg_ret("pmc", ret);
47 upriv = dev_get_uclass_priv(dev);
48
49 return readl(upriv->pmc_bar0 + IRQ_REG);
50}
51
52int arch_write_sci_irq_select(uint scis)
53{
54 struct acpi_pmc_upriv *upriv;
55 struct udevice *dev;
56 int ret;
57
58 ret = uclass_first_device_err(UCLASS_ACPI_PMC, &dev);
59 if (ret)
60 return log_msg_ret("pmc", ret);
61 upriv = dev_get_uclass_priv(dev);
62 writel(scis, upriv->pmc_bar0 + IRQ_REG);
63
64 return 0;
65}
66
Simon Glass012310b2020-11-04 09:57:36 -070067/**
68 * chromeos_init_acpi() - Initialise basic data to boot Chrome OS
69 *
70 * This tells Chrome OS to boot in developer mode
71 *
72 * @cros: Structure to initialise
73 */
74static void chromeos_init_acpi(struct chromeos_acpi_gnvs *cros)
75{
76 cros->active_main_fw = 1;
77 cros->active_main_fw = 1; /* A */
78 cros->switches = CHSW_DEVELOPER_SWITCH;
79 cros->main_fw_type = 2; /* Developer */
80}
81
Simon Glassb16dbec2020-09-22 12:45:19 -060082int acpi_create_gnvs(struct acpi_global_nvs *gnvs)
83{
84 struct udevice *cpu;
85 int ret;
86
87 /* Clear out GNV */
88 memset(gnvs, '\0', sizeof(*gnvs));
89
90 /* TODO(sjg@chromium.org): Add the console log to gnvs->cbmc */
91
Simon Glass012310b2020-11-04 09:57:36 -070092 if (IS_ENABLED(CONFIG_CHROMEOS))
93 chromeos_init_acpi(&gnvs->chromeos);
94
Simon Glassb16dbec2020-09-22 12:45:19 -060095 /* Set unknown wake source */
96 gnvs->pm1i = ~0ULL;
97
98 /* CPU core count */
99 gnvs->pcnt = 1;
100 ret = uclass_find_first_device(UCLASS_CPU, &cpu);
101 if (cpu) {
102 ret = cpu_get_count(cpu);
103 if (ret > 0)
104 gnvs->pcnt = ret;
105 }
106
Simon Glass012310b2020-11-04 09:57:36 -0700107 gnvs->dpte = 1;
108
Simon Glassb16dbec2020-09-22 12:45:19 -0600109 return 0;
110}
111
112uint32_t acpi_fill_soc_wake(uint32_t generic_pm1_en)
113{
114 /*
115 * WAK_STS bit is set when the system is in one of the sleep states
116 * (via the SLP_EN bit) and an enabled wake event occurs. Upon setting
117 * this bit, the PMC will transition the system to the ON state and
118 * can only be set by hardware and can only be cleared by writing a one
119 * to this bit position.
120 */
121 generic_pm1_en |= WAK_STS | RTC_EN | PWRBTN_EN;
122
123 return generic_pm1_en;
124}
125
126int arch_madt_sci_irq_polarity(int sci)
127{
128 return MP_IRQ_POLARITY_LOW;
129}
130
131void fill_fadt(struct acpi_fadt *fadt)
132{
133 fadt->pm_tmr_blk = IOMAP_ACPI_BASE + PM1_TMR;
134
135 fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED;
136 fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED;
137
138 fadt->pm_tmr_len = 4;
139 fadt->duty_width = 3;
140
141 fadt->iapc_boot_arch = ACPI_FADT_LEGACY_DEVICES | ACPI_FADT_8042;
142
143 fadt->x_pm_tmr_blk.space_id = 1;
144 fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8;
145 fadt->x_pm_tmr_blk.addrl = IOMAP_ACPI_BASE + PM1_TMR;
146}
147
Simon Glass9bd6b622023-09-01 11:27:09 -0600148static int apl_write_fadt(struct acpi_ctx *ctx, const struct acpi_writer *entry)
Simon Glassb16dbec2020-09-22 12:45:19 -0600149{
Simon Glass9bd6b622023-09-01 11:27:09 -0600150 struct acpi_table_header *header;
151 struct acpi_fadt *fadt;
Simon Glassb16dbec2020-09-22 12:45:19 -0600152
Simon Glass9bd6b622023-09-01 11:27:09 -0600153 fadt = ctx->current;
154 acpi_fadt_common(fadt, ctx->facs, ctx->dsdt);
Simon Glassb16dbec2020-09-22 12:45:19 -0600155 intel_acpi_fill_fadt(fadt);
156 fill_fadt(fadt);
Simon Glass9bd6b622023-09-01 11:27:09 -0600157 header = &fadt->header;
Simon Glassb16dbec2020-09-22 12:45:19 -0600158 header->checksum = table_compute_checksum(fadt, header->length);
Simon Glass9bd6b622023-09-01 11:27:09 -0600159
Andy Shevchenko6f15ab72023-09-01 11:27:10 -0600160 return acpi_add_fadt(ctx, fadt);
Simon Glassb16dbec2020-09-22 12:45:19 -0600161}
Simon Glass9bd6b622023-09-01 11:27:09 -0600162ACPI_WRITER(5fadt, "FADT", apl_write_fadt, 0);
Simon Glassb16dbec2020-09-22 12:45:19 -0600163
164int apl_acpi_fill_dmar(struct acpi_ctx *ctx)
165{
166 struct udevice *dev, *sa_dev;
167 u64 gfxvtbar = readq(MCHBAR_REG(GFXVTBAR)) & VTBAR_MASK;
168 u64 defvtbar = readq(MCHBAR_REG(DEFVTBAR)) & VTBAR_MASK;
169 bool gfxvten = readl(MCHBAR_REG(GFXVTBAR)) & VTBAR_ENABLED;
170 bool defvten = readl(MCHBAR_REG(DEFVTBAR)) & VTBAR_ENABLED;
171 void *tmp;
172 int ret;
173
174 uclass_find_first_device(UCLASS_VIDEO, &dev);
175 ret = uclass_first_device_err(UCLASS_NORTHBRIDGE, &sa_dev);
176 if (ret)
177 return log_msg_ret("no sa", ret);
178
179 /* IGD has to be enabled, GFXVTBAR set and enabled */
180 if (dev && device_active(dev) && gfxvtbar && gfxvten) {
181 tmp = ctx->current;
182
183 acpi_create_dmar_drhd(ctx, 0, 0, gfxvtbar);
184 ret = acpi_create_dmar_ds_pci(ctx, PCI_BDF(0, 2, 0));
185 if (ret)
186 return log_msg_ret("ds_pci", ret);
187 acpi_dmar_drhd_fixup(ctx, tmp);
188
189 /* Add RMRR entry */
190 tmp = ctx->current;
191 acpi_create_dmar_rmrr(ctx->current, 0, sa_get_gsm_base(sa_dev),
192 sa_get_tolud_base(sa_dev) - 1);
193 acpi_create_dmar_ds_pci(ctx->current, PCI_BDF(0, 2, 0));
194 acpi_dmar_rmrr_fixup(ctx, tmp);
195 }
196
197 /* DEFVTBAR has to be set and enabled */
198 if (defvtbar && defvten) {
199 struct udevice *p2sb_dev;
200 u16 ibdf, hbdf;
201 uint ioapic, hpet;
202 int ret;
203
204 tmp = ctx->current;
205 /*
206 * P2SB may already be hidden. There's no clear rule, when.
207 * It is needed to get bus, device and function for IOAPIC and
208 * HPET device which is stored in P2SB device. So unhide it to
209 * get the info and hide it again when done.
210 *
211 * TODO(sjg@chromium.org): p2sb_unhide() ?
212 */
213 ret = uclass_first_device_err(UCLASS_P2SB, &p2sb_dev);
214 if (ret)
215 return log_msg_ret("p2sb", ret);
216
217 dm_pci_read_config16(p2sb_dev, PCH_P2SB_IBDF, &ibdf);
218 ioapic = PCI_TO_BDF(ibdf);
219 dm_pci_read_config16(p2sb_dev, PCH_P2SB_HBDF, &hbdf);
220 hpet = PCI_TO_BDF(hbdf);
221 /* TODO(sjg@chromium.org): p2sb_hide() ? */
222
223 acpi_create_dmar_drhd(ctx, DRHD_INCLUDE_PCI_ALL, 0, defvtbar);
224 acpi_create_dmar_ds_ioapic(ctx, 2, ioapic);
225 acpi_create_dmar_ds_msi_hpet(ctx, 0, hpet);
226 acpi_dmar_drhd_fixup(tmp, ctx->current);
227 }
228
229 return 0;
230}