Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * wmi.h - ACPI WMI interface
4 *
5 * Copyright (c) 2015 Andrew Lutomirski
6 */
7
8#ifndef _LINUX_WMI_H
9#define _LINUX_WMI_H
10
11#include <linux/compiler_attributes.h>
12#include <linux/device.h>
13#include <linux/acpi.h>
14#include <linux/mod_devicetable.h>
15#include <linux/types.h>
16
17/**
18 * struct wmi_device - WMI device structure
19 * @dev: Device associated with this WMI device
20 * @setable: True for devices implementing the Set Control Method
21 * @driver_override: Driver name to force a match; do not set directly,
22 * because core frees it; use driver_set_override() to
23 * set or clear it.
24 *
25 * This represents WMI devices discovered by the WMI driver core.
26 */
27struct wmi_device {
28 struct device dev;
29 bool setable;
30 const char *driver_override;
31};
32
33/**
34 * to_wmi_device() - Helper macro to cast a device to a wmi_device
35 * @device: device struct
36 *
37 * Cast a struct device to a struct wmi_device.
38 */
39#define to_wmi_device(device) container_of_const(device, struct wmi_device, dev)
40
41/**
42 * struct wmi_buffer - WMI data buffer
43 * @length: Buffer length in bytes
44 * @data: Pointer to the buffer content
45 *
46 * This structure is used to exchange data with the WMI driver core.
47 */
48struct wmi_buffer {
49 size_t length;
50 void *data;
51};
52
53/**
54 * struct wmi_string - WMI string representation
55 * @length: Size of @chars in bytes
56 * @chars: UTF16-LE characters with optional nul termination and padding
57 *
58 * This structure is used when exchanging string data over the WMI interface.
59 */
60struct wmi_string {
61 __le16 length;
62 __le16 chars[];
63} __packed;
64
65ssize_t wmi_string_to_utf8s(const struct wmi_string *str, u8 *dst, size_t length);
66
67ssize_t wmi_string_from_utf8s(struct wmi_string *str, size_t max_chars, const u8 *src,
68 size_t src_length);
69
70int wmidev_invoke_method(struct wmi_device *wdev, u8 instance, u32 method_id,
71 const struct wmi_buffer *in, struct wmi_buffer *out);
72
73int wmidev_query_block(struct wmi_device *wdev, u8 instance, struct wmi_buffer *out);
74
75int wmidev_set_block(struct wmi_device *wdev, u8 instance, const struct wmi_buffer *in);
76
77acpi_status wmidev_evaluate_method(struct wmi_device *wdev, u8 instance, u32 method_id,
78 const struct acpi_buffer *in, struct acpi_buffer *out);
79
80union acpi_object *wmidev_block_query(struct wmi_device *wdev, u8 instance);
81
82acpi_status wmidev_block_set(struct wmi_device *wdev, u8 instance, const struct acpi_buffer *in);
83
84u8 wmidev_instance_count(struct wmi_device *wdev);
85
86/**
87 * struct wmi_driver - WMI driver structure
88 * @driver: Driver model structure
89 * @id_table: List of WMI GUIDs supported by this driver
90 * @no_notify_data: Driver supports WMI events which provide no event data
91 * @no_singleton: Driver can be instantiated multiple times
92 * @probe: Callback for device binding
93 * @remove: Callback for device unbinding
94 * @shutdown: Callback for device shutdown
95 * @notify: Callback for receiving WMI events (deprecated)
96 * @notify_new: Callback for receiving WMI events
97 *
98 * This represents WMI drivers which handle WMI devices. The data inside the buffer
99 * passed to the @notify_new callback is guaranteed to be aligned on a 8-byte boundary.
100 */
101struct wmi_driver {
102 struct device_driver driver;
103 const struct wmi_device_id *id_table;
104 bool no_notify_data;
105 bool no_singleton;
106
107 int (*probe)(struct wmi_device *wdev, const void *context);
108 void (*remove)(struct wmi_device *wdev);
109 void (*shutdown)(struct wmi_device *wdev);
110 void (*notify)(struct wmi_device *device, union acpi_object *data);
111 void (*notify_new)(struct wmi_device *device, const struct wmi_buffer *data);
112};
113
114/**
115 * to_wmi_driver() - Helper macro to cast a driver to a wmi_driver
116 * @drv: driver struct
117 *
118 * Cast a struct device_driver to a struct wmi_driver.
119 */
120#define to_wmi_driver(drv) container_of_const(drv, struct wmi_driver, driver)
121
122int __must_check __wmi_driver_register(struct wmi_driver *driver, struct module *owner);
123
124void wmi_driver_unregister(struct wmi_driver *driver);
125
126/**
127 * wmi_driver_register() - Helper macro to register a WMI driver
128 * @driver: wmi_driver struct
129 *
130 * Helper macro for registering a WMI driver. It automatically passes
131 * THIS_MODULE to the underlying function.
132 */
133#define wmi_driver_register(driver) __wmi_driver_register((driver), THIS_MODULE)
134
135/**
136 * module_wmi_driver() - Helper macro to register/unregister a WMI driver
137 * @__wmi_driver: wmi_driver struct
138 *
139 * Helper macro for WMI drivers which do not do anything special in module
140 * init/exit. This eliminates a lot of boilerplate. Each module may only
141 * use this macro once, and calling it replaces module_init() and module_exit().
142 */
143#define module_wmi_driver(__wmi_driver) \
144 module_driver(__wmi_driver, wmi_driver_register, \
145 wmi_driver_unregister)
146
147#endif