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
15 #include <dm/device-internal.h>
18 /* Type of method to call */
23 /* Prototype for all methods */
24 typedef int (*acpi_method)(const struct udevice *dev, struct acpi_ctx *ctx);
26 int acpi_copy_name(char *out_name, const char *name)
28 strncpy(out_name, name, ACPI_NAME_LEN);
29 out_name[ACPI_NAME_LEN] = '\0';
34 int acpi_get_name(const struct udevice *dev, char *out_name)
36 struct acpi_ops *aops;
38 aops = device_get_acpi_ops(dev);
39 if (aops && aops->get_name)
40 return aops->get_name(dev, out_name);
45 acpi_method acpi_get_method(struct udevice *dev, enum method_t method)
47 struct acpi_ops *aops;
49 aops = device_get_acpi_ops(dev);
52 case METHOD_WRITE_TABLES:
53 return aops->write_tables;
60 int acpi_recurse_method(struct acpi_ctx *ctx, struct udevice *parent,
67 func = acpi_get_method(parent, method);
70 log_debug("- %s %p\n", parent->name, func);
71 ret = device_ofdata_to_platdata(parent);
73 return log_msg_ret("ofdata", ret);
74 ret = func(parent, ctx);
76 return log_msg_ret("func", ret);
78 device_foreach_child(dev, parent) {
79 ret = acpi_recurse_method(ctx, dev, method);
81 return log_msg_ret("recurse", ret);
87 int acpi_write_dev_tables(struct acpi_ctx *ctx)
91 log_debug("Writing device tables\n");
92 ret = acpi_recurse_method(ctx, dm_root(), METHOD_WRITE_TABLES);
93 log_debug("Writing finished, err=%d\n", ret);