MdeModulePkg CdExpressPei: Use correct PeiServices pointer to call low level BlockIoP...
[mirror_edk2.git] / MdeModulePkg / Universal / Disk / CdExpressPei / PeiCdExpress.h
1 /** @file
2 Header file for CD recovery PEIM
3
4 Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
5
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions
8 of the BSD License which accompanies this distribution. The
9 full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 **/
16
17 #ifndef _PEI_CD_EXPRESS_H_
18 #define _PEI_CD_EXPRESS_H_
19
20
21 #include <PiPei.h>
22
23 #include <Ppi/BlockIo.h>
24 #include <Guid/RecoveryDevice.h>
25 #include <Ppi/DeviceRecoveryModule.h>
26
27 #include <Library/DebugLib.h>
28 #include <Library/PcdLib.h>
29 #include <Library/PeimEntryPoint.h>
30 #include <Library/BaseMemoryLib.h>
31 #include <Library/PeiServicesTablePointerLib.h>
32 #include <Library/PeiServicesLib.h>
33 #include <Library/MemoryAllocationLib.h>
34
35
36 #pragma pack(1)
37
38 #define PEI_CD_EXPRESS_MAX_BLOCK_IO_PPI 8
39 #define PEI_CD_EXPRESS_MAX_CAPSULE_NUMBER 16
40
41 #define PEI_CD_BLOCK_SIZE 0x800
42 #define PEI_MEMMORY_PAGE_SIZE 0x1000
43
44 //
45 // Recovery file name (in root directory)
46 //
47 #define PEI_RECOVERY_FILE_NAME "FVMAIN.FV"
48
49 //
50 // Following are defined according to ISO-9660 specification
51 //
52 #define PEI_CD_STANDARD_ID "CD001"
53 #define PEI_CD_EXPRESS_STANDARD_ID_SIZE 5
54
55 #define PEI_CD_EXPRESS_VOLUME_TYPE_OFFSET 0
56 #define PEI_CD_EXPRESS_STANDARD_ID_OFFSET 1
57 #define PEI_CD_EXPRESS_VOLUME_SPACE_OFFSET 80
58 #define PEI_CD_EXPRESS_ROOT_DIR_RECORD_OFFSET 156
59
60 #define PEI_CD_EXPRESS_VOLUME_TYPE_PRIMARY 1
61 #define PEI_CD_EXPRESS_VOLUME_TYPE_TERMINATOR 255
62
63 #define PEI_CD_EXPRESS_DIR_FILE_REC_FLAG_ISDIR 0x02
64
65 typedef struct {
66 UINTN CapsuleStartLBA;
67 UINTN CapsuleSize;
68 UINTN IndexBlock;
69 EFI_PEI_RECOVERY_BLOCK_IO_PPI *BlockIo;
70 } PEI_CD_EXPRESS_CAPSULE_DATA;
71
72 #define PEI_CD_EXPRESS_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('p', 'c', 'd', 'e')
73
74 typedef struct {
75
76 UINTN Signature;
77 EFI_PEI_DEVICE_RECOVERY_MODULE_PPI DeviceRecoveryPpi;
78 EFI_PEI_PPI_DESCRIPTOR PpiDescriptor;
79 EFI_PEI_NOTIFY_DESCRIPTOR NotifyDescriptor;
80
81 UINT8 *BlockBuffer;
82 UINTN CapsuleCount;
83 PEI_CD_EXPRESS_CAPSULE_DATA CapsuleData[PEI_CD_EXPRESS_MAX_CAPSULE_NUMBER];
84
85 } PEI_CD_EXPRESS_PRIVATE_DATA;
86
87 #define PEI_CD_EXPRESS_PRIVATE_DATA_FROM_THIS(a) \
88 CR (a, \
89 PEI_CD_EXPRESS_PRIVATE_DATA, \
90 DeviceRecoveryPpi, \
91 PEI_CD_EXPRESS_PRIVATE_DATA_SIGNATURE \
92 )
93
94 typedef struct {
95 UINT8 Length;
96 UINT8 ExtendedAttributeRecordLength;
97 UINT32 LocationOfExtent[2];
98 UINT32 DataLength[2];
99 UINT8 DateTime[7];
100 UINT8 Flag;
101 UINT8 FileUnitSize;
102 UINT8 InterleaveGapSize;
103 UINT32 VolumeSequenceNumber;
104 UINT8 FileIDLength;
105 UINT8 FileID[1];
106 } PEI_CD_EXPRESS_DIR_FILE_RECORD;
107
108 /**
109 BlockIo installation notification function.
110
111 This function finds out all the current Block IO PPIs in the system and add them
112 into private data.
113
114 @param PeiServices Indirect reference to the PEI Services Table.
115 @param NotifyDescriptor Address of the notification descriptor data structure.
116 @param Ppi Address of the PPI that was installed.
117
118 @retval EFI_SUCCESS The function completes successfully.
119
120 **/
121 EFI_STATUS
122 EFIAPI
123 BlockIoNotifyEntry (
124 IN EFI_PEI_SERVICES **PeiServices,
125 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
126 IN VOID *Ppi
127 );
128
129 /**
130 Finds out all the current Block IO PPIs in the system and add them into private data.
131
132 @param PrivateData The private data structure that contains recovery module information.
133
134 @retval EFI_SUCCESS The blocks and volumes are updated successfully.
135
136 **/
137 EFI_STATUS
138 UpdateBlocksAndVolumes (
139 IN OUT PEI_CD_EXPRESS_PRIVATE_DATA *PrivateData
140 );
141
142 /**
143 Returns the number of DXE capsules residing on the device.
144
145 This function searches for DXE capsules from the associated device and returns
146 the number and maximum size in bytes of the capsules discovered. Entry 1 is
147 assumed to be the highest load priority and entry N is assumed to be the lowest
148 priority.
149
150 @param[in] PeiServices General-purpose services that are available
151 to every PEIM
152 @param[in] This Indicates the EFI_PEI_DEVICE_RECOVERY_MODULE_PPI
153 instance.
154 @param[out] NumberRecoveryCapsules Pointer to a caller-allocated UINTN. On
155 output, *NumberRecoveryCapsules contains
156 the number of recovery capsule images
157 available for retrieval from this PEIM
158 instance.
159
160 @retval EFI_SUCCESS One or more capsules were discovered.
161 @retval EFI_DEVICE_ERROR A device error occurred.
162 @retval EFI_NOT_FOUND A recovery DXE capsule cannot be found.
163
164 **/
165 EFI_STATUS
166 EFIAPI
167 GetNumberRecoveryCapsules (
168 IN EFI_PEI_SERVICES **PeiServices,
169 IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
170 OUT UINTN *NumberRecoveryCapsules
171 );
172
173 /**
174 Returns the size and type of the requested recovery capsule.
175
176 This function gets the size and type of the capsule specified by CapsuleInstance.
177
178 @param[in] PeiServices General-purpose services that are available to every PEIM
179 @param[in] This Indicates the EFI_PEI_DEVICE_RECOVERY_MODULE_PPI
180 instance.
181 @param[in] CapsuleInstance Specifies for which capsule instance to retrieve
182 the information. This parameter must be between
183 one and the value returned by GetNumberRecoveryCapsules()
184 in NumberRecoveryCapsules.
185 @param[out] Size A pointer to a caller-allocated UINTN in which
186 the size of the requested recovery module is
187 returned.
188 @param[out] CapsuleType A pointer to a caller-allocated EFI_GUID in which
189 the type of the requested recovery capsule is
190 returned. The semantic meaning of the value
191 returned is defined by the implementation.
192
193 @retval EFI_SUCCESS One or more capsules were discovered.
194 @retval EFI_DEVICE_ERROR A device error occurred.
195 @retval EFI_NOT_FOUND A recovery DXE capsule cannot be found.
196
197 **/
198 EFI_STATUS
199 EFIAPI
200 GetRecoveryCapsuleInfo (
201 IN EFI_PEI_SERVICES **PeiServices,
202 IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
203 IN UINTN CapsuleInstance,
204 OUT UINTN *Size,
205 OUT EFI_GUID *CapsuleType
206 );
207
208 /**
209 Loads a DXE capsule from some media into memory.
210
211 This function, by whatever mechanism, retrieves a DXE capsule from some device
212 and loads it into memory. Note that the published interface is device neutral.
213
214 @param[in] PeiServices General-purpose services that are available
215 to every PEIM
216 @param[in] This Indicates the EFI_PEI_DEVICE_RECOVERY_MODULE_PPI
217 instance.
218 @param[in] CapsuleInstance Specifies which capsule instance to retrieve.
219 @param[out] Buffer Specifies a caller-allocated buffer in which
220 the requested recovery capsule will be returned.
221
222 @retval EFI_SUCCESS The capsule was loaded correctly.
223 @retval EFI_DEVICE_ERROR A device error occurred.
224 @retval EFI_NOT_FOUND A requested recovery DXE capsule cannot be found.
225
226 **/
227 EFI_STATUS
228 EFIAPI
229 LoadRecoveryCapsule (
230 IN EFI_PEI_SERVICES **PeiServices,
231 IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
232 IN UINTN CapsuleInstance,
233 OUT VOID *Buffer
234 );
235
236 /**
237 Finds out the recovery capsule in the current volume.
238
239 @param PrivateData The private data structure that contains recovery module information.
240
241 @retval EFI_SUCCESS The recovery capsule is successfully found in the volume.
242 @retval EFI_NOT_FOUND The recovery capsule is not found in the volume.
243
244 **/
245 EFI_STATUS
246 EFIAPI
247 FindRecoveryCapsules (
248 IN OUT PEI_CD_EXPRESS_PRIVATE_DATA *PrivateData
249 );
250
251 /**
252 Retrieves the recovery capsule in root directory of the current volume.
253
254 @param PrivateData The private data structure that contains recovery module information.
255 @param BlockIoPpi The Block IO PPI used to access the volume.
256 @param IndexBlockDevice The index of current block device.
257 @param Lba The starting logic block address to retrieve capsule.
258
259 @retval EFI_SUCCESS The recovery capsule is successfully found in the volume.
260 @retval EFI_NOT_FOUND The recovery capsule is not found in the volume.
261 @retval Others
262
263 **/
264 EFI_STATUS
265 EFIAPI
266 RetrieveCapsuleFileFromRoot (
267 IN OUT PEI_CD_EXPRESS_PRIVATE_DATA *PrivateData,
268 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *BlockIoPpi,
269 IN UINTN IndexBlockDevice,
270 IN UINT32 Lba
271 );
272
273
274 /**
275 This function compares two ASCII strings in case sensitive/insensitive way.
276
277 @param Source1 The first string.
278 @param Source2 The second string.
279 @param Size The maximum comparison length.
280 @param CaseSensitive Flag to indicate whether the comparison is case sensitive.
281
282 @retval TRUE The two strings are the same.
283 @retval FALSE The two string are not the same.
284
285 **/
286 BOOLEAN
287 StringCmp (
288 IN UINT8 *Source1,
289 IN UINT8 *Source2,
290 IN UINTN Size,
291 IN BOOLEAN CaseSensitive
292 );
293
294 #pragma pack()
295
296 #endif