2 * SMI methods for use with dell-smbios
4 * Copyright (c) Red Hat <mjg@redhat.com>
5 * Copyright (c) 2014 Gabriele Mazzotta <gabriele.mzt@gmail.com>
6 * Copyright (c) 2014 Pali Rohár <pali.rohar@gmail.com>
7 * Copyright (c) 2017 Dell Inc.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
13 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15 #include <linux/dmi.h>
16 #include <linux/gfp.h>
18 #include <linux/module.h>
19 #include <linux/mutex.h>
20 #include <linux/platform_device.h>
21 #include "../../firmware/dcdbas.h"
22 #include "dell-smbios.h"
24 static int da_command_address
;
25 static int da_command_code
;
26 static struct calling_interface_buffer
*buffer
;
27 struct platform_device
*platform_device
;
28 static DEFINE_MUTEX(smm_mutex
);
30 static const struct dmi_system_id dell_device_table
[] __initconst
= {
32 .ident
= "Dell laptop",
34 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
35 DMI_MATCH(DMI_CHASSIS_TYPE
, "8"),
40 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
41 DMI_MATCH(DMI_CHASSIS_TYPE
, "9"), /*Laptop*/
46 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
47 DMI_MATCH(DMI_CHASSIS_TYPE
, "10"), /*Notebook*/
51 .ident
= "Dell Computer Corporation",
53 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Computer Corporation"),
54 DMI_MATCH(DMI_CHASSIS_TYPE
, "8"),
59 MODULE_DEVICE_TABLE(dmi
, dell_device_table
);
61 static void __init
parse_da_table(const struct dmi_header
*dm
)
63 struct calling_interface_structure
*table
=
64 container_of(dm
, struct calling_interface_structure
, header
);
66 /* 4 bytes of table header, plus 7 bytes of Dell header, plus at least
72 da_command_address
= table
->cmdIOAddress
;
73 da_command_code
= table
->cmdIOCode
;
76 static void __init
find_cmd_address(const struct dmi_header
*dm
, void *dummy
)
79 case 0xda: /* Calling interface */
85 int dell_smbios_smm_call(struct calling_interface_buffer
*input
)
87 struct smi_cmd command
;
90 size
= sizeof(struct calling_interface_buffer
);
91 command
.magic
= SMI_CMD_MAGIC
;
92 command
.command_address
= da_command_address
;
93 command
.command_code
= da_command_code
;
94 command
.ebx
= virt_to_phys(buffer
);
95 command
.ecx
= 0x42534931;
97 mutex_lock(&smm_mutex
);
98 memcpy(buffer
, input
, size
);
99 dcdbas_smi_request(&command
);
100 memcpy(input
, buffer
, size
);
101 mutex_unlock(&smm_mutex
);
105 static int __init
dell_smbios_smm_init(void)
109 * Allocate buffer below 4GB for SMI data--only 32-bit physical addr
110 * is passed to SMI handler.
112 buffer
= (void *)__get_free_page(GFP_KERNEL
| GFP_DMA32
);
116 dmi_walk(find_cmd_address
, NULL
);
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
);
141 fail_platform_device_alloc
:
142 free_page((unsigned long)buffer
);
146 static void __exit
dell_smbios_smm_exit(void)
148 if (platform_device
) {
149 dell_smbios_unregister_device(&platform_device
->dev
);
150 platform_device_unregister(platform_device
);
151 free_page((unsigned long)buffer
);
155 subsys_initcall(dell_smbios_smm_init
);
156 module_exit(dell_smbios_smm_exit
);
158 MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
159 MODULE_AUTHOR("Gabriele Mazzotta <gabriele.mzt@gmail.com>");
160 MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>");
161 MODULE_AUTHOR("Mario Limonciello <mario.limonciello@dell.com>");
162 MODULE_DESCRIPTION("Dell SMBIOS communications over SMI");
163 MODULE_LICENSE("GPL");