acpi_get_table(char *signature,
u32 instance, struct acpi_table_header ** out_table)
这个函数用于获取指定名称的acpi 表
其用法如下:
struct acpi_table_lpit *lpit;
#通过形参ACPI_SIG_LPIT 指定要当前要读取的acpi表示#define ACPI_SIG_LPIT "LPIT" /* Low Power Idle Table */当前要读取的表示LPIT,最后会将表头指针保存在形参lpit中
status = acpi_get_table(ACPI_SIG_LPIT, 0, (struct acpi_table_header **)&lpit);
if (ACPI_FAILURE(status))
return;
其源码分析如下:
acpi_status
acpi_get_table(char *signature,
u32 instance, struct acpi_table_header ** out_table)
{
u32 i;
u32 j;
acpi_status status = AE_NOT_FOUND;
struct acpi_table_desc *table_desc;
/* Parameter validation */
#要读取acpi表的表头和最后保存表头的指针不能同时为null,否则就没啥意义
if (!signature || !out_table) {
return (AE_BAD_PARAMETER);
}
/*
* Note that the following line is required by some OSPMs, they only
* check if the returned table is NULL instead of the returned status
* to determined if this function is succeeded.
*/
#指针值清零
*out_table = NULL;
(void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
/* Walk the root table list */
#遍历acpi表,从这里可以知道所有的acpi表都是保存在acpi_gbl_root_table_list 中
for (i = 0, j = 0; i < acpi_gbl_root_table_list.current_table_count;
i++) {
table_desc = &acpi_gbl_root_table_list.tables[i];
#这里的signature 就说表的名字,这里就是通过比较是否名字是否相等
if (!ACPI_COMPARE_NAME(&table_desc->signature, signature)) {
continue;
}
#可以看到可以存在同名的表,例如可以同时存在两个name为LPIT的表,我可以指定读取第几个
if (++j < instance) {
continue;
}
#获得这个表头指针,将结果保存在out_table中
status = acpi_tb_get_table(table_desc, out_table);
break;
}
(void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
return (status);
}
acpi_tb_get_table 的实现如下:
acpi_tb_get_table(struct acpi_table_desc *table_desc,
struct acpi_table_header **out_table)
{
acpi_status status;
ACPI_FUNCTION_TRACE(acpi_tb_get_table);
#检查这个表是否有效
if (table_desc->validation_count == 0) {
/* Table need to be "VALIDATED" */
status = acpi_tb_validate_table(table_desc);
if (ACPI_FAILURE(status)) {
return_ACPI_STATUS(status);
}
}
if (table_desc->validation_count < ACPI_MAX_TABLE_VALIDATIONS) {
table_desc->validation_count++;
/*
* Detect validation_count overflows to ensure that the warning
* message will only be printed once.
*/
if (table_desc->validation_count >= ACPI_MAX_TABLE_VALIDATIONS) {
ACPI_WARNING((AE_INFO,
"Table %p, Validation count overflows\n",
table_desc));
}
}
保存这个表的指针
*out_table = table_desc->pointer;
return_ACPI_STATUS(AE_OK);
}
内核ACPI函数API之acpi_get_table
最新推荐文章于 2023-01-07 14:09:30 发布