| 1 |
// SPDX-License-Identifier: GPL-2.0-only |
| 2 |
/* |
| 3 |
* WMI embedded Binary MOF driver |
| 4 |
* |
| 5 |
* Copyright (c) 2015 Andrew Lutomirski |
| 6 |
* Copyright (C) 2017 VMware, Inc. All Rights Reserved. |
| 7 |
*/ |
| 8 |
|
| 9 |
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 10 |
|
| 11 |
#include <linux/device.h> |
| 12 |
#include <linux/fs.h> |
| 13 |
#include <linux/kernel.h> |
| 14 |
#include <linux/module.h> |
| 15 |
#include <linux/string.h> |
| 16 |
#include <linux/sysfs.h> |
| 17 |
#include <linux/types.h> |
| 18 |
#include <linux/wmi.h> |
| 19 |
|
| 20 |
#define WMI_BMOF_GUID "05901221-D566-11D1-B2F0-00A0C9062910" |
| 21 |
|
| 22 |
static ssize_t bmof_read(struct file *filp, struct kobject *kobj, const struct bin_attribute *attr, |
| 23 |
char *buf, loff_t off, size_t count) |
| 24 |
{ |
| 25 |
struct device *dev = kobj_to_dev(kobj); |
| 26 |
struct wmi_buffer *buffer = dev_get_drvdata(dev); |
| 27 |
|
| 28 |
return memory_read_from_buffer(buf, count, &off, buffer->data, buffer->length); |
| 29 |
} |
| 30 |
|
| 31 |
static const BIN_ATTR_ADMIN_RO(bmof, 0); |
| 32 |
|
| 33 |
static const struct bin_attribute * const bmof_attrs[] = { |
| 34 |
&bin_attr_bmof, |
| 35 |
NULL |
| 36 |
}; |
| 37 |
|
| 38 |
static size_t bmof_bin_size(struct kobject *kobj, const struct bin_attribute *attr, int n) |
| 39 |
{ |
| 40 |
struct device *dev = kobj_to_dev(kobj); |
| 41 |
struct wmi_buffer *buffer = dev_get_drvdata(dev); |
| 42 |
|
| 43 |
return buffer->length; |
| 44 |
} |
| 45 |
|
| 46 |
static const struct attribute_group bmof_group = { |
| 47 |
.bin_size = bmof_bin_size, |
| 48 |
.bin_attrs = bmof_attrs, |
| 49 |
}; |
| 50 |
|
| 51 |
static const struct attribute_group *bmof_groups[] = { |
| 52 |
&bmof_group, |
| 53 |
NULL |
| 54 |
}; |
| 55 |
|
| 56 |
static int wmi_bmof_probe(struct wmi_device *wdev, const void *context) |
| 57 |
{ |
| 58 |
struct wmi_buffer *buffer; |
| 59 |
int ret; |
| 60 |
|
| 61 |
buffer = devm_kzalloc(&wdev->dev, sizeof(*buffer), GFP_KERNEL); |
| 62 |
if (!buffer) |
| 63 |
return -ENOMEM; |
| 64 |
|
| 65 |
ret = wmidev_query_block(wdev, 0, buffer); |
| 66 |
if (ret < 0) |
| 67 |
return ret; |
| 68 |
|
| 69 |
dev_set_drvdata(&wdev->dev, buffer); |
| 70 |
|
| 71 |
return 0; |
| 72 |
} |
| 73 |
|
| 74 |
static void wmi_bmof_remove(struct wmi_device *wdev) |
| 75 |
{ |
| 76 |
struct wmi_buffer *buffer = dev_get_drvdata(&wdev->dev); |
| 77 |
|
| 78 |
kfree(buffer->data); |
| 79 |
} |
| 80 |
|
| 81 |
static const struct wmi_device_id wmi_bmof_id_table[] = { |
| 82 |
{ .guid_string = WMI_BMOF_GUID }, |
| 83 |
{ }, |
| 84 |
}; |
| 85 |
|
| 86 |
static struct wmi_driver wmi_bmof_driver = { |
| 87 |
.driver = { |
| 88 |
.name = "wmi-bmof", |
| 89 |
.dev_groups = bmof_groups, |
| 90 |
}, |
| 91 |
.probe = wmi_bmof_probe, |
| 92 |
.remove = wmi_bmof_remove, |
| 93 |
.id_table = wmi_bmof_id_table, |
| 94 |
.no_singleton = true, |
| 95 |
}; |
| 96 |
|
| 97 |
module_wmi_driver(wmi_bmof_driver); |
| 98 |
|
| 99 |
MODULE_DEVICE_TABLE(wmi, wmi_bmof_id_table); |
| 100 |
MODULE_AUTHOR("Andrew Lutomirski <[email protected]>"); |
| 101 |
MODULE_DESCRIPTION("WMI embedded Binary MOF driver"); |
| 102 |
MODULE_LICENSE("GPL"); |