Home | History | Annotate | Line # | Download | only in acpidump
apmain.c revision 1.1.1.2.2.5
      1          1.1  christos /******************************************************************************
      2          1.1  christos  *
      3          1.1  christos  * Module Name: apmain - Main module for the acpidump utility
      4          1.1  christos  *
      5          1.1  christos  *****************************************************************************/
      6          1.1  christos 
      7          1.1  christos /*
      8  1.1.1.2.2.3     skrll  * Copyright (C) 2000 - 2016, Intel Corp.
      9          1.1  christos  * All rights reserved.
     10          1.1  christos  *
     11          1.1  christos  * Redistribution and use in source and binary forms, with or without
     12          1.1  christos  * modification, are permitted provided that the following conditions
     13          1.1  christos  * are met:
     14          1.1  christos  * 1. Redistributions of source code must retain the above copyright
     15          1.1  christos  *    notice, this list of conditions, and the following disclaimer,
     16          1.1  christos  *    without modification.
     17          1.1  christos  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18          1.1  christos  *    substantially similar to the "NO WARRANTY" disclaimer below
     19          1.1  christos  *    ("Disclaimer") and any redistribution must be conditioned upon
     20          1.1  christos  *    including a substantially similar Disclaimer requirement for further
     21          1.1  christos  *    binary redistribution.
     22          1.1  christos  * 3. Neither the names of the above-listed copyright holders nor the names
     23          1.1  christos  *    of any contributors may be used to endorse or promote products derived
     24          1.1  christos  *    from this software without specific prior written permission.
     25          1.1  christos  *
     26          1.1  christos  * Alternatively, this software may be distributed under the terms of the
     27          1.1  christos  * GNU General Public License ("GPL") version 2 as published by the Free
     28          1.1  christos  * Software Foundation.
     29          1.1  christos  *
     30          1.1  christos  * NO WARRANTY
     31          1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32          1.1  christos  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33          1.1  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34          1.1  christos  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35          1.1  christos  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36          1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37          1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38          1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39          1.1  christos  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40          1.1  christos  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41          1.1  christos  * POSSIBILITY OF SUCH DAMAGES.
     42          1.1  christos  */
     43          1.1  christos 
     44          1.1  christos #define _DECLARE_GLOBALS
     45          1.1  christos #include "acpidump.h"
     46          1.1  christos 
     47          1.1  christos 
     48          1.1  christos /*
     49          1.1  christos  * acpidump - A portable utility for obtaining system ACPI tables and dumping
     50          1.1  christos  * them in an ASCII hex format suitable for binary extraction via acpixtract.
     51          1.1  christos  *
     52          1.1  christos  * Obtaining the system ACPI tables is an OS-specific operation.
     53          1.1  christos  *
     54          1.1  christos  * This utility can be ported to any host operating system by providing a
     55          1.1  christos  * module containing system-specific versions of these interfaces:
     56          1.1  christos  *
     57          1.1  christos  *      AcpiOsGetTableByAddress
     58          1.1  christos  *      AcpiOsGetTableByIndex
     59          1.1  christos  *      AcpiOsGetTableByName
     60          1.1  christos  *
     61          1.1  christos  * See the ACPICA Reference Guide for the exact definitions of these
     62          1.1  christos  * interfaces. Also, see these ACPICA source code modules for example
     63          1.1  christos  * implementations:
     64          1.1  christos  *
     65          1.1  christos  *      source/os_specific/service_layers/oswintbl.c
     66          1.1  christos  *      source/os_specific/service_layers/oslinuxtbl.c
     67          1.1  christos  */
     68          1.1  christos 
     69          1.1  christos 
     70          1.1  christos /* Local prototypes */
     71          1.1  christos 
     72          1.1  christos static void
     73          1.1  christos ApDisplayUsage (
     74          1.1  christos     void);
     75          1.1  christos 
     76          1.1  christos static int
     77          1.1  christos ApDoOptions (
     78          1.1  christos     int                     argc,
     79          1.1  christos     char                    **argv);
     80          1.1  christos 
     81      1.1.1.2  christos static int
     82          1.1  christos ApInsertAction (
     83          1.1  christos     char                    *Argument,
     84          1.1  christos     UINT32                  ToBeDone);
     85          1.1  christos 
     86          1.1  christos 
     87          1.1  christos /* Table for deferred actions from command line options */
     88          1.1  christos 
     89          1.1  christos AP_DUMP_ACTION              ActionTable [AP_MAX_ACTIONS];
     90          1.1  christos UINT32                      CurrentAction = 0;
     91          1.1  christos 
     92          1.1  christos 
     93          1.1  christos #define AP_UTILITY_NAME             "ACPI Binary Table Dump Utility"
     94  1.1.1.2.2.2     skrll #define AP_SUPPORTED_OPTIONS        "?a:bc:f:hn:o:r:svxz"
     95          1.1  christos 
     96          1.1  christos 
     97          1.1  christos /******************************************************************************
     98          1.1  christos  *
     99          1.1  christos  * FUNCTION:    ApDisplayUsage
    100          1.1  christos  *
    101          1.1  christos  * DESCRIPTION: Usage message for the AcpiDump utility
    102          1.1  christos  *
    103          1.1  christos  ******************************************************************************/
    104          1.1  christos 
    105          1.1  christos static void
    106          1.1  christos ApDisplayUsage (
    107          1.1  christos     void)
    108          1.1  christos {
    109          1.1  christos 
    110          1.1  christos     ACPI_USAGE_HEADER ("acpidump [options]");
    111          1.1  christos 
    112          1.1  christos     ACPI_OPTION ("-b",                      "Dump tables to binary files");
    113          1.1  christos     ACPI_OPTION ("-h -?",                   "This help message");
    114          1.1  christos     ACPI_OPTION ("-o <File>",               "Redirect output to file");
    115          1.1  christos     ACPI_OPTION ("-r <Address>",            "Dump tables from specified RSDP");
    116          1.1  christos     ACPI_OPTION ("-s",                      "Print table summaries only");
    117          1.1  christos     ACPI_OPTION ("-v",                      "Display version information");
    118          1.1  christos     ACPI_OPTION ("-z",                      "Verbose mode");
    119          1.1  christos 
    120      1.1.1.2  christos     ACPI_USAGE_TEXT ("\nTable Options:\n");
    121          1.1  christos 
    122          1.1  christos     ACPI_OPTION ("-a <Address>",            "Get table via a physical address");
    123  1.1.1.2.2.2     skrll     ACPI_OPTION ("-c <on|off>",             "Turning on/off customized table dumping");
    124          1.1  christos     ACPI_OPTION ("-f <BinaryFile>",         "Get table via a binary file");
    125          1.1  christos     ACPI_OPTION ("-n <Signature>",          "Get table via a name/signature");
    126      1.1.1.2  christos     ACPI_OPTION ("-x",                      "Do not use but dump XSDT");
    127      1.1.1.2  christos     ACPI_OPTION ("-x -x",                   "Do not use or dump XSDT");
    128          1.1  christos 
    129      1.1.1.2  christos     ACPI_USAGE_TEXT (
    130          1.1  christos         "\n"
    131          1.1  christos         "Invocation without parameters dumps all available tables\n"
    132          1.1  christos         "Multiple mixed instances of -a, -f, and -n are supported\n\n");
    133          1.1  christos }
    134          1.1  christos 
    135          1.1  christos 
    136          1.1  christos /******************************************************************************
    137          1.1  christos  *
    138          1.1  christos  * FUNCTION:    ApInsertAction
    139          1.1  christos  *
    140          1.1  christos  * PARAMETERS:  Argument            - Pointer to the argument for this action
    141          1.1  christos  *              ToBeDone            - What to do to process this action
    142          1.1  christos  *
    143      1.1.1.2  christos  * RETURN:      Status
    144          1.1  christos  *
    145          1.1  christos  * DESCRIPTION: Add an action item to the action table
    146          1.1  christos  *
    147          1.1  christos  ******************************************************************************/
    148          1.1  christos 
    149      1.1.1.2  christos static int
    150          1.1  christos ApInsertAction (
    151          1.1  christos     char                    *Argument,
    152          1.1  christos     UINT32                  ToBeDone)
    153          1.1  christos {
    154          1.1  christos 
    155          1.1  christos     /* Insert action and check for table overflow */
    156          1.1  christos 
    157          1.1  christos     ActionTable [CurrentAction].Argument = Argument;
    158          1.1  christos     ActionTable [CurrentAction].ToBeDone = ToBeDone;
    159          1.1  christos 
    160          1.1  christos     CurrentAction++;
    161          1.1  christos     if (CurrentAction > AP_MAX_ACTIONS)
    162          1.1  christos     {
    163  1.1.1.2.2.5     skrll         fprintf (stderr, "Too many table options (max %u)\n", AP_MAX_ACTIONS);
    164      1.1.1.2  christos         return (-1);
    165          1.1  christos     }
    166      1.1.1.2  christos 
    167      1.1.1.2  christos     return (0);
    168          1.1  christos }
    169          1.1  christos 
    170          1.1  christos 
    171          1.1  christos /******************************************************************************
    172          1.1  christos  *
    173          1.1  christos  * FUNCTION:    ApDoOptions
    174          1.1  christos  *
    175          1.1  christos  * PARAMETERS:  argc/argv           - Standard argc/argv
    176          1.1  christos  *
    177          1.1  christos  * RETURN:      Status
    178          1.1  christos  *
    179          1.1  christos  * DESCRIPTION: Command line option processing. The main actions for getting
    180          1.1  christos  *              and dumping tables are deferred via the action table.
    181          1.1  christos  *
    182          1.1  christos  *****************************************************************************/
    183          1.1  christos 
    184          1.1  christos static int
    185          1.1  christos ApDoOptions (
    186          1.1  christos     int                     argc,
    187          1.1  christos     char                    **argv)
    188          1.1  christos {
    189          1.1  christos     int                     j;
    190          1.1  christos     ACPI_STATUS             Status;
    191          1.1  christos 
    192          1.1  christos 
    193          1.1  christos     /* Command line options */
    194          1.1  christos 
    195      1.1.1.2  christos     while ((j = AcpiGetopt (argc, argv, AP_SUPPORTED_OPTIONS)) != ACPI_OPT_END) switch (j)
    196          1.1  christos     {
    197          1.1  christos     /*
    198          1.1  christos      * Global options
    199          1.1  christos      */
    200          1.1  christos     case 'b':   /* Dump all input tables to binary files */
    201          1.1  christos 
    202          1.1  christos         Gbl_BinaryMode = TRUE;
    203          1.1  christos         continue;
    204          1.1  christos 
    205          1.1  christos     case 'c':   /* Dump customized tables */
    206          1.1  christos 
    207  1.1.1.2.2.2     skrll         if (!strcmp (AcpiGbl_Optarg, "on"))
    208  1.1.1.2.2.2     skrll         {
    209  1.1.1.2.2.2     skrll             Gbl_DumpCustomizedTables = TRUE;
    210  1.1.1.2.2.2     skrll         }
    211  1.1.1.2.2.2     skrll         else if (!strcmp (AcpiGbl_Optarg, "off"))
    212  1.1.1.2.2.2     skrll         {
    213  1.1.1.2.2.2     skrll             Gbl_DumpCustomizedTables = FALSE;
    214  1.1.1.2.2.2     skrll         }
    215  1.1.1.2.2.2     skrll         else
    216  1.1.1.2.2.2     skrll         {
    217  1.1.1.2.2.5     skrll             fprintf (stderr, "%s: Cannot handle this switch, please use on|off\n",
    218  1.1.1.2.2.2     skrll                 AcpiGbl_Optarg);
    219  1.1.1.2.2.2     skrll             return (-1);
    220  1.1.1.2.2.2     skrll         }
    221          1.1  christos         continue;
    222          1.1  christos 
    223          1.1  christos     case 'h':
    224          1.1  christos     case '?':
    225          1.1  christos 
    226          1.1  christos         ApDisplayUsage ();
    227      1.1.1.2  christos         return (1);
    228          1.1  christos 
    229          1.1  christos     case 'o':   /* Redirect output to a single file */
    230          1.1  christos 
    231          1.1  christos         if (ApOpenOutputFile (AcpiGbl_Optarg))
    232          1.1  christos         {
    233      1.1.1.2  christos             return (-1);
    234          1.1  christos         }
    235          1.1  christos         continue;
    236          1.1  christos 
    237          1.1  christos     case 'r':   /* Dump tables from specified RSDP */
    238          1.1  christos 
    239  1.1.1.2.2.5     skrll         Status = AcpiUtStrtoul64 (AcpiGbl_Optarg, ACPI_STRTOUL_64BIT,
    240  1.1.1.2.2.5     skrll             &Gbl_RsdpBase);
    241          1.1  christos         if (ACPI_FAILURE (Status))
    242          1.1  christos         {
    243  1.1.1.2.2.5     skrll             fprintf (stderr, "%s: Could not convert to a physical address\n",
    244          1.1  christos                 AcpiGbl_Optarg);
    245      1.1.1.2  christos             return (-1);
    246          1.1  christos         }
    247          1.1  christos         continue;
    248          1.1  christos 
    249          1.1  christos     case 's':   /* Print table summaries only */
    250          1.1  christos 
    251          1.1  christos         Gbl_SummaryMode = TRUE;
    252          1.1  christos         continue;
    253          1.1  christos 
    254      1.1.1.2  christos     case 'x':   /* Do not use XSDT */
    255      1.1.1.2  christos 
    256      1.1.1.2  christos         if (!AcpiGbl_DoNotUseXsdt)
    257      1.1.1.2  christos         {
    258      1.1.1.2  christos             AcpiGbl_DoNotUseXsdt = TRUE;
    259      1.1.1.2  christos         }
    260      1.1.1.2  christos         else
    261      1.1.1.2  christos         {
    262      1.1.1.2  christos             Gbl_DoNotDumpXsdt = TRUE;
    263      1.1.1.2  christos         }
    264      1.1.1.2  christos         continue;
    265      1.1.1.2  christos 
    266          1.1  christos     case 'v':   /* Revision/version */
    267          1.1  christos 
    268      1.1.1.2  christos         AcpiOsPrintf (ACPI_COMMON_SIGNON (AP_UTILITY_NAME));
    269      1.1.1.2  christos         return (1);
    270          1.1  christos 
    271          1.1  christos     case 'z':   /* Verbose mode */
    272          1.1  christos 
    273          1.1  christos         Gbl_VerboseMode = TRUE;
    274  1.1.1.2.2.5     skrll         fprintf (stderr, ACPI_COMMON_SIGNON (AP_UTILITY_NAME));
    275          1.1  christos         continue;
    276          1.1  christos 
    277          1.1  christos     /*
    278          1.1  christos      * Table options
    279          1.1  christos      */
    280          1.1  christos     case 'a':   /* Get table by physical address */
    281          1.1  christos 
    282      1.1.1.2  christos         if (ApInsertAction (AcpiGbl_Optarg, AP_DUMP_TABLE_BY_ADDRESS))
    283      1.1.1.2  christos         {
    284      1.1.1.2  christos             return (-1);
    285      1.1.1.2  christos         }
    286          1.1  christos         break;
    287          1.1  christos 
    288          1.1  christos     case 'f':   /* Get table from a file */
    289          1.1  christos 
    290      1.1.1.2  christos         if (ApInsertAction (AcpiGbl_Optarg, AP_DUMP_TABLE_BY_FILE))
    291      1.1.1.2  christos         {
    292      1.1.1.2  christos             return (-1);
    293      1.1.1.2  christos         }
    294          1.1  christos         break;
    295          1.1  christos 
    296          1.1  christos     case 'n':   /* Get table by input name (signature) */
    297          1.1  christos 
    298      1.1.1.2  christos         if (ApInsertAction (AcpiGbl_Optarg, AP_DUMP_TABLE_BY_NAME))
    299      1.1.1.2  christos         {
    300      1.1.1.2  christos             return (-1);
    301      1.1.1.2  christos         }
    302          1.1  christos         break;
    303          1.1  christos 
    304          1.1  christos     default:
    305          1.1  christos 
    306          1.1  christos         ApDisplayUsage ();
    307      1.1.1.2  christos         return (-1);
    308          1.1  christos     }
    309          1.1  christos 
    310          1.1  christos     /* If there are no actions, this means "get/dump all tables" */
    311          1.1  christos 
    312          1.1  christos     if (CurrentAction == 0)
    313          1.1  christos     {
    314      1.1.1.2  christos         if (ApInsertAction (NULL, AP_DUMP_ALL_TABLES))
    315      1.1.1.2  christos         {
    316      1.1.1.2  christos             return (-1);
    317      1.1.1.2  christos         }
    318          1.1  christos     }
    319          1.1  christos 
    320          1.1  christos     return (0);
    321          1.1  christos }
    322          1.1  christos 
    323          1.1  christos 
    324          1.1  christos /******************************************************************************
    325          1.1  christos  *
    326          1.1  christos  * FUNCTION:    main
    327          1.1  christos  *
    328          1.1  christos  * PARAMETERS:  argc/argv           - Standard argc/argv
    329          1.1  christos  *
    330          1.1  christos  * RETURN:      Status
    331          1.1  christos  *
    332          1.1  christos  * DESCRIPTION: C main function for acpidump utility
    333          1.1  christos  *
    334          1.1  christos  ******************************************************************************/
    335          1.1  christos 
    336      1.1.1.2  christos #ifndef _GNU_EFI
    337          1.1  christos int ACPI_SYSTEM_XFACE
    338          1.1  christos main (
    339          1.1  christos     int                     argc,
    340          1.1  christos     char                    *argv[])
    341      1.1.1.2  christos #else
    342      1.1.1.2  christos int ACPI_SYSTEM_XFACE
    343      1.1.1.2  christos acpi_main (
    344      1.1.1.2  christos     int                     argc,
    345      1.1.1.2  christos     char                    *argv[])
    346      1.1.1.2  christos #endif
    347          1.1  christos {
    348          1.1  christos     int                     Status = 0;
    349          1.1  christos     AP_DUMP_ACTION          *Action;
    350          1.1  christos     UINT32                  FileSize;
    351          1.1  christos     UINT32                  i;
    352          1.1  christos 
    353          1.1  christos 
    354          1.1  christos     ACPI_DEBUG_INITIALIZE (); /* For debug version only */
    355      1.1.1.2  christos     AcpiOsInitialize ();
    356      1.1.1.2  christos     Gbl_OutputFile = ACPI_FILE_OUT;
    357  1.1.1.2.2.5     skrll     AcpiGbl_IntegerByteWidth = 8;
    358          1.1  christos 
    359          1.1  christos     /* Process command line options */
    360          1.1  christos 
    361      1.1.1.2  christos     Status = ApDoOptions (argc, argv);
    362      1.1.1.2  christos     if (Status > 0)
    363          1.1  christos     {
    364      1.1.1.2  christos         return (0);
    365      1.1.1.2  christos     }
    366      1.1.1.2  christos     if (Status < 0)
    367      1.1.1.2  christos     {
    368      1.1.1.2  christos         return (Status);
    369          1.1  christos     }
    370          1.1  christos 
    371          1.1  christos     /* Get/dump ACPI table(s) as requested */
    372          1.1  christos 
    373          1.1  christos     for (i = 0; i < CurrentAction; i++)
    374          1.1  christos     {
    375          1.1  christos         Action = &ActionTable[i];
    376          1.1  christos         switch (Action->ToBeDone)
    377          1.1  christos         {
    378          1.1  christos         case AP_DUMP_ALL_TABLES:
    379          1.1  christos 
    380          1.1  christos             Status = ApDumpAllTables ();
    381          1.1  christos             break;
    382          1.1  christos 
    383          1.1  christos         case AP_DUMP_TABLE_BY_ADDRESS:
    384          1.1  christos 
    385          1.1  christos             Status = ApDumpTableByAddress (Action->Argument);
    386          1.1  christos             break;
    387          1.1  christos 
    388          1.1  christos         case AP_DUMP_TABLE_BY_NAME:
    389          1.1  christos 
    390          1.1  christos             Status = ApDumpTableByName (Action->Argument);
    391          1.1  christos             break;
    392          1.1  christos 
    393          1.1  christos         case AP_DUMP_TABLE_BY_FILE:
    394          1.1  christos 
    395          1.1  christos             Status = ApDumpTableFromFile (Action->Argument);
    396          1.1  christos             break;
    397          1.1  christos 
    398          1.1  christos         default:
    399          1.1  christos 
    400  1.1.1.2.2.5     skrll             fprintf (stderr, "Internal error, invalid action: 0x%X\n",
    401          1.1  christos                 Action->ToBeDone);
    402          1.1  christos             return (-1);
    403          1.1  christos         }
    404          1.1  christos 
    405          1.1  christos         if (Status)
    406          1.1  christos         {
    407          1.1  christos             return (Status);
    408          1.1  christos         }
    409          1.1  christos     }
    410          1.1  christos 
    411      1.1.1.2  christos     if (Gbl_OutputFilename)
    412          1.1  christos     {
    413          1.1  christos         if (Gbl_VerboseMode)
    414          1.1  christos         {
    415          1.1  christos             /* Summary for the output file */
    416          1.1  christos 
    417      1.1.1.2  christos             FileSize = CmGetFileSize (Gbl_OutputFile);
    418  1.1.1.2.2.5     skrll             fprintf (stderr, "Output file %s contains 0x%X (%u) bytes\n\n",
    419          1.1  christos                 Gbl_OutputFilename, FileSize, FileSize);
    420          1.1  christos         }
    421          1.1  christos 
    422  1.1.1.2.2.5     skrll         fclose (Gbl_OutputFile);
    423          1.1  christos     }
    424          1.1  christos 
    425          1.1  christos     return (Status);
    426          1.1  christos }
    427