void * _cm_callocate ( u32 size, u32 component, NATIVE_CHAR *module, u32 line) { void *address = NULL; DEBUG_ONLY_MEMBERS (\ ACPI_STATUS status) /* Check for an inadvertent size of zero bytes */ if (!size) { _REPORT_ERROR (module, line, component, ("Cm_callocate: Attempt to allocate zero bytes\n")); return (NULL); } address = acpi_os_callocate (size); if (!address) { /* Report allocation error */ _REPORT_ERROR (module, line, component, ("Cm_callocate: Could not allocate size %X\n", size)); return (NULL); } return (address); }
acpi_status bm_pr_print ( BM_POWER_RESOURCE *pr) { acpi_buffer buffer; PROC_NAME("bm_pr_print"); if (!pr) { return(AE_BAD_PARAMETER); } buffer.length = 256; buffer.pointer = acpi_os_callocate(buffer.length); if (!buffer.pointer) { return(AE_NO_MEMORY); } acpi_get_name(pr->acpi_handle, ACPI_FULL_PATHNAME, &buffer); acpi_os_printf("Power Resource: found\n"); ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "+------------------------------------------------------------\n")); ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "| Power_resource[%02x]:[%p] %s\n", pr->device_handle, pr->acpi_handle, (char*)buffer.pointer)); ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "| system_level[S%d] resource_order[%d]\n", pr->system_level, pr->resource_order)); ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "| state[D%d] reference_count[%d]\n", pr->state, pr->reference_count)); ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "+------------------------------------------------------------\n")); acpi_os_free(buffer.pointer); return(AE_OK); }
void pr_print ( PR_CONTEXT *processor) { #ifdef ACPI_DEBUG acpi_buffer buffer; FUNCTION_TRACE("pr_print"); buffer.length = 256; buffer.pointer = acpi_os_callocate(buffer.length); if (!buffer.pointer) { return; } /* * Get the full pathname for this ACPI object. */ acpi_get_name(processor->acpi_handle, ACPI_FULL_PATHNAME, &buffer); /* * Print out basic processor information. */ ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "+------------------------------------------------------------\n")); ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "| Processor[%02x]:[%p] uid[%02x] %s\n", processor->device_handle, processor->acpi_handle, processor->uid, (char*)buffer.pointer)); ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "| power: %cC0 %cC1 %cC2[%d] %cC3[%d]\n", (processor->power.state[0].is_valid?'+':'-'), (processor->power.state[1].is_valid?'+':'-'), (processor->power.state[2].is_valid?'+':'-'), processor->power.state[2].latency, (processor->power.state[3].is_valid?'+':'-'), processor->power.state[3].latency)); ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "| performance: states[%d]\n", processor->performance.state_count)); ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "+------------------------------------------------------------\n")); acpi_os_free(buffer.pointer); #endif /* ACPI_DEBUG */ return; }
acpi_status bm_evaluate_object ( acpi_handle handle, acpi_string pathname, acpi_object_list *arguments, acpi_buffer *buffer) { acpi_status status = AE_OK; FUNCTION_TRACE("bm_evaluate_object"); /* If caller provided a buffer it must be unallocated/zero'd. */ if ((buffer) && (buffer->length != 0 || buffer->pointer)) { return_ACPI_STATUS(AE_BAD_PARAMETER); } /* * Evalute Object: * --------------- * The first attempt is just to get the size of the object data * (that is unless there's no return data, e.g. _INI); the second * gets the data. */ status = acpi_evaluate_object(handle, pathname, arguments, buffer); if (ACPI_SUCCESS(status)) { return_ACPI_STATUS(status); } else if ((buffer) && (status == AE_BUFFER_OVERFLOW)) { /* Gotta allocate -- CALLER MUST FREE! */ buffer->pointer = acpi_os_callocate(buffer->length); if (!buffer->pointer) { return_ACPI_STATUS(AE_NO_MEMORY); } /* Re-evaluate -- this time it should work */ status = acpi_evaluate_object(handle, pathname, arguments, buffer); } if (ACPI_FAILURE(status)) { if (status != AE_NOT_FOUND) { DEBUG_EVAL_ERROR(ACPI_LV_WARN, handle, pathname, status); } if (buffer && buffer->pointer) { acpi_os_free(buffer->pointer); buffer->pointer = NULL; buffer->length = 0; } } return_ACPI_STATUS(status); }
void bn_print ( BN_CONTEXT *button) { #ifdef ACPI_DEBUG acpi_buffer buffer; PROC_NAME("bn_print"); if (!button) { return; } buffer.length = 256; buffer.pointer = acpi_os_callocate(buffer.length); if (!buffer.pointer) { return; } /* * Get the full pathname for this ACPI object. */ acpi_get_name(button->acpi_handle, ACPI_FULL_PATHNAME, &buffer); /* * Print out basic button information. */ ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "+------------------------------------------------------------\n")); switch (button->type) { case BN_TYPE_POWER_BUTTON: case BN_TYPE_POWER_BUTTON_FIXED: ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "| Power_button[%02x]:[%p] %s\n", button->device_handle, button->acpi_handle, (char*)buffer.pointer)); break; case BN_TYPE_SLEEP_BUTTON: case BN_TYPE_SLEEP_BUTTON_FIXED: ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "| Sleep_button[%02x]:[%p] %s\n", button->device_handle, button->acpi_handle, (char*)buffer.pointer)); break; case BN_TYPE_LID_SWITCH: ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "| Lid_switch[%02x]:[%p] %s\n", button->device_handle, button->acpi_handle, (char*)buffer.pointer)); break; } ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "+------------------------------------------------------------\n")); acpi_os_free(buffer.pointer); #endif /*ACPI_DEBUG*/ return; }
acpi_status ec_get_port_values( EC_CONTEXT *ec) { acpi_status status = AE_OK; acpi_buffer buffer; acpi_resource *resource = NULL; FUNCTION_TRACE("ec_get_port_values"); if (!ec) { return_ACPI_STATUS(AE_BAD_PARAMETER); } buffer.length = 0; buffer.pointer = NULL; status = acpi_get_current_resources(ec->acpi_handle, &buffer); if (status != AE_BUFFER_OVERFLOW) { return_ACPI_STATUS(status); } buffer.pointer = acpi_os_callocate(buffer.length); if (!buffer.pointer) { return_ACPI_STATUS(AE_NO_MEMORY); } status = acpi_get_current_resources(ec->acpi_handle, &buffer); if (ACPI_FAILURE(status)) { goto end; } resource = (acpi_resource *) buffer.pointer; ec->data_port = resource->data.io.min_base_address; resource = NEXT_RESOURCE(resource); ec->status_port = ec->command_port = resource->data.io.min_base_address; end: acpi_os_free(buffer.pointer); return_ACPI_STATUS(status); }
acpi_status bm_enumerate_fixed_features (void) { FUNCTION_TRACE("bm_enumerate_fixed_features"); /* * Root Object: * ------------ * Fabricate the root object, which happens to always get a * device_handle of zero. */ node_list.nodes[0] = acpi_os_callocate(sizeof(BM_NODE)); if (NULL == (node_list.nodes[0])) { return_ACPI_STATUS(AE_NO_MEMORY); } node_list.nodes[0]->device.handle = BM_HANDLE_ROOT; node_list.nodes[0]->device.acpi_handle = ACPI_ROOT_OBJECT; node_list.nodes[0]->device.flags = BM_FLAGS_UNKNOWN; node_list.nodes[0]->device.status = BM_STATUS_DEFAULT; node_list.nodes[0]->device.id.type = BM_TYPE_SYSTEM; /* TBD: Get system PM capabilities (Sx states?) */ node_list.count++; /* * Fixed Features: * --------------- * Enumerate fixed-feature devices (e.g. power and sleep buttons). */ if (acpi_fadt.pwr_button == 0) { bm_add_fixed_feature_device(node_list.nodes[0], BM_TYPE_FIXED_BUTTON, BM_HID_POWER_BUTTON); } if (acpi_fadt.sleep_button == 0) { bm_add_fixed_feature_device(node_list.nodes[0], BM_TYPE_FIXED_BUTTON, BM_HID_SLEEP_BUTTON); } return_ACPI_STATUS(AE_OK); }
void ec_print ( EC_CONTEXT *ec) { #ifdef ACPI_DEBUG acpi_buffer buffer; #endif /*ACPI_DEBUG*/ PROC_NAME("ec_print"); if (!ec) { return; } acpi_os_printf("EC: found, GPE %d\n", ec->gpe_bit); #ifdef ACPI_DEBUG buffer.length = 256; buffer.pointer = acpi_os_callocate(buffer.length); if (!buffer.pointer) { return; } /* * Get the full pathname for this ACPI object. */ acpi_get_name(ec->acpi_handle, ACPI_FULL_PATHNAME, &buffer); /* * Print out basic thermal zone information. */ ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "+------------------------------------------------------------\n")); ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "| Embedded_controller[%02x]:[%p] %s\n", ec->device_handle, ec->acpi_handle, (char*)buffer.pointer)); ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "| gpe_bit[%02x] status/command_port[%02x] data_port[%02x]\n", ec->gpe_bit, ec->status_port, ec->data_port)); ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "+------------------------------------------------------------\n")); acpi_os_free(buffer.pointer); #endif /*ACPI_DEBUG*/ return; }
int acpi_db_initialize (void) { /* Init globals */ acpi_gbl_db_buffer = acpi_os_callocate (ACPI_DEBUG_BUFFER_SIZE); /* Initial scope is the root */ acpi_gbl_db_scope_buf [0] = '\\'; acpi_gbl_db_scope_buf [1] = 0; /* * If configured for multi-thread support, the debug executor runs in * a separate thread so that the front end can be in another address * space, environment, or even another machine. */ if (acpi_gbl_debugger_configuration & DEBUGGER_MULTI_THREADED) { /* These were created with one unit, grab it */ acpi_ut_acquire_mutex (ACPI_MTX_DEBUG_CMD_COMPLETE); acpi_ut_acquire_mutex (ACPI_MTX_DEBUG_CMD_READY); /* Create the debug execution thread to execute commands */ acpi_os_queue_for_execution (0, acpi_db_execute_thread, NULL); } if (!acpi_gbl_db_opt_verbose) { acpi_gbl_db_disasm_indent = " "; acpi_gbl_db_opt_disasm = TRUE; acpi_gbl_db_opt_stats = FALSE; } return (0); }
acpi_status acpi_os_create_semaphore( u32 max_units, u32 initial_units, acpi_handle *handle) { struct semaphore *sem = NULL; PROC_NAME("acpi_os_create_semaphore"); sem = acpi_os_callocate(sizeof(struct semaphore)); if (!sem) return AE_NO_MEMORY; sema_init(sem, initial_units); *handle = (acpi_handle*)sem; ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Creating semaphore[%p|%d].\n", *handle, initial_units)); return AE_OK; }
void ac_print ( AC_CONTEXT *ac_adapter) { #ifdef ACPI_DEBUG acpi_buffer buffer; PROC_NAME("ac_print"); if (!ac_adapter) { return; } buffer.length = 256; buffer.pointer = acpi_os_callocate(buffer.length); if (!buffer.pointer) { return; } /* * Get the full pathname for this ACPI object. */ acpi_get_name(ac_adapter->acpi_handle, ACPI_FULL_PATHNAME, &buffer); /* * Print out basic adapter information. */ ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "+------------------------------------------------------------\n")); ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "| AC Adapter[%02x]:[%p] %s\n", ac_adapter->device_handle, ac_adapter->acpi_handle, (char*)buffer.pointer)); ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "+------------------------------------------------------------\n")); acpi_os_free(buffer.pointer); #endif /*ACPI_DEBUG*/ return; }
void bm_print_eval_error ( u32 debug_level, acpi_handle handle, acpi_string pathname, acpi_status status) { acpi_buffer buffer; acpi_status local_status; PROC_NAME("bm_print_eval_error"); buffer.length = 256; buffer.pointer = acpi_os_callocate(buffer.length); if (!buffer.pointer) { return; } local_status = acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); if (ACPI_FAILURE(local_status)) { ACPI_DEBUG_PRINT((ACPI_DEBUG_LEVEL(debug_level), "Evaluate object [%p], %s\n", handle, acpi_format_exception(status))); return; } if (pathname) { ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluate object [%s.%s], %s\n", (char*)buffer.pointer, pathname, acpi_format_exception(status))); } else { ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluate object [%s], %s\n", (char*)buffer.pointer, acpi_format_exception(status))); } acpi_os_free(buffer.pointer); }
void bm_print_node ( BM_NODE *node, u32 flags) { #ifdef ACPI_DEBUG acpi_buffer buffer; BM_DEVICE *device = NULL; char *type_string = NULL; PROC_NAME("bm_print_node"); if (!node) { return; } device = &(node->device); if (flags & BM_PRINT_PRESENT) { if (!BM_DEVICE_PRESENT(device)) { return; } } buffer.length = 256; buffer.pointer = acpi_os_callocate(buffer.length); if (!buffer.pointer) { return; } acpi_get_name(device->acpi_handle, ACPI_FULL_PATHNAME, &buffer); switch(device->id.type) { case BM_TYPE_SYSTEM: type_string = " System"; break; case BM_TYPE_SCOPE: type_string = " Scope"; break; case BM_TYPE_PROCESSOR: type_string = " Proc"; break; case BM_TYPE_THERMAL_ZONE: type_string = "Thermal"; break; case BM_TYPE_POWER_RESOURCE: type_string = " Power"; break; case BM_TYPE_FIXED_BUTTON: type_string = " Button"; break; case BM_TYPE_DEVICE: type_string = " Device"; break; default: type_string = "Unknown"; break; } if (!(flags & BM_PRINT_GROUP)) { ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "+-------------------------------------------------------------------------------\n")); } ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "| %s[%02x]:[%p] flags[%02x] hid[%s] %s\n", type_string, device->handle, device->acpi_handle, device->flags, (device->id.hid[0] ? device->id.hid : " "), (char*)buffer.pointer)); if (flags & BM_PRINT_IDENTIFICATION) { ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "| identification: uid[%s] adr[%08x]\n", device->id.uid, device->id.adr)); } if (flags & BM_PRINT_LINKAGE) { ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "| linkage: this[%p] parent[%p] next[%p]\n", node, node->parent, node->next)); ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "| scope.head[%p] scope.tail[%p]\n", node->scope.head, node->scope.tail)); } if (flags & BM_PRINT_POWER) { ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "| power: state[D%d] flags[%08x]\n", device->power.state, device->power.flags)); ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "| S0[%02x] S1[%02x] S2[%02x] S3[%02x] S4[%02x] S5[%02x]\n", device->power.dx_supported[0], device->power.dx_supported[1], device->power.dx_supported[2], device->power.dx_supported[3], device->power.dx_supported[4], device->power.dx_supported[5])); } if (!(flags & BM_PRINT_GROUP)) { ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "+-------------------------------------------------------------------------------\n")); } acpi_os_free(buffer.pointer); #endif /*ACPI_DEBUG*/ return; }
acpi_status bm_osl_generate_event ( BM_HANDLE device_handle, char *device_type, char *device_instance, u32 event_type, u32 event_data) { BM_OSL_EVENT *event = NULL; u32 flags = 0; /* drop event on the floor if no one's listening */ if (!event_is_open) return (AE_OK); /* * Allocate a new event structure. */ event = acpi_os_callocate(sizeof(BM_OSL_EVENT)); if (!event) goto alloc_error; event->device_type = acpi_os_callocate(strlen(device_type) + sizeof(char)); if (!event->device_type) goto alloc_error; event->device_instance = acpi_os_callocate(strlen(device_instance) + sizeof(char)); if (!event->device_instance) goto alloc_error; /* * Set event data. */ event->device_handle = device_handle; strcpy(event->device_type, device_type); strcpy(event->device_instance, device_instance); event->event_type = event_type; event->event_data = event_data; /* * Add to the end of our event list. */ spin_lock_irqsave(&bm_osl_event_lock, flags); list_add_tail(&event->list, &bm_event_list); spin_unlock_irqrestore(&bm_osl_event_lock, flags); /* * Signal waiting threads (if any). */ wake_up_interruptible(&bm_event_wait_queue); return(AE_OK); alloc_error: if (event->device_instance) acpi_os_free(event->device_instance); if (event->device_type) acpi_os_free(event->device_type); if (event) acpi_os_free(event); return (AE_NO_MEMORY); }
acpi_status ec_add_device( BM_HANDLE device_handle, void **context) { acpi_status status = AE_OK; BM_DEVICE *device = NULL; EC_CONTEXT *ec = NULL; u8 gpe_handler = FALSE; u8 space_handler = FALSE; FUNCTION_TRACE("ec_add_device"); ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Adding EC device [%02x].\n", device_handle)); if (!context || *context) { return_ACPI_STATUS(AE_BAD_PARAMETER); } /* * Get information on this device. */ status = bm_get_device_info(device_handle, &device); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* * Allocate a new EC_CONTEXT structure. */ ec = acpi_os_callocate(sizeof(EC_CONTEXT)); if (!ec) { return_ACPI_STATUS(AE_NO_MEMORY); } ec->device_handle = device->handle; ec->acpi_handle = device->acpi_handle; /* * Get the I/O port addresses for the command/status and data ports. */ status = ec_get_port_values(ec); if (ACPI_FAILURE(status)) { goto end; } /* * See if we need to obtain the global lock for EC transactions. */ status = bm_evaluate_simple_integer(ec->acpi_handle, "_GLK", &ec->use_global_lock); if (status == AE_NOT_FOUND) { ec->use_global_lock = 0; } else if (ACPI_FAILURE(status)) { ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "EC _GLK failed\n")); goto end; } /* * Install a handler for servicing this EC's GPE. */ status = ec_install_gpe_handler(ec); if (ACPI_FAILURE(status)) { goto end; } else { gpe_handler = TRUE; } /* * Install a handler for servicing this EC's address space. */ status = ec_install_space_handler(ec); if (ACPI_FAILURE(status)) { goto end; } else { space_handler = TRUE; } /* * Create a semaphore to serialize EC transactions. */ status = acpi_os_create_semaphore(1,1, &(ec->mutex)); if (ACPI_FAILURE(status)) { goto end; } /* * Context now contains information specific to this EC. Note * that we'll get this pointer back on every ec_request() and * ec_notify(). */ *context = ec; ec_print(ec); end: if (ACPI_FAILURE(status)) { if (gpe_handler) { ec_remove_gpe_handler(ec); } if (space_handler) { ec_remove_space_handler(ec); } if (ec->mutex) { acpi_os_delete_semaphore(ec->mutex); } acpi_os_free(ec); } return_ACPI_STATUS(status); }
acpi_status bm_pr_add_device ( BM_HANDLE device_handle, void **context) { acpi_status status = AE_OK; BM_POWER_RESOURCE *pr = NULL; BM_DEVICE *device = NULL; acpi_buffer buffer; acpi_object acpi_object; FUNCTION_TRACE("bm_pr_add_device"); ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Adding power resource [%02x].\n", device_handle)); if (!context || *context) { return_ACPI_STATUS(AE_BAD_PARAMETER); } buffer.length = sizeof(acpi_object); buffer.pointer = &acpi_object; /* * Get information on this device. */ status = bm_get_device_info(device_handle, &device); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* * Allocate a new BM_POWER_RESOURCE structure. */ pr = acpi_os_callocate(sizeof(BM_POWER_RESOURCE)); if (!pr) { return_ACPI_STATUS(AE_NO_MEMORY); } pr->device_handle = device->handle; pr->acpi_handle = device->acpi_handle; /* * Get information on this power resource. */ status = acpi_evaluate_object(pr->acpi_handle, NULL, NULL, &buffer); if (ACPI_FAILURE(status)) { goto end; } pr->system_level = acpi_object.power_resource.system_level; pr->resource_order = acpi_object.power_resource.resource_order; pr->state = ACPI_STATE_UNKNOWN; pr->reference_count = 0; /* * Get the power resource's current state (ON|OFF). */ status = bm_pr_get_state(pr); end: if (ACPI_FAILURE(status)) { acpi_os_free(pr); } else { *context = pr; bm_pr_print(pr); } return_ACPI_STATUS(status); }
acpi_status bn_add_device( BM_HANDLE device_handle, void **context) { acpi_status status = AE_OK; BM_DEVICE *device = NULL; BN_CONTEXT *button = NULL; FUNCTION_TRACE("bn_add_device"); ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Adding button device [%02x].\n", device_handle)); if (!context || *context) { ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid context.\n")); return_ACPI_STATUS(AE_BAD_PARAMETER); } /* * Get information on this device. */ status = bm_get_device_info( device_handle, &device ); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* * Allocate a new BN_CONTEXT structure. */ button = acpi_os_callocate(sizeof(BN_CONTEXT)); if (!button) { return_ACPI_STATUS(AE_NO_MEMORY); } button->device_handle = device->handle; button->acpi_handle = device->acpi_handle; /* * Power Button? * ------------- * Either fixed-feature or generic (namespace) types. */ if (strncmp(device->id.hid, BN_HID_POWER_BUTTON, sizeof(BM_DEVICE_HID)) == 0) { if (device->id.type == BM_TYPE_FIXED_BUTTON) { button->type = BN_TYPE_POWER_BUTTON_FIXED; /* Register for fixed-feature events. */ status = acpi_install_fixed_event_handler( ACPI_EVENT_POWER_BUTTON, bn_notify_fixed, (void*)button); } else { button->type = BN_TYPE_POWER_BUTTON; } } /* * Sleep Button? * ------------- * Either fixed-feature or generic (namespace) types. */ else if (strncmp( device->id.hid, BN_HID_SLEEP_BUTTON, sizeof(BM_DEVICE_HID)) == 0) { if (device->id.type == BM_TYPE_FIXED_BUTTON) { button->type = BN_TYPE_SLEEP_BUTTON_FIXED; /* Register for fixed-feature events. */ status = acpi_install_fixed_event_handler( ACPI_EVENT_SLEEP_BUTTON, bn_notify_fixed, (void*)button); } else { button->type = BN_TYPE_SLEEP_BUTTON; } } /* * LID Switch? * ----------- */ else if (strncmp( device->id.hid, BN_HID_LID_SWITCH, sizeof(BM_DEVICE_HID)) == 0) { button->type = BN_TYPE_LID_SWITCH; } status = bn_osl_add_device(button); if (ACPI_FAILURE(status)) { goto end; } *context = button; bn_print(button); end: if (ACPI_FAILURE(status)) { acpi_os_free(button); } return_ACPI_STATUS(status); }
acpi_status bm_add_fixed_feature_device ( BM_NODE *parent, BM_DEVICE_TYPE device_type, char *device_hid) { acpi_status status = AE_OK; BM_NODE *node = NULL; FUNCTION_TRACE("bm_add_fixed_feature_device"); if (!parent) { return_ACPI_STATUS(AE_BAD_PARAMETER); } if (node_list.count > BM_HANDLES_MAX) { return_ACPI_STATUS(AE_NO_MEMORY); } /* * Allocate the new device and add to the device array. */ node = acpi_os_callocate(sizeof(BM_NODE)); if (!node) { return_ACPI_STATUS(AE_NO_MEMORY); } /* * Get device info. */ node->device.handle = node_list.count; node->device.acpi_handle = ACPI_ROOT_OBJECT; node->device.id.type = BM_TYPE_FIXED_BUTTON; if (device_hid) { MEMCPY((void*)node->device.id.hid, device_hid, sizeof(node->device.id.hid)); } node->device.flags = BM_FLAGS_FIXED_FEATURE; node->device.status = BM_STATUS_DEFAULT; /* TBD: Device PM capabilities */ /* * Add to the node_list. */ node_list.nodes[node_list.count++] = node; /* * Formulate Hierarchy: * -------------------- * Arrange within the namespace by assigning the parent and * adding to the parent device's list of children (scope). */ node->parent = parent; node->next = NULL; if (parent) { if (!parent->scope.head) { parent->scope.head = node; } else { if (!parent->scope.tail) { (parent->scope.head)->next = node; } else { (parent->scope.tail)->next = node; } } parent->scope.tail = node; } return_ACPI_STATUS(status); }
void bm_print_object ( acpi_handle handle) { acpi_buffer buffer; acpi_handle parent; acpi_object_type type; buffer.length = 256; buffer.pointer = acpi_os_callocate(buffer.length); if (!buffer.pointer) { return; } acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); acpi_get_parent(handle, &parent); acpi_get_type(handle, &type); /* * TBD: Hack to get around scope identification problem. */ if (type == ACPI_TYPE_ANY) { if (ACPI_SUCCESS(acpi_get_next_object(ACPI_TYPE_ANY, handle, 0, NULL))) { type = INTERNAL_TYPE_SCOPE; } } switch (type) { case INTERNAL_TYPE_SCOPE: acpi_os_printf("SCOPE: "); break; case ACPI_TYPE_INTEGER: acpi_os_printf("SIMPLE (number): "); break; case ACPI_TYPE_STRING: acpi_os_printf("SIMPLE (string): "); break; case ACPI_TYPE_BUFFER: acpi_os_printf("SIMPLE (buffer): "); break; case ACPI_TYPE_PACKAGE: acpi_os_printf("SIMPLE (package): "); break; case ACPI_TYPE_FIELD_UNIT: acpi_os_printf("FIELD UNIT: "); break; case ACPI_TYPE_DEVICE: acpi_os_printf("DEVICE: "); break; case ACPI_TYPE_EVENT: acpi_os_printf("EVENT: "); break; case ACPI_TYPE_METHOD: acpi_os_printf("CONTROL METHOD: "); break; case ACPI_TYPE_MUTEX: acpi_os_printf("MUTEX: "); break; case ACPI_TYPE_REGION: acpi_os_printf("OPERATION REGION: "); break; case ACPI_TYPE_POWER: acpi_os_printf("POWER RESOURCE: "); break; case ACPI_TYPE_PROCESSOR: acpi_os_printf("PROCESSOR: "); break; case ACPI_TYPE_THERMAL: acpi_os_printf("THERMAL ZONE: "); break; case ACPI_TYPE_BUFFER_FIELD: acpi_os_printf("BUFFER FIELD: "); break; case ACPI_TYPE_DDB_HANDLE: acpi_os_printf("DDB HANDLE: "); break; default: acpi_os_printf("OTHER (%d): ", type); break; } acpi_os_printf("Object[%p][%s] parent[%p].\n", handle, (char*)buffer.pointer, parent); acpi_os_free(buffer.pointer); }
acpi_status pr_add_device( BM_HANDLE device_handle, void **context) { acpi_status status = AE_OK; PR_CONTEXT *processor = NULL; BM_DEVICE *device = NULL; acpi_buffer buffer; acpi_object acpi_object; static u32 processor_count = 0; FUNCTION_TRACE("pr_add_device"); if (!context || *context) { return_ACPI_STATUS(AE_BAD_PARAMETER); } status = bm_get_device_info(device_handle, &device); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } processor = acpi_os_callocate(sizeof(PR_CONTEXT)); if (!processor) { return AE_NO_MEMORY; } processor->device_handle = device->handle; processor->acpi_handle = device->acpi_handle; /* * Processor Block: * ---------------- */ memset(&acpi_object, 0, sizeof(acpi_object)); buffer.length = sizeof(acpi_object); buffer.pointer = &acpi_object; status = acpi_evaluate_object(processor->acpi_handle, NULL, NULL, &buffer); if (ACPI_FAILURE(status)) { goto end; } /* * Processor ID: * ------------- * TBD: We need to synchronize the processor ID values in ACPI * with those of the APIC. For example, an IBM T20 has a * proc_id value of '1', where the Linux value for the * first CPU on this system is '0'. Since x86 CPUs are * mapped 1:1 we can simply use a zero-based counter. Note * that this assumes that processor objects are enumerated * in the proper order. */ /* processor->uid = acpi_object.processor.proc_id; */ processor->uid = processor_count++; processor->pblk.length = acpi_object.processor.pblk_length; processor->pblk.address = acpi_object.processor.pblk_address; status = pr_power_add_device(processor); if (ACPI_FAILURE(status)) { goto end; } status = pr_perf_add_device(processor); if (ACPI_FAILURE(status)) { goto end; } status = pr_osl_add_device(processor); if (ACPI_FAILURE(status)) { goto end; } *context = processor; pr_print(processor); end: if (ACPI_FAILURE(status)) { acpi_os_free(processor); } return_ACPI_STATUS(status); }
void tz_print ( TZ_CONTEXT *tz) { #ifdef ACPI_DEBUG acpi_buffer buffer; u32 i,j = 0; TZ_THRESHOLDS *thresholds = NULL; FUNCTION_TRACE("tz_print"); if (!tz) return; thresholds = &(tz->policy.thresholds); buffer.length = 256; buffer.pointer = acpi_os_callocate(buffer.length); if (!buffer.pointer) return; /* * Get the full pathname for this ACPI object. */ acpi_get_name(tz->acpi_handle, ACPI_FULL_PATHNAME, &buffer); /* * Print out basic thermal zone information. */ ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "+------------------------------------------------------------\n")); ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "| Thermal_zone[%02x]:[%p] %s\n", tz->device_handle, tz->acpi_handle, (char*)buffer.pointer)); ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "| temperature[%d] state[%08x]\n", tz->policy.temperature, tz->policy.state)); ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "| cooling_mode[%08x] polling_freq[%d]\n", tz->policy.cooling_mode, tz->policy.polling_freq)); ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "| critical[%d]\n", thresholds->critical.temperature)); if (thresholds->hot.is_valid) ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "| hot[%d]\n", thresholds->hot.temperature)); if (thresholds->passive.is_valid) { ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "| passive[%d]: tc1[%d] tc2[%d] tsp[%d]\n", thresholds->passive.temperature, thresholds->passive.tc1, thresholds->passive.tc2, thresholds->passive.tsp)); if (thresholds->passive.devices.count > 0) { ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "| devices")); for (j=0; (j<thresholds->passive.devices.count && j<10); j++) { ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "[%02x]", thresholds->passive.devices.handles[j])); } ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "\n")); } } for (i=0; i<TZ_MAX_ACTIVE_THRESHOLDS; i++) { if (!thresholds->active[i].is_valid) break; ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "| active[%d]: index[%d]\n", thresholds->active[i].temperature, i)); if (thresholds->active[i].devices.count > 0) { ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "| devices")); for (j=0; (j<thresholds->active[i].devices.count && j<10); j++) { ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "[%02x]", thresholds->active[i].devices.handles[j])); } ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "\n")); } } ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "+------------------------------------------------------------\n")); acpi_os_free(buffer.pointer); #endif /*ACPI_DEBUG*/ return; }
acpi_status tz_add_device ( BM_HANDLE device_handle, void **context) { acpi_status status = AE_OK; TZ_CONTEXT *tz = NULL; BM_DEVICE *device = NULL; acpi_handle tmp_handle = NULL; static u32 zone_count = 0; FUNCTION_TRACE("tz_add_device"); ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Adding thermal zone [%02x].\n", device_handle)); if (!context || *context) { ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "Invalid context for device [%02x].\n", device_handle)); return_ACPI_STATUS(AE_BAD_PARAMETER); } /* * Get information on this device. */ status = bm_get_device_info(device_handle, &device); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* * Allocate a new Thermal Zone device. */ tz = acpi_os_callocate(sizeof(TZ_CONTEXT)); if (!tz) { return_ACPI_STATUS(AE_NO_MEMORY); } tz->device_handle = device->handle; tz->acpi_handle = device->acpi_handle; /* TBD: How to manage 'uid' when zones are Pn_p? */ sprintf(tz->uid, "%d", zone_count++); /* * Temperature: * ------------ * Make sure we can read the zone's current temperature (_TMP). * If we can't, there's no use in doing any policy (abort). */ status = tz_get_temperature(tz); if (ACPI_FAILURE(status)) goto end; /* * Polling Frequency: * ------------------ * If _TZP doesn't exist use the OS default polling frequency. */ status = bm_evaluate_simple_integer(tz->acpi_handle, "_TZP", &(tz->policy.polling_freq)); if (ACPI_FAILURE(status)) { tz->policy.polling_freq = TZP; } status = AE_OK; /* * Cooling Preference: * ------------------- * Default to ACTIVE (noisy) cooling until policy decides otherwise. * Note that _SCP is optional. */ tz_set_cooling_preference(tz, TZ_COOLING_MODE_ACTIVE); /* * Start Policy: * ------------- * Thermal policy is included in the kernel (this driver) because * of the critical role it plays in avoiding nuclear meltdown. =O */ status = tz_policy_add_device(tz); if (ACPI_FAILURE(status)) goto end; status = tz_osl_add_device(tz); if (ACPI_FAILURE(status)) goto end; *context = tz; tz_print(tz); end: if (ACPI_FAILURE(status)) acpi_os_free(tz); return_ACPI_STATUS(status); }
acpi_status bm_add_namespace_device ( acpi_handle acpi_handle, acpi_object_type acpi_type, BM_NODE *parent, BM_NODE **child) { acpi_status status = AE_OK; BM_NODE *node = NULL; BM_DEVICE *device = NULL; FUNCTION_TRACE("bm_add_namespace_device"); if (!parent || !child) { return_ACPI_STATUS(AE_BAD_PARAMETER); } if (node_list.count > BM_HANDLES_MAX) { return_ACPI_STATUS(AE_NO_MEMORY); } (*child) = NULL; /* * Create Node: * ------------ */ node = acpi_os_callocate(sizeof(BM_NODE)); if (!node) { return_ACPI_STATUS(AE_NO_MEMORY); } node->parent = parent; node->next = NULL; device = &(node->device); device->handle = node_list.count; device->acpi_handle = acpi_handle; /* * Device Type: * ------------ */ switch (acpi_type) { case INTERNAL_TYPE_SCOPE: device->id.type = BM_TYPE_SCOPE; break; case ACPI_TYPE_PROCESSOR: device->id.type = BM_TYPE_PROCESSOR; break; case ACPI_TYPE_THERMAL: device->id.type = BM_TYPE_THERMAL_ZONE; break; case ACPI_TYPE_POWER: device->id.type = BM_TYPE_POWER_RESOURCE; break; case ACPI_TYPE_DEVICE: device->id.type = BM_TYPE_DEVICE; break; } /* * Get Other Device Info: * ---------------------- * But only if this device's parent is present (which implies * this device MAY be present). */ if (BM_NODE_PRESENT(node->parent)) { /* * Device Flags */ status = bm_get_flags(device); if (ACPI_FAILURE(status)) { goto end; } /* * Device Identification */ status = bm_get_identification(device); if (ACPI_FAILURE(status)) { goto end; } /* * Device Status */ status = bm_get_status(device); if (ACPI_FAILURE(status)) { goto end; } /* * Power Management: * ----------------- * If this node doesn't provide direct power control * then we inherit PM capabilities from its parent. * * TBD: Inherit! */ if (BM_IS_POWER_CONTROL(device)) { status = bm_get_pm_capabilities(node); if (ACPI_FAILURE(status)) { goto end; } } } end: if (ACPI_FAILURE(status)) { acpi_os_free(node); } else { /* * Add to the node_list. */ node_list.nodes[node_list.count++] = node; /* * Formulate Hierarchy: * -------------------- * Arrange within the namespace by assigning the parent and * adding to the parent device's list of children (scope). */ if (!parent->scope.head) { parent->scope.head = node; } else { if (!parent->scope.tail) { (parent->scope.head)->next = node; } else { (parent->scope.tail)->next = node; } } parent->scope.tail = node; (*child) = node; } return_ACPI_STATUS(status); }
acpi_status ac_add_device( BM_HANDLE device_handle, void **context) { acpi_status status = AE_OK; BM_DEVICE *device = NULL; AC_CONTEXT *ac_adapter = NULL; acpi_device_info info; FUNCTION_TRACE("ac_add_device"); ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Adding ac_adapter device [%02x].\n", device_handle)); if (!context || *context) { ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid (NULL) context.")); return_ACPI_STATUS(AE_BAD_PARAMETER); } /* * Get information on this device. */ status = bm_get_device_info(device_handle, &device); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* * Allocate a new AC_CONTEXT structure. */ ac_adapter = acpi_os_callocate(sizeof(AC_CONTEXT)); if (!ac_adapter) { return_ACPI_STATUS(AE_NO_MEMORY); } ac_adapter->device_handle = device->handle; ac_adapter->acpi_handle = device->acpi_handle; /* * Get information on this object. */ status = acpi_get_object_info(ac_adapter->acpi_handle, &info); if (ACPI_FAILURE(status)) { ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unable to get object info for ac_adapter device.")); goto end; } /* * _UID? * ----- */ if (info.valid & ACPI_VALID_UID) { strncpy(ac_adapter->uid, info.unique_id, sizeof(info.unique_id)); } else { strncpy(ac_adapter->uid, "0", sizeof("0")); } /* * _STA? * ----- */ if (!(info.valid & ACPI_VALID_STA)) { ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Must have valid _STA.\n")); status = AE_ERROR; goto end; } status = ac_osl_add_device(ac_adapter); if (ACPI_FAILURE(status)) { goto end; } *context = ac_adapter; ac_print(ac_adapter); end: if (ACPI_FAILURE(status)) { acpi_os_free(ac_adapter); } return_ACPI_STATUS(status); }