]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/dev/acpica/tbget.c
This commit was generated by cvs2svn to compensate for changes in r165670,
[FreeBSD/FreeBSD.git] / sys / contrib / dev / acpica / tbget.c
1 /******************************************************************************
2  *
3  * Module Name: tbget - ACPI Table get* routines
4  *              $Revision: 90 $
5  *
6  *****************************************************************************/
7
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
13  * All rights reserved.
14  *
15  * 2. License
16  *
17  * 2.1. This is your license from Intel Corp. under its intellectual property
18  * rights.  You may have additional license terms from the party that provided
19  * you this software, covering your right to use that party's intellectual
20  * property rights.
21  *
22  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23  * copy of the source code appearing in this file ("Covered Code") an
24  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25  * base code distributed originally by Intel ("Original Intel Code") to copy,
26  * make derivatives, distribute, use and display any portion of the Covered
27  * Code in any form, with the right to sublicense such rights; and
28  *
29  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30  * license (with the right to sublicense), under only those claims of Intel
31  * patents that are infringed by the Original Intel Code, to make, use, sell,
32  * offer to sell, and import the Covered Code and derivative works thereof
33  * solely to the minimum extent necessary to exercise the above copyright
34  * license, and in no event shall the patent license extend to any additions
35  * to or modifications of the Original Intel Code.  No other license or right
36  * is granted directly or by implication, estoppel or otherwise;
37  *
38  * The above copyright and patent license is granted only if the following
39  * conditions are met:
40  *
41  * 3. Conditions
42  *
43  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44  * Redistribution of source code of any substantial portion of the Covered
45  * Code or modification with rights to further distribute source must include
46  * the above Copyright Notice, the above License, this list of Conditions,
47  * and the following Disclaimer and Export Compliance provision.  In addition,
48  * Licensee must cause all Covered Code to which Licensee contributes to
49  * contain a file documenting the changes Licensee made to create that Covered
50  * Code and the date of any change.  Licensee must include in that file the
51  * documentation of any changes made by any predecessor Licensee.  Licensee
52  * must include a prominent statement that the modification is derived,
53  * directly or indirectly, from Original Intel Code.
54  *
55  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56  * Redistribution of source code of any substantial portion of the Covered
57  * Code or modification without rights to further distribute source must
58  * include the following Disclaimer and Export Compliance provision in the
59  * documentation and/or other materials provided with distribution.  In
60  * addition, Licensee may not authorize further sublicense of source of any
61  * portion of the Covered Code, and must include terms to the effect that the
62  * license from Licensee to its licensee is limited to the intellectual
63  * property embodied in the software Licensee provides to its licensee, and
64  * not to intellectual property embodied in modifications its licensee may
65  * make.
66  *
67  * 3.3. Redistribution of Executable. Redistribution in executable form of any
68  * substantial portion of the Covered Code or modification must reproduce the
69  * above Copyright Notice, and the following Disclaimer and Export Compliance
70  * provision in the documentation and/or other materials provided with the
71  * distribution.
72  *
73  * 3.4. Intel retains all right, title, and interest in and to the Original
74  * Intel Code.
75  *
76  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77  * Intel shall be used in advertising or otherwise to promote the sale, use or
78  * other dealings in products derived from or relating to the Covered Code
79  * without prior written authorization from Intel.
80  *
81  * 4. Disclaimer and Export Compliance
82  *
83  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89  * PARTICULAR PURPOSE.
90  *
91  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98  * LIMITED REMEDY.
99  *
100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
101  * software or system incorporating such software without first obtaining any
102  * required license or other approval from the U. S. Department of Commerce or
103  * any other agency or department of the United States Government.  In the
104  * event Licensee exports any such software from the United States or
105  * re-exports any such software from a foreign destination, Licensee shall
106  * ensure that the distribution and export/re-export of the software is in
107  * compliance with all laws, regulations, orders, or other restrictions of the
108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109  * any of its subsidiaries will export/re-export any technical data, process,
110  * software, or service, directly or indirectly, to any country for which the
111  * United States government or any agency thereof requires an export license,
112  * other governmental approval, or letter of assurance, without first obtaining
113  * such license, approval or letter.
114  *
115  *****************************************************************************/
116
117 #define __TBGET_C__
118
119 #include <contrib/dev/acpica/acpi.h>
120 #include <contrib/dev/acpica/actables.h>
121
122
123 #define _COMPONENT          ACPI_TABLES
124         ACPI_MODULE_NAME    ("tbget")
125
126 /* Local prototypes */
127
128 static ACPI_STATUS
129 AcpiTbGetThisTable (
130     ACPI_POINTER            *Address,
131     ACPI_TABLE_HEADER       *Header,
132     ACPI_TABLE_DESC         *TableInfo);
133
134 static ACPI_STATUS
135 AcpiTbTableOverride (
136     ACPI_TABLE_HEADER       *Header,
137     ACPI_TABLE_DESC         *TableInfo);
138
139
140 /*******************************************************************************
141  *
142  * FUNCTION:    AcpiTbGetTable
143  *
144  * PARAMETERS:  Address             - Address of table to retrieve.  Can be
145  *                                    Logical or Physical
146  *              TableInfo           - Where table info is returned
147  *
148  * RETURN:      None
149  *
150  * DESCRIPTION: Get entire table of unknown size.
151  *
152  ******************************************************************************/
153
154 ACPI_STATUS
155 AcpiTbGetTable (
156     ACPI_POINTER            *Address,
157     ACPI_TABLE_DESC         *TableInfo)
158 {
159     ACPI_STATUS             Status;
160     ACPI_TABLE_HEADER       Header;
161
162
163     ACPI_FUNCTION_TRACE ("TbGetTable");
164
165
166     /* Get the header in order to get signature and table size */
167
168     Status = AcpiTbGetTableHeader (Address, &Header);
169     if (ACPI_FAILURE (Status))
170     {
171         return_ACPI_STATUS (Status);
172     }
173
174     /* Get the entire table */
175
176     Status = AcpiTbGetTableBody (Address, &Header, TableInfo);
177     if (ACPI_FAILURE (Status))
178     {
179         ACPI_REPORT_ERROR (("Could not get ACPI table (size %X), %s\n",
180             Header.Length, AcpiFormatException (Status)));
181         return_ACPI_STATUS (Status);
182     }
183
184     return_ACPI_STATUS (AE_OK);
185 }
186
187
188 /*******************************************************************************
189  *
190  * FUNCTION:    AcpiTbGetTableHeader
191  *
192  * PARAMETERS:  Address             - Address of table to retrieve.  Can be
193  *                                    Logical or Physical
194  *              ReturnHeader        - Where the table header is returned
195  *
196  * RETURN:      Status
197  *
198  * DESCRIPTION: Get an ACPI table header.  Works in both physical or virtual
199  *              addressing mode.  Works with both physical or logical pointers.
200  *              Table is either copied or mapped, depending on the pointer
201  *              type and mode of the processor.
202  *
203  ******************************************************************************/
204
205 ACPI_STATUS
206 AcpiTbGetTableHeader (
207     ACPI_POINTER            *Address,
208     ACPI_TABLE_HEADER       *ReturnHeader)
209 {
210     ACPI_STATUS             Status = AE_OK;
211     ACPI_TABLE_HEADER       *Header = NULL;
212
213
214     ACPI_FUNCTION_TRACE ("TbGetTableHeader");
215
216
217     /*
218      * Flags contains the current processor mode (Virtual or Physical
219      * addressing) The PointerType is either Logical or Physical
220      */
221     switch (Address->PointerType)
222     {
223     case ACPI_PHYSMODE_PHYSPTR:
224     case ACPI_LOGMODE_LOGPTR:
225
226         /* Pointer matches processor mode, copy the header */
227
228         ACPI_MEMCPY (ReturnHeader, Address->Pointer.Logical,
229             sizeof (ACPI_TABLE_HEADER));
230         break;
231
232
233     case ACPI_LOGMODE_PHYSPTR:
234
235         /* Create a logical address for the physical pointer*/
236
237         Status = AcpiOsMapMemory (Address->Pointer.Physical,
238                     sizeof (ACPI_TABLE_HEADER), (void *) &Header);
239         if (ACPI_FAILURE (Status))
240         {
241             ACPI_REPORT_ERROR ((
242                 "Could not map memory at %8.8X%8.8X for length %X\n",
243                 ACPI_FORMAT_UINT64 (Address->Pointer.Physical),
244                 sizeof (ACPI_TABLE_HEADER)));
245             return_ACPI_STATUS (Status);
246         }
247
248         /* Copy header and delete mapping */
249
250         ACPI_MEMCPY (ReturnHeader, Header, sizeof (ACPI_TABLE_HEADER));
251         AcpiOsUnmapMemory (Header, sizeof (ACPI_TABLE_HEADER));
252         break;
253
254
255     default:
256
257         ACPI_REPORT_ERROR (("Invalid address flags %X\n",
258             Address->PointerType));
259         return_ACPI_STATUS (AE_BAD_PARAMETER);
260     }
261
262     ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "Table Signature: [%4.4s]\n",
263         ReturnHeader->Signature));
264
265     return_ACPI_STATUS (AE_OK);
266 }
267
268
269 /*******************************************************************************
270  *
271  * FUNCTION:    AcpiTbGetTableBody
272  *
273  * PARAMETERS:  Address             - Address of table to retrieve.  Can be
274  *                                    Logical or Physical
275  *              Header              - Header of the table to retrieve
276  *              TableInfo           - Where the table info is returned
277  *
278  * RETURN:      Status
279  *
280  * DESCRIPTION: Get an entire ACPI table with support to allow the host OS to
281  *              replace the table with a newer version (table override.)
282  *              Works in both physical or virtual
283  *              addressing mode.  Works with both physical or logical pointers.
284  *              Table is either copied or mapped, depending on the pointer
285  *              type and mode of the processor.
286  *
287  ******************************************************************************/
288
289 ACPI_STATUS
290 AcpiTbGetTableBody (
291     ACPI_POINTER            *Address,
292     ACPI_TABLE_HEADER       *Header,
293     ACPI_TABLE_DESC         *TableInfo)
294 {
295     ACPI_STATUS             Status;
296
297
298     ACPI_FUNCTION_TRACE ("TbGetTableBody");
299
300
301     if (!TableInfo || !Address)
302     {
303         return_ACPI_STATUS (AE_BAD_PARAMETER);
304     }
305
306     /* Attempt table override. */
307
308     Status = AcpiTbTableOverride (Header, TableInfo);
309     if (ACPI_SUCCESS (Status))
310     {
311         /* Table was overridden by the host OS */
312
313         return_ACPI_STATUS (Status);
314     }
315
316     /* No override, get the original table */
317
318     Status = AcpiTbGetThisTable (Address, Header, TableInfo);
319     return_ACPI_STATUS (Status);
320 }
321
322
323 /*******************************************************************************
324  *
325  * FUNCTION:    AcpiTbTableOverride
326  *
327  * PARAMETERS:  Header              - Pointer to table header
328  *              TableInfo           - Return info if table is overridden
329  *
330  * RETURN:      None
331  *
332  * DESCRIPTION: Attempts override of current table with a new one if provided
333  *              by the host OS.
334  *
335  ******************************************************************************/
336
337 static ACPI_STATUS
338 AcpiTbTableOverride (
339     ACPI_TABLE_HEADER       *Header,
340     ACPI_TABLE_DESC         *TableInfo)
341 {
342     ACPI_TABLE_HEADER       *NewTable;
343     ACPI_STATUS             Status;
344     ACPI_POINTER            Address;
345
346
347     ACPI_FUNCTION_TRACE ("TbTableOverride");
348
349
350     /*
351      * The OSL will examine the header and decide whether to override this
352      * table.  If it decides to override, a table will be returned in NewTable,
353      * which we will then copy.
354      */
355     Status = AcpiOsTableOverride (Header, &NewTable);
356     if (ACPI_FAILURE (Status))
357     {
358         /* Some severe error from the OSL, but we basically ignore it */
359
360         ACPI_REPORT_ERROR (("Could not override ACPI table, %s\n",
361             AcpiFormatException (Status)));
362         return_ACPI_STATUS (Status);
363     }
364
365     if (!NewTable)
366     {
367         /* No table override */
368
369         return_ACPI_STATUS (AE_NO_ACPI_TABLES);
370     }
371
372     /*
373      * We have a new table to override the old one.  Get a copy of
374      * the new one.  We know that the new table has a logical pointer.
375      */
376     Address.PointerType     = ACPI_LOGICAL_POINTER | ACPI_LOGICAL_ADDRESSING;
377     Address.Pointer.Logical = NewTable;
378
379     Status = AcpiTbGetThisTable (&Address, NewTable, TableInfo);
380     if (ACPI_FAILURE (Status))
381     {
382         ACPI_REPORT_ERROR (("Could not copy override ACPI table, %s\n",
383             AcpiFormatException (Status)));
384         return_ACPI_STATUS (Status);
385     }
386
387     /* Copy the table info */
388
389     ACPI_REPORT_INFO (("Table [%4.4s] replaced by host OS\n",
390         TableInfo->Pointer->Signature));
391
392     return_ACPI_STATUS (AE_OK);
393 }
394
395
396 /*******************************************************************************
397  *
398  * FUNCTION:    AcpiTbGetThisTable
399  *
400  * PARAMETERS:  Address             - Address of table to retrieve.  Can be
401  *                                    Logical or Physical
402  *              Header              - Header of the table to retrieve
403  *              TableInfo           - Where the table info is returned
404  *
405  * RETURN:      Status
406  *
407  * DESCRIPTION: Get an entire ACPI table.  Works in both physical or virtual
408  *              addressing mode.  Works with both physical or logical pointers.
409  *              Table is either copied or mapped, depending on the pointer
410  *              type and mode of the processor.
411  *
412  ******************************************************************************/
413
414 static ACPI_STATUS
415 AcpiTbGetThisTable (
416     ACPI_POINTER            *Address,
417     ACPI_TABLE_HEADER       *Header,
418     ACPI_TABLE_DESC         *TableInfo)
419 {
420     ACPI_TABLE_HEADER       *FullTable = NULL;
421     UINT8                   Allocation;
422     ACPI_STATUS             Status = AE_OK;
423
424
425     ACPI_FUNCTION_TRACE ("TbGetThisTable");
426
427
428     /*
429      * Flags contains the current processor mode (Virtual or Physical
430      * addressing) The PointerType is either Logical or Physical
431      */
432     switch (Address->PointerType)
433     {
434     case ACPI_PHYSMODE_PHYSPTR:
435     case ACPI_LOGMODE_LOGPTR:
436
437         /* Pointer matches processor mode, copy the table to a new buffer */
438
439         FullTable = ACPI_MEM_ALLOCATE (Header->Length);
440         if (!FullTable)
441         {
442             ACPI_REPORT_ERROR ((
443                 "Could not allocate table memory for [%4.4s] length %X\n",
444                 Header->Signature, Header->Length));
445             return_ACPI_STATUS (AE_NO_MEMORY);
446         }
447
448         /* Copy the entire table (including header) to the local buffer */
449
450         ACPI_MEMCPY (FullTable, Address->Pointer.Logical, Header->Length);
451
452         /* Save allocation type */
453
454         Allocation = ACPI_MEM_ALLOCATED;
455         break;
456
457
458     case ACPI_LOGMODE_PHYSPTR:
459
460         /*
461          * Just map the table's physical memory
462          * into our address space.
463          */
464         Status = AcpiOsMapMemory (Address->Pointer.Physical,
465                     (ACPI_SIZE) Header->Length, (void *) &FullTable);
466         if (ACPI_FAILURE (Status))
467         {
468             ACPI_REPORT_ERROR ((
469                 "Could not map memory for table [%4.4s] at %8.8X%8.8X for length %X\n",
470                 Header->Signature,
471                 ACPI_FORMAT_UINT64 (Address->Pointer.Physical),
472                 Header->Length));
473             return (Status);
474         }
475
476         /* Save allocation type */
477
478         Allocation = ACPI_MEM_MAPPED;
479         break;
480
481
482     default:
483
484         ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid address flags %X\n",
485             Address->PointerType));
486         return_ACPI_STATUS (AE_BAD_PARAMETER);
487     }
488
489     /*
490      * Validate checksum for _most_ tables,
491      * even the ones whose signature we don't recognize
492      */
493     if (TableInfo->Type != ACPI_TABLE_FACS)
494     {
495         Status = AcpiTbVerifyTableChecksum (FullTable);
496
497 #if (!ACPI_CHECKSUM_ABORT)
498         if (ACPI_FAILURE (Status))
499         {
500             /* Ignore the error if configuration says so */
501
502             Status = AE_OK;
503         }
504 #endif
505     }
506
507     /* Return values */
508
509     TableInfo->Pointer      = FullTable;
510     TableInfo->Length       = (ACPI_SIZE) Header->Length;
511     TableInfo->Allocation   = Allocation;
512
513     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
514         "Found table [%4.4s] at %8.8X%8.8X, mapped/copied to %p\n",
515         FullTable->Signature,
516         ACPI_FORMAT_UINT64 (Address->Pointer.Physical), FullTable));
517
518     return_ACPI_STATUS (Status);
519 }
520
521
522 /*******************************************************************************
523  *
524  * FUNCTION:    AcpiTbGetTablePtr
525  *
526  * PARAMETERS:  TableType       - one of the defined table types
527  *              Instance        - Which table of this type
528  *              TablePtrLoc     - pointer to location to place the pointer for
529  *                                return
530  *
531  * RETURN:      Status
532  *
533  * DESCRIPTION: This function is called to get the pointer to an ACPI table.
534  *
535  ******************************************************************************/
536
537 ACPI_STATUS
538 AcpiTbGetTablePtr (
539     ACPI_TABLE_TYPE         TableType,
540     UINT32                  Instance,
541     ACPI_TABLE_HEADER       **TablePtrLoc)
542 {
543     ACPI_TABLE_DESC         *TableDesc;
544     UINT32                  i;
545
546
547     ACPI_FUNCTION_TRACE ("TbGetTablePtr");
548
549
550     if (!AcpiGbl_DSDT)
551     {
552         return_ACPI_STATUS (AE_NO_ACPI_TABLES);
553     }
554
555     if (TableType > ACPI_TABLE_MAX)
556     {
557         return_ACPI_STATUS (AE_BAD_PARAMETER);
558     }
559
560     /*
561      * For all table types (Single/Multiple), the first
562      * instance is always in the list head.
563      */
564     if (Instance == 1)
565     {
566         /* Get the first */
567
568         *TablePtrLoc = NULL;
569         if (AcpiGbl_TableLists[TableType].Next)
570         {
571             *TablePtrLoc = AcpiGbl_TableLists[TableType].Next->Pointer;
572         }
573         return_ACPI_STATUS (AE_OK);
574     }
575
576     /* Check for instance out of range */
577
578     if (Instance > AcpiGbl_TableLists[TableType].Count)
579     {
580         return_ACPI_STATUS (AE_NOT_EXIST);
581     }
582
583     /* Walk the list to get the desired table
584      * Since the if (Instance == 1) check above checked for the
585      * first table, setting TableDesc equal to the .Next member
586      * is actually pointing to the second table.  Therefore, we
587      * need to walk from the 2nd table until we reach the Instance
588      * that the user is looking for and return its table pointer.
589      */
590     TableDesc = AcpiGbl_TableLists[TableType].Next;
591     for (i = 2; i < Instance; i++)
592     {
593         TableDesc = TableDesc->Next;
594     }
595
596     /* We are now pointing to the requested table's descriptor */
597
598     *TablePtrLoc = TableDesc->Pointer;
599
600     return_ACPI_STATUS (AE_OK);
601 }
602