tbrsdt.c 8.6 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7
/******************************************************************************
 *
 * Module Name: tbrsdt - ACPI RSDT table utilities
 *
 *****************************************************************************/

/*
B
Bob Moore 已提交
8
 * Copyright (C) 2000 - 2006, R. Byron Moore
L
Linus Torvalds 已提交
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
 * 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/actables.h>

#define _COMPONENT          ACPI_TABLES
L
Len Brown 已提交
48
ACPI_MODULE_NAME("tbrsdt")
L
Linus Torvalds 已提交
49 50 51 52 53 54 55 56 57 58 59 60

/*******************************************************************************
 *
 * FUNCTION:    acpi_tb_verify_rsdp
 *
 * PARAMETERS:  Address         - RSDP (Pointer to RSDT)
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Load and validate the RSDP (ptr) and RSDT (table)
 *
 ******************************************************************************/
L
Len Brown 已提交
61
acpi_status acpi_tb_verify_rsdp(struct acpi_pointer *address)
L
Linus Torvalds 已提交
62
{
L
Len Brown 已提交
63 64 65
	struct acpi_table_desc table_info;
	acpi_status status;
	struct rsdp_descriptor *rsdp;
L
Linus Torvalds 已提交
66

B
Bob Moore 已提交
67
	ACPI_FUNCTION_TRACE(tb_verify_rsdp);
L
Linus Torvalds 已提交
68 69 70 71 72 73 74 75 76 77 78

	switch (address->pointer_type) {
	case ACPI_LOGICAL_POINTER:

		rsdp = address->pointer.logical;
		break;

	case ACPI_PHYSICAL_POINTER:
		/*
		 * Obtain access to the RSDP structure
		 */
L
Len Brown 已提交
79 80
		status = acpi_os_map_memory(address->pointer.physical,
					    sizeof(struct rsdp_descriptor),
B
Bob Moore 已提交
81
					    ACPI_CAST_PTR(void, &rsdp));
L
Len Brown 已提交
82 83
		if (ACPI_FAILURE(status)) {
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
84 85 86 87
		}
		break;

	default:
L
Len Brown 已提交
88
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
89 90
	}

91
	/* Verify RSDP signature and checksum */
L
Linus Torvalds 已提交
92

L
Len Brown 已提交
93 94
	status = acpi_tb_validate_rsdp(rsdp);
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
95 96 97
		goto cleanup;
	}

B
Bob Moore 已提交
98
	/* RSDP is ok. Init the table info */
L
Linus Torvalds 已提交
99

L
Len Brown 已提交
100 101
	table_info.pointer = ACPI_CAST_PTR(struct acpi_table_header, rsdp);
	table_info.length = sizeof(struct rsdp_descriptor);
B
Bob Moore 已提交
102 103 104 105 106 107

	if (address->pointer_type == ACPI_PHYSICAL_POINTER) {
		table_info.allocation = ACPI_MEM_MAPPED;
	} else {
		table_info.allocation = ACPI_MEM_NOT_ALLOCATED;
	}
L
Linus Torvalds 已提交
108 109 110

	/* Save the table pointers and allocation info */

B
Bob Moore 已提交
111
	status = acpi_tb_init_table_descriptor(ACPI_TABLE_ID_RSDP, &table_info);
L
Len Brown 已提交
112
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
113 114 115 116 117
		goto cleanup;
	}

	/* Save the RSDP in a global for easy access */

L
Len Brown 已提交
118 119 120
	acpi_gbl_RSDP =
	    ACPI_CAST_PTR(struct rsdp_descriptor, table_info.pointer);
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
121 122

	/* Error exit */
L
Len Brown 已提交
123
      cleanup:
L
Linus Torvalds 已提交
124 125

	if (acpi_gbl_table_flags & ACPI_PHYSICAL_POINTER) {
L
Len Brown 已提交
126
		acpi_os_unmap_memory(rsdp, sizeof(struct rsdp_descriptor));
L
Linus Torvalds 已提交
127
	}
L
Len Brown 已提交
128
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
129 130 131 132 133 134
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_tb_get_rsdt_address
 *
R
Robert Moore 已提交
135
 * PARAMETERS:  out_address         - Where the address is returned
L
Linus Torvalds 已提交
136
 *
R
Robert Moore 已提交
137
 * RETURN:      None, Address
L
Linus Torvalds 已提交
138
 *
139 140
 * DESCRIPTION: Extract the address of either the RSDT or XSDT, depending on the
 *              version of the RSDP and whether the XSDT pointer is valid
L
Linus Torvalds 已提交
141 142 143
 *
 ******************************************************************************/

L
Len Brown 已提交
144
void acpi_tb_get_rsdt_address(struct acpi_pointer *out_address)
L
Linus Torvalds 已提交
145 146
{

L
Len Brown 已提交
147
	ACPI_FUNCTION_ENTRY();
L
Linus Torvalds 已提交
148

L
Len Brown 已提交
149 150
	out_address->pointer_type =
	    acpi_gbl_table_flags | ACPI_LOGICAL_ADDRESSING;
L
Linus Torvalds 已提交
151

152 153 154
	/* Use XSDT if it is present */

	if ((acpi_gbl_RSDP->revision >= 2) &&
L
Len Brown 已提交
155
	    acpi_gbl_RSDP->xsdt_physical_address) {
R
Robert Moore 已提交
156
		out_address->pointer.value =
L
Len Brown 已提交
157
		    acpi_gbl_RSDP->xsdt_physical_address;
158
		acpi_gbl_root_table_type = ACPI_TABLE_TYPE_XSDT;
L
Len Brown 已提交
159
	} else {
160 161
		/* No XSDT, use the RSDT */

L
Len Brown 已提交
162 163
		out_address->pointer.value =
		    acpi_gbl_RSDP->rsdt_physical_address;
164
		acpi_gbl_root_table_type = ACPI_TABLE_TYPE_RSDT;
L
Linus Torvalds 已提交
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
	}
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_tb_validate_rsdt
 *
 * PARAMETERS:  table_ptr       - Addressable pointer to the RSDT.
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Validate signature for the RSDT or XSDT
 *
 ******************************************************************************/

L
Len Brown 已提交
180
acpi_status acpi_tb_validate_rsdt(struct acpi_table_header *table_ptr)
L
Linus Torvalds 已提交
181
{
B
Bob Moore 已提交
182
	char *signature;
L
Linus Torvalds 已提交
183

B
Bob Moore 已提交
184
	ACPI_FUNCTION_ENTRY();
L
Linus Torvalds 已提交
185

B
Bob Moore 已提交
186 187 188 189
	/* Validate minimum length */

	if (table_ptr->length < sizeof(struct acpi_table_header)) {
		ACPI_ERROR((AE_INFO,
R
Randy Dunlap 已提交
190
			    "RSDT/XSDT length (%X) is smaller than minimum (%zX)",
B
Bob Moore 已提交
191 192 193 194 195 196
			    table_ptr->length,
			    sizeof(struct acpi_table_header)));

		return (AE_INVALID_TABLE_LENGTH);
	}

B
Bob Moore 已提交
197 198
	/* Search for appropriate signature, RSDT or XSDT */

199
	if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) {
B
Bob Moore 已提交
200
		signature = RSDT_SIG;
L
Len Brown 已提交
201
	} else {
B
Bob Moore 已提交
202
		signature = XSDT_SIG;
L
Linus Torvalds 已提交
203 204
	}

B
Bob Moore 已提交
205
	if (!ACPI_COMPARE_NAME(table_ptr->signature, signature)) {
B
Bob Moore 已提交
206

L
Linus Torvalds 已提交
207 208
		/* Invalid RSDT or XSDT signature */

B
Bob Moore 已提交
209 210
		ACPI_ERROR((AE_INFO,
			    "Invalid signature where RSDP indicates RSDT/XSDT should be located. RSDP:"));
L
Linus Torvalds 已提交
211

L
Len Brown 已提交
212
		ACPI_DUMP_BUFFER(acpi_gbl_RSDP, 20);
L
Linus Torvalds 已提交
213

B
Bob Moore 已提交
214
		ACPI_ERROR((AE_INFO,
B
Bob Moore 已提交
215 216
			    "RSDT/XSDT signature at %X is invalid",
			    acpi_gbl_RSDP->rsdt_physical_address));
L
Linus Torvalds 已提交
217

218
		if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) {
B
Bob Moore 已提交
219
			ACPI_ERROR((AE_INFO, "Looking for RSDT"));
L
Len Brown 已提交
220
		} else {
B
Bob Moore 已提交
221
			ACPI_ERROR((AE_INFO, "Looking for XSDT"));
L
Linus Torvalds 已提交
222 223
		}

B
Bob Moore 已提交
224
		ACPI_DUMP_BUFFER(ACPI_CAST_PTR(char, table_ptr), 48);
L
Linus Torvalds 已提交
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
		return (AE_BAD_SIGNATURE);
	}

	return (AE_OK);
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_tb_get_table_rsdt
 *
 * PARAMETERS:  None
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Load and validate the RSDP (ptr) and RSDT (table)
 *
 ******************************************************************************/

L
Len Brown 已提交
243
acpi_status acpi_tb_get_table_rsdt(void)
L
Linus Torvalds 已提交
244
{
L
Len Brown 已提交
245 246 247
	struct acpi_table_desc table_info;
	acpi_status status;
	struct acpi_pointer address;
L
Linus Torvalds 已提交
248

B
Bob Moore 已提交
249
	ACPI_FUNCTION_TRACE(tb_get_table_rsdt);
L
Linus Torvalds 已提交
250 251 252

	/* Get the RSDT/XSDT via the RSDP */

L
Len Brown 已提交
253
	acpi_tb_get_rsdt_address(&address);
L
Linus Torvalds 已提交
254

B
Bob Moore 已提交
255
	table_info.type = ACPI_TABLE_ID_XSDT;
L
Len Brown 已提交
256 257
	status = acpi_tb_get_table(&address, &table_info);
	if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
258 259
		ACPI_EXCEPTION((AE_INFO, status,
				"Could not get the RSDT/XSDT"));
L
Len Brown 已提交
260
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
261 262
	}

L
Len Brown 已提交
263
	ACPI_DEBUG_PRINT((ACPI_DB_INFO,
B
Bob Moore 已提交
264
			  "RSDP located at %p, points to RSDT physical=%8.8X%8.8X\n",
L
Len Brown 已提交
265 266
			  acpi_gbl_RSDP,
			  ACPI_FORMAT_UINT64(address.pointer.value)));
L
Linus Torvalds 已提交
267 268 269

	/* Check the RSDT or XSDT signature */

L
Len Brown 已提交
270 271
	status = acpi_tb_validate_rsdt(table_info.pointer);
	if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
272
		goto error_cleanup;
L
Linus Torvalds 已提交
273 274 275 276
	}

	/* Get the number of tables defined in the RSDT or XSDT */

L
Len Brown 已提交
277 278
	acpi_gbl_rsdt_table_count = acpi_tb_get_table_count(acpi_gbl_RSDP,
							    table_info.pointer);
L
Linus Torvalds 已提交
279 280 281

	/* Convert and/or copy to an XSDT structure */

L
Len Brown 已提交
282 283
	status = acpi_tb_convert_to_xsdt(&table_info);
	if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
284
		goto error_cleanup;
L
Linus Torvalds 已提交
285 286 287 288
	}

	/* Save the table pointers and allocation info */

B
Bob Moore 已提交
289
	status = acpi_tb_init_table_descriptor(ACPI_TABLE_ID_XSDT, &table_info);
L
Len Brown 已提交
290
	if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
291
		goto error_cleanup;
L
Linus Torvalds 已提交
292 293
	}

B
Bob Moore 已提交
294 295
	acpi_gbl_XSDT =
	    ACPI_CAST_PTR(struct xsdt_descriptor, table_info.pointer);
L
Linus Torvalds 已提交
296

L
Len Brown 已提交
297 298
	ACPI_DEBUG_PRINT((ACPI_DB_INFO, "XSDT located at %p\n", acpi_gbl_XSDT));
	return_ACPI_STATUS(status);
B
Bob Moore 已提交
299 300 301 302 303 304 305 306

      error_cleanup:

	/* Free table allocated by acpi_tb_get_table */

	acpi_tb_delete_single_table(&table_info);

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