Skip to content

Commit 332ed4e

Browse files
spandruvadarafaeljw
authored andcommitted
thermal: intel: int340x: Capability to map user space to firmware values
To ensure compatibility between user inputs and firmware requirements, a conversion mechanism is necessary for certain attributes. For instance, on some platforms, the DLVR frequency must be translated into a predefined index before being communicated to the firmware. On Lunar Lake platform: RFI_FREQ_SELECT and RFI_FREQ: Index 0 corresponds to a DLVR frequency of 2227.2 MHz Index 1 corresponds to a DLVR frequency of 2140 MHz Introduce a feature that enables the conversion of values between user space inputs and firmware-accepted formats. This feature would also facilitate the reverse process, converting firmware values back into user friendly display values. To support this functionality, a model-specific mapping table will be utilized. When available, this table will provide the necessary translations between user space values and firmware values, ensuring seamless communication and accurate settings. Signed-off-by: Srinivas Pandruvada <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 822b2a7 commit 332ed4e

File tree

1 file changed

+76
-4
lines changed

1 file changed

+76
-4
lines changed

drivers/thermal/intel/int340x_thermal/processor_thermal_rfim.c

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ struct mmio_reg {
1919
u16 shift;
2020
};
2121

22+
struct mapping_table {
23+
const char *attr_name;
24+
const u32 value;
25+
const char *mapped_str;
26+
};
27+
2228
/* These will represent sysfs attribute names */
2329
static const char * const fivr_strings[] = {
2430
"vco_ref_code_lo",
@@ -62,6 +68,59 @@ static const struct mmio_reg dlvr_mmio_regs[] = {
6268
{ 1, 0x15A10, 1, 0x1, 16}, /* dlvr_pll_busy */
6369
};
6470

71+
static int match_mapping_table(const struct mapping_table *table, const char *attr_name,
72+
bool match_int_value, const u32 value, const char *value_str,
73+
char **result_str, u32 *result_int)
74+
{
75+
bool attr_matched = false;
76+
int i = 0;
77+
78+
if (!table)
79+
return -EOPNOTSUPP;
80+
81+
while (table[i].attr_name) {
82+
if (strncmp(table[i].attr_name, attr_name, strlen(attr_name)))
83+
goto match_next;
84+
85+
attr_matched = true;
86+
87+
if (match_int_value) {
88+
if (table[i].value != value)
89+
goto match_next;
90+
91+
*result_str = (char *)table[i].mapped_str;
92+
return 0;
93+
}
94+
95+
if (strncmp(table[i].mapped_str, value_str, strlen(table[i].mapped_str)))
96+
goto match_next;
97+
98+
*result_int = table[i].value;
99+
100+
return 0;
101+
match_next:
102+
i++;
103+
}
104+
105+
/* If attribute name is matched, then the user space value is invalid */
106+
if (attr_matched)
107+
return -EINVAL;
108+
109+
return -EOPNOTSUPP;
110+
}
111+
112+
static int get_mapped_string(const struct mapping_table *table, const char *attr_name,
113+
u32 value, char **result)
114+
{
115+
return match_mapping_table(table, attr_name, true, value, NULL, result, NULL);
116+
}
117+
118+
static int get_mapped_value(const struct mapping_table *table, const char *attr_name,
119+
const char *value, unsigned int *result)
120+
{
121+
return match_mapping_table(table, attr_name, false, 0, value, NULL, result);
122+
}
123+
65124
/* These will represent sysfs attribute names */
66125
static const char * const dvfs_strings[] = {
67126
"rfi_restriction_run_busy",
@@ -93,12 +152,14 @@ static ssize_t suffix##_show(struct device *dev,\
93152
struct device_attribute *attr,\
94153
char *buf)\
95154
{\
155+
const struct mapping_table *mapping = NULL;\
96156
struct proc_thermal_device *proc_priv;\
97157
struct pci_dev *pdev = to_pci_dev(dev);\
98158
const struct mmio_reg *mmio_regs;\
99159
const char **match_strs;\
160+
int ret, err;\
100161
u32 reg_val;\
101-
int ret;\
162+
char *str;\
102163
\
103164
proc_priv = pci_get_drvdata(pdev);\
104165
if (table == 1) {\
@@ -116,14 +177,20 @@ static ssize_t suffix##_show(struct device *dev,\
116177
return ret;\
117178
reg_val = readl((void __iomem *) (proc_priv->mmio_base + mmio_regs[ret].offset));\
118179
ret = (reg_val >> mmio_regs[ret].shift) & mmio_regs[ret].mask;\
119-
return sprintf(buf, "%u\n", ret);\
180+
err = get_mapped_string(mapping, attr->attr.name, ret, &str);\
181+
if (!err)\
182+
return sprintf(buf, "%s\n", str);\
183+
if (err == -EOPNOTSUPP)\
184+
return sprintf(buf, "%u\n", ret);\
185+
return err;\
120186
}
121187

122188
#define RFIM_STORE(suffix, table)\
123189
static ssize_t suffix##_store(struct device *dev,\
124190
struct device_attribute *attr,\
125191
const char *buf, size_t count)\
126192
{\
193+
const struct mapping_table *mapping = NULL;\
127194
struct proc_thermal_device *proc_priv;\
128195
struct pci_dev *pdev = to_pci_dev(dev);\
129196
unsigned int input;\
@@ -150,9 +217,14 @@ static ssize_t suffix##_store(struct device *dev,\
150217
return ret;\
151218
if (mmio_regs[ret].read_only)\
152219
return -EPERM;\
153-
err = kstrtouint(buf, 10, &input);\
154-
if (err)\
220+
err = get_mapped_value(mapping, attr->attr.name, buf, &input);\
221+
if (err == -EINVAL)\
155222
return err;\
223+
if (err == -EOPNOTSUPP) {\
224+
err = kstrtouint(buf, 10, &input);\
225+
if (err)\
226+
return err;\
227+
} \
156228
mask = GENMASK(mmio_regs[ret].shift + mmio_regs[ret].bits - 1, mmio_regs[ret].shift);\
157229
reg_val = readl((void __iomem *) (proc_priv->mmio_base + mmio_regs[ret].offset));\
158230
reg_val &= ~mask;\

0 commit comments

Comments
 (0)