2019-05-27 08:55:21 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2017-06-06 10:07:32 -07:00
|
|
|
/*
|
|
|
|
* WMI embedded Binary MOF driver
|
|
|
|
*
|
|
|
|
* Copyright (c) 2015 Andrew Lutomirski
|
2017-06-06 16:40:56 -07:00
|
|
|
* Copyright (C) 2017 VMware, Inc. All Rights Reserved.
|
2017-06-06 10:07:32 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
|
|
|
#include <linux/acpi.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/sysfs.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/wmi.h>
|
|
|
|
|
|
|
|
#define WMI_BMOF_GUID "05901221-D566-11D1-B2F0-00A0C9062910"
|
|
|
|
|
2024-12-06 22:56:50 +01:00
|
|
|
static ssize_t bmof_read(struct file *filp, struct kobject *kobj, const struct bin_attribute *attr,
|
2023-07-30 22:45:49 +02:00
|
|
|
char *buf, loff_t off, size_t count)
|
2017-06-06 10:07:32 -07:00
|
|
|
{
|
2024-12-06 22:56:50 +01:00
|
|
|
struct device *dev = kobj_to_dev(kobj);
|
|
|
|
union acpi_object *obj = dev_get_drvdata(dev);
|
2017-06-06 10:07:32 -07:00
|
|
|
|
2024-12-06 22:56:50 +01:00
|
|
|
return memory_read_from_buffer(buf, count, &off, obj->buffer.pointer, obj->buffer.length);
|
2017-06-06 10:07:32 -07:00
|
|
|
}
|
|
|
|
|
2024-12-06 22:56:50 +01:00
|
|
|
static const BIN_ATTR_ADMIN_RO(bmof, 0);
|
|
|
|
|
|
|
|
static const struct bin_attribute * const bmof_attrs[] = {
|
|
|
|
&bin_attr_bmof,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static size_t bmof_bin_size(struct kobject *kobj, const struct bin_attribute *attr, int n)
|
2017-06-06 10:07:32 -07:00
|
|
|
{
|
2024-12-06 22:56:50 +01:00
|
|
|
struct device *dev = kobj_to_dev(kobj);
|
|
|
|
union acpi_object *obj = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
return obj->buffer.length;
|
|
|
|
}
|
2017-06-06 10:07:32 -07:00
|
|
|
|
2024-12-06 22:56:50 +01:00
|
|
|
static const struct attribute_group bmof_group = {
|
|
|
|
.bin_size = bmof_bin_size,
|
2025-05-30 05:54:38 +02:00
|
|
|
.bin_attrs = bmof_attrs,
|
2024-12-06 22:56:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct attribute_group *bmof_groups[] = {
|
|
|
|
&bmof_group,
|
|
|
|
NULL
|
|
|
|
};
|
2017-06-06 10:07:32 -07:00
|
|
|
|
2024-12-06 22:56:50 +01:00
|
|
|
static int wmi_bmof_probe(struct wmi_device *wdev, const void *context)
|
|
|
|
{
|
|
|
|
union acpi_object *obj;
|
2017-06-06 10:07:32 -07:00
|
|
|
|
2024-12-06 22:56:50 +01:00
|
|
|
obj = wmidev_block_query(wdev, 0);
|
|
|
|
if (!obj) {
|
2017-06-06 10:07:32 -07:00
|
|
|
dev_err(&wdev->dev, "failed to read Binary MOF\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2024-12-06 22:56:50 +01:00
|
|
|
if (obj->type != ACPI_TYPE_BUFFER) {
|
2017-06-06 10:07:32 -07:00
|
|
|
dev_err(&wdev->dev, "Binary MOF is not a buffer\n");
|
2024-12-06 22:56:50 +01:00
|
|
|
kfree(obj);
|
|
|
|
return -EIO;
|
2017-06-06 10:07:32 -07:00
|
|
|
}
|
|
|
|
|
2024-12-06 22:56:50 +01:00
|
|
|
dev_set_drvdata(&wdev->dev, obj);
|
2017-06-06 10:07:32 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-01 17:04:04 +01:00
|
|
|
static void wmi_bmof_remove(struct wmi_device *wdev)
|
2017-06-06 10:07:32 -07:00
|
|
|
{
|
2024-12-06 22:56:50 +01:00
|
|
|
union acpi_object *obj = dev_get_drvdata(&wdev->dev);
|
2017-06-06 10:07:32 -07:00
|
|
|
|
2024-12-06 22:56:50 +01:00
|
|
|
kfree(obj);
|
2017-06-06 10:07:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wmi_device_id wmi_bmof_id_table[] = {
|
|
|
|
{ .guid_string = WMI_BMOF_GUID },
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct wmi_driver wmi_bmof_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "wmi-bmof",
|
2024-12-06 22:56:50 +01:00
|
|
|
.dev_groups = bmof_groups,
|
2017-06-06 10:07:32 -07:00
|
|
|
},
|
|
|
|
.probe = wmi_bmof_probe,
|
|
|
|
.remove = wmi_bmof_remove,
|
|
|
|
.id_table = wmi_bmof_id_table,
|
2024-02-26 20:35:56 +01:00
|
|
|
.no_singleton = true,
|
2017-06-06 10:07:32 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
module_wmi_driver(wmi_bmof_driver);
|
|
|
|
|
2019-02-19 20:59:56 +01:00
|
|
|
MODULE_DEVICE_TABLE(wmi, wmi_bmof_id_table);
|
2017-06-06 10:07:32 -07:00
|
|
|
MODULE_AUTHOR("Andrew Lutomirski <luto@kernel.org>");
|
|
|
|
MODULE_DESCRIPTION("WMI embedded Binary MOF driver");
|
|
|
|
MODULE_LICENSE("GPL");
|