[PATCH] board: ls1028ardb: add BOARD_LATE_INIT config

2020-03-08 Thread andy . tang
From: Yuantian Tang 

Select BOARD_LATE_INIT config so that many board works can be done
in late init stage.

Signed-off-by: Yuantian Tang 
---
 arch/arm/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 8d9f7fcce7..d871c13aab 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1376,6 +1376,7 @@ config TARGET_LS1028ARDB
select ARM64
select ARMV8_MULTIENTRY
select ARCH_SUPPORT_TFABOOT
+   select BOARD_LATE_INIT
help
  Support for Freescale LS1028ARDB platform
  The LS1028A Development System (RDB) is a high-performance
-- 
2.17.1



[PATCH v2 38/39] acpi: Add support for DSDT generation

2020-03-08 Thread Simon Glass
Some devices need to inject extra code into the Differentiated System
Descriptor Table (DSDT). Add a method to handle this.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Generalise the ACPI function recursion with acpi_recurse_method()

 arch/sandbox/dts/test.dts |  2 ++
 drivers/core/acpi.c   | 25 ++-
 include/dm/acpi.h | 23 +
 test/dm/acpi.c| 42 +++
 4 files changed, 91 insertions(+), 1 deletion(-)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 7d55d360f6..9748c29a49 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -209,11 +209,13 @@
acpi_test1: acpi-test {
compatible = "denx,u-boot-acpi-test";
acpi-ssdt-test-data = "ab";
+   acpi-dsdt-test-data = "hi";
};
 
acpi_test2: acpi-test2 {
compatible = "denx,u-boot-acpi-test";
acpi-ssdt-test-data = "cd";
+   acpi-dsdt-test-data = "jk";
};
 
clocks {
diff --git a/drivers/core/acpi.c b/drivers/core/acpi.c
index 2f57ff9da2..5613a41eb0 100644
--- a/drivers/core/acpi.c
+++ b/drivers/core/acpi.c
@@ -21,12 +21,14 @@
 enum gen_type_t {
TYPE_NONE,
TYPE_SSDT,
+   TYPE_DSDT,
 };
 
 /* Type of method to call */
 enum method_t {
METHOD_WRITE_TABLES,
METHOD_FILL_SDDT,
+   METHOD_INJECT_DSDT,
 };
 
 /* Prototype for all methods */
@@ -129,7 +131,9 @@ static int build_type(struct acpi_ctx *ctx, void *start, 
enum gen_type_t type)
void *end = ctx->current;
 
ptr = start;
-   order = ofnode_read_chosen_prop("u-boot,acpi-ssdt-order", &size);
+   order = ofnode_read_chosen_prop(type == TYPE_DSDT ?
+   "u-boot,acpi-dsdt-order" :
+   "u-boot,acpi-ssdt-order", &size);
if (!order) {
log_warning("Failed to find ordering, leaving as is\n");
return 0;
@@ -174,6 +178,8 @@ acpi_method acpi_get_method(struct udevice *dev, enum 
method_t method)
return aops->write_tables;
case METHOD_FILL_SDDT:
return aops->fill_ssdt;
+   case METHOD_INJECT_DSDT:
+   return aops->inject_dsdt;
}
}
 
@@ -231,6 +237,23 @@ int acpi_fill_ssdt(struct acpi_ctx *ctx)
return ret;
 }
 
+int acpi_inject_dsdt(struct acpi_ctx *ctx)
+{
+   void *start = ctx->current;
+   int ret;
+
+   log_debug("Writing DSDT tables\n");
+   item_count = 0;
+   ret = acpi_recurse_method(ctx, dm_root(), METHOD_INJECT_DSDT,
+ TYPE_DSDT);
+   log_debug("Writing DSDT finished, err=%d\n", ret);
+   ret = build_type(ctx, start, TYPE_DSDT);
+   if (ret)
+   return log_msg_ret("build", ret);
+
+   return ret;
+}
+
 int acpi_write_dev_tables(struct acpi_ctx *ctx)
 {
int ret;
diff --git a/include/dm/acpi.h b/include/dm/acpi.h
index c340c21685..8de9296e71 100644
--- a/include/dm/acpi.h
+++ b/include/dm/acpi.h
@@ -85,6 +85,19 @@ struct acpi_ops {
 * @return 0 if OK, -ve on error
 */
int (*fill_ssdt)(const struct udevice *dev, struct acpi_ctx *ctx);
+
+   /**
+* inject_dsdt() - Generate DSDT code for a device
+*
+* This is called to create the DSDT code. THe method should write out
+* whatever ACPI code is needed by this device. It will end up in the
+* DSDT table.
+*
+* @dev: Device to write
+* @ctx: ACPI context to use
+* @return 0 if OK, -ve on error
+*/
+   int (*inject_dsdt)(const struct udevice *dev, struct acpi_ctx *ctx);
 };
 
 #define device_get_acpi_ops(dev)   ((dev)->driver->acpi_ops)
@@ -139,6 +152,16 @@ int acpi_write_dev_tables(struct acpi_ctx *ctx);
  */
 int acpi_fill_ssdt(struct acpi_ctx *ctx);
 
+/**
+ * acpi_inject_dsdt() - Generate ACPI tables for DSDT
+ *
+ * This is called to create the DSDT code for all devices.
+ *
+ * @ctx: ACPI context to use
+ * @return 0 if OK, -ve on error
+ */
+int acpi_inject_dsdt(struct acpi_ctx *ctx);
+
 #endif /* __ACPI__ */
 
 #endif
diff --git a/test/dm/acpi.c b/test/dm/acpi.c
index b0d8d41e49..16dc0955be 100644
--- a/test/dm/acpi.c
+++ b/test/dm/acpi.c
@@ -54,10 +54,22 @@ static int testacpi_fill_ssdt(const struct udevice *dev, 
struct acpi_ctx *ctx)
return 0;
 }
 
+static int testacpi_inject_dsdt(const struct udevice *dev, struct acpi_ctx 
*ctx)
+{
+   const char *data;
+
+   data = dev_read_string(dev, "acpi-dsdt-test-data");
+   while (*data)
+   acpigen_emit_byte(ctx, *data++);
+
+   return 0;
+}
+
 struct acpi_ops testacpi_ops = {
.get_name   = testacpi_get_name,
.write_tables   = testacpi_write_tables,
.fill_ssdt  = testacpi_fill_ssdt,
+   .inj

[PATCH v2 39/39] x86: Allow devices to write to DSDT

2020-03-08 Thread Simon Glass
Call the new core function to inject ASL programmatically into the DSDT.
This is made up of fragments generated by devices that have the
inject_dsdt() method. The normal, compiled ASL file is added after this.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 arch/x86/lib/acpi_table.c | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c
index 3b97fe162c..5e14149923 100644
--- a/arch/x86/lib/acpi_table.c
+++ b/arch/x86/lib/acpi_table.c
@@ -422,7 +422,20 @@ ulong write_acpi_tables(ulong start_addr)
memcpy(ctx->current,
   (char *)&AmlCode + sizeof(struct acpi_table_header),
   dsdt->length - sizeof(struct acpi_table_header));
-   acpi_inc_align(ctx, dsdt->length - sizeof(struct acpi_table_header));
+
+   if (dsdt->length >= sizeof(struct acpi_table_header)) {
+   acpi_inject_dsdt(ctx);
+   memcpy(ctx->current,
+  (char *)AmlCode + sizeof(struct acpi_table_header),
+  dsdt->length - sizeof(struct acpi_table_header));
+   acpi_inc(ctx, dsdt->length - sizeof(struct acpi_table_header));
+
+   /* (Re)calculate length and checksum. */
+   dsdt->length = ctx->current - (void *)dsdt;
+   dsdt->checksum = 0;
+   dsdt->checksum = table_compute_checksum(dsdt, dsdt->length);
+   }
+   acpi_align(ctx);
 
/* Pack GNVS into the ACPI table area */
for (i = 0; i < dsdt->length; i++) {
-- 
2.25.1.481.gfbce0eb801-goog



[PATCH v2 35/39] acpi: Record the items added to SSDT

2020-03-08 Thread Simon Glass
It is useful to be able to control the order of data written to the SSDT
so that we can compare the output against known-good kernel dumps.

Add code to record each item that is added along with the device that
added it. That allows us to reorder things later if needed.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Generalise the ACPI function recursion with acpi_recurse_method()

 drivers/core/acpi.c | 83 ++---
 1 file changed, 79 insertions(+), 4 deletions(-)

diff --git a/drivers/core/acpi.c b/drivers/core/acpi.c
index d2f6a9a9d1..7b295bf921 100644
--- a/drivers/core/acpi.c
+++ b/drivers/core/acpi.c
@@ -9,11 +9,20 @@
 #define LOG_CATEOGRY   LOGC_ACPI
 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 
+#define MAX_ITEMS  100
+
+/* Type of table that we collected */
+enum gen_type_t {
+   TYPE_NONE,
+   TYPE_SSDT,
+};
+
 /* Type of method to call */
 enum method_t {
METHOD_WRITE_TABLES,
@@ -23,6 +32,25 @@ enum method_t {
 /* Prototype for all methods */
 typedef int (*acpi_method)(const struct udevice *dev, struct acpi_ctx *ctx);
 
+/**
+ * struct acpi_item - Holds info about ACPI data generated by a driver method
+ *
+ * @dev: Device that generated this data
+ * @type: Table type it refers to
+ * @buf: Buffer containing the data
+ * @size: Size of the data in bytes
+ */
+struct acpi_item {
+   struct udevice *dev;
+   enum gen_type_t type;
+   char *buf;
+   int size;
+};
+
+/* List of ACPI items collected */
+static struct acpi_item acpi_item[MAX_ITEMS];
+static int item_count;
+
 int acpi_return_name(char *out_name, const char *name)
 {
strcpy(out_name, name);
@@ -41,6 +69,43 @@ int acpi_get_name(const struct udevice *dev, char *out_name)
return -ENOSYS;
 }
 
+/**
+ * acpi_add_item() - Add a new item to the list of data collected
+ *
+ * @ctx: ACPI context
+ * @dev: Device that generated the data
+ * @type: Table type it refers to
+ * @start: The start of the data (the end is obtained from ctx->current)
+ * @return 0 if OK, -ENOSPC if too many items, -ENOMEM if out of memory
+ */
+static int acpi_add_item(struct acpi_ctx *ctx, struct udevice *dev,
+enum gen_type_t type, void *start)
+{
+   struct acpi_item *item;
+   void *end = ctx->current;
+
+   if (item_count == MAX_ITEMS) {
+   log_err("Too many items\n");
+   return log_msg_ret("mem", -ENOSPC);
+   }
+
+   item = &acpi_item[item_count];
+   item->dev = dev;
+   item->type = type;
+   item->size = end - start;
+   if (!item->size)
+   return 0;
+   item->buf = malloc(item->size);
+   if (!item->buf)
+   return log_msg_ret("mem", -ENOMEM);
+   memcpy(item->buf, start, item->size);
+   item_count++;
+   log_debug("* %s: Added type %d, %p, size %x\n", dev->name, type, start,
+ item->size);
+
+   return 0;
+}
+
 acpi_method acpi_get_method(struct udevice *dev, enum method_t method)
 {
struct acpi_ops *aops;
@@ -59,7 +124,7 @@ acpi_method acpi_get_method(struct udevice *dev, enum 
method_t method)
 }
 
 int acpi_recurse_method(struct acpi_ctx *ctx, struct udevice *parent,
-   enum method_t method)
+   enum method_t method, enum gen_type_t type)
 {
struct udevice *dev;
acpi_method func;
@@ -67,6 +132,8 @@ int acpi_recurse_method(struct acpi_ctx *ctx, struct udevice 
*parent,
 
func = acpi_get_method(parent, method);
if (func) {
+   void *start = ctx->current;
+
log_debug("\n- %s %p\n", parent->name, func);
ret = device_ofdata_to_platdata(parent);
if (ret)
@@ -74,9 +141,16 @@ int acpi_recurse_method(struct acpi_ctx *ctx, struct 
udevice *parent,
ret = func(parent, ctx);
if (ret)
return log_msg_ret("func", ret);
+
+   /* Add the item to the internal list */
+   if (type != TYPE_NONE) {
+   ret = acpi_add_item(ctx, parent, type, start);
+   if (ret)
+   return log_msg_ret("add", ret);
+   }
}
device_foreach_child(dev, parent) {
-   ret = acpi_recurse_method(ctx, dev, method);
+   ret = acpi_recurse_method(ctx, dev, method, type);
if (ret)
return log_msg_ret("recurse", ret);
}
@@ -89,7 +163,7 @@ int acpi_fill_ssdt(struct acpi_ctx *ctx)
int ret;
 
log_debug("Writing SSDT tables\n");
-   ret = acpi_recurse_method(ctx, dm_root(), METHOD_FILL_SDDT);
+   ret = acpi_recurse_method(ctx, dm_root(), METHOD_FILL_SDDT, TYPE_SSDT);
log_debug("Writing SSDT finished, err=%d\n", ret);
 
return ret;
@@ -100,7 +174,8 @@ int acpi_write_dev_tables(struct acpi_ctx *ctx)
int ret;
 
l

[PATCH v2 37/39] x86: Allow devices to write an SSDT

2020-03-08 Thread Simon Glass
Call the new core function to write the SSDT. This is made up of fragments
generated by devices that have the fill_ssdt() method.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Move ACPI_TABLE_CREATOR to here

 arch/x86/lib/acpi_table.c | 50 +++
 include/acpi_table.h  |  1 +
 2 files changed, 51 insertions(+)

diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c
index 694e92c158..3b97fe162c 100644
--- a/arch/x86/lib/acpi_table.c
+++ b/arch/x86/lib/acpi_table.c
@@ -7,6 +7,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -344,6 +345,46 @@ static void acpi_create_spcr(struct acpi_spcr *spcr)
header->checksum = table_compute_checksum((void *)spcr, header->length);
 }
 
+static void acpi_ssdt_write_cbtable(struct acpi_ctx *ctx)
+{
+   uintptr_t base;
+   u32 size;
+
+   base = 0;
+   size = 0;
+
+   acpigen_write_device(ctx, "CTBL");
+   acpigen_write_coreboot_hid(ctx, COREBOOT_ACPI_ID_CBTABLE);
+   acpigen_write_name_integer(ctx, "_UID", 0);
+   acpigen_write_sta(ctx, ACPI_STATUS_DEVICE_HIDDEN_ON);
+   acpigen_write_name(ctx, "_CRS");
+   acpigen_write_resourcetemplate_header(ctx);
+   acpigen_write_mem32fixed(ctx, 0, base, size);
+   acpigen_write_resourcetemplate_footer(ctx);
+   acpigen_pop_len(ctx);
+}
+
+void acpi_create_ssdt(struct acpi_ctx *ctx, struct acpi_table_header *ssdt,
+ const char *oem_table_id)
+{
+   memset((void *)ssdt, '\0', sizeof(struct acpi_table_header));
+
+   acpi_fill_header(ssdt, "SSDT");
+   ssdt->revision = acpi_get_table_revision(ACPITAB_SSDT);
+   ssdt->aslc_revision = 1;
+   ssdt->length = sizeof(struct acpi_table_header);
+
+   acpi_inc(ctx, sizeof(struct acpi_table_header));
+
+   /* Write object to declare coreboot tables */
+   acpi_ssdt_write_cbtable(ctx);
+   acpi_fill_ssdt(ctx);
+
+   /* (Re)calculate length and checksum. */
+   ssdt->length = ctx->current - (void *)ssdt;
+   ssdt->checksum = table_compute_checksum((void *)ssdt, ssdt->length);
+}
+
 /*
  * QEMU's version of write_acpi_tables is defined in drivers/misc/qfw.c
  */
@@ -353,6 +394,7 @@ ulong write_acpi_tables(ulong start_addr)
struct acpi_facs *facs;
struct acpi_table_header *dsdt;
struct acpi_fadt *fadt;
+   struct acpi_table_header *ssdt;
struct acpi_mcfg *mcfg;
struct acpi_madt *madt;
struct acpi_csrt *csrt;
@@ -408,6 +450,14 @@ ulong write_acpi_tables(ulong start_addr)
acpi_create_fadt(fadt, facs, dsdt);
acpi_add_table(ctx, fadt);
 
+   debug("ACPI: * SSDT\n");
+   ssdt = (struct acpi_table_header *)ctx->current;
+   acpi_create_ssdt(ctx, ssdt, ACPI_TABLE_CREATOR);
+   if (ssdt->length > sizeof(struct acpi_table_header)) {
+   acpi_inc_align(ctx, ssdt->length);
+   acpi_add_table(ctx, ssdt);
+   }
+
debug("ACPI:* MCFG\n");
mcfg = ctx->current;
acpi_create_mcfg(mcfg);
diff --git a/include/acpi_table.h b/include/acpi_table.h
index 5fd2cef5d1..2a802758aa 100644
--- a/include/acpi_table.h
+++ b/include/acpi_table.h
@@ -17,6 +17,7 @@
 #define OEM_ID "U-BOOT"/* U-Boot */
 #define OEM_TABLE_ID   "U-BOOTBL"  /* U-Boot Table */
 #define ASLC_ID"INTL"  /* Intel ASL Compiler */
+#define ACPI_TABLE_CREATOR OEM_TABLE_ID
 
 #define ACPI_RSDP_REV_ACPI_1_0 0
 #define ACPI_RSDP_REV_ACPI_2_0 2
-- 
2.25.1.481.gfbce0eb801-goog



[PATCH v2 33/39] acpi: Add support for SSDT generation

2020-03-08 Thread Simon Glass
Some devices need to generate code for the Secondary System Descriptor
Table (SSDT). Add a method to handle this.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Switch parameter order of _acpi_fill_ssdt() and make it static

 arch/sandbox/dts/test.dts |  2 ++
 drivers/core/acpi.c   | 14 +
 include/dm/acpi.h | 23 ++
 test/dm/acpi.c| 41 ++-
 4 files changed, 79 insertions(+), 1 deletion(-)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 1204c14b07..fefa3af999 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -208,10 +208,12 @@
 
acpi-test {
compatible = "denx,u-boot-acpi-test";
+   acpi-ssdt-test-data = "ab";
};
 
acpi-test2 {
compatible = "denx,u-boot-acpi-test";
+   acpi-ssdt-test-data = "cd";
};
 
clocks {
diff --git a/drivers/core/acpi.c b/drivers/core/acpi.c
index 10bac38c1d..d2f6a9a9d1 100644
--- a/drivers/core/acpi.c
+++ b/drivers/core/acpi.c
@@ -17,6 +17,7 @@
 /* Type of method to call */
 enum method_t {
METHOD_WRITE_TABLES,
+   METHOD_FILL_SDDT,
 };
 
 /* Prototype for all methods */
@@ -49,6 +50,8 @@ acpi_method acpi_get_method(struct udevice *dev, enum 
method_t method)
switch (method) {
case METHOD_WRITE_TABLES:
return aops->write_tables;
+   case METHOD_FILL_SDDT:
+   return aops->fill_ssdt;
}
}
 
@@ -81,6 +84,17 @@ int acpi_recurse_method(struct acpi_ctx *ctx, struct udevice 
*parent,
return 0;
 }
 
+int acpi_fill_ssdt(struct acpi_ctx *ctx)
+{
+   int ret;
+
+   log_debug("Writing SSDT tables\n");
+   ret = acpi_recurse_method(ctx, dm_root(), METHOD_FILL_SDDT);
+   log_debug("Writing SSDT finished, err=%d\n", ret);
+
+   return ret;
+}
+
 int acpi_write_dev_tables(struct acpi_ctx *ctx)
 {
int ret;
diff --git a/include/dm/acpi.h b/include/dm/acpi.h
index 0f78a506da..c340c21685 100644
--- a/include/dm/acpi.h
+++ b/include/dm/acpi.h
@@ -72,6 +72,19 @@ struct acpi_ops {
 * @return 0 if OK, -ve on error
 */
int (*write_tables)(const struct udevice *dev, struct acpi_ctx *ctx);
+
+   /**
+* fill_ssdt() - Generate SSDT code for a device
+*
+* This is called to create the SSDT code. THe method should write out
+* whatever ACPI code is needed by this device. It will end up in the
+* SSDT table.
+*
+* @dev: Device to write
+* @ctx: ACPI context to use
+* @return 0 if OK, -ve on error
+*/
+   int (*fill_ssdt)(const struct udevice *dev, struct acpi_ctx *ctx);
 };
 
 #define device_get_acpi_ops(dev)   ((dev)->driver->acpi_ops)
@@ -116,6 +129,16 @@ int acpi_return_name(char *out_name, const char *name);
  */
 int acpi_write_dev_tables(struct acpi_ctx *ctx);
 
+/**
+ * acpi_fill_ssdt() - Generate ACPI tables for SSDT
+ *
+ * This is called to create the SSDT code for all devices.
+ *
+ * @ctx: ACPI context to use
+ * @return 0 if OK, -ve on error
+ */
+int acpi_fill_ssdt(struct acpi_ctx *ctx);
+
 #endif /* __ACPI__ */
 
 #endif
diff --git a/test/dm/acpi.c b/test/dm/acpi.c
index feb380b26c..305d8395ff 100644
--- a/test/dm/acpi.c
+++ b/test/dm/acpi.c
@@ -7,6 +7,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -14,7 +15,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -43,9 +43,21 @@ static int testacpi_get_name(const struct udevice *dev, char 
*out_name)
return acpi_return_name(out_name, ACPI_TEST_DEV_NAME);
 }
 
+static int testacpi_fill_ssdt(const struct udevice *dev, struct acpi_ctx *ctx)
+{
+   const char *data;
+
+   data = dev_read_string(dev, "acpi-ssdt-test-data");
+   while (*data)
+   acpigen_emit_byte(ctx, *data++);
+
+   return 0;
+}
+
 struct acpi_ops testacpi_ops = {
.get_name   = testacpi_get_name,
.write_tables   = testacpi_write_tables,
+   .fill_ssdt  = testacpi_fill_ssdt,
 };
 
 static const struct udevice_id testacpi_ids[] = {
@@ -313,3 +325,30 @@ static int dm_test_acpi_cmd_dump(struct unit_test_state 
*uts)
return 0;
 }
 DM_TEST(dm_test_acpi_cmd_dump, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test acpi_fill_ssdt() */
+static int dm_test_acpi_fill_ssdt(struct unit_test_state *uts)
+{
+   struct acpi_ctx ctx;
+   u8 *buf;
+
+   buf = malloc(BUF_SIZE);
+   ut_assertnonnull(buf);
+
+   ctx.current = buf;
+   buf[4] = 'z';   /* sentinal */
+   ut_assertok(acpi_fill_ssdt(&ctx));
+
+   /* These values come from acpi-test's acpi-ssdt-test-data property */
+   ut_asserteq('a', buf[0]);
+   ut_asserteq('b', buf[1]);
+
+   /* These values come from acpi-test2's acpi-ssdt-test-data property */
+   ut_asserteq('c',

[PATCH v2 36/39] acpi: Support ordering SSDT data by device

2020-03-08 Thread Simon Glass
Add a /chosen property to control the order in which the data appears
in the SSDT. This allows matching up U-Boot's output from a dump of the
known-good data obtained from within Linux.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Generalise the ACPI function recursion with acpi_recurse_method()

 arch/sandbox/dts/test.dts   |  5 ++-
 doc/device-tree-bindings/chosen.txt |  9 +
 drivers/core/acpi.c | 62 +
 test/dm/acpi.c  | 17 
 4 files changed, 84 insertions(+), 9 deletions(-)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index fefa3af999..7d55d360f6 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -206,12 +206,12 @@
compatible = "denx,u-boot-devres-test";
};
 
-   acpi-test {
+   acpi_test1: acpi-test {
compatible = "denx,u-boot-acpi-test";
acpi-ssdt-test-data = "ab";
};
 
-   acpi-test2 {
+   acpi_test2: acpi-test2 {
compatible = "denx,u-boot-acpi-test";
acpi-ssdt-test-data = "cd";
};
@@ -829,6 +829,7 @@
setting = "sunrise ohoka";
other-node = "/some-bus/c-test@5";
int-values = <0x1937 72993>;
+   u-boot,acpi-ssdt-order = <&acpi_test2 &acpi_test1>;
chosen-test {
compatible = "denx,u-boot-fdt-test";
reg = <9 1>;
diff --git a/doc/device-tree-bindings/chosen.txt 
b/doc/device-tree-bindings/chosen.txt
index 395c9501e3..d4dfc05847 100644
--- a/doc/device-tree-bindings/chosen.txt
+++ b/doc/device-tree-bindings/chosen.txt
@@ -134,3 +134,12 @@ Example
phandlepart = <&mmc 1>;
};
 };
+
+u-boot,acpi-ssdt-order
+--
+
+This provides the ordering to use when writing device data to the ACPI SSDT
+(Secondary System Descriptor Table). Each cell is a phandle pointer to a device
+node to add. The ACPI information is written in this order.
+
+If the ordering does not include all nodes, an error is generated.
diff --git a/drivers/core/acpi.c b/drivers/core/acpi.c
index 7b295bf921..2f57ff9da2 100644
--- a/drivers/core/acpi.c
+++ b/drivers/core/acpi.c
@@ -106,6 +106,63 @@ static int acpi_add_item(struct acpi_ctx *ctx, struct 
udevice *dev,
return 0;
 }
 
+struct acpi_item *find_item(const char *devname)
+{
+   int i;
+
+   for (i = 0; i < item_count; i++) {
+   struct acpi_item *item = &acpi_item[i];
+
+   if (!strcmp(devname, item->dev->name))
+   return item;
+   }
+
+   return NULL;
+}
+
+static int build_type(struct acpi_ctx *ctx, void *start, enum gen_type_t type)
+{
+   const u32 *order;
+   int size;
+   int count;
+   void *ptr;
+   void *end = ctx->current;
+
+   ptr = start;
+   order = ofnode_read_chosen_prop("u-boot,acpi-ssdt-order", &size);
+   if (!order) {
+   log_warning("Failed to find ordering, leaving as is\n");
+   return 0;
+   }
+
+   count = size / sizeof(u32);
+   while (count--) {
+   struct acpi_item *item;
+   const char *name;
+   ofnode node;
+
+   node = ofnode_get_by_phandle(fdt32_to_cpu(*order++));
+   name = ofnode_get_name(node);
+   item = find_item(name);
+   if (!item) {
+   log_err("Failed to find item '%s'\n", name);
+   return log_msg_ret("find", -ENOENT);
+   }
+   if (item->type == type) {
+   log_debug("   - add %s\n", item->dev->name);
+   memcpy(ptr, item->buf, item->size);
+   ptr += item->size;
+   }
+   }
+
+   if (ptr != end) {
+   log_warning("*** Missing bytes: ptr=%p, end=%p\n", ptr, end);
+   return -ENXIO;
+   }
+
+   return 0;
+}
+
 acpi_method acpi_get_method(struct udevice *dev, enum method_t method)
 {
struct acpi_ops *aops;
@@ -160,11 +217,16 @@ int acpi_recurse_method(struct acpi_ctx *ctx, struct 
udevice *parent,
 
 int acpi_fill_ssdt(struct acpi_ctx *ctx)
 {
+   void *start = ctx->current;
int ret;
 
log_debug("Writing SSDT tables\n");
+   item_count = 0;
ret = acpi_recurse_method(ctx, dm_root(), METHOD_FILL_SDDT, TYPE_SSDT);
log_debug("Writing SSDT finished, err=%d\n", ret);
+   ret = build_type(ctx, start, TYPE_SSDT);
+   if (ret)
+   return log_msg_ret("build", ret);
 
return ret;
 }
diff --git a/test/dm/acpi.c b/test/dm/acpi.c
index 305d8395ff..b0d8d41e49 100644
--- a/test/dm/acpi.c
+++ b/test/dm/acpi.c
@@ -336,16 +336,19 @@ static int dm_test_acpi_fill_ssdt(struct unit_test_state 
*uts)
ut_assertnonnull(buf);
 
ctx.current = buf;
-   buf[4] = 'z';   /* sentinal 

[PATCH v2 34/39] x86: acpi: Move MADT up a bit

2020-03-08 Thread Simon Glass
Put this table before MCFG so that it matches the order that coreboot uses
when passing tables to Linux. This is a cosmetic change since the order of
the tables does not otherwise matter.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 arch/x86/lib/acpi_table.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c
index 83b92e2a4c..694e92c158 100644
--- a/arch/x86/lib/acpi_table.c
+++ b/arch/x86/lib/acpi_table.c
@@ -408,18 +408,18 @@ ulong write_acpi_tables(ulong start_addr)
acpi_create_fadt(fadt, facs, dsdt);
acpi_add_table(ctx, fadt);
 
-   debug("ACPI:* MADT\n");
-   madt = ctx->current;
-   acpi_create_madt(madt);
-   acpi_inc_align(ctx, madt->header.length);
-   acpi_add_table(ctx, madt);
-
debug("ACPI:* MCFG\n");
mcfg = ctx->current;
acpi_create_mcfg(mcfg);
acpi_inc_align(ctx, mcfg->header.length);
acpi_add_table(ctx, mcfg);
 
+   debug("ACPI:* MADT\n");
+   madt = ctx->current;
+   acpi_create_madt(madt);
+   acpi_inc_align(ctx, madt->header.length);
+   acpi_add_table(ctx, madt);
+
debug("ACPI:* CSRT\n");
csrt = ctx->current;
acpi_create_csrt(csrt);
-- 
2.25.1.481.gfbce0eb801-goog



[PATCH v2 29/39] acpi: Add generation code for devices

2020-03-08 Thread Simon Glass
Some devices need to create ACPI tables to communcate their parameters
to Linux. Add support for this.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Drop CID value from i2c struct

 include/acpi_device.h  |  705 ++
 lib/acpi/acpi_device.c | 1094 
 2 files changed, 1799 insertions(+)
 create mode 100644 include/acpi_device.h
 create mode 100644 lib/acpi/acpi_device.c

diff --git a/include/acpi_device.h b/include/acpi_device.h
new file mode 100644
index 00..f97bd075ec
--- /dev/null
+++ b/include/acpi_device.h
@@ -0,0 +1,705 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Generation of tables for particular device types
+ *
+ * Copyright 2019 Google LLC
+ * Mostly taken from coreboot file of the same name
+ */
+
+#ifndef __ACPI_DEVICE_H
+#define __ACPI_DEVICE_H
+
+#include 
+#include 
+#include 
+#include 
+
+struct acpi_ctx;
+struct irq;
+struct gpio_desc;
+struct udevice;
+
+/**
+ * enum acpi_dp_type - types of device property objects
+ *
+ * These refer to the types defined by struct acpi_dp below
+ *
+ * @ACPI_DP_TYPE_UNKNOWN: Unknown / do not use
+ * @ACPI_DP_TYPE_INTEGER: Integer value (u64) in @integer
+ * @ACPI_DP_TYPE_STRING: String value in @string
+ * @ACPI_DP_TYPE_REFERENCE: Reference to another object, with value in @string
+ * @ACPI_DP_TYPE_TABLE: Type for a top-level table which may have children
+ * @ACPI_DP_TYPE_ARRAY: Array of items with first item in @array and following
+ * items linked from that item's @next
+ * @ACPI_DP_TYPE_CHILD: Child object, with siblings in that child's @next
+ */
+enum acpi_dp_type {
+   ACPI_DP_TYPE_UNKNOWN,
+   ACPI_DP_TYPE_INTEGER,
+   ACPI_DP_TYPE_STRING,
+   ACPI_DP_TYPE_REFERENCE,
+   ACPI_DP_TYPE_TABLE,
+   ACPI_DP_TYPE_ARRAY,
+   ACPI_DP_TYPE_CHILD,
+};
+
+/* ACPI descriptor values for common descriptors: SERIAL_BUS means I2C */
+#define ACPI_DESCRIPTOR_LARGE  BIT(7)
+#define ACPI_DESCRIPTOR_INTERRUPT  (ACPI_DESCRIPTOR_LARGE | 9)
+#define ACPI_DESCRIPTOR_GPIO   (ACPI_DESCRIPTOR_LARGE | 12)
+#define ACPI_DESCRIPTOR_SERIAL_BUS (ACPI_DESCRIPTOR_LARGE | 14)
+
+/*
+ * PRP0001 is a special DT namespace link device ID. It provides a means to use
+ * existing DT-compatible device identification in ACPI. When this _HID is used
+ * by an ACPI device, the ACPI subsystem in OS looks up "compatible" property 
in
+ * the device object's _DSD and will use the value of that property to identify
+ * the corresponding device in analogy with the original DT device
+ * identification algorithm.
+ * More details can be found in Linux kernel documentation:
+ * Documentation/acpi/enumeration.txt
+ */
+#define ACPI_DT_NAMESPACE_HID  "PRP0001"
+
+/* Length of a full path to an ACPI device */
+#define ACPI_PATH_MAX  30
+
+/**
+ * acpi_device_name() - Locate and return the ACPI name for this device
+ *
+ * @dev: Device to check
+ * @name: Returns the character name, must be at least ACPI_NAME_MAX long
+ * @return 0 if OK, -ve on error
+ */
+int acpi_device_name(const struct udevice *dev, char *name);
+
+/**
+ * acpi_device_path() - Get the full path to an ACPI device
+ *
+ * This gets the full path in the form .. where  is the root
+ * and  is the device. All parent devices are added to the path.
+ *
+ * @dev: Device to check
+ * @buf: Buffer to place the path in (should be ACPI_PATH_MAX long)
+ * @maxlen: Size of buffer (typically ACPI_PATH_MAX)
+ * @return 0 if OK, -ve on error
+ */
+int acpi_device_path(const struct udevice *dev, char *buf, int maxlen);
+
+/**
+ * acpi_device_scope() - Get the scope of an ACPI device
+ *
+ * This gets the scope which is the full path of the parent device, as per
+ * acpi_device_path().
+ *
+ * @dev: Device to check
+ * @buf: Buffer to place the path in (should be ACPI_PATH_MAX long)
+ * @maxlen: Size of buffer (typically ACPI_PATH_MAX)
+ * @return 0 if OK, -EINVAL if the device has no parent, other -ve on other
+ * error
+ */
+int acpi_device_scope(const struct udevice *dev, char *scope, int maxlen);
+
+/**
+ * acpi_device_status() - Get the status of a device
+ *
+ * This currently just returns ACPI_STATUS_DEVICE_ALL_ON. It does not support
+ * inactive or hidden devices.
+ *
+ * @dev: Device to check
+ * @return device status, as ACPI_STATUS_DEVICE_...
+ */
+int acpi_device_status(const struct udevice *dev);
+
+/** enum acpi_irq_mode - edge/level trigger mode */
+enum acpi_irq_mode {
+   ACPI_IRQ_EDGE_TRIGGERED,
+   ACPI_IRQ_LEVEL_TRIGGERED,
+};
+
+/**
+ * enum acpi_irq_polarity - polarity of interrupt
+ *
+ * @ACPI_IRQ_ACTIVE_LOW - for ACPI_IRQ_EDGE_TRIGGERED this means falling edge
+ * @ACPI_IRQ_ACTIVE_HIGH - for ACPI_IRQ_EDGE_TRIGGERED this means rising edge
+ * @ACPI_IRQ_ACTIVE_BOTH - not meaningful for ACPI_IRQ_EDGE_TRIGGERED
+ */
+enum acpi_irq_polarity {
+   ACPI_IRQ_ACTIVE_LOW,
+   ACPI_IRQ_ACTIVE_HIGH,
+   ACPI_IRQ_ACTIVE_BOTH,
+};
+
+/**
+ * e

[PATCH v2 30/39] acpi: Add functions to generate ACPI code

2020-03-08 Thread Simon Glass
Sometimes we need to generate ACPI code on the fly based on things only
known at run time. Add a new 'acpigen' library to handle this. This code
comes from coreboot and has been modified to support the acpi_ctx struct.

Also add acpi_device.c to the build, since these files are co-dependent.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 include/acpigen.h  |  482 +
 include/dm/acpi.h  |7 +
 include/irq.h  |2 +
 lib/acpi/Makefile  |2 +
 lib/acpi/acpigen.c | 1683 
 5 files changed, 2176 insertions(+)
 create mode 100644 include/acpigen.h
 create mode 100644 lib/acpi/acpigen.c

diff --git a/include/acpigen.h b/include/acpigen.h
new file mode 100644
index 00..08000831b9
--- /dev/null
+++ b/include/acpigen.h
@@ -0,0 +1,482 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Core ACPI (Advanced Configuration and Power Interface) support
+ *
+ * Copyright 2019 Google LLC
+ *
+ * Modified from coreboot file acpigen.h
+ */
+
+#ifndef _ACPIGEN_H
+#define _ACPIGEN_H
+
+#include 
+
+struct acpi_cstate;
+struct acpi_pld;
+struct acpi_gpio;
+struct acpi_tstate;
+
+/* Values that can be returned for ACPI Device _STA method */
+#define ACPI_STATUS_DEVICE_PRESENT BIT(0)
+#define ACPI_STATUS_DEVICE_ENABLED BIT(1)
+#define ACPI_STATUS_DEVICE_SHOW_IN_UI  BIT(2)
+#define ACPI_STATUS_DEVICE_STATE_OKBIT(3)
+
+#define ACPI_STATUS_DEVICE_ALL_OFF 0
+#define ACPI_STATUS_DEVICE_ALL_ON  (ACPI_STATUS_DEVICE_PRESENT |\
+ACPI_STATUS_DEVICE_ENABLED |\
+ACPI_STATUS_DEVICE_SHOW_IN_UI |\
+ACPI_STATUS_DEVICE_STATE_OK)
+#define ACPI_STATUS_DEVICE_HIDDEN_ON   (ACPI_STATUS_DEVICE_PRESENT |\
+ACPI_STATUS_DEVICE_ENABLED |\
+ACPI_STATUS_DEVICE_STATE_OK)
+
+/* ACPI Op/Prefix Codes */
+enum {
+   ZERO_OP = 0x00,
+   ONE_OP  = 0x01,
+   ALIAS_OP= 0x06,
+   NAME_OP = 0x08,
+   BYTE_PREFIX = 0x0A,
+   WORD_PREFIX = 0x0B,
+   DWORD_PREFIX= 0x0C,
+   STRING_PREFIX   = 0x0D,
+   QWORD_PREFIX= 0x0E,
+   SCOPE_OP= 0x10,
+   BUFFER_OP   = 0x11,
+   PACKAGE_OP  = 0x12,
+   VARIABLE_PACKAGE_OP = 0x13,
+   METHOD_OP   = 0x14,
+   EXTERNAL_OP = 0x15,
+   DUAL_NAME_PREFIX= 0x2E,
+   MULTI_NAME_PREFIX   = 0x2F,
+   EXT_OP_PREFIX   = 0x5B,
+
+   MUTEX_OP= 0x01,
+   EVENT_OP= 0x01,
+   SF_RIGHT_OP = 0x10,
+   SF_LEFT_OP  = 0x11,
+   COND_REFOF_OP   = 0x12,
+   CREATEFIELD_OP  = 0x13,
+   LOAD_TABLE_OP   = 0x1f,
+   LOAD_OP = 0x20,
+   STALL_OP= 0x21,
+   SLEEP_OP= 0x22,
+   ACQUIRE_OP  = 0x23,
+   SIGNAL_OP   = 0x24,
+   WAIT_OP = 0x25,
+   RST_OP  = 0x26,
+   RELEASE_OP  = 0x27,
+   FROM_BCD_OP = 0x28,
+   TO_BCD_OP   = 0x29,
+   UNLOAD_OP   = 0x2A,
+   REVISON_OP  = 0x30,
+   DEBUG_OP= 0x31,
+   FATAL_OP= 0x32,
+   TIMER_OP= 0x33,
+   OPREGION_OP = 0x80,
+   FIELD_OP= 0x81,
+   DEVICE_OP   = 0x82,
+   PROCESSOR_OP= 0x83,
+   POWER_RES_OP= 0x84,
+   THERMAL_ZONE_OP = 0x85,
+   INDEX_FIELD_OP  = 0x86,
+   BANK_FIELD_OP   = 0x87,
+   DATA_REGION_OP  = 0x88,
+
+   ROOT_PREFIX = 0x5C,
+   PARENT_PREFIX   = 0x5D,
+   LOCAL0_OP   = 0x60,
+   LOCAL1_OP   = 0x61,
+   LOCAL2_OP   = 0x62,
+   LOCAL3_OP   = 0x63,
+   LOCAL4_OP   = 0x64,
+   LOCAL5_OP   = 0x65,
+   LOCAL6_OP   = 0x66,
+   LOCAL7_OP   = 0x67,
+   ARG0_OP = 0x68,
+   ARG1_OP = 0x69,
+   ARG2_OP = 0x6A,
+   ARG3_OP = 0x6B,
+   ARG4_OP = 0x6C,
+   ARG5_OP = 0x6D,
+   ARG6_OP = 0x6E,
+   STORE_OP= 0x70,
+   REF_OF_OP   = 0x71,
+   ADD_OP  = 0x72,
+   CONCATENATE_OP  = 0x73,
+   SUBTRACT_OP = 0x74,
+   INCREMENT_OP= 0x75,
+   DECREMENT_OP= 0x76,
+   MULTIPLY_OP = 0x77,
+   DIVIDE_OP   = 0x78,
+   SHIFT_LEFT_OP   = 

[PATCH v2 28/39] acpi: Add some tables required by the generation code

2020-03-08 Thread Simon Glass
The code which generates ACPI tables programmatically, add a few ACPI
definitions required by that code.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 include/acpi_table.h | 50 
 1 file changed, 50 insertions(+)

diff --git a/include/acpi_table.h b/include/acpi_table.h
index f500f0d3fe..5fd2cef5d1 100644
--- a/include/acpi_table.h
+++ b/include/acpi_table.h
@@ -28,6 +28,18 @@
 
 struct acpi_ctx;
 
+/*
+ * The assigned ACPI ID for the coreboot project is 'BOOT'
+ * http://www.uefi.org/acpi_id_list
+ */
+#define COREBOOT_ACPI_ID   "BOOT"  /* ACPI ID for coreboot HIDs */
+
+/* List of ACPI HID that use the coreboot ACPI ID */
+enum coreboot_acpi_ids {
+   COREBOOT_ACPI_ID_CBTABLE= 0x, /* BOOT */
+   COREBOOT_ACPI_ID_MAX= 0x, /* BOOT */
+};
+
 /*
  * RSDP (Root System Description Pointer)
  * Note: ACPI 1.0 didn't have length, xsdt_address, and ext_checksum
@@ -365,6 +377,44 @@ struct acpi_csrt_shared_info {
u32 max_block_size;
 };
 
+struct __packed acpi_cstate {
+   u8  ctype;
+   u16 latency;
+   u32 power;
+   struct acpi_gen_regaddr resource;
+};
+
+struct __packed acpi_tstate {
+   u32 percent;
+   u32 power;
+   u32 latency;
+   u32 control;
+   u32 status;
+};
+
+/* Port types for ACPI _UPC object */
+enum acpi_upc_type {
+   UPC_TYPE_A,
+   UPC_TYPE_MINI_AB,
+   UPC_TYPE_EXPRESSCARD,
+   UPC_TYPE_USB3_A,
+   UPC_TYPE_USB3_B,
+   UPC_TYPE_USB3_MICRO_B,
+   UPC_TYPE_USB3_MICRO_AB,
+   UPC_TYPE_USB3_POWER_B,
+   UPC_TYPE_C_USB2_ONLY,
+   UPC_TYPE_C_USB2_SS_SWITCH,
+   UPC_TYPE_C_USB2_SS,
+   UPC_TYPE_PROPRIETARY = 0xff,
+   /*
+* The following types are not directly defined in the ACPI
+* spec but are used by coreboot to identify a USB device type.
+*/
+   UPC_TYPE_INTERNAL = 0xff,
+   UPC_TYPE_UNUSED,
+   UPC_TYPE_HUB
+};
+
 enum dmar_type {
DMAR_DRHD = 0,
DMAR_RMRR = 1,
-- 
2.25.1.481.gfbce0eb801-goog



[PATCH v2 26/39] acpi: Move the xsdt pointer to acpi_ctx

2020-03-08 Thread Simon Glass
Put this in the context along with the other important pointers.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 include/dm/acpi.h |  2 ++
 lib/acpi/acpi_table.c | 38 --
 test/dm/acpi.c|  5 +
 3 files changed, 23 insertions(+), 22 deletions(-)

diff --git a/include/dm/acpi.h b/include/dm/acpi.h
index 4465e62848..f3e9d73b78 100644
--- a/include/dm/acpi.h
+++ b/include/dm/acpi.h
@@ -33,11 +33,13 @@
  * @rsdp: Pointer to the Root System Description Pointer, typically used when
  * adding a new table. The RSDP holds pointers to the RSDP and XSDT.
  * @rsdt: Pointer to the Root System Description Table
+ * @xsdt: Pointer to the Extended System Description Table
  */
 struct acpi_ctx {
void *current;
struct acpi_rsdp *rsdp;
struct acpi_rsdt *rsdt;
+   struct acpi_xsdt *xsdt;
 };
 
 /**
diff --git a/lib/acpi/acpi_table.c b/lib/acpi/acpi_table.c
index 9f452a65ce..be52b3ac8e 100644
--- a/lib/acpi/acpi_table.c
+++ b/lib/acpi/acpi_table.c
@@ -127,13 +127,11 @@ int acpi_add_table(struct acpi_ctx *ctx, void *table)
 {
int i, entries_num;
struct acpi_rsdt *rsdt;
-   struct acpi_xsdt *xsdt = NULL;
+   struct acpi_xsdt *xsdt;
 
/* The RSDT is mandatory while the XSDT is not */
rsdt = ctx->rsdt;
-
-   if (ctx->rsdp->xsdt_address)
-   xsdt = map_sysmem(ctx->rsdp->xsdt_address, 0);
+   xsdt = ctx->xsdt;
 
/* This should always be MAX_ACPI_TABLES */
entries_num = ARRAY_SIZE(rsdt->entry);
@@ -164,19 +162,17 @@ int acpi_add_table(struct acpi_ctx *ctx, void *table)
 * And now the same thing for the XSDT. We use the same index as for
 * now we want the XSDT and RSDT to always be in sync in U-Boot
 */
-   if (xsdt) {
-   /* Add table to the XSDT */
-   xsdt->entry[i] = map_to_sysmem(table);
-
-   /* Fix XSDT length */
-   xsdt->header.length = sizeof(struct acpi_table_header) +
-   (sizeof(u64) * (i + 1));
-
-   /* Re-calculate checksum */
-   xsdt->header.checksum = 0;
-   xsdt->header.checksum =
-   table_compute_checksum(xsdt, xsdt->header.length);
-   }
+   /* Add table to the XSDT */
+   xsdt->entry[i] = map_to_sysmem(table);
+
+   /* Fix XSDT length */
+   xsdt->header.length = sizeof(struct acpi_table_header) +
+   (sizeof(u64) * (i + 1));
+
+   /* Re-calculate checksum */
+   xsdt->header.checksum = 0;
+   xsdt->header.checksum = table_compute_checksum(xsdt,
+  xsdt->header.length);
 
return 0;
 }
@@ -235,8 +231,6 @@ static void acpi_write_xsdt(struct acpi_xsdt *xsdt)
 
 void acpi_setup_base_tables(struct acpi_ctx *ctx, void *start)
 {
-   struct acpi_xsdt *xsdt;
-
ctx->current = start;
 
/* Align ACPI tables to 16 byte */
@@ -247,7 +241,7 @@ void acpi_setup_base_tables(struct acpi_ctx *ctx, void 
*start)
acpi_inc_align(ctx, sizeof(struct acpi_rsdp));
ctx->rsdt = ctx->current;
acpi_inc_align(ctx, sizeof(struct acpi_rsdt));
-   xsdt = ctx->current;
+   ctx->xsdt = ctx->current;
acpi_inc_align(ctx, sizeof(struct acpi_xsdt));
/*
 * Per ACPI spec, the FACS table address must be aligned to a 64 byte
@@ -258,7 +252,7 @@ void acpi_setup_base_tables(struct acpi_ctx *ctx, void 
*start)
/* clear all table memory */
memset((void *)start, '\0', ctx->current - start);
 
-   acpi_write_rsdp(ctx->rsdp, ctx->rsdt, xsdt);
+   acpi_write_rsdp(ctx->rsdp, ctx->rsdt, ctx->xsdt);
acpi_write_rsdt(ctx->rsdt);
-   acpi_write_xsdt(xsdt);
+   acpi_write_xsdt(ctx->xsdt);
 }
diff --git a/test/dm/acpi.c b/test/dm/acpi.c
index bb66c7229c..a60f67e73d 100644
--- a/test/dm/acpi.c
+++ b/test/dm/acpi.c
@@ -161,6 +161,10 @@ static int dm_test_acpi_write_tables(struct 
unit_test_state *uts)
ut_asserteq(map_to_sysmem(dmar + 1), ctx.rsdt->entry[1]);
ut_asserteq(0, ctx.rsdt->entry[2]);
 
+   ut_asserteq(map_to_sysmem(dmar), ctx.xsdt->entry[0]);
+   ut_asserteq(map_to_sysmem(dmar + 1), ctx.xsdt->entry[1]);
+   ut_asserteq(0, ctx.xsdt->entry[2]);
+
return 0;
 }
 DM_TEST(dm_test_acpi_write_tables, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
@@ -221,6 +225,7 @@ static int dm_test_acpi_setup_base_tables(struct 
unit_test_state *uts)
ut_assertok(table_compute_checksum(rsdt, sizeof(*rsdt)));
 
xsdt = PTR_ALIGN((void *)rsdt + sizeof(*rsdt), 16);
+   ut_asserteq_ptr(xsdt, ctx.xsdt);
ut_assertok(memcmp("XSDT", xsdt->header.signature, ACPI_NAME_LEN));
ut_asserteq(sizeof(*xsdt), xsdt->header.length);
ut_assertok(table_compute_checksum(xsdt, sizeof(*xsdt)));
-- 
2.25.1.481.gfbce0eb801-goog



[PATCH v2 32/39] irq: Add a method to convert an interrupt to ACPI

2020-03-08 Thread Simon Glass
When generating ACPI tables we need to convert IRQs in U-Boot to the ACPI
structures required by ACPI. This is a SoC-specific conversion and cannot
be handled by generic code, so add a new IRQ method to do the conversion.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 drivers/misc/irq-uclass.c | 18 +++-
 include/acpi_device.h | 27 +++
 include/irq.h | 41 +
 lib/acpi/acpi_device.c| 94 +++
 4 files changed, 178 insertions(+), 2 deletions(-)

diff --git a/drivers/misc/irq-uclass.c b/drivers/misc/irq-uclass.c
index 61aa10e465..b4a8b7b429 100644
--- a/drivers/misc/irq-uclass.c
+++ b/drivers/misc/irq-uclass.c
@@ -153,8 +153,6 @@ int irq_request(struct udevice *dev, struct irq *irq)
const struct irq_ops *ops;
 
log_debug("(dev=%p, irq=%p)\n", dev, irq);
-   if (!irq)
-   return 0;
ops = irq_get_ops(dev);
 
irq->dev = dev;
@@ -176,6 +174,22 @@ int irq_first_device_type(enum irq_dev_t type, struct 
udevice **devp)
return 0;
 }
 
+#if CONFIG_IS_ENABLED(ACPIGEN)
+int irq_get_acpi(const struct irq *irq, struct acpi_irq *acpi_irq)
+{
+   struct irq_ops *ops;
+
+   if (!irq_is_valid(irq))
+   return -EINVAL;
+
+   ops = irq_get_ops(irq->dev);
+   if (!ops->get_acpi)
+   return -ENOSYS;
+
+   return ops->get_acpi(irq, acpi_irq);
+}
+#endif
+
 UCLASS_DRIVER(irq) = {
.id = UCLASS_IRQ,
.name   = "irq",
diff --git a/include/acpi_device.h b/include/acpi_device.h
index acd26c0f54..50ba9b66aa 100644
--- a/include/acpi_device.h
+++ b/include/acpi_device.h
@@ -545,6 +545,33 @@ int acpi_dp_write(struct acpi_ctx *ctx, struct acpi_dp 
*table);
 int acpi_device_write_gpio_desc(struct acpi_ctx *ctx,
const struct gpio_desc *desc);
 
+/**
+ * acpi_device_write_interrupt_irq() - Write an interrupt to ACPI
+ *
+ * This creates an interrupt descriptor for an interrupt, including information
+ * ACPI needs to use it.
+ *
+ * @req_irq: Interrupt to write
+ * @return 0 if OK, -ve on error
+ */
+int acpi_device_write_interrupt_irq(struct acpi_ctx *ctx,
+   const struct irq *req_irq);
+
+/**
+ * acpi_device_write_interrupt_or_gpio() - Write interrupt or GPIO to ACPI
+ *
+ * This reads the an interrupt from the device tree, if available. If not it
+ * reads the first GPIO with the name @prop.
+ *
+ * If an interrupt is found, that is written to ACPI. If not, but an GPIO is
+ * found, that is written.
+ *
+ * @return 0 if OK, -ve if neither an interrupt nor a GPIO could be found, or
+ * some other error occurred
+ */
+int acpi_device_write_interrupt_or_gpio(struct acpi_ctx *ctx,
+   struct udevice *dev, const char *prop);
+
 /**
  * acpi_device_write_i2c_dev() - Write an I2C device to ACPI, including
  * information ACPI needs to use it.
diff --git a/include/irq.h b/include/irq.h
index d4948e6dc4..8527e4dd79 100644
--- a/include/irq.h
+++ b/include/irq.h
@@ -8,6 +8,7 @@
 #ifndef __irq_H
 #define __irq_H
 
+struct acpi_irq;
 struct ofnode_phandle_args;
 
 /*
@@ -26,10 +27,12 @@ enum irq_dev_t {
  *
  * @dev: IRQ device that handles this irq
  * @id: ID to identify this irq with the device
+ * @flags: Flags associated with this interrupt (IRQ_TYPE_...)
  */
 struct irq {
struct udevice *dev;
ulong id;
+   ulong flags;
 };
 
 /**
@@ -121,10 +124,36 @@ struct irq_ops {
 * @return 0 if OK, or a negative error code.
 */
int (*free)(struct irq *irq);
+
+#if CONFIG_IS_ENABLED(ACPIGEN)
+   /**
+* get_acpi() - Get the ACPI info for an irq
+*
+* This converts a irq to an ACPI structure for adding to the ACPI
+* tables.
+*
+* @irq:irq to convert
+* @acpi_irq:   Output ACPI interrupt information
+* @return ACPI pin number or -ve on error
+*/
+   int (*get_acpi)(const struct irq *irq, struct acpi_irq *acpi_irq);
+#endif
 };
 
 #define irq_get_ops(dev)   ((struct irq_ops *)(dev)->driver->ops)
 
+/**
+ * irq_is_valid() - Check if an IRQ is valid
+ *
+ * @irq:   IRQ description containing device and ID, e.g. previously
+ * returned by irq_get_by_index()
+ * @return true if valid, false if not
+ */
+static inline bool irq_is_valid(const struct irq *irq)
+{
+   return irq->dev != NULL;
+}
+
 /**
  * irq_route_pmc_gpio_gpe() - Get the GPIO for an event
  *
@@ -225,4 +254,16 @@ int irq_free(struct irq *irq);
  */
 int irq_first_device_type(enum irq_dev_t type, struct udevice **devp);
 
+/**
+ * irq_get_acpi() - Get the ACPI info for an irq
+ *
+ * This converts a irq to an ACPI structure for adding to the ACPI
+ * tables.
+ *
+ * @irq:   irq to convert
+ * @acpi_irq:  Output ACPI interrupt information
+ * @return ACPI pin number or -ve on error
+ */
+int irq_get_acpi(const struct irq *ir

[PATCH v2 25/39] acpi: Put table-setup code in its own function

2020-03-08 Thread Simon Glass
We always write three basic tables to ACPI at the start. Move this into
its own function, along with acpi_fill_header(), so we can write a test
for this code.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 arch/x86/lib/acpi_table.c | 77 +--
 include/acpi_table.h  | 10 +
 lib/acpi/acpi_table.c | 86 ++-
 test/dm/acpi.c| 55 -
 4 files changed, 148 insertions(+), 80 deletions(-)

diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c
index 9168119547..83b92e2a4c 100644
--- a/arch/x86/lib/acpi_table.c
+++ b/arch/x86/lib/acpi_table.c
@@ -31,58 +31,6 @@ extern const unsigned char AmlCode[];
 /* ACPI RSDP address to be used in boot parameters */
 static ulong acpi_rsdp_addr;
 
-static void acpi_write_rsdp(struct acpi_rsdp *rsdp, struct acpi_rsdt *rsdt,
-   struct acpi_xsdt *xsdt)
-{
-   memset(rsdp, 0, sizeof(struct acpi_rsdp));
-
-   memcpy(rsdp->signature, RSDP_SIG, 8);
-   memcpy(rsdp->oem_id, OEM_ID, 6);
-
-   rsdp->length = sizeof(struct acpi_rsdp);
-   rsdp->rsdt_address = (u32)rsdt;
-
-   rsdp->xsdt_address = (u64)(u32)xsdt;
-   rsdp->revision = ACPI_RSDP_REV_ACPI_2_0;
-
-   /* Calculate checksums */
-   rsdp->checksum = table_compute_checksum((void *)rsdp, 20);
-   rsdp->ext_checksum = table_compute_checksum((void *)rsdp,
-   sizeof(struct acpi_rsdp));
-}
-
-static void acpi_write_rsdt(struct acpi_rsdt *rsdt)
-{
-   struct acpi_table_header *header = &(rsdt->header);
-
-   /* Fill out header fields */
-   acpi_fill_header(header, "RSDT");
-   header->length = sizeof(struct acpi_rsdt);
-   header->revision = 1;
-
-   /* Entries are filled in later, we come with an empty set */
-
-   /* Fix checksum */
-   header->checksum = table_compute_checksum((void *)rsdt,
-   sizeof(struct acpi_rsdt));
-}
-
-static void acpi_write_xsdt(struct acpi_xsdt *xsdt)
-{
-   struct acpi_table_header *header = &(xsdt->header);
-
-   /* Fill out header fields */
-   acpi_fill_header(header, "XSDT");
-   header->length = sizeof(struct acpi_xsdt);
-   header->revision = 1;
-
-   /* Entries are filled in later, we come with an empty set */
-
-   /* Fix checksum */
-   header->checksum = table_compute_checksum((void *)xsdt,
-   sizeof(struct acpi_xsdt));
-}
-
 static void acpi_create_facs(struct acpi_facs *facs)
 {
memset((void *)facs, 0, sizeof(struct acpi_facs));
@@ -402,7 +350,6 @@ static void acpi_create_spcr(struct acpi_spcr *spcr)
 ulong write_acpi_tables(ulong start_addr)
 {
struct acpi_ctx sctx, *ctx = &sctx;
-   struct acpi_xsdt *xsdt;
struct acpi_facs *facs;
struct acpi_table_header *dsdt;
struct acpi_fadt *fadt;
@@ -415,32 +362,10 @@ ulong write_acpi_tables(ulong start_addr)
int i;
 
start = map_sysmem(start_addr, 0);
-   ctx->current = start;
-
-   /* Align ACPI tables to 16 byte */
-   acpi_align(ctx);
 
debug("ACPI: Writing ACPI tables at %lx\n", start_addr);
 
-   /* We need at least an RSDP and an RSDT Table */
-   ctx->rsdp = ctx->current;
-   acpi_inc_align(ctx, sizeof(struct acpi_rsdp));
-   ctx->rsdt = ctx->current;
-   acpi_inc_align(ctx, sizeof(struct acpi_rsdt));
-   xsdt = ctx->current;
-   acpi_inc_align(ctx, sizeof(struct acpi_xsdt));
-   /*
-* Per ACPI spec, the FACS table address must be aligned to a 64 byte
-* boundary (Windows checks this, but Linux does not).
-*/
-   acpi_align_large(ctx);
-
-   /* clear all table memory */
-   memset((void *)start, 0, ctx->current - start);
-
-   acpi_write_rsdp(ctx->rsdp, ctx->rsdt, xsdt);
-   acpi_write_rsdt(ctx->rsdt);
-   acpi_write_xsdt(xsdt);
+   acpi_setup_base_tables(ctx, start);
 
debug("ACPI:* FACS\n");
facs = ctx->current;
diff --git a/include/acpi_table.h b/include/acpi_table.h
index 2131484880..f500f0d3fe 100644
--- a/include/acpi_table.h
+++ b/include/acpi_table.h
@@ -564,6 +564,16 @@ void acpi_inc_align(struct acpi_ctx *ctx, uint amount);
  */
 int acpi_add_table(struct acpi_ctx *ctx, void *table);
 
+/**
+ * acpi_setup_base_tables() - Set up context along with RSDP, RSDT and XDST
+ *
+ * Set up the context with the given start position. Some basic tables are
+ * always needed, so set them up as well.
+ *
+ * @ctx: Context to set up
+ */
+void acpi_setup_base_tables(struct acpi_ctx *ctx, void *start);
+
 #endif /* !__ACPI__*/
 
 #include 
diff --git a/lib/acpi/acpi_table.c b/lib/acpi/acpi_table.c
index 00e80ac39a..9f452a65ce 100644
--- a/lib/acpi/acpi_table.c
+++ b/lib/acpi/acpi_table.c
@@ -157,7 +157,7 @@ int acpi_add_table(struct acpi_ctx *ctx, void *table)
 
/* Re-calculate checksum */
rsdt->header.checksum = 0;
-   rsdt->header.che

[PATCH v2 31/39] gpio: Add a method to convert a GPIO to ACPI

2020-03-08 Thread Simon Glass
When generating ACPI tables we need to convert GPIOs in U-Boot to the ACPI
structures required by ACPI. This is a SoC-specific conversion and cannot
be handled by generic code, so add a new GPIO method to do the conversion.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 drivers/gpio/gpio-uclass.c | 21 +
 include/acpi_device.h  | 12 
 include/asm-generic/gpio.h | 27 +++
 lib/acpi/acpi_device.c | 16 
 4 files changed, 76 insertions(+)

diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index 0a22441d38..7bd656ad63 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -4,6 +4,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -697,6 +698,26 @@ int gpio_get_status(struct udevice *dev, int offset, char 
*buf, int buffsize)
return 0;
 }
 
+#if CONFIG_IS_ENABLED(ACPIGEN)
+int gpio_get_acpi(const struct gpio_desc *desc, struct acpi_gpio *gpio)
+{
+   struct dm_gpio_ops *ops;
+
+   if (!dm_gpio_is_valid(desc)) {
+   /* Indicate that the GPIO is not valid */
+   gpio->pin_count = 0;
+   gpio->pins[0] = 0;
+   return -EINVAL;
+   }
+
+   ops = gpio_get_ops(desc->dev);
+   if (!ops->get_acpi)
+   return -ENOSYS;
+
+   return ops->get_acpi(desc, gpio);
+}
+#endif
+
 int gpio_claim_vector(const int *gpio_num_array, const char *fmt)
 {
int i, ret;
diff --git a/include/acpi_device.h b/include/acpi_device.h
index f97bd075ec..acd26c0f54 100644
--- a/include/acpi_device.h
+++ b/include/acpi_device.h
@@ -533,6 +533,18 @@ size_t acpi_dp_add_property_list(struct acpi_dp *dp,
  */
 int acpi_dp_write(struct acpi_ctx *ctx, struct acpi_dp *table);
 
+/**
+ * acpi_device_write_gpio_desc() - Write a GPIO to ACPI
+ *
+ * This creates a GPIO descriptor for a GPIO, including information ACPI needs
+ * to use it. The type is always ACPI_GPIO_TYPE_IO.
+ *
+ * @desc: GPIO to write
+ * @return 0 if OK, -ve on error
+ */
+int acpi_device_write_gpio_desc(struct acpi_ctx *ctx,
+   const struct gpio_desc *desc);
+
 /**
  * acpi_device_write_i2c_dev() - Write an I2C device to ACPI, including
  * information ACPI needs to use it.
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index 05777e6afe..b594a273fa 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -9,6 +9,7 @@
 
 #include 
 
+struct acpi_gpio;
 struct ofnode_phandle_args;
 
 /*
@@ -290,6 +291,20 @@ struct dm_gpio_ops {
 */
int (*xlate)(struct udevice *dev, struct gpio_desc *desc,
 struct ofnode_phandle_args *args);
+
+#if CONFIG_IS_ENABLED(ACPIGEN)
+   /**
+* get_acpi() - Get the ACPI info for a GPIO
+*
+* This converts a GPIO to an ACPI structure for adding to the ACPI
+* tables.
+*
+* @desc:   GPIO description to convert
+* @gpio:   Output ACPI GPIO information
+* @return ACPI pin number or -ve on error
+*/
+   int (*get_acpi)(const struct gpio_desc *desc, struct acpi_gpio *gpio);
+#endif
 };
 
 /**
@@ -657,4 +672,16 @@ int dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong 
flags);
  */
 int gpio_get_number(const struct gpio_desc *desc);
 
+/**
+ * gpio_get_acpi() - Get the ACPI pin for a GPIO
+ *
+ * This converts a GPIO to an ACPI pin number for adding to the ACPI
+ * tables. If the GPIO is invalid, the pin_count and pins[0] are set to 0
+ *
+ * @desc:  GPIO description to convert
+ * @gpio:  Output ACPI GPIO information
+ * @return ACPI pin number or -ve on error
+ */
+int gpio_get_acpi(const struct gpio_desc *desc, struct acpi_gpio *gpio);
+
 #endif /* _ASM_GENERIC_GPIO_H_ */
diff --git a/lib/acpi/acpi_device.c b/lib/acpi/acpi_device.c
index 145de90677..adc32f1216 100644
--- a/lib/acpi/acpi_device.c
+++ b/lib/acpi/acpi_device.c
@@ -288,6 +288,22 @@ int acpi_device_write_gpio(struct acpi_ctx *ctx, const 
struct acpi_gpio *gpio)
return 0;
 }
 
+int acpi_device_write_gpio_desc(struct acpi_ctx *ctx,
+   const struct gpio_desc *desc)
+{
+   struct acpi_gpio gpio;
+   int ret;
+
+   ret = gpio_get_acpi(desc, &gpio);
+   if (ret)
+   return log_msg_ret("desc", ret);
+   ret = acpi_device_write_gpio(ctx, &gpio);
+   if (ret)
+   return log_msg_ret("gpio", ret);
+
+   return 0;
+}
+
 /* ACPI 6.1 section 6.4.3.8.2.1 - I2cSerialBus() */
 static void acpi_device_write_i2c(struct acpi_ctx *ctx,
  const struct acpi_i2c *i2c)
-- 
2.25.1.481.gfbce0eb801-goog



[PATCH v2 27/39] acpi: Add an acpi command

2020-03-08 Thread Simon Glass
It is useful to dump ACPI tables in U-Boot to see what has been generated.
Add a command to handle this.

To allow the command to find the tables, add a position into the global
data.

Support subcommands to list and dump the tables.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 arch/sandbox/include/asm/global_data.h |   1 +
 arch/x86/include/asm/global_data.h |   1 +
 cmd/Kconfig|  14 ++
 cmd/Makefile   |   1 +
 cmd/acpi.c | 179 +
 lib/acpi/acpi_table.c  |   1 +
 test/dm/acpi.c |  73 ++
 7 files changed, 270 insertions(+)
 create mode 100644 cmd/acpi.c

diff --git a/arch/sandbox/include/asm/global_data.h 
b/arch/sandbox/include/asm/global_data.h
index f4ce72d566..f95ddb058a 100644
--- a/arch/sandbox/include/asm/global_data.h
+++ b/arch/sandbox/include/asm/global_data.h
@@ -13,6 +13,7 @@
 struct arch_global_data {
uint8_t *ram_buf;   /* emulated RAM buffer */
void*text_base; /* pointer to base of text region */
+   ulong acpi_start;   /* Start address of ACPI tables */
 };
 
 #include 
diff --git a/arch/x86/include/asm/global_data.h 
b/arch/x86/include/asm/global_data.h
index f4c1839104..4aee2f3e8c 100644
--- a/arch/x86/include/asm/global_data.h
+++ b/arch/x86/include/asm/global_data.h
@@ -123,6 +123,7 @@ struct arch_global_data {
 #ifdef CONFIG_FSP_VERSION2
struct fsp_header *fsp_s_hdr;   /* Pointer to FSP-S header */
 #endif
+   ulong acpi_start;   /* Start address of ACPI tables */
 };
 
 #endif
diff --git a/cmd/Kconfig b/cmd/Kconfig
index 6403bc45a5..2d3bfe0ab9 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -190,6 +190,20 @@ comment "Commands"
 
 menu "Info commands"
 
+config CMD_ACPI
+   bool "acpi"
+   default y if ACPIGEN
+   help
+ List and dump ACPI tables. ACPI (Advanced Configuration and Power
+ Interface) is used mostly on x86 for providing information to the
+ Operating System about devices in the system. The tables are set up
+ by the firmware, typically U-Boot but possibly an earlier firmware
+ module, if U-Boot is chain-loaded from something else. ACPI tables
+ can also include code, to perform hardware-specific tasks required
+ by the Operating Systems. This allows some amount of separation
+ between the firmware and OS, and is particularly useful when you
+ want to make hardware changes without the OS needing to be adjusted.
+
 config CMD_BDI
bool "bdinfo"
default y
diff --git a/cmd/Makefile b/cmd/Makefile
index f1dd513a4b..15a9693ed0 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -11,6 +11,7 @@ obj-y += help.o
 obj-y += version.o
 
 # command
+obj-$(CONFIG_CMD_ACPI) += acpi.o
 obj-$(CONFIG_CMD_AES) += aes.o
 obj-$(CONFIG_CMD_AB_SELECT) += ab_select.o
 obj-$(CONFIG_CMD_ADC) += adc.o
diff --git a/cmd/acpi.c b/cmd/acpi.c
new file mode 100644
index 00..b66c26265b
--- /dev/null
+++ b/cmd/acpi.c
@@ -0,0 +1,179 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2019 Google LLC
+ * Written by Simon Glass 
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static void dump_hdr(struct acpi_table_header *hdr)
+{
+   bool has_hdr = memcmp(hdr->signature, "FACS", ACPI_NAME_LEN);
+
+   printf("%.*s %08lx %06x", ACPI_NAME_LEN, hdr->signature,
+  (ulong)map_to_sysmem(hdr), hdr->length);
+   if (has_hdr) {
+   printf(" (v%02d %.6s %.8s %u %.4s %d)\n", hdr->revision,
+  hdr->oem_id, hdr->oem_table_id, hdr->oem_revision,
+  hdr->aslc_id, hdr->aslc_revision);
+   } else {
+   printf("\n");
+   }
+}
+
+/**
+ * find_table() - Look up an ACPI table
+ *
+ * @sig: Signature of table (4 characters, upper case)
+ * @return pointer to table header, or NULL if not found
+ */
+struct acpi_table_header *find_table(const char *sig)
+{
+   struct acpi_rsdp *rsdp;
+   struct acpi_rsdt *rsdt;
+   int len, i, count;
+
+   rsdp = map_sysmem(gd->arch.acpi_start, 0);
+   if (!rsdp)
+   return NULL;
+   rsdt = map_sysmem(rsdp->rsdt_address, 0);
+   len = rsdt->header.length - sizeof(rsdt->header);
+   count = len / sizeof(u32);
+   for (i = 0; i < count; i++) {
+   struct acpi_table_header *hdr;
+
+   hdr = map_sysmem(rsdt->entry[i], 0);
+   if (!memcmp(hdr->signature, sig, ACPI_NAME_LEN))
+   return hdr;
+   if (!memcmp(hdr->signature, "FACP", ACPI_NAME_LEN)) {
+   struct acpi_fadt *fadt = (struct acpi_fadt *)hdr;
+
+   if (!memcmp(sig, "DSDT", ACPI_NAME_LEN) && fadt->dsdt)
+   return map_sysmem(fadt->dsdt, 0);
+   if (!m

[PATCH v2 24/39] acpi: Move acpi_add_table() to generic code

2020-03-08 Thread Simon Glass
Move this code to a generic location so that we can test it with sandbox.
This requires adding a few new fields to acpi_ctx, so drop the local
variables used in the original code.

Also use mapmem to avoid pointer-to-address casts which don't work on
sandbox.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 arch/x86/lib/acpi_table.c | 82 +--
 include/acpi_table.h  |  9 +
 include/dm/acpi.h |  5 +++
 lib/acpi/acpi_table.c | 64 ++
 test/dm/acpi.c|  4 ++
 5 files changed, 92 insertions(+), 72 deletions(-)

diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c
index 0757ac3431..9168119547 100644
--- a/arch/x86/lib/acpi_table.c
+++ b/arch/x86/lib/acpi_table.c
@@ -83,66 +83,6 @@ static void acpi_write_xsdt(struct acpi_xsdt *xsdt)
sizeof(struct acpi_xsdt));
 }
 
-/**
- * Add an ACPI table to the RSDT (and XSDT) structure, recalculate length
- * and checksum.
- */
-static void acpi_add_table(struct acpi_rsdp *rsdp, void *table)
-{
-   int i, entries_num;
-   struct acpi_rsdt *rsdt;
-   struct acpi_xsdt *xsdt = NULL;
-
-   /* The RSDT is mandatory while the XSDT is not */
-   rsdt = (struct acpi_rsdt *)rsdp->rsdt_address;
-
-   if (rsdp->xsdt_address)
-   xsdt = (struct acpi_xsdt *)((u32)rsdp->xsdt_address);
-
-   /* This should always be MAX_ACPI_TABLES */
-   entries_num = ARRAY_SIZE(rsdt->entry);
-
-   for (i = 0; i < entries_num; i++) {
-   if (rsdt->entry[i] == 0)
-   break;
-   }
-
-   if (i >= entries_num) {
-   debug("ACPI: Error: too many tables\n");
-   return;
-   }
-
-   /* Add table to the RSDT */
-   rsdt->entry[i] = (u32)table;
-
-   /* Fix RSDT length or the kernel will assume invalid entries */
-   rsdt->header.length = sizeof(struct acpi_table_header) +
-   (sizeof(u32) * (i + 1));
-
-   /* Re-calculate checksum */
-   rsdt->header.checksum = 0;
-   rsdt->header.checksum = table_compute_checksum((u8 *)rsdt,
-   rsdt->header.length);
-
-   /*
-* And now the same thing for the XSDT. We use the same index as for
-* now we want the XSDT and RSDT to always be in sync in U-Boot
-*/
-   if (xsdt) {
-   /* Add table to the XSDT */
-   xsdt->entry[i] = (u64)(u32)table;
-
-   /* Fix XSDT length */
-   xsdt->header.length = sizeof(struct acpi_table_header) +
-   (sizeof(u64) * (i + 1));
-
-   /* Re-calculate checksum */
-   xsdt->header.checksum = 0;
-   xsdt->header.checksum = table_compute_checksum((u8 *)xsdt,
-   xsdt->header.length);
-   }
-}
-
 static void acpi_create_facs(struct acpi_facs *facs)
 {
memset((void *)facs, 0, sizeof(struct acpi_facs));
@@ -462,8 +402,6 @@ static void acpi_create_spcr(struct acpi_spcr *spcr)
 ulong write_acpi_tables(ulong start_addr)
 {
struct acpi_ctx sctx, *ctx = &sctx;
-   struct acpi_rsdp *rsdp;
-   struct acpi_rsdt *rsdt;
struct acpi_xsdt *xsdt;
struct acpi_facs *facs;
struct acpi_table_header *dsdt;
@@ -485,9 +423,9 @@ ulong write_acpi_tables(ulong start_addr)
debug("ACPI: Writing ACPI tables at %lx\n", start_addr);
 
/* We need at least an RSDP and an RSDT Table */
-   rsdp = ctx->current;
+   ctx->rsdp = ctx->current;
acpi_inc_align(ctx, sizeof(struct acpi_rsdp));
-   rsdt = ctx->current;
+   ctx->rsdt = ctx->current;
acpi_inc_align(ctx, sizeof(struct acpi_rsdt));
xsdt = ctx->current;
acpi_inc_align(ctx, sizeof(struct acpi_xsdt));
@@ -500,8 +438,8 @@ ulong write_acpi_tables(ulong start_addr)
/* clear all table memory */
memset((void *)start, 0, ctx->current - start);
 
-   acpi_write_rsdp(rsdp, rsdt, xsdt);
-   acpi_write_rsdt(rsdt);
+   acpi_write_rsdp(ctx->rsdp, ctx->rsdt, xsdt);
+   acpi_write_rsdt(ctx->rsdt);
acpi_write_xsdt(xsdt);
 
debug("ACPI:* FACS\n");
@@ -543,38 +481,38 @@ ulong write_acpi_tables(ulong start_addr)
fadt = ctx->current;
acpi_inc_align(ctx, sizeof(struct acpi_fadt));
acpi_create_fadt(fadt, facs, dsdt);
-   acpi_add_table(rsdp, fadt);
+   acpi_add_table(ctx, fadt);
 
debug("ACPI:* MADT\n");
madt = ctx->current;
acpi_create_madt(madt);
acpi_inc_align(ctx, madt->header.length);
-   acpi_add_table(rsdp, madt);
+   acpi_add_table(ctx, madt);
 
debug("ACPI:* MCFG\n");
mcfg = ctx->current;
acpi_create_mcfg(mcfg);
acpi_inc_align(ctx, mcfg->header.length);
-   acpi_add_table(rsdp, mcfg);
+   acpi_add_table(ctx, mcfg);
 
debug("ACPI:* CSRT\n");
csrt = ctx->current

[PATCH v2 21/39] acpi: Convert part of acpi_table to use acpi_ctx

2020-03-08 Thread Simon Glass
The current code uses an address but a pointer would result in fewer
casts. Also it repeats the alignment code in a lot of places so this would
be better done in a helper function.

Update write_acpi_tables() to make use of the new acpi_ctx structure,
adding a few helpers to clean things up.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 arch/x86/lib/acpi_table.c | 88 +++
 include/acpi_table.h  | 36 
 lib/acpi/acpi_table.c | 22 ++
 test/dm/acpi.c| 28 +
 4 files changed, 129 insertions(+), 45 deletions(-)

diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c
index 487fef87f2..8e13d6a3e6 100644
--- a/arch/x86/lib/acpi_table.c
+++ b/arch/x86/lib/acpi_table.c
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -19,6 +20,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /*
  * IASL compiles the dsdt entries and writes the hex values
@@ -468,9 +470,9 @@ static void acpi_create_spcr(struct acpi_spcr *spcr)
 /*
  * QEMU's version of write_acpi_tables is defined in drivers/misc/qfw.c
  */
-ulong write_acpi_tables(ulong start)
+ulong write_acpi_tables(ulong start_addr)
 {
-   u32 current;
+   struct acpi_ctx sctx, *ctx = &sctx;
struct acpi_rsdp *rsdp;
struct acpi_rsdt *rsdt;
struct acpi_xsdt *xsdt;
@@ -481,60 +483,61 @@ ulong write_acpi_tables(ulong start)
struct acpi_madt *madt;
struct acpi_csrt *csrt;
struct acpi_spcr *spcr;
+   void *start;
+   ulong addr;
int i;
 
-   current = start;
+   start = map_sysmem(start_addr, 0);
+   ctx->current = start;
 
/* Align ACPI tables to 16 byte */
-   current = ALIGN(current, 16);
+   acpi_align(ctx);
 
-   debug("ACPI: Writing ACPI tables at %lx\n", start);
+   debug("ACPI: Writing ACPI tables at %lx\n", start_addr);
 
/* We need at least an RSDP and an RSDT Table */
-   rsdp = (struct acpi_rsdp *)current;
-   current += sizeof(struct acpi_rsdp);
-   current = ALIGN(current, 16);
-   rsdt = (struct acpi_rsdt *)current;
-   current += sizeof(struct acpi_rsdt);
-   current = ALIGN(current, 16);
-   xsdt = (struct acpi_xsdt *)current;
-   current += sizeof(struct acpi_xsdt);
+   rsdp = ctx->current;
+   acpi_inc_align(ctx, sizeof(struct acpi_rsdp));
+   rsdt = ctx->current;
+   acpi_inc_align(ctx, sizeof(struct acpi_rsdt));
+   xsdt = ctx->current;
+   acpi_inc_align(ctx, sizeof(struct acpi_xsdt));
/*
 * Per ACPI spec, the FACS table address must be aligned to a 64 byte
 * boundary (Windows checks this, but Linux does not).
 */
-   current = ALIGN(current, 64);
+   acpi_align_large(ctx);
 
/* clear all table memory */
-   memset((void *)start, 0, current - start);
+   memset((void *)start, 0, ctx->current - start);
 
acpi_write_rsdp(rsdp, rsdt, xsdt);
acpi_write_rsdt(rsdt);
acpi_write_xsdt(xsdt);
 
debug("ACPI:* FACS\n");
-   facs = (struct acpi_facs *)current;
-   current += sizeof(struct acpi_facs);
-   current = ALIGN(current, 16);
+   facs = ctx->current;
+   acpi_inc_align(ctx, sizeof(struct acpi_facs));
 
acpi_create_facs(facs);
 
debug("ACPI:* DSDT\n");
-   dsdt = (struct acpi_table_header *)current;
+   dsdt = ctx->current;
memcpy(dsdt, &AmlCode, sizeof(struct acpi_table_header));
-   current += sizeof(struct acpi_table_header);
-   memcpy((char *)current,
+   acpi_inc(ctx, sizeof(struct acpi_table_header));
+   memcpy(ctx->current,
   (char *)&AmlCode + sizeof(struct acpi_table_header),
   dsdt->length - sizeof(struct acpi_table_header));
-   current += dsdt->length - sizeof(struct acpi_table_header);
-   current = ALIGN(current, 16);
+   acpi_inc_align(ctx, dsdt->length - sizeof(struct acpi_table_header));
 
/* 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;
+   ulong addr = (ulong)map_to_sysmem(ctx->current);
+
+   debug("Fix up global NVS in DSDT to %#08lx\n", addr);
+   *gnvs = addr;
break;
}
}
@@ -544,51 +547,46 @@ ulong write_acpi_tables(ulong start)
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);
+   acpi_create_gnvs(ctx->current)

[PATCH v2 19/39] acpi: Move acpi_fill_header() to generic code

2020-03-08 Thread Simon Glass
This function needs to be used by sandbox for tests. Move it into the
generic directory.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
---

Changes in v2: None

 arch/x86/lib/acpi_table.c |  9 -
 include/acpi_table.h  | 10 ++
 lib/acpi/acpi_table.c | 10 ++
 test/dm/acpi.c| 28 
 4 files changed, 48 insertions(+), 9 deletions(-)

diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c
index 71913b6f65..487fef87f2 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/include/acpi_table.h b/include/acpi_table.h
index db84b79be5..3fd2ef16b0 100644
--- a/include/acpi_table.h
+++ b/include/acpi_table.h
@@ -509,6 +509,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/lib/acpi/acpi_table.c b/lib/acpi/acpi_table.c
index ed312ac663..a86bfa6187 100644
--- a/lib/acpi/acpi_table.c
+++ b/lib/acpi/acpi_table.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 
 int acpi_create_dmar(struct acpi_dmar *dmar, enum dmar_flags flags)
 {
@@ -84,3 +85,12 @@ int acpi_get_table_revision(enum acpi_tables table)
return -EINVAL;
}
 }
+
+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);
+}
diff --git a/test/dm/acpi.c b/test/dm/acpi.c
index 2737896643..e28ebf4f90 100644
--- a/test/dm/acpi.c
+++ b/test/dm/acpi.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -81,3 +82,30 @@ static int dm_test_acpi_create_dmar(struct unit_test_state 
*uts)
return 0;
 }
 DM_TEST(dm_test_acpi_create_dmar, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test acpi_fill_header() */
+static int dm_test_acpi_fill_header(struct unit_test_state *uts)
+{
+   struct acpi_table_header hdr;
+
+   /* Make sure these 5 fields are not changed */
+   hdr.length = 0x11;
+   hdr.revision = 0x22;
+   hdr.checksum = 0x33;
+   hdr.aslc_revision = 0x44;
+   acpi_fill_header(&hdr, "ABCD");
+
+   ut_assertok(memcmp("ABCD", hdr.signature, sizeof(hdr.signature)));
+   ut_asserteq(0x11, hdr.length);
+   ut_asserteq(0x22, hdr.revision);
+   ut_asserteq(0x33, hdr.checksum);
+   ut_assertok(memcmp(OEM_ID, hdr.oem_id, sizeof(hdr.oem_id)));
+   ut_assertok(memcmp(OEM_TABLE_ID, hdr.oem_table_id,
+  sizeof(hdr.oem_table_id)));
+   ut_asserteq(U_BOOT_BUILD_DATE, hdr.oem_revision);
+   ut_assertok(memcmp(ASLC_ID, hdr.aslc_id, sizeof(hdr.aslc_id)));
+   ut_asserteq(0x44, hdr.aslc_revision);
+
+   return 0;
+}
+DM_TEST(dm_test_acpi_fill_header, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
-- 
2.25.1.481.gfbce0eb801-goog



[PATCH v2 23/39] acpi: Drop code for missing XSDT from acpi_write_rsdp()

2020-03-08 Thread Simon Glass
We don't actually support tables without an XSDT so we can drop this dead
code.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 arch/x86/lib/acpi_table.c | 15 ++-
 1 file changed, 2 insertions(+), 13 deletions(-)

diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c
index 964f10a7cb..0757ac3431 100644
--- a/arch/x86/lib/acpi_table.c
+++ b/arch/x86/lib/acpi_table.c
@@ -42,19 +42,8 @@ static void acpi_write_rsdp(struct acpi_rsdp *rsdp, struct 
acpi_rsdt *rsdt,
rsdp->length = sizeof(struct acpi_rsdp);
rsdp->rsdt_address = (u32)rsdt;
 
-   /*
-* Revision: ACPI 1.0: 0, ACPI 2.0/3.0/4.0: 2
-*
-* Some OSes expect an XSDT to be present for RSD PTR revisions >= 2.
-* If we don't have an ACPI XSDT, force ACPI 1.0 (and thus RSD PTR
-* revision 0)
-*/
-   if (xsdt == NULL) {
-   rsdp->revision = ACPI_RSDP_REV_ACPI_1_0;
-   } else {
-   rsdp->xsdt_address = (u64)(u32)xsdt;
-   rsdp->revision = ACPI_RSDP_REV_ACPI_2_0;
-   }
+   rsdp->xsdt_address = (u64)(u32)xsdt;
+   rsdp->revision = ACPI_RSDP_REV_ACPI_2_0;
 
/* Calculate checksums */
rsdp->checksum = table_compute_checksum((void *)rsdp, 20);
-- 
2.25.1.481.gfbce0eb801-goog



[PATCH v2 22/39] x86: Allow devices to write ACPI tables

2020-03-08 Thread Simon Glass
Call the new core function to permit devices to write their own ACPI
tables. These tables will appear after all other tables.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 arch/x86/lib/acpi_table.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c
index 8e13d6a3e6..964f10a7cb 100644
--- a/arch/x86/lib/acpi_table.c
+++ b/arch/x86/lib/acpi_table.c
@@ -580,6 +580,8 @@ ulong write_acpi_tables(ulong start_addr)
acpi_inc_align(ctx, spcr->header.length);
acpi_add_table(rsdp, spcr);
 
+   acpi_write_dev_tables(ctx);
+
addr = map_to_sysmem(ctx->current);
debug("current = %lx\n", addr);
 
-- 
2.25.1.481.gfbce0eb801-goog



[PATCH v2 20/39] acpi: Add a method to write tables for a device

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

Signed-off-by: Simon Glass 
---

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 +++
 drivers/core/acpi.c   | 61 +++
 include/dm/acpi.h | 30 +++
 test/dm/acpi.c| 43 +++
 4 files changed, 138 insertions(+)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 5fa951ad4b..1204c14b07 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/drivers/core/acpi.c b/drivers/core/acpi.c
index 45542199f5..10bac38c1d 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_return_name(char *out_name, const char *name)
 {
strcpy(out_name, name);
@@ -30,3 +39,55 @@ 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- %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/dm/acpi.h b/include/dm/acpi.h
index 8d6c3fd424..dcfcf5c347 100644
--- a/include/dm/acpi.h
+++ b/include/dm/acpi.h
@@ -24,6 +24,17 @@
 
 #if !defined(__ACPI__)
 
+/**
+ * struct acpi_ctx - Context used for writing ACPI tables
+ *
+ * This contains a few useful pieces of information used when writing
+ *
+ * @current: Current address for writing
+ */
+struct acpi_ctx {
+   void *current;
+};
+
 /**
  * struct acpi_ops - ACPI operations supported by driver model
  */
@@ -38,6 +49,15 @@ struct acpi_ops {
 *  other error
 */
int (*get_name)(const struct udevice *dev, char *out_name);
+
+   /**
+* write_tables() - Write out any tables required by this device
+*
+* @dev: Device to write
+* @ctx: ACPI context to use
+* @return 0 if OK, -ve on error
+*/
+   int (*write_tables)(const struct udevice *dev, struct acpi_ctx *ctx);
 };
 
 #define device_get_acpi_ops(dev)   ((dev)->driver->acpi_ops)
@@ -72,6 +92,16 @@ int acpi_get_name(const struct udevice *dev, char *out_name);
  */
 int acpi_return_name(char *out_name, const char *name);
 
+/**
+ * acpi_write_dev_tables() - Write ACPI tables required by devices
+ *
+ * This scans through all devices and tells them to write any tables they want
+ * to write.
+ *
+ * @return 0 if OK, -ve if any device returned an error
+ */
+int acpi_write_dev_tables(struct acpi_ctx *ctx);
+
 #endif /* __ACPI__ */
 
 #endif
diff --git a/test/dm/acpi.c b/test/dm/acpi.c
index e28ebf4f90..b87fbd16b0 100644
--- a/test/dm/acpi.c
+++ b/test/dm/acpi.c
@@ -15,6 +15,19 @@
 #include 
 
 #define ACPI_TEST_DEV_NAME "ABCD"
+#define BUF_SIZE   4096
+
+static int testacpi_write_tables(const struct udevice *dev,
+struct acpi_ctx *ctx)
+{
+   struct acpi_dmar *dmar;
+
+   dmar = (struct acpi_dmar *)ctx->curre

[PATCH v2 18/39] acpi: Add support for DMAR

2020-03-08 Thread Simon Glass
The DMA Remapping Reporting (DMAR) table contains information about DMA
remapping.

Add a version simple version of this table with only the minimum fields
filled out. i.e. no entries.

Reviewed-by: Bin Meng 
Signed-off-by: Simon Glass 
---

Changes in v2:
- Drop two unnecessary __packed
- Move __packed to after struct

 include/acpi_table.h  | 57 +++
 lib/acpi/acpi_table.c | 26 
 test/dm/acpi.c| 14 +++
 3 files changed, 97 insertions(+)

diff --git a/include/acpi_table.h b/include/acpi_table.h
index ccf6fa04db..db84b79be5 100644
--- a/include/acpi_table.h
+++ b/include/acpi_table.h
@@ -21,6 +21,9 @@
 #define ACPI_RSDP_REV_ACPI_1_0 0
 #define ACPI_RSDP_REV_ACPI_2_0 2
 
+/* TODO(s...@chromium.org): Figure out how to get compiler revision */
+#define ASL_REVISION   0
+
 #if !defined(__ACPI__)
 
 /*
@@ -360,6 +363,51 @@ struct acpi_csrt_shared_info {
u32 max_block_size;
 };
 
+enum dmar_type {
+   DMAR_DRHD = 0,
+   DMAR_RMRR = 1,
+   DMAR_ATSR = 2,
+   DMAR_RHSA = 3,
+   DMAR_ANDD = 4
+};
+
+enum {
+   DRHD_INCLUDE_PCI_ALL = 1
+};
+
+enum dmar_flags {
+   DMAR_INTR_REMAP = 1 << 0,
+   DMAR_X2APIC_OPT_OUT = 1 << 1,
+   DMA_CTRL_PLATFORM_OPT_IN_FLAG   = 1 << 2,
+};
+
+struct dmar_entry {
+   u16 type;
+   u16 length;
+   u8 flags;
+   u8 reserved;
+   u16 segment;
+   u64 bar;
+};
+
+struct dmar_rmrr_entry {
+   u16 type;
+   u16 length;
+   u16 reserved;
+   u16 segment;
+   u64 bar;
+   u64 limit;
+};
+
+/* DMAR (DMA Remapping Reporting Structure) */
+struct __packed acpi_dmar {
+   struct acpi_table_header header;
+   u8 host_address_width;
+   u8 flags;
+   u8 reserved[10];
+   struct dmar_entry structure[0];
+};
+
 /* DBG2 definitions are partially used for SPCR interface_type */
 
 /* Types for port_type field */
@@ -452,6 +500,15 @@ enum acpi_tables {
  */
 int acpi_get_table_revision(enum acpi_tables table);
 
+/**
+ * acpi_create_dmar() - Create a DMA Remapping Reporting (DMAR) table
+ *
+ * @dmar: Place to put the table
+ * @flags: DMAR flags to use
+ * @return 0 if OK, -ve on error
+ */
+int acpi_create_dmar(struct acpi_dmar *dmar, enum dmar_flags flags);
+
 #endif /* !__ACPI__*/
 
 #include 
diff --git a/lib/acpi/acpi_table.c b/lib/acpi/acpi_table.c
index 197f965c08..ed312ac663 100644
--- a/lib/acpi/acpi_table.c
+++ b/lib/acpi/acpi_table.c
@@ -6,7 +6,33 @@
  */
 
 #include 
+#include 
 #include 
+#include 
+
+int acpi_create_dmar(struct acpi_dmar *dmar, enum dmar_flags flags)
+{
+   struct acpi_table_header *header = &dmar->header;
+   struct cpu_info info;
+   struct udevice *cpu;
+   int ret;
+
+   ret = uclass_first_device(UCLASS_CPU, &cpu);
+   if (ret)
+   return log_msg_ret("cpu", ret);
+   ret = cpu_get_info(cpu, &info);
+   memset((void *)dmar, 0, sizeof(struct acpi_dmar));
+
+   /* Fill out header fields. */
+   acpi_fill_header(&dmar->header, "DMAR");
+   header->length = sizeof(struct acpi_dmar);
+   header->revision = acpi_get_table_revision(ACPITAB_DMAR);
+
+   dmar->host_address_width = info.address_width - 1;
+   dmar->flags = flags;
+
+   return 0;
+}
 
 int acpi_get_table_revision(enum acpi_tables table)
 {
diff --git a/test/dm/acpi.c b/test/dm/acpi.c
index e65295b7ca..2737896643 100644
--- a/test/dm/acpi.c
+++ b/test/dm/acpi.c
@@ -67,3 +67,17 @@ static int dm_test_acpi_get_table_revision(struct 
unit_test_state *uts)
 }
 DM_TEST(dm_test_acpi_get_table_revision,
DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test acpi_create_dmar() */
+static int dm_test_acpi_create_dmar(struct unit_test_state *uts)
+{
+   struct acpi_dmar dmar;
+
+   ut_assertok(acpi_create_dmar(&dmar, DMAR_INTR_REMAP));
+   ut_asserteq(DMAR_INTR_REMAP, dmar.flags);
+   ut_asserteq(DMAR_INTR_REMAP, dmar.flags);
+   ut_asserteq(32 - 1, dmar.host_address_width);
+
+   return 0;
+}
+DM_TEST(dm_test_acpi_create_dmar, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
-- 
2.25.1.481.gfbce0eb801-goog



[PATCH v2 13/39] acpi: Add a binding for ACPI settings in the device tree

2020-03-08 Thread Simon Glass
Devices need to report various identifiers in the ACPI tables. Rather than
hard-coding these in drivers it is typically better to put them in the
device tree.

Add a binding file to describe this.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Fix definition of HID
- Infer hid-over-i2c CID value
- Add the hid-over-i2c binding document

 doc/device-tree-bindings/device.txt   | 36 +++
 .../input/hid-over-i2c.txt| 44 +++
 2 files changed, 80 insertions(+)
 create mode 100644 doc/device-tree-bindings/device.txt
 create mode 100644 doc/device-tree-bindings/input/hid-over-i2c.txt

diff --git a/doc/device-tree-bindings/device.txt 
b/doc/device-tree-bindings/device.txt
new file mode 100644
index 00..31ec2fa31b
--- /dev/null
+++ b/doc/device-tree-bindings/device.txt
@@ -0,0 +1,36 @@
+Devices
+===
+
+Device bindings are described by their own individual binding files.
+
+U-Boot provides for some optional properties which are documented here. See
+also hid-over-i2c.txt which describes HID devices.
+
+ - acpi,has-power-resource : (boolean) true if this device has a power 
resource.
+This causes a PRIC (ACPI PowerResource) to be written containing the
+properties provided by this binding, to describe how to handle powering the
+device up and down using GPIOs
+ - acpi,compatible : compatible string to report
+ - acpi,desc : Contains the string to use as the _DDN (DOS (Disk Operating
+System) Device Name)
+ - acpi,hid : Contains the string to use as the HID (Hardware ID)
+identifier _HID
+ - hid-descr-addr : HID register offset (for Human Interface Devices)
+ - acpi,probed : Tells U-Boot to add 'linux,probed' to the ACPI tables so that
+Linux will not re-init the device
+ - acpi,uid : _UID value for device
+
+
+Example
+---
+
+synaptics_touchpad: synaptics-touchpad@2c {
+   compatible = "hid-over-i2c";
+   reg = <0x2c>;
+   acpi,hid = "PNP0C50";
+   acpi,desc = "Synaptics Touchpad";
+   interrupts-extended = <&acpi_gpe GPIO_18_IRQ
+   IRQ_TYPE_EDGE_FALLING>;
+   acpi,probed;
+   hid-descr-addr = <0x20>;
+};
diff --git a/doc/device-tree-bindings/input/hid-over-i2c.txt 
b/doc/device-tree-bindings/input/hid-over-i2c.txt
new file mode 100644
index 00..c76bafaf98
--- /dev/null
+++ b/doc/device-tree-bindings/input/hid-over-i2c.txt
@@ -0,0 +1,44 @@
+* HID over I2C Device-Tree bindings
+
+HID over I2C provides support for various Human Interface Devices over the
+I2C bus. These devices can be for example touchpads, keyboards, touch screens
+or sensors.
+
+The specification has been written by Microsoft and is currently available 
here:
+http://msdn.microsoft.com/en-us/library/windows/hardware/hh852380.aspx
+
+If this binding is used, the kernel module i2c-hid will handle the 
communication
+with the device and the generic hid core layer will handle the protocol.
+
+Required properties:
+- compatible: must be "hid-over-i2c"
+- reg: i2c slave address
+- hid-descr-addr: HID descriptor address
+- interrupts: interrupt line
+
+Additional optional properties:
+
+Some devices may support additional optional properties to help with, e.g.,
+power sequencing. The following properties can be supported by one or more
+device-specific compatible properties, which should be used in addition to the
+"hid-over-i2c" string.
+
+- compatible:
+  * "wacom,w9013" (Wacom W9013 digitizer). Supports:
+- vdd-supply (3.3V)
+- vddl-supply (1.8V)
+- post-power-on-delay-ms
+
+- vdd-supply: phandle of the regulator that provides the supply voltage.
+- post-power-on-delay-ms: time required by the device after enabling its 
regulators
+  or powering it on, before it is ready for communication.
+
+Example:
+
+   i2c-hid-dev@2c {
+   compatible = "hid-over-i2c";
+   reg = <0x2c>;
+   hid-descr-addr = <0x0020>;
+   interrupt-parent = <&gpx3>;
+   interrupts = <3 2>;
+   };
-- 
2.25.1.481.gfbce0eb801-goog



[PATCH v2 14/39] acpi: Add a simple sandbox test

2020-03-08 Thread Simon Glass
Add a sandbox test for the basic ACPI functionality we have so far.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
---

Changes in v2:
- Add in the acpi_table.h header file to this patch

 arch/sandbox/dts/test.dts |  4 ++
 arch/sandbox/include/asm/acpi_table.h |  9 +
 include/dm/uclass-id.h|  1 +
 test/dm/Makefile  |  1 +
 test/dm/acpi.c| 55 +++
 5 files changed, 70 insertions(+)
 create mode 100644 arch/sandbox/include/asm/acpi_table.h
 create mode 100644 test/dm/acpi.c

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 4a277934a7..5fa951ad4b 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -206,6 +206,10 @@
compatible = "denx,u-boot-devres-test";
};
 
+   acpi-test {
+   compatible = "denx,u-boot-acpi-test";
+   };
+
clocks {
clk_fixed: clk-fixed {
compatible = "fixed-clock";
diff --git a/arch/sandbox/include/asm/acpi_table.h 
b/arch/sandbox/include/asm/acpi_table.h
new file mode 100644
index 00..921c7f4201
--- /dev/null
+++ b/arch/sandbox/include/asm/acpi_table.h
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2019 Google LLC
+ */
+
+#ifndef __ASM_ACPI_TABLE_H__
+#define __ASM_ACPI_TABLE_H__
+
+#endif /* __ASM_ACPI_TABLE_H__ */
diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
index 598f65ea7a..37ada51f9f 100644
--- a/include/dm/uclass-id.h
+++ b/include/dm/uclass-id.h
@@ -20,6 +20,7 @@ enum uclass_id {
UCLASS_TEST_PROBE,
UCLASS_TEST_DUMMY,
UCLASS_TEST_DEVRES,
+   UCLASS_TEST_ACPI,
UCLASS_SPI_EMUL,/* sandbox SPI device emulator */
UCLASS_I2C_EMUL,/* sandbox I2C device emulator */
UCLASS_I2C_EMUL_PARENT, /* parent for I2C device emulators */
diff --git a/test/dm/Makefile b/test/dm/Makefile
index dd1ceff86c..3daf8a544e 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -13,6 +13,7 @@ obj-$(CONFIG_UT_DM) += test-uclass.o
 # subsystem you must add sandbox tests here.
 obj-$(CONFIG_UT_DM) += core.o
 ifneq ($(CONFIG_SANDBOX),)
+obj-$(CONFIG_ACPIGEN) += acpi.o
 obj-$(CONFIG_SOUND) += audio.o
 obj-$(CONFIG_BLK) += blk.o
 obj-$(CONFIG_BOARD) += board.o
diff --git a/test/dm/acpi.c b/test/dm/acpi.c
new file mode 100644
index 00..e3519d4689
--- /dev/null
+++ b/test/dm/acpi.c
@@ -0,0 +1,55 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Tests for ACPI table generation
+ *
+ * Copyright 2019 Google LLC
+ * Written by Simon Glass 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define ACPI_TEST_DEV_NAME "ABCD"
+
+static int testacpi_get_name(const struct udevice *dev, char *out_name)
+{
+   return acpi_return_name(out_name, ACPI_TEST_DEV_NAME);
+}
+
+struct acpi_ops testacpi_ops = {
+   .get_name   = testacpi_get_name,
+};
+
+static const struct udevice_id testacpi_ids[] = {
+   { .compatible = "denx,u-boot-acpi-test" },
+   { }
+};
+
+U_BOOT_DRIVER(testacpi_drv) = {
+   .name   = "testacpi_drv",
+   .of_match   = testacpi_ids,
+   .id = UCLASS_TEST_ACPI,
+   acpi_ops_ptr(&testacpi_ops)
+};
+
+UCLASS_DRIVER(testacpi) = {
+   .name   = "testacpi",
+   .id = UCLASS_TEST_ACPI,
+};
+
+/* Test ACPI get_name() */
+static int dm_test_acpi_get_name(struct unit_test_state *uts)
+{
+   char name[ACPI_NAME_MAX];
+   struct udevice *dev;
+
+   ut_assertok(uclass_first_device_err(UCLASS_TEST_ACPI, &dev));
+   ut_assertok(acpi_get_name(dev, name));
+   ut_asserteq_str(ACPI_TEST_DEV_NAME, name);
+
+   return 0;
+}
+DM_TEST(dm_test_acpi_get_name, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
-- 
2.25.1.481.gfbce0eb801-goog



[PATCH v2 15/39] x86: Move acpi_table header to main include/ directory

2020-03-08 Thread Simon Glass
This file is potentially useful to other architectures saddled with ACPI
so move it into a common location.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
---

Changes in v2: None

 arch/x86/cpu/baytrail/acpi.c  |   2 +-
 arch/x86/cpu/cpu.c|   2 +-
 arch/x86/cpu/quark/acpi.c |   2 +-
 arch/x86/cpu/tangier/acpi.c   |   2 +-
 arch/x86/include/asm/acpi_table.h | 376 
 arch/x86/lib/acpi.c   |   2 +-
 arch/x86/lib/acpi_s3.c|   2 +-
 arch/x86/lib/acpi_table.c |   2 +-
 arch/x86/lib/tables.c |   2 +-
 arch/x86/lib/zimage.c |   2 +-
 include/acpi_table.h  | 394 ++
 lib/efi_loader/efi_acpi.c |   2 +-
 12 files changed, 404 insertions(+), 386 deletions(-)
 create mode 100644 include/acpi_table.h

diff --git a/arch/x86/cpu/baytrail/acpi.c b/arch/x86/cpu/baytrail/acpi.c
index f44228e693..856af95556 100644
--- a/arch/x86/cpu/baytrail/acpi.c
+++ b/arch/x86/cpu/baytrail/acpi.c
@@ -8,7 +8,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/x86/cpu/cpu.c b/arch/x86/cpu/cpu.c
index 3db035c2c0..b878fd4b1f 100644
--- a/arch/x86/cpu/cpu.c
+++ b/arch/x86/cpu/cpu.c
@@ -28,7 +28,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/x86/cpu/quark/acpi.c b/arch/x86/cpu/quark/acpi.c
index 7b6fc2f4a5..dd562a6e2f 100644
--- a/arch/x86/cpu/quark/acpi.c
+++ b/arch/x86/cpu/quark/acpi.c
@@ -4,7 +4,7 @@
  */
 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/x86/cpu/tangier/acpi.c b/arch/x86/cpu/tangier/acpi.c
index 8b128138b0..768c4dcbc8 100644
--- a/arch/x86/cpu/tangier/acpi.c
+++ b/arch/x86/cpu/tangier/acpi.c
@@ -9,7 +9,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/x86/include/asm/acpi_table.h 
b/arch/x86/include/asm/acpi_table.h
index 7588913f93..22d54057f1 100644
--- a/arch/x86/include/asm/acpi_table.h
+++ b/arch/x86/include/asm/acpi_table.h
@@ -9,382 +9,6 @@
 #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 */
-#define ASLC_ID"INTL"  /* Intel ASL Compiler */
-
-#define ACPI_RSDP_REV_ACPI_1_0 0
-#define ACPI_RSDP_REV_ACPI_2_0 2
-
-/*
- * RSDP (Root System Description Pointer)
- * Note: ACPI 1.0 didn't have length, xsdt_address, and ext_checksum
- */
-struct acpi_rsdp {
-   char signature[8];  /* RSDP signature */
-   u8 checksum;/* Checksum of the first 20 bytes */
-   char oem_id[6]; /* OEM ID */
-   u8 revision;/* 0 for ACPI 1.0, others 2 */
-   u32 rsdt_address;   /* Physical address of RSDT (32 bits) */
-   u32 length; /* Total RSDP length (incl. extended part) */
-   u64 xsdt_address;   /* Physical address of XSDT (64 bits) */
-   u8 ext_checksum;/* Checksum of the whole table */
-   u8 reserved[3];
-};
-
-/* Generic ACPI header, provided by (almost) all tables */
-struct __packed acpi_table_header {
-   char signature[4];  /* ACPI signature (4 ASCII characters) */
-   u32 length; /* Table length in bytes (incl. header) */
-   u8 revision;/* Table version (not ACPI version!) */
-   volatile u8 checksum;   /* To make sum of entire table == 0 */
-   char oem_id[6]; /* OEM identification */
-   char oem_table_id[8];   /* OEM table identification */
-   u32 oem_revision;   /* OEM revision number */
-   char aslc_id[4];/* ASL compiler vendor ID */
-   u32 aslc_revision;  /* ASL compiler revision number */
-};
-
-/* A maximum number of 32 ACPI tables ought to be enough for now */
-#define MAX_ACPI_TABLES32
-
-/* RSDT (Root System Description Table) */
-struct acpi_rsdt {
-   struct acpi_table_header header;
-   u32 entry[MAX_ACPI_TABLES];
-};
-
-/* XSDT (Extended System Description Table) */
-struct acpi_xsdt {
-   struct acpi_table_header header;
-   u64 entry[MAX_ACPI_TABLES];
-};
-
-/* FADT Preferred Power Management Profile */
-enum acpi_pm_profile {
-   ACPI_PM_UNSPECIFIED = 0,
-   ACPI_PM_DESKTOP,
-   ACPI_PM_MOBILE,
-   ACPI_PM_WORKSTATION,
-   ACPI_PM_ENTERPRISE_SERVER,
-   ACPI_PM_SOHO_SERVER,
-   ACPI_PM_APPLIANCE_PC,
-   ACPI_PM_PERFORMANCE_SERVER,
-   ACPI_PM_TABLET
-};
-
-/* FADT flags for p_lvl2_lat and p_lvl3_lat */
-#define ACPI_FADT_C2_NOT_SUPPORTED 101
-#define ACPI_FADT_C3_NOT_SUPPORTED 1001
-
-/* FADT Boot Architecture Flags */
-#define ACPI_FADT_LEGACY_FREE  0x00
-#define ACPI_FADT_LEGACY_DEVICES   (1 << 0)
-#define ACPI_FADT

[PATCH v2 17/39] acpi: Add a central location for table version numbers

2020-03-08 Thread Simon Glass
Each ACPI table has its own version number. Add the version numbers in a
single function so we can keep them consistent and easily see what
versions are supported.

Start a new acpi_table file in a generic directory to house this function.
We can move things over to this file from x86 as needed.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Move the sandbox acpi_table.h header file to an earlier patch
- Use #defines for MADT and MCFG version numbers

 include/acpi_table.h  | 61 +++
 lib/Makefile  |  1 +
 lib/acpi/Makefile |  4 +++
 lib/acpi/acpi_table.c | 60 ++
 test/dm/acpi.c| 14 ++
 5 files changed, 140 insertions(+)
 create mode 100644 lib/acpi/Makefile
 create mode 100644 lib/acpi/acpi_table.c

diff --git a/include/acpi_table.h b/include/acpi_table.h
index dd74895813..ccf6fa04db 100644
--- a/include/acpi_table.h
+++ b/include/acpi_table.h
@@ -202,6 +202,26 @@ struct __packed acpi_fadt {
struct acpi_gen_regaddr x_gpe1_blk;
 };
 
+/* FADT TABLE Revision values */
+#define ACPI_FADT_REV_ACPI_1_0 1
+#define ACPI_FADT_REV_ACPI_2_0 3
+#define ACPI_FADT_REV_ACPI_3_0 4
+#define ACPI_FADT_REV_ACPI_4_0 4
+#define ACPI_FADT_REV_ACPI_5_0 5
+#define ACPI_FADT_REV_ACPI_6_0 6
+
+/* MADT TABLE Revision values */
+#define ACPI_MADT_REV_ACPI_3_0 2
+#define ACPI_MADT_REV_ACPI_4_0 3
+#define ACPI_MADT_REV_ACPI_5_0 3
+#define ACPI_MADT_REV_ACPI_6_0 5
+
+#define ACPI_MCFG_REV_ACPI_3_0 1
+
+/* IVRS Revision Field */
+#define IVRS_FORMAT_FIXED  0x01/* Type 10h & 11h only */
+#define IVRS_FORMAT_MIXED  0x02/* Type 10h, 11h, & 40h */
+
 /* FACS flags */
 #define ACPI_FACS_S4BIOS_F BIT(0)
 #define ACPI_FACS_64BIT_WAKE_F BIT(1)
@@ -391,6 +411,47 @@ struct __packed acpi_spcr {
u32 reserved2;
 };
 
+/* Tables defined by ACPI and generated by U-Boot */
+enum acpi_tables {
+   ACPITAB_BERT,
+   ACPITAB_DBG2,
+   ACPITAB_DMAR,
+   ACPITAB_DSDT,
+   ACPITAB_FACS,
+   ACPITAB_FADT,
+   ACPITAB_HEST,
+   ACPITAB_HPET,
+   ACPITAB_IVRS,
+   ACPITAB_MADT,
+   ACPITAB_MCFG,
+   ACPITAB_RSDP,
+   ACPITAB_RSDT,
+   ACPITAB_SLIT,
+   ACPITAB_SRAT,
+   ACPITAB_SSDT,
+   ACPITAB_TCPA,
+   ACPITAB_TPM2,
+   ACPITAB_XSDT,
+   ACPITAB_ECDT,
+
+   /* Additional proprietary tables */
+   ACPITAB_VFCT,
+   ACPITAB_NHLT,
+   ACPITAB_SPMI,
+
+   ACPITAB_COUNT,
+};
+
+/**
+ * acpi_get_table_revision() - Get the revision number generated for a table
+ *
+ * This keeps the version-number information in one place
+ *
+ * @table: ACPI table to check
+ * @return version number that U-Boot generates
+ */
+int acpi_get_table_revision(enum acpi_tables table);
+
 #endif /* !__ACPI__*/
 
 #include 
diff --git a/lib/Makefile b/lib/Makefile
index 15259d0473..9df834c2fd 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -5,6 +5,7 @@
 
 ifndef CONFIG_SPL_BUILD
 
+obj-$(CONFIG_$(SPL_TPL_)ACPIGEN) += acpi/
 obj-$(CONFIG_EFI) += efi/
 obj-$(CONFIG_EFI_LOADER) += efi_driver/
 obj-$(CONFIG_EFI_LOADER) += efi_loader/
diff --git a/lib/acpi/Makefile b/lib/acpi/Makefile
new file mode 100644
index 00..660491ef71
--- /dev/null
+++ b/lib/acpi/Makefile
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+
+obj-y += acpi_table.o
diff --git a/lib/acpi/acpi_table.c b/lib/acpi/acpi_table.c
new file mode 100644
index 00..197f965c08
--- /dev/null
+++ b/lib/acpi/acpi_table.c
@@ -0,0 +1,60 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Tests for ACPI table generation
+ *
+ * Copyright 2019 Google LLC
+ */
+
+#include 
+#include 
+
+int acpi_get_table_revision(enum acpi_tables table)
+{
+   switch (table) {
+   case ACPITAB_FADT:
+   return ACPI_FADT_REV_ACPI_3_0;
+   case ACPITAB_MADT:
+   return ACPI_MADT_REV_ACPI_3_0;
+   case ACPITAB_MCFG:
+   return ACPI_MCFG_REV_ACPI_3_0;
+   case ACPITAB_TCPA:
+   /* THis version and the rest are open-coded */
+   return 2;
+   case ACPITAB_TPM2:
+   return 4;
+   case ACPITAB_SSDT: /* ACPI 3.0 upto 6.3: 2 */
+   return 2;
+   case ACPITAB_SRAT: /* ACPI 2.0: 1, ACPI 3.0: 2, ACPI 4.0 upto 6.3: 3 */
+   return 1; /* TODO Should probably be upgraded to 2 */
+   case ACPITAB_DMAR:
+   return 1;
+   case ACPITAB_SLIT: /* ACPI 2.0 upto 6.3: 1 */
+   return 1;
+   case ACPITAB_SPMI: /* IMPI 2.0 */
+   return 5;
+   case ACPITAB_HPET: /* Currently 1. Table added in ACPI 2.0 */
+   return 1;
+   case ACPITAB_VFCT: /* ACPI 2.0/3.0/4.0: 1 */
+   return 1;
+   case ACPITAB_IVRS:
+   return IVRS_FORMAT_FIXED;
+   case ACPITAB_DBG2:
+   return 0;
+   case ACP

[PATCH v2 16/39] acpi: Add an __ACPI__ preprocessor symbol

2020-03-08 Thread Simon Glass
The ASL compiler cannot handle C structures and the like so needs some
sort of header guard around these.

We already have an __ASSEMBLY__ #define but it seems best to create a new
one for ACPI since the rules may be different.

Add the check to a few files that ACPI always includes.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
---

Changes in v2: None

 include/acpi_table.h | 4 
 include/dm/acpi.h| 4 
 scripts/Makefile.lib | 4 ++--
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/include/acpi_table.h b/include/acpi_table.h
index b4404a632c..dd74895813 100644
--- a/include/acpi_table.h
+++ b/include/acpi_table.h
@@ -21,6 +21,8 @@
 #define ACPI_RSDP_REV_ACPI_1_0 0
 #define ACPI_RSDP_REV_ACPI_2_0 2
 
+#if !defined(__ACPI__)
+
 /*
  * RSDP (Root System Description Pointer)
  * Note: ACPI 1.0 didn't have length, xsdt_address, and ext_checksum
@@ -389,6 +391,8 @@ struct __packed acpi_spcr {
u32 reserved2;
 };
 
+#endif /* !__ACPI__*/
+
 #include 
 
 #endif /* __ACPI_TABLE_H__ */
diff --git a/include/dm/acpi.h b/include/dm/acpi.h
index 120576adc0..8d6c3fd424 100644
--- a/include/dm/acpi.h
+++ b/include/dm/acpi.h
@@ -22,6 +22,8 @@
 /* Length of an ACPI name string including nul terminator */
 #define ACPI_NAME_MAX  5
 
+#if !defined(__ACPI__)
+
 /**
  * struct acpi_ops - ACPI operations supported by driver model
  */
@@ -70,4 +72,6 @@ int acpi_get_name(const struct udevice *dev, char *out_name);
  */
 int acpi_return_name(char *out_name, const char *name);
 
+#endif /* __ACPI__ */
+
 #endif
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 30f392fdfb..aebdb38d0d 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -413,8 +413,8 @@ ASL_TMP = $(patsubst %.c,%.asl.tmp,$@)
 
 quiet_cmd_acpi_c_asl= ASL $<
 cmd_acpi_c_asl= \
-   $(CPP) -x assembler-with-cpp -D__ASSEMBLY__ -P $(UBOOTINCLUDE) \
-   -o $(ASL_TMP) $< && \
+   $(CPP) -x assembler-with-cpp -D__ASSEMBLY__ -D__ACPI__ \
+   -P $(UBOOTINCLUDE) -o $(ASL_TMP) $< && \
iasl -p $@ -tc $(ASL_TMP) $(if $(KBUILD_VERBOSE:1=), >/dev/null) && \
mv $(patsubst %.c,%.hex,$@) $@
 
-- 
2.25.1.481.gfbce0eb801-goog



[PATCH v2 12/39] dm: core: Add basic ACPI support

2020-03-08 Thread Simon Glass
ACPI (Advanced Configuration and Power Interface) is an Intel standard
for specifying information about a platform. It is a little like device
tree but considerably more complicated and with more backslashes. A
primary difference is that it supports an interpreted bytecode language.

Driver model does not use ACPI for U-Boot's configuration, but it is
convenient to have it support generation of ACPI tables for passing to
Linux, etc.

As a starting point, add an optional set of ACPI operations to each
device. Initially only a single operation is available, to obtain the
ACPI name for the device. More operations are added later.

Enable ACPI for sandbox to ensure build coverage and so that we can add
tests.

Reviewed-by: Bin Meng 
Signed-off-by: Simon Glass 
---

Changes in v2:
- Move LOGC_ACPI definition to this patch

 drivers/core/Kconfig  |  9 ++
 drivers/core/Makefile |  1 +
 drivers/core/acpi.c   | 32 +++
 include/dm/acpi.h | 73 +++
 include/dm/device.h   |  5 +++
 include/log.h |  2 ++
 6 files changed, 122 insertions(+)
 create mode 100644 drivers/core/acpi.c
 create mode 100644 include/dm/acpi.h

diff --git a/drivers/core/Kconfig b/drivers/core/Kconfig
index 3b95b5387b..a3b0399342 100644
--- a/drivers/core/Kconfig
+++ b/drivers/core/Kconfig
@@ -261,4 +261,13 @@ config DM_DEV_READ_INLINE
bool
default y if !OF_LIVE
 
+config ACPIGEN
+   bool "Support ACPI table generation in driver model"
+   default y if SANDBOX || GENERATE_ACPI_TABLE
+   help
+ This option enables generation of ACPI tables using driver-model
+ devices. It adds a new operation struct to each driver, to support
+ things like generating device-specific tables and returning the ACPI
+ name of a device.
+
 endmenu
diff --git a/drivers/core/Makefile b/drivers/core/Makefile
index bce7467da1..c707026a3a 100644
--- a/drivers/core/Makefile
+++ b/drivers/core/Makefile
@@ -3,6 +3,7 @@
 # Copyright (c) 2013 Google, Inc
 
 obj-y  += device.o fdtaddr.o lists.o root.o uclass.o util.o
+obj-$(CONFIG_$(SPL_TPL_)ACPIGEN) += acpi.o
 obj-$(CONFIG_DEVRES) += devres.o
 obj-$(CONFIG_$(SPL_)DM_DEVICE_REMOVE)  += device-remove.o
 obj-$(CONFIG_$(SPL_)SIMPLE_BUS)+= simple-bus.o
diff --git a/drivers/core/acpi.c b/drivers/core/acpi.c
new file mode 100644
index 00..45542199f5
--- /dev/null
+++ b/drivers/core/acpi.c
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Core driver model support for ACPI table generation
+ *
+ * Copyright 2019 Google LLC
+ * Written by Simon Glass 
+ */
+
+#define LOG_CATEOGRY   LOGC_ACPI
+
+#include 
+#include 
+#include 
+#include 
+
+int acpi_return_name(char *out_name, const char *name)
+{
+   strcpy(out_name, name);
+
+   return 0;
+}
+
+int acpi_get_name(const struct udevice *dev, char *out_name)
+{
+   struct acpi_ops *aops;
+
+   aops = device_get_acpi_ops(dev);
+   if (aops && aops->get_name)
+   return aops->get_name(dev, out_name);
+
+   return -ENOSYS;
+}
diff --git a/include/dm/acpi.h b/include/dm/acpi.h
new file mode 100644
index 00..120576adc0
--- /dev/null
+++ b/include/dm/acpi.h
@@ -0,0 +1,73 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Core ACPI (Advanced Configuration and Power Interface) support
+ *
+ * Copyright 2019 Google LLC
+ * Written by Simon Glass 
+ */
+
+#ifndef __DM_ACPI_H__
+#define __DM_ACPI_H__
+
+/* Allow operations to be optional for ACPI */
+#if CONFIG_IS_ENABLED(ACPIGEN)
+#define acpi_ops_ptr(_ptr) .acpi_ops   = _ptr,
+#else
+#define acpi_ops_ptr(_ptr)
+#endif
+
+/* Length of an ACPI name string, excluding nul terminator */
+#define ACPI_NAME_LEN  4
+
+/* Length of an ACPI name string including nul terminator */
+#define ACPI_NAME_MAX  5
+
+/**
+ * struct acpi_ops - ACPI operations supported by driver model
+ */
+struct acpi_ops {
+   /**
+* get_name() - Obtain the ACPI name of a device
+*
+* @dev: Device to check
+* @out_name: Place to put the name, must hold at least ACPI_NAME_MAX
+*  bytes
+* @return 0 if OK, -ENOENT if no name is available, other -ve value on
+*  other error
+*/
+   int (*get_name)(const struct udevice *dev, char *out_name);
+};
+
+#define device_get_acpi_ops(dev)   ((dev)->driver->acpi_ops)
+
+/**
+ * acpi_get_name() - Obtain the ACPI name of a device
+ *
+ * @dev: Device to check
+ * @out_name: Place to put the name, must hold at least ACPI_NAME_MAX
+ * bytes
+ * @return 0 if OK, -ENOENT if no name is available, other -ve value on
+ * other error
+ */
+int acpi_get_name(const struct udevice *dev, char *out_name);
+
+/**
+ * acpi_return_name() - Copy an ACPI name to an output buffer
+ *
+ * This convenience function can be used to return a literal string as a name
+ * in functions that implement the get_name() method.
+ *
+ * For example:
+ *
+ * static int mydev_get_

[PATCH v2 10/39] pci: Adjust dm_pci_read_bar32() to return errors correctly

2020-03-08 Thread Simon Glass
At present if reading a BAR returns 0x (e.g. the device is not
present) then the value is masked and a different value is returned.
This makes it harder to detect the problem when debugging.

Update the function to avoid masking in this case.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
---

Changes in v2: None

 drivers/pci/pci-uclass.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
index 213381da6b..7f46e901fb 100644
--- a/drivers/pci/pci-uclass.c
+++ b/drivers/pci/pci-uclass.c
@@ -1213,7 +1213,14 @@ u32 dm_pci_read_bar32(const struct udevice *dev, int 
barnum)
 
bar = PCI_BASE_ADDRESS_0 + barnum * 4;
dm_pci_read_config32(dev, bar, &addr);
-   if (addr & PCI_BASE_ADDRESS_SPACE_IO)
+
+   /*
+* If we get an invalid address, return this so that comparisons with
+* FDT_ADDR_T_NONE work correctly
+*/
+   if (addr == 0x)
+   return addr;
+   else if (addr & PCI_BASE_ADDRESS_SPACE_IO)
return addr & PCI_BASE_ADDRESS_IO_MASK;
else
return addr & PCI_BASE_ADDRESS_MEM_MASK;
-- 
2.25.1.481.gfbce0eb801-goog



[PATCH v2 11/39] x86: apl: Add Global NVS table header

2020-03-08 Thread Simon Glass
Add the C version of this header. It includes a few Chrome OS bits which
are disabled for a normal build.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Drop the Chrome OS pieces
- Rename the 'coreboot' console to 'U-Boot'

 .../include/asm/arch-apollolake/global_nvs.h  | 37 +++
 1 file changed, 37 insertions(+)
 create mode 100644 arch/x86/include/asm/arch-apollolake/global_nvs.h

diff --git a/arch/x86/include/asm/arch-apollolake/global_nvs.h 
b/arch/x86/include/asm/arch-apollolake/global_nvs.h
new file mode 100644
index 00..344a853fe9
--- /dev/null
+++ b/arch/x86/include/asm/arch-apollolake/global_nvs.h
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2015-2017 Intel Corp.
+ * (Written by Lance Zhao  for Intel Corp.)
+ * Copyright Google LLC 2019
+ *
+ * Modified from coreboot apollolake/include/soc/nvs.h
+ */
+
+#ifndef _GLOBAL_NVS_H_
+#define _GLOBAL_NVS_H_
+
+struct __packed acpi_global_nvs {
+   /* Miscellaneous */
+   u8  pcnt; /* 0x00 - Processor Count */
+   u8  ppcm; /* 0x01 - Max PPC State */
+   u8  lids; /* 0x02 - LID State */
+   u8  pwrs; /* 0x03 - AC Power State */
+   u8  dpte; /* 0x04 - Enable DPTF */
+   u32 cbmc; /* 0x05 - 0x08 - U-Boot Console */
+   u64 pm1i; /* 0x09 - 0x10 - System Wake Source - PM1 Index */
+   u64 gpei; /* 0x11 - 0x18 - GPE Wake Source */
+   u64 nhla; /* 0x19 - 0x20 - NHLT Address */
+   u32 nhll; /* 0x21 - 0x24 - NHLT Length */
+   u32 prt0; /* 0x25 - 0x28 - PERST_0 Address */
+   u8  scdp; /* 0x29 - SD_CD GPIO portid */
+   u8  scdo; /* 0x2A - GPIO pad offset relative to the community */
+   u8  uior; /* 0x2B - UART debug controller init on S3 resume */
+   u8  ecps; /* 0x2C - SGX Enabled status */
+   u64 emna; /* 0x2D - 0x34 EPC base address */
+   u64 elng; /* 0x35 - 0x3C EPC Length */
+   u8  unused[195];
+   u8  unused2[0xf00];
+#endif
+};
+
+#endif /* _GLOBAL_NVS_H_ */
-- 
2.25.1.481.gfbce0eb801-goog



[PATCH v2 09/39] x86: apl: Move p2sb ofdata reading to the correct method

2020-03-08 Thread Simon Glass
With P2SB the initial BAR (base-address register) is set up by TPL and
this is used unchanged right through U-Boot.

At present the reading of this address is split between the ofdata() and
probe() methods. There are a few problems that are unique to the p2sb.
One is that its children need to call pcr_read32(), etc. which needs to
have the p2sb address correct. Also some of its children are pinctrl
devices and pinctrl is used when any device is probed. So p2sb really
needs to get its base address set up in ofdata_to_platdata(), before it is
probed.

Another point is that reading the p2sb BAR will not work if the p2sb is
hidden. The FSP-S seems to hide it, presumably to avoid confusing PCI
enumeration.

Reading ofdata in ofdata_to_platdata() is the correct place anyway, so
this is easy to fix.

Move the code into one place and use the early-regs property in all cases
for simplicity and to avoid needing to probe any PCI devices just to read
the BAR.

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

Changes in v2: None

 arch/x86/cpu/intel_common/p2sb.c | 35 +++-
 1 file changed, 12 insertions(+), 23 deletions(-)

diff --git a/arch/x86/cpu/intel_common/p2sb.c b/arch/x86/cpu/intel_common/p2sb.c
index d5b4846e0a..4af55786e6 100644
--- a/arch/x86/cpu/intel_common/p2sb.c
+++ b/arch/x86/cpu/intel_common/p2sb.c
@@ -92,46 +92,35 @@ int p2sb_ofdata_to_platdata(struct udevice *dev)
 
 #if !CONFIG_IS_ENABLED(OF_PLATDATA)
int ret;
+   u32 base[2];
 
+   ret = dev_read_u32_array(dev, "early-regs", base, ARRAY_SIZE(base));
+   if (ret)
+   return log_msg_ret("Missing/short early-regs", ret);
+   plat->mmio_base = base[0];
+   /* TPL sets up the initial BAR */
if (spl_phase() == PHASE_TPL) {
-   u32 base[2];
-
-   /* TPL sets up the initial BAR */
-   ret = dev_read_u32_array(dev, "early-regs", base,
-ARRAY_SIZE(base));
-   if (ret)
-   return log_msg_ret("Missing/short early-regs", ret);
-   plat->mmio_base = base[0];
plat->bdf = pci_get_devfn(dev);
if (plat->bdf < 0)
return log_msg_ret("Cannot get p2sb PCI address",
-  plat->bdf);
+   plat->bdf);
}
+   upriv->mmio_base = plat->mmio_base;
 #else
plat->mmio_base = plat->dtplat.early_regs[0];
plat->bdf = pci_ofplat_get_devfn(plat->dtplat.reg[0]);
-#endif
upriv->mmio_base = plat->mmio_base;
-   debug("p2sb: mmio_base=%x\n", (uint)plat->mmio_base);
+#endif
 
return 0;
 }
 
 static int p2sb_probe(struct udevice *dev)
 {
-   if (spl_phase() == PHASE_TPL) {
+   if (spl_phase() == PHASE_TPL)
return p2sb_early_init(dev);
-   } else {
-   struct p2sb_platdata *plat = dev_get_platdata(dev);
-
-   plat->mmio_base = dev_read_addr_pci(dev);
-   /* Don't set BDF since it should not be used */
-   if (!plat->mmio_base || plat->mmio_base == FDT_ADDR_T_NONE)
-   return -EINVAL;
-
-   if (spl_phase() == PHASE_SPL)
-   return p2sb_spl_init(dev);
-   }
+   else if (spl_phase() == PHASE_SPL)
+   return p2sb_spl_init(dev);
 
return 0;
 }
-- 
2.25.1.481.gfbce0eb801-goog



[PATCH v2 08/39] x86: Correct wording of coreboot source code

2020-03-08 Thread Simon Glass
Some files are taken or modified from coreboot, but the files are
no-longer part of the coreboot project. Fix the wording in a few places.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
---

Changes in v2: None

 arch/x86/cpu/coreboot/timestamp.c  | 4 ++--
 arch/x86/include/asm/arch-coreboot/timestamp.h | 4 ++--
 arch/x86/include/asm/intel_pinctrl_defs.h  | 2 --
 3 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/arch/x86/cpu/coreboot/timestamp.c 
b/arch/x86/cpu/coreboot/timestamp.c
index e698200d70..e8ccaf2212 100644
--- a/arch/x86/cpu/coreboot/timestamp.c
+++ b/arch/x86/cpu/coreboot/timestamp.c
@@ -1,8 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * This file is part of the coreboot project.
- *
  * Copyright (C) 2011 The ChromiumOS Authors.  All rights reserved.
+ *
+ * Modified from the coreboot version
  */
 
 #include 
diff --git a/arch/x86/include/asm/arch-coreboot/timestamp.h 
b/arch/x86/include/asm/arch-coreboot/timestamp.h
index 9320afba56..85d42c02c4 100644
--- a/arch/x86/include/asm/arch-coreboot/timestamp.h
+++ b/arch/x86/include/asm/arch-coreboot/timestamp.h
@@ -1,8 +1,8 @@
 /* SPDX-License-Identifier: GPL-2.0 */
 /*
- * This file is part of the coreboot project.
- *
  * Copyright (C) 2011 The ChromiumOS Authors.  All rights reserved.
+ *
+ * Taken from the coreboot version
  */
 
 #ifndef __COREBOOT_TIMESTAMP_H__
diff --git a/arch/x86/include/asm/intel_pinctrl_defs.h 
b/arch/x86/include/asm/intel_pinctrl_defs.h
index 6da06bb52b..1ea141f082 100644
--- a/arch/x86/include/asm/intel_pinctrl_defs.h
+++ b/arch/x86/include/asm/intel_pinctrl_defs.h
@@ -1,7 +1,5 @@
 /* SPDX-License-Identifier: GPL-2.0 */
 /*
- * This file is part of the coreboot project.
- *
  * Copyright (C) 2015-2016 Intel Corp.
  * Copyright 2019 Google LLC
  *
-- 
2.25.1.481.gfbce0eb801-goog



[PATCH v2 06/39] tpm: Don't cleanup unless an error happens

2020-03-08 Thread Simon Glass
At present the cleanup() method is called on every transfer. It should
only be called on failing transfers. Fix this and tidy up the error
handling a little.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
---

Changes in v2: None

 drivers/tpm/tpm-uclass.c | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/tpm/tpm-uclass.c b/drivers/tpm/tpm-uclass.c
index 1b11c93194..71d5807006 100644
--- a/drivers/tpm/tpm-uclass.c
+++ b/drivers/tpm/tpm-uclass.c
@@ -72,7 +72,7 @@ int tpm_xfer(struct udevice *dev, const uint8_t *sendbuf, 
size_t send_size,
struct tpm_ops *ops = tpm_get_ops(dev);
ulong start, stop;
uint count, ordinal;
-   int ret, ret2;
+   int ret, ret2 = 0;
 
if (ops->xfer)
return ops->xfer(dev, sendbuf, send_size, recvbuf, recv_size);
@@ -120,9 +120,16 @@ int tpm_xfer(struct udevice *dev, const uint8_t *sendbuf, 
size_t send_size,
}
} while (ret);
 
-   ret2 = ops->cleanup ? ops->cleanup(dev) : 0;
+   if (ret) {
+   if (ops->cleanup) {
+   ret2 = ops->cleanup(dev);
+   if (ret2)
+   return log_msg_ret("cleanup", ret2);
+   }
+   return log_msg_ret("xfer", ret);
+   }
 
-   return ret2 ? ret2 : ret;
+   return 0;
 }
 
 UCLASS_DRIVER(tpm) = {
-- 
2.25.1.481.gfbce0eb801-goog



[PATCH v2 05/39] tpm: cr50: Use the correct GPIO binding

2020-03-08 Thread Simon Glass
This device should use ready-gpios rather than ready-gpio. Fix it.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
---

Changes in v2: None

 arch/x86/dts/chromebook_coral.dts   | 2 +-
 doc/device-tree-bindings/gpio/intel,apl-gpio.txt| 2 +-
 .../interrupt-controller/intel,acpi-gpe.txt | 2 +-
 drivers/tpm/cr50_i2c.c  | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/x86/dts/chromebook_coral.dts 
b/arch/x86/dts/chromebook_coral.dts
index af52e11c89..d48ef3573e 100644
--- a/arch/x86/dts/chromebook_coral.dts
+++ b/arch/x86/dts/chromebook_coral.dts
@@ -292,7 +292,7 @@
reg = <0x50>;
compatible = "google,cr50";
u-boot,i2c-offset-len = <0>;
-   ready-gpio = <&gpio_n 28 GPIO_ACTIVE_LOW>;
+   ready-gpios = <&gpio_n 28 GPIO_ACTIVE_LOW>;
interrupts-extended = <&acpi_gpe 0x3c 0>;
};
};
diff --git a/doc/device-tree-bindings/gpio/intel,apl-gpio.txt 
b/doc/device-tree-bindings/gpio/intel,apl-gpio.txt
index cf0659b70e..8422ff63ab 100644
--- a/doc/device-tree-bindings/gpio/intel,apl-gpio.txt
+++ b/doc/device-tree-bindings/gpio/intel,apl-gpio.txt
@@ -47,7 +47,7 @@ Example:
reg = <0x50>;
compatible = "google,cr50";
u-boot,i2c-offset-len = <0>;
-   ready-gpio = <&gpio_n GPIO_28 GPIO_ACTIVE_LOW>;
+   ready-gpios = <&gpio_n GPIO_28 GPIO_ACTIVE_LOW>;
};
};
 
diff --git a/doc/device-tree-bindings/interrupt-controller/intel,acpi-gpe.txt 
b/doc/device-tree-bindings/interrupt-controller/intel,acpi-gpe.txt
index d9252bf29f..2fe02d8a22 100644
--- a/doc/device-tree-bindings/interrupt-controller/intel,acpi-gpe.txt
+++ b/doc/device-tree-bindings/interrupt-controller/intel,acpi-gpe.txt
@@ -25,6 +25,6 @@ Example:
tpm@50 {
reg = <0x50>;
compatible = "google,cr50";
-   ready-gpio = <&gpio_n 0x1c GPIO_ACTIVE_LOW>;
+   ready-gpios = <&gpio_n 0x1c GPIO_ACTIVE_LOW>;
interrupts-extended = <&acpi_gpe 0x3c 0>;
};
diff --git a/drivers/tpm/cr50_i2c.c b/drivers/tpm/cr50_i2c.c
index c1d2d2fa38..b67051af26 100644
--- a/drivers/tpm/cr50_i2c.c
+++ b/drivers/tpm/cr50_i2c.c
@@ -607,7 +607,7 @@ static int cr50_i2c_ofdata_to_platdata(struct udevice *dev)
priv->irq = irq;
priv->use_irq = true;
} else {
-   ret = gpio_request_by_name(dev, "ready-gpio", 0,
+   ret = gpio_request_by_name(dev, "ready-gpios", 0,
   &priv->ready_gpio, GPIOD_IS_IN);
if (ret) {
log_warning("Cr50 does not have an ready GPIO/interrupt 
(err=%d)\n",
-- 
2.25.1.481.gfbce0eb801-goog



[PATCH v2 07/39] dm: pci: Allow disabling auto-config for a device

2020-03-08 Thread Simon Glass
Add a means to avoid configuring a device when needed. Add an explanation
of why this is useful to the binding file.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
---

Changes in v2: None

 doc/device-tree-bindings/pci/x86-pci.txt | 24 
 drivers/pci/pci-uclass.c |  2 ++
 2 files changed, 26 insertions(+)

diff --git a/doc/device-tree-bindings/pci/x86-pci.txt 
b/doc/device-tree-bindings/pci/x86-pci.txt
index 3aa5bd9a46..62b29a4e36 100644
--- a/doc/device-tree-bindings/pci/x86-pci.txt
+++ b/doc/device-tree-bindings/pci/x86-pci.txt
@@ -10,6 +10,17 @@ Optional properties:
configuration in TPL/SPL to reduce code size and boot time, since these
phases only know about a small subset of PCI devices.
 
+For PCI devices the following optional property is available:
+
+- pci,no-autoconfig : Don't automatically configure this PCI device at all.
+   This is used when the device is statically configured and must maintain
+   this same config throughout the boot process. An example is a serial
+   UART being used to debug PCI configuration, since reconfiguring it stops
+   the UART from working until the driver is re-probed, and this can cause
+   output to be lost. This should not generally be used in production code,
+   although it is often harmless.
+
+
 Example:
 
 pci {
@@ -21,4 +32,17 @@ pci {
0x4200 0x0 0xb000 0xb000 0 0x1000
0x0100 0x0 0x1000 0x1000 0 0xefff>;
u-boot,skip-auto-config-until-reloc;
+
+
+   serial: serial@18,2 {
+   reg = <0x0200c210 0 0 0 0>;
+   u-boot,dm-pre-reloc;
+   compatible = "intel,apl-ns16550";
+   early-regs = <0xde00 0x20>;
+   reg-shift = <2>;
+   clock-frequency = <1843200>;
+   current-speed = <115200>;
+   acpi,name = "URT3";
+   pci,no-autoconfig;
+   };
 };
diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
index 94733662b1..213381da6b 100644
--- a/drivers/pci/pci-uclass.c
+++ b/drivers/pci/pci-uclass.c
@@ -536,6 +536,8 @@ int pci_auto_config_devices(struct udevice *bus)
int ret;
 
debug("%s: device %s\n", __func__, dev->name);
+   if (dev_read_bool(dev, "pci,no-autoconfig"))
+   continue;
ret = dm_pciauto_config_device(dev);
if (ret < 0)
return ret;
-- 
2.25.1.481.gfbce0eb801-goog



[PATCH v2 04/39] tpm: cr50: Add a comment for cr50_priv

2020-03-08 Thread Simon Glass
Add a comment for the private structure

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
---

Changes in v2:
- Drop the other comment change since it is already applied

 drivers/tpm/cr50_i2c.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/tpm/cr50_i2c.c b/drivers/tpm/cr50_i2c.c
index b30f55b40d..c1d2d2fa38 100644
--- a/drivers/tpm/cr50_i2c.c
+++ b/drivers/tpm/cr50_i2c.c
@@ -34,6 +34,15 @@ enum {
CR50_MAX_BUF_SIZE = 63,
 };
 
+/**
+ * struct cr50_priv - Private driver data
+ *
+ * @ready_gpio: GPIO to use to check if the TPM is ready
+ * @irq: IRQ to use check if the TPM is ready (has priority over @ready_gpio)
+ * @locality: Currenttly claimed locality (-1 if none)
+ * @vendor: vendor: Vendor ID for TPM
+ * @use_irq: true to use @irq, false to use @ready if available
+ */
 struct cr50_priv {
struct gpio_desc ready_gpio;
struct irq irq;
-- 
2.25.1.481.gfbce0eb801-goog



[PATCH v2 02/39] spi: Add SPI mode enums

2020-03-08 Thread Simon Glass
With ACPI we need to describe the settings of the SPI bus. Add enums to
handle this.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
---

Changes in v2:
- Don't bracket the definitions with DM_SPI

 include/spi.h | 33 +
 1 file changed, 33 insertions(+)

diff --git a/include/spi.h b/include/spi.h
index 852f570eaa..2092940f4c 100644
--- a/include/spi.h
+++ b/include/spi.h
@@ -66,6 +66,39 @@ struct dm_spi_slave_platdata {
 
 #endif /* CONFIG_DM_SPI */
 
+/**
+ * enum spi_clock_phase - indicates  the clock phase to use for SPI (CPHA)
+ *
+ * @SPI_CLOCK_PHASE_FIRST: Data sampled on the first phase
+ * @SPI_CLOCK_PHASE_SECOND: Data sampled on the second phase
+ */
+enum spi_clock_phase {
+   SPI_CLOCK_PHASE_FIRST,
+   SPI_CLOCK_PHASE_SECOND
+};
+
+/**
+ * enum spi_wire_mode - indicates the number of wires used for SPI
+ *
+ * @SPI_4_WIRE_MODE: Normal bidirectional mode with MOSI and MISO
+ * @SPI_3_WIRE_MODE: Unidirectional version with a single data line SISO
+ */
+enum spi_wire_mode {
+   SPI_4_WIRE_MODE,
+   SPI_3_WIRE_MODE
+};
+
+/**
+ * enum spi_polarity - indicates the polarity of the SPI bus (CPOL)
+ *
+ * @SPI_POLARITY_LOW: Clock is low in idle state
+ * @SPI_POLARITY_HIGH: Clock is high in idle state
+ */
+enum spi_polarity {
+   SPI_POLARITY_LOW,
+   SPI_POLARITY_HIGH
+};
+
 /**
  * struct spi_slave - Representation of a SPI slave
  *
-- 
2.25.1.481.gfbce0eb801-goog



[PATCH v2 03/39] tpm: cr50: Release locality on exit

2020-03-08 Thread Simon Glass
At present the cr50 driver claims the locality and does not release it for
Linux. This causes problems. Fix this by tracking what is claimed, and
adding a 'remove' method.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
---

Changes in v2: None

 drivers/tpm/cr50_i2c.c | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/tpm/cr50_i2c.c b/drivers/tpm/cr50_i2c.c
index b904a7d426..b30f55b40d 100644
--- a/drivers/tpm/cr50_i2c.c
+++ b/drivers/tpm/cr50_i2c.c
@@ -206,7 +206,7 @@ static int release_locality(struct udevice *dev, int force)
cr50_i2c_write(dev, addr, &buf, 1);
}
 
-   priv->locality = 0;
+   priv->locality = -1;
 
return 0;
 }
@@ -499,6 +499,7 @@ static int process_reset(struct udevice *dev)
 static int claim_locality(struct udevice *dev, int loc)
 {
const u8 mask = TPM_ACCESS_VALID | TPM_ACCESS_ACTIVE_LOCALITY;
+   struct cr50_priv *priv = dev_get_priv(dev);
u8 access;
int ret;
 
@@ -525,6 +526,7 @@ static int claim_locality(struct udevice *dev, int loc)
return -EPERM;
}
log_info("Claimed locality %d\n", loc);
+   priv->locality = loc;
 
return 0;
 }
@@ -559,7 +561,11 @@ static int cr50_i2c_open(struct udevice *dev)
 
 static int cr50_i2c_cleanup(struct udevice *dev)
 {
-   release_locality(dev, 1);
+   struct cr50_priv *priv = dev_get_priv(dev);
+
+   printf("%s: cleanup %d\n", __func__, priv->locality);
+   if (priv->locality != -1)
+   release_locality(dev, 1);
 
return 0;
 }
@@ -631,6 +637,7 @@ static int cr50_i2c_probe(struct udevice *dev)
return log_msg_ret("vendor-id", -EXDEV);
}
priv->vendor = vendor;
+   priv->locality = -1;
 
return 0;
 }
@@ -655,5 +662,7 @@ U_BOOT_DRIVER(cr50_i2c) = {
.ops= &cr50_i2c_ops,
.ofdata_to_platdata = cr50_i2c_ofdata_to_platdata,
.probe  = cr50_i2c_probe,
+   .remove = cr50_i2c_cleanup,
.priv_auto_alloc_size = sizeof(struct cr50_priv),
+   .flags  = DM_FLAG_OS_PREPARE,
 };
-- 
2.25.1.481.gfbce0eb801-goog



[PATCH v2 01/39] cpu: Support querying the address width

2020-03-08 Thread Simon Glass
Different CPUs may support different address widths, meaning the amount of
memory they can address. Add a property for this to the cpu_info struct.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
---

Changes in v2: None

 drivers/cpu/cpu_sandbox.c | 1 +
 include/cpu.h | 2 ++
 test/dm/cpu.c | 1 +
 3 files changed, 4 insertions(+)

diff --git a/drivers/cpu/cpu_sandbox.c b/drivers/cpu/cpu_sandbox.c
index ff87e8adca..05b384f6a4 100644
--- a/drivers/cpu/cpu_sandbox.c
+++ b/drivers/cpu/cpu_sandbox.c
@@ -19,6 +19,7 @@ int cpu_sandbox_get_info(struct udevice *dev, struct cpu_info 
*info)
 {
info->cpu_freq = 42 * 42 * 42 * 42 * 42;
info->features = 0x42424242;
+   info->address_width = IS_ENABLED(CONFIG_PHYS_64BIT) ? 64 : 32;
 
return 0;
 }
diff --git a/include/cpu.h b/include/cpu.h
index 28dd48feb8..6b1b6b37b3 100644
--- a/include/cpu.h
+++ b/include/cpu.h
@@ -44,10 +44,12 @@ enum {
  *
  * @cpu_freq:  Current CPU frequency in Hz
  * @features:  Flags for supported CPU features
+ * @address_width: Width of the CPU address space in bits (e.g. 32)
  */
 struct cpu_info {
ulong cpu_freq;
ulong features;
+   uint address_width;
 };
 
 struct cpu_ops {
diff --git a/test/dm/cpu.c b/test/dm/cpu.c
index f5f1caef71..e6dc576ea3 100644
--- a/test/dm/cpu.c
+++ b/test/dm/cpu.c
@@ -33,6 +33,7 @@ static int dm_test_cpu(struct unit_test_state *uts)
ut_assertok(cpu_get_info(dev, &info));
ut_asserteq(info.cpu_freq, 42 * 42 * 42 * 42 * 42);
ut_asserteq(info.features, 0x42424242);
+   ut_asserteq(info.address_width, 32);
 
ut_asserteq(cpu_get_count(dev), 42);
 
-- 
2.25.1.481.gfbce0eb801-goog



[PATCH v2 00/39] dm: Add programmatic generation of ACPI tables (part A)

2020-03-08 Thread Simon Glass
This is split from the original series in an attempt to get things applied
in chunks.

The first 20 or so patches here have been reviewed and the changes here
incorporate those comments.

Changes in v2:
- Don't bracket the definitions with DM_SPI
- Drop the other comment change since it is already applied
- Drop the Chrome OS pieces
- Rename the 'coreboot' console to 'U-Boot'
- Move LOGC_ACPI definition to this patch
- Fix definition of HID
- Infer hid-over-i2c CID value
- Add the hid-over-i2c binding document
- Add in the acpi_table.h header file to this patch
- Move the sandbox acpi_table.h header file to an earlier patch
- Use #defines for MADT and MCFG version numbers
- Drop two unnecessary __packed
- Move __packed to after struct
- 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()
- Drop CID value from i2c struct
- Switch parameter order of _acpi_fill_ssdt() and make it static
- Generalise the ACPI function recursion with acpi_recurse_method()
- Generalise the ACPI function recursion with acpi_recurse_method()
- Move ACPI_TABLE_CREATOR to here
- Generalise the ACPI function recursion with acpi_recurse_method()

Simon Glass (39):
  cpu: Support querying the address width
  spi: Add SPI mode enums
  tpm: cr50: Release locality on exit
  tpm: cr50: Add a comment for cr50_priv
  tpm: cr50: Use the correct GPIO binding
  tpm: Don't cleanup unless an error happens
  dm: pci: Allow disabling auto-config for a device
  x86: Correct wording of coreboot source code
  x86: apl: Move p2sb ofdata reading to the correct method
  pci: Adjust dm_pci_read_bar32() to return errors correctly
  x86: apl: Add Global NVS table header
  dm: core: Add basic ACPI support
  acpi: Add a binding for ACPI settings in the device tree
  acpi: Add a simple sandbox test
  x86: Move acpi_table header to main include/ directory
  acpi: Add an __ACPI__ preprocessor symbol
  acpi: Add a central location for table version numbers
  acpi: Add support for DMAR
  acpi: Move acpi_fill_header() to generic code
  acpi: Add a method to write tables for a device
  acpi: Convert part of acpi_table to use acpi_ctx
  x86: Allow devices to write ACPI tables
  acpi: Drop code for missing XSDT from acpi_write_rsdp()
  acpi: Move acpi_add_table() to generic code
  acpi: Put table-setup code in its own function
  acpi: Move the xsdt pointer to acpi_ctx
  acpi: Add an acpi command
  acpi: Add some tables required by the generation code
  acpi: Add generation code for devices
  acpi: Add functions to generate ACPI code
  gpio: Add a method to convert a GPIO to ACPI
  irq: Add a method to convert an interrupt to ACPI
  acpi: Add support for SSDT generation
  x86: acpi: Move MADT up a bit
  acpi: Record the items added to SSDT
  acpi: Support ordering SSDT data by device
  x86: Allow devices to write an SSDT
  acpi: Add support for DSDT generation
  x86: Allow devices to write to DSDT

 arch/sandbox/dts/test.dts |   13 +
 arch/sandbox/include/asm/acpi_table.h |9 +
 arch/sandbox/include/asm/global_data.h|1 +
 arch/x86/cpu/baytrail/acpi.c  |2 +-
 arch/x86/cpu/coreboot/timestamp.c |4 +-
 arch/x86/cpu/cpu.c|2 +-
 arch/x86/cpu/intel_common/p2sb.c  |   35 +-
 arch/x86/cpu/quark/acpi.c |2 +-
 arch/x86/cpu/tangier/acpi.c   |2 +-
 arch/x86/dts/chromebook_coral.dts |2 +-
 arch/x86/include/asm/acpi_table.h |  376 
 .../include/asm/arch-apollolake/global_nvs.h  |   37 +
 .../x86/include/asm/arch-coreboot/timestamp.h |4 +-
 arch/x86/include/asm/global_data.h|1 +
 arch/x86/include/asm/intel_pinctrl_defs.h |2 -
 arch/x86/lib/acpi.c   |2 +-
 arch/x86/lib/acpi_s3.c|2 +-
 arch/x86/lib/acpi_table.c |  312 ++-
 arch/x86/lib/tables.c |2 +-
 arch/x86/lib/zimage.c |2 +-
 cmd/Kconfig   |   14 +
 cmd/Makefile  |1 +
 cmd/acpi.c|  179 ++
 doc/device-tree-bindings/chosen.txt   |9 +
 doc/device-tree-bindings/device.txt   |   36 +
 .../gpio/intel,apl-gpio.txt   |2 +-
 .../input/hid-over-i2c.txt|   44 +
 .../interrupt-controller/intel,acpi-gpe.txt   |2 +-
 doc/device-tree-bindings/pci/x86-pci.txt  |   24 +
 drivers/core/Kconfig  |9 +
 drivers/core/Makefile |1 +
 drivers/core/acpi.c   |  267 +++
 drivers/cpu/cpu_sandbox.c |1 +
 drivers/gpio/gpio-uclass.c|   21 +
 drivers/misc/irq-uclass.c |   18 +-
 drivers/

[PATCH] arm: socfpga: increase QSPI kernel Image size for Stratix10 and Agilex

2020-03-08 Thread Ooi, Joyce
From: Joyce Ooi 

This patch increases the allocated kernel Image size to 32MB for QSPI
for Stratix10 and Agilex as the latest kernel size has increased.

Signed-off-by: Joyce Ooi 
---
 include/configs/socfpga_agilex_socdk.h|8 
 include/configs/socfpga_stratix10_socdk.h |8 
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/configs/socfpga_agilex_socdk.h 
b/include/configs/socfpga_agilex_socdk.h
index 6a90ce6..4bb2e8f 100644
--- a/include/configs/socfpga_agilex_socdk.h
+++ b/include/configs/socfpga_agilex_socdk.h
@@ -78,7 +78,7 @@
 #ifdef CONFIG_ENV_IS_IN_SPI_FLASH
 #undef CONFIG_ENV_OFFSET
 #undef CONFIG_ENV_SIZE
-#define CONFIG_ENV_OFFSET  0x0208
+#define CONFIG_ENV_OFFSET  0x020C
 #define CONFIG_ENV_SIZE(64 * 1024)
 #define CONFIG_ENV_SECT_SIZE   (64 * 1024)
 #endif /* CONFIG_ENV_IS_IN_SPI_FLASH */
@@ -120,9 +120,9 @@ unsigned int cm_get_qspi_controller_clk_hz(void);
 #define CONFIG_BOOTARGS "earlycon"
 
 #define CONFIG_EXTRA_ENV_SETTINGS \
-   "qspibootimageaddr=0x020B\0" \
-   "qspifdtaddr=0x0209\0" \
-   "bootimagesize=0x0140\0" \
+   "qspibootimageaddr=0x020E\0" \
+   "qspifdtaddr=0x020D\0" \
+   "bootimagesize=0x01F0\0" \
"fdtimagesize=0x0001\0" \
"qspiload=sf read ${loadaddr} ${qspibootimageaddr} ${bootimagesize};" \
"sf read ${fdt_addr} ${qspifdtaddr} ${fdtimagesize}\0" \
diff --git a/include/configs/socfpga_stratix10_socdk.h 
b/include/configs/socfpga_stratix10_socdk.h
index 28fb546..1c41fc4 100644
--- a/include/configs/socfpga_stratix10_socdk.h
+++ b/include/configs/socfpga_stratix10_socdk.h
@@ -78,7 +78,7 @@
 #ifdef CONFIG_ENV_IS_IN_SPI_FLASH
 #undef CONFIG_ENV_OFFSET
 #undef CONFIG_ENV_SIZE
-#define CONFIG_ENV_OFFSET  0x0208
+#define CONFIG_ENV_OFFSET  0x020C
 #define CONFIG_ENV_SIZE(64 * 1024)
 #define CONFIG_ENV_SECT_SIZE   (64 * 1024)
 #endif /* CONFIG_ENV_IS_IN_SPI_FLASH */
@@ -116,9 +116,9 @@ unsigned int cm_get_qspi_controller_clk_hz(void);
 #endif
 
 #define CONFIG_EXTRA_ENV_SETTINGS \
-   "qspibootimageaddr=0x020B\0" \
-   "qspifdtaddr=0x0209\0" \
-   "bootimagesize=0x0140\0" \
+   "qspibootimageaddr=0x020E\0" \
+   "qspifdtaddr=0x020D\0" \
+   "bootimagesize=0x01F0\0" \
"fdtimagesize=0x0001\0" \
"qspiload=sf read ${loadaddr} ${qspibootimageaddr} ${bootimagesize};" \
"sf read ${fdt_addr} ${qspifdtaddr} ${fdtimagesize}\0" \
-- 
1.7.1



Re: Re: [PATCH 013/108] acpi: Add a binding for ACPI settings in the device tree

2020-03-08 Thread Simon Glass
Hi Wolfgang,

On Mon, 3 Feb 2020 at 02:52, Wolfgang Wallner
 wrote:
>
> Hi Simon,
>
> > -"Simon Glass"  schrieb: -
> > Hi Wolfgang,
> >
> > On Fri, 31 Jan 2020 at 01:18, Wolfgang Wallner
> >  wrote:
> > >
> > > Hi Simon,
> > >
> > > > +Devices
> > > > +===
> > > > +
> > > > +Device bindings are described by their own individual binding files.
> > > > +
> > > > +U-Boot provides for some optional properties which are documented here.
> > > > +
> > > > + - acpi,has-power-resource : (boolean) true if this device has a power 
> > > > resource.
> > > > +This causes a PRIC (ACPI PowerResource) to be written containing 
> > > > the
> > > > +properties provided by this binding, to describe how to handle 
> > > > powering the
> > > > +device up and down using GPIOs
> > > > + - acpi,cid : Contains the string to use as the compatible ID (_CID)
> > > > + - acpi,compatible : compatible string to report
> > > > + - acpi,desc : Contains the string to use as the _DDN (DOS (Disk 
> > > > Operating
> > > > +System) Device Name)
> > > > + - acpi,hid : Contains the string to use as the HID (Human Interface 
> > > > Device)
> > > > +identifier _HID
> > >
> > > Nit: "_HID" in ACPI stands for "Hardware ID"
> >
> > OK thank you, will fix. I am trying to write things out in full since
> > it is very hard to find out what all these different things mean.
>
> I appreciate that, it makes it easier for to follow the text.
>
> > > > + - acpi,hid-desc-reg-offset : HID register offset (for Human Interface 
> > > > Devices)
> > > > + - acpi,probed : Tells U-Boot to add 'linux,probed' to the ACPI tables 
> > > > so that
> > > > +Linux will not re-init the device
> > > > + - acpi,uid : _UID value for device
> > >
> > > Would it make sense to automatically infer ACPI properties from existing
> > > device tree properties?
> > >
> > > E.g. if the compatible string contains "hid-over-i2c", then _CID could be 
> > > set
> > > to "PNP0C50".
> >
> > Yes we could do that. So is that true for all devices that use this i2c 
> > driver?
>
> As far as I understand the ids "PNP0C50" and "hid-over-i2c" serve the same
> purpose, just in two different description languages.
>
> Devicetree: If an I2C over HID device is described in Devicetree, it should
> have a compatible string of "hid-over-i2c" (see [1] for details).
>
> ACPI:   If an I2C over HID device is described in ACPI, it should have a
> _CID of "PNP0C50" (See [2] for details).
>
> [1] 
> https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/input/hid-over-i2c.txt
> [2] 
> https://docs.microsoft.com/en-us/windows-hardware/drivers/hid/plug-and-play-support-and-power-management
>
> As both identifiers are standardized, I think we could infer one from the
> other.
>
> I'm not sure whether inferring ACPI-properties from Devicetree properties is
> worth it, but I wanted to bring up the idea for discussion as adding new
> properties for someting where we already have something similar feels
> redundant.
>
> > > And a "hid-over-i2c" device would also have a "hid-descr-addr" device tree
> > > property for the offset of the HID descriptor register which could be 
> > > passed
> > > on in ACPI as part of the _DSM method.
> >
> > Are you suggesting renaming acpi,hid-desc-reg-offset to hid-descr-addr?
>
> An ACPI "PNP0C50"-device has a _DSM (Device Specific Method) which provides 
> the
> HID descriptor offset (for UUID "3CDFF6F7-4267-4555-AD05-B30A3D8938DE").
>
> A Devicetree "hid-over-i2c"-device has a property "hid-descr-addr" which
> provides the HID descriptor offset.
>
> So instead of adding a new "acpi,hid-desc-reg-offset" I think we could also
> use the existing "hid-descr-addr" property.

OK I've updated that in v2.

>
> Interrupts are another topic that need to be described in both worlds:
>
>   Devicetree: "interrupts"-property
>   ACPI:   "_CRS"-method (Current Resource Settings)
>
> Maybe we could also infer that description too?

It might be possible, I think. If we do that we'll need to document it
somewhere. But CRS does have multiple GPIOs sometimes, so I'm not sure
if we would want to scan the DT node and add all of those to the CRS?
In any case this is something we can refine later since it doesn't
affect the binding.

Regards,
Simon


Re: [PATCH 005/108] tpm: cr50: Use the correct GPIO binding

2020-03-08 Thread Simon Glass
Hi Bin,

On Sat, 8 Feb 2020 at 07:53, Bin Meng  wrote:
>
> On Mon, Jan 27, 2020 at 1:08 PM Simon Glass  wrote:
> >
> > This device should use ready-gpios rather than ready-gpio. Fix it.
>
> Where does this requirement come from? Is this coming from the Linux
> kernel bindings?

Yes it seems to be the way things are done in Linux.

>
> >
> > Signed-off-by: Simon Glass 
> > ---
> >
> >  arch/x86/dts/chromebook_coral.dts   | 2 +-
> >  doc/device-tree-bindings/gpio/intel,apl-gpio.txt| 2 +-
> >  .../interrupt-controller/intel,acpi-gpe.txt | 2 +-
> >  drivers/tpm/cr50_i2c.c  | 2 +-
> >  4 files changed, 4 insertions(+), 4 deletions(-)
> >
>
> Reviewed-by: Bin Meng 

Regards,
Simon


RE: [PATCH] ARM: socfpga: Enable DM RTC bootcount on ABB SECU1

2020-03-08 Thread Tan, Ley Foon



> -Original Message-
> From: Marek Vasut 
> Sent: Saturday, March 7, 2020 4:52 AM
> To: u-boot@lists.denx.de
> Cc: Marek Vasut ; Tan, Ley Foon
> ; Simon Goldschmidt
> 
> Subject: [PATCH] ARM: socfpga: Enable DM RTC bootcount on ABB SECU1
> 
> Add and enable RTC-backed boot counter on ABB SECU1 platform.
> 
> Signed-off-by: Marek Vasut 
> Cc: Ley Foon Tan 
> Cc: Simon Goldschmidt 

Reviewed-by: Ley Foon Tan 

Regards
Ley Foon


RE: [PATCH 3/3] mmc: Kconfig: remove MMC_BROKEN_CD configuration

2020-03-08 Thread Peng Fan
Hi Jaehoon,

> Subject: [PATCH 3/3] mmc: Kconfig: remove MMC_BROKEN_CD configuration
> 
> Remove MMC_BROKEN_CD configuration.
> It doesn't need to use configuration, instead use broken-cd property.

Will this cause issue if board not use dts saying in SPL stage?

Regards,
Peng.

> 
> Signed-off-by: Jaehoon Chung 
> ---
>  configs/brppt2_defconfig| 1 -
>  configs/ci20_mmc_defconfig  | 1 -
>  configs/meerkat96_defconfig | 1 -
>  drivers/mmc/Kconfig | 5 -
>  4 files changed, 8 deletions(-)
> 
> diff --git a/configs/brppt2_defconfig b/configs/brppt2_defconfig index
> f94ea28376..5d1dfde36e 100644
> --- a/configs/brppt2_defconfig
> +++ b/configs/brppt2_defconfig
> @@ -68,7 +68,6 @@ CONFIG_SPL_DM_SEQ_ALIAS=y  # CONFIG_SPL_BLK is
> not set  CONFIG_BOOTCOUNT_LIMIT=y  CONFIG_SYS_I2C_MXC=y
> -CONFIG_MMC_BROKEN_CD=y  # CONFIG_SPL_DM_MMC is not set
> CONFIG_FSL_ESDHC=y  CONFIG_MTD=y diff --git
> a/configs/ci20_mmc_defconfig b/configs/ci20_mmc_defconfig index
> a0b0772f40..f31a3c44f4 100644
> --- a/configs/ci20_mmc_defconfig
> +++ b/configs/ci20_mmc_defconfig
> @@ -34,7 +34,6 @@ CONFIG_SYS_RELOC_GD_ENV_ADDR=y  #
> CONFIG_DM_DEVICE_REMOVE is not set  CONFIG_JZ4780_EFUSE=y
> CONFIG_MMC=y -CONFIG_MMC_BROKEN_CD=y  CONFIG_DM_MMC=y  #
> CONFIG_MMC_HW_PARTITIONING is not set
> CONFIG_MMC_IO_VOLTAGE=y diff --git a/configs/meerkat96_defconfig
> b/configs/meerkat96_defconfig index 45f12115ba..d358ed23a5 100644
> --- a/configs/meerkat96_defconfig
> +++ b/configs/meerkat96_defconfig
> @@ -34,7 +34,6 @@ CONFIG_OF_CONTROL=y
>  CONFIG_DEFAULT_DEVICE_TREE="imx7d-meerkat96"
>  CONFIG_SYS_RELOC_GD_ENV_ADDR=y
>  CONFIG_NET_RANDOM_ETHADDR=y
> -CONFIG_MMC_BROKEN_CD=y
>  CONFIG_DM_MMC=y
>  CONFIG_FSL_ESDHC=y
>  CONFIG_MTD=y
> diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig index
> 2f0eedc22f..3722e7bc13 100644
> --- a/drivers/mmc/Kconfig
> +++ b/drivers/mmc/Kconfig
> @@ -18,11 +18,6 @@ config MMC_WRITE
>   help
> Enable write access to MMC and SD Cards
> 
> -config MMC_BROKEN_CD
> - bool "Poll for broken card detection case"
> - help
> -   If card  detection feature is broken, just poll to detect.
> -
>  config DM_MMC
>   bool "Enable MMC controllers using Driver Model"
>   depends on DM
> --
> 2.25.0



[PATCH 2/2] timer: sti: use clk API to get timer clock rate

2020-03-08 Thread Nicolas Heemeryck
Retrieve clock rate through device tree. This mimics the behavior of
arm_global_timer in Linux.

Signed-off-by: Nicolas Heemeryck 
---
 drivers/timer/sti-timer.c | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/timer/sti-timer.c b/drivers/timer/sti-timer.c
index eac22ae39b..123fac04a9 100644
--- a/drivers/timer/sti-timer.c
+++ b/drivers/timer/sti-timer.c
@@ -6,6 +6,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -41,14 +42,22 @@ static int sti_timer_probe(struct udevice *dev)
 {
struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
struct sti_timer_priv *priv = dev_get_priv(dev);
-
-   uc_priv->clock_rate = CONFIG_SYS_HZ_CLOCK;
+   struct clk clk;
+   int ret;
 
/* get arm global timer base address */
priv->global_timer = (struct globaltimer *)dev_read_addr_ptr(dev);
if (!priv->global_timer)
return -ENOENT;
 
+   ret = clk_get_by_index(dev, 0, &clk);
+   if (ret)
+   return ret;
+
+   uc_priv->clock_rate = clk_get_rate(&clk);
+   if (!uc_priv->clock_rate)
+   return -EINVAL;
+
/* init timer */
writel(0x01, &priv->global_timer->ctl);
 
-- 
2.20.1



[PATCH 1/2] timer: sti: convert to livetree

2020-03-08 Thread Nicolas Heemeryck
Update STI timer to support a live tree

Signed-off-by: Nicolas Heemeryck 
---
 drivers/timer/sti-timer.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/timer/sti-timer.c b/drivers/timer/sti-timer.c
index 9def7e02f4..eac22ae39b 100644
--- a/drivers/timer/sti-timer.c
+++ b/drivers/timer/sti-timer.c
@@ -6,14 +6,11 @@
 
 #include 
 #include 
-#include 
 #include 
 
 #include 
 #include 
 
-DECLARE_GLOBAL_DATA_PTR;
-
 struct sti_timer_priv {
struct globaltimer *global_timer;
 };
@@ -44,13 +41,13 @@ static int sti_timer_probe(struct udevice *dev)
 {
struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
struct sti_timer_priv *priv = dev_get_priv(dev);
-   fdt_addr_t addr;
 
uc_priv->clock_rate = CONFIG_SYS_HZ_CLOCK;
 
/* get arm global timer base address */
-   addr = fdtdec_get_addr(gd->fdt_blob, dev_of_offset(dev), "reg");
-   priv->global_timer = (struct globaltimer *)addr;
+   priv->global_timer = (struct globaltimer *)dev_read_addr_ptr(dev);
+   if (!priv->global_timer)
+   return -ENOENT;
 
/* init timer */
writel(0x01, &priv->global_timer->ctl);
-- 
2.20.1



[PATCH 0/2] timer: sti: mimic Linux declaration and usage

2020-03-08 Thread Nicolas Heemeryck
This series update the sti-timer for cortex-a9 CPU (arm global timer) to mimic
the behavior presents in Linux.
Therefor, the same device tree node can be use for U-Boot and Linux.

Nicolas Heemeryck (2):
  timer: sti: convert to livetree
  timer: sti: use clk API to get timer clock rate

 drivers/timer/sti-timer.c | 22 ++
 1 file changed, 14 insertions(+), 8 deletions(-)

-- 
2.20.1



Re: [PATCH 03/18] clk: imx: clk-imxrt1050: setup PLL5 for video in non-SPL

2020-03-08 Thread Giulio Benetti

Hi Lukasz,

On 3/8/20 9:27 PM, Lukasz Majewski wrote:

On Wed, 26 Feb 2020 18:15:46 +0100
Giulio Benetti  wrote:


mxsfb needs PLL5 as source, so let's setup it and set it as source for
mxsfb(lcdif).

Signed-off-by: Giulio Benetti 
---
  drivers/clk/imx/clk-imxrt1050.c | 13 -
  1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/imx/clk-imxrt1050.c
b/drivers/clk/imx/clk-imxrt1050.c index e33d426363..2819ffb9ac 100644
--- a/drivers/clk/imx/clk-imxrt1050.c
+++ b/drivers/clk/imx/clk-imxrt1050.c
@@ -238,9 +238,9 @@ static int imxrt1050_clk_probe(struct udevice
*dev) clk_dm(IMXRT1050_CLK_LCDIF,
   imx_clk_gate2("lcdif", "lcdif_podf", base + 0x70,
28));
-#ifdef CONFIG_SPL_BUILD
struct clk *clk, *clk1;
  
+#ifdef CONFIG_SPL_BUILD

/* bypass pll1 before setting its rate */
clk_get_by_id(IMXRT1050_CLK_PLL1_REF_SEL, &clk);
clk_get_by_id(IMXRT1050_CLK_PLL1_BYPASS, &clk1);
@@ -271,7 +271,18 @@ static int imxrt1050_clk_probe(struct udevice
*dev)
clk_get_by_id(IMXRT1050_CLK_PLL3_BYPASS, &clk1);
clk_set_parent(clk1, clk);
+#else
+   /* Set PLL5 for LCDIF to its default 650Mhz */
+   clk_get_by_id(IMXRT1050_CLK_PLL5_VIDEO, &clk);
+   clk_enable(clk);
+   clk_set_rate(clk, 65000UL);
+
+   clk_get_by_id(IMXRT1050_CLK_PLL5_BYPASS, &clk1);
+   clk_set_parent(clk1, clk);
  
+	/* Configure PLL5 as LCDIF source */

+   clk_get_by_id(IMXRT1050_CLK_LCDIF_SEL, &clk1);
+   clk_set_parent(clk1, clk);


As pointed by Fabio, this ^^^ should be substituted with a using 
assigned-parent-clocks in dts instead of being hardcoded here.

What do you think about it?

Thanks for reviewing and
best regards
--
Giulio Benetti
Benetti Engineering sas


  #endif
  
  	return 0;


Reviewed-by: Lukasz Majewski 


Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lu...@denx.de





[PATCH] ARM: dts: rmobile: Enable eMMC DDR52 modes on Gen3 Salvator-X(S), ULCB, Ebisu

2020-03-08 Thread Marek Vasut
Enable DDR52 modes, since the SD core supports correct switching now.
For completeness, list HS200 modes, however those were already enabled.

Signed-off-by: Marek Vasut 
Cc: Nobuhiro Iwamatsu 
---
 arch/arm/dts/r8a7795-h3ulcb-u-boot.dts  | 2 ++
 arch/arm/dts/r8a7795-salvator-x-u-boot.dts  | 2 ++
 arch/arm/dts/r8a7796-m3ulcb-u-boot.dts  | 2 ++
 arch/arm/dts/r8a7796-salvator-x-u-boot.dts  | 2 ++
 arch/arm/dts/r8a77965-m3nulcb-u-boot.dts| 2 ++
 arch/arm/dts/r8a77965-salvator-x-u-boot.dts | 2 ++
 arch/arm/dts/r8a77990-ebisu.dts | 1 +
 7 files changed, 13 insertions(+)

diff --git a/arch/arm/dts/r8a7795-h3ulcb-u-boot.dts 
b/arch/arm/dts/r8a7795-h3ulcb-u-boot.dts
index f1b9c53fd2..aa2e276719 100644
--- a/arch/arm/dts/r8a7795-h3ulcb-u-boot.dts
+++ b/arch/arm/dts/r8a7795-h3ulcb-u-boot.dts
@@ -32,6 +32,8 @@
 };
 
 &sdhi2 {
+   mmc-ddr-1_8v;
+   mmc-hs200-1_8v;
mmc-hs400-1_8v;
max-frequency = <2>;
 };
diff --git a/arch/arm/dts/r8a7795-salvator-x-u-boot.dts 
b/arch/arm/dts/r8a7795-salvator-x-u-boot.dts
index 3f2bc76e7f..2f6c1cb0f7 100644
--- a/arch/arm/dts/r8a7795-salvator-x-u-boot.dts
+++ b/arch/arm/dts/r8a7795-salvator-x-u-boot.dts
@@ -21,6 +21,8 @@
 };
 
 &sdhi2 {
+   mmc-ddr-1_8v;
+   mmc-hs200-1_8v;
mmc-hs400-1_8v;
max-frequency = <2>;
 };
diff --git a/arch/arm/dts/r8a7796-m3ulcb-u-boot.dts 
b/arch/arm/dts/r8a7796-m3ulcb-u-boot.dts
index 7887bce32c..a0f239ee69 100644
--- a/arch/arm/dts/r8a7796-m3ulcb-u-boot.dts
+++ b/arch/arm/dts/r8a7796-m3ulcb-u-boot.dts
@@ -32,6 +32,8 @@
 };
 
 &sdhi2 {
+   mmc-ddr-1_8v;
+   mmc-hs200-1_8v;
mmc-hs400-1_8v;
max-frequency = <2>;
 };
diff --git a/arch/arm/dts/r8a7796-salvator-x-u-boot.dts 
b/arch/arm/dts/r8a7796-salvator-x-u-boot.dts
index 62ad15f1bb..cff48f3665 100644
--- a/arch/arm/dts/r8a7796-salvator-x-u-boot.dts
+++ b/arch/arm/dts/r8a7796-salvator-x-u-boot.dts
@@ -21,6 +21,8 @@
 };
 
 &sdhi2 {
+   mmc-ddr-1_8v;
+   mmc-hs200-1_8v;
mmc-hs400-1_8v;
max-frequency = <2>;
 };
diff --git a/arch/arm/dts/r8a77965-m3nulcb-u-boot.dts 
b/arch/arm/dts/r8a77965-m3nulcb-u-boot.dts
index 5798747d02..0c0b35c4cf 100644
--- a/arch/arm/dts/r8a77965-m3nulcb-u-boot.dts
+++ b/arch/arm/dts/r8a77965-m3nulcb-u-boot.dts
@@ -33,6 +33,8 @@
 };
 
 &sdhi2 {
+   mmc-ddr-1_8v;
+   mmc-hs200-1_8v;
mmc-hs400-1_8v;
max-frequency = <2>;
status = "okay";
diff --git a/arch/arm/dts/r8a77965-salvator-x-u-boot.dts 
b/arch/arm/dts/r8a77965-salvator-x-u-boot.dts
index d61b2367d3..8cbef83b9c 100644
--- a/arch/arm/dts/r8a77965-salvator-x-u-boot.dts
+++ b/arch/arm/dts/r8a77965-salvator-x-u-boot.dts
@@ -22,6 +22,8 @@
 };
 
 &sdhi2 {
+   mmc-ddr-1_8v;
+   mmc-hs200-1_8v;
mmc-hs400-1_8v;
max-frequency = <2>;
status = "okay";
diff --git a/arch/arm/dts/r8a77990-ebisu.dts b/arch/arm/dts/r8a77990-ebisu.dts
index c727725899..21f2d57dc0 100644
--- a/arch/arm/dts/r8a77990-ebisu.dts
+++ b/arch/arm/dts/r8a77990-ebisu.dts
@@ -741,6 +741,7 @@
 
vmmc-supply = <®_3p3v>;
vqmmc-supply = <®_1p8v>;
+   mmc-ddr-1_8v;
mmc-hs200-1_8v;
mmc-hs400-1_8v;
bus-width = <8>;
-- 
2.25.0



Re: [PATCH 01/18] clk: imx: pllv3: add enable_bit

2020-03-08 Thread Lukasz Majewski
On Wed, 26 Feb 2020 18:15:44 +0100
Giulio Benetti  wrote:

> pllv3 PLLs have powerdown/up bits but enable bits too. Specifically
> "enable bit" enable the pll output, so when dis/enabling pll by
> setting/clearing power_bit we must also set/clear enable_bit.
> 
> Signed-off-by: Giulio Benetti 
> ---
>  drivers/clk/imx/clk-pllv3.c | 9 +
>  1 file changed, 9 insertions(+)
> 
> diff --git a/drivers/clk/imx/clk-pllv3.c b/drivers/clk/imx/clk-pllv3.c
> index 525442debf..b4a9d587e1 100644
> --- a/drivers/clk/imx/clk-pllv3.c
> +++ b/drivers/clk/imx/clk-pllv3.c
> @@ -25,6 +25,7 @@
>  #define PLL_DENOM_OFFSET 0x20
>  
>  #define BM_PLL_POWER (0x1 << 12)
> +#define BM_PLL_ENABLE(0x1 << 13)
>  #define BM_PLL_LOCK  (0x1 << 31)
>  
>  struct clk_pllv3 {
> @@ -32,6 +33,7 @@ struct clk_pllv3 {
>   void __iomem*base;
>   u32 power_bit;
>   boolpowerup_set;
> + u32 enable_bit;
>   u32 div_mask;
>   u32 div_shift;
>  };
> @@ -83,6 +85,9 @@ static int clk_pllv3_generic_enable(struct clk *clk)
>   val |= pll->power_bit;
>   else
>   val &= ~pll->power_bit;
> +
> + val |= pll->enable_bit;
> +
>   writel(val, pll->base);
>  
>   return 0;
> @@ -98,6 +103,9 @@ static int clk_pllv3_generic_disable(struct clk
> *clk) val &= ~pll->power_bit;
>   else
>   val |= pll->power_bit;
> +
> + val &= ~pll->enable_bit;
> +
>   writel(val, pll->base);
>  
>   return 0;
> @@ -238,6 +246,7 @@ struct clk *imx_clk_pllv3(enum imx_pllv3_type
> type, const char *name, return ERR_PTR(-ENOMEM);
>  
>   pll->power_bit = BM_PLL_POWER;
> + pll->enable_bit = BM_PLL_ENABLE;
>  
>   switch (type) {
>   case IMX_PLLV3_GENERIC:

Reviewed-by: Lukasz Majewski 


Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lu...@denx.de


pgpRHHPBrXQDQ.pgp
Description: OpenPGP digital signature


Re: [PATCH 03/18] clk: imx: clk-imxrt1050: setup PLL5 for video in non-SPL

2020-03-08 Thread Lukasz Majewski
On Wed, 26 Feb 2020 18:15:46 +0100
Giulio Benetti  wrote:

> mxsfb needs PLL5 as source, so let's setup it and set it as source for
> mxsfb(lcdif).
> 
> Signed-off-by: Giulio Benetti 
> ---
>  drivers/clk/imx/clk-imxrt1050.c | 13 -
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/clk/imx/clk-imxrt1050.c
> b/drivers/clk/imx/clk-imxrt1050.c index e33d426363..2819ffb9ac 100644
> --- a/drivers/clk/imx/clk-imxrt1050.c
> +++ b/drivers/clk/imx/clk-imxrt1050.c
> @@ -238,9 +238,9 @@ static int imxrt1050_clk_probe(struct udevice
> *dev) clk_dm(IMXRT1050_CLK_LCDIF,
>  imx_clk_gate2("lcdif", "lcdif_podf", base + 0x70,
> 28)); 
> -#ifdef CONFIG_SPL_BUILD
>   struct clk *clk, *clk1;
>  
> +#ifdef CONFIG_SPL_BUILD
>   /* bypass pll1 before setting its rate */
>   clk_get_by_id(IMXRT1050_CLK_PLL1_REF_SEL, &clk);
>   clk_get_by_id(IMXRT1050_CLK_PLL1_BYPASS, &clk1);
> @@ -271,7 +271,18 @@ static int imxrt1050_clk_probe(struct udevice
> *dev) 
>   clk_get_by_id(IMXRT1050_CLK_PLL3_BYPASS, &clk1);
>   clk_set_parent(clk1, clk);
> +#else
> + /* Set PLL5 for LCDIF to its default 650Mhz */
> + clk_get_by_id(IMXRT1050_CLK_PLL5_VIDEO, &clk);
> + clk_enable(clk);
> + clk_set_rate(clk, 65000UL);
> +
> + clk_get_by_id(IMXRT1050_CLK_PLL5_BYPASS, &clk1);
> + clk_set_parent(clk1, clk);
>  
> + /* Configure PLL5 as LCDIF source */
> + clk_get_by_id(IMXRT1050_CLK_LCDIF_SEL, &clk1);
> + clk_set_parent(clk1, clk);
>  #endif
>  
>   return 0;

Reviewed-by: Lukasz Majewski 


Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lu...@denx.de


pgpRwbxpxYLQI.pgp
Description: OpenPGP digital signature


Re: [PATCH 02/18] clk: imx: imxrt1050-clk: fix typo in clock name "video:"

2020-03-08 Thread Lukasz Majewski
On Wed, 26 Feb 2020 18:15:45 +0100
Giulio Benetti  wrote:

> "video:" must be "video", ":" is a typo.
> 
> Signed-off-by: Giulio Benetti 
> ---
>  drivers/clk/imx/clk-imxrt1050.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/clk/imx/clk-imxrt1050.c
> b/drivers/clk/imx/clk-imxrt1050.c index 44ca52c013..e33d426363 100644
> --- a/drivers/clk/imx/clk-imxrt1050.c
> +++ b/drivers/clk/imx/clk-imxrt1050.c
> @@ -90,7 +90,7 @@ static const char *const usdhc_sels[] = {
> "pll2_pfd2_396m", "pll2_pfd0_352m", }; static const char *const
> lpuart_sels[] = { "pll3_80m", "osc", }; static const char *const
> semc_alt_sels[] = { "pll2_pfd2_396m", "pll3_pfd1_664_62m", }; static
> const char *const semc_sels[] = { "periph_sel", "semc_alt_sel", };
> -static const char *const lcdif_sels[] = { "pll2_sys",
> "pll3_pfd3_454_74m", "pll5_video:", "pll2_pfd0_352m",
> "pll2_pfd1_594m", "pll3_pfd1_664_62m"}; +static const char *const
> lcdif_sels[] = { "pll2_sys", "pll3_pfd3_454_74m", "pll5_video",
> "pll2_pfd0_352m", "pll2_pfd1_594m", "pll3_pfd1_664_62m"}; static int
> imxrt1050_clk_probe(struct udevice *dev) {

Reviewed-by: Lukasz Majewski 


Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lu...@denx.de


pgpbZ7NQ7wz6m.pgp
Description: OpenPGP digital signature


Re: [RFT PATCH v5 3/3] image: Add compressed Image parsing support in booti.

2020-03-08 Thread Atish Patra
On Fri, Mar 6, 2020 at 6:59 AM Tom Rini  wrote:
>
> On Thu, Mar 05, 2020 at 04:24:23PM -0800, Atish Patra wrote:
> > Add compressed Image parsing support so that booti can parse both
> > flat and compressed Image to boot Linux. Currently, it is difficult
> > to calculate a safe address for every board where the compressed
> > image can be decompressed. It is also not possible to figure out the
> > size of the compressed file as well. Thus, user need to set two
> > additional environment variables kernel_comp_addr_r and filesize to
> > make this work.
> >
> > Following compression methods are supported for now.
> > lzma, lzo, bzip2, gzip.
> >
> > lz4 support is not added as ARM64 kernel generates a lz4 compressed
> > image with legacy header which U-Boot doesn't know how to parse and
> > decompress.
>
> Is that a "legacy lz4 header" or something else?  Thanks!
>

Yeah. I was talking about legacy lz4 header as per U-Boot documentation.


> --
> Tom



--
Regards,
Atish


Re: [PATCH] image.h: isolate android_image_* functions from tooling

2020-03-08 Thread Heinrich Schuchardt

On 3/8/20 1:11 AM, Eugeniu Rosca wrote:

On Feb. 16, 2020, Tom reported [1] build failure of U-Boot in-tree
tooling after applying https://patchwork.ozlabs.org/cover/1229663/
("[v6,0/7] rsa: extend rsa_verify() for UEFI secure boot").

Later on, Heinrich stressed the urgency of the issue in
https://patchwork.ozlabs.org/patch/1250858/#2379069:

  >
  We should finalize the topic as it stops EFI patches from being merged
  >

On the surface, the problem is caused by U-Boot commits [2-3], which
employed 'u32' in 'include/image.h', while historically U-Boot tooling
stayed agnostic on the {u,s}{8,16,32} types.

Thanks to Tom, Yamada-san and Heinrich, the following solutions have
been put head-to-head ('+' pros, '-' cons):

  A. Use an equivalent fixed-size type, i.e. s/u32/uint32_t/ in both
 android function prototypes (image.h) and definitions (c file):
 + quick and low-line-count
 - creates a 'soup' of fixed-sized types in the Android C file
 - will confuse contributors
 - is going against Linux kernel best practices [4]

  B. Guard Android functions by '!defined(USE_HOSTCC)' in image.h:
 + quick and low-line-count
 + reflects the reality (no android function is used by tooling)
 + zero impact on other subsystems
 - ifdeffery may look annoying (pre-existing problem of image.h)

  C. Make {u8,u16,u32} available in U-Boot tooling:
 + quick and low-line-count
 + [Yamada-san][5]:
   * forbidding u32 for tools is questionable to me
   * Linux kernel and Barebox use {u8,u16,u32} for the tools space
 - breaks U-Boot tradition?
 - has larger impact than [A] and [B]
 - adds type complexity/inconsistency in the tooling space

  D. [Yamada-san] Refactor the headers to minimize the code shared
 between U-Boot space and tooling space:
 + probably the long-term solution
 - high effort
 - can be seen/done as an incremental update on top of [B]

Looking at the above, [B] looks like the natural way to go forward.

[1] https://patchwork.ozlabs.org/patch/1238245/#2363052
[2] commit 7f2531502c74c0 ("image: android: Add routine to get dtbo params")
[3] commit c3bfad825a71ea ("image: android: Add functions for handling dtb 
field")
[4] 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=e6176fa4728fb6d
 ("checkpatch: add --strict warning for c99 fixed size typedefs : 
int_t")
[5] https://patchwork.ozlabs.org/patch/1238245/#2363340

Cc: Masahiro Yamada 
Cc: Heinrich Schuchardt 
Cc: Sam Protsenko 
Cc: Lokesh Vutla 
Cc: Simon Glass 
Cc: AKASHI Takahiro 
Reported-by: Tom Rini 
Signed-off-by: Eugeniu Rosca 


The patch is sufficient to overcome the build errors occurring with
Takahiro's RSA and secure boot patches.
https://patchwork.ozlabs.org/project/uboot/list/?series=&submitter=61166

Tested-by: Heinrich Schuchardt 


Re: AXP813 configuration for BananaPi M3

2020-03-08 Thread Vagrant Cascadian
On 2020-03-08, Bernhard wrote:
> I had an additional look for the possible problem with the AXP813 for 
> BananaPi M3 in U-Boot.
> With help of Google, i found a patchset for U-Boot from 2016:
>
> https://lists.denx.de/pipermail/u-boot/2016-January/240259.html
>
>> +++ b/configs/Bananapi_m3_defconfig
>> @@ -0,0 +1,25 @@
>> +CONFIG_ARM=y
>> +CONFIG_ARCH_SUNXI=y
>> +CONFIG_MACH_SUN8I_A83T=y
>> +CONFIG_DRAM_CLK=480
>> +CONFIG_DRAM_ZQ=15355
>> +CONFIG_DRAM_ODT_EN=y
>> +CONFIG_SYS_EXTRA_OPTIONS="DRAM_TYPE=7"
>> +#CONFIG_USB0_VBUS_PIN="AXP0-VBUS-ENABLE"
>> +#CONFIG_USB0_VBUS_DET="AXP0-VBUS-DETECT"
>> +CONFIG_AXP_GPIO=y
>> +#CONFIG_USB_MUSB_HOST=y
>> +CONFIG_DEFAULT_DEVICE_TREE="sun8i-a83t-bananapi-m3-v1.2"
>> +# CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
>> +CONFIG_SPL=y
>> +# CONFIG_CMD_IMLS is not set
>> +# CONFIG_CMD_FLASH is not set
>> +# CONFIG_CMD_FPGA is not set
>> +CONFIG_AXP_DCDC1_VOLT=3000
>> +CONFIG_AXP_DCDC2_VOLT=900
>> +CONFIG_AXP_DCDC3_VOLT=900
>> +CONFIG_AXP_DCDC4_VOLT=0
>> +CONFIG_AXP_DCDC5_VOLT=1200
>> +CONFIG_AXP_ALDO2_VOLT=0
>> +CONFIG_AXP_ALDO3_VOLT=0
>> +CONFIG_AXP_DLDO4_VOLT=0
>> -- 
>
> In the Debian configuration, i found the following:
>
>> CONFIG_ARM=y
>> CONFIG_ARCH_SUNXI=y
>> CONFIG_NR_DRAM_BANKS=1
>> CONFIG_SPL=y
>> CONFIG_MACH_SUN8I_A83T=y
>> CONFIG_DRAM_TYPE=7
>> CONFIG_DRAM_CLK=480
>> CONFIG_DRAM_ZQ=15355
>> CONFIG_DRAM_ODT_EN=y
>> CONFIG_MMC_SUNXI_SLOT_EXTRA=2
>> CONFIG_INITIAL_USB_SCAN_DELAY=500
>> CONFIG_USB0_VBUS_PIN="AXP0-VBUS-ENABLE"
>> CONFIG_USB0_VBUS_DET="AXP0-VBUS-DETECT"
>> CONFIG_USB0_ID_DET="PH11"
>> CONFIG_USB1_VBUS_PIN="PD24"
>> CONFIG_AXP_GPIO=y
>> CONFIG_SATAPWR="PD25"
>> # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
>> CONFIG_USE_PREBOOT=y
>> CONFIG_CONSOLE_MUX=y
>> # CONFIG_SPL_DOS_PARTITION is not set
>> # CONFIG_SPL_EFI_PARTITION is not set
>> CONFIG_DEFAULT_DEVICE_TREE="sun8i-a83t-bananapi-m3"
>> CONFIG_SYS_RELOC_GD_ENV_ADDR=y
>> CONFIG_PHY_REALTEK=y
>> CONFIG_SUN8I_EMAC=y
>> CONFIG_AXP_DCDC5_VOLT=1200
>> CONFIG_AXP_DLDO3_VOLT=3300
>> CONFIG_AXP_SW_ON=y
>> CONFIG_USB_EHCI_HCD=y
>> CONFIG_USB_OHCI_HCD=y
>> CONFIG_USB_MUSB_HOST=y
>> CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE=y

I presume this is configs/Sinovoip_BPI_M3_defconfig ?


> Some CONFIG_AXP_... are missing in the Debian configuration.
> Is it possible, that these missing AXP-configs have to be added in the Debian 
> configuration?
>
> If i can do some tests, please let me know.

Debian doesn't have any patches that should affect this; CCing
upstream. Hopefully someone there has some suggestions or ideas.


live well,
  vagrant


signature.asc
Description: PGP signature


[PATCH v2] ARM: dts: stm32mp1: DT alignment with Linux 5.6-rc1

2020-03-08 Thread Patrick Delaunay
This commit manages diversity for STM32M15x SOCs with:
- dedicated files to support all STM32MP15 SOCs family.
  The differences between those SOCs are:
  -STM32MP151 [1]: common file.
  -STM32MP153 [2]: STM32MP151 + CANs + a second CortexA7-CPU.
  -STM32MP157 [3]: STM32MP153 + DSI + GPU.
- new files to manage security diversity on STM32MP15x SOCs.
  On STM32MP15xY, "Y" gives information:
  -Y = A means no cryp IP and no secure boot.
  -Y = C means cryp IP + secure boot.
- stm32mp157 pinctrl files to better manage package diversity.

Signed-off-by: Patrick Delaunay 
---

Changes in v2:
- rename "stm32mp157-u-boot.dtsi" to "stm32mp15-u-boot.dtsi"
  as this file is common for STM32M15x SOCs

 arch/arm/dts/stm32mp15-pinctrl.dtsi   | 1114 +
 ...p157-u-boot.dtsi => stm32mp15-u-boot.dtsi} |0
 .../dts/{stm32mp157c.dtsi => stm32mp151.dtsi} |  274 ++--
 arch/arm/dts/stm32mp153.dtsi  |   45 +
 arch/arm/dts/stm32mp157-pinctrl.dtsi  | 1057 
 arch/arm/dts/stm32mp157.dtsi  |   31 +
 .../arm/dts/stm32mp157a-avenger96-u-boot.dtsi |   11 +-
 arch/arm/dts/stm32mp157a-avenger96.dts|5 +-
 arch/arm/dts/stm32mp157a-dk1-u-boot.dtsi  |7 +-
 arch/arm/dts/stm32mp157a-dk1.dts  |  541 +---
 arch/arm/dts/stm32mp157c-dk2-u-boot.dtsi  |6 -
 arch/arm/dts/stm32mp157c-dk2.dts  |   15 +-
 arch/arm/dts/stm32mp157c-ed1-u-boot.dtsi  |7 +-
 arch/arm/dts/stm32mp157c-ed1.dts  |   22 +-
 arch/arm/dts/stm32mp157c-ev1.dts  |   30 +-
 arch/arm/dts/stm32mp157xaa-pinctrl.dtsi   |   90 --
 arch/arm/dts/stm32mp157xab-pinctrl.dtsi   |   62 -
 arch/arm/dts/stm32mp157xac-pinctrl.dtsi   |   78 --
 arch/arm/dts/stm32mp157xad-pinctrl.dtsi   |   62 -
 arch/arm/dts/stm32mp15xc.dtsi |   18 +
 arch/arm/dts/stm32mp15xx-dhcom-u-boot.dtsi|7 +-
 arch/arm/dts/stm32mp15xx-dhcom.dtsi   |6 +-
 arch/arm/dts/stm32mp15xx-dkx.dtsi |  639 ++
 arch/arm/dts/stm32mp15xxaa-pinctrl.dtsi   |   85 ++
 arch/arm/dts/stm32mp15xxab-pinctrl.dtsi   |   57 +
 arch/arm/dts/stm32mp15xxac-pinctrl.dtsi   |   73 ++
 arch/arm/dts/stm32mp15xxad-pinctrl.dtsi   |   57 +
 27 files changed, 2406 insertions(+), 1993 deletions(-)
 create mode 100644 arch/arm/dts/stm32mp15-pinctrl.dtsi
 rename arch/arm/dts/{stm32mp157-u-boot.dtsi => stm32mp15-u-boot.dtsi} (100%)
 rename arch/arm/dts/{stm32mp157c.dtsi => stm32mp151.dtsi} (89%)
 create mode 100644 arch/arm/dts/stm32mp153.dtsi
 delete mode 100644 arch/arm/dts/stm32mp157-pinctrl.dtsi
 create mode 100644 arch/arm/dts/stm32mp157.dtsi
 delete mode 100644 arch/arm/dts/stm32mp157xaa-pinctrl.dtsi
 delete mode 100644 arch/arm/dts/stm32mp157xab-pinctrl.dtsi
 delete mode 100644 arch/arm/dts/stm32mp157xac-pinctrl.dtsi
 delete mode 100644 arch/arm/dts/stm32mp157xad-pinctrl.dtsi
 create mode 100644 arch/arm/dts/stm32mp15xc.dtsi
 create mode 100644 arch/arm/dts/stm32mp15xx-dkx.dtsi
 create mode 100644 arch/arm/dts/stm32mp15xxaa-pinctrl.dtsi
 create mode 100644 arch/arm/dts/stm32mp15xxab-pinctrl.dtsi
 create mode 100644 arch/arm/dts/stm32mp15xxac-pinctrl.dtsi
 create mode 100644 arch/arm/dts/stm32mp15xxad-pinctrl.dtsi

diff --git a/arch/arm/dts/stm32mp15-pinctrl.dtsi 
b/arch/arm/dts/stm32mp15-pinctrl.dtsi
new file mode 100644
index 00..53df840f85
--- /dev/null
+++ b/arch/arm/dts/stm32mp15-pinctrl.dtsi
@@ -0,0 +1,1114 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
+/*
+ * Copyright (C) STMicroelectronics 2017 - All Rights Reserved
+ * Author: Ludovic Barre  for STMicroelectronics.
+ */
+#include 
+
+&pinctrl {
+   adc1_in6_pins_a: adc1-in6 {
+   pins {
+   pinmux = ;
+   };
+   };
+
+   adc12_ain_pins_a: adc12-ain-0 {
+   pins {
+   pinmux = , /* ADC1 in13 */
+, /* ADC1 in6 */
+, /* ADC2 in2 */
+; /* ADC2 in6 */
+   };
+   };
+
+   adc12_usb_cc_pins_a: adc12-usb-cc-pins-0 {
+   pins {
+   pinmux = , /* ADC12 in18 
*/
+; /* ADC12 in19 
*/
+   };
+   };
+
+   cec_pins_a: cec-0 {
+   pins {
+   pinmux = ;
+   bias-disable;
+   drive-open-drain;
+   slew-rate = <0>;
+   };
+   };
+
+   cec_pins_sleep_a: cec-sleep-0 {
+   pins {
+   pinmux = ; /* HDMI_CEC */
+   };
+   };
+
+   cec_pins_b: cec-1 {
+   pins {
+   pinmux = ;
+   bias-disable;
+   drive-open-drain;
+   slew-rate = <0>;
+   };
+   };
+
+   cec_pins_sleep_b: cec-sleep-1 {
+