2 The header file of RamDiskDxe driver.
4 Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #ifndef _RAM_DISK_IMPL_H_
16 #define _RAM_DISK_IMPL_H_
19 #include <Library/BaseLib.h>
20 #include <Library/BaseMemoryLib.h>
21 #include <Library/DebugLib.h>
22 #include <Library/UefiLib.h>
23 #include <Library/UefiDriverEntryPoint.h>
24 #include <Library/UefiBootServicesTableLib.h>
25 #include <Library/UefiHiiServicesLib.h>
26 #include <Library/MemoryAllocationLib.h>
27 #include <Library/HiiLib.h>
28 #include <Library/FileExplorerLib.h>
29 #include <Library/DevicePathLib.h>
30 #include <Library/PrintLib.h>
31 #include <Protocol/RamDisk.h>
32 #include <Protocol/BlockIo.h>
33 #include <Protocol/BlockIo2.h>
34 #include <Protocol/HiiConfigAccess.h>
35 #include <Protocol/SimpleFileSystem.h>
36 #include <Guid/MdeModuleHii.h>
37 #include <Guid/RamDiskHii.h>
38 #include <Guid/FileInfo.h>
40 #include "RamDiskNVData.h"
43 /// RAM disk general definitions and declarations
47 // Block size for RAM disk
49 #define RAM_DISK_BLOCK_SIZE 512
52 // Iterate through the doule linked list. NOT delete safe
54 #define EFI_LIST_FOR_EACH(Entry, ListHead) \
55 for(Entry = (ListHead)->ForwardLink; Entry != (ListHead); Entry = Entry->ForwardLink)
58 // Iterate through the doule linked list. This is delete-safe.
59 // Do not touch NextEntry
61 #define EFI_LIST_FOR_EACH_SAFE(Entry, NextEntry, ListHead) \
62 for(Entry = (ListHead)->ForwardLink, NextEntry = Entry->ForwardLink;\
63 Entry != (ListHead); Entry = NextEntry, NextEntry = Entry->ForwardLink)
66 // RamDiskDxe driver maintains a list of registered RAM disks.
68 extern LIST_ENTRY RegisteredRamDisks
;
69 extern UINTN ListEntryNum
;
72 // RAM Disk create method.
74 typedef enum _RAM_DISK_CREATE_METHOD
{
75 RamDiskCreateOthers
= 0,
77 } RAM_DISK_CREATE_METHOD
;
80 // RamDiskDxe driver maintains a list of registered RAM disks.
81 // The struct contains the list entry and the information of each RAM
89 EFI_BLOCK_IO_PROTOCOL BlockIo
;
90 EFI_BLOCK_IO2_PROTOCOL BlockIo2
;
91 EFI_BLOCK_IO_MEDIA Media
;
92 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
97 UINT16 InstanceNumber
;
98 RAM_DISK_CREATE_METHOD CreateMethod
;
100 LIST_ENTRY ThisInstance
;
101 } RAM_DISK_PRIVATE_DATA
;
103 #define RAM_DISK_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('R', 'D', 'S', 'K')
104 #define RAM_DISK_PRIVATE_FROM_BLKIO(a) CR (a, RAM_DISK_PRIVATE_DATA, BlockIo, RAM_DISK_PRIVATE_DATA_SIGNATURE)
105 #define RAM_DISK_PRIVATE_FROM_BLKIO2(a) CR (a, RAM_DISK_PRIVATE_DATA, BlockIo2, RAM_DISK_PRIVATE_DATA_SIGNATURE)
106 #define RAM_DISK_PRIVATE_FROM_THIS(a) CR (a, RAM_DISK_PRIVATE_DATA, ThisInstance, RAM_DISK_PRIVATE_DATA_SIGNATURE)
109 /// RAM disk HII-related definitions and declarations
113 // Tool generated IFR binary data and String package data
115 extern UINT8 RamDiskHiiBin
[];
116 extern UINT8 RamDiskDxeStrings
[];
119 VENDOR_DEVICE_PATH VendorDevicePath
;
120 EFI_DEVICE_PATH_PROTOCOL End
;
121 } HII_VENDOR_DEVICE_PATH
;
126 EFI_HII_CONFIG_ACCESS_PROTOCOL ConfigAccess
;
127 EFI_HANDLE DriverHandle
;
128 EFI_HII_HANDLE HiiHandle
;
129 } RAM_DISK_CONFIG_PRIVATE_DATA
;
131 extern RAM_DISK_CONFIG_PRIVATE_DATA mRamDiskConfigPrivateDataTemplate
;
133 #define RAM_DISK_CONFIG_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('R', 'C', 'F', 'G')
134 #define RAM_DISK_CONFIG_PRIVATE_FROM_THIS(a) CR (a, RAM_DISK_CONFIG_PRIVATE_DATA, ConfigAccess, RAM_DISK_CONFIG_PRIVATE_DATA_SIGNATURE)
136 #define RAM_DISK_LIST_VAR_OFFSET ((UINT16) OFFSET_OF (RAM_DISK_CONFIGURATION, RamDiskList))
139 Register a RAM disk with specified address, size and type.
141 @param[in] RamDiskBase The base address of registered RAM disk.
142 @param[in] RamDiskSize The size of registered RAM disk.
143 @param[in] RamDiskType The type of registered RAM disk. The GUID can be
144 any of the values defined in section 9.3.6.9, or a
146 @param[in] ParentDevicePath
147 Pointer to the parent device path. If there is no
148 parent device path then ParentDevicePath is NULL.
149 @param[out] DevicePath On return, points to a pointer to the device path
150 of the RAM disk device.
151 If ParentDevicePath is not NULL, the returned
152 DevicePath is created by appending a RAM disk node
153 to the parent device path. If ParentDevicePath is
154 NULL, the returned DevicePath is a RAM disk device
155 path without appending. This function is
156 responsible for allocating the buffer DevicePath
157 with the boot service AllocatePool().
159 @retval EFI_SUCCESS The RAM disk is registered successfully.
160 @retval EFI_INVALID_PARAMETER DevicePath or RamDiskType is NULL.
162 @retval EFI_ALREADY_STARTED A Device Path Protocol instance to be created
163 is already present in the handle database.
164 @retval EFI_OUT_OF_RESOURCES The RAM disk register operation fails due to
171 IN UINT64 RamDiskBase
,
172 IN UINT64 RamDiskSize
,
173 IN EFI_GUID
*RamDiskType
,
174 IN EFI_DEVICE_PATH
*ParentDevicePath OPTIONAL
,
175 OUT EFI_DEVICE_PATH_PROTOCOL
**DevicePath
179 Unregister a RAM disk specified by DevicePath.
181 @param[in] DevicePath A pointer to the device path that describes a RAM
184 @retval EFI_SUCCESS The RAM disk is unregistered successfully.
185 @retval EFI_INVALID_PARAMETER DevicePath is NULL.
186 @retval EFI_UNSUPPORTED The device specified by DevicePath is not a
187 valid ramdisk device path and not supported
189 @retval EFI_NOT_FOUND The RAM disk pointed by DevicePath doesn't
196 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
200 Initialize the BlockIO protocol of a RAM disk device.
202 @param[in] PrivateData Points to RAM disk private data.
207 IN RAM_DISK_PRIVATE_DATA
*PrivateData
211 Reset the Block Device.
213 @param[in] This Indicates a pointer to the calling context.
214 @param[in] ExtendedVerification
215 Driver may perform diagnostics on reset.
217 @retval EFI_SUCCESS The device was reset.
218 @retval EFI_DEVICE_ERROR The device is not functioning properly and
225 IN EFI_BLOCK_IO_PROTOCOL
*This
,
226 IN BOOLEAN ExtendedVerification
230 Read BufferSize bytes from Lba into Buffer.
232 @param[in] This Indicates a pointer to the calling context.
233 @param[in] MediaId Id of the media, changes every time the media is
235 @param[in] Lba The starting Logical Block Address to read from.
236 @param[in] BufferSize Size of Buffer, must be a multiple of device block
238 @param[out] Buffer A pointer to the destination buffer for the data.
239 The caller is responsible for either having
240 implicit or explicit ownership of the buffer.
242 @retval EFI_SUCCESS The data was read correctly from the device.
243 @retval EFI_DEVICE_ERROR The device reported an error while performing
245 @retval EFI_NO_MEDIA There is no media in the device.
246 @retval EFI_MEDIA_CHANGED The MediaId does not matched the current
248 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block
250 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
251 valid, or the buffer is not on proper alignment.
256 RamDiskBlkIoReadBlocks (
257 IN EFI_BLOCK_IO_PROTOCOL
*This
,
265 Write BufferSize bytes from Lba into Buffer.
267 @param[in] This Indicates a pointer to the calling context.
268 @param[in] MediaId The media ID that the write request is for.
269 @param[in] Lba The starting logical block address to be written.
270 The caller is responsible for writing to only
271 legitimate locations.
272 @param[in] BufferSize Size of Buffer, must be a multiple of device block
274 @param[in] Buffer A pointer to the source buffer for the data.
276 @retval EFI_SUCCESS The data was written correctly to the device.
277 @retval EFI_WRITE_PROTECTED The device can not be written to.
278 @retval EFI_DEVICE_ERROR The device reported an error while performing
280 @retval EFI_NO_MEDIA There is no media in the device.
281 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current
283 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block
285 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not
286 valid, or the buffer is not on proper alignment.
291 RamDiskBlkIoWriteBlocks (
292 IN EFI_BLOCK_IO_PROTOCOL
*This
,
300 Flush the Block Device.
302 @param[in] This Indicates a pointer to the calling context.
304 @retval EFI_SUCCESS All outstanding data was written to the device.
305 @retval EFI_DEVICE_ERROR The device reported an error while writting
307 @retval EFI_NO_MEDIA There is no media in the device.
312 RamDiskBlkIoFlushBlocks (
313 IN EFI_BLOCK_IO_PROTOCOL
*This
317 Resets the block device hardware.
319 @param[in] This The pointer of EFI_BLOCK_IO2_PROTOCOL.
320 @param[in] ExtendedVerification The flag about if extend verificate.
322 @retval EFI_SUCCESS The device was reset.
323 @retval EFI_DEVICE_ERROR The block device is not functioning correctly
324 and could not be reset.
330 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
331 IN BOOLEAN ExtendedVerification
335 Reads the requested number of blocks from the device.
337 @param[in] This Indicates a pointer to the calling context.
338 @param[in] MediaId The media ID that the read request is for.
339 @param[in] Lba The starting logical block address to read
341 @param[in, out] Token A pointer to the token associated with the
343 @param[in] BufferSize The size of the Buffer in bytes. This must be
344 a multiple of the intrinsic block size of the
346 @param[out] Buffer A pointer to the destination buffer for the
347 data. The caller is responsible for either
348 having implicit or explicit ownership of the
351 @retval EFI_SUCCESS The read request was queued if Token->Event
352 is not NULL. The data was read correctly from
353 the device if the Token->Event is NULL.
354 @retval EFI_DEVICE_ERROR The device reported an error while attempting
355 to perform the read operation.
356 @retval EFI_NO_MEDIA There is no media in the device.
357 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
358 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
359 the intrinsic block size of the device.
360 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
361 valid, or the buffer is not on proper
363 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
369 RamDiskBlkIo2ReadBlocksEx (
370 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
373 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
379 Writes a specified number of blocks to the device.
381 @param[in] This Indicates a pointer to the calling context.
382 @param[in] MediaId The media ID that the write request is for.
383 @param[in] Lba The starting logical block address to be
384 written. The caller is responsible for
385 writing to only legitimate locations.
386 @param[in, out] Token A pointer to the token associated with the
388 @param[in] BufferSize The size in bytes of Buffer. This must be a
389 multiple of the intrinsic block size of the
391 @param[in] Buffer A pointer to the source buffer for the data.
393 @retval EFI_SUCCESS The write request was queued if Event is not
394 NULL. The data was written correctly to the
395 device if the Event is NULL.
396 @retval EFI_WRITE_PROTECTED The device cannot be written to.
397 @retval EFI_NO_MEDIA There is no media in the device.
398 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
399 @retval EFI_DEVICE_ERROR The device reported an error while attempting
400 to perform the write operation.
401 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
402 the intrinsic block size of the device.
403 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not
404 valid, or the buffer is not on proper
406 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
412 RamDiskBlkIo2WriteBlocksEx (
413 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
416 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
422 Flushes all modified data to a physical block device.
424 @param[in] This Indicates a pointer to the calling context.
425 @param[in, out] Token A pointer to the token associated with the
428 @retval EFI_SUCCESS The flush request was queued if Event is not
429 NULL. All outstanding data was written
430 correctly to the device if the Event is NULL.
431 @retval EFI_DEVICE_ERROR The device reported an error while attempting
433 @retval EFI_WRITE_PROTECTED The device cannot be written to.
434 @retval EFI_NO_MEDIA There is no media in the device.
435 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
436 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
442 RamDiskBlkIo2FlushBlocksEx (
443 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
444 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
448 This function publish the RAM disk configuration Form.
450 @param[in, out] ConfigPrivateData
451 Points to RAM disk configuration private data.
453 @retval EFI_SUCCESS HII Form is installed successfully.
454 @retval EFI_OUT_OF_RESOURCES Not enough resource for HII Form installation.
455 @retval Others Other errors as indicated.
459 InstallRamDiskConfigForm (
460 IN OUT RAM_DISK_CONFIG_PRIVATE_DATA
*ConfigPrivateData
464 This function removes RAM disk configuration Form.
466 @param[in, out] ConfigPrivateData
467 Points to RAM disk configuration private data.
471 UninstallRamDiskConfigForm (
472 IN OUT RAM_DISK_CONFIG_PRIVATE_DATA
*ConfigPrivateData
476 Unregister all registered RAM disks.
480 UnregisterAllRamDisks (
485 This function allows a caller to extract the current configuration for one
486 or more named elements from the target driver.
488 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
489 @param[in] Request A null-terminated Unicode string in
490 <ConfigRequest> format.
491 @param[out] Progress On return, points to a character in the Request
492 string. Points to the string's null terminator if
493 request was successful. Points to the most recent
494 '&' before the first failing name/value pair (or
495 the beginning of the string if the failure is in
496 the first name/value pair) if the request was not
498 @param[out] Results A null-terminated Unicode string in
499 <ConfigAltResp> format which has all values filled
500 in for the names in the Request string. String to
501 be allocated by the called function.
503 @retval EFI_SUCCESS The Results is filled with the requested
505 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
506 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
507 @retval EFI_NOT_FOUND Routing data doesn't match any storage in
513 RamDiskExtractConfig (
514 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
515 IN CONST EFI_STRING Request
,
516 OUT EFI_STRING
*Progress
,
517 OUT EFI_STRING
*Results
521 This function processes the results of changes in configuration.
523 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
524 @param[in] Configuration A null-terminated Unicode string in <ConfigResp>
526 @param[out] Progress A pointer to a string filled in with the offset of
527 the most recent '&' before the first failing
528 name/value pair (or the beginning of the string if
529 the failure is in the first name/value pair) or
530 the terminating NULL if all was successful.
532 @retval EFI_SUCCESS The Results is processed successfully.
533 @retval EFI_INVALID_PARAMETER Configuration is NULL.
534 @retval EFI_NOT_FOUND Routing data doesn't match any storage in
541 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
542 IN CONST EFI_STRING Configuration
,
543 OUT EFI_STRING
*Progress
547 This function processes the results of changes in configuration.
549 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
550 @param[in] Action Specifies the type of action taken by the browser.
551 @param[in] QuestionId A unique value which is sent to the original
552 exporting driver so that it can identify the type
554 @param[in] Type The type of value for the question.
555 @param[in] Value A pointer to the data being sent to the original
557 @param[out] ActionRequest On return, points to the action requested by the
560 @retval EFI_SUCCESS The callback successfully handled the action.
561 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
562 variable and its data.
563 @retval EFI_DEVICE_ERROR The variable could not be saved.
564 @retval EFI_UNSUPPORTED The specified Action is not supported by the
571 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
572 IN EFI_BROWSER_ACTION Action
,
573 IN EFI_QUESTION_ID QuestionId
,
575 IN EFI_IFR_TYPE_VALUE
*Value
,
576 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
581 This function gets the file information from an open file descriptor,
582 and stores it in a buffer allocated from pool.
584 @param[in] FHand File Handle.
586 @return A pointer to a buffer with file information or NULL is returned.
591 IN EFI_FILE_HANDLE FHand
596 This function will open a file or directory referenced by DevicePath.
598 This function opens a file with the open mode according to the file path. The
599 Attributes is valid only for EFI_FILE_MODE_CREATE.
601 @param[in, out] FilePath On input, the device path to the file.
602 On output, the remaining device path.
603 @param[out] FileHandle Pointer to the file handle.
604 @param[in] OpenMode The mode to open the file with.
605 @param[in] Attributes The file's file attributes.
607 @retval EFI_SUCCESS The information was set.
608 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
609 @retval EFI_UNSUPPORTED Could not open the file path.
610 @retval EFI_NOT_FOUND The specified file could not be found on the
611 device or the file system could not be found
613 @retval EFI_NO_MEDIA The device has no medium.
614 @retval EFI_MEDIA_CHANGED The device has a different medium in it or
615 the medium is no longer supported.
616 @retval EFI_DEVICE_ERROR The device reported an error.
617 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
618 @retval EFI_WRITE_PROTECTED The file or medium is write protected.
619 @retval EFI_ACCESS_DENIED The file was opened read only.
620 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open
622 @retval EFI_VOLUME_FULL The volume is full.
626 OpenFileByDevicePath(
627 IN OUT EFI_DEVICE_PATH_PROTOCOL
**FilePath
,
628 OUT EFI_FILE_HANDLE
*FileHandle
,