Skip to contentSkip to conversation

gsmi: Google specific firmware patches

PATCH In review Ross Zwisler 2 participants 6 messages Oct 12, 2018 – Oct 15, 2018 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

cover gsmi: Google specific firmware patches

This series contains some Google specific firmware patches that we've been carrying out of tree. I've updated the changelog for each so that it is suitable for upstream, and I've retested them to make sure I know what the patches are doing.

Duncan Laurie (3):
gsmi: Fix bug in append_to_eventlog sysfs handler
gsmi: Add coreboot to list of matching BIOS vendors
gsmi: Remove autoselected dependency on EFI and EFI_VARS

Furquan Shaikh (1):
gsmi: Add GSMI commands to log S0ix info

 drivers/firmware/google/Kconfig |   6 +-
 drivers/firmware/google/gsmi.c  | 120 +++++++++++++++++++++++++++++---
 2 files changed, 115 insertions(+), 11 deletions(-)
Signature · 1 line
2.19.0.605.g01d371f741-goog
#1 lore raw

PATCH 1/4 gsmi: Fix bug in append_to_eventlog sysfs handler

From: Duncan Laurie <[email protected]>

The sysfs handler should return the number of bytes consumed, which in the case of a successful write is the entire buffer. Also fix a bug where param.data_len was being set to (count - (2 * sizeof(u32))) instead of just (count - sizeof(u32)). The latter is correct because we skip over the leading u32 which is our param.type, but we were also incorrectly subtracting sizeof(u32) on the line where we were actually setting param.data_len:

	param.data_len = count - sizeof(u32);

This meant that for our example event.kernel_software_watchdog with total length 10 bytes, param.data_len was just 2 prior to this change.

To test, successfully append an event to the log with gsmi sysfs. This sample event is for a "Kernel Software Watchdog"

Quoted 1 line

xxd -g 1 event.kernel_software_watchdog

0000000: 01 00 00 00 ad de 06 00 00 00

Quoted 3 lines

cat event.kernel_software_watchdog > /sys/firmware/gsmi/append_to_eventlog

mosys eventlog list | tail -1

14 | 2012-06-25 10:14:14 | Kernl Event | Software Watchdog

---
 drivers/firmware/google/gsmi.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/firmware/google/gsmi.c +2 -3
index c8f169bf2e27..62337be07afc 100644
@@ -480,11 +480,10 @@ static ssize_t eventlog_write(struct file *filp, struct kobject *kobj,
 	if (count < sizeof(u32))
 		return -EINVAL;
 	param.type = *(u32 *)buf;
-	count -= sizeof(u32);
 	buf += sizeof(u32);
 
 	/* The remaining buffer is the data payload */
-	if (count > gsmi_dev.data_buf->length)
+	if ((count - sizeof(u32)) > gsmi_dev.data_buf->length)
 		return -EINVAL;
 	param.data_len = count - sizeof(u32);
 
@@ -504,7 +503,7 @@ static ssize_t eventlog_write(struct file *filp, struct kobject *kobj,
 
 	spin_unlock_irqrestore(&gsmi_dev.lock, flags);
 
-	return rc;
+	return (rc == 0) ? count : rc;
 
 }
 
Signature · 1 line
2.19.0.605.g01d371f741-goog
#2 lore raw

PATCH 2/4 gsmi: Add coreboot to list of matching BIOS vendors

In reply to Ross Zwisler

From: Duncan Laurie <[email protected]>

In order to use this coreboot needs board support for:
CONFIG_ELOG=y
CONFIG_ELOG_GSMI=y

And the kernel driver needs enabled:
CONFIG_GOOGLE_GSMI=y

To test, verify that clean shutdown event is added to the log:

Quoted 1 line

mosys eventlog list | grep 'Clean Shutdown'

11 | 2012-06-25 09:49:24 | Kernl Event | Clean Shutdown

---
 drivers/firmware/google/gsmi.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/firmware/google/gsmi.c +6 -0
index 62337be07afc..252884787266 100644
@@ -715,6 +715,12 @@ static const struct dmi_system_id gsmi_dmi_table[] __initconst = {
 			DMI_MATCH(DMI_BOARD_VENDOR, "Google, Inc."),
 		},
 	},
+	{
+		.ident = "Coreboot Firmware",
+		.matches = {
+			DMI_MATCH(DMI_BIOS_VENDOR, "coreboot"),
+		},
+	},
 	{}
 };
 MODULE_DEVICE_TABLE(dmi, gsmi_dmi_table);
Signature · 1 line
2.19.0.605.g01d371f741-goog
#3 lore raw

PATCH 3/4 gsmi: Remove autoselected dependency on EFI and EFI_VARS

In reply to Ross Zwisler

From: Duncan Laurie <[email protected]>

Instead of selecting EFI and EFI_VARS automatically when GSMI is enabled let that portion of the driver be conditionally compiled if EFI and EFI_VARS are enabled.

This allows the rest of the driver (specifically event log) to be used if EFI_VARS is not enabled.

To test:
1) verify that EFI_VARS is not automatically selected when CONFIG_GOOGLE_GSMI is enabled
2) verify that the kernel boots on Link and that GSMI event log is still available and functional
3) specifically boot the kernel on Alex to ensure it does not try to load efivars and that gsmi also does not load because it is not in the supported DMI table

---
 drivers/firmware/google/Kconfig |  6 +++---
 drivers/firmware/google/gsmi.c  | 16 ++++++++++++----
 2 files changed, 15 insertions(+), 7 deletions(-)
drivers/firmware/google/Kconfig +3 -3
index a456a000048b..9ac36762e503 100644
@@ -10,12 +10,12 @@ if GOOGLE_FIRMWARE
 
 config GOOGLE_SMI
 	tristate "SMI interface for Google platforms"
-	depends on X86 && ACPI && DMI && EFI
-	select EFI_VARS
+	depends on X86 && ACPI && DMI
 	help
 	  Say Y here if you want to enable SMI callbacks for Google
 	  platforms.  This provides an interface for writing to and
-	  clearing the EFI event log and reading and writing NVRAM
+	  clearing the event log.  If EFI_VARS is also enabled this
+	  driver provides an interface for reading and writing NVRAM
 	  variables.
 
 config GOOGLE_COREBOOT_TABLE
drivers/firmware/google/gsmi.c +12 -4
index 252884787266..edab00cc6bba 100644
@@ -289,6 +289,10 @@ static int gsmi_exec(u8 func, u8 sub)
 	return rc;
 }
 
+#ifdef CONFIG_EFI_VARS
+
+static struct efivars efivars;
+
 static efi_status_t gsmi_get_variable(efi_char16_t *name,
 				      efi_guid_t *vendor, u32 *attr,
 				      unsigned long *data_size,
@@ -466,6 +470,8 @@ static const struct efivar_operations efivar_ops = {
 	.get_next_variable = gsmi_get_next_variable,
 };
 
+#endif /* CONFIG_EFI_VARS */
+
 static ssize_t eventlog_write(struct file *filp, struct kobject *kobj,
 			       struct bin_attribute *bin_attr,
 			       char *buf, loff_t pos, size_t count)
@@ -767,7 +773,6 @@ static __init int gsmi_system_valid(void)
 }
 
 static struct kobject *gsmi_kobj;
-static struct efivars efivars;
 
 static const struct platform_device_info gsmi_dev_info = {
 	.name		= "gsmi",
@@ -891,11 +896,14 @@ static __init int gsmi_init(void)
 		goto out_remove_bin_file;
 	}
 
+#ifdef CONFIG_EFI_VARS
 	ret = efivars_register(&efivars, &efivar_ops, gsmi_kobj);
 	if (ret) {
 		printk(KERN_INFO "gsmi: Failed to register efivars\n");
-		goto out_remove_sysfs_files;
+		sysfs_remove_files(gsmi_kobj, gsmi_attrs);
+		goto out_remove_bin_file;
 	}
+#endif
 
 	register_reboot_notifier(&gsmi_reboot_notifier);
 	register_die_notifier(&gsmi_die_notifier);
@@ -906,8 +914,6 @@ static __init int gsmi_init(void)
 
 	return 0;
 
-out_remove_sysfs_files:
-	sysfs_remove_files(gsmi_kobj, gsmi_attrs);
 out_remove_bin_file:
 	sysfs_remove_bin_file(gsmi_kobj, &eventlog_bin_attr);
 out_err:
@@ -927,7 +933,9 @@ static void __exit gsmi_exit(void)
 	unregister_die_notifier(&gsmi_die_notifier);
 	atomic_notifier_chain_unregister(&panic_notifier_list,
 					 &gsmi_panic_notifier);
+#ifdef CONFIG_EFI_VARS
 	efivars_unregister(&efivars);
+#endif
 
 	sysfs_remove_files(gsmi_kobj, gsmi_attrs);
 	sysfs_remove_bin_file(gsmi_kobj, &eventlog_bin_attr);
Signature · 1 line
2.19.0.605.g01d371f741-goog
#4 lore raw

PATCH 4/4 gsmi: Add GSMI commands to log S0ix info

In reply to Ross Zwisler

From: Furquan Shaikh <[email protected]>

Add new GSMI commands (GSMI_CMD_LOG_S0IX_SUSPEND = 0xa, GSMI_CMD_LOG_S0IX_RESUME = 0xb) that allow firmware to log any information during S0ix suspend/resume paths.

Traditional ACPI suspend S3 involves BIOS both during the suspend and the resume paths. However, modern suspend type like S0ix does not involve firmware on either of the paths. This command gives the firmware an opportunity to log any required information about the suspend and resume operations e.g. wake sources.

Additionally, this change adds a module parameter to allow platforms to specifically enable S0ix logging if required. This prevents any other platforms from unnecessarily making a GSMI call which could have any side-effects.

Tested by verifying that wake sources are correctly logged in eventlog.

---
 drivers/firmware/google/gsmi.c | 93 +++++++++++++++++++++++++++++++++-
 1 file changed, 92 insertions(+), 1 deletion(-)
drivers/firmware/google/gsmi.c +92 -1
index edab00cc6bba..7ee25ce0e318 100644
@@ -29,6 +29,7 @@
 #include <linux/efi.h>
 #include <linux/module.h>
 #include <linux/ucs2_string.h>
+#include <linux/suspend.h>
 
 #define GSMI_SHUTDOWN_CLEAN	0	/* Clean Shutdown */
 /* TODO([email protected]): Tie in HARDLOCKUP_DETECTOR with NMIWDT */
@@ -70,6 +71,8 @@
 #define GSMI_CMD_SET_NVRAM_VAR		0x03
 #define GSMI_CMD_SET_EVENT_LOG		0x08
 #define GSMI_CMD_CLEAR_EVENT_LOG	0x09
+#define GSMI_CMD_LOG_S0IX_SUSPEND	0x0a
+#define GSMI_CMD_LOG_S0IX_RESUME	0x0b
 #define GSMI_CMD_CLEAR_CONFIG		0x20
 #define GSMI_CMD_HANDSHAKE_TYPE		0xC1
 
@@ -122,7 +125,6 @@ struct gsmi_log_entry_type_1 {
 	u32	instance;
 } __packed;
 
-
 /*
  * Some platforms don't have explicit SMI handshake
  * and need to wait for SMI to complete.
@@ -133,6 +135,15 @@ module_param(spincount, uint, 0600);
 MODULE_PARM_DESC(spincount,
 	"The number of loop iterations to use when using the spin handshake.");
 
+/*
+ * Platforms might not support S0ix logging in their GSMI handlers. In order to
+ * avoid any side-effects of generating an SMI for S0ix logging, use the S0ix
+ * related GSMI commands only for those platforms that explicitly enable this
+ * option.
+ */
+static bool s0ix_logging_enable;
+module_param(s0ix_logging_enable, bool, 0600);
+
 static struct gsmi_buf *gsmi_buf_alloc(void)
 {
 	struct gsmi_buf *smibuf;
@@ -781,6 +792,78 @@ static const struct platform_device_info gsmi_dev_info = {
 	.dma_mask	= DMA_BIT_MASK(32),
 };
 
+#ifdef CONFIG_PM
+static void gsmi_log_s0ix_info(u8 cmd)
+{
+	unsigned long flags;
+
+	/*
+	 * If platform has not enabled S0ix logging, then no action is
+	 * necessary.
+	 */
+	if (!s0ix_logging_enable)
+		return;
+
+	spin_lock_irqsave(&gsmi_dev.lock, flags);
+
+	memset(gsmi_dev.param_buf->start, 0, gsmi_dev.param_buf->length);
+
+	gsmi_exec(GSMI_CALLBACK, cmd);
+
+	spin_unlock_irqrestore(&gsmi_dev.lock, flags);
+}
+
+static int gsmi_log_s0ix_suspend(struct device *dev)
+{
+	/*
+	 * If system is not suspending via firmware using the standard ACPI Sx
+	 * types, then make a GSMI call to log the suspend info.
+	 */
+	if (!pm_suspend_via_firmware())
+		gsmi_log_s0ix_info(GSMI_CMD_LOG_S0IX_SUSPEND);
+
+	/*
+	 * Always return success, since we do not want suspend
+	 * to fail just because of logging failure.
+	 */
+	return 0;
+}
+
+static int gsmi_log_s0ix_resume(struct device *dev)
+{
+	/*
+	 * If system did not resume via firmware, then make a GSMI call to log
+	 * the resume info and wake source.
+	 */
+	if (!pm_resume_via_firmware())
+		gsmi_log_s0ix_info(GSMI_CMD_LOG_S0IX_RESUME);
+
+	/*
+	 * Always return success, since we do not want resume
+	 * to fail just because of logging failure.
+	 */
+	return 0;
+}
+
+static const struct dev_pm_ops gsmi_pm_ops = {
+	.suspend_noirq = gsmi_log_s0ix_suspend,
+	.resume_noirq = gsmi_log_s0ix_resume,
+};
+
+static int gsmi_platform_driver_probe(struct platform_device *dev)
+{
+	return 0;
+}
+
+static struct platform_driver gsmi_driver_info = {
+	.driver = {
+		.name = "gsmi",
+		.pm = &gsmi_pm_ops,
+	},
+	.probe = gsmi_platform_driver_probe,
+};
+#endif
+
 static __init int gsmi_init(void)
 {
 	unsigned long flags;
@@ -792,6 +875,14 @@ static __init int gsmi_init(void)
 
 	gsmi_dev.smi_cmd = acpi_gbl_FADT.smi_command;
 
+#ifdef CONFIG_PM
+	ret = platform_driver_register(&gsmi_driver_info);
+	if (unlikely(ret)) {
+		printk(KERN_ERR "gsmi: unable to register platform driver\n");
+		return ret;
+	}
+#endif
+
 	/* register device */
 	gsmi_dev.pdev = platform_device_register_full(&gsmi_dev_info);
 	if (IS_ERR(gsmi_dev.pdev)) {
Signature · 1 line
2.19.0.605.g01d371f741-goog

A message that is not in the archive (sent off-list or not yet received): CABXOdTfUKWejqTxvtcH_O6SKaWDRGcu5qCVafTstm-r8y7ke1Q@mail.gmail.com

#6 lore raw
Quoted 12 lines · Guenter Roeck
Quoted 10 lines · Ross Zwisler

This series contains some Google specific firmware patches that we've been carrying out of tree. I've updated the changelog for each so that it is suitable for upstream, and I've retested them to make sure I know what the patches are doing.

Duncan Laurie (3):
gsmi: Fix bug in append_to_eventlog sysfs handler
gsmi: Add coreboot to list of matching BIOS vendors
gsmi: Remove autoselected dependency on EFI and EFI_VARS

Quoted 7 lines
Quoted 4 lines

Furquan Shaikh (1):
gsmi: Add GSMI commands to log S0ix info

For the series: Reviewed-by: Guenter Roeck <[email protected]>

Greg, please let me know if I should send this for every patch.

Nope, this works.

greg k-h