--- /dev/null
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation \r
+All rights reserved. This program and the accompanying materials \r
+are licensed and made available under the terms and conditions of the BSD License \r
+which accompanies this distribution. The full text of the license may be found at \r
+http://opensource.org/licenses/bsd-license.php \r
+ \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
+\r
+Module Name:\r
+\r
+ BaseUefiTianoCustomDecompressLib.c\r
+\r
+Abstract:\r
+\r
+ UEFI and Custom Decompress Library \r
+\r
+--*/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "BaseUefiTianoCustomDecompressLibInternals.h"\r
+\r
+VOID\r
+FillBuf (\r
+ IN SCRATCH_DATA *Sd,\r
+ IN UINT16 NumOfBits\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Shift mBitBuf NumOfBits left. Read in NumOfBits of bits from source.\r
+\r
+Arguments:\r
+\r
+ Sd - The global scratch data\r
+ NumOfBits - The number of bits to shift and read.\r
+\r
+Returns: (VOID)\r
+\r
+--*/\r
+{\r
+ Sd->mBitBuf = (UINT32) (Sd->mBitBuf << NumOfBits);\r
+\r
+ while (NumOfBits > Sd->mBitCount) {\r
+\r
+ Sd->mBitBuf |= (UINT32) (Sd->mSubBitBuf << (NumOfBits = (UINT16) (NumOfBits - Sd->mBitCount)));\r
+\r
+ if (Sd->mCompSize > 0) {\r
+ //\r
+ // Get 1 byte into SubBitBuf\r
+ //\r
+ Sd->mCompSize--;\r
+ Sd->mSubBitBuf = 0;\r
+ Sd->mSubBitBuf = Sd->mSrcBase[Sd->mInBuf++];\r
+ Sd->mBitCount = 8;\r
+\r
+ } else {\r
+ //\r
+ // No more bits from the source, just pad zero bit.\r
+ //\r
+ Sd->mSubBitBuf = 0;\r
+ Sd->mBitCount = 8;\r
+\r
+ }\r
+ }\r
+\r
+ Sd->mBitCount = (UINT16) (Sd->mBitCount - NumOfBits);\r
+ Sd->mBitBuf |= Sd->mSubBitBuf >> Sd->mBitCount;\r
+}\r
+\r
+UINT32\r
+GetBits (\r
+ IN SCRATCH_DATA *Sd,\r
+ IN UINT16 NumOfBits\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Get NumOfBits of bits out from mBitBuf. Fill mBitBuf with subsequent \r
+ NumOfBits of bits from source. Returns NumOfBits of bits that are \r
+ popped out.\r
+\r
+Arguments:\r
+\r
+ Sd - The global scratch data.\r
+ NumOfBits - The number of bits to pop and read.\r
+\r
+Returns:\r
+\r
+ The bits that are popped out.\r
+\r
+--*/\r
+{\r
+ UINT32 OutBits;\r
+\r
+ OutBits = (UINT32) (Sd->mBitBuf >> (BITBUFSIZ - NumOfBits));\r
+\r
+ FillBuf (Sd, NumOfBits);\r
+\r
+ return OutBits;\r
+}\r
+\r
+UINT16\r
+MakeTable (\r
+ IN SCRATCH_DATA *Sd,\r
+ IN UINT16 NumOfChar,\r
+ IN UINT8 *BitLen,\r
+ IN UINT16 TableBits,\r
+ OUT UINT16 *Table\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Creates Huffman Code mapping table according to code length array.\r
+\r
+Arguments:\r
+\r
+ Sd - The global scratch data\r
+ NumOfChar - Number of symbols in the symbol set\r
+ BitLen - Code length array\r
+ TableBits - The width of the mapping table\r
+ Table - The table\r
+ \r
+Returns:\r
+ \r
+ 0 - OK.\r
+ BAD_TABLE - The table is corrupted.\r
+\r
+--*/\r
+{\r
+ UINT16 Count[17];\r
+ UINT16 Weight[17];\r
+ UINT16 Start[18];\r
+ UINT16 *Pointer;\r
+ UINT16 Index3;\r
+ volatile UINT16 Index;\r
+ UINT16 Len;\r
+ UINT16 Char;\r
+ UINT16 JuBits;\r
+ UINT16 Avail;\r
+ UINT16 NextCode;\r
+ UINT16 Mask;\r
+ UINT16 WordOfStart;\r
+ UINT16 WordOfCount;\r
+\r
+ for (Index = 1; Index <= 16; Index++) {\r
+ Count[Index] = 0;\r
+ }\r
+\r
+ for (Index = 0; Index < NumOfChar; Index++) {\r
+ Count[BitLen[Index]]++;\r
+ }\r
+\r
+ Start[1] = 0;\r
+\r
+ for (Index = 1; Index <= 16; Index++) {\r
+ WordOfStart = Start[Index];\r
+ WordOfCount = Count[Index];\r
+ Start[Index + 1] = (UINT16) (WordOfStart + (WordOfCount << (16 - Index)));\r
+ }\r
+\r
+ if (Start[17] != 0) {\r
+ /*(1U << 16)*/\r
+ return (UINT16) BAD_TABLE;\r
+ }\r
+\r
+ JuBits = (UINT16) (16 - TableBits);\r
+\r
+ for (Index = 1; Index <= TableBits; Index++) {\r
+ Start[Index] >>= JuBits;\r
+ Weight[Index] = (UINT16) (1U << (TableBits - Index));\r
+ }\r
+\r
+ while (Index <= 16) {\r
+ Weight[Index] = (UINT16) (1U << (16 - Index));\r
+ Index++;\r
+ }\r
+\r
+ Index = (UINT16) (Start[TableBits + 1] >> JuBits);\r
+\r
+ if (Index != 0) {\r
+ Index3 = (UINT16) (1U << TableBits);\r
+ while (Index != Index3) {\r
+ Table[Index++] = 0;\r
+ }\r
+ }\r
+\r
+ Avail = NumOfChar;\r
+ Mask = (UINT16) (1U << (15 - TableBits));\r
+\r
+ for (Char = 0; Char < NumOfChar; Char++) {\r
+\r
+ Len = BitLen[Char];\r
+ if (Len == 0) {\r
+ continue;\r
+ }\r
+\r
+ NextCode = (UINT16) (Start[Len] + Weight[Len]);\r
+\r
+ if (Len <= TableBits) {\r
+\r
+ for (Index = Start[Len]; Index < NextCode; Index++) {\r
+ Table[Index] = Char;\r
+ }\r
+\r
+ } else {\r
+\r
+ Index3 = Start[Len];\r
+ Pointer = &Table[Index3 >> JuBits];\r
+ Index = (UINT16) (Len - TableBits);\r
+\r
+ while (Index != 0) {\r
+ if (*Pointer == 0) {\r
+ Sd->mRight[Avail] = Sd->mLeft[Avail] = 0;\r
+ *Pointer = Avail++;\r
+ }\r
+\r
+ if (Index3 & Mask) {\r
+ Pointer = &Sd->mRight[*Pointer];\r
+ } else {\r
+ Pointer = &Sd->mLeft[*Pointer];\r
+ }\r
+\r
+ Index3 <<= 1;\r
+ Index--;\r
+ }\r
+\r
+ *Pointer = Char;\r
+\r
+ }\r
+\r
+ Start[Len] = NextCode;\r
+ }\r
+ //\r
+ // Succeeds\r
+ //\r
+ return 0;\r
+}\r
+\r
+UINT32\r
+DecodeP (\r
+ IN SCRATCH_DATA *Sd\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Decodes a position value.\r
+\r
+Arguments:\r
+\r
+ Sd - the global scratch data\r
+\r
+Returns:\r
+\r
+ The position value decoded.\r
+\r
+--*/\r
+{\r
+ UINT16 Val;\r
+ UINT32 Mask;\r
+ UINT32 Pos;\r
+\r
+ Val = Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)];\r
+\r
+ if (Val >= MAXNP) {\r
+ Mask = 1U << (BITBUFSIZ - 1 - 8);\r
+\r
+ do {\r
+\r
+ if (Sd->mBitBuf & Mask) {\r
+ Val = Sd->mRight[Val];\r
+ } else {\r
+ Val = Sd->mLeft[Val];\r
+ }\r
+\r
+ Mask >>= 1;\r
+ } while (Val >= MAXNP);\r
+ }\r
+ //\r
+ // Advance what we have read\r
+ //\r
+ FillBuf (Sd, Sd->mPTLen[Val]);\r
+\r
+ Pos = Val;\r
+ if (Val > 1) {\r
+ Pos = (UINT32) ((1U << (Val - 1)) + GetBits (Sd, (UINT16) (Val - 1)));\r
+ }\r
+\r
+ return Pos;\r
+}\r
+\r
+UINT16\r
+ReadPTLen (\r
+ IN SCRATCH_DATA *Sd,\r
+ IN UINT16 nn,\r
+ IN UINT16 nbit,\r
+ IN UINT16 Special\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Reads code lengths for the Extra Set or the Position Set\r
+\r
+Arguments:\r
+\r
+ Sd - The global scratch data\r
+ nn - Number of symbols\r
+ nbit - Number of bits needed to represent nn\r
+ Special - The special symbol that needs to be taken care of \r
+\r
+Returns:\r
+\r
+ 0 - OK.\r
+ BAD_TABLE - Table is corrupted.\r
+\r
+--*/\r
+{\r
+ UINT16 Number;\r
+ UINT16 CharC;\r
+ volatile UINT16 Index;\r
+ UINT32 Mask;\r
+\r
+ Number = (UINT16) GetBits (Sd, nbit);\r
+\r
+ if (Number == 0) {\r
+ CharC = (UINT16) GetBits (Sd, nbit);\r
+\r
+ for (Index = 0; Index < 256; Index++) {\r
+ Sd->mPTTable[Index] = CharC;\r
+ }\r
+\r
+ for (Index = 0; Index < nn; Index++) {\r
+ Sd->mPTLen[Index] = 0;\r
+ }\r
+\r
+ return 0;\r
+ }\r
+\r
+ Index = 0;\r
+\r
+ while (Index < Number) {\r
+\r
+ CharC = (UINT16) (Sd->mBitBuf >> (BITBUFSIZ - 3));\r
+\r
+ if (CharC == 7) {\r
+ Mask = 1U << (BITBUFSIZ - 1 - 3);\r
+ while (Mask & Sd->mBitBuf) {\r
+ Mask >>= 1;\r
+ CharC += 1;\r
+ }\r
+ }\r
+\r
+ FillBuf (Sd, (UINT16) ((CharC < 7) ? 3 : CharC - 3));\r
+\r
+ Sd->mPTLen[Index++] = (UINT8) CharC;\r
+\r
+ if (Index == Special) {\r
+ CharC = (UINT16) GetBits (Sd, 2);\r
+ while ((INT16) (--CharC) >= 0) {\r
+ Sd->mPTLen[Index++] = 0;\r
+ }\r
+ }\r
+ }\r
+\r
+ while (Index < nn) {\r
+ Sd->mPTLen[Index++] = 0;\r
+ }\r
+\r
+ return MakeTable (Sd, nn, Sd->mPTLen, 8, Sd->mPTTable);\r
+}\r
+\r
+VOID\r
+ReadCLen (\r
+ SCRATCH_DATA *Sd\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Reads code lengths for Char&Len Set.\r
+\r
+Arguments:\r
+\r
+ Sd - the global scratch data\r
+\r
+Returns: (VOID)\r
+\r
+--*/\r
+{\r
+ UINT16 Number;\r
+ UINT16 CharC;\r
+ volatile UINT16 Index;\r
+ UINT32 Mask;\r
+\r
+ Number = (UINT16) GetBits (Sd, CBIT);\r
+\r
+ if (Number == 0) {\r
+ CharC = (UINT16) GetBits (Sd, CBIT);\r
+\r
+ for (Index = 0; Index < NC; Index++) {\r
+ Sd->mCLen[Index] = 0;\r
+ }\r
+\r
+ for (Index = 0; Index < 4096; Index++) {\r
+ Sd->mCTable[Index] = CharC;\r
+ }\r
+\r
+ return ;\r
+ }\r
+\r
+ Index = 0;\r
+ while (Index < Number) {\r
+\r
+ CharC = Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)];\r
+ if (CharC >= NT) {\r
+ Mask = 1U << (BITBUFSIZ - 1 - 8);\r
+\r
+ do {\r
+\r
+ if (Mask & Sd->mBitBuf) {\r
+ CharC = Sd->mRight[CharC];\r
+ } else {\r
+ CharC = Sd->mLeft[CharC];\r
+ }\r
+\r
+ Mask >>= 1;\r
+\r
+ } while (CharC >= NT);\r
+ }\r
+ //\r
+ // Advance what we have read\r
+ //\r
+ FillBuf (Sd, Sd->mPTLen[CharC]);\r
+\r
+ if (CharC <= 2) {\r
+\r
+ if (CharC == 0) {\r
+ CharC = 1;\r
+ } else if (CharC == 1) {\r
+ CharC = (UINT16) (GetBits (Sd, 4) + 3);\r
+ } else if (CharC == 2) {\r
+ CharC = (UINT16) (GetBits (Sd, CBIT) + 20);\r
+ }\r
+\r
+ while ((INT16) (--CharC) >= 0) {\r
+ Sd->mCLen[Index++] = 0;\r
+ }\r
+\r
+ } else {\r
+\r
+ Sd->mCLen[Index++] = (UINT8) (CharC - 2);\r
+\r
+ }\r
+ }\r
+\r
+ while (Index < NC) {\r
+ Sd->mCLen[Index++] = 0;\r
+ }\r
+\r
+ MakeTable (Sd, NC, Sd->mCLen, 12, Sd->mCTable);\r
+\r
+ return ;\r
+}\r
+\r
+UINT16\r
+DecodeC (\r
+ SCRATCH_DATA *Sd\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Decode a character/length value.\r
+\r
+Arguments:\r
+\r
+ Sd - The global scratch data.\r
+\r
+Returns:\r
+\r
+ The value decoded.\r
+\r
+--*/\r
+{\r
+ UINT16 Index2;\r
+ UINT32 Mask;\r
+\r
+ if (Sd->mBlockSize == 0) {\r
+ //\r
+ // Starting a new block\r
+ //\r
+ Sd->mBlockSize = (UINT16) GetBits (Sd, 16);\r
+ Sd->mBadTableFlag = ReadPTLen (Sd, NT, TBIT, 3);\r
+ if (Sd->mBadTableFlag != 0) {\r
+ return 0;\r
+ }\r
+\r
+ ReadCLen (Sd);\r
+\r
+ Sd->mBadTableFlag = ReadPTLen (Sd, MAXNP, Sd->mPBit, (UINT16) (-1));\r
+ if (Sd->mBadTableFlag != 0) {\r
+ return 0;\r
+ }\r
+ }\r
+\r
+ Sd->mBlockSize--;\r
+ Index2 = Sd->mCTable[Sd->mBitBuf >> (BITBUFSIZ - 12)];\r
+\r
+ if (Index2 >= NC) {\r
+ Mask = 1U << (BITBUFSIZ - 1 - 12);\r
+\r
+ do {\r
+ if (Sd->mBitBuf & Mask) {\r
+ Index2 = Sd->mRight[Index2];\r
+ } else {\r
+ Index2 = Sd->mLeft[Index2];\r
+ }\r
+\r
+ Mask >>= 1;\r
+ } while (Index2 >= NC);\r
+ }\r
+ //\r
+ // Advance what we have read\r
+ //\r
+ FillBuf (Sd, Sd->mCLen[Index2]);\r
+\r
+ return Index2;\r
+}\r
+\r
+VOID\r
+Decode (\r
+ SCRATCH_DATA *Sd\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Decode the source data and put the resulting data into the destination buffer.\r
+\r
+Arguments:\r
+\r
+ Sd - The global scratch data\r
+\r
+Returns: (VOID)\r
+\r
+ --*/\r
+{\r
+ UINT16 BytesRemain;\r
+ UINT32 DataIdx;\r
+ UINT16 CharC;\r
+\r
+ BytesRemain = (UINT16) (-1);\r
+\r
+ DataIdx = 0;\r
+\r
+ for (;;) {\r
+ CharC = DecodeC (Sd);\r
+ if (Sd->mBadTableFlag != 0) {\r
+ goto Done ;\r
+ }\r
+\r
+ if (CharC < 256) {\r
+ //\r
+ // Process an Original character\r
+ //\r
+ if (Sd->mOutBuf >= Sd->mOrigSize) {\r
+ goto Done ;\r
+ } else {\r
+ Sd->mDstBase[Sd->mOutBuf++] = (UINT8) CharC;\r
+ }\r
+\r
+ } else {\r
+ //\r
+ // Process a Pointer\r
+ //\r
+ CharC = (UINT16) (CharC - (UINT8_MAX + 1 - THRESHOLD));\r
+\r
+ BytesRemain = CharC;\r
+\r
+ DataIdx = Sd->mOutBuf - DecodeP (Sd) - 1;\r
+\r
+ BytesRemain--;\r
+ while ((INT16) (BytesRemain) >= 0) {\r
+ Sd->mDstBase[Sd->mOutBuf++] = Sd->mDstBase[DataIdx++];\r
+ if (Sd->mOutBuf >= Sd->mOrigSize) {\r
+ goto Done ;\r
+ }\r
+\r
+ BytesRemain--;\r
+ }\r
+ }\r
+ }\r
+\r
+Done:\r
+ return ;\r
+}\r
+\r
+RETURN_STATUS\r
+EFIAPI\r
+UefiDecompressGetInfo (\r
+ IN CONST VOID *Source,\r
+ IN UINT32 SourceSize,\r
+ OUT UINT32 *DestinationSize,\r
+ OUT UINT32 *ScratchSize\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ The internal implementation of *_DECOMPRESS_PROTOCOL.GetInfo().\r
+\r
+Arguments:\r
+\r
+ Source - The source buffer containing the compressed data.\r
+ SourceSize - The size of source buffer\r
+ DestinationSize - The size of destination buffer.\r
+ ScratchSize - The size of scratch buffer.\r
+\r
+Returns:\r
+\r
+ RETURN_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved.\r
+ RETURN_INVALID_PARAMETER - The source data is corrupted\r
+\r
+--*/\r
+{\r
+ UINT32 CompressedSize;\r
+\r
+ ASSERT (Source != NULL);\r
+ ASSERT (DestinationSize != NULL);\r
+ ASSERT (ScratchSize != NULL);\r
+\r
+ *ScratchSize = sizeof (SCRATCH_DATA);\r
+\r
+ if (SourceSize < 8) {\r
+ return RETURN_INVALID_PARAMETER;\r
+ }\r
+\r
+ CopyMem (&CompressedSize, Source, sizeof (UINT32));\r
+ CopyMem (DestinationSize, (VOID *)((UINT8 *)Source + 4), sizeof (UINT32));\r
+\r
+ if (SourceSize < (CompressedSize + 8)) {\r
+ return RETURN_INVALID_PARAMETER;\r
+ }\r
+\r
+ return RETURN_SUCCESS;\r
+}\r
+\r
+RETURN_STATUS\r
+EFIAPI\r
+UefiTianoDecompress (\r
+ IN CONST VOID *Source,\r
+ IN OUT VOID *Destination,\r
+ IN OUT VOID *Scratch,\r
+ IN UINT32 Version\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ The internal implementation of *_DECOMPRESS_PROTOCOL.Decompress().\r
+\r
+Arguments:\r
+\r
+ Source - The source buffer containing the compressed data.\r
+ Destination - The destination buffer to store the decompressed data\r
+ Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.\r
+ Version - 1 for UEFI Decompress algoruthm, 2 for Tiano Decompess algorithm\r
+\r
+Returns:\r
+\r
+ RETURN_SUCCESS - Decompression is successfull\r
+ RETURN_INVALID_PARAMETER - The source data is corrupted\r
+\r
+--*/\r
+{\r
+ volatile UINT32 Index;\r
+ UINT32 CompSize;\r
+ UINT32 OrigSize;\r
+ SCRATCH_DATA *Sd;\r
+ CONST UINT8 *Src;\r
+ UINT8 *Dst;\r
+\r
+ ASSERT (Source != NULL);\r
+ ASSERT (Destination != NULL);\r
+ ASSERT (Scratch != NULL);\r
+\r
+ Src = Source;\r
+ Dst = Destination;\r
+\r
+ Sd = (SCRATCH_DATA *) Scratch;\r
+\r
+ CompSize = Src[0] + (Src[1] << 8) + (Src[2] << 16) + (Src[3] << 24);\r
+ OrigSize = Src[4] + (Src[5] << 8) + (Src[6] << 16) + (Src[7] << 24);\r
+\r
+ //\r
+ // If compressed file size is 0, return\r
+ //\r
+ if (OrigSize == 0) {\r
+ return RETURN_SUCCESS;\r
+ }\r
+\r
+ Src = Src + 8;\r
+\r
+ for (Index = 0; Index < sizeof (SCRATCH_DATA); Index++) {\r
+ ((UINT8 *) Sd)[Index] = 0;\r
+ }\r
+ //\r
+ // The length of the field 'Position Set Code Length Array Size' in Block Header.\r
+ // For EFI 1.1 de/compression algorithm(Version 1), mPBit = 4\r
+ // For Tiano de/compression algorithm(Version 2), mPBit = 5\r
+ //\r
+ switch (Version) {\r
+ case 1 :\r
+ Sd->mPBit = 4;\r
+ break;\r
+ case 2 :\r
+ Sd->mPBit = 5;\r
+ break;\r
+ default:\r
+ ASSERT (FALSE);\r
+ }\r
+ Sd->mSrcBase = (UINT8 *)Src;\r
+ Sd->mDstBase = Dst;\r
+ Sd->mCompSize = CompSize;\r
+ Sd->mOrigSize = OrigSize;\r
+\r
+ //\r
+ // Fill the first BITBUFSIZ bits\r
+ //\r
+ FillBuf (Sd, BITBUFSIZ);\r
+\r
+ //\r
+ // Decompress it\r
+ //\r
+ Decode (Sd);\r
+\r
+ if (Sd->mBadTableFlag != 0) {\r
+ //\r
+ // Something wrong with the source\r
+ //\r
+ return RETURN_INVALID_PARAMETER;\r
+ }\r
+\r
+ return RETURN_SUCCESS;\r
+}\r
+\r
+RETURN_STATUS\r
+EFIAPI\r
+UefiDecompress (\r
+ IN CONST VOID *Source,\r
+ IN OUT VOID *Destination,\r
+ IN OUT VOID *Scratch\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ The internal implementation of *_DECOMPRESS_PROTOCOL.Decompress().\r
+\r
+Arguments:\r
+\r
+ Source - The source buffer containing the compressed data.\r
+ Destination - The destination buffer to store the decompressed data\r
+ Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.\r
+\r
+Returns:\r
+\r
+ RETURN_SUCCESS - Decompression is successfull\r
+ RETURN_INVALID_PARAMETER - The source data is corrupted\r
+\r
+--*/\r
+{\r
+ return UefiTianoDecompress (Source, Destination, Scratch, 1);\r
+}\r
+\r
+RETURN_STATUS\r
+EFIAPI\r
+CustomDecompressGetInfo (\r
+ IN CONST VOID *Source,\r
+ IN UINT32 SourceSize,\r
+ OUT UINT32 *DestinationSize,\r
+ OUT UINT32 *ScratchSize\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ The internal implementation of *_DECOMPRESS_PROTOCOL.GetInfo().\r
+\r
+Arguments:\r
+\r
+ Source - The source buffer containing the compressed data.\r
+ SourceSize - The size of source buffer\r
+ DestinationSize - The size of destination buffer.\r
+ ScratchSize - The size of scratch buffer.\r
+\r
+Returns:\r
+\r
+ RETURN_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved.\r
+ RETURN_INVALID_PARAMETER - The source data is corrupted\r
+\r
+--*/\r
+{\r
+ return UefiDecompressGetInfo (Source, SourceSize, DestinationSize, ScratchSize);\r
+}\r
+\r
+RETURN_STATUS\r
+EFIAPI\r
+CustomDecompress (\r
+ IN CONST VOID *Source,\r
+ IN OUT VOID *Destination,\r
+ IN OUT VOID *Scratch\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ The internal implementation of *_DECOMPRESS_PROTOCOL.Decompress().\r
+\r
+Arguments:\r
+\r
+ Source - The source buffer containing the compressed data.\r
+ Destination - The destination buffer to store the decompressed data\r
+ Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.\r
+\r
+Returns:\r
+\r
+ RETURN_SUCCESS - Decompression is successfull\r
+ RETURN_INVALID_PARAMETER - The source data is corrupted\r
+\r
+--*/\r
+{\r
+ return UefiTianoDecompress (Source, Destination, Scratch, 2);\r
+}\r
--- /dev/null
+#/** @file\r
+# Uefi Tiano Decomression Library\r
+#\r
+# Uefi Decompression library instance\r
+# Copyright (c) 2006, Intel Corporation.\r
+#\r
+# All rights reserved. This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution. The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+ INF_VERSION = 0x00010005\r
+ BASE_NAME = BaseUefiTianoDecompressLib\r
+ FILE_GUID = d774c4d9-c121-4da3-a5e2-0f317e3c630c\r
+ MODULE_TYPE = BASE\r
+ VERSION_STRING = 1.0\r
+ LIBRARY_CLASS = CustomDecompressLib UefiDecompressLib \r
+ EDK_RELEASE_VERSION = 0x00020000\r
+ EFI_SPECIFICATION_VERSION = 0x00020000\r
+\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC\r
+#\r
+\r
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+ BaseUefiTianoCustomDecompressLibInternals.h\r
+ BaseUefiTianoCustomDecompressLib.c\r
+ CommonHeader.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Includes Section - list of Include locations that are required for\r
+# this module.\r
+#\r
+################################################################################\r
+\r
+[Includes]\r
+ $(WORKSPACE)/MdePkg/Include\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+# this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+ MdePkg/MdePkg.dec\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+# this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+ BaseMemoryLib\r
+ DebugLib\r
+\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+ <MsaHeader>\r
+ <ModuleName>BaseUefiTianoCustomDecompressLib</ModuleName>\r
+ <ModuleType>BASE</ModuleType>\r
+ <GuidValue>d774c4d9-c121-4da3-a5e2-0f317e3c630c</GuidValue>\r
+ <Version>1.0</Version>\r
+ <Abstract>Uefi Tiano Decomression Library</Abstract>\r
+ <Description>Uefi Decompression library instance</Description>\r
+ <Copyright>Copyright (c) 2006, Intel Corporation.</Copyright>\r
+ <License>All rights reserved. This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.</License>\r
+ <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052</Specification>\r
+ </MsaHeader>\r
+ <ModuleDefinitions>\r
+ <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+ <BinaryModule>false</BinaryModule>\r
+ <OutputFileBasename>BaseUefiTianoDecompressLib</OutputFileBasename>\r
+ </ModuleDefinitions>\r
+ <LibraryClassDefinitions>\r
+ <LibraryClass Usage="ALWAYS_PRODUCED">\r
+ <Keyword>UefiDecompressLib</Keyword>\r
+ </LibraryClass>\r
+ <LibraryClass Usage="ALWAYS_PRODUCED">\r
+ <Keyword>CustomDecompressLib</Keyword>\r
+ </LibraryClass>\r
+ <LibraryClass Usage="ALWAYS_CONSUMED">\r
+ <Keyword>DebugLib</Keyword>\r
+ </LibraryClass>\r
+ <LibraryClass Usage="ALWAYS_CONSUMED">\r
+ <Keyword>BaseMemoryLib</Keyword>\r
+ </LibraryClass>\r
+ </LibraryClassDefinitions>\r
+ <SourceFiles>\r
+ <Filename>BaseUefiTianoCustomDecompressLib.c</Filename>\r
+ <Filename>BaseUefiTianoCustomDecompressLibInternals.h</Filename>\r
+ </SourceFiles>\r
+ <PackageDependencies>\r
+ <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+ <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+ </PackageDependencies>\r
+ <Externs>\r
+ <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+ <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+ </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file
--- /dev/null
+/** @file\r
+ Internal include file for Base UEFI Decompress Libary.\r
+\r
+ Copyright (c) 2006, Intel Corporation\r
+ All rights reserved. This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+ Module Name: BaseUefiCustomDecompressLibInternals.h\r
+\r
+**/\r
+\r
+#ifndef __BASE_UEFI_TIANO_CUSTOM_DECOMPRESS_LIB_INTERNALS_H__\r
+#define __BASE_UEFI_TIANO_CUSTOM_DECOMPRESS_LIB_INTERNALS_H__\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+//\r
+// Decompression algorithm begins here\r
+//\r
+#define BITBUFSIZ 32\r
+#define MAXMATCH 256\r
+#define THRESHOLD 3\r
+#define CODE_BIT 16\r
+#define BAD_TABLE - 1\r
+\r
+//\r
+// C: Char&Len Set; P: Position Set; T: exTra Set\r
+//\r
+#define NC (0xff + MAXMATCH + 2 - THRESHOLD)\r
+#define CBIT 9\r
+#define MAXPBIT 5\r
+#define TBIT 5\r
+#define MAXNP ((1U << MAXPBIT) - 1)\r
+#define NT (CODE_BIT + 3)\r
+#if NT > MAXNP\r
+#define NPT NT\r
+#else\r
+#define NPT MAXNP\r
+#endif\r
+\r
+typedef struct {\r
+ UINT8 *mSrcBase; // Starting address of compressed data\r
+ UINT8 *mDstBase; // Starting address of decompressed data\r
+ UINT32 mOutBuf;\r
+ UINT32 mInBuf;\r
+\r
+ UINT16 mBitCount;\r
+ UINT32 mBitBuf;\r
+ UINT32 mSubBitBuf;\r
+ UINT16 mBlockSize;\r
+ UINT32 mCompSize;\r
+ UINT32 mOrigSize;\r
+\r
+ UINT16 mBadTableFlag;\r
+\r
+ UINT16 mLeft[2 * NC - 1];\r
+ UINT16 mRight[2 * NC - 1];\r
+ UINT8 mCLen[NC];\r
+ UINT8 mPTLen[NPT];\r
+ UINT16 mCTable[4096];\r
+ UINT16 mPTTable[256];\r
+\r
+ //\r
+ // The length of the field 'Position Set Code Length Array Size' in Block Header.\r
+ // For EFI 1.1 de/compression algorithm, mPBit = 4\r
+ // For Tiano de/compression algorithm, mPBit = 5\r
+ //\r
+ UINT8 mPBit;\r
+} SCRATCH_DATA;\r
+\r
+/**\r
+ Read NumOfBit of bits from source into mBitBuf\r
+\r
+ Shift mBitBuf NumOfBits left. Read in NumOfBits of bits from source.\r
+\r
+ @param Sd The global scratch data\r
+ @param NumOfBits The number of bits to shift and read.\r
+\r
+**/\r
+VOID\r
+FillBuf (\r
+ IN SCRATCH_DATA *Sd,\r
+ IN UINT16 NumOfBits\r
+ );\r
+\r
+/**\r
+ Get NumOfBits of bits out from mBitBuf\r
+\r
+ Get NumOfBits of bits out from mBitBuf. Fill mBitBuf with subsequent \r
+ NumOfBits of bits from source. Returns NumOfBits of bits that are \r
+ popped out.\r
+\r
+ @param Sd The global scratch data.\r
+ @param NumOfBits The number of bits to pop and read.\r
+\r
+ @return The bits that are popped out.\r
+\r
+**/\r
+UINT32\r
+GetBits (\r
+ IN SCRATCH_DATA *Sd,\r
+ IN UINT16 NumOfBits\r
+ );\r
+\r
+/**\r
+ Creates Huffman Code mapping table according to code length array.\r
+\r
+ Creates Huffman Code mapping table for Extra Set, Char&Len Set \r
+ and Position Set according to code length array.\r
+\r
+ @param Sd The global scratch data\r
+ @param NumOfChar Number of symbols in the symbol set\r
+ @param BitLen Code length array\r
+ @param TableBits The width of the mapping table\r
+ @param Table The table\r
+\r
+ @retval 0 OK.\r
+ @retval BAD_TABLE The table is corrupted.\r
+\r
+**/\r
+UINT16\r
+MakeTable (\r
+ IN SCRATCH_DATA *Sd,\r
+ IN UINT16 NumOfChar,\r
+ IN UINT8 *BitLen,\r
+ IN UINT16 TableBits,\r
+ OUT UINT16 *Table\r
+ );\r
+\r
+/**\r
+ Decodes a position value.\r
+\r
+ Get a position value according to Position Huffman Table.\r
+ \r
+ @param Sd the global scratch data\r
+\r
+ @return The position value decoded.\r
+\r
+**/\r
+UINT32\r
+DecodeP (\r
+ IN SCRATCH_DATA *Sd\r
+ );\r
+\r
+/**\r
+ Reads code lengths for the Extra Set or the Position Set.\r
+\r
+ Read in the Extra Set or Pointion Set Length Arrary, then\r
+ generate the Huffman code mapping for them.\r
+\r
+ @param Sd The global scratch data.\r
+ @param nn Number of symbols.\r
+ @param nbit Number of bits needed to represent nn.\r
+ @param Special The special symbol that needs to be taken care of.\r
+\r
+ @retval 0 OK.\r
+ @retval BAD_TABLE Table is corrupted.\r
+\r
+**/\r
+UINT16\r
+ReadPTLen (\r
+ IN SCRATCH_DATA *Sd,\r
+ IN UINT16 nn,\r
+ IN UINT16 nbit,\r
+ IN UINT16 Special\r
+ );\r
+\r
+/**\r
+ Reads code lengths for Char&Len Set.\r
+ \r
+ Read in and decode the Char&Len Set Code Length Array, then\r
+ generate the Huffman Code mapping table for the Char&Len Set.\r
+\r
+ @param Sd the global scratch data\r
+\r
+**/\r
+VOID\r
+ReadCLen (\r
+ SCRATCH_DATA *Sd\r
+ );\r
+\r
+/**\r
+ Decode a character/length value.\r
+ \r
+ Read one value from mBitBuf, Get one code from mBitBuf. If it is at block boundary, generates\r
+ Huffman code mapping table for Extra Set, Code&Len Set and\r
+ Position Set.\r
+\r
+ @param Sd The global scratch data.\r
+\r
+ @return The value decoded.\r
+\r
+**/\r
+UINT16\r
+DecodeC (\r
+ SCRATCH_DATA *Sd\r
+ );\r
+\r
+/**\r
+ Decode the source data and put the resulting data into the destination buffer.\r
+\r
+ Decode the source data and put the resulting data into the destination buffer.\r
+ \r
+ @param Sd The global scratch data\r
+\r
+**/\r
+VOID\r
+Decode (\r
+ SCRATCH_DATA *Sd\r
+ );\r
+\r
+RETURN_STATUS\r
+EFIAPI\r
+UefiTianoDecompress (\r
+ IN CONST VOID *Source,\r
+ IN OUT VOID *Destination,\r
+ IN OUT VOID *Scratch,\r
+ IN UINT32 Version\r
+ );\r
+\r
+#endif\r
--- /dev/null
+/**@file\r
+ Common header file shared by all source files.\r
+\r
+ This file includes package header files, library classes and protocol, PPI & GUID definitions.\r
+\r
+ Copyright (c) 2006, Intel Corporation.\r
+ All rights reserved. This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+\r
+#ifndef __COMMON_HEADER_H_\r
+#define __COMMON_HEADER_H_\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <Base.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/UefiDecompressLib.h>\r
+#include <Library/CustomDecompressLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+\r
+#endif\r
--- /dev/null
+/**@file\r
+ Common header file shared by all source files.\r
+\r
+ This file includes package header files, library classes and protocol, PPI & GUID definitions.\r
+\r
+ Copyright (c) 2006 - 2007, Intel Corporation.\r
+ All rights reserved. This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+\r
+#ifndef __COMMON_HEADER_H_\r
+#define __COMMON_HEADER_H_\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiPei.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/OemHookStatusCodeLib.h>\r
+\r
+#endif\r
--- /dev/null
+/** @file\r
+ OEM hook status code library functions with no library constructor/destructor\r
+\r
+ Copyright (c) 2006, Intel Corporation\r
+ All rights reserved. This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+ Module Name: OemHookStatusCodeLibNull.c\r
+\r
+**/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+/**\r
+\r
+ Initialize OEM status code device .\r
+\r
+ @return Always return EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+OemHookStatusCodeInitialize (\r
+ VOID\r
+ )\r
+{\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ Report status code to OEM device.\r
+ \r
+ @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.\r
+ \r
+ @param Value Describes the current status of a hardware or software entity. \r
+ This included information about the class and subclass that is used to classify the entity \r
+ as well as an operation. For progress codes, the operation is the current activity. \r
+ For error codes, it is the exception. For debug codes, it is not defined at this time. \r
+ Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below. \r
+ Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.\r
+ \r
+ @param Instance The enumeration of a hardware or software entity within the system. \r
+ A system may contain multiple entities that match a class/subclass pairing. \r
+ The instance differentiates between them. An instance of 0 indicates that instance information is unavailable, \r
+ not meaningful, or not relevant. Valid instance numbers start with 1.\r
+\r
+\r
+ @param CallerId This optional parameter may be used to identify the caller. \r
+ This parameter allows the status code driver to apply different rules to different callers. \r
+ Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.\r
+\r
+\r
+ @param Data This optional parameter may be used to pass additional data\r
+ \r
+ @return The function always return EFI_UNSUPPORTED.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+OemHookStatusCodeReport (\r
+ IN EFI_STATUS_CODE_TYPE CodeType,\r
+ IN EFI_STATUS_CODE_VALUE Value,\r
+ IN UINT32 Instance,\r
+ IN EFI_GUID *CallerId, OPTIONAL\r
+ IN EFI_STATUS_CODE_DATA *Data OPTIONAL\r
+ )\r
+{\r
+ return EFI_UNSUPPORTED;\r
+}\r
+\r
--- /dev/null
+#/** @file\r
+# Memory Status Code Library for UEFI drivers\r
+#\r
+# Lib to provide memory journal status code reporting Routines\r
+# Copyright (c) 2006 - 2007, Intel Corporation.\r
+#\r
+# All rights reserved. This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution. The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+ INF_VERSION = 0x00010005\r
+ BASE_NAME = EdkOemHookStatusCodeLibNull\r
+ FILE_GUID = 54D2878F-25CD-4a2b-8420-EBD18E609C76\r
+ MODULE_TYPE = PEIM\r
+ VERSION_STRING = 1.0\r
+ LIBRARY_CLASS = OemHookStatusCodeLib \r
+ EDK_RELEASE_VERSION = 0x00020000\r
+ EFI_SPECIFICATION_VERSION = 0x00020000\r
+\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC\r
+#\r
+\r
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+ OemHookStatusCodeLibNull.c\r
+ CommonHeader.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Includes Section - list of Include locations that are required for\r
+# this module.\r
+#\r
+################################################################################\r
+\r
+[Includes]\r
+ $(WORKSPACE)/MdePkg/Include\r
+ $(WORKSPACE)/IntelFrameworkModulePkg/Include\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+# this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+ MdePkg/MdePkg.dec\r
+ IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+ <MsaHeader>\r
+ <ModuleName>EdkOemHookStatusCodeLibNull</ModuleName>\r
+ <ModuleType>PEIM</ModuleType>\r
+ <GuidValue>54D2878F-25CD-4a2b-8420-EBD18E609C76</GuidValue>\r
+ <Version>1.0</Version>\r
+ <Abstract>Memory Status Code Library for UEFI drivers</Abstract>\r
+ <Description>Lib to provide memory journal status code reporting Routines</Description>\r
+ <Copyright>Copyright (c) 2006 - 2007, Intel Corporation.</Copyright>\r
+ <License>All rights reserved. This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.</License>\r
+ <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052</Specification>\r
+ </MsaHeader>\r
+ <ModuleDefinitions>\r
+ <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+ <BinaryModule>false</BinaryModule>\r
+ <OutputFileBasename>EdkOemHookStatusCodeLibNull</OutputFileBasename>\r
+ </ModuleDefinitions>\r
+ <LibraryClassDefinitions>\r
+ <LibraryClass Usage="ALWAYS_PRODUCED">\r
+ <Keyword>OemHookStatusCodeLib</Keyword>\r
+ </LibraryClass>\r
+ </LibraryClassDefinitions>\r
+ <SourceFiles>\r
+ <Filename>OemHookStatusCodeLibNull.c</Filename>\r
+ </SourceFiles>\r
+ <PackageDependencies>\r
+ <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+ <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+ </PackageDependencies>\r
+ <Externs>\r
+ <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+ <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+ </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file
--- /dev/null
+/**@file\r
+ Common header file shared by all source files.\r
+\r
+ This file includes package header files, library classes and protocol, PPI & GUID definitions.\r
+\r
+ Copyright (c) 2007, Intel Corporation.\r
+ All rights reserved. This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+\r
+#ifndef __COMMON_HEADER_H_\r
+#define __COMMON_HEADER_H_\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiDxe.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/PciIncompatibleDeviceSupportLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/DebugLib.h>\r
+\r
+#endif\r
--- /dev/null
+/** @file\r
+ The incompatible PCI device list\r
+\r
+Copyright (c) 2007 Intel Corporation. All rights reserved. <BR>\r
+This software and associated documentation (if any) is furnished\r
+under a license and may only be used or copied in accordance\r
+with the terms of the license. Except as permitted by such\r
+license, no part of this software or documentation may be\r
+reproduced, stored in a retrieval system, or transmitted in any\r
+form or by any means without the express written consent of\r
+Intel Corporation.\r
+\r
+**/\r
+\r
+#ifndef _EFI_INCOMPATIBLE_PCI_DEVICE_LIST_H\r
+#define _EFI_INCOMPATIBLE_PCI_DEVICE_LIST_H\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include <IndustryStandard/pci22.h>\r
+#include <IndustryStandard/Acpi.h>\r
+\r
+\r
+#define PCI_DEVICE_ID(VendorId, DeviceId, Revision, SubVendorId, SubDeviceId) \\r
+ VendorId, DeviceId, Revision, SubVendorId, SubDeviceId\r
+\r
+#define PCI_BAR_TYPE_IO ACPI_ADDRESS_SPACE_TYPE_IO\r
+#define PCI_BAR_TYPE_MEM ACPI_ADDRESS_SPACE_TYPE_MEM\r
+\r
+#define DEVICE_INF_TAG 0xFFF2\r
+#define DEVICE_RES_TAG 0xFFF1\r
+#define LIST_END_TAG 0x0000\r
+\r
+//\r
+// descriptor for access width of incompatible PCI device\r
+//\r
+typedef struct {\r
+ UINT64 AccessType;\r
+ UINT64 AccessWidth;\r
+ EFI_PCI_REGISTER_ACCESS_DATA PciRegisterAccessData;\r
+} EFI_PCI_REGISTER_ACCESS_DESCRIPTOR;\r
+\r
+//\r
+// descriptor for register value of incompatible PCI device\r
+//\r
+typedef struct {\r
+ UINT64 AccessType;\r
+ UINT64 Offset;\r
+ EFI_PCI_REGISTER_VALUE_DATA PciRegisterValueData;\r
+} EFI_PCI_REGISTER_VALUE_DESCRIPTOR;\r
+\r
+\r
+//\r
+// the incompatible PCI devices list for ACPI resource\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED UINT64 IncompatiblePciDeviceListForResource[] = {\r
+ //\r
+ // DEVICE_INF_TAG,\r
+ // PCI_DEVICE_ID (VendorID, DeviceID, Revision, SubVendorId, SubDeviceId),\r
+ // DEVICE_RES_TAG,\r
+ // ResType, GFlag , SFlag, Granularity, RangeMin,\r
+ // RangeMax, Offset, AddrLen\r
+ //\r
+ //\r
+ // Device Adaptec 9004\r
+ //\r
+ DEVICE_INF_TAG,\r
+ PCI_DEVICE_ID(0x9004, DEVICE_ID_NOCARE, DEVICE_ID_NOCARE, DEVICE_ID_NOCARE, DEVICE_ID_NOCARE),\r
+ DEVICE_RES_TAG,\r
+ PCI_BAR_TYPE_IO,\r
+ PCI_ACPI_UNUSED,\r
+ PCI_ACPI_UNUSED,\r
+ PCI_ACPI_UNUSED,\r
+ PCI_ACPI_UNUSED,\r
+ PCI_BAR_EVEN_ALIGN,\r
+ PCI_BAR_ALL,\r
+ PCI_BAR_NOCHANGE,\r
+ //\r
+ // Device Adaptec 9005\r
+ //\r
+ DEVICE_INF_TAG,\r
+ PCI_DEVICE_ID(0x9005, DEVICE_ID_NOCARE, DEVICE_ID_NOCARE, DEVICE_ID_NOCARE, DEVICE_ID_NOCARE),\r
+ DEVICE_RES_TAG,\r
+ PCI_BAR_TYPE_IO,\r
+ PCI_ACPI_UNUSED,\r
+ PCI_ACPI_UNUSED,\r
+ PCI_ACPI_UNUSED,\r
+ PCI_ACPI_UNUSED,\r
+ PCI_BAR_EVEN_ALIGN,\r
+ PCI_BAR_ALL,\r
+ PCI_BAR_NOCHANGE,\r
+ //\r
+ // Device QLogic 1007\r
+ //\r
+ DEVICE_INF_TAG,\r
+ PCI_DEVICE_ID(0x1077, DEVICE_ID_NOCARE, DEVICE_ID_NOCARE, DEVICE_ID_NOCARE, DEVICE_ID_NOCARE),\r
+ DEVICE_RES_TAG,\r
+ PCI_BAR_TYPE_IO,\r
+ PCI_ACPI_UNUSED,\r
+ PCI_ACPI_UNUSED,\r
+ PCI_ACPI_UNUSED,\r
+ PCI_ACPI_UNUSED,\r
+ PCI_BAR_EVEN_ALIGN,\r
+ PCI_BAR_ALL,\r
+ PCI_BAR_NOCHANGE,\r
+ //\r
+ // Device Agilent 103C\r
+ //\r
+ DEVICE_INF_TAG,\r
+ PCI_DEVICE_ID(0x103C, DEVICE_ID_NOCARE, DEVICE_ID_NOCARE, DEVICE_ID_NOCARE, DEVICE_ID_NOCARE),\r
+ DEVICE_RES_TAG,\r
+ PCI_BAR_TYPE_IO,\r
+ PCI_ACPI_UNUSED,\r
+ PCI_ACPI_UNUSED,\r
+ PCI_ACPI_UNUSED,\r
+ PCI_ACPI_UNUSED,\r
+ PCI_BAR_EVEN_ALIGN,\r
+ PCI_BAR_ALL,\r
+ PCI_BAR_NOCHANGE,\r
+ //\r
+ // Device Agilent 15BC\r
+ //\r
+ DEVICE_INF_TAG,\r
+ PCI_DEVICE_ID(0x15BC, DEVICE_ID_NOCARE, DEVICE_ID_NOCARE, DEVICE_ID_NOCARE, DEVICE_ID_NOCARE),\r
+ DEVICE_RES_TAG,\r
+ PCI_BAR_TYPE_IO,\r
+ PCI_ACPI_UNUSED,\r
+ PCI_ACPI_UNUSED,\r
+ PCI_ACPI_UNUSED,\r
+ PCI_ACPI_UNUSED,\r
+ PCI_BAR_EVEN_ALIGN,\r
+ PCI_BAR_ALL,\r
+ PCI_BAR_NOCHANGE,\r
+ //\r
+ // The end of the list\r
+ //\r
+ LIST_END_TAG\r
+};\r
+\r
+//\r
+// the incompatible PCI devices list for the values of configuration registers\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED UINT64 IncompatiblePciDeviceListForRegister[] = {\r
+ //\r
+ // DEVICE_INF_TAG,\r
+ // PCI_DEVICE_ID (VendorID, DeviceID, Revision, SubVendorId, SubDeviceId),\r
+ // PCI_RES_TAG,\r
+ // PCI_ACCESS_TYPE, PCI_CONFIG_ADDRESS,\r
+ // AND_VALUE, OR_VALUE\r
+\r
+ //\r
+ // Device Lava 0x1407, DeviceId 0x0110\r
+ //\r
+ DEVICE_INF_TAG,\r
+ PCI_DEVICE_ID(0x1407, 0x0110, DEVICE_ID_NOCARE, DEVICE_ID_NOCARE, DEVICE_ID_NOCARE),\r
+ DEVICE_RES_TAG,\r
+ PCI_REGISTER_READ,\r
+ PCI_CAPBILITY_POINTER_OFFSET,\r
+ 0xffffff00,\r
+ VALUE_NOCARE,\r
+\r
+ //\r
+ // Device Lava 0x1407, DeviceId 0x0111\r
+ //\r
+ DEVICE_INF_TAG,\r
+ PCI_DEVICE_ID(0x1407, 0x0111, DEVICE_ID_NOCARE, DEVICE_ID_NOCARE, DEVICE_ID_NOCARE),\r
+ DEVICE_RES_TAG,\r
+ PCI_REGISTER_READ,\r
+ PCI_CAPBILITY_POINTER_OFFSET,\r
+ 0xffffff00,\r
+ VALUE_NOCARE,\r
+\r
+ //\r
+ // The end of the list\r
+ //\r
+ LIST_END_TAG\r
+};\r
+\r
+//\r
+// the incompatible PCI devices list for the access width of configuration registers\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED UINT64 DeviceListForAccessWidth[] = {\r
+ //\r
+ // DEVICE_INF_TAG,\r
+ // PCI_DEVICE_ID (VendorID, DeviceID, Revision, SubVendorId, SubDeviceId),\r
+ // DEVICE_RES_TAG,\r
+ // PCI_ACCESS_TYPE, PCI_ACCESS_WIDTH,\r
+ // START_ADDRESS, END_ADDRESS,\r
+ // ACTUAL_PCI_ACCESS_WIDTH,\r
+ //\r
+\r
+ //\r
+ // Sample Device\r
+ //\r
+ //DEVICE_INF_TAG,\r
+ //PCI_DEVICE_ID(0xXXXX, DEVICE_ID_NOCARE, DEVICE_ID_NOCARE, DEVICE_ID_NOCARE, DEVICE_ID_NOCARE),\r
+ //DEVICE_RES_TAG,\r
+ //PCI_REGISTER_READ,\r
+ //EfiPciWidthUint8,\r
+ //0,\r
+ //0xFF,\r
+ //EfiPciWidthUint32,\r
+ //\r
+\r
+ //\r
+ // The end of the list\r
+ //\r
+ LIST_END_TAG\r
+};\r
+\r
+#endif\r
--- /dev/null
+/** @file\r
+ The implementation of PCI incompatible device support libary.\r
+\r
+Copyright (c) 2007 Intel Corporation. All rights reserved. <BR>\r
+This software and associated documentation (if any) is furnished\r
+under a license and may only be used or copied in accordance\r
+with the terms of the license. Except as permitted by such\r
+license, no part of this software or documentation may be\r
+reproduced, stored in a retrieval system, or transmitted in any\r
+form or by any means without the express written consent of\r
+Intel Corporation.\r
+\r
+**/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "IncompatiblePciDeviceList.h"\r
+\r
+/**\r
+ Check whether two PCI devices matched\r
+\r
+ @param PciDeviceInfo A pointer to EFI_PCI_DEVICE_INFO.\r
+ @param Header A pointer to EFI_PCI_DEVICE_INFO.\r
+\r
+ @retval returns EFI_SUCCESS if two PCI device matched.\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+DeviceCheck (\r
+ IN EFI_PCI_DEVICE_INFO *PciDeviceInfo,\r
+ IN EFI_PCI_DEVICE_INFO *Header\r
+ )\r
+{\r
+ //\r
+ // See if the Header matches the parameters passed in\r
+ //\r
+ if (Header->VendorID != DEVICE_ID_NOCARE) {\r
+ if (PciDeviceInfo->VendorID != Header->VendorID) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+ }\r
+\r
+ if (Header->DeviceID != DEVICE_ID_NOCARE) {\r
+ if (PciDeviceInfo->DeviceID != Header->DeviceID) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+ }\r
+\r
+ if (Header->RevisionID != DEVICE_ID_NOCARE) {\r
+ if (PciDeviceInfo->RevisionID != Header->RevisionID) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+ }\r
+\r
+ if (Header->SubsystemVendorID != DEVICE_ID_NOCARE) {\r
+ if (PciDeviceInfo->SubsystemVendorID != Header->SubsystemVendorID) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+ }\r
+\r
+ if (Header->SubsystemID != DEVICE_ID_NOCARE) {\r
+ if (PciDeviceInfo->SubsystemID != Header->SubsystemID) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+ Check the incompatible device list for ACPI resource update and return\r
+ the configuration\r
+\r
+ This function searches the incompatible device list according to request\r
+ information. If the PCI device belongs to the devices list, corresponding\r
+ configuration informtion will be returned, in the meantime return EFI_SUCCESS.\r
+\r
+ @param PciDeviceInfo A pointer to PCI device information.\r
+ @param Configuration Returned information.\r
+\r
+ @retval returns EFI_SUCCESS if check incompatible device ok.\r
+ Otherwise return EFI_UNSUPPORTED.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PciResourceUpdateCheck (\r
+ IN EFI_PCI_DEVICE_INFO *PciDeviceInfo,\r
+ OUT VOID *Configuration\r
+ )\r
+{\r
+ UINT64 Tag;\r
+ UINT64 *ListPtr;\r
+ UINT64 *TempListPtr;\r
+ EFI_PCI_DEVICE_INFO *Header;\r
+ EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *AcpiPtr;\r
+ EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *OldAcpiPtr;\r
+ EFI_PCI_RESOUCE_DESCRIPTOR *Dsc;\r
+ EFI_ACPI_END_TAG_DESCRIPTOR *PtrEnd;\r
+ UINTN Index;\r
+\r
+ ASSERT (PciDeviceInfo != NULL);\r
+\r
+ //\r
+ // Initialize the return value to NULL\r
+ //\r
+ * (VOID **) Configuration = NULL;\r
+\r
+ ListPtr = IncompatiblePciDeviceListForResource;\r
+ while (*ListPtr != LIST_END_TAG) {\r
+\r
+ Tag = *ListPtr;\r
+\r
+ switch (Tag) {\r
+ case DEVICE_INF_TAG:\r
+ Header = (EFI_PCI_DEVICE_INFO *) (ListPtr + 1);\r
+ ListPtr = ListPtr + 1 + sizeof (EFI_PCI_DEVICE_INFO) / sizeof (UINT64);\r
+\r
+ if (DeviceCheck (PciDeviceInfo, Header) != EFI_SUCCESS) {\r
+ continue;\r
+ }\r
+\r
+ //\r
+ // Matched an item, so construct the ACPI descriptor for the resource.\r
+ //\r
+ //\r
+ // Count the resource items so that to allocate space\r
+ //\r
+ for (Index = 0, TempListPtr = ListPtr; *TempListPtr == DEVICE_RES_TAG; Index++) {\r
+ TempListPtr = TempListPtr + 1 + ((sizeof (EFI_PCI_RESOUCE_DESCRIPTOR)) / sizeof (UINT64));\r
+ }\r
+ //\r
+ // If there is at least one type of resource request,\r
+ // allocate a acpi resource node\r
+ //\r
+ if (Index == 0) {\r
+ return EFI_ABORTED;\r
+ }\r
+\r
+ AcpiPtr = AllocateZeroPool (\r
+ sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) * Index + sizeof (EFI_ACPI_END_TAG_DESCRIPTOR)\r
+ );\r
+\r
+ OldAcpiPtr = AcpiPtr;\r
+\r
+ //\r
+ // Fill the EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR structure\r
+ // according to the EFI_PCI_RESOUCE_DESCRIPTOR structure\r
+ //\r
+ for (; *ListPtr == DEVICE_RES_TAG;) {\r
+\r
+ Dsc = (EFI_PCI_RESOUCE_DESCRIPTOR *) (ListPtr + 1);\r
+\r
+ AcpiPtr->Desc = ACPI_ADDRESS_SPACE_DESCRIPTOR;\r
+ AcpiPtr->Len = sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR);\r
+ AcpiPtr->ResType = (UINT8) Dsc->ResType;\r
+ AcpiPtr->GenFlag = (UINT8) Dsc->GenFlag;\r
+ AcpiPtr->SpecificFlag = (UINT8) Dsc->SpecificFlag;\r
+ AcpiPtr->AddrSpaceGranularity = Dsc->AddrSpaceGranularity;;\r
+ AcpiPtr->AddrRangeMin = Dsc->AddrRangeMin;\r
+ AcpiPtr->AddrRangeMax = Dsc->AddrRangeMax;\r
+ AcpiPtr->AddrTranslationOffset = Dsc->AddrTranslationOffset;\r
+ AcpiPtr->AddrLen = Dsc->AddrLen;\r
+\r
+ ListPtr = ListPtr + 1 + ((sizeof (EFI_PCI_RESOUCE_DESCRIPTOR)) / sizeof (UINT64));\r
+ AcpiPtr++;\r
+ }\r
+ //\r
+ // put the checksum\r
+ //\r
+ PtrEnd = (EFI_ACPI_END_TAG_DESCRIPTOR *) (AcpiPtr);\r
+ PtrEnd->Desc = ACPI_END_TAG_DESCRIPTOR;\r
+ PtrEnd->Checksum = 0;\r
+\r
+ *(VOID **) Configuration = OldAcpiPtr;\r
+\r
+ return EFI_SUCCESS;\r
+\r
+ case DEVICE_RES_TAG:\r
+ //\r
+ // Adjust the pointer to the next PCI resource descriptor item\r
+ //\r
+ ListPtr = ListPtr + 1 + ((sizeof (EFI_PCI_RESOUCE_DESCRIPTOR)) / sizeof (UINT64));\r
+ break;\r
+\r
+ default:\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+ }\r
+\r
+ return EFI_UNSUPPORTED;\r
+\r
+}\r
+\r
+/**\r
+ Check the incompatible device list and return configuraton register mask values.\r
+\r
+ This function searches the incompatible device list according to request\r
+ information. If the PCI device belongs to the devices list, corresponding\r
+ configuration informtion will be returned, in the meantime return EFI_SUCCESS.\r
+\r
+ @param PciDeviceInfo A pointer to EFI_PCI_DEVICE_INFO.\r
+ @param AccessType Access Type, READ or WRITE.\r
+ @param Offset The address within the PCI configuration space.\r
+ @param Configuration Returned information.\r
+\r
+ @retval returns EFI_SUCCESS if check incompatible device ok.\r
+ Otherwise return EFI_UNSUPPORTED.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PciRegisterUpdateCheck (\r
+ IN EFI_PCI_DEVICE_INFO *PciDeviceInfo,\r
+ IN UINT64 AccessType,\r
+ IN UINT64 Offset,\r
+ OUT VOID *Configuration\r
+ )\r
+{\r
+ EFI_PCI_DEVICE_INFO *Header;\r
+ UINT64 Tag;\r
+ UINT64 *ListPtr;\r
+ EFI_PCI_REGISTER_VALUE_DATA *RegisterPtr;\r
+ EFI_PCI_REGISTER_VALUE_DATA *Dsc;\r
+\r
+ ASSERT (PciDeviceInfo != NULL);\r
+\r
+ ListPtr = IncompatiblePciDeviceListForRegister;\r
+\r
+ //\r
+ // Initialize the return value to NULL\r
+ //\r
+ * (VOID **) Configuration = NULL;\r
+\r
+ while (*ListPtr != LIST_END_TAG) {\r
+\r
+ Tag = *ListPtr;\r
+\r
+ switch (Tag) {\r
+ case DEVICE_INF_TAG:\r
+ Header = (EFI_PCI_DEVICE_INFO *) (ListPtr + 1);\r
+ ListPtr = ListPtr + 1 + sizeof (EFI_PCI_DEVICE_INFO) / sizeof (UINT64);\r
+\r
+ //\r
+ // Check whether the PCI device matches the device in the incompatible devices list?\r
+ // If not, ship next\r
+ //\r
+ if (DeviceCheck (PciDeviceInfo, Header) != EFI_SUCCESS) {\r
+ continue;\r
+ }\r
+\r
+ //\r
+ // Matched an item, check whether access matches?\r
+ //\r
+ for (; *ListPtr == DEVICE_RES_TAG;) {\r
+ ListPtr ++;\r
+ if (((EFI_PCI_REGISTER_VALUE_DESCRIPTOR *)ListPtr)->Offset == (Offset & 0xfc)) {\r
+ if (((EFI_PCI_REGISTER_VALUE_DESCRIPTOR *)ListPtr)->AccessType == AccessType) {\r
+\r
+ Dsc = (EFI_PCI_REGISTER_VALUE_DATA *) (ListPtr + 2);\r
+ RegisterPtr = AllocateZeroPool (sizeof (EFI_PCI_REGISTER_VALUE_DATA));\r
+\r
+ RegisterPtr->AndValue = Dsc->AndValue;\r
+ RegisterPtr->OrValue = Dsc->OrValue;\r
+\r
+ *(VOID **) Configuration = RegisterPtr;\r
+\r
+ return EFI_SUCCESS;\r
+ }\r
+ }\r
+ ListPtr += sizeof (EFI_PCI_REGISTER_VALUE_DESCRIPTOR) / (sizeof (UINT64));\r
+ }\r
+ return EFI_UNSUPPORTED;\r
+\r
+ case DEVICE_RES_TAG:\r
+ //\r
+ // Adjust the pointer to the next item\r
+ //\r
+ ListPtr = ListPtr + 1 + ((sizeof (EFI_PCI_REGISTER_VALUE_DESCRIPTOR)) / sizeof (UINT64));\r
+ break;\r
+\r
+ default:\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+ }\r
+\r
+ return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+ Check the incompatible device list for access width incompatibility and\r
+ return the configuration\r
+\r
+ This function searches the incompatible device list for access width\r
+ incompatibility according to request information. If the PCI device\r
+ belongs to the devices list, corresponding configuration informtion\r
+ will be returned, in the meantime return EFI_SUCCESS.\r
+\r
+ @param PciDeviceInfo A pointer to PCI device information.\r
+ @param AccessType Access type, READ or WRITE.\r
+ @param Offset The address within the PCI configuration space.\r
+ @param AccessWidth Access width needs to check incompatibility.\r
+ @param Configuration Returned information.\r
+\r
+ @retval returns EFI_SUCCESS if check incompatible device ok.\r
+ Otherwise return EFI_UNSUPPORTED.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PciRegisterAccessCheck (\r
+ IN EFI_PCI_DEVICE_INFO *PciDeviceInfo,\r
+ IN UINT64 AccessType,\r
+ IN UINT64 Offset,\r
+ IN UINT64 AccessWidth,\r
+ OUT VOID *Configuration\r
+ )\r
+{\r
+ EFI_PCI_DEVICE_INFO *Header;\r
+ UINT64 Tag;\r
+ UINT64 *ListPtr;\r
+ EFI_PCI_REGISTER_ACCESS_DATA *RegisterPtr;\r
+ EFI_PCI_REGISTER_ACCESS_DATA *Dsc;\r
+\r
+ ASSERT (PciDeviceInfo != NULL);\r
+\r
+ ListPtr = DeviceListForAccessWidth;\r
+\r
+ //\r
+ // Initialize the return value to NULL\r
+ //\r
+ * (VOID **) Configuration = NULL;\r
+\r
+ while (*ListPtr != LIST_END_TAG) {\r
+\r
+ Tag = *ListPtr;\r
+\r
+ switch (Tag) {\r
+ case DEVICE_INF_TAG:\r
+ Header = (EFI_PCI_DEVICE_INFO *) (ListPtr + 1);\r
+ ListPtr = ListPtr + 1 + sizeof (EFI_PCI_DEVICE_INFO) / sizeof (UINT64);\r
+\r
+ //\r
+ // Check whether the PCI device matches the device in the incompatible devices list?\r
+ // If not, ship next\r
+ //\r
+ if (DeviceCheck (PciDeviceInfo, Header) != EFI_SUCCESS) {\r
+ continue;\r
+ }\r
+\r
+ //\r
+ // Matched an item, check whether access matches?\r
+ //\r
+ for (; *ListPtr == DEVICE_RES_TAG;) {\r
+ ListPtr ++;\r
+ if (((EFI_PCI_REGISTER_ACCESS_DESCRIPTOR *) ListPtr)->AccessType == AccessType &&\r
+ ((EFI_PCI_REGISTER_ACCESS_DESCRIPTOR *) ListPtr)->AccessWidth == AccessWidth ) {\r
+\r
+ Dsc = (EFI_PCI_REGISTER_ACCESS_DATA *) (ListPtr + 2);\r
+\r
+ if((Dsc->StartOffset <= Offset) && (Dsc->EndOffset > Offset)) {\r
+\r
+ RegisterPtr = AllocateZeroPool (sizeof (EFI_PCI_REGISTER_ACCESS_DATA));\r
+\r
+ RegisterPtr->StartOffset = Dsc->StartOffset;\r
+ RegisterPtr->EndOffset = Dsc->EndOffset;\r
+ RegisterPtr->Width = Dsc->Width;\r
+\r
+ *(VOID **) Configuration = RegisterPtr;\r
+\r
+ return EFI_SUCCESS;\r
+ }\r
+ }\r
+ ListPtr += sizeof (EFI_PCI_REGISTER_ACCESS_DESCRIPTOR) / (sizeof (UINT64));\r
+ }\r
+ return EFI_UNSUPPORTED;\r
+\r
+ case DEVICE_RES_TAG:\r
+ //\r
+ // Adjust the pointer to the next item\r
+ //\r
+ ListPtr = ListPtr + 1 + ((sizeof (EFI_PCI_REGISTER_ACCESS_DESCRIPTOR)) / sizeof (UINT64));\r
+ break;\r
+\r
+ default:\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+ }\r
+\r
+ return EFI_UNSUPPORTED;\r
+}\r
+\r
--- /dev/null
+#/** @file\r
+# PCI Incompatible device support Library\r
+#\r
+# Check PCI incompatible devices and set necessary configuration\r
+# Copyright (c) 2007, Intel Corporation.\r
+#\r
+# All rights reserved. This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution. The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+ INF_VERSION = 0x00010005\r
+ BASE_NAME = EdkPciIncompatibleDeviceSupportLib\r
+ FILE_GUID = 1ca1c1f9-5baf-4204-b6e5-5e24109a4e4e\r
+ MODULE_TYPE = DXE_DRIVER\r
+ VERSION_STRING = 1.0\r
+ LIBRARY_CLASS = PciIncompatibleDeviceSupportLib \r
+ EDK_RELEASE_VERSION = 0x00020000\r
+ EFI_SPECIFICATION_VERSION = 0x00020000\r
+\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC\r
+#\r
+\r
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+ IncompatiblePciDeviceList.h\r
+ PciIncompatibleDeviceSupportLib.c\r
+ CommonHeader.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Includes Section - list of Include locations that are required for\r
+# this module.\r
+#\r
+################################################################################\r
+\r
+[Includes]\r
+ $(WORKSPACE)/MdePkg/Include\r
+ $(WORKSPACE)/IntelFrameworkModulePkg/Include\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+# this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+ MdePkg/MdePkg.dec\r
+ IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+# this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+ MemoryAllocationLib\r
+ DebugLib\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+ <MsaHeader>\r
+ <ModuleName>EdkPciIncompatibleDeviceSuppportLib</ModuleName>\r
+ <ModuleType>DXE_DRIVER</ModuleType>\r
+ <GuidValue>1ca1c1f9-5baf-4204-b6e5-5e24109a4e4e</GuidValue>\r
+ <Version>1.0</Version>\r
+ <Abstract>PCI Incompatible device support Library</Abstract>\r
+ <Description>Check PCI incompatible devices and set necessary configuration</Description>\r
+ <Copyright>Copyright (c) 2007, Intel Corporation.</Copyright>\r
+ <License>All rights reserved. This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.</License>\r
+ <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052</Specification>\r
+ </MsaHeader>\r
+ <ModuleDefinitions>\r
+ <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+ <BinaryModule>false</BinaryModule>\r
+ <OutputFileBasename>EdkPciIncompatibleDeviceSupportLib</OutputFileBasename>\r
+ </ModuleDefinitions>\r
+ <LibraryClassDefinitions>\r
+ <LibraryClass Usage="ALWAYS_PRODUCED">\r
+ <Keyword>PciIncompatibleDeviceSupportLib</Keyword>\r
+ </LibraryClass>\r
+ <LibraryClass Usage="ALWAYS_CONSUMED">\r
+ <Keyword>MemoryAllocationLib</Keyword>\r
+ </LibraryClass>\r
+ <LibraryClass Usage="ALWAYS_CONSUMED">\r
+ <Keyword>DebugLib</Keyword>\r
+ </LibraryClass>\r
+ </LibraryClassDefinitions>\r
+ <SourceFiles>\r
+ <Filename>PciIncompatibleDeviceSupportLib.c</Filename>\r
+ <Filename>IncompatiblePciDeviceList.h</Filename>\r
+ </SourceFiles>\r
+ <PackageDependencies>\r
+ <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+ <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+ </PackageDependencies>\r
+ <Externs>\r
+ <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+ <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+ </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file