Skip to content

Instantly share code, notes, and snippets.

@andrew-d
Created September 10, 2018 02:59
Show Gist options
  • Save andrew-d/622faa1abacf83958a9548534755c11a to your computer and use it in GitHub Desktop.
Save andrew-d/622faa1abacf83958a9548534755c11a to your computer and use it in GitHub Desktop.
Thinkpad X1 Carbon thermal throttling patches for Linux
commit 0000000000000000000000000000000000000000
Author: Andrew Dunham <redacted>
Date: Mon Jan 01 00:00:00 2018 +0100
Apply https://patchwork.kernel.org/patch/8756801/
Original commit message:
Added AdaptivePerformance, EmergencyCallMode,
PassivePolicy2, PowerBoss, VirtualSensor
Policy UUID's
diff --git a/drivers/thermal/int340x_thermal/int3400_thermal.c b/drivers/thermal/int340x_thermal/int3400_thermal.c
index 43b90fd577e4..ebb98074a6ab 100644
--- a/drivers/thermal/int340x_thermal/int3400_thermal.c
+++ b/drivers/thermal/int340x_thermal/int3400_thermal.c
@@ -22,6 +22,11 @@ enum int3400_thermal_uuid {
INT3400_THERMAL_PASSIVE_1,
INT3400_THERMAL_ACTIVE,
INT3400_THERMAL_CRITICAL,
+ INT3400_THERMAL_ADAPTIVE_PERFORMANCE,
+ INT3400_THERMAL_EMERGENCY_CALL_MODE,
+ INT3400_THERMAL_PASSIVE_2,
+ INT3400_THERMAL_POWER_BOSS,
+ INT3400_THERMAL_VIRTUAL_SENSOR,
INT3400_THERMAL_MAXIMUM_UUID,
};
@@ -29,6 +34,11 @@ static char *int3400_thermal_uuids[INT3400_THERMAL_MAXIMUM_UUID] = {
"42A441D6-AE6A-462b-A84B-4A8CE79027D3",
"3A95C389-E4B8-4629-A526-C52C88626BAE",
"97C68AE7-15FA-499c-B8C9-5DA81D606E0A",
+ "63BE270F-1C11-48FD-A6F7-3AF253FF3E2D",
+ "5349962F-71E6-431D-9AE8-0A635B710AEE",
+ "9E04115A-AE87-4D1C-9500-0F3E340BFE75",
+ "F5A35014-C209-46A4-993A-EB56DE7530A1",
+ "6ED722A7-9240-48A5-B479-31EEF723D7CF",
};
struct int3400_thermal_priv {
commit 0000000000000000000000000000000000000000
Author: Andrew Dunham <redacted>
Date: Mon Jan 01 00:00:00 2018 +0100
Trigger int3400_thermal_run_osc on current_uuid_store
diff --git a/drivers/thermal/int340x_thermal/int3400_thermal.c b/drivers/thermal/int340x_thermal/int3400_thermal.c
index ebb98074a6ab..146f8048bc3e 100644
--- a/drivers/thermal/int340x_thermal/int3400_thermal.c
+++ b/drivers/thermal/int340x_thermal/int3400_thermal.c
@@ -54,6 +54,35 @@ struct int3400_thermal_priv {
int current_uuid_index;
};
+static int int3400_thermal_run_osc(acpi_handle handle,
+ enum int3400_thermal_uuid uuid, bool enable)
+{
+ u32 ret, buf[2];
+ acpi_status status;
+ int result = 0;
+ struct acpi_osc_context context = {
+ .uuid_str = int3400_thermal_uuids[uuid],
+ .rev = 1,
+ .cap.length = 8,
+ };
+
+ buf[OSC_QUERY_DWORD] = 0;
+ buf[OSC_SUPPORT_DWORD] = enable;
+
+ context.cap.pointer = buf;
+
+ status = acpi_run_osc(handle, &context);
+ if (ACPI_SUCCESS(status)) {
+ ret = *((u32 *)(context.ret.pointer + 4));
+ if (ret != enable)
+ result = -EPERM;
+ } else
+ result = -EPERM;
+
+ kfree(context.ret.pointer);
+ return result;
+}
+
static ssize_t available_uuids_show(struct device *dev,
struct device_attribute *attr,
char *buf)
@@ -101,6 +130,10 @@ static ssize_t current_uuid_store(struct device *dev,
!(strncmp(buf, int3400_thermal_uuids[i],
sizeof(int3400_thermal_uuids[i]) - 1))) {
priv->current_uuid_index = i;
+
+ // HACK(andrew): on recommendation of mjg59
+ int3400_thermal_run_osc(priv->adev->handle, i, true);
+
return count;
}
}
@@ -168,35 +201,6 @@ static int int3400_thermal_get_uuids(struct int3400_thermal_priv *priv)
return result;
}
-static int int3400_thermal_run_osc(acpi_handle handle,
- enum int3400_thermal_uuid uuid, bool enable)
-{
- u32 ret, buf[2];
- acpi_status status;
- int result = 0;
- struct acpi_osc_context context = {
- .uuid_str = int3400_thermal_uuids[uuid],
- .rev = 1,
- .cap.length = 8,
- };
-
- buf[OSC_QUERY_DWORD] = 0;
- buf[OSC_SUPPORT_DWORD] = enable;
-
- context.cap.pointer = buf;
-
- status = acpi_run_osc(handle, &context);
- if (ACPI_SUCCESS(status)) {
- ret = *((u32 *)(context.ret.pointer + 4));
- if (ret != enable)
- result = -EPERM;
- } else
- result = -EPERM;
-
- kfree(context.ret.pointer);
- return result;
-}
-
static void int3400_notify(acpi_handle handle,
u32 event,
void *data)
@andrew-d
Copy link
Author

andrew-d commented Sep 10, 2018

Then, echo 3A95C389-E4B8-4629-A526-C52C88626BAE > /sys/devices/platform/INT3400\:00/uuids/current_uuid to trigger the active policy, which should reset the thermal trip temperature. Can confirm with rdmsr -a -f 29:24 -d 0x1a2. Before changing anything, it should show 20; after, 3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment