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 null 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 /* Number of nested objects supported */
26 #define ACPIGEN_LENSTACK_SIZE 10
28 #if !defined(__ACPI__)
32 /** enum acpi_dump_option - selects what ACPI information to dump */
33 enum acpi_dump_option {
34 ACPI_DUMP_LIST, /* Just the list of items */
35 ACPI_DUMP_CONTENTS, /* Include the binary contents also */
39 * struct acpi_ctx - Context used for writing ACPI tables
41 * This contains a few useful pieces of information used when writing
43 * @base: Base address of ACPI tables
44 * @current: Current address for writing
45 * @rsdp: Pointer to the Root System Description Pointer, typically used when
46 * adding a new table. The RSDP holds pointers to the RSDT and XSDT.
47 * @rsdt: Pointer to the Root System Description Table
48 * @xsdt: Pointer to the Extended System Description Table
49 * @nhlt: Intel Non-High-Definition-Audio Link Table (NHLT) pointer, used to
50 * build up information that audio codecs need to provide in the NHLT ACPI
52 * @len_stack: Stack of 'length' words to fix up later
53 * @ltop: Points to current top of stack (0 = empty)
58 struct acpi_rsdp *rsdp;
59 struct acpi_rsdt *rsdt;
60 struct acpi_xsdt *xsdt;
62 char *len_stack[ACPIGEN_LENSTACK_SIZE];
67 * struct acpi_ops - ACPI operations supported by driver model
71 * get_name() - Obtain the ACPI name of a device
73 * @dev: Device to check
74 * @out_name: Place to put the name, must hold at least ACPI_NAME_MAX
76 * @return 0 if OK, -ENOENT if no name is available, other -ve value on
79 int (*get_name)(const struct udevice *dev, char *out_name);
82 * write_tables() - Write out any tables required by this device
84 * @dev: Device to write
85 * @ctx: ACPI context to use
86 * @return 0 if OK, -ve on error
88 int (*write_tables)(const struct udevice *dev, struct acpi_ctx *ctx);
91 * fill_ssdt() - Generate SSDT code for a device
93 * This is called to create the SSDT code. The method should write out
94 * whatever ACPI code is needed by this device. It will end up in the
97 * Note that this is called 'fill' because the entire contents of the
98 * SSDT is build by calling this method on all devices.
100 * @dev: Device to write
101 * @ctx: ACPI context to use
102 * @return 0 if OK, -ve on error
104 int (*fill_ssdt)(const struct udevice *dev, struct acpi_ctx *ctx);
107 * inject_dsdt() - Generate DSDT code for a device
109 * This is called to create the DSDT code. The method should write out
110 * whatever ACPI code is needed by this device. It will end up in the
113 * Note that this is called 'inject' because the output of calling this
114 * method on all devices is injected into the DSDT, the bulk of which
115 * is written in .asl files for the board.
117 * @dev: Device to write
118 * @ctx: ACPI context to use
119 * @return 0 if OK, -ve on error
121 int (*inject_dsdt)(const struct udevice *dev, struct acpi_ctx *ctx);
124 * setup_nhlt() - Set up audio information for this device
126 * The method can add information to ctx->nhlt if it likes
128 * @return 0 if OK, -ENODATA if nothing to add, -ve on error
130 int (*setup_nhlt)(const struct udevice *dev, struct acpi_ctx *ctx);
133 #define device_get_acpi_ops(dev) ((dev)->driver->acpi_ops)
136 * acpi_get_name() - Obtain the ACPI name of a device
138 * @dev: Device to check
139 * @out_name: Place to put the name, must hold at least ACPI_NAME_MAX
141 * @return 0 if OK, -ENOENT if no name is available, other -ve value on
144 int acpi_get_name(const struct udevice *dev, char *out_name);
147 * acpi_copy_name() - Copy an ACPI name to an output buffer
149 * This convenience function can be used to return a literal string as a name
150 * in functions that implement the get_name() method.
154 * static int mydev_get_name(const struct udevice *dev, char *out_name)
156 * return acpi_copy_name(out_name, "WIBB");
159 * @out_name: Place to put the name
160 * @name: Name to copy
163 int acpi_copy_name(char *out_name, const char *name);
166 * acpi_write_dev_tables() - Write ACPI tables required by devices
168 * This scans through all devices and tells them to write any tables they want
171 * @return 0 if OK, -ve if any device returned an error
173 int acpi_write_dev_tables(struct acpi_ctx *ctx);
176 * acpi_fill_ssdt() - Generate ACPI tables for SSDT
178 * This is called to create the SSDT code for all devices.
180 * @ctx: ACPI context to use
181 * @return 0 if OK, -ve on error
183 int acpi_fill_ssdt(struct acpi_ctx *ctx);
186 * acpi_inject_dsdt() - Generate ACPI tables for DSDT
188 * This is called to create the DSDT code for all devices.
190 * @ctx: ACPI context to use
191 * @return 0 if OK, -ve on error
193 int acpi_inject_dsdt(struct acpi_ctx *ctx);
196 * acpi_setup_nhlt() - Set up audio information
198 * This is called to set up the nhlt information for all devices.
200 * @ctx: ACPI context to use
201 * @nhlt: Pointer to nhlt information to add to
202 * @return 0 if OK, -ve on error
204 int acpi_setup_nhlt(struct acpi_ctx *ctx, struct nhlt *nhlt);
207 * acpi_dump_items() - Dump out the collected ACPI items
209 * This lists the ACPI DSDT and SSDT items generated by the various U-Boot
212 * @option: Sets what should be dumpyed
214 void acpi_dump_items(enum acpi_dump_option option);
217 * acpi_get_path() - Get the full ACPI path for a device
219 * This checks for any override in the device tree and calls acpi_device_path()
222 * @dev: Device to check
223 * @out_path: Buffer to place the path in (should be ACPI_PATH_MAX long)
224 * @maxlen: Size of buffer (typically ACPI_PATH_MAX)
225 * @return 0 if OK, -ve on error
227 int acpi_get_path(const struct udevice *dev, char *out_path, int maxlen);
229 #endif /* __ACPI__ */