]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.h
MdeModulePkg: Replace BSD License with BSD+Patent License
[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 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #ifndef _RAM_DISK_IMPL_H_
10 #define _RAM_DISK_IMPL_H_
11
12 #include <Uefi.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>
38
39 #include "RamDiskNVData.h"
40
41 ///
42 /// RAM disk general definitions and declarations
43 ///
44
45 //
46 // Default block size for RAM disk
47 //
48 #define RAM_DISK_DEFAULT_BLOCK_SIZE 512
49
50 //
51 // Iterate through the double linked list. NOT delete safe
52 //
53 #define EFI_LIST_FOR_EACH(Entry, ListHead) \
54 for(Entry = (ListHead)->ForwardLink; Entry != (ListHead); Entry = Entry->ForwardLink)
55
56 //
57 // Iterate through the double linked list. This is delete-safe.
58 // Do not touch NextEntry
59 //
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)
63
64 //
65 // RamDiskDxe driver maintains a list of registered RAM disks.
66 //
67 extern LIST_ENTRY RegisteredRamDisks;
68
69 //
70 // Pointers to the EFI_ACPI_TABLE_PROTOCOL and EFI_ACPI_SDT_PROTOCOL.
71 //
72 extern EFI_ACPI_TABLE_PROTOCOL *mAcpiTableProtocol;
73 extern EFI_ACPI_SDT_PROTOCOL *mAcpiSdtProtocol;
74
75 //
76 // RAM Disk create method.
77 //
78 typedef enum _RAM_DISK_CREATE_METHOD {
79 RamDiskCreateOthers = 0,
80 RamDiskCreateHii
81 } RAM_DISK_CREATE_METHOD;
82
83 //
84 // RamDiskDxe driver maintains a list of registered RAM disks.
85 // The struct contains the list entry and the information of each RAM
86 // disk
87 //
88 typedef struct {
89 UINTN Signature;
90
91 EFI_HANDLE Handle;
92
93 EFI_BLOCK_IO_PROTOCOL BlockIo;
94 EFI_BLOCK_IO2_PROTOCOL BlockIo2;
95 EFI_BLOCK_IO_MEDIA Media;
96 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
97
98 UINT64 StartingAddr;
99 UINT64 Size;
100 EFI_GUID TypeGuid;
101 UINT16 InstanceNumber;
102 RAM_DISK_CREATE_METHOD CreateMethod;
103 BOOLEAN InNfit;
104 EFI_QUESTION_ID CheckBoxId;
105 BOOLEAN CheckBoxChecked;
106
107 LIST_ENTRY ThisInstance;
108 } RAM_DISK_PRIVATE_DATA;
109
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)
114
115 ///
116 /// RAM disk HII-related definitions and declarations
117 ///
118
119 //
120 // Tool generated IFR binary data and String package data
121 //
122 extern UINT8 RamDiskHiiBin[];
123 extern UINT8 RamDiskDxeStrings[];
124
125 typedef struct {
126 VENDOR_DEVICE_PATH VendorDevicePath;
127 EFI_DEVICE_PATH_PROTOCOL End;
128 } HII_VENDOR_DEVICE_PATH;
129
130 typedef struct {
131 UINTN Signature;
132
133 RAM_DISK_CONFIGURATION ConfigStore;
134
135 EFI_HII_CONFIG_ACCESS_PROTOCOL ConfigAccess;
136 EFI_HANDLE DriverHandle;
137 EFI_HII_HANDLE HiiHandle;
138 } RAM_DISK_CONFIG_PRIVATE_DATA;
139
140 extern RAM_DISK_CONFIG_PRIVATE_DATA mRamDiskConfigPrivateDataTemplate;
141
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)
144
145 /**
146 Register a RAM disk with specified address, size and type.
147
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
152 vendor defined GUID.
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().
165
166 @retval EFI_SUCCESS The RAM disk is registered successfully.
167 @retval EFI_INVALID_PARAMETER DevicePath or RamDiskType is NULL.
168 RamDiskSize is 0.
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
172 resource limitation.
173
174 **/
175 EFI_STATUS
176 EFIAPI
177 RamDiskRegister (
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
183 );
184
185 /**
186 Unregister a RAM disk specified by DevicePath.
187
188 @param[in] DevicePath A pointer to the device path that describes a RAM
189 Disk device.
190
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
195 by the driver.
196 @retval EFI_NOT_FOUND The RAM disk pointed by DevicePath doesn't
197 exist.
198
199 **/
200 EFI_STATUS
201 EFIAPI
202 RamDiskUnregister (
203 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
204 );
205
206 /**
207 Initialize the BlockIO protocol of a RAM disk device.
208
209 @param[in] PrivateData Points to RAM disk private data.
210
211 **/
212 VOID
213 RamDiskInitBlockIo (
214 IN RAM_DISK_PRIVATE_DATA *PrivateData
215 );
216
217 /**
218 Reset the Block Device.
219
220 @param[in] This Indicates a pointer to the calling context.
221 @param[in] ExtendedVerification
222 Driver may perform diagnostics on reset.
223
224 @retval EFI_SUCCESS The device was reset.
225 @retval EFI_DEVICE_ERROR The device is not functioning properly and
226 could not be reset.
227
228 **/
229 EFI_STATUS
230 EFIAPI
231 RamDiskBlkIoReset (
232 IN EFI_BLOCK_IO_PROTOCOL *This,
233 IN BOOLEAN ExtendedVerification
234 );
235
236 /**
237 Read BufferSize bytes from Lba into Buffer.
238
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
241 replaced.
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
244 size.
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.
248
249 @retval EFI_SUCCESS The data was read correctly from the device.
250 @retval EFI_DEVICE_ERROR The device reported an error while performing
251 the read.
252 @retval EFI_NO_MEDIA There is no media in the device.
253 @retval EFI_MEDIA_CHANGED The MediaId does not matched the current
254 device.
255 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block
256 size of the device.
257 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
258 valid, or the buffer is not on proper alignment.
259
260 **/
261 EFI_STATUS
262 EFIAPI
263 RamDiskBlkIoReadBlocks (
264 IN EFI_BLOCK_IO_PROTOCOL *This,
265 IN UINT32 MediaId,
266 IN EFI_LBA Lba,
267 IN UINTN BufferSize,
268 OUT VOID *Buffer
269 );
270
271 /**
272 Write BufferSize bytes from Lba into Buffer.
273
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
280 size.
281 @param[in] Buffer A pointer to the source buffer for the data.
282
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
286 the write.
287 @retval EFI_NO_MEDIA There is no media in the device.
288 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current
289 device.
290 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block
291 size of the device.
292 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not
293 valid, or the buffer is not on proper alignment.
294
295 **/
296 EFI_STATUS
297 EFIAPI
298 RamDiskBlkIoWriteBlocks (
299 IN EFI_BLOCK_IO_PROTOCOL *This,
300 IN UINT32 MediaId,
301 IN EFI_LBA Lba,
302 IN UINTN BufferSize,
303 IN VOID *Buffer
304 );
305
306 /**
307 Flush the Block Device.
308
309 @param[in] This Indicates a pointer to the calling context.
310
311 @retval EFI_SUCCESS All outstanding data was written to the device.
312 @retval EFI_DEVICE_ERROR The device reported an error while writting
313 back the data
314 @retval EFI_NO_MEDIA There is no media in the device.
315
316 **/
317 EFI_STATUS
318 EFIAPI
319 RamDiskBlkIoFlushBlocks (
320 IN EFI_BLOCK_IO_PROTOCOL *This
321 );
322
323 /**
324 Resets the block device hardware.
325
326 @param[in] This The pointer of EFI_BLOCK_IO2_PROTOCOL.
327 @param[in] ExtendedVerification The flag about if extend verificate.
328
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.
332
333 **/
334 EFI_STATUS
335 EFIAPI
336 RamDiskBlkIo2Reset (
337 IN EFI_BLOCK_IO2_PROTOCOL *This,
338 IN BOOLEAN ExtendedVerification
339 );
340
341 /**
342 Reads the requested number of blocks from the device.
343
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
347 from on the device.
348 @param[in, out] Token A pointer to the token associated with the
349 transaction.
350 @param[in] BufferSize The size of the Buffer in bytes. This must be
351 a multiple of the intrinsic block size of the
352 device.
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
356 buffer.
357
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
369 alignment.
370 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
371 lack of resources.
372
373 **/
374 EFI_STATUS
375 EFIAPI
376 RamDiskBlkIo2ReadBlocksEx (
377 IN EFI_BLOCK_IO2_PROTOCOL *This,
378 IN UINT32 MediaId,
379 IN EFI_LBA Lba,
380 IN OUT EFI_BLOCK_IO2_TOKEN *Token,
381 IN UINTN BufferSize,
382 OUT VOID *Buffer
383 );
384
385 /**
386 Writes a specified number of blocks to the device.
387
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
394 transaction.
395 @param[in] BufferSize The size in bytes of Buffer. This must be a
396 multiple of the intrinsic block size of the
397 device.
398 @param[in] Buffer A pointer to the source buffer for the data.
399
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
412 alignment.
413 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
414 lack of resources.
415
416 **/
417 EFI_STATUS
418 EFIAPI
419 RamDiskBlkIo2WriteBlocksEx (
420 IN EFI_BLOCK_IO2_PROTOCOL *This,
421 IN UINT32 MediaId,
422 IN EFI_LBA Lba,
423 IN OUT EFI_BLOCK_IO2_TOKEN *Token,
424 IN UINTN BufferSize,
425 IN VOID *Buffer
426 );
427
428 /**
429 Flushes all modified data to a physical block device.
430
431 @param[in] This Indicates a pointer to the calling context.
432 @param[in, out] Token A pointer to the token associated with the
433 transaction.
434
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
439 to write data.
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
444 lack of resources.
445
446 **/
447 EFI_STATUS
448 EFIAPI
449 RamDiskBlkIo2FlushBlocksEx (
450 IN EFI_BLOCK_IO2_PROTOCOL *This,
451 IN OUT EFI_BLOCK_IO2_TOKEN *Token
452 );
453
454 /**
455 This function publish the RAM disk configuration Form.
456
457 @param[in, out] ConfigPrivateData
458 Points to RAM disk configuration private data.
459
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.
463
464 **/
465 EFI_STATUS
466 InstallRamDiskConfigForm (
467 IN OUT RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivateData
468 );
469
470 /**
471 This function removes RAM disk configuration Form.
472
473 @param[in, out] ConfigPrivateData
474 Points to RAM disk configuration private data.
475
476 **/
477 VOID
478 UninstallRamDiskConfigForm (
479 IN OUT RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivateData
480 );
481
482 /**
483 Unregister all registered RAM disks.
484
485 **/
486 VOID
487 UnregisterAllRamDisks (
488 VOID
489 );
490
491 /**
492 This function allows a caller to extract the current configuration for one
493 or more named elements from the target driver.
494
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
504 successful.
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.
509
510 @retval EFI_SUCCESS The Results is filled with the requested
511 values.
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
515 this driver.
516
517 **/
518 EFI_STATUS
519 EFIAPI
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
525 );
526
527 /**
528 This function processes the results of changes in configuration.
529
530 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
531 @param[in] Configuration A null-terminated Unicode string in <ConfigResp>
532 format.
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.
538
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
542 this driver.
543
544 **/
545 EFI_STATUS
546 EFIAPI
547 RamDiskRouteConfig (
548 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
549 IN CONST EFI_STRING Configuration,
550 OUT EFI_STRING *Progress
551 );
552
553 /**
554 This function processes the results of changes in configuration.
555
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
560 of data to expect.
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
563 exporting driver.
564 @param[out] ActionRequest On return, points to the action requested by the
565 callback function.
566
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
572 callback.
573
574 **/
575 EFI_STATUS
576 EFIAPI
577 RamDiskCallback (
578 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
579 IN EFI_BROWSER_ACTION Action,
580 IN EFI_QUESTION_ID QuestionId,
581 IN UINT8 Type,
582 IN EFI_IFR_TYPE_VALUE *Value,
583 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
584 );
585
586
587 /**
588 This function gets the file information from an open file descriptor,
589 and stores it in a buffer allocated from pool.
590
591 @param[in] FHand File Handle.
592
593 @return A pointer to a buffer with file information or NULL is returned.
594
595 **/
596 EFI_FILE_INFO *
597 FileInfo (
598 IN EFI_FILE_HANDLE FHand
599 );
600
601
602 /**
603 Publish the RAM disk NVDIMM Firmware Interface Table (NFIT) to the ACPI
604 table.
605
606 @param[in] PrivateData Points to RAM disk private data.
607
608 @retval EFI_SUCCESS The RAM disk NFIT has been published.
609 @retval others The RAM disk NFIT has not been published.
610
611 **/
612 EFI_STATUS
613 RamDiskPublishNfit (
614 IN RAM_DISK_PRIVATE_DATA *PrivateData
615 );
616
617 #endif