ACPI_STATUS AcpiTbRecognizeTable ( ACPI_TABLE_DESC *TableInfo, UINT8 SearchType) { ACPI_TABLE_HEADER *TableHeader; ACPI_STATUS Status; ACPI_FUNCTION_TRACE (TbRecognizeTable); /* Ensure that we have a valid table pointer */ TableHeader = (ACPI_TABLE_HEADER *) TableInfo->Pointer; if (!TableHeader) { return_ACPI_STATUS (AE_BAD_PARAMETER); } /* * We only "recognize" a limited number of ACPI tables -- namely, the * ones that are used by the subsystem (DSDT, FADT, etc.) * * An AE_TABLE_NOT_SUPPORTED means that the table was not recognized. * This can be any one of many valid ACPI tables, it just isn't one of * the tables that is consumed by the core subsystem */ Status = AcpiTbMatchSignature (TableHeader->Signature, TableInfo, SearchType); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } Status = AcpiTbValidateTableHeader (TableHeader); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } /* Return the table type and length via the info struct */ TableInfo->Length = (ACPI_SIZE) TableHeader->Length; return_ACPI_STATUS (Status); }
ACPI_STATUS AcpiDbLoadTable( FILE *fp, ACPI_TABLE_HEADER **TablePtr, UINT32 *TableLength) { ACPI_TABLE_HEADER TableHeader; UINT8 *AmlPtr; UINT32 AmlLength; UINT32 Actual; ACPI_STATUS Status; /* Read the table header */ if (fread (&TableHeader, 1, sizeof (TableHeader), fp) != sizeof (ACPI_TABLE_HEADER)) { AcpiOsPrintf ("Couldn't read the table header\n"); return (AE_BAD_SIGNATURE); } /* Validate the table header/length */ Status = AcpiTbValidateTableHeader (&TableHeader); if ((ACPI_FAILURE (Status)) || (TableHeader.Length > 524288)) /* 1/2 Mbyte should be enough */ { AcpiOsPrintf ("Table header is invalid!\n"); return (AE_ERROR); } /* We only support a limited number of table types */ if (STRNCMP ((char *) TableHeader.Signature, DSDT_SIG, 4) && STRNCMP ((char *) TableHeader.Signature, PSDT_SIG, 4) && STRNCMP ((char *) TableHeader.Signature, SSDT_SIG, 4)) { AcpiOsPrintf ("Table signature is invalid\n"); DUMP_BUFFER (&TableHeader, sizeof (ACPI_TABLE_HEADER)); return (AE_ERROR); } /* Allocate a buffer for the table */ *TableLength = TableHeader.Length; *TablePtr = ACPI_MEM_ALLOCATE ((size_t) *TableLength); if (!*TablePtr) { AcpiOsPrintf ("Could not allocate memory for ACPI table %4.4s (size=%X)\n", TableHeader.Signature, TableHeader.Length); return (AE_NO_MEMORY); } AmlPtr = (UINT8 *) *TablePtr + sizeof (TableHeader); AmlLength = *TableLength - sizeof (TableHeader); /* Copy the header to the buffer */ MEMCPY (*TablePtr, &TableHeader, sizeof (TableHeader)); /* Get the rest of the table */ Actual = fread (AmlPtr, 1, (size_t) AmlLength, fp); if (Actual == AmlLength) { return (AE_OK); } if (Actual > 0) { AcpiOsPrintf ("Warning - reading table, asked for %X got %X\n", AmlLength, Actual); return (AE_OK); } AcpiOsPrintf ("Error - could not read the table file\n"); ACPI_MEM_FREE (*TablePtr); *TablePtr = NULL; *TableLength = 0; return (AE_ERROR); }
static ACPI_STATUS AcpiUtReadTable ( FILE *fp, ACPI_TABLE_HEADER **Table, UINT32 *TableLength) { ACPI_TABLE_HEADER TableHeader; UINT32 Actual; ACPI_STATUS Status; UINT32 FileSize; BOOLEAN StandardHeader = TRUE; INT32 Count; /* Get the file size */ FileSize = CmGetFileSize (fp); if (FileSize == ACPI_UINT32_MAX) { return (AE_ERROR); } if (FileSize < 4) { return (AE_BAD_HEADER); } /* Read the signature */ fseek (fp, 0, SEEK_SET); Count = fread (&TableHeader, 1, sizeof (ACPI_TABLE_HEADER), fp); if (Count != sizeof (ACPI_TABLE_HEADER)) { AcpiOsPrintf ("Could not read the table header\n"); return (AE_BAD_HEADER); } /* The RSDP table does not have standard ACPI header */ if (ACPI_VALIDATE_RSDP_SIG (TableHeader.Signature)) { *TableLength = FileSize; StandardHeader = FALSE; } else { #if 0 /* Validate the table header/length */ Status = AcpiTbValidateTableHeader (&TableHeader); if (ACPI_FAILURE (Status)) { AcpiOsPrintf ("Table header is invalid!\n"); return (Status); } #endif /* File size must be at least as long as the Header-specified length */ if (TableHeader.Length > FileSize) { AcpiOsPrintf ( "TableHeader length [0x%X] greater than the input file size [0x%X]\n", TableHeader.Length, FileSize); #ifdef ACPI_ASL_COMPILER AcpiOsPrintf ("File is corrupt or is ASCII text -- " "it must be a binary file\n"); #endif return (AE_BAD_HEADER); } #ifdef ACPI_OBSOLETE_CODE /* We only support a limited number of table types */ if (!ACPI_COMPARE_NAME ((char *) TableHeader.Signature, ACPI_SIG_DSDT) && !ACPI_COMPARE_NAME ((char *) TableHeader.Signature, ACPI_SIG_PSDT) && !ACPI_COMPARE_NAME ((char *) TableHeader.Signature, ACPI_SIG_SSDT)) { AcpiOsPrintf ("Table signature [%4.4s] is invalid or not supported\n", (char *) TableHeader.Signature); ACPI_DUMP_BUFFER (&TableHeader, sizeof (ACPI_TABLE_HEADER)); return (AE_ERROR); } #endif *TableLength = TableHeader.Length; } /* Allocate a buffer for the table */ *Table = AcpiOsAllocate ((size_t) FileSize); if (!*Table) { AcpiOsPrintf ( "Could not allocate memory for ACPI table %4.4s (size=0x%X)\n", TableHeader.Signature, *TableLength); return (AE_NO_MEMORY); } /* Get the rest of the table */ fseek (fp, 0, SEEK_SET); Actual = fread (*Table, 1, (size_t) FileSize, fp); if (Actual == FileSize) { if (StandardHeader) { /* Now validate the checksum */ Status = AcpiTbVerifyChecksum ((void *) *Table, ACPI_CAST_PTR (ACPI_TABLE_HEADER, *Table)->Length); if (Status == AE_BAD_CHECKSUM) { Status = AcpiUtCheckTextModeCorruption ((UINT8 *) *Table, FileSize, (*Table)->Length); return (Status); } } return (AE_OK); } if (Actual > 0) { AcpiOsPrintf ("Warning - reading table, asked for %X got %X\n", FileSize, Actual); return (AE_OK); } AcpiOsPrintf ("Error - could not read the table file\n"); AcpiOsFree (*Table); *Table = NULL; *TableLength = 0; return (AE_ERROR); }
static ACPI_STATUS AcpiDbReadTable ( FILE *fp, ACPI_TABLE_HEADER **Table, UINT32 *TableLength) { ACPI_TABLE_HEADER TableHeader; UINT32 Actual; ACPI_STATUS Status; UINT32 FileSize; BOOLEAN StandardHeader = TRUE; /* Get the file size */ fseek (fp, 0, SEEK_END); FileSize = (UINT32) ftell (fp); fseek (fp, 0, SEEK_SET); if (FileSize < 4) { return (AE_BAD_HEADER); } /* Read the signature */ if (fread (&TableHeader, 1, 4, fp) != 4) { AcpiOsPrintf ("Could not read the table signature\n"); return (AE_BAD_HEADER); } fseek (fp, 0, SEEK_SET); /* The RSDT, FACS and S3PT tables do not have standard ACPI headers */ if (ACPI_COMPARE_NAME (TableHeader.Signature, "RSD ") || ACPI_COMPARE_NAME (TableHeader.Signature, "FACS") || ACPI_COMPARE_NAME (TableHeader.Signature, "S3PT")) { *TableLength = FileSize; StandardHeader = FALSE; } else { /* Read the table header */ if (fread (&TableHeader, 1, sizeof (TableHeader), fp) != sizeof (ACPI_TABLE_HEADER)) { AcpiOsPrintf ("Could not read the table header\n"); return (AE_BAD_HEADER); } #if 0 /* Validate the table header/length */ Status = AcpiTbValidateTableHeader (&TableHeader); if (ACPI_FAILURE (Status)) { AcpiOsPrintf ("Table header is invalid!\n"); return (Status); } #endif /* File size must be at least as long as the Header-specified length */ if (TableHeader.Length > FileSize) { AcpiOsPrintf ( "TableHeader length [0x%X] greater than the input file size [0x%X]\n", TableHeader.Length, FileSize); return (AE_BAD_HEADER); } #ifdef ACPI_OBSOLETE_CODE /* We only support a limited number of table types */ if (ACPI_STRNCMP ((char *) TableHeader.Signature, DSDT_SIG, 4) && ACPI_STRNCMP ((char *) TableHeader.Signature, PSDT_SIG, 4) && ACPI_STRNCMP ((char *) TableHeader.Signature, SSDT_SIG, 4)) { AcpiOsPrintf ("Table signature [%4.4s] is invalid or not supported\n", (char *) TableHeader.Signature); ACPI_DUMP_BUFFER (&TableHeader, sizeof (ACPI_TABLE_HEADER)); return (AE_ERROR); } #endif *TableLength = TableHeader.Length; } /* Allocate a buffer for the table */ *Table = AcpiOsAllocate ((size_t) FileSize); if (!*Table) { AcpiOsPrintf ( "Could not allocate memory for ACPI table %4.4s (size=0x%X)\n", TableHeader.Signature, *TableLength); return (AE_NO_MEMORY); } /* Get the rest of the table */ fseek (fp, 0, SEEK_SET); Actual = fread (*Table, 1, (size_t) FileSize, fp); if (Actual == FileSize) { if (StandardHeader) { /* Now validate the checksum */ Status = AcpiTbVerifyChecksum ((void *) *Table, ACPI_CAST_PTR (ACPI_TABLE_HEADER, *Table)->Length); if (Status == AE_BAD_CHECKSUM) { Status = AcpiDbCheckTextModeCorruption ((UINT8 *) *Table, FileSize, (*Table)->Length); return (Status); } } return (AE_OK); } if (Actual > 0) { AcpiOsPrintf ("Warning - reading table, asked for %X got %X\n", FileSize, Actual); return (AE_OK); } AcpiOsPrintf ("Error - could not read the table file\n"); AcpiOsFree (*Table); *Table = NULL; *TableLength = 0; return (AE_ERROR); }