blob: a58722de737d9a949106d16d86c86bbacc930714 [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 Glassa4f82082020-07-07 13:12:12 -060030/** enum acpi_dump_option - selects what ACPI information to dump */
31enum acpi_dump_option {
32 ACPI_DUMP_LIST, /* Just the list of items */
33 ACPI_DUMP_CONTENTS, /* Include the binary contents also */
34};
35
Simon Glass7ca28502020-04-09 10:27:38 -060036/**
Simon Glass93f7f822020-04-26 09:19:46 -060037 * struct acpi_ctx - Context used for writing ACPI tables
38 *
39 * This contains a few useful pieces of information used when writing
40 *
Simon Glass61cc9332020-07-07 13:11:42 -060041 * @base: Base address of ACPI tables
Simon Glass93f7f822020-04-26 09:19:46 -060042 * @current: Current address for writing
Simon Glass29b35112020-04-26 09:19:50 -060043 * @rsdp: Pointer to the Root System Description Pointer, typically used when
44 * adding a new table. The RSDP holds pointers to the RSDT and XSDT.
45 * @rsdt: Pointer to the Root System Description Table
Simon Glassb38309b2020-04-26 09:19:52 -060046 * @xsdt: Pointer to the Extended System Description Table
Simon Glass7e148f22020-07-07 13:11:50 -060047 * @len_stack: Stack of 'length' words to fix up later
48 * @ltop: Points to current top of stack (0 = empty)
Simon Glass93f7f822020-04-26 09:19:46 -060049 */
50struct acpi_ctx {
Simon Glass61cc9332020-07-07 13:11:42 -060051 void *base;
Simon Glass93f7f822020-04-26 09:19:46 -060052 void *current;
Simon Glass29b35112020-04-26 09:19:50 -060053 struct acpi_rsdp *rsdp;
54 struct acpi_rsdt *rsdt;
Simon Glassb38309b2020-04-26 09:19:52 -060055 struct acpi_xsdt *xsdt;
Simon Glass7e148f22020-07-07 13:11:50 -060056 char *len_stack[ACPIGEN_LENSTACK_SIZE];
57 int ltop;
Simon Glass93f7f822020-04-26 09:19:46 -060058};
59
60/**
Simon Glass7ca28502020-04-09 10:27:38 -060061 * struct acpi_ops - ACPI operations supported by driver model
62 */
63struct acpi_ops {
64 /**
65 * get_name() - Obtain the ACPI name of a device
66 *
67 * @dev: Device to check
68 * @out_name: Place to put the name, must hold at least ACPI_NAME_MAX
69 * bytes
70 * @return 0 if OK, -ENOENT if no name is available, other -ve value on
71 * other error
72 */
73 int (*get_name)(const struct udevice *dev, char *out_name);
Simon Glass93f7f822020-04-26 09:19:46 -060074
75 /**
76 * write_tables() - Write out any tables required by this device
77 *
78 * @dev: Device to write
79 * @ctx: ACPI context to use
80 * @return 0 if OK, -ve on error
81 */
82 int (*write_tables)(const struct udevice *dev, struct acpi_ctx *ctx);
Simon Glassb5183172020-07-07 13:12:03 -060083
84 /**
85 * fill_ssdt() - Generate SSDT code for a device
86 *
87 * This is called to create the SSDT code. The method should write out
88 * whatever ACPI code is needed by this device. It will end up in the
89 * SSDT table.
90 *
Simon Glass01694582020-07-07 13:12:08 -060091 * Note that this is called 'fill' because the entire contents of the
92 * SSDT is build by calling this method on all devices.
93 *
Simon Glassb5183172020-07-07 13:12:03 -060094 * @dev: Device to write
95 * @ctx: ACPI context to use
96 * @return 0 if OK, -ve on error
97 */
98 int (*fill_ssdt)(const struct udevice *dev, struct acpi_ctx *ctx);
Simon Glass01694582020-07-07 13:12:08 -060099
100 /**
101 * inject_dsdt() - Generate DSDT code for a device
102 *
103 * This is called to create the DSDT code. The method should write out
104 * whatever ACPI code is needed by this device. It will end up in the
105 * DSDT table.
106 *
107 * Note that this is called 'inject' because the output of calling this
108 * method on all devices is injected into the DSDT, the bulk of which
109 * is written in .asl files for the board.
110 *
111 * @dev: Device to write
112 * @ctx: ACPI context to use
113 * @return 0 if OK, -ve on error
114 */
115 int (*inject_dsdt)(const struct udevice *dev, struct acpi_ctx *ctx);
Simon Glass7ca28502020-04-09 10:27:38 -0600116};
117
118#define device_get_acpi_ops(dev) ((dev)->driver->acpi_ops)
119
120/**
121 * acpi_get_name() - Obtain the ACPI name of a device
122 *
123 * @dev: Device to check
124 * @out_name: Place to put the name, must hold at least ACPI_NAME_MAX
125 * bytes
126 * @return 0 if OK, -ENOENT if no name is available, other -ve value on
127 * other error
128 */
129int acpi_get_name(const struct udevice *dev, char *out_name);
130
131/**
132 * acpi_copy_name() - Copy an ACPI name to an output buffer
133 *
134 * This convenience function can be used to return a literal string as a name
135 * in functions that implement the get_name() method.
136 *
137 * For example:
138 *
139 * static int mydev_get_name(const struct udevice *dev, char *out_name)
140 * {
141 * return acpi_copy_name(out_name, "WIBB");
142 * }
143 *
144 * @out_name: Place to put the name
145 * @name: Name to copy
146 * @return 0 (always)
147 */
148int acpi_copy_name(char *out_name, const char *name);
149
Simon Glass93f7f822020-04-26 09:19:46 -0600150/**
151 * acpi_write_dev_tables() - Write ACPI tables required by devices
152 *
153 * This scans through all devices and tells them to write any tables they want
154 * to write.
155 *
156 * @return 0 if OK, -ve if any device returned an error
157 */
158int acpi_write_dev_tables(struct acpi_ctx *ctx);
159
Simon Glassb5183172020-07-07 13:12:03 -0600160/**
161 * acpi_fill_ssdt() - Generate ACPI tables for SSDT
162 *
163 * This is called to create the SSDT code for all devices.
164 *
165 * @ctx: ACPI context to use
166 * @return 0 if OK, -ve on error
167 */
168int acpi_fill_ssdt(struct acpi_ctx *ctx);
169
Simon Glass01694582020-07-07 13:12:08 -0600170/**
171 * acpi_inject_dsdt() - Generate ACPI tables for DSDT
172 *
173 * This is called to create the DSDT code for all devices.
174 *
175 * @ctx: ACPI context to use
176 * @return 0 if OK, -ve on error
177 */
178int acpi_inject_dsdt(struct acpi_ctx *ctx);
179
Simon Glassa4f82082020-07-07 13:12:12 -0600180/**
181 * acpi_dump_items() - Dump out the collected ACPI items
182 *
183 * This lists the ACPI DSDT and SSDT items generated by the various U-Boot
184 * drivers.
185 *
186 * @option: Sets what should be dumpyed
187 */
188void acpi_dump_items(enum acpi_dump_option option);
189
Simon Glassf1858952020-07-07 21:32:07 -0600190/**
191 * acpi_get_path() - Get the full ACPI path for a device
192 *
193 * This checks for any override in the device tree and calls acpi_device_path()
194 * if not
195 *
196 * @dev: Device to check
197 * @out_path: Buffer to place the path in (should be ACPI_PATH_MAX long)
198 * @maxlen: Size of buffer (typically ACPI_PATH_MAX)
199 * @return 0 if OK, -ve on error
200 */
201int acpi_get_path(const struct udevice *dev, char *out_path, int maxlen);
202
Simon Glass89c27982020-04-08 16:57:37 -0600203#endif /* __ACPI__ */
204
Simon Glass7ca28502020-04-09 10:27:38 -0600205#endif