summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2021-12-01 19:03:04 +0300
committerSimon Glass <sjg@chromium.org>2022-01-25 21:44:36 +0300
commit2d7c7382969ff2a412acb409e76b2959dd715cc3 (patch)
tree937255d5f3c65de963c652d58ced6794843e3540
parent9d2adca8c3e8d195fa4be5acc8c6dfe14933e826 (diff)
downloadu-boot-2d7c7382969ff2a412acb409e76b2959dd715cc3.tar.xz
acpi: Collect tables in the acpi_item list
At present this list is used to collect items within the DSDT and SSDT tables. It is useful for it to collect the whole tables as well, so there is a list of what was created and which write created each one. Refactor the code accordingly. Signed-off-by: Simon Glass <sjg@chromium.org>
-rw-r--r--drivers/core/acpi.c43
-rw-r--r--include/dm/acpi.h14
-rw-r--r--lib/acpi/acpi_writer.c5
3 files changed, 51 insertions, 11 deletions
diff --git a/drivers/core/acpi.c b/drivers/core/acpi.c
index 5425e4d040..1e2f5d5630 100644
--- a/drivers/core/acpi.c
+++ b/drivers/core/acpi.c
@@ -19,11 +19,19 @@
#define MAX_ACPI_ITEMS 100
-/* Type of table that we collected */
+/**
+ * Type of table that we collected
+ *
+ * @TYPE_NONE: Not yet known
+ * @TYPE_SSDT: Items in the Secondary System Description Table
+ * @TYPE_DSDT: Items in the Differentiated System Description Table
+ * @TYPE_OTHER: Other (whole)
+ */
enum gen_type_t {
TYPE_NONE,
TYPE_SSDT,
TYPE_DSDT,
+ TYPE_OTHER,
};
/* Type of method to call */
@@ -42,11 +50,13 @@ typedef int (*acpi_method)(const struct udevice *dev, struct acpi_ctx *ctx);
*
* @dev: Device that generated this data
* @type: Table type it refers to
+ * @writer: Writer that wrote this table
* @buf: Buffer containing the data
* @size: Size of the data in bytes
*/
struct acpi_item {
struct udevice *dev;
+ const struct acpi_writer *writer;
enum gen_type_t type;
char *buf;
int size;
@@ -103,16 +113,18 @@ int acpi_get_path(const struct udevice *dev, char *out_path, int maxlen)
}
/**
- * acpi_add_item() - Add a new item to the list of data collected
+ * add_item() - Add a new item to the list of data collected
*
* @ctx: ACPI context
- * @dev: Device that generated the data
+ * @dev: Device that generated the data, if type != TYPE_OTHER
+ * @writer: Writer entry that generated the data, if type == TYPE_OTHER
* @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)
+static int add_item(struct acpi_ctx *ctx, struct udevice *dev,
+ const struct acpi_writer *writer, enum gen_type_t type,
+ void *start)
{
struct acpi_item *item;
void *end = ctx->current;
@@ -124,14 +136,17 @@ static int acpi_add_item(struct acpi_ctx *ctx, struct udevice *dev,
item = &acpi_item[item_count];
item->dev = dev;
+ item->writer = writer;
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);
+ if (type != TYPE_OTHER) {
+ 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);
@@ -139,6 +154,12 @@ static int acpi_add_item(struct acpi_ctx *ctx, struct udevice *dev,
return 0;
}
+int acpi_add_other_item(struct acpi_ctx *ctx, const struct acpi_writer *writer,
+ void *start)
+{
+ return add_item(ctx, NULL, writer, TYPE_OTHER, start);
+}
+
void acpi_dump_items(enum acpi_dump_option option)
{
int i;
@@ -162,7 +183,7 @@ static struct acpi_item *find_acpi_item(const char *devname)
for (i = 0; i < item_count; i++) {
struct acpi_item *item = &acpi_item[i];
- if (!strcmp(devname, item->dev->name))
+ if (item->dev && !strcmp(devname, item->dev->name))
return item;
}
@@ -277,7 +298,7 @@ int acpi_recurse_method(struct acpi_ctx *ctx, struct udevice *parent,
/* Add the item to the internal list */
if (type != TYPE_NONE) {
- ret = acpi_add_item(ctx, parent, type, ctx->tab_start);
+ ret = add_item(ctx, parent, NULL, type, ctx->tab_start);
if (ret)
return log_msg_ret("add", ret);
}
diff --git a/include/dm/acpi.h b/include/dm/acpi.h
index 815a887ae4..3adfe21767 100644
--- a/include/dm/acpi.h
+++ b/include/dm/acpi.h
@@ -263,6 +263,20 @@ int acpi_inject_dsdt(struct acpi_ctx *ctx);
int acpi_setup_nhlt(struct acpi_ctx *ctx, struct nhlt *nhlt);
/**
+ * acpi_add_other_item() - Add a new table to the list of ACPI tables
+ *
+ * This adds an entry of type ACPIT_TYPE_OTHER
+ *
+ * @ctx: ACPI context
+ * @writer: Writer entry 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
+ */
+int acpi_add_other_item(struct acpi_ctx *ctx, const struct acpi_writer *writer,
+ void *start);
+
+/**
* acpi_dump_items() - Dump out the collected ACPI items
*
* This lists the ACPI DSDT and SSDT items generated by the various U-Boot
diff --git a/lib/acpi/acpi_writer.c b/lib/acpi/acpi_writer.c
index 9b0aa23fd7..946f90e8e7 100644
--- a/lib/acpi/acpi_writer.c
+++ b/lib/acpi/acpi_writer.c
@@ -40,6 +40,11 @@ int acpi_write_one(struct acpi_ctx *ctx, const struct acpi_writer *entry)
else
acpi_align(ctx);
+ /* Add the item to the internal list */
+ ret = acpi_add_other_item(ctx, entry, ctx->tab_start);
+ if (ret)
+ return log_msg_ret("add", ret);
+
return 0;
}