Home | History | Annotate | Download | only in FvbRuntimeDxe
      1 /** @file
      2   The header file for Firmware volume block driver.
      3 
      4 Copyright (c) 2006  - 2014, Intel Corporation. All rights reserved.<BR>
      5 
      6   This program and the accompanying materials are licensed and made available under
      8   the terms and conditions of the BSD License that accompanies this distribution.
     10   The full text of the license may be found at
     12   http://opensource.org/licenses/bsd-license.php.
     14 
     16   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     18   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     20 
     22 
     24 **/
     25 
     26 #ifndef _FW_BLOCK_SERVICE_H
     27 #define _FW_BLOCK_SERVICE_H
     28 
     29 #include <Guid/EventGroup.h>
     30 #include <Guid/FirmwareFileSystem2.h>
     31 #include <Guid/SystemNvDataGuid.h>
     32 #include <Protocol/DevicePath.h>
     33 #include <Protocol/FirmwareVolumeBlock.h>
     34 
     35 #include <Library/UefiDriverEntryPoint.h>
     36 #include <Library/UefiBootServicesTableLib.h>
     37 #include <Library/UefiLib.h>
     38 #include <Library/BaseLib.h>
     39 #include <Library/DebugLib.h>
     40 #include <Library/BaseMemoryLib.h>
     41 #include <Library/IoLib.h>
     42 #include <Library/CacheMaintenanceLib.h>
     43 #include <Library/MemoryAllocationLib.h>
     44 #include <Library/PcdLib.h>
     45 #include <Library/FlashDeviceLib.h>
     46 #include <Library/DevicePathLib.h>
     47 
     48 //
     49 // Define two helper macro to extract the Capability field or Status field in FVB
     50 // bit fields.
     51 //
     52 #define EFI_FVB2_CAPABILITIES (EFI_FVB2_READ_DISABLED_CAP | \
     53                               EFI_FVB2_READ_ENABLED_CAP | \
     54                               EFI_FVB2_WRITE_DISABLED_CAP | \
     55                               EFI_FVB2_WRITE_ENABLED_CAP | \
     56                               EFI_FVB2_LOCK_CAP \
     57                               )
     58 
     59 #define EFI_FVB2_STATUS (EFI_FVB2_READ_STATUS | EFI_FVB2_WRITE_STATUS | EFI_FVB2_LOCK_STATUS)
     60 
     61 
     62 typedef struct {
     63   UINTN                       FvBase;
     64   UINTN                       NumOfBlocks;
     65   //
     66   // Note!!!: VolumeHeader must be the last element
     67   // of the structure.
     68   //
     69   EFI_FIRMWARE_VOLUME_HEADER  VolumeHeader;
     70 } EFI_FW_VOL_INSTANCE;
     71 
     72 typedef struct {
     73   EFI_FW_VOL_INSTANCE         *FvInstance;
     74   UINT32                      NumFv;
     75 } FWB_GLOBAL;
     76 
     77 //
     78 // Fvb Protocol instance data.
     79 //
     80 #define FVB_DEVICE_FROM_THIS(a) CR(a, EFI_FW_VOL_BLOCK_DEVICE, FwVolBlockInstance, FVB_DEVICE_SIGNATURE)
     81 #define FVB_EXTEND_DEVICE_FROM_THIS(a) CR(a, EFI_FW_VOL_BLOCK_DEVICE, FvbExtension, FVB_DEVICE_SIGNATURE)
     82 #define FVB_DEVICE_SIGNATURE       SIGNATURE_32('F','V','B','C')
     83 
     84 typedef struct {
     85   MEDIA_FW_VOL_DEVICE_PATH  FvDevPath;
     86   EFI_DEVICE_PATH_PROTOCOL  EndDevPath;
     87 } FV_PIWG_DEVICE_PATH;
     88 
     89 typedef struct {
     90   MEMMAP_DEVICE_PATH          MemMapDevPath;
     91   EFI_DEVICE_PATH_PROTOCOL    EndDevPath;
     92 } FV_MEMMAP_DEVICE_PATH;
     93 
     94 typedef struct {
     95   UINT32                                Signature;
     96   EFI_DEVICE_PATH_PROTOCOL              *DevicePath;
     97   UINTN                                 Instance;
     98   EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL    FwVolBlockInstance;
     99 } EFI_FW_VOL_BLOCK_DEVICE;
    100 
    101 EFI_STATUS
    102 GetFvbInfo (
    103   IN  EFI_PHYSICAL_ADDRESS              FvBaseAddress,
    104   OUT EFI_FIRMWARE_VOLUME_HEADER        **FvbInfo
    105   );
    106 
    107 //
    108 // Protocol APIs
    109 //
    110 EFI_STATUS
    111 EFIAPI
    112 FvbProtocolGetAttributes (
    113   IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL   *This,
    114   OUT EFI_FVB_ATTRIBUTES_2                      *Attributes
    115   );
    116 
    117 EFI_STATUS
    118 EFIAPI
    119 FvbProtocolSetAttributes (
    120   IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL   *This,
    121   IN OUT EFI_FVB_ATTRIBUTES_2                   *Attributes
    122   );
    123 
    124 EFI_STATUS
    125 EFIAPI
    126 FvbProtocolGetPhysicalAddress (
    127   IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL  *This,
    128        OUT EFI_PHYSICAL_ADDRESS                *Address
    129   );
    130 
    131 EFI_STATUS
    132 EFIAPI
    133 FvbProtocolGetBlockSize (
    134   IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL  *This,
    135   IN  EFI_LBA                            Lba,
    136   OUT UINTN                              *BlockSize,
    137   OUT UINTN                              *NumOfBlocks
    138   );
    139 
    140 EFI_STATUS
    141 EFIAPI
    142 FvbProtocolRead (
    143   IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL   *This,
    144   IN EFI_LBA                              Lba,
    145   IN UINTN                                Offset,
    146   IN OUT UINTN                            *NumBytes,
    147   OUT UINT8                                *Buffer
    148   );
    149 
    150 EFI_STATUS
    151 EFIAPI
    152 FvbProtocolWrite (
    153   IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL   *This,
    154   IN EFI_LBA                              Lba,
    155   IN UINTN                                Offset,
    156   IN OUT UINTN                            *NumBytes,
    157   IN UINT8                                *Buffer
    158   );
    159 
    160 EFI_STATUS
    161 EFIAPI
    162 FvbProtocolEraseBlocks (
    163   IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL    *This,
    164   ...
    165   );
    166 
    167 EFI_FW_VOL_INSTANCE *
    168 GetFvbInstance (
    169   IN  UINTN                              Instance
    170   );
    171 
    172 BOOLEAN
    173 IsFvHeaderValid (
    174   IN       EFI_PHYSICAL_ADDRESS          FvBase,
    175   IN CONST EFI_FIRMWARE_VOLUME_HEADER    *FwVolHeader
    176   );
    177 
    178 VOID
    179 InstallFvbProtocol (
    180   IN  EFI_FW_VOL_INSTANCE               *FwhInstance,
    181   IN  UINTN                             InstanceNum
    182   );
    183 
    184 EFI_STATUS
    185 FvbInitialize (
    186   VOID
    187   );
    188 
    189 extern FWB_GLOBAL              mFvbModuleGlobal;
    190 extern EFI_FW_VOL_BLOCK_DEVICE mFvbDeviceTemplate;
    191 extern FV_MEMMAP_DEVICE_PATH   mFvMemmapDevicePathTemplate;
    192 extern FV_PIWG_DEVICE_PATH     mFvPIWGDevicePathTemplate;
    193 extern UINT32                  mPlatformFvBaseAddress[3];
    194 
    195 #endif
    196 
    197