2 The header file of RamDiskDxe driver.
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
10 #ifndef _RAM_DISK_IMPL_H_
11 #define _RAM_DISK_IMPL_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>
40 #include "RamDiskNVData.h"
43 /// RAM disk general definitions and declarations
47 // Default block size for RAM disk
49 #define RAM_DISK_DEFAULT_BLOCK_SIZE 512
52 // RamDiskDxe driver maintains a list of registered RAM disks.
54 extern LIST_ENTRY RegisteredRamDisks
;
57 // Pointers to the EFI_ACPI_TABLE_PROTOCOL and EFI_ACPI_SDT_PROTOCOL.
59 extern EFI_ACPI_TABLE_PROTOCOL
*mAcpiTableProtocol
;
60 extern EFI_ACPI_SDT_PROTOCOL
*mAcpiSdtProtocol
;
63 // RAM Disk create method.
65 typedef enum _RAM_DISK_CREATE_METHOD
{
66 RamDiskCreateOthers
= 0,
68 } RAM_DISK_CREATE_METHOD
;
71 // RamDiskDxe driver maintains a list of registered RAM disks.
72 // The struct contains the list entry and the information of each RAM
80 EFI_BLOCK_IO_PROTOCOL BlockIo
;
81 EFI_BLOCK_IO2_PROTOCOL BlockIo2
;
82 EFI_BLOCK_IO_MEDIA Media
;
83 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
88 UINT16 InstanceNumber
;
89 RAM_DISK_CREATE_METHOD CreateMethod
;
91 EFI_QUESTION_ID CheckBoxId
;
92 BOOLEAN CheckBoxChecked
;
94 LIST_ENTRY ThisInstance
;
95 } RAM_DISK_PRIVATE_DATA
;
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)
103 /// RAM disk HII-related definitions and declarations
107 // Tool generated IFR binary data and String package data
109 extern UINT8 RamDiskHiiBin
[];
110 extern UINT8 RamDiskDxeStrings
[];
113 VENDOR_DEVICE_PATH VendorDevicePath
;
114 EFI_DEVICE_PATH_PROTOCOL End
;
115 } HII_VENDOR_DEVICE_PATH
;
120 RAM_DISK_CONFIGURATION ConfigStore
;
122 EFI_HII_CONFIG_ACCESS_PROTOCOL ConfigAccess
;
123 EFI_HANDLE DriverHandle
;
124 EFI_HII_HANDLE HiiHandle
;
125 } RAM_DISK_CONFIG_PRIVATE_DATA
;
127 extern RAM_DISK_CONFIG_PRIVATE_DATA mRamDiskConfigPrivateDataTemplate
;
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)
133 Register a RAM disk with specified address, size and type.
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
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().
153 @retval EFI_SUCCESS The RAM disk is registered successfully.
154 @retval EFI_INVALID_PARAMETER DevicePath or RamDiskType is NULL.
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
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
173 Unregister a RAM disk specified by DevicePath.
175 @param[in] DevicePath A pointer to the device path that describes a RAM
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
183 @retval EFI_NOT_FOUND The RAM disk pointed by DevicePath doesn't
190 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
194 Initialize the BlockIO protocol of a RAM disk device.
196 @param[in] PrivateData Points to RAM disk private data.
201 IN RAM_DISK_PRIVATE_DATA
*PrivateData
205 Reset the Block Device.
207 @param[in] This Indicates a pointer to the calling context.
208 @param[in] ExtendedVerification
209 Driver may perform diagnostics on reset.
211 @retval EFI_SUCCESS The device was reset.
212 @retval EFI_DEVICE_ERROR The device is not functioning properly and
219 IN EFI_BLOCK_IO_PROTOCOL
*This
,
220 IN BOOLEAN ExtendedVerification
224 Read BufferSize bytes from Lba into Buffer.
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
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
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.
236 @retval EFI_SUCCESS The data was read correctly from the device.
237 @retval EFI_DEVICE_ERROR The device reported an error while performing
239 @retval EFI_NO_MEDIA There is no media in the device.
240 @retval EFI_MEDIA_CHANGED The MediaId does not matched the current
242 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block
244 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
245 valid, or the buffer is not on proper alignment.
250 RamDiskBlkIoReadBlocks (
251 IN EFI_BLOCK_IO_PROTOCOL
*This
,
259 Write BufferSize bytes from Lba into Buffer.
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
268 @param[in] Buffer A pointer to the source buffer for the data.
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
274 @retval EFI_NO_MEDIA There is no media in the device.
275 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current
277 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block
279 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not
280 valid, or the buffer is not on proper alignment.
285 RamDiskBlkIoWriteBlocks (
286 IN EFI_BLOCK_IO_PROTOCOL
*This
,
294 Flush the Block Device.
296 @param[in] This Indicates a pointer to the calling context.
298 @retval EFI_SUCCESS All outstanding data was written to the device.
299 @retval EFI_DEVICE_ERROR The device reported an error while writting
301 @retval EFI_NO_MEDIA There is no media in the device.
306 RamDiskBlkIoFlushBlocks (
307 IN EFI_BLOCK_IO_PROTOCOL
*This
311 Resets the block device hardware.
313 @param[in] This The pointer of EFI_BLOCK_IO2_PROTOCOL.
314 @param[in] ExtendedVerification The flag about if extend verificate.
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.
324 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
325 IN BOOLEAN ExtendedVerification
329 Reads the requested number of blocks from the device.
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
335 @param[in, out] Token A pointer to the token associated with the
337 @param[in] BufferSize The size of the Buffer in bytes. This must be
338 a multiple of the intrinsic block size of the
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
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
357 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
363 RamDiskBlkIo2ReadBlocksEx (
364 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
367 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
373 Writes a specified number of blocks to the device.
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
382 @param[in] BufferSize The size in bytes of Buffer. This must be a
383 multiple of the intrinsic block size of the
385 @param[in] Buffer A pointer to the source buffer for the data.
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
400 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
406 RamDiskBlkIo2WriteBlocksEx (
407 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
410 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
416 Flushes all modified data to a physical block device.
418 @param[in] This Indicates a pointer to the calling context.
419 @param[in, out] Token A pointer to the token associated with the
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
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
436 RamDiskBlkIo2FlushBlocksEx (
437 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
438 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
442 This function publish the RAM disk configuration Form.
444 @param[in, out] ConfigPrivateData
445 Points to RAM disk configuration private data.
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.
453 InstallRamDiskConfigForm (
454 IN OUT RAM_DISK_CONFIG_PRIVATE_DATA
*ConfigPrivateData
458 This function removes RAM disk configuration Form.
460 @param[in, out] ConfigPrivateData
461 Points to RAM disk configuration private data.
465 UninstallRamDiskConfigForm (
466 IN OUT RAM_DISK_CONFIG_PRIVATE_DATA
*ConfigPrivateData
470 Unregister all registered RAM disks.
474 UnregisterAllRamDisks (
479 This function allows a caller to extract the current configuration for one
480 or more named elements from the target driver.
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
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.
497 @retval EFI_SUCCESS The Results is filled with the requested
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
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
515 This function processes the results of changes in configuration.
517 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
518 @param[in] Configuration A null-terminated Unicode string in <ConfigResp>
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.
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
535 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
536 IN CONST EFI_STRING Configuration
,
537 OUT EFI_STRING
*Progress
541 This function processes the results of changes in configuration.
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
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
551 @param[out] ActionRequest On return, points to the action requested by the
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
565 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
566 IN EFI_BROWSER_ACTION Action
,
567 IN EFI_QUESTION_ID QuestionId
,
569 IN EFI_IFR_TYPE_VALUE
*Value
,
570 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
574 This function gets the file information from an open file descriptor,
575 and stores it in a buffer allocated from pool.
577 @param[in] FHand File Handle.
579 @return A pointer to a buffer with file information or NULL is returned.
584 IN EFI_FILE_HANDLE FHand
588 Publish the RAM disk NVDIMM Firmware Interface Table (NFIT) to the ACPI
591 @param[in] PrivateData Points to RAM disk private data.
593 @retval EFI_SUCCESS The RAM disk NFIT has been published.
594 @retval others The RAM disk NFIT has not been published.
599 IN RAM_DISK_PRIVATE_DATA
*PrivateData