tbxfroot.c 18.0 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 48 49
/******************************************************************************
 *
 * Module Name: tbxfroot - Find the root ACPI table (RSDT)
 *
 *****************************************************************************/

/*
 * 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 <linux/module.h>

#include <acpi/acpi.h>
#include <acpi/actables.h>

#define _COMPONENT          ACPI_TABLES
L
Len Brown 已提交
50
ACPI_MODULE_NAME("tbxfroot")
L
Linus Torvalds 已提交
51

R
Robert Moore 已提交
52 53
/* Local prototypes */
static acpi_status
L
Len Brown 已提交
54
acpi_tb_find_rsdp(struct acpi_table_desc *table_info, u32 flags);
R
Robert Moore 已提交
55

L
Len Brown 已提交
56
static u8 *acpi_tb_scan_memory_for_rsdp(u8 * start_address, u32 length);
L
Linus Torvalds 已提交
57

58 59 60 61 62 63 64 65 66 67 68 69
/*******************************************************************************
 *
 * FUNCTION:    acpi_tb_validate_rsdp
 *
 * PARAMETERS:  Rsdp        - Pointer to unvalidated RSDP
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Validate the RSDP (ptr)
 *
 ******************************************************************************/

L
Len Brown 已提交
70
acpi_status acpi_tb_validate_rsdp(struct rsdp_descriptor *rsdp)
71
{
L
Len Brown 已提交
72
	ACPI_FUNCTION_ENTRY();
73 74 75 76

	/*
	 *  The signature and checksum must both be correct
	 */
L
Len Brown 已提交
77
	if (ACPI_STRNCMP((char *)rsdp, RSDP_SIG, sizeof(RSDP_SIG) - 1) != 0) {
78 79 80 81 82 83 84
		/* Nope, BAD Signature */

		return (AE_BAD_SIGNATURE);
	}

	/* Check the standard checksum */

L
Len Brown 已提交
85
	if (acpi_tb_generate_checksum(rsdp, ACPI_RSDP_CHECKSUM_LENGTH) != 0) {
86 87 88 89 90 91
		return (AE_BAD_CHECKSUM);
	}

	/* Check extended checksum if table version >= 2 */

	if ((rsdp->revision >= 2) &&
L
Len Brown 已提交
92 93
	    (acpi_tb_generate_checksum(rsdp, ACPI_RSDP_XCHECKSUM_LENGTH) !=
	     0)) {
94 95 96 97 98 99
		return (AE_BAD_CHECKSUM);
	}

	return (AE_OK);
}

L
Linus Torvalds 已提交
100 101 102 103 104 105
/*******************************************************************************
 *
 * FUNCTION:    acpi_tb_find_table
 *
 * PARAMETERS:  Signature           - String with ACPI table signature
 *              oem_id              - String with the table OEM ID
R
Robert Moore 已提交
106 107
 *              oem_table_id        - String with the OEM Table ID
 *              table_ptr           - Where the table pointer is returned
L
Linus Torvalds 已提交
108 109 110 111 112 113 114 115 116
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Find an ACPI table (in the RSDT/XSDT) that matches the
 *              Signature, OEM ID and OEM Table ID.
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
117 118 119
acpi_tb_find_table(char *signature,
		   char *oem_id,
		   char *oem_table_id, struct acpi_table_header ** table_ptr)
L
Linus Torvalds 已提交
120
{
L
Len Brown 已提交
121 122
	acpi_status status;
	struct acpi_table_header *table;
L
Linus Torvalds 已提交
123

L
Len Brown 已提交
124
	ACPI_FUNCTION_TRACE("tb_find_table");
L
Linus Torvalds 已提交
125 126 127

	/* Validate string lengths */

L
Len Brown 已提交
128 129 130 131
	if ((ACPI_STRLEN(signature) > ACPI_NAME_SIZE) ||
	    (ACPI_STRLEN(oem_id) > sizeof(table->oem_id)) ||
	    (ACPI_STRLEN(oem_table_id) > sizeof(table->oem_table_id))) {
		return_ACPI_STATUS(AE_AML_STRING_LIMIT);
L
Linus Torvalds 已提交
132 133
	}

L
Len Brown 已提交
134
	if (!ACPI_STRNCMP(signature, DSDT_SIG, ACPI_NAME_SIZE)) {
L
Linus Torvalds 已提交
135 136 137 138 139 140 141 142
		/*
		 * The DSDT pointer is contained in the FADT, not the RSDT.
		 * This code should suffice, because the only code that would perform
		 * a "find" on the DSDT is the data_table_region() AML opcode -- in
		 * which case, the DSDT is guaranteed to be already loaded.
		 * If this becomes insufficient, the FADT will have to be found first.
		 */
		if (!acpi_gbl_DSDT) {
L
Len Brown 已提交
143
			return_ACPI_STATUS(AE_NO_ACPI_TABLES);
L
Linus Torvalds 已提交
144 145
		}
		table = acpi_gbl_DSDT;
L
Len Brown 已提交
146
	} else {
L
Linus Torvalds 已提交
147 148
		/* Find the table */

L
Len Brown 已提交
149 150 151 152 153
		status = acpi_get_firmware_table(signature, 1,
						 ACPI_LOGICAL_ADDRESSING,
						 &table);
		if (ACPI_FAILURE(status)) {
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
154 155 156 157 158
		}
	}

	/* Check oem_id and oem_table_id */

L
Len Brown 已提交
159 160 161 162 163
	if ((oem_id[0] && ACPI_STRNCMP(oem_id, table->oem_id,
				       sizeof(table->oem_id))) ||
	    (oem_table_id[0] && ACPI_STRNCMP(oem_table_id, table->oem_table_id,
					     sizeof(table->oem_table_id)))) {
		return_ACPI_STATUS(AE_AML_NAME_NOT_FOUND);
L
Linus Torvalds 已提交
164 165
	}

L
Len Brown 已提交
166 167
	ACPI_DEBUG_PRINT((ACPI_DB_TABLES, "Found table [%4.4s]\n",
			  table->signature));
R
Robert Moore 已提交
168

L
Linus Torvalds 已提交
169
	*table_ptr = table;
L
Len Brown 已提交
170
	return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_get_firmware_table
 *
 * PARAMETERS:  Signature       - Any ACPI table signature
 *              Instance        - the non zero instance of the table, allows
 *                                support for multiple tables of the same type
 *              Flags           - Physical/Virtual support
 *              table_pointer   - Where a buffer containing the table is
 *                                returned
 *
 * RETURN:      Status
 *
 * DESCRIPTION: This function is called to get an ACPI table. A buffer is
 *              allocated for the table and returned in table_pointer.
 *              This table will be a complete table including the header.
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
193 194 195
acpi_get_firmware_table(acpi_string signature,
			u32 instance,
			u32 flags, struct acpi_table_header **table_pointer)
L
Linus Torvalds 已提交
196
{
L
Len Brown 已提交
197 198 199 200 201 202 203 204
	acpi_status status;
	struct acpi_pointer address;
	struct acpi_table_header *header = NULL;
	struct acpi_table_desc *table_info = NULL;
	struct acpi_table_desc *rsdt_info;
	u32 table_count;
	u32 i;
	u32 j;
L
Linus Torvalds 已提交
205

L
Len Brown 已提交
206
	ACPI_FUNCTION_TRACE("acpi_get_firmware_table");
L
Linus Torvalds 已提交
207 208 209 210 211 212

	/*
	 * Ensure that at least the table manager is initialized.  We don't
	 * require that the entire ACPI subsystem is up for this interface.
	 * If we have a buffer, we must have a length too
	 */
L
Len Brown 已提交
213 214
	if ((instance == 0) || (!signature) || (!table_pointer)) {
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
215 216 217 218 219 220 221
	}

	/* Ensure that we have a RSDP */

	if (!acpi_gbl_RSDP) {
		/* Get the RSDP */

L
Len Brown 已提交
222 223 224 225
		status = acpi_os_get_root_pointer(flags, &address);
		if (ACPI_FAILURE(status)) {
			ACPI_DEBUG_PRINT((ACPI_DB_INFO, "RSDP not found\n"));
			return_ACPI_STATUS(AE_NO_ACPI_TABLES);
L
Linus Torvalds 已提交
226 227 228 229 230
		}

		/* Map and validate the RSDP */

		if ((flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING) {
L
Len Brown 已提交
231 232 233 234 235 236
			status = acpi_os_map_memory(address.pointer.physical,
						    sizeof(struct
							   rsdp_descriptor),
						    (void *)&acpi_gbl_RSDP);
			if (ACPI_FAILURE(status)) {
				return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
237
			}
L
Len Brown 已提交
238
		} else {
L
Linus Torvalds 已提交
239 240 241
			acpi_gbl_RSDP = address.pointer.logical;
		}

242
		/* The RDSP signature and checksum must both be correct */
L
Linus Torvalds 已提交
243

L
Len Brown 已提交
244 245 246
		status = acpi_tb_validate_rsdp(acpi_gbl_RSDP);
		if (ACPI_FAILURE(status)) {
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
247 248 249 250 251
		}
	}

	/* Get the RSDT address via the RSDP */

L
Len Brown 已提交
252 253 254 255 256
	acpi_tb_get_rsdt_address(&address);
	ACPI_DEBUG_PRINT((ACPI_DB_INFO,
			  "RSDP located at %p, RSDT physical=%8.8X%8.8X \n",
			  acpi_gbl_RSDP,
			  ACPI_FORMAT_UINT64(address.pointer.value)));
L
Linus Torvalds 已提交
257 258 259 260 261 262 263

	/* Insert processor_mode flags */

	address.pointer_type |= flags;

	/* Get and validate the RSDT */

L
Len Brown 已提交
264
	rsdt_info = ACPI_MEM_CALLOCATE(sizeof(struct acpi_table_desc));
L
Linus Torvalds 已提交
265
	if (!rsdt_info) {
L
Len Brown 已提交
266
		return_ACPI_STATUS(AE_NO_MEMORY);
L
Linus Torvalds 已提交
267 268
	}

L
Len Brown 已提交
269 270
	status = acpi_tb_get_table(&address, rsdt_info);
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
271 272 273
		goto cleanup;
	}

L
Len Brown 已提交
274 275
	status = acpi_tb_validate_rsdt(rsdt_info->pointer);
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
276 277 278 279 280
		goto cleanup;
	}

	/* Allocate a scratch table header and table descriptor */

L
Len Brown 已提交
281
	header = ACPI_MEM_ALLOCATE(sizeof(struct acpi_table_header));
L
Linus Torvalds 已提交
282 283 284 285 286
	if (!header) {
		status = AE_NO_MEMORY;
		goto cleanup;
	}

L
Len Brown 已提交
287
	table_info = ACPI_MEM_ALLOCATE(sizeof(struct acpi_table_desc));
L
Linus Torvalds 已提交
288 289 290 291 292 293 294
	if (!table_info) {
		status = AE_NO_MEMORY;
		goto cleanup;
	}

	/* Get the number of table pointers within the RSDT */

L
Len Brown 已提交
295 296
	table_count =
	    acpi_tb_get_table_count(acpi_gbl_RSDP, rsdt_info->pointer);
L
Linus Torvalds 已提交
297 298 299 300 301 302 303
	address.pointer_type = acpi_gbl_table_flags | flags;

	/*
	 * Search the RSDT/XSDT for the correct instance of the
	 * requested table
	 */
	for (i = 0, j = 0; i < table_count; i++) {
304 305 306 307 308
		/*
		 * Get the next table pointer, handle RSDT vs. XSDT
		 * RSDT pointers are 32 bits, XSDT pointers are 64 bits
		 */
		if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) {
L
Len Brown 已提交
309 310 311 312 313 314 315 316 317
			address.pointer.value =
			    (ACPI_CAST_PTR
			     (RSDT_DESCRIPTOR,
			      rsdt_info->pointer))->table_offset_entry[i];
		} else {
			address.pointer.value =
			    (ACPI_CAST_PTR
			     (XSDT_DESCRIPTOR,
			      rsdt_info->pointer))->table_offset_entry[i];
L
Linus Torvalds 已提交
318 319 320 321
		}

		/* Get the table header */

L
Len Brown 已提交
322 323
		status = acpi_tb_get_table_header(&address, header);
		if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
324 325 326 327 328
			goto cleanup;
		}

		/* Compare table signatures and table instance */

L
Len Brown 已提交
329
		if (!ACPI_STRNCMP(header->signature, signature, ACPI_NAME_SIZE)) {
L
Linus Torvalds 已提交
330 331 332 333 334 335
			/* An instance of the table was found */

			j++;
			if (j >= instance) {
				/* Found the correct instance, get the entire table */

L
Len Brown 已提交
336 337 338 339
				status =
				    acpi_tb_get_table_body(&address, header,
							   table_info);
				if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
340 341 342 343 344 345 346 347 348 349 350 351 352
					goto cleanup;
				}

				*table_pointer = table_info->pointer;
				goto cleanup;
			}
		}
	}

	/* Did not find the table */

	status = AE_NOT_EXIST;

L
Len Brown 已提交
353
      cleanup:
354
	if (rsdt_info->pointer) {
L
Len Brown 已提交
355 356
		acpi_os_unmap_memory(rsdt_info->pointer,
				     (acpi_size) rsdt_info->pointer->length);
357
	}
L
Len Brown 已提交
358
	ACPI_MEM_FREE(rsdt_info);
L
Linus Torvalds 已提交
359 360

	if (header) {
L
Len Brown 已提交
361
		ACPI_MEM_FREE(header);
L
Linus Torvalds 已提交
362 363
	}
	if (table_info) {
L
Len Brown 已提交
364
		ACPI_MEM_FREE(table_info);
L
Linus Torvalds 已提交
365
	}
L
Len Brown 已提交
366
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
367 368
}

L
Len Brown 已提交
369
EXPORT_SYMBOL(acpi_get_firmware_table);
L
Linus Torvalds 已提交
370 371 372 373 374 375 376 377 378

/* TBD: Move to a new file */

#if ACPI_MACHINE_WIDTH != 16

/*******************************************************************************
 *
 * FUNCTION:    acpi_find_root_pointer
 *
R
Robert Moore 已提交
379 380
 * PARAMETERS:  Flags                   - Logical/Physical addressing
 *              rsdp_address            - Where to place the RSDP address
L
Linus Torvalds 已提交
381 382 383 384 385 386 387
 *
 * RETURN:      Status, Physical address of the RSDP
 *
 * DESCRIPTION: Find the RSDP
 *
 ******************************************************************************/

L
Len Brown 已提交
388
acpi_status acpi_find_root_pointer(u32 flags, struct acpi_pointer *rsdp_address)
L
Linus Torvalds 已提交
389
{
L
Len Brown 已提交
390 391
	struct acpi_table_desc table_info;
	acpi_status status;
L
Linus Torvalds 已提交
392

L
Len Brown 已提交
393
	ACPI_FUNCTION_TRACE("acpi_find_root_pointer");
L
Linus Torvalds 已提交
394 395 396

	/* Get the RSDP */

L
Len Brown 已提交
397 398 399 400 401
	status = acpi_tb_find_rsdp(&table_info, flags);
	if (ACPI_FAILURE(status)) {
		ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
				  "RSDP structure not found, %s Flags=%X\n",
				  acpi_format_exception(status), flags));
R
Robert Moore 已提交
402

L
Len Brown 已提交
403
		return_ACPI_STATUS(AE_NO_ACPI_TABLES);
L
Linus Torvalds 已提交
404 405 406 407
	}

	rsdp_address->pointer_type = ACPI_PHYSICAL_POINTER;
	rsdp_address->pointer.physical = table_info.physical_address;
L
Len Brown 已提交
408
	return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_tb_scan_memory_for_rsdp
 *
 * PARAMETERS:  start_address       - Starting pointer for search
 *              Length              - Maximum length to search
 *
 * RETURN:      Pointer to the RSDP if found, otherwise NULL.
 *
 * DESCRIPTION: Search a block of memory for the RSDP signature
 *
 ******************************************************************************/

L
Len Brown 已提交
424
static u8 *acpi_tb_scan_memory_for_rsdp(u8 * start_address, u32 length)
L
Linus Torvalds 已提交
425
{
L
Len Brown 已提交
426 427 428
	acpi_status status;
	u8 *mem_rover;
	u8 *end_address;
L
Linus Torvalds 已提交
429

L
Len Brown 已提交
430
	ACPI_FUNCTION_TRACE("tb_scan_memory_for_rsdp");
L
Linus Torvalds 已提交
431 432 433 434 435 436

	end_address = start_address + length;

	/* Search from given start address for the requested length */

	for (mem_rover = start_address; mem_rover < end_address;
L
Len Brown 已提交
437
	     mem_rover += ACPI_RSDP_SCAN_STEP) {
438
		/* The RSDP signature and checksum must both be correct */
L
Linus Torvalds 已提交
439

L
Len Brown 已提交
440 441 442 443
		status =
		    acpi_tb_validate_rsdp(ACPI_CAST_PTR
					  (struct rsdp_descriptor, mem_rover));
		if (ACPI_SUCCESS(status)) {
444
			/* Sig and checksum valid, we have found a real RSDP */
L
Linus Torvalds 已提交
445

L
Len Brown 已提交
446 447 448 449
			ACPI_DEBUG_PRINT((ACPI_DB_INFO,
					  "RSDP located at physical address %p\n",
					  mem_rover));
			return_PTR(mem_rover);
L
Linus Torvalds 已提交
450 451
		}

452
		/* No sig match or bad checksum, keep searching */
L
Linus Torvalds 已提交
453 454 455 456
	}

	/* Searched entire block, no RSDP was found */

L
Len Brown 已提交
457 458 459 460
	ACPI_DEBUG_PRINT((ACPI_DB_INFO,
			  "Searched entire block from %p, valid RSDP was not found\n",
			  start_address));
	return_PTR(NULL);
L
Linus Torvalds 已提交
461 462 463 464 465 466
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_tb_find_rsdp
 *
R
Robert Moore 已提交
467
 * PARAMETERS:  table_info              - Where the table info is returned
L
Linus Torvalds 已提交
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484
 *              Flags                   - Current memory mode (logical vs.
 *                                        physical addressing)
 *
 * RETURN:      Status, RSDP physical address
 *
 * DESCRIPTION: search lower 1_mbyte of memory for the root system descriptor
 *              pointer structure.  If it is found, set *RSDP to point to it.
 *
 *              NOTE1: The RSDp must be either in the first 1_k of the Extended
 *              BIOS Data Area or between E0000 and FFFFF (From ACPI Spec.)
 *              Only a 32-bit physical address is necessary.
 *
 *              NOTE2: This function is always available, regardless of the
 *              initialization state of the rest of ACPI.
 *
 ******************************************************************************/

R
Robert Moore 已提交
485
static acpi_status
L
Len Brown 已提交
486
acpi_tb_find_rsdp(struct acpi_table_desc *table_info, u32 flags)
L
Linus Torvalds 已提交
487
{
L
Len Brown 已提交
488 489 490 491
	u8 *table_ptr;
	u8 *mem_rover;
	u32 physical_address;
	acpi_status status;
L
Linus Torvalds 已提交
492

L
Len Brown 已提交
493
	ACPI_FUNCTION_TRACE("tb_find_rsdp");
L
Linus Torvalds 已提交
494 495

	/*
R
Robert Moore 已提交
496
	 * Scan supports either logical addressing or physical addressing
L
Linus Torvalds 已提交
497 498
	 */
	if ((flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING) {
R
Robert Moore 已提交
499 500
		/* 1a) Get the location of the Extended BIOS Data Area (EBDA) */

L
Len Brown 已提交
501 502 503 504 505 506 507 508 509 510 511
		status = acpi_os_map_memory((acpi_physical_address)
					    ACPI_EBDA_PTR_LOCATION,
					    ACPI_EBDA_PTR_LENGTH,
					    (void *)&table_ptr);
		if (ACPI_FAILURE(status)) {
			ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
					  "Could not map memory at %8.8X for length %X\n",
					  ACPI_EBDA_PTR_LOCATION,
					  ACPI_EBDA_PTR_LENGTH));

			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
512 513
		}

L
Len Brown 已提交
514
		ACPI_MOVE_16_TO_32(&physical_address, table_ptr);
R
Robert Moore 已提交
515 516 517 518

		/* Convert segment part to physical address */

		physical_address <<= 4;
L
Len Brown 已提交
519
		acpi_os_unmap_memory(table_ptr, ACPI_EBDA_PTR_LENGTH);
L
Linus Torvalds 已提交
520 521 522 523 524

		/* EBDA present? */

		if (physical_address > 0x400) {
			/*
R
Robert Moore 已提交
525 526
			 * 1b) Search EBDA paragraphs (EBDa is required to be a
			 *     minimum of 1_k length)
L
Linus Torvalds 已提交
527
			 */
L
Len Brown 已提交
528 529 530 531 532 533 534 535 536 537 538
			status = acpi_os_map_memory((acpi_physical_address)
						    physical_address,
						    ACPI_EBDA_WINDOW_SIZE,
						    (void *)&table_ptr);
			if (ACPI_FAILURE(status)) {
				ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
						  "Could not map memory at %8.8X for length %X\n",
						  physical_address,
						  ACPI_EBDA_WINDOW_SIZE));

				return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
539 540
			}

L
Len Brown 已提交
541 542 543
			mem_rover = acpi_tb_scan_memory_for_rsdp(table_ptr,
								 ACPI_EBDA_WINDOW_SIZE);
			acpi_os_unmap_memory(table_ptr, ACPI_EBDA_WINDOW_SIZE);
L
Linus Torvalds 已提交
544 545

			if (mem_rover) {
546
				/* Return the physical address */
L
Linus Torvalds 已提交
547

L
Len Brown 已提交
548 549
				physical_address +=
				    ACPI_PTR_DIFF(mem_rover, table_ptr);
L
Linus Torvalds 已提交
550

R
Robert Moore 已提交
551
				table_info->physical_address =
L
Len Brown 已提交
552 553
				    (acpi_physical_address) physical_address;
				return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
554 555 556 557 558 559
			}
		}

		/*
		 * 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh
		 */
L
Len Brown 已提交
560 561 562 563 564 565 566 567 568 569 570 571
		status = acpi_os_map_memory((acpi_physical_address)
					    ACPI_HI_RSDP_WINDOW_BASE,
					    ACPI_HI_RSDP_WINDOW_SIZE,
					    (void *)&table_ptr);

		if (ACPI_FAILURE(status)) {
			ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
					  "Could not map memory at %8.8X for length %X\n",
					  ACPI_HI_RSDP_WINDOW_BASE,
					  ACPI_HI_RSDP_WINDOW_SIZE));

			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
572 573
		}

L
Len Brown 已提交
574 575 576 577
		mem_rover =
		    acpi_tb_scan_memory_for_rsdp(table_ptr,
						 ACPI_HI_RSDP_WINDOW_SIZE);
		acpi_os_unmap_memory(table_ptr, ACPI_HI_RSDP_WINDOW_SIZE);
L
Linus Torvalds 已提交
578 579

		if (mem_rover) {
580
			/* Return the physical address */
L
Linus Torvalds 已提交
581

R
Robert Moore 已提交
582
			physical_address =
L
Len Brown 已提交
583 584
			    ACPI_HI_RSDP_WINDOW_BASE + ACPI_PTR_DIFF(mem_rover,
								     table_ptr);
L
Linus Torvalds 已提交
585

R
Robert Moore 已提交
586
			table_info->physical_address =
L
Len Brown 已提交
587 588
			    (acpi_physical_address) physical_address;
			return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
589 590 591 592 593 594 595
		}
	}

	/*
	 * Physical addressing
	 */
	else {
R
Robert Moore 已提交
596 597
		/* 1a) Get the location of the EBDA */

L
Len Brown 已提交
598 599
		ACPI_MOVE_16_TO_32(&physical_address, ACPI_EBDA_PTR_LOCATION);
		physical_address <<= 4;	/* Convert segment to physical address */
L
Linus Torvalds 已提交
600 601 602 603 604

		/* EBDA present? */

		if (physical_address > 0x400) {
			/*
R
Robert Moore 已提交
605 606
			 * 1b) Search EBDA paragraphs (EBDa is required to be a minimum of
			 *     1_k length)
L
Linus Torvalds 已提交
607
			 */
L
Len Brown 已提交
608 609 610 611
			mem_rover =
			    acpi_tb_scan_memory_for_rsdp(ACPI_PHYSADDR_TO_PTR
							 (physical_address),
							 ACPI_EBDA_WINDOW_SIZE);
L
Linus Torvalds 已提交
612
			if (mem_rover) {
613
				/* Return the physical address */
L
Linus Torvalds 已提交
614

L
Len Brown 已提交
615 616 617
				table_info->physical_address =
				    ACPI_TO_INTEGER(mem_rover);
				return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
618 619 620
			}
		}

R
Robert Moore 已提交
621 622
		/* 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh */

L
Len Brown 已提交
623 624 625 626
		mem_rover =
		    acpi_tb_scan_memory_for_rsdp(ACPI_PHYSADDR_TO_PTR
						 (ACPI_HI_RSDP_WINDOW_BASE),
						 ACPI_HI_RSDP_WINDOW_SIZE);
L
Linus Torvalds 已提交
627 628 629
		if (mem_rover) {
			/* Found it, return the physical address */

L
Len Brown 已提交
630 631 632
			table_info->physical_address =
			    ACPI_TO_INTEGER(mem_rover);
			return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
633 634 635
		}
	}

636
	/* A valid RSDP was not found */
L
Linus Torvalds 已提交
637

L
Len Brown 已提交
638 639
	ACPI_REPORT_ERROR(("No valid RSDP was found\n"));
	return_ACPI_STATUS(AE_NOT_FOUND);
L
Linus Torvalds 已提交
640 641 642
}

#endif