Skip to contentSkip to conversation

x86: acpi: Introduce ACPI global NVS support

PATCH New Bin Meng 2 participants 10 messages Jun 17, 2016 – Jun 18, 2016 x86

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

v2 cover x86: acpi: Introduce ACPI global NVS support

ACPI global NVS is an area in system memory with various platform defined variables that can be utilized between U-Boot and ACPI ASL codes. U-Boot set these variables at runtime, so that ASL codes can test these variables to provide some runtime flexiblity.

Tested on MinnowMax with CONFIG_INTERNAL_UART set to off, and install a Windows 10, check the internal UART is not exposed in the Windows device manager.

This series is available at u-boot-x86/gnvs-working.

Changes in v2:
- Add arch/x86/include/asm/acpi/global_nvs.h for 0xdeadbeef defines
- Replace with 0xdeadbeef with defines from header file
- Don't use hardcoded 0xdeadbeef, use defines instead
- Simplify the casting of gnvs by declaring it as "u32 *"

Bin Meng (4):
x86: baytrail: Introduce ACPI global NVS
x86: quark: Introduce ACPI global NVS
x86: acpi: Pack global NVS into ACPI table
x86: baytrail: acpi: Hide internal UART per GNVS setting

 arch/x86/cpu/baytrail/acpi.c                       | 26 ++++++++++++++++++++++
 arch/x86/cpu/quark/acpi.c                          |  7 ++++++
 arch/x86/include/asm/acpi/global_nvs.h             | 19 ++++++++++++++++
 arch/x86/include/asm/acpi_table.h                  |  4 ++++
 .../include/asm/arch-baytrail/acpi/global_nvs.asl  | 15 +++++++++++++
 arch/x86/include/asm/arch-baytrail/acpi/lpc.asl    | 19 +++++++---------
 .../include/asm/arch-baytrail/acpi/platform.asl    |  3 +++
 arch/x86/include/asm/arch-baytrail/global_nvs.h    | 21 +++++++++++++++++
 .../x86/include/asm/arch-quark/acpi/global_nvs.asl | 14 ++++++++++++
 arch/x86/include/asm/arch-quark/acpi/platform.asl  |  3 +++
 arch/x86/include/asm/arch-quark/global_nvs.h       | 20 +++++++++++++++++
 arch/x86/lib/acpi_table.c                          | 22 ++++++++++++++++++
 doc/README.x86                                     |  2 --
 13 files changed, 162 insertions(+), 13 deletions(-)
 create mode 100644 arch/x86/include/asm/acpi/global_nvs.h
 create mode 100644 arch/x86/include/asm/arch-baytrail/acpi/global_nvs.asl
 create mode 100644 arch/x86/include/asm/arch-baytrail/global_nvs.h
 create mode 100644 arch/x86/include/asm/arch-quark/acpi/global_nvs.asl
 create mode 100644 arch/x86/include/asm/arch-quark/global_nvs.h
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH v2 1/4 x86: baytrail: Introduce ACPI global NVS

This introduces baytrail-specific ACPI global NVS structure, defined in both C header file and ASL file.

---

Changes in v2:
- Add arch/x86/include/asm/acpi/global_nvs.h for 0xdeadbeef defines

 arch/x86/cpu/baytrail/acpi.c                       | 26 ++++++++++++++++++++++
 arch/x86/include/asm/acpi/global_nvs.h             | 19 ++++++++++++++++
 .../include/asm/arch-baytrail/acpi/global_nvs.asl  | 15 +++++++++++++
 arch/x86/include/asm/arch-baytrail/global_nvs.h    | 21 +++++++++++++++++
 4 files changed, 81 insertions(+)
 create mode 100644 arch/x86/include/asm/acpi/global_nvs.h
 create mode 100644 arch/x86/include/asm/arch-baytrail/acpi/global_nvs.asl
 create mode 100644 arch/x86/include/asm/arch-baytrail/global_nvs.h
arch/x86/cpu/baytrail/acpi.c +26 -0
index 5ee4868..fa92d88 100644
@@ -5,10 +5,14 @@
  */
 
 #include <common.h>
+#include <cpu.h>
+#include <dm.h>
+#include <dm/uclass-internal.h>
 #include <asm/acpi_table.h>
 #include <asm/ioapic.h>
 #include <asm/mpspec.h>
 #include <asm/tables.h>
+#include <asm/arch/global_nvs.h>
 #include <asm/arch/iomap.h>
 
 void acpi_create_fadt(struct acpi_fadt *fadt, struct acpi_facs *facs,
@@ -161,3 +165,25 @@ u32 acpi_fill_madt(u32 current)
 
 	return current;
 }
+
+void acpi_create_gnvs(struct acpi_global_nvs *gnvs)
+{
+	struct udevice *dev;
+	int ret;
+
+	/* at least we have one processor */
+	gnvs->pcnt = 1;
+	/* override the processor count with actual number */
+	ret = uclass_find_first_device(UCLASS_CPU, &dev);
+	if (ret == 0 && dev != NULL) {
+		ret = cpu_get_count(dev);
+		if (ret > 0)
+			gnvs->pcnt = ret;
+	}
+
+	/* determine whether internal uart is on */
+	if (IS_ENABLED(CONFIG_INTERNAL_UART))
+		gnvs->iuart_en = 1;
+	else
+		gnvs->iuart_en = 0;
+}
arch/x86/include/asm/acpi/global_nvs.h new file +19 -0
new file mode 100644
index 0000000..7f2ffd4
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2016, Bin Meng <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef _ACPI_GNVS_H_
+#define _ACPI_GNVS_H_
+
+/*
+ * This file provides two ACPI global NVS macros: ACPI_GNVS_ADDR and
+ * ACPI_GNVS_SIZE. They are to be used in platform's global_nvs.asl file
+ * to declare the GNVS OperationRegion, as well as write_acpi_tables()
+ * for the GNVS address runtime fix up.
+ */
+#define ACPI_GNVS_ADDR	0xdeadbeef
+#define ACPI_GNVS_SIZE	0x100
+
+#endif /* _ACPI_GNVS_H_ */
arch/x86/include/asm/arch-baytrail/acpi/global_nvs.asl new file +15 -0
new file mode 100644
index 0000000..a28d4df
@@ -0,0 +1,15 @@
+/*
+ * Copyright (C) 2016 Bin Meng <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <asm/acpi/global_nvs.h>
+
+OperationRegion(GNVS, SystemMemory, ACPI_GNVS_ADDR, ACPI_GNVS_SIZE)
+Field(GNVS, ByteAcc, NoLock, Preserve)
+{
+	Offset (0x00),
+	PCNT, 8,	/* processor count */
+	IURE, 8,	/* internal UART enabled */
+}
arch/x86/include/asm/arch-baytrail/global_nvs.h new file +21 -0
new file mode 100644
index 0000000..56e3626
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2016, Bin Meng <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef _GLOBAL_NVS_H_
+#define _GLOBAL_NVS_H_
+
+struct __packed acpi_global_nvs {
+	u8	pcnt;		/* processor count */
+	u8	iuart_en;	/* internal UART enabled */
+
+	/*
+	 * Add padding so sizeof(struct acpi_global_nvs) == 0x100.
+	 * This must match the size defined in the global_nvs.asl.
+	 */
+	u8	rsvd[254];
+};
+
+#endif /* _GLOBAL_NVS_H_ */
Signature · 1 line
2.7.4
author
#3 lore raw

PATCH v2 2/4 x86: quark: Introduce ACPI global NVS

In reply to Bin Meng

This introduces quark-specific ACPI global NVS structure, defined in both C header file and ASL file.

---

Changes in v2:
- Replace with 0xdeadbeef with defines from header file

 arch/x86/cpu/quark/acpi.c                           |  7 +++++++
 arch/x86/include/asm/arch-quark/acpi/global_nvs.asl | 14 ++++++++++++++
 arch/x86/include/asm/arch-quark/global_nvs.h        | 20 ++++++++++++++++++++
 3 files changed, 41 insertions(+)
 create mode 100644 arch/x86/include/asm/arch-quark/acpi/global_nvs.asl
 create mode 100644 arch/x86/include/asm/arch-quark/global_nvs.h
arch/x86/cpu/quark/acpi.c +7 -0
index 8f69829..3968f7a 100644
@@ -9,6 +9,7 @@
 #include <asm/ioapic.h>
 #include <asm/mpspec.h>
 #include <asm/tables.h>
+#include <asm/arch/global_nvs.h>
 #include <asm/arch/iomap.h>
 
 void acpi_create_fadt(struct acpi_fadt *fadt, struct acpi_facs *facs,
@@ -161,3 +162,9 @@ u32 acpi_fill_madt(u32 current)
 
 	return current;
 }
+
+void acpi_create_gnvs(struct acpi_global_nvs *gnvs)
+{
+	/* quark is a uni-processor */
+	gnvs->pcnt = 1;
+}
arch/x86/include/asm/arch-quark/acpi/global_nvs.asl new file +14 -0
new file mode 100644
index 0000000..6f0435e
@@ -0,0 +1,14 @@
+/*
+ * Copyright (C) 2016 Bin Meng <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <asm/acpi/global_nvs.h>
+
+OperationRegion(GNVS, SystemMemory, ACPI_GNVS_ADDR, ACPI_GNVS_SIZE)
+Field(GNVS, ByteAcc, NoLock, Preserve)
+{
+	Offset (0x00),
+	PCNT, 8,	/* processor count */
+}
arch/x86/include/asm/arch-quark/global_nvs.h new file +20 -0
new file mode 100644
index 0000000..0231da0
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2016, Bin Meng <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef _GLOBAL_NVS_H_
+#define _GLOBAL_NVS_H_
+
+struct __packed acpi_global_nvs {
+	u8	pcnt;		/* processor count */
+
+	/*
+	 * Add padding so sizeof(struct acpi_global_nvs) == 0x100.
+	 * This must match the size defined in the global_nvs.asl.
+	 */
+	u8	rsvd[255];
+};
+
+#endif /* _GLOBAL_NVS_H_ */
Signature · 1 line
2.7.4
author
#5 lore raw

PATCH v2 3/4 x86: acpi: Pack global NVS into ACPI table

In reply to Bin Meng

Now that platform-specific ACPI global NVS is added, pack it into ACPI table and get its address fixed up.

---

Changes in v2:
- Don't use hardcoded 0xdeadbeef, use defines instead
- Simplify the casting of gnvs by declaring it as "u32 *"

 arch/x86/include/asm/acpi_table.h                  |  4 ++++
 .../include/asm/arch-baytrail/acpi/platform.asl    |  3 +++
 arch/x86/include/asm/arch-quark/acpi/platform.asl  |  3 +++
 arch/x86/lib/acpi_table.c                          | 22 ++++++++++++++++++++++
 doc/README.x86                                     |  2 --
 5 files changed, 32 insertions(+), 2 deletions(-)
arch/x86/include/asm/acpi_table.h +4 -0
index 56aa282..caff4d8 100644
@@ -299,6 +299,9 @@ struct acpi_mcfg_mmconfig {
 /* PM1_CNT bit defines */
 #define PM1_CNT_SCI_EN		(1 << 0)
 
+/* ACPI global NVS structure */
+struct acpi_global_nvs;
+
 /* These can be used by the target port */
 
 void acpi_fill_header(struct acpi_table_header *header, char *signature);
@@ -312,4 +315,5 @@ int acpi_create_madt_irqoverride(struct acpi_madt_irqoverride *irqoverride,
 int acpi_create_madt_lapic_nmi(struct acpi_madt_lapic_nmi *lapic_nmi,
 			       u8 cpu, u16 flags, u8 lint);
 u32 acpi_fill_madt(u32 current);
+void acpi_create_gnvs(struct acpi_global_nvs *gnvs);
 u32 write_acpi_tables(u32 start);
arch/x86/include/asm/arch-baytrail/acpi/platform.asl +3 -0
index 6bc82ec..a80d2c0 100644
@@ -22,6 +22,9 @@ Method(_WAK, 1)
 	Return (Package() {0, 0})
 }
 
+/* ACPI global NVS */
+#include "global_nvs.asl"
+
 /* TODO: add CPU ASL support */
 
 Scope (\_SB)
arch/x86/include/asm/arch-quark/acpi/platform.asl +3 -0
index bd72842..1ecf153 100644
@@ -22,6 +22,9 @@ Method(_WAK, 1)
 	Return (Package() {0, 0})
 }
 
+/* ACPI global NVS */
+#include "global_nvs.asl"
+
 /* TODO: add CPU ASL support */
 
 Scope (\_SB)
arch/x86/lib/acpi_table.c +22 -0
index bb71286..7001e8b 100644
@@ -11,10 +11,12 @@
 #include <cpu.h>
 #include <dm.h>
 #include <dm/uclass-internal.h>
+#include <asm/acpi/global_nvs.h>
 #include <asm/acpi_table.h>
 #include <asm/io.h>
 #include <asm/lapic.h>
 #include <asm/tables.h>
+#include <asm/arch/global_nvs.h>
 
 /*
  * IASL compiles the dsdt entries and writes the hex values
@@ -336,6 +338,7 @@ u32 write_acpi_tables(u32 start)
 	struct acpi_fadt *fadt;
 	struct acpi_mcfg *mcfg;
 	struct acpi_madt *madt;
+	int i;
 
 	current = start;
 
@@ -383,6 +386,25 @@ u32 write_acpi_tables(u32 start)
 	current += dsdt->length - sizeof(struct acpi_table_header);
 	current = ALIGN(current, 16);
 
+	/* Pack GNVS into the ACPI table area */
+	for (i = 0; i < dsdt->length; i++) {
+		u32 *gnvs = (u32 *)((u32)dsdt + i);
+		if (*gnvs == ACPI_GNVS_ADDR) {
+			debug("Fix up global NVS in DSDT to 0x%08x\n", current);
+			*gnvs = current;
+			break;
+		}
+	}
+
+	/* Update DSDT checksum since we patched the GNVS address */
+	dsdt->checksum = 0;
+	dsdt->checksum = table_compute_checksum((void *)dsdt, dsdt->length);
+
+	/* Fill in platform-specific global NVS variables */
+	acpi_create_gnvs((struct acpi_global_nvs *)current);
+	current += sizeof(struct acpi_global_nvs);
+	current = ALIGN(current, 16);
+
 	debug("ACPI:    * FADT\n");
 	fadt = (struct acpi_fadt *)current;
 	current += sizeof(struct acpi_fadt);
doc/README.x86 +0 -2
index a548b54..7d694b1 100644
@@ -1020,8 +1020,6 @@ Features not supported so far (to make it a complete ACPI solution):
  * S3 (Suspend to RAM), S4 (Suspend to Disk).
 
 Features that are optional:
- * ACPI global NVS support. We may need it to simplify ASL code logic if
-   utilizing NVS variables. Most likely we will need this sooner or later.
  * Dynamic AML bytecodes insertion at run-time. We may need this to support
    SSDT table generation and DSDT fix up.
  * SMI support. Since U-Boot is a modern bootloader, we don't want to bring
Signature · 1 line
2.7.4
author
#7 lore raw

PATCH v2 4/4 x86: baytrail: acpi: Hide internal UART per GNVS setting

In reply to Bin Meng

If global NVS says internal UART is not enabled, hide it in the ASL code so that OS won't see it.

---

Changes in v2: None

 arch/x86/include/asm/arch-baytrail/acpi/lpc.asl | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
arch/x86/include/asm/arch-baytrail/acpi/lpc.asl +8 -11
index 22f0d68..fe34d32 100644
@@ -119,17 +119,14 @@ Device (LPCB)
 
 		Method(_STA, 0, Serialized)
 		{
-			/*
-			 * TODO:
-			 *
-			 * Need to hide the internal UART depending on whether
-			 * internal UART is enabled or not so that external
-			 * SuperIO UART can be exposed to system.
-			 */
-			Store(1, UI3E)
-			Store(1, UI4E)
-			Store(1, C1EN)
-			Return (STA_VISIBLE)
+			If (LEqual(IURE, 1)) {
+				Store(1, UI3E)
+				Store(1, UI4E)
+				Store(1, C1EN)
+				Return (STA_VISIBLE)
+			} Else {
+				Return (STA_MISSING)
+			}
 
 		}
 
Signature · 1 line
2.7.4
#8 lore raw

PATCH v2 4/4 x86: baytrail: acpi: Hide internal UART per GNVS setting

Quoted 7 lines · Bin Meng

If global NVS says internal UART is not enabled, hide it in the ASL code so that OS won't see it.

Quoted 6 lines

---

Changes in v2: None

 arch/x86/include/asm/arch-baytrail/acpi/lpc.asl | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
author
#2 lore raw

PATCH v2 1/4 x86: baytrail: Introduce ACPI global NVS

In reply to Bin Meng
Quoted 13 lines · Bin Meng

This introduces baytrail-specific ACPI global NVS structure, defined in both C header file and ASL file.

---

Changes in v2:
- Add arch/x86/include/asm/acpi/global_nvs.h for 0xdeadbeef defines

Quoted 9 lines
 arch/x86/cpu/baytrail/acpi.c                       | 26 ++++++++++++++++++++++
 arch/x86/include/asm/acpi/global_nvs.h             | 19 ++++++++++++++++
 .../include/asm/arch-baytrail/acpi/global_nvs.asl  | 15 +++++++++++++
 arch/x86/include/asm/arch-baytrail/global_nvs.h    | 21 +++++++++++++++++
 4 files changed, 81 insertions(+)
 create mode 100644 arch/x86/include/asm/acpi/global_nvs.h
 create mode 100644 arch/x86/include/asm/arch-baytrail/acpi/global_nvs.asl
 create mode 100644 arch/x86/include/asm/arch-baytrail/global_nvs.h

applied to u-boot-x86/next, thanks!

author
#4 lore raw

PATCH v2 2/4 x86: quark: Introduce ACPI global NVS

In reply to Bin Meng
Quoted 11 lines · Bin Meng

This introduces quark-specific ACPI global NVS structure, defined in both C header file and ASL file.

---

Changes in v2:
- Replace with 0xdeadbeef with defines from header file

Quoted 7 lines
 arch/x86/cpu/quark/acpi.c                           |  7 +++++++
 arch/x86/include/asm/arch-quark/acpi/global_nvs.asl | 14 ++++++++++++++
 arch/x86/include/asm/arch-quark/global_nvs.h        | 20 ++++++++++++++++++++
 3 files changed, 41 insertions(+)
 create mode 100644 arch/x86/include/asm/arch-quark/acpi/global_nvs.asl
 create mode 100644 arch/x86/include/asm/arch-quark/global_nvs.h

applied to u-boot-x86/next, thanks!

author
#6 lore raw

PATCH v2 3/4 x86: acpi: Pack global NVS into ACPI table

In reply to Bin Meng
Quoted 14 lines · Bin Meng

Now that platform-specific ACPI global NVS is added, pack it into ACPI table and get its address fixed up.

---

Changes in v2:
- Don't use hardcoded 0xdeadbeef, use defines instead
- Simplify the casting of gnvs by declaring it as "u32 *"

Quoted 7 lines
 arch/x86/include/asm/acpi_table.h                  |  4 ++++
 .../include/asm/arch-baytrail/acpi/platform.asl    |  3 +++
 arch/x86/include/asm/arch-quark/acpi/platform.asl  |  3 +++
 arch/x86/lib/acpi_table.c                          | 22 ++++++++++++++++++++++
 doc/README.x86                                     |  2 --
 5 files changed, 32 insertions(+), 2 deletions(-)

applied to u-boot-x86/next, thanks!

author
#9 lore raw

PATCH v2 4/4 x86: baytrail: acpi: Hide internal UART per GNVS setting

In reply to Simon Glass
Quoted 8 lines · Simon Glass
Quoted 7 lines · Bin Meng

If global NVS says internal UART is not enabled, hide it in the ASL code so that OS won't see it.

Quoted 8 lines
Quoted 6 lines

---

Changes in v2: None

 arch/x86/include/asm/arch-baytrail/acpi/lpc.asl | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

applied to u-boot-x86/next, thanks!