blob: e956e49680e9ffac1beeaf4c112f0f97e8b4d158 [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 *
85 * @dev: Device to write
86 * @ctx: ACPI context to use
87 * @return 0 if OK, -ve on error
88 */
89 int (*fill_ssdt)(const struct udevice *dev, struct acpi_ctx *ctx);
Simon Glass9fb9e9b2020-04-09 10:27:38 -060090};
91
92#define device_get_acpi_ops(dev) ((dev)->driver->acpi_ops)
93
94/**
95 * acpi_get_name() - Obtain the ACPI name of a device
96 *
97 * @dev: Device to check
98 * @out_name: Place to put the name, must hold at least ACPI_NAME_MAX
99 * bytes
100 * @return 0 if OK, -ENOENT if no name is available, other -ve value on
101 * other error
102 */
103int acpi_get_name(const struct udevice *dev, char *out_name);
104
105/**
106 * acpi_copy_name() - Copy an ACPI name to an output buffer
107 *
108 * This convenience function can be used to return a literal string as a name
109 * in functions that implement the get_name() method.
110 *
111 * For example:
112 *
113 * static int mydev_get_name(const struct udevice *dev, char *out_name)
114 * {
115 * return acpi_copy_name(out_name, "WIBB");
116 * }
117 *
118 * @out_name: Place to put the name
119 * @name: Name to copy
120 * @return 0 (always)
121 */
122int acpi_copy_name(char *out_name, const char *name);
123
Simon Glass17968c32020-04-26 09:19:46 -0600124/**
125 * acpi_write_dev_tables() - Write ACPI tables required by devices
126 *
127 * This scans through all devices and tells them to write any tables they want
128 * to write.
129 *
130 * @return 0 if OK, -ve if any device returned an error
131 */
132int acpi_write_dev_tables(struct acpi_ctx *ctx);
133
Simon Glassd43e0ba2020-07-07 13:12:03 -0600134/**
135 * acpi_fill_ssdt() - Generate ACPI tables for SSDT
136 *
137 * This is called to create the SSDT code for all devices.
138 *
139 * @ctx: ACPI context to use
140 * @return 0 if OK, -ve on error
141 */
142int acpi_fill_ssdt(struct acpi_ctx *ctx);
143
Simon Glass4969d212020-04-08 16:57:37 -0600144#endif /* __ACPI__ */
145
Simon Glass9fb9e9b2020-04-09 10:27:38 -0600146#endif