acpi: add device tree attributes from _CLS if available

means B_DEVICE_TYPE, B_DEVICE_SUB_TYPE, B_DEVICE_INTERFACE.
_CLS is rare, it means I don't own devices with this attribute.

from the spec: _CLS:
Class Code – supplies OSPM with the PCI-defined class, subclass and programming interface for a device. Optional.

Change-Id: I4f7b7ed66cbe6b4ff4511cb13df2af218350a5d8
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7210
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
This commit is contained in:
Jérôme Duval 2023-12-17 10:56:10 +01:00
parent 53f146bc7d
commit e2f1a42ea9
6 changed files with 30 additions and 8 deletions

View File

@ -253,7 +253,7 @@ struct acpi_module_info {
size_t resultLength);
status_t (*get_device_info)(const char *path, char** hid,
char** cidList, size_t cidListLength, char** uid);
char** cidList, size_t cidListLength, char** uid, char** cls);
uint32 (*get_object_type)(const char *path);
status_t (*get_object)(const char *path,
acpi_object_type **_returnValue);

View File

@ -116,7 +116,7 @@ typedef struct acpi_root_info {
size_t resultLength);
status_t (*get_device_info)(const char *path, char **hid,
char** cidList, size_t cidListCount, char** uid);
char** cidList, size_t cidListCount, char** uid, char** cls);
uint32 (*get_object_type)(const char *path);
status_t (*get_object)(const char *path,
acpi_object_type **_returnValue);
@ -219,7 +219,7 @@ status_t get_device(const char* hid, uint32 index, char* result,
size_t resultLength);
status_t get_device_info(const char* path, char** hid, char** cidList,
size_t cidListCount, char** uniqueId);
size_t cidListCount, char** uniqueId, char** cls);
status_t get_device_addr(const char* path, uint32* addr);
uint32 get_object_type(const char* path);
status_t get_object(const char* path, acpi_object_type** _returnValue);

View File

@ -525,7 +525,7 @@ get_device(const char* hid, uint32 index, char* result, size_t resultLength)
status_t
get_device_info(const char *path, char** hid, char** cidList,
size_t cidListCount, char** uid)
size_t cidListCount, char** uid, char** cls)
{
ACPI_HANDLE handle;
ACPI_DEVICE_INFO *info;
@ -552,6 +552,11 @@ get_device_info(const char *path, char** hid, char** cidList,
if ((info->Valid & ACPI_VALID_UID) != 0 && uid != NULL)
*uid = strndup(info->UniqueId.String, info->UniqueId.Length);
if ((info->Valid & ACPI_VALID_CLS) != 0 && cls != NULL
&& info->ClassCode.Length >= ACPI_PCICLS_STRING_SIZE) {
*cls = strndup(info->ClassCode.String, info->ClassCode.Length);
}
AcpiOsFree(info);
return B_OK;
}

View File

@ -101,11 +101,12 @@ acpi_enumerate_child_devices(device_node* node, const char* root)
uint32 attrCount = 4;
char* hid = NULL;
char* cidList[8] = { NULL };
char* cidList[11] = { NULL };
char* uid = NULL;
char* cls = NULL;
if (type == ACPI_TYPE_DEVICE) {
if (get_device_info(result, &hid, (char**)&cidList, 8,
&uid) == B_OK) {
&uid, &cls) == B_OK) {
if (hid != NULL) {
attrs[attrCount].name = ACPI_DEVICE_HID_ITEM;
attrs[attrCount].type = B_STRING_TYPE;
@ -124,6 +125,21 @@ acpi_enumerate_child_devices(device_node* node, const char* root)
attrs[attrCount].value.string = uid;
attrCount++;
}
if (cls != NULL) {
uint32 clsClass = strtoul(cls, NULL, 16);
attrs[attrCount].name = B_DEVICE_TYPE;
attrs[attrCount].type = B_UINT16_TYPE;
attrs[attrCount].value.ui16 = (clsClass >> 16) & 0xff ;
attrCount++;
attrs[attrCount].name = B_DEVICE_SUB_TYPE;
attrs[attrCount].type = B_UINT16_TYPE;
attrs[attrCount].value.ui16 = (clsClass >> 8) & 0xff ;
attrCount++;
attrs[attrCount].name = B_DEVICE_INTERFACE;
attrs[attrCount].type = B_UINT16_TYPE;
attrs[attrCount].value.ui16 = (clsClass >> 0) & 0xff ;
attrCount++;
}
}
uint32 addr;
if (get_device_addr(result, &addr) == B_OK) {
@ -138,6 +154,7 @@ acpi_enumerate_child_devices(device_node* node, const char* root)
ACPI_DEVICE_MODULE_NAME, attrs, NULL, &deviceNode);
free(hid);
free(uid);
free(cls);
for (int i = 0; cidList[i] != NULL; i++)
free(cidList[i]);
if (status != B_OK)

View File

@ -114,7 +114,7 @@ dump_acpi_namespace(acpi_ns_device_info *device, char *root, int indenting)
case ACPI_TYPE_DEVICE:
{
char* hid = NULL;
device->acpi->get_device_info(result, &hid, NULL, 0, NULL);
device->acpi->get_device_info(result, &hid, NULL, 0, NULL, NULL);
strlcat(output, " DEVICE (", sizeof(output));
if (hid != NULL) {
strlcat(output, hid, sizeof(output));

View File

@ -338,7 +338,7 @@ pch_i2c_scan_bus_callback(acpi_handle object, uint32 nestingLevel,
char* hid = NULL;
char* cidList[8] = { NULL };
status = gACPI->get_device_info((const char*)buffer.pointer, &hid,
(char**)&cidList, 8, NULL);
(char**)&cidList, 8, NULL, NULL);
if (status != B_OK) {
ERROR("pch_i2c_scan_bus_callback get_device_info failed\n");
return status;