From patchwork Thu Mar 10 21:08:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jorge Lopez X-Patchwork-Id: 12776931 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E4C3C433EF for ; Thu, 10 Mar 2022 21:08:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343879AbiCJVJ7 (ORCPT ); Thu, 10 Mar 2022 16:09:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242662AbiCJVJ6 (ORCPT ); Thu, 10 Mar 2022 16:09:58 -0500 Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D347E4E39F for ; Thu, 10 Mar 2022 13:08:56 -0800 (PST) Received: by mail-qk1-x733.google.com with SMTP id k125so95845qkf.0 for ; Thu, 10 Mar 2022 13:08:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=hT9GBFHhgAIWzF/ewVI8GFvXyI97EyT2euSkepLdhXQ=; b=pQBhLzrEe7A1tdJqVp4tIJbfCzm10Sc3XMNC8gqjPuOUGekGubkIJ2zkAgjjuJS9FK yDJLN1xR08sQNtPkYkPDH2blSBGEiqzjOzpRmway+x5ZFZbHM8XYgiEcUAvXv8AggA/m E8fybQPlWDWPcbMkcPB/hq70gBz6r4TO0l0OxOLsqjTf3l+vL4iMBTCYPq3KzK3A3veS cbsA3nFx/C+xT0Kjf9at/1Jlgzej7Wvc+bosT2NIpUcA7s608tGQXJofHEhRRKXVJju/ jVAaJYFgrQNGjCQ8O7FON7AnH+FKvohwsiN8m/JeAwkWp9B9PamF+0qtajZLuR0+sgN5 uuDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hT9GBFHhgAIWzF/ewVI8GFvXyI97EyT2euSkepLdhXQ=; b=4Nd4BTLXdCHvUZNG/9mJpitHqD/Zys/SOaN44cFitENNqP2EL7IDLvAuGRBd2QNaOp WFutLLHYjAqHZnaZQiDUQw/adxaHqipBoslycA5B12N31caDDcDi8N2k7h6P+kki5VwR e2ywTNSefpIu0igdQgr/tAF3XzU9fnb8NaSG9IT6a0IKtSaQOlvDO8hrbAOfoXJN3O5Y opUALsikL6dQht69BMn8A2OUr4gwVcU+hsP7QXm87P5paQbM0Do/ljCh9pKQuQMuvYxT BrwwgByHnbuwGIWpHQw/O1kyETTxgb1DV3n5G1nY5ohoJ5MMRyGZAz4NKcNynGi8tcsL 0HyQ== X-Gm-Message-State: AOAM53292rkAzeBrszOhhhfyoNRvs5qh616co4mTiM8bjM25uv2n1af8 +U3jEx4LqMbn22DzWsY9fuOeiBi7Ajs= X-Google-Smtp-Source: ABdhPJwqluFRzapPAZKLC9eeCEV/CiXUGu9wvAZqO2BK8W2i+JH6Mganz2gIulUMlpqSv3oY3LGRQA== X-Received: by 2002:a05:620a:22db:b0:67d:72f5:bc60 with SMTP id o27-20020a05620a22db00b0067d72f5bc60mr775951qki.633.1646946535715; Thu, 10 Mar 2022 13:08:55 -0800 (PST) Received: from grumpy-vm.hsd1.tx.comcast.net ([2601:2c3:480:7390:c0b0:4de4:5b27:f2e7]) by smtp.gmail.com with ESMTPSA id k6-20020a378806000000b0064915d9584fsm2881727qkd.8.2022.03.10.13.08.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 13:08:55 -0800 (PST) From: Jorge Lopez X-Google-Original-From: Jorge Lopez To: platform-driver-x86@vger.kernel.org Subject: [PATCH v5 1/4] Fix hp_wmi_read_int() reporting error (0x05) Date: Thu, 10 Mar 2022 15:08:50 -0600 Message-Id: <20220310210853.28367-2-jorge.lopez2@hp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220310210853.28367-1-jorge.lopez2@hp.com> References: <20220310210853.28367-1-jorge.lopez2@hp.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org The purpose of this patch is to introduce a fix to hp_wmi_read_int() and eliminate failure error (0x05). Several WMI queries leverage hp_wmi_read_int() to read their data and were failing with error 0x05. HPWMI_DISPLAY_QUERY HPWMI_HDDTEMP_QUERY HPWMI_ALS_QUERY HPWMI_HARDWARE_QUERY HPWMI_WIRELESS_QUERY HPWMI_POSTCODEERROR_QUERY The failure occurs because hp_wmi_read_int() calls hp_wmi_perform_query() with input parameter of size greater than zero. Invoking those WMI commands with an input buffer size greater than zero causes the command to be rejected and error 0x05 be returned. All changes were validated on a HP ZBook Workstation notebook, HP EliteBook x360, and HP EliteBook 850 G8. Signed-off-by: Jorge Lopez --- Based on the latest platform-drivers-x86.git/for-next --- drivers/platform/x86/hp-wmi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c index 48a46466f086..103f56399ed0 100644 --- a/drivers/platform/x86/hp-wmi.c +++ b/drivers/platform/x86/hp-wmi.c @@ -337,7 +337,7 @@ static int hp_wmi_read_int(int query) int val = 0, ret; ret = hp_wmi_perform_query(query, HPWMI_READ, &val, - sizeof(val), sizeof(val)); + 0, sizeof(val)); if (ret) return ret < 0 ? ret : -EINVAL; From patchwork Thu Mar 10 21:08:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jorge Lopez X-Patchwork-Id: 12776932 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08B0EC433FE for ; Thu, 10 Mar 2022 21:09:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242662AbiCJVJ7 (ORCPT ); Thu, 10 Mar 2022 16:09:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343889AbiCJVJ7 (ORCPT ); Thu, 10 Mar 2022 16:09:59 -0500 Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 934BF3DDC3 for ; Thu, 10 Mar 2022 13:08:57 -0800 (PST) Received: by mail-qk1-x735.google.com with SMTP id v15so5490392qkg.8 for ; Thu, 10 Mar 2022 13:08:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Upaa1kgWpqw/Vg1N6wJAUKq4F3KMqmL1t14zMQMurnw=; b=Zcr11dA/zREo3dihXOrKQx35Umctakjw2T0daa/ozhEXlMP7h/SKh7mgcHsNdTjrhe wX0BkA+7R7mXuA8qTXysU9P61dVP4pKgSQzfTEk2PEm7BE3yk+0tRwtDCU6gPOCA2lhX uAfMrs8XaCT0DtaRNcg+E4+v9VbbDGy5Nh8LOwMjsE8mGi0JCZ9V4JSRexp48BVK3LTv RBt0lBOtpxC3aVAgDt6i50oqKXg5/I80KDTRix1Z+NkauhuKsjzhxHl+LY18uL9phW49 u2iR0I7MO6NB5Ns8CHHnI0FglBE17u0I2fA88mP9pu4Lm9NaVydoO/vy6ePznid4PWzZ 7QXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Upaa1kgWpqw/Vg1N6wJAUKq4F3KMqmL1t14zMQMurnw=; b=qApV1WRa7Dgua4apn0NS8FfaLjZagZPk+yDeKog1FfDyuCaD20aDoB2PFRu1wiM09M goia1h/G1vKQzF710KzcBPNfErt4jhu/d5odiqqw6djKOQE02HAw1neQxzCy2ZR3L/qu Yx9GZ/PM9AteBhyQU2gykfNiNGcg+BWXh1pkVZO4DIxDTSBYxTdjZqeu4qdqdimpXhOP 9GWbzo8dsyWMCVRIqq2P037NAUkFWGGLq64P5dvSnMMh6LS7Fus+deEk5Eg8s/u84K1q +VvD2HffIMtcJMPT4+hohLaXaRhpT/0TTrw/61W9fEr/PMBQFhUBocNbVZgogDF4wWJI QZtw== X-Gm-Message-State: AOAM530Rqz4QuTeFy0UaOyH06mdLpMpsuaPYlOx2nGmMYkE2dEkY8k+P P2ewbh+j0D24hW+zcCzt3S/ESt23YIE= X-Google-Smtp-Source: ABdhPJz4brUUBTP8SyzgvJvtUbUDJJDp01LeL0o+ZNSavjbap0bz9WhfGZJ2JtOEuI6JPr2U+Pv3Tw== X-Received: by 2002:a37:f510:0:b0:663:9d17:8c2e with SMTP id l16-20020a37f510000000b006639d178c2emr4346307qkk.397.1646946536461; Thu, 10 Mar 2022 13:08:56 -0800 (PST) Received: from grumpy-vm.hsd1.tx.comcast.net ([2601:2c3:480:7390:c0b0:4de4:5b27:f2e7]) by smtp.gmail.com with ESMTPSA id k6-20020a378806000000b0064915d9584fsm2881727qkd.8.2022.03.10.13.08.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 13:08:56 -0800 (PST) From: Jorge Lopez X-Google-Original-From: Jorge Lopez To: platform-driver-x86@vger.kernel.org Subject: [PATCH v5 2/4] Fix SW_TABLET_MODE detection method Date: Thu, 10 Mar 2022 15:08:51 -0600 Message-Id: <20220310210853.28367-3-jorge.lopez2@hp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220310210853.28367-1-jorge.lopez2@hp.com> References: <20220310210853.28367-1-jorge.lopez2@hp.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org The purpose of this patch is to introduce a fix and removal of the current hack when determining tablet mode status. Determining the tablet mode status requires reading Byte 0 bit 2 as reported by HPWMI_HARDWARE_QUERY. The investigation identified the failure was rooted in two areas: HPWMI_HARDWARE_QUERY failure (0x05) and reading Byte 0, bit 2 only to determine the table mode status. HPWMI_HARDWARE_QUERY WMI failure also rendered the dock state value invalid. The latest changes use SMBIOS Type 3 (chassis type) and WMI Command 0x40 (device_mode_status) information to determine if the device is in tablet mode or not. hp_wmi_hw_state function was split into two functions; hp_wmi_get_dock_state and hp_wmi_get_tablet_mode. The new functions separate how dock_state and tablet_mode is handled in a cleaner manner. All changes were validated on a HP ZBook Workstation notebook, HP EliteBook x360, and HP EliteBook 850 G8. Signed-off-by: Jorge Lopez Signed-off-by: Stefan Sichler --- Based on the latest platform-drivers-x86.git/for-next This patch requires patch "Fix hp_wmi_read_int() reporting error (0x05)" in order to work correctly. --- drivers/platform/x86/hp-wmi.c | 71 +++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 19 deletions(-) diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c index 103f56399ed0..e9aa05c26a40 100644 --- a/drivers/platform/x86/hp-wmi.c +++ b/drivers/platform/x86/hp-wmi.c @@ -35,10 +35,6 @@ MODULE_LICENSE("GPL"); MODULE_ALIAS("wmi:95F24279-4D7B-4334-9387-ACCDC67EF61C"); MODULE_ALIAS("wmi:5FB7F034-2C63-45e9-BE91-3D44E2C707E4"); -static int enable_tablet_mode_sw = -1; -module_param(enable_tablet_mode_sw, int, 0444); -MODULE_PARM_DESC(enable_tablet_mode_sw, "Enable SW_TABLET_MODE reporting (-1=auto, 0=no, 1=yes)"); - #define HPWMI_EVENT_GUID "95F24279-4D7B-4334-9387-ACCDC67EF61C" #define HPWMI_BIOS_GUID "5FB7F034-2C63-45e9-BE91-3D44E2C707E4" #define HP_OMEN_EC_THERMAL_PROFILE_OFFSET 0x95 @@ -107,6 +103,7 @@ enum hp_wmi_commandtype { HPWMI_FEATURE2_QUERY = 0x0d, HPWMI_WIRELESS2_QUERY = 0x1b, HPWMI_POSTCODEERROR_QUERY = 0x2a, + HPWMI_SYSTEM_DEVICE_MODE = 0x40, HPWMI_THERMAL_PROFILE_QUERY = 0x4c, }; @@ -217,6 +214,18 @@ struct rfkill2_device { static int rfkill2_count; static struct rfkill2_device rfkill2[HPWMI_MAX_RFKILL2_DEVICES]; +/* Chassis Types values were obtained from SMBIOS reference + * specification version 3.00. A complete list of system enclosures + * and chassis types is available on Table 17. + */ +static const char * const tablet_chassis_types[] = { + "30", /* Tablet*/ + "31", /* Convertible */ + "32" /* Detachable */ +}; + +#define DEVICE_MODE_TABLET 0x06 + /* map output size to the corresponding WMI method id */ static inline int encode_outsize_for_pvsz(int outsize) { @@ -345,14 +354,40 @@ static int hp_wmi_read_int(int query) return val; } -static int hp_wmi_hw_state(int mask) +static int hp_wmi_get_dock_state(void) { int state = hp_wmi_read_int(HPWMI_HARDWARE_QUERY); if (state < 0) return state; - return !!(state & mask); + return !!(state & HPWMI_DOCK_MASK); +} + +static int hp_wmi_get_tablet_mode(void) +{ + char system_device_mode[4] = { 0 }; + int ret; + bool tablet_found = false; + + const char *chassis_type = dmi_get_system_info(DMI_CHASSIS_TYPE); + + if (!chassis_type) + return -ENODEV; + + tablet_found = match_string(tablet_chassis_types, + ARRAY_SIZE(tablet_chassis_types), + chassis_type) >= 0; + if (!tablet_found) + return -ENODEV; + + ret = hp_wmi_perform_query(HPWMI_SYSTEM_DEVICE_MODE, HPWMI_READ, + system_device_mode, 0, sizeof(system_device_mode)); + + if (ret < 0) + return ret; + + return system_device_mode[0] == DEVICE_MODE_TABLET; } static int omen_thermal_profile_set(int mode) @@ -568,7 +603,7 @@ static ssize_t als_show(struct device *dev, struct device_attribute *attr, static ssize_t dock_show(struct device *dev, struct device_attribute *attr, char *buf) { - int value = hp_wmi_hw_state(HPWMI_DOCK_MASK); + int value = hp_wmi_get_dock_state(); if (value < 0) return value; return sprintf(buf, "%d\n", value); @@ -577,7 +612,7 @@ static ssize_t dock_show(struct device *dev, struct device_attribute *attr, static ssize_t tablet_show(struct device *dev, struct device_attribute *attr, char *buf) { - int value = hp_wmi_hw_state(HPWMI_TABLET_MASK); + int value = hp_wmi_get_tablet_mode(); if (value < 0) return value; return sprintf(buf, "%d\n", value); @@ -699,10 +734,10 @@ static void hp_wmi_notify(u32 value, void *context) case HPWMI_DOCK_EVENT: if (test_bit(SW_DOCK, hp_wmi_input_dev->swbit)) input_report_switch(hp_wmi_input_dev, SW_DOCK, - hp_wmi_hw_state(HPWMI_DOCK_MASK)); + hp_wmi_get_dock_state()); if (test_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit)) input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, - hp_wmi_hw_state(HPWMI_TABLET_MASK)); + hp_wmi_get_tablet_mode()); input_sync(hp_wmi_input_dev); break; case HPWMI_PARK_HDD: @@ -780,19 +815,17 @@ static int __init hp_wmi_input_setup(void) __set_bit(EV_SW, hp_wmi_input_dev->evbit); /* Dock */ - val = hp_wmi_hw_state(HPWMI_DOCK_MASK); + val = hp_wmi_get_dock_state(); if (!(val < 0)) { __set_bit(SW_DOCK, hp_wmi_input_dev->swbit); input_report_switch(hp_wmi_input_dev, SW_DOCK, val); } /* Tablet mode */ - if (enable_tablet_mode_sw > 0) { - val = hp_wmi_hw_state(HPWMI_TABLET_MASK); - if (val >= 0) { - __set_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit); - input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, val); - } + val = hp_wmi_get_tablet_mode(); + if (!(val < 0)) { + __set_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit); + input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, val); } err = sparse_keymap_setup(hp_wmi_input_dev, hp_wmi_keymap, NULL); @@ -1227,10 +1260,10 @@ static int hp_wmi_resume_handler(struct device *device) if (hp_wmi_input_dev) { if (test_bit(SW_DOCK, hp_wmi_input_dev->swbit)) input_report_switch(hp_wmi_input_dev, SW_DOCK, - hp_wmi_hw_state(HPWMI_DOCK_MASK)); + hp_wmi_get_dock_state()); if (test_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit)) input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, - hp_wmi_hw_state(HPWMI_TABLET_MASK)); + hp_wmi_get_tablet_mode()); input_sync(hp_wmi_input_dev); } From patchwork Thu Mar 10 21:08:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jorge Lopez X-Patchwork-Id: 12776933 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD4CFC433F5 for ; Thu, 10 Mar 2022 21:09:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343902AbiCJVKA (ORCPT ); Thu, 10 Mar 2022 16:10:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343894AbiCJVKA (ORCPT ); Thu, 10 Mar 2022 16:10:00 -0500 Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C6A64D273 for ; Thu, 10 Mar 2022 13:08:58 -0800 (PST) Received: by mail-qk1-x72d.google.com with SMTP id s16so5506235qks.4 for ; Thu, 10 Mar 2022 13:08:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=iwbfiO4dV4isxj0/47jC10sTAI5+jcOns3DMoibBzAk=; b=ZhwHOB02CqKgQHRF0xOU7+BO5pe+IvHYGYh4hf/pmCUGSArs3dfSZaVtJk0j0XNQMy qWJj5wTVrKVyifUKFBt/lKVSbZIEXn3mItqoVf0jr7wP57bUdKI0pbZ1wcE/Rq8+QS9F IRVho7ISkPduN4DdzJU3e4i48bZ6loA/W+K4j9Kti1aJdJuW0MPxGU8amE7IJoU1GK95 eQtKrRxqWMzNPU7TAuhNbbEDqZ4tl5Qq2T+9Ii7PXVV9+cDx4H/njLCHPq7cG792yLbc x3FXDSQT1ReL39YllYtEt0msibjYDWP6BCTmw5XcrrCukLofoIJUOKLtxELKF/1vuS2s QleQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iwbfiO4dV4isxj0/47jC10sTAI5+jcOns3DMoibBzAk=; b=tZ3rFTYpcIngCGuJPE1jl5Yxkq121J0WcYWtOx4fjdjA72tGofZMBkKquMLPln8ts5 xUT89FZqe4WnrgARIJu0zhPhristVpxaEM/YLtcOaxw+ehZipVZ4sOBpEdp4weRgFC7U iDgoC//AEKNlyB8qGZXAwQLJP1rS63jhlfwGhPtLM4Z5w9IdkiPgavM+2sV+57ENCGNR b1iNeEhItSuMm8VlSP/MtDyUTz/SQ8Z+pOYFvIi5yCMQNL8X5AjmgjLjhz7k6mF+XD1G RgsCISnoO2J97I3I3kqVjGsmltt4D8Cmt8GJ8/Wyft4vCX9NACYjOnQJ7mfkbnqdtZ9D OTyw== X-Gm-Message-State: AOAM530onsaZ2eaJrWRcddJvHy7LQW+cj9ayiqIG69My0xkzeUMzAfDK 27tg9SL++yHzcoyB5rdzixCSlT3EzwM= X-Google-Smtp-Source: ABdhPJzRT5tzU0OEPwg+ANsAEcPlbwc1CEoRF9ICnm0EeCxo/MZc60BLJpQSTkCAS2ji79IgNn57Vw== X-Received: by 2002:a05:620a:1a99:b0:67d:27ba:9bec with SMTP id bl25-20020a05620a1a9900b0067d27ba9becmr4495415qkb.482.1646946537257; Thu, 10 Mar 2022 13:08:57 -0800 (PST) Received: from grumpy-vm.hsd1.tx.comcast.net ([2601:2c3:480:7390:c0b0:4de4:5b27:f2e7]) by smtp.gmail.com with ESMTPSA id k6-20020a378806000000b0064915d9584fsm2881727qkd.8.2022.03.10.13.08.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 13:08:56 -0800 (PST) From: Jorge Lopez X-Google-Original-From: Jorge Lopez To: platform-driver-x86@vger.kernel.org Subject: [PATCH v5 3/4] Fix 0x05 error code reported by several WMI calls Date: Thu, 10 Mar 2022 15:08:52 -0600 Message-Id: <20220310210853.28367-4-jorge.lopez2@hp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220310210853.28367-1-jorge.lopez2@hp.com> References: <20220310210853.28367-1-jorge.lopez2@hp.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Several WMI queries leverage hp_wmi_read_int function to read their data. hp_wmi_read_int function was corrected in a previous patch. Now, this function invokes hp_wmi_perform_query with input parameter of size zero and the output buffer of size 4. WMI commands calling hp_wmi_perform_query with input buffer size value of zero are listed below. HPWMI_DISPLAY_QUERY HPWMI_HDDTEMP_QUERY HPWMI_ALS_QUERY HPWMI_HARDWARE_QUERY HPWMI_WIRELESS_QUERY HPWMI_BIOS_QUERY HPWMI_FEATURE_QUERY HPWMI_HOTKEY_QUERY HPWMI_FEATURE2_QUERY HPWMI_WIRELESS2_QUERY HPWMI_POSTCODEERROR_QUERY HPWMI_THERMAL_PROFILE_QUERY HPWMI_FAN_SPEED_MAX_GET_QUERY Invoking those WMI commands with an input buffer size greater than zero will cause error 0x05 to be returned. All WMI commands executed by the driver were reviewed and changes were made to ensure the expected input and output buffer size match the WMI specification. Changes were validated on a HP ZBook Workstation notebook, HP EliteBook x360, and HP EliteBook 850 G8. Additional validation was included in the test process to ensure no other commands were incorrectly handled. Signed-off-by: Jorge Lopez --- Based on the latest platform-drivers-x86.git/for-next --- drivers/platform/x86/hp-wmi.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c index e9aa05c26a40..e76bd4bef6b5 100644 --- a/drivers/platform/x86/hp-wmi.c +++ b/drivers/platform/x86/hp-wmi.c @@ -329,7 +329,7 @@ static int hp_wmi_get_fan_speed(int fan) char fan_data[4] = { fan, 0, 0, 0 }; int ret = hp_wmi_perform_query(HPWMI_FAN_SPEED_GET_QUERY, HPWMI_GM, - &fan_data, sizeof(fan_data), + &fan_data, sizeof(char), sizeof(fan_data)); if (ret != 0) @@ -399,7 +399,7 @@ static int omen_thermal_profile_set(int mode) return -EINVAL; ret = hp_wmi_perform_query(HPWMI_SET_PERFORMANCE_MODE, HPWMI_GM, - &buffer, sizeof(buffer), sizeof(buffer)); + &buffer, sizeof(buffer), 0); if (ret) return ret < 0 ? ret : -EINVAL; @@ -436,7 +436,7 @@ static int hp_wmi_fan_speed_max_set(int enabled) int ret; ret = hp_wmi_perform_query(HPWMI_FAN_SPEED_MAX_SET_QUERY, HPWMI_GM, - &enabled, sizeof(enabled), sizeof(enabled)); + &enabled, sizeof(enabled), 0); if (ret) return ret < 0 ? ret : -EINVAL; @@ -449,7 +449,7 @@ static int hp_wmi_fan_speed_max_get(void) int val = 0, ret; ret = hp_wmi_perform_query(HPWMI_FAN_SPEED_MAX_GET_QUERY, HPWMI_GM, - &val, sizeof(val), sizeof(val)); + &val, 0, sizeof(val)); if (ret) return ret < 0 ? ret : -EINVAL; @@ -461,7 +461,7 @@ static int __init hp_wmi_bios_2008_later(void) { int state = 0; int ret = hp_wmi_perform_query(HPWMI_FEATURE_QUERY, HPWMI_READ, &state, - sizeof(state), sizeof(state)); + 0, sizeof(state)); if (!ret) return 1; @@ -472,7 +472,7 @@ static int __init hp_wmi_bios_2009_later(void) { u8 state[128]; int ret = hp_wmi_perform_query(HPWMI_FEATURE2_QUERY, HPWMI_READ, &state, - sizeof(state), sizeof(state)); + 0, sizeof(state)); if (!ret) return 1; @@ -550,7 +550,7 @@ static int hp_wmi_rfkill2_refresh(void) int err, i; err = hp_wmi_perform_query(HPWMI_WIRELESS2_QUERY, HPWMI_READ, &state, - sizeof(state), sizeof(state)); + 0, sizeof(state)); if (err) return err; @@ -639,7 +639,7 @@ static ssize_t als_store(struct device *dev, struct device_attribute *attr, return ret; ret = hp_wmi_perform_query(HPWMI_ALS_QUERY, HPWMI_WRITE, &tmp, - sizeof(tmp), sizeof(tmp)); + sizeof(tmp), 0); if (ret) return ret < 0 ? ret : -EINVAL; @@ -660,9 +660,9 @@ static ssize_t postcode_store(struct device *dev, struct device_attribute *attr, if (clear == false) return -EINVAL; - /* Clear the POST error code. It is kept until until cleared. */ + /* Clear the POST error code. It is kept until cleared. */ ret = hp_wmi_perform_query(HPWMI_POSTCODEERROR_QUERY, HPWMI_WRITE, &tmp, - sizeof(tmp), sizeof(tmp)); + sizeof(tmp), 0); if (ret) return ret < 0 ? ret : -EINVAL; @@ -952,7 +952,7 @@ static int __init hp_wmi_rfkill2_setup(struct platform_device *device) int err, i; err = hp_wmi_perform_query(HPWMI_WIRELESS2_QUERY, HPWMI_READ, &state, - sizeof(state), sizeof(state)); + 0, sizeof(state)); if (err) return err < 0 ? err : -EINVAL; From patchwork Thu Mar 10 21:08:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jorge Lopez X-Patchwork-Id: 12776934 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F0F0C4332F for ; Thu, 10 Mar 2022 21:09:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343894AbiCJVKB (ORCPT ); Thu, 10 Mar 2022 16:10:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343889AbiCJVKA (ORCPT ); Thu, 10 Mar 2022 16:10:00 -0500 Received: from mail-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2B184DF62 for ; Thu, 10 Mar 2022 13:08:58 -0800 (PST) Received: by mail-qk1-x72f.google.com with SMTP id r127so5467696qke.13 for ; Thu, 10 Mar 2022 13:08:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=lKko2zVjvFLxheKUr9P/i/K6RQQt+T5e5d08DGe2Z24=; b=ET4f7079R32BGXGYt43glhtAJhUVPVdkb4yprXlpvy6+MqJezjqYs45sw23S2M/tm/ fR0bIrO3RM+OTTzsUQWcZqKROqr/28pVUfpD+0GLxdPMoPb/wLj62C3w3BQVoV456gFZ PNDOScXOdlN11jKv6n6WPObkGbZ/CIFsOrCoFR78T2XjSbItIJc63KgT0kxvm3f2hC4v zFRYfKFZBiQHdMdtaK+hn3VTwuXQWzkh3/CPnIKtnr4RG3UN6MgYiLVoNWrOcMrANalu ln6pZyIaX+ageF7L9oFiP07D0xnJjRelbyXC6fX3aWgJSHSRL8iCRMBvKEw8y2agua7x mbtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lKko2zVjvFLxheKUr9P/i/K6RQQt+T5e5d08DGe2Z24=; b=qCKyR/Gox2bbQOz1H6kjL2Cs00y9gG/MxQuGubIUjmAcc44z0yEC4jPCMC0lRYlWsv htpBYmNSCoHIZIut3m2EfyH3Y78sUte/Sr/BXeV5qGETLHFGFA8qiq0rzhC4sHmPV0yW 4d9W54nFXVOfvQ9EYagK2K2P08j3EFyjxCoX4n8Xv8zl4TLoL9OI+MTQROwafIEQABzp 6pXiPz4pQgFfdpkzvaMp4MlNXHb+XjT9U/iZuAQBG3Be3I5FZWszIkH0UDIV6mCfADlK twkpiAugXnl0PxSdEwPN9pMTCaCQD/iX4TyDS7ba3bFV5sWU3TJuTlnnduqqRwwddrbf rsKA== X-Gm-Message-State: AOAM530vtd1WCF4s/QoygxrHhnjsPuEK/fRuOROo3jrUpIcZKIhWOc4i i9UeRYd/hg6uhmFPGcWT488pHhdCXaA= X-Google-Smtp-Source: ABdhPJzJY/helysDLJUAEfiDC2s+evLdi3dwZaGy5uyjPO5CEHHSNGpYhbtPH97DUKRtBbq8T9lrUA== X-Received: by 2002:a37:c85:0:b0:67b:30aa:b09c with SMTP id 127-20020a370c85000000b0067b30aab09cmr4415834qkm.283.1646946537783; Thu, 10 Mar 2022 13:08:57 -0800 (PST) Received: from grumpy-vm.hsd1.tx.comcast.net ([2601:2c3:480:7390:c0b0:4de4:5b27:f2e7]) by smtp.gmail.com with ESMTPSA id k6-20020a378806000000b0064915d9584fsm2881727qkd.8.2022.03.10.13.08.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 13:08:57 -0800 (PST) From: Jorge Lopez X-Google-Original-From: Jorge Lopez To: platform-driver-x86@vger.kernel.org Subject: [PATCH v5 4/4] Changing bios_args.data to be dynamically allocated Date: Thu, 10 Mar 2022 15:08:53 -0600 Message-Id: <20220310210853.28367-5-jorge.lopez2@hp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220310210853.28367-1-jorge.lopez2@hp.com> References: <20220310210853.28367-1-jorge.lopez2@hp.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org The purpose of this patch is to remove 128 bytes buffer limitation imposed in bios_args structure. A limiting factor discovered during this investigation was the struct bios_args.data size restriction. The data member size limits all possible WMI commands to those requiring buffer size of 128 bytes or less. Several WMI commands and queries require a buffer size larger than 128 bytes hence limiting current and feature supported by the driver. It is for this reason, struct bios_args.data changed and is dynamically allocated. hp_wmi_perform_query function changed to handle the memory allocation and release of any required buffer size. All changes were validated on a HP ZBook Workstation notebook, HP EliteBook x360, and HP EliteBook 850 G8. Additional validation was included in the test process to ensure no other commands were incorrectly handled. Signed-off-by: Jorge Lopez --- Based on the latest platform-drivers-x86.git/for-next --- drivers/platform/x86/hp-wmi.c | 64 +++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 22 deletions(-) diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c index e76bd4bef6b5..cc5c4f637328 100644 --- a/drivers/platform/x86/hp-wmi.c +++ b/drivers/platform/x86/hp-wmi.c @@ -82,12 +82,17 @@ enum hp_wmi_event_ids { HPWMI_BATTERY_CHARGE_PERIOD = 0x10, }; +/** + * struct bios_args buffer is dynamically allocated. New WMI command types + * were introduced that exceeds 128-byte data size. Changes to handle + * the data size allocation scheme were kept in hp_wmi_perform_qurey function. + */ struct bios_args { u32 signature; u32 command; u32 commandtype; u32 datasize; - u8 data[128]; + u8 data[]; }; enum hp_wmi_commandtype { @@ -268,34 +273,40 @@ static int hp_wmi_perform_query(int query, enum hp_wmi_command command, int mid; struct bios_return *bios_return; int actual_outsize; - union acpi_object *obj; - struct bios_args args = { - .signature = 0x55434553, - .command = command, - .commandtype = query, - .datasize = insize, - .data = { 0 }, - }; - struct acpi_buffer input = { sizeof(struct bios_args), &args }; + union acpi_object *obj = NULL; + struct bios_args *args = NULL; + size_t bios_args_size = struct_size(args, data, insize); + + struct acpi_buffer input; struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; int ret = 0; - mid = encode_outsize_for_pvsz(outsize); - if (WARN_ON(mid < 0)) - return mid; + args = kmalloc(bios_args_size, GFP_KERNEL); + if (!args) + return -ENOMEM; - if (WARN_ON(insize > sizeof(args.data))) - return -EINVAL; - memcpy(&args.data[0], buffer, insize); + input.length = bios_args_size; + input.pointer = args; - wmi_evaluate_method(HPWMI_BIOS_GUID, 0, mid, &input, &output); + mid = encode_outsize_for_pvsz(outsize); + if (WARN_ON(mid < 0)) { + ret = mid; + goto out_free; + } - obj = output.pointer; + memcpy(args->data, buffer, flex_array_size(args, data, insize)); - if (!obj) - return -EINVAL; + args->signature = 0x55434553; + args->command = command; + args->commandtype = query; + args->datasize = insize; - if (obj->type != ACPI_TYPE_BUFFER) { + ret = wmi_evaluate_method(HPWMI_BIOS_GUID, 0, mid, &input, &output); + if (ret) + goto out_free; + + obj = output.pointer; + if (!obj) { ret = -EINVAL; goto out_free; } @@ -310,9 +321,17 @@ static int hp_wmi_perform_query(int query, enum hp_wmi_command command, goto out_free; } + if (obj->type != ACPI_TYPE_BUFFER) { + pr_warn("query 0x%x returned an invalid object 0x%x\n", query, ret); + ret = -EINVAL; + goto out_free; + } + /* Ignore output data of zero size */ - if (!outsize) + if (!outsize) { + ret = 0; goto out_free; + } actual_outsize = min(outsize, (int)(obj->buffer.length - sizeof(*bios_return))); memcpy(buffer, obj->buffer.pointer + sizeof(*bios_return), actual_outsize); @@ -320,6 +339,7 @@ static int hp_wmi_perform_query(int query, enum hp_wmi_command command, out_free: kfree(obj); + kfree(args); return ret; }