📄 nsxfeval.c
字号:
* Context - Passed to user function * return_value - Location where return value of * user_function is put if terminated early * * RETURNS Return value from the user_function if terminated early. * Otherwise, returns NULL. * * DESCRIPTION: Performs a modified depth-first walk of the namespace tree, * starting (and ending) at the object specified by start_handle. * The user_function is called whenever an object that matches * the type parameter is found. If the user function returns * a non-zero value, the search is terminated immediately and this * value is returned to the caller. * * The point of this procedure is to provide a generic namespace * walk routine that can be called from multiple places to * provide multiple services; the User Function can be tailored * to each task, whether it is a print function, a compare * function, etc. * ******************************************************************************/acpi_statusacpi_walk_namespace(acpi_object_type type, acpi_handle start_object, u32 max_depth, acpi_walk_callback user_function, void *context, void **return_value){ acpi_status status; ACPI_FUNCTION_TRACE("acpi_walk_namespace"); /* Parameter validation */ if ((type > ACPI_TYPE_EXTERNAL_MAX) || (!max_depth) || (!user_function)) { return_ACPI_STATUS(AE_BAD_PARAMETER); } /* * Lock the namespace around the walk. * The namespace will be unlocked/locked around each call * to the user function - since this function * must be allowed to make Acpi calls itself. */ status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } status = acpi_ns_walk_namespace(type, start_object, max_depth, ACPI_NS_WALK_UNLOCK, user_function, context, return_value); (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); return_ACPI_STATUS(status);}EXPORT_SYMBOL(acpi_walk_namespace);/******************************************************************************* * * FUNCTION: acpi_ns_get_device_callback * * PARAMETERS: Callback from acpi_get_device * * RETURN: Status * * DESCRIPTION: Takes callbacks from walk_namespace and filters out all non- * present devices, or if they specified a HID, it filters based * on that. * ******************************************************************************/static acpi_statusacpi_ns_get_device_callback(acpi_handle obj_handle, u32 nesting_level, void *context, void **return_value){ struct acpi_get_devices_info *info = context; acpi_status status; struct acpi_namespace_node *node; u32 flags; struct acpi_device_id hid; struct acpi_compatible_id_list *cid; acpi_native_uint i; status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); if (ACPI_FAILURE(status)) { return (status); } node = acpi_ns_map_handle_to_node(obj_handle); status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); if (ACPI_FAILURE(status)) { return (status); } if (!node) { return (AE_BAD_PARAMETER); } /* Run _STA to determine if device is present */ status = acpi_ut_execute_STA(node, &flags); if (ACPI_FAILURE(status)) { return (AE_CTRL_DEPTH); } if (!(flags & 0x01)) { /* Don't return at the device or children of the device if not there */ return (AE_CTRL_DEPTH); } /* Filter based on device HID & CID */ if (info->hid != NULL) { status = acpi_ut_execute_HID(node, &hid); if (status == AE_NOT_FOUND) { return (AE_OK); } else if (ACPI_FAILURE(status)) { return (AE_CTRL_DEPTH); } if (ACPI_STRNCMP(hid.value, info->hid, sizeof(hid.value)) != 0) { /* Get the list of Compatible IDs */ status = acpi_ut_execute_CID(node, &cid); if (status == AE_NOT_FOUND) { return (AE_OK); } else if (ACPI_FAILURE(status)) { return (AE_CTRL_DEPTH); } /* Walk the CID list */ for (i = 0; i < cid->count; i++) { if (ACPI_STRNCMP(cid->id[i].value, info->hid, sizeof(struct acpi_compatible_id)) != 0) { ACPI_MEM_FREE(cid); return (AE_OK); } } ACPI_MEM_FREE(cid); } } status = info->user_function(obj_handle, nesting_level, info->context, return_value); return (status);}/******************************************************************************* * * FUNCTION: acpi_get_devices * * PARAMETERS: HID - HID to search for. Can be NULL. * user_function - Called when a matching object is found * Context - Passed to user function * return_value - Location where return value of * user_function is put if terminated early * * RETURNS Return value from the user_function if terminated early. * Otherwise, returns NULL. * * DESCRIPTION: Performs a modified depth-first walk of the namespace tree, * starting (and ending) at the object specified by start_handle. * The user_function is called whenever an object of type * Device is found. If the user function returns * a non-zero value, the search is terminated immediately and this * value is returned to the caller. * * This is a wrapper for walk_namespace, but the callback performs * additional filtering. Please see acpi_get_device_callback. * ******************************************************************************/acpi_statusacpi_get_devices(char *HID, acpi_walk_callback user_function, void *context, void **return_value){ acpi_status status; struct acpi_get_devices_info info; ACPI_FUNCTION_TRACE("acpi_get_devices"); /* Parameter validation */ if (!user_function) { return_ACPI_STATUS(AE_BAD_PARAMETER); } /* * We're going to call their callback from OUR callback, so we need * to know what it is, and their context parameter. */ info.context = context; info.user_function = user_function; info.hid = HID; /* * Lock the namespace around the walk. * The namespace will be unlocked/locked around each call * to the user function - since this function * must be allowed to make Acpi calls itself. */ status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } status = acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK, acpi_ns_get_device_callback, &info, return_value); (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); return_ACPI_STATUS(status);}EXPORT_SYMBOL(acpi_get_devices);/******************************************************************************* * * FUNCTION: acpi_attach_data * * PARAMETERS: obj_handle - Namespace node * Handler - Handler for this attachment * Data - Pointer to data to be attached * * RETURN: Status * * DESCRIPTION: Attach arbitrary data and handler to a namespace node. * ******************************************************************************/acpi_statusacpi_attach_data(acpi_handle obj_handle, acpi_object_handler handler, void *data){ struct acpi_namespace_node *node; acpi_status status; /* Parameter validation */ if (!obj_handle || !handler || !data) { return (AE_BAD_PARAMETER); } status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); if (ACPI_FAILURE(status)) { return (status); } /* Convert and validate the handle */ node = acpi_ns_map_handle_to_node(obj_handle); if (!node) { status = AE_BAD_PARAMETER; goto unlock_and_exit; } status = acpi_ns_attach_data(node, handler, data); unlock_and_exit: (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); return (status);}/******************************************************************************* * * FUNCTION: acpi_detach_data * * PARAMETERS: obj_handle - Namespace node handle * Handler - Handler used in call to acpi_attach_data * * RETURN: Status * * DESCRIPTION: Remove data that was previously attached to a node. * ******************************************************************************/acpi_statusacpi_detach_data(acpi_handle obj_handle, acpi_object_handler handler){ struct acpi_namespace_node *node; acpi_status status; /* Parameter validation */ if (!obj_handle || !handler) { return (AE_BAD_PARAMETER); } status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); if (ACPI_FAILURE(status)) { return (status); } /* Convert and validate the handle */ node = acpi_ns_map_handle_to_node(obj_handle); if (!node) { status = AE_BAD_PARAMETER; goto unlock_and_exit; } status = acpi_ns_detach_data(node, handler); unlock_and_exit: (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); return (status);}/******************************************************************************* * * FUNCTION: acpi_get_data * * PARAMETERS: obj_handle - Namespace node * Handler - Handler used in call to attach_data * Data - Where the data is returned * * RETURN: Status * * DESCRIPTION: Retrieve data that was previously attached to a namespace node. * ******************************************************************************/acpi_statusacpi_get_data(acpi_handle obj_handle, acpi_object_handler handler, void **data){ struct acpi_namespace_node *node; acpi_status status; /* Parameter validation */ if (!obj_handle || !handler || !data) { return (AE_BAD_PARAMETER); } status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); if (ACPI_FAILURE(status)) { return (status); } /* Convert and validate the handle */ node = acpi_ns_map_handle_to_node(obj_handle); if (!node) { status = AE_BAD_PARAMETER; goto unlock_and_exit; } status = acpi_ns_get_attached_data(node, handler, data); unlock_and_exit: (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); return (status);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -