aboutsummaryrefslogtreecommitdiff
path: root/include/dm/acpi.h
diff options
context:
space:
mode:
authorSimon Glass2020-04-09 10:27:38 -0600
committerBin Meng2020-04-16 14:36:28 +0800
commit7ca2850cbcb2adca4f6927d9bf77626091ab5c3e (patch)
treea84c7bbd42198a146e59f6bd8b62e113b18b3978 /include/dm/acpi.h
parentb2c386846332e9fc1571aa1eed3ac47b903bd32c (diff)
dm: core: Add basic ACPI support
ACPI (Advanced Configuration and Power Interface) is a standard for specifying information about a platform. It is a little like device tree but the bindings are part of the specification and 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. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Wolfgang Wallner <wolfgang.wallner@br-automation.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Diffstat (limited to 'include/dm/acpi.h')
-rw-r--r--include/dm/acpi.h73
1 files changed, 73 insertions, 0 deletions
diff --git a/include/dm/acpi.h b/include/dm/acpi.h
new file mode 100644
index 00000000000..ba0813fa21c
--- /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 <sjg@chromium.org>
+ */
+
+#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 (ACPI_NAME_LEN + 1)
+
+/**
+ * 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_copy_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_name(const struct udevice *dev, char *out_name)
+ * {
+ * return acpi_copy_name(out_name, "WIBB");
+ * }
+ *
+ * @out_name: Place to put the name
+ * @name: Name to copy
+ * @return 0 (always)
+ */
+int acpi_copy_name(char *out_name, const char *name);
+
+#endif