/* SPDX-License-Identifier: GPL-2.0-only */


#ifndef _LINUX_WMI_H
#define _LINUX_WMI_H

#include <linux/compiler_attributes.h>
#include <linux/device.h>
#include <linux/acpi.h>
#include <linux/mod_devicetable.h>
#include <linux/types.h>


struct wmi_device {
	struct device dev;
	bool setable;
};


#define to_wmi_device(device)	container_of_const(device, struct wmi_device, dev)


struct wmi_buffer {
	size_t length;
	void *data;
};


struct wmi_string {
	__le16 length;
	__le16 chars[];
} __packed;

ssize_t wmi_string_to_utf8s(const struct wmi_string *str, u8 *dst, size_t length);

ssize_t wmi_string_from_utf8s(struct wmi_string *str, size_t max_chars, const u8 *src,
			      size_t src_length);

int wmidev_invoke_method(struct wmi_device *wdev, u8 instance, u32 method_id,
			 const struct wmi_buffer *in, struct wmi_buffer *out);

int wmidev_query_block(struct wmi_device *wdev, u8 instance, struct wmi_buffer *out);

int wmidev_set_block(struct wmi_device *wdev, u8 instance, const struct wmi_buffer *in);

acpi_status wmidev_evaluate_method(struct wmi_device *wdev, u8 instance, u32 method_id,
				   const struct acpi_buffer *in, struct acpi_buffer *out);

union acpi_object *wmidev_block_query(struct wmi_device *wdev, u8 instance);

acpi_status wmidev_block_set(struct wmi_device *wdev, u8 instance, const struct acpi_buffer *in);

u8 wmidev_instance_count(struct wmi_device *wdev);


struct wmi_driver {
	struct device_driver driver;
	const struct wmi_device_id *id_table;
	bool no_notify_data;
	bool no_singleton;

	int (*probe)(struct wmi_device *wdev, const void *context);
	void (*remove)(struct wmi_device *wdev);
	void (*shutdown)(struct wmi_device *wdev);
	void (*notify)(struct wmi_device *device, union acpi_object *data);
	void (*notify_new)(struct wmi_device *device, const struct wmi_buffer *data);
};


#define to_wmi_driver(drv)	container_of_const(drv, struct wmi_driver, driver)

int __must_check __wmi_driver_register(struct wmi_driver *driver, struct module *owner);

void wmi_driver_unregister(struct wmi_driver *driver);


#define wmi_driver_register(driver) __wmi_driver_register((driver), THIS_MODULE)


#define module_wmi_driver(__wmi_driver) \
	module_driver(__wmi_driver, wmi_driver_register, \
		      wmi_driver_unregister)

#endif
