blob: e6951b6a25d97525cbe03579d3c83ca257896e67 [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;
31
Simon Glassa4f82082020-07-07 13:12:12 -060032/** enum acpi_dump_option - selects what ACPI information to dump */
33enum acpi_dump_option {
34 ACPI_DUMP_LIST, /* Just the list of items */
35 ACPI_DUMP_CONTENTS, /* Include the binary contents also */
36};
37
Simon Glass7ca28502020-04-09 10:27:38 -060038/**
Simon Glass93f7f822020-04-26 09:19:46 -060039 * struct acpi_ctx - Context used for writing ACPI tables
40 *
41 * This contains a few useful pieces of information used when writing
42 *
Simon Glass61cc9332020-07-07 13:11:42 -060043 * @base: Base address of ACPI tables
Simon Glass93f7f822020-04-26 09:19:46 -060044 * @current: Current address for writing
Simon Glass29b35112020-04-26 09:19:50 -060045 * @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
Simon Glassb38309b2020-04-26 09:19:52 -060048 * @xsdt: Pointer to the Extended System Description Table
Simon Glassb4e84332020-07-07 21:32:08 -060049 * @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
51 * table
Simon Glass7e148f22020-07-07 13:11:50 -060052 * @len_stack: Stack of 'length' words to fix up later
53 * @ltop: Points to current top of stack (0 = empty)
Simon Glass93f7f822020-04-26 09:19:46 -060054 */
55struct acpi_ctx {
Simon Glass61cc9332020-07-07 13:11:42 -060056 void *base;
Simon Glass93f7f822020-04-26 09:19:46 -060057 void *current;
Simon Glass29b35112020-04-26 09:19:50 -060058 struct acpi_rsdp *rsdp;
59 struct acpi_rsdt *rsdt;
Simon Glassb38309b2020-04-26 09:19:52 -060060 struct acpi_xsdt *xsdt;
Simon Glassb4e84332020-07-07 21:32:08 -060061 struct nhlt *nhlt;
Simon Glass7e148f22020-07-07 13:11:50 -060062 char *len_stack[ACPIGEN_LENSTACK_SIZE];
63 int ltop;
Simon Glass93f7f822020-04-26 09:19:46 -060064};
65
66/**
Simon Glass7ca28502020-04-09 10:27:38 -060067 * struct acpi_ops - ACPI operations supported by driver model
68 */
69struct acpi_ops {
70 /**
71 * get_name() - Obtain the ACPI name of a device
72 *
73 * @dev: Device to check
74 * @out_name: Place to put the name, must hold at least ACPI_NAME_MAX
75 * bytes
76 * @return 0 if OK, -ENOENT if no name is available, other -ve value on
77 * other error
78 */
79 int (*get_name)(const struct udevice *dev, char *out_name);
Simon Glass93f7f822020-04-26 09:19:46 -060080
81 /**
82 * write_tables() - Write out any tables required by this device
83 *
84 * @dev: Device to write
85 * @ctx: ACPI context to use
86 * @return 0 if OK, -ve on error
87 */
88 int (*write_tables)(const struct udevice *dev, struct acpi_ctx *ctx);
Simon Glassb5183172020-07-07 13:12:03 -060089
90 /**
91 * fill_ssdt() - Generate SSDT code for a device
92 *
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
95 * SSDT table.
96 *
Simon Glass01694582020-07-07 13:12:08 -060097 * Note that this is called 'fill' because the entire contents of the
98 * SSDT is build by calling this method on all devices.
99 *
Simon Glassb5183172020-07-07 13:12:03 -0600100 * @dev: Device to write
101 * @ctx: ACPI context to use
102 * @return 0 if OK, -ve on error
103 */
104 int (*fill_ssdt)(const struct udevice *dev, struct acpi_ctx *ctx);
Simon Glass01694582020-07-07 13:12:08 -0600105
106 /**
107 * inject_dsdt() - Generate DSDT code for a device
108 *
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
111 * DSDT table.
112 *
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.
116 *
117 * @dev: Device to write
118 * @ctx: ACPI context to use
119 * @return 0 if OK, -ve on error
120 */
121 int (*inject_dsdt)(const struct udevice *dev, struct acpi_ctx *ctx);
Simon Glassb4e84332020-07-07 21:32:08 -0600122
123 /**
124 * setup_nhlt() - Set up audio information for this device
125 *
126 * The method can add information to ctx->nhlt if it likes
127 *
128 * @return 0 if OK, -ENODATA if nothing to add, -ve on error
129 */
130 int (*setup_nhlt)(const struct udevice *dev, struct acpi_ctx *ctx);
Simon Glass7ca28502020-04-09 10:27:38 -0600131};
132
133#define device_get_acpi_ops(dev) ((dev)->driver->acpi_ops)
134
135/**
136 * acpi_get_name() - Obtain the ACPI name of a device
137 *
138 * @dev: Device to check
139 * @out_name: Place to put the name, must hold at least ACPI_NAME_MAX
140 * bytes
141 * @return 0 if OK, -ENOENT if no name is available, other -ve value on
142 * other error
143 */
144int acpi_get_name(const struct udevice *dev, char *out_name);
145
146/**
147 * acpi_copy_name() - Copy an ACPI name to an output buffer
148 *
149 * This convenience function can be used to return a literal string as a name
150 * in functions that implement the get_name() method.
151 *
152 * For example:
153 *
154 * static int mydev_get_name(const struct udevice *dev, char *out_name)
155 * {
156 * return acpi_copy_name(out_name, "WIBB");
157 * }
158 *
159 * @out_name: Place to put the name
160 * @name: Name to copy
161 * @return 0 (always)
162 */
163int acpi_copy_name(char *out_name, const char *name);
164
Simon Glass93f7f822020-04-26 09:19:46 -0600165/**
166 * acpi_write_dev_tables() - Write ACPI tables required by devices
167 *
168 * This scans through all devices and tells them to write any tables they want
169 * to write.
170 *
171 * @return 0 if OK, -ve if any device returned an error
172 */
173int acpi_write_dev_tables(struct acpi_ctx *ctx);
174
Simon Glassb5183172020-07-07 13:12:03 -0600175/**
176 * acpi_fill_ssdt() - Generate ACPI tables for SSDT
177 *
178 * This is called to create the SSDT code for all devices.
179 *
180 * @ctx: ACPI context to use
181 * @return 0 if OK, -ve on error
182 */
183int acpi_fill_ssdt(struct acpi_ctx *ctx);
184
Simon Glass01694582020-07-07 13:12:08 -0600185/**
186 * acpi_inject_dsdt() - Generate ACPI tables for DSDT
187 *
188 * This is called to create the DSDT code for all devices.
189 *
190 * @ctx: ACPI context to use
191 * @return 0 if OK, -ve on error
192 */
193int acpi_inject_dsdt(struct acpi_ctx *ctx);
194
Simon Glassa4f82082020-07-07 13:12:12 -0600195/**
Simon Glassb4e84332020-07-07 21:32:08 -0600196 * acpi_setup_nhlt() - Set up audio information
197 *
198 * This is called to set up the nhlt information for all devices.
199 *
200 * @ctx: ACPI context to use
201 * @nhlt: Pointer to nhlt information to add to
202 * @return 0 if OK, -ve on error
203 */
204int acpi_setup_nhlt(struct acpi_ctx *ctx, struct nhlt *nhlt);
205
206/**
Simon Glassa4f82082020-07-07 13:12:12 -0600207 * acpi_dump_items() - Dump out the collected ACPI items
208 *
209 * This lists the ACPI DSDT and SSDT items generated by the various U-Boot
210 * drivers.
211 *
212 * @option: Sets what should be dumpyed
213 */
214void acpi_dump_items(enum acpi_dump_option option);
215
Simon Glassf1858952020-07-07 21:32:07 -0600216/**
217 * acpi_get_path() - Get the full ACPI path for a device
218 *
219 * This checks for any override in the device tree and calls acpi_device_path()
220 * if not
221 *
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
226 */
227int acpi_get_path(const struct udevice *dev, char *out_path, int maxlen);
228
Simon Glass18434ae2020-11-04 09:57:33 -0700229/**
230 * acpi_reset_items() - Reset the list of ACPI items to empty
231 *
232 * This list keeps track of DSDT and SSDT items that are generated
233 * programmatically. The 'acpi items' command shows the list. Use this function
234 * to empty the list, before writing new items.
235 */
236void acpi_reset_items(void);
237
Simon Glass89c27982020-04-08 16:57:37 -0600238#endif /* __ACPI__ */
239
Simon Glass7ca28502020-04-09 10:27:38 -0600240#endif