10 #include <linux/kernel.h>
12 #include <linux/types.h>
13 #include <linux/device.h>
15 #include <linux/errno.h>
16 #include <linux/string.h>
21 #include <linux/slab.h>
28 #include <linux/reboot.h>
30 #include <linux/module.h>
32 #define GSMI_SHUTDOWN_CLEAN 0
34 #define GSMI_SHUTDOWN_NMIWDT 1
35 #define GSMI_SHUTDOWN_PANIC 2
36 #define GSMI_SHUTDOWN_OOPS 3
37 #define GSMI_SHUTDOWN_DIE 4
38 #define GSMI_SHUTDOWN_MCE 5
39 #define GSMI_SHUTDOWN_SOFTWDT 6
40 #define GSMI_SHUTDOWN_MBE 7
41 #define GSMI_SHUTDOWN_TRIPLE 8
43 #define DRIVER_VERSION "1.0"
44 #define GSMI_GUID_SIZE 16
45 #define GSMI_BUF_SIZE 1024
46 #define GSMI_BUF_ALIGN sizeof(u64)
47 #define GSMI_CALLBACK 0xef
50 #define GSMI_SUCCESS 0x00
51 #define GSMI_UNSUPPORTED2 0x03
52 #define GSMI_LOG_FULL 0x0b
53 #define GSMI_VAR_NOT_FOUND 0x0e
54 #define GSMI_HANDSHAKE_SPIN 0x7d
55 #define GSMI_HANDSHAKE_CF 0x7e
56 #define GSMI_HANDSHAKE_NONE 0x7f
57 #define GSMI_INVALID_PARAMETER 0x82
58 #define GSMI_UNSUPPORTED 0x83
59 #define GSMI_BUFFER_TOO_SMALL 0x85
60 #define GSMI_NOT_READY 0x86
61 #define GSMI_DEVICE_ERROR 0x87
62 #define GSMI_NOT_FOUND 0x8e
64 #define QUIRKY_BOARD_HASH 0x78a30a50
67 #define GSMI_CMD_GET_NVRAM_VAR 0x01
68 #define GSMI_CMD_GET_NEXT_VAR 0x02
69 #define GSMI_CMD_SET_NVRAM_VAR 0x03
70 #define GSMI_CMD_SET_EVENT_LOG 0x08
71 #define GSMI_CMD_CLEAR_EVENT_LOG 0x09
72 #define GSMI_CMD_CLEAR_CONFIG 0x20
73 #define GSMI_CMD_HANDSHAKE_TYPE 0xC1
76 #define GSMI_LOG_ENTRY_TYPE_KERNEL 0xDEAD
129 #define GSMI_DEFAULT_SPINCOUNT 0x10000
133 "The number of loop iterations to use when using the spin handshake.");
135 static struct gsmi_buf *gsmi_buf_alloc(
void)
139 smibuf = kzalloc(
sizeof(*smibuf),
GFP_KERNEL);
148 if (!smibuf->
start) {
161 static void gsmi_buf_free(
struct gsmi_buf *smibuf)
175 static int gsmi_exec(
u8 func,
u8 sub)
177 u16 cmd = (sub << 8) | func;
229 "outb %%al, %%dx\n\t"
297 while (*data++ != 0 && length < maxlength)
308 .name_ptr =
gsmi_dev.name_buf->address,
309 .data_ptr =
gsmi_dev.data_buf->address,
310 .data_len = (
u32)*data_size,
340 }
else if (rc == 1) {
348 *data_size =
min_t(
unsigned long, *data_size,
350 *data_size =
min_t(
unsigned long, *data_size, param.
data_len);
361 spin_unlock_irqrestore(&
gsmi_dev.lock, flags);
366 static efi_status_t gsmi_get_next_variable(
unsigned long *name_size,
372 .name_len =
gsmi_dev.name_buf->length,
402 }
else if (rc == 1) {
418 spin_unlock_irqrestore(&
gsmi_dev.lock, flags);
426 unsigned long data_size,
431 .data_ptr =
gsmi_dev.data_buf->address,
432 .data_len = (
u32)data_size,
468 spin_unlock_irqrestore(&
gsmi_dev.lock, flags);
473 static const struct efivar_operations efivar_ops = {
474 .get_variable = gsmi_get_variable,
475 .set_variable = gsmi_set_variable,
476 .get_next_variable = gsmi_get_next_variable,
490 if (count <
sizeof(
u32))
493 count -=
sizeof(
u32);
497 if (count >
gsmi_dev.data_buf->length)
515 spin_unlock_irqrestore(&
gsmi_dev.lock, flags);
522 .attr = {.name =
"append_to_eventlog", .mode = 0200},
523 .write = eventlog_write,
528 const char *buf,
size_t count)
550 param.percentage =
val;
561 spin_unlock_irqrestore(&
gsmi_dev.lock, flags);
569 .attr = {.name =
"clear_eventlog", .mode = 0200},
570 .store = gsmi_clear_eventlog_store,
575 const char *buf,
size_t count)
587 spin_unlock_irqrestore(&
gsmi_dev.lock, flags);
595 .attr = {.name =
"clear_config", .mode = 0200},
596 .store = gsmi_clear_config_store,
599 static const struct attribute *gsmi_attrs[] = {
600 &gsmi_clear_config_attr.
attr,
601 &gsmi_clear_eventlog_attr.
attr,
605 static int gsmi_shutdown_reason(
int reason)
615 static int saved_reason;
620 if (saved_reason & (1 << reason))
625 saved_reason |= (1 <<
reason);
638 spin_unlock_irqrestore(&
gsmi_dev.lock, flags);
650 unsigned long reason,
void *
arg)
657 .notifier_call = gsmi_reboot_callback
661 unsigned long reason,
void *
arg)
669 .notifier_call = gsmi_die_callback
673 unsigned long reason,
void *arg)
680 .notifier_call = gsmi_panic_callback,
712 return hash >> (64 -
bits);
715 static u32 __init hash_oem_table_id(
char s[8])
719 return local_hash_64(input, 32);
724 .ident =
"Google Board",
733 static __init int gsmi_system_valid(
void)
757 if (
strncmp(bios_ver,
"1.0", 3) == 0) {
758 pr_info(
"gsmi: disabled on this board's BIOS %s\n",
766 pr_info(
"gsmi: missing smi_command\n");
774 static struct kobject *gsmi_kobj;
775 static struct efivars efivars;
777 static __init int gsmi_init(
void)
782 ret = gsmi_system_valid();
789 gsmi_dev.pdev = platform_device_register_simple(
"gsmi", -1,
NULL, 0);
801 &
gsmi_dev.pdev->dev.coherent_dma_mask;
812 gsmi_dev.name_buf = gsmi_buf_alloc();
818 gsmi_dev.data_buf = gsmi_buf_alloc();
824 gsmi_dev.param_buf = gsmi_buf_alloc();
864 spin_unlock_irqrestore(&
gsmi_dev.lock, flags);
869 " failed to load\n");
893 goto out_remove_bin_file;
899 goto out_remove_sysfs_files;
905 &gsmi_panic_notifier);
911 out_remove_sysfs_files:
923 pr_info(
"gsmi: failed to load: %d\n", ret);
927 static void __exit gsmi_exit(
void)
932 &gsmi_panic_notifier);