Commit 023a25b0 authored by Shyam Sundar S K's avatar Shyam Sundar S K Committed by Hans de Goede
Browse files

platform/x86/amd/pmf: Add support for notifying Smart PC Solution updates



The APMF function 14 (Notify Smart PC Solution Updates) allows the BIOS
(AMD/OEM) to be informed about the outputs of custom Smart PC policies.
Enhance the PMF driver to invoke APMF function 14 when these custom policy
outputs are triggered.

Co-developed-by: default avatarPatil Rajesh Reddy <Patil.Reddy@amd.com>
Signed-off-by: default avatarPatil Rajesh Reddy <Patil.Reddy@amd.com>
Signed-off-by: default avatarShyam Sundar S K <Shyam-sundar.S-k@amd.com>
Link: https://lore.kernel.org/r/20240812131839.308768-1-Shyam-sundar.S-k@amd.com


Reviewed-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
parent e35ee8ee
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -282,6 +282,29 @@ int apmf_update_fan_idx(struct amd_pmf_dev *pdev, bool manual, u32 idx)
	return 0;
}

static int apmf_notify_smart_pc_update(struct amd_pmf_dev *pdev, u32 val, u32 preq, u32 index)
{
	struct amd_pmf_notify_smart_pc_update args;
	struct acpi_buffer params;
	union acpi_object *info;

	args.size = sizeof(args);
	args.pending_req = preq;
	args.custom_bios[index] = val;

	params.length = sizeof(args);
	params.pointer = &args;

	info = apmf_if_call(pdev, APMF_FUNC_NOTIFY_SMART_PC_UPDATES, &params);
	if (!info)
		return -EIO;

	kfree(info);
	dev_dbg(pdev->dev, "Notify smart pc update, val: %u\n", val);

	return 0;
}

int apmf_get_auto_mode_def(struct amd_pmf_dev *pdev, struct apmf_auto_mode *data)
{
	return apmf_if_call_store_buffer(pdev, APMF_FUNC_AUTO_MODE, data, sizeof(*data));
@@ -447,6 +470,14 @@ int apmf_check_smart_pc(struct amd_pmf_dev *pmf_dev)
	return 0;
}

int amd_pmf_smartpc_apply_bios_output(struct amd_pmf_dev *dev, u32 val, u32 preq, u32 idx)
{
	if (!is_apmf_func_supported(dev, APMF_FUNC_NOTIFY_SMART_PC_UPDATES))
		return -EINVAL;

	return apmf_notify_smart_pc_update(dev, val, preq, idx);
}

void apmf_acpi_deinit(struct amd_pmf_dev *pmf_dev)
{
	acpi_handle ahandle = ACPI_HANDLE(pmf_dev->dev);
+18 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ struct cookie_header {
#define APMF_FUNC_STATIC_SLIDER_GRANULAR       9
#define APMF_FUNC_DYN_SLIDER_AC				11
#define APMF_FUNC_DYN_SLIDER_DC				12
#define APMF_FUNC_NOTIFY_SMART_PC_UPDATES		14
#define APMF_FUNC_SBIOS_HEARTBEAT_V2			16

/* Message Definitions */
@@ -82,7 +83,17 @@ struct cookie_header {
#define PMF_POLICY_STT_SKINTEMP_APU				7
#define PMF_POLICY_STT_SKINTEMP_HS2				8
#define PMF_POLICY_SYSTEM_STATE					9
#define PMF_POLICY_BIOS_OUTPUT_1				10
#define PMF_POLICY_BIOS_OUTPUT_2				11
#define PMF_POLICY_P3T						38
#define PMF_POLICY_BIOS_OUTPUT_3				57
#define PMF_POLICY_BIOS_OUTPUT_4				58
#define PMF_POLICY_BIOS_OUTPUT_5				59
#define PMF_POLICY_BIOS_OUTPUT_6				60
#define PMF_POLICY_BIOS_OUTPUT_7				61
#define PMF_POLICY_BIOS_OUTPUT_8				62
#define PMF_POLICY_BIOS_OUTPUT_9				63
#define PMF_POLICY_BIOS_OUTPUT_10				64

/* TA macros */
#define PMF_TA_IF_VERSION_MAJOR				1
@@ -344,6 +355,12 @@ struct os_power_slider {
	u8 slider_event;
} __packed;

struct amd_pmf_notify_smart_pc_update {
	u16 size;
	u32 pending_req;
	u32 custom_bios[10];
} __packed;

struct fan_table_control {
	bool manual;
	unsigned long fan_id;
@@ -717,6 +734,7 @@ extern const struct attribute_group cnqf_feature_attribute_group;
int amd_pmf_init_smart_pc(struct amd_pmf_dev *dev);
void amd_pmf_deinit_smart_pc(struct amd_pmf_dev *dev);
int apmf_check_smart_pc(struct amd_pmf_dev *pmf_dev);
int amd_pmf_smartpc_apply_bios_output(struct amd_pmf_dev *dev, u32 val, u32 preq, u32 idx);

/* Smart PC - TA interfaces */
void amd_pmf_populate_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_table *in);
+40 −0
Original line number Diff line number Diff line
@@ -160,6 +160,46 @@ static void amd_pmf_apply_policies(struct amd_pmf_dev *dev, struct ta_pmf_enact_
			dev_dbg(dev->dev, "update SYSTEM_STATE: %s\n",
				amd_pmf_uevent_as_str(val));
			break;

		case PMF_POLICY_BIOS_OUTPUT_1:
			amd_pmf_smartpc_apply_bios_output(dev, val, BIT(0), 0);
			break;

		case PMF_POLICY_BIOS_OUTPUT_2:
			amd_pmf_smartpc_apply_bios_output(dev, val, BIT(1), 1);
			break;

		case PMF_POLICY_BIOS_OUTPUT_3:
			amd_pmf_smartpc_apply_bios_output(dev, val, BIT(2), 2);
			break;

		case PMF_POLICY_BIOS_OUTPUT_4:
			amd_pmf_smartpc_apply_bios_output(dev, val, BIT(3), 3);
			break;

		case PMF_POLICY_BIOS_OUTPUT_5:
			amd_pmf_smartpc_apply_bios_output(dev, val, BIT(4), 4);
			break;

		case PMF_POLICY_BIOS_OUTPUT_6:
			amd_pmf_smartpc_apply_bios_output(dev, val, BIT(5), 5);
			break;

		case PMF_POLICY_BIOS_OUTPUT_7:
			amd_pmf_smartpc_apply_bios_output(dev, val, BIT(6), 6);
			break;

		case PMF_POLICY_BIOS_OUTPUT_8:
			amd_pmf_smartpc_apply_bios_output(dev, val, BIT(7), 7);
			break;

		case PMF_POLICY_BIOS_OUTPUT_9:
			amd_pmf_smartpc_apply_bios_output(dev, val, BIT(8), 8);
			break;

		case PMF_POLICY_BIOS_OUTPUT_10:
			amd_pmf_smartpc_apply_bios_output(dev, val, BIT(9), 9);
			break;
		}
	}
}