blob: a2da57fe22470c71f920e7f3dc97f811597b2470 [file] [log] [blame]
Simon Glass7ca28502020-04-09 10:27:38 -06001/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Core ACPI (Advanced Configuration and Power Interface) support
4 *
5 * Copyright 2019 Google LLC
6 * Written by Simon Glass <sjg@chromium.org>
7 */
8
9#ifndef __DM_ACPI_H__
10#define __DM_ACPI_H__
11
12/* Allow operations to be optional for ACPI */
13#if CONFIG_IS_ENABLED(ACPIGEN)
14#define ACPI_OPS_PTR(_ptr) .acpi_ops = _ptr,
15#else
16#define ACPI_OPS_PTR(_ptr)
17#endif
18
Simon Glass7e148f22020-07-07 13:11:50 -060019/* Length of an ACPI name string, excluding null terminator */
Simon Glass7ca28502020-04-09 10:27:38 -060020#define ACPI_NAME_LEN 4
21
22/* Length of an ACPI name string including nul terminator */
23#define ACPI_NAME_MAX (ACPI_NAME_LEN + 1)
24
Simon Glass7e148f22020-07-07 13:11:50 -060025/* Number of nested objects supported */
26#define ACPIGEN_LENSTACK_SIZE 10
27
Simon Glass89c27982020-04-08 16:57:37 -060028#if !defined(__ACPI__)
29
Simon Glassb4e84332020-07-07 21:32:08 -060030struct nhlt;
Simon Glass401d1c42020-10-30 21:38:53 -060031struct udevice;
Simon Glassb4e84332020-07-07 21:32:08 -060032
Simon Glassa4f82082020-07-07 13:12:12 -060033/** enum acpi_dump_option - selects what ACPI information to dump */
34enum acpi_dump_option {
35 ACPI_DUMP_LIST, /* Just the list of items */
36 ACPI_DUMP_CONTENTS, /* Include the binary contents also */
37};
38
Simon Glass7ca28502020-04-09 10:27:38 -060039/**
Simon Glass93f7f822020-04-26 09:19:46 -060040 * struct acpi_ctx - Context used for writing ACPI tables
41 *
42 * This contains a few useful pieces of information used when writing
43 *
Simon Glass61cc9332020-07-07 13:11:42 -060044 * @base: Base address of ACPI tables
Simon Glass93f7f822020-04-26 09:19:46 -060045 * @current: Current address for writing
Simon Glassfb746fd2021-12-01 09:02:46 -070046 * @tab_start: Address of start of the table being written. This is set up
47 * before the writer or driver method is called. It must not be changed by the
48 * method
Simon Glass29b35112020-04-26 09:19:50 -060049 * @rsdp: Pointer to the Root System Description Pointer, typically used when
50 * adding a new table. The RSDP holds pointers to the RSDT and XSDT.
51 * @rsdt: Pointer to the Root System Description Table
Simon Glassb38309b2020-04-26 09:19:52 -060052 * @xsdt: Pointer to the Extended System Description Table
Simon Glassb4e84332020-07-07 21:32:08 -060053 * @nhlt: Intel Non-High-Definition-Audio Link Table (NHLT) pointer, used to
54 * build up information that audio codecs need to provide in the NHLT ACPI
55 * table
Simon Glass7e148f22020-07-07 13:11:50 -060056 * @len_stack: Stack of 'length' words to fix up later
57 * @ltop: Points to current top of stack (0 = empty)
Simon Glass93f7f822020-04-26 09:19:46 -060058 */
59struct acpi_ctx {
Simon Glass61cc9332020-07-07 13:11:42 -060060 void *base;
Simon Glass93f7f822020-04-26 09:19:46 -060061 void *current;
Simon Glassfb746fd2021-12-01 09:02:46 -070062 void *tab_start;
Simon Glass29b35112020-04-26 09:19:50 -060063 struct acpi_rsdp *rsdp;
64 struct acpi_rsdt *rsdt;
Simon Glassb38309b2020-04-26 09:19:52 -060065 struct acpi_xsdt *xsdt;
Simon Glassb4e84332020-07-07 21:32:08 -060066 struct nhlt *nhlt;
Simon Glass7e148f22020-07-07 13:11:50 -060067 char *len_stack[ACPIGEN_LENSTACK_SIZE];
68 int ltop;
Simon Glass93f7f822020-04-26 09:19:46 -060069};
70
71/**
Simon Glass7ca28502020-04-09 10:27:38 -060072 * struct acpi_ops - ACPI operations supported by driver model
73 */
74struct acpi_ops {
75 /**
76 * get_name() - Obtain the ACPI name of a device
77 *
78 * @dev: Device to check
79 * @out_name: Place to put the name, must hold at least ACPI_NAME_MAX
80 * bytes
81 * @return 0 if OK, -ENOENT if no name is available, other -ve value on
82 * other error
83 */
84 int (*get_name)(const struct udevice *dev, char *out_name);
Simon Glass93f7f822020-04-26 09:19:46 -060085
86 /**
87 * write_tables() - Write out any tables required by this device
88 *
89 * @dev: Device to write
90 * @ctx: ACPI context to use
91 * @return 0 if OK, -ve on error
92 */
93 int (*write_tables)(const struct udevice *dev, struct acpi_ctx *ctx);
Simon Glassb5183172020-07-07 13:12:03 -060094
95 /**
96 * fill_ssdt() - Generate SSDT code for a device
97 *
98 * This is called to create the SSDT code. The method should write out
99 * whatever ACPI code is needed by this device. It will end up in the
100 * SSDT table.
101 *
Simon Glass01694582020-07-07 13:12:08 -0600102 * Note that this is called 'fill' because the entire contents of the
103 * SSDT is build by calling this method on all devices.
104 *
Simon Glassb5183172020-07-07 13:12:03 -0600105 * @dev: Device to write
106 * @ctx: ACPI context to use
107 * @return 0 if OK, -ve on error
108 */
109 int (*fill_ssdt)(const struct udevice *dev, struct acpi_ctx *ctx);
Simon Glass01694582020-07-07 13:12:08 -0600110
111 /**
112 * inject_dsdt() - Generate DSDT code for a device
113 *
114 * This is called to create the DSDT code. The method should write out
115 * whatever ACPI code is needed by this device. It will end up in the
116 * DSDT table.
117 *
118 * Note that this is called 'inject' because the output of calling this
119 * method on all devices is injected into the DSDT, the bulk of which
120 * is written in .asl files for the board.
121 *
122 * @dev: Device to write
123 * @ctx: ACPI context to use
124 * @return 0 if OK, -ve on error
125 */
126 int (*inject_dsdt)(const struct udevice *dev, struct acpi_ctx *ctx);
Simon Glassb4e84332020-07-07 21:32:08 -0600127
128 /**
129 * setup_nhlt() - Set up audio information for this device
130 *
131 * The method can add information to ctx->nhlt if it likes
132 *
133 * @return 0 if OK, -ENODATA if nothing to add, -ve on error
134 */
135 int (*setup_nhlt)(const struct udevice *dev, struct acpi_ctx *ctx);
Simon Glass7ca28502020-04-09 10:27:38 -0600136};
137
138#define device_get_acpi_ops(dev) ((dev)->driver->acpi_ops)
139
140/**
141 * acpi_get_name() - Obtain the ACPI name of a device
142 *
143 * @dev: Device to check
144 * @out_name: Place to put the name, must hold at least ACPI_NAME_MAX
145 * bytes
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100146 * Return: 0 if OK, -ENOENT if no name is available, other -ve value on
Simon Glass7ca28502020-04-09 10:27:38 -0600147 * other error
148 */
149int acpi_get_name(const struct udevice *dev, char *out_name);
150
151/**
152 * acpi_copy_name() - Copy an ACPI name to an output buffer
153 *
154 * This convenience function can be used to return a literal string as a name
155 * in functions that implement the get_name() method.
156 *
157 * For example:
158 *
159 * static int mydev_get_name(const struct udevice *dev, char *out_name)
160 * {
161 * return acpi_copy_name(out_name, "WIBB");
162 * }
163 *
164 * @out_name: Place to put the name
165 * @name: Name to copy
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100166 * Return: 0 (always)
Simon Glass7ca28502020-04-09 10:27:38 -0600167 */
168int acpi_copy_name(char *out_name, const char *name);
169
Simon Glass93f7f822020-04-26 09:19:46 -0600170/**
171 * acpi_write_dev_tables() - Write ACPI tables required by devices
172 *
173 * This scans through all devices and tells them to write any tables they want
174 * to write.
175 *
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100176 * Return: 0 if OK, -ve if any device returned an error
Simon Glass93f7f822020-04-26 09:19:46 -0600177 */
178int acpi_write_dev_tables(struct acpi_ctx *ctx);
179
Simon Glassb5183172020-07-07 13:12:03 -0600180/**
181 * acpi_fill_ssdt() - Generate ACPI tables for SSDT
182 *
183 * This is called to create the SSDT code for all devices.
184 *
185 * @ctx: ACPI context to use
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100186 * Return: 0 if OK, -ve on error
Simon Glassb5183172020-07-07 13:12:03 -0600187 */
188int acpi_fill_ssdt(struct acpi_ctx *ctx);
189
Simon Glass01694582020-07-07 13:12:08 -0600190/**
191 * acpi_inject_dsdt() - Generate ACPI tables for DSDT
192 *
193 * This is called to create the DSDT code for all devices.
194 *
195 * @ctx: ACPI context to use
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100196 * Return: 0 if OK, -ve on error
Simon Glass01694582020-07-07 13:12:08 -0600197 */
198int acpi_inject_dsdt(struct acpi_ctx *ctx);
199
Simon Glassa4f82082020-07-07 13:12:12 -0600200/**
Simon Glassb4e84332020-07-07 21:32:08 -0600201 * acpi_setup_nhlt() - Set up audio information
202 *
203 * This is called to set up the nhlt information for all devices.
204 *
205 * @ctx: ACPI context to use
206 * @nhlt: Pointer to nhlt information to add to
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100207 * Return: 0 if OK, -ve on error
Simon Glassb4e84332020-07-07 21:32:08 -0600208 */
209int acpi_setup_nhlt(struct acpi_ctx *ctx, struct nhlt *nhlt);
210
211/**
Simon Glassa4f82082020-07-07 13:12:12 -0600212 * acpi_dump_items() - Dump out the collected ACPI items
213 *
214 * This lists the ACPI DSDT and SSDT items generated by the various U-Boot
215 * drivers.
216 *
217 * @option: Sets what should be dumpyed
218 */
219void acpi_dump_items(enum acpi_dump_option option);
220
Simon Glassf1858952020-07-07 21:32:07 -0600221/**
222 * acpi_get_path() - Get the full ACPI path for a device
223 *
224 * This checks for any override in the device tree and calls acpi_device_path()
225 * if not
226 *
227 * @dev: Device to check
228 * @out_path: Buffer to place the path in (should be ACPI_PATH_MAX long)
229 * @maxlen: Size of buffer (typically ACPI_PATH_MAX)
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100230 * Return: 0 if OK, -ve on error
Simon Glassf1858952020-07-07 21:32:07 -0600231 */
232int acpi_get_path(const struct udevice *dev, char *out_path, int maxlen);
233
Simon Glass18434ae2020-11-04 09:57:33 -0700234/**
235 * acpi_reset_items() - Reset the list of ACPI items to empty
236 *
237 * This list keeps track of DSDT and SSDT items that are generated
238 * programmatically. The 'acpi items' command shows the list. Use this function
239 * to empty the list, before writing new items.
240 */
241void acpi_reset_items(void);
242
Simon Glass89c27982020-04-08 16:57:37 -0600243#endif /* __ACPI__ */
244
Simon Glass7ca28502020-04-09 10:27:38 -0600245#endif