1 // SPDX-License-Identifier: GPL-2.0-only
3 * processor thermal device for Workload type hints
4 * update from user space
6 * Copyright (c) 2020-2023, Intel Corporation.
10 #include "processor_thermal_device.h"
12 /* List of workload types */
13 static const char * const workload_types
[] = {
23 static ssize_t
workload_available_types_show(struct device
*dev
,
24 struct device_attribute
*attr
,
30 while (workload_types
[i
] != NULL
)
31 ret
+= sprintf(&buf
[ret
], "%s ", workload_types
[i
++]);
33 ret
+= sprintf(&buf
[ret
], "\n");
38 static DEVICE_ATTR_RO(workload_available_types
);
40 static ssize_t
workload_type_store(struct device
*dev
,
41 struct device_attribute
*attr
,
42 const char *buf
, size_t count
)
44 struct pci_dev
*pdev
= to_pci_dev(dev
);
45 char str_preference
[15];
49 ret
= sscanf(buf
, "%14s", str_preference
);
53 ret
= match_string(workload_types
, -1, str_preference
);
60 data
= BIT(MBOX_DATA_BIT_VALID
) | BIT(MBOX_DATA_BIT_AC_DC
);
64 ret
= processor_thermal_send_mbox_write_cmd(pdev
, MBOX_CMD_WORKLOAD_TYPE_WRITE
, data
);
71 static ssize_t
workload_type_show(struct device
*dev
,
72 struct device_attribute
*attr
,
75 struct pci_dev
*pdev
= to_pci_dev(dev
);
79 ret
= processor_thermal_send_mbox_read_cmd(pdev
, MBOX_CMD_WORKLOAD_TYPE_READ
, &cmd_resp
);
85 if (cmd_resp
> ARRAY_SIZE(workload_types
) - 1)
88 return sprintf(buf
, "%s\n", workload_types
[cmd_resp
]);
91 static DEVICE_ATTR_RW(workload_type
);
93 static struct attribute
*workload_req_attrs
[] = {
94 &dev_attr_workload_available_types
.attr
,
95 &dev_attr_workload_type
.attr
,
99 static const struct attribute_group workload_req_attribute_group
= {
100 .attrs
= workload_req_attrs
,
101 .name
= "workload_request"
104 static bool workload_req_created
;
106 int proc_thermal_wt_req_add(struct pci_dev
*pdev
, struct proc_thermal_device
*proc_priv
)
111 /* Check if there is a mailbox support, if fails return success */
112 ret
= processor_thermal_send_mbox_read_cmd(pdev
, MBOX_CMD_WORKLOAD_TYPE_READ
, &cmd_resp
);
116 ret
= sysfs_create_group(&pdev
->dev
.kobj
, &workload_req_attribute_group
);
120 workload_req_created
= true;
124 EXPORT_SYMBOL_GPL(proc_thermal_wt_req_add
);
126 void proc_thermal_wt_req_remove(struct pci_dev
*pdev
)
128 if (workload_req_created
)
129 sysfs_remove_group(&pdev
->dev
.kobj
, &workload_req_attribute_group
);
131 workload_req_created
= false;
133 EXPORT_SYMBOL_GPL(proc_thermal_wt_req_remove
);
135 MODULE_IMPORT_NS("INT340X_THERMAL");
136 MODULE_LICENSE("GPL");
137 MODULE_DESCRIPTION("Processor Thermal Work Load type request Interface");