Skip to content

Commit f2645fa

Browse files
Mario Limonciellodvhart
authored andcommitted
platform/x86: dell-smbios-wmi: introduce userspace interface
It's important for the driver to provide a R/W ioctl to ensure that two competing userspace processes don't race to provide or read each others data. This userspace character device will be used to perform SMBIOS calls from any applications. It provides an ioctl that will allow passing the WMI calling interface buffer between userspace and kernel space. This character device is intended to deprecate the dcdbas kernel module and the interface that it provides to userspace. To perform an SMBIOS IOCTL call using the character device userspace will perform a read() on the the character device. The WMI bus will provide a u64 variable containing the necessary size of the IOCTL buffer. The API for interacting with this interface is defined in documentation as well as the WMI uapi header provides the format of the structures. Not all userspace requests will be accepted. The dell-smbios filtering functionality will be used to prevent access to certain tokens and calls. All whitelisted commands and tokens are now shared out to userspace so applications don't need to define them in their own headers. Signed-off-by: Mario Limonciello <mario.limonciello@dell.com> Reviewed-by: Edward O'Callaghan <quasisec@google.com> Signed-off-by: Darren Hart (VMware) <dvhart@infradead.org>
1 parent 44b6b76 commit f2645fa

4 files changed

Lines changed: 133 additions & 41 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
What: /dev/wmi/dell-smbios
2+
Date: November 2017
3+
KernelVersion: 4.15
4+
Contact: "Mario Limonciello" <mario.limonciello@dell.com>
5+
Description:
6+
Perform SMBIOS calls on supported Dell machines.
7+
through the Dell ACPI-WMI interface.
8+
9+
IOCTL's and buffer formats are defined in:
10+
<uapi/linux/wmi.h>
11+
12+
1) To perform an SMBIOS call from userspace, you'll need to
13+
first determine the minimum size of the calling interface
14+
buffer for your machine.
15+
Platforms that contain larger buffers can return larger
16+
objects from the system firmware.
17+
Commonly this size is either 4k or 32k.
18+
19+
To determine the size of the buffer read() a u64 dword from
20+
the WMI character device /dev/wmi/dell-smbios.
21+
22+
2) After you've determined the minimum size of the calling
23+
interface buffer, you can allocate a structure that represents
24+
the structure documented above.
25+
26+
3) In the 'length' object store the size of the buffer you
27+
determined above and allocated.
28+
29+
4) In this buffer object, prepare as necessary for the SMBIOS
30+
call you're interested in. Typically SMBIOS buffers have
31+
"class", "select", and "input" defined to values that coincide
32+
with the data you are interested in.
33+
Documenting class/select/input values is outside of the scope
34+
of this documentation. Check with the libsmbios project for
35+
further documentation on these values.
36+
37+
6) Run the call by using ioctl() as described in the header.
38+
39+
7) The output will be returned in the buffer object.
40+
41+
8) Be sure to free up your allocated object.

‎drivers/platform/x86/dell-smbios-wmi.c‎

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,6 @@ struct misc_bios_flags_structure {
3030

3131
#define DELL_WMI_SMBIOS_GUID "A80593CE-A997-11DA-B012-B622A1EF5492"
3232

33-
struct dell_wmi_extensions {
34-
__u32 argattrib;
35-
__u32 blength;
36-
__u8 data[];
37-
} __packed;
38-
39-
struct dell_wmi_smbios_buffer {
40-
struct calling_interface_buffer std;
41-
struct dell_wmi_extensions ext;
42-
} __packed;
43-
4433
struct wmi_smbios_priv {
4534
struct dell_wmi_smbios_buffer *buf;
4635
struct list_head list;
@@ -117,6 +106,42 @@ int dell_smbios_wmi_call(struct calling_interface_buffer *buffer)
117106
return ret;
118107
}
119108

109+
static long dell_smbios_wmi_filter(struct wmi_device *wdev, unsigned int cmd,
110+
struct wmi_ioctl_buffer *arg)
111+
{
112+
struct wmi_smbios_priv *priv;
113+
int ret = 0;
114+
115+
switch (cmd) {
116+
case DELL_WMI_SMBIOS_CMD:
117+
mutex_lock(&call_mutex);
118+
priv = dev_get_drvdata(&wdev->dev);
119+
if (!priv) {
120+
ret = -ENODEV;
121+
goto fail_smbios_cmd;
122+
}
123+
memcpy(priv->buf, arg, priv->req_buf_size);
124+
if (dell_smbios_call_filter(&wdev->dev, &priv->buf->std)) {
125+
dev_err(&wdev->dev, "Invalid call %d/%d:%8x\n",
126+
priv->buf->std.cmd_class,
127+
priv->buf->std.cmd_select,
128+
priv->buf->std.input[0]);
129+
ret = -EFAULT;
130+
goto fail_smbios_cmd;
131+
}
132+
ret = run_smbios_call(priv->wdev);
133+
if (ret)
134+
goto fail_smbios_cmd;
135+
memcpy(arg, priv->buf, priv->req_buf_size);
136+
fail_smbios_cmd:
137+
mutex_unlock(&call_mutex);
138+
break;
139+
default:
140+
ret = -ENOIOCTLCMD;
141+
}
142+
return ret;
143+
}
144+
120145
static int dell_smbios_wmi_probe(struct wmi_device *wdev)
121146
{
122147
struct wmi_smbios_priv *priv;
@@ -135,6 +160,12 @@ static int dell_smbios_wmi_probe(struct wmi_device *wdev)
135160
if (!dell_wmi_get_size(&priv->req_buf_size))
136161
return -EPROBE_DEFER;
137162

163+
/* add in the length object we will use internally with ioctl */
164+
priv->req_buf_size += sizeof(u64);
165+
ret = set_required_buffer_size(wdev, priv->req_buf_size);
166+
if (ret)
167+
return ret;
168+
138169
count = get_order(priv->req_buf_size);
139170
priv->buf = (void *)__get_free_pages(GFP_KERNEL, count);
140171
if (!priv->buf)
@@ -210,6 +241,7 @@ static struct wmi_driver dell_smbios_wmi_driver = {
210241
.probe = dell_smbios_wmi_probe,
211242
.remove = dell_smbios_wmi_remove,
212243
.id_table = dell_smbios_wmi_id_table,
244+
.filter_callback = dell_smbios_wmi_filter,
213245
};
214246

215247
static int __init init_dell_smbios_wmi(void)

‎drivers/platform/x86/dell-smbios.h‎

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,11 @@
1717
#define _DELL_SMBIOS_H_
1818

1919
#include <linux/device.h>
20+
#include <uapi/linux/wmi.h>
2021

21-
/* Classes and selects used in kernel drivers */
22-
#define CLASS_TOKEN_READ 0
23-
#define CLASS_TOKEN_WRITE 1
24-
#define SELECT_TOKEN_STD 0
25-
#define SELECT_TOKEN_BAT 1
26-
#define SELECT_TOKEN_AC 2
22+
/* Classes and selects used only in kernel drivers */
2723
#define CLASS_KBD_BACKLIGHT 4
2824
#define SELECT_KBD_BACKLIGHT 11
29-
#define CLASS_FLASH_INTERFACE 7
30-
#define SELECT_FLASH_INTERFACE 3
31-
#define CLASS_ADMIN_PROP 10
32-
#define SELECT_ADMIN_PROP 3
33-
#define CLASS_INFO 17
34-
#define SELECT_RFKILL 11
35-
#define SELECT_APP_REGISTRATION 3
36-
#define SELECT_DOCK 22
3725

3826
/* Tokens used in kernel drivers, any of these
3927
* should be filtered from userspace access
@@ -50,24 +38,8 @@
5038
#define GLOBAL_MIC_MUTE_ENABLE 0x0364
5139
#define GLOBAL_MIC_MUTE_DISABLE 0x0365
5240

53-
/* tokens whitelisted to userspace use */
54-
#define CAPSULE_EN_TOKEN 0x0461
55-
#define CAPSULE_DIS_TOKEN 0x0462
56-
#define WSMT_EN_TOKEN 0x04EC
57-
#define WSMT_DIS_TOKEN 0x04ED
58-
5941
struct notifier_block;
6042

61-
/* This structure will be modified by the firmware when we enter
62-
* system management mode, hence the volatiles */
63-
64-
struct calling_interface_buffer {
65-
u16 cmd_class;
66-
u16 cmd_select;
67-
volatile u32 input[4];
68-
volatile u32 output[4];
69-
} __packed;
70-
7143
struct calling_interface_token {
7244
u16 tokenID;
7345
u16 location;

‎include/uapi/linux/wmi.h‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#ifndef _UAPI_LINUX_WMI_H
1111
#define _UAPI_LINUX_WMI_H
1212

13+
#include <linux/ioctl.h>
1314
#include <linux/types.h>
1415

1516
/* WMI bus will filter all WMI vendor driver requests through this IOC */
@@ -23,4 +24,50 @@ struct wmi_ioctl_buffer {
2324
__u8 data[];
2425
};
2526

27+
/* This structure may be modified by the firmware when we enter
28+
* system management mode through SMM, hence the volatiles
29+
*/
30+
struct calling_interface_buffer {
31+
__u16 cmd_class;
32+
__u16 cmd_select;
33+
volatile __u32 input[4];
34+
volatile __u32 output[4];
35+
} __packed;
36+
37+
struct dell_wmi_extensions {
38+
__u32 argattrib;
39+
__u32 blength;
40+
__u8 data[];
41+
} __packed;
42+
43+
struct dell_wmi_smbios_buffer {
44+
__u64 length;
45+
struct calling_interface_buffer std;
46+
struct dell_wmi_extensions ext;
47+
} __packed;
48+
49+
/* Whitelisted smbios class/select commands */
50+
#define CLASS_TOKEN_READ 0
51+
#define CLASS_TOKEN_WRITE 1
52+
#define SELECT_TOKEN_STD 0
53+
#define SELECT_TOKEN_BAT 1
54+
#define SELECT_TOKEN_AC 2
55+
#define CLASS_FLASH_INTERFACE 7
56+
#define SELECT_FLASH_INTERFACE 3
57+
#define CLASS_ADMIN_PROP 10
58+
#define SELECT_ADMIN_PROP 3
59+
#define CLASS_INFO 17
60+
#define SELECT_RFKILL 11
61+
#define SELECT_APP_REGISTRATION 3
62+
#define SELECT_DOCK 22
63+
64+
/* whitelisted tokens */
65+
#define CAPSULE_EN_TOKEN 0x0461
66+
#define CAPSULE_DIS_TOKEN 0x0462
67+
#define WSMT_EN_TOKEN 0x04EC
68+
#define WSMT_DIS_TOKEN 0x04ED
69+
70+
/* Dell SMBIOS calling IOCTL command used by dell-smbios-wmi */
71+
#define DELL_WMI_SMBIOS_CMD _IOWR(WMI_IOC, 0, struct dell_wmi_smbios_buffer)
72+
2673
#endif

0 commit comments

Comments
 (0)