Beispiel #1
0
void *acpi_ut_allocate(acpi_size size, u32 component, char *module, u32 line)
{
	void *allocation;

	ACPI_FUNCTION_TRACE_U32(ut_allocate, size);

	/* Check for an inadvertent size of zero bytes */

	if (!size) {
		ACPI_WARNING((module, line,
			      "Attempt to allocate zero bytes, allocating 1 byte"));
		size = 1;
	}

	allocation = acpi_os_allocate(size);
	if (!allocation) {

		/* Report allocation error */

		ACPI_WARNING((module, line,
			      "Could not allocate size %X", (u32) size));

		return_PTR(NULL);
	}

	return_PTR(allocation);
}
Beispiel #2
0
acpi_status
acpi_vendor_resource_match(struct acpi_resource *resource, void *context)
{
	struct acpi_vendor_info *info = (struct acpi_vendor_info *) context;
	struct acpi_resource_vendor *vendor;
	struct acpi_vendor_descriptor *descriptor;
	u32 length;

	if (resource->id != ACPI_RSTYPE_VENDOR)
		return AE_OK;

	vendor = (struct acpi_resource_vendor *) &resource->data;
	descriptor = (struct acpi_vendor_descriptor *) vendor->reserved;
	if (vendor->length <= sizeof(*info->descriptor) ||
	    descriptor->guid_id != info->descriptor->guid_id ||
	    efi_guidcmp(descriptor->guid, info->descriptor->guid))
		return AE_OK;

	length = vendor->length - sizeof(struct acpi_vendor_descriptor);
	info->data = acpi_os_allocate(length);
	if (!info->data)
		return AE_NO_MEMORY;

	memcpy(info->data, vendor->reserved + sizeof(struct acpi_vendor_descriptor), length);
	info->length = length;
	return AE_CTRL_TERMINATE;
}
Beispiel #3
0
void *
_cm_allocate (
	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_allocate: Attempt to allocate zero bytes\n"));
		size = 1;
	}

	address = acpi_os_allocate (size);
	if (!address) {
		/* Report allocation error */

		_REPORT_ERROR (module, line, component,
				("Cm_allocate: Could not allocate size %X\n", size));

		return (NULL);
	}


	return (address);
}
Beispiel #4
0
/*******************************************************************************
 *
 * FUNCTION:    acpi_os_create_cache
 *
 * PARAMETERS:  cache_name      - Ascii name for the cache
 *              object_size     - Size of each cached object
 *              max_depth       - Maximum depth of the cache (in objects)
 *              return_cache    - Where the new cache object is returned
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Create a cache object
 *
 ******************************************************************************/
acpi_status
acpi_os_create_cache(char *cache_name,
		     u16 object_size,
		     u16 max_depth, struct acpi_memory_list **return_cache)
{
	struct acpi_memory_list *cache;

	ACPI_FUNCTION_ENTRY();

	if (!cache_name || !return_cache || (object_size < 16)) {
		return (AE_BAD_PARAMETER);
	}

	/* Create the cache object */

	cache = acpi_os_allocate(sizeof(struct acpi_memory_list));
	if (!cache) {
		return (AE_NO_MEMORY);
	}

	/* Populate the cache object and return it */

	ACPI_MEMSET(cache, 0, sizeof(struct acpi_memory_list));
	cache->list_name = cache_name;
	cache->object_size = object_size;
	cache->max_depth = max_depth;

	*return_cache = cache;
	return (AE_OK);
}
void *
acpi_os_callocate(u32 size)
{
    void *ptr = acpi_os_allocate(size);
    if (ptr)
        memset(ptr, 0, size);

    return ptr;
}
Beispiel #6
0
acpi_status
acpi_ut_initialize_buffer(struct acpi_buffer * buffer,
			  acpi_size required_length)
{
	acpi_status status = AE_OK;

	switch (buffer->length) {
	case ACPI_NO_BUFFER:

		/* Set the exception and returned the required length */

		status = AE_BUFFER_OVERFLOW;
		break;

	case ACPI_ALLOCATE_BUFFER:

		/* Allocate a new buffer */

		buffer->pointer = acpi_os_allocate(required_length);
		if (!buffer->pointer) {
			return (AE_NO_MEMORY);
		}

		/* Clear the buffer */

		ACPI_MEMSET(buffer->pointer, 0, required_length);
		break;

	case ACPI_ALLOCATE_LOCAL_BUFFER:

		/* Allocate a new buffer with local interface to allow tracking */

		buffer->pointer = ACPI_ALLOCATE_ZEROED(required_length);
		if (!buffer->pointer) {
			return (AE_NO_MEMORY);
		}
		break;

	default:

		/* Existing buffer: Validate the size of the buffer */

		if (buffer->length < required_length) {
			status = AE_BUFFER_OVERFLOW;
			break;
		}

		/* Clear the buffer */

		ACPI_MEMSET(buffer->pointer, 0, required_length);
		break;
	}

	buffer->length = required_length;
	return (status);
}
Beispiel #7
0
/*******************************************************************************
 *
 * FUNCTION:    acpi_os_allocate_zeroed
 *
 * PARAMETERS:  size                - Size of the allocation
 *
 * RETURN:      Address of the allocated memory on success, NULL on failure.
 *
 * DESCRIPTION: Subsystem equivalent of calloc. Allocate and zero memory.
 *              This is the default implementation. Can be overridden via the
 *              USE_NATIVE_ALLOCATE_ZEROED flag.
 *
 ******************************************************************************/
void *acpi_os_allocate_zeroed(acpi_size size)
{
	void *allocation;

	ACPI_FUNCTION_ENTRY();

	allocation = acpi_os_allocate(size);
	if (allocation) {

		/* Clear the memory block */

		memset(allocation, 0, size);
	}

	return (allocation);
}
Beispiel #8
0
void *acpi_ut_allocate_and_track(acpi_size size,
				 u32 component, const char *module, u32 line)
{
	struct acpi_debug_mem_block *allocation;
	acpi_status status;

	/* Check for an inadvertent size of zero bytes */

	if (!size) {
		ACPI_WARNING((module, line,
			      "Attempt to allocate zero bytes, allocating 1 byte"));
		size = 1;
	}

	allocation =
	    acpi_os_allocate(size + sizeof(struct acpi_debug_mem_header));
	if (!allocation) {

		/* Report allocation error */

		ACPI_WARNING((module, line,
			      "Could not allocate size %u", (u32)size));

		return (NULL);
	}

	status =
	    acpi_ut_track_allocation(allocation, size, ACPI_MEM_MALLOC,
				     component, module, line);
	if (ACPI_FAILURE(status)) {
		acpi_os_free(allocation);
		return (NULL);
	}

	acpi_gbl_global_list->total_allocated++;
	acpi_gbl_global_list->total_size += (u32)size;
	acpi_gbl_global_list->current_total_size += (u32)size;

	if (acpi_gbl_global_list->current_total_size >
	    acpi_gbl_global_list->max_occupied) {
		acpi_gbl_global_list->max_occupied =
		    acpi_gbl_global_list->current_total_size;
	}

	return ((void *)&allocation->user_space);
}
/*
 * Allocate the memory for a spinlock and initialize it.
 */
acpi_status
acpi_os_create_lock (
	acpi_handle	*out_handle)
{
	spinlock_t *lock_ptr;

	ACPI_FUNCTION_TRACE ("os_create_lock");

	lock_ptr = acpi_os_allocate(sizeof(spinlock_t));

	spin_lock_init(lock_ptr);

	ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Creating spinlock[%p].\n", lock_ptr));

	*out_handle = lock_ptr;

	return_ACPI_STATUS (AE_OK);
}
Beispiel #10
0
acpi_status
acpi_ut_create_list(const char *list_name,
		    u16 object_size, struct acpi_memory_list **return_cache)
{
	struct acpi_memory_list *cache;

	cache = acpi_os_allocate(sizeof(struct acpi_memory_list));
	if (!cache) {
		return (AE_NO_MEMORY);
	}

	memset(cache, 0, sizeof(struct acpi_memory_list));

	cache->list_name = list_name;
	cache->object_size = object_size;

	*return_cache = cache;
	return (AE_OK);
}
Beispiel #11
0
acpi_status
acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
{
	struct semaphore *sem = NULL;

	sem = acpi_os_allocate(sizeof(struct semaphore));
	if (!sem)
		return AE_NO_MEMORY;
	memset(sem, 0, sizeof(struct semaphore));

	sema_init(sem, initial_units);

	*handle = (acpi_handle *) sem;

	ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
			  *handle, initial_units));

	return AE_OK;
}
Beispiel #12
0
Datei: osl.c Projekt: PyroOS/Pyro
acpi_status
acpi_os_create_semaphore(
	u32		max_units,
	u32		initial_units,
	acpi_handle	*handle)
{
	sem_id	*sem = NULL;

	ACPI_FUNCTION_TRACE ("os_create_semaphore");

	sem = acpi_os_allocate(sizeof(sem_id));
	if (!sem)
		return_ACPI_STATUS (AE_NO_MEMORY);
	memset(sem, 0, sizeof(sem_id));

	*sem = create_semaphore( "acpi_semaphore", initial_units, 0 );

	*handle = (acpi_handle*)sem;

	ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n", *handle, initial_units));

	return_ACPI_STATUS (AE_OK);
}
Beispiel #13
0
acpi_status
acpi_os_create_semaphore(u32 max_units,
			 u32 initial_units, acpi_handle *out_handle)
{
	sem_t *sem;

	if (!out_handle) {
		return (AE_BAD_PARAMETER);
	}
#ifdef __APPLE__
	{
		char *semaphore_name = tmpnam(NULL);

		sem =
		    sem_open(semaphore_name, O_EXCL | O_CREAT, 0755,
			     initial_units);
		if (!sem) {
			return (AE_NO_MEMORY);
		}
		sem_unlink(semaphore_name);	/* This just deletes the name */
	}

#else
	sem = acpi_os_allocate(sizeof(sem_t));
	if (!sem) {
		return (AE_NO_MEMORY);
	}

	if (sem_init(sem, 0, initial_units) == -1) {
		acpi_os_free(sem);
		return (AE_BAD_PARAMETER);
	}
#endif

	*out_handle = (acpi_handle)sem;
	return (AE_OK);
}
Beispiel #14
0
acpi_status
acpi_ut_initialize_buffer(struct acpi_buffer *buffer, acpi_size required_length)
{
	acpi_size input_buffer_length;

	/* Parameter validation */

	if (!buffer || !required_length) {
		return (AE_BAD_PARAMETER);
	}

	/*
	 * Buffer->Length is used as both an input and output parameter. Get the
	 * input actual length and set the output required buffer length.
	 */
	input_buffer_length = buffer->length;
	buffer->length = required_length;

	/*
	 * The input buffer length contains the actual buffer length, or the type
	 * of buffer to be allocated by this routine.
	 */
	switch (input_buffer_length) {
	case ACPI_NO_BUFFER:

		/* Return the exception (and the required buffer length) */

		return (AE_BUFFER_OVERFLOW);

	case ACPI_ALLOCATE_BUFFER:
		/*
		 * Allocate a new buffer. We directectly call acpi_os_allocate here to
		 * purposefully bypass the (optionally enabled) internal allocation
		 * tracking mechanism since we only want to track internal
		 * allocations. Note: The caller should use acpi_os_free to free this
		 * buffer created via ACPI_ALLOCATE_BUFFER.
		 */
		buffer->pointer = acpi_os_allocate(required_length);
		break;

	case ACPI_ALLOCATE_LOCAL_BUFFER:

		/* Allocate a new buffer with local interface to allow tracking */

		buffer->pointer = ACPI_ALLOCATE(required_length);
		break;

	default:

		/* Existing buffer: Validate the size of the buffer */

		if (input_buffer_length < required_length) {
			return (AE_BUFFER_OVERFLOW);
		}
		break;
	}

	/* Validate allocation from above or input buffer pointer */

	if (!buffer->pointer) {
		return (AE_NO_MEMORY);
	}

	/* Have a valid buffer, clear it */

	memset(buffer->pointer, 0, required_length);
	return (AE_OK);
}
Beispiel #15
0
static acpi_status
acpi_ut_read_table(FILE * fp,
		   struct acpi_table_header **table, u32 *table_length)
{
	struct acpi_table_header table_header;
	u32 actual;
	acpi_status status;
	u32 file_size;
	u8 standard_header = TRUE;
	s32 count;

	/* Get the file size */

	file_size = cm_get_file_size(fp);
	if (file_size == ACPI_UINT32_MAX) {
		return (AE_ERROR);
	}

	if (file_size < 4) {
		return (AE_BAD_HEADER);
	}

	/* Read the signature */

	fseek(fp, 0, SEEK_SET);

	count = fread(&table_header, 1, sizeof(struct acpi_table_header), fp);
	if (count != sizeof(struct acpi_table_header)) {
		acpi_os_printf("Could not read the table header\n");
		return (AE_BAD_HEADER);
	}

	/* The RSDP table does not have standard ACPI header */

	if (ACPI_VALIDATE_RSDP_SIG(table_header.signature)) {
		*table_length = file_size;
		standard_header = FALSE;
	} else {

#if 0
		/* Validate the table header/length */

		status = acpi_tb_validate_table_header(&table_header);
		if (ACPI_FAILURE(status)) {
			acpi_os_printf("Table header is invalid!\n");
			return (status);
		}
#endif

		/* File size must be at least as long as the Header-specified length */

		if (table_header.length > file_size) {
			acpi_os_printf
			    ("TableHeader length [0x%X] greater than the input file size [0x%X]\n",
			     table_header.length, file_size);

#ifdef ACPI_ASL_COMPILER
			acpi_os_printf("File is corrupt or is ASCII text -- "
				       "it must be a binary file\n");
#endif
			return (AE_BAD_HEADER);
		}
#ifdef ACPI_OBSOLETE_CODE
		/* We only support a limited number of table types */

		if (!ACPI_COMPARE_NAME
		    ((char *)table_header.signature, ACPI_SIG_DSDT)
		    && !ACPI_COMPARE_NAME((char *)table_header.signature,
					  ACPI_SIG_PSDT)
		    && !ACPI_COMPARE_NAME((char *)table_header.signature,
					  ACPI_SIG_SSDT)) {
			acpi_os_printf
			    ("Table signature [%4.4s] is invalid or not supported\n",
			     (char *)table_header.signature);
			ACPI_DUMP_BUFFER(&table_header,
					 sizeof(struct acpi_table_header));
			return (AE_ERROR);
		}
#endif

		*table_length = table_header.length;
	}

	/* Allocate a buffer for the table */

	*table = acpi_os_allocate((size_t) file_size);
	if (!*table) {
		acpi_os_printf
		    ("Could not allocate memory for ACPI table %4.4s (size=0x%X)\n",
		     table_header.signature, *table_length);
		return (AE_NO_MEMORY);
	}

	/* Get the rest of the table */

	fseek(fp, 0, SEEK_SET);
	actual = fread(*table, 1, (size_t) file_size, fp);
	if (actual == file_size) {
		if (standard_header) {

			/* Now validate the checksum */

			status = acpi_tb_verify_checksum((void *)*table,
							 ACPI_CAST_PTR(struct
								       acpi_table_header,
								       *table)->
							 length);

			if (status == AE_BAD_CHECKSUM) {
				status =
				    acpi_ut_check_text_mode_corruption((u8 *)
								       *table,
								       file_size,
								       (*table)->
								       length);
				return (status);
			}
		}
		return (AE_OK);
	}

	if (actual > 0) {
		acpi_os_printf("Warning - reading table, asked for %X got %X\n",
			       file_size, actual);
		return (AE_OK);
	}

	acpi_os_printf("Error - could not read the table file\n");
	acpi_os_free(*table);
	*table = NULL;
	*table_length = 0;
	return (AE_ERROR);
}
Beispiel #16
0
acpi_status
acpi_ut_initialize_buffer(struct acpi_buffer * buffer,
			  acpi_size required_length)
{
	acpi_size input_buffer_length;

	/* Parameter validation */

	if (!buffer || !required_length) {
		return (AE_BAD_PARAMETER);
	}

	/*
	 * Buffer->Length is used as both an input and output parameter. Get the
	 * input actual length and set the output required buffer length.
	 */
	input_buffer_length = buffer->length;
	buffer->length = required_length;

	/*
	 * The input buffer length contains the actual buffer length, or the type
	 * of buffer to be allocated by this routine.
	 */
	switch (input_buffer_length) {
	case ACPI_NO_BUFFER:

		/* Return the exception (and the required buffer length) */

		return (AE_BUFFER_OVERFLOW);

	case ACPI_ALLOCATE_BUFFER:

		/* Allocate a new buffer */

		buffer->pointer = acpi_os_allocate(required_length);
		break;

	case ACPI_ALLOCATE_LOCAL_BUFFER:

		/* Allocate a new buffer with local interface to allow tracking */

		buffer->pointer = ACPI_ALLOCATE(required_length);
		break;

	default:

		/* Existing buffer: Validate the size of the buffer */

		if (input_buffer_length < required_length) {
			return (AE_BUFFER_OVERFLOW);
		}
		break;
	}

	/* Validate allocation from above or input buffer pointer */

	if (!buffer->pointer) {
		return (AE_NO_MEMORY);
	}

	/* Have a valid buffer, clear it */

	ACPI_MEMSET(buffer->pointer, 0, required_length);
	return (AE_OK);
}
Beispiel #17
0
acpi_status acpi_initialize_debugger(void)
{
	acpi_status status;

	ACPI_FUNCTION_TRACE(acpi_initialize_debugger);

	/* Init globals */

	acpi_gbl_db_buffer = NULL;
	acpi_gbl_db_filename = NULL;
	acpi_gbl_db_output_to_file = FALSE;

	acpi_gbl_db_debug_level = ACPI_LV_VERBOSITY2;
	acpi_gbl_db_console_debug_level = ACPI_NORMAL_DEFAULT | ACPI_LV_TABLES;
	acpi_gbl_db_output_flags = ACPI_DB_CONSOLE_OUTPUT;

	acpi_gbl_db_opt_no_ini_methods = FALSE;

	acpi_gbl_db_buffer = acpi_os_allocate(ACPI_DEBUG_BUFFER_SIZE);
	if (!acpi_gbl_db_buffer) {
		return_ACPI_STATUS(AE_NO_MEMORY);
	}
	memset(acpi_gbl_db_buffer, 0, ACPI_DEBUG_BUFFER_SIZE);

	/* Initial scope is the root */

	acpi_gbl_db_scope_buf[0] = AML_ROOT_PREFIX;
	acpi_gbl_db_scope_buf[1] = 0;
	acpi_gbl_db_scope_node = acpi_gbl_root_node;

	/* Initialize user commands loop */

	acpi_gbl_db_terminate_loop = FALSE;

	/*
	 * 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 */

		status = acpi_os_acquire_mutex(acpi_gbl_db_command_complete,
					       ACPI_WAIT_FOREVER);
		if (ACPI_FAILURE(status)) {
			acpi_os_printf("Could not get debugger mutex\n");
			return_ACPI_STATUS(status);
		}

		status = acpi_os_acquire_mutex(acpi_gbl_db_command_ready,
					       ACPI_WAIT_FOREVER);
		if (ACPI_FAILURE(status)) {
			acpi_os_printf("Could not get debugger mutex\n");
			return_ACPI_STATUS(status);
		}

		/* Create the debug execution thread to execute commands */

		acpi_gbl_db_threads_terminated = FALSE;
		status = acpi_os_execute(OSL_DEBUGGER_MAIN_THREAD,
					 acpi_db_execute_thread, NULL);
		if (ACPI_FAILURE(status)) {
			ACPI_EXCEPTION((AE_INFO, status,
					"Could not start debugger thread"));
			acpi_gbl_db_threads_terminated = TRUE;
			return_ACPI_STATUS(status);
		}
	} else {
		acpi_gbl_db_thread_id = acpi_os_get_thread_id();
	}

	return_ACPI_STATUS(AE_OK);
}