ACPI/ADXL: Added function for ADXL DSM Function 3
PATCH 1/1 ACPI/ADXL: Added function for ADXL DSM Function 3
Current driver supports only Function Index 1 & 2 as mentioned in the ACPI ADXL DSM Interface. Added a function for ACPI Function Index 3.
--- drivers/acpi/acpi_adxl.c | 54 +++++++++++++++++++++++++++++++++++++++- include/linux/adxl.h | 1 + 2 files changed, 54 insertions(+), 1 deletion(-)
drivers/acpi/acpi_adxl.c +53 -1
@@ -14,6 +14,7 @@#define ADXL_REVISION 0x1#define ADXL_IDX_GET_ADDR_PARAMS 0x1#define ADXL_IDX_FORWARD_TRANSLATE 0x2 +#define ADXL_IDX_REVERSE_TRANSLATE 0X3#define ACPI_ADXL_PATH "\\_SB.ADXL"/*
@@ -135,6 +136,56 @@ int adxl_decode(u64 addr, u64 component_values[]) }EXPORT_SYMBOL_GPL (adxl_decode); +/** +* adxl_reverse_decode - Ask BIOS to decode a memory address to system address +* @component_values: pointer to array of values for each component +* Returns 0 on success, negative error code otherwise +* +*/ + +int adxl_reverse_decode (u64 component_values[]) +{ +union acpi_object *argv4, *results, *r; +int i, cnt; + + argv4 =kzalloc ((adxl_count+1 )*sizeof (*argv4),GFP_KERNEL ); +if (!argv4) +return -ENOMEM ; + +if (!adxl_component_names) +return -EOPNOTSUPP ; + + argv4[0 ].type =ACPI_TYPE_PACKAGE ; + argv4[0 ].package.count = adxl_count; + argv4[0 ].package.elements = &argv4[1 ]; + +/* +* Loop through supported memory component values +*/ +for (i =1 ; i <= adxl_count; i++) { + argv4[i].integer.type =ACPI_TYPE_INTEGER ; + argv4[i].integer.value = component_values[i-1 ]; + } + + results =adxl_dsm (ADXL_IDX_REVERSE_TRANSLATE , argv4); +if (!results) +return -EINVAL ; + + r = results->package.elements +1 ; + cnt = r->package.count; +if (cnt != adxl_count) { +ACPI_FREE (results); +return -EINVAL ; + } + r = r->package.elements; +for (i =0 ; i < cnt; i++) + component_values[i] = r[i].integer.value; + +ACPI_FREE (results); +return 0 ; +} +EXPORT_SYMBOL_GPL (adxl_reverse_decode); +static int __init adxl_init (void ) {char *path =ACPI_ADXL_PATH ;
@@ -155,7 +206,8 @@ static int __init adxl_init(void)if (!acpi_check_dsm (handle, &adxl_guid,ADXL_REVISION ,ADXL_IDX_GET_ADDR_PARAMS | -ADXL_IDX_FORWARD_TRANSLATE )) { +ADXL_IDX_FORWARD_TRANSLATE | +ADXL_IDX_REVERSE_TRANSLATE )) {pr_info ("DSM method does not support forward translate\n" );return -ENODEV ; }
include/linux/adxl.h +1 -0
@@ -9,5 +9,6 @@const char *const *adxl_get_component_names (void );int adxl_decode (u64 addr,u64 component_values[]); +int adxl_reverse_decode (u64 component_values[]);#endif /* _LINUX_ADXL_H */
Signature · 1 line
2.34.1
Rafael J. Wysocki
maintainerQuoted 3 lines · Rithvik Rama
Current driver supports only Function Index 1 & 2 as mentioned in the ACPI ADXL DSM Interface. Added a function for ACPI Function Index 3.
What's happened that it has become useful now?
Who's going to use it and for what purpose?
Quoted 19 lines
Signed-off-by Rithvik Rama <[email protected]>--- drivers/acpi/acpi_adxl.c | 54 +++++++++++++++++++++++++++++++++++++++- include/linux/adxl.h | 1 + 2 files changed, 54 insertions(+), 1 deletion(-)drivers/acpi/acpi_adxl.c +1
-0@@ -14,6 +14,7 @@#define ADXL_REVISION 0x1#define ADXL_IDX_GET_ADDR_PARAMS 0x1#define ADXL_IDX_FORWARD_TRANSLATE 0x2 +#define ADXL_IDX_REVERSE_TRANSLATE 0X3#define ACPI_ADXL_PATH "\\_SB.ADXL"/*
drivers/acpi/acpi_adxl.c int adxl_decode(u64 addr, u64 component_values[]) · line 143
Quoted 8 lines
drivers/acpi/acpi_adxl.c +5
-0@@ -135,6 +136,56 @@ int adxl_decode(u64 addr, u64 component_values[]) }EXPORT_SYMBOL_GPL (adxl_decode); +/** +* adxl_reverse_decode - Ask BIOS to decode a memory address to system address +* @component_values: pointer to array of values for each component +* Returns 0 on success, negative error code otherwise +*
Redundant line.
drivers/acpi/acpi_adxl.c int adxl_decode(u64 addr, u64 component_values[]) · line 151
Quoted 8 lines
drivers/acpi/acpi_adxl.c +8
-0+*/ + +int adxl_reverse_decode (u64 component_values[]) +{ +union acpi_object *argv4, *results, *r; +int i, cnt; + + argv4 =kzalloc ((adxl_count+1 )*sizeof (*argv4),GFP_KERNEL );
kcalloc()?
drivers/acpi/acpi_adxl.c int adxl_decode(u64 addr, u64 component_values[]) · line 156
Quoted 5 lines
drivers/acpi/acpi_adxl.c +5
-0+if (!argv4) +return -ENOMEM ; + +if (!adxl_component_names) +return -EOPNOTSUPP ;
This could be checked before allocating memory which is now leaked if it is NULL.
This function generally leaks the argv4 memory AFAICS.
Quoted 21 lines
drivers/acpi/acpi_adxl.c +21
-0+ + argv4[0 ].type =ACPI_TYPE_PACKAGE ; + argv4[0 ].package.count = adxl_count; + argv4[0 ].package.elements = &argv4[1 ]; + +/* +* Loop through supported memory component values +*/ +for (i =1 ; i <= adxl_count; i++) { + argv4[i].integer.type =ACPI_TYPE_INTEGER ; + argv4[i].integer.value = component_values[i-1 ]; + } + + results =adxl_dsm (ADXL_IDX_REVERSE_TRANSLATE , argv4); +if (!results) +return -EINVAL ; + + r = results->package.elements +1 ; + cnt = r->package.count; +if (cnt != adxl_count) { +ACPI_FREE (results);
drivers/acpi/acpi_adxl.c int adxl_decode(u64 addr, u64 component_values[]) · line 187
Quoted 10 lines
drivers/acpi/acpi_adxl.c +10
-0+return -EINVAL ; + } + r = r->package.elements; +for (i =0 ; i < cnt; i++) + component_values[i] = r[i].integer.value; + +ACPI_FREE (results); +return 0 ; +} +EXPORT_SYMBOL_GPL (adxl_reverse_decode);
No users of this are being added.
For this to be applicable, you need to also submit a patch adding a caller of adxl_reverse_decode().
Quoted 26 lines
drivers/acpi/acpi_adxl.c +3
-1+static int __init adxl_init (void ) {char *path =ACPI_ADXL_PATH ;@@ -155,7 +206,8 @@ static int __init adxl_init(void)if (!acpi_check_dsm (handle, &adxl_guid,ADXL_REVISION ,ADXL_IDX_GET_ADDR_PARAMS | -ADXL_IDX_FORWARD_TRANSLATE )) { +ADXL_IDX_FORWARD_TRANSLATE | +ADXL_IDX_REVERSE_TRANSLATE )) {pr_info ("DSM method does not support forward translate\n" );return -ENODEV ; }include/linux/adxl.h +1
-1@@ -9,5 +9,6 @@const char *const *adxl_get_component_names (void );int adxl_decode (u64 addr,u64 component_values[]); +int adxl_reverse_decode (u64 component_values[]);#endif /* _LINUX_ADXL_H */ --