Home | History | Annotate | Download | only in FwVolDxe
      1 /** @file
      2 
      3   Implements get/set firmware volume attributes.
      4 
      5   Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
      6 
      7   This program and the accompanying materials
      8   are licensed and made available under the terms and conditions
      9   of the BSD License which accompanies this distribution.  The
     10   full text of the license may be found at
     11   http://opensource.org/licenses/bsd-license.php
     12 
     13   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     14   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     15 
     16 **/
     17 
     18 #include "FwVolDriver.h"
     19 
     20 /**
     21   Retrieves attributes, insures positive polarity of attribute bits, returns
     22   resulting attributes in output parameter.
     23 
     24   @param  This             Calling context
     25   @param  Attributes       output buffer which contains attributes
     26 
     27   @retval EFI_SUCCESS      Successfully got volume attributes
     28 
     29 **/
     30 EFI_STATUS
     31 EFIAPI
     32 FvGetVolumeAttributes (
     33   IN  CONST EFI_FIRMWARE_VOLUME2_PROTOCOL  *This,
     34   OUT EFI_FV_ATTRIBUTES             *Attributes
     35   )
     36 {
     37   EFI_STATUS                          Status;
     38   FV_DEVICE                           *FvDevice;
     39   EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL  *Fvb;
     40   EFI_FVB_ATTRIBUTES_2                FvbAttributes;
     41 
     42   FvDevice  = FV_DEVICE_FROM_THIS (This);
     43   Fvb       = FvDevice->Fvb;
     44 
     45   //
     46   // First get the Firmware Volume Block Attributes
     47   //
     48   Status = Fvb->GetAttributes (Fvb, &FvbAttributes);
     49   FvbAttributes &= 0xfffff0ff;
     50 
     51   *Attributes = FvbAttributes;
     52   *Attributes |= EFI_FV2_WRITE_POLICY_RELIABLE;
     53   return Status;
     54 }
     55 
     56 /**
     57   Sets current attributes for volume.
     58 
     59   @param  This          Calling context
     60   @param  Attributes    On input, FvAttributes is a pointer to
     61                         an EFI_FV_ATTRIBUTES containing the
     62                         desired firmware volume settings. On
     63                         successful return, it contains the new
     64                         settings of the firmware volume. On
     65                         unsuccessful return, FvAttributes is not
     66                         modified and the firmware volume
     67                         settings are not changed.
     68 
     69   @retval EFI_SUCCESS             The requested firmware volume attributes
     70                                   were set and the resulting
     71                                   EFI_FV_ATTRIBUTES is returned in
     72                                   FvAttributes.
     73   @retval EFI_ACCESS_DENIED       Atrribute is locked down.
     74   @retval EFI_INVALID_PARAMETER   Atrribute is not valid.
     75 
     76 **/
     77 EFI_STATUS
     78 EFIAPI
     79 FvSetVolumeAttributes (
     80   IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL   *This,
     81   IN OUT EFI_FV_ATTRIBUTES          *Attributes
     82   )
     83 {
     84   EFI_STATUS                          Status;
     85   FV_DEVICE                           *FvDevice;
     86   EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL  *Fvb;
     87   EFI_FVB_ATTRIBUTES_2                OldFvbAttributes;
     88   EFI_FVB_ATTRIBUTES_2                NewFvbAttributes;
     89   UINT64                              NewStatus;
     90   UINT32                              Capabilities;
     91 
     92   FvDevice  = FV_DEVICE_FROM_THIS (This);
     93   Fvb       = FvDevice->Fvb;
     94 
     95   //
     96   // First get the current Volume Attributes
     97   //
     98   Status = Fvb->GetAttributes (
     99                   Fvb,
    100                   &OldFvbAttributes
    101                   );
    102 
    103   if ((OldFvbAttributes & EFI_FVB2_LOCK_STATUS) != 0) {
    104     return EFI_ACCESS_DENIED;
    105   }
    106   //
    107   // Only status attributes can be updated.
    108   //
    109   Capabilities  = OldFvbAttributes & EFI_FVB2_CAPABILITIES;
    110   NewStatus     = (*Attributes) & EFI_FVB2_STATUS;
    111 
    112   //
    113   // Test read disable
    114   //
    115   if ((Capabilities & EFI_FVB2_READ_DISABLED_CAP) == 0) {
    116     if ((NewStatus & EFI_FVB2_READ_STATUS) == 0) {
    117       return EFI_INVALID_PARAMETER;
    118     }
    119   }
    120   //
    121   // Test read enable
    122   //
    123   if ((Capabilities & EFI_FVB2_READ_ENABLED_CAP) == 0) {
    124     if ((NewStatus & EFI_FVB2_READ_STATUS) != 0) {
    125       return EFI_INVALID_PARAMETER;
    126     }
    127   }
    128   //
    129   // Test write disable
    130   //
    131   if ((Capabilities & EFI_FVB2_WRITE_DISABLED_CAP) == 0) {
    132     if ((NewStatus & EFI_FVB2_WRITE_STATUS) == 0) {
    133       return EFI_INVALID_PARAMETER;
    134     }
    135   }
    136   //
    137   // Test write enable
    138   //
    139   if ((Capabilities & EFI_FVB2_WRITE_ENABLED_CAP) == 0) {
    140     if ((NewStatus & EFI_FVB2_WRITE_STATUS) != 0) {
    141       return EFI_INVALID_PARAMETER;
    142     }
    143   }
    144   //
    145   // Test lock
    146   //
    147   if ((Capabilities & EFI_FVB2_LOCK_CAP) == 0) {
    148     if ((NewStatus & EFI_FVB2_LOCK_STATUS) != 0) {
    149       return EFI_INVALID_PARAMETER;
    150     }
    151   }
    152 
    153   NewFvbAttributes = OldFvbAttributes & (0xFFFFFFFF & (~EFI_FVB2_STATUS));
    154   NewFvbAttributes |= NewStatus;
    155   Status = Fvb->SetAttributes (
    156                   Fvb,
    157                   &NewFvbAttributes
    158                   );
    159 
    160   if (EFI_ERROR (Status)) {
    161     return Status;
    162   }
    163 
    164   *Attributes = 0;
    165 
    166   This->GetVolumeAttributes (
    167           This,
    168           Attributes
    169           );
    170 
    171   return EFI_SUCCESS;
    172 }
    173 
    174 /**
    175   Return information of type InformationType for the requested firmware
    176   volume.
    177 
    178   @param This             Pointer to EFI_FIRMWARE_VOLUME2_PROTOCOL.
    179   @param InformationType  InformationType for requested.
    180   @param BufferSize       On input, size of Buffer.On output, the amount of
    181                           data returned in Buffer.
    182   @param Buffer           A poniter to the data buffer to return.
    183 
    184   @return EFI_UNSUPPORTED Could not get.
    185 
    186 **/
    187 EFI_STATUS
    188 EFIAPI
    189 FvGetVolumeInfo (
    190   IN  CONST EFI_FIRMWARE_VOLUME2_PROTOCOL       *This,
    191   IN  CONST EFI_GUID                            *InformationType,
    192   IN OUT UINTN                                  *BufferSize,
    193   OUT VOID                                      *Buffer
    194   )
    195 {
    196   return EFI_UNSUPPORTED;
    197 }
    198 
    199 /**
    200   Set information with InformationType into the requested firmware volume.
    201 
    202   @param  This             Pointer to EFI_FIRMWARE_VOLUME2_PROTOCOL.
    203   @param  InformationType  InformationType for requested.
    204   @param  BufferSize       Size of Buffer data.
    205   @param  Buffer           A poniter to the data buffer to be set.
    206 
    207   @retval EFI_UNSUPPORTED  Could not set.
    208 
    209 **/
    210 EFI_STATUS
    211 EFIAPI
    212 FvSetVolumeInfo (
    213   IN  CONST EFI_FIRMWARE_VOLUME2_PROTOCOL       *This,
    214   IN  CONST EFI_GUID                            *InformationType,
    215   IN  UINTN                                     BufferSize,
    216   IN CONST  VOID                                *Buffer
    217   )
    218 {
    219   return EFI_UNSUPPORTED;
    220 }
    221