acpi_thermal: implement B_GET_DEVICE_NAME

Get the name from the _STR method of the ACPI object.
Convert from UTF16 as needed.

In cases where the ACPI implementation provides multiple zones, this
allows to differenciate them.

Change-Id: If349207dcfd22cc9c3baf50b8f8d63d56dc62f21
Reviewed-on: https://review.haiku-os.org/c/haiku/+/9739
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
PulkoMandy
2025-10-27 12:48:11 +00:00
committed by Adrien Destugues
parent f80d1b0293
commit b543cfa664
2 changed files with 49 additions and 9 deletions
@@ -1,5 +1,7 @@
SubDir HAIKU_TOP src add-ons kernel drivers power acpi_thermal ;
UsePrivateKernelHeaders ;
KernelAddon acpi_thermal :
acpi_thermal.c
;
@@ -17,6 +17,9 @@
#include <stdlib.h>
#include <ACPI.h>
#include <util/convertutf.h>
#include "acpi_thermal.h"
#define ACPI_THERMAL_MODULE_NAME "drivers/power/acpi_thermal/driver_v1"
@@ -156,18 +159,53 @@ status_t
acpi_thermal_control(void* _cookie, uint32 op, void* arg, size_t len)
{
acpi_thermal_device_info* device = (acpi_thermal_device_info*)_cookie;
status_t err = B_ERROR;
acpi_thermal_type* att = NULL;
acpi_object_type object;
acpi_data buffer;
buffer.pointer = &object;
buffer.length = sizeof(object);
status_t err = B_DEV_INVALID_IOCTL;
switch (op) {
case B_GET_DEVICE_NAME: {
acpi_data buffer;
buffer.pointer = NULL;
buffer.length = ACPI_ALLOCATE_BUFFER;
err = device->acpi->evaluate_method (device->acpi_cookie, "_STR",
NULL, &buffer);
if (err != B_OK) {
dprintf("acpi_thermal: could not get zone name: %s\n", strerror(err));
free(buffer.pointer);
break;
}
acpi_object_type* object = (acpi_object_type*)buffer.pointer;
if (object->object_type == ACPI_TYPE_STRING) {
err = user_strlcpy((char*)arg, object->string.string, min(object->string.len, len));
free(buffer.pointer);
} else if (object->object_type == ACPI_TYPE_BUFFER) {
char utf8[256];
ssize_t bytes = utf16le_to_utf8(object->buffer.buffer, object->buffer.length / 2,
utf8, sizeof(utf8));
free(buffer.pointer);
if (bytes < 0) {
err = bytes;
break;
}
err = user_strlcpy((char*)arg, utf8, min((size_t)bytes, len));
}
if (err > 0)
err = B_OK;
break;
}
case drvOpGetThermalType: {
acpi_object_type object;
acpi_thermal_type* att = NULL;
acpi_data buffer;
buffer.pointer = &object;
buffer.length = sizeof(object);
att = (acpi_thermal_type*)arg;
// Read basic temperature thresholds.