platform/x86/amd/pmf: install notify handler after acpi init
authorShyam Sundar S K <Shyam-sundar.S-k@amd.com>
Fri, 23 Sep 2022 13:17:24 +0000 (18:47 +0530)
committerHans de Goede <hdegoede@redhat.com>
Tue, 27 Sep 2022 12:45:21 +0000 (14:45 +0200)
It is observed that when thinkpad_acpi driver loads before amd-pmf
driver, thinkpad_acpi driver sends the AMT "on" event and the request
immediately will be part of the PMF BIOS "pending requests".

With the current amd-pmf code, as soon as the amd-pmf driver gets
probed, it calls apmf_acpi_init() where the notify handler will be
installed. Handler callback would call amd_pmf_handle_amt() where the
amd_pmf_set_automode() shall update the auto-mode thermals.
In this case, the auto-mode config_store shall have "zeros", as the
auto mode init gets called during the later stage.

To fix this, change the order of the acpi notifer install and call it
after the auto mode initialization is done.

Fixes: 7d77dcc83ada ("platform/x86/amd/pmf: Handle AMT and CQL events for Auto mode")
Cc: Mario Limonciello <mario.limonciello@amd.com>
Cc: Mark Pearson <markpearson@lenovo.com>
Cc: Patil Rajesh Reddy <Patil.Reddy@amd.com>
Signed-off-by: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
Link: https://lore.kernel.org/r/20220923131724.1812685-1-Shyam-sundar.S-k@amd.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
drivers/platform/x86/amd/pmf/acpi.c
drivers/platform/x86/amd/pmf/core.c
drivers/platform/x86/amd/pmf/pmf.h

index cb46a7252414e10c2a3eee404c00bcc21c91ee88..b445c91aa52e5e78ba3bc454fec58930e6e3d53e 100644 (file)
@@ -233,6 +233,28 @@ static int apmf_get_system_params(struct amd_pmf_dev *dev)
        return 0;
 }
 
+int apmf_install_handler(struct amd_pmf_dev *pmf_dev)
+{
+       acpi_handle ahandle = ACPI_HANDLE(pmf_dev->dev);
+       acpi_status status;
+
+       /* Install the APMF Notify handler */
+       if (is_apmf_func_supported(pmf_dev, APMF_FUNC_AUTO_MODE) &&
+           is_apmf_func_supported(pmf_dev, APMF_FUNC_SBIOS_REQUESTS)) {
+               status = acpi_install_notify_handler(ahandle, ACPI_ALL_NOTIFY,
+                                                    apmf_event_handler, pmf_dev);
+               if (ACPI_FAILURE(status)) {
+                       dev_err(pmf_dev->dev, "failed to install notify handler\n");
+                       return -ENODEV;
+               }
+
+               /* Call the handler once manually to catch up with possibly missed notifies. */
+               apmf_event_handler(ahandle, 0, pmf_dev);
+       }
+
+       return 0;
+}
+
 void apmf_acpi_deinit(struct amd_pmf_dev *pmf_dev)
 {
        acpi_handle ahandle = ACPI_HANDLE(pmf_dev->dev);
@@ -247,8 +269,6 @@ void apmf_acpi_deinit(struct amd_pmf_dev *pmf_dev)
 
 int apmf_acpi_init(struct amd_pmf_dev *pmf_dev)
 {
-       acpi_handle ahandle = ACPI_HANDLE(pmf_dev->dev);
-       acpi_status status;
        int ret;
 
        ret = apmf_if_verify_interface(pmf_dev);
@@ -269,20 +289,6 @@ int apmf_acpi_init(struct amd_pmf_dev *pmf_dev)
                schedule_delayed_work(&pmf_dev->heart_beat, 0);
        }
 
-       /* Install the APMF Notify handler */
-       if (is_apmf_func_supported(pmf_dev, APMF_FUNC_AUTO_MODE) &&
-           is_apmf_func_supported(pmf_dev, APMF_FUNC_SBIOS_REQUESTS)) {
-               status = acpi_install_notify_handler(ahandle,
-                                                    ACPI_ALL_NOTIFY,
-                                                    apmf_event_handler, pmf_dev);
-               if (ACPI_FAILURE(status)) {
-                       dev_err(pmf_dev->dev, "failed to install notify handler\n");
-                       return -ENODEV;
-               }
-               /* Call the handler once manually to catch up with possibly missed notifies. */
-               apmf_event_handler(ahandle, 0, pmf_dev);
-       }
-
 out:
        return ret;
 }
index a675ca969331061f14d691a36c4d16eae8aa11ca..785d2ba5ec4fbe8b951ff1d960a8307a6e57f86a 100644 (file)
@@ -352,6 +352,7 @@ static int amd_pmf_probe(struct platform_device *pdev)
        apmf_acpi_init(dev);
        platform_set_drvdata(pdev, dev);
        amd_pmf_init_features(dev);
+       apmf_install_handler(dev);
        amd_pmf_dbgfs_register(dev);
 
        mutex_init(&dev->lock);
index 0a72a395c2efba49a0a315154e7ff79c5c1921e8..1ae4c70a18b24dc7ed5b7b3d950f38f34e9f848b 100644 (file)
@@ -301,6 +301,7 @@ int is_apmf_func_supported(struct amd_pmf_dev *pdev, unsigned long index);
 int amd_pmf_send_cmd(struct amd_pmf_dev *dev, u8 message, bool get, u32 arg, u32 *data);
 int amd_pmf_init_metrics_table(struct amd_pmf_dev *dev);
 int amd_pmf_get_power_source(void);
+int apmf_install_handler(struct amd_pmf_dev *pmf_dev);
 
 /* SPS Layer */
 int amd_pmf_get_pprof_modes(struct amd_pmf_dev *pmf);