Re: [PATCH v5 22/29] acpi: Add a method to write tables for a device

2020-04-15 Thread Bin Meng
Hi Simon,

On Thu, Apr 9, 2020 at 6:58 AM Simon Glass  wrote:
>
> A device may want to write out ACPI tables to describe itself to Linux.
> Add a method to permit this.
>
> Reviewed-by: Wolfgang Wallner 
> Signed-off-by: Simon Glass 
> ---
>
> Changes in v5:
> - Drop bisectability changes
>
> Changes in v4:
> - Separate out the log newline
>
> Changes in v3: None
> Changes in v2:
> - Drop definition of ACPI_TABLE_CREATOR
> - Make _acpi_write_dev_tables() static and switch argument order
> - Generalise the ACPI function recursion with acpi_recurse_method()
>
>  arch/sandbox/dts/test.dts |  4 +++
>  arch/x86/lib/acpi_table.c |  9 -
>  drivers/core/acpi.c   | 62 
>  include/acpi/acpi_table.h | 10 ++
>  include/dm/acpi.h | 30 
>  lib/acpi/acpi_table.c | 13 +--
>  test/dm/acpi.c| 74 +--
>  7 files changed, 187 insertions(+), 15 deletions(-)
>

This patch does not apply on top of u-boot-x86/master. Please rebase
and resubmit. I will leave the rest of the patches in this series
un-applied.

Regards,
Bin


[PATCH v5 22/29] acpi: Add a method to write tables for a device

2020-04-08 Thread Simon Glass
A device may want to write out ACPI tables to describe itself to Linux.
Add a method to permit this.

Reviewed-by: Wolfgang Wallner 
Signed-off-by: Simon Glass 
---

Changes in v5:
- Drop bisectability changes

Changes in v4:
- Separate out the log newline

Changes in v3: None
Changes in v2:
- Drop definition of ACPI_TABLE_CREATOR
- Make _acpi_write_dev_tables() static and switch argument order
- Generalise the ACPI function recursion with acpi_recurse_method()

 arch/sandbox/dts/test.dts |  4 +++
 arch/x86/lib/acpi_table.c |  9 -
 drivers/core/acpi.c   | 62 
 include/acpi/acpi_table.h | 10 ++
 include/dm/acpi.h | 30 
 lib/acpi/acpi_table.c | 13 +--
 test/dm/acpi.c| 74 +--
 7 files changed, 187 insertions(+), 15 deletions(-)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 5fa951ad4b6..1204c14b079 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -210,6 +210,10 @@
compatible = "denx,u-boot-acpi-test";
};
 
+   acpi-test2 {
+   compatible = "denx,u-boot-acpi-test";
+   };
+
clocks {
clk_fixed: clk-fixed {
compatible = "fixed-clock";
diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c
index 4832364f3ca..98f97208339 100644
--- a/arch/x86/lib/acpi_table.c
+++ b/arch/x86/lib/acpi_table.c
@@ -60,15 +60,6 @@ static void acpi_write_rsdp(struct acpi_rsdp *rsdp, struct 
acpi_rsdt *rsdt,
sizeof(struct acpi_rsdp));
 }
 
-void acpi_fill_header(struct acpi_table_header *header, char *signature)
-{
-   memcpy(header->signature, signature, 4);
-   memcpy(header->oem_id, OEM_ID, 6);
-   memcpy(header->oem_table_id, OEM_TABLE_ID, 8);
-   header->oem_revision = U_BOOT_BUILD_DATE;
-   memcpy(header->aslc_id, ASLC_ID, 4);
-}
-
 static void acpi_write_rsdt(struct acpi_rsdt *rsdt)
 {
struct acpi_table_header *header = &(rsdt->header);
diff --git a/drivers/core/acpi.c b/drivers/core/acpi.c
index 0e64c21bf5b..8a6570c3b95 100644
--- a/drivers/core/acpi.c
+++ b/drivers/core/acpi.c
@@ -11,8 +11,17 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
+/* Type of method to call */
+enum method_t {
+   METHOD_WRITE_TABLES,
+};
+
+/* Prototype for all methods */
+typedef int (*acpi_method)(const struct udevice *dev, struct acpi_ctx *ctx);
+
 int acpi_copy_name(char *out_name, const char *name)
 {
strncpy(out_name, name, ACPI_NAME_MAX);
@@ -31,3 +40,56 @@ int acpi_get_name(const struct udevice *dev, char *out_name)
 
return -ENOSYS;
 }
+
+acpi_method acpi_get_method(struct udevice *dev, enum method_t method)
+{
+   struct acpi_ops *aops;
+
+   aops = device_get_acpi_ops(dev);
+   if (aops) {
+   switch (method) {
+   case METHOD_WRITE_TABLES:
+   return aops->write_tables;
+   }
+   }
+
+   return NULL;
+}
+
+int acpi_recurse_method(struct acpi_ctx *ctx, struct udevice *parent,
+   enum method_t method)
+{
+   struct udevice *dev;
+   acpi_method func;
+   int ret;
+
+   func = acpi_get_method(parent, method);
+   if (func) {
+   log_debug("\n");
+   log_debug("- %s %p\n", parent->name, func);
+   ret = device_ofdata_to_platdata(parent);
+   if (ret)
+   return log_msg_ret("ofdata", ret);
+   ret = func(parent, ctx);
+   if (ret)
+   return log_msg_ret("func", ret);
+   }
+   device_foreach_child(dev, parent) {
+   ret = acpi_recurse_method(ctx, dev, method);
+   if (ret)
+   return log_msg_ret("recurse", ret);
+   }
+
+   return 0;
+}
+
+int acpi_write_dev_tables(struct acpi_ctx *ctx)
+{
+   int ret;
+
+   log_debug("Writing device tables\n");
+   ret = acpi_recurse_method(ctx, dm_root(), METHOD_WRITE_TABLES);
+   log_debug("Writing finished, err=%d\n", ret);
+
+   return ret;
+}
diff --git a/include/acpi/acpi_table.h b/include/acpi/acpi_table.h
index 194be9aa589..a2bd929c920 100644
--- a/include/acpi/acpi_table.h
+++ b/include/acpi/acpi_table.h
@@ -505,6 +505,16 @@ int acpi_get_table_revision(enum acpi_tables table);
  */
 int acpi_create_dmar(struct acpi_dmar *dmar, enum dmar_flags flags);
 
+/**
+ * acpi_fill_header() - Set up a new table header
+ *
+ * This sets all fields except length, revision, checksum and aslc_revision
+ *
+ * @header: ACPI header to update
+ * @signature: Table signature to use (4 characters)
+ */
+void acpi_fill_header(struct acpi_table_header *header, char *signature);
+
 #endif /* !__ACPI__*/
 
 #include 
diff --git a/include/dm/acpi.h b/include/dm/acpi.h
index 49257914ffd..69d69d7f423 100644
--- a/include/dm/acpi.h
+++ b/include/dm/acpi.h
@@ -24,6 +24,1