blob: 696b1a96a0999e0a2ef8e7e4a39b7028a851d51d [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
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 Glass89c27982020-04-08 16:57:37 -060025#if !defined(__ACPI__)
26
Simon Glass7ca28502020-04-09 10:27:38 -060027/**
Simon Glass93f7f822020-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 *
Simon Glass61cc9332020-07-07 13:11:42 -060032 * @base: Base address of ACPI tables
Simon Glass93f7f822020-04-26 09:19:46 -060033 * @current: Current address for writing
Simon Glass29b35112020-04-26 09:19:50 -060034 * @rsdp: Pointer to the Root System Description Pointer, typically used when
35 * adding a new table. The RSDP holds pointers to the RSDT and XSDT.
36 * @rsdt: Pointer to the Root System Description Table
Simon Glassb38309b2020-04-26 09:19:52 -060037 * @xsdt: Pointer to the Extended System Description Table
Simon Glass93f7f822020-04-26 09:19:46 -060038 */
39struct acpi_ctx {
Simon Glass61cc9332020-07-07 13:11:42 -060040 void *base;
Simon Glass93f7f822020-04-26 09:19:46 -060041 void *current;
Simon Glass29b35112020-04-26 09:19:50 -060042 struct acpi_rsdp *rsdp;
43 struct acpi_rsdt *rsdt;
Simon Glassb38309b2020-04-26 09:19:52 -060044 struct acpi_xsdt *xsdt;
Simon Glass93f7f822020-04-26 09:19:46 -060045};
46
47/**
Simon Glass7ca28502020-04-09 10:27:38 -060048 * struct acpi_ops - ACPI operations supported by driver model
49 */
50struct acpi_ops {
51 /**
52 * get_name() - Obtain the ACPI name of a device
53 *
54 * @dev: Device to check
55 * @out_name: Place to put the name, must hold at least ACPI_NAME_MAX
56 * bytes
57 * @return 0 if OK, -ENOENT if no name is available, other -ve value on
58 * other error
59 */
60 int (*get_name)(const struct udevice *dev, char *out_name);
Simon Glass93f7f822020-04-26 09:19:46 -060061
62 /**
63 * write_tables() - Write out any tables required by this device
64 *
65 * @dev: Device to write
66 * @ctx: ACPI context to use
67 * @return 0 if OK, -ve on error
68 */
69 int (*write_tables)(const struct udevice *dev, struct acpi_ctx *ctx);
Simon Glass7ca28502020-04-09 10:27:38 -060070};
71
72#define device_get_acpi_ops(dev) ((dev)->driver->acpi_ops)
73
74/**
75 * acpi_get_name() - Obtain the ACPI name of a device
76 *
77 * @dev: Device to check
78 * @out_name: Place to put the name, must hold at least ACPI_NAME_MAX
79 * bytes
80 * @return 0 if OK, -ENOENT if no name is available, other -ve value on
81 * other error
82 */
83int acpi_get_name(const struct udevice *dev, char *out_name);
84
85/**
86 * acpi_copy_name() - Copy an ACPI name to an output buffer
87 *
88 * This convenience function can be used to return a literal string as a name
89 * in functions that implement the get_name() method.
90 *
91 * For example:
92 *
93 * static int mydev_get_name(const struct udevice *dev, char *out_name)
94 * {
95 * return acpi_copy_name(out_name, "WIBB");
96 * }
97 *
98 * @out_name: Place to put the name
99 * @name: Name to copy
100 * @return 0 (always)
101 */
102int acpi_copy_name(char *out_name, const char *name);
103
Simon Glass93f7f822020-04-26 09:19:46 -0600104/**
105 * acpi_write_dev_tables() - Write ACPI tables required by devices
106 *
107 * This scans through all devices and tells them to write any tables they want
108 * to write.
109 *
110 * @return 0 if OK, -ve if any device returned an error
111 */
112int acpi_write_dev_tables(struct acpi_ctx *ctx);
113
Simon Glass89c27982020-04-08 16:57:37 -0600114#endif /* __ACPI__ */
115
Simon Glass7ca28502020-04-09 10:27:38 -0600116#endif