blob: dfda88e4931beb5e8d082275e8b05eecff94944f [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 Glass9fb9e9b2020-04-09 10:27:38 -060077};
78
79#define device_get_acpi_ops(dev) ((dev)->driver->acpi_ops)
80
81/**
82 * acpi_get_name() - Obtain the ACPI name of a device
83 *
84 * @dev: Device to check
85 * @out_name: Place to put the name, must hold at least ACPI_NAME_MAX
86 * bytes
87 * @return 0 if OK, -ENOENT if no name is available, other -ve value on
88 * other error
89 */
90int acpi_get_name(const struct udevice *dev, char *out_name);
91
92/**
93 * acpi_copy_name() - Copy an ACPI name to an output buffer
94 *
95 * This convenience function can be used to return a literal string as a name
96 * in functions that implement the get_name() method.
97 *
98 * For example:
99 *
100 * static int mydev_get_name(const struct udevice *dev, char *out_name)
101 * {
102 * return acpi_copy_name(out_name, "WIBB");
103 * }
104 *
105 * @out_name: Place to put the name
106 * @name: Name to copy
107 * @return 0 (always)
108 */
109int acpi_copy_name(char *out_name, const char *name);
110
Simon Glass17968c32020-04-26 09:19:46 -0600111/**
112 * acpi_write_dev_tables() - Write ACPI tables required by devices
113 *
114 * This scans through all devices and tells them to write any tables they want
115 * to write.
116 *
117 * @return 0 if OK, -ve if any device returned an error
118 */
119int acpi_write_dev_tables(struct acpi_ctx *ctx);
120
Simon Glass4969d212020-04-08 16:57:37 -0600121#endif /* __ACPI__ */
122
Simon Glass9fb9e9b2020-04-09 10:27:38 -0600123#endif