From ea64db7d19d4ac07fabd8b07ea6e1bba384b37c3 Mon Sep 17 00:00:00 2001 From: Mario Limonciello Date: Tue, 30 Aug 2022 15:11:33 -0500 Subject: [PATCH] lenovo-thinklmi: Disable changing sleep mode on Ryzen 6000 systems S3 is not supported by AMD and is not exposed in the GUI on these systems. Lenovo however exports it to their WMI interface and changing it will means it can only be changed from the OS. --- .../fu-plugin-lenovo-thinklmi.c | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/plugins/lenovo-thinklmi/fu-plugin-lenovo-thinklmi.c b/plugins/lenovo-thinklmi/fu-plugin-lenovo-thinklmi.c index 172876cdf..0beac7b2d 100644 --- a/plugins/lenovo-thinklmi/fu-plugin-lenovo-thinklmi.c +++ b/plugins/lenovo-thinklmi/fu-plugin-lenovo-thinklmi.c @@ -8,6 +8,7 @@ #include +#define SLEEP_MODE "com.thinklmi.SleepState" #define BOOT_ORDER_LOCK "com.thinklmi.BootOrderLock" static gboolean @@ -27,13 +28,23 @@ fu_plugin_lenovo_thinklmi_startup(FuPlugin *plugin, FuProgress *progress, GError } static void -fu_plugin_lenovo_thinklmi_device_registered(FuPlugin *plugin, FuDevice *device) +fu_plugin_lenovo_thinklmi_cpu_registered(FuContext *ctx, FuDevice *device) { - FuContext *ctx = fu_plugin_get_context(plugin); - FwupdBiosSetting *attr; + /* Ryzen 6000 doesn't support S3 even if the BIOS offers it */ + if (fu_device_has_instance_id(device, "CPUID\\PRO_0&FAM_19&MOD_44")) { + FwupdBiosSetting *attr = fu_context_get_bios_setting(ctx, SLEEP_MODE); - if (g_strcmp0(fu_device_get_plugin(device), "uefi_capsule") != 0) - return; + if (attr != NULL) { + g_debug("Setting %s to read-only", fwupd_bios_setting_get_name(attr)); + fwupd_bios_setting_set_read_only(attr, TRUE); + } + } +} + +static void +fu_plugin_lenovo_thinklmi_uefi_capsule_registered(FuContext *ctx, FuDevice *device) +{ + FwupdBiosSetting *attr; /* check if boot order lock is turned on */ attr = fu_context_get_bios_setting(ctx, BOOT_ORDER_LOCK); @@ -55,6 +66,17 @@ fu_plugin_lenovo_thinklmi_device_registered(FuPlugin *plugin, FuDevice *device) } } +static void +fu_plugin_lenovo_thinklmi_device_registered(FuPlugin *plugin, FuDevice *device) +{ + if (g_strcmp0(fu_device_get_plugin(device), "uefi_capsule") == 0) { + fu_plugin_lenovo_thinklmi_uefi_capsule_registered(fu_plugin_get_context(plugin), + device); + } else if (g_strcmp0(fu_device_get_plugin(device), "cpu") == 0) { + fu_plugin_lenovo_thinklmi_cpu_registered(fu_plugin_get_context(plugin), device); + } +} + void fu_plugin_init_vfuncs(FuPluginVfuncs *vfuncs) {