Skip to content

Commit 5eb315e

Browse files
Shyam Sundar S Kjwrdegoede
authored andcommitted
platform/x86/amd/pmf: Add support for PMF APCI layer
PMF driver implements the ACPI methods as defined by AMD for PMF Support. The ACPI layer acts as a glue that helps in providing the infrastructure for OEMs customization. OEMs can refer to PMF support documentation to decide on the list of functions to be supported on their specific platform model. AMD mandates that PMF ACPI fn0 and fn1 to be implemented which provides the set of functions, params and the notifications that would be sent to PMF driver so that PMF driver can adapt and react. Signed-off-by: Shyam Sundar S K <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Hans de Goede <[email protected]> Signed-off-by: Hans de Goede <[email protected]>
1 parent da5ce22 commit 5eb315e

File tree

4 files changed

+176
-1
lines changed

4 files changed

+176
-1
lines changed

drivers/platform/x86/amd/pmf/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
#
66

77
obj-$(CONFIG_AMD_PMF) += amd-pmf.o
8-
amd-pmf-objs := core.o
8+
amd-pmf-objs := core.o acpi.o
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* AMD Platform Management Framework Driver
4+
*
5+
* Copyright (c) 2022, Advanced Micro Devices, Inc.
6+
* All Rights Reserved.
7+
*
8+
* Author: Shyam Sundar S K <[email protected]>
9+
*/
10+
11+
#include <linux/acpi.h>
12+
#include "pmf.h"
13+
14+
static union acpi_object *apmf_if_call(struct amd_pmf_dev *pdev, int fn, struct acpi_buffer *param)
15+
{
16+
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
17+
acpi_handle ahandle = ACPI_HANDLE(pdev->dev);
18+
struct acpi_object_list apmf_if_arg_list;
19+
union acpi_object apmf_if_args[2];
20+
acpi_status status;
21+
22+
apmf_if_arg_list.count = 2;
23+
apmf_if_arg_list.pointer = &apmf_if_args[0];
24+
25+
apmf_if_args[0].type = ACPI_TYPE_INTEGER;
26+
apmf_if_args[0].integer.value = fn;
27+
28+
if (param) {
29+
apmf_if_args[1].type = ACPI_TYPE_BUFFER;
30+
apmf_if_args[1].buffer.length = param->length;
31+
apmf_if_args[1].buffer.pointer = param->pointer;
32+
} else {
33+
apmf_if_args[1].type = ACPI_TYPE_INTEGER;
34+
apmf_if_args[1].integer.value = 0;
35+
}
36+
37+
status = acpi_evaluate_object(ahandle, "APMF", &apmf_if_arg_list, &buffer);
38+
if (ACPI_FAILURE(status)) {
39+
dev_err(pdev->dev, "APMF method:%d call failed\n", fn);
40+
kfree(buffer.pointer);
41+
return NULL;
42+
}
43+
44+
return buffer.pointer;
45+
}
46+
47+
static int apmf_if_call_store_buffer(struct amd_pmf_dev *pdev, int fn, void *dest, size_t out_sz)
48+
{
49+
union acpi_object *info;
50+
size_t size;
51+
int err = 0;
52+
53+
info = apmf_if_call(pdev, fn, NULL);
54+
if (!info)
55+
return -EIO;
56+
57+
if (info->type != ACPI_TYPE_BUFFER) {
58+
dev_err(pdev->dev, "object is not a buffer\n");
59+
err = -EINVAL;
60+
goto out;
61+
}
62+
63+
if (info->buffer.length < 2) {
64+
dev_err(pdev->dev, "buffer too small\n");
65+
err = -EINVAL;
66+
goto out;
67+
}
68+
69+
size = *(u16 *)info->buffer.pointer;
70+
if (info->buffer.length < size) {
71+
dev_err(pdev->dev, "buffer smaller then headersize %u < %zu\n",
72+
info->buffer.length, size);
73+
err = -EINVAL;
74+
goto out;
75+
}
76+
77+
if (size < out_sz) {
78+
dev_err(pdev->dev, "buffer too small %zu\n", size);
79+
err = -EINVAL;
80+
goto out;
81+
}
82+
83+
memcpy(dest, info->buffer.pointer, out_sz);
84+
85+
out:
86+
kfree(info);
87+
return err;
88+
}
89+
90+
int is_apmf_func_supported(struct amd_pmf_dev *pdev, unsigned long index)
91+
{
92+
/* If bit-n is set, that indicates function n+1 is supported */
93+
return !!(pdev->supported_func & BIT(index - 1));
94+
}
95+
96+
static int apmf_if_verify_interface(struct amd_pmf_dev *pdev)
97+
{
98+
struct apmf_verify_interface output;
99+
int err;
100+
101+
err = apmf_if_call_store_buffer(pdev, APMF_FUNC_VERIFY_INTERFACE, &output, sizeof(output));
102+
if (err)
103+
return err;
104+
105+
pdev->supported_func = output.supported_functions;
106+
dev_dbg(pdev->dev, "supported functions:0x%x notifications:0x%x\n",
107+
output.supported_functions, output.notification_mask);
108+
109+
return 0;
110+
}
111+
112+
static int apmf_get_system_params(struct amd_pmf_dev *dev)
113+
{
114+
struct apmf_system_params params;
115+
int err;
116+
117+
if (!is_apmf_func_supported(dev, APMF_FUNC_GET_SYS_PARAMS))
118+
return -EINVAL;
119+
120+
err = apmf_if_call_store_buffer(dev, APMF_FUNC_GET_SYS_PARAMS, &params, sizeof(params));
121+
if (err)
122+
return err;
123+
124+
dev_dbg(dev->dev, "system params mask:0x%x flags:0x%x cmd_code:0x%x\n",
125+
params.valid_mask,
126+
params.flags,
127+
params.command_code);
128+
params.flags = params.flags & params.valid_mask;
129+
130+
return 0;
131+
}
132+
133+
int apmf_acpi_init(struct amd_pmf_dev *pmf_dev)
134+
{
135+
int ret;
136+
137+
ret = apmf_if_verify_interface(pmf_dev);
138+
if (ret) {
139+
dev_err(pmf_dev->dev, "APMF verify interface failed :%d\n", ret);
140+
goto out;
141+
}
142+
143+
ret = apmf_get_system_params(pmf_dev);
144+
if (ret) {
145+
dev_err(pmf_dev->dev, "APMF apmf_get_system_params failed :%d\n", ret);
146+
goto out;
147+
}
148+
149+
out:
150+
return ret;
151+
}

drivers/platform/x86/amd/pmf/core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ static int amd_pmf_probe(struct platform_device *pdev)
204204
if (!dev->regbase)
205205
return -ENOMEM;
206206

207+
apmf_acpi_init(dev);
207208
platform_set_drvdata(pdev, dev);
208209

209210
mutex_init(&dev->lock);

drivers/platform/x86/amd/pmf/pmf.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
#ifndef PMF_H
1212
#define PMF_H
1313

14+
#include <linux/acpi.h>
15+
16+
/* APMF Functions */
17+
#define APMF_FUNC_VERIFY_INTERFACE 0
18+
#define APMF_FUNC_GET_SYS_PARAMS 1
19+
1420
/* Message Definitions */
1521
#define SET_SPL 0x03 /* SPL: Sustained Power Limit */
1622
#define SET_SPPT 0x05 /* SPPT: Slow Package Power Tracking */
@@ -30,6 +36,21 @@
3036
#define GET_STT_LIMIT_APU 0x20
3137
#define GET_STT_LIMIT_HS2 0x21
3238

39+
/* AMD PMF BIOS interfaces */
40+
struct apmf_verify_interface {
41+
u16 size;
42+
u16 version;
43+
u32 notification_mask;
44+
u32 supported_functions;
45+
} __packed;
46+
47+
struct apmf_system_params {
48+
u16 size;
49+
u32 valid_mask;
50+
u32 flags;
51+
u8 command_code;
52+
} __packed;
53+
3354
struct amd_pmf_dev {
3455
void __iomem *regbase;
3556
void __iomem *smu_virt_addr;
@@ -38,9 +59,11 @@ struct amd_pmf_dev {
3859
u32 cpu_id;
3960
struct device *dev;
4061
struct mutex lock; /* protects the PMF interface */
62+
u32 supported_func;
4163
};
4264

4365
/* Core Layer */
66+
int apmf_acpi_init(struct amd_pmf_dev *pmf_dev);
4467
int amd_pmf_send_cmd(struct amd_pmf_dev *dev, u8 message, bool get, u32 arg, u32 *data);
4568

4669
#endif /* PMF_H */

0 commit comments

Comments
 (0)