1*cb565728SJerry Jelinek /****************************************************************************** 2*cb565728SJerry Jelinek * 3*cb565728SJerry Jelinek * Module Name: acpixtract.h - Include for acpixtract utility 4*cb565728SJerry Jelinek * 5*cb565728SJerry Jelinek *****************************************************************************/ 6*cb565728SJerry Jelinek 7*cb565728SJerry Jelinek /* 8*cb565728SJerry Jelinek * Copyright (C) 2000 - 2016, Intel Corp. 9*cb565728SJerry Jelinek * All rights reserved. 10*cb565728SJerry Jelinek * 11*cb565728SJerry Jelinek * Redistribution and use in source and binary forms, with or without 12*cb565728SJerry Jelinek * modification, are permitted provided that the following conditions 13*cb565728SJerry Jelinek * are met: 14*cb565728SJerry Jelinek * 1. Redistributions of source code must retain the above copyright 15*cb565728SJerry Jelinek * notice, this list of conditions, and the following disclaimer, 16*cb565728SJerry Jelinek * without modification. 17*cb565728SJerry Jelinek * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18*cb565728SJerry Jelinek * substantially similar to the "NO WARRANTY" disclaimer below 19*cb565728SJerry Jelinek * ("Disclaimer") and any redistribution must be conditioned upon 20*cb565728SJerry Jelinek * including a substantially similar Disclaimer requirement for further 21*cb565728SJerry Jelinek * binary redistribution. 22*cb565728SJerry Jelinek * 3. Neither the names of the above-listed copyright holders nor the names 23*cb565728SJerry Jelinek * of any contributors may be used to endorse or promote products derived 24*cb565728SJerry Jelinek * from this software without specific prior written permission. 25*cb565728SJerry Jelinek * 26*cb565728SJerry Jelinek * Alternatively, this software may be distributed under the terms of the 27*cb565728SJerry Jelinek * GNU General Public License ("GPL") version 2 as published by the Free 28*cb565728SJerry Jelinek * Software Foundation. 29*cb565728SJerry Jelinek * 30*cb565728SJerry Jelinek * NO WARRANTY 31*cb565728SJerry Jelinek * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32*cb565728SJerry Jelinek * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33*cb565728SJerry Jelinek * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34*cb565728SJerry Jelinek * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35*cb565728SJerry Jelinek * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36*cb565728SJerry Jelinek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37*cb565728SJerry Jelinek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38*cb565728SJerry Jelinek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39*cb565728SJerry Jelinek * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40*cb565728SJerry Jelinek * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41*cb565728SJerry Jelinek * POSSIBILITY OF SUCH DAMAGES. 42*cb565728SJerry Jelinek */ 43*cb565728SJerry Jelinek 44*cb565728SJerry Jelinek #include "acpi.h" 45*cb565728SJerry Jelinek #include "accommon.h" 46*cb565728SJerry Jelinek #include "acapps.h" 47*cb565728SJerry Jelinek #include <stdio.h> 48*cb565728SJerry Jelinek 49*cb565728SJerry Jelinek 50*cb565728SJerry Jelinek #undef ACPI_GLOBAL 51*cb565728SJerry Jelinek 52*cb565728SJerry Jelinek #ifdef DEFINE_ACPIXTRACT_GLOBALS 53*cb565728SJerry Jelinek #define ACPI_GLOBAL(type,name) \ 54*cb565728SJerry Jelinek extern type name; \ 55*cb565728SJerry Jelinek type name 56*cb565728SJerry Jelinek 57*cb565728SJerry Jelinek #else 58*cb565728SJerry Jelinek #define ACPI_GLOBAL(type,name) \ 59*cb565728SJerry Jelinek extern type name 60*cb565728SJerry Jelinek #endif 61*cb565728SJerry Jelinek 62*cb565728SJerry Jelinek 63*cb565728SJerry Jelinek /* Options */ 64*cb565728SJerry Jelinek 65*cb565728SJerry Jelinek #define AX_EXTRACT_ALL 0 66*cb565728SJerry Jelinek #define AX_LIST_ALL 1 67*cb565728SJerry Jelinek #define AX_EXTRACT_SIGNATURE 2 68*cb565728SJerry Jelinek #define AX_EXTRACT_AML_TABLES 3 69*cb565728SJerry Jelinek #define AX_EXTRACT_MULTI_TABLE 4 70*cb565728SJerry Jelinek 71*cb565728SJerry Jelinek #define AX_OPTIONAL_TABLES 0 72*cb565728SJerry Jelinek #define AX_REQUIRED_TABLE 1 73*cb565728SJerry Jelinek 74*cb565728SJerry Jelinek #define AX_UTILITY_NAME "ACPI Binary Table Extraction Utility" 75*cb565728SJerry Jelinek #define AX_SUPPORTED_OPTIONS "ahlms:v" 76*cb565728SJerry Jelinek #define AX_MULTI_TABLE_FILENAME "amltables.dat" 77*cb565728SJerry Jelinek #define AX_TABLE_INFO_FORMAT "Acpi table [%4.4s] - %7u bytes written to %s\n" 78*cb565728SJerry Jelinek 79*cb565728SJerry Jelinek /* Extraction states */ 80*cb565728SJerry Jelinek 81*cb565728SJerry Jelinek #define AX_STATE_FIND_HEADER 0 82*cb565728SJerry Jelinek #define AX_STATE_EXTRACT_DATA 1 83*cb565728SJerry Jelinek 84*cb565728SJerry Jelinek /* Miscellaneous constants */ 85*cb565728SJerry Jelinek 86*cb565728SJerry Jelinek #define AX_LINE_BUFFER_SIZE 256 87*cb565728SJerry Jelinek #define AX_MIN_BLOCK_HEADER_LENGTH 6 /* strlen ("DSDT @") */ 88*cb565728SJerry Jelinek 89*cb565728SJerry Jelinek 90*cb565728SJerry Jelinek typedef struct AxTableInfo 91*cb565728SJerry Jelinek { 92*cb565728SJerry Jelinek UINT32 Signature; 93*cb565728SJerry Jelinek unsigned int Instances; 94*cb565728SJerry Jelinek unsigned int NextInstance; 95*cb565728SJerry Jelinek struct AxTableInfo *Next; 96*cb565728SJerry Jelinek 97*cb565728SJerry Jelinek } AX_TABLE_INFO; 98*cb565728SJerry Jelinek 99*cb565728SJerry Jelinek 100*cb565728SJerry Jelinek /* Globals */ 101*cb565728SJerry Jelinek 102*cb565728SJerry Jelinek ACPI_GLOBAL (char, Gbl_LineBuffer[AX_LINE_BUFFER_SIZE]); 103*cb565728SJerry Jelinek ACPI_GLOBAL (char, Gbl_HeaderBuffer[AX_LINE_BUFFER_SIZE]); 104*cb565728SJerry Jelinek ACPI_GLOBAL (char, Gbl_InstanceBuffer[AX_LINE_BUFFER_SIZE]); 105*cb565728SJerry Jelinek 106*cb565728SJerry Jelinek ACPI_GLOBAL (AX_TABLE_INFO, *Gbl_TableListHead); 107*cb565728SJerry Jelinek ACPI_GLOBAL (char, Gbl_OutputFilename[32]); 108*cb565728SJerry Jelinek ACPI_GLOBAL (unsigned char, Gbl_BinaryData[16]); 109*cb565728SJerry Jelinek ACPI_GLOBAL (unsigned int, Gbl_TableCount); 110*cb565728SJerry Jelinek 111*cb565728SJerry Jelinek /* 112*cb565728SJerry Jelinek * acpixtract.c 113*cb565728SJerry Jelinek */ 114*cb565728SJerry Jelinek int 115*cb565728SJerry Jelinek AxExtractTables ( 116*cb565728SJerry Jelinek char *InputPathname, 117*cb565728SJerry Jelinek char *Signature, 118*cb565728SJerry Jelinek unsigned int MinimumInstances); 119*cb565728SJerry Jelinek 120*cb565728SJerry Jelinek int 121*cb565728SJerry Jelinek AxExtractToMultiAmlFile ( 122*cb565728SJerry Jelinek char *InputPathname); 123*cb565728SJerry Jelinek 124*cb565728SJerry Jelinek int 125*cb565728SJerry Jelinek AxListTables ( 126*cb565728SJerry Jelinek char *InputPathname); 127*cb565728SJerry Jelinek 128*cb565728SJerry Jelinek 129*cb565728SJerry Jelinek /* 130*cb565728SJerry Jelinek * axutils.c 131*cb565728SJerry Jelinek */ 132*cb565728SJerry Jelinek size_t 133*cb565728SJerry Jelinek AxGetTableHeader ( 134*cb565728SJerry Jelinek FILE *InputFile, 135*cb565728SJerry Jelinek unsigned char *OutputData); 136*cb565728SJerry Jelinek 137*cb565728SJerry Jelinek unsigned int 138*cb565728SJerry Jelinek AxCountTableInstances ( 139*cb565728SJerry Jelinek char *InputPathname, 140*cb565728SJerry Jelinek char *Signature); 141*cb565728SJerry Jelinek 142*cb565728SJerry Jelinek unsigned int 143*cb565728SJerry Jelinek AxGetNextInstance ( 144*cb565728SJerry Jelinek char *InputPathname, 145*cb565728SJerry Jelinek char *Signature); 146*cb565728SJerry Jelinek 147*cb565728SJerry Jelinek void 148*cb565728SJerry Jelinek AxNormalizeSignature ( 149*cb565728SJerry Jelinek char *Signature); 150*cb565728SJerry Jelinek 151*cb565728SJerry Jelinek void 152*cb565728SJerry Jelinek AxCheckAscii ( 153*cb565728SJerry Jelinek char *Name, 154*cb565728SJerry Jelinek int Count); 155*cb565728SJerry Jelinek 156*cb565728SJerry Jelinek int 157*cb565728SJerry Jelinek AxIsEmptyLine ( 158*cb565728SJerry Jelinek char *Buffer); 159*cb565728SJerry Jelinek 160*cb565728SJerry Jelinek int 161*cb565728SJerry Jelinek AxIsDataBlockHeader ( 162*cb565728SJerry Jelinek void); 163*cb565728SJerry Jelinek 164*cb565728SJerry Jelinek long 165*cb565728SJerry Jelinek AxProcessOneTextLine ( 166*cb565728SJerry Jelinek FILE *OutputFile, 167*cb565728SJerry Jelinek char *ThisSignature, 168*cb565728SJerry Jelinek unsigned int ThisTableBytesWritten); 169*cb565728SJerry Jelinek 170*cb565728SJerry Jelinek size_t 171*cb565728SJerry Jelinek AxConvertLine ( 172*cb565728SJerry Jelinek char *InputLine, 173*cb565728SJerry Jelinek unsigned char *OutputData); 174