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