rsaddr.c 22.5 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 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
/*******************************************************************************
 *
 * Module Name: rsaddr - Address resource descriptors (16/32/64)
 *
 ******************************************************************************/

/*
 * Copyright (C) 2000 - 2005, R. Byron Moore
 * 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/acresrc.h>

#define _COMPONENT          ACPI_RESOURCES
L
Len Brown 已提交
48
ACPI_MODULE_NAME("rsaddr")
L
Linus Torvalds 已提交
49

R
Robert Moore 已提交
50 51 52 53 54 55 56 57 58 59 60
/* Local prototypes */
static void
acpi_rs_decode_general_flags(union acpi_resource_data *resource, u8 flags);

static u8 acpi_rs_encode_general_flags(union acpi_resource_data *resource);

static void
acpi_rs_decode_specific_flags(union acpi_resource_data *resource, u8 flags);

static u8 acpi_rs_encode_specific_flags(union acpi_resource_data *resource);

B
Bob Moore 已提交
61 62 63 64 65 66 67 68
static void
acpi_rs_set_address_common(union aml_resource *aml,
			   struct acpi_resource *resource);

static u8
acpi_rs_get_address_common(struct acpi_resource *resource,
			   union aml_resource *aml);

R
Robert Moore 已提交
69 70 71 72 73
/*******************************************************************************
 *
 * FUNCTION:    acpi_rs_decode_general_flags
 *
 * PARAMETERS:  Resource            - Address resource data struct
B
Bob Moore 已提交
74
 *              Flags               - Raw AML flag byte
R
Robert Moore 已提交
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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
 *
 * RETURN:      Decoded flag bits in resource struct
 *
 * DESCRIPTION: Decode a general flag byte to an address resource struct
 *
 ******************************************************************************/

static void
acpi_rs_decode_general_flags(union acpi_resource_data *resource, u8 flags)
{
	ACPI_FUNCTION_ENTRY();

	/* Producer / Consumer - flag bit[0] */

	resource->address.producer_consumer = (u32) (flags & 0x01);

	/* Decode (_DEC) - flag bit[1] */

	resource->address.decode = (u32) ((flags >> 1) & 0x01);

	/* Min Address Fixed (_MIF) - flag bit[2] */

	resource->address.min_address_fixed = (u32) ((flags >> 2) & 0x01);

	/* Max Address Fixed (_MAF) - flag bit[3] */

	resource->address.max_address_fixed = (u32) ((flags >> 3) & 0x01);
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_rs_encode_general_flags
 *
 * PARAMETERS:  Resource            - Address resource data struct
 *
 * RETURN:      Encoded general flag byte
 *
 * DESCRIPTION: Construct a general flag byte from an address resource struct
 *
 ******************************************************************************/

static u8 acpi_rs_encode_general_flags(union acpi_resource_data *resource)
{
	ACPI_FUNCTION_ENTRY();

B
Bob Moore 已提交
120 121 122 123 124 125 126 127 128 129 130
	return ((u8)

		/* Producer / Consumer - flag bit[0] */
		((resource->address.producer_consumer & 0x01) |
		 /* Decode (_DEC) - flag bit[1] */
		 ((resource->address.decode & 0x01) << 1) |
		 /* Min Address Fixed (_MIF) - flag bit[2] */
		 ((resource->address.min_address_fixed & 0x01) << 2) |
		 /* Max Address Fixed (_MAF) - flag bit[3] */
		 ((resource->address.max_address_fixed & 0x01) << 3))
	    );
R
Robert Moore 已提交
131 132 133 134 135 136 137
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_rs_decode_specific_flags
 *
 * PARAMETERS:  Resource            - Address resource data struct
B
Bob Moore 已提交
138
 *              Flags               - Raw AML flag byte
R
Robert Moore 已提交
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
 *
 * RETURN:      Decoded flag bits in attribute struct
 *
 * DESCRIPTION: Decode a type-specific flag byte to an attribute struct.
 *              Type-specific flags are only defined for the Memory and IO
 *              resource types.
 *
 ******************************************************************************/

static void
acpi_rs_decode_specific_flags(union acpi_resource_data *resource, u8 flags)
{
	ACPI_FUNCTION_ENTRY();

	if (resource->address.resource_type == ACPI_MEMORY_RANGE) {
		/* Write Status (_RW) - flag bit[0] */

		resource->address.attribute.memory.read_write_attribute =
		    (u16) (flags & 0x01);

		/* Memory Attributes (_MEM) - flag bits[2:1] */

		resource->address.attribute.memory.cache_attribute =
		    (u16) ((flags >> 1) & 0x03);
	} else if (resource->address.resource_type == ACPI_IO_RANGE) {
		/* Ranges (_RNG) - flag bits[1:0] */

		resource->address.attribute.io.range_attribute =
		    (u16) (flags & 0x03);

		/* Translations (_TTP and _TRS) - flag bits[5:4] */

		resource->address.attribute.io.translation_attribute =
		    (u16) ((flags >> 4) & 0x03);
	}
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_rs_encode_specific_flags
 *
 * PARAMETERS:  Resource            - Address resource data struct
 *
 * RETURN:      Encoded type-specific flag byte
 *
 * DESCRIPTION: Construct a type-specific flag byte from an attribute struct.
 *              Type-specific flags are only defined for the Memory and IO
 *              resource types.
 *
 ******************************************************************************/

static u8 acpi_rs_encode_specific_flags(union acpi_resource_data *resource)
{
	ACPI_FUNCTION_ENTRY();

	if (resource->address.resource_type == ACPI_MEMORY_RANGE) {
B
Bob Moore 已提交
195 196 197 198 199 200 201 202
		return ((u8)

			/* Write Status (_RW) - flag bit[0] */
			((resource->address.attribute.memory.
			  read_write_attribute & 0x01) |
			 /* Memory Attributes (_MEM) - flag bits[2:1] */
			 ((resource->address.attribute.memory.
			   cache_attribute & 0x03) << 1)));
R
Robert Moore 已提交
203
	} else if (resource->address.resource_type == ACPI_IO_RANGE) {
B
Bob Moore 已提交
204 205 206 207 208 209 210 211
		return ((u8)

			/* Ranges (_RNG) - flag bits[1:0] */
			((resource->address.attribute.io.
			  range_attribute & 0x03) |
			 /* Translations (_TTP and _TRS) - flag bits[5:4] */
			 ((resource->address.attribute.io.
			   translation_attribute & 0x03) << 4)));
R
Robert Moore 已提交
212 213
	}

B
Bob Moore 已提交
214
	return (0);
R
Robert Moore 已提交
215 216
}

L
Linus Torvalds 已提交
217 218
/*******************************************************************************
 *
B
Bob Moore 已提交
219
 * FUNCTION:    acpi_rs_set_address_common
L
Linus Torvalds 已提交
220
 *
B
Bob Moore 已提交
221 222
 * PARAMETERS:  Aml                 - Pointer to the AML resource descriptor
 *              Resource            - Pointer to the internal resource struct
L
Linus Torvalds 已提交
223
 *
B
Bob Moore 已提交
224
 * RETURN:      None
L
Linus Torvalds 已提交
225
 *
B
Bob Moore 已提交
226 227
 * DESCRIPTION: Convert common flag fields from a resource descriptor to an
 *              AML descriptor
L
Linus Torvalds 已提交
228 229
 *
 ******************************************************************************/
R
Robert Moore 已提交
230

B
Bob Moore 已提交
231 232 233
static void
acpi_rs_set_address_common(union aml_resource *aml,
			   struct acpi_resource *resource)
L
Linus Torvalds 已提交
234
{
B
Bob Moore 已提交
235
	ACPI_FUNCTION_ENTRY();
L
Linus Torvalds 已提交
236

B
Bob Moore 已提交
237
	/* Set the Resource Type (Memory, Io, bus_number, etc.) */
L
Linus Torvalds 已提交
238

B
Bob Moore 已提交
239
	aml->address.resource_type = (u8) resource->data.address.resource_type;
R
Robert Moore 已提交
240

B
Bob Moore 已提交
241
	/* Set the general flags */
L
Linus Torvalds 已提交
242

B
Bob Moore 已提交
243
	aml->address.flags = acpi_rs_encode_general_flags(&resource->data);
L
Linus Torvalds 已提交
244

B
Bob Moore 已提交
245
	/* Set the type-specific flags */
L
Linus Torvalds 已提交
246

B
Bob Moore 已提交
247 248 249
	aml->address.specific_flags =
	    acpi_rs_encode_specific_flags(&resource->data);
}
L
Linus Torvalds 已提交
250

B
Bob Moore 已提交
251 252 253 254 255 256 257 258 259 260 261 262 263
/*******************************************************************************
 *
 * FUNCTION:    acpi_rs_get_address_common
 *
 * PARAMETERS:  Resource            - Pointer to the internal resource struct
 *              Aml                 - Pointer to the AML resource descriptor
 *
 * RETURN:      TRUE if the resource_type field is OK, FALSE otherwise
 *
 * DESCRIPTION: Convert common flag fields from a raw AML resource descriptor
 *              to an internal resource descriptor
 *
 ******************************************************************************/
R
Robert Moore 已提交
264

B
Bob Moore 已提交
265 266 267 268 269
static u8
acpi_rs_get_address_common(struct acpi_resource *resource,
			   union aml_resource *aml)
{
	ACPI_FUNCTION_ENTRY();
L
Linus Torvalds 已提交
270

B
Bob Moore 已提交
271
	/* Validate resource type */
L
Linus Torvalds 已提交
272

B
Bob Moore 已提交
273 274 275
	if ((aml->address.resource_type > 2)
	    && (aml->address.resource_type < 0xC0)) {
		return (FALSE);
L
Linus Torvalds 已提交
276 277
	}

B
Bob Moore 已提交
278
	/* Get the Resource Type (Memory, Io, bus_number, etc.) */
L
Linus Torvalds 已提交
279

B
Bob Moore 已提交
280
	resource->data.address.resource_type = aml->address.resource_type;
R
Robert Moore 已提交
281

B
Bob Moore 已提交
282
	/* Get the General Flags */
L
Linus Torvalds 已提交
283

B
Bob Moore 已提交
284
	acpi_rs_decode_general_flags(&resource->data, aml->address.flags);
R
Robert Moore 已提交
285

B
Bob Moore 已提交
286
	/* Get the Type-Specific Flags */
L
Linus Torvalds 已提交
287

B
Bob Moore 已提交
288 289 290 291
	acpi_rs_decode_specific_flags(&resource->data,
				      aml->address.specific_flags);
	return (TRUE);
}
R
Robert Moore 已提交
292

B
Bob Moore 已提交
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
/*******************************************************************************
 *
 * FUNCTION:    acpi_rs_get_address16
 *
 * PARAMETERS:  Aml                 - Pointer to the AML resource descriptor
 *              aml_resource_length - Length of the resource from the AML header
 *              Resource            - Where the internal resource is returned
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Convert a raw AML resource descriptor to the corresponding
 *              internal resource descriptor, simplifying bitflags and handling
 *              alignment and endian issues if necessary.
 *
 ******************************************************************************/
L
Linus Torvalds 已提交
308

B
Bob Moore 已提交
309 310 311 312 313
acpi_status
acpi_rs_get_address16(union aml_resource * aml,
		      u16 aml_resource_length, struct acpi_resource * resource)
{
	ACPI_FUNCTION_TRACE("rs_get_address16");
L
Linus Torvalds 已提交
314

B
Bob Moore 已提交
315
	/* Get the Resource Type, general flags, and type-specific flags */
R
Robert Moore 已提交
316

B
Bob Moore 已提交
317 318 319
	if (!acpi_rs_get_address_common(resource, aml)) {
		return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE);
	}
L
Linus Torvalds 已提交
320 321

	/*
B
Bob Moore 已提交
322 323 324 325 326 327
	 * Get the following contiguous fields from the AML descriptor:
	 * Address Granularity
	 * Address Range Minimum
	 * Address Range Maximum
	 * Address Translation Offset
	 * Address Length
L
Linus Torvalds 已提交
328
	 */
B
Bob Moore 已提交
329 330 331
	acpi_rs_move_data(&resource->data.address16.granularity,
			  &aml->address16.granularity, 5,
			  ACPI_MOVE_TYPE_16_TO_32);
L
Linus Torvalds 已提交
332

B
Bob Moore 已提交
333
	/* Get the optional resource_source (index and string) */
L
Linus Torvalds 已提交
334

B
Bob Moore 已提交
335 336 337 338 339 340
	resource->length =
	    ACPI_SIZEOF_RESOURCE(struct acpi_resource_address16) +
	    acpi_rs_get_resource_source(aml_resource_length,
					sizeof(struct aml_resource_address16),
					&resource->data.address16.
					resource_source, aml, NULL);
L
Linus Torvalds 已提交
341

B
Bob Moore 已提交
342
	/* Complete the resource header */
L
Linus Torvalds 已提交
343

B
Bob Moore 已提交
344
	resource->type = ACPI_RESOURCE_TYPE_ADDRESS16;
L
Len Brown 已提交
345
	return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
346 347 348 349
}

/*******************************************************************************
 *
B
Bob Moore 已提交
350
 * FUNCTION:    acpi_rs_set_address16
L
Linus Torvalds 已提交
351
 *
B
Bob Moore 已提交
352 353
 * PARAMETERS:  Resource            - Pointer to the resource descriptor
 *              Aml                 - Where the AML descriptor is returned
L
Linus Torvalds 已提交
354 355 356
 *
 * RETURN:      Status
 *
B
Bob Moore 已提交
357 358
 * DESCRIPTION: Convert an internal resource descriptor to the corresponding
 *              external AML resource descriptor.
L
Linus Torvalds 已提交
359 360 361 362
 *
 ******************************************************************************/

acpi_status
B
Bob Moore 已提交
363
acpi_rs_set_address16(struct acpi_resource *resource, union aml_resource *aml)
L
Linus Torvalds 已提交
364
{
B
Bob Moore 已提交
365
	acpi_size descriptor_length;
R
Robert Moore 已提交
366

B
Bob Moore 已提交
367
	ACPI_FUNCTION_TRACE("rs_set_address16");
L
Linus Torvalds 已提交
368

B
Bob Moore 已提交
369
	/* Set the Resource Type, General Flags, and Type-Specific Flags */
R
Robert Moore 已提交
370

B
Bob Moore 已提交
371
	acpi_rs_set_address_common(aml, resource);
R
Robert Moore 已提交
372

B
Bob Moore 已提交
373 374 375 376 377 378 379 380 381 382 383
	/*
	 * Set the following contiguous fields in the AML descriptor:
	 * Address Granularity
	 * Address Range Minimum
	 * Address Range Maximum
	 * Address Translation Offset
	 * Address Length
	 */
	acpi_rs_move_data(&aml->address16.granularity,
			  &resource->data.address16.granularity, 5,
			  ACPI_MOVE_TYPE_32_TO_16);
L
Linus Torvalds 已提交
384

R
Robert Moore 已提交
385 386
	/* Resource Source Index and Resource Source are optional */

B
Bob Moore 已提交
387 388 389 390 391 392
	descriptor_length = acpi_rs_set_resource_source(aml,
							sizeof(struct
							       aml_resource_address16),
							&resource->data.
							address16.
							resource_source);
L
Linus Torvalds 已提交
393

B
Bob Moore 已提交
394
	/* Complete the AML descriptor header */
R
Robert Moore 已提交
395

B
Bob Moore 已提交
396 397
	acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_ADDRESS16,
				    descriptor_length, aml);
L
Len Brown 已提交
398
	return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
399 400 401 402
}

/*******************************************************************************
 *
B
Bob Moore 已提交
403
 * FUNCTION:    acpi_rs_get_address32
L
Linus Torvalds 已提交
404
 *
B
Bob Moore 已提交
405 406 407
 * PARAMETERS:  Aml                 - Pointer to the AML resource descriptor
 *              aml_resource_length - Length of the resource from the AML header
 *              Resource            - Where the internal resource is returned
L
Linus Torvalds 已提交
408 409 410
 *
 * RETURN:      Status
 *
B
Bob Moore 已提交
411 412 413
 * DESCRIPTION: Convert a raw AML resource descriptor to the corresponding
 *              internal resource descriptor, simplifying bitflags and handling
 *              alignment and endian issues if necessary.
L
Linus Torvalds 已提交
414 415 416 417
 *
 ******************************************************************************/

acpi_status
B
Bob Moore 已提交
418 419
acpi_rs_get_address32(union aml_resource *aml,
		      u16 aml_resource_length, struct acpi_resource *resource)
L
Linus Torvalds 已提交
420 421
{

B
Bob Moore 已提交
422
	ACPI_FUNCTION_TRACE("rs_get_address32");
L
Linus Torvalds 已提交
423

B
Bob Moore 已提交
424
	/* Get the Resource Type, general flags, and type-specific flags */
L
Linus Torvalds 已提交
425

B
Bob Moore 已提交
426
	if (!acpi_rs_get_address_common(resource, (void *)aml)) {
L
Len Brown 已提交
427
		return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE);
L
Linus Torvalds 已提交
428 429 430
	}

	/*
B
Bob Moore 已提交
431 432 433 434 435 436
	 * Get the following contiguous fields from the AML descriptor:
	 * Address Granularity
	 * Address Range Minimum
	 * Address Range Maximum
	 * Address Translation Offset
	 * Address Length
L
Linus Torvalds 已提交
437
	 */
B
Bob Moore 已提交
438 439 440
	acpi_rs_move_data(&resource->data.address32.granularity,
			  &aml->address32.granularity, 5,
			  ACPI_MOVE_TYPE_32_TO_32);
L
Linus Torvalds 已提交
441

B
Bob Moore 已提交
442
	/* Get the optional resource_source (index and string) */
L
Linus Torvalds 已提交
443

B
Bob Moore 已提交
444 445 446 447 448 449
	resource->length =
	    ACPI_SIZEOF_RESOURCE(struct acpi_resource_address32) +
	    acpi_rs_get_resource_source(aml_resource_length,
					sizeof(struct aml_resource_address32),
					&resource->data.address32.
					resource_source, aml, NULL);
L
Linus Torvalds 已提交
450

B
Bob Moore 已提交
451
	/* Complete the resource header */
L
Linus Torvalds 已提交
452

B
Bob Moore 已提交
453
	resource->type = ACPI_RESOURCE_TYPE_ADDRESS32;
L
Len Brown 已提交
454
	return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
455 456 457 458
}

/*******************************************************************************
 *
B
Bob Moore 已提交
459
 * FUNCTION:    acpi_rs_set_address32
L
Linus Torvalds 已提交
460
 *
B
Bob Moore 已提交
461 462
 * PARAMETERS:  Resource            - Pointer to the resource descriptor
 *              Aml                 - Where the AML descriptor is returned
L
Linus Torvalds 已提交
463 464 465
 *
 * RETURN:      Status
 *
B
Bob Moore 已提交
466 467
 * DESCRIPTION: Convert an internal resource descriptor to the corresponding
 *              external AML resource descriptor.
L
Linus Torvalds 已提交
468 469 470 471
 *
 ******************************************************************************/

acpi_status
B
Bob Moore 已提交
472
acpi_rs_set_address32(struct acpi_resource *resource, union aml_resource *aml)
L
Linus Torvalds 已提交
473
{
B
Bob Moore 已提交
474
	acpi_size descriptor_length;
L
Linus Torvalds 已提交
475

B
Bob Moore 已提交
476
	ACPI_FUNCTION_TRACE("rs_set_address32");
R
Robert Moore 已提交
477

B
Bob Moore 已提交
478
	/* Set the Resource Type, General Flags, and Type-Specific Flags */
L
Linus Torvalds 已提交
479

B
Bob Moore 已提交
480
	acpi_rs_set_address_common(aml, resource);
R
Robert Moore 已提交
481

B
Bob Moore 已提交
482 483 484 485 486 487 488 489 490 491 492
	/*
	 * Set the following contiguous fields in the AML descriptor:
	 * Address Granularity
	 * Address Range Minimum
	 * Address Range Maximum
	 * Address Translation Offset
	 * Address Length
	 */
	acpi_rs_move_data(&aml->address32.granularity,
			  &resource->data.address32.granularity, 5,
			  ACPI_MOVE_TYPE_32_TO_32);
L
Linus Torvalds 已提交
493

R
Robert Moore 已提交
494 495
	/* Resource Source Index and Resource Source are optional */

B
Bob Moore 已提交
496 497 498 499 500 501
	descriptor_length = acpi_rs_set_resource_source(aml,
							sizeof(struct
							       aml_resource_address32),
							&resource->data.
							address32.
							resource_source);
R
Robert Moore 已提交
502

B
Bob Moore 已提交
503
	/* Complete the AML descriptor header */
L
Linus Torvalds 已提交
504

B
Bob Moore 已提交
505 506
	acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_ADDRESS32,
				    descriptor_length, aml);
L
Len Brown 已提交
507
	return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
508 509 510 511
}

/*******************************************************************************
 *
B
Bob Moore 已提交
512
 * FUNCTION:    acpi_rs_get_address64
L
Linus Torvalds 已提交
513
 *
B
Bob Moore 已提交
514 515 516
 * PARAMETERS:  Aml                 - Pointer to the AML resource descriptor
 *              aml_resource_length - Length of the resource from the AML header
 *              Resource            - Where the internal resource is returned
L
Linus Torvalds 已提交
517 518 519
 *
 * RETURN:      Status
 *
B
Bob Moore 已提交
520 521 522
 * DESCRIPTION: Convert a raw AML resource descriptor to the corresponding
 *              internal resource descriptor, simplifying bitflags and handling
 *              alignment and endian issues if necessary.
L
Linus Torvalds 已提交
523 524 525 526
 *
 ******************************************************************************/

acpi_status
B
Bob Moore 已提交
527 528
acpi_rs_get_address64(union aml_resource *aml,
		      u16 aml_resource_length, struct acpi_resource *resource)
L
Linus Torvalds 已提交
529
{
B
Bob Moore 已提交
530
	ACPI_FUNCTION_TRACE("rs_get_address64");
R
Robert Moore 已提交
531

B
Bob Moore 已提交
532
	/* Get the Resource Type, general Flags, and type-specific Flags */
L
Linus Torvalds 已提交
533

B
Bob Moore 已提交
534
	if (!acpi_rs_get_address_common(resource, aml)) {
L
Len Brown 已提交
535
		return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE);
L
Linus Torvalds 已提交
536 537
	}

B
Bob Moore 已提交
538 539 540 541 542 543 544 545 546 547 548
	/*
	 * Get the following contiguous fields from the AML descriptor:
	 * Address Granularity
	 * Address Range Minimum
	 * Address Range Maximum
	 * Address Translation Offset
	 * Address Length
	 */
	acpi_rs_move_data(&resource->data.address64.granularity,
			  &aml->address64.granularity, 5,
			  ACPI_MOVE_TYPE_64_TO_64);
R
Robert Moore 已提交
549

B
Bob Moore 已提交
550
	/* Get the optional resource_source (index and string) */
L
Linus Torvalds 已提交
551

B
Bob Moore 已提交
552 553 554 555 556 557
	resource->length =
	    ACPI_SIZEOF_RESOURCE(struct acpi_resource_address64) +
	    acpi_rs_get_resource_source(aml_resource_length,
					sizeof(struct aml_resource_address64),
					&resource->data.address64.
					resource_source, aml, NULL);
L
Linus Torvalds 已提交
558

B
Bob Moore 已提交
559
	/* Complete the resource header */
L
Linus Torvalds 已提交
560

B
Bob Moore 已提交
561 562 563
	resource->type = ACPI_RESOURCE_TYPE_ADDRESS64;
	return_ACPI_STATUS(AE_OK);
}
L
Linus Torvalds 已提交
564

B
Bob Moore 已提交
565 566 567 568 569 570 571 572 573 574 575 576 577
/*******************************************************************************
 *
 * FUNCTION:    acpi_rs_set_address64
 *
 * PARAMETERS:  Resource            - Pointer to the resource descriptor
 *              Aml                 - Where the AML descriptor is returned
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Convert an internal resource descriptor to the corresponding
 *              external AML resource descriptor.
 *
 ******************************************************************************/
L
Linus Torvalds 已提交
578

B
Bob Moore 已提交
579 580 581 582
acpi_status
acpi_rs_set_address64(struct acpi_resource *resource, union aml_resource *aml)
{
	acpi_size descriptor_length;
R
Robert Moore 已提交
583

B
Bob Moore 已提交
584
	ACPI_FUNCTION_TRACE("rs_set_address64");
L
Linus Torvalds 已提交
585

B
Bob Moore 已提交
586
	/* Set the Resource Type, General Flags, and Type-Specific Flags */
L
Linus Torvalds 已提交
587

B
Bob Moore 已提交
588
	acpi_rs_set_address_common(aml, resource);
L
Linus Torvalds 已提交
589

B
Bob Moore 已提交
590 591 592 593 594 595 596 597 598 599 600
	/*
	 * Set the following contiguous fields in the AML descriptor:
	 * Address Granularity
	 * Address Range Minimum
	 * Address Range Maximum
	 * Address Translation Offset
	 * Address Length
	 */
	acpi_rs_move_data(&aml->address64.granularity,
			  &resource->data.address64.granularity, 5,
			  ACPI_MOVE_TYPE_64_TO_64);
L
Linus Torvalds 已提交
601

B
Bob Moore 已提交
602
	/* Resource Source Index and Resource Source are optional */
L
Linus Torvalds 已提交
603

B
Bob Moore 已提交
604 605 606 607 608 609
	descriptor_length = acpi_rs_set_resource_source(aml,
							sizeof(struct
							       aml_resource_address64),
							&resource->data.
							address64.
							resource_source);
L
Linus Torvalds 已提交
610

B
Bob Moore 已提交
611
	/* Complete the AML descriptor header */
L
Linus Torvalds 已提交
612

B
Bob Moore 已提交
613 614 615 616
	acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_ADDRESS64,
				    descriptor_length, aml);
	return_ACPI_STATUS(AE_OK);
}
L
Linus Torvalds 已提交
617

B
Bob Moore 已提交
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632
/*******************************************************************************
 *
 * FUNCTION:    acpi_rs_get_ext_address64
 *
 * PARAMETERS:  Aml                 - Pointer to the AML resource descriptor
 *              aml_resource_length - Length of the resource from the AML header
 *              Resource            - Where the internal resource is returned
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Convert a raw AML resource descriptor to the corresponding
 *              internal resource descriptor, simplifying bitflags and handling
 *              alignment and endian issues if necessary.
 *
 ******************************************************************************/
L
Linus Torvalds 已提交
633

B
Bob Moore 已提交
634 635 636 637 638
acpi_status
acpi_rs_get_ext_address64(union aml_resource *aml,
			  u16 aml_resource_length,
			  struct acpi_resource *resource)
{
L
Linus Torvalds 已提交
639

B
Bob Moore 已提交
640
	ACPI_FUNCTION_TRACE("rs_get_ext_address64");
L
Linus Torvalds 已提交
641

B
Bob Moore 已提交
642
	/* Get the Resource Type, general flags, and type-specific flags */
L
Linus Torvalds 已提交
643

B
Bob Moore 已提交
644 645
	if (!acpi_rs_get_address_common(resource, aml)) {
		return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE);
L
Linus Torvalds 已提交
646 647
	}

B
Bob Moore 已提交
648 649 650 651 652 653 654 655 656 657
	/*
	 * Get and validate the Revision ID
	 * Note: Only one revision ID is currently supported
	 */
	resource->data.ext_address64.revision_iD =
	    aml->ext_address64.revision_iD;
	if (aml->ext_address64.revision_iD !=
	    AML_RESOURCE_EXTENDED_ADDRESS_REVISION) {
		return_ACPI_STATUS(AE_SUPPORT);
	}
R
Robert Moore 已提交
658

B
Bob Moore 已提交
659 660 661 662 663 664 665 666 667 668 669 670
	/*
	 * Get the following contiguous fields from the AML descriptor:
	 * Address Granularity
	 * Address Range Minimum
	 * Address Range Maximum
	 * Address Translation Offset
	 * Address Length
	 * Type-Specific Attribute
	 */
	acpi_rs_move_data(&resource->data.ext_address64.granularity,
			  &aml->ext_address64.granularity, 6,
			  ACPI_MOVE_TYPE_64_TO_64);
L
Linus Torvalds 已提交
671

B
Bob Moore 已提交
672
	/* Complete the resource header */
R
Robert Moore 已提交
673

B
Bob Moore 已提交
674 675 676
	resource->type = ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64;
	resource->length =
	    ACPI_SIZEOF_RESOURCE(struct acpi_resource_extended_address64);
L
Len Brown 已提交
677
	return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
678 679 680 681
}

/*******************************************************************************
 *
B
Bob Moore 已提交
682
 * FUNCTION:    acpi_rs_set_ext_address64
L
Linus Torvalds 已提交
683
 *
B
Bob Moore 已提交
684 685
 * PARAMETERS:  Resource            - Pointer to the resource descriptor
 *              Aml                 - Where the AML descriptor is returned
L
Linus Torvalds 已提交
686 687 688
 *
 * RETURN:      Status
 *
B
Bob Moore 已提交
689 690
 * DESCRIPTION: Convert an internal resource descriptor to the corresponding
 *              external AML resource descriptor.
L
Linus Torvalds 已提交
691 692 693 694
 *
 ******************************************************************************/

acpi_status
B
Bob Moore 已提交
695 696
acpi_rs_set_ext_address64(struct acpi_resource *resource,
			  union aml_resource *aml)
L
Linus Torvalds 已提交
697
{
B
Bob Moore 已提交
698
	ACPI_FUNCTION_TRACE("rs_set_ext_address64");
R
Robert Moore 已提交
699

B
Bob Moore 已提交
700
	/* Set the Resource Type, General Flags, and Type-Specific Flags */
L
Linus Torvalds 已提交
701

B
Bob Moore 已提交
702
	acpi_rs_set_address_common(aml, resource);
R
Robert Moore 已提交
703

B
Bob Moore 已提交
704
	/* Only one Revision ID is currently supported */
L
Linus Torvalds 已提交
705

B
Bob Moore 已提交
706 707
	aml->ext_address64.revision_iD = AML_RESOURCE_EXTENDED_ADDRESS_REVISION;
	aml->ext_address64.reserved = 0;
L
Linus Torvalds 已提交
708 709

	/*
B
Bob Moore 已提交
710 711 712 713 714 715 716
	 * Set the following contiguous fields in the AML descriptor:
	 * Address Granularity
	 * Address Range Minimum
	 * Address Range Maximum
	 * Address Translation Offset
	 * Address Length
	 * Type-Specific Attribute
L
Linus Torvalds 已提交
717
	 */
B
Bob Moore 已提交
718 719 720 721 722 723 724 725 726 727
	acpi_rs_move_data(&aml->ext_address64.granularity,
			  &resource->data.address64.granularity, 6,
			  ACPI_MOVE_TYPE_64_TO_64);

	/* Complete the AML descriptor header */

	acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_EXTENDED_ADDRESS64,
				    sizeof(struct
					   aml_resource_extended_address64),
				    aml);
L
Len Brown 已提交
728
	return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
729
}