内核ACPI函数API之acpi_os_execute

12人阅读 评论(0) 收藏 举报
分类:
acpi_status acpi_os_execute(acpi_execute_type type,
			    acpi_osd_exec_callback function, void *context)
这个函数主要作用是执行形参的callback函数,根据type的不同可以选择不同的queue来执行
acpi_status acpi_os_execute(acpi_execute_type type,
			    acpi_osd_exec_callback function, void *context)
{
	acpi_status status = AE_OK;
	struct acpi_os_dpc *dpc;
	struct workqueue_struct *queue;
	int ret;
	ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
			  "Scheduling function [%p(%p)] for deferred execution.\n",
			  function, context));
	#一般用于debug
	if (type == OSL_DEBUGGER_MAIN_THREAD) {
		ret = acpi_debugger_create_thread(function, context);
		if (ret) {
			pr_err("Call to kthread_create() failed.\n");
			status = AE_ERROR;
		}
		goto out_thread;
	}

	/*
	 * Allocate/initialize DPC structure.  Note that this memory will be
	 * freed by the callee.  The kernel handles the work_struct list  in a
	 * way that allows us to also free its memory inside the callee.
	 * Because we may want to schedule several tasks with different
	 * parameters we can't use the approach some kernel code uses of
	 * having a static work_struct.
	 */
	#申请一个acpi_os_dpc 结构,用于保存要执行的callback和参数
	dpc = kzalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC);
	if (!dpc)
		return AE_NO_MEMORY;

	dpc->function = function;
	dpc->context = context;

	/*
	 * To prevent lockdep from complaining unnecessarily, make sure that
	 * there is a different static lockdep key for each workqueue by using
	 * INIT_WORK() for each of them separately.
	 */
	 #根据不同的type,可以选择不同的queue 来执行
	if (type == OSL_NOTIFY_HANDLER) {
	#根据type给queue赋值,并初始化要执行的队列
		queue = kacpi_notify_wq;
		INIT_WORK(&dpc->work, acpi_os_execute_deferred);
	} else if (type == OSL_GPE_HANDLER) {
		queue = kacpid_wq;
		INIT_WORK(&dpc->work, acpi_os_execute_deferred);
	} else {
		pr_err("Unsupported os_execute type %d.\n", type);
		status = AE_ERROR;
	}

	if (ACPI_FAILURE(status))
		goto err_workqueue;

	/*
	 * On some machines, a software-initiated SMI causes corruption unless
	 * the SMI runs on CPU 0.  An SMI can be initiated by any AML, but
	 * typically it's done in GPE-related methods that are run via
	 * workqueues, so we can avoid the known corruption cases by always
	 * queueing on CPU 0.
	 */
	 #执行这个queue
	ret = queue_work_on(0, queue, &dpc->work);
	if (!ret) {
		printk(KERN_ERR PREFIX
			  "Call to queue_work() failed.\n");
		status = AE_ERROR;
	}
err_workqueue:
	if (ACPI_FAILURE(status))
		kfree(dpc);
out_thread:
	return status;
}

查看评论

内核ACPI函数API之acpi_is_root_bridge

acpi_is_root_bridge 用于判断一个形参的acpi_handle 是否是root bridge 其源码分析如下: int acpi_is_root_bridge(acpi_handle...
  • tiantao2012
  • tiantao2012
  • 2018-04-16 08:28:13
  • 11

内核ACPI函数API之acpi_os_map_iomem

void __iomem *__ref acpi_os_map_iomem(acpi_physical_address phys, acpi_size size) 的作用是将形参指定的物理地址的范围映...
  • tiantao2012
  • tiantao2012
  • 2018-04-03 08:20:17
  • 10

内核ACPI函数API之acpi_pci_find_root

acpi_pci_find_root 函数根据形参的handle返回对应的pci root bridge 其源码分析如下: struct acpi_pci_root *acpi_pci_fin...
  • tiantao2012
  • tiantao2012
  • 2018-04-16 09:34:27
  • 9

内核ACPI函数API之acpi_reboot

acpi_reboot 这个函数用于写pci/io/memory的相关寄存器让其重启 其源码分析如下: void acpi_reboot(void) { struct acpi_generic_...
  • tiantao2012
  • tiantao2012
  • 2018-04-17 08:30:06
  • 7

内核ACPI函数API之acpi_create_platform_device

acpi_create_platform_device 这个函数会为没有platform_driver 自动创建platform_device设备。只有当用户只调用register_platform_...
  • tiantao2012
  • tiantao2012
  • 2018-04-08 08:45:04
  • 9

内核ACPI函数API之acpi_get_first_physical_node

acpi_get_first_physical_node 这个函数用于获取acpi_device的第一个物理节点。 其源码分析如下: struct device *acpi_get_first_phy...
  • tiantao2012
  • tiantao2012
  • 2018-04-11 08:28:21
  • 12

内核ACPI函数API之acpi_os_unmap_iomem

acpi_os_unmap_iomem函数用于释放acpi_os_map_iomem 映射的虚拟地址 其源码分析如下: void __ref acpi_os_unmap_iomem(void __i...
  • tiantao2012
  • tiantao2012
  • 2018-04-03 08:21:07
  • 12

内核ACPI函数API之acpi_execute_simple_method

acpi_status acpi_execute_simple_method(acpi_handle handle, char *method, u64 arg) 这个函数用于执...
  • tiantao2012
  • tiantao2012
  • 2018-04-10 08:40:57
  • 12

内核ACPI函数API之acpi_dev_get_resources

acpi_dev_get_resources 用于获取形参指定的acpi_device 所有的资源,这里的资源包括 memory/io/interrupt等 部分资源定义如下: #define IOR...
  • tiantao2012
  • tiantao2012
  • 2018-04-02 09:50:07
  • 18

内核ACPI函数API之acpi_scan_add_handler

int acpi_scan_add_handler(struct acpi_scan_handler *handler)用于将一个acpi handler添加到acpi_scan_handlers_l...
  • tiantao2012
  • tiantao2012
  • 2018-04-09 08:29:15
  • 9
    个人资料
    持之以恒
    等级:
    访问量: 37万+
    积分: 1万+
    排名: 810
    最新评论