1 // SPDX-License-Identifier: GPL-2.0-only
3 * SMI methods for use with dell-smbios
5 * Copyright (c) Red Hat <mjg@redhat.com>
6 * Copyright (c) 2014 Gabriele Mazzotta <gabriele.mzt@gmail.com>
7 * Copyright (c) 2014 Pali Rohár <pali@kernel.org>
8 * Copyright (c) 2017 Dell Inc.
10 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12 #include <linux/dmi.h>
13 #include <linux/gfp.h>
15 #include <linux/module.h>
16 #include <linux/mutex.h>
17 #include <linux/platform_device.h>
19 #include "dell-smbios.h"
21 static int da_command_address
;
22 static int da_command_code
;
23 static struct smi_buffer smi_buf
;
24 static struct calling_interface_buffer
*buffer
;
25 static struct platform_device
*platform_device
;
26 static DEFINE_MUTEX(smm_mutex
);
28 static void parse_da_table(const struct dmi_header
*dm
)
30 struct calling_interface_structure
*table
=
31 container_of(dm
, struct calling_interface_structure
, header
);
33 /* 4 bytes of table header, plus 7 bytes of Dell header, plus at least
39 da_command_address
= table
->cmdIOAddress
;
40 da_command_code
= table
->cmdIOCode
;
43 static void find_cmd_address(const struct dmi_header
*dm
, void *dummy
)
46 case 0xda: /* Calling interface */
52 static int dell_smbios_smm_call(struct calling_interface_buffer
*input
)
54 struct smi_cmd command
;
57 size
= sizeof(struct calling_interface_buffer
);
58 command
.magic
= SMI_CMD_MAGIC
;
59 command
.command_address
= da_command_address
;
60 command
.command_code
= da_command_code
;
61 command
.ebx
= smi_buf
.dma
;
62 command
.ecx
= 0x42534931;
64 mutex_lock(&smm_mutex
);
65 memcpy(buffer
, input
, size
);
66 dcdbas_smi_request(&command
);
67 memcpy(input
, buffer
, size
);
68 mutex_unlock(&smm_mutex
);
72 /* When enabled this indicates that SMM won't work */
73 static bool test_wsmt_enabled(void)
75 struct calling_interface_token
*wsmt
;
77 /* if token doesn't exist, SMM will work */
78 wsmt
= dell_smbios_find_token(WSMT_EN_TOKEN
);
82 /* If token exists, try to access over SMM but set a dummy return.
83 * - If WSMT disabled it will be overwritten by SMM
84 * - If WSMT enabled then dummy value will remain
86 buffer
->cmd_class
= CLASS_TOKEN_READ
;
87 buffer
->cmd_select
= SELECT_TOKEN_STD
;
88 memset(buffer
, 0, sizeof(struct calling_interface_buffer
));
89 buffer
->input
[0] = wsmt
->location
;
90 buffer
->output
[0] = 99;
91 dell_smbios_smm_call(buffer
);
92 if (buffer
->output
[0] == 99)
98 int init_dell_smbios_smm(void)
102 * Allocate buffer below 4GB for SMI data--only 32-bit physical addr
103 * is passed to SMI handler.
105 ret
= dcdbas_smi_alloc(&smi_buf
, PAGE_SIZE
);
108 buffer
= (void *)smi_buf
.virt
;
110 dmi_walk(find_cmd_address
, NULL
);
112 if (test_wsmt_enabled()) {
113 pr_debug("Disabling due to WSMT enabled\n");
118 platform_device
= platform_device_alloc("dell-smbios", 1);
119 if (!platform_device
) {
121 goto fail_platform_device_alloc
;
124 ret
= platform_device_add(platform_device
);
126 goto fail_platform_device_add
;
128 ret
= dell_smbios_register_device(&platform_device
->dev
,
129 &dell_smbios_smm_call
);
136 platform_device_del(platform_device
);
138 fail_platform_device_add
:
139 platform_device_put(platform_device
);
142 fail_platform_device_alloc
:
143 dcdbas_smi_free(&smi_buf
);
147 void exit_dell_smbios_smm(void)
149 if (platform_device
) {
150 dell_smbios_unregister_device(&platform_device
->dev
);
151 platform_device_unregister(platform_device
);
152 dcdbas_smi_free(&smi_buf
);