summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drivers/acpi/acpi_lpss.c21
-rw-r--r--drivers/acpi/property.c20
-rw-r--r--drivers/acpi/resource.c94
-rw-r--r--drivers/acpi/scan.c1
-rw-r--r--drivers/acpi/thermal.c710
-rw-r--r--drivers/acpi/utils.c68
-rw-r--r--drivers/platform/surface/surface_acpi_notify.c10
-rw-r--r--include/acpi/acpi_bus.h9
8 files changed, 509 insertions, 424 deletions
diff --git a/drivers/acpi/acpi_lpss.c b/drivers/acpi/acpi_lpss.c
index 539e700de4d2..875de44961bf 100644
--- a/drivers/acpi/acpi_lpss.c
+++ b/drivers/acpi/acpi_lpss.c
@@ -368,7 +368,6 @@ static const struct acpi_device_id acpi_lpss_device_ids[] = {
{ "INT33C4", LPSS_ADDR(lpt_uart_dev_desc) },
{ "INT33C5", LPSS_ADDR(lpt_uart_dev_desc) },
{ "INT33C6", LPSS_ADDR(lpt_sdio_dev_desc) },
- { "INT33C7", },
/* BayTrail LPSS devices */
{ "80860F09", LPSS_ADDR(byt_pwm_dev_desc) },
@@ -376,8 +375,6 @@ static const struct acpi_device_id acpi_lpss_device_ids[] = {
{ "80860F0E", LPSS_ADDR(byt_spi_dev_desc) },
{ "80860F14", LPSS_ADDR(byt_sdio_dev_desc) },
{ "80860F41", LPSS_ADDR(byt_i2c_dev_desc) },
- { "INT33B2", },
- { "INT33FC", },
/* Braswell LPSS devices */
{ "80862286", LPSS_ADDR(lpss_dma_desc) },
@@ -396,7 +393,6 @@ static const struct acpi_device_id acpi_lpss_device_ids[] = {
{ "INT3434", LPSS_ADDR(lpt_uart_dev_desc) },
{ "INT3435", LPSS_ADDR(lpt_uart_dev_desc) },
{ "INT3436", LPSS_ADDR(lpt_sdio_dev_desc) },
- { "INT3437", },
/* Wildcat Point LPSS devices */
{ "INT3438", LPSS_ADDR(lpt_spi_dev_desc) },
@@ -578,6 +574,7 @@ static bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle)
{
struct acpi_handle_list dep_devices;
acpi_status status;
+ bool ret = false;
int i;
if (!acpi_has_method(adev->handle, "_DEP"))
@@ -591,11 +588,14 @@ static bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle)
}
for (i = 0; i < dep_devices.count; i++) {
- if (dep_devices.handles[i] == handle)
- return true;
+ if (dep_devices.handles[i] == handle) {
+ ret = true;
+ break;
+ }
}
- return false;
+ acpi_handle_list_free(&dep_devices);
+ return ret;
}
static void acpi_lpss_link_consumer(struct device *dev1,
@@ -657,10 +657,9 @@ static int acpi_lpss_create_device(struct acpi_device *adev,
int ret;
dev_desc = (const struct lpss_device_desc *)id->driver_data;
- if (!dev_desc) {
- pdev = acpi_create_platform_device(adev, NULL);
- return IS_ERR_OR_NULL(pdev) ? PTR_ERR(pdev) : 1;
- }
+ if (!dev_desc)
+ return -EINVAL;
+
pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
if (!pdata)
return -ENOMEM;
diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
index 413e4fcadcaf..6979a3f9f90a 100644
--- a/drivers/acpi/property.c
+++ b/drivers/acpi/property.c
@@ -55,6 +55,7 @@ static const guid_t ads_guid =
GUID_INIT(0xdbb8e3e6, 0x5886, 0x4ba6,
0x87, 0x95, 0x13, 0x19, 0xf5, 0x2a, 0x96, 0x6b);
+/* ACPI _DSD data buffer GUID: edb12dd0-363d-4085-a3d2-49522ca160c4 */
static const guid_t buffer_prop_guid =
GUID_INIT(0xedb12dd0, 0x363d, 0x4085,
0xa3, 0xd2, 0x49, 0x52, 0x2c, 0xa1, 0x60, 0xc4);
@@ -1102,25 +1103,26 @@ static int acpi_data_prop_read(const struct acpi_device_data *data,
switch (proptype) {
case DEV_PROP_STRING:
break;
- case DEV_PROP_U8 ... DEV_PROP_U64:
+ default:
if (obj->type == ACPI_TYPE_BUFFER) {
if (nval > obj->buffer.length)
return -EOVERFLOW;
- break;
+ } else {
+ if (nval > obj->package.count)
+ return -EOVERFLOW;
}
- fallthrough;
- default:
- if (nval > obj->package.count)
- return -EOVERFLOW;
break;
}
if (nval == 0)
return -EINVAL;
- if (obj->type != ACPI_TYPE_BUFFER)
- items = obj->package.elements;
- else
+ if (obj->type == ACPI_TYPE_BUFFER) {
+ if (proptype != DEV_PROP_U8)
+ return -EPROTO;
items = obj;
+ } else {
+ items = obj->package.elements;
+ }
switch (proptype) {
case DEV_PROP_U8:
diff --git a/drivers/acpi/resource.c b/drivers/acpi/resource.c
index 297a88587031..15a3bdbd0755 100644
--- a/drivers/acpi/resource.c
+++ b/drivers/acpi/resource.c
@@ -385,127 +385,144 @@ unsigned int acpi_dev_get_irq_type(int triggering, int polarity)
}
EXPORT_SYMBOL_GPL(acpi_dev_get_irq_type);
-static const struct dmi_system_id medion_laptop[] = {
+/*
+ * DMI matches for boards where the DSDT specifies the kbd IRQ as
+ * level active-low and using the override changes this to rising edge,
+ * stopping the keyboard from working.
+ */
+static const struct dmi_system_id irq1_level_low_skip_override[] = {
{
- .ident = "MEDION P15651",
+ /* MEDION P15651 */
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
DMI_MATCH(DMI_BOARD_NAME, "M15T"),
},
},
{
- .ident = "MEDION S17405",
+ /* MEDION S17405 */
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
DMI_MATCH(DMI_BOARD_NAME, "M17T"),
},
},
{
- .ident = "MEDION S17413",
+ /* MEDION S17413 */
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
DMI_MATCH(DMI_BOARD_NAME, "M1xA"),
},
},
- { }
-};
-
-static const struct dmi_system_id asus_laptop[] = {
{
- .ident = "Asus Vivobook K3402ZA",
+ /* Asus Vivobook K3402ZA */
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
DMI_MATCH(DMI_BOARD_NAME, "K3402ZA"),
},
},
{
- .ident = "Asus Vivobook K3502ZA",
+ /* Asus Vivobook K3502ZA */
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
DMI_MATCH(DMI_BOARD_NAME, "K3502ZA"),
},
},
{
- .ident = "Asus Vivobook S5402ZA",
+ /* Asus Vivobook S5402ZA */
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
DMI_MATCH(DMI_BOARD_NAME, "S5402ZA"),
},
},
{
- .ident = "Asus Vivobook S5602ZA",
+ /* Asus Vivobook S5602ZA */
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
DMI_MATCH(DMI_BOARD_NAME, "S5602ZA"),
},
},
{
- .ident = "Asus ExpertBook B1402CBA",
+ /* Asus ExpertBook B1402CBA */
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
DMI_MATCH(DMI_BOARD_NAME, "B1402CBA"),
},
},
{
- .ident = "Asus ExpertBook B1502CBA",
+ /* Asus ExpertBook B1502CBA */
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
DMI_MATCH(DMI_BOARD_NAME, "B1502CBA"),
},
},
{
- .ident = "Asus ExpertBook B2402CBA",
+ /* Asus ExpertBook B2402CBA */
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
DMI_MATCH(DMI_BOARD_NAME, "B2402CBA"),
},
},
{
- .ident = "Asus ExpertBook B2402FBA",
+ /* Asus ExpertBook B2402FBA */
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
DMI_MATCH(DMI_BOARD_NAME, "B2402FBA"),
},
},
{
- .ident = "Asus ExpertBook B2502",
+ /* Asus ExpertBook B2502 */
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
DMI_MATCH(DMI_BOARD_NAME, "B2502CBA"),
},
},
+ {
+ /* LG Electronics 17U70P */
+ .matches = {
+ DMI_MATCH(DMI_SYS_VENDOR, "LG Electronics"),
+ DMI_MATCH(DMI_BOARD_NAME, "17U70P"),
+ },
+ },
{ }
};
-static const struct dmi_system_id tongfang_gm_rg[] = {
+/*
+ * DMI matches for AMD Zen boards where the DSDT specifies the kbd IRQ
+ * as falling edge and this must be overridden to rising edge,
+ * to have a working keyboard.
+ */
+static const struct dmi_system_id irq1_edge_low_force_override[] = {
{
- .ident = "TongFang GMxRGxx/XMG CORE 15 (M22)/TUXEDO Stellaris 15 Gen4 AMD",
+ /* TongFang GMxRGxx/XMG CORE 15 (M22)/TUXEDO Stellaris 15 Gen4 AMD */
.matches = {
DMI_MATCH(DMI_BOARD_NAME, "GMxRGxx"),
},
},
- { }
-};
-
-static const struct dmi_system_id maingear_laptop[] = {
{
- .ident = "MAINGEAR Vector Pro 2 15",
+ /* TongFang GMxXGxx/TUXEDO Polaris 15 Gen5 AMD */
+ .matches = {
+ DMI_MATCH(DMI_BOARD_NAME, "GMxXGxx"),
+ },
+ },
+ {
+ /* TongFang GM6XGxX/TUXEDO Stellaris 16 Gen5 AMD */
+ .matches = {
+ DMI_MATCH(DMI_BOARD_NAME, "GM6XGxX"),
+ },
+ },
+ {
+ /* MAINGEAR Vector Pro 2 15 */
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "Micro Electronics Inc"),
DMI_MATCH(DMI_PRODUCT_NAME, "MG-VCP2-15A3070T"),
}
},
{
- .ident = "MAINGEAR Vector Pro 2 17",
+ /* MAINGEAR Vector Pro 2 17 */
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "Micro Electronics Inc"),
DMI_MATCH(DMI_PRODUCT_NAME, "MG-VCP2-17A3070T"),
},
},
- { }
-};
-
-static const struct dmi_system_id pcspecialist_laptop[] = {
{
/* TongFang GM6BGEQ / PCSpecialist Elimina Pro 16 M, RTX 3050 */
.matches = {
@@ -527,17 +544,6 @@ static const struct dmi_system_id pcspecialist_laptop[] = {
{ }
};
-static const struct dmi_system_id lg_laptop[] = {
- {
- .ident = "LG Electronics 17U70P",
- .matches = {
- DMI_MATCH(DMI_SYS_VENDOR, "LG Electronics"),
- DMI_MATCH(DMI_BOARD_NAME, "17U70P"),
- },
- },
- { }
-};
-
struct irq_override_cmp {
const struct dmi_system_id *system;
unsigned char irq;
@@ -548,12 +554,8 @@ struct irq_override_cmp {
};
static const struct irq_override_cmp override_table[] = {
- { medion_laptop, 1, ACPI_LEVEL_SENSITIVE, ACPI_ACTIVE_LOW, 0, false },
- { asus_laptop, 1, ACPI_LEVEL_SENSITIVE, ACPI_ACTIVE_LOW, 0, false },
- { tongfang_gm_rg, 1, ACPI_EDGE_SENSITIVE, ACPI_ACTIVE_LOW, 1, true },
- { maingear_laptop, 1, ACPI_EDGE_SENSITIVE, ACPI_ACTIVE_LOW, 1, true },
- { pcspecialist_laptop, 1, ACPI_EDGE_SENSITIVE, ACPI_ACTIVE_LOW, 1, true },
- { lg_laptop, 1, ACPI_LEVEL_SENSITIVE, ACPI_ACTIVE_LOW, 0, false },
+ { irq1_level_low_skip_override, 1, ACPI_LEVEL_SENSITIVE, ACPI_ACTIVE_LOW, 0, false },
+ { irq1_edge_low_force_override, 1, ACPI_EDGE_SENSITIVE, ACPI_ACTIVE_LOW, 1, true },
};
static bool acpi_dev_irq_override(u32 gsi, u8 triggering, u8 polarity,
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 17ab875a7d4e..fa5dd71a80fa 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -2032,6 +2032,7 @@ static u32 acpi_scan_check_dep(acpi_handle handle, bool check_dep)
mutex_unlock(&acpi_dep_list_lock);
}
+ acpi_handle_list_free(&dep_devices);
return count;
}
diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index 312730f8272e..42a3df9d625d 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -43,17 +43,7 @@
#define ACPI_THERMAL_MAX_ACTIVE 10
#define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65
-#define ACPI_TRIPS_CRITICAL BIT(0)
-#define ACPI_TRIPS_HOT BIT(1)
-#define ACPI_TRIPS_PASSIVE BIT(2)
-#define ACPI_TRIPS_ACTIVE BIT(3)
-#define ACPI_TRIPS_DEVICES BIT(4)
-
-#define ACPI_TRIPS_THRESHOLDS (ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE)
-
-#define ACPI_TRIPS_INIT (ACPI_TRIPS_CRITICAL | ACPI_TRIPS_HOT | \
- ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE | \
- ACPI_TRIPS_DEVICES)
+#define ACPI_THERMAL_TRIP_PASSIVE (-1)
/*
* This exception is thrown out in two cases:
@@ -62,12 +52,11 @@
* 2.TODO: Devices listed in _PSL, _ALx, _TZD may change.
* We need to re-bind the cooling devices of a thermal zone when this occurs.
*/
-#define ACPI_THERMAL_TRIPS_EXCEPTION(flags, tz, str) \
+#define ACPI_THERMAL_TRIPS_EXCEPTION(tz, str) \
do { \
- if (flags != ACPI_TRIPS_INIT) \
- acpi_handle_info(tz->device->handle, \
- "ACPI thermal trip point %s changed\n" \
- "Please report to linux-acpi@vger.kernel.org\n", str); \
+ acpi_handle_info(tz->device->handle, \
+ "ACPI thermal trip point %s changed\n" \
+ "Please report to linux-acpi@vger.kernel.org\n", str); \
} while (0)
static int act;
@@ -94,12 +83,11 @@ static struct workqueue_struct *acpi_thermal_pm_queue;
struct acpi_thermal_trip {
unsigned long temperature;
- bool valid;
+ struct acpi_handle_list devices;
};
struct acpi_thermal_passive {
struct acpi_thermal_trip trip;
- struct acpi_handle_list devices;
unsigned long tc1;
unsigned long tc2;
unsigned long tsp;
@@ -107,14 +95,13 @@ struct acpi_thermal_passive {
struct acpi_thermal_active {
struct acpi_thermal_trip trip;
- struct acpi_handle_list devices;
};
struct acpi_thermal_trips {
- struct acpi_thermal_trip critical;
- struct acpi_thermal_trip hot;
struct acpi_thermal_passive passive;
struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE];
+ bool critical_valid;
+ bool hot_valid;
};
struct acpi_thermal {
@@ -188,215 +175,117 @@ static int acpi_thermal_temp(struct acpi_thermal *tz, int temp_deci_k)
tz->kelvin_offset);
}
-static void __acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
+static bool acpi_thermal_trip_valid(struct acpi_thermal_trip *acpi_trip)
+{
+ return acpi_trip->temperature != THERMAL_TEMP_INVALID;
+}
+
+static long get_passive_temp(struct acpi_thermal *tz)
{
- acpi_status status;
unsigned long long tmp;
- struct acpi_handle_list devices;
- bool valid = false;
- int i;
+ acpi_status status;
- /* Critical Shutdown */
- if (flag & ACPI_TRIPS_CRITICAL) {
- status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL, &tmp);
- tz->trips.critical.temperature = tmp;
- /*
- * Treat freezing temperatures as invalid as well; some
- * BIOSes return really low values and cause reboots at startup.
- * Below zero (Celsius) values clearly aren't right for sure..
- * ... so lets discard those as invalid.
- */
- if (ACPI_FAILURE(status)) {
- tz->trips.critical.valid = false;
- acpi_handle_debug(tz->device->handle,
- "No critical threshold\n");
- } else if (tmp <= 2732) {
- pr_info(FW_BUG "Invalid critical threshold (%llu)\n", tmp);
- tz->trips.critical.valid = false;
- } else {
- tz->trips.critical.valid = true;
- acpi_handle_debug(tz->device->handle,
- "Found critical threshold [%lu]\n",
- tz->trips.critical.temperature);
- }
- if (tz->trips.critical.valid) {
- if (crt == -1) {
- tz->trips.critical.valid = false;
- } else if (crt > 0) {
- unsigned long crt_k = celsius_to_deci_kelvin(crt);
-
- /*
- * Allow override critical threshold
- */
- if (crt_k > tz->trips.critical.temperature)
- pr_info("Critical threshold %d C\n", crt);
-
- tz->trips.critical.temperature = crt_k;
- }
- }
- }
+ status = acpi_evaluate_integer(tz->device->handle, "_PSV", NULL, &tmp);
+ if (ACPI_FAILURE(status))
+ return THERMAL_TEMP_INVALID;
- /* Critical Sleep (optional) */
- if (flag & ACPI_TRIPS_HOT) {
- status = acpi_evaluate_integer(tz->device->handle, "_HOT", NULL, &tmp);
- if (ACPI_FAILURE(status)) {
- tz->trips.hot.valid = false;
- acpi_handle_debug(tz->device->handle,
- "No hot threshold\n");
- } else {
- tz->trips.hot.temperature = tmp;
- tz->trips.hot.valid = true;
- acpi_handle_debug(tz->device->handle,
- "Found hot threshold [%lu]\n",
- tz->trips.hot.temperature);
- }
- }
+ return tmp;
+}
- /* Passive (optional) */
- if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.trip.valid) ||
- flag == ACPI_TRIPS_INIT) {
- valid = tz->trips.passive.trip.valid;
- if (psv == -1) {
- status = AE_SUPPORT;
- } else if (psv > 0) {
- tmp = celsius_to_deci_kelvin(psv);
- status = AE_OK;
- } else {
- status = acpi_evaluate_integer(tz->device->handle,
- "_PSV", NULL, &tmp);
- }
+static void acpi_thermal_update_passive_trip(struct acpi_thermal *tz)
+{
+ struct acpi_thermal_trip *acpi_trip = &tz->trips.passive.trip;
- if (ACPI_FAILURE(status)) {
- tz->trips.passive.trip.valid = false;
- } else {
- tz->trips.passive.trip.temperature = tmp;
- tz->trips.passive.trip.valid = true;
- if (flag == ACPI_TRIPS_INIT) {
- status = acpi_evaluate_integer(tz->device->handle,
- "_TC1", NULL, &tmp);
- if (ACPI_FAILURE(status))
- tz->trips.passive.trip.valid = false;
- else
- tz->trips.passive.tc1 = tmp;
-
- status = acpi_evaluate_integer(tz->device->handle,
- "_TC2", NULL, &tmp);
- if (ACPI_FAILURE(status))
- tz->trips.passive.trip.valid = false;
- else
- tz->trips.passive.tc2 = tmp;
-
- status = acpi_evaluate_integer(tz->device->handle,
- "_TSP", NULL, &tmp);
- if (ACPI_FAILURE(status))
- tz->trips.passive.trip.valid = false;
- else
- tz->trips.passive.tsp = tmp;
- }
- }
+ if (!acpi_thermal_trip_valid(acpi_trip) || psv > 0)
+ return;
+
+ acpi_trip->temperature = get_passive_temp(tz);
+ if (!acpi_thermal_trip_valid(acpi_trip))
+ ACPI_THERMAL_TRIPS_EXCEPTION(tz, "state");
+}
+
+static bool update_trip_devices(struct acpi_thermal *tz,
+ struct acpi_thermal_trip *acpi_trip,
+ int index, bool compare)
+{
+ struct acpi_handle_list devices = { 0 };
+ char method[] = "_PSL";
+ acpi_status status;
+
+ if (index != ACPI_THERMAL_TRIP_PASSIVE) {
+ method[1] = 'A';
+ method[2] = 'L';
+ method[3] = '0' + index;
}
- if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.passive.trip.valid) {
- memset(&devices, 0, sizeof(struct acpi_handle_list));
- status = acpi_evaluate_reference(tz->device->handle, "_PSL",
- NULL, &devices);
- if (ACPI_FAILURE(status)) {
- acpi_handle_info(tz->device->handle,
- "Invalid passive threshold\n");
- tz->trips.passive.trip.valid = false;
- } else {
- tz->trips.passive.trip.valid = true;
- }
- if (memcmp(&tz->trips.passive.devices, &devices,
- sizeof(struct acpi_handle_list))) {
- memcpy(&tz->trips.passive.devices, &devices,
- sizeof(struct acpi_handle_list));
- ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "device");
- }
+ status = acpi_evaluate_reference(tz->device->handle, method, NULL, &devices);
+ if (ACPI_FAILURE(status)) {
+ acpi_handle_info(tz->device->handle, "%s evaluation failure\n", method);
+ return false;
}
- if ((flag & ACPI_TRIPS_PASSIVE) || (flag & ACPI_TRIPS_DEVICES)) {
- if (valid != tz->trips.passive.trip.valid)
- ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "state");
+
+ if (acpi_handle_list_equal(&acpi_trip->devices, &devices)) {
+ acpi_handle_list_free(&devices);
+ return true;
}
- /* Active (optional) */
- for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
- char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
- valid = tz->trips.active[i].trip.valid;
+ if (compare)
+ ACPI_THERMAL_TRIPS_EXCEPTION(tz, "device");
- if (act == -1)
- break; /* disable all active trip points */
-
- if (flag == ACPI_TRIPS_INIT || ((flag & ACPI_TRIPS_ACTIVE) &&
- tz->trips.active[i].trip.valid)) {
- status = acpi_evaluate_integer(tz->device->handle,
- name, NULL, &tmp);
- if (ACPI_FAILURE(status)) {
- tz->trips.active[i].trip.valid = false;
- if (i == 0)
- break;
-
- if (act <= 0)
- break;
-
- if (i == 1)
- tz->trips.active[0].trip.temperature =
- celsius_to_deci_kelvin(act);
- else
- /*
- * Don't allow override higher than
- * the next higher trip point
- */
- tz->trips.active[i-1].trip.temperature =
- min_t(unsigned long,
- tz->trips.active[i-2].trip.temperature,
- celsius_to_deci_kelvin(act));
-
- break;
- } else {
- tz->trips.active[i].trip.temperature = tmp;
- tz->trips.active[i].trip.valid = true;
- }
- }
+ acpi_handle_list_replace(&acpi_trip->devices, &devices);
+ return true;
+}
- name[2] = 'L';
- if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].trip.valid) {
- memset(&devices, 0, sizeof(struct acpi_handle_list));
- status = acpi_evaluate_reference(tz->device->handle,
- name, NULL, &devices);
- if (ACPI_FAILURE(status)) {
- acpi_handle_info(tz->device->handle,
- "Invalid active%d threshold\n", i);
- tz->trips.active[i].trip.valid = false;
- } else {
- tz->trips.active[i].trip.valid = true;
- }
-
- if (memcmp(&tz->trips.active[i].devices, &devices,
- sizeof(struct acpi_handle_list))) {
- memcpy(&tz->trips.active[i].devices, &devices,
- sizeof(struct acpi_handle_list));
- ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "device");
- }
- }
- if ((flag & ACPI_TRIPS_ACTIVE) || (flag & ACPI_TRIPS_DEVICES))
- if (valid != tz->trips.active[i].trip.valid)
- ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "state");
+static void acpi_thermal_update_trip_devices(struct acpi_thermal *tz, int index)
+{
+ struct acpi_thermal_trip *acpi_trip;
- if (!tz->trips.active[i].trip.valid)
- break;
+ acpi_trip = index == ACPI_THERMAL_TRIP_PASSIVE ?
+ &tz->trips.passive.trip : &tz->trips.active[index].trip;
+ if (!acpi_thermal_trip_valid(acpi_trip))
+ return;
+
+ if (update_trip_devices(tz, acpi_trip, index, true)) {
+ return;
}
- if (flag & ACPI_TRIPS_DEVICES) {
- memset(&devices, 0, sizeof(devices));
- status = acpi_evaluate_reference(tz->device->handle, "_TZD",
- NULL, &devices);
- if (ACPI_SUCCESS(status) &&
- memcmp(&tz->devices, &devices, sizeof(devices))) {
- tz->devices = devices;
- ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "device");
- }
+ acpi_trip->temperature = THERMAL_TEMP_INVALID;
+ ACPI_THERMAL_TRIPS_EXCEPTION(tz, "state");
+}
+
+static long get_active_temp(struct acpi_thermal *tz, int index)
+{
+ char method[] = { '_', 'A', 'C', '0' + index, '\0' };
+ unsigned long long tmp;
+ acpi_status status;
+
+ status = acpi_evaluate_integer(tz->device->handle, method, NULL, &tmp);
+ if (ACPI_FAILURE(status))
+ return THERMAL_TEMP_INVALID;
+
+ /*
+ * If an override has been provided, apply it so there are no active
+ * trips with thresholds greater than the override.
+ */
+ if (act > 0) {
+ unsigned long long override = celsius_to_deci_kelvin(act);
+
+ if (tmp > override)
+ tmp = override;
}
+ return tmp;
+}
+
+static void acpi_thermal_update_active_trip(struct acpi_thermal *tz, int index)
+{
+ struct acpi_thermal_trip *acpi_trip = &tz->trips.active[index].trip;
+
+ if (!acpi_thermal_trip_valid(acpi_trip))
+ return;
+
+ acpi_trip->temperature = get_active_temp(tz, index);
+ if (!acpi_thermal_trip_valid(acpi_trip))
+ ACPI_THERMAL_TRIPS_EXCEPTION(tz, "state");
}
static int acpi_thermal_adjust_trip(struct thermal_trip *trip, void *data)
@@ -407,7 +296,7 @@ static int acpi_thermal_adjust_trip(struct thermal_trip *trip, void *data)
if (!acpi_trip)
return 0;
- if (acpi_trip->valid)
+ if (acpi_thermal_trip_valid(acpi_trip))
trip->temperature = acpi_thermal_temp(tz, acpi_trip->temperature);
else
trip->temperature = THERMAL_TEMP_INVALID;
@@ -419,10 +308,17 @@ static void acpi_thermal_adjust_thermal_zone(struct thermal_zone_device *thermal
unsigned long data)
{
struct acpi_thermal *tz = thermal_zone_device_priv(thermal);
- int flag = data == ACPI_THERMAL_NOTIFY_THRESHOLDS ?
- ACPI_TRIPS_THRESHOLDS : ACPI_TRIPS_DEVICES;
+ int i;
- __acpi_thermal_trips_update(tz, flag);
+ if (data == ACPI_THERMAL_NOTIFY_THRESHOLDS) {
+ acpi_thermal_update_passive_trip(tz);
+ for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
+ acpi_thermal_update_active_trip(tz, i);
+ } else {
+ acpi_thermal_update_trip_devices(tz, ACPI_THERMAL_TRIP_PASSIVE);
+ for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
+ acpi_thermal_update_trip_devices(tz, i);
+ }
for_each_thermal_trip(tz->thermal_zone, acpi_thermal_adjust_trip, tz);
}
@@ -451,25 +347,143 @@ static void acpi_thermal_trips_update(struct acpi_thermal *tz, u32 event)
dev_name(&adev->dev), event, 0);
}
+static long acpi_thermal_get_critical_trip(struct acpi_thermal *tz)
+{
+ unsigned long long tmp;
+ acpi_status status;
+
+ if (crt > 0) {
+ tmp = celsius_to_deci_kelvin(crt);
+ goto set;
+ }
+ if (crt == -1) {
+ acpi_handle_debug(tz->device->handle, "Critical threshold disabled\n");
+ goto fail;
+ }
+
+ status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL, &tmp);
+ if (ACPI_FAILURE(status)) {
+ acpi_handle_debug(tz->device->handle, "No critical threshold\n");
+ goto fail;
+ }
+ if (tmp <= 2732) {
+ /*
+ * Below zero (Celsius) values clearly aren't right for sure,
+ * so discard them as invalid.
+ */
+ pr_info(FW_BUG "Invalid critical threshold (%llu)\n", tmp);
+ goto fail;
+ }
+
+set:
+ tz->trips.critical_valid = true;
+ acpi_handle_debug(tz->device->handle, "Critical threshold [%llu]\n", tmp);
+ return tmp;
+
+fail:
+ tz->trips.critical_valid = false;
+ return THERMAL_TEMP_INVALID;
+}
+
+static long acpi_thermal_get_hot_trip(struct acpi_thermal *tz)
+{
+ unsigned long long tmp;
+ acpi_status status;
+
+ status = acpi_evaluate_integer(tz->device->handle, "_HOT", NULL, &tmp);
+ if (ACPI_FAILURE(status)) {
+ tz->trips.hot_valid = false;
+ acpi_handle_debug(tz->device->handle, "No hot threshold\n");
+ return THERMAL_TEMP_INVALID;
+ }
+
+ tz->trips.hot_valid = true;
+ acpi_handle_debug(tz->device->handle, "Hot threshold [%llu]\n", tmp);
+ return tmp;
+}
+
+static bool passive_trip_params_init(struct acpi_thermal *tz)
+{
+ unsigned long long tmp;
+ acpi_status status;
+
+ status = acpi_evaluate_integer(tz->device->handle, "_TC1", NULL, &tmp);
+ if (ACPI_FAILURE(status))
+ return false;
+
+ tz->trips.passive.tc1 = tmp;
+
+ status = acpi_evaluate_integer(tz->device->handle, "_TC2", NULL, &tmp);
+ if (ACPI_FAILURE(status))
+ return false;
+
+ tz->trips.passive.tc2 = tmp;
+
+ status = acpi_evaluate_integer(tz->device->handle, "_TSP", NULL, &tmp);
+ if (ACPI_FAILURE(status))
+ return false;
+
+ tz->trips.passive.tsp = tmp;
+
+ return true;
+}
+
+static bool acpi_thermal_init_trip(struct acpi_thermal *tz, int index)
+{
+ struct acpi_thermal_trip *acpi_trip;
+ long temp;
+
+ if (index == ACPI_THERMAL_TRIP_PASSIVE) {
+ acpi_trip = &tz->trips.passive.trip;
+
+ if (psv == -1)
+ goto fail;
+
+ if (!passive_trip_params_init(tz))
+ goto fail;
+
+ temp = psv > 0 ? celsius_to_deci_kelvin(psv) :
+ get_passive_temp(tz);
+ } else {
+ acpi_trip = &tz->trips.active[index].trip;
+
+ if (act == -1)
+ goto fail;
+
+ temp = get_active_temp(tz, index);
+ }
+
+ if (temp == THERMAL_TEMP_INVALID)
+ goto fail;
+
+ if (!update_trip_devices(tz, acpi_trip, index, false))
+ goto fail;
+
+ acpi_trip->temperature = temp;
+ return true;
+
+fail:
+ acpi_trip->temperature = THERMAL_TEMP_INVALID;
+ return false;
+}
+
static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
{
- bool valid;
+ unsigned int count = 0;
int i;
- __acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT);
-
- valid = tz->trips.critical.valid |
- tz->trips.hot.valid |
- tz->trips.passive.trip.valid;
+ if (acpi_thermal_init_trip(tz, ACPI_THERMAL_TRIP_PASSIVE))
+ count++;
- for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
- valid = valid || tz->trips.active[i].trip.valid;
+ for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
+ if (acpi_thermal_init_trip(tz, i))
+ count++;
+ else
+ break;
- if (!valid) {
- pr_warn(FW_BUG "No valid trip found\n");
- return -ENODEV;
}
- return 0;
+
+ return count;
}
/* sys I/F for generic thermal sysfs support */
@@ -503,7 +517,7 @@ static int thermal_get_trend(struct thermal_zone_device *thermal,
return -EINVAL;
acpi_trip = trip->priv;
- if (!acpi_trip || !acpi_trip->valid)
+ if (!acpi_trip || !acpi_thermal_trip_valid(acpi_trip))
return -EINVAL;
switch (trip->type) {
@@ -563,6 +577,7 @@ static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
{
struct acpi_device *device = cdev->devdata;
struct acpi_thermal *tz = thermal_zone_device_priv(thermal);
+ struct acpi_thermal_trip *acpi_trip;
struct acpi_device *dev;
acpi_handle handle;
int i;
@@ -570,16 +585,17 @@ static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
int trip = -1;
int result = 0;
- if (tz->trips.critical.valid)
+ if (tz->trips.critical_valid)
trip++;
- if (tz->trips.hot.valid)
+ if (tz->trips.hot_valid)
trip++;
- if (tz->trips.passive.trip.valid) {
+ acpi_trip = &tz->trips.passive.trip;
+ if (acpi_thermal_trip_valid(acpi_trip)) {
trip++;
- for (i = 0; i < tz->trips.passive.devices.count; i++) {
- handle = tz->trips.passive.devices.handles[i];
+ for (i = 0; i < acpi_trip->devices.count; i++) {
+ handle = acpi_trip->devices.handles[i];
dev = acpi_fetch_acpi_dev(handle);
if (dev != device)
continue;
@@ -601,12 +617,13 @@ static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
}
for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
- if (!tz->trips.active[i].trip.valid)
+ acpi_trip = &tz->trips.active[i].trip;
+ if (!acpi_thermal_trip_valid(acpi_trip))
break;
trip++;
- for (j = 0; j < tz->trips.active[i].devices.count; j++) {
- handle = tz->trips.active[i].devices.handles[j];
+ for (j = 0; j < acpi_trip->devices.count; j++) {
+ handle = acpi_trip->devices.handles[j];
dev = acpi_fetch_acpi_dev(handle);
if (dev != device)
continue;
@@ -679,66 +696,11 @@ static void acpi_thermal_zone_sysfs_remove(struct acpi_thermal *tz)
sysfs_remove_link(&tzdev->kobj, "device");
}
-static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
+static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz,
+ unsigned int trip_count,
+ int passive_delay)
{
- struct acpi_thermal_trip *acpi_trip;
- struct thermal_trip *trip;
- int passive_delay = 0;
- int trip_count = 0;
int result;
- int i;
-
- if (tz->trips.critical.valid)
- trip_count++;
-
- if (tz->trips.hot.valid)
- trip_count++;
-
- if (tz->trips.passive.trip.valid) {
- trip_count++;
- passive_delay = tz->trips.passive.tsp * 100;
- }
-
- for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && tz->trips.active[i].trip.valid; i++)
- trip_count++;
-
- trip = kcalloc(trip_count, sizeof(*trip), GFP_KERNEL);
- if (!trip)
- return -ENOMEM;
-
- tz->trip_table = trip;
-
- if (tz->trips.critical.valid) {
- trip->type = THERMAL_TRIP_CRITICAL;
- trip->temperature = acpi_thermal_temp(tz, tz->trips.critical.temperature);
- trip++;
- }
-
- if (tz->trips.hot.valid) {
- trip->type = THERMAL_TRIP_HOT;
- trip->temperature = acpi_thermal_temp(tz, tz->trips.hot.temperature);
- trip++;
- }
-
- acpi_trip = &tz->trips.passive.trip;
- if (acpi_trip->valid) {
- trip->type = THERMAL_TRIP_PASSIVE;
- trip->temperature = acpi_thermal_temp(tz, acpi_trip->temperature);
- trip->priv = acpi_trip;
- trip++;
- }
-
- for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
- acpi_trip = &tz->trips.active[i].trip;
-
- if (!acpi_trip->valid)
- break;
-
- trip->type = THERMAL_TRIP_ACTIVE;
- trip->temperature = acpi_thermal_temp(tz, acpi_trip->temperature);
- trip->priv = acpi_trip;
- trip++;
- }
tz->thermal_zone = thermal_zone_device_register_with_trips("acpitz",
tz->trip_table,
@@ -748,10 +710,8 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
NULL,
passive_delay,
tz->polling_frequency * 100);
- if (IS_ERR(tz->thermal_zone)) {
- result = PTR_ERR(tz->thermal_zone);
- goto free_trip_table;
- }
+ if (IS_ERR(tz->thermal_zone))
+ return PTR_ERR(tz->thermal_zone);
result = acpi_thermal_zone_sysfs_add(tz);
if (result)
@@ -770,8 +730,6 @@ remove_links:
acpi_thermal_zone_sysfs_remove(tz);
unregister_tzd:
thermal_zone_device_unregister(tz->thermal_zone);
-free_trip_table:
- kfree(tz->trip_table);
return result;
}
@@ -844,38 +802,6 @@ static void acpi_thermal_aml_dependency_fix(struct acpi_thermal *tz)
acpi_evaluate_integer(handle, "_TMP", NULL, &value);
}
-static int acpi_thermal_get_info(struct acpi_thermal *tz)
-{
- int result;
-
- if (!tz)
- return -EINVAL;
-
- acpi_thermal_aml_dependency_fix(tz);
-
- /* Get trip points [_CRT, _PSV, etc.] (required) */
- result = acpi_thermal_get_trip_points(tz);
- if (result)
- return result;
-
- /* Get temperature [_TMP] (required) */
- result = acpi_thermal_get_temperature(tz);
- if (result)
- return result;
-
- /* Set the cooling mode [_SCP] to active cooling (default) */
- acpi_execute_simple_method(tz->device->handle, "_SCP",
- ACPI_THERMAL_MODE_ACTIVE);
-
- /* Get default polling frequency [_TZP] (optional) */
- if (tzp)
- tz->polling_frequency = tzp;
- else
- acpi_thermal_get_polling_frequency(tz);
-
- return 0;
-}
-
/*
* The exact offset between Kelvin and degree Celsius is 273.15. However ACPI
* handles temperature values with a single decimal place. As a consequence,
@@ -886,10 +812,9 @@ static int acpi_thermal_get_info(struct acpi_thermal *tz)
* The heuristic below should work for all ACPI thermal zones which have a
* critical trip point with a value being a multiple of 0.5 degree Celsius.
*/
-static void acpi_thermal_guess_offset(struct acpi_thermal *tz)
+static void acpi_thermal_guess_offset(struct acpi_thermal *tz, long crit_temp)
{
- if (tz->trips.critical.valid &&
- (tz->trips.critical.temperature % 5) == 1)
+ if (tz->trips.critical_valid && crit_temp % 5 == 1)
tz->kelvin_offset = 273100;
else
tz->kelvin_offset = 273200;
@@ -920,10 +845,27 @@ static void acpi_thermal_check_fn(struct work_struct *work)
mutex_unlock(&tz->thermal_check_lock);
}
+static void acpi_thermal_free_thermal_zone(struct acpi_thermal *tz)
+{
+ int i;
+
+ acpi_handle_list_free(&tz->trips.passive.trip.devices);
+ for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
+ acpi_handle_list_free(&tz->trips.active[i].trip.devices);
+
+ kfree(tz);
+}
+
static int acpi_thermal_add(struct acpi_device *device)
{
+ struct acpi_thermal_trip *acpi_trip;
+ struct thermal_trip *trip;
struct acpi_thermal *tz;
+ unsigned int trip_count;
+ int crit_temp, hot_temp;
+ int passive_delay = 0;
int result;
+ int i;
if (!device)
return -EINVAL;
@@ -938,15 +880,87 @@ static int acpi_thermal_add(struct acpi_device *device)
strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
device->driver_data = tz;
- result = acpi_thermal_get_info(tz);
+ acpi_thermal_aml_dependency_fix(tz);
+
+ /* Get trip points [_CRT, _PSV, etc.] (required). */
+ trip_count = acpi_thermal_get_trip_points(tz);
+
+ crit_temp = acpi_thermal_get_critical_trip(tz);
+ if (tz->trips.critical_valid)
+ trip_count++;
+
+ hot_temp = acpi_thermal_get_hot_trip(tz);
+ if (tz->trips.hot_valid)
+ trip_count++;
+
+ if (!trip_count) {
+ pr_warn(FW_BUG "No valid trip points!\n");
+ result = -ENODEV;
+ goto free_memory;
+ }
+
+ /* Get temperature [_TMP] (required). */
+ result = acpi_thermal_get_temperature(tz);
if (result)
goto free_memory;
- acpi_thermal_guess_offset(tz);
+ /* Set the cooling mode [_SCP] to active cooling. */
+ acpi_execute_simple_method(tz->device->handle, "_SCP",
+ ACPI_THERMAL_MODE_ACTIVE);
- result = acpi_thermal_register_thermal_zone(tz);
- if (result)
+ /* Determine the default polling frequency [_TZP]. */
+ if (tzp)
+ tz->polling_frequency = tzp;
+ else
+ acpi_thermal_get_polling_frequency(tz);
+
+ acpi_thermal_guess_offset(tz, crit_temp);
+
+ trip = kcalloc(trip_count, sizeof(*trip), GFP_KERNEL);
+ if (!trip) {
+ result = -ENOMEM;
goto free_memory;
+ }
+
+ tz->trip_table = trip;
+
+ if (tz->trips.critical_valid) {
+ trip->type = THERMAL_TRIP_CRITICAL;
+ trip->temperature = acpi_thermal_temp(tz, crit_temp);
+ trip++;
+ }
+
+ if (tz->trips.hot_valid) {
+ trip->type = THERMAL_TRIP_HOT;
+ trip->temperature = acpi_thermal_temp(tz, hot_temp);
+ trip++;
+ }
+
+ acpi_trip = &tz->trips.passive.trip;
+ if (acpi_thermal_trip_valid(acpi_trip)) {
+ passive_delay = tz->trips.passive.tsp * 100;
+
+ trip->type = THERMAL_TRIP_PASSIVE;
+ trip->temperature = acpi_thermal_temp(tz, acpi_trip->temperature);
+ trip->priv = acpi_trip;
+ trip++;
+ }
+
+ for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
+ acpi_trip = &tz->trips.active[i].trip;
+
+ if (!acpi_thermal_trip_valid(acpi_trip))
+ break;
+
+ trip->type = THERMAL_TRIP_ACTIVE;
+ trip->temperature = acpi_thermal_temp(tz, acpi_trip->temperature);
+ trip->priv = acpi_trip;
+ trip++;
+ }
+
+ result = acpi_thermal_register_thermal_zone(tz, trip_count, passive_delay);
+ if (result)
+ goto free_trips;
refcount_set(&tz->thermal_check_count, 3);
mutex_init(&tz->thermal_check_lock);
@@ -965,8 +979,10 @@ static int acpi_thermal_add(struct acpi_device *device)
flush_wq:
flush_workqueue(acpi_thermal_pm_queue);
acpi_thermal_unregister_thermal_zone(tz);
+free_trips:
+ kfree(tz->trip_table);
free_memory:
- kfree(tz);
+ acpi_thermal_free_thermal_zone(tz);
return result;
}
@@ -986,7 +1002,7 @@ static void acpi_thermal_remove(struct acpi_device *device)
flush_workqueue(acpi_thermal_pm_queue);
acpi_thermal_unregister_thermal_zone(tz);
- kfree(tz);
+ acpi_thermal_free_thermal_zone(tz);
}
#ifdef CONFIG_PM_SLEEP
@@ -1010,11 +1026,13 @@ static int acpi_thermal_resume(struct device *dev)
return -EINVAL;
for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
- if (!tz->trips.active[i].trip.valid)
+ struct acpi_thermal_trip *acpi_trip = &tz->trips.active[i].trip;
+
+ if (!acpi_thermal_trip_valid(acpi_trip))
break;
- for (j = 0; j < tz->trips.active[i].devices.count; j++) {
- acpi_bus_update_power(tz->trips.active[i].devices.handles[j],
+ for (j = 0; j < acpi_trip->devices.count; j++) {
+ acpi_bus_update_power(acpi_trip->devices.handles[j],
&power_state);
}
}
diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index 2ea14648a661..79915d4a0031 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -342,9 +342,8 @@ acpi_evaluate_reference(acpi_handle handle,
u32 i = 0;
- if (!list) {
+ if (!list)
return AE_BAD_PARAMETER;
- }
/* Evaluate object. */
@@ -370,7 +369,8 @@ acpi_evaluate_reference(acpi_handle handle,
goto end;
}
- if (package->package.count > ACPI_MAX_HANDLES) {
+ list->handles = kcalloc(package->package.count, sizeof(*list->handles), GFP_KERNEL);
+ if (!list->handles) {
kfree(package);
return AE_NO_MEMORY;
}
@@ -399,10 +399,11 @@ acpi_evaluate_reference(acpi_handle handle,
acpi_handle_debug(list->handles[i], "Found in reference list\n");
}
- end:
+end:
if (ACPI_FAILURE(status)) {
list->count = 0;
- //kfree(list->handles);
+ kfree(list->handles);
+ list->handles = NULL;
}
kfree(buffer.pointer);
@@ -412,6 +413,61 @@ acpi_evaluate_reference(acpi_handle handle,
EXPORT_SYMBOL(acpi_evaluate_reference);
+/**
+ * acpi_handle_list_equal - Check if two ACPI handle lists are the same
+ * @list1: First list to compare.
+ * @list2: Second list to compare.
+ *
+ * Return true if the given ACPI handle lists are of the same size and
+ * contain the same ACPI handles in the same order. Otherwise, return false.
+ */
+bool acpi_handle_list_equal(struct acpi_handle_list *list1,
+ struct acpi_handle_list *list2)
+{
+ return list1->count == list2->count &&
+ !memcmp(list1->handles, list2->handles,
+ list1->count * sizeof(acpi_handle));
+}
+EXPORT_SYMBOL_GPL(acpi_handle_list_equal);
+
+/**
+ * acpi_handle_list_replace - Replace one ACPI handle list with another
+ * @dst: ACPI handle list to replace.
+ * @src: Source ACPI handle list.
+ *
+ * Free the handles table in @dst, move the handles table from @src to @dst,
+ * copy count from @src to @dst and clear @src.
+ */
+void acpi_handle_list_replace(struct acpi_handle_list *dst,
+ struct acpi_handle_list *src)
+{
+ if (dst->count)
+ kfree(dst->handles);
+
+ dst->count = src->count;
+ dst->handles = src->handles;
+
+ src->handles = NULL;
+ src->count = 0;
+}
+EXPORT_SYMBOL_GPL(acpi_handle_list_replace);
+
+/**
+ * acpi_handle_list_free - Free the handles table in an ACPI handle list
+ * @list: ACPI handle list to free.
+ *
+ * Free the handles table in @list and clear its count field.
+ */
+void acpi_handle_list_free(struct acpi_handle_list *list)
+{
+ if (!list->count)
+ return;
+
+ kfree(list->handles);
+ list->count = 0;
+}
+EXPORT_SYMBOL_GPL(acpi_handle_list_free);
+
acpi_status
acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld)
{
@@ -523,7 +579,7 @@ acpi_handle_printk(const char *level, acpi_handle handle, const char *fmt, ...)
vaf.va = &args;
path = acpi_handle_path(handle);
- printk("%sACPI: %s: %pV", level, path ? path : "<n/a>" , &vaf);
+ printk("%sACPI: %s: %pV", level, path ? path : "<n/a>", &vaf);
va_end(args);
kfree(path);
diff --git a/drivers/platform/surface/surface_acpi_notify.c b/drivers/platform/surface/surface_acpi_notify.c
index 897cdd9c3aae..0412a644fece 100644
--- a/drivers/platform/surface/surface_acpi_notify.c
+++ b/drivers/platform/surface/surface_acpi_notify.c
@@ -741,6 +741,7 @@ static bool is_san_consumer(struct platform_device *pdev, acpi_handle handle)
struct acpi_handle_list dep_devices;
acpi_handle supplier = ACPI_HANDLE(&pdev->dev);
acpi_status status;
+ bool ret = false;
int i;
if (!acpi_has_method(handle, "_DEP"))
@@ -753,11 +754,14 @@ static bool is_san_consumer(struct platform_device *pdev, acpi_handle handle)
}
for (i = 0; i < dep_devices.count; i++) {
- if (dep_devices.handles[i] == supplier)
- return true;
+ if (dep_devices.handles[i] == supplier) {
+ ret = true;
+ break;
+ }
}
- return false;
+ acpi_handle_list_free(&dep_devices);
+ return ret;
}
static acpi_status san_consumer_setup(acpi_handle handle, u32 lvl,
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index 254685085c82..9920611a6faa 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -12,11 +12,9 @@
#include <linux/device.h>
#include <linux/property.h>
-/* TBD: Make dynamic */
-#define ACPI_MAX_HANDLES 10
struct acpi_handle_list {
u32 count;
- acpi_handle handles[ACPI_MAX_HANDLES];
+ acpi_handle* handles;
};
/* acpi_utils.h */
@@ -32,6 +30,11 @@ acpi_evaluate_reference(acpi_handle handle,
acpi_string pathname,
struct acpi_object_list *arguments,
struct acpi_handle_list *list);
+bool acpi_handle_list_equal(struct acpi_handle_list *list1,
+ struct acpi_handle_list *list2);
+void acpi_handle_list_replace(struct acpi_handle_list *dst,
+ struct acpi_handle_list *src);
+void acpi_handle_list_free(struct acpi_handle_list *list);
acpi_status
acpi_evaluate_ost(acpi_handle handle, u32 source_event, u32 status_code,
struct acpi_buffer *status_buf);