summaryrefslogtreecommitdiffstats
path: root/drivers/acpi/tables/tbget.c
blob: 255ca172d785fad348b03ff52ca684ba36cf16f1 (plain)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324

/******************************************************************************
 *
 * Module Name: tbget - ACPI Table get* routines
 *
 *****************************************************************************/

/*
 *  Copyright (C) 2000 R. Byron Moore
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */


#include "acpi.h"
#include "hardware.h"
#include "tables.h"


#define _COMPONENT          TABLE_MANAGER
	 MODULE_NAME         ("tbget");


/*******************************************************************************
 *
 * FUNCTION:    Acpi_tb_get_table_ptr
 *
 * PARAMETERS:  Table_type      - one of the defined table types
 *              Instance        - Which table of this type
 *              Table_ptr_loc   - pointer to location to place the pointer for
 *                                return
 *
 * RETURN:      Status
 *
 * DESCRIPTION: This function is called to get the pointer to an ACPI table.
 *
 ******************************************************************************/

ACPI_STATUS
acpi_tb_get_table_ptr (
	ACPI_TABLE_TYPE         table_type,
	u32                     instance,
	ACPI_TABLE_HEADER       **table_ptr_loc)
{
	ACPI_TABLE_DESC         *table_desc;
	u32                     i;


	if (!acpi_gbl_DSDT) {
		return (AE_NO_ACPI_TABLES);
	}

	if (table_type > ACPI_TABLE_MAX) {
		return (AE_BAD_PARAMETER);
	}


	/*
	 * For all table types (Single/Multiple), the first
	 * instance is always in the list head.
	 */

	if (instance == 1) {
		/*
		 * Just pluck the pointer out of the global table!
		 * Will be null if no table is present
		 */

		*table_ptr_loc = acpi_gbl_acpi_tables[table_type].pointer;
		return (AE_OK);
	}


	/*
	 * Check for instance out of range
	 */
	if (instance > acpi_gbl_acpi_tables[table_type].count) {
		return (AE_NOT_EXIST);
	}

	/* Walk the list to get the table */

	table_desc = acpi_gbl_acpi_tables[table_type].next;
	for (i = 1; i < acpi_gbl_acpi_tables[table_type].count; i++) {
		table_desc = table_desc->next;
	}

	/* We are now pointing to the requested table's descriptor */

	*table_ptr_loc = table_desc->pointer;

	return (AE_OK);
}


/*******************************************************************************
 *
 * FUNCTION:    Acpi_tb_get_table
 *
 * PARAMETERS:  Physical_address        - Physical address of table to retrieve
 *              *Buffer_ptr             - If == NULL, read data from buffer
 *                                        rather than searching memory
 *              *Table_info             - Where the table info is returned
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Maps the physical address of table into a logical address
 *
 ******************************************************************************/

ACPI_STATUS
acpi_tb_get_table (
	void                    *physical_address,
	char                    *buffer_ptr,
	ACPI_TABLE_DESC         *table_info)
{
	ACPI_TABLE_HEADER       *table_header = NULL;
	ACPI_TABLE_HEADER       *full_table = NULL;
	u32                     size;
	u8                      allocation;
	ACPI_STATUS             status = AE_OK;


	if (!table_info) {
		return (AE_BAD_PARAMETER);
	}


	if (buffer_ptr) {
		/*
		 * Getting data from a buffer, not BIOS tables
		 */

		table_header = (ACPI_TABLE_HEADER *) buffer_ptr;
		status = acpi_tb_validate_table_header (table_header);
		if (ACPI_FAILURE (status)) {
			/* Table failed verification, map all errors to BAD_DATA */

			return (AE_BAD_DATA);
		}

		/* Allocate buffer for the entire table */

		full_table = acpi_cm_allocate (table_header->length);
		if (!full_table) {
			return (AE_NO_MEMORY);
		}

		/* Copy the entire table (including header) to the local buffer */

		size = (ACPI_SIZE) table_header->length;
		MEMCPY (full_table, buffer_ptr, size);

		/* Save allocation type */

		allocation = ACPI_MEM_ALLOCATED;
	}


	/*
	 * Not reading from a buffer, just map the table's physical memory
	 * into our address space.
	 */
	else {
		size = SIZE_IN_HEADER;

		status = acpi_tb_map_acpi_table (physical_address, &size,
				  (void **) &full_table);
		if (ACPI_FAILURE (status)) {
			return (status);
		}

		/* Save allocation type */

		allocation = ACPI_MEM_MAPPED;
	}


	/* Return values */

	table_info->pointer     = full_table;
	table_info->length      = size;
	table_info->allocation  = allocation;
	table_info->base_pointer = full_table;

	return (status);
}


/*******************************************************************************
 *
 * FUNCTION:    Acpi_tb_get_all_tables
 *
 * PARAMETERS:  Number_of_tables    - Number of tables to get
 *              Table_ptr           - Input buffer pointer, optional
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Load and validate all tables other than the RSDT.  The RSDT must
 *              already be loaded and validated.
 *
 ******************************************************************************/

ACPI_STATUS
acpi_tb_get_all_tables (
	u32                     number_of_tables,
	char                    *table_ptr)
{
	ACPI_STATUS             status = AE_OK;
	u32                     index;
	ACPI_TABLE_DESC         table_info;


	/*
	 * Loop through all table pointers found in RSDT.
	 * This will NOT include the FACS and DSDT - we must get
	 * them after the loop
	 */

	for (index = 0; index < number_of_tables; index++) {
		/* Clear the Table_info each time */

		MEMSET (&table_info, 0, sizeof (ACPI_TABLE_DESC));

		/* Get the table via the RSDT */

		status = acpi_tb_get_table ((void *) acpi_gbl_RSDT->table_offset_entry[index],
				 table_ptr, &table_info);

		/* Ignore a table that failed verification */

		if (status == AE_BAD_DATA) {
			continue;
		}

		/* However, abort on serious errors */

		if (ACPI_FAILURE (status)) {
			return (status);
		}

		/* Recognize and install the table */

		status = acpi_tb_install_table (table_ptr, &table_info);
		if (ACPI_FAILURE (status)) {
			/*
			 * Unrecognized or unsupported table, delete it and ignore the
			 * error.  Just get as many tables as we can, later we will
			 * determine if there are enough tables to continue.
			 */

			acpi_tb_delete_single_table (&table_info);
		}
	}


	/*
	 * Get the minimum set of ACPI tables, namely:
	 *
	 * 1) FACP (via RSDT in loop above)
	 * 2) FACS
	 * 3) DSDT
	 *
	 */


	/*
	 * Get the FACS (must have the FACP first, from loop above)
	 * Acpi_tb_get_table_facs will fail if FACP pointer is not valid
	 */

	status = acpi_tb_get_table_facs (table_ptr, &table_info);
	if (ACPI_FAILURE (status)) {
		return (status);
	}

	/* Install the FACS */

	status = acpi_tb_install_table (table_ptr, &table_info);
	if (ACPI_FAILURE (status)) {
		return (status);
	}


	/* Get the DSDT (We know that the FACP if valid now) */

	status = acpi_tb_get_table ((void *) acpi_gbl_FACP->dsdt, table_ptr, &table_info);
	if (ACPI_FAILURE (status)) {
		return (status);
	}

	/* Install the DSDT */

	status = acpi_tb_install_table (table_ptr, &table_info);
	if (ACPI_FAILURE (status)) {
		return (status);
	}

	/* Dump the DSDT Header */

	/* Dump the entire DSDT */

	/*
	 * Initialize the capabilities flags.
	 * Assumes that platform supports ACPI_MODE since we have tables!
	 */

	acpi_gbl_system_flags |= acpi_hw_get_mode_capabilities ();

	return (status);
}