Skip to contentSkip to conversation

x86: acpi: Introduce ACPI global NVS support

PATCH Superseded Bin Meng 3 participants 14 messages Jun 15, 2016 – Jun 17, 2016 x86

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

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.

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_table.h                  |  4 ++++
 .../include/asm/arch-baytrail/acpi/global_nvs.asl  | 13 +++++++++++
 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 | 12 ++++++++++
 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                          | 21 +++++++++++++++++
 doc/README.x86                                     |  2 --
 12 files changed, 138 insertions(+), 13 deletions(-)
 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 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.

---

 arch/x86/cpu/baytrail/acpi.c                       | 26 ++++++++++++++++++++++
 .../include/asm/arch-baytrail/acpi/global_nvs.asl  | 13 +++++++++++
 arch/x86/include/asm/arch-baytrail/global_nvs.h    | 21 +++++++++++++++++
 3 files changed, 60 insertions(+)
 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/arch-baytrail/acpi/global_nvs.asl new file +13 -0
new file mode 100644
index 0000000..fe348b3
@@ -0,0 +1,13 @@
+/*
+ * Copyright (C) 2016 Bin Meng <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+OperationRegion(GNVS, SystemMemory, 0xdeadbeef, 0x100)
+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
#4 lore raw

PATCH 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.

---

 arch/x86/cpu/quark/acpi.c                           |  7 +++++++
 arch/x86/include/asm/arch-quark/acpi/global_nvs.asl | 12 ++++++++++++
 arch/x86/include/asm/arch-quark/global_nvs.h        | 20 ++++++++++++++++++++
 3 files changed, 39 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 +12 -0
new file mode 100644
index 0000000..3f9fd89
@@ -0,0 +1,12 @@
+/*
+ * Copyright (C) 2016 Bin Meng <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+OperationRegion(GNVS, SystemMemory, 0xdeadbeef, 0x100)
+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
#6 lore raw

PATCH 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.

---

 arch/x86/include/asm/acpi_table.h                   |  4 ++++
 .../x86/include/asm/arch-baytrail/acpi/platform.asl |  3 +++
 arch/x86/include/asm/arch-quark/acpi/platform.asl   |  3 +++
 arch/x86/lib/acpi_table.c                           | 21 +++++++++++++++++++++
 doc/README.x86                                      |  2 --
 5 files changed, 31 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 +21 -0
index bb71286..2e4f3ab 100644
@@ -15,6 +15,7 @@
 #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 +337,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 +385,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)dsdt + i;
+		if (*(u32 *)gnvs == 0xdeadbeef) {
+			debug("Fix up global NVS in DSDT to 0x%08x\n", current);
+			*(u32 *)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
#10 lore raw

PATCH 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.

---

 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
#2 lore raw

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

In reply to Bin Meng
Quoted 4 lines · Bin Meng

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

Quoted 8 lines

---

 arch/x86/cpu/baytrail/acpi.c                       | 26 ++++++++++++++++++++++
 .../include/asm/arch-baytrail/acpi/global_nvs.asl  | 13 +++++++++++
 arch/x86/include/asm/arch-baytrail/global_nvs.h    | 21 +++++++++++++++++
 3 files changed, 60 insertions(+)
 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
#7 lore raw

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

In reply to Bin Meng
Quoted 4 lines · Bin Meng

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

Quoted 8 lines

---

 arch/x86/include/asm/acpi_table.h                   |  4 ++++
 .../x86/include/asm/arch-baytrail/acpi/platform.asl |  3 +++
 arch/x86/include/asm/arch-quark/acpi/platform.asl   |  3 +++
 arch/x86/lib/acpi_table.c                           | 21 +++++++++++++++++++++
 doc/README.x86                                      |  2 --
 5 files changed, 31 insertions(+), 2 deletions(-)
#11 lore raw

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

In reply to Bin Meng
Quoted 9 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.

---

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

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

Hi George,

Quoted 6 lines · George McCollister
Quoted 5 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 7 lines
Quoted 4 lines

---

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

Thanks for the review and testing. Does this series solve the UART issue you were seeing when booting Linux?

Regards,
Bin

#13 lore raw

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

Quoted 12 lines · Bin Meng

Hi George,

Quoted 8 lines · George McCollister
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 5 lines
Quoted 2 lines
 arch/x86/include/asm/arch-baytrail/acpi/lpc.asl | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

Thanks for the review and testing. Does this series solve the UART issue you were seeing when booting Linux?

Yes, it works perfectly now. Thanks.

Quoted 3 lines

Regards,
Bin

#5 lore raw

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

In reply to Bin Meng
Quoted 4 lines · Bin Meng

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

Quoted 8 lines

---

 arch/x86/cpu/quark/acpi.c                           |  7 +++++++
 arch/x86/include/asm/arch-quark/acpi/global_nvs.asl | 12 ++++++++++++
 arch/x86/include/asm/arch-quark/global_nvs.h        | 20 ++++++++++++++++++++
 3 files changed, 39 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
#3 lore raw

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

In reply to Bin Meng
Quoted 4 lines · Bin Meng

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

Quoted 8 lines

---

 arch/x86/cpu/baytrail/acpi.c                       | 26 ++++++++++++++++++++++
 .../include/asm/arch-baytrail/acpi/global_nvs.asl  | 13 +++++++++++
 arch/x86/include/asm/arch-baytrail/global_nvs.h    | 21 +++++++++++++++++
 3 files changed, 60 insertions(+)
 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
#8 lore raw

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

In reply to Bin Meng

Hi Bin,

Quoted 4 lines · Bin Meng

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

Quoted 8 lines

---

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

Comments/questions below

Quoted 70 lines
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 +2 -0
index bb71286..2e4f3ab 100644
@@ -15,6 +15,7 @@
 #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 +337,7 @@ u32 write_acpi_tables(u32 start)
        struct acpi_fadt *fadt;
        struct acpi_mcfg *mcfg;
        struct acpi_madt *madt;
+       int i;
 
        current = start;
 

arch/x86/lib/acpi_table.c u32 write_acpi_tables(u32 start) · line 390

Quoted 6 lines
arch/x86/lib/acpi_table.c +3 -0
@@ -383,6 +385,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)dsdt + i;

How about:

u32 *gnvs = (u32 *)(dsdt + i)

arch/x86/lib/acpi_table.c u32 write_acpi_tables(u32 start) · line 391

Quoted 1 line
arch/x86/lib/acpi_table.c +1 -0
+               if (*(u32 *)gnvs == 0xdeadbeef) {

The deadbeef comes from the .asl file, right? Can you use a #define shared by both files?

Quoted 32 lines
arch/x86/lib/acpi_table.c +15 -0
+                       debug("Fix up global NVS in DSDT to 0x%08x\n", current);
+                       *(u32 *)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 -3
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
--
Quoted 2 lines

2.7.4

Regards,
Simon

author
#9 lore raw

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

Hi Simon,

Quoted 93 lines · Simon Glass

Hi Bin,

Quoted 4 lines · Bin Meng

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

Quoted 8 lines

---

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

Comments/questions below

Quoted 73 lines
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 +2 -0
index bb71286..2e4f3ab 100644
@@ -15,6 +15,7 @@
 #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 +337,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 +385,25 @@ u32 write_acpi_tables(u32 start)
        current += dsdt->length - sizeof(struct acpi_table_header);
        current = ALIGN(current, 16);
 
Quoted 7 lines

arch/x86/lib/acpi_table.c u32 write_acpi_tables(u32 start) · line 390

Quoted 3 lines
arch/x86/lib/acpi_table.c +3 -0
+       /* Pack GNVS into the ACPI table area */
+       for (i = 0; i < dsdt->length; i++) {
+               u32 gnvs = (u32)dsdt + i;

How about:

u32 *gnvs = (u32 *)(dsdt + i)

(dsdt + i) points to wrong place, it should be:

u32 *gnvs = (u32 *)((u32)dsdt + i);

Which way do you prefer?

Quoted 6 lines

arch/x86/lib/acpi_table.c u32 write_acpi_tables(u32 start) · line 391

Quoted 2 lines
arch/x86/lib/acpi_table.c +1 -0
+               if (*(u32 *)gnvs == 0xdeadbeef) {

The deadbeef comes from the .asl file, right? Can you use a #define shared by both files?

Yes, they have to match. Will do in v2.

Quoted 25 lines
Quoted 25 lines
arch/x86/lib/acpi_table.c +15 -0
+                       debug("Fix up global NVS in DSDT to 0x%08x\n", current);
+                       *(u32 *)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 -0
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).
 
Quoted 7 lines

doc/README.x86 Features not supported so far (to make it a complete ACPI solution):

Quoted 7 lines
doc/README.x86 +0 -3
 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
--

Regards,
Bin