Skip to contentSkip to conversation

x86: acpi: Move APIs unrelated to ACPI tables generation to a separate library

PATCH Superseded Bin Meng 2 participants 5 messages Jun 28, 2018 x86

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

PATCH 1/3 x86: acpi: Move APIs unrelated to ACPI tables generation to a separate library

acpi_find_fadt(), acpi_find_wakeup_vector() and enter_acpi_mode() are something unrelated to ACPI tables generation. Move these to a separate library.

This also fixes several style issues reported by checkpatch in the original codes.

---

 arch/x86/cpu/cpu.c                |   1 +
 arch/x86/include/asm/acpi.h       |  41 +++++++++++++++
 arch/x86/include/asm/acpi_table.h |  28 ----------
 arch/x86/lib/Makefile             |   1 +
 arch/x86/lib/acpi.c               | 108 ++++++++++++++++++++++++++++++++++++++
 arch/x86/lib/acpi_s3.c            |   1 +
 arch/x86/lib/acpi_table.c         | 101 +----------------------------------
 7 files changed, 153 insertions(+), 128 deletions(-)
 create mode 100644 arch/x86/include/asm/acpi.h
 create mode 100644 arch/x86/lib/acpi.c
arch/x86/cpu/cpu.c +1 -0
index 6aefa12..f7601b3 100644
@@ -24,6 +24,7 @@
 #include <errno.h>
 #include <malloc.h>
 #include <syscon.h>
+#include <asm/acpi.h>
 #include <asm/acpi_s3.h>
 #include <asm/acpi_table.h>
 #include <asm/control_regs.h>
arch/x86/include/asm/acpi.h new file +41 -0

41 lines not on this page · raw message

arch/x86/include/asm/acpi_table.h +0 -28
index 239bcdc..dd516df 100644
@@ -317,15 +317,6 @@ int acpi_create_mcfg_mmconfig(struct acpi_mcfg_mmconfig *mmconfig, u32 base,
 			      u16 seg_nr, u8 start, u8 end);
 u32 acpi_fill_mcfg(u32 current);
 void acpi_create_gnvs(struct acpi_global_nvs *gnvs);
-/**
- * enter_acpi_mode() - enter into ACPI mode
- *
- * This programs the ACPI-defined PM1_CNT register to enable SCI interrupt
- * so that the whole system swiches to ACPI mode.
- *
- * @pm1_cnt:	PM1_CNT register I/O address
- */
-void enter_acpi_mode(int pm1_cnt);
 ulong write_acpi_tables(ulong start);
 
 /**
@@ -336,22 +327,3 @@ ulong write_acpi_tables(ulong start);
  * @return:	ACPI RSDP table address
  */
 ulong acpi_get_rsdp_addr(void);
-
-/**
- * acpi_find_fadt() - find ACPI FADT table in the sytem memory
- *
- * This routine parses the ACPI table to locate the ACPI FADT table.
- *
- * @return:	a pointer to the ACPI FADT table in the system memory
- */
-struct acpi_fadt *acpi_find_fadt(void);
-
-/**
- * acpi_find_wakeup_vector() - find OS installed wake up vector address
- *
- * This routine parses the ACPI table to locate the wake up vector installed
- * by the OS previously.
- *
- * @return:	wake up vector address installed by the OS
- */
-void *acpi_find_wakeup_vector(struct acpi_fadt *);
arch/x86/lib/Makefile +1 -0
index ba07ac7..1e8efcc 100644
@@ -33,6 +33,7 @@ obj-$(CONFIG_INTEL_MID) += scu.o
 obj-y	+= sections.o
 obj-y += sfi.o
 obj-y	+= string.o
+obj-y	+= acpi.o
 obj-$(CONFIG_HAVE_ACPI_RESUME) += acpi_s3.o
 ifndef CONFIG_QEMU
 obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi_table.o
arch/x86/lib/acpi.c new file +108 -0

108 lines not on this page · raw message

arch/x86/lib/acpi_s3.c +1 -0
index 514b92f..0391718 100644
@@ -4,6 +4,7 @@
  */
 
 #include <common.h>
+#include <asm/acpi.h>
 #include <asm/acpi_s3.h>
 #include <asm/acpi_table.h>
 #include <asm/post.h>
arch/x86/lib/acpi_table.c +1 -100

117 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#1 lore raw

PATCH 2/3 x86: acpi: Don't touch ACPI hardware in write_acpi_tables()

write_acpi_tables() currently touches ACPI hardware to switch to ACPI mode at the end. Move such operation out of this function, so that it only does what the function name tells us.

---

 arch/x86/cpu/cpu.c        | 20 +++++++++++++++++---
 arch/x86/lib/acpi_table.c | 11 -----------
 2 files changed, 17 insertions(+), 14 deletions(-)
arch/x86/cpu/cpu.c +17 -3
index f7601b3..3a45677 100644
@@ -206,16 +206,30 @@ __weak void board_final_cleanup(void)
 int last_stage_init(void)
 {
 	board_final_cleanup();
+	struct acpi_fadt __maybe_unused *fadt;
 
-#if CONFIG_HAVE_ACPI_RESUME
-	struct acpi_fadt *fadt = acpi_find_fadt();
+#ifdef CONFIG_HAVE_ACPI_RESUME
+	fadt = acpi_find_fadt();
 
-	if (fadt != NULL && gd->arch.prev_sleep_state == ACPI_S3)
+	if (fadt && gd->arch.prev_sleep_state == ACPI_S3)
 		acpi_resume(fadt);
 #endif
 
 	write_tables();
 
+#ifdef CONFIG_GENERATE_ACPI_TABLE
+	fadt = acpi_find_fadt();
+
+	/* Don't touch ACPI hardware on HW reduced platforms */
+	if (fadt && !(fadt->flags & ACPI_FADT_HW_REDUCED_ACPI)) {
+		/*
+		 * Other than waiting for OSPM to request us to switch to ACPI
+		 * mode, do it by ourselves, since SMI will not be triggered.
+		 */
+		enter_acpi_mode(fadt->pm1a_cnt_blk);
+	}
+#endif
+
 	return 0;
 }
 #endif
arch/x86/lib/acpi_table.c +0 -11
index e26c54d..e48c9b9 100644
@@ -12,7 +12,6 @@
 #include <dm/uclass-internal.h>
 #include <version.h>
 #include <asm/acpi/global_nvs.h>
-#include <asm/acpi.h>
 #include <asm/acpi_table.h>
 #include <asm/ioapic.h>
 #include <asm/lapic.h>
@@ -444,16 +443,6 @@ ulong write_acpi_tables(ulong start)
 	acpi_rsdp_addr = (unsigned long)rsdp;
 	debug("ACPI: done\n");
 
-	/* Don't touch ACPI hardware on HW reduced platforms */
-	if (fadt->flags & ACPI_FADT_HW_REDUCED_ACPI)
-		return current;
-
-	/*
-	 * Other than waiting for OSPM to request us to switch to ACPI mode,
-	 * do it by ourselves, since SMI will not be triggered.
-	 */
-	enter_acpi_mode(fadt->pm1a_cnt_blk);
-
 	return current;
 }
 
Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/3 x86: acpi: Don't touch ACPI hardware in write_acpi_tables()

Quoted 7 lines · Bin Meng

write_acpi_tables() currently touches ACPI hardware to switch to ACPI mode at the end. Move such operation out of this function, so that it only does what the function name tells us.

 {
        board_final_cleanup();

+ struct acpi_fadt __maybe_unused *fadt;

I guess this would be first line in the function. No? And personally I don't like to see __maybe_unused near to local variables (see also below).

arch/x86/cpu/cpu.c __weak void board_final_cleanup(void) · line 221

Quoted 12 lines
arch/x86/cpu/cpu.c +5 -1
+#ifdef CONFIG_HAVE_ACPI_RESUME
+       fadt = acpi_find_fadt();
 
-       if (fadt != NULL && gd->arch.prev_sleep_state == ACPI_S3)
+       if (fadt && gd->arch.prev_sleep_state == ACPI_S3)
                acpi_resume(fadt);
 #endif
 
        write_tables();
 
+#ifdef CONFIG_GENERATE_ACPI_TABLE
+       fadt = acpi_find_fadt();

This sounds superfluous, we create tables ourselves, why do we need traverse again to find them?

Looks like you would do something such as

struct acpi_fadt *fadt /* maybe save to do as well: = acpi_find_fadt() */;

...

fadt = write_tables(); //or any other way to get the pointer without traversing
...

Quoted 9 lines
arch/x86/cpu/cpu.c +9 -0
+
+       /* Don't touch ACPI hardware on HW reduced platforms */
+       if (fadt && !(fadt->flags & ACPI_FADT_HW_REDUCED_ACPI)) {
+               /*
+                * Other than waiting for OSPM to request us to switch to ACPI
+                * mode, do it by ourselves, since SMI will not be triggered.
+                */
+               enter_acpi_mode(fadt->pm1a_cnt_blk);
+       }
Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#3 lore raw

PATCH 2/3 x86: acpi: Don't touch ACPI hardware in write_acpi_tables()

Hi Andy,

Quoted 10 lines · Andy Shevchenko
Quoted 7 lines · Bin Meng

write_acpi_tables() currently touches ACPI hardware to switch to ACPI mode at the end. Move such operation out of this function, so that it only does what the function name tells us.

 {
        board_final_cleanup();

+ struct acpi_fadt __maybe_unused *fadt;

I guess this would be first line in the function. No?

Yes, it should be the first line. Will fix.

Quoted 3 lines

And personally I don't like to see __maybe_unused near to local variables (see also below).

Without __maybe_unused

Quoted 13 lines

arch/x86/cpu/cpu.c __weak void board_final_cleanup(void) · line 221

Quoted 12 lines
arch/x86/cpu/cpu.c +5 -1
+#ifdef CONFIG_HAVE_ACPI_RESUME
+       fadt = acpi_find_fadt();
 
-       if (fadt != NULL && gd->arch.prev_sleep_state == ACPI_S3)
+       if (fadt && gd->arch.prev_sleep_state == ACPI_S3)
                acpi_resume(fadt);
 #endif
 
        write_tables();
 
+#ifdef CONFIG_GENERATE_ACPI_TABLE
+       fadt = acpi_find_fadt();
Quoted 6 lines

This sounds superfluous, we create tables ourselves, why do we need traverse again to find them?

Looks like you would do something such as

struct acpi_fadt *fadt /* maybe save to do as well: = acpi_find_fadt() */;

Do the assignment here only works for S3 path.

Quoted 4 lines

...

fadt = write_tables(); //or any other way to get the pointer without traversing

Let write_tables() return FADT address is odd. write_tables() is generic API for writing various configuration tables.

Quoted 12 lines

...

arch/x86/cpu/cpu.c __weak void board_final_cleanup(void) · line 230

Quoted 9 lines
arch/x86/cpu/cpu.c +9 -0
+
+       /* Don't touch ACPI hardware on HW reduced platforms */
+       if (fadt && !(fadt->flags & ACPI_FADT_HW_REDUCED_ACPI)) {
+               /*
+                * Other than waiting for OSPM to request us to switch to ACPI
+                * mode, do it by ourselves, since SMI will not be triggered.
+                */
+               enter_acpi_mode(fadt->pm1a_cnt_blk);
+       }

Regards,
Bin

author
#4 lore raw

PATCH 3/3 x86: acpi: Prevent acpi_table.h from being included more than once

In reply to Bin Meng

The wrapper #ifndef is currently missing in acpi_table.h. Add it to prevent it from being included multiple times.

---

 arch/x86/include/asm/acpi_table.h | 5 +++++
 1 file changed, 5 insertions(+)
arch/x86/include/asm/acpi_table.h +5 -0
index dd516df..95fae03 100644
@@ -6,6 +6,9 @@
  * Copyright (C) 2016, Bin Meng <[email protected]>
  */
 
+#ifndef __ASM_ACPI_TABLE_H__
+#define __ASM_ACPI_TABLE_H__
+
 #define RSDP_SIG		"RSD PTR "	/* RSDP pointer signature */
 #define OEM_ID			"U-BOOT"	/* U-Boot */
 #define OEM_TABLE_ID		"U-BOOTBL"	/* U-Boot Table */
@@ -327,3 +330,5 @@ ulong write_acpi_tables(ulong start);
  * @return:	ACPI RSDP table address
  */
 ulong acpi_get_rsdp_addr(void);
+
+#endif /* __ASM_ACPI_TABLE_H__ */
Signature · 1 line
2.7.4