2 * Copyright 2010 Google Inc. All Rights Reserved.
3 * Author: dlaurie@google.com (Duncan Laurie)
5 * Re-worked to expose sysfs APIs by mikew@google.com (Mike Waychison)
7 * EFI SMI interface for Google platforms
10 #include <linux/kernel.h>
11 #include <linux/init.h>
12 #include <linux/types.h>
13 #include <linux/device.h>
14 #include <linux/platform_device.h>
15 #include <linux/errno.h>
16 #include <linux/string.h>
17 #include <linux/spinlock.h>
18 #include <linux/dma-mapping.h>
19 #include <linux/dmapool.h>
21 #include <linux/slab.h>
22 #include <linux/ioctl.h>
23 #include <linux/acpi.h>
25 #include <linux/uaccess.h>
26 #include <linux/dmi.h>
27 #include <linux/kdebug.h>
28 #include <linux/reboot.h>
29 #include <linux/efi.h>
30 #include <linux/module.h>
32 #define GSMI_SHUTDOWN_CLEAN 0 /* Clean Shutdown */
33 /* TODO(mikew@google.com): Tie in HARDLOCKUP_DETECTOR with NMIWDT */
34 #define GSMI_SHUTDOWN_NMIWDT 1 /* NMI Watchdog */
35 #define GSMI_SHUTDOWN_PANIC 2 /* Panic */
36 #define GSMI_SHUTDOWN_OOPS 3 /* Oops */
37 #define GSMI_SHUTDOWN_DIE 4 /* Die -- No longer meaningful */
38 #define GSMI_SHUTDOWN_MCE 5 /* Machine Check */
39 #define GSMI_SHUTDOWN_SOFTWDT 6 /* Software Watchdog */
40 #define GSMI_SHUTDOWN_MBE 7 /* Uncorrected ECC */
41 #define GSMI_SHUTDOWN_TRIPLE 8 /* Triple Fault */
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
49 /* SMI return codes */
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
66 /* Internally used commands passed to the firmware */
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
75 /* Magic entry type for kernel events */
76 #define GSMI_LOG_ENTRY_TYPE_KERNEL 0xDEAD
78 /* SMI buffers must be in 32bit physical address space */
80 u8 *start; /* start of buffer */
81 size_t length; /* length of buffer */
82 dma_addr_t handle; /* dma allocation handle */
83 u32 address; /* physical address of buffer */
87 struct platform_device *pdev; /* platform device */
88 struct gsmi_buf *name_buf; /* variable name buffer */
89 struct gsmi_buf *data_buf; /* generic data buffer */
90 struct gsmi_buf *param_buf; /* parameter buffer */
91 spinlock_t lock; /* serialize access to SMIs */
92 u16 smi_cmd; /* SMI command port */
93 int handshake_type; /* firmware handler interlock type */
94 struct dma_pool *dma_pool; /* DMA buffer pool */
97 /* Packed structures for communicating with the firmware */
98 struct gsmi_nvram_var_param {
106 struct gsmi_get_next_var_param {
107 u8 guid[GSMI_GUID_SIZE];
112 struct gsmi_set_eventlog_param {
118 /* Event log formats */
119 struct gsmi_log_entry_type_1 {
126 * Some platforms don't have explicit SMI handshake
127 * and need to wait for SMI to complete.
129 #define GSMI_DEFAULT_SPINCOUNT 0x10000
130 static unsigned int spincount = GSMI_DEFAULT_SPINCOUNT;
131 module_param(spincount, uint, 0600);
132 MODULE_PARM_DESC(spincount,
133 "The number of loop iterations to use when using the spin handshake.");
135 static struct gsmi_buf *gsmi_buf_alloc(void)
137 struct gsmi_buf *smibuf;
139 smibuf = kzalloc(sizeof(*smibuf), GFP_KERNEL);
141 printk(KERN_ERR "gsmi: out of memory\n");
145 /* allocate buffer in 32bit address space */
146 smibuf->start = dma_pool_alloc(gsmi_dev.dma_pool, GFP_KERNEL,
148 if (!smibuf->start) {
149 printk(KERN_ERR "gsmi: failed to allocate name buffer\n");
154 /* fill in the buffer handle */
155 smibuf->length = GSMI_BUF_SIZE;
156 smibuf->address = (u32)virt_to_phys(smibuf->start);
161 static void gsmi_buf_free(struct gsmi_buf *smibuf)
165 dma_pool_free(gsmi_dev.dma_pool, smibuf->start,
172 * Make a call to gsmi func(sub). GSMI error codes are translated to
173 * in-kernel errnos (0 on success, -ERRNO on error).
175 static int gsmi_exec(u8 func, u8 sub)
177 u16 cmd = (sub << 8) | func;
182 * AH : Subfunction number
183 * AL : Function number
184 * EBX : Parameter block address
185 * DX : SMI command port
187 * Three protocols here. See also the comment in gsmi_init().
189 if (gsmi_dev.handshake_type == GSMI_HANDSHAKE_CF) {
191 * If handshake_type == HANDSHAKE_CF then set CF on the
192 * way in and wait for the handler to clear it; this avoids
193 * corrupting register state on those chipsets which have
194 * a delay between writing the SMI trigger register and
203 "d" (gsmi_dev.smi_cmd),
204 "b" (gsmi_dev.param_buf->address)
207 } else if (gsmi_dev.handshake_type == GSMI_HANDSHAKE_SPIN) {
209 * If handshake_type == HANDSHAKE_SPIN we spin a
210 * hundred-ish usecs to ensure the SMI has triggered.
217 "d" (gsmi_dev.smi_cmd),
218 "b" (gsmi_dev.param_buf->address),
224 * If handshake_type == HANDSHAKE_NONE we do nothing;
225 * either we don't need to or it's legacy firmware that
226 * doesn't understand the CF protocol.
229 "outb %%al, %%dx\n\t"
232 "d" (gsmi_dev.smi_cmd),
233 "b" (gsmi_dev.param_buf->address)
238 /* check return code from SMI handler */
242 case GSMI_VAR_NOT_FOUND:
243 /* not really an error, but let the caller know */
246 case GSMI_INVALID_PARAMETER:
247 printk(KERN_ERR "gsmi: exec 0x%04x: Invalid parameter\n", cmd);
250 case GSMI_BUFFER_TOO_SMALL:
251 printk(KERN_ERR "gsmi: exec 0x%04x: Buffer too small\n", cmd);
254 case GSMI_UNSUPPORTED:
255 case GSMI_UNSUPPORTED2:
256 if (sub != GSMI_CMD_HANDSHAKE_TYPE)
257 printk(KERN_ERR "gsmi: exec 0x%04x: Not supported\n",
262 printk(KERN_ERR "gsmi: exec 0x%04x: Not ready\n", cmd);
265 case GSMI_DEVICE_ERROR:
266 printk(KERN_ERR "gsmi: exec 0x%04x: Device error\n", cmd);
270 printk(KERN_ERR "gsmi: exec 0x%04x: Data not found\n", cmd);
274 printk(KERN_ERR "gsmi: exec 0x%04x: Log full\n", cmd);
277 case GSMI_HANDSHAKE_CF:
278 case GSMI_HANDSHAKE_SPIN:
279 case GSMI_HANDSHAKE_NONE:
283 printk(KERN_ERR "gsmi: exec 0x%04x: Unknown error 0x%04x\n",
291 static efi_status_t gsmi_get_variable(efi_char16_t *name,
292 efi_guid_t *vendor, u32 *attr,
293 unsigned long *data_size,
296 struct gsmi_nvram_var_param param = {
297 .name_ptr = gsmi_dev.name_buf->address,
298 .data_ptr = gsmi_dev.data_buf->address,
299 .data_len = (u32)*data_size,
301 efi_status_t ret = EFI_SUCCESS;
303 size_t name_len = utf16_strnlen(name, GSMI_BUF_SIZE / 2);
306 if (name_len >= GSMI_BUF_SIZE / 2)
307 return EFI_BAD_BUFFER_SIZE;
309 spin_lock_irqsave(&gsmi_dev.lock, flags);
312 memcpy(¶m.guid, vendor, sizeof(param.guid));
314 /* variable name, already in UTF-16 */
315 memset(gsmi_dev.name_buf->start, 0, gsmi_dev.name_buf->length);
316 memcpy(gsmi_dev.name_buf->start, name, name_len * 2);
319 memset(gsmi_dev.data_buf->start, 0, gsmi_dev.data_buf->length);
321 /* parameter buffer */
322 memset(gsmi_dev.param_buf->start, 0, gsmi_dev.param_buf->length);
323 memcpy(gsmi_dev.param_buf->start, ¶m, sizeof(param));
325 rc = gsmi_exec(GSMI_CALLBACK, GSMI_CMD_GET_NVRAM_VAR);
327 printk(KERN_ERR "gsmi: Get Variable failed\n");
328 ret = EFI_LOAD_ERROR;
329 } else if (rc == 1) {
330 /* variable was not found */
333 /* Get the arguments back */
334 memcpy(¶m, gsmi_dev.param_buf->start, sizeof(param));
336 /* The size reported is the min of all of our buffers */
337 *data_size = min_t(unsigned long, *data_size,
338 gsmi_dev.data_buf->length);
339 *data_size = min_t(unsigned long, *data_size, param.data_len);
341 /* Copy data back to return buffer. */
342 memcpy(data, gsmi_dev.data_buf->start, *data_size);
344 /* All variables are have the following attributes */
345 *attr = EFI_VARIABLE_NON_VOLATILE |
346 EFI_VARIABLE_BOOTSERVICE_ACCESS |
347 EFI_VARIABLE_RUNTIME_ACCESS;
350 spin_unlock_irqrestore(&gsmi_dev.lock, flags);
355 static efi_status_t gsmi_get_next_variable(unsigned long *name_size,
359 struct gsmi_get_next_var_param param = {
360 .name_ptr = gsmi_dev.name_buf->address,
361 .name_len = gsmi_dev.name_buf->length,
363 efi_status_t ret = EFI_SUCCESS;
367 /* For the moment, only support buffers that exactly match in size */
368 if (*name_size != GSMI_BUF_SIZE)
369 return EFI_BAD_BUFFER_SIZE;
371 /* Let's make sure the thing is at least null-terminated */
372 if (utf16_strnlen(name, GSMI_BUF_SIZE / 2) == GSMI_BUF_SIZE / 2)
373 return EFI_INVALID_PARAMETER;
375 spin_lock_irqsave(&gsmi_dev.lock, flags);
378 memcpy(¶m.guid, vendor, sizeof(param.guid));
380 /* variable name, already in UTF-16 */
381 memcpy(gsmi_dev.name_buf->start, name, *name_size);
383 /* parameter buffer */
384 memset(gsmi_dev.param_buf->start, 0, gsmi_dev.param_buf->length);
385 memcpy(gsmi_dev.param_buf->start, ¶m, sizeof(param));
387 rc = gsmi_exec(GSMI_CALLBACK, GSMI_CMD_GET_NEXT_VAR);
389 printk(KERN_ERR "gsmi: Get Next Variable Name failed\n");
390 ret = EFI_LOAD_ERROR;
391 } else if (rc == 1) {
392 /* variable not found -- end of list */
395 /* copy variable data back to return buffer */
396 memcpy(¶m, gsmi_dev.param_buf->start, sizeof(param));
398 /* Copy the name back */
399 memcpy(name, gsmi_dev.name_buf->start, GSMI_BUF_SIZE);
400 *name_size = utf16_strnlen(name, GSMI_BUF_SIZE / 2) * 2;
402 /* copy guid to return buffer */
403 memcpy(vendor, ¶m.guid, sizeof(param.guid));
407 spin_unlock_irqrestore(&gsmi_dev.lock, flags);
412 static efi_status_t gsmi_set_variable(efi_char16_t *name,
415 unsigned long data_size,
418 struct gsmi_nvram_var_param param = {
419 .name_ptr = gsmi_dev.name_buf->address,
420 .data_ptr = gsmi_dev.data_buf->address,
421 .data_len = (u32)data_size,
422 .attributes = EFI_VARIABLE_NON_VOLATILE |
423 EFI_VARIABLE_BOOTSERVICE_ACCESS |
424 EFI_VARIABLE_RUNTIME_ACCESS,
426 size_t name_len = utf16_strnlen(name, GSMI_BUF_SIZE / 2);
427 efi_status_t ret = EFI_SUCCESS;
431 if (name_len >= GSMI_BUF_SIZE / 2)
432 return EFI_BAD_BUFFER_SIZE;
434 spin_lock_irqsave(&gsmi_dev.lock, flags);
437 memcpy(¶m.guid, vendor, sizeof(param.guid));
439 /* variable name, already in UTF-16 */
440 memset(gsmi_dev.name_buf->start, 0, gsmi_dev.name_buf->length);
441 memcpy(gsmi_dev.name_buf->start, name, name_len * 2);
444 memset(gsmi_dev.data_buf->start, 0, gsmi_dev.data_buf->length);
445 memcpy(gsmi_dev.data_buf->start, data, data_size);
447 /* parameter buffer */
448 memset(gsmi_dev.param_buf->start, 0, gsmi_dev.param_buf->length);
449 memcpy(gsmi_dev.param_buf->start, ¶m, sizeof(param));
451 rc = gsmi_exec(GSMI_CALLBACK, GSMI_CMD_SET_NVRAM_VAR);
453 printk(KERN_ERR "gsmi: Set Variable failed\n");
454 ret = EFI_INVALID_PARAMETER;
457 spin_unlock_irqrestore(&gsmi_dev.lock, flags);
462 static const struct efivar_operations efivar_ops = {
463 .get_variable = gsmi_get_variable,
464 .set_variable = gsmi_set_variable,
465 .get_next_variable = gsmi_get_next_variable,
468 static ssize_t eventlog_write(struct file *filp, struct kobject *kobj,
469 struct bin_attribute *bin_attr,
470 char *buf, loff_t pos, size_t count)
472 struct gsmi_set_eventlog_param param = {
473 .data_ptr = gsmi_dev.data_buf->address,
478 /* Pull the type out */
479 if (count < sizeof(u32))
481 param.type = *(u32 *)buf;
482 count -= sizeof(u32);
485 /* The remaining buffer is the data payload */
486 if (count > gsmi_dev.data_buf->length)
488 param.data_len = count - sizeof(u32);
490 spin_lock_irqsave(&gsmi_dev.lock, flags);
493 memset(gsmi_dev.data_buf->start, 0, gsmi_dev.data_buf->length);
494 memcpy(gsmi_dev.data_buf->start, buf, param.data_len);
496 /* parameter buffer */
497 memset(gsmi_dev.param_buf->start, 0, gsmi_dev.param_buf->length);
498 memcpy(gsmi_dev.param_buf->start, ¶m, sizeof(param));
500 rc = gsmi_exec(GSMI_CALLBACK, GSMI_CMD_SET_EVENT_LOG);
502 printk(KERN_ERR "gsmi: Set Event Log failed\n");
504 spin_unlock_irqrestore(&gsmi_dev.lock, flags);
510 static struct bin_attribute eventlog_bin_attr = {
511 .attr = {.name = "append_to_eventlog", .mode = 0200},
512 .write = eventlog_write,
515 static ssize_t gsmi_clear_eventlog_store(struct kobject *kobj,
516 struct kobj_attribute *attr,
517 const char *buf, size_t count)
527 rc = strict_strtoul(buf, 0, &val);
532 * Value entered is a percentage, 0 through 100, anything else
538 /* data_type here selects the smbios event log. */
539 param.percentage = val;
542 spin_lock_irqsave(&gsmi_dev.lock, flags);
544 /* parameter buffer */
545 memset(gsmi_dev.param_buf->start, 0, gsmi_dev.param_buf->length);
546 memcpy(gsmi_dev.param_buf->start, ¶m, sizeof(param));
548 rc = gsmi_exec(GSMI_CALLBACK, GSMI_CMD_CLEAR_EVENT_LOG);
550 spin_unlock_irqrestore(&gsmi_dev.lock, flags);
557 static struct kobj_attribute gsmi_clear_eventlog_attr = {
558 .attr = {.name = "clear_eventlog", .mode = 0200},
559 .store = gsmi_clear_eventlog_store,
562 static ssize_t gsmi_clear_config_store(struct kobject *kobj,
563 struct kobj_attribute *attr,
564 const char *buf, size_t count)
569 spin_lock_irqsave(&gsmi_dev.lock, flags);
571 /* clear parameter buffer */
572 memset(gsmi_dev.param_buf->start, 0, gsmi_dev.param_buf->length);
574 rc = gsmi_exec(GSMI_CALLBACK, GSMI_CMD_CLEAR_CONFIG);
576 spin_unlock_irqrestore(&gsmi_dev.lock, flags);
583 static struct kobj_attribute gsmi_clear_config_attr = {
584 .attr = {.name = "clear_config", .mode = 0200},
585 .store = gsmi_clear_config_store,
588 static const struct attribute *gsmi_attrs[] = {
589 &gsmi_clear_config_attr.attr,
590 &gsmi_clear_eventlog_attr.attr,
594 static int gsmi_shutdown_reason(int reason)
596 struct gsmi_log_entry_type_1 entry = {
597 .type = GSMI_LOG_ENTRY_TYPE_KERNEL,
600 struct gsmi_set_eventlog_param param = {
601 .data_len = sizeof(entry),
604 static int saved_reason;
608 /* avoid duplicate entries in the log */
609 if (saved_reason & (1 << reason))
612 spin_lock_irqsave(&gsmi_dev.lock, flags);
614 saved_reason |= (1 << reason);
617 memset(gsmi_dev.data_buf->start, 0, gsmi_dev.data_buf->length);
618 memcpy(gsmi_dev.data_buf->start, &entry, sizeof(entry));
620 /* parameter buffer */
621 param.data_ptr = gsmi_dev.data_buf->address;
622 memset(gsmi_dev.param_buf->start, 0, gsmi_dev.param_buf->length);
623 memcpy(gsmi_dev.param_buf->start, ¶m, sizeof(param));
625 rc = gsmi_exec(GSMI_CALLBACK, GSMI_CMD_SET_EVENT_LOG);
627 spin_unlock_irqrestore(&gsmi_dev.lock, flags);
630 printk(KERN_ERR "gsmi: Log Shutdown Reason failed\n");
632 printk(KERN_EMERG "gsmi: Log Shutdown Reason 0x%02x\n",
638 static int gsmi_reboot_callback(struct notifier_block *nb,
639 unsigned long reason, void *arg)
641 gsmi_shutdown_reason(GSMI_SHUTDOWN_CLEAN);
645 static struct notifier_block gsmi_reboot_notifier = {
646 .notifier_call = gsmi_reboot_callback
649 static int gsmi_die_callback(struct notifier_block *nb,
650 unsigned long reason, void *arg)
652 if (reason == DIE_OOPS)
653 gsmi_shutdown_reason(GSMI_SHUTDOWN_OOPS);
657 static struct notifier_block gsmi_die_notifier = {
658 .notifier_call = gsmi_die_callback
661 static int gsmi_panic_callback(struct notifier_block *nb,
662 unsigned long reason, void *arg)
664 gsmi_shutdown_reason(GSMI_SHUTDOWN_PANIC);
668 static struct notifier_block gsmi_panic_notifier = {
669 .notifier_call = gsmi_panic_callback,
673 * This hash function was blatantly copied from include/linux/hash.h.
674 * It is used by this driver to obfuscate a board name that requires a
675 * quirk within this driver.
677 * Please do not remove this copy of the function as any changes to the
678 * global utility hash_64() function would break this driver's ability
679 * to identify a board and provide the appropriate quirk -- mikew@google.com
681 static u64 __init local_hash_64(u64 val, unsigned bits)
685 /* Sigh, gcc can't optimise this alone like it does for 32 bits. */
700 /* High bits are more random, so use them. */
701 return hash >> (64 - bits);
704 static u32 __init hash_oem_table_id(char s[8])
707 memcpy(&input, s, 8);
708 return local_hash_64(input, 32);
711 static struct dmi_system_id gsmi_dmi_table[] __initdata = {
713 .ident = "Google Board",
715 DMI_MATCH(DMI_BOARD_VENDOR, "Google, Inc."),
720 MODULE_DEVICE_TABLE(dmi, gsmi_dmi_table);
722 static __init int gsmi_system_valid(void)
726 if (!dmi_check_system(gsmi_dmi_table))
730 * Only newer firmware supports the gsmi interface. All older
731 * firmware that didn't support this interface used to plug the
732 * table name in the first four bytes of the oem_table_id field.
733 * Newer firmware doesn't do that though, so use that as the
734 * discriminant factor. We have to do this in order to
735 * whitewash our board names out of the public driver.
737 if (!strncmp(acpi_gbl_FADT.header.oem_table_id, "FACP", 4)) {
738 printk(KERN_INFO "gsmi: Board is too old\n");
742 /* Disable on board with 1.0 BIOS due to Google bug 2602657 */
743 hash = hash_oem_table_id(acpi_gbl_FADT.header.oem_table_id);
744 if (hash == QUIRKY_BOARD_HASH) {
745 const char *bios_ver = dmi_get_system_info(DMI_BIOS_VERSION);
746 if (strncmp(bios_ver, "1.0", 3) == 0) {
747 pr_info("gsmi: disabled on this board's BIOS %s\n",
753 /* check for valid SMI command port in ACPI FADT */
754 if (acpi_gbl_FADT.smi_command == 0) {
755 pr_info("gsmi: missing smi_command\n");
763 static struct kobject *gsmi_kobj;
764 static struct efivars efivars;
766 static __init int gsmi_init(void)
771 ret = gsmi_system_valid();
775 gsmi_dev.smi_cmd = acpi_gbl_FADT.smi_command;
777 /* register device */
778 gsmi_dev.pdev = platform_device_register_simple("gsmi", -1, NULL, 0);
779 if (IS_ERR(gsmi_dev.pdev)) {
780 printk(KERN_ERR "gsmi: unable to register platform device\n");
781 return PTR_ERR(gsmi_dev.pdev);
784 /* SMI access needs to be serialized */
785 spin_lock_init(&gsmi_dev.lock);
787 /* SMI callbacks require 32bit addresses */
788 gsmi_dev.pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
789 gsmi_dev.pdev->dev.dma_mask =
790 &gsmi_dev.pdev->dev.coherent_dma_mask;
792 gsmi_dev.dma_pool = dma_pool_create("gsmi", &gsmi_dev.pdev->dev,
793 GSMI_BUF_SIZE, GSMI_BUF_ALIGN, 0);
794 if (!gsmi_dev.dma_pool)
798 * pre-allocate buffers because sometimes we are called when
799 * this is not feasible: oops, panic, die, mce, etc
801 gsmi_dev.name_buf = gsmi_buf_alloc();
802 if (!gsmi_dev.name_buf) {
803 printk(KERN_ERR "gsmi: failed to allocate name buffer\n");
807 gsmi_dev.data_buf = gsmi_buf_alloc();
808 if (!gsmi_dev.data_buf) {
809 printk(KERN_ERR "gsmi: failed to allocate data buffer\n");
813 gsmi_dev.param_buf = gsmi_buf_alloc();
814 if (!gsmi_dev.param_buf) {
815 printk(KERN_ERR "gsmi: failed to allocate param buffer\n");
820 * Determine type of handshake used to serialize the SMI
821 * entry. See also gsmi_exec().
823 * There's a "behavior" present on some chipsets where writing the
824 * SMI trigger register in the southbridge doesn't result in an
825 * immediate SMI. Rather, the processor can execute "a few" more
826 * instructions before the SMI takes effect. To ensure synchronous
827 * behavior, implement a handshake between the kernel driver and the
828 * firmware handler to spin until released. This ioctl determines
829 * the type of handshake.
831 * NONE: The firmware handler does not implement any
832 * handshake. Either it doesn't need to, or it's legacy firmware
833 * that doesn't know it needs to and never will.
835 * CF: The firmware handler will clear the CF in the saved
836 * state before returning. The driver may set the CF and test for
837 * it to clear before proceeding.
839 * SPIN: The firmware handler does not implement any handshake
840 * but the driver should spin for a hundred or so microseconds
841 * to ensure the SMI has triggered.
843 * Finally, the handler will return -ENOSYS if
844 * GSMI_CMD_HANDSHAKE_TYPE is unimplemented, which implies
847 spin_lock_irqsave(&gsmi_dev.lock, flags);
848 gsmi_dev.handshake_type = GSMI_HANDSHAKE_SPIN;
849 gsmi_dev.handshake_type =
850 gsmi_exec(GSMI_CALLBACK, GSMI_CMD_HANDSHAKE_TYPE);
851 if (gsmi_dev.handshake_type == -ENOSYS)
852 gsmi_dev.handshake_type = GSMI_HANDSHAKE_NONE;
853 spin_unlock_irqrestore(&gsmi_dev.lock, flags);
855 /* Remove and clean up gsmi if the handshake could not complete. */
856 if (gsmi_dev.handshake_type == -ENXIO) {
857 printk(KERN_INFO "gsmi version " DRIVER_VERSION
858 " failed to load\n");
863 /* Register in the firmware directory */
865 gsmi_kobj = kobject_create_and_add("gsmi", firmware_kobj);
867 printk(KERN_INFO "gsmi: Failed to create firmware kobj\n");
871 /* Setup eventlog access */
872 ret = sysfs_create_bin_file(gsmi_kobj, &eventlog_bin_attr);
874 printk(KERN_INFO "gsmi: Failed to setup eventlog");
878 /* Other attributes */
879 ret = sysfs_create_files(gsmi_kobj, gsmi_attrs);
881 printk(KERN_INFO "gsmi: Failed to add attrs");
882 goto out_remove_bin_file;
885 ret = efivars_register(&efivars, &efivar_ops, gsmi_kobj);
887 printk(KERN_INFO "gsmi: Failed to register efivars\n");
888 goto out_remove_sysfs_files;
891 ret = efivars_sysfs_init();
893 printk(KERN_INFO "gsmi: Failed to create efivars files\n");
894 efivars_unregister(&efivars);
895 goto out_remove_sysfs_files;
898 register_reboot_notifier(&gsmi_reboot_notifier);
899 register_die_notifier(&gsmi_die_notifier);
900 atomic_notifier_chain_register(&panic_notifier_list,
901 &gsmi_panic_notifier);
903 printk(KERN_INFO "gsmi version " DRIVER_VERSION " loaded\n");
907 out_remove_sysfs_files:
908 sysfs_remove_files(gsmi_kobj, gsmi_attrs);
910 sysfs_remove_bin_file(gsmi_kobj, &eventlog_bin_attr);
912 kobject_put(gsmi_kobj);
913 gsmi_buf_free(gsmi_dev.param_buf);
914 gsmi_buf_free(gsmi_dev.data_buf);
915 gsmi_buf_free(gsmi_dev.name_buf);
916 if (gsmi_dev.dma_pool)
917 dma_pool_destroy(gsmi_dev.dma_pool);
918 platform_device_unregister(gsmi_dev.pdev);
919 pr_info("gsmi: failed to load: %d\n", ret);
923 static void __exit gsmi_exit(void)
925 unregister_reboot_notifier(&gsmi_reboot_notifier);
926 unregister_die_notifier(&gsmi_die_notifier);
927 atomic_notifier_chain_unregister(&panic_notifier_list,
928 &gsmi_panic_notifier);
929 efivars_unregister(&efivars);
931 sysfs_remove_files(gsmi_kobj, gsmi_attrs);
932 sysfs_remove_bin_file(gsmi_kobj, &eventlog_bin_attr);
933 kobject_put(gsmi_kobj);
934 gsmi_buf_free(gsmi_dev.param_buf);
935 gsmi_buf_free(gsmi_dev.data_buf);
936 gsmi_buf_free(gsmi_dev.name_buf);
937 dma_pool_destroy(gsmi_dev.dma_pool);
938 platform_device_unregister(gsmi_dev.pdev);
941 module_init(gsmi_init);
942 module_exit(gsmi_exit);
944 MODULE_AUTHOR("Google, Inc.");
945 MODULE_LICENSE("GPL");