From bd5b4fb47dde86b5e04686463dc2420e5ed6932a Mon Sep 17 00:00:00 2001 From: Kate Hsuan Date: Fri, 20 Aug 2021 14:04:57 +0300 Subject: platform/x86: intel-wmi-sbl-fw-update: Move to intel sub-directory Move Intel WMI Slim Bootloader FW update driver to intel sub-directory to improve readability. Signed-off-by: Kate Hsuan Reviewed-by: Hans de Goede Signed-off-by: Andy Shevchenko Link: https://lore.kernel.org/r/20210820110458.73018-20-andriy.shevchenko@linux.intel.com Signed-off-by: Hans de Goede --- drivers/platform/x86/Kconfig | 10 -- drivers/platform/x86/Makefile | 1 - drivers/platform/x86/intel-wmi-sbl-fw-update.c | 144 ------------------------- drivers/platform/x86/intel/Kconfig | 1 + drivers/platform/x86/intel/Makefile | 1 + drivers/platform/x86/intel/wmi/Kconfig | 18 ++++ drivers/platform/x86/intel/wmi/Makefile | 7 ++ drivers/platform/x86/intel/wmi/sbl-fw-update.c | 144 +++++++++++++++++++++++++ 8 files changed, 171 insertions(+), 155 deletions(-) delete mode 100644 drivers/platform/x86/intel-wmi-sbl-fw-update.c create mode 100644 drivers/platform/x86/intel/wmi/Kconfig create mode 100644 drivers/platform/x86/intel/wmi/Makefile create mode 100644 drivers/platform/x86/intel/wmi/sbl-fw-update.c (limited to 'drivers/platform/x86') diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig index f1349a1e17ae..d23053b6e29f 100644 --- a/drivers/platform/x86/Kconfig +++ b/drivers/platform/x86/Kconfig @@ -77,16 +77,6 @@ config UV_SYSFS To compile this driver as a module, choose M here: the module will be called uv_sysfs. -config INTEL_WMI_SBL_FW_UPDATE - tristate "Intel WMI Slim Bootloader firmware update signaling driver" - depends on ACPI_WMI - help - Say Y here if you want to be able to use the WMI interface to signal - Slim Bootloader to trigger update on next reboot. - - To compile this driver as a module, choose M here: the module will - be called intel-wmi-sbl-fw-update. - config INTEL_WMI_THUNDERBOLT tristate "Intel WMI thunderbolt force power driver" depends on ACPI_WMI diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile index e6e888af9df7..29ab09e0f36b 100644 --- a/drivers/platform/x86/Makefile +++ b/drivers/platform/x86/Makefile @@ -10,7 +10,6 @@ obj-$(CONFIG_WMI_BMOF) += wmi-bmof.o # WMI drivers obj-$(CONFIG_HUAWEI_WMI) += huawei-wmi.o -obj-$(CONFIG_INTEL_WMI_SBL_FW_UPDATE) += intel-wmi-sbl-fw-update.o obj-$(CONFIG_INTEL_WMI_THUNDERBOLT) += intel-wmi-thunderbolt.o obj-$(CONFIG_MXM_WMI) += mxm-wmi.o obj-$(CONFIG_PEAQ_WMI) += peaq-wmi.o diff --git a/drivers/platform/x86/intel-wmi-sbl-fw-update.c b/drivers/platform/x86/intel-wmi-sbl-fw-update.c deleted file mode 100644 index 3c86e0108a24..000000000000 --- a/drivers/platform/x86/intel-wmi-sbl-fw-update.c +++ /dev/null @@ -1,144 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Slim Bootloader(SBL) firmware update signaling driver - * - * Slim Bootloader is a small, open-source, non UEFI compliant, boot firmware - * optimized for running on certain Intel platforms. - * - * SBL exposes an ACPI-WMI device via /sys/bus/wmi/devices/. - * This driver further adds "firmware_update_request" device attribute. - * This attribute normally has a value of 0 and userspace can signal SBL - * to update firmware, on next reboot, by writing a value of 1. - * - * More details of SBL firmware update process is available at: - * https://slimbootloader.github.io/security/firmware-update.html - */ - -#include -#include -#include -#include -#include -#include - -#define INTEL_WMI_SBL_GUID "44FADEB1-B204-40F2-8581-394BBDC1B651" - -static int get_fwu_request(struct device *dev, u32 *out) -{ - struct acpi_buffer result = {ACPI_ALLOCATE_BUFFER, NULL}; - union acpi_object *obj; - acpi_status status; - - status = wmi_query_block(INTEL_WMI_SBL_GUID, 0, &result); - if (ACPI_FAILURE(status)) { - dev_err(dev, "wmi_query_block failed\n"); - return -ENODEV; - } - - obj = (union acpi_object *)result.pointer; - if (!obj || obj->type != ACPI_TYPE_INTEGER) { - dev_warn(dev, "wmi_query_block returned invalid value\n"); - kfree(obj); - return -EINVAL; - } - - *out = obj->integer.value; - kfree(obj); - - return 0; -} - -static int set_fwu_request(struct device *dev, u32 in) -{ - struct acpi_buffer input; - acpi_status status; - u32 value; - - value = in; - input.length = sizeof(u32); - input.pointer = &value; - - status = wmi_set_block(INTEL_WMI_SBL_GUID, 0, &input); - if (ACPI_FAILURE(status)) { - dev_err(dev, "wmi_set_block failed\n"); - return -ENODEV; - } - - return 0; -} - -static ssize_t firmware_update_request_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - u32 val; - int ret; - - ret = get_fwu_request(dev, &val); - if (ret) - return ret; - - return sprintf(buf, "%d\n", val); -} - -static ssize_t firmware_update_request_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) -{ - unsigned int val; - int ret; - - ret = kstrtouint(buf, 0, &val); - if (ret) - return ret; - - /* May later be extended to support values other than 0 and 1 */ - if (val > 1) - return -ERANGE; - - ret = set_fwu_request(dev, val); - if (ret) - return ret; - - return count; -} -static DEVICE_ATTR_RW(firmware_update_request); - -static struct attribute *firmware_update_attrs[] = { - &dev_attr_firmware_update_request.attr, - NULL -}; -ATTRIBUTE_GROUPS(firmware_update); - -static int intel_wmi_sbl_fw_update_probe(struct wmi_device *wdev, - const void *context) -{ - dev_info(&wdev->dev, "Slim Bootloader signaling driver attached\n"); - return 0; -} - -static void intel_wmi_sbl_fw_update_remove(struct wmi_device *wdev) -{ - dev_info(&wdev->dev, "Slim Bootloader signaling driver removed\n"); -} - -static const struct wmi_device_id intel_wmi_sbl_id_table[] = { - { .guid_string = INTEL_WMI_SBL_GUID }, - {} -}; -MODULE_DEVICE_TABLE(wmi, intel_wmi_sbl_id_table); - -static struct wmi_driver intel_wmi_sbl_fw_update_driver = { - .driver = { - .name = "intel-wmi-sbl-fw-update", - .dev_groups = firmware_update_groups, - }, - .probe = intel_wmi_sbl_fw_update_probe, - .remove = intel_wmi_sbl_fw_update_remove, - .id_table = intel_wmi_sbl_id_table, -}; -module_wmi_driver(intel_wmi_sbl_fw_update_driver); - -MODULE_AUTHOR("Jithu Joseph "); -MODULE_DESCRIPTION("Slim Bootloader firmware update signaling driver"); -MODULE_LICENSE("GPL v2"); diff --git a/drivers/platform/x86/intel/Kconfig b/drivers/platform/x86/intel/Kconfig index a5d71d669b82..0b21468e1bd0 100644 --- a/drivers/platform/x86/intel/Kconfig +++ b/drivers/platform/x86/intel/Kconfig @@ -24,6 +24,7 @@ source "drivers/platform/x86/intel/pmc/Kconfig" source "drivers/platform/x86/intel/pmt/Kconfig" source "drivers/platform/x86/intel/speed_select_if/Kconfig" source "drivers/platform/x86/intel/telemetry/Kconfig" +source "drivers/platform/x86/intel/wmi/Kconfig" config INTEL_HID_EVENT tristate "Intel HID Event" diff --git a/drivers/platform/x86/intel/Makefile b/drivers/platform/x86/intel/Makefile index 67b16119e712..8b3a3f7bab49 100644 --- a/drivers/platform/x86/intel/Makefile +++ b/drivers/platform/x86/intel/Makefile @@ -12,6 +12,7 @@ obj-$(CONFIG_INTEL_PMC_CORE) += pmc/ obj-$(CONFIG_INTEL_PMT_CLASS) += pmt/ obj-$(CONFIG_INTEL_SPEED_SELECT_INTERFACE) += speed_select_if/ obj-$(CONFIG_INTEL_TELEMETRY) += telemetry/ +obj-$(CONFIG_INTEL_WMI) += wmi/ # Intel input drivers intel-hid-y := hid.o diff --git a/drivers/platform/x86/intel/wmi/Kconfig b/drivers/platform/x86/intel/wmi/Kconfig new file mode 100644 index 000000000000..c5753b1e8f43 --- /dev/null +++ b/drivers/platform/x86/intel/wmi/Kconfig @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Intel x86 Platform Specific Drivers +# + +config INTEL_WMI + bool + +config INTEL_WMI_SBL_FW_UPDATE + tristate "Intel WMI Slim Bootloader firmware update signaling driver" + depends on ACPI_WMI + select INTEL_WMI + help + Say Y here if you want to be able to use the WMI interface to signal + Slim Bootloader to trigger update on next reboot. + + To compile this driver as a module, choose M here: the module will + be called intel-wmi-sbl-fw-update. diff --git a/drivers/platform/x86/intel/wmi/Makefile b/drivers/platform/x86/intel/wmi/Makefile new file mode 100644 index 000000000000..bf1f118b6839 --- /dev/null +++ b/drivers/platform/x86/intel/wmi/Makefile @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Intel x86 Platform Specific Drivers +# + +intel-wmi-sbl-fw-update-y := sbl-fw-update.o +obj-$(CONFIG_INTEL_WMI_SBL_FW_UPDATE) += intel-wmi-sbl-fw-update.o diff --git a/drivers/platform/x86/intel/wmi/sbl-fw-update.c b/drivers/platform/x86/intel/wmi/sbl-fw-update.c new file mode 100644 index 000000000000..3c86e0108a24 --- /dev/null +++ b/drivers/platform/x86/intel/wmi/sbl-fw-update.c @@ -0,0 +1,144 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Slim Bootloader(SBL) firmware update signaling driver + * + * Slim Bootloader is a small, open-source, non UEFI compliant, boot firmware + * optimized for running on certain Intel platforms. + * + * SBL exposes an ACPI-WMI device via /sys/bus/wmi/devices/. + * This driver further adds "firmware_update_request" device attribute. + * This attribute normally has a value of 0 and userspace can signal SBL + * to update firmware, on next reboot, by writing a value of 1. + * + * More details of SBL firmware update process is available at: + * https://slimbootloader.github.io/security/firmware-update.html + */ + +#include +#include +#include +#include +#include +#include + +#define INTEL_WMI_SBL_GUID "44FADEB1-B204-40F2-8581-394BBDC1B651" + +static int get_fwu_request(struct device *dev, u32 *out) +{ + struct acpi_buffer result = {ACPI_ALLOCATE_BUFFER, NULL}; + union acpi_object *obj; + acpi_status status; + + status = wmi_query_block(INTEL_WMI_SBL_GUID, 0, &result); + if (ACPI_FAILURE(status)) { + dev_err(dev, "wmi_query_block failed\n"); + return -ENODEV; + } + + obj = (union acpi_object *)result.pointer; + if (!obj || obj->type != ACPI_TYPE_INTEGER) { + dev_warn(dev, "wmi_query_block returned invalid value\n"); + kfree(obj); + return -EINVAL; + } + + *out = obj->integer.value; + kfree(obj); + + return 0; +} + +static int set_fwu_request(struct device *dev, u32 in) +{ + struct acpi_buffer input; + acpi_status status; + u32 value; + + value = in; + input.length = sizeof(u32); + input.pointer = &value; + + status = wmi_set_block(INTEL_WMI_SBL_GUID, 0, &input); + if (ACPI_FAILURE(status)) { + dev_err(dev, "wmi_set_block failed\n"); + return -ENODEV; + } + + return 0; +} + +static ssize_t firmware_update_request_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + u32 val; + int ret; + + ret = get_fwu_request(dev, &val); + if (ret) + return ret; + + return sprintf(buf, "%d\n", val); +} + +static ssize_t firmware_update_request_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + unsigned int val; + int ret; + + ret = kstrtouint(buf, 0, &val); + if (ret) + return ret; + + /* May later be extended to support values other than 0 and 1 */ + if (val > 1) + return -ERANGE; + + ret = set_fwu_request(dev, val); + if (ret) + return ret; + + return count; +} +static DEVICE_ATTR_RW(firmware_update_request); + +static struct attribute *firmware_update_attrs[] = { + &dev_attr_firmware_update_request.attr, + NULL +}; +ATTRIBUTE_GROUPS(firmware_update); + +static int intel_wmi_sbl_fw_update_probe(struct wmi_device *wdev, + const void *context) +{ + dev_info(&wdev->dev, "Slim Bootloader signaling driver attached\n"); + return 0; +} + +static void intel_wmi_sbl_fw_update_remove(struct wmi_device *wdev) +{ + dev_info(&wdev->dev, "Slim Bootloader signaling driver removed\n"); +} + +static const struct wmi_device_id intel_wmi_sbl_id_table[] = { + { .guid_string = INTEL_WMI_SBL_GUID }, + {} +}; +MODULE_DEVICE_TABLE(wmi, intel_wmi_sbl_id_table); + +static struct wmi_driver intel_wmi_sbl_fw_update_driver = { + .driver = { + .name = "intel-wmi-sbl-fw-update", + .dev_groups = firmware_update_groups, + }, + .probe = intel_wmi_sbl_fw_update_probe, + .remove = intel_wmi_sbl_fw_update_remove, + .id_table = intel_wmi_sbl_id_table, +}; +module_wmi_driver(intel_wmi_sbl_fw_update_driver); + +MODULE_AUTHOR("Jithu Joseph "); +MODULE_DESCRIPTION("Slim Bootloader firmware update signaling driver"); +MODULE_LICENSE("GPL v2"); -- cgit v1.2.3-59-g8ed1b