blob: ba0813fa21c20e0538fd718ed087dc5ab0b5d58f [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
25/**
26 * struct acpi_ops - ACPI operations supported by driver model
27 */
28struct acpi_ops {
29 /**
30 * get_name() - Obtain the ACPI name of a device
31 *
32 * @dev: Device to check
33 * @out_name: Place to put the name, must hold at least ACPI_NAME_MAX
34 * bytes
35 * @return 0 if OK, -ENOENT if no name is available, other -ve value on
36 * other error
37 */
38 int (*get_name)(const struct udevice *dev, char *out_name);
39};
40
41#define device_get_acpi_ops(dev) ((dev)->driver->acpi_ops)
42
43/**
44 * acpi_get_name() - Obtain the ACPI name of a device
45 *
46 * @dev: Device to check
47 * @out_name: Place to put the name, must hold at least ACPI_NAME_MAX
48 * bytes
49 * @return 0 if OK, -ENOENT if no name is available, other -ve value on
50 * other error
51 */
52int acpi_get_name(const struct udevice *dev, char *out_name);
53
54/**
55 * acpi_copy_name() - Copy an ACPI name to an output buffer
56 *
57 * This convenience function can be used to return a literal string as a name
58 * in functions that implement the get_name() method.
59 *
60 * For example:
61 *
62 * static int mydev_get_name(const struct udevice *dev, char *out_name)
63 * {
64 * return acpi_copy_name(out_name, "WIBB");
65 * }
66 *
67 * @out_name: Place to put the name
68 * @name: Name to copy
69 * @return 0 (always)
70 */
71int acpi_copy_name(char *out_name, const char *name);
72
73#endif