in acpica/nsaccess.c [34:254]
acpi_status acpi_ns_root_initialize(void)
{
acpi_status status;
const struct acpi_predefined_names *init_val = NULL;
struct acpi_namespace_node *new_node;
struct acpi_namespace_node *prev_node = NULL;
union acpi_operand_object *obj_desc;
acpi_string val = NULL;
ACPI_FUNCTION_TRACE(ns_root_initialize);
status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
if (ACPI_FAILURE(status)) {
return_ACPI_STATUS(status);
}
/*
* The global root ptr is initially NULL, so a non-NULL value indicates
* that acpi_ns_root_initialize() has already been called; just return.
*/
if (acpi_gbl_root_node) {
status = AE_OK;
goto unlock_and_exit;
}
/*
* Tell the rest of the subsystem that the root is initialized
* (This is OK because the namespace is locked)
*/
acpi_gbl_root_node = &acpi_gbl_root_node_struct;
/* Enter the predefined names in the name table */
ACPI_DEBUG_PRINT((ACPI_DB_INFO,
"Entering predefined entries into namespace\n"));
/*
* Create the initial (default) namespace.
* This namespace looks like something similar to this:
*
* ACPI Namespace (from Namespace Root):
* 0 _GPE Scope 00203160 00
* 0 _PR_ Scope 002031D0 00
* 0 _SB_ Device 00203240 00 Notify Object: 0020ADD8
* 0 _SI_ Scope 002032B0 00
* 0 _TZ_ Device 00203320 00
* 0 _REV Integer 00203390 00 = 0000000000000002
* 0 _OS_ String 00203488 00 Len 14 "Microsoft Windows NT"
* 0 _GL_ Mutex 00203580 00 Object 002035F0
* 0 _OSI Method 00203678 00 Args 1 Len 0000 Aml 00000000
*/
for (init_val = acpi_gbl_pre_defined_names; init_val->name; init_val++) {
status = AE_OK;
/* _OSI is optional for now, will be permanent later */
if (!strcmp(init_val->name, "_OSI")
&& !acpi_gbl_create_osi_method) {
continue;
}
/*
* Create, init, and link the new predefined name
* Note: No need to use acpi_ns_lookup here because all the
* predefined names are at the root level. It is much easier to
* just create and link the new node(s) here.
*/
new_node =
acpi_ns_create_node(*ACPI_CAST_PTR(u32, init_val->name));
if (!new_node) {
status = AE_NO_MEMORY;
goto unlock_and_exit;
}
new_node->descriptor_type = ACPI_DESC_TYPE_NAMED;
new_node->type = init_val->type;
if (!prev_node) {
acpi_gbl_root_node_struct.child = new_node;
} else {
prev_node->peer = new_node;
}
new_node->parent = &acpi_gbl_root_node_struct;
prev_node = new_node;
/*
* Name entered successfully. If entry in pre_defined_names[] specifies
* an initial value, create the initial value.
*/
if (init_val->val) {
status = acpi_os_predefined_override(init_val, &val);
if (ACPI_FAILURE(status)) {
ACPI_ERROR((AE_INFO,
"Could not override predefined %s",
init_val->name));
}
if (!val) {
val = init_val->val;
}
/*
* Entry requests an initial value, allocate a
* descriptor for it.
*/
obj_desc =
acpi_ut_create_internal_object(init_val->type);
if (!obj_desc) {
status = AE_NO_MEMORY;
goto unlock_and_exit;
}
/*
* Convert value string from table entry to
* internal representation. Only types actually
* used for initial values are implemented here.
*/
switch (init_val->type) {
case ACPI_TYPE_METHOD:
obj_desc->method.param_count =
(u8) ACPI_TO_INTEGER(val);
obj_desc->common.flags |= AOPOBJ_DATA_VALID;
#if defined (ACPI_ASL_COMPILER)
/* Save the parameter count for the iASL compiler */
new_node->value = obj_desc->method.param_count;
#else
/* Mark this as a very SPECIAL method (_OSI) */
obj_desc->method.info_flags =
ACPI_METHOD_INTERNAL_ONLY;
obj_desc->method.dispatch.implementation =
acpi_ut_osi_implementation;
#endif
break;
case ACPI_TYPE_INTEGER:
obj_desc->integer.value = ACPI_TO_INTEGER(val);
break;
case ACPI_TYPE_STRING:
/* Build an object around the static string */
obj_desc->string.length = (u32)strlen(val);
obj_desc->string.pointer = val;
obj_desc->common.flags |= AOPOBJ_STATIC_POINTER;
break;
case ACPI_TYPE_MUTEX:
obj_desc->mutex.node = new_node;
obj_desc->mutex.sync_level =
(u8) (ACPI_TO_INTEGER(val) - 1);
/* Create a mutex */
status =
acpi_os_create_mutex(&obj_desc->mutex.
os_mutex);
if (ACPI_FAILURE(status)) {
acpi_ut_remove_reference(obj_desc);
goto unlock_and_exit;
}
/* Special case for ACPI Global Lock */
if (strcmp(init_val->name, "_GL_") == 0) {
acpi_gbl_global_lock_mutex = obj_desc;
/* Create additional counting semaphore for global lock */
status =
acpi_os_create_semaphore(1, 0,
&acpi_gbl_global_lock_semaphore);
if (ACPI_FAILURE(status)) {
acpi_ut_remove_reference
(obj_desc);
goto unlock_and_exit;
}
}
break;
default:
ACPI_ERROR((AE_INFO,
"Unsupported initial type value 0x%X",
init_val->type));
acpi_ut_remove_reference(obj_desc);
obj_desc = NULL;
continue;
}
/* Store pointer to value descriptor in the Node */
status = acpi_ns_attach_object(new_node, obj_desc,
obj_desc->common.type);
/* Remove local reference to the object */
acpi_ut_remove_reference(obj_desc);
}
}
unlock_and_exit:
(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
/* Save a handle to "_GPE", it is always present */
if (ACPI_SUCCESS(status)) {
status = acpi_ns_get_node(NULL, "\\_GPE", ACPI_NS_NO_UPSEARCH,
&acpi_gbl_fadt_gpe_device);
}
return_ACPI_STATUS(status);
}