以下是DSDT表中的一段描述,使用acpi_evaluate_object函数对clock-frequence进行解析
Name (_DSD, Package (0x02) // _DSD: Device-Specific Data
{
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301") /* Device Properties for _DSD */,
Package (0x02)
{
Package (0x02)
{
"clock-frequency",
0x00061A80
},
Package (0x02)
{
"clocks",
Package (0x01)
{
"\\_SB.CLK2"
}
}
}
})
解析模板如下:
1)先调用函数获取代码中obj->type的类型;
2)根据类型值判断有多少个元素;
3)按照以上思路对返回值进行一级一级展开,开发者需要熟悉union acpi_object的类型即可
struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER };
acpi_handle handle = ACPI_HANDLE(&pdev->dev);
union acpi_object *obj;
if (ACPI_FAILURE(acpi_evaluate_object(handle, "_DSD", NULL, &buf)))
{
return;
}
else
{
obj = (union acpi_object *)buf.pointer;
if (obj->type == ACPI_TYPE_PACKAGE)
{
dbg_show("obj->package.count:%d",obj->package.count);
dbg_show("obj->package.elements[0].type:%d\n",obj->package.elements[0].type);
dbg_show("obj->package.elements[0].buffer.pointer:%s\n",obj->package.elements[0].buffer.pointer);
dbg_show("obj->package.elements[1].type:%d\n",obj->package.elements[1].type);
dbg_show("obj->package.elements[1].package.count:%d\n",obj->package.elements[1].package.count);
dbg_show("obj->package.elements[1].package.elements[0].type:%d\n",obj->package.elements[1].package.elements[0].type);
dbg_show("obj->package.elements[1].package.elements[0].package.count:%d\n",obj->package.elements[1].package.elements[0].package.count);
dbg_show("obj->package.elements[1].package.elements[0].package.elements[0].type:%d\n",obj->package.elements[1].package.elements[0].package.elements[0].type);
dbg_show("obj->package.elements[1].package.elements[0].package.elements[1].type:%d\n",obj->package.elements[1].package.elements[0].package.elements[1].type);
dbg_show("obj->package.elements[1].package.elements[1].type:%d\n",obj->package.elements[1].package.elements[1].type);
dbg_show("obj->package.elements[1].package.elements[1].package.count:%d\n",obj->package.elements[1].package.elements[1].package.count);
dbg_show("obj->package.elements[1].package.elements[1].package.elements[0].type:%d\n",obj->package.elements[1].package.elements[1].package.elements[0].type);
dbg_show("obj->package.elements[1].package.elements[1].package.elements[1].type:%d\n",obj->package.elements[1].package.elements[1].package.elements[1].type);
}
return;
}