1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Core ACPI (Advanced Configuration and Power Interface) support
5 * Copyright 2019 Google LLC
6 * Written by Simon Glass <sjg@chromium.org>
12 /* Allow operations to be optional for ACPI */
13 #if CONFIG_IS_ENABLED(ACPIGEN)
14 #define ACPI_OPS_PTR(_ptr) .acpi_ops = _ptr,
16 #define ACPI_OPS_PTR(_ptr)
19 /* Length of an ACPI name string, excluding nul terminator */
20 #define ACPI_NAME_LEN 4
22 /* Length of an ACPI name string including nul terminator */
23 #define ACPI_NAME_MAX (ACPI_NAME_LEN + 1)
25 #if !defined(__ACPI__)
28 * struct acpi_ctx - Context used for writing ACPI tables
30 * This contains a few useful pieces of information used when writing
32 * @current: Current address for writing
39 * struct acpi_ops - ACPI operations supported by driver model
43 * get_name() - Obtain the ACPI name of a device
45 * @dev: Device to check
46 * @out_name: Place to put the name, must hold at least ACPI_NAME_MAX
48 * @return 0 if OK, -ENOENT if no name is available, other -ve value on
51 int (*get_name)(const struct udevice *dev, char *out_name);
54 * write_tables() - Write out any tables required by this device
56 * @dev: Device to write
57 * @ctx: ACPI context to use
58 * @return 0 if OK, -ve on error
60 int (*write_tables)(const struct udevice *dev, struct acpi_ctx *ctx);
63 #define device_get_acpi_ops(dev) ((dev)->driver->acpi_ops)
66 * acpi_get_name() - Obtain the ACPI name of a device
68 * @dev: Device to check
69 * @out_name: Place to put the name, must hold at least ACPI_NAME_MAX
71 * @return 0 if OK, -ENOENT if no name is available, other -ve value on
74 int acpi_get_name(const struct udevice *dev, char *out_name);
77 * acpi_copy_name() - Copy an ACPI name to an output buffer
79 * This convenience function can be used to return a literal string as a name
80 * in functions that implement the get_name() method.
84 * static int mydev_get_name(const struct udevice *dev, char *out_name)
86 * return acpi_copy_name(out_name, "WIBB");
89 * @out_name: Place to put the name
93 int acpi_copy_name(char *out_name, const char *name);
96 * acpi_write_dev_tables() - Write ACPI tables required by devices
98 * This scans through all devices and tells them to write any tables they want
101 * @return 0 if OK, -ve if any device returned an error
103 int acpi_write_dev_tables(struct acpi_ctx *ctx);
105 #endif /* __ACPI__ */