⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 coresectionextraction.c

📁 EFI BIOS是Intel提出的下一代的BIOS标准。这里上传的Edk源代码是EFI BIOS源代码中的与平台无关部分的代码
💻 C
📖 第 1 页 / 共 4 页
字号:
/*++

Copyright (c) 2004, Intel Corporation                                                         
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.             

Module Name:

  CoreSectionExtraction.c
  
Abstract:

  Section Extraction Protocol implementation.
  
  Stream database is implemented as a linked list of section streams,
  where each stream contains a linked list of children, which may be leaves or
  encapsulations.  
  
  Children that are encapsulations generate new stream entries
  when they are created.  Streams can also be created by calls to 
  SEP->OpenSectionStream().
  
  The database is only created far enough to return the requested data from
  any given stream, or to determine that the requested data is not found.
  
  If a GUIDed encapsulation is encountered, there are three possiblilites.
  
  1) A support protocol is found, in which the stream is simply processed with
     the support protocol.
     
  2) A support protocol is not found, but the data is available to be read
     without processing.  In this case, the database is built up through the
     recursions to return the data, and a RPN event is set that will enable
     the stream in question to be refreshed if and when the required section
     extraction protocol is published.This insures the AuthenticationStatus 
     does not become stale in the cache.
     
  3) A support protocol is not found, and the data is not available to be read
     without it.  This results in EFI_PROTOCOL_ERROR.
  
--*/

#include "Tiano.h"
#include "DxeCore.h"
#include "EfiFirmwareFileSystem.h"

//
// Comsumed protocol
//
#include EFI_PROTOCOL_DEFINITION (TianoDecompress)
#include EFI_PROTOCOL_DEFINITION (GuidedSectionExtraction)

//
// Produced protocol
//
#include EFI_PROTOCOL_DEFINITION (SectionExtraction)

//
// Local defines and typedefs
//
#define CORE_SECTION_CHILD_SIGNATURE  EFI_SIGNATURE_32('S','X','C','S')
#define CHILD_SECTION_NODE_FROM_LINK(Node) \
  CR (Node, CORE_SECTION_CHILD_NODE, Link, CORE_SECTION_CHILD_SIGNATURE)

typedef struct {
  UINT32                      Signature;
  EFI_LIST_ENTRY              Link;
  UINT32                      Type;
  UINT32                      Size;
  //
  // StreamBase + OffsetInStream == pointer to section header in stream.  The
  // stream base is always known when walking the sections within.
  //
  UINT32                      OffsetInStream;
  //
  // Then EncapsulatedStreamHandle below is always 0 if the section is NOT an
  // encapsulating section.  Otherwise, it contains the stream handle
  // of the encapsulated stream.  This handle is ALWAYS produced any time an
  // encapsulating child is encountered, irrespective of whether the
  // encapsulated stream is processed further.
  //
  UINTN                       EncapsulatedStreamHandle;
  EFI_GUID                    *EncapsulationGuid;
} CORE_SECTION_CHILD_NODE;

#define CORE_SECTION_STREAM_SIGNATURE EFI_SIGNATURE_32('S','X','S','S')
#define STREAM_NODE_FROM_LINK(Node) \
  CR (Node, CORE_SECTION_STREAM_NODE, Link, CORE_SECTION_STREAM_SIGNATURE)

typedef struct {
  UINT32                      Signature;
  EFI_LIST_ENTRY              Link;
  UINTN                       StreamHandle;
  UINT8                       *StreamBuffer;
  UINTN                       StreamLength;
  EFI_LIST                    Children;
  //
  // Authentication status is from GUIDed encapsulations.
  //
  UINT32                      AuthenticationStatus;
} CORE_SECTION_STREAM_NODE;

#define NULL_STREAM_HANDLE    0

typedef struct {
  CORE_SECTION_CHILD_NODE     *ChildNode;
  CORE_SECTION_STREAM_NODE    *ParentStream;
  VOID                        *Registration;
  EFI_EVENT                   Event;
} RPN_EVENT_CONTEXT;
  
  

//
// Local prototypes
//

STATIC
BOOLEAN
ChildIsType (
  IN CORE_SECTION_STREAM_NODE                 *Stream,
  IN CORE_SECTION_CHILD_NODE                  *Child,
  IN EFI_SECTION_TYPE                         SearchType,
  IN EFI_GUID                                 *SectionDefinitionGuid
  );

STATIC
VOID
EFIAPI
NotifyGuidedExtraction (
  IN  EFI_EVENT                             Event,
  IN  VOID                                  *RpnContext
  );

STATIC
VOID
CreateGuidedExtractionRpnEvent (
  IN CORE_SECTION_STREAM_NODE                 *ParentStream,
  IN CORE_SECTION_CHILD_NODE                  *ChildNode
  );

EFI_STATUS
EFIAPI
OpenSectionStream (
  IN     EFI_SECTION_EXTRACTION_PROTOCOL      *This,
  IN     UINTN                                SectionStreamLength,
  IN     VOID                                 *SectionStream,
     OUT UINTN                                *SectionStreamHandle
  );
  
EFI_STATUS
EFIAPI
GetSection (
  IN EFI_SECTION_EXTRACTION_PROTOCOL          *This,
  IN UINTN                                    SectionStreamHandle,
  IN EFI_SECTION_TYPE                         *SectionType,
  IN EFI_GUID                                 *SectionDefinitionGuid,
  IN UINTN                                    SectionInstance,
  IN VOID                                     **Buffer,
  IN OUT UINTN                                *BufferSize,
  OUT UINT32                                  *AuthenticationStatus
  );
  
EFI_STATUS
EFIAPI
CloseSectionStream (
  IN  EFI_SECTION_EXTRACTION_PROTOCOL         *This,
  IN  UINTN                                   StreamHandleToClose
  );
  
STATIC
EFI_STATUS
FindStreamNode (
  IN  UINTN                                   SearchHandle,
  OUT CORE_SECTION_STREAM_NODE                **FoundStream
  );
  
STATIC
EFI_STATUS
FindChildNode (
  IN     CORE_SECTION_STREAM_NODE             *SourceStream,
  IN     EFI_SECTION_TYPE                     SearchType,
  IN     UINTN                                *SectionInstance,
  IN     EFI_GUID                             *SectionDefinitionGuid,
  OUT    CORE_SECTION_CHILD_NODE              **FoundChild,
  OUT    CORE_SECTION_STREAM_NODE             **FoundStream,
  OUT    UINT32                               *AuthenticationStatus
  );
  
STATIC
EFI_STATUS
CreateChildNode (
  IN     CORE_SECTION_STREAM_NODE             *Stream,
  IN     UINT32                               ChildOffset,
  OUT    CORE_SECTION_CHILD_NODE              **ChildNode
  );
  
STATIC
VOID
FreeChildNode (
  IN  CORE_SECTION_CHILD_NODE                 *ChildNode
  );
  
STATIC
EFI_STATUS
OpenSectionStreamEx (
  IN     UINTN                                SectionStreamLength,
  IN     VOID                                 *SectionStream,
  IN     BOOLEAN                              AllocateBuffer,
  IN     UINT32                               AuthenticationStatus,   
     OUT UINTN                                *SectionStreamHandle
  );
  
STATIC
BOOLEAN
IsValidSectionStream (
  IN  VOID                                    *SectionStream,
  IN  UINTN                                   SectionStreamLength
  );
  
//
// Module globals
//
EFI_LIST mStreamRoot = INITIALIZE_LIST_HEAD_VARIABLE (mStreamRoot);

EFI_HANDLE mSectionExtractionHandle = NULL;

EFI_SECTION_EXTRACTION_PROTOCOL mSectionExtraction = { 
  OpenSectionStream, 
  GetSection, 
  CloseSectionStream
};

                                             
EFI_STATUS
EFIAPI
InitializeSectionExtraction (
  IN EFI_HANDLE                   ImageHandle,
  IN EFI_SYSTEM_TABLE             *SystemTable
  )
/*++

Routine Description: 
  Entry point of the section extraction code. Initializes an instance of the 
  section extraction interface and installs it on a new handle.

Arguments:  
  ImageHandle   EFI_HANDLE: A handle for the image that is initializing this driver
  SystemTable   EFI_SYSTEM_TABLE: A pointer to the EFI system table        

Returns:  
  EFI_SUCCESS:  Driver initialized successfully
  EFI_OUT_OF_RESOURCES:   Could not allocate needed resources

--*/
{
  EFI_STATUS                         Status;

  //
  // Install SEP to a new handle
  //
  Status = CoreInstallProtocolInterface (
            &mSectionExtractionHandle,
            &gEfiSectionExtractionProtocolGuid,
            EFI_NATIVE_INTERFACE,
            &mSectionExtraction
            );
  ASSERT_EFI_ERROR (Status);

  return Status;
}


EFI_STATUS
EFIAPI
OpenSectionStream (
  IN     EFI_SECTION_EXTRACTION_PROTOCOL           *This,
  IN     UINTN                                     SectionStreamLength,
  IN     VOID                                      *SectionStream,
     OUT UINTN                                     *SectionStreamHandle
  )
/*++

Routine Description:
  SEP member function.  This function creates and returns a new section stream
  handle to represent the new section stream.

Arguments:
  This                - Indicates the calling context.
  SectionStreamLength - Size in bytes of the section stream.
  SectionStream       - Buffer containing the new section stream.
  SectionStreamHandle - A pointer to a caller allocated UINTN that on output
                        contains the new section stream handle.

Returns:
  EFI_SUCCESS
  EFI_OUT_OF_RESOURCES - memory allocation failed.
  EFI_INVALID_PARAMETER - section stream does not end concident with end of
                          last section.

--*/
{
  //
  // Check to see section stream looks good...
  //
  if (!IsValidSectionStream (SectionStream, SectionStreamLength)) {
    return EFI_INVALID_PARAMETER;
  }
  
  return OpenSectionStreamEx ( 
          SectionStreamLength, 
          SectionStream,
          TRUE,
          0,
          SectionStreamHandle
          );
}
  

EFI_STATUS
EFIAPI
GetSection (
  IN EFI_SECTION_EXTRACTION_PROTOCOL                    *This,
  IN UINTN                                              SectionStreamHandle,
  IN EFI_SECTION_TYPE                                   *SectionType,
  IN EFI_GUID                                           *SectionDefinitionGuid,
  IN UINTN                                              SectionInstance,
  IN VOID                                               **Buffer,
  IN OUT UINTN                                          *BufferSize,
  OUT UINT32                                            *AuthenticationStatus
  )
/*++

Routine Description:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -