Changeset 58459 in vbox for trunk/src/VBox/Devices/EFI/Firmware/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c
- Timestamp:
- Oct 28, 2015 8:17:18 PM (9 years ago)
- Location:
- trunk/src/VBox/Devices/EFI/Firmware
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/EFI/Firmware
-
Property svn:mergeinfo
set to (toggle deleted branches)
/vendor/edk2/current 103735-103757
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/VBox/Devices/EFI/Firmware/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c
r48674 r58459 3 3 gEfiDevicePathUtilitiesProtocolGuid. 4 4 5 Copyright (c) 2006 - 201 0, Intel Corporation. All rights reserved.<BR>5 Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR> 6 6 This program and the accompanying materials 7 7 are licensed and made available under the terms and conditions of the BSD License … … 18 18 19 19 #include <Protocol/DevicePathUtilities.h> 20 #include <Protocol/DevicePathToText.h> 21 #include <Protocol/DevicePathFromText.h> 20 22 21 23 #include <Library/DevicePathLib.h> … … 25 27 #include <Library/BaseMemoryLib.h> 26 28 #include <Library/UefiBootServicesTableLib.h> 27 28 EFI_DEVICE_PATH_UTILITIES_PROTOCOL *mDevicePathUtilities = NULL; 29 #include <Library/PcdLib.h> 30 31 GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_UTILITIES_PROTOCOL *mDevicePathLibDevicePathUtilities = NULL; 32 GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *mDevicePathLibDevicePathToText = NULL; 33 GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL *mDevicePathLibDevicePathFromText = NULL; 29 34 30 35 // … … 64 69 &gEfiDevicePathUtilitiesProtocolGuid, 65 70 NULL, 66 (VOID**) &mDevicePath Utilities71 (VOID**) &mDevicePathLibDevicePathUtilities 67 72 ); 68 73 ASSERT_EFI_ERROR (Status); 69 ASSERT (mDevicePathUtilities != NULL); 70 74 ASSERT (mDevicePathLibDevicePathUtilities != NULL); 71 75 return Status; 76 } 77 78 /** 79 Determine whether a given device path is valid. 80 If DevicePath is NULL, then ASSERT(). 81 82 @param DevicePath A pointer to a device path data structure. 83 @param MaxSize The maximum size of the device path data structure. 84 85 @retval TRUE DevicePath is valid. 86 @retval FALSE The length of any node node in the DevicePath is less 87 than sizeof (EFI_DEVICE_PATH_PROTOCOL). 88 @retval FALSE If MaxSize is not zero, the size of the DevicePath 89 exceeds MaxSize. 90 @retval FALSE If PcdMaximumDevicePathNodeCount is not zero, the node 91 count of the DevicePath exceeds PcdMaximumDevicePathNodeCount. 92 **/ 93 BOOLEAN 94 EFIAPI 95 IsDevicePathValid ( 96 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, 97 IN UINTN MaxSize 98 ) 99 { 100 UINTN Count; 101 UINTN Size; 102 UINTN NodeLength; 103 104 ASSERT (DevicePath != NULL); 105 106 for (Count = 0, Size = 0; !IsDevicePathEnd (DevicePath); DevicePath = NextDevicePathNode (DevicePath)) { 107 NodeLength = DevicePathNodeLength (DevicePath); 108 if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) { 109 return FALSE; 110 } 111 112 if (MaxSize > 0) { 113 Size += NodeLength; 114 if (Size + END_DEVICE_PATH_LENGTH > MaxSize) { 115 return FALSE; 116 } 117 } 118 119 if (PcdGet32 (PcdMaximumDevicePathNodeCount) > 0) { 120 Count++; 121 if (Count >= PcdGet32 (PcdMaximumDevicePathNodeCount)) { 122 return FALSE; 123 } 124 } 125 } 126 127 // 128 // Only return TRUE when the End Device Path node is valid. 129 // 130 return (BOOLEAN) (DevicePathNodeLength (DevicePath) == END_DEVICE_PATH_LENGTH); 72 131 } 73 132 … … 257 316 258 317 If Node is NULL, then ASSERT(). 259 If NodeLength >= 0x10000, then ASSERT(). 318 If NodeLength >= SIZE_64KB, then ASSERT(). 319 If NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL), then ASSERT(). 260 320 261 321 @param Node A pointer to a device path node data structure. … … 273 333 { 274 334 ASSERT (Node != NULL); 275 ASSERT ( Length < 0x10000);335 ASSERT ((Length >= sizeof (EFI_DEVICE_PATH_PROTOCOL)) && (Length < SIZE_64KB)); 276 336 return WriteUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Length[0], (UINT16)(Length)); 277 337 } … … 306 366 Returns the size of a device path in bytes. 307 367 308 This function returns the size, in bytes, of the device path data structure specified by 309 DevicePath including the end of device path node. If DevicePath is NULL, then 0 is returned. 310 311 @param DevicePath A pointer to a device path data structure. 312 313 @retval 0 If DevicePath is NULL. 314 @retval Others The size of a device path in bytes. 368 This function returns the size, in bytes, of the device path data structure 369 specified by DevicePath including the end of device path node. 370 If DevicePath is NULL or invalid, then 0 is returned. 371 372 @param DevicePath A pointer to a device path data structure. 373 374 @retval 0 If DevicePath is NULL or invalid. 375 @retval Others The size of a device path in bytes. 315 376 316 377 **/ … … 321 382 ) 322 383 { 323 return mDevicePath Utilities->GetDevicePathSize (DevicePath);384 return mDevicePathLibDevicePathUtilities->GetDevicePathSize (DevicePath); 324 385 } 325 386 … … 337 398 @param DevicePath A pointer to a device path data structure. 338 399 339 @retval NULL If DevicePath is NULL .400 @retval NULL If DevicePath is NULL or invalid. 340 401 @retval Others A pointer to the duplicated device path. 341 402 … … 347 408 ) 348 409 { 349 return mDevicePath Utilities->DuplicateDevicePath (DevicePath);410 return mDevicePathLibDevicePathUtilities->DuplicateDevicePath (DevicePath); 350 411 } 351 412 … … 368 429 369 430 @retval NULL If there is not enough memory for the newly allocated buffer. 431 @retval NULL If FirstDevicePath or SecondDevicePath is invalid. 370 432 @retval Others A pointer to the new device path if success. 371 433 Or a copy an end-of-device-path if both FirstDevicePath and … … 380 442 ) 381 443 { 382 return mDevicePath Utilities->AppendDevicePath (FirstDevicePath, SecondDevicePath);444 return mDevicePathLibDevicePathUtilities->AppendDevicePath (FirstDevicePath, SecondDevicePath); 383 445 } 384 446 … … 418 480 ) 419 481 { 420 return mDevicePath Utilities->AppendDeviceNode (DevicePath, DevicePathNode);482 return mDevicePathLibDevicePathUtilities->AppendDeviceNode (DevicePath, DevicePathNode); 421 483 } 422 484 … … 432 494 If DevicePath is NULL, then a copy if DevicePathInstance is returned. 433 495 If DevicePathInstance is NULL, then NULL is returned. 496 If DevicePath or DevicePathInstance is invalid, then NULL is returned. 434 497 If there is not enough memory to allocate space for the new device path, then 435 498 NULL is returned. … … 450 513 ) 451 514 { 452 return mDevicePath Utilities->AppendDevicePathInstance (DevicePath, DevicePathInstance);515 return mDevicePathLibDevicePathUtilities->AppendDevicePathInstance (DevicePath, DevicePathInstance); 453 516 } 454 517 … … 488 551 { 489 552 ASSERT (Size != NULL); 490 return mDevicePath Utilities->GetNextDevicePathInstance (DevicePath, Size);553 return mDevicePathLibDevicePathUtilities->GetNextDevicePathInstance (DevicePath, Size); 491 554 } 492 555 … … 501 564 NULL is returned. 502 565 The memory is allocated from EFI boot services memory. It is the responsibility 503 of the caller to 504 free the memory allocated. 566 of the caller to free the memory allocated. 505 567 506 568 @param NodeType The device node type for the new device node. … … 519 581 ) 520 582 { 521 return mDevicePath Utilities->CreateDeviceNode (NodeType, NodeSubType, NodeLength);583 return mDevicePathLibDevicePathUtilities->CreateDeviceNode (NodeType, NodeSubType, NodeLength); 522 584 } 523 585 … … 525 587 Determines if a device path is single or multi-instance. 526 588 527 This function returns TRUE if the device path specified by DevicePath is 589 This function returns TRUE if the device path specified by DevicePath is 528 590 multi-instance. 529 Otherwise, FALSE is returned. If DevicePath is NULL, then FALSE is returned. 591 Otherwise, FALSE is returned. 592 If DevicePath is NULL or invalid, then FALSE is returned. 530 593 531 594 @param DevicePath A pointer to a device path data structure. 532 595 533 596 @retval TRUE DevicePath is multi-instance. 534 @retval FALSE DevicePath is not multi-instance or DevicePath535 is NULL .597 @retval FALSE DevicePath is not multi-instance, or DevicePath 598 is NULL or invalid. 536 599 537 600 **/ … … 542 605 ) 543 606 { 544 return mDevicePath Utilities->IsDevicePathMultiInstance (DevicePath);607 return mDevicePathLibDevicePathUtilities->IsDevicePathMultiInstance (DevicePath); 545 608 } 546 609 … … 634 697 return DevicePath; 635 698 } 699 700 /** 701 Locate and return the protocol instance identified by the ProtocolGuid. 702 703 @param ProtocolGuid The GUID of the protocol. 704 705 @return A pointer to the protocol instance or NULL when absent. 706 **/ 707 VOID * 708 UefiDevicePathLibLocateProtocol ( 709 EFI_GUID *ProtocolGuid 710 ) 711 { 712 EFI_STATUS Status; 713 VOID *Protocol; 714 Status = gBS->LocateProtocol ( 715 ProtocolGuid, 716 NULL, 717 (VOID**) &Protocol 718 ); 719 if (EFI_ERROR (Status)) { 720 return NULL; 721 } else { 722 return Protocol; 723 } 724 } 725 726 /** 727 Converts a device node to its string representation. 728 729 @param DeviceNode A Pointer to the device node to be converted. 730 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation 731 of the display node is used, where applicable. If DisplayOnly 732 is FALSE, then the longer text representation of the display node 733 is used. 734 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text 735 representation for a device node can be used, where applicable. 736 737 @return A pointer to the allocated text representation of the device node or NULL if DeviceNode 738 is NULL or there was insufficient memory. 739 740 **/ 741 CHAR16 * 742 EFIAPI 743 ConvertDeviceNodeToText ( 744 IN CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode, 745 IN BOOLEAN DisplayOnly, 746 IN BOOLEAN AllowShortcuts 747 ) 748 { 749 if (mDevicePathLibDevicePathToText == NULL) { 750 mDevicePathLibDevicePathToText = UefiDevicePathLibLocateProtocol (&gEfiDevicePathToTextProtocolGuid); 751 } 752 if (mDevicePathLibDevicePathToText != NULL) { 753 return mDevicePathLibDevicePathToText->ConvertDeviceNodeToText (DeviceNode, DisplayOnly, AllowShortcuts); 754 } else { 755 return NULL; 756 } 757 } 758 759 /** 760 Converts a device path to its text representation. 761 762 @param DevicePath A Pointer to the device to be converted. 763 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation 764 of the display node is used, where applicable. If DisplayOnly 765 is FALSE, then the longer text representation of the display node 766 is used. 767 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text 768 representation for a device node can be used, where applicable. 769 770 @return A pointer to the allocated text representation of the device path or 771 NULL if DeviceNode is NULL or there was insufficient memory. 772 773 **/ 774 CHAR16 * 775 EFIAPI 776 ConvertDevicePathToText ( 777 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, 778 IN BOOLEAN DisplayOnly, 779 IN BOOLEAN AllowShortcuts 780 ) 781 { 782 if (mDevicePathLibDevicePathToText == NULL) { 783 mDevicePathLibDevicePathToText = UefiDevicePathLibLocateProtocol (&gEfiDevicePathToTextProtocolGuid); 784 } 785 if (mDevicePathLibDevicePathToText != NULL) { 786 return mDevicePathLibDevicePathToText->ConvertDevicePathToText (DevicePath, DisplayOnly, AllowShortcuts); 787 } else { 788 return NULL; 789 } 790 } 791 792 /** 793 Convert text to the binary representation of a device node. 794 795 @param TextDeviceNode TextDeviceNode points to the text representation of a device 796 node. Conversion starts with the first character and continues 797 until the first non-device node character. 798 799 @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was 800 insufficient memory or text unsupported. 801 802 **/ 803 EFI_DEVICE_PATH_PROTOCOL * 804 EFIAPI 805 ConvertTextToDeviceNode ( 806 IN CONST CHAR16 *TextDeviceNode 807 ) 808 { 809 if (mDevicePathLibDevicePathFromText == NULL) { 810 mDevicePathLibDevicePathFromText = UefiDevicePathLibLocateProtocol (&gEfiDevicePathFromTextProtocolGuid); 811 } 812 if (mDevicePathLibDevicePathFromText != NULL) { 813 return mDevicePathLibDevicePathFromText->ConvertTextToDeviceNode (TextDeviceNode); 814 } else { 815 return NULL; 816 } 817 } 818 819 /** 820 Convert text to the binary representation of a device path. 821 822 823 @param TextDevicePath TextDevicePath points to the text representation of a device 824 path. Conversion starts with the first character and continues 825 until the first non-device node character. 826 827 @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or 828 there was insufficient memory. 829 830 **/ 831 EFI_DEVICE_PATH_PROTOCOL * 832 EFIAPI 833 ConvertTextToDevicePath ( 834 IN CONST CHAR16 *TextDevicePath 835 ) 836 { 837 if (mDevicePathLibDevicePathFromText == NULL) { 838 mDevicePathLibDevicePathFromText = UefiDevicePathLibLocateProtocol (&gEfiDevicePathFromTextProtocolGuid); 839 } 840 if (mDevicePathLibDevicePathFromText != NULL) { 841 return mDevicePathLibDevicePathFromText->ConvertTextToDevicePath (TextDevicePath); 842 } else { 843 return NULL; 844 } 845 } 846
Note:
See TracChangeset
for help on using the changeset viewer.