blob: c6c63b8183928adc00debfe2ab1659b9ab331f74 [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
19/* Length of an ACPI name string, excluding nul terminator */
20#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 Glass4969d212020-04-08 16:57:37 -060025#if !defined(__ACPI__)
26
Simon Glass9fb9e9b2020-04-09 10:27:38 -060027/**
Simon Glass17968c32020-04-26 09:19:46 -060028 * struct acpi_ctx - Context used for writing ACPI tables
29 *
30 * This contains a few useful pieces of information used when writing
31 *
32 * @current: Current address for writing
Simon Glass575a5472020-04-26 09:19:50 -060033 * @rsdp: Pointer to the Root System Description Pointer, typically used when
34 * adding a new table. The RSDP holds pointers to the RSDT and XSDT.
35 * @rsdt: Pointer to the Root System Description Table
Simon Glass17968c32020-04-26 09:19:46 -060036 */
37struct acpi_ctx {
38 void *current;
Simon Glass575a5472020-04-26 09:19:50 -060039 struct acpi_rsdp *rsdp;
40 struct acpi_rsdt *rsdt;
Simon Glass17968c32020-04-26 09:19:46 -060041};
42
43/**
Simon Glass9fb9e9b2020-04-09 10:27:38 -060044 * struct acpi_ops - ACPI operations supported by driver model
45 */
46struct acpi_ops {
47 /**
48 * get_name() - Obtain the ACPI name of a device
49 *
50 * @dev: Device to check
51 * @out_name: Place to put the name, must hold at least ACPI_NAME_MAX
52 * bytes
53 * @return 0 if OK, -ENOENT if no name is available, other -ve value on
54 * other error
55 */
56 int (*get_name)(const struct udevice *dev, char *out_name);
Simon Glass17968c32020-04-26 09:19:46 -060057
58 /**
59 * write_tables() - Write out any tables required by this device
60 *
61 * @dev: Device to write
62 * @ctx: ACPI context to use
63 * @return 0 if OK, -ve on error
64 */
65 int (*write_tables)(const struct udevice *dev, struct acpi_ctx *ctx);
Simon Glass9fb9e9b2020-04-09 10:27:38 -060066};
67
68#define device_get_acpi_ops(dev) ((dev)->driver->acpi_ops)
69
70/**
71 * acpi_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 */
79int acpi_get_name(const struct udevice *dev, char *out_name);
80
81/**
82 * acpi_copy_name() - Copy an ACPI name to an output buffer
83 *
84 * This convenience function can be used to return a literal string as a name
85 * in functions that implement the get_name() method.
86 *
87 * For example:
88 *
89 * static int mydev_get_name(const struct udevice *dev, char *out_name)
90 * {
91 * return acpi_copy_name(out_name, "WIBB");
92 * }
93 *
94 * @out_name: Place to put the name
95 * @name: Name to copy
96 * @return 0 (always)
97 */
98int acpi_copy_name(char *out_name, const char *name);
99
Simon Glass17968c32020-04-26 09:19:46 -0600100/**
101 * acpi_write_dev_tables() - Write ACPI tables required by devices
102 *
103 * This scans through all devices and tells them to write any tables they want
104 * to write.
105 *
106 * @return 0 if OK, -ve if any device returned an error
107 */
108int acpi_write_dev_tables(struct acpi_ctx *ctx);
109
Simon Glass4969d212020-04-08 16:57:37 -0600110#endif /* __ACPI__ */
111
Simon Glass9fb9e9b2020-04-09 10:27:38 -0600112#endif