blob: fceb1ae95c26185b3b4c9a295ec7066a87b12794 [file] [log] [blame]
Simon Glass9fb9e9b2020-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 Glass0f277632020-07-07 13:11:50 -060019/* Length of an ACPI name string, excluding null terminator */
Simon Glass9fb9e9b2020-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 Glass0f277632020-07-07 13:11:50 -060025/* Number of nested objects supported */
26#define ACPIGEN_LENSTACK_SIZE 10
27
Simon Glass4969d212020-04-08 16:57:37 -060028#if !defined(__ACPI__)
29
Simon Glass9fb9e9b2020-04-09 10:27:38 -060030/**
Simon Glass17968c32020-04-26 09:19:46 -060031 * struct acpi_ctx - Context used for writing ACPI tables
32 *
33 * This contains a few useful pieces of information used when writing
34 *
Simon Glass98528d42020-07-07 13:11:42 -060035 * @base: Base address of ACPI tables
Simon Glass17968c32020-04-26 09:19:46 -060036 * @current: Current address for writing
Simon Glass575a5472020-04-26 09:19:50 -060037 * @rsdp: Pointer to the Root System Description Pointer, typically used when
38 * adding a new table. The RSDP holds pointers to the RSDT and XSDT.
39 * @rsdt: Pointer to the Root System Description Table
Simon Glassabeaca82020-04-26 09:19:52 -060040 * @xsdt: Pointer to the Extended System Description Table
Simon Glass0f277632020-07-07 13:11:50 -060041 * @len_stack: Stack of 'length' words to fix up later
42 * @ltop: Points to current top of stack (0 = empty)
Simon Glass17968c32020-04-26 09:19:46 -060043 */
44struct acpi_ctx {
Simon Glass98528d42020-07-07 13:11:42 -060045 void *base;
Simon Glass17968c32020-04-26 09:19:46 -060046 void *current;
Simon Glass575a5472020-04-26 09:19:50 -060047 struct acpi_rsdp *rsdp;
48 struct acpi_rsdt *rsdt;
Simon Glassabeaca82020-04-26 09:19:52 -060049 struct acpi_xsdt *xsdt;
Simon Glass0f277632020-07-07 13:11:50 -060050 char *len_stack[ACPIGEN_LENSTACK_SIZE];
51 int ltop;
Simon Glass17968c32020-04-26 09:19:46 -060052};
53
54/**
Simon Glass9fb9e9b2020-04-09 10:27:38 -060055 * struct acpi_ops - ACPI operations supported by driver model
56 */
57struct acpi_ops {
58 /**
59 * get_name() - Obtain the ACPI name of a device
60 *
61 * @dev: Device to check
62 * @out_name: Place to put the name, must hold at least ACPI_NAME_MAX
63 * bytes
64 * @return 0 if OK, -ENOENT if no name is available, other -ve value on
65 * other error
66 */
67 int (*get_name)(const struct udevice *dev, char *out_name);
Simon Glass17968c32020-04-26 09:19:46 -060068
69 /**
70 * write_tables() - Write out any tables required by this device
71 *
72 * @dev: Device to write
73 * @ctx: ACPI context to use
74 * @return 0 if OK, -ve on error
75 */
76 int (*write_tables)(const struct udevice *dev, struct acpi_ctx *ctx);
Simon Glassd43e0ba2020-07-07 13:12:03 -060077
78 /**
79 * fill_ssdt() - Generate SSDT code for a device
80 *
81 * This is called to create the SSDT code. The method should write out
82 * whatever ACPI code is needed by this device. It will end up in the
83 * SSDT table.
84 *
Simon Glass990cd5b2020-07-07 13:12:08 -060085 * Note that this is called 'fill' because the entire contents of the
86 * SSDT is build by calling this method on all devices.
87 *
Simon Glassd43e0ba2020-07-07 13:12:03 -060088 * @dev: Device to write
89 * @ctx: ACPI context to use
90 * @return 0 if OK, -ve on error
91 */
92 int (*fill_ssdt)(const struct udevice *dev, struct acpi_ctx *ctx);
Simon Glass990cd5b2020-07-07 13:12:08 -060093
94 /**
95 * inject_dsdt() - Generate DSDT code for a device
96 *
97 * This is called to create the DSDT code. The method should write out
98 * whatever ACPI code is needed by this device. It will end up in the
99 * DSDT table.
100 *
101 * Note that this is called 'inject' because the output of calling this
102 * method on all devices is injected into the DSDT, the bulk of which
103 * is written in .asl files for the board.
104 *
105 * @dev: Device to write
106 * @ctx: ACPI context to use
107 * @return 0 if OK, -ve on error
108 */
109 int (*inject_dsdt)(const struct udevice *dev, struct acpi_ctx *ctx);
Simon Glass9fb9e9b2020-04-09 10:27:38 -0600110};
111
112#define device_get_acpi_ops(dev) ((dev)->driver->acpi_ops)
113
114/**
115 * acpi_get_name() - Obtain the ACPI name of a device
116 *
117 * @dev: Device to check
118 * @out_name: Place to put the name, must hold at least ACPI_NAME_MAX
119 * bytes
120 * @return 0 if OK, -ENOENT if no name is available, other -ve value on
121 * other error
122 */
123int acpi_get_name(const struct udevice *dev, char *out_name);
124
125/**
126 * acpi_copy_name() - Copy an ACPI name to an output buffer
127 *
128 * This convenience function can be used to return a literal string as a name
129 * in functions that implement the get_name() method.
130 *
131 * For example:
132 *
133 * static int mydev_get_name(const struct udevice *dev, char *out_name)
134 * {
135 * return acpi_copy_name(out_name, "WIBB");
136 * }
137 *
138 * @out_name: Place to put the name
139 * @name: Name to copy
140 * @return 0 (always)
141 */
142int acpi_copy_name(char *out_name, const char *name);
143
Simon Glass17968c32020-04-26 09:19:46 -0600144/**
145 * acpi_write_dev_tables() - Write ACPI tables required by devices
146 *
147 * This scans through all devices and tells them to write any tables they want
148 * to write.
149 *
150 * @return 0 if OK, -ve if any device returned an error
151 */
152int acpi_write_dev_tables(struct acpi_ctx *ctx);
153
Simon Glassd43e0ba2020-07-07 13:12:03 -0600154/**
155 * acpi_fill_ssdt() - Generate ACPI tables for SSDT
156 *
157 * This is called to create the SSDT code for all devices.
158 *
159 * @ctx: ACPI context to use
160 * @return 0 if OK, -ve on error
161 */
162int acpi_fill_ssdt(struct acpi_ctx *ctx);
163
Simon Glass990cd5b2020-07-07 13:12:08 -0600164/**
165 * acpi_inject_dsdt() - Generate ACPI tables for DSDT
166 *
167 * This is called to create the DSDT code for all devices.
168 *
169 * @ctx: ACPI context to use
170 * @return 0 if OK, -ve on error
171 */
172int acpi_inject_dsdt(struct acpi_ctx *ctx);
173
Simon Glass4969d212020-04-08 16:57:37 -0600174#endif /* __ACPI__ */
175
Simon Glass9fb9e9b2020-04-09 10:27:38 -0600176#endif