Skip to content

Commit f00571b

Browse files
committed
Merge branch 'acpi-utils'
Merge ACPI utility functions updates for 6.8-rc1: - Modify acpi_dev_uid_match() to support different types of its second argument and adjust its users accordingly (Raag Jadav). - Clean up code related to acpi_evaluate_reference() and ACPI device lists (Rafael J. Wysocki). * acpi-utils: ACPI: utils: Introduce helper for _DEP list lookup ACPI: utils: Fix white space in struct acpi_handle_list definition ACPI: utils: Refine acpi_handle_list_equal() slightly ACPI: utils: Return bool from acpi_evaluate_reference() ACPI: utils: Rearrange in acpi_evaluate_reference() perf: arm_cspmu: drop redundant acpi_dev_uid_to_integer() efi: dev-path-parser: use acpi_dev_uid_match() for matching _UID ACPI: LPSS: use acpi_dev_uid_match() for matching _UID ACPI: bus: update acpi_dev_hid_uid_match() to support multiple types ACPI: bus: update acpi_dev_uid_match() to support multiple types
2 parents 8be056a + d70d141 commit f00571b

File tree

9 files changed

+151
-202
lines changed

9 files changed

+151
-202
lines changed

drivers/acpi/acpi_lpss.c

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,9 @@ static struct pwm_lookup byt_pwm_lookup[] = {
167167

168168
static void byt_pwm_setup(struct lpss_private_data *pdata)
169169
{
170-
u64 uid;
171-
172170
/* Only call pwm_add_table for the first PWM controller */
173-
if (acpi_dev_uid_to_integer(pdata->adev, &uid) || uid != 1)
174-
return;
175-
176-
pwm_add_table(byt_pwm_lookup, ARRAY_SIZE(byt_pwm_lookup));
171+
if (acpi_dev_uid_match(pdata->adev, 1))
172+
pwm_add_table(byt_pwm_lookup, ARRAY_SIZE(byt_pwm_lookup));
177173
}
178174

179175
#define LPSS_I2C_ENABLE 0x6c
@@ -218,13 +214,9 @@ static struct pwm_lookup bsw_pwm_lookup[] = {
218214

219215
static void bsw_pwm_setup(struct lpss_private_data *pdata)
220216
{
221-
u64 uid;
222-
223217
/* Only call pwm_add_table for the first PWM controller */
224-
if (acpi_dev_uid_to_integer(pdata->adev, &uid) || uid != 1)
225-
return;
226-
227-
pwm_add_table(bsw_pwm_lookup, ARRAY_SIZE(bsw_pwm_lookup));
218+
if (acpi_dev_uid_match(pdata->adev, 1))
219+
pwm_add_table(bsw_pwm_lookup, ARRAY_SIZE(bsw_pwm_lookup));
228220
}
229221

230222
static const struct property_entry lpt_spi_properties[] = {
@@ -570,34 +562,6 @@ static struct device *acpi_lpss_find_device(const char *hid, const char *uid)
570562
return bus_find_device(&pci_bus_type, NULL, &data, match_hid_uid);
571563
}
572564

573-
static bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle)
574-
{
575-
struct acpi_handle_list dep_devices;
576-
acpi_status status;
577-
bool ret = false;
578-
int i;
579-
580-
if (!acpi_has_method(adev->handle, "_DEP"))
581-
return false;
582-
583-
status = acpi_evaluate_reference(adev->handle, "_DEP", NULL,
584-
&dep_devices);
585-
if (ACPI_FAILURE(status)) {
586-
dev_dbg(&adev->dev, "Failed to evaluate _DEP.\n");
587-
return false;
588-
}
589-
590-
for (i = 0; i < dep_devices.count; i++) {
591-
if (dep_devices.handles[i] == handle) {
592-
ret = true;
593-
break;
594-
}
595-
}
596-
597-
acpi_handle_list_free(&dep_devices);
598-
return ret;
599-
}
600-
601565
static void acpi_lpss_link_consumer(struct device *dev1,
602566
const struct lpss_device_links *link)
603567
{
@@ -608,7 +572,7 @@ static void acpi_lpss_link_consumer(struct device *dev1,
608572
return;
609573

610574
if ((link->dep_missing_ids && dmi_check_system(link->dep_missing_ids))
611-
|| acpi_lpss_dep(ACPI_COMPANION(dev2), ACPI_HANDLE(dev1)))
575+
|| acpi_device_dep(ACPI_HANDLE(dev2), ACPI_HANDLE(dev1)))
612576
device_link_add(dev2, dev1, link->flags);
613577

614578
put_device(dev2);
@@ -624,7 +588,7 @@ static void acpi_lpss_link_supplier(struct device *dev1,
624588
return;
625589

626590
if ((link->dep_missing_ids && dmi_check_system(link->dep_missing_ids))
627-
|| acpi_lpss_dep(ACPI_COMPANION(dev1), ACPI_HANDLE(dev2)))
591+
|| acpi_device_dep(ACPI_HANDLE(dev1), ACPI_HANDLE(dev2)))
628592
device_link_add(dev1, dev2, link->flags);
629593

630594
put_device(dev2);

drivers/acpi/scan.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,7 +1984,6 @@ static void acpi_scan_init_hotplug(struct acpi_device *adev)
19841984
static u32 acpi_scan_check_dep(acpi_handle handle)
19851985
{
19861986
struct acpi_handle_list dep_devices;
1987-
acpi_status status;
19881987
u32 count;
19891988
int i;
19901989

@@ -1997,8 +1996,7 @@ static u32 acpi_scan_check_dep(acpi_handle handle)
19971996
if (!acpi_has_method(handle, "_DEP") || !acpi_has_method(handle, "_HID"))
19981997
return 0;
19991998

2000-
status = acpi_evaluate_reference(handle, "_DEP", NULL, &dep_devices);
2001-
if (ACPI_FAILURE(status)) {
1999+
if (!acpi_evaluate_reference(handle, "_DEP", NULL, &dep_devices)) {
20022000
acpi_handle_debug(handle, "Failed to evaluate _DEP.\n");
20032001
return 0;
20042002
}
@@ -2007,6 +2005,7 @@ static u32 acpi_scan_check_dep(acpi_handle handle)
20072005
struct acpi_device_info *info;
20082006
struct acpi_dep_data *dep;
20092007
bool skip, honor_dep;
2008+
acpi_status status;
20102009

20112010
status = acpi_get_object_info(dep_devices.handles[i], &info);
20122011
if (ACPI_FAILURE(status)) {

drivers/acpi/thermal.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,16 +247,14 @@ static bool update_trip_devices(struct acpi_thermal *tz,
247247
{
248248
struct acpi_handle_list devices = { 0 };
249249
char method[] = "_PSL";
250-
acpi_status status;
251250

252251
if (index != ACPI_THERMAL_TRIP_PASSIVE) {
253252
method[1] = 'A';
254253
method[2] = 'L';
255254
method[3] = '0' + index;
256255
}
257256

258-
status = acpi_evaluate_reference(tz->device->handle, method, NULL, &devices);
259-
if (ACPI_FAILURE(status)) {
257+
if (!acpi_evaluate_reference(tz->device->handle, method, NULL, &devices)) {
260258
acpi_handle_info(tz->device->handle, "%s evaluation failure\n", method);
261259
return false;
262260
}

drivers/acpi/utils.c

Lines changed: 66 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -329,21 +329,18 @@ const char *acpi_get_subsystem_id(acpi_handle handle)
329329
}
330330
EXPORT_SYMBOL_GPL(acpi_get_subsystem_id);
331331

332-
acpi_status
333-
acpi_evaluate_reference(acpi_handle handle,
334-
acpi_string pathname,
335-
struct acpi_object_list *arguments,
336-
struct acpi_handle_list *list)
332+
bool acpi_evaluate_reference(acpi_handle handle, acpi_string pathname,
333+
struct acpi_object_list *arguments,
334+
struct acpi_handle_list *list)
337335
{
338-
acpi_status status = AE_OK;
339-
union acpi_object *package = NULL;
340-
union acpi_object *element = NULL;
341336
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
342-
u32 i = 0;
343-
337+
union acpi_object *package;
338+
acpi_status status;
339+
bool ret = false;
340+
u32 i;
344341

345342
if (!list)
346-
return AE_BAD_PARAMETER;
343+
return false;
347344

348345
/* Evaluate object. */
349346

@@ -353,62 +350,47 @@ acpi_evaluate_reference(acpi_handle handle,
353350

354351
package = buffer.pointer;
355352

356-
if ((buffer.length == 0) || !package) {
357-
status = AE_BAD_DATA;
358-
acpi_util_eval_error(handle, pathname, status);
359-
goto end;
360-
}
361-
if (package->type != ACPI_TYPE_PACKAGE) {
362-
status = AE_BAD_DATA;
363-
acpi_util_eval_error(handle, pathname, status);
364-
goto end;
365-
}
366-
if (!package->package.count) {
367-
status = AE_BAD_DATA;
368-
acpi_util_eval_error(handle, pathname, status);
369-
goto end;
370-
}
353+
if (buffer.length == 0 || !package ||
354+
package->type != ACPI_TYPE_PACKAGE || !package->package.count)
355+
goto err;
371356

372-
list->handles = kcalloc(package->package.count, sizeof(*list->handles), GFP_KERNEL);
373-
if (!list->handles) {
374-
kfree(package);
375-
return AE_NO_MEMORY;
376-
}
377357
list->count = package->package.count;
358+
list->handles = kcalloc(list->count, sizeof(*list->handles), GFP_KERNEL);
359+
if (!list->handles)
360+
goto err_clear;
378361

379362
/* Extract package data. */
380363

381364
for (i = 0; i < list->count; i++) {
365+
union acpi_object *element = &(package->package.elements[i]);
382366

383-
element = &(package->package.elements[i]);
367+
if (element->type != ACPI_TYPE_LOCAL_REFERENCE ||
368+
!element->reference.handle)
369+
goto err_free;
384370

385-
if (element->type != ACPI_TYPE_LOCAL_REFERENCE) {
386-
status = AE_BAD_DATA;
387-
acpi_util_eval_error(handle, pathname, status);
388-
break;
389-
}
390-
391-
if (!element->reference.handle) {
392-
status = AE_NULL_ENTRY;
393-
acpi_util_eval_error(handle, pathname, status);
394-
break;
395-
}
396371
/* Get the acpi_handle. */
397372

398373
list->handles[i] = element->reference.handle;
399374
acpi_handle_debug(list->handles[i], "Found in reference list\n");
400375
}
401376

402-
if (ACPI_FAILURE(status)) {
403-
list->count = 0;
404-
kfree(list->handles);
405-
list->handles = NULL;
406-
}
377+
ret = true;
407378

408379
end:
409380
kfree(buffer.pointer);
410381

411-
return status;
382+
return ret;
383+
384+
err_free:
385+
kfree(list->handles);
386+
list->handles = NULL;
387+
388+
err_clear:
389+
list->count = 0;
390+
391+
err:
392+
acpi_util_eval_error(handle, pathname, status);
393+
goto end;
412394
}
413395

414396
EXPORT_SYMBOL(acpi_evaluate_reference);
@@ -426,7 +408,7 @@ bool acpi_handle_list_equal(struct acpi_handle_list *list1,
426408
{
427409
return list1->count == list2->count &&
428410
!memcmp(list1->handles, list2->handles,
429-
list1->count * sizeof(acpi_handle));
411+
list1->count * sizeof(*list1->handles));
430412
}
431413
EXPORT_SYMBOL_GPL(acpi_handle_list_equal);
432414

@@ -468,6 +450,40 @@ void acpi_handle_list_free(struct acpi_handle_list *list)
468450
}
469451
EXPORT_SYMBOL_GPL(acpi_handle_list_free);
470452

453+
/**
454+
* acpi_device_dep - Check ACPI device dependency
455+
* @target: ACPI handle of the target ACPI device.
456+
* @match: ACPI handle to look up in the target's _DEP list.
457+
*
458+
* Return true if @match is present in the list returned by _DEP for
459+
* @target or false otherwise.
460+
*/
461+
bool acpi_device_dep(acpi_handle target, acpi_handle match)
462+
{
463+
struct acpi_handle_list dep_devices;
464+
bool ret = false;
465+
int i;
466+
467+
if (!acpi_has_method(target, "_DEP"))
468+
return false;
469+
470+
if (!acpi_evaluate_reference(target, "_DEP", NULL, &dep_devices)) {
471+
acpi_handle_debug(target, "Failed to evaluate _DEP.\n");
472+
return false;
473+
}
474+
475+
for (i = 0; i < dep_devices.count; i++) {
476+
if (dep_devices.handles[i] == match) {
477+
ret = true;
478+
break;
479+
}
480+
}
481+
482+
acpi_handle_list_free(&dep_devices);
483+
return ret;
484+
}
485+
EXPORT_SYMBOL_GPL(acpi_device_dep);
486+
471487
acpi_status
472488
acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld)
473489
{
@@ -824,54 +840,6 @@ bool acpi_check_dsm(acpi_handle handle, const guid_t *guid, u64 rev, u64 funcs)
824840
}
825841
EXPORT_SYMBOL(acpi_check_dsm);
826842

827-
/**
828-
* acpi_dev_uid_match - Match device by supplied UID
829-
* @adev: ACPI device to match.
830-
* @uid2: Unique ID of the device.
831-
*
832-
* Matches UID in @adev with given @uid2.
833-
*
834-
* Returns:
835-
* - %true if matches.
836-
* - %false otherwise.
837-
*/
838-
bool acpi_dev_uid_match(struct acpi_device *adev, const char *uid2)
839-
{
840-
const char *uid1 = acpi_device_uid(adev);
841-
842-
return uid1 && uid2 && !strcmp(uid1, uid2);
843-
}
844-
EXPORT_SYMBOL_GPL(acpi_dev_uid_match);
845-
846-
/**
847-
* acpi_dev_hid_uid_match - Match device by supplied HID and UID
848-
* @adev: ACPI device to match.
849-
* @hid2: Hardware ID of the device.
850-
* @uid2: Unique ID of the device, pass NULL to not check _UID.
851-
*
852-
* Matches HID and UID in @adev with given @hid2 and @uid2. Absence of @uid2
853-
* will be treated as a match. If user wants to validate @uid2, it should be
854-
* done before calling this function.
855-
*
856-
* Returns:
857-
* - %true if matches or @uid2 is NULL.
858-
* - %false otherwise.
859-
*/
860-
bool acpi_dev_hid_uid_match(struct acpi_device *adev,
861-
const char *hid2, const char *uid2)
862-
{
863-
const char *hid1 = acpi_device_hid(adev);
864-
865-
if (strcmp(hid1, hid2))
866-
return false;
867-
868-
if (!uid2)
869-
return true;
870-
871-
return acpi_dev_uid_match(adev, uid2);
872-
}
873-
EXPORT_SYMBOL(acpi_dev_hid_uid_match);
874-
875843
/**
876844
* acpi_dev_uid_to_integer - treat ACPI device _UID as integer
877845
* @adev: ACPI device to get _UID from

drivers/firmware/efi/dev-path-parser.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ static long __init parse_acpi_path(const struct efi_dev_path *node,
1818
struct acpi_device *adev;
1919
struct device *phys_dev;
2020
char hid[ACPI_ID_LEN];
21-
u64 uid;
22-
int ret;
2321

2422
if (node->header.length != 12)
2523
return -EINVAL;
@@ -31,10 +29,9 @@ static long __init parse_acpi_path(const struct efi_dev_path *node,
3129
node->acpi.hid >> 16);
3230

3331
for_each_acpi_dev_match(adev, hid, NULL, -1) {
34-
ret = acpi_dev_uid_to_integer(adev, &uid);
35-
if (ret == 0 && node->acpi.uid == uid)
32+
if (acpi_dev_uid_match(adev, node->acpi.uid))
3633
break;
37-
if (ret == -ENODATA && node->acpi.uid == 0)
34+
if (!acpi_device_uid(adev) && node->acpi.uid == 0)
3835
break;
3936
}
4037
if (!adev)

drivers/perf/arm_cspmu/arm_cspmu.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,6 @@ static int arm_cspmu_request_irq(struct arm_cspmu *cspmu)
11081108

11091109
static inline int arm_cspmu_find_cpu_container(int cpu, u32 container_uid)
11101110
{
1111-
u64 acpi_uid;
11121111
struct device *cpu_dev;
11131112
struct acpi_device *acpi_dev;
11141113

@@ -1118,8 +1117,7 @@ static inline int arm_cspmu_find_cpu_container(int cpu, u32 container_uid)
11181117

11191118
acpi_dev = ACPI_COMPANION(cpu_dev);
11201119
while (acpi_dev) {
1121-
if (acpi_dev_hid_uid_match(acpi_dev, ACPI_PROCESSOR_CONTAINER_HID, NULL) &&
1122-
!acpi_dev_uid_to_integer(acpi_dev, &acpi_uid) && acpi_uid == container_uid)
1120+
if (acpi_dev_hid_uid_match(acpi_dev, ACPI_PROCESSOR_CONTAINER_HID, container_uid))
11231121
return 0;
11241122

11251123
acpi_dev = acpi_dev_parent(acpi_dev);

0 commit comments

Comments
 (0)