1 // SPDX-License-Identifier: GPL-2.0+
3 * Core driver model support for ACPI table generation
5 * Copyright 2019 Google LLC
6 * Written by Simon Glass <sjg@chromium.org>
9 #define LOG_CATEOGRY LOGC_ACPI
14 #include <dm/device-internal.h>
17 /* Type of method to call */
22 /* Prototype for all methods */
23 typedef int (*acpi_method)(const struct udevice *dev, struct acpi_ctx *ctx);
25 int acpi_copy_name(char *out_name, const char *name)
27 strncpy(out_name, name, ACPI_NAME_LEN);
28 out_name[ACPI_NAME_LEN] = '\0';
33 int acpi_get_name(const struct udevice *dev, char *out_name)
35 struct acpi_ops *aops;
37 aops = device_get_acpi_ops(dev);
38 if (aops && aops->get_name)
39 return aops->get_name(dev, out_name);
44 acpi_method acpi_get_method(struct udevice *dev, enum method_t method)
46 struct acpi_ops *aops;
48 aops = device_get_acpi_ops(dev);
51 case METHOD_WRITE_TABLES:
52 return aops->write_tables;
59 int acpi_recurse_method(struct acpi_ctx *ctx, struct udevice *parent,
66 func = acpi_get_method(parent, method);
69 log_debug("- %s %p\n", parent->name, func);
70 ret = device_ofdata_to_platdata(parent);
72 return log_msg_ret("ofdata", ret);
73 ret = func(parent, ctx);
75 return log_msg_ret("func", ret);
77 device_foreach_child(dev, parent) {
78 ret = acpi_recurse_method(ctx, dev, method);
80 return log_msg_ret("recurse", ret);
86 int acpi_write_dev_tables(struct acpi_ctx *ctx)
90 log_debug("Writing device tables\n");
91 ret = acpi_recurse_method(ctx, dm_root(), METHOD_WRITE_TABLES);
92 log_debug("Writing finished, err=%d\n", ret);