From nobody Fri Nov 29 00:57:18 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F49D17B4F6; Thu, 26 Sep 2024 03:00:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727319608; cv=none; b=g0vmxyVTX8eh4TR24DyKhm1aMMtHr9bL06A0I9PgAorfYpnfe2nCWGEG8WjDhN91DRkxVr8kzfR6tMrhhS0qk1f+pI2SJNrYAyaQYNVGi8bxTFYkdWpG+wm4hX9oxwlX8gSFhEq+Ff1iExDyM9ZumiLaO8n+BZfwwo0ROFyHZUc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727319608; c=relaxed/simple; bh=DQn0vH1OySQQskSdxWk+PEierBBh+i24Ih2z+s/Zr6o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rN1koNTUH71RnxGOn/hOmVC7kpYIm/H4NCuvUhBwsI8kC6K3rfM+iE+p9uaJgKxJMjau9NyPwMByPXTVCvwAzLojdsxbZESYVCG6dfEamMJGPYwyvGBVvK82vz1XDKxzs6zror75ixj8iOEq/uKk4lNpQt/+uxbexyP9z9AC2kA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LzygvwhD; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LzygvwhD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4EE91C4CECE; Thu, 26 Sep 2024 03:00:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727319607; bh=DQn0vH1OySQQskSdxWk+PEierBBh+i24Ih2z+s/Zr6o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LzygvwhD+jk8H6oHSZsA8K6uguxfDYbyW2CPEziSd8933NLkE+bHxNb7moIB2uxun 6KSDW0RM9gWuuHONxateHdCWqjziCn0ZKc0ejbn5DTAj/JT1RMRMHWy6Axcyjft5RD VMJ4qaVx0ZHBEtEvNRPakkAW/VcmpZGdFRRgPHZrLje/GrtDlOFq6sQbd1qhIKN8yI KnLp6oIHD92aAfdJ0QNZRz8uZEjapxtpD0AMxHUwnfKstr0FWYbgTHaie1y3tsR1xZ r0nS8dz5V/G4fsV+dqIdfOhOOc5UW36wgZxeLtGrINtvA8Zm2GGwPT+7dFRZhlphF0 W3rXDgQh6di4g== From: Mario Limonciello To: Shyam Sundar S K , "Rafael J . Wysocki" , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , "Luke D . Jones" , Mark Pearson Cc: platform-driver-x86@vger.kernel.org (open list:AMD PMF DRIVER), linux-kernel@vger.kernel.org (open list), linux-acpi@vger.kernel.org (open list:ACPI), "Derek J . Clark" , Antheas Kapenekakis , me@kylegospodneti.ch, Denis Benato , Mario Limonciello Subject: [RFC 1/2] ACPI: Add support for a 'custom' profile Date: Wed, 25 Sep 2024 21:59:54 -0500 Message-ID: <20240926025955.1728766-2-superm1@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240926025955.1728766-1-superm1@kernel.org> References: <20240926025955.1728766-1-superm1@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Mario Limonciello Introduce a new profile type called 'custom' that can be set to allow changing settings outside of the standard profile settings. The idea behind this is to enforce a state machine so that a user can't set 'balanced' then manually change one APU setting and confuse userspace because the system is no longer really behaving in balanced. In practice the intention is that userspace would first set "custom" followed by modifying any settings. If userspace wants to go back to one of the predefined profiles then those profiles can be written to /sys/firmware/acpi/platform_profile. Signed-off-by: Mario Limonciello --- Documentation/ABI/testing/sysfs-platform_profile | 1 + drivers/acpi/platform_profile.c | 1 + include/linux/platform_profile.h | 1 + 3 files changed, 3 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-platform_profile b/Documentati= on/ABI/testing/sysfs-platform_profile index baf1d125f9f8..13dfe8aadbe2 100644 --- a/Documentation/ABI/testing/sysfs-platform_profile +++ b/Documentation/ABI/testing/sysfs-platform_profile @@ -15,6 +15,7 @@ Description: This file contains a space-separated list of= profiles supported for power consumption with a slight bias towards performance performance High performance operation + custom Custom profile tuned by the user =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 Userspace may expect drivers to offer more than one of these diff --git a/drivers/acpi/platform_profile.c b/drivers/acpi/platform_profil= e.c index d2f7fd7743a1..383f87c8c036 100644 --- a/drivers/acpi/platform_profile.c +++ b/drivers/acpi/platform_profile.c @@ -19,6 +19,7 @@ static const char * const profile_names[] =3D { [PLATFORM_PROFILE_BALANCED] =3D "balanced", [PLATFORM_PROFILE_BALANCED_PERFORMANCE] =3D "balanced-performance", [PLATFORM_PROFILE_PERFORMANCE] =3D "performance", + [PLATFORM_PROFILE_CUSTOM] =3D "custom", }; static_assert(ARRAY_SIZE(profile_names) =3D=3D PLATFORM_PROFILE_LAST); =20 diff --git a/include/linux/platform_profile.h b/include/linux/platform_prof= ile.h index f5492ed413f3..61273b615419 100644 --- a/include/linux/platform_profile.h +++ b/include/linux/platform_profile.h @@ -23,6 +23,7 @@ enum platform_profile_option { PLATFORM_PROFILE_BALANCED, PLATFORM_PROFILE_BALANCED_PERFORMANCE, PLATFORM_PROFILE_PERFORMANCE, + PLATFORM_PROFILE_CUSTOM, PLATFORM_PROFILE_LAST, /*must always be last */ }; =20 --=20 2.43.0 From nobody Fri Nov 29 00:57:18 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 629F2185935; Thu, 26 Sep 2024 03:00:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727319609; cv=none; b=GRmCBXd8bqn13P5eVDrR4IVDzFQiOcTQpVYiUJCr/nKJUS7djonVwZBZJg+LKALNQe1UxR96aXUfE+AhA7bpq7klftobbnaunfHwtsRRjKBsRzF5MIV5a1B4yUHb93ags5KhmieEtnOqPcluoB/E7LQzt0dmaaIhjVuVK7lwdhs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727319609; c=relaxed/simple; bh=76u71rRNZF7OhwZgnbtAuqloFp7f92CXMWJRA3n6qmo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rMTw/TE8b7609/ztU0GA8HtVkqJ9ppSMOAQ0OX5uxevu2y/w0R+353JAyVAvNPW6w7I6n2eiL8huqBQ2bLR6OauMpUJQBYo7FoeIRGPJew1vP3IGKajLKXCZ9b6Eg1oy7Cq4KvvEm9IZvhYgCWilpOQ+JjLz3vsnPPvRDOX0hPI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LIZMkgbf; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LIZMkgbf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D970CC4CEC3; Thu, 26 Sep 2024 03:00:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727319609; bh=76u71rRNZF7OhwZgnbtAuqloFp7f92CXMWJRA3n6qmo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LIZMkgbfTc5T58oBBADwsmWnxcvfTXZ7ltwbKUoQELjg+KPhKqxIC5BJhDUWYQxAN Xe1ioH5eo57G3VPzoemBUxdMup0J21tbKRiyDf3MrBGV4W6P4GMKzVtb7iuWOBtEky s48va1I1UjABIfwY6EZMU3mDEcGbHLC8FiNorViryKaS7hF78/hvz21lRQTiZzVhUV zIGHQGX6Ao4ea6CLouTyEXIFSV24gbXWjSIoukh0wDFTKNHk56yrhS9+PKQd5v621l 9glVwosXRpX3yY0PAUmSY2BjTf+oYbO1Zq+22Zpv3nM7Hjwtek//zZd5PdZXj7l8qY fsUlGIoOVb4Pw== From: Mario Limonciello To: Shyam Sundar S K , "Rafael J . Wysocki" , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , "Luke D . Jones" , Mark Pearson Cc: platform-driver-x86@vger.kernel.org (open list:AMD PMF DRIVER), linux-kernel@vger.kernel.org (open list), linux-acpi@vger.kernel.org (open list:ACPI), "Derek J . Clark" , Antheas Kapenekakis , me@kylegospodneti.ch, Denis Benato , Mario Limonciello Subject: [RFC 2/2] platform/x86/amd: pmf: Add manual control support Date: Wed, 25 Sep 2024 21:59:55 -0500 Message-ID: <20240926025955.1728766-3-superm1@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240926025955.1728766-1-superm1@kernel.org> References: <20240926025955.1728766-1-superm1@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Mario Limonciello A number of users resort to using reverse engineered software like ryzenadj to manipulate debugging interfaces for modifying APU settings. At a glance these tools are useful, but the problem is they break state machines in other software such as the PMF driver or the OEM EC. Offer a knob for PMF to allow 'manual control' which will users can directly change things like fPPT and sPPT. As this can be harmful for a system to try to push limits outside of a thermal design, taint the kernel and show a critical message when in use. Signed-off-by: Mario Limonciello --- Documentation/ABI/testing/sysfs-amd-pmf | 10 +++ drivers/platform/x86/amd/pmf/Makefile | 1 + drivers/platform/x86/amd/pmf/core.c | 9 +++ drivers/platform/x86/amd/pmf/manual.c | 88 +++++++++++++++++++++++++ drivers/platform/x86/amd/pmf/pmf.h | 5 ++ drivers/platform/x86/amd/pmf/sps.c | 4 ++ 6 files changed, 117 insertions(+) create mode 100644 drivers/platform/x86/amd/pmf/manual.c diff --git a/Documentation/ABI/testing/sysfs-amd-pmf b/Documentation/ABI/te= sting/sysfs-amd-pmf index 7fc0e1c2b76b..6f3d5cbf443f 100644 --- a/Documentation/ABI/testing/sysfs-amd-pmf +++ b/Documentation/ABI/testing/sysfs-amd-pmf @@ -11,3 +11,13 @@ Description: Reading this file tells if the AMD Platform= Management(PMF) To turn off CnQF user can write "off" to the sysfs node. Note: Systems that support auto mode will not have this sysfs file available. + +What: /sys/devices/platform/*/{spl, fppt, sppt, sppt_apu_only, stt_min, s= tt_limit_apu, stt_skip_temp} +Date: December 2024 +Contact: Mario Limonciello +Description: Manual control of AMD PMF APU coefficients + . + These files are used to manually control the APU coefficients. + In order to write to these files the module most be + loaded with manual_control=3D1 and the user must write "custom" + to the ACPI platform profile. diff --git a/drivers/platform/x86/amd/pmf/Makefile b/drivers/platform/x86/a= md/pmf/Makefile index 7d6079b02589..81444d6f4428 100644 --- a/drivers/platform/x86/amd/pmf/Makefile +++ b/drivers/platform/x86/amd/pmf/Makefile @@ -7,4 +7,5 @@ obj-$(CONFIG_AMD_PMF) +=3D amd-pmf.o amd-pmf-objs :=3D core.o acpi.o sps.o \ auto-mode.o cnqf.o \ + manual.o \ tee-if.o spc.o pmf-quirks.o diff --git a/drivers/platform/x86/amd/pmf/core.c b/drivers/platform/x86/amd= /pmf/core.c index d6af0ca036f1..52a68ca094be 100644 --- a/drivers/platform/x86/amd/pmf/core.c +++ b/drivers/platform/x86/amd/pmf/core.c @@ -53,6 +53,10 @@ static bool force_load; module_param(force_load, bool, 0444); MODULE_PARM_DESC(force_load, "Force load this driver on supported older pl= atforms (experimental)"); =20 +bool pmf_manual_control; +module_param_named(manual_control, pmf_manual_control, bool, 0444); +MODULE_PARM_DESC(manual_control, "Expose manual control knobs (experimenta= l)"); + static int amd_pmf_pwr_src_notify_call(struct notifier_block *nb, unsigned= long event, void *data) { struct amd_pmf_dev *pmf =3D container_of(nb, struct amd_pmf_dev, pwr_src_= notifier); @@ -349,6 +353,10 @@ static void amd_pmf_init_features(struct amd_pmf_dev *= dev) dev_dbg(dev->dev, "SPS enabled and Platform Profiles registered\n"); } =20 + if (pmf_manual_control) { + amd_pmf_init_manual_control(dev); + return; + } amd_pmf_init_smart_pc(dev); if (dev->smart_pc_enabled) { dev_dbg(dev->dev, "Smart PC Solution Enabled\n"); @@ -485,6 +493,7 @@ static void amd_pmf_remove(struct platform_device *pdev) =20 static const struct attribute_group *amd_pmf_driver_groups[] =3D { &cnqf_feature_attribute_group, + &manual_attribute_group, NULL, }; =20 diff --git a/drivers/platform/x86/amd/pmf/manual.c b/drivers/platform/x86/a= md/pmf/manual.c new file mode 100644 index 000000000000..b33fc3cd8d61 --- /dev/null +++ b/drivers/platform/x86/amd/pmf/manual.c @@ -0,0 +1,88 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * AMD Platform Management Framework Driver + * + * Copyright (c) 2024, Advanced Micro Devices, Inc. + * All Rights Reserved. + * + * Author: Mario Limonciello + */ + +#include "pmf.h" + +#define pmf_manual_attribute(_name, _set_command, _get_command) \ +static ssize_t _name##_store(struct device *d, \ + struct device_attribute *attr, \ + const char *buf, size_t count) \ +{ \ + struct amd_pmf_dev *dev =3D dev_get_drvdata(d); \ + uint val; \ + \ + if (dev->current_profile !=3D PLATFORM_PROFILE_CUSTOM) { \ + dev_warn_once(dev->dev, \ + "Manual control is disabled, please set " \ + "platform profile to custom.\n"); \ + return -EINVAL; \ + } \ + \ + if (kstrtouint(buf, 10, &val) < 0) \ + return -EINVAL; \ + \ + amd_pmf_send_cmd(dev, _set_command, false, val, NULL); \ + \ + return count; \ +} \ +static ssize_t _name##_show(struct device *d, \ + struct device_attribute *attr, \ + char *buf) \ +{ \ + struct amd_pmf_dev *dev =3D dev_get_drvdata(d); \ + uint val; \ + \ + amd_pmf_send_cmd(dev, _get_command, true, ARG_NONE, &val); \ + \ + return sysfs_emit(buf, "%u\n", val); \ +} + +pmf_manual_attribute(spl, SET_SPL, GET_SPL); +static DEVICE_ATTR_RW(spl); +pmf_manual_attribute(fppt, SET_FPPT, GET_FPPT); +static DEVICE_ATTR_RW(fppt); +pmf_manual_attribute(sppt, SET_SPPT, GET_SPPT); +static DEVICE_ATTR_RW(sppt); +pmf_manual_attribute(sppt_apu_only, SET_SPPT_APU_ONLY, GET_SPPT_APU_ONLY); +static DEVICE_ATTR_RW(sppt_apu_only); +pmf_manual_attribute(stt_min, SET_STT_MIN_LIMIT, GET_STT_MIN_LIMIT); +static DEVICE_ATTR_RW(stt_min); +pmf_manual_attribute(stt_limit_apu, SET_STT_LIMIT_APU, GET_STT_LIMIT_APU); +static DEVICE_ATTR_RW(stt_limit_apu); +pmf_manual_attribute(stt_skin_temp, SET_STT_LIMIT_HS2, GET_STT_LIMIT_HS2); +static DEVICE_ATTR_RW(stt_skin_temp); + +static umode_t manual_attr_is_visible(struct kobject *kobj, struct attribu= te *attr, int idx) +{ + return pmf_manual_control ? 0660 : 0; +} + +static struct attribute *manual_attrs[] =3D { + &dev_attr_spl.attr, + &dev_attr_fppt.attr, + &dev_attr_sppt.attr, + &dev_attr_sppt_apu_only.attr, + &dev_attr_stt_min.attr, + &dev_attr_stt_limit_apu.attr, + &dev_attr_stt_skin_temp.attr, + NULL, +}; + +const struct attribute_group manual_attribute_group =3D { + .attrs =3D manual_attrs, + .is_visible =3D manual_attr_is_visible, +}; + +void amd_pmf_init_manual_control(struct amd_pmf_dev *dev) +{ + add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_STILL_OK); + pr_crit("Manual PMF control is enabled, please disable it before " + "reporting any bugs unrelated to PMF.\n"); +} diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/= pmf/pmf.h index 8ce8816da9c1..ca3df63cf190 100644 --- a/drivers/platform/x86/amd/pmf/pmf.h +++ b/drivers/platform/x86/amd/pmf/pmf.h @@ -798,4 +798,9 @@ void amd_pmf_dump_ta_inputs(struct amd_pmf_dev *dev, st= ruct ta_pmf_enact_table * /* Quirk infrastructure */ void amd_pmf_quirks_init(struct amd_pmf_dev *dev); =20 +/* Manual configuration */ +extern bool pmf_manual_control; +extern const struct attribute_group manual_attribute_group; +void amd_pmf_init_manual_control(struct amd_pmf_dev *dev); + #endif /* PMF_H */ diff --git a/drivers/platform/x86/amd/pmf/sps.c b/drivers/platform/x86/amd/= pmf/sps.c index 92f7fb22277d..6db88e523a86 100644 --- a/drivers/platform/x86/amd/pmf/sps.c +++ b/drivers/platform/x86/amd/pmf/sps.c @@ -305,6 +305,8 @@ int amd_pmf_get_pprof_modes(struct amd_pmf_dev *pmf) case PLATFORM_PROFILE_LOW_POWER: mode =3D POWER_MODE_POWER_SAVER; break; + case PLATFORM_PROFILE_CUSTOM: + return 0; default: dev_err(pmf->dev, "Unknown Platform Profile.\n"); return -EOPNOTSUPP; @@ -412,6 +414,8 @@ int amd_pmf_init_sps(struct amd_pmf_dev *dev) set_bit(PLATFORM_PROFILE_LOW_POWER, dev->pprof.choices); set_bit(PLATFORM_PROFILE_BALANCED, dev->pprof.choices); set_bit(PLATFORM_PROFILE_PERFORMANCE, dev->pprof.choices); + if (pmf_manual_control) + set_bit(PLATFORM_PROFILE_CUSTOM, dev->pprof.choices); =20 /* Create platform_profile structure and register */ err =3D platform_profile_register(&dev->pprof); --=20 2.43.0