public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [PATCH v3 34/57] x86: apl: Generate required ACPI tables
Date: Sun,  6 Sep 2020 15:43:42 -0600	[thread overview]
Message-ID: <20200906214405.71632-14-sjg@chromium.org> (raw)
In-Reply-To: <20200906214405.71632-1-sjg@chromium.org>

Add support for generating various ACPI tables for Apollo Lake. Add a few
S3 definitions that are needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v1)

Changes in v1:
- Drop unnecessary callbacks

 arch/x86/cpu/apollolake/Makefile            |   1 +
 arch/x86/cpu/apollolake/acpi.c              | 211 ++++++++++++++++++++
 arch/x86/include/asm/arch-apollolake/acpi.h |  18 ++
 include/acpi/acpi_s3.h                      |   4 +
 4 files changed, 234 insertions(+)
 create mode 100644 arch/x86/cpu/apollolake/acpi.c
 create mode 100644 arch/x86/include/asm/arch-apollolake/acpi.h

diff --git a/arch/x86/cpu/apollolake/Makefile b/arch/x86/cpu/apollolake/Makefile
index 3aa2a556765..2ddf4af62c5 100644
--- a/arch/x86/cpu/apollolake/Makefile
+++ b/arch/x86/cpu/apollolake/Makefile
@@ -16,6 +16,7 @@ obj-y += fsp_m.o
 endif
 endif
 ifndef CONFIG_SPL_BUILD
+obj-y += acpi.o
 obj-y += fsp_s.o
 endif
 
diff --git a/arch/x86/cpu/apollolake/acpi.c b/arch/x86/cpu/apollolake/acpi.c
new file mode 100644
index 00000000000..69b544f0d98
--- /dev/null
+++ b/arch/x86/cpu/apollolake/acpi.c
@@ -0,0 +1,211 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2016 Intel Corp.
+ * Copyright (C) 2017-2019 Siemens AG
+ * (Written by Lance Zhao <lijian.zhao@intel.com> for Intel Corp.)
+ * Copyright 2019 Google LLC
+ *
+ * Modified from coreboot apollolake/acpi.c
+ */
+
+#define LOG_CATEGORY LOGC_ACPI
+
+#include <common.h>
+#include <cpu.h>
+#include <dm.h>
+#include <log.h>
+#include <p2sb.h>
+#include <pci.h>
+#include <acpi/acpigen.h>
+#include <acpi/acpi_s3.h>
+#include <asm/acpi_table.h>
+#include <asm/cpu_common.h>
+#include <asm/intel_acpi.h>
+#include <asm/intel_gnvs.h>
+#include <asm/intel_pinctrl.h>
+#include <asm/intel_pinctrl_defs.h>
+#include <asm/intel_regs.h>
+#include <asm/io.h>
+#include <asm/mpspec.h>
+#include <asm/tables.h>
+#include <asm/arch/iomap.h>
+#include <asm/arch/gpio.h>
+#include <asm/arch/pm.h>
+#include <asm/arch/systemagent.h>
+#include <dm/acpi.h>
+#include <dm/uclass-internal.h>
+#include <power/acpi_pmc.h>
+
+int arch_read_sci_irq_select(void)
+{
+	struct acpi_pmc_upriv *upriv;
+	struct udevice *dev;
+	int ret;
+
+	ret = uclass_first_device_err(UCLASS_ACPI_PMC, &dev);
+	if (ret)
+		return log_msg_ret("pmc", ret);
+	upriv = dev_get_uclass_priv(dev);
+
+	return readl(upriv->pmc_bar0 + IRQ_REG);
+}
+
+int arch_write_sci_irq_select(uint scis)
+{
+	struct acpi_pmc_upriv *upriv;
+	struct udevice *dev;
+	int ret;
+
+	ret = uclass_first_device_err(UCLASS_ACPI_PMC, &dev);
+	if (ret)
+		return log_msg_ret("pmc", ret);
+	upriv = dev_get_uclass_priv(dev);
+	writel(scis, upriv->pmc_bar0 + IRQ_REG);
+
+	return 0;
+}
+
+int acpi_create_gnvs(struct acpi_global_nvs *gnvs)
+{
+	struct udevice *cpu;
+	int ret;
+
+	/* Clear out GNV */
+	memset(gnvs, '\0', sizeof(*gnvs));
+
+	/* TODO(sjg at chromium.org): Add the console log to gnvs->cbmc */
+
+#ifdef CONFIG_CHROMEOS
+	/* Initialise Verified Boot data */
+	chromeos_init_acpi(&gnvs->chromeos);
+	gnvs->chromeos.vbt2 = ACTIVE_ECFW_RO;
+#endif
+	/* Set unknown wake source */
+	gnvs->pm1i = ~0ULL;
+
+	/* CPU core count */
+	gnvs->pcnt = 1;
+	ret = uclass_find_first_device(UCLASS_CPU, &cpu);
+	if (cpu) {
+		ret = cpu_get_count(cpu);
+		if (ret > 0)
+			gnvs->pcnt = ret;
+	}
+
+	return 0;
+}
+
+uint32_t acpi_fill_soc_wake(uint32_t generic_pm1_en)
+{
+	/*
+	 * WAK_STS bit is set when the system is in one of the sleep states
+	 * (via the SLP_EN bit) and an enabled wake event occurs. Upon setting
+	 * this bit, the PMC will transition the system to the ON state and
+	 * can only be set by hardware and can only be cleared by writing a one
+	 * to this bit position.
+	 */
+	generic_pm1_en |= WAK_STS | RTC_EN | PWRBTN_EN;
+
+	return generic_pm1_en;
+}
+
+int arch_madt_sci_irq_polarity(int sci)
+{
+	return MP_IRQ_POLARITY_LOW;
+}
+
+void fill_fadt(struct acpi_fadt *fadt)
+{
+	fadt->pm_tmr_blk = IOMAP_ACPI_BASE + PM1_TMR;
+
+	fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED;
+	fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED;
+
+	fadt->pm_tmr_len = 4;
+	fadt->duty_width = 3;
+
+	fadt->iapc_boot_arch = ACPI_FADT_LEGACY_DEVICES | ACPI_FADT_8042;
+
+	fadt->x_pm_tmr_blk.space_id = 1;
+	fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8;
+	fadt->x_pm_tmr_blk.addrl = IOMAP_ACPI_BASE + PM1_TMR;
+}
+
+void acpi_create_fadt(struct acpi_fadt *fadt, struct acpi_facs *facs,
+		      void *dsdt)
+{
+	struct acpi_table_header *header = &fadt->header;
+
+	acpi_fadt_common(fadt, facs, dsdt);
+	intel_acpi_fill_fadt(fadt);
+	fill_fadt(fadt);
+	header->checksum = table_compute_checksum(fadt, header->length);
+}
+
+int apl_acpi_fill_dmar(struct acpi_ctx *ctx)
+{
+	struct udevice *dev, *sa_dev;
+	u64 gfxvtbar = readq(MCHBAR_REG(GFXVTBAR)) & VTBAR_MASK;
+	u64 defvtbar = readq(MCHBAR_REG(DEFVTBAR)) & VTBAR_MASK;
+	bool gfxvten = readl(MCHBAR_REG(GFXVTBAR)) & VTBAR_ENABLED;
+	bool defvten = readl(MCHBAR_REG(DEFVTBAR)) & VTBAR_ENABLED;
+	void *tmp;
+	int ret;
+
+	uclass_find_first_device(UCLASS_VIDEO, &dev);
+	ret = uclass_first_device_err(UCLASS_NORTHBRIDGE, &sa_dev);
+	if (ret)
+		return log_msg_ret("no sa", ret);
+
+	/* IGD has to be enabled, GFXVTBAR set and enabled */
+	if (dev && device_active(dev) && gfxvtbar && gfxvten) {
+		tmp = ctx->current;
+
+		acpi_create_dmar_drhd(ctx, 0, 0, gfxvtbar);
+		ret = acpi_create_dmar_ds_pci(ctx, PCI_BDF(0, 2, 0));
+		if (ret)
+			return log_msg_ret("ds_pci", ret);
+		acpi_dmar_drhd_fixup(ctx, tmp);
+
+		/* Add RMRR entry */
+		tmp = ctx->current;
+		acpi_create_dmar_rmrr(ctx->current, 0, sa_get_gsm_base(sa_dev),
+				      sa_get_tolud_base(sa_dev) - 1);
+		acpi_create_dmar_ds_pci(ctx->current, PCI_BDF(0, 2, 0));
+		acpi_dmar_rmrr_fixup(ctx, tmp);
+	}
+
+	/* DEFVTBAR has to be set and enabled */
+	if (defvtbar && defvten) {
+		struct udevice *p2sb_dev;
+		u16 ibdf, hbdf;
+		uint ioapic, hpet;
+		int ret;
+
+		tmp = ctx->current;
+		/*
+		 * P2SB may already be hidden. There's no clear rule, when.
+		 * It is needed to get bus, device and function for IOAPIC and
+		 * HPET device which is stored in P2SB device. So unhide it to
+		 * get the info and hide it again when done.
+		 *
+		 * TODO(sjg at chromium.org): p2sb_unhide() ?
+		 */
+		ret = uclass_first_device_err(UCLASS_P2SB, &p2sb_dev);
+		if (ret)
+			return log_msg_ret("p2sb", ret);
+
+		dm_pci_read_config16(p2sb_dev, PCH_P2SB_IBDF, &ibdf);
+		ioapic = PCI_TO_BDF(ibdf);
+		dm_pci_read_config16(p2sb_dev, PCH_P2SB_HBDF, &hbdf);
+		hpet = PCI_TO_BDF(hbdf);
+		/* TODO(sjg at chromium.org): p2sb_hide() ? */
+
+		acpi_create_dmar_drhd(ctx, DRHD_INCLUDE_PCI_ALL, 0, defvtbar);
+		acpi_create_dmar_ds_ioapic(ctx, 2, ioapic);
+		acpi_create_dmar_ds_msi_hpet(ctx, 0, hpet);
+		acpi_dmar_drhd_fixup(tmp, ctx->current);
+	}
+
+	return 0;
+}
diff --git a/arch/x86/include/asm/arch-apollolake/acpi.h b/arch/x86/include/asm/arch-apollolake/acpi.h
new file mode 100644
index 00000000000..ed852feee03
--- /dev/null
+++ b/arch/x86/include/asm/arch-apollolake/acpi.h
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright 2019 Google LLC
+ */
+
+#ifndef _ASM_ARCH_ACPI_H
+#define _ASM_ARCH_ACPI_H
+
+struct acpi_ctx;
+
+/**
+ * apl_acpi_fill_dmar() - Set up the DMAR for APL
+ *
+ * @ctx: ACPI context pointer
+ */
+int apl_acpi_fill_dmar(struct acpi_ctx *ctx);
+
+#endif /* _ASM_ARCH_CPU_H */
diff --git a/include/acpi/acpi_s3.h b/include/acpi/acpi_s3.h
index baa848dcd15..847139baa0c 100644
--- a/include/acpi/acpi_s3.h
+++ b/include/acpi/acpi_s3.h
@@ -28,6 +28,10 @@
 #define SLP_TYP_S4	6
 #define SLP_TYP_S5	7
 
+/* PM1_STS register */
+#define RTC_EN		BIT(10)
+#define PWRBTN_EN	BIT(8)
+
 /* Memory size reserved for S3 resume */
 #define S3_RESERVE_SIZE	0x1000
 
-- 
2.28.0.526.ge36021eeef-goog

  parent reply	other threads:[~2020-09-06 21:43 UTC|newest]

Thread overview: 80+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-06 21:43 [PATCH v3 00/57] dm: Add programatic generation of ACPI tables (part D) Simon Glass
2020-09-06 21:43 ` [PATCH v3 01/57] x86: acpi: Add cros_ec tables Simon Glass
2020-09-06 21:43 ` [PATCH v3 02/57] x86: acpi: Add base asl files for common x86 devices Simon Glass
2020-09-21 13:50   ` Wolfgang Wallner
2020-09-22 13:51     ` Simon Glass
2020-09-22 14:19       ` Wolfgang Wallner
2020-09-22 14:30         ` Bin Meng
2020-09-22 14:47           ` Wolfgang Wallner
2020-09-22 14:52             ` Bin Meng
2020-09-06 21:43 ` [PATCH v3 03/57] x86: acpi: apl: Add asl files for Apollo Lake Simon Glass
2020-09-06 21:43 ` [PATCH v3 04/57] x86: acpi: Add DPTF asl files Simon Glass
2020-09-06 21:43 ` [PATCH v3 05/57] x86: apl: Correct PCIE_ECAM_BASE Simon Glass
2020-09-22  7:30   ` Bin Meng
2020-09-06 21:43 ` [PATCH v3 06/57] x86: Add a config for the systemagent PCIEX regions size Simon Glass
2020-09-06 21:43 ` [PATCH v3 07/57] x86: Add a common global NVS structure Simon Glass
2020-09-06 21:43 ` [PATCH v3 08/57] x86: acpi: Support external GNVS tables Simon Glass
2020-09-06 21:43 ` [PATCH v3 09/57] x86: acpi: Expand the GNVS Simon Glass
2020-09-06 21:43 ` [PATCH v3 10/57] x86: coral: Add ACPI tables for coral Simon Glass
2020-09-06 21:43 ` [PATCH v3 11/57] acpi: Add support for writing a _PRW Simon Glass
2020-09-06 21:43 ` [PATCH v3 12/57] acpi: Add support for conditions and return values Simon Glass
2020-09-06 21:43 ` [PATCH v3 13/57] acpi: Support generating a multi-function _DSM for devices Simon Glass
2020-09-06 21:43 ` [PATCH v3 14/57] dm: acpi: Use correct GPIO polarity type in acpi_dp_add_gpio() Simon Glass
2020-09-06 21:43 ` [PATCH v3 15/57] x86: link: Allow more space for U-Boot Simon Glass
2020-09-22  7:44   ` Bin Meng
2020-09-06 21:43 ` [PATCH v3 16/57] i2c: Add a generic driver to generate ACPI info Simon Glass
2020-09-06 21:43 ` [PATCH v3 17/57] x86: Add wake sources for the acpi_gpe driver Simon Glass
2020-09-06 21:43 ` [PATCH v3 18/57] x86: apl: Support writing the IntelGraphicsMem table Simon Glass
2020-09-06 21:43 ` [PATCH v3 19/57] x86: acpi: Add a common routine to write WiFi info Simon Glass
2020-09-06 21:43 ` [PATCH v3 20/57] x86: Add some definitions for SMM Simon Glass
2020-09-06 21:43 ` [PATCH v3 21/57] x86: apl: Add power-management definitions Simon Glass
2020-09-06 21:43 ` [PATCH v3 22/57] x86: apl: Update iomap for ACPI Simon Glass
2020-09-06 21:43 ` [PATCH v3 23/57] x86: Add a few common Intel CPU functions Simon Glass
2020-09-06 21:43 ` [PATCH v3 24/57] x86: acpi: Support generation of the HPET table Simon Glass
2020-09-06 21:43 ` [PATCH v3 25/57] x86: acpi: Support generation of the DBG2 table Simon Glass
2020-09-06 21:43 ` [PATCH v3 26/57] acpi: Add support for generating processor tables Simon Glass
2020-09-06 21:43 ` [PATCH v3 27/57] x86: acpi: Add PCT and PTC tables Simon Glass
2020-09-06 21:43 ` [PATCH v3 28/57] acpi: Add more support for generating processor tables Simon Glass
2020-09-06 21:43 ` [PATCH v3 29/57] x86: acpi: Add common Intel ACPI tables Simon Glass
2020-09-06 21:43 ` [PATCH v3 30/57] x86: Support Atom SoCs using SWSMISCI rather than the SWSCI Simon Glass
2020-09-06 21:43 ` [PATCH v3 31/57] x86: acpi: Add support for additional Intel tables Simon Glass
2020-09-06 21:43 ` [PATCH v3 32/57] x86: apl: Allow reading hostbridge base addresses Simon Glass
2020-09-06 21:43 ` [PATCH v3 33/57] p2sb: Add some definitions used for ACPI Simon Glass
2020-09-06 21:43 ` Simon Glass [this message]
2020-09-06 21:43 ` [PATCH v3 35/57] x86: apl: Add support for hostbridge ACPI generation Simon Glass
2020-09-06 21:43 ` [PATCH v3 36/57] x86: apl: Generate CPU tables Simon Glass
2020-09-06 21:43 ` [PATCH v3 37/57] x86: apl: Generate ACPI table for LPC Simon Glass
2020-09-06 21:43 ` [PATCH v3 38/57] x86: apl: Drop unnecessary code in PMC driver Simon Glass
2020-09-06 21:43 ` [PATCH v3 39/57] tpm: cr50: Add ACPI support Simon Glass
2020-09-21 11:50   ` Andy Shevchenko
2020-09-21 11:53     ` Andy Shevchenko
2020-09-22  8:15     ` Bin Meng
2020-09-22  8:27     ` Andy Shevchenko
2020-09-06 21:43 ` [PATCH v3 40/57] x86: fsp: Update the FSP API with the end-firmware method Simon Glass
2020-09-22  7:58   ` Bin Meng
2020-09-06 21:43 ` [PATCH v3 41/57] x86: cpu: Report address width from cpu_get_info() Simon Glass
2020-09-06 21:43 ` [PATCH v3 42/57] x86: Sort the MTRR table Simon Glass
2020-09-06 21:43 ` [PATCH v3 43/57] x86: Notify the FSP of the 'end firmware' event Simon Glass
2020-09-06 21:43 ` [PATCH v3 44/57] x86: Correct the assembly guard in e820.h Simon Glass
2020-09-22  8:02   ` Bin Meng
2020-09-06 21:43 ` [PATCH v3 45/57] x86: Add a header guard to asm/acpi_table.h Simon Glass
2020-09-22  8:03   ` Bin Meng
2020-09-06 21:43 ` [PATCH v3 46/57] x86: Correct handling of MADT table CPUs Simon Glass
2020-09-06 21:43 ` [PATCH v3 47/57] acpi: tpm: Add a TPM2 table Simon Glass
2020-09-06 21:43 ` [PATCH v3 48/57] acpi: tpm: Add a TPM1 table Simon Glass
2020-09-06 21:43 ` [PATCH v3 49/57] x86: acpi: Set the log category for x86 table generation Simon Glass
2020-09-22  8:04   ` Bin Meng
2020-09-06 21:43 ` [PATCH v3 50/57] x86: coral: Add audio descriptor files Simon Glass
2020-09-06 21:43 ` [PATCH v3 51/57] x86: apl: Check low-level init in FSP-S pre-init Simon Glass
2020-09-06 21:44 ` [PATCH v3 52/57] x86: fsp: Add more debugging for silicon init Simon Glass
2020-09-22  8:06   ` Bin Meng
2020-09-06 21:44 ` [PATCH v3 53/57] x86: fsp: Show FSP-S or FSP-M address in fsp_get_header() Simon Glass
2020-09-22  8:06   ` Bin Meng
2020-09-06 21:44 ` [PATCH v3 54/57] acpi: Use defines for field lengths Simon Glass
2020-09-22  8:07   ` Bin Meng
2020-09-06 21:44 ` [PATCH v3 55/57] x86: Add a way to add to the e820 memory table Simon Glass
2020-09-22  8:09   ` Bin Meng
2020-09-06 21:44 ` [PATCH v3 56/57] x86: Move include of bitops out of ACPI region Simon Glass
2020-09-22  8:09   ` Bin Meng
2020-09-06 21:44 ` [PATCH v3 57/57] x86: coral: Update config and device tree for ACPI Simon Glass
2020-09-22  8:16 ` [PATCH v3 00/57] dm: Add programatic generation of ACPI tables (part D) Bin Meng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200906214405.71632-14-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox