• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2 
3   The internal header file includes the common header files, defines
4   internal structure and functions used by FVB module.
5 
6 Copyright (c) 2010  - 2014, Intel Corporation. All rights reserved. <BR>
7 
8 
9   This program and the accompanying materials are licensed and made available under
10 
11   the terms and conditions of the BSD License that accompanies this distribution.
12 
13   The full text of the license may be found at
14 
15   http://opensource.org/licenses/bsd-license.php.
16 
17 
18 
19   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
20 
21   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 
23 
24 
25 
26 **/
27 
28 #ifndef _SMM_FVB_DXE_H_
29 #define _SMM_FVB_DXE_H_
30 
31 #include <PiDxe.h>
32 
33 #include <Protocol/SmmFirmwareVolumeBlock.h>
34 #include <Protocol/SmmCommunication.h>
35 
36 #include <Library/UefiBootServicesTableLib.h>
37 #include <Library/UefiDriverEntryPoint.h>
38 #include <Library/DebugLib.h>
39 #include <Library/BaseMemoryLib.h>
40 #include <Library/UefiLib.h>
41 #include <Library/BaseLib.h>
42 #include <Library/MemoryAllocationLib.h>
43 #include <Library/DevicePathLib.h>
44 
45 #include <Guid/EventGroup.h>
46 #include "FvbSmmCommon.h"
47 
48 #define FVB_DEVICE_SIGNATURE              SIGNATURE_32 ('F', 'V', 'B', 'S')
49 #define FVB_DEVICE_FROM_THIS(a)           CR (a, EFI_FVB_DEVICE, FvbInstance, FVB_DEVICE_SIGNATURE)
50 
51 typedef struct {
52   MEDIA_FW_VOL_DEVICE_PATH  FvDevPath;
53   EFI_DEVICE_PATH_PROTOCOL  EndDevPath;
54 } FV_PIWG_DEVICE_PATH;
55 
56 typedef struct {
57   MEMMAP_DEVICE_PATH          MemMapDevPath;
58   EFI_DEVICE_PATH_PROTOCOL    EndDevPath;
59 } FV_MEMMAP_DEVICE_PATH;
60 
61 typedef struct {
62   UINTN                                   Signature;
63   EFI_DEVICE_PATH_PROTOCOL                *DevicePath;
64   EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL      FvbInstance;
65   EFI_SMM_FIRMWARE_VOLUME_BLOCK_PROTOCOL  *SmmFvbInstance;
66 } EFI_FVB_DEVICE;
67 
68 /**
69   This function retrieves the attributes and current settings of the block.
70 
71   @param[in]  This       Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.
72 
73   @param[out] Attributes Pointer to EFI_FVB_ATTRIBUTES_2 in which the attributes
74                          and current settings are returned. Type EFI_FVB_ATTRIBUTES_2
75                          is defined in EFI_FIRMWARE_VOLUME_HEADER.
76 
77   @retval EFI_SUCCESS    The firmware volume attributes were returned.
78 
79 **/
80 EFI_STATUS
81 EFIAPI
82 FvbGetAttributes (
83   IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL   *This,
84      OUT   EFI_FVB_ATTRIBUTES_2                 *Attributes
85   );
86 
87 
88   /**
89   Sets Volume attributes. No polarity translations are done.
90 
91   @param[in]  This        Calling context.
92   @param[out] Attributes  Output buffer which contains attributes.
93 
94   @retval     EFI_SUCCESS The function always return successfully.
95 
96 **/
97 EFI_STATUS
98 EFIAPI
99 FvbSetAttributes (
100   IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL   *This,
101   IN OUT   EFI_FVB_ATTRIBUTES_2                 *Attributes
102   );
103 
104 
105 /**
106   Retrieves the physical address of the device.
107 
108   @param[in]  This    A pointer to EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL.
109   @param[out] Address Output buffer containing the address.
110 
111   @retval EFI_SUCCESS The function always return successfully.
112 
113 **/
114 EFI_STATUS
115 EFIAPI
116 FvbGetPhysicalAddress (
117   IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL  *This,
118      OUT   EFI_PHYSICAL_ADDRESS                *Address
119   );
120 
121 
122 /**
123   Retrieve the size of a logical block.
124 
125   @param[in]  This         Calling context.
126   @param[in]  Lba          Indicates which block to return the size for.
127   @param[out] BlockSize    A pointer to a caller allocated UINTN in which
128                            the size of the block is returned.
129   @param[out] NumOfBlocks  A pointer to a caller allocated UINTN in which the
130                            number of consecutive blocks starting with Lba is
131                            returned. All blocks in this range have a size of
132                            BlockSize.
133 
134   @retval     EFI_SUCCESS  The function always return successfully.
135 
136 **/
137 EFI_STATUS
138 EFIAPI
139 FvbGetBlockSize (
140   IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL  *This,
141   IN       EFI_LBA                             Lba,
142      OUT   UINTN                               *BlockSize,
143      OUT   UINTN                               *NumOfBlocks
144   );
145 
146 
147 /**
148   Reads data beginning at Lba:Offset from FV. The Read terminates either
149   when *NumBytes of data have been read, or when a block boundary is
150   reached.  *NumBytes is updated to reflect the actual number of bytes
151   written. The write opertion does not include erase. This routine will
152   attempt to write only the specified bytes. If the writes do not stick,
153   it will return an error.
154 
155   @param[in]      This           Calling context.
156   @param[in]      Lba            Block in which to begin write.
157   @param[in]      Offset         Offset in the block at which to begin write
158   @param[in,out]  NumBytes       On input, indicates the requested write size. On
159                                  output, indicates the actual number of bytes written
160   @param[in]      Buffer         Buffer containing source data for the write.
161 
162   @retval EFI_SUCCESS            The firmware volume was read successfully and
163                                  contents are in Buffer
164   @retval EFI_BAD_BUFFER_SIZE    Read attempted across a LBA boundary. On output,
165                                  NumBytes contains the total number of bytes returned
166                                  in Buffer
167   @retval EFI_ACCESS_DENIED      The firmware volume is in the ReadDisabled state
168   @retval EFI_DEVICE_ERROR       The block device is not functioning correctly and
169                                  could not be read
170   @retval EFI_INVALID_PARAMETER  NumBytes or Buffer are NULL
171 
172 **/
173 EFI_STATUS
174 EFIAPI
175 FvbRead (
176   IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL   *This,
177   IN       EFI_LBA                              Lba,
178   IN       UINTN                                Offset,
179   IN OUT   UINTN                                *NumBytes,
180      OUT   UINT8                                *Buffer
181   );
182 
183 
184 /**
185   Writes data beginning at Lba:Offset from FV. The write terminates either
186   when *NumBytes of data have been written, or when a block boundary is
187   reached.  *NumBytes is updated to reflect the actual number of bytes
188   written. The write opertion does not include erase. This routine will
189   attempt to write only the specified bytes. If the writes do not stick,
190   it will return an error.
191 
192   @param[in]      This           Calling context.
193   @param[in]      Lba            Block in which to begin write.
194   @param[in]      Offset         Offset in the block at which to begin write.
195   @param[in,out]  NumBytes       On input, indicates the requested write size. On
196                                  output, indicates the actual number of bytes written
197   @param[in]      Buffer         Buffer containing source data for the write.
198 
199   @retval EFI_SUCCESS            The firmware volume was written successfully
200   @retval EFI_BAD_BUFFER_SIZE    Write attempted across a LBA boundary. On output,
201                                  NumBytes contains the total number of bytes
202                                  actually written.
203   @retval EFI_ACCESS_DENIED      The firmware volume is in the WriteDisabled state
204   @retval EFI_DEVICE_ERROR       The block device is not functioning correctly and
205                                  could not be written.
206   @retval EFI_INVALID_PARAMETER  NumBytes or Buffer are NULL.
207 
208 **/
209 EFI_STATUS
210 EFIAPI
211 FvbWrite (
212   IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL   *This,
213   IN       EFI_LBA                              Lba,
214   IN       UINTN                                Offset,
215   IN OUT   UINTN                                *NumBytes,
216   IN       UINT8                                *Buffer
217   );
218 
219 
220 /**
221   The EraseBlock() function erases one or more blocks as denoted by the
222   variable argument list. The entire parameter list of blocks must be verified
223   prior to erasing any blocks.  If a block is requested that does not exist
224   within the associated firmware volume (it has a larger index than the last
225   block of the firmware volume), the EraseBlock() function must return
226   EFI_INVALID_PARAMETER without modifying the contents of the firmware volume.
227 
228   @param[in] This         Calling context.
229   @param[in] ...          Starting LBA followed by Number of Lba to erase.
230                           a -1 to terminate the list.
231 
232   @retval EFI_SUCCESS       The erase request was successfully completed.
233   @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled state
234   @retval EFI_DEVICE_ERROR  The block device is not functioning correctly and
235                             could not be written. Firmware device may have been
236                             partially erased.
237 
238 **/
239 EFI_STATUS
240 EFIAPI
241 FvbEraseBlocks (
242   IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL    *This,
243   ...
244   );
245 
246 #endif
247