blob: 5af8a181b1e02211a0fc62cc840bdee4cc9cdf3f [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
13#include <common.h>
14#include <cpu.h>
15#include <dm.h>
16#include <log.h>
17#include <p2sb.h>
18#include <pci.h>
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>
28#include <asm/io.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>
35#include <dm/acpi.h>
36#include <dm/uclass-internal.h>
37#include <power/acpi_pmc.h>
38
39int arch_read_sci_irq_select(void)
40{
41 struct acpi_pmc_upriv *upriv;
42 struct udevice *dev;
43 int ret;
44
45 ret = uclass_first_device_err(UCLASS_ACPI_PMC, &dev);
46 if (ret)
47 return log_msg_ret("pmc", ret);
48 upriv = dev_get_uclass_priv(dev);
49
50 return readl(upriv->pmc_bar0 + IRQ_REG);
51}
52
53int arch_write_sci_irq_select(uint scis)
54{
55 struct acpi_pmc_upriv *upriv;
56 struct udevice *dev;
57 int ret;
58
59 ret = uclass_first_device_err(UCLASS_ACPI_PMC, &dev);
60 if (ret)
61 return log_msg_ret("pmc", ret);
62 upriv = dev_get_uclass_priv(dev);
63 writel(scis, upriv->pmc_bar0 + IRQ_REG);
64
65 return 0;
66}
67
68int acpi_create_gnvs(struct acpi_global_nvs *gnvs)
69{
70 struct udevice *cpu;
71 int ret;
72
73 /* Clear out GNV */
74 memset(gnvs, '\0', sizeof(*gnvs));
75
76 /* TODO(sjg@chromium.org): Add the console log to gnvs->cbmc */
77
Simon Glassd81f07f2020-11-04 09:57:35 -070078/* Disable this code until a later patch */
79#if 0
Simon Glassb16dbec2020-09-22 12:45:19 -060080 /* Initialise Verified Boot data */
81 chromeos_init_acpi(&gnvs->chromeos);
82 gnvs->chromeos.vbt2 = ACTIVE_ECFW_RO;
83#endif
84 /* Set unknown wake source */
85 gnvs->pm1i = ~0ULL;
86
87 /* CPU core count */
88 gnvs->pcnt = 1;
89 ret = uclass_find_first_device(UCLASS_CPU, &cpu);
90 if (cpu) {
91 ret = cpu_get_count(cpu);
92 if (ret > 0)
93 gnvs->pcnt = ret;
94 }
95
96 return 0;
97}
98
99uint32_t acpi_fill_soc_wake(uint32_t generic_pm1_en)
100{
101 /*
102 * WAK_STS bit is set when the system is in one of the sleep states
103 * (via the SLP_EN bit) and an enabled wake event occurs. Upon setting
104 * this bit, the PMC will transition the system to the ON state and
105 * can only be set by hardware and can only be cleared by writing a one
106 * to this bit position.
107 */
108 generic_pm1_en |= WAK_STS | RTC_EN | PWRBTN_EN;
109
110 return generic_pm1_en;
111}
112
113int arch_madt_sci_irq_polarity(int sci)
114{
115 return MP_IRQ_POLARITY_LOW;
116}
117
118void fill_fadt(struct acpi_fadt *fadt)
119{
120 fadt->pm_tmr_blk = IOMAP_ACPI_BASE + PM1_TMR;
121
122 fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED;
123 fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED;
124
125 fadt->pm_tmr_len = 4;
126 fadt->duty_width = 3;
127
128 fadt->iapc_boot_arch = ACPI_FADT_LEGACY_DEVICES | ACPI_FADT_8042;
129
130 fadt->x_pm_tmr_blk.space_id = 1;
131 fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8;
132 fadt->x_pm_tmr_blk.addrl = IOMAP_ACPI_BASE + PM1_TMR;
133}
134
135void acpi_create_fadt(struct acpi_fadt *fadt, struct acpi_facs *facs,
136 void *dsdt)
137{
138 struct acpi_table_header *header = &fadt->header;
139
140 acpi_fadt_common(fadt, facs, dsdt);
141 intel_acpi_fill_fadt(fadt);
142 fill_fadt(fadt);
143 header->checksum = table_compute_checksum(fadt, header->length);
144}
145
146int apl_acpi_fill_dmar(struct acpi_ctx *ctx)
147{
148 struct udevice *dev, *sa_dev;
149 u64 gfxvtbar = readq(MCHBAR_REG(GFXVTBAR)) & VTBAR_MASK;
150 u64 defvtbar = readq(MCHBAR_REG(DEFVTBAR)) & VTBAR_MASK;
151 bool gfxvten = readl(MCHBAR_REG(GFXVTBAR)) & VTBAR_ENABLED;
152 bool defvten = readl(MCHBAR_REG(DEFVTBAR)) & VTBAR_ENABLED;
153 void *tmp;
154 int ret;
155
156 uclass_find_first_device(UCLASS_VIDEO, &dev);
157 ret = uclass_first_device_err(UCLASS_NORTHBRIDGE, &sa_dev);
158 if (ret)
159 return log_msg_ret("no sa", ret);
160
161 /* IGD has to be enabled, GFXVTBAR set and enabled */
162 if (dev && device_active(dev) && gfxvtbar && gfxvten) {
163 tmp = ctx->current;
164
165 acpi_create_dmar_drhd(ctx, 0, 0, gfxvtbar);
166 ret = acpi_create_dmar_ds_pci(ctx, PCI_BDF(0, 2, 0));
167 if (ret)
168 return log_msg_ret("ds_pci", ret);
169 acpi_dmar_drhd_fixup(ctx, tmp);
170
171 /* Add RMRR entry */
172 tmp = ctx->current;
173 acpi_create_dmar_rmrr(ctx->current, 0, sa_get_gsm_base(sa_dev),
174 sa_get_tolud_base(sa_dev) - 1);
175 acpi_create_dmar_ds_pci(ctx->current, PCI_BDF(0, 2, 0));
176 acpi_dmar_rmrr_fixup(ctx, tmp);
177 }
178
179 /* DEFVTBAR has to be set and enabled */
180 if (defvtbar && defvten) {
181 struct udevice *p2sb_dev;
182 u16 ibdf, hbdf;
183 uint ioapic, hpet;
184 int ret;
185
186 tmp = ctx->current;
187 /*
188 * P2SB may already be hidden. There's no clear rule, when.
189 * It is needed to get bus, device and function for IOAPIC and
190 * HPET device which is stored in P2SB device. So unhide it to
191 * get the info and hide it again when done.
192 *
193 * TODO(sjg@chromium.org): p2sb_unhide() ?
194 */
195 ret = uclass_first_device_err(UCLASS_P2SB, &p2sb_dev);
196 if (ret)
197 return log_msg_ret("p2sb", ret);
198
199 dm_pci_read_config16(p2sb_dev, PCH_P2SB_IBDF, &ibdf);
200 ioapic = PCI_TO_BDF(ibdf);
201 dm_pci_read_config16(p2sb_dev, PCH_P2SB_HBDF, &hbdf);
202 hpet = PCI_TO_BDF(hbdf);
203 /* TODO(sjg@chromium.org): p2sb_hide() ? */
204
205 acpi_create_dmar_drhd(ctx, DRHD_INCLUDE_PCI_ALL, 0, defvtbar);
206 acpi_create_dmar_ds_ioapic(ctx, 2, ioapic);
207 acpi_create_dmar_ds_msi_hpet(ctx, 0, hpet);
208 acpi_dmar_drhd_fixup(tmp, ctx->current);
209 }
210
211 return 0;
212}