内核ACPI函数API之acpi_get_table

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);
}

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值