2 The header file of RamDiskDxe driver.
4 Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #ifndef _RAM_DISK_IMPL_H_
10 #define _RAM_DISK_IMPL_H_
13 #include <Library/BaseLib.h>
14 #include <Library/BaseMemoryLib.h>
15 #include <Library/DebugLib.h>
16 #include <Library/UefiLib.h>
17 #include <Library/UefiDriverEntryPoint.h>
18 #include <Library/UefiBootServicesTableLib.h>
19 #include <Library/UefiHiiServicesLib.h>
20 #include <Library/MemoryAllocationLib.h>
21 #include <Library/HiiLib.h>
22 #include <Library/FileExplorerLib.h>
23 #include <Library/DevicePathLib.h>
24 #include <Library/PrintLib.h>
25 #include <Library/PcdLib.h>
26 #include <Library/DxeServicesLib.h>
27 #include <Protocol/RamDisk.h>
28 #include <Protocol/BlockIo.h>
29 #include <Protocol/BlockIo2.h>
30 #include <Protocol/HiiConfigAccess.h>
31 #include <Protocol/SimpleFileSystem.h>
32 #include <Protocol/AcpiTable.h>
33 #include <Protocol/AcpiSystemDescriptionTable.h>
34 #include <Guid/MdeModuleHii.h>
35 #include <Guid/RamDiskHii.h>
36 #include <Guid/FileInfo.h>
37 #include <IndustryStandard/Acpi61.h>
39 #include "RamDiskNVData.h"
42 /// RAM disk general definitions and declarations
46 // Default block size for RAM disk
48 #define RAM_DISK_DEFAULT_BLOCK_SIZE 512
51 // Iterate through the double linked list. NOT delete safe
53 #define EFI_LIST_FOR_EACH(Entry, ListHead) \
54 for(Entry = (ListHead)->ForwardLink; Entry != (ListHead); Entry = Entry->ForwardLink)
57 // Iterate through the double linked list. This is delete-safe.
58 // Do not touch NextEntry
60 #define EFI_LIST_FOR_EACH_SAFE(Entry, NextEntry, ListHead) \
61 for(Entry = (ListHead)->ForwardLink, NextEntry = Entry->ForwardLink;\
62 Entry != (ListHead); Entry = NextEntry, NextEntry = Entry->ForwardLink)
65 // RamDiskDxe driver maintains a list of registered RAM disks.
67 extern LIST_ENTRY RegisteredRamDisks
;
70 // Pointers to the EFI_ACPI_TABLE_PROTOCOL and EFI_ACPI_SDT_PROTOCOL.
72 extern EFI_ACPI_TABLE_PROTOCOL
*mAcpiTableProtocol
;
73 extern EFI_ACPI_SDT_PROTOCOL
*mAcpiSdtProtocol
;
76 // RAM Disk create method.
78 typedef enum _RAM_DISK_CREATE_METHOD
{
79 RamDiskCreateOthers
= 0,
81 } RAM_DISK_CREATE_METHOD
;
84 // RamDiskDxe driver maintains a list of registered RAM disks.
85 // The struct contains the list entry and the information of each RAM
93 EFI_BLOCK_IO_PROTOCOL BlockIo
;
94 EFI_BLOCK_IO2_PROTOCOL BlockIo2
;
95 EFI_BLOCK_IO_MEDIA Media
;
96 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
101 UINT16 InstanceNumber
;
102 RAM_DISK_CREATE_METHOD CreateMethod
;
104 EFI_QUESTION_ID CheckBoxId
;
105 BOOLEAN CheckBoxChecked
;
107 LIST_ENTRY ThisInstance
;
108 } RAM_DISK_PRIVATE_DATA
;
110 #define RAM_DISK_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('R', 'D', 'S', 'K')
111 #define RAM_DISK_PRIVATE_FROM_BLKIO(a) CR (a, RAM_DISK_PRIVATE_DATA, BlockIo, RAM_DISK_PRIVATE_DATA_SIGNATURE)
112 #define RAM_DISK_PRIVATE_FROM_BLKIO2(a) CR (a, RAM_DISK_PRIVATE_DATA, BlockIo2, RAM_DISK_PRIVATE_DATA_SIGNATURE)
113 #define RAM_DISK_PRIVATE_FROM_THIS(a) CR (a, RAM_DISK_PRIVATE_DATA, ThisInstance, RAM_DISK_PRIVATE_DATA_SIGNATURE)
116 /// RAM disk HII-related definitions and declarations
120 // Tool generated IFR binary data and String package data
122 extern UINT8 RamDiskHiiBin
[];
123 extern UINT8 RamDiskDxeStrings
[];
126 VENDOR_DEVICE_PATH VendorDevicePath
;
127 EFI_DEVICE_PATH_PROTOCOL End
;
128 } HII_VENDOR_DEVICE_PATH
;
133 RAM_DISK_CONFIGURATION ConfigStore
;
135 EFI_HII_CONFIG_ACCESS_PROTOCOL ConfigAccess
;
136 EFI_HANDLE DriverHandle
;
137 EFI_HII_HANDLE HiiHandle
;
138 } RAM_DISK_CONFIG_PRIVATE_DATA
;
140 extern RAM_DISK_CONFIG_PRIVATE_DATA mRamDiskConfigPrivateDataTemplate
;
142 #define RAM_DISK_CONFIG_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('R', 'C', 'F', 'G')
143 #define RAM_DISK_CONFIG_PRIVATE_FROM_THIS(a) CR (a, RAM_DISK_CONFIG_PRIVATE_DATA, ConfigAccess, RAM_DISK_CONFIG_PRIVATE_DATA_SIGNATURE)
146 Register a RAM disk with specified address, size and type.
148 @param[in] RamDiskBase The base address of registered RAM disk.
149 @param[in] RamDiskSize The size of registered RAM disk.
150 @param[in] RamDiskType The type of registered RAM disk. The GUID can be
151 any of the values defined in section 9.3.6.9, or a
153 @param[in] ParentDevicePath
154 Pointer to the parent device path. If there is no
155 parent device path then ParentDevicePath is NULL.
156 @param[out] DevicePath On return, points to a pointer to the device path
157 of the RAM disk device.
158 If ParentDevicePath is not NULL, the returned
159 DevicePath is created by appending a RAM disk node
160 to the parent device path. If ParentDevicePath is
161 NULL, the returned DevicePath is a RAM disk device
162 path without appending. This function is
163 responsible for allocating the buffer DevicePath
164 with the boot service AllocatePool().
166 @retval EFI_SUCCESS The RAM disk is registered successfully.
167 @retval EFI_INVALID_PARAMETER DevicePath or RamDiskType is NULL.
169 @retval EFI_ALREADY_STARTED A Device Path Protocol instance to be created
170 is already present in the handle database.
171 @retval EFI_OUT_OF_RESOURCES The RAM disk register operation fails due to
178 IN UINT64 RamDiskBase
,
179 IN UINT64 RamDiskSize
,
180 IN EFI_GUID
*RamDiskType
,
181 IN EFI_DEVICE_PATH
*ParentDevicePath OPTIONAL
,
182 OUT EFI_DEVICE_PATH_PROTOCOL
**DevicePath
186 Unregister a RAM disk specified by DevicePath.
188 @param[in] DevicePath A pointer to the device path that describes a RAM
191 @retval EFI_SUCCESS The RAM disk is unregistered successfully.
192 @retval EFI_INVALID_PARAMETER DevicePath is NULL.
193 @retval EFI_UNSUPPORTED The device specified by DevicePath is not a
194 valid ramdisk device path and not supported
196 @retval EFI_NOT_FOUND The RAM disk pointed by DevicePath doesn't
203 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
207 Initialize the BlockIO protocol of a RAM disk device.
209 @param[in] PrivateData Points to RAM disk private data.
214 IN RAM_DISK_PRIVATE_DATA
*PrivateData
218 Reset the Block Device.
220 @param[in] This Indicates a pointer to the calling context.
221 @param[in] ExtendedVerification
222 Driver may perform diagnostics on reset.
224 @retval EFI_SUCCESS The device was reset.
225 @retval EFI_DEVICE_ERROR The device is not functioning properly and
232 IN EFI_BLOCK_IO_PROTOCOL
*This
,
233 IN BOOLEAN ExtendedVerification
237 Read BufferSize bytes from Lba into Buffer.
239 @param[in] This Indicates a pointer to the calling context.
240 @param[in] MediaId Id of the media, changes every time the media is
242 @param[in] Lba The starting Logical Block Address to read from.
243 @param[in] BufferSize Size of Buffer, must be a multiple of device block
245 @param[out] Buffer A pointer to the destination buffer for the data.
246 The caller is responsible for either having
247 implicit or explicit ownership of the buffer.
249 @retval EFI_SUCCESS The data was read correctly from the device.
250 @retval EFI_DEVICE_ERROR The device reported an error while performing
252 @retval EFI_NO_MEDIA There is no media in the device.
253 @retval EFI_MEDIA_CHANGED The MediaId does not matched the current
255 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block
257 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
258 valid, or the buffer is not on proper alignment.
263 RamDiskBlkIoReadBlocks (
264 IN EFI_BLOCK_IO_PROTOCOL
*This
,
272 Write BufferSize bytes from Lba into Buffer.
274 @param[in] This Indicates a pointer to the calling context.
275 @param[in] MediaId The media ID that the write request is for.
276 @param[in] Lba The starting logical block address to be written.
277 The caller is responsible for writing to only
278 legitimate locations.
279 @param[in] BufferSize Size of Buffer, must be a multiple of device block
281 @param[in] Buffer A pointer to the source buffer for the data.
283 @retval EFI_SUCCESS The data was written correctly to the device.
284 @retval EFI_WRITE_PROTECTED The device can not be written to.
285 @retval EFI_DEVICE_ERROR The device reported an error while performing
287 @retval EFI_NO_MEDIA There is no media in the device.
288 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current
290 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block
292 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not
293 valid, or the buffer is not on proper alignment.
298 RamDiskBlkIoWriteBlocks (
299 IN EFI_BLOCK_IO_PROTOCOL
*This
,
307 Flush the Block Device.
309 @param[in] This Indicates a pointer to the calling context.
311 @retval EFI_SUCCESS All outstanding data was written to the device.
312 @retval EFI_DEVICE_ERROR The device reported an error while writting
314 @retval EFI_NO_MEDIA There is no media in the device.
319 RamDiskBlkIoFlushBlocks (
320 IN EFI_BLOCK_IO_PROTOCOL
*This
324 Resets the block device hardware.
326 @param[in] This The pointer of EFI_BLOCK_IO2_PROTOCOL.
327 @param[in] ExtendedVerification The flag about if extend verificate.
329 @retval EFI_SUCCESS The device was reset.
330 @retval EFI_DEVICE_ERROR The block device is not functioning correctly
331 and could not be reset.
337 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
338 IN BOOLEAN ExtendedVerification
342 Reads the requested number of blocks from the device.
344 @param[in] This Indicates a pointer to the calling context.
345 @param[in] MediaId The media ID that the read request is for.
346 @param[in] Lba The starting logical block address to read
348 @param[in, out] Token A pointer to the token associated with the
350 @param[in] BufferSize The size of the Buffer in bytes. This must be
351 a multiple of the intrinsic block size of the
353 @param[out] Buffer A pointer to the destination buffer for the
354 data. The caller is responsible for either
355 having implicit or explicit ownership of the
358 @retval EFI_SUCCESS The read request was queued if Token->Event
359 is not NULL. The data was read correctly from
360 the device if the Token->Event is NULL.
361 @retval EFI_DEVICE_ERROR The device reported an error while attempting
362 to perform the read operation.
363 @retval EFI_NO_MEDIA There is no media in the device.
364 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
365 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
366 the intrinsic block size of the device.
367 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
368 valid, or the buffer is not on proper
370 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
376 RamDiskBlkIo2ReadBlocksEx (
377 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
380 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
386 Writes a specified number of blocks to the device.
388 @param[in] This Indicates a pointer to the calling context.
389 @param[in] MediaId The media ID that the write request is for.
390 @param[in] Lba The starting logical block address to be
391 written. The caller is responsible for
392 writing to only legitimate locations.
393 @param[in, out] Token A pointer to the token associated with the
395 @param[in] BufferSize The size in bytes of Buffer. This must be a
396 multiple of the intrinsic block size of the
398 @param[in] Buffer A pointer to the source buffer for the data.
400 @retval EFI_SUCCESS The write request was queued if Event is not
401 NULL. The data was written correctly to the
402 device if the Event is NULL.
403 @retval EFI_WRITE_PROTECTED The device cannot be written to.
404 @retval EFI_NO_MEDIA There is no media in the device.
405 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
406 @retval EFI_DEVICE_ERROR The device reported an error while attempting
407 to perform the write operation.
408 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
409 the intrinsic block size of the device.
410 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not
411 valid, or the buffer is not on proper
413 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
419 RamDiskBlkIo2WriteBlocksEx (
420 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
423 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
429 Flushes all modified data to a physical block device.
431 @param[in] This Indicates a pointer to the calling context.
432 @param[in, out] Token A pointer to the token associated with the
435 @retval EFI_SUCCESS The flush request was queued if Event is not
436 NULL. All outstanding data was written
437 correctly to the device if the Event is NULL.
438 @retval EFI_DEVICE_ERROR The device reported an error while attempting
440 @retval EFI_WRITE_PROTECTED The device cannot be written to.
441 @retval EFI_NO_MEDIA There is no media in the device.
442 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
443 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
449 RamDiskBlkIo2FlushBlocksEx (
450 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
451 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
455 This function publish the RAM disk configuration Form.
457 @param[in, out] ConfigPrivateData
458 Points to RAM disk configuration private data.
460 @retval EFI_SUCCESS HII Form is installed successfully.
461 @retval EFI_OUT_OF_RESOURCES Not enough resource for HII Form installation.
462 @retval Others Other errors as indicated.
466 InstallRamDiskConfigForm (
467 IN OUT RAM_DISK_CONFIG_PRIVATE_DATA
*ConfigPrivateData
471 This function removes RAM disk configuration Form.
473 @param[in, out] ConfigPrivateData
474 Points to RAM disk configuration private data.
478 UninstallRamDiskConfigForm (
479 IN OUT RAM_DISK_CONFIG_PRIVATE_DATA
*ConfigPrivateData
483 Unregister all registered RAM disks.
487 UnregisterAllRamDisks (
492 This function allows a caller to extract the current configuration for one
493 or more named elements from the target driver.
495 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
496 @param[in] Request A null-terminated Unicode string in
497 <ConfigRequest> format.
498 @param[out] Progress On return, points to a character in the Request
499 string. Points to the string's null terminator if
500 request was successful. Points to the most recent
501 '&' before the first failing name/value pair (or
502 the beginning of the string if the failure is in
503 the first name/value pair) if the request was not
505 @param[out] Results A null-terminated Unicode string in
506 <ConfigAltResp> format which has all values filled
507 in for the names in the Request string. String to
508 be allocated by the called function.
510 @retval EFI_SUCCESS The Results is filled with the requested
512 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
513 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
514 @retval EFI_NOT_FOUND Routing data doesn't match any storage in
520 RamDiskExtractConfig (
521 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
522 IN CONST EFI_STRING Request
,
523 OUT EFI_STRING
*Progress
,
524 OUT EFI_STRING
*Results
528 This function processes the results of changes in configuration.
530 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
531 @param[in] Configuration A null-terminated Unicode string in <ConfigResp>
533 @param[out] Progress A pointer to a string filled in with the offset of
534 the most recent '&' before the first failing
535 name/value pair (or the beginning of the string if
536 the failure is in the first name/value pair) or
537 the terminating NULL if all was successful.
539 @retval EFI_SUCCESS The Results is processed successfully.
540 @retval EFI_INVALID_PARAMETER Configuration is NULL.
541 @retval EFI_NOT_FOUND Routing data doesn't match any storage in
548 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
549 IN CONST EFI_STRING Configuration
,
550 OUT EFI_STRING
*Progress
554 This function processes the results of changes in configuration.
556 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
557 @param[in] Action Specifies the type of action taken by the browser.
558 @param[in] QuestionId A unique value which is sent to the original
559 exporting driver so that it can identify the type
561 @param[in] Type The type of value for the question.
562 @param[in] Value A pointer to the data being sent to the original
564 @param[out] ActionRequest On return, points to the action requested by the
567 @retval EFI_SUCCESS The callback successfully handled the action.
568 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
569 variable and its data.
570 @retval EFI_DEVICE_ERROR The variable could not be saved.
571 @retval EFI_UNSUPPORTED The specified Action is not supported by the
578 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
579 IN EFI_BROWSER_ACTION Action
,
580 IN EFI_QUESTION_ID QuestionId
,
582 IN EFI_IFR_TYPE_VALUE
*Value
,
583 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
588 This function gets the file information from an open file descriptor,
589 and stores it in a buffer allocated from pool.
591 @param[in] FHand File Handle.
593 @return A pointer to a buffer with file information or NULL is returned.
598 IN EFI_FILE_HANDLE FHand
603 Publish the RAM disk NVDIMM Firmware Interface Table (NFIT) to the ACPI
606 @param[in] PrivateData Points to RAM disk private data.
608 @retval EFI_SUCCESS The RAM disk NFIT has been published.
609 @retval others The RAM disk NFIT has not been published.
614 IN RAM_DISK_PRIVATE_DATA
*PrivateData