rsutils.c 21.6 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1 2 3 4 5 6 7
/*******************************************************************************
 *
 * Module Name: rsutils - Utilities for the resource manager
 *
 ******************************************************************************/

/*
Bob Moore's avatar
Bob Moore committed
8
 * Copyright (C) 2000 - 2006, R. Byron Moore
Linus Torvalds's avatar
Linus Torvalds committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions, and the following disclaimer,
 *    without modification.
 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
 *    substantially similar to the "NO WARRANTY" disclaimer below
 *    ("Disclaimer") and any redistribution must be conditioned upon
 *    including a substantially similar Disclaimer requirement for further
 *    binary redistribution.
 * 3. Neither the names of the above-listed copyright holders nor the names
 *    of any contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * Alternatively, this software may be distributed under the terms of the
 * GNU General Public License ("GPL") version 2 as published by the Free
 * Software Foundation.
 *
 * NO WARRANTY
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 */

#include <acpi/acpi.h>
#include <acpi/acnamesp.h>
#include <acpi/acresrc.h>

#define _COMPONENT          ACPI_RESOURCES
Len Brown's avatar
Len Brown committed
49
ACPI_MODULE_NAME("rsutils")
Linus Torvalds's avatar
Linus Torvalds committed
50

Bob Moore's avatar
Bob Moore committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
/*******************************************************************************
 *
 * FUNCTION:    acpi_rs_decode_bitmask
 *
 * PARAMETERS:  Mask            - Bitmask to decode
 *              List            - Where the converted list is returned
 *
 * RETURN:      Count of bits set (length of list)
 *
 * DESCRIPTION: Convert a bit mask into a list of values
 *
 ******************************************************************************/
u8 acpi_rs_decode_bitmask(u16 mask, u8 * list)
{
	acpi_native_uint i;
	u8 bit_count;

Bob Moore's avatar
Bob Moore committed
68 69
	ACPI_FUNCTION_ENTRY();

Bob Moore's avatar
Bob Moore committed
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
	/* Decode the mask bits */

	for (i = 0, bit_count = 0; mask; i++) {
		if (mask & 0x0001) {
			list[bit_count] = (u8) i;
			bit_count++;
		}

		mask >>= 1;
	}

	return (bit_count);
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_rs_encode_bitmask
 *
 * PARAMETERS:  List            - List of values to encode
 *              Count           - Length of list
 *
 * RETURN:      Encoded bitmask
 *
 * DESCRIPTION: Convert a list of values to an encoded bitmask
 *
 ******************************************************************************/

u16 acpi_rs_encode_bitmask(u8 * list, u8 count)
{
	acpi_native_uint i;
	u16 mask;

Bob Moore's avatar
Bob Moore committed
102 103
	ACPI_FUNCTION_ENTRY();

Bob Moore's avatar
Bob Moore committed
104 105 106 107 108 109 110 111 112
	/* Encode the list into a single bitmask */

	for (i = 0, mask = 0; i < count; i++) {
		mask |= (0x0001 << list[i]);
	}

	return (mask);
}

Bob Moore's avatar
Bob Moore committed
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
/*******************************************************************************
 *
 * FUNCTION:    acpi_rs_move_data
 *
 * PARAMETERS:  Destination         - Pointer to the destination descriptor
 *              Source              - Pointer to the source descriptor
 *              item_count          - How many items to move
 *              move_type           - Byte width
 *
 * RETURN:      None
 *
 * DESCRIPTION: Move multiple data items from one descriptor to another. Handles
 *              alignment issues and endian issues if necessary, as configured
 *              via the ACPI_MOVE_* macros. (This is why a memcpy is not used)
 *
 ******************************************************************************/
Bob Moore's avatar
Bob Moore committed
129

Bob Moore's avatar
Bob Moore committed
130 131 132 133 134
void
acpi_rs_move_data(void *destination, void *source, u16 item_count, u8 move_type)
{
	acpi_native_uint i;

Bob Moore's avatar
Bob Moore committed
135 136
	ACPI_FUNCTION_ENTRY();

Bob Moore's avatar
Bob Moore committed
137 138 139 140
	/* One move per item */

	for (i = 0; i < item_count; i++) {
		switch (move_type) {
Bob Moore's avatar
Bob Moore committed
141 142 143 144 145 146 147
			/*
			 * For the 8-bit case, we can perform the move all at once
			 * since there are no alignment or endian issues
			 */
		case ACPI_RSC_MOVE8:
			ACPI_MEMCPY(destination, source, item_count);
			return;
Bob Moore's avatar
Bob Moore committed
148

Bob Moore's avatar
Bob Moore committed
149 150 151 152 153 154
			/*
			 * 16-, 32-, and 64-bit cases must use the move macros that perform
			 * endian conversion and/or accomodate hardware that cannot perform
			 * misaligned memory transfers
			 */
		case ACPI_RSC_MOVE16:
Bob Moore's avatar
Bob Moore committed
155 156
			ACPI_MOVE_16_TO_16(&ACPI_CAST_PTR(u16, destination)[i],
					   &ACPI_CAST_PTR(u16, source)[i]);
Bob Moore's avatar
Bob Moore committed
157 158
			break;

Bob Moore's avatar
Bob Moore committed
159
		case ACPI_RSC_MOVE32:
Bob Moore's avatar
Bob Moore committed
160 161
			ACPI_MOVE_32_TO_32(&ACPI_CAST_PTR(u32, destination)[i],
					   &ACPI_CAST_PTR(u32, source)[i]);
Bob Moore's avatar
Bob Moore committed
162 163
			break;

Bob Moore's avatar
Bob Moore committed
164
		case ACPI_RSC_MOVE64:
Bob Moore's avatar
Bob Moore committed
165 166
			ACPI_MOVE_64_TO_64(&ACPI_CAST_PTR(u64, destination)[i],
					   &ACPI_CAST_PTR(u64, source)[i]);
Bob Moore's avatar
Bob Moore committed
167 168 169 170 171 172 173 174 175 176
			break;

		default:
			return;
		}
	}
}

/*******************************************************************************
 *
Bob Moore's avatar
Bob Moore committed
177
 * FUNCTION:    acpi_rs_set_resource_length
Bob Moore's avatar
Bob Moore committed
178
 *
Bob Moore's avatar
Bob Moore committed
179 180 181
 * PARAMETERS:  total_length        - Length of the AML descriptor, including
 *                                    the header and length fields.
 *              Aml                 - Pointer to the raw AML descriptor
Bob Moore's avatar
Bob Moore committed
182
 *
Bob Moore's avatar
Bob Moore committed
183
 * RETURN:      None
Bob Moore's avatar
Bob Moore committed
184
 *
Bob Moore's avatar
Bob Moore committed
185 186 187 188
 * DESCRIPTION: Set the resource_length field of an AML
 *              resource descriptor, both Large and Small descriptors are
 *              supported automatically. Note: Descriptor Type field must
 *              be valid.
Bob Moore's avatar
Bob Moore committed
189 190 191
 *
 ******************************************************************************/

Bob Moore's avatar
Bob Moore committed
192 193 194
void
acpi_rs_set_resource_length(acpi_rsdesc_size total_length,
			    union aml_resource *aml)
Bob Moore's avatar
Bob Moore committed
195
{
Bob Moore's avatar
Bob Moore committed
196
	acpi_rs_length resource_length;
Bob Moore's avatar
Bob Moore committed
197 198 199

	ACPI_FUNCTION_ENTRY();

Bob Moore's avatar
Bob Moore committed
200
	/* Length is the total descriptor length minus the header length */
Bob Moore's avatar
Bob Moore committed
201

Bob Moore's avatar
Bob Moore committed
202 203
	resource_length = (acpi_rs_length)
	    (total_length - acpi_ut_get_resource_header_length(aml));
Bob Moore's avatar
Bob Moore committed
204

Bob Moore's avatar
Bob Moore committed
205
	/* Length is stored differently for large and small descriptors */
Bob Moore's avatar
Bob Moore committed
206

Bob Moore's avatar
Bob Moore committed
207
	if (aml->small_header.descriptor_type & ACPI_RESOURCE_NAME_LARGE) {
Bob Moore's avatar
Bob Moore committed
208

Bob Moore's avatar
Bob Moore committed
209
		/* Large descriptor -- bytes 1-2 contain the 16-bit length */
Bob Moore's avatar
Bob Moore committed
210

Bob Moore's avatar
Bob Moore committed
211 212
		ACPI_MOVE_16_TO_16(&aml->large_header.resource_length,
				   &resource_length);
Bob Moore's avatar
Bob Moore committed
213
	} else {
Bob Moore's avatar
Bob Moore committed
214
		/* Small descriptor -- bits 2:0 of byte 0 contain the length */
Bob Moore's avatar
Bob Moore committed
215

Bob Moore's avatar
Bob Moore committed
216
		aml->small_header.descriptor_type = (u8)
Bob Moore's avatar
Bob Moore committed
217

Bob Moore's avatar
Bob Moore committed
218 219 220
		    /* Clear any existing length, preserving descriptor type bits */
		    ((aml->small_header.
		      descriptor_type & ~ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK)
Bob Moore's avatar
Bob Moore committed
221

Bob Moore's avatar
Bob Moore committed
222
		     | resource_length);
Bob Moore's avatar
Bob Moore committed
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
	}
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_rs_set_resource_header
 *
 * PARAMETERS:  descriptor_type     - Byte to be inserted as the type
 *              total_length        - Length of the AML descriptor, including
 *                                    the header and length fields.
 *              Aml                 - Pointer to the raw AML descriptor
 *
 * RETURN:      None
 *
 * DESCRIPTION: Set the descriptor_type and resource_length fields of an AML
 *              resource descriptor, both Large and Small descriptors are
 *              supported automatically
 *
 ******************************************************************************/

void
acpi_rs_set_resource_header(u8 descriptor_type,
Bob Moore's avatar
Bob Moore committed
245 246
			    acpi_rsdesc_size total_length,
			    union aml_resource *aml)
Bob Moore's avatar
Bob Moore committed
247 248 249
{
	ACPI_FUNCTION_ENTRY();

Bob Moore's avatar
Bob Moore committed
250
	/* Set the Resource Type */
Bob Moore's avatar
Bob Moore committed
251 252 253

	aml->small_header.descriptor_type = descriptor_type;

Bob Moore's avatar
Bob Moore committed
254
	/* Set the Resource Length */
Bob Moore's avatar
Bob Moore committed
255

Bob Moore's avatar
Bob Moore committed
256
	acpi_rs_set_resource_length(total_length, aml);
Bob Moore's avatar
Bob Moore committed
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_rs_strcpy
 *
 * PARAMETERS:  Destination         - Pointer to the destination string
 *              Source              - Pointer to the source string
 *
 * RETURN:      String length, including NULL terminator
 *
 * DESCRIPTION: Local string copy that returns the string length, saving a
 *              strcpy followed by a strlen.
 *
 ******************************************************************************/

static u16 acpi_rs_strcpy(char *destination, char *source)
{
	u16 i;

	ACPI_FUNCTION_ENTRY();

	for (i = 0; source[i]; i++) {
		destination[i] = source[i];
	}

	destination[i] = 0;

	/* Return string length including the NULL terminator */

	return ((u16) (i + 1));
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_rs_get_resource_source
 *
 * PARAMETERS:  resource_length     - Length field of the descriptor
 *              minimum_length      - Minimum length of the descriptor (minus
 *                                    any optional fields)
 *              resource_source     - Where the resource_source is returned
 *              Aml                 - Pointer to the raw AML descriptor
 *              string_ptr          - (optional) where to store the actual
 *                                    resource_source string
 *
 * RETURN:      Length of the string plus NULL terminator, rounded up to 32 bit
 *
 * DESCRIPTION: Copy the optional resource_source data from a raw AML descriptor
 *              to an internal resource descriptor
 *
 ******************************************************************************/

Bob Moore's avatar
Bob Moore committed
309 310 311
acpi_rs_length
acpi_rs_get_resource_source(acpi_rs_length resource_length,
			    acpi_rs_length minimum_length,
Bob Moore's avatar
Bob Moore committed
312 313 314
			    struct acpi_resource_source * resource_source,
			    union aml_resource * aml, char *string_ptr)
{
Bob Moore's avatar
Bob Moore committed
315
	acpi_rsdesc_size total_length;
Bob Moore's avatar
Bob Moore committed
316 317 318 319 320 321
	u8 *aml_resource_source;

	ACPI_FUNCTION_ENTRY();

	total_length =
	    resource_length + sizeof(struct aml_resource_large_header);
Bob Moore's avatar
Bob Moore committed
322
	aml_resource_source = ACPI_ADD_PTR(u8, aml, minimum_length);
Bob Moore's avatar
Bob Moore committed
323 324 325 326 327 328 329 330

	/*
	 * resource_source is present if the length of the descriptor is longer than
	 * the minimum length.
	 *
	 * Note: Some resource descriptors will have an additional null, so
	 * we add 1 to the minimum length.
	 */
Bob Moore's avatar
Bob Moore committed
331
	if (total_length > (acpi_rsdesc_size) (minimum_length + 1)) {
Bob Moore's avatar
Bob Moore committed
332

Bob Moore's avatar
Bob Moore committed
333 334 335 336 337 338 339 340 341 342
		/* Get the resource_source_index */

		resource_source->index = aml_resource_source[0];

		resource_source->string_ptr = string_ptr;
		if (!string_ptr) {
			/*
			 * String destination pointer is not specified; Set the String
			 * pointer to the end of the current resource_source structure.
			 */
Bob Moore's avatar
Bob Moore committed
343 344 345
			resource_source->string_ptr =
			    ACPI_ADD_PTR(char, resource_source,
					 sizeof(struct acpi_resource_source));
Bob Moore's avatar
Bob Moore committed
346 347
		}

Bob Moore's avatar
Bob Moore committed
348 349 350 351 352 353 354 355
		/*
		 * In order for the struct_size to fall on a 32-bit boundary, calculate
		 * the length of the string (+1 for the NULL terminator) and expand the
		 * struct_size to the next 32-bit boundary.
		 *
		 * Zero the entire area of the buffer.
		 */
		total_length =
Bob Moore's avatar
Bob Moore committed
356
		    (u32)
Bob Moore's avatar
Bob Moore committed
357
		    ACPI_ROUND_UP_to_32_bITS(ACPI_STRLEN
Bob Moore's avatar
Bob Moore committed
358 359 360 361
					     (ACPI_CAST_PTR
					      (char,
					       &aml_resource_source[1])) + 1);

Bob Moore's avatar
Bob Moore committed
362 363
		ACPI_MEMSET(resource_source->string_ptr, 0, total_length);

Bob Moore's avatar
Bob Moore committed
364 365 366 367
		/* Copy the resource_source string to the destination */

		resource_source->string_length =
		    acpi_rs_strcpy(resource_source->string_ptr,
Bob Moore's avatar
Bob Moore committed
368 369
				   ACPI_CAST_PTR(char,
						 &aml_resource_source[1]));
Bob Moore's avatar
Bob Moore committed
370

Bob Moore's avatar
Bob Moore committed
371
		return ((acpi_rs_length) total_length);
Bob Moore's avatar
Bob Moore committed
372
	}
Bob Moore's avatar
Bob Moore committed
373 374 375 376 377 378 379

	/* resource_source is not present */

	resource_source->index = 0;
	resource_source->string_length = 0;
	resource_source->string_ptr = NULL;
	return (0);
Bob Moore's avatar
Bob Moore committed
380 381 382 383 384 385 386 387 388 389 390 391 392 393
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_rs_set_resource_source
 *
 * PARAMETERS:  Aml                 - Pointer to the raw AML descriptor
 *              minimum_length      - Minimum length of the descriptor (minus
 *                                    any optional fields)
 *              resource_source     - Internal resource_source

 *
 * RETURN:      Total length of the AML descriptor
 *
Bob Moore's avatar
Bob Moore committed
394
 * DESCRIPTION: Convert an optional resource_source from internal format to a
Bob Moore's avatar
Bob Moore committed
395 396 397 398
 *              raw AML resource descriptor
 *
 ******************************************************************************/

Bob Moore's avatar
Bob Moore committed
399
acpi_rsdesc_size
Bob Moore's avatar
Bob Moore committed
400
acpi_rs_set_resource_source(union aml_resource * aml,
Bob Moore's avatar
Bob Moore committed
401
			    acpi_rs_length minimum_length,
Bob Moore's avatar
Bob Moore committed
402 403 404
			    struct acpi_resource_source * resource_source)
{
	u8 *aml_resource_source;
Bob Moore's avatar
Bob Moore committed
405
	acpi_rsdesc_size descriptor_length;
Bob Moore's avatar
Bob Moore committed
406 407 408 409 410 411 412 413

	ACPI_FUNCTION_ENTRY();

	descriptor_length = minimum_length;

	/* Non-zero string length indicates presence of a resource_source */

	if (resource_source->string_length) {
Bob Moore's avatar
Bob Moore committed
414

Bob Moore's avatar
Bob Moore committed
415 416
		/* Point to the end of the AML descriptor */

Bob Moore's avatar
Bob Moore committed
417
		aml_resource_source = ACPI_ADD_PTR(u8, aml, minimum_length);
Bob Moore's avatar
Bob Moore committed
418 419 420 421 422 423 424

		/* Copy the resource_source_index */

		aml_resource_source[0] = (u8) resource_source->index;

		/* Copy the resource_source string */

Bob Moore's avatar
Bob Moore committed
425
		ACPI_STRCPY(ACPI_CAST_PTR(char, &aml_resource_source[1]),
Bob Moore's avatar
Bob Moore committed
426 427 428 429 430 431 432
			    resource_source->string_ptr);

		/*
		 * Add the length of the string (+ 1 for null terminator) to the
		 * final descriptor length
		 */
		descriptor_length +=
Bob Moore's avatar
Bob Moore committed
433
		    ((acpi_rsdesc_size) resource_source->string_length + 1);
Bob Moore's avatar
Bob Moore committed
434 435 436 437 438 439 440
	}

	/* Return the new total length of the AML descriptor */

	return (descriptor_length);
}

Linus Torvalds's avatar
Linus Torvalds committed
441 442 443 444
/*******************************************************************************
 *
 * FUNCTION:    acpi_rs_get_prt_method_data
 *
Bob Moore's avatar
Bob Moore committed
445 446 447
 * PARAMETERS:  Handle          - Handle to the containing object
 *              ret_buffer      - Pointer to a buffer structure for the
 *                                results
Linus Torvalds's avatar
Linus Torvalds committed
448 449 450 451 452 453 454 455 456 457
 *
 * RETURN:      Status
 *
 * DESCRIPTION: This function is called to get the _PRT value of an object
 *              contained in an object specified by the handle passed in
 *
 *              If the function fails an appropriate status will be returned
 *              and the contents of the callers buffer is undefined.
 *
 ******************************************************************************/
Bob Moore's avatar
Bob Moore committed
458

Linus Torvalds's avatar
Linus Torvalds committed
459
acpi_status
Bob Moore's avatar
Bob Moore committed
460
acpi_rs_get_prt_method_data(acpi_handle handle, struct acpi_buffer * ret_buffer)
Linus Torvalds's avatar
Linus Torvalds committed
461
{
Len Brown's avatar
Len Brown committed
462 463
	union acpi_operand_object *obj_desc;
	acpi_status status;
Linus Torvalds's avatar
Linus Torvalds committed
464

Len Brown's avatar
Len Brown committed
465
	ACPI_FUNCTION_TRACE("rs_get_prt_method_data");
Linus Torvalds's avatar
Linus Torvalds committed
466 467 468

	/* Parameters guaranteed valid by caller */

469 470
	/* Execute the method, no parameters */

Len Brown's avatar
Len Brown committed
471 472 473 474
	status = acpi_ut_evaluate_object(handle, METHOD_NAME__PRT,
					 ACPI_BTYPE_PACKAGE, &obj_desc);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
Linus Torvalds's avatar
Linus Torvalds committed
475 476 477 478 479 480
	}

	/*
	 * Create a resource linked list from the byte stream buffer that comes
	 * back from the _CRS method execution.
	 */
Len Brown's avatar
Len Brown committed
481
	status = acpi_rs_create_pci_routing_table(obj_desc, ret_buffer);
Linus Torvalds's avatar
Linus Torvalds committed
482 483 484

	/* On exit, we must delete the object returned by evaluate_object */

Len Brown's avatar
Len Brown committed
485 486
	acpi_ut_remove_reference(obj_desc);
	return_ACPI_STATUS(status);
Linus Torvalds's avatar
Linus Torvalds committed
487 488 489 490 491 492
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_rs_get_crs_method_data
 *
Bob Moore's avatar
Bob Moore committed
493 494 495
 * PARAMETERS:  Handle          - Handle to the containing object
 *              ret_buffer      - Pointer to a buffer structure for the
 *                                results
Linus Torvalds's avatar
Linus Torvalds committed
496 497 498 499 500 501 502 503 504 505 506 507
 *
 * RETURN:      Status
 *
 * DESCRIPTION: This function is called to get the _CRS value of an object
 *              contained in an object specified by the handle passed in
 *
 *              If the function fails an appropriate status will be returned
 *              and the contents of the callers buffer is undefined.
 *
 ******************************************************************************/

acpi_status
Len Brown's avatar
Len Brown committed
508
acpi_rs_get_crs_method_data(acpi_handle handle, struct acpi_buffer *ret_buffer)
Linus Torvalds's avatar
Linus Torvalds committed
509
{
Len Brown's avatar
Len Brown committed
510 511
	union acpi_operand_object *obj_desc;
	acpi_status status;
Linus Torvalds's avatar
Linus Torvalds committed
512

Len Brown's avatar
Len Brown committed
513
	ACPI_FUNCTION_TRACE("rs_get_crs_method_data");
Linus Torvalds's avatar
Linus Torvalds committed
514 515 516

	/* Parameters guaranteed valid by caller */

517 518
	/* Execute the method, no parameters */

Len Brown's avatar
Len Brown committed
519 520 521 522
	status = acpi_ut_evaluate_object(handle, METHOD_NAME__CRS,
					 ACPI_BTYPE_BUFFER, &obj_desc);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
Linus Torvalds's avatar
Linus Torvalds committed
523 524 525 526 527 528 529
	}

	/*
	 * Make the call to create a resource linked list from the
	 * byte stream buffer that comes back from the _CRS method
	 * execution.
	 */
Len Brown's avatar
Len Brown committed
530
	status = acpi_rs_create_resource_list(obj_desc, ret_buffer);
Linus Torvalds's avatar
Linus Torvalds committed
531 532 533

	/* on exit, we must delete the object returned by evaluate_object */

Len Brown's avatar
Len Brown committed
534 535
	acpi_ut_remove_reference(obj_desc);
	return_ACPI_STATUS(status);
Linus Torvalds's avatar
Linus Torvalds committed
536 537 538 539 540 541
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_rs_get_prs_method_data
 *
Bob Moore's avatar
Bob Moore committed
542 543 544
 * PARAMETERS:  Handle          - Handle to the containing object
 *              ret_buffer      - Pointer to a buffer structure for the
 *                                results
Linus Torvalds's avatar
Linus Torvalds committed
545 546 547 548 549 550 551 552 553 554
 *
 * RETURN:      Status
 *
 * DESCRIPTION: This function is called to get the _PRS value of an object
 *              contained in an object specified by the handle passed in
 *
 *              If the function fails an appropriate status will be returned
 *              and the contents of the callers buffer is undefined.
 *
 ******************************************************************************/
555

Linus Torvalds's avatar
Linus Torvalds committed
556 557
#ifdef ACPI_FUTURE_USAGE
acpi_status
Len Brown's avatar
Len Brown committed
558
acpi_rs_get_prs_method_data(acpi_handle handle, struct acpi_buffer *ret_buffer)
Linus Torvalds's avatar
Linus Torvalds committed
559
{
Len Brown's avatar
Len Brown committed
560 561
	union acpi_operand_object *obj_desc;
	acpi_status status;
Linus Torvalds's avatar
Linus Torvalds committed
562

Len Brown's avatar
Len Brown committed
563
	ACPI_FUNCTION_TRACE("rs_get_prs_method_data");
Linus Torvalds's avatar
Linus Torvalds committed
564 565 566

	/* Parameters guaranteed valid by caller */

567 568
	/* Execute the method, no parameters */

Len Brown's avatar
Len Brown committed
569 570 571 572
	status = acpi_ut_evaluate_object(handle, METHOD_NAME__PRS,
					 ACPI_BTYPE_BUFFER, &obj_desc);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
Linus Torvalds's avatar
Linus Torvalds committed
573 574 575 576 577 578 579
	}

	/*
	 * Make the call to create a resource linked list from the
	 * byte stream buffer that comes back from the _CRS method
	 * execution.
	 */
Len Brown's avatar
Len Brown committed
580
	status = acpi_rs_create_resource_list(obj_desc, ret_buffer);
Linus Torvalds's avatar
Linus Torvalds committed
581 582 583

	/* on exit, we must delete the object returned by evaluate_object */

Len Brown's avatar
Len Brown committed
584 585
	acpi_ut_remove_reference(obj_desc);
	return_ACPI_STATUS(status);
Linus Torvalds's avatar
Linus Torvalds committed
586
}
Len Brown's avatar
Len Brown committed
587
#endif				/*  ACPI_FUTURE_USAGE  */
Linus Torvalds's avatar
Linus Torvalds committed
588 589 590 591 592

/*******************************************************************************
 *
 * FUNCTION:    acpi_rs_get_method_data
 *
Bob Moore's avatar
Bob Moore committed
593
 * PARAMETERS:  Handle          - Handle to the containing object
594
 *              Path            - Path to method, relative to Handle
Bob Moore's avatar
Bob Moore committed
595 596
 *              ret_buffer      - Pointer to a buffer structure for the
 *                                results
Linus Torvalds's avatar
Linus Torvalds committed
597 598 599 600 601 602 603 604 605 606 607 608
 *
 * RETURN:      Status
 *
 * DESCRIPTION: This function is called to get the _CRS or _PRS value of an
 *              object contained in an object specified by the handle passed in
 *
 *              If the function fails an appropriate status will be returned
 *              and the contents of the callers buffer is undefined.
 *
 ******************************************************************************/

acpi_status
Len Brown's avatar
Len Brown committed
609 610
acpi_rs_get_method_data(acpi_handle handle,
			char *path, struct acpi_buffer *ret_buffer)
Linus Torvalds's avatar
Linus Torvalds committed
611
{
Len Brown's avatar
Len Brown committed
612 613
	union acpi_operand_object *obj_desc;
	acpi_status status;
Linus Torvalds's avatar
Linus Torvalds committed
614

Len Brown's avatar
Len Brown committed
615
	ACPI_FUNCTION_TRACE("rs_get_method_data");
Linus Torvalds's avatar
Linus Torvalds committed
616 617 618

	/* Parameters guaranteed valid by caller */

619 620
	/* Execute the method, no parameters */

Len Brown's avatar
Len Brown committed
621 622 623 624
	status =
	    acpi_ut_evaluate_object(handle, path, ACPI_BTYPE_BUFFER, &obj_desc);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
Linus Torvalds's avatar
Linus Torvalds committed
625 626 627 628 629 630 631
	}

	/*
	 * Make the call to create a resource linked list from the
	 * byte stream buffer that comes back from the method
	 * execution.
	 */
Len Brown's avatar
Len Brown committed
632
	status = acpi_rs_create_resource_list(obj_desc, ret_buffer);
Linus Torvalds's avatar
Linus Torvalds committed
633 634 635

	/* On exit, we must delete the object returned by evaluate_object */

Len Brown's avatar
Len Brown committed
636 637
	acpi_ut_remove_reference(obj_desc);
	return_ACPI_STATUS(status);
Linus Torvalds's avatar
Linus Torvalds committed
638 639 640 641 642 643
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_rs_set_srs_method_data
 *
Bob Moore's avatar
Bob Moore committed
644 645 646
 * PARAMETERS:  Handle          - Handle to the containing object
 *              in_buffer       - Pointer to a buffer structure of the
 *                                parameter
Linus Torvalds's avatar
Linus Torvalds committed
647 648 649 650 651 652 653 654 655 656 657 658
 *
 * RETURN:      Status
 *
 * DESCRIPTION: This function is called to set the _SRS of an object contained
 *              in an object specified by the handle passed in
 *
 *              If the function fails an appropriate status will be returned
 *              and the contents of the callers buffer is undefined.
 *
 ******************************************************************************/

acpi_status
Len Brown's avatar
Len Brown committed
659
acpi_rs_set_srs_method_data(acpi_handle handle, struct acpi_buffer *in_buffer)
Linus Torvalds's avatar
Linus Torvalds committed
660
{
Len Brown's avatar
Len Brown committed
661 662 663 664
	struct acpi_parameter_info info;
	union acpi_operand_object *params[2];
	acpi_status status;
	struct acpi_buffer buffer;
Linus Torvalds's avatar
Linus Torvalds committed
665

Len Brown's avatar
Len Brown committed
666
	ACPI_FUNCTION_TRACE("rs_set_srs_method_data");
Linus Torvalds's avatar
Linus Torvalds committed
667 668 669 670 671 672 673 674 675 676 677

	/* Parameters guaranteed valid by caller */

	/*
	 * The in_buffer parameter will point to a linked list of
	 * resource parameters.  It needs to be formatted into a
	 * byte stream to be sent in as an input parameter to _SRS
	 *
	 * Convert the linked list into a byte stream
	 */
	buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
Bob Moore's avatar
Bob Moore committed
678
	status = acpi_rs_create_aml_resources(in_buffer->pointer, &buffer);
Len Brown's avatar
Len Brown committed
679 680
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
Linus Torvalds's avatar
Linus Torvalds committed
681 682
	}

683 684
	/* Init the param object */

Len Brown's avatar
Len Brown committed
685
	params[0] = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER);
Linus Torvalds's avatar
Linus Torvalds committed
686
	if (!params[0]) {
Len Brown's avatar
Len Brown committed
687 688
		acpi_os_free(buffer.pointer);
		return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds's avatar
Linus Torvalds committed
689 690
	}

691 692
	/* Set up the parameter object */

Len Brown's avatar
Len Brown committed
693
	params[0]->buffer.length = (u32) buffer.length;
Linus Torvalds's avatar
Linus Torvalds committed
694
	params[0]->buffer.pointer = buffer.pointer;
Len Brown's avatar
Len Brown committed
695
	params[0]->common.flags = AOPOBJ_DATA_VALID;
Linus Torvalds's avatar
Linus Torvalds committed
696 697 698 699 700 701
	params[1] = NULL;

	info.node = handle;
	info.parameters = params;
	info.parameter_type = ACPI_PARAM_ARGS;

702 703
	/* Execute the method, no return value */

Len Brown's avatar
Len Brown committed
704 705
	status = acpi_ns_evaluate_relative(METHOD_NAME__SRS, &info);
	if (ACPI_SUCCESS(status)) {
Bob Moore's avatar
Bob Moore committed
706

Linus Torvalds's avatar
Linus Torvalds committed
707 708 709
		/* Delete any return object (especially if implicit_return is enabled) */

		if (info.return_object) {
Len Brown's avatar
Len Brown committed
710
			acpi_ut_remove_reference(info.return_object);
Linus Torvalds's avatar
Linus Torvalds committed
711 712 713
		}
	}

714 715
	/* Clean up and return the status from acpi_ns_evaluate_relative */

Len Brown's avatar
Len Brown committed
716 717
	acpi_ut_remove_reference(params[0]);
	return_ACPI_STATUS(status);
Linus Torvalds's avatar
Linus Torvalds committed
718
}