thermal: intel: int340x_thermal: New IOCTLs for thermal
PATCH 1/1 thermal: intel: int340x_thermal: New IOCTLs for thermal
Export Passive version 2 table similar to the way _TRT and _ART tables via IOCTLs.
This removes need for binary utility to read ACPI Passive 2 table by providing open source support. This table already has open source implementation in the user space thermald, when the table is part of data vault exported by the int3400 sysfs.
This table is supported in some older platforms before Ice Lake generation.
Passive 2 tables contain multiple entries. Each entry has following fields:
Source: Named Reference (String). This is the source device for temperature.
Target: Named Reference (String). This is the target device to control.
Priority: Priority of this device compared to others.
SamplingPeriod: Time Period in 1/10 of seconds unit.
PassiveTemp: Passive Temperature in 1/10 of Kelvin.
SourceDomain: Domain for the source (00:Processor, others reserved).
ControlKnob: Type of control knob (00:Power Limit 1, others: reserved)
Limit: The target state to set on reaching passive temperature. This can be a string "max", "min" or a power limit value.
LimitStepSize: Step size during activation.
UnLimitStepSize: Step size during deactivation.
Reserved1: Reserved
Four IOCTLs are added similar to IOCTLs for reading TRT:
ACPI_THERMAL_GET_PSVT_COUNT: Number of passive 2 entries.ACPI_THERMAL_GET_PSVT_LEN: Total return data size (count x each passive 2 entry size).ACPI_THERMAL_GET_PSVT: Get the data as an array of objects with passive 2 entries.
This change is based on original development done by:
Todd Brandt <[email protected]>
--- .../intel/int340x_thermal/acpi_thermal_rel.c | 218 ++++++++++++++++++ .../intel/int340x_thermal/acpi_thermal_rel.h | 57 +++++ 2 files changed, 275 insertions(+)
drivers/thermal/intel/int340x_thermal/acpi_thermal_rel.c +218 -0
@@ -203,6 +203,151 @@ int acpi_parse_art(acpi_handle handle, int *art_count, struct art **artp, }EXPORT_SYMBOL (acpi_parse_art); +/* +* acpi_parse_psvt - Passive Table (PSVT) for passive cooling +* +* @handle: ACPI handle of the device which contains PSVT +* @psvt_count: the number of valid entries resulted from parsing PSVT +* @psvtp: pointer to array of psvt entries +* +*/ +int acpi_parse_psvt (acpi_handle handle,int *psvt_count,struct psvt **psvtp) +{ +struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL }; +int nr_bad_entries =0 , revision; +union acpi_object *p; +acpi_status status; +int i, result =0 ; +struct psvt *psvts; + +if (!acpi_has_method (handle,"PSVT" )) +return -ENODEV ; + + status =acpi_evaluate_object (handle,"PSVT" ,NULL , &buffer); +if (ACPI_FAILURE (status)) +return -ENODEV ; + + p = buffer.pointer; +if (!p || (p->type !=ACPI_TYPE_PACKAGE )) { + result = -EFAULT ; + goto end; + } + +/* first package is the revision number */ +if (p->package.count >0 ) { +union acpi_object *prev = &(p->package.elements[0 ]); + +if (prev->type ==ACPI_TYPE_INTEGER ) + revision = (int )prev->integer.value; + }else { + result = -EFAULT ; + goto end; + } + +/* Support only version 2 */ +if (revision !=2 ) { + result = -EFAULT ; + goto end; + } + + *psvt_count = p->package.count -1 ; +if (!*psvt_count) { + result = -EFAULT ; + goto end; + } + + psvts =kcalloc (*psvt_count,sizeof (*psvts),GFP_KERNEL ); +if (!psvts) { + result = -ENOMEM ; + goto end; + } + +/* Start index is 1 because the first package is the revision number */ +for (i =1 ; i < p->package.count; i++) { +struct acpi_buffer psvt_int_format = {sizeof ("RRNNNNNNNNNN" ),"RRNNNNNNNNNN" }; +struct acpi_buffer psvt_str_format = {sizeof ("RRNNNNNSNNNN" ),"RRNNNNNSNNNN" }; +union acpi_object *package = &(p->package.elements[i]); +struct psvt *psvt = &psvts[i -1 - nr_bad_entries]; +struct acpi_buffer *psvt_format = &psvt_int_format; +struct acpi_buffer element = {0 ,NULL }; +union acpi_object *knob; +struct acpi_device *res; +struct psvt *psvt_ptr; + + element.length =ACPI_ALLOCATE_BUFFER ; + element.pointer =NULL ; + +if (package->package.count >=ACPI_NR_PSVT_ELEMENTS ) { + knob = &(package->package.elements[ACPI_PSVT_CONTROL_KNOB ]); + }else { + nr_bad_entries++; +pr_info ("PSVT package %d is invalid, ignored\n" , i); +continue ; + } + +if (knob->type ==ACPI_TYPE_STRING ) { + psvt_format = &psvt_str_format; +if (knob->string.length >ACPI_LIMIT_STR_MAX_LEN ) { +pr_info ("PSVT package %d limit string len exceeds max\n" , i); + knob->string.length =ACPI_LIMIT_STR_MAX_LEN ; + } + } + + status =acpi_extract_package (&(p->package.elements[i]), psvt_format, &element); +if (ACPI_FAILURE (status)) { + nr_bad_entries++; +pr_info ("PSVT package %d is invalid, ignored\n" , i); +continue ; + } + + psvt_ptr = (struct psvt *)element.pointer; + +memcpy (psvt, psvt_ptr,sizeof (*psvt_ptr)); + +/* The limit element can be string or U64 */ + psvt->control_knob_type = (u64 )knob->type; + +if (knob->type ==ACPI_TYPE_STRING ) { +memset (&psvt->limit,0 ,sizeof (u64)); +strncpy (psvt->limit.string, psvt_ptr->limit.str_ptr, knob->string.length); + }else { + psvt->limit.integer = psvt_ptr->limit.integer; + } + +kfree (element.pointer); + + res =acpi_fetch_acpi_dev (psvt->source); +if (!res) { + nr_bad_entries++; +pr_info ("Failed to get source ACPI device\n" ); +continue ; + } + + res =acpi_fetch_acpi_dev (psvt->target); +if (!res) { + nr_bad_entries++; +pr_info ("Failed to get target ACPI device\n" ); +continue ; + } + } + +/* don't count bad entries */ + *psvt_count -= nr_bad_entries; + +if (!*psvt_count) { + result = -EFAULT ; +kfree (psvts); + goto end; + } + + *psvtp = psvts; + +return 0 ; + +end: +kfree (buffer.pointer); +return result; +}/* get device name from acpi handle */ static void get_single_name (acpi_handle handle,char *name)
@@ -289,6 +434,57 @@ static int fill_trt(char __user *ubuf)return ret; } +static int fill_psvt (char __user *ubuf) +{ +int i, ret, count, psvt_len; +union psvt_object *psvt_user; +struct psvt *psvts; + + ret =acpi_parse_psvt (acpi_thermal_rel_handle, &count, &psvts); +if (ret) +return ret; + + psvt_len = count *sizeof (*psvt_user); + + psvt_user =kzalloc (psvt_len,GFP_KERNEL ); +if (!psvt_user) { + ret = -ENOMEM ; + goto free_psvt; + } + +/* now fill in user psvt data */ +for (i =0 ; i < count; i++) { +/* userspace psvt needs device name instead of acpi reference */ +get_single_name (psvts[i].source, psvt_user[i].source_device); +get_single_name (psvts[i].target, psvt_user[i].target_device); + + psvt_user[i].priority = psvts[i].priority; + psvt_user[i].sample_period = psvts[i].sample_period; + psvt_user[i].passive_temp = psvts[i].passive_temp; + psvt_user[i].source_domain = psvts[i].source_domain; + psvt_user[i].control_knob = psvts[i].control_knob; + psvt_user[i].step_size = psvts[i].step_size; + psvt_user[i].limit_coeff = psvts[i].limit_coeff; + psvt_user[i].unlimit_coeff = psvts[i].unlimit_coeff; + psvt_user[i].control_knob_type = psvts[i].control_knob_type; +if (psvt_user[i].control_knob_type ==ACPI_TYPE_STRING ) +strncpy (psvt_user[i].limit.string, psvts[i].limit.string, +ACPI_LIMIT_STR_MAX_LEN ); +else + psvt_user[i].limit.integer = psvts[i].limit.integer; + + } + +if (copy_to_user (ubuf, psvt_user, psvt_len)) + ret = -EFAULT ; + +kfree (psvt_user); + +free_psvt: +kfree (psvts); +return ret; +} +static long acpi_thermal_rel_ioctl (struct file *f,unsigned int cmd,unsigned long __arg) {
@@ -298,6 +494,7 @@ static long acpi_thermal_rel_ioctl(struct file *f, unsigned int cmd,char __user *arg = (void __user *)__arg;struct trt *trts =NULL ;struct art *arts =NULL ; +struct psvt *psvts;switch (cmd) {case ACPI_THERMAL_GET_TRT_COUNT :
@@ -336,6 +533,27 @@ static long acpi_thermal_rel_ioctl(struct file *f, unsigned int cmd,case ACPI_THERMAL_GET_ART :return fill_art (arg); +case ACPI_THERMAL_GET_PSVT_COUNT : + ret =acpi_parse_psvt (acpi_thermal_rel_handle, &count, &psvts); +if (!ret) { +kfree (psvts); +return put_user (count, (unsigned long __user *)__arg); + } +return ret; + +case ACPI_THERMAL_GET_PSVT_LEN : +/* total length of the data retrieved (count * PSVT entry size) */ + ret =acpi_parse_psvt (acpi_thermal_rel_handle, &count, &psvts); + length = count *sizeof (union psvt_object ); +if (!ret) { +kfree (psvts); +return put_user (length, (unsigned long __user *)__arg); + } +return ret; + +case ACPI_THERMAL_GET_PSVT : +return fill_psvt (arg); +default :return -ENOTTY ; }
drivers/thermal/intel/int340x_thermal/acpi_thermal_rel.h +57 -0
75 lines not on this page · raw message
Signature · 1 line
2.34.1
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): ec67f5a343dbcdfd337eb192c178dc4578819b29.1432082423.git.todd.e.brandt@linux.intel.com
Re: [PATCH 2/2] simple python script for testing PSVT table
Sent by mistake please ignore.
Thanks,
Srinivas
Quoted 187 lines · Srinivas Pandruvada
From: Todd Brandt <[email protected]>
Added a simple python script for testing the thermal tables.
ACPI Thermal Table Test
Usage:therm-table-test.py<options>
Description:
Python script for quick testing of thermal table availablity Options:
-h Print this help text
-art Test the ART table
-trt Test the TRT table
-psvt Test the PSVT table
(none) Test all tablesSigned-off-by Todd Brandt <[email protected]>---
scripts/acpi-thermal-rel-test.py | 148
+++++++++++++++++++++++++++++++++++++++1 file changed, 148 insertions(+)create mode 100644
scripts/acpi-thermal-rel-test.pyscripts/acpi-thermal- renamed from scripts/acpi-thermal-rel-test.py +0
-0
rel-test.py
new file mode 100644
index 0000000..9a82777scripts/acpi-thermal-rel-test.py new file +70
-0@@ -0,0 +1,148 @@ +#!/usr/bin/python + +import sys +import os +from fcntl import ioctl +import array +import struct + +def i(x): + return x - 2**32 + +ACPI_THERMAL_GET_TRT_LEN = i(0x80087301) +ACPI_THERMAL_GET_ART_LEN = i(0x80087302) +ACPI_THERMAL_GET_TRT_COUNT = i(0x80087303) +ACPI_THERMAL_GET_ART_COUNT = i(0x80087304) +ACPI_THERMAL_GET_TRT = i(0x80087305) +ACPI_THERMAL_GET_ART = i(0x80087306) +ACPI_THERMAL_GET_PSVT_REV = i(0x80087307) +ACPI_THERMAL_GET_PSVT_LEN = i(0x80087308) +ACPI_THERMAL_GET_PSVT_COUNT = i(0x80087309) +ACPI_THERMAL_GET_PSVT = i(0x8008730a) + +def toInt(buf): + return struct.unpack('Q', buf)[0] + +def toStr(buf): + return buf.tostring() + +def testART(): + f = os.open('/dev/acpi_thermal_rel', os.O_RDWR) + buf = array.array('h', [0]) + ioctl(f, ACPI_THERMAL_GET_ART_COUNT, buf) + count = buf[0] + print('ACPI_THERMAL_GET_ART_COUNT = %d' % count) + buf = array.array('h', [0]) + ioctl(f, ACPI_THERMAL_GET_ART_LEN, buf) + length = buf[0] + print('ACPI_THERMAL_GET_ART_LEN = %d' % length) + buf = array.array('c', '\0'*length) + ioctl(f, ACPI_THERMAL_GET_ART, buf) + print('ACPI_THERMAL_GET_ART') + plen = length/count + for i in range(count): + package = buf[(i*plen):((i+1)*plen)] + print(' package %d' % i) + print(' source: %s' % toStr(package[0:8])) + print(' target: %s' % toStr(package[8:16])) + print(' weight: %d' % toInt(package[16:24])) + +def testTRT(): + f = os.open('/dev/acpi_thermal_rel', os.O_RDWR) + buf = array.array('h', [0]) + ioctl(f, ACPI_THERMAL_GET_TRT_COUNT, buf) + count = buf[0] + print('ACPI_THERMAL_GET_TRT_COUNT = %d' % count) + buf = array.array('h', [0]) + ioctl(f, ACPI_THERMAL_GET_TRT_LEN, buf) + length = buf[0] + print('ACPI_THERMAL_GET_TRT_LEN = %d' % length) + buf = array.array('c', '\0'*length) + ioctl(f, ACPI_THERMAL_GET_TRT, buf) + print('ACPI_THERMAL_GET_TRT') + plen = length/count + for i in range(count): + package = buf[(i*plen):((i+1)*plen)] + print(' package %d' % i) + print(' source: %s' % toStr(package[0:8])) + print(' target: %s' % toStr(package[8:16])) + print(' influence: %d' % toInt(package[16:24])) + print(' sample_period: %d' %
toInt(package[24:32]))scripts/acpi-thermal-rel-test.py new file +27
-0+ +def testPSVT(): + f = os.open('/dev/acpi_thermal_rel', os.O_RDWR) + buf = array.array('h', [0]) + ioctl(f, ACPI_THERMAL_GET_PSVT_REV, buf) + rev = buf[0] + print('ACPI_THERMAL_GET_PSVT_REV = %d' % rev) + buf = array.array('h', [0]) + ioctl(f, ACPI_THERMAL_GET_PSVT_COUNT, buf) + count = buf[0] + print('ACPI_THERMAL_GET_PSVT_COUNT = %d' % count) + buf = array.array('h', [0]) + ioctl(f, ACPI_THERMAL_GET_PSVT_LEN, buf) + length = buf[0] + print('ACPI_THERMAL_GET_PSVT_LEN = %d' % length) + buf = array.array('c', '\0'*length) + ioctl(f, ACPI_THERMAL_GET_PSVT, buf) + print('ACPI_THERMAL_GET_PSVT') + plen = length/count + for i in range(count): + package = buf[(i*plen):((i+1)*plen)] + knobtype = toInt(package[88:96]) + print(' package %d' % i) + print(' source: %s' % toStr(package[0:8])) + print(' target: %s' % toStr(package[8:16])) + print(' priority: %d' % toInt(package[16:24])) + print(' sample_period: %d' %
toInt(package[24:32]))
+ print('target_domain: %d' %toInt(package[32:40]))
+ print('passive_temp: %d' %toInt(package[40:48])) + print('source_domain: %d' %toInt(package[48:56]))
+ if(knobtype == 2):
+ print('control_knob: %s' %toStr(package[56:64]))
+ else:
+ print('control_knob: %d' %toInt(package[56:64]))
+ print(' limit: %d' %toInt(package[64:72])) + print('limit_step_size: %d' %toInt(package[72:80]))
+ print('unlimit_step_size: %d' %toInt(package[80:88]))scripts/acpi-thermal-rel-test.py new file +6
-0+ +def printHelp(): + print('ACPI Thermal Table Test') + print('Usage: therm-table-test.py <options>') + print('Description:') + print(' Python script for quick testing of thermal tableavailablity')
+ print('Options:')
+ print(' -h Print this help text')
+ print(' -art Test the ART table')
+ print(' -trt Test the TRT table')
+ print(' -psvt Test the PSVT table')
+ print(' (none) Test all tables')scripts/acpi-thermal-rel-test.py new file +20
-0+ +if __name__ == '__main__': + tests = {'art':False, 'trt':False, 'psvt':False} + args = iter(sys.argv[1:]) + for arg in args: + if(arg == '-h'): + printHelp() + sys.exit() + elif(arg == '-art'): + tests['art'] = True + elif(arg == '-trt'): + tests['trt'] = True + elif(arg == '-psvt'): + tests['psvt'] = True + else: + printHelp() + print('Invalid argument: %s' % arg) + sys.exit() + + if not tests['art'] and not tests['trt'] and nottests['psvt']:
+ for i in tests:
+ tests[i] = True
+
+ if tests['art']:
+ testART()
+ if tests['trt']:
+ testTRT()
+ if tests['psvt']:
+ testPSVT()
A message that is not in the archive (sent off-list or not yet received): a3773670b3317d5a784d915759865cddaf8a0900.1432082423.git.todd.e.brandt@linux.intel.com
Re: [PATCH v2 1/2] ACPI PSVT table addition to acpi_thermal_rel
Sent by mistake. Please ignore.
Thanks,
Srinivas
Quoted 380 lines · Srinivas Pandruvada
From: Todd Brandt <[email protected]>
Added PSVT table to
acpi_thermal_reldriver. Its exported to userspace
via an ioctl to theacpi_thermal_reldevice. The PSVT table consists of 12 fields:source: B0D4
target: SEN3
priority: 2
sample_period: 300
target_domain: 3032
passive_temp: 9
source_domain: 65536
control_knob: 12000
limit: 500
limit_step_size: 10
unlimit_step_size: 20
control_knob_type: 1=int, 2=stringThe
control_knob_typefield was added since the control knob value can be either a string or integer. The field is necessary for userspace to know how to read its value. The ACPI spec calls for a reserved field at the end, so I just borrowed the space for the new val.Signed-off-by Todd Brandt <[email protected]>---
drivers/thermal/int340x_thermal/acpi_thermal_rel.c | 188
+++++++++++++++++++++
drivers/thermal/int340x_thermal/acpi_thermal_rel.h | 55 ++++++2 files changed, 243 insertions(+)drivers/thermal/int340x_thermal/acpi_thermal_rel.c +0
-0@@ -221,6 +221,128 @@ end: } EXPORT_SYMBOL(acpi_parse_art);
+/*
+ *acpi_parse_psvt- Passive Table PSVT for passive cooling
+ *
+ * @handle: ACPI handle of the device contains PSVT
+ * @psvt_revision: the revision number of the PSVT, used to interpret limit
+ * @psvt_count: the number of valid entries resulted from parsing PSVT
+ * @psvtp: pointer to array of psvt entries in parsing result
+ * @create_dev: whether to create platform devices for target and source
+ *
+ */
+int acpi_parse_psvt(acpi_handle handle, int*psvt_revision, int*psvt_count,
+ struct psvt **psvtp, boolcreate_dev)
+{
+ acpi_status status;
+ int result = 0;
+ int i;
+ intnr_bad_entries= 0;
+ struct psvt *psvts;
+ structacpi_device*adev;
+ unionacpi_object*p;
+ structacpi_bufferbuffer = {ACPI_ALLOCATE_BUFFER, NULL }; + structacpi_bufferelement = { 0, NULL };
+ structacpi_bufferpsvt_int_format= {sizeof("RRNNNNNNNNNN"), "RRNNNNNNNNNN" };
+ structacpi_bufferpsvt_str_format= {sizeof("RRNNNNNSNNNN"), "RRNNNNNSNNNN" };drivers/thermal/int340x_thermal/acpi_thermal_rel.c +28
-0+ + if (!acpi_has_method(handle, "PSVT")) + return -ENODEV; + + status = acpi_evaluate_object(handle, "PSVT", NULL, &buffer); + if (ACPI_FAILURE(status)) + return -ENODEV; + + p = buffer.pointer; + if (!p || (p->type != ACPI_TYPE_PACKAGE)) { + pr_err("Invalid PSVT data\n"); + result = -EFAULT; + goto end; + } + + /* first package is the revision number */ + if(p->package.count > 0) { + union acpi_object *prev = &(p->package.elements[0]); + if(prev->type == ACPI_TYPE_INTEGER) + *psvt_revision = (int)prev->integer.value; + } else { + pr_err("Invalid PSVT data\n"); + result = -EFAULT; + goto end; + } + + *psvt_count = p->package.count - 1; + psvts = kzalloc(*psvt_count * sizeof(struct psvt),
GFP_KERNEL);
+ if (!psvts) {
+ result =-ENOMEM;
+ goto end;
+ }
+
+ for (i = 1; i <p->package.count; i++) {
+ struct psvt *psvt = &psvts[i - 1 -nr_bad_entries]; + struct psvt*psvt_ptr;
+ structacpi_buffer*psvt_format=&psvt_int_format; + unionacpi_object*package = &(p-Quoted 1 line
package.elements[i]);
+ union
acpi_object*knob;drivers/thermal/int340x_thermal/acpi_thermal_rel.c +6
-0+ + element.length = ACPI_ALLOCATE_BUFFER; + element.pointer = NULL; + + if(package->package.count >= ACPI_NR_PSVT_ELEMENTS) { + knob = &(package-Quoted 1 line
package.elements[ACPI_PSVT_CONTROL_KNOB]);
+ } else {
+ nr_bad_entries++;
+ pr_warn("PSVT package %d is invalid, ignored\n", i);
+ continue;
+ }
+
+ if(knob->type ==ACPI_TYPE_STRING) {
+ psvt_format =&psvt_str_format; + if(knob->string.length > 8) {
+ pr_warn("PSVT package %d ctrlknob string len > 8\n", i);
+ knob->string.length = 8; + }
+ }
+ status = acpi_extract_package(&(p-Quoted 1 line
package.elements[i]),
+
psvt_format, &element); + if (ACPI_FAILURE(status)) {
+ nr_bad_entries++;
+ pr_warn("PSVT package %d is invalid, ignored\n", i);
+ continue;
+ }
+
+ psvt_ptr = (struct psvt *)element.pointer; + memcpy(psvt,psvt_ptr, sizeof(struct psvt)); + psvt->control_knob_type = (u64)knob->type; + if(knob->type ==ACPI_TYPE_STRING) {
+ char *val = psvt_ptr-Quoted 1 line
control_knob.string_ptr;
+ memset(&psvt->control_knob, 0, sizeof(u64)); + memcpy(&psvt->control_knob, val, knob-
Quoted 1 line
string.length*sizeof(char));
+ }
+ kfree(element.pointer);drivers/thermal/int340x_thermal/acpi_thermal_rel.c +7
-0+ + if (!create_dev) + continue; + + result = acpi_bus_get_device(psvt->source, &adev); + if (result) + pr_warn("Failed to get source ACPIdevice\n");
+
+ result =acpi_bus_get_device(psvt->target, &adev); + if (result)
+ pr_warn("Failed to get target ACPI device\n");
+ }drivers/thermal/int340x_thermal/acpi_thermal_rel.c +11
-0+ + result = 0; + + *psvtp = psvts; + /* don't count bad entries */ + *psvt_count -= nr_bad_entries; +end: + kfree(buffer.pointer); + return result; +} +EXPORT_SYMBOL (acpi_parse_psvt);
/* get device name from acpi handle */
static voidget_single_name(acpi_handle handle, char *name)drivers/thermal/int340x_thermal/acpi_thermal_rel.c +0
-0@@ -306,15 +428,55 @@ free_trt: return ret; }drivers/thermal/int340x_thermal/acpi_thermal_rel.c +23
-0+static int fill_psvt (char __user *ubuf) +{ + int i; + int ret; + int count; + int revision = 0; + int psvt_len; + struct psvt *psvts = NULL; + union psvt_object *psvt_user; + + ret = acpi_parse_psvt(acpi_thermal_rel_handle, &revision, + &count, &psvts, false); + if (ret) + goto free_psvt; + psvt_len = count * sizeof(union psvt_object); + psvt_user = kzalloc(psvt_len, GFP_KERNEL); + if (!psvt_user) { + ret = -ENOMEM; + goto free_psvt; + } + /* now fill in user psvt data */ + for (i = 0; i < count; i++) { + /* userspace psvt needs device name instead of acpireference */
+ get_single_name(psvts[i].source, psvt_user[i].source_device);
+ get_single_name(psvts[i].target, psvt_user[i].target_device);
+ /* copy the rest int data in addition to source and target */
+ memcpy(&psvt_user[i].priority, &psvts[i].priority, + sizeof(u64) * (ACPI_NR_PSVT_ELEMENTS- 2)); + }drivers/thermal/int340x_thermal/acpi_thermal_rel.c +9
-0+ + if (copy_to_user(ubuf, psvt_user, psvt_len)) + ret = -EFAULT; + kfree(psvt_user); +free_psvt: + kfree(psvts); + return ret; +} +static long
acpi_thermal_rel_ioctl(struct file *f, unsigned int cmd, unsigned long __arg)
{
int ret = 0;
unsigned long length = 0;
+ int revision = 0;
int count = 0;
char__user*arg = (void__user*)__arg;
struct trt *trts = NULL;
struct art *arts = NULL;
+ struct psvt *psvts = NULL;
switch (cmd) {
caseACPI_THERMAL_GET_TRT_COUNT:drivers/thermal/int340x_thermal/acpi_thermal_rel.c +0
-0@@ -353,6 +515,32 @@ static long acpi_thermal_rel_ioctl(struct file *f, unsigned int cmd,case
ACPI_THERMAL_GET_ART:
returnfill_art(arg);
+ caseACPI_THERMAL_GET_PSVT_REV:
+ ret = acpi_parse_psvt(acpi_thermal_rel_handle, &revision, &count,
+ &psvts, false);
+ kfree(psvts);
+ if (!ret)
+ returnput_user(revision, (unsigned long __user *)__arg);
+ return ret;
+ caseACPI_THERMAL_GET_PSVT_COUNT:
+ ret = acpi_parse_psvt(acpi_thermal_rel_handle, &revision, &count,
+ &psvts, false);
+ kfree(psvts);
+ if (!ret)
+ returnput_user(count, (unsigned long __user *)__arg);
+ return ret;
+ caseACPI_THERMAL_GET_PSVT_LEN:
+ /* total length of the data retrieved (count * PSVT entry size) */
+ ret = acpi_parse_psvt(acpi_thermal_rel_handle, &revision, &count,
+ &psvts, false);
+ kfree(psvts);
+ length = count *sizeof(union psvt_object); + if (!ret)
+ returnput_user(length, (unsigned long __user *)__arg);
+ return ret;
+ caseACPI_THERMAL_GET_PSVT:
+ returnfill_psvt(arg);
+
default:
return-ENOTTY;
}drivers/thermal/int340x_thermal/acpi_thermal_rel.h +0
-0@@ -13,6 +13,18 @@ #define ACPI_THERMAL_GET_TRT _IOR(ACPI_THERMAL_MAGIC, 5, unsigned long) #define ACPI_THERMAL_GET_ART _IOR(ACPI_THERMAL_MAGIC, 6, unsigned long)
+/*
+ *ACPI_THERMAL_GET_PSVT_REV= revision number
+ * identifies limit type: 1=true porportional limit, 2=depth limit
+ *ACPI_THERMAL_GET_PSVT_COUNT= number of package entries
+ *ACPI_THERMAL_GET_PSVT_LEN= total return data size (pkg count x pkg size)
+ *ACPI_THERMAL_GET_PSVT= get the data as an array ofpsvt_objects
+ */
+#defineACPI_THERMAL_GET_PSVT_REV_IOR(ACPI_THERMAL_MAGIC, 7, unsigned long)
+#defineACPI_THERMAL_GET_PSVT_LEN_IOR(ACPI_THERMAL_MAGIC, 8, unsigned long)
+#defineACPI_THERMAL_GET_PSVT_COUNT_IOR(ACPI_THERMAL_MAGIC, 9, unsigned long)
+#define ACPI_THERMAL_GET_PSVT _IOR(ACPI_THERMAL_MAGIC, 10, unsigned long)
+
struct art {
acpi_handle source;
acpi_handle target;drivers/thermal/int340x_thermal/acpi_thermal_rel.h +0
-0@@ -40,6 +52,28 @@ struct trt { u64 reverved4; } __packed;drivers/thermal/int340x_thermal/acpi_thermal_rel.h +12
-0+#define ACPI_NR_PSVT_ELEMENTS 12 +#define ACPI_PSVT_CONTROL_KNOB 7 +struct psvt { + acpi_handle source; + acpi_handle target; + u64 priority; + u64 sample_period; + u64 target_domain; + u64 passive_temp; + u64 source_domain; + union { + u64 integer; /* control_knob_type =
ACPI_TYPE_INTEGER*/
+ char string[8]; /*control_knob_type=ACPI_TYPE_STRING*/
+ char*string_ptr;
+ }control_knob;
+ u64 limit;
+ u64limit_step_size;
+ u64unlimit_step_size;
+ /* ACPI spec calls this field reserved, so we borrow it for type info */
+ u64control_knob_type; /*ACPI_TYPE_STRINGorACPI_TYPE_INTEGER*/drivers/thermal/int340x_thermal/acpi_thermal_rel.h +2
-0+} __packed; +#define
ACPI_NR_ART_ELEMENTS13
/* for usrspace */
unionart_object{drivers/thermal/int340x_thermal/acpi_thermal_rel.h +0
-0@@ -72,6 +106,27 @@ union trt_object { u64 __data[8]; };
+unionpsvt_object{
+ struct {
+ char source_device[8]; /* ACPI single name */ + char target_device[8]; /* ACPI single name */ + u64 priority;
+ u64sample_period;
+ u64target_domain;
+ u64passive_temp;
+ u64source_domain;
+ union {
+ u64 integer; /*control_knob_type=ACPI_TYPE_INTEGER*/
+ char string[8]; /*control_knob_type=ACPI_TYPE_STRING*/
+ }control_knob;
+ u64 limit;
+ u64limit_step_size;
+ u64unlimit_step_size;
+ u64control_knob_type; /*ACPI_TYPE_STRINGorACPI_TYPE_INTEGER*/
+ };
+ u64 __data[ACPI_NR_PSVT_ELEMENTS];drivers/thermal/int340x_thermal/acpi_thermal_rel.h +2
-0+}; +#ifdef
__KERNEL__
intacpi_thermal_rel_misc_device_add(acpi_handle handle); intacpi_thermal_rel_misc_device_remove(acpi_handle handle);
Re: [PATCH 0/2] ACPI PSVT table exported to userspace
In reply to a message not in the archiveSent by mistake. Please ignore.
Thanks,
Srinivas
Quoted 22 lines · Srinivas Pandruvada
From: Todd Brandt <[email protected]>
I've completed an update to the
acpi_thermal_reldriver which provides the PSVT table to userspace. It includes a python test script for testing and to help explain how to use it. I've tested it on my Broadwell system and it seems to work well.Todd Brandt (2):
Added PSVT table toacpi_thermal_reldriver. Its exported to userspace
via an ioctl to theacpi_thermal_reldevice. The PSVT table consists of 12 fields:
Added a simple python script for testing the thermal tables.drivers/thermal/int340x_thermal/acpi_thermal_rel.c | 188
+++++++++++++++++++++
drivers/thermal/int340x_thermal/acpi_thermal_rel.h | 55 ++++++ scripts/acpi-thermal-rel-test.py | 148
++++++++++++++++3 files changed, 391 insertions(+)create mode 100644
scripts/acpi-thermal-rel-test.py