]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.h
e194951805899108dc7ea6edc404f33a958a29c8
[mirror_edk2.git] / MdeModulePkg / Universal / Disk / RamDiskDxe / RamDiskImpl.h
1 /** @file
2 The header file of RamDiskDxe driver.
3
4 Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) Microsoft Corporation.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #ifndef _RAM_DISK_IMPL_H_
11 #define _RAM_DISK_IMPL_H_
12
13 #include <Uefi.h>
14 #include <Library/BaseLib.h>
15 #include <Library/BaseMemoryLib.h>
16 #include <Library/DebugLib.h>
17 #include <Library/UefiLib.h>
18 #include <Library/UefiDriverEntryPoint.h>
19 #include <Library/UefiBootServicesTableLib.h>
20 #include <Library/UefiHiiServicesLib.h>
21 #include <Library/MemoryAllocationLib.h>
22 #include <Library/HiiLib.h>
23 #include <Library/FileExplorerLib.h>
24 #include <Library/DevicePathLib.h>
25 #include <Library/PrintLib.h>
26 #include <Library/PcdLib.h>
27 #include <Library/DxeServicesLib.h>
28 #include <Protocol/RamDisk.h>
29 #include <Protocol/BlockIo.h>
30 #include <Protocol/BlockIo2.h>
31 #include <Protocol/HiiConfigAccess.h>
32 #include <Protocol/SimpleFileSystem.h>
33 #include <Protocol/AcpiTable.h>
34 #include <Protocol/AcpiSystemDescriptionTable.h>
35 #include <Guid/MdeModuleHii.h>
36 #include <Guid/RamDiskHii.h>
37 #include <Guid/FileInfo.h>
38 #include <IndustryStandard/Acpi61.h>
39
40 #include "RamDiskNVData.h"
41
42 ///
43 /// RAM disk general definitions and declarations
44 ///
45
46 //
47 // Default block size for RAM disk
48 //
49 #define RAM_DISK_DEFAULT_BLOCK_SIZE 512
50
51 //
52 // RamDiskDxe driver maintains a list of registered RAM disks.
53 //
54 extern LIST_ENTRY RegisteredRamDisks;
55
56 //
57 // Pointers to the EFI_ACPI_TABLE_PROTOCOL and EFI_ACPI_SDT_PROTOCOL.
58 //
59 extern EFI_ACPI_TABLE_PROTOCOL *mAcpiTableProtocol;
60 extern EFI_ACPI_SDT_PROTOCOL *mAcpiSdtProtocol;
61
62 //
63 // RAM Disk create method.
64 //
65 typedef enum _RAM_DISK_CREATE_METHOD {
66 RamDiskCreateOthers = 0,
67 RamDiskCreateHii
68 } RAM_DISK_CREATE_METHOD;
69
70 //
71 // RamDiskDxe driver maintains a list of registered RAM disks.
72 // The struct contains the list entry and the information of each RAM
73 // disk
74 //
75 typedef struct {
76 UINTN Signature;
77
78 EFI_HANDLE Handle;
79
80 EFI_BLOCK_IO_PROTOCOL BlockIo;
81 EFI_BLOCK_IO2_PROTOCOL BlockIo2;
82 EFI_BLOCK_IO_MEDIA Media;
83 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
84
85 UINT64 StartingAddr;
86 UINT64 Size;
87 EFI_GUID TypeGuid;
88 UINT16 InstanceNumber;
89 RAM_DISK_CREATE_METHOD CreateMethod;
90 BOOLEAN InNfit;
91 EFI_QUESTION_ID CheckBoxId;
92 BOOLEAN CheckBoxChecked;
93
94 LIST_ENTRY ThisInstance;
95 } RAM_DISK_PRIVATE_DATA;
96
97 #define RAM_DISK_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('R', 'D', 'S', 'K')
98 #define RAM_DISK_PRIVATE_FROM_BLKIO(a) CR (a, RAM_DISK_PRIVATE_DATA, BlockIo, RAM_DISK_PRIVATE_DATA_SIGNATURE)
99 #define RAM_DISK_PRIVATE_FROM_BLKIO2(a) CR (a, RAM_DISK_PRIVATE_DATA, BlockIo2, RAM_DISK_PRIVATE_DATA_SIGNATURE)
100 #define RAM_DISK_PRIVATE_FROM_THIS(a) CR (a, RAM_DISK_PRIVATE_DATA, ThisInstance, RAM_DISK_PRIVATE_DATA_SIGNATURE)
101
102 ///
103 /// RAM disk HII-related definitions and declarations
104 ///
105
106 //
107 // Tool generated IFR binary data and String package data
108 //
109 extern UINT8 RamDiskHiiBin[];
110 extern UINT8 RamDiskDxeStrings[];
111
112 typedef struct {
113 VENDOR_DEVICE_PATH VendorDevicePath;
114 EFI_DEVICE_PATH_PROTOCOL End;
115 } HII_VENDOR_DEVICE_PATH;
116
117 typedef struct {
118 UINTN Signature;
119
120 RAM_DISK_CONFIGURATION ConfigStore;
121
122 EFI_HII_CONFIG_ACCESS_PROTOCOL ConfigAccess;
123 EFI_HANDLE DriverHandle;
124 EFI_HII_HANDLE HiiHandle;
125 } RAM_DISK_CONFIG_PRIVATE_DATA;
126
127 extern RAM_DISK_CONFIG_PRIVATE_DATA mRamDiskConfigPrivateDataTemplate;
128
129 #define RAM_DISK_CONFIG_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('R', 'C', 'F', 'G')
130 #define RAM_DISK_CONFIG_PRIVATE_FROM_THIS(a) CR (a, RAM_DISK_CONFIG_PRIVATE_DATA, ConfigAccess, RAM_DISK_CONFIG_PRIVATE_DATA_SIGNATURE)
131
132 /**
133 Register a RAM disk with specified address, size and type.
134
135 @param[in] RamDiskBase The base address of registered RAM disk.
136 @param[in] RamDiskSize The size of registered RAM disk.
137 @param[in] RamDiskType The type of registered RAM disk. The GUID can be
138 any of the values defined in section 9.3.6.9, or a
139 vendor defined GUID.
140 @param[in] ParentDevicePath
141 Pointer to the parent device path. If there is no
142 parent device path then ParentDevicePath is NULL.
143 @param[out] DevicePath On return, points to a pointer to the device path
144 of the RAM disk device.
145 If ParentDevicePath is not NULL, the returned
146 DevicePath is created by appending a RAM disk node
147 to the parent device path. If ParentDevicePath is
148 NULL, the returned DevicePath is a RAM disk device
149 path without appending. This function is
150 responsible for allocating the buffer DevicePath
151 with the boot service AllocatePool().
152
153 @retval EFI_SUCCESS The RAM disk is registered successfully.
154 @retval EFI_INVALID_PARAMETER DevicePath or RamDiskType is NULL.
155 RamDiskSize is 0.
156 @retval EFI_ALREADY_STARTED A Device Path Protocol instance to be created
157 is already present in the handle database.
158 @retval EFI_OUT_OF_RESOURCES The RAM disk register operation fails due to
159 resource limitation.
160
161 **/
162 EFI_STATUS
163 EFIAPI
164 RamDiskRegister (
165 IN UINT64 RamDiskBase,
166 IN UINT64 RamDiskSize,
167 IN EFI_GUID *RamDiskType,
168 IN EFI_DEVICE_PATH *ParentDevicePath OPTIONAL,
169 OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
170 );
171
172 /**
173 Unregister a RAM disk specified by DevicePath.
174
175 @param[in] DevicePath A pointer to the device path that describes a RAM
176 Disk device.
177
178 @retval EFI_SUCCESS The RAM disk is unregistered successfully.
179 @retval EFI_INVALID_PARAMETER DevicePath is NULL.
180 @retval EFI_UNSUPPORTED The device specified by DevicePath is not a
181 valid ramdisk device path and not supported
182 by the driver.
183 @retval EFI_NOT_FOUND The RAM disk pointed by DevicePath doesn't
184 exist.
185
186 **/
187 EFI_STATUS
188 EFIAPI
189 RamDiskUnregister (
190 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
191 );
192
193 /**
194 Initialize the BlockIO protocol of a RAM disk device.
195
196 @param[in] PrivateData Points to RAM disk private data.
197
198 **/
199 VOID
200 RamDiskInitBlockIo (
201 IN RAM_DISK_PRIVATE_DATA *PrivateData
202 );
203
204 /**
205 Reset the Block Device.
206
207 @param[in] This Indicates a pointer to the calling context.
208 @param[in] ExtendedVerification
209 Driver may perform diagnostics on reset.
210
211 @retval EFI_SUCCESS The device was reset.
212 @retval EFI_DEVICE_ERROR The device is not functioning properly and
213 could not be reset.
214
215 **/
216 EFI_STATUS
217 EFIAPI
218 RamDiskBlkIoReset (
219 IN EFI_BLOCK_IO_PROTOCOL *This,
220 IN BOOLEAN ExtendedVerification
221 );
222
223 /**
224 Read BufferSize bytes from Lba into Buffer.
225
226 @param[in] This Indicates a pointer to the calling context.
227 @param[in] MediaId Id of the media, changes every time the media is
228 replaced.
229 @param[in] Lba The starting Logical Block Address to read from.
230 @param[in] BufferSize Size of Buffer, must be a multiple of device block
231 size.
232 @param[out] Buffer A pointer to the destination buffer for the data.
233 The caller is responsible for either having
234 implicit or explicit ownership of the buffer.
235
236 @retval EFI_SUCCESS The data was read correctly from the device.
237 @retval EFI_DEVICE_ERROR The device reported an error while performing
238 the read.
239 @retval EFI_NO_MEDIA There is no media in the device.
240 @retval EFI_MEDIA_CHANGED The MediaId does not matched the current
241 device.
242 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block
243 size of the device.
244 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
245 valid, or the buffer is not on proper alignment.
246
247 **/
248 EFI_STATUS
249 EFIAPI
250 RamDiskBlkIoReadBlocks (
251 IN EFI_BLOCK_IO_PROTOCOL *This,
252 IN UINT32 MediaId,
253 IN EFI_LBA Lba,
254 IN UINTN BufferSize,
255 OUT VOID *Buffer
256 );
257
258 /**
259 Write BufferSize bytes from Lba into Buffer.
260
261 @param[in] This Indicates a pointer to the calling context.
262 @param[in] MediaId The media ID that the write request is for.
263 @param[in] Lba The starting logical block address to be written.
264 The caller is responsible for writing to only
265 legitimate locations.
266 @param[in] BufferSize Size of Buffer, must be a multiple of device block
267 size.
268 @param[in] Buffer A pointer to the source buffer for the data.
269
270 @retval EFI_SUCCESS The data was written correctly to the device.
271 @retval EFI_WRITE_PROTECTED The device can not be written to.
272 @retval EFI_DEVICE_ERROR The device reported an error while performing
273 the write.
274 @retval EFI_NO_MEDIA There is no media in the device.
275 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current
276 device.
277 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block
278 size of the device.
279 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not
280 valid, or the buffer is not on proper alignment.
281
282 **/
283 EFI_STATUS
284 EFIAPI
285 RamDiskBlkIoWriteBlocks (
286 IN EFI_BLOCK_IO_PROTOCOL *This,
287 IN UINT32 MediaId,
288 IN EFI_LBA Lba,
289 IN UINTN BufferSize,
290 IN VOID *Buffer
291 );
292
293 /**
294 Flush the Block Device.
295
296 @param[in] This Indicates a pointer to the calling context.
297
298 @retval EFI_SUCCESS All outstanding data was written to the device.
299 @retval EFI_DEVICE_ERROR The device reported an error while writting
300 back the data
301 @retval EFI_NO_MEDIA There is no media in the device.
302
303 **/
304 EFI_STATUS
305 EFIAPI
306 RamDiskBlkIoFlushBlocks (
307 IN EFI_BLOCK_IO_PROTOCOL *This
308 );
309
310 /**
311 Resets the block device hardware.
312
313 @param[in] This The pointer of EFI_BLOCK_IO2_PROTOCOL.
314 @param[in] ExtendedVerification The flag about if extend verificate.
315
316 @retval EFI_SUCCESS The device was reset.
317 @retval EFI_DEVICE_ERROR The block device is not functioning correctly
318 and could not be reset.
319
320 **/
321 EFI_STATUS
322 EFIAPI
323 RamDiskBlkIo2Reset (
324 IN EFI_BLOCK_IO2_PROTOCOL *This,
325 IN BOOLEAN ExtendedVerification
326 );
327
328 /**
329 Reads the requested number of blocks from the device.
330
331 @param[in] This Indicates a pointer to the calling context.
332 @param[in] MediaId The media ID that the read request is for.
333 @param[in] Lba The starting logical block address to read
334 from on the device.
335 @param[in, out] Token A pointer to the token associated with the
336 transaction.
337 @param[in] BufferSize The size of the Buffer in bytes. This must be
338 a multiple of the intrinsic block size of the
339 device.
340 @param[out] Buffer A pointer to the destination buffer for the
341 data. The caller is responsible for either
342 having implicit or explicit ownership of the
343 buffer.
344
345 @retval EFI_SUCCESS The read request was queued if Token->Event
346 is not NULL. The data was read correctly from
347 the device if the Token->Event is NULL.
348 @retval EFI_DEVICE_ERROR The device reported an error while attempting
349 to perform the read operation.
350 @retval EFI_NO_MEDIA There is no media in the device.
351 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
352 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
353 the intrinsic block size of the device.
354 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
355 valid, or the buffer is not on proper
356 alignment.
357 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
358 lack of resources.
359
360 **/
361 EFI_STATUS
362 EFIAPI
363 RamDiskBlkIo2ReadBlocksEx (
364 IN EFI_BLOCK_IO2_PROTOCOL *This,
365 IN UINT32 MediaId,
366 IN EFI_LBA Lba,
367 IN OUT EFI_BLOCK_IO2_TOKEN *Token,
368 IN UINTN BufferSize,
369 OUT VOID *Buffer
370 );
371
372 /**
373 Writes a specified number of blocks to the device.
374
375 @param[in] This Indicates a pointer to the calling context.
376 @param[in] MediaId The media ID that the write request is for.
377 @param[in] Lba The starting logical block address to be
378 written. The caller is responsible for
379 writing to only legitimate locations.
380 @param[in, out] Token A pointer to the token associated with the
381 transaction.
382 @param[in] BufferSize The size in bytes of Buffer. This must be a
383 multiple of the intrinsic block size of the
384 device.
385 @param[in] Buffer A pointer to the source buffer for the data.
386
387 @retval EFI_SUCCESS The write request was queued if Event is not
388 NULL. The data was written correctly to the
389 device if the Event is NULL.
390 @retval EFI_WRITE_PROTECTED The device cannot be written to.
391 @retval EFI_NO_MEDIA There is no media in the device.
392 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
393 @retval EFI_DEVICE_ERROR The device reported an error while attempting
394 to perform the write operation.
395 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
396 the intrinsic block size of the device.
397 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not
398 valid, or the buffer is not on proper
399 alignment.
400 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
401 lack of resources.
402
403 **/
404 EFI_STATUS
405 EFIAPI
406 RamDiskBlkIo2WriteBlocksEx (
407 IN EFI_BLOCK_IO2_PROTOCOL *This,
408 IN UINT32 MediaId,
409 IN EFI_LBA Lba,
410 IN OUT EFI_BLOCK_IO2_TOKEN *Token,
411 IN UINTN BufferSize,
412 IN VOID *Buffer
413 );
414
415 /**
416 Flushes all modified data to a physical block device.
417
418 @param[in] This Indicates a pointer to the calling context.
419 @param[in, out] Token A pointer to the token associated with the
420 transaction.
421
422 @retval EFI_SUCCESS The flush request was queued if Event is not
423 NULL. All outstanding data was written
424 correctly to the device if the Event is NULL.
425 @retval EFI_DEVICE_ERROR The device reported an error while attempting
426 to write data.
427 @retval EFI_WRITE_PROTECTED The device cannot be written to.
428 @retval EFI_NO_MEDIA There is no media in the device.
429 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
430 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
431 lack of resources.
432
433 **/
434 EFI_STATUS
435 EFIAPI
436 RamDiskBlkIo2FlushBlocksEx (
437 IN EFI_BLOCK_IO2_PROTOCOL *This,
438 IN OUT EFI_BLOCK_IO2_TOKEN *Token
439 );
440
441 /**
442 This function publish the RAM disk configuration Form.
443
444 @param[in, out] ConfigPrivateData
445 Points to RAM disk configuration private data.
446
447 @retval EFI_SUCCESS HII Form is installed successfully.
448 @retval EFI_OUT_OF_RESOURCES Not enough resource for HII Form installation.
449 @retval Others Other errors as indicated.
450
451 **/
452 EFI_STATUS
453 InstallRamDiskConfigForm (
454 IN OUT RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivateData
455 );
456
457 /**
458 This function removes RAM disk configuration Form.
459
460 @param[in, out] ConfigPrivateData
461 Points to RAM disk configuration private data.
462
463 **/
464 VOID
465 UninstallRamDiskConfigForm (
466 IN OUT RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivateData
467 );
468
469 /**
470 Unregister all registered RAM disks.
471
472 **/
473 VOID
474 UnregisterAllRamDisks (
475 VOID
476 );
477
478 /**
479 This function allows a caller to extract the current configuration for one
480 or more named elements from the target driver.
481
482 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
483 @param[in] Request A null-terminated Unicode string in
484 <ConfigRequest> format.
485 @param[out] Progress On return, points to a character in the Request
486 string. Points to the string's null terminator if
487 request was successful. Points to the most recent
488 '&' before the first failing name/value pair (or
489 the beginning of the string if the failure is in
490 the first name/value pair) if the request was not
491 successful.
492 @param[out] Results A null-terminated Unicode string in
493 <ConfigAltResp> format which has all values filled
494 in for the names in the Request string. String to
495 be allocated by the called function.
496
497 @retval EFI_SUCCESS The Results is filled with the requested
498 values.
499 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
500 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
501 @retval EFI_NOT_FOUND Routing data doesn't match any storage in
502 this driver.
503
504 **/
505 EFI_STATUS
506 EFIAPI
507 RamDiskExtractConfig (
508 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
509 IN CONST EFI_STRING Request,
510 OUT EFI_STRING *Progress,
511 OUT EFI_STRING *Results
512 );
513
514 /**
515 This function processes the results of changes in configuration.
516
517 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
518 @param[in] Configuration A null-terminated Unicode string in <ConfigResp>
519 format.
520 @param[out] Progress A pointer to a string filled in with the offset of
521 the most recent '&' before the first failing
522 name/value pair (or the beginning of the string if
523 the failure is in the first name/value pair) or
524 the terminating NULL if all was successful.
525
526 @retval EFI_SUCCESS The Results is processed successfully.
527 @retval EFI_INVALID_PARAMETER Configuration is NULL.
528 @retval EFI_NOT_FOUND Routing data doesn't match any storage in
529 this driver.
530
531 **/
532 EFI_STATUS
533 EFIAPI
534 RamDiskRouteConfig (
535 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
536 IN CONST EFI_STRING Configuration,
537 OUT EFI_STRING *Progress
538 );
539
540 /**
541 This function processes the results of changes in configuration.
542
543 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
544 @param[in] Action Specifies the type of action taken by the browser.
545 @param[in] QuestionId A unique value which is sent to the original
546 exporting driver so that it can identify the type
547 of data to expect.
548 @param[in] Type The type of value for the question.
549 @param[in] Value A pointer to the data being sent to the original
550 exporting driver.
551 @param[out] ActionRequest On return, points to the action requested by the
552 callback function.
553
554 @retval EFI_SUCCESS The callback successfully handled the action.
555 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
556 variable and its data.
557 @retval EFI_DEVICE_ERROR The variable could not be saved.
558 @retval EFI_UNSUPPORTED The specified Action is not supported by the
559 callback.
560
561 **/
562 EFI_STATUS
563 EFIAPI
564 RamDiskCallback (
565 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
566 IN EFI_BROWSER_ACTION Action,
567 IN EFI_QUESTION_ID QuestionId,
568 IN UINT8 Type,
569 IN EFI_IFR_TYPE_VALUE *Value,
570 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
571 );
572
573 /**
574 This function gets the file information from an open file descriptor,
575 and stores it in a buffer allocated from pool.
576
577 @param[in] FHand File Handle.
578
579 @return A pointer to a buffer with file information or NULL is returned.
580
581 **/
582 EFI_FILE_INFO *
583 FileInfo (
584 IN EFI_FILE_HANDLE FHand
585 );
586
587 /**
588 Publish the RAM disk NVDIMM Firmware Interface Table (NFIT) to the ACPI
589 table.
590
591 @param[in] PrivateData Points to RAM disk private data.
592
593 @retval EFI_SUCCESS The RAM disk NFIT has been published.
594 @retval others The RAM disk NFIT has not been published.
595
596 **/
597 EFI_STATUS
598 RamDiskPublishNfit (
599 IN RAM_DISK_PRIVATE_DATA *PrivateData
600 );
601
602 #endif