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#include <acpi/acpi.h>
45#include "accommon.h"
46#include "actables.h"
47
48#define _COMPONENT ACPI_TABLES
49ACPI_MODULE_NAME("tbutils")
50
51
52static acpi_physical_address
53acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size);
54
55#if (!ACPI_REDUCED_HARDWARE)
56
57
58
59
60
61
62
63
64
65
66
67
68
69acpi_status acpi_tb_initialize_facs(void)
70{
71 struct acpi_table_facs *facs;
72
73
74
75 if (acpi_gbl_reduced_hardware) {
76 acpi_gbl_FACS = NULL;
77 return (AE_OK);
78 } else if (acpi_gbl_FADT.Xfacs &&
79 (!acpi_gbl_FADT.facs
80 || !acpi_gbl_use32_bit_facs_addresses)) {
81 (void)acpi_get_table_by_index(acpi_gbl_xfacs_index,
82 ACPI_CAST_INDIRECT_PTR(struct
83 acpi_table_header,
84 &facs));
85 acpi_gbl_FACS = facs;
86 } else if (acpi_gbl_FADT.facs) {
87 (void)acpi_get_table_by_index(acpi_gbl_facs_index,
88 ACPI_CAST_INDIRECT_PTR(struct
89 acpi_table_header,
90 &facs));
91 acpi_gbl_FACS = facs;
92 }
93
94
95
96 return (AE_OK);
97}
98#endif
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114void acpi_tb_check_dsdt_header(void)
115{
116
117
118
119 if (acpi_gbl_original_dsdt_header.length != acpi_gbl_DSDT->length ||
120 acpi_gbl_original_dsdt_header.checksum != acpi_gbl_DSDT->checksum) {
121 ACPI_BIOS_ERROR((AE_INFO,
122 "The DSDT has been corrupted or replaced - "
123 "old, new headers below"));
124
125 acpi_tb_print_table_header(0, &acpi_gbl_original_dsdt_header);
126 acpi_tb_print_table_header(0, acpi_gbl_DSDT);
127
128 ACPI_ERROR((AE_INFO,
129 "Please send DMI info to linux-acpi@vger.kernel.org\n"
130 "If system does not work as expected, please boot with acpi=copy_dsdt"));
131
132
133
134 acpi_gbl_original_dsdt_header.length = acpi_gbl_DSDT->length;
135 acpi_gbl_original_dsdt_header.checksum =
136 acpi_gbl_DSDT->checksum;
137 }
138}
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154struct acpi_table_header *acpi_tb_copy_dsdt(u32 table_index)
155{
156 struct acpi_table_header *new_table;
157 struct acpi_table_desc *table_desc;
158
159 table_desc = &acpi_gbl_root_table_list.tables[table_index];
160
161 new_table = ACPI_ALLOCATE(table_desc->length);
162 if (!new_table) {
163 ACPI_ERROR((AE_INFO, "Could not copy DSDT of length 0x%X",
164 table_desc->length));
165 return (NULL);
166 }
167
168 memcpy(new_table, table_desc->pointer, table_desc->length);
169 acpi_tb_uninstall_table(table_desc);
170
171 acpi_tb_init_table_descriptor(&acpi_gbl_root_table_list.
172 tables[acpi_gbl_dsdt_index],
173 ACPI_PTR_TO_PHYSADDR(new_table),
174 ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL,
175 new_table);
176
177 ACPI_INFO(("Forced DSDT copy: length 0x%05X copied locally, original unmapped", new_table->length));
178
179 return (new_table);
180}
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199static acpi_physical_address
200acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size)
201{
202 u64 address64;
203
204
205
206
207
208 if (table_entry_size == ACPI_RSDT_ENTRY_SIZE) {
209
210
211
212
213 return ((acpi_physical_address)
214 (*ACPI_CAST_PTR(u32, table_entry)));
215 } else {
216
217
218
219
220
221 ACPI_MOVE_64_TO_64(&address64, table_entry);
222
223#if ACPI_MACHINE_WIDTH == 32
224 if (address64 > ACPI_UINT32_MAX) {
225
226
227
228 ACPI_BIOS_WARNING((AE_INFO,
229 "64-bit Physical Address in XSDT is too large (0x%8.8X%8.8X),"
230 " truncating",
231 ACPI_FORMAT_UINT64(address64)));
232 }
233#endif
234 return ((acpi_physical_address)(address64));
235 }
236}
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255acpi_status ACPI_INIT_FUNCTION
256acpi_tb_parse_root_table(acpi_physical_address rsdp_address)
257{
258 struct acpi_table_rsdp *rsdp;
259 u32 table_entry_size;
260 u32 i;
261 u32 table_count;
262 struct acpi_table_header *table;
263 acpi_physical_address address;
264 u32 length;
265 u8 *table_entry;
266 acpi_status status;
267 u32 table_index;
268
269 ACPI_FUNCTION_TRACE(tb_parse_root_table);
270
271
272
273 rsdp = acpi_os_map_memory(rsdp_address, sizeof(struct acpi_table_rsdp));
274 if (!rsdp) {
275 return_ACPI_STATUS(AE_NO_MEMORY);
276 }
277
278 acpi_tb_print_table_header(rsdp_address,
279 ACPI_CAST_PTR(struct acpi_table_header,
280 rsdp));
281
282
283
284 if ((rsdp->revision > 1) &&
285 rsdp->xsdt_physical_address && !acpi_gbl_do_not_use_xsdt) {
286
287
288
289
290
291 address = (acpi_physical_address)rsdp->xsdt_physical_address;
292 table_entry_size = ACPI_XSDT_ENTRY_SIZE;
293 } else {
294
295
296 address = (acpi_physical_address)rsdp->rsdt_physical_address;
297 table_entry_size = ACPI_RSDT_ENTRY_SIZE;
298 }
299
300
301
302
303
304 acpi_os_unmap_memory(rsdp, sizeof(struct acpi_table_rsdp));
305
306
307
308 table = acpi_os_map_memory(address, sizeof(struct acpi_table_header));
309 if (!table) {
310 return_ACPI_STATUS(AE_NO_MEMORY);
311 }
312
313 acpi_tb_print_table_header(address, table);
314
315
316
317
318
319 length = table->length;
320 acpi_os_unmap_memory(table, sizeof(struct acpi_table_header));
321
322 if (length < (sizeof(struct acpi_table_header) + table_entry_size)) {
323 ACPI_BIOS_ERROR((AE_INFO,
324 "Invalid table length 0x%X in RSDT/XSDT",
325 length));
326 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
327 }
328
329 table = acpi_os_map_memory(address, length);
330 if (!table) {
331 return_ACPI_STATUS(AE_NO_MEMORY);
332 }
333
334
335
336 status = acpi_tb_verify_checksum(table, length);
337 if (ACPI_FAILURE(status)) {
338 acpi_os_unmap_memory(table, length);
339 return_ACPI_STATUS(status);
340 }
341
342
343
344 table_count = (u32)((table->length - sizeof(struct acpi_table_header)) /
345 table_entry_size);
346 table_entry = ACPI_ADD_PTR(u8, table, sizeof(struct acpi_table_header));
347
348
349
350 for (i = 0; i < table_count; i++) {
351
352
353
354 address =
355 acpi_tb_get_root_table_entry(table_entry, table_entry_size);
356
357
358
359 if (!address) {
360 goto next_table;
361 }
362
363 status = acpi_tb_install_standard_table(address,
364 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL,
365 FALSE, TRUE,
366 &table_index);
367
368 if (ACPI_SUCCESS(status) &&
369 ACPI_COMPARE_NAME(&acpi_gbl_root_table_list.
370 tables[table_index].signature,
371 ACPI_SIG_FADT)) {
372 acpi_gbl_fadt_index = table_index;
373 acpi_tb_parse_fadt();
374 }
375
376next_table:
377
378 table_entry += table_entry_size;
379 }
380
381 acpi_os_unmap_memory(table, length);
382 return_ACPI_STATUS(AE_OK);
383}
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401acpi_status
402acpi_tb_get_table(struct acpi_table_desc *table_desc,
403 struct acpi_table_header **out_table)
404{
405 acpi_status status;
406
407 ACPI_FUNCTION_TRACE(acpi_tb_get_table);
408
409 if (table_desc->validation_count == 0) {
410
411
412
413 status = acpi_tb_validate_table(table_desc);
414 if (ACPI_FAILURE(status)) {
415 return_ACPI_STATUS(status);
416 }
417 }
418
419 if (table_desc->validation_count < ACPI_MAX_TABLE_VALIDATIONS) {
420 table_desc->validation_count++;
421
422
423
424
425
426 if (table_desc->validation_count >= ACPI_MAX_TABLE_VALIDATIONS) {
427 ACPI_WARNING((AE_INFO,
428 "Table %p, Validation count overflows\n",
429 table_desc));
430 }
431 }
432
433 *out_table = table_desc->pointer;
434 return_ACPI_STATUS(AE_OK);
435}
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452void acpi_tb_put_table(struct acpi_table_desc *table_desc)
453{
454
455 ACPI_FUNCTION_TRACE(acpi_tb_put_table);
456
457 if (table_desc->validation_count < ACPI_MAX_TABLE_VALIDATIONS) {
458 table_desc->validation_count--;
459
460
461
462
463
464 if (table_desc->validation_count >= ACPI_MAX_TABLE_VALIDATIONS) {
465 ACPI_WARNING((AE_INFO,
466 "Table %p, Validation count underflows\n",
467 table_desc));
468 return_VOID;
469 }
470 }
471
472 if (table_desc->validation_count == 0) {
473
474
475
476 acpi_tb_invalidate_table(table_desc);
477 }
478
479 return_VOID;
480}
481