acpi_test1: acpi-test {
compatible = "denx,u-boot-acpi-test";
acpi-ssdt-test-data = "ab";
+ acpi-dsdt-test-data = "hi";
child {
compatible = "denx,u-boot-acpi-test";
};
acpi_test2: acpi-test2 {
compatible = "denx,u-boot-acpi-test";
acpi-ssdt-test-data = "cd";
+ acpi-dsdt-test-data = "jk";
};
clocks {
enum gen_type_t {
TYPE_NONE,
TYPE_SSDT,
+ TYPE_DSDT,
};
/* Type of method to call */
enum method_t {
METHOD_WRITE_TABLES,
METHOD_FILL_SSDT,
+ METHOD_INJECT_DSDT,
};
/* Prototype for all methods */
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;
return aops->write_tables;
case METHOD_FILL_SSDT:
return aops->fill_ssdt;
+ case METHOD_INJECT_DSDT:
+ return aops->inject_dsdt;
}
}
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 = sort_acpi_item_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;
* whatever ACPI code is needed by this device. It will end up in the
* SSDT table.
*
+ * Note that this is called 'fill' because the entire contents of the
+ * SSDT is build by calling this method on all devices.
+ *
* @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);
+
+ /**
+ * 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.
+ *
+ * Note that this is called 'inject' because the output of calling this
+ * method on all devices is injected into the DSDT, the bulk of which
+ * is written in .asl files for the board.
+ *
+ * @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)
*/
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
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");
+ if (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,
+ .inject_dsdt = testacpi_inject_dsdt,
};
static const struct udevice_id testacpi_ids[] = {
return 0;
}
DM_TEST(dm_test_acpi_fill_ssdt, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test acpi_inject_dsdt() */
+static int dm_test_acpi_inject_dsdt(struct unit_test_state *uts)
+{
+ struct acpi_ctx ctx;
+ u8 *buf;
+
+ buf = malloc(BUF_SIZE);
+ ut_assertnonnull(buf);
+
+ ctx.current = buf;
+ buf[4] = 'z'; /* sentinel */
+ ut_assertok(acpi_inject_dsdt(&ctx));
+
+ /*
+ * These values come from acpi-test's acpi-dsdt-test-data property.
+ * There is no u-boot,acpi-dsdt-order so device-tree order is used.
+ */
+ ut_asserteq('h', buf[0]);
+ ut_asserteq('i', buf[1]);
+
+ /* These values come from acpi-test's acpi-dsdt-test-data property */
+ ut_asserteq('j', buf[2]);
+ ut_asserteq('k', buf[3]);
+
+ ut_asserteq('z', buf[4]);
+
+ return 0;
+}
+DM_TEST(dm_test_acpi_inject_dsdt, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);