Changeset 108794 in vbox for trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library
- Timestamp:
- Mar 31, 2025 11:31:09 AM (5 weeks ago)
- svn:sync-xref-src-repo-rev:
- 168237
- Location:
- trunk/src/VBox/Devices/EFI/FirmwareNew
- Files:
-
- 127 added
- 3 deleted
- 61 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/EFI/FirmwareNew
-
Property svn:mergeinfo
changed from (toggle deleted branches)
to (toggle deleted branches)/vendor/edk2/current 103735-103757,103769-103776,129194-164365 /vendor/edk2/current 103735-103757,103769-103776,129194-168232
-
Property svn:mergeinfo
changed from (toggle deleted branches)
-
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseArmTrngLibNull/BaseArmTrngLibNull.c
r99404 r108794 42 42 ) 43 43 { 44 ASSERT (FALSE);44 DEBUG ((DEBUG_ERROR, "ArmTrng Backend not found\n")); 45 45 return RETURN_UNSUPPORTED; 46 46 } -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
r101291 r108794 58 58 59 59 [BuildOptions] 60 MSFT:*_*_IA32_CC_FLAGS = /wd4146 /wd4245 61 MSFT:*_*_X64_CC_FLAGS = /wd4146 /wd4244 /wd4245 /wd4267 60 # warning C4706: assignment within conditional expression 61 # if ((err = fdt_splice_(fdt, p, oldlen, newlen))) 62 # in BaseFdtLib\libfdt\libfdt\fdt_rw.c (wait for sub module update to remove this) 63 MSFT:*_*_IA32_CC_FLAGS = /wd4146 /wd4245 /wd4706 64 MSFT:*_*_X64_CC_FLAGS = /wd4146 /wd4244 /wd4245 /wd4267 /wd4706 62 65 -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseFdtLib/FdtLib.c
r105670 r108794 8 8 9 9 #include <libfdt/libfdt/libfdt.h> 10 #include <Library/FdtLib.h> 11 #include <Uefi/UefiBaseType.h> 10 12 11 13 /** … … 148 150 149 151 /** 152 Unpack FDT blob into new buffer 153 154 @param[in] Fdt The pointer to FDT blob. 155 @param[out] Buffer Pointer to destination buffer. 156 @param[in] BufferSize The size of destination buffer. 157 158 @return Zero for successfully, otherwise failed. 159 160 **/ 161 INT32 162 EFIAPI 163 FdtOpenInto ( 164 IN CONST VOID *Fdt, 165 OUT VOID *Buffer, 166 IN INT32 BufferSize 167 ) 168 { 169 return fdt_open_into (Fdt, Buffer, BufferSize); 170 } 171 172 /** 173 Pack FDT blob in place. 174 175 @param[in][out] Fdt The pointer to FDT blob. 176 177 @return Zero. 178 **/ 179 INT32 180 EFIAPI 181 FdtPack ( 182 IN OUT VOID *Fdt 183 ) 184 { 185 return fdt_pack (Fdt); 186 } 187 188 /** 189 Returns a pointer to the node at a given offset. 190 191 @param[in] Fdt The pointer to FDT blob. 192 @param[in] Offset The offset to node. 193 @param[in] Length Maximum length of node. 194 195 @return pointer to node. 196 **/ 197 CONST VOID * 198 EFIAPI 199 FdtOffsetPointer ( 200 IN CONST VOID *Fdt, 201 IN INT32 Offset, 202 IN UINT32 Length 203 ) 204 { 205 return fdt_offset_ptr (Fdt, Offset, Length); 206 } 207 208 /** 150 209 Returns a offset of next node from the given node. 151 210 … … 204 263 { 205 264 return fdt_next_subnode (Fdt, Offset); 265 } 266 267 /** 268 Returns the number of memory reserve map entries. 269 270 @param[in] Fdt The pointer to FDT blob. 271 272 @return The number of entries in the reserve map. 273 274 **/ 275 INTN 276 EFIAPI 277 FdtGetNumberOfReserveMapEntries ( 278 IN CONST VOID *Fdt 279 ) 280 { 281 return fdt_num_mem_rsv (Fdt); 282 } 283 284 /** 285 Returns a memory reserve map entry. 286 287 @param[in] *Fdt The pointer to FDT blob. 288 @param[in] Index Index of reserve map entry. 289 @param[out] Addr Pointer to 64-bit variable to hold the start address 290 @param[out] *Size Pointer to 64-bit variable to hold size of reservation 291 292 @return 0 on success, or negative error code. 293 294 **/ 295 INTN 296 EFIAPI 297 FdtGetReserveMapEntry ( 298 IN CONST VOID *Fdt, 299 IN INTN Index, 300 OUT EFI_PHYSICAL_ADDRESS *Addr, 301 OUT UINT64 *Size 302 ) 303 { 304 return fdt_get_mem_rsv (Fdt, Index, Addr, Size); 206 305 } 207 306 … … 230 329 231 330 /** 331 Returns a offset of first node which matches the given name. 332 333 @param[in] Fdt The pointer to FDT blob. 334 @param[in] ParentOffset The offset to the node which start find under. 335 @param[in] Name The name to search the node with the name. 336 337 @return The offset to node offset with given node name. 338 339 **/ 340 INT32 341 EFIAPI 342 FdtSubnodeOffset ( 343 IN CONST VOID *Fdt, 344 IN INT32 ParentOffset, 345 IN CONST CHAR8 *Name 346 ) 347 { 348 return fdt_subnode_offset (Fdt, ParentOffset, Name); 349 } 350 351 /** 352 Find the parent of a given node. 353 354 @param[in] Fdt The pointer to FDT blob. 355 @param[in] NodeOffset The offset to the node to find the parent for. 356 357 @return Structure block offset, or negative return value. 358 **/ 359 INT32 360 EFIAPI 361 FdtParentOffset ( 362 IN CONST VOID *Fdt, 363 IN INT32 NodeOffset 364 ) 365 { 366 return fdt_parent_offset (Fdt, NodeOffset); 367 } 368 369 /** 232 370 Returns a offset of first node which includes the given property name and value. 233 371 … … 243 381 INT32 244 382 EFIAPI 245 FdtNodeOffsetByProp Value (383 FdtNodeOffsetByPropertyValue ( 246 384 IN CONST VOID *Fdt, 247 385 IN INT32 StartOffset, … … 255 393 256 394 /** 395 Returns a offset of first node which includes the given property name and value. 396 397 @param[in] Fdt The pointer to FDT blob. 398 @param[in] Phandle Phandle value to search for. 399 400 @return The offset to node with matching Phandle value. 401 **/ 402 INT32 403 EFIAPI 404 FdtNodeOffsetByPhandle ( 405 IN CONST VOID *Fdt, 406 IN UINT32 Phandle 407 ) 408 { 409 return fdt_node_offset_by_phandle (Fdt, Phandle); 410 } 411 412 /** 413 Look for a string in a stringlist 414 415 @param[in] StringList Pointer to stringlist to search. 416 @param[in] ListLength Length of StringList. 417 @param[in] String Pointer to string to search for. 418 419 @return 1 if found. 420 **/ 421 INT32 422 EFIAPI 423 FdtStringListContains ( 424 IN CONST CHAR8 *StringList, 425 IN INT32 ListLength, 426 IN CONST CHAR8 *String 427 ) 428 { 429 return fdt_stringlist_contains (StringList, ListLength, String); 430 } 431 432 /** 257 433 Returns a property with the given name from the given node. 258 434 … … 266 442 267 443 **/ 268 CONST struct fdt_property*444 CONST FDT_PROPERTY * 269 445 EFIAPI 270 446 FdtGetProperty ( … … 275 451 ) 276 452 { 277 return fdt_get_property (Fdt, NodeOffset, Name, Length); 453 return (FDT_PROPERTY *)fdt_get_property (Fdt, NodeOffset, Name, Length); 454 } 455 456 /** 457 Returns a pointer to a node mapped to an alias matching a substring. 458 459 @param[in] Fdt The pointer to FDT blob. 460 @param[in] Name The alias name string. 461 @param[in] Length The length to the size of the property found. 462 463 @return A pointer to the expansion of the alias matching the substring, 464 or NULL if alias not found. 465 466 **/ 467 CONST CHAR8 * 468 EFIAPI 469 FdtGetAliasNameLen ( 470 IN CONST VOID *Fdt, 471 IN CONST CHAR8 *Name, 472 IN INT32 Length 473 ) 474 { 475 return fdt_get_alias_namelen (Fdt, Name, Length); 278 476 } 279 477 … … 326 524 327 525 **/ 328 CONST struct fdt_property*526 CONST FDT_PROPERTY * 329 527 EFIAPI 330 528 FdtGetPropertyByOffset ( … … 334 532 ) 335 533 { 336 return fdt_get_property_by_offset (Fdt, Offset, Length);534 return (FDT_PROPERTY *)fdt_get_property_by_offset (Fdt, Offset, Length); 337 535 } 338 536 … … 393 591 INT32 394 592 EFIAPI 395 FdtSetProp (593 FdtSetProperty ( 396 594 IN VOID *Fdt, 397 595 IN INT32 NodeOffset, … … 405 603 406 604 /** 605 Set a property to a 64-bit integer. 606 607 @param[in] Fdt The pointer to FDT blob. 608 @param[in] NodeOffset The offset to the node offset which want to add in. 609 @param[in] Name The name to name the property. 610 @param[in] Value The value (big-endian) to the property value. 611 612 @return Zero for successfully, otherwise failed. 613 614 **/ 615 INT32 616 EFIAPI 617 FdtSetPropU64 ( 618 IN VOID *Fdt, 619 IN INT32 NodeOffset, 620 IN CONST CHAR8 *Name, 621 IN UINT64 Value 622 ) 623 { 624 UINT64 Tmp; 625 626 Tmp = cpu_to_fdt64 (Value); 627 628 return fdt_setprop (Fdt, NodeOffset, Name, &Tmp, sizeof (Tmp)); 629 } 630 631 /** 632 Append or create a property in the given node. 633 634 @param[in] Fdt The pointer to FDT blob. 635 @param[in] NodeOffset The offset to the node offset which want to add in. 636 @param[in] Name The name to name the property. 637 @param[in] Value The value (big-endian) to the property value. 638 @param[in] Length The length to the size of the property. 639 640 @return Zero for successfully, otherwise failed. 641 642 **/ 643 INT32 644 EFIAPI 645 FdtAppendProp ( 646 IN VOID *Fdt, 647 IN INT32 NodeOffset, 648 IN CONST CHAR8 *Name, 649 IN CONST VOID *Value, 650 IN UINT32 Length 651 ) 652 { 653 return fdt_appendprop (Fdt, NodeOffset, Name, Value, (int)Length); 654 } 655 656 /** 657 Delete a property. 658 659 This function will delete data from the blob, and will therefore 660 change the offsets of some existing nodes. 661 662 @param[in][out] Fdt Pointer to the device tree blob. 663 @param[in] NodeOffset Offset of the node whose property to nop. 664 @param[in] Name Name of the property to nop. 665 666 @return Zero for successfully, otherwise failed. 667 668 **/ 669 INT32 670 FdtDelProp ( 671 IN OUT VOID *Fdt, 672 IN INT32 NodeOffset, 673 IN CONST CHAR8 *Name 674 ) 675 { 676 return fdt_delprop (Fdt, NodeOffset, Name); 677 } 678 679 /** 680 Finds a tree node by substring 681 682 @param[in] Fdt The pointer to FDT blob. 683 @param[in] Path Full path of the node to locate. 684 @param[in] NameLength The length of the name to check only. 685 686 @return structure block offset of the node with the requested path (>=0), on success 687 **/ 688 INT32 689 EFIAPI 690 FdtPathOffsetNameLen ( 691 IN CONST VOID *Fdt, 692 IN CONST CHAR8 *Path, 693 IN INT32 NameLength 694 ) 695 { 696 return fdt_path_offset_namelen (Fdt, Path, NameLength); 697 } 698 699 /** 700 Finds a tree node by its full path. 701 702 @param[in] Fdt The pointer to FDT blob. 703 @param[in] Path Full path of the node to locate. 704 705 @return structure block offset of the node with the requested path (>=0), on success 706 **/ 707 INT32 708 EFIAPI 709 FdtPathOffset ( 710 IN CONST VOID *Fdt, 711 IN CONST CHAR8 *Path 712 ) 713 { 714 return fdt_path_offset (Fdt, Path); 715 } 716 717 /** 407 718 Returns the name of a given node. 408 719 … … 443 754 return fdt_node_depth (Fdt, NodeOffset); 444 755 } 756 757 /** 758 Find nodes with a given 'compatible' value. 759 760 @param[in] Fdt The pointer to FDT blob. 761 @param[in] StartOffset Only find nodes after this offset. 762 @param[in] Compatible The string to match against. 763 764 @retval The offset of the first node after StartOffset. 765 **/ 766 INT32 767 EFIAPI 768 FdtNodeOffsetByCompatible ( 769 IN CONST VOID *Fdt, 770 IN INT32 StartOffset, 771 IN CONST CHAR8 *Compatible 772 ) 773 { 774 return fdt_node_offset_by_compatible (Fdt, StartOffset, Compatible); 775 } 776 777 /** 778 Retrieve address size for a bus represented in the tree 779 780 @param[in] Fdt The pointer to FDT blob. 781 @param[in] NodeOffset Offset of node to check. 782 783 @return Number of cells in the bus address, or negative error. 784 **/ 785 INT32 786 EFIAPI 787 FdtAddressCells ( 788 IN CONST VOID *Fdt, 789 IN INT32 NodeOffset 790 ) 791 { 792 return fdt_address_cells (Fdt, NodeOffset); 793 } 794 795 /** 796 Retrieve address range size for a bus represented in the tree 797 798 @param[in] Fdt The pointer to FDT blob. 799 @param[in] NodeOffset Offset of node to check. 800 801 @return Number of cells in the bus size, or negative error. 802 **/ 803 INT32 804 EFIAPI 805 FdtSizeCells ( 806 IN CONST VOID *Fdt, 807 IN INT32 NodeOffset 808 ) 809 { 810 return fdt_size_cells (Fdt, NodeOffset); 811 } 812 813 /* Debug functions. */ 814 CONST 815 CHAR8 816 * 817 FdtStrerror ( 818 IN INT32 ErrVal 819 ) 820 { 821 return fdt_strerror (ErrVal); 822 } -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseFdtLib/LibFdtSupport.h
r105670 r108794 15 15 #include <Library/BaseMemoryLib.h> 16 16 17 typedef UINT8 uint8_t; 18 typedef UINT16 uint16_t; 19 typedef INT32 int32_t; 20 typedef UINT32 uint32_t; 21 typedef UINT64 uint64_t; 22 typedef UINTN uintptr_t; 23 typedef UINTN size_t; 24 typedef BOOLEAN bool; 17 typedef UINT8 uint8_t; 18 typedef UINT16 uint16_t; 19 typedef INT32 int32_t; 20 typedef UINT32 uint32_t; 21 typedef UINT64 uint64_t; 22 typedef UINTN uintptr_t; 23 typedef UINTN size_t; 25 24 25 #if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L 26 /* bool, true and false are keywords. */ 27 #else 28 typedef BOOLEAN bool; 26 29 #define true (1 == 1) 27 30 #define false (1 == 0) 31 #endif 28 32 29 33 // -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseLib/BaseLib.inf
r105670 r108794 4 4 # Copyright (c) 2007 - 2021, Intel Corporation. All rights reserved.<BR> 5 5 # Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR> 6 # Portions copyright (c) 2011 - 20 13, ARM Ltd. All rights reserved.<BR>6 # Portions copyright (c) 2011 - 2024, Arm Limited. All rights reserved.<BR> 7 7 # Copyright (c) 2020 - 2021, Hewlett Packard Enterprise Development LP. All rights reserved.<BR> 8 8 # … … 353 353 Unaligned.c 354 354 Math64.c 355 IntelTdxNull.c 355 356 356 357 [Sources.ARM] … … 378 379 Arm/MemoryFence.S | GCC 379 380 Arm/SpeculationBarrier.S | GCC 381 IntelTdxNull.c 380 382 381 383 [Sources.AARCH64] … … 392 394 AArch64/CpuBreakpoint.S | GCC 393 395 AArch64/SpeculationBarrier.S | GCC 396 AArch64/ArmReadCntPctReg.S | GCC 397 AArch64/ArmReadIdAA64Isar0Reg.S | GCC 394 398 395 399 AArch64/MemoryFence.asm | MSFT … … 401 405 AArch64/CpuBreakpoint.asm | MSFT 402 406 AArch64/SpeculationBarrier.asm | MSFT 407 AArch64/ArmReadCntPctReg.asm | MSFT 408 AArch64/ArmReadIdAA64Isar0Reg.asm | MSFT 409 IntelTdxNull.c 403 410 404 411 [Sources.RISCV64] … … 422 429 RiscV64/RiscVMmu.S | GCC 423 430 RiscV64/SpeculationBarrier.S | GCC 431 IntelTdxNull.c 424 432 425 433 [Sources.LOONGARCH64] … … 442 450 LoongArch64/Cpucfg.S | GCC 443 451 LoongArch64/ReadStableCounter.S | GCC 452 IntelTdxNull.c 444 453 445 454 [Packages] -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseLib/CheckSum.c
r105670 r108794 763 763 return ~Crc; 764 764 } 765 766 // The lookup table is inherited from [https://crccalc.com/](https://crccalc.com/%60) 767 GLOBAL_REMOVE_IF_UNREFERENCED STATIC CONST UINT16 mCrc16CcittFLookupTable[256] = { 768 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 769 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, 770 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, 771 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, 772 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, 773 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, 774 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, 775 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, 776 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, 777 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, 778 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, 779 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, 780 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, 781 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, 782 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, 783 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, 784 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, 785 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, 786 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, 787 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, 788 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, 789 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, 790 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, 791 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, 792 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, 793 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, 794 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, 795 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, 796 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, 797 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, 798 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, 799 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0, 800 }; 801 802 /** 803 Calculates the CRC16-CCITT-FALSE checksum of the given buffer. 804 805 @param[in] Buffer Pointer to the buffer. 806 @param[in] Length Length of the buffer, in bytes. 807 @param[in] InitialValue Initial value of the CRC. 808 809 @return The CRC16-CCITT-FALSE checksum. 810 **/ 811 UINT16 812 EFIAPI 813 CalculateCrc16CcittF ( 814 IN CONST VOID *Buffer, 815 IN UINTN Length, 816 IN UINT16 InitialValue 817 ) 818 { 819 CONST UINT8 *Buf; 820 UINT16 Crc; 821 822 ASSERT (Buffer != NULL); 823 ASSERT (Length <= (MAX_ADDRESS - ((UINTN)Buffer) + 1)); 824 825 Buf = Buffer; 826 Crc = InitialValue; 827 828 while (Length-- != 0) { 829 Crc = mCrc16CcittFLookupTable[((Crc >> 8) ^ *(Buf++)) & 0xFF] ^ (Crc << 8); 830 } 831 832 return Crc; 833 } -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseLib/CpuDeadLoop.c
r99404 r108794 2 2 Base Library CPU Functions for all architectures. 3 3 4 Copyright (c) 2006 - 20 08, Intel Corporation. All rights reserved.<BR>4 Copyright (c) 2006 - 2024, Intel Corporation. All rights reserved.<BR> 5 5 SPDX-License-Identifier: BSD-2-Clause-Patent 6 6 … … 9 9 #include <Base.h> 10 10 #include <Library/BaseLib.h> 11 12 static volatile UINTN mDeadLoopComparator = 0; 11 13 12 14 /** … … 27 29 volatile UINTN Index; 28 30 29 for (Index = 0; Index == 0;) {31 for (Index = mDeadLoopComparator; Index == mDeadLoopComparator;) { 30 32 CpuPause (); 31 33 } -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseLib/LoongArch64/AsmCsr.S
r105670 r108794 51 51 52 52 CfgCsrRd: 53 li.w $t0, LOONGARCH_CSR_CPU NUM53 li.w $t0, LOONGARCH_CSR_CPUID 54 54 bltu $a0, $t0, ReadSelNumErr 55 55 li.w $t0, LOONGARCH_CSR_PRCFG3 56 56 bltu $t0, $a0, KcsCsrRd 57 57 la.pcrel $t0, CfgCsrRead 58 addi.w $t1, $a0, -LOONGARCH_CSR_CPU NUM58 addi.w $t1, $a0, -LOONGARCH_CSR_CPUID 59 59 alsl.d $t0, $t1, $t0, 3 60 60 jirl $zero, $t0, 0 … … 101 101 102 102 ReadSelNumErr: 103 addi.d $a0, $zero, -1 104 jirl $zero, $ra, 0 103 break 0 105 104 106 105 BasicCsrRead: … … 119 118 120 119 CfgCsrRead: 121 CsrSel = LOONGARCH_CSR_CPU NUM122 .rept LOONGARCH_CSR_PRCFG3 - LOONGARCH_CSR_CPU NUM+ 1120 CsrSel = LOONGARCH_CSR_CPUID 121 .rept LOONGARCH_CSR_PRCFG3 - LOONGARCH_CSR_CPUID + 1 123 122 AsmCsrRd CsrSel 124 123 CsrSel = CsrSel + 1 … … 176 175 177 176 CfgCsrWr: 178 li.w $t0, LOONGARCH_CSR_CPU NUM177 li.w $t0, LOONGARCH_CSR_CPUID 179 178 bltu $a0, $t0, WriteSelNumErr 180 179 li.w $t0, LOONGARCH_CSR_PRCFG3 181 180 bltu $t0, $a0, KcsCsrWr 182 181 la.pcrel $t0, CfgCsrWrite 183 addi.w $t1, $a0, -LOONGARCH_CSR_CPU NUM182 addi.w $t1, $a0, -LOONGARCH_CSR_CPUID 184 183 alsl.d $t0, $t1, $t0, 3 185 184 move $a0, $a1 … … 231 230 232 231 WriteSelNumErr: 233 addi.d $a0, $zero, -1 234 jirl $zero, $ra, 0 232 break 0 235 233 236 234 BasicCsrWrite: … … 249 247 250 248 CfgCsrWrite: 251 CsrSel = LOONGARCH_CSR_CPU NUM252 .rept LOONGARCH_CSR_PRCFG3 - LOONGARCH_CSR_CPU NUM+ 1249 CsrSel = LOONGARCH_CSR_CPUID 250 .rept LOONGARCH_CSR_PRCFG3 - LOONGARCH_CSR_CPUID + 1 253 251 AsmCsrWr CsrSel 254 252 CsrSel = CsrSel + 1 … … 309 307 310 308 CfgCsrXchg: 311 li.w $t0, LOONGARCH_CSR_CPU NUM309 li.w $t0, LOONGARCH_CSR_CPUID 312 310 bltu $a0, $t0, XchgSelNumErr 313 311 li.w $t0, LOONGARCH_CSR_PRCFG3 314 312 bltu $t0, $a0, KcsCsrXchg 315 313 la.pcrel $t0, CfgCsrXchange 316 addi.w $t1, $a0, -LOONGARCH_CSR_CPU NUM314 addi.w $t1, $a0, -LOONGARCH_CSR_CPUID 317 315 alsl.d $t0, $t1, $t0, 3 318 316 move $a0, $a1 … … 369 367 370 368 XchgSelNumErr: 371 addi.d $a0, $zero, -1 372 jirl $zero, $ra, 0 369 break 0 373 370 374 371 BasicCsrXchange: … … 387 384 388 385 CfgCsrXchange: 389 CsrSel = LOONGARCH_CSR_CPU NUM390 .rept LOONGARCH_CSR_PRCFG3 - LOONGARCH_CSR_CPU NUM+ 1386 CsrSel = LOONGARCH_CSR_CPUID 387 .rept LOONGARCH_CSR_PRCFG3 - LOONGARCH_CSR_CPUID + 1 391 388 AsmCsrXChange CsrSel 392 389 CsrSel = CsrSel + 1 -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseLib/LoongArch64/Cpucfg.S
r105670 r108794 21 21 ASM_PFX(AsmCpucfg): 22 22 cpucfg $t0, $a0 23 stptr. d$t0, $a1, 023 stptr.w $t0, $a1, 0 24 24 25 25 jirl $zero, $ra, 0 -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseLib/LoongArch64/Csr.c
r105670 r108794 30 30 @param[in] Select CSR read instruction select values. 31 31 32 @return The return value of csrrd instruction, return -1 means Select is out of support. 32 @return The return value of csrrd instruction, 33 if a break exception is triggered, the Select is out of support. 33 34 **/ 34 35 UINTN … … 48 49 49 50 @return The return value of csrwr instruction, that is, store the old value of 50 the register, return -1 meansSelect is out of support.51 the register, if a break exception is triggered, the Select is out of support. 51 52 **/ 52 53 UINTN … … 68 69 69 70 @return The return value of csrxchg instruction, that is, store the old value of 70 the register, return -1 meansSelect is out of support.71 the register, if a break exception is triggered, the Select is out of support. 71 72 **/ 72 73 UINTN -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseLib/String.c
r101291 r108794 407 407 ) 408 408 { 409 UINTN Result; 410 411 if (RETURN_ERROR (StrDecimalToUintnS (String, (CHAR16 **)NULL, &Result))) { 412 return MAX_UINTN; 409 UINTN Result; 410 RETURN_STATUS Status; 411 412 Status = StrDecimalToUintnS (String, (CHAR16 **)NULL, &Result); 413 if (Status == RETURN_INVALID_PARAMETER) { 414 Result = 0; 413 415 } 414 416 … … 456 458 ) 457 459 { 458 UINT64 Result; 459 460 if (RETURN_ERROR (StrDecimalToUint64S (String, (CHAR16 **)NULL, &Result))) { 461 return MAX_UINT64; 460 UINT64 Result; 461 RETURN_STATUS Status; 462 463 Status = StrDecimalToUint64S (String, (CHAR16 **)NULL, &Result); 464 if (Status == RETURN_INVALID_PARAMETER) { 465 Result = 0; 462 466 } 463 467 … … 506 510 ) 507 511 { 508 UINTN Result; 509 510 if (RETURN_ERROR (StrHexToUintnS (String, (CHAR16 **)NULL, &Result))) { 511 return MAX_UINTN; 512 UINTN Result; 513 RETURN_STATUS Status; 514 515 Status = StrHexToUintnS (String, (CHAR16 **)NULL, &Result); 516 if (Status == RETURN_INVALID_PARAMETER) { 517 Result = 0; 512 518 } 513 519 … … 556 562 ) 557 563 { 558 UINT64 Result; 559 560 if (RETURN_ERROR (StrHexToUint64S (String, (CHAR16 **)NULL, &Result))) { 561 return MAX_UINT64; 564 UINT64 Result; 565 RETURN_STATUS Status; 566 567 Status = StrHexToUint64S (String, (CHAR16 **)NULL, &Result); 568 if (Status == RETURN_INVALID_PARAMETER) { 569 Result = 0; 562 570 } 563 571 … … 1000 1008 ) 1001 1009 { 1002 UINTN Result; 1003 1004 if (RETURN_ERROR (AsciiStrDecimalToUintnS (String, (CHAR8 **)NULL, &Result))) { 1005 return MAX_UINTN; 1010 UINTN Result; 1011 RETURN_STATUS Status; 1012 1013 Status = AsciiStrDecimalToUintnS (String, (CHAR8 **)NULL, &Result); 1014 if (Status == RETURN_INVALID_PARAMETER) { 1015 Result = 0; 1006 1016 } 1007 1017 … … 1045 1055 ) 1046 1056 { 1047 UINT64 Result; 1048 1049 if (RETURN_ERROR (AsciiStrDecimalToUint64S (String, (CHAR8 **)NULL, &Result))) { 1050 return MAX_UINT64; 1057 UINT64 Result; 1058 RETURN_STATUS Status; 1059 1060 Status = AsciiStrDecimalToUint64S (String, (CHAR8 **)NULL, &Result); 1061 if (Status == RETURN_INVALID_PARAMETER) { 1062 Result = 0; 1051 1063 } 1052 1064 … … 1094 1106 ) 1095 1107 { 1096 UINTN Result; 1097 1098 if (RETURN_ERROR (AsciiStrHexToUintnS (String, (CHAR8 **)NULL, &Result))) { 1099 return MAX_UINTN; 1108 UINTN Result; 1109 RETURN_STATUS Status; 1110 1111 Status = AsciiStrHexToUintnS (String, (CHAR8 **)NULL, &Result); 1112 if (Status == RETURN_INVALID_PARAMETER) { 1113 Result = 0; 1100 1114 } 1101 1115 … … 1143 1157 ) 1144 1158 { 1145 UINT64 Result; 1146 1147 if (RETURN_ERROR (AsciiStrHexToUint64S (String, (CHAR8 **)NULL, &Result))) { 1148 return MAX_UINT64; 1159 UINT64 Result; 1160 RETURN_STATUS Status; 1161 1162 Status = AsciiStrHexToUint64S (String, (CHAR8 **)NULL, &Result); 1163 if (Status == RETURN_INVALID_PARAMETER) { 1164 Result = 0; 1149 1165 } 1150 1166 -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseLib/X86UnitTestHost.c
r99404 r108794 67 67 ) 68 68 { 69 UINT32 RetEcx; 70 71 RetEcx = 0; 72 switch (Index) { 73 case 1: 74 RetEcx |= BIT30; /* RdRand */ 75 break; 76 } 77 69 78 if (Eax != NULL) { 70 79 *Eax = 0; … … 76 85 77 86 if (Ecx != NULL) { 78 *Ecx = 0;87 *Ecx = RetEcx; 79 88 } 80 89 -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
r107874 r108794 33 33 ZeroMemWrapper.c 34 34 CompareMemWrapper.c 35 SetMemNWrapper.c 35 36 SetMem64Wrapper.c 36 37 SetMem32Wrapper.c -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseMemoryLib/SetMemWrapper.c
r80721 r108794 1 1 /** @file 2 SetMem() and SetMemN()implementation.2 SetMem() implementation. 3 3 4 4 The following BaseMemoryLib instances contain the same copy of this file: … … 50 50 return InternalMemSetMem (Buffer, Length, Value); 51 51 } 52 53 /**54 Fills a target buffer with a value that is size UINTN, and returns the target buffer.55 56 This function fills Length bytes of Buffer with the UINTN sized value specified by57 Value, and returns Buffer. Value is repeated every sizeof(UINTN) bytes for Length58 bytes of Buffer.59 60 If Length > 0 and Buffer is NULL, then ASSERT().61 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().62 If Buffer is not aligned on a UINTN boundary, then ASSERT().63 If Length is not aligned on a UINTN boundary, then ASSERT().64 65 @param Buffer The pointer to the target buffer to fill.66 @param Length The number of bytes in Buffer to fill.67 @param Value The value with which to fill Length bytes of Buffer.68 69 @return Buffer.70 71 **/72 VOID *73 EFIAPI74 SetMemN (75 OUT VOID *Buffer,76 IN UINTN Length,77 IN UINTN Value78 )79 {80 if (sizeof (UINTN) == sizeof (UINT64)) {81 return SetMem64 (Buffer, Length, (UINT64)Value);82 } else {83 return SetMem32 (Buffer, Length, (UINT32)Value);84 }85 } -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseMemoryLibMmx/BaseMemoryLibMmx.inf
r80721 r108794 37 37 ZeroMemWrapper.c 38 38 CompareMemWrapper.c 39 SetMemNWrapper.c 39 40 SetMem64Wrapper.c 40 41 SetMem32Wrapper.c … … 47 48 48 49 [Sources.Ia32] 49 Ia32/ScanMem64.nasm50 Ia32/ScanMem32.nasm51 Ia32/ScanMem16.nasm52 Ia32/ScanMem8.nasm53 Ia32/CompareMem.nasm54 Ia32/SetMem64.nasm55 Ia32/SetMem32.nasm56 Ia32/SetMem16.nasm57 Ia32/ZeroMem.nasm58 Ia32/SetMem.nasm59 Ia32/CopyMem.nasm60 50 Ia32/ScanMem64.nasm 61 51 Ia32/ScanMem32.nasm … … 83 73 X64/SetMem.nasm 84 74 X64/CopyMem.nasm 85 X64/ScanMem64.nasm86 X64/ScanMem32.nasm87 X64/ScanMem16.nasm88 X64/ScanMem8.nasm89 X64/CompareMem.nasm90 X64/SetMem64.nasm91 X64/SetMem32.nasm92 X64/SetMem16.nasm93 X64/ZeroMem.nasm94 X64/SetMem.nasm95 X64/CopyMem.nasm96 75 X64/IsZeroBuffer.nasm 97 98 76 99 77 [LibraryClasses] -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseMemoryLibMmx/SetMemWrapper.c
r80721 r108794 1 1 /** @file 2 SetMem() and SetMemN()implementation.2 SetMem() implementation. 3 3 4 4 The following BaseMemoryLib instances contain the same copy of this file: … … 50 50 return InternalMemSetMem (Buffer, Length, Value); 51 51 } 52 53 /**54 Fills a target buffer with a value that is size UINTN, and returns the target buffer.55 56 This function fills Length bytes of Buffer with the UINTN sized value specified by57 Value, and returns Buffer. Value is repeated every sizeof(UINTN) bytes for Length58 bytes of Buffer.59 60 If Length > 0 and Buffer is NULL, then ASSERT().61 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().62 If Buffer is not aligned on a UINTN boundary, then ASSERT().63 If Length is not aligned on a UINTN boundary, then ASSERT().64 65 @param Buffer The pointer to the target buffer to fill.66 @param Length The number of bytes in Buffer to fill.67 @param Value The value with which to fill Length bytes of Buffer.68 69 @return Buffer.70 71 **/72 VOID *73 EFIAPI74 SetMemN (75 OUT VOID *Buffer,76 IN UINTN Length,77 IN UINTN Value78 )79 {80 if (sizeof (UINTN) == sizeof (UINT64)) {81 return SetMem64 (Buffer, Length, (UINT64)Value);82 } else {83 return SetMem32 (Buffer, Length, (UINT32)Value);84 }85 } -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseMemoryLibOptDxe/BaseMemoryLibOptDxe.inf
r99404 r108794 30 30 31 31 [Sources.Ia32] 32 Ia32/ScanMem64.nasm33 Ia32/ScanMem32.nasm34 Ia32/ScanMem16.nasm35 Ia32/ScanMem8.nasm36 Ia32/CompareMem.nasm37 Ia32/ZeroMem.nasm38 Ia32/SetMem64.nasm39 Ia32/SetMem32.nasm40 Ia32/SetMem16.nasm41 Ia32/SetMem.nasm42 Ia32/CopyMem.nasm43 32 Ia32/ScanMem64.nasm 44 33 Ia32/ScanMem32.nasm … … 104 93 ZeroMemWrapper.c 105 94 CompareMemWrapper.c 95 SetMemNWrapper.c 106 96 SetMem64Wrapper.c 107 97 SetMem32Wrapper.c -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseMemoryLibOptDxe/SetMemWrapper.c
r80721 r108794 1 1 /** @file 2 SetMem() and SetMemN()implementation.2 SetMem() implementation. 3 3 4 4 The following BaseMemoryLib instances contain the same copy of this file: … … 50 50 return InternalMemSetMem (Buffer, Length, Value); 51 51 } 52 53 /**54 Fills a target buffer with a value that is size UINTN, and returns the target buffer.55 56 This function fills Length bytes of Buffer with the UINTN sized value specified by57 Value, and returns Buffer. Value is repeated every sizeof(UINTN) bytes for Length58 bytes of Buffer.59 60 If Length > 0 and Buffer is NULL, then ASSERT().61 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().62 If Buffer is not aligned on a UINTN boundary, then ASSERT().63 If Length is not aligned on a UINTN boundary, then ASSERT().64 65 @param Buffer The pointer to the target buffer to fill.66 @param Length The number of bytes in Buffer to fill.67 @param Value The value with which to fill Length bytes of Buffer.68 69 @return Buffer.70 71 **/72 VOID *73 EFIAPI74 SetMemN (75 OUT VOID *Buffer,76 IN UINTN Length,77 IN UINTN Value78 )79 {80 if (sizeof (UINTN) == sizeof (UINT64)) {81 return SetMem64 (Buffer, Length, (UINT64)Value);82 } else {83 return SetMem32 (Buffer, Length, (UINT32)Value);84 }85 } -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseMemoryLibOptPei/BaseMemoryLibOptPei.inf
r80721 r108794 28 28 [Sources] 29 29 MemLibInternals.h 30 ScanMem64Wrapper.c 31 ScanMem32Wrapper.c 32 ScanMem16Wrapper.c 33 ScanMem8Wrapper.c 34 ZeroMemWrapper.c 35 CompareMemWrapper.c 36 SetMemNWrapper.c 37 SetMem64Wrapper.c 38 SetMem32Wrapper.c 39 SetMem16Wrapper.c 40 SetMemWrapper.c 41 CopyMemWrapper.c 42 IsZeroBufferWrapper.c 43 MemLibGuid.c 30 44 31 45 [Sources.Ia32] … … 41 55 Ia32/SetMem.nasm 42 56 Ia32/CopyMem.nasm 43 Ia32/ScanMem64.nasm44 Ia32/ScanMem32.nasm45 Ia32/ScanMem16.nasm46 Ia32/ScanMem8.nasm47 Ia32/CompareMem.nasm48 Ia32/ZeroMem.nasm49 Ia32/SetMem64.nasm50 Ia32/SetMem32.nasm51 Ia32/SetMem16.nasm52 Ia32/SetMem.nasm53 Ia32/CopyMem.nasm54 57 Ia32/IsZeroBuffer.nasm 55 ScanMem64Wrapper.c56 ScanMem32Wrapper.c57 ScanMem16Wrapper.c58 ScanMem8Wrapper.c59 ZeroMemWrapper.c60 CompareMemWrapper.c61 SetMem64Wrapper.c62 SetMem32Wrapper.c63 SetMem16Wrapper.c64 SetMemWrapper.c65 CopyMemWrapper.c66 IsZeroBufferWrapper.c67 MemLibGuid.c68 58 69 59 [Sources.X64] … … 80 70 X64/CopyMem.nasm 81 71 X64/IsZeroBuffer.nasm 82 ScanMem64Wrapper.c83 ScanMem32Wrapper.c84 ScanMem16Wrapper.c85 ScanMem8Wrapper.c86 ZeroMemWrapper.c87 CompareMemWrapper.c88 SetMem64Wrapper.c89 SetMem32Wrapper.c90 SetMem16Wrapper.c91 SetMemWrapper.c92 CopyMemWrapper.c93 IsZeroBufferWrapper.c94 MemLibGuid.c95 96 72 97 73 [Packages] -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseMemoryLibOptPei/SetMemWrapper.c
r80721 r108794 1 1 /** @file 2 SetMem() and SetMemN()implementation.2 SetMem() implementation. 3 3 4 4 The following BaseMemoryLib instances contain the same copy of this file: … … 50 50 return InternalMemSetMem (Buffer, Length, Value); 51 51 } 52 53 /**54 Fills a target buffer with a value that is size UINTN, and returns the target buffer.55 56 This function fills Length bytes of Buffer with the UINTN sized value specified by57 Value, and returns Buffer. Value is repeated every sizeof(UINTN) bytes for Length58 bytes of Buffer.59 60 If Length > 0 and Buffer is NULL, then ASSERT().61 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().62 If Buffer is not aligned on a UINTN boundary, then ASSERT().63 If Length is not aligned on a UINTN boundary, then ASSERT().64 65 @param Buffer The pointer to the target buffer to fill.66 @param Length The number of bytes in Buffer to fill.67 @param Value The value with which to fill Length bytes of Buffer.68 69 @return Buffer.70 71 **/72 VOID *73 EFIAPI74 SetMemN (75 OUT VOID *Buffer,76 IN UINTN Length,77 IN UINTN Value78 )79 {80 if (sizeof (UINTN) == sizeof (UINT64)) {81 return SetMem64 (Buffer, Length, (UINT64)Value);82 } else {83 return SetMem32 (Buffer, Length, (UINT32)Value);84 }85 } -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf
r80721 r108794 34 34 ZeroMemWrapper.c 35 35 CompareMemWrapper.c 36 SetMemNWrapper.c 36 37 SetMem64Wrapper.c 37 38 SetMem32Wrapper.c … … 43 44 44 45 [Sources.Ia32] 45 Ia32/ScanMem64.nasm46 Ia32/ScanMem32.nasm47 Ia32/ScanMem16.nasm48 Ia32/ScanMem8.nasm49 Ia32/CompareMem.nasm50 Ia32/ZeroMem.nasm51 Ia32/SetMem64.nasm52 Ia32/SetMem32.nasm53 Ia32/SetMem16.nasm54 Ia32/SetMem.nasm55 Ia32/CopyMem.nasm56 46 Ia32/ScanMem64.nasm 57 47 Ia32/ScanMem32.nasm … … 79 69 X64/SetMem.nasm 80 70 X64/CopyMem.nasm 81 X64/ScanMem64.nasm82 X64/ScanMem32.nasm83 X64/ScanMem16.nasm84 X64/ScanMem8.nasm85 X64/CompareMem.nasm86 X64/ZeroMem.nasm87 X64/SetMem64.nasm88 X64/SetMem32.nasm89 X64/SetMem16.nasm90 X64/SetMem.nasm91 X64/CopyMem.nasm92 71 X64/IsZeroBuffer.nasm 93 72 -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseMemoryLibRepStr/SetMemWrapper.c
r80721 r108794 1 1 /** @file 2 SetMem() and SetMemN()implementation.2 SetMem() implementation. 3 3 4 4 The following BaseMemoryLib instances contain the same copy of this file: … … 50 50 return InternalMemSetMem (Buffer, Length, Value); 51 51 } 52 53 /**54 Fills a target buffer with a value that is size UINTN, and returns the target buffer.55 56 This function fills Length bytes of Buffer with the UINTN sized value specified by57 Value, and returns Buffer. Value is repeated every sizeof(UINTN) bytes for Length58 bytes of Buffer.59 60 If Length > 0 and Buffer is NULL, then ASSERT().61 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().62 If Buffer is not aligned on a UINTN boundary, then ASSERT().63 If Length is not aligned on a UINTN boundary, then ASSERT().64 65 @param Buffer The pointer to the target buffer to fill.66 @param Length The number of bytes in Buffer to fill.67 @param Value The value with which to fill Length bytes of Buffer.68 69 @return Buffer.70 71 **/72 VOID *73 EFIAPI74 SetMemN (75 OUT VOID *Buffer,76 IN UINTN Length,77 IN UINTN Value78 )79 {80 if (sizeof (UINTN) == sizeof (UINT64)) {81 return SetMem64 (Buffer, Length, (UINT64)Value);82 } else {83 return SetMem32 (Buffer, Length, (UINT32)Value);84 }85 } -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseMemoryLibSse2/BaseMemoryLibSse2.inf
r80721 r108794 33 33 ZeroMemWrapper.c 34 34 CompareMemWrapper.c 35 SetMemNWrapper.c 35 36 SetMem64Wrapper.c 36 37 SetMem32Wrapper.c … … 42 43 43 44 [Sources.Ia32] 44 Ia32/ScanMem64.nasm45 Ia32/ScanMem32.nasm46 Ia32/ScanMem16.nasm47 Ia32/ScanMem8.nasm48 Ia32/CompareMem.nasm49 Ia32/ZeroMem.nasm50 Ia32/SetMem64.nasm51 Ia32/SetMem32.nasm52 Ia32/SetMem16.nasm53 Ia32/SetMem.nasm54 Ia32/CopyMem.nasm55 45 Ia32/ScanMem64.nasm 56 46 Ia32/ScanMem32.nasm … … 78 68 X64/SetMem.nasm 79 69 X64/CopyMem.nasm 80 X64/ScanMem64.nasm81 X64/ScanMem32.nasm82 X64/ScanMem16.nasm83 X64/ScanMem8.nasm84 X64/CompareMem.nasm85 X64/ZeroMem.nasm86 X64/SetMem64.nasm87 X64/SetMem32.nasm88 X64/SetMem16.nasm89 X64/SetMem.nasm90 X64/CopyMem.nasm91 70 X64/IsZeroBuffer.nasm 92 71 -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseMemoryLibSse2/SetMemWrapper.c
r80721 r108794 1 1 /** @file 2 SetMem() and SetMemN()implementation.2 SetMem() implementation. 3 3 4 4 The following BaseMemoryLib instances contain the same copy of this file: … … 50 50 return InternalMemSetMem (Buffer, Length, Value); 51 51 } 52 53 /**54 Fills a target buffer with a value that is size UINTN, and returns the target buffer.55 56 This function fills Length bytes of Buffer with the UINTN sized value specified by57 Value, and returns Buffer. Value is repeated every sizeof(UINTN) bytes for Length58 bytes of Buffer.59 60 If Length > 0 and Buffer is NULL, then ASSERT().61 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().62 If Buffer is not aligned on a UINTN boundary, then ASSERT().63 If Length is not aligned on a UINTN boundary, then ASSERT().64 65 @param Buffer The pointer to the target buffer to fill.66 @param Length The number of bytes in Buffer to fill.67 @param Value The value with which to fill Length bytes of Buffer.68 69 @return Buffer.70 71 **/72 VOID *73 EFIAPI74 SetMemN (75 OUT VOID *Buffer,76 IN UINTN Length,77 IN UINTN Value78 )79 {80 if (sizeof (UINTN) == sizeof (UINT64)) {81 return SetMem64 (Buffer, Length, (UINT64)Value);82 } else {83 return SetMem32 (Buffer, Length, (UINT32)Value);84 }85 } -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
r101291 r108794 25 25 26 26 #include "BasePeCoffLibInternals.h" 27 #include <Library/SafeIntLib.h> 27 28 28 29 /** … … 69 70 UINTN ReadSize; 70 71 UINT32 SectionHeaderOffset; 71 UINT 32Index;72 UINTN Index; 72 73 UINT32 HeaderWithoutDataDir; 73 74 CHAR8 BufferData; … … 976 977 UINT32 NumberOfRvaAndSizes; 977 978 UINT32 TeStrippedOffset; 979 UINT32 EndAddress; 978 980 979 981 ASSERT (ImageContext != NULL); … … 1055 1057 } 1056 1058 1059 RelocBase = NULL; 1060 RelocBaseEnd = NULL; 1057 1061 if ((RelocDir != NULL) && (RelocDir->Size > 0)) { 1058 RelocBase = (EFI_IMAGE_BASE_RELOCATION *)PeCoffLoaderImageAddress (ImageContext, RelocDir->VirtualAddress, TeStrippedOffset); 1059 RelocBaseEnd = (EFI_IMAGE_BASE_RELOCATION *)PeCoffLoaderImageAddress ( 1060 ImageContext, 1061 RelocDir->VirtualAddress + RelocDir->Size - 1, 1062 TeStrippedOffset 1063 ); 1062 Status = SafeUint32Add (RelocDir->VirtualAddress, (RelocDir->Size - 1), &EndAddress); 1063 if (!RETURN_ERROR (Status)) { 1064 RelocBase = (EFI_IMAGE_BASE_RELOCATION *)PeCoffLoaderImageAddress (ImageContext, RelocDir->VirtualAddress, TeStrippedOffset); 1065 RelocBaseEnd = (EFI_IMAGE_BASE_RELOCATION *)PeCoffLoaderImageAddress ( 1066 ImageContext, 1067 EndAddress, 1068 TeStrippedOffset 1069 ); 1070 } 1071 1064 1072 if ((RelocBase == NULL) || (RelocBaseEnd == NULL) || ((UINTN)RelocBaseEnd < (UINTN)RelocBase)) { 1065 1073 ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION; 1074 DEBUG ((DEBUG_ERROR, "Relocation block is not valid\n")); 1066 1075 return RETURN_LOAD_ERROR; 1067 1076 } 1068 } else {1069 //1070 // Set base and end to bypass processing below.1071 //1072 RelocBase = RelocBaseEnd = NULL;1073 1077 } 1074 1078 … … 1408 1412 } 1409 1413 1410 if ( Section->SizeOfRawData > 0) {1414 if ((Section->SizeOfRawData > 0) && (Base != NULL)) { 1411 1415 Status = ImageContext->ImageRead ( 1412 1416 ImageContext->Handle, … … 1425 1429 // 1426 1430 1427 if ( Size < Section->Misc.VirtualSize) {1431 if ((Size < Section->Misc.VirtualSize) && (Base != NULL)) { 1428 1432 ZeroMem (Base + Size, Section->Misc.VirtualSize - Size); 1429 1433 } … … 1768 1772 RETURN_STATUS Status; 1769 1773 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; 1774 UINT32 EndAddress; 1770 1775 1771 1776 if ((RelocationData == NULL) || (ImageBase == 0x0) || (VirtImageBase == 0x0)) { … … 1829 1834 RelocDir = DataDirectory + EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC; 1830 1835 if ((RelocDir != NULL) && (RelocDir->Size > 0)) { 1831 RelocBase = (EFI_IMAGE_BASE_RELOCATION *)PeCoffLoaderImageAddress (&ImageContext, RelocDir->VirtualAddress, 0); 1832 RelocBaseEnd = (EFI_IMAGE_BASE_RELOCATION *)PeCoffLoaderImageAddress ( 1833 &ImageContext, 1834 RelocDir->VirtualAddress + RelocDir->Size - 1, 1835 0 1836 ); 1836 Status = SafeUint32Add (RelocDir->VirtualAddress, (RelocDir->Size - 1), &EndAddress); 1837 if (!RETURN_ERROR (Status)) { 1838 RelocBase = (EFI_IMAGE_BASE_RELOCATION *)PeCoffLoaderImageAddress (&ImageContext, RelocDir->VirtualAddress, 0); 1839 RelocBaseEnd = (EFI_IMAGE_BASE_RELOCATION *)PeCoffLoaderImageAddress ( 1840 &ImageContext, 1841 EndAddress, 1842 0 1843 ); 1844 } 1837 1845 } 1838 1846 -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
r99404 r108794 59 59 PeCoffExtraActionLib 60 60 BaseMemoryLib 61 SafeIntLib 61 62 -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BasePeCoffLib/LoongArch/PeCoffLoaderEx.c
r99404 r108794 105 105 ) 106 106 { 107 if (Machine == IMAGE_FILE_MACHINE_LOONGARCH64) { 107 /* 108 * ARM64 and X64 may allow such foreign images to be used when 109 * a driver implementing EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL is 110 * present. 111 */ 112 if ((Machine == IMAGE_FILE_MACHINE_LOONGARCH64) || 113 (Machine == IMAGE_FILE_MACHINE_ARM64) || 114 (Machine == IMAGE_FILE_MACHINE_X64)) 115 { 108 116 return TRUE; 109 117 } -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseRngLib/AArch64/ArmRng.S
r101291 r108794 9 9 #------------------------------------------------------------------------------ 10 10 11 #include " BaseRngLibInternals.h"11 #include "ArmRng.h" 12 12 13 13 .text -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseRngLib/AArch64/ArmRng.asm
r89983 r108794 9 9 ;------------------------------------------------------------------------------ 10 10 11 #include " BaseRngLibInternals.h"11 #include "ArmRng.h" 12 12 13 13 EXPORT ArmRndr -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseRngLib/AArch64/ArmRng.h
r99404 r108794 11 11 #ifndef ARM_RNG_H_ 12 12 #define ARM_RNG_H_ 13 14 #include <AArch64/AArch64.h> 13 15 14 16 /** … … 28 30 ); 29 31 30 /**31 Reads the ID_AA64ISAR0 Register.32 33 @return The contents of the ID_AA64ISAR0 register.34 35 **/36 UINT6437 EFIAPI38 ArmReadIdIsar0 (39 VOID40 );41 42 32 #endif /* ARM_RNG_H_ */ -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseRngLib/AArch64/Rndr.c
r106386 r108794 27 27 #ifndef VBOX 28 28 STATIC BOOLEAN mRndrSupported; 29 #endif 30 31 // 32 // Bit mask used to determine if RNDR instruction is supported. 33 // 34 #define RNDR_MASK ((UINT64)MAX_UINT16 << 60U) 29 #else 30 inline BOOLEAN VBoxIsRndrSupported() 31 { 32 UINT64 Isar0; 33 34 Isar0 = ArmReadIdAA64Isar0Reg (); 35 return !!((Isar0 >> ARM_ID_AA64ISAR0_EL1_RNDR_SHIFT) & ARM_ID_AA64ISAR0_EL1_RNDR_MASK); 36 } 37 #endif 35 38 36 39 /** … … 58 61 // MSR. A non-zero value indicates that the processor supports the RNDR instruction. 59 62 // 60 Isar0 = ArmReadIdIsar0 (); 61 62 mRndrSupported = ((Isar0 & RNDR_MASK) != 0); 63 Isar0 = ArmReadIdAA64Isar0Reg (); 64 mRndrSupported = !!((Isar0 >> ARM_ID_AA64ISAR0_EL1_RNDR_SHIFT) & ARM_ID_AA64ISAR0_EL1_RNDR_MASK); 63 65 #endif 64 66 … … 150 152 return mRndrSupported; 151 153 #else 152 return (ArmReadIdIsar0() & RNDR_MASK) != 0;154 return VBoxIsRndrSupported(); 153 155 #endif 154 156 } … … 181 183 } 182 184 #else 183 if (! (ArmReadIdIsar0() & RNDR_MASK)) {185 if (!VBoxIsRndrSupported()) { 184 186 return EFI_UNSUPPORTED; 185 187 } -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseRngLib/BaseRngLib.inf
r105670 r108794 39 39 AArch64/ArmRng.h 40 40 41 AArch64/ArmReadIdIsar0.S | GCC42 41 AArch64/ArmRng.S | GCC 43 42 44 AArch64/ArmReadIdIsar0.asm | MSFT45 43 AArch64/ArmRng.asm | MSFT 46 44 … … 50 48 [Guids.Ia32, Guids.X64] 51 49 gEfiRngAlgorithmSp80090Ctr256Guid 50 51 [Sources.RISCV64] 52 Riscv/Rng.c 53 Riscv/Seed.S | GCC 52 54 53 55 [Packages] … … 60 62 BaseLib 61 63 DebugLib 64 65 [Pcd.RISCV64] 66 # Does the CPU support the Zkr extension (for the `Seed` CSR) 67 gEfiMdePkgTokenSpaceGuid.PcdRiscVFeatureOverride ## CONSUMES -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseRngLib/BaseRngLibInternals.h
r105670 r108794 70 70 ); 71 71 72 #if defined (MDE_CPU_AARCH64)73 74 // RNDR, Random Number75 #define RNDR S3_3_C2_C4_076 77 #endif78 79 72 #endif // BASE_RNGLIB_INTERNALS_H_ -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseRngLib/Rand/RdRand.c
r105670 r108794 3 3 to provide high-quality random numbers. 4 4 5 Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR> 5 6 Copyright (c) 2023, Arm Limited. All rights reserved.<BR> 7 Copyright (c) 2022, Pedro Falcato. All rights reserved.<BR> 6 8 Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR> 7 9 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR> … … 23 25 #define RDRAND_MASK BIT30 24 26 25 STATIC BOOLEAN mRdRandSupported; 27 // 28 // Intel SDM says 10 tries is good enough for reliable RDRAND usage. 29 // 30 #define RDRAND_RETRIES 10 31 32 #define RDRAND_TEST_SAMPLES 8 33 34 #define RDRAND_MIN_CHANGE 5 35 36 // 37 // Add a define for native-word RDRAND, just for the test. 38 // 39 #ifdef MDE_CPU_X64 40 #define ASM_RDRAND AsmRdRand64 41 #else 42 #define ASM_RDRAND AsmRdRand32 43 #endif 44 45 /** 46 Tests RDRAND for broken implementations. 47 48 @retval TRUE RDRAND is reliable (and hopefully safe). 49 @retval FALSE RDRAND is unreliable and should be disabled, despite CPUID. 50 51 **/ 52 STATIC 53 BOOLEAN 54 TestRdRand ( 55 VOID 56 ) 57 { 58 // 59 // Test for notoriously broken rdrand implementations that always return the same 60 // value, like the Zen 3 uarch (all-1s) or other several AMD families on suspend/resume (also all-1s). 61 // Note that this should be expanded to extensively test for other sorts of possible errata. 62 // 63 64 // 65 // Our algorithm samples rdrand $RDRAND_TEST_SAMPLES times and expects 66 // a different result $RDRAND_MIN_CHANGE times for reliable RDRAND usage. 67 // 68 UINTN Prev; 69 UINT8 Idx; 70 UINT8 TestIteration; 71 UINT32 Changed; 72 73 Changed = 0; 74 75 for (TestIteration = 0; TestIteration < RDRAND_TEST_SAMPLES; TestIteration++) { 76 UINTN Sample; 77 // 78 // Note: We use a retry loop for rdrand. Normal users get this in BaseRng.c 79 // Any failure to get a random number will assume RDRAND does not work. 80 // 81 for (Idx = 0; Idx < RDRAND_RETRIES; Idx++) { 82 if (ASM_RDRAND (&Sample)) { 83 break; 84 } 85 } 86 87 if (Idx == RDRAND_RETRIES) { 88 DEBUG ((DEBUG_ERROR, "BaseRngLib/x86: CPU BUG: Failed to get an RDRAND random number - disabling\n")); 89 return FALSE; 90 } 91 92 if (TestIteration != 0) { 93 Changed += Sample != Prev; 94 } 95 96 Prev = Sample; 97 } 98 99 if (Changed < RDRAND_MIN_CHANGE) { 100 DEBUG ((DEBUG_ERROR, "BaseRngLib/x86: CPU BUG: RDRAND not reliable - disabling\n")); 101 return FALSE; 102 } 103 104 return TRUE; 105 } 106 107 #undef ASM_RDRAND 26 108 27 109 /** … … 42 124 ) 43 125 { 44 UINT32 RegEcx; 126 return EFI_SUCCESS; 127 } 128 129 /** 130 Generates a 16-bit random number. 131 132 @param[out] Rand Buffer pointer to store the 16-bit random value. 133 134 @retval TRUE Random number generated successfully. 135 @retval FALSE Failed to generate the random number. 136 137 **/ 138 BOOLEAN 139 EFIAPI 140 ArchGetRandomNumber16 ( 141 OUT UINT16 *Rand 142 ) 143 { 144 return AsmRdRand16 (Rand); 145 } 146 147 /** 148 Generates a 32-bit random number. 149 150 @param[out] Rand Buffer pointer to store the 32-bit random value. 151 152 @retval TRUE Random number generated successfully. 153 @retval FALSE Failed to generate the random number. 154 155 **/ 156 BOOLEAN 157 EFIAPI 158 ArchGetRandomNumber32 ( 159 OUT UINT32 *Rand 160 ) 161 { 162 return AsmRdRand32 (Rand); 163 } 164 165 /** 166 Generates a 64-bit random number. 167 168 @param[out] Rand Buffer pointer to store the 64-bit random value. 169 170 @retval TRUE Random number generated successfully. 171 @retval FALSE Failed to generate the random number. 172 173 **/ 174 BOOLEAN 175 EFIAPI 176 ArchGetRandomNumber64 ( 177 OUT UINT64 *Rand 178 ) 179 { 180 return AsmRdRand64 (Rand); 181 } 182 183 /** 184 Checks whether RDRAND is supported. 185 186 @retval TRUE RDRAND is supported. 187 @retval FALSE RDRAND is not supported. 188 189 **/ 190 BOOLEAN 191 EFIAPI 192 ArchIsRngSupported ( 193 VOID 194 ) 195 { 196 BOOLEAN RdRandSupported; 197 UINT32 RegEcx; 45 198 46 199 // … … 49 202 // 50 203 AsmCpuid (1, 0, 0, &RegEcx, 0); 51 ASSERT ((RegEcx & RDRAND_MASK) == RDRAND_MASK); 52 53 mRdRandSupported = ((RegEcx & RDRAND_MASK) == RDRAND_MASK); 54 55 return EFI_SUCCESS; 56 } 57 58 /** 59 Generates a 16-bit random number. 60 61 @param[out] Rand Buffer pointer to store the 16-bit random value. 62 63 @retval TRUE Random number generated successfully. 64 @retval FALSE Failed to generate the random number. 65 66 **/ 67 BOOLEAN 68 EFIAPI 69 ArchGetRandomNumber16 ( 70 OUT UINT16 *Rand 71 ) 72 { 73 return AsmRdRand16 (Rand); 74 } 75 76 /** 77 Generates a 32-bit random number. 78 79 @param[out] Rand Buffer pointer to store the 32-bit random value. 80 81 @retval TRUE Random number generated successfully. 82 @retval FALSE Failed to generate the random number. 83 84 **/ 85 BOOLEAN 86 EFIAPI 87 ArchGetRandomNumber32 ( 88 OUT UINT32 *Rand 89 ) 90 { 91 return AsmRdRand32 (Rand); 92 } 93 94 /** 95 Generates a 64-bit random number. 96 97 @param[out] Rand Buffer pointer to store the 64-bit random value. 98 99 @retval TRUE Random number generated successfully. 100 @retval FALSE Failed to generate the random number. 101 102 **/ 103 BOOLEAN 104 EFIAPI 105 ArchGetRandomNumber64 ( 106 OUT UINT64 *Rand 107 ) 108 { 109 return AsmRdRand64 (Rand); 110 } 111 112 /** 113 Checks whether RDRAND is supported. 114 115 @retval TRUE RDRAND is supported. 116 @retval FALSE RDRAND is not supported. 117 118 **/ 119 BOOLEAN 120 EFIAPI 121 ArchIsRngSupported ( 122 VOID 123 ) 124 { 125 /* 126 Existing software depends on this always returning TRUE, so for 127 now hard-code it. 128 129 return mRdRandSupported; 130 */ 131 return TRUE; 204 205 RdRandSupported = ((RegEcx & RDRAND_MASK) == RDRAND_MASK); 206 207 if (RdRandSupported) { 208 RdRandSupported = TestRdRand (); 209 } 210 211 return RdRandSupported; 132 212 } 133 213 -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf
r80721 r108794 34 34 BaseLib 35 35 DebugLib 36 StackCheckLib 36 37 -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/DxeRngLib/DxeRngLib.c
r105670 r108794 2 2 Provides an implementation of the library class RngLib that uses the Rng protocol. 3 3 4 Copyright (c) 2023 , Arm Limited. All rights reserved.4 Copyright (c) 2023 - 2024, Arm Limited. All rights reserved. 5 5 Copyright (c) Microsoft Corporation. All rights reserved. 6 6 SPDX-License-Identifier: BSD-2-Clause-Patent … … 9 9 #include <Uefi.h> 10 10 #include <Library/UefiBootServicesTableLib.h> 11 #include <Library/BaseMemoryLib.h> 11 12 #include <Library/DebugLib.h> 13 #include <Library/MemoryAllocationLib.h> 12 14 #include <Library/RngLib.h> 13 15 #include <Protocol/Rng.h> 16 17 STATIC EFI_RNG_PROTOCOL *mRngProtocol; 18 STATIC UINTN mFirstAlgo = MAX_UINTN; 19 20 typedef struct { 21 /// Guid of the secure algorithm. 22 EFI_GUID *Guid; 23 24 /// Algorithm name. 25 CONST CHAR8 *Name; 26 27 /// The algorithm is available for use. 28 BOOLEAN Available; 29 } SECURE_RNG_ALGO_ARRAY; 30 31 // 32 // These represent UEFI SPEC defined algorithms that should be supported by 33 // the RNG protocol and are generally considered secure. 34 // 35 static SECURE_RNG_ALGO_ARRAY mSecureHashAlgorithms[] = { 36 #ifdef MDE_CPU_AARCH64 37 { 38 &gEfiRngAlgorithmArmRndr, // unspecified SP800-90A DRBG (through RNDR instr.) 39 "ARM-RNDR", 40 FALSE, 41 }, 42 #endif 43 { 44 &gEfiRngAlgorithmSp80090Ctr256Guid, // SP800-90A DRBG CTR using AES-256 45 "DRBG-CTR", 46 FALSE, 47 }, 48 { 49 &gEfiRngAlgorithmSp80090Hmac256Guid, // SP800-90A DRBG HMAC using SHA-256 50 "DRBG-HMAC", 51 FALSE, 52 }, 53 { 54 &gEfiRngAlgorithmSp80090Hash256Guid, // SP800-90A DRBG Hash using SHA-256 55 "DRBG-Hash", 56 FALSE, 57 }, 58 { 59 &gEfiRngAlgorithmRaw, // Raw data from NRBG (or TRNG) 60 "TRNG", 61 FALSE, 62 }, 63 }; 64 65 /** 66 Constructor routine to probe the available secure Rng algorithms. 67 68 @param ImageHandle The firmware allocated handle for the EFI image. 69 @param SystemTable A pointer to the EFI System Table. 70 71 @retval EFI_SUCCESS Success. 72 @retval EFI_NOT_FOUND Not found. 73 @retval EFI_INVALID_PARAMETER Invalid parameter. 74 **/ 75 EFI_STATUS 76 EFIAPI 77 DxeRngLibConstructor ( 78 IN EFI_HANDLE ImageHandle, 79 IN EFI_SYSTEM_TABLE *SystemTable 80 ) 81 { 82 EFI_STATUS Status; 83 UINTN RngArraySize; 84 UINTN RngArrayCnt; 85 UINT32 Index; 86 UINT32 Index1; 87 EFI_RNG_ALGORITHM *RngArray; 88 89 Status = gBS->LocateProtocol (&gEfiRngProtocolGuid, NULL, (VOID **)&mRngProtocol); 90 if (EFI_ERROR (Status) || (mRngProtocol == NULL)) { 91 DEBUG ((DEBUG_ERROR, "%a: Could not locate RNG protocol, Status = %r\n", __func__, Status)); 92 return Status; 93 } 94 95 RngArraySize = 0; 96 97 Status = mRngProtocol->GetInfo (mRngProtocol, &RngArraySize, NULL); 98 if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) { 99 return Status; 100 } else if (RngArraySize == 0) { 101 return EFI_NOT_FOUND; 102 } 103 104 RngArrayCnt = RngArraySize / sizeof (*RngArray); 105 106 RngArray = AllocateZeroPool (RngArraySize); 107 if (RngArray == NULL) { 108 return EFI_OUT_OF_RESOURCES; 109 } 110 111 Status = mRngProtocol->GetInfo (mRngProtocol, &RngArraySize, RngArray); 112 if (EFI_ERROR (Status)) { 113 goto ExitHandler; 114 } 115 116 for (Index = 0; Index < RngArrayCnt; Index++) { 117 for (Index1 = 0; Index1 < ARRAY_SIZE (mSecureHashAlgorithms); Index1++) { 118 if (CompareGuid (&RngArray[Index], mSecureHashAlgorithms[Index1].Guid)) { 119 mSecureHashAlgorithms[Index1].Available = TRUE; 120 if (mFirstAlgo == MAX_UINTN) { 121 mFirstAlgo = Index1; 122 } 123 124 break; 125 } 126 } 127 } 128 129 ExitHandler: 130 FreePool (RngArray); 131 return Status; 132 } 14 133 15 134 /** … … 33 152 ) 34 153 { 35 EFI_STATUS Status; 36 EFI_RNG_PROTOCOL *RngProtocol; 37 38 RngProtocol = NULL; 154 EFI_STATUS Status; 155 UINTN Index; 156 SECURE_RNG_ALGO_ARRAY *Algo; 39 157 40 158 if (Buffer == NULL) { … … 43 161 } 44 162 45 Status = gBS->LocateProtocol (&gEfiRngProtocolGuid, NULL, (VOID **)&RngProtocol); 46 if (EFI_ERROR (Status) || (RngProtocol == NULL)) { 47 DEBUG ((DEBUG_ERROR, "%a: Could not locate RNG prototocol, Status = %r\n", __func__, Status)); 48 return Status; 49 } 50 51 Status = RngProtocol->GetRNG (RngProtocol, &gEfiRngAlgorithmSp80090Ctr256Guid, BufferSize, Buffer); 52 DEBUG ((DEBUG_INFO, "%a: GetRNG algorithm CTR-256 - Status = %r\n", __func__, Status)); 53 if (!EFI_ERROR (Status)) { 54 return Status; 55 } 56 57 Status = RngProtocol->GetRNG (RngProtocol, &gEfiRngAlgorithmSp80090Hmac256Guid, BufferSize, Buffer); 58 DEBUG ((DEBUG_INFO, "%a: GetRNG algorithm HMAC-256 - Status = %r\n", __func__, Status)); 59 if (!EFI_ERROR (Status)) { 60 return Status; 61 } 62 63 Status = RngProtocol->GetRNG (RngProtocol, &gEfiRngAlgorithmSp80090Hash256Guid, BufferSize, Buffer); 64 DEBUG ((DEBUG_INFO, "%a: GetRNG algorithm Hash-256 - Status = %r\n", __func__, Status)); 65 if (!EFI_ERROR (Status)) { 66 return Status; 67 } 68 69 Status = RngProtocol->GetRNG (RngProtocol, &gEfiRngAlgorithmRaw, BufferSize, Buffer); 70 DEBUG ((DEBUG_INFO, "%a: GetRNG algorithm Raw - Status = %r\n", __func__, Status)); 71 if (!EFI_ERROR (Status)) { 72 return Status; 73 } 74 75 // If all the other methods have failed, use the default method from the RngProtocol 76 Status = RngProtocol->GetRNG (RngProtocol, NULL, BufferSize, Buffer); 77 DEBUG ((DEBUG_INFO, "%a: GetRNG algorithm default - Status = %r\n", __func__, Status)); 78 if (!EFI_ERROR (Status)) { 79 return Status; 163 if (mRngProtocol == NULL) { 164 return EFI_NOT_FOUND; 165 } 166 167 // Try the first available algorithm. 168 if (mFirstAlgo != MAX_UINTN) { 169 Algo = &mSecureHashAlgorithms[mFirstAlgo]; 170 Status = mRngProtocol->GetRNG (mRngProtocol, Algo->Guid, BufferSize, Buffer); 171 DEBUG (( 172 DEBUG_INFO, 173 "%a: GetRNG algorithm %a - Status = %r\n", 174 __func__, 175 Algo->Name, 176 Status 177 )); 178 if (!EFI_ERROR (Status)) { 179 return Status; 180 } 181 182 Index = mFirstAlgo + 1; 183 } else { 184 Index = 0; 185 } 186 187 // Iterate over other available algorithms. 188 for ( ; Index < ARRAY_SIZE (mSecureHashAlgorithms); Index++) { 189 Algo = &mSecureHashAlgorithms[Index]; 190 if (!Algo->Available) { 191 continue; 192 } 193 194 Status = mRngProtocol->GetRNG (mRngProtocol, Algo->Guid, BufferSize, Buffer); 195 DEBUG (( 196 DEBUG_INFO, 197 "%a: GetRNG algorithm %a - Status = %r\n", 198 __func__, 199 Algo->Name, 200 Status 201 )); 202 if (!EFI_ERROR (Status)) { 203 return Status; 204 } 205 } 206 207 if (PcdGetBool (PcdEnforceSecureRngAlgorithms)) { 208 // Platform does not permit the use of the default (insecure) algorithm. 209 Status = EFI_SECURITY_VIOLATION; 210 } else { 211 // If all the other methods have failed, use the default method from the RngProtocol 212 Status = mRngProtocol->GetRNG (mRngProtocol, NULL, BufferSize, Buffer); 213 DEBUG ((DEBUG_INFO, "%a: GetRNG algorithm default - Status = %r\n", __func__, Status)); 214 if (!EFI_ERROR (Status)) { 215 return Status; 216 } 80 217 } 81 218 82 219 // If we get to this point, we have failed 83 DEBUG ((DEBUG_ERROR, "%a: GetRNG() failed, staus = %r\n", __func__, Status));220 DEBUG ((DEBUG_ERROR, "%a: GetRNG() failed, Status = %r\n", __func__, Status)); 84 221 85 222 return Status; -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/DxeRngLib/DxeRngLib.inf
r105670 r108794 16 16 VERSION_STRING = 1.0 17 17 LIBRARY_CLASS = RngLib|DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION UEFI_DRIVER 18 CONSTRUCTOR = DxeRngLibConstructor 18 19 19 20 [Packages] … … 25 26 [LibraryClasses] 26 27 DebugLib 28 MemoryAllocationLib 27 29 UefiBootServicesTableLib 28 30 … … 38 40 gEfiRngAlgorithmSp80090Hmac256Guid 39 41 gEfiRngAlgorithmRaw 42 43 [Guids.AARCH64] 44 gEfiRngAlgorithmArmRndr 45 46 [FixedPcd] 47 gEfiMdePkgTokenSpaceGuid.PcdEnforceSecureRngAlgorithms ## CONSUMES -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/PeiCoreEntryPoint/PeiCoreEntryPoint.inf
r80721 r108794 32 32 BaseLib 33 33 DebugLib 34 34 StackCheckLib -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/PeiServicesLib/PeiServicesLib.c
r99404 r108794 686 686 687 687 FvInfoPpiDescriptor = AllocatePool (sizeof (EFI_PEI_PPI_DESCRIPTOR)); 688 ASSERT (FvInfoPpiDescriptor != NULL); 688 if (FvInfoPpiDescriptor == NULL) { 689 ASSERT (FvInfoPpiDescriptor != NULL); 690 // Need to return here, FV may not be published, but we are out of resources anyway... 691 return; 692 } 689 693 690 694 FvInfoPpiDescriptor->Guid = PpiGuid; -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf
r80721 r108794 32 32 [LibraryClasses] 33 33 DebugLib 34 34 StackCheckLib -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/SmmPciExpressLib/SmmPciExpressLib.inf
r89983 r108794 33 33 DebugLib 34 34 IoLib 35 UefiBootServicesTableLib 35 36 36 37 [Pcd] -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/StandaloneMmDriverEntryPoint/StandaloneMmDriverEntryPoint.inf
r89983 r108794 37 37 DebugLib 38 38 MmServicesTableLib 39 StackCheckLib 39 40 40 41 [Protocols] -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/StandaloneMmServicesTableLib/StandaloneMmServicesTableLib.inf
r80721 r108794 17 17 MODULE_TYPE = MM_STANDALONE 18 18 VERSION_STRING = 1.0 19 LIBRARY_CLASS = MmServicesTableLib|MM_STANDALONE 19 LIBRARY_CLASS = MmServicesTableLib|MM_STANDALONE MM_CORE_STANDALONE 20 20 PI_SPECIFICATION_VERSION = 0x00010032 21 21 CONSTRUCTOR = StandaloneMmServicesTableLibConstructor -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf
r80721 r108794 33 33 DebugLib 34 34 BaseLib 35 StackCheckLib 35 36 -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiDebugLibDebugPortProtocol/DebugLib.c
r99404 r108794 234 234 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n" 235 235 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of 236 PcdDebugProper yMask is set then CpuBreakpoint() is called. Otherwise, if237 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProper yMask is set then236 PcdDebugPropertyMask is set then CpuBreakpoint() is called. Otherwise, if 237 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugPropertyMask is set then 238 238 CpuDeadLoop() is called. If neither of these bits are set, then this function 239 239 returns immediately after the message is printed to the debug output device. … … 328 328 329 329 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of 330 PcdDebugProper yMask is set. Otherwise FALSE is returned.331 332 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProper yMask is set.333 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProper yMask is clear.330 PcdDebugPropertyMask is set. Otherwise FALSE is returned. 331 332 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugPropertyMask is set. 333 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugPropertyMask is clear. 334 334 335 335 **/ … … 347 347 348 348 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of 349 PcdDebugProper yMask is set. Otherwise FALSE is returned.350 351 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProper yMask is set.352 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProper yMask is clear.349 PcdDebugPropertyMask is set. Otherwise FALSE is returned. 350 351 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugPropertyMask is set. 352 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugPropertyMask is clear. 353 353 354 354 **/ … … 366 366 367 367 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of 368 PcdDebugProper yMask is set. Otherwise FALSE is returned.369 370 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProper yMask is set.371 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProper yMask is clear.368 PcdDebugPropertyMask is set. Otherwise FALSE is returned. 369 370 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugPropertyMask is set. 371 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugPropertyMask is clear. 372 372 373 373 **/ … … 385 385 386 386 This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of 387 PcdDebugProper yMask is set. Otherwise FALSE is returned.388 389 @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProper yMask is set.390 @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProper yMask is clear.387 PcdDebugPropertyMask is set. Otherwise FALSE is returned. 388 389 @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugPropertyMask is set. 390 @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugPropertyMask is clear. 391 391 392 392 **/ -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiDebugLibDebugPortProtocol/DebugLibConstructor.c
r99404 r108794 14 14 15 15 // 16 // BOOLEAN value to indicate if it is at the post ExitBootServices p ahse16 // BOOLEAN value to indicate if it is at the post ExitBootServices phase 17 17 // 18 18 BOOLEAN mPostEBS = FALSE; … … 35 35 36 36 **/ 37 static 37 38 VOID 38 39 EFIAPI 39 ExitBootServicesCallback (40 UefiDebugLibDebugPortProtocolExitBootServicesCallback ( 40 41 EFI_EVENT Event, 41 42 VOID *Context … … 68 69 EVT_SIGNAL_EXIT_BOOT_SERVICES, 69 70 TPL_NOTIFY, 70 ExitBootServicesCallback,71 UefiDebugLibDebugPortProtocolExitBootServicesCallback, 71 72 NULL, 72 73 &mExitBootServicesEvent -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiDebugLibStdErr/DebugLib.c
r99404 r108794 178 178 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n" 179 179 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of 180 PcdDebugProper yMask is set then CpuBreakpoint() is called. Otherwise, if181 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProper yMask is set then180 PcdDebugPropertyMask is set then CpuBreakpoint() is called. Otherwise, if 181 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugPropertyMask is set then 182 182 CpuDeadLoop() is called. If neither of these bits are set, then this function 183 183 returns immediately after the message is printed to the debug output device. … … 274 274 275 275 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of 276 PcdDebugProper yMask is set. Otherwise FALSE is returned.277 278 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProper yMask is set.279 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProper yMask is clear.276 PcdDebugPropertyMask is set. Otherwise FALSE is returned. 277 278 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugPropertyMask is set. 279 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugPropertyMask is clear. 280 280 281 281 **/ … … 293 293 294 294 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of 295 PcdDebugProper yMask is set. Otherwise FALSE is returned.296 297 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProper yMask is set.298 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProper yMask is clear.295 PcdDebugPropertyMask is set. Otherwise FALSE is returned. 296 297 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugPropertyMask is set. 298 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugPropertyMask is clear. 299 299 300 300 **/ … … 312 312 313 313 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of 314 PcdDebugProper yMask is set. Otherwise FALSE is returned.315 316 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProper yMask is set.317 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProper yMask is clear.314 PcdDebugPropertyMask is set. Otherwise FALSE is returned. 315 316 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugPropertyMask is set. 317 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugPropertyMask is clear. 318 318 319 319 **/ … … 331 331 332 332 This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of 333 PcdDebugProper yMask is set. Otherwise FALSE is returned.334 335 @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProper yMask is set.336 @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProper yMask is clear.333 PcdDebugPropertyMask is set. Otherwise FALSE is returned. 334 335 @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugPropertyMask is set. 336 @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugPropertyMask is clear. 337 337 338 338 **/ -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
r99404 r108794 270 270 // skip preceeding white space 271 271 // 272 while ( (*Str != 0) &&*Str == L' ') {272 while (*Str == L' ') { 273 273 Str++; 274 274 } … … 277 277 // skip preceeding zeros 278 278 // 279 while ( (*Str != 0) &&*Str == L'0') {279 while (*Str == L'0') { 280 280 Str++; 281 281 } … … 389 389 ); 390 390 391 StrHexToBytes (DataStr, DataLength * 2, (UINT8 *)(Node + 1), DataLength); 391 if (Node != NULL) { 392 StrHexToBytes (DataStr, DataLength * 2, (UINT8 *)(Node + 1), DataLength); 393 } 394 392 395 return Node; 393 396 } … … 454 457 ); 455 458 456 Pci->Function = (UINT8)Strtoi (FunctionStr); 457 Pci->Device = (UINT8)Strtoi (DeviceStr); 459 if (Pci != NULL) { 460 Pci->Function = (UINT8)Strtoi (FunctionStr); 461 Pci->Device = (UINT8)Strtoi (DeviceStr); 462 } 458 463 459 464 return (EFI_DEVICE_PATH_PROTOCOL *)Pci; … … 483 488 ); 484 489 485 Pccard->FunctionNumber = (UINT8)Strtoi (FunctionNumberStr); 490 if (Pccard != NULL) { 491 Pccard->FunctionNumber = (UINT8)Strtoi (FunctionNumberStr); 492 } 486 493 487 494 return (EFI_DEVICE_PATH_PROTOCOL *)Pccard; … … 515 522 ); 516 523 517 MemMap->MemoryType = (UINT32)Strtoi (MemoryTypeStr); 518 Strtoi64 (StartingAddressStr, &MemMap->StartingAddress); 519 Strtoi64 (EndingAddressStr, &MemMap->EndingAddress); 524 if (MemMap != NULL) { 525 MemMap->MemoryType = (UINT32)Strtoi (MemoryTypeStr); 526 Strtoi64 (StartingAddressStr, &MemMap->StartingAddress); 527 Strtoi64 (EndingAddressStr, &MemMap->EndingAddress); 528 } 520 529 521 530 return (EFI_DEVICE_PATH_PROTOCOL *)MemMap; … … 560 569 ); 561 570 562 StrToGuid (GuidStr, &Vendor->Guid); 563 StrHexToBytes (DataStr, Length * 2, (UINT8 *)(Vendor + 1), Length); 571 if (Vendor != NULL) { 572 StrToGuid (GuidStr, &Vendor->Guid); 573 StrHexToBytes (DataStr, Length * 2, (UINT8 *)(Vendor + 1), Length); 574 } 564 575 565 576 return (EFI_DEVICE_PATH_PROTOCOL *)Vendor; … … 608 619 (UINT16)sizeof (CONTROLLER_DEVICE_PATH) 609 620 ); 610 Controller->ControllerNumber = (UINT32)Strtoi (ControllerStr); 621 622 if (Controller != NULL) { 623 Controller->ControllerNumber = (UINT32)Strtoi (ControllerStr); 624 } 611 625 612 626 return (EFI_DEVICE_PATH_PROTOCOL *)Controller; … … 638 652 ); 639 653 640 BmcDp->InterfaceType = (UINT8)Strtoi (InterfaceTypeStr); 641 WriteUnaligned64 ( 642 (UINT64 *)(&BmcDp->BaseAddress), 643 StrHexToUint64 (BaseAddressStr) 644 ); 654 if (BmcDp != NULL) { 655 BmcDp->InterfaceType = (UINT8)Strtoi (InterfaceTypeStr); 656 WriteUnaligned64 ( 657 (UINT64 *)(&BmcDp->BaseAddress), 658 StrHexToUint64 (BaseAddressStr) 659 ); 660 } 645 661 646 662 return (EFI_DEVICE_PATH_PROTOCOL *)BmcDp; … … 707 723 ); 708 724 709 Acpi->HID = EisaIdFromText (HIDStr); 710 Acpi->UID = (UINT32)Strtoi (UIDStr); 725 if (Acpi != NULL) { 726 Acpi->HID = EisaIdFromText (HIDStr); 727 Acpi->UID = (UINT32)Strtoi (UIDStr); 728 } 711 729 712 730 return (EFI_DEVICE_PATH_PROTOCOL *)Acpi; … … 738 756 ); 739 757 740 Acpi->HID = EFI_PNP_ID (PnPId); 741 Acpi->UID = (UINT32)Strtoi (UIDStr); 758 if (Acpi != NULL) { 759 Acpi->HID = EFI_PNP_ID (PnPId); 760 Acpi->UID = (UINT32)Strtoi (UIDStr); 761 } 742 762 743 763 return (EFI_DEVICE_PATH_PROTOCOL *)Acpi; … … 879 899 ); 880 900 881 AcpiEx->HID = EisaIdFromText (HIDStr); 882 AcpiEx->CID = EisaIdFromText (CIDStr); 883 AcpiEx->UID = (UINT32)Strtoi (UIDStr); 884 885 AsciiStr = (CHAR8 *)((UINT8 *)AcpiEx + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH)); 886 StrToAscii (HIDSTRStr, &AsciiStr); 887 StrToAscii (UIDSTRStr, &AsciiStr); 888 StrToAscii (CIDSTRStr, &AsciiStr); 901 if (AcpiEx != NULL) { 902 AcpiEx->HID = EisaIdFromText (HIDStr); 903 AcpiEx->CID = EisaIdFromText (CIDStr); 904 AcpiEx->UID = (UINT32)Strtoi (UIDStr); 905 906 AsciiStr = (CHAR8 *)((UINT8 *)AcpiEx + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH)); 907 StrToAscii (HIDSTRStr, &AsciiStr); 908 StrToAscii (UIDSTRStr, &AsciiStr); 909 StrToAscii (CIDSTRStr, &AsciiStr); 910 } 889 911 890 912 return (EFI_DEVICE_PATH_PROTOCOL *)AcpiEx; … … 921 943 ); 922 944 945 if (AcpiEx == NULL) { 946 return (EFI_DEVICE_PATH_PROTOCOL *)AcpiEx; 947 } 948 923 949 AcpiEx->HID = EisaIdFromText (HIDStr); 924 950 // 925 // According to UEFI spec, the CID paramet r is optional and has a default value of 0.926 // So when the CID paramet r is not specified or specified as 0 in the text device node.951 // According to UEFI spec, the CID parameter is optional and has a default value of 0. 952 // So when the CID parameter is not specified or specified as 0 in the text device node. 927 953 // Set the CID to 0 in the ACPI extension device path structure. 928 954 // … … 976 1002 (UINT16)sizeof (ACPI_ADR_DEVICE_PATH) 977 1003 ); 978 ASSERT (AcpiAdr != NULL); 1004 if (AcpiAdr == NULL) { 1005 ASSERT (AcpiAdr != NULL); 1006 return (EFI_DEVICE_PATH_PROTOCOL *)AcpiAdr; 1007 } 979 1008 980 1009 for (Index = 0; ; Index++) { … … 991 1020 AcpiAdr 992 1021 ); 993 ASSERT (AcpiAdr != NULL); 1022 1023 if (AcpiAdr == NULL) { 1024 ASSERT (AcpiAdr != NULL); 1025 return (EFI_DEVICE_PATH_PROTOCOL *)AcpiAdr; 1026 } 1027 994 1028 SetDevicePathNodeLength (AcpiAdr, Length + sizeof (UINT32)); 995 1029 } … … 1040 1074 (UINT16)sizeof (ATAPI_DEVICE_PATH) 1041 1075 ); 1076 1077 if (Atapi == NULL) { 1078 return (EFI_DEVICE_PATH_PROTOCOL *)Atapi; 1079 } 1042 1080 1043 1081 PrimarySecondaryStr = GetNextParamStr (&TextDeviceNode); … … 1091 1129 ); 1092 1130 1093 Scsi->Pun = (UINT16)Strtoi (PunStr); 1094 Scsi->Lun = (UINT16)Strtoi (LunStr); 1131 if (Scsi != NULL) { 1132 Scsi->Pun = (UINT16)Strtoi (PunStr); 1133 Scsi->Lun = (UINT16)Strtoi (LunStr); 1134 } 1095 1135 1096 1136 return (EFI_DEVICE_PATH_PROTOCOL *)Scsi; … … 1122 1162 ); 1123 1163 1124 Fibre->Reserved = 0; 1125 Strtoi64 (WWNStr, &Fibre->WWN); 1126 Strtoi64 (LunStr, &Fibre->Lun); 1164 if (Fibre != NULL) { 1165 Fibre->Reserved = 0; 1166 Strtoi64 (WWNStr, &Fibre->WWN); 1167 Strtoi64 (LunStr, &Fibre->Lun); 1168 } 1127 1169 1128 1170 return (EFI_DEVICE_PATH_PROTOCOL *)Fibre; … … 1154 1196 ); 1155 1197 1156 FibreEx->Reserved = 0; 1157 Strtoi64 (WWNStr, (UINT64 *)(&FibreEx->WWN)); 1158 Strtoi64 (LunStr, (UINT64 *)(&FibreEx->Lun)); 1159 1160 *(UINT64 *)(&FibreEx->WWN) = SwapBytes64 (*(UINT64 *)(&FibreEx->WWN)); 1161 *(UINT64 *)(&FibreEx->Lun) = SwapBytes64 (*(UINT64 *)(&FibreEx->Lun)); 1198 if (FibreEx != NULL) { 1199 FibreEx->Reserved = 0; 1200 Strtoi64 (WWNStr, (UINT64 *)(&FibreEx->WWN)); 1201 Strtoi64 (LunStr, (UINT64 *)(&FibreEx->Lun)); 1202 1203 *(UINT64 *)(&FibreEx->WWN) = SwapBytes64 (*(UINT64 *)(&FibreEx->WWN)); 1204 *(UINT64 *)(&FibreEx->Lun) = SwapBytes64 (*(UINT64 *)(&FibreEx->Lun)); 1205 } 1162 1206 1163 1207 return (EFI_DEVICE_PATH_PROTOCOL *)FibreEx; … … 1187 1231 ); 1188 1232 1189 F1394DevPath->Reserved = 0; 1190 F1394DevPath->Guid = StrHexToUint64 (GuidStr); 1233 if (F1394DevPath != NULL) { 1234 F1394DevPath->Reserved = 0; 1235 F1394DevPath->Guid = StrHexToUint64 (GuidStr); 1236 } 1191 1237 1192 1238 return (EFI_DEVICE_PATH_PROTOCOL *)F1394DevPath; … … 1218 1264 ); 1219 1265 1220 Usb->ParentPortNumber = (UINT8)Strtoi (PortStr); 1221 Usb->InterfaceNumber = (UINT8)Strtoi (InterfaceStr); 1266 if (Usb != NULL) { 1267 Usb->ParentPortNumber = (UINT8)Strtoi (PortStr); 1268 Usb->InterfaceNumber = (UINT8)Strtoi (InterfaceStr); 1269 } 1222 1270 1223 1271 return (EFI_DEVICE_PATH_PROTOCOL *)Usb; … … 1247 1295 ); 1248 1296 1249 I2ODevPath->Tid = (UINT32)Strtoi (TIDStr); 1297 if (I2ODevPath != NULL) { 1298 I2ODevPath->Tid = (UINT32)Strtoi (TIDStr); 1299 } 1250 1300 1251 1301 return (EFI_DEVICE_PATH_PROTOCOL *)I2ODevPath; … … 1283 1333 ); 1284 1334 1285 InfiniBand->ResourceFlags = (UINT32)Strtoi (FlagsStr); 1286 StrToGuid (GuidStr, (EFI_GUID *)InfiniBand->PortGid); 1287 Strtoi64 (SidStr, &InfiniBand->ServiceId); 1288 Strtoi64 (TidStr, &InfiniBand->TargetPortId); 1289 Strtoi64 (DidStr, &InfiniBand->DeviceId); 1335 if (InfiniBand != NULL) { 1336 InfiniBand->ResourceFlags = (UINT32)Strtoi (FlagsStr); 1337 StrToGuid (GuidStr, (EFI_GUID *)InfiniBand->PortGid); 1338 Strtoi64 (SidStr, &InfiniBand->ServiceId); 1339 Strtoi64 (TidStr, &InfiniBand->TargetPortId); 1340 Strtoi64 (DidStr, &InfiniBand->DeviceId); 1341 } 1290 1342 1291 1343 return (EFI_DEVICE_PATH_PROTOCOL *)InfiniBand; … … 1332 1384 (UINT16)sizeof (VENDOR_DEVICE_PATH) 1333 1385 ); 1334 CopyGuid (&Vendor->Guid, &gEfiPcAnsiGuid); 1386 1387 if (Vendor != NULL) { 1388 CopyGuid (&Vendor->Guid, &gEfiPcAnsiGuid); 1389 } 1335 1390 1336 1391 return (EFI_DEVICE_PATH_PROTOCOL *)Vendor; … … 1357 1412 (UINT16)sizeof (VENDOR_DEVICE_PATH) 1358 1413 ); 1359 CopyGuid (&Vendor->Guid, &gEfiVT100Guid); 1414 1415 if (Vendor != NULL) { 1416 CopyGuid (&Vendor->Guid, &gEfiVT100Guid); 1417 } 1360 1418 1361 1419 return (EFI_DEVICE_PATH_PROTOCOL *)Vendor; … … 1382 1440 (UINT16)sizeof (VENDOR_DEVICE_PATH) 1383 1441 ); 1384 CopyGuid (&Vendor->Guid, &gEfiVT100PlusGuid); 1442 1443 if (Vendor != NULL) { 1444 CopyGuid (&Vendor->Guid, &gEfiVT100PlusGuid); 1445 } 1385 1446 1386 1447 return (EFI_DEVICE_PATH_PROTOCOL *)Vendor; … … 1407 1468 (UINT16)sizeof (VENDOR_DEVICE_PATH) 1408 1469 ); 1409 CopyGuid (&Vendor->Guid, &gEfiVTUTF8Guid); 1470 1471 if (Vendor != NULL) { 1472 CopyGuid (&Vendor->Guid, &gEfiVTUTF8Guid); 1473 } 1410 1474 1411 1475 return (EFI_DEVICE_PATH_PROTOCOL *)Vendor; … … 1435 1499 ); 1436 1500 1437 CopyGuid (&UartFlowControl->Guid, &gEfiUartDevicePathGuid); 1438 if (StrCmp (ValueStr, L"XonXoff") == 0) { 1439 UartFlowControl->FlowControlMap = 2; 1440 } else if (StrCmp (ValueStr, L"Hardware") == 0) { 1441 UartFlowControl->FlowControlMap = 1; 1442 } else { 1443 UartFlowControl->FlowControlMap = 0; 1501 if (UartFlowControl != NULL) { 1502 CopyGuid (&UartFlowControl->Guid, &gEfiUartDevicePathGuid); 1503 if (StrCmp (ValueStr, L"XonXoff") == 0) { 1504 UartFlowControl->FlowControlMap = 2; 1505 } else if (StrCmp (ValueStr, L"Hardware") == 0) { 1506 UartFlowControl->FlowControlMap = 1; 1507 } else { 1508 UartFlowControl->FlowControlMap = 0; 1509 } 1444 1510 } 1445 1511 … … 1486 1552 ); 1487 1553 1554 if (Sas == NULL) { 1555 return (EFI_DEVICE_PATH_PROTOCOL *)Sas; 1556 } 1557 1488 1558 CopyGuid (&Sas->Guid, &gEfiSasDevicePathGuid); 1489 1559 Strtoi64 (AddressStr, &Sas->SasAddress); … … 1581 1651 ); 1582 1652 1653 if (SasEx == NULL) { 1654 return (EFI_DEVICE_PATH_PROTOCOL *)SasEx; 1655 } 1656 1583 1657 Strtoi64 (AddressStr, &SasAddress); 1584 1658 Strtoi64 (LunStr, &Lun); … … 1664 1738 ); 1665 1739 1666 Nvme->NamespaceId = (UINT32)Strtoi (NamespaceIdStr); 1667 Uuid = (UINT8 *)&Nvme->NamespaceUuid; 1668 1669 Index = sizeof (Nvme->NamespaceUuid) / sizeof (UINT8); 1670 while (Index-- != 0) { 1671 Uuid[Index] = (UINT8)StrHexToUintn (SplitStr (&NamespaceUuidStr, L'-')); 1740 if (Nvme != NULL) { 1741 Nvme->NamespaceId = (UINT32)Strtoi (NamespaceIdStr); 1742 Uuid = (UINT8 *)&Nvme->NamespaceUuid; 1743 1744 Index = sizeof (Nvme->NamespaceUuid) / sizeof (UINT8); 1745 while (Index-- != 0) { 1746 Uuid[Index] = (UINT8)StrHexToUintn (SplitStr (&NamespaceUuidStr, L'-')); 1747 } 1672 1748 } 1673 1749 … … 1700 1776 ); 1701 1777 1702 Ufs->Pun = (UINT8)Strtoi (PunStr); 1703 Ufs->Lun = (UINT8)Strtoi (LunStr); 1778 if (Ufs != NULL) { 1779 Ufs->Pun = (UINT8)Strtoi (PunStr); 1780 Ufs->Lun = (UINT8)Strtoi (LunStr); 1781 } 1704 1782 1705 1783 return (EFI_DEVICE_PATH_PROTOCOL *)Ufs; … … 1729 1807 ); 1730 1808 1731 Sd->SlotNumber = (UINT8)Strtoi (SlotNumberStr); 1809 if (Sd != NULL) { 1810 Sd->SlotNumber = (UINT8)Strtoi (SlotNumberStr); 1811 } 1732 1812 1733 1813 return (EFI_DEVICE_PATH_PROTOCOL *)Sd; … … 1757 1837 ); 1758 1838 1759 Emmc->SlotNumber = (UINT8)Strtoi (SlotNumberStr); 1839 if (Emmc != NULL) { 1840 Emmc->SlotNumber = (UINT8)Strtoi (SlotNumberStr); 1841 } 1760 1842 1761 1843 return (EFI_DEVICE_PATH_PROTOCOL *)Emmc; … … 1783 1865 ); 1784 1866 1785 CopyGuid (&Vend->Guid, &gEfiDebugPortProtocolGuid); 1867 if (Vend != NULL) { 1868 CopyGuid (&Vend->Guid, &gEfiDebugPortProtocolGuid); 1869 } 1786 1870 1787 1871 return (EFI_DEVICE_PATH_PROTOCOL *)Vend; … … 1814 1898 ); 1815 1899 1816 MACDevPath->IfType = (UINT8)Strtoi (IfTypeStr); 1817 1818 Length = sizeof (EFI_MAC_ADDRESS); 1819 if ((MACDevPath->IfType == 0x01) || (MACDevPath->IfType == 0x00)) { 1820 Length = 6; 1821 } 1822 1823 StrHexToBytes (AddressStr, Length * 2, MACDevPath->MacAddress.Addr, Length); 1900 if (MACDevPath != NULL) { 1901 MACDevPath->IfType = (UINT8)Strtoi (IfTypeStr); 1902 1903 Length = sizeof (EFI_MAC_ADDRESS); 1904 if ((MACDevPath->IfType == 0x01) || (MACDevPath->IfType == 0x00)) { 1905 Length = 6; 1906 } 1907 1908 StrHexToBytes (AddressStr, Length * 2, MACDevPath->MacAddress.Addr, Length); 1909 } 1824 1910 1825 1911 return (EFI_DEVICE_PATH_PROTOCOL *)MACDevPath; … … 1883 1969 ); 1884 1970 1971 if (IPv4 == NULL) { 1972 return (EFI_DEVICE_PATH_PROTOCOL *)IPv4; 1973 } 1974 1885 1975 StrToIpv4Address (RemoteIPStr, NULL, &IPv4->RemoteIpAddress, NULL); 1886 1976 IPv4->Protocol = (UINT16)NetworkProtocolFromText (ProtocolStr); … … 1939 2029 ); 1940 2030 2031 if (IPv6 == NULL) { 2032 return (EFI_DEVICE_PATH_PROTOCOL *)IPv6; 2033 } 2034 1941 2035 StrToIpv6Address (RemoteIPStr, NULL, &IPv6->RemoteIpAddress, NULL); 1942 2036 IPv6->Protocol = (UINT16)NetworkProtocolFromText (ProtocolStr); … … 1992 2086 (UINT16)sizeof (UART_DEVICE_PATH) 1993 2087 ); 2088 2089 if (Uart == NULL) { 2090 return (EFI_DEVICE_PATH_PROTOCOL *)Uart; 2091 } 1994 2092 1995 2093 if (StrCmp (BaudStr, L"DEFAULT") == 0) { … … 2072 2170 (UINT16)sizeof (USB_CLASS_DEVICE_PATH) 2073 2171 ); 2172 2173 if (UsbClass == NULL) { 2174 return (EFI_DEVICE_PATH_PROTOCOL *)UsbClass; 2175 } 2074 2176 2075 2177 VIDStr = GetNextParamStr (&TextDeviceNode); … … 2514 2616 (UINT16)(sizeof (USB_WWID_DEVICE_PATH) + SerialNumberStrLen * sizeof (CHAR16)) 2515 2617 ); 2516 UsbWwid->VendorId = (UINT16)Strtoi (VIDStr); 2517 UsbWwid->ProductId = (UINT16)Strtoi (PIDStr); 2518 UsbWwid->InterfaceNumber = (UINT16)Strtoi (InterfaceNumStr); 2519 2520 // 2521 // There is no memory allocated in UsbWwid for the '\0' in SerialNumberStr. 2522 // Therefore, the '\0' will not be copied. 2523 // 2524 CopyMem ( 2525 (UINT8 *)UsbWwid + sizeof (USB_WWID_DEVICE_PATH), 2526 SerialNumberStr, 2527 SerialNumberStrLen * sizeof (CHAR16) 2528 ); 2618 2619 if (UsbWwid != NULL) { 2620 UsbWwid->VendorId = (UINT16)Strtoi (VIDStr); 2621 UsbWwid->ProductId = (UINT16)Strtoi (PIDStr); 2622 UsbWwid->InterfaceNumber = (UINT16)Strtoi (InterfaceNumStr); 2623 2624 // 2625 // There is no memory allocated in UsbWwid for the '\0' in SerialNumberStr. 2626 // Therefore, the '\0' will not be copied. 2627 // 2628 CopyMem ( 2629 (UINT8 *)UsbWwid + sizeof (USB_WWID_DEVICE_PATH), 2630 SerialNumberStr, 2631 SerialNumberStrLen * sizeof (CHAR16) 2632 ); 2633 } 2529 2634 2530 2635 return (EFI_DEVICE_PATH_PROTOCOL *)UsbWwid; … … 2554 2659 ); 2555 2660 2556 LogicalUnit->Lun = (UINT8)Strtoi (LunStr); 2661 if (LogicalUnit != NULL) { 2662 LogicalUnit->Lun = (UINT8)Strtoi (LunStr); 2663 } 2557 2664 2558 2665 return (EFI_DEVICE_PATH_PROTOCOL *)LogicalUnit; … … 2597 2704 ); 2598 2705 2706 if (ISCSIDevPath == NULL) { 2707 return (EFI_DEVICE_PATH_PROTOCOL *)ISCSIDevPath; 2708 } 2709 2599 2710 AsciiStr = ISCSIDevPath->TargetName; 2600 2711 StrToAscii (NameStr, &AsciiStr); … … 2658 2769 ); 2659 2770 2660 Vlan->VlanId = (UINT16)Strtoi (VlanStr); 2771 if (Vlan != NULL) { 2772 Vlan->VlanId = (UINT16)Strtoi (VlanStr); 2773 } 2661 2774 2662 2775 return (EFI_DEVICE_PATH_PROTOCOL *)Vlan; … … 2685 2798 (UINT16)sizeof (BLUETOOTH_DEVICE_PATH) 2686 2799 ); 2687 StrHexToBytes ( 2688 BluetoothStr, 2689 sizeof (BLUETOOTH_ADDRESS) * 2, 2690 BluetoothDp->BD_ADDR.Address, 2691 sizeof (BLUETOOTH_ADDRESS) 2692 ); 2800 2801 if (BluetoothDp != NULL) { 2802 StrHexToBytes ( 2803 BluetoothStr, 2804 sizeof (BLUETOOTH_ADDRESS) * 2, 2805 BluetoothDp->BD_ADDR.Address, 2806 sizeof (BLUETOOTH_ADDRESS) 2807 ); 2808 } 2809 2693 2810 return (EFI_DEVICE_PATH_PROTOCOL *)BluetoothDp; 2694 2811 } … … 2719 2836 ); 2720 2837 2721 if ( NULL != SSIdStr) {2838 if ((NULL != SSIdStr) && (NULL != WiFiDp)) { 2722 2839 DataLen = StrLen (SSIdStr); 2723 2840 if (StrLen (SSIdStr) > 32) { … … 2758 2875 ); 2759 2876 2760 BluetoothLeDp->Address.Type = (UINT8)Strtoi (BluetoothLeAddrTypeStr); 2761 StrHexToBytes ( 2762 BluetoothLeAddrStr, 2763 sizeof (BluetoothLeDp->Address.Address) * 2, 2764 BluetoothLeDp->Address.Address, 2765 sizeof (BluetoothLeDp->Address.Address) 2766 ); 2877 if (BluetoothLeDp != NULL) { 2878 BluetoothLeDp->Address.Type = (UINT8)Strtoi (BluetoothLeAddrTypeStr); 2879 StrHexToBytes ( 2880 BluetoothLeAddrStr, 2881 sizeof (BluetoothLeDp->Address.Address) * 2, 2882 BluetoothLeDp->Address.Address, 2883 sizeof (BluetoothLeDp->Address.Address) 2884 ); 2885 } 2886 2767 2887 return (EFI_DEVICE_PATH_PROTOCOL *)BluetoothLeDp; 2768 2888 } … … 2884 3004 ); 2885 3005 2886 while (Uri Length-- != 0) {3006 while (Uri != NULL && UriLength-- != 0) { 2887 3007 Uri->Uri[UriLength] = (CHAR8)UriStr[UriLength]; 2888 3008 } … … 2939 3059 ); 2940 3060 3061 if (Hd == NULL) { 3062 return (EFI_DEVICE_PATH_PROTOCOL *)Hd; 3063 } 3064 2941 3065 Hd->PartitionNumber = (UINT32)Strtoi (PartitionStr); 2942 3066 … … 2992 3116 ); 2993 3117 2994 CDROMDevPath->BootEntry = (UINT32)Strtoi (EntryStr); 2995 Strtoi64 (StartStr, &CDROMDevPath->PartitionStart); 2996 Strtoi64 (SizeStr, &CDROMDevPath->PartitionSize); 3118 if (CDROMDevPath != NULL) { 3119 CDROMDevPath->BootEntry = (UINT32)Strtoi (EntryStr); 3120 Strtoi64 (StartStr, &CDROMDevPath->PartitionStart); 3121 Strtoi64 (SizeStr, &CDROMDevPath->PartitionSize); 3122 } 2997 3123 2998 3124 return (EFI_DEVICE_PATH_PROTOCOL *)CDROMDevPath; … … 3040 3166 ); 3041 3167 3042 StrCpyS (File->PathName, StrLen (TextDeviceNode) + 1, TextDeviceNode); 3168 if (File != NULL) { 3169 StrCpyS (File->PathName, StrLen (TextDeviceNode) + 1, TextDeviceNode); 3170 } 3043 3171 3044 3172 return (EFI_DEVICE_PATH_PROTOCOL *)File; … … 3068 3196 ); 3069 3197 3070 StrToGuid (GuidStr, &Media->Protocol); 3198 if (Media != NULL) { 3199 StrToGuid (GuidStr, &Media->Protocol); 3200 } 3071 3201 3072 3202 return (EFI_DEVICE_PATH_PROTOCOL *)Media; … … 3096 3226 ); 3097 3227 3098 StrToGuid (GuidStr, &Fv->FvName); 3228 if (Fv != NULL) { 3229 StrToGuid (GuidStr, &Fv->FvName); 3230 } 3099 3231 3100 3232 return (EFI_DEVICE_PATH_PROTOCOL *)Fv; … … 3124 3256 ); 3125 3257 3126 StrToGuid (GuidStr, &FvFile->FvFileName); 3258 if (FvFile != NULL) { 3259 StrToGuid (GuidStr, &FvFile->FvFileName); 3260 } 3127 3261 3128 3262 return (EFI_DEVICE_PATH_PROTOCOL *)FvFile; … … 3154 3288 ); 3155 3289 3156 Strtoi64 (StartingOffsetStr, &Offset->StartingOffset); 3157 Strtoi64 (EndingOffsetStr, &Offset->EndingOffset); 3290 if (Offset != NULL) { 3291 Strtoi64 (StartingOffsetStr, &Offset->StartingOffset); 3292 Strtoi64 (EndingOffsetStr, &Offset->EndingOffset); 3293 } 3158 3294 3159 3295 return (EFI_DEVICE_PATH_PROTOCOL *)Offset; … … 3191 3327 ); 3192 3328 3193 Strtoi64 (StartingAddrStr, &StartingAddr); 3194 WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr); 3195 Strtoi64 (EndingAddrStr, &EndingAddr); 3196 WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr); 3197 RamDisk->Instance = (UINT16)Strtoi (InstanceStr); 3198 StrToGuid (TypeGuidStr, &RamDisk->TypeGuid); 3329 if (RamDisk != NULL) { 3330 Strtoi64 (StartingAddrStr, &StartingAddr); 3331 WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr); 3332 Strtoi64 (EndingAddrStr, &EndingAddr); 3333 WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr); 3334 RamDisk->Instance = (UINT16)Strtoi (InstanceStr); 3335 StrToGuid (TypeGuidStr, &RamDisk->TypeGuid); 3336 } 3199 3337 3200 3338 return (EFI_DEVICE_PATH_PROTOCOL *)RamDisk; … … 3231 3369 ); 3232 3370 3233 Strtoi64 (StartingAddrStr, &StartingAddr); 3234 WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr); 3235 Strtoi64 (EndingAddrStr, &EndingAddr); 3236 WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr); 3237 RamDisk->Instance = (UINT16)Strtoi (InstanceStr); 3238 CopyGuid (&RamDisk->TypeGuid, &gEfiVirtualDiskGuid); 3371 if (RamDisk != NULL) { 3372 Strtoi64 (StartingAddrStr, &StartingAddr); 3373 WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr); 3374 Strtoi64 (EndingAddrStr, &EndingAddr); 3375 WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr); 3376 RamDisk->Instance = (UINT16)Strtoi (InstanceStr); 3377 CopyGuid (&RamDisk->TypeGuid, &gEfiVirtualDiskGuid); 3378 } 3239 3379 3240 3380 return (EFI_DEVICE_PATH_PROTOCOL *)RamDisk; … … 3271 3411 ); 3272 3412 3273 Strtoi64 (StartingAddrStr, &StartingAddr); 3274 WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr); 3275 Strtoi64 (EndingAddrStr, &EndingAddr); 3276 WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr); 3277 RamDisk->Instance = (UINT16)Strtoi (InstanceStr); 3278 CopyGuid (&RamDisk->TypeGuid, &gEfiVirtualCdGuid); 3413 if (RamDisk != NULL) { 3414 Strtoi64 (StartingAddrStr, &StartingAddr); 3415 WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr); 3416 Strtoi64 (EndingAddrStr, &EndingAddr); 3417 WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr); 3418 RamDisk->Instance = (UINT16)Strtoi (InstanceStr); 3419 CopyGuid (&RamDisk->TypeGuid, &gEfiVirtualCdGuid); 3420 } 3279 3421 3280 3422 return (EFI_DEVICE_PATH_PROTOCOL *)RamDisk; … … 3311 3453 ); 3312 3454 3313 Strtoi64 (StartingAddrStr, &StartingAddr); 3314 WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr); 3315 Strtoi64 (EndingAddrStr, &EndingAddr); 3316 WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr); 3317 RamDisk->Instance = (UINT16)Strtoi (InstanceStr); 3318 CopyGuid (&RamDisk->TypeGuid, &gEfiPersistentVirtualDiskGuid); 3455 if (RamDisk != NULL) { 3456 Strtoi64 (StartingAddrStr, &StartingAddr); 3457 WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr); 3458 Strtoi64 (EndingAddrStr, &EndingAddr); 3459 WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr); 3460 RamDisk->Instance = (UINT16)Strtoi (InstanceStr); 3461 CopyGuid (&RamDisk->TypeGuid, &gEfiPersistentVirtualDiskGuid); 3462 } 3319 3463 3320 3464 return (EFI_DEVICE_PATH_PROTOCOL *)RamDisk; … … 3351 3495 ); 3352 3496 3353 Strtoi64 (StartingAddrStr, &StartingAddr); 3354 WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr); 3355 Strtoi64 (EndingAddrStr, &EndingAddr); 3356 WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr); 3357 RamDisk->Instance = (UINT16)Strtoi (InstanceStr); 3358 CopyGuid (&RamDisk->TypeGuid, &gEfiPersistentVirtualCdGuid); 3497 if (RamDisk != NULL) { 3498 Strtoi64 (StartingAddrStr, &StartingAddr); 3499 WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr); 3500 Strtoi64 (EndingAddrStr, &EndingAddr); 3501 WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr); 3502 RamDisk->Instance = (UINT16)Strtoi (InstanceStr); 3503 CopyGuid (&RamDisk->TypeGuid, &gEfiPersistentVirtualCdGuid); 3504 } 3359 3505 3360 3506 return (EFI_DEVICE_PATH_PROTOCOL *)RamDisk; … … 3404 3550 (UINT16)(sizeof (BBS_BBS_DEVICE_PATH) + StrLen (IdStr)) 3405 3551 ); 3552 3553 if (Bbs == NULL) { 3554 return (EFI_DEVICE_PATH_PROTOCOL *)Bbs; 3555 } 3406 3556 3407 3557 if (StrCmp (TypeStr, L"Floppy") == 0) { … … 3456 3606 (UINT16)sizeof (SATA_DEVICE_PATH) 3457 3607 ); 3608 3609 if (Sata == NULL) { 3610 return (EFI_DEVICE_PATH_PROTOCOL *)Sata; 3611 } 3612 3458 3613 Sata->HBAPortNumber = (UINT16)Strtoi (Param1); 3459 3614 … … 3657 3812 3658 3813 DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)AllocatePool (END_DEVICE_PATH_LENGTH); 3659 ASSERT (DevicePath != NULL); 3814 3815 if (DevicePath == NULL) { 3816 ASSERT (DevicePath != NULL); 3817 return NULL; 3818 } 3819 3660 3820 SetDevicePathEndNode (DevicePath); 3661 3821 3662 3822 DevicePathStr = UefiDevicePathLibStrDuplicate (TextDevicePath); 3823 3824 if (DevicePathStr == NULL) { 3825 return NULL; 3826 } 3663 3827 3664 3828 Str = DevicePathStr; … … 3667 3831 3668 3832 NewDevicePath = AppendDevicePathNode (DevicePath, DeviceNode); 3669 FreePool (DevicePath); 3670 FreePool (DeviceNode); 3833 if (DevicePath != NULL) { 3834 FreePool (DevicePath); 3835 } 3836 3837 if (DeviceNode != NULL) { 3838 FreePool (DeviceNode); 3839 } 3840 3671 3841 DevicePath = NewDevicePath; 3672 3842 3673 3843 if (IsInstanceEnd) { 3674 3844 DeviceNode = (EFI_DEVICE_PATH_PROTOCOL *)AllocatePool (END_DEVICE_PATH_LENGTH); 3675 ASSERT (DeviceNode != NULL); 3845 if (DeviceNode == NULL) { 3846 ASSERT (DeviceNode != NULL); 3847 return NULL; 3848 } 3849 3676 3850 SetDevicePathEndNode (DeviceNode); 3677 3851 DeviceNode->SubType = END_INSTANCE_DEVICE_PATH_SUBTYPE; 3678 3852 3679 3853 NewDevicePath = AppendDevicePathNode (DevicePath, DeviceNode); 3680 FreePool (DevicePath); 3681 FreePool (DeviceNode); 3854 if (DevicePath != NULL) { 3855 FreePool (DevicePath); 3856 } 3857 3858 if (DeviceNode != NULL) { 3859 FreePool (DeviceNode); 3860 } 3861 3682 3862 DevicePath = NewDevicePath; 3683 3863 } -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c
r105670 r108794 1004 1004 // In case no NULL terminator in SerialNumber, create a new one with NULL terminator 1005 1005 // 1006 NewStr = Allocate CopyPool ((Length + 1) * sizeof (CHAR16), SerialNumberStr);1006 NewStr = AllocatePool ((Length + 1) * sizeof (CHAR16)); 1007 1007 ASSERT (NewStr != NULL); 1008 CopyMem (NewStr, SerialNumberStr, Length * sizeof (CHAR16)); 1008 1009 NewStr[Length] = 0; 1009 1010 SerialNumberStr = NewStr; … … 1842 1843 UriLength = DevicePathNodeLength (Uri) - sizeof (URI_DEVICE_PATH); 1843 1844 UriStr = AllocatePool (UriLength + 1); 1844 ASSERT (UriStr != NULL); 1845 1846 if (UriStr == NULL) { 1847 ASSERT (UriStr != NULL); 1848 return; 1849 } 1845 1850 1846 1851 CopyMem (UriStr, Uri->Uri, UriLength); … … 1878 1883 UefiDevicePathLibCatPrint ( 1879 1884 Str, 1880 L"HD(%d,%s,0x%08x ,",1885 L"HD(%d,%s,0x%08x", 1881 1886 Hd->PartitionNumber, 1882 1887 L"MBR", … … 1888 1893 UefiDevicePathLibCatPrint ( 1889 1894 Str, 1890 L"HD(%d,%s,%g ,",1895 L"HD(%d,%s,%g", 1891 1896 Hd->PartitionNumber, 1892 1897 L"GPT", … … 1898 1903 UefiDevicePathLibCatPrint ( 1899 1904 Str, 1900 L"HD(%d,%d,0 ,",1905 L"HD(%d,%d,0", 1901 1906 Hd->PartitionNumber, 1902 1907 Hd->SignatureType … … 1905 1910 } 1906 1911 1907 UefiDevicePathLibCatPrint (Str, L"0x%lx,0x%lx)", Hd->PartitionStart, Hd->PartitionSize); 1912 if (DisplayOnly) { 1913 UefiDevicePathLibCatPrint (Str, L")"); 1914 } else { 1915 UefiDevicePathLibCatPrint (Str, L",0x%lx,0x%lx)", Hd->PartitionStart, Hd->PartitionSize); 1916 } 1908 1917 } 1909 1918 -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
r80721 r108794 37 37 DebugLib 38 38 BaseLib 39 StackCheckLib 39 40 40 41 -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c
r99404 r108794 931 931 if (Status == EFI_BUFFER_TOO_SMALL) { 932 932 RetVal = AllocateZeroPool (Size); 933 934 if (RetVal == NULL) { 935 return NULL; 936 } 937 933 938 Status = FileHandleReadLine (Handle, RetVal, &Size, FALSE, Ascii); 934 939 } -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiLib/Acpi.c
r99404 r108794 221 221 NULL 222 222 ); 223 Table = LocateAcpiDsdtFromFadt (Fadt); 223 224 if (Fadt != NULL) { 225 Table = LocateAcpiDsdtFromFadt (Fadt); 226 } else { 227 Table = NULL; 228 } 224 229 } else if (Signature == EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE) { 225 230 ASSERT (PreviousTable == NULL); … … 235 240 NULL 236 241 ); 237 Table = LocateAcpiFacsFromFadt (Fadt); 242 243 if (Fadt != NULL) { 244 Table = LocateAcpiFacsFromFadt (Fadt); 245 } else { 246 Table = NULL; 247 } 238 248 } else { 239 249 Table = ScanTableInSDT ( … … 276 286 NULL 277 287 ); 278 Table = LocateAcpiDsdtFromFadt (Fadt); 288 289 if (Fadt != NULL) { 290 Table = LocateAcpiDsdtFromFadt (Fadt); 291 } else { 292 Table = NULL; 293 } 279 294 } else if (Signature == EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE) { 280 295 ASSERT (PreviousTable == NULL); … … 290 305 NULL 291 306 ); 292 Table = LocateAcpiFacsFromFadt (Fadt); 307 308 if (Fadt != NULL) { 309 Table = LocateAcpiFacsFromFadt (Fadt); 310 } else { 311 Table = NULL; 312 } 293 313 } else { 294 314 Table = ScanTableInSDT ( -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiLib/Console.c
r99404 r108794 478 478 // 479 479 Line = AllocateZeroPool ((MaxLength + 3) * sizeof (CHAR16)); 480 ASSERT (Line != NULL); 480 481 if (Line == NULL) { 482 ASSERT (Line != NULL); 483 return; 484 } 481 485 482 486 // … … 514 518 UefiLibGetStringWidth (String, TRUE, MaxLength, &Length); 515 519 TmpString = AllocateZeroPool ((Length + 1) * sizeof (CHAR16)); 516 ASSERT (TmpString != NULL); 520 521 if (TmpString == NULL) { 522 ASSERT (TmpString != NULL); 523 break; 524 } 525 517 526 StrnCpyS (TmpString, Length + 1, String, Length - 3); 518 527 StrCatS (TmpString, Length + 1, L"..."); -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiLib/UefiLibPrint.c
r99404 r108794 66 66 67 67 Buffer = (CHAR16 *)AllocatePool (BufferSize); 68 ASSERT (Buffer != NULL); 68 69 if (Buffer == NULL) { 70 ASSERT (Buffer != NULL); 71 return 0; 72 } 69 73 70 74 Return = UnicodeVSPrint (Buffer, BufferSize, Format, Marker); … … 200 204 201 205 Buffer = (CHAR16 *)AllocatePool (BufferSize); 202 ASSERT (Buffer != NULL); 206 207 if (Buffer == NULL) { 208 ASSERT (Buffer != NULL); 209 return 0; 210 } 203 211 204 212 Return = UnicodeVSPrintAsciiFormat (Buffer, BufferSize, Format, Marker); … … 420 428 421 429 Blt = (EFI_IMAGE_OUTPUT *)AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT)); 422 ASSERT (Blt != NULL); 430 431 if (Blt == NULL) { 432 ASSERT (Blt != NULL); 433 goto Error; 434 } 423 435 424 436 Blt->Width = (UINT16)(HorizontalResolution); … … 626 638 627 639 Buffer = (CHAR16 *)AllocatePool (BufferSize); 628 ASSERT (Buffer != NULL); 640 641 if (Buffer == NULL) { 642 ASSERT (Buffer != NULL); 643 return 0; 644 } 629 645 630 646 PrintNum = UnicodeVSPrint (Buffer, BufferSize, Format, Marker); … … 704 720 705 721 Buffer = (CHAR16 *)AllocatePool (BufferSize); 706 ASSERT (Buffer != NULL); 722 723 if (Buffer == NULL) { 724 ASSERT (Buffer != NULL); 725 return 0; 726 } 707 727 708 728 PrintNum = UnicodeSPrintAsciiFormat (Buffer, BufferSize, Format, Marker); -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiMemoryLib/SetMemWrapper.c
r80721 r108794 1 1 /** @file 2 SetMem() and SetMemN()implementation.2 SetMem() implementation. 3 3 4 4 The following BaseMemoryLib instances contain the same copy of this file: … … 50 50 return InternalMemSetMem (Buffer, Length, Value); 51 51 } 52 53 /**54 Fills a target buffer with a value that is size UINTN, and returns the target buffer.55 56 This function fills Length bytes of Buffer with the UINTN sized value specified by57 Value, and returns Buffer. Value is repeated every sizeof(UINTN) bytes for Length58 bytes of Buffer.59 60 If Length > 0 and Buffer is NULL, then ASSERT().61 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().62 If Buffer is not aligned on a UINTN boundary, then ASSERT().63 If Length is not aligned on a UINTN boundary, then ASSERT().64 65 @param Buffer The pointer to the target buffer to fill.66 @param Length The number of bytes in Buffer to fill.67 @param Value The value with which to fill Length bytes of Buffer.68 69 @return Buffer.70 71 **/72 VOID *73 EFIAPI74 SetMemN (75 OUT VOID *Buffer,76 IN UINTN Length,77 IN UINTN Value78 )79 {80 if (sizeof (UINTN) == sizeof (UINT64)) {81 return SetMem64 (Buffer, Length, (UINT64)Value);82 } else {83 return SetMem32 (Buffer, Length, (UINT32)Value);84 }85 } -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiMemoryLib/UefiMemoryLib.inf
r80721 r108794 33 33 ZeroMemWrapper.c 34 34 CompareMemWrapper.c 35 SetMemNWrapper.c 35 36 SetMem64Wrapper.c 36 37 SetMem32Wrapper.c … … 48 49 MdePkg/MdePkg.dec 49 50 50 51 51 [LibraryClasses] 52 52 BaseLib -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiPciSegmentLibPciRootBridgeIo/PciSegmentLib.c
r99404 r108794 185 185 186 186 PciRootBridgeIo = PciSegmentLibSearchForRootBridge (Address); 187 ASSERT (PciRootBridgeIo != NULL); 187 188 if (PciRootBridgeIo == NULL) { 189 ASSERT (PciRootBridgeIo != NULL); 190 return 0; 191 } 188 192 189 193 PciRootBridgeIo->Pci.Read ( … … 224 228 225 229 PciRootBridgeIo = PciSegmentLibSearchForRootBridge (Address); 226 ASSERT (PciRootBridgeIo != NULL); 230 231 if (PciRootBridgeIo == NULL) { 232 ASSERT (PciRootBridgeIo != NULL); 233 return 0; 234 } 227 235 228 236 PciRootBridgeIo->Pci.Write ( -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiUsbLib/UefiUsbLib.inf
r80721 r108794 6 6 # 7 7 # Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR> 8 # Copyright (c) 2024, American Megatrends International LLC. All rights reserved.<BR> 8 9 # 9 10 # SPDX-License-Identifier: BSD-2-Clause-Patent … … 20 21 VERSION_STRING = 1.0 21 22 LIBRARY_CLASS = UefiUsbLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER 23 DESTRUCTOR = UefiUsbLibDestructor 22 24 23 25 … … 38 40 BaseMemoryLib 39 41 PcdLib 42 UefiBootServicesTableLib 40 43 41 44 [Pcd] -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiUsbLib/UefiUsbLibInternal.h
r99404 r108794 6 6 7 7 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR> 8 Copyright (c) 2024, American Megatrends International LLC. All rights reserved.<BR> 8 9 SPDX-License-Identifier: BSD-2-Clause-Patent 9 10 **/ … … 18 19 #include <Library/DebugLib.h> 19 20 #include <Library/PcdLib.h> 21 #include <Library/UefiBootServicesTableLib.h> 20 22 21 23 #include <IndustryStandard/Usb.h> -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiUsbLib/UsbDxeLib.c
r99404 r108794 5 5 6 6 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR> 7 Copyright (c) 2024, American Megatrends International LLC. All rights reserved.<BR> 7 8 SPDX-License-Identifier: BSD-2-Clause-Patent 8 9 … … 10 11 11 12 #include "UefiUsbLibInternal.h" 13 14 static UINT8 *mConfigData = NULL; 15 static EFI_USB_DEVICE_DESCRIPTOR mDeviceDescriptor; 12 16 13 17 /** … … 651 655 return Result; 652 656 } 657 658 /** 659 Global library data initialization. 660 661 Library public functions' input is the instance of UsbIo protocol. Check if the global 662 data relevant to the UsbIo. If not, read the device and update the global data. 663 664 @param UsbIo The instance of EFI_USB_IO_PROTOCOL. 665 666 @retval EFI_SUCCESS The global data is updated. 667 @retval EFI_NOT_FOUND The UsbIo configuration was not found. 668 669 **/ 670 static 671 EFI_STATUS 672 InitUsbConfigDescriptorData ( 673 EFI_USB_IO_PROTOCOL *UsbIo 674 ) 675 { 676 EFI_STATUS Status; 677 EFI_USB_DEVICE_DESCRIPTOR DevDesc; 678 EFI_USB_CONFIG_DESCRIPTOR CnfDesc; 679 UINT8 ConfigNum; 680 UINT8 ConfigValue; 681 UINT32 UsbStatus; 682 683 // 684 // Get UsbIo device and configuration descriptors. 685 // 686 Status = UsbIo->UsbGetDeviceDescriptor (UsbIo, &DevDesc); 687 ASSERT_EFI_ERROR (Status); 688 689 Status = UsbIo->UsbGetConfigDescriptor (UsbIo, &CnfDesc); 690 ASSERT_EFI_ERROR (Status); 691 692 if (mConfigData != NULL) { 693 if ( (CompareMem (&DevDesc, &mDeviceDescriptor, sizeof (EFI_USB_DEVICE_DESCRIPTOR)) == 0) 694 && (CompareMem (&CnfDesc, mConfigData, sizeof (EFI_USB_CONFIG_DESCRIPTOR)) == 0)) 695 { 696 return EFI_SUCCESS; 697 } 698 699 gBS->FreePool (mConfigData); 700 mConfigData = NULL; 701 } 702 703 CopyMem (&mDeviceDescriptor, &DevDesc, sizeof (EFI_USB_DEVICE_DESCRIPTOR)); 704 705 // 706 // Examine device with multiple configurations: find configuration index of UsbIo config descriptor. 707 // 708 // Use EFI_USB_DEVICE_DESCRIPTOR.NumConfigurations to loop through configuration descriptors, match 709 // EFI_USB_CONFIG_DESCRIPTOR.ConfigurationValue to the configuration value reported by UsbIo->UsbGetConfigDescriptor. 710 // The index of the matched configuration is used in wValue of the following GET_DESCRIPTOR request. 711 // 712 ConfigValue = CnfDesc.ConfigurationValue; 713 for (ConfigNum = 0; ConfigNum < DevDesc.NumConfigurations; ConfigNum++) { 714 Status = UsbGetDescriptor ( 715 UsbIo, 716 (USB_DESC_TYPE_CONFIG << 8) | ConfigNum, 717 0, 718 sizeof (EFI_USB_CONFIG_DESCRIPTOR), 719 &CnfDesc, 720 &UsbStatus 721 ); 722 ASSERT_EFI_ERROR (Status); 723 724 if (CnfDesc.ConfigurationValue == ConfigValue) { 725 break; 726 } 727 } 728 729 ASSERT (ConfigNum < DevDesc.NumConfigurations); 730 if (ConfigNum == DevDesc.NumConfigurations) { 731 return EFI_NOT_FOUND; 732 } 733 734 // 735 // ConfigNum has zero based index of the configuration that UsbIo belongs to. Use this index to retrieve 736 // full configuration descriptor data. 737 // 738 Status = gBS->AllocatePool (EfiBootServicesData, CnfDesc.TotalLength, (VOID **)&mConfigData); 739 ASSERT_EFI_ERROR (Status); 740 741 Status = UsbGetDescriptor ( 742 UsbIo, 743 (USB_DESC_TYPE_CONFIG << 8) | ConfigNum, 744 0, 745 CnfDesc.TotalLength, 746 mConfigData, 747 &UsbStatus 748 ); 749 ASSERT_EFI_ERROR (Status); 750 751 return Status; 752 } 753 754 /** 755 Find descriptor of a given type within data area pointed by mConfigData. 756 757 The following are the assumptions of the configuration descriptor layout: 758 - mConfigData is populated with the configuration data that contains USB interface referenced by UsbIo. 759 - Endpoint may have only one class specific descriptor that immediately follows the endpoint descriptor. 760 761 @param[in] UsbIo A pointer to the EFI_USB_IO_PROTOCOL instance. 762 @param[in] DescType Type of descriptor to look for. 763 @param[in] Setting Interface alternate setting. 764 @param[in] Index Index of the descriptor. This descriptor index is used to find a specific 765 descriptor (only for endpoint descriptors and class specific interface descriptors) 766 when several descriptors of the same type are implemented in a device. For other 767 descriptor types, a descriptor index of zero must be used. 768 @param[out] Data A pointer to the caller allocated Descriptor. 769 770 @retval EFI_SUCCESS Output parameters were updated successfully. 771 @retval EFI_UNSUPPORTED Setting is greater than the number of alternate settings in this interface. 772 @retval EFI_NOT_FOUND Index is greater than the number of descriptors of the requested type in this 773 interface. 774 **/ 775 static 776 EFI_STATUS 777 FindUsbDescriptor ( 778 EFI_USB_IO_PROTOCOL *UsbIo, 779 UINT8 DescType, 780 UINT16 Setting, 781 UINTN Index, 782 VOID **Data 783 ) 784 { 785 EFI_USB_INTERFACE_DESCRIPTOR IntfDesc; 786 EFI_STATUS Status; 787 UINT8 *BufferPtr; 788 UINT8 *BufferEnd; 789 UINT8 *ConfigEnd; 790 UINTN Idx; 791 792 // 793 // Find the interface descriptor referenced by UsbIo in the current configuration 794 // 795 Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &IntfDesc); 796 ASSERT_EFI_ERROR (Status); 797 798 ConfigEnd = mConfigData + ((EFI_USB_CONFIG_DESCRIPTOR *)mConfigData)->TotalLength; 799 800 for (BufferPtr = mConfigData; BufferPtr < ConfigEnd; BufferPtr += BufferPtr[0]) { 801 if (BufferPtr[1] == USB_DESC_TYPE_INTERFACE) { 802 if ((BufferPtr[2] == IntfDesc.InterfaceNumber) && (BufferPtr[3] == (UINT8)Setting)) { 803 break; 804 } 805 } 806 } 807 808 if (BufferPtr >= ConfigEnd) { 809 return EFI_UNSUPPORTED; 810 } 811 812 // 813 // Found the beginning of the interface, find the ending 814 // 815 for (BufferEnd = BufferPtr + BufferPtr[0]; BufferEnd < ConfigEnd; BufferEnd += BufferEnd[0]) { 816 if (BufferEnd[1] == USB_DESC_TYPE_INTERFACE) { 817 break; 818 } 819 } 820 821 Idx = 0; 822 823 if (DescType == USB_DESC_TYPE_INTERFACE) { 824 *Data = BufferPtr; 825 return EFI_SUCCESS; 826 } 827 828 if ((DescType == USB_DESC_TYPE_ENDPOINT) || (DescType == USB_DESC_TYPE_CS_ENDPOINT)) { 829 while (BufferPtr < BufferEnd) { 830 BufferPtr += BufferPtr[0]; 831 if (BufferPtr[1] == USB_DESC_TYPE_ENDPOINT) { 832 if (Idx == Index) { 833 if (DescType == USB_DESC_TYPE_CS_ENDPOINT) { 834 BufferPtr += BufferPtr[0]; 835 if (BufferPtr[1] != USB_DESC_TYPE_CS_ENDPOINT) { 836 break; 837 } 838 } 839 840 *Data = BufferPtr; 841 return EFI_SUCCESS; 842 } 843 844 Idx++; 845 } 846 } 847 } 848 849 if (DescType == USB_DESC_TYPE_CS_INTERFACE) { 850 while (BufferPtr < BufferEnd) { 851 BufferPtr += BufferPtr[0]; 852 if (BufferPtr[1] == USB_DESC_TYPE_CS_INTERFACE) { 853 if (Idx == Index) { 854 *Data = BufferPtr; 855 return EFI_SUCCESS; 856 } 857 858 Idx++; 859 } 860 } 861 } 862 863 return EFI_NOT_FOUND; 864 } 865 866 /** 867 Retrieve the number of class specific interface descriptors. 868 869 @param[in] Data A pointer to the USB interface descriptor that may contain class code descriptors. 870 871 @retval UINT8 Number of the class code interface descriptors. 872 873 **/ 874 static 875 UINT8 876 FindNumberOfCsInterfaces ( 877 VOID *Data 878 ) 879 { 880 UINT8 *Buffer; 881 UINT8 *ConfigEnd; 882 UINT8 Index; 883 884 Buffer = Data; 885 ConfigEnd = mConfigData + ((EFI_USB_CONFIG_DESCRIPTOR *)mConfigData)->TotalLength; 886 887 Index = 0; 888 889 for (Buffer += Buffer[0]; Buffer < ConfigEnd; Buffer += Buffer[0]) { 890 if (Buffer[1] == USB_DESC_TYPE_INTERFACE) { 891 break; 892 } 893 894 if (Buffer[1] == USB_DESC_TYPE_CS_INTERFACE) { 895 Index++; 896 } 897 } 898 899 return Index; 900 } 901 902 /** 903 Retrieve the interface descriptor details from the interface setting. 904 905 This is an extended version of UsbIo->GetInterfaceDescriptor. It returns the interface 906 descriptor for an alternate setting of the interface without executing SET_INTERFACE 907 transfer. It also returns the number of class specific interfaces. 908 AlternateSetting parameter is the zero-based interface descriptor index that is used in USB 909 interface descriptor as USB_INTERFACE_DESCRIPTOR.AlternateSetting. 910 911 912 @param[in] This A pointer to the EFI_USB_IO_PROTOCOL instance. 913 @param[in] AlternateSetting Interface alternate setting. 914 @param[out] Descriptor The caller allocated buffer to return the contents of the Interface descriptor. 915 @param[out] CsInterfaceNumber Number of class specific interfaces for this interface setting. 916 917 @retval EFI_SUCCESS Output parameters were updated successfully. 918 @retval EFI_INVALID_PARAMETER Descriptor or CsInterfaceNumber is NULL. 919 @retval EFI_UNSUPPORTED AlternateSetting is greater than the number of alternate settings in this interface. 920 @retval EFI_DEVICE_ERROR Error reading device data. 921 922 **/ 923 EFI_STATUS 924 EFIAPI 925 UsbGetInterfaceDescriptorSetting ( 926 IN EFI_USB_IO_PROTOCOL *This, 927 IN UINT16 AlternateSetting, 928 OUT EFI_USB_INTERFACE_DESCRIPTOR *Descriptor, 929 OUT UINTN *CsInterfacesNumber 930 ) 931 { 932 EFI_STATUS Status; 933 VOID *Data; 934 EFI_TPL OldTpl; 935 936 if ((Descriptor == NULL) || (CsInterfacesNumber == NULL)) { 937 return EFI_INVALID_PARAMETER; 938 } 939 940 OldTpl = gBS->RaiseTPL (TPL_NOTIFY); 941 942 Status = InitUsbConfigDescriptorData (This); 943 if (EFI_ERROR (Status)) { 944 Status = EFI_DEVICE_ERROR; 945 goto ON_EXIT; 946 } 947 948 Status = FindUsbDescriptor (This, USB_DESC_TYPE_INTERFACE, AlternateSetting, 0, &Data); 949 if (EFI_ERROR (Status)) { 950 goto ON_EXIT; 951 } 952 953 *CsInterfacesNumber = FindNumberOfCsInterfaces (Data); 954 CopyMem (Descriptor, Data, sizeof (EFI_USB_INTERFACE_DESCRIPTOR)); 955 956 ON_EXIT: 957 gBS->RestoreTPL (OldTpl); 958 return Status; 959 } 960 961 /** 962 Retrieve the endpoint descriptor from the interface setting. 963 964 This is an extended version of UsbIo->GetEndpointDescriptor. It returns the endpoint 965 descriptor for an alternate setting of a given interface. 966 AlternateSetting parameter is the zero-based interface descriptor index that is used in USB 967 interface descriptor as USB_INTERFACE_DESCRIPTOR.AlternateSetting. 968 969 Note: The total number of endpoints can be retrieved from the interface descriptor 970 returned by EDKII_USBIO_EXT_GET_INTERFACE_DESCRIPTOR function. 971 972 @param[in] This A pointer to the EFI_USB_IO_PROTOCOL instance. 973 @param[in] AlternateSetting Interface alternate setting. 974 @param[in] Index Index of the endpoint to retrieve. The valid range is 0..15. 975 @param[out] Descriptor A pointer to the caller allocated USB Interface Descriptor. 976 977 @retval EFI_SUCCESS Output parameters were updated successfully. 978 @retval EFI_INVALID_PARAMETER Descriptor is NULL. 979 @retval EFI_UNSUPPORTED AlternateSetting is greater than the number of alternate settings in this interface. 980 @retval EFI_NOT_FOUND Index is greater than the number of endpoints in this interface. 981 @retval EFI_DEVICE_ERROR Error reading device data. 982 983 **/ 984 EFI_STATUS 985 EFIAPI 986 UsbGetEndpointDescriptorSetting ( 987 IN EFI_USB_IO_PROTOCOL *This, 988 IN UINT16 AlternateSetting, 989 IN UINTN Index, 990 OUT EFI_USB_ENDPOINT_DESCRIPTOR *Descriptor 991 ) 992 { 993 EFI_STATUS Status; 994 VOID *Data; 995 EFI_TPL OldTpl; 996 997 if (Descriptor == NULL) { 998 return EFI_INVALID_PARAMETER; 999 } 1000 1001 OldTpl = gBS->RaiseTPL (TPL_NOTIFY); 1002 1003 Status = InitUsbConfigDescriptorData (This); 1004 if (EFI_ERROR (Status)) { 1005 Status = EFI_DEVICE_ERROR; 1006 goto ON_EXIT; 1007 } 1008 1009 Status = FindUsbDescriptor (This, USB_DESC_TYPE_ENDPOINT, AlternateSetting, Index, &Data); 1010 if (EFI_ERROR (Status)) { 1011 goto ON_EXIT; 1012 } 1013 1014 CopyMem (Descriptor, Data, sizeof (EFI_USB_ENDPOINT_DESCRIPTOR)); 1015 1016 ON_EXIT: 1017 gBS->RestoreTPL (OldTpl); 1018 return Status; 1019 } 1020 1021 /** 1022 Retrieve class specific interface descriptor. 1023 1024 AlternateSetting parameter is the zero-based interface descriptor index that is used in USB 1025 interface descriptor as USB_INTERFACE_DESCRIPTOR.AlternateSetting. 1026 1027 @param[in] This A pointer to the EFI_USB_IO_PROTOCOL instance. 1028 @param[in] AlternateSetting Interface alternate setting. 1029 @param[in] Index Zero-based index of the class specific interface. 1030 @param[in][out] BufferSize On input, the size in bytes of the return Descriptor buffer. 1031 On output the size of data returned in Descriptor. 1032 @param[out] Descriptor The buffer to return the contents of the class specific interface descriptor. May 1033 be NULL with a zero BufferSize in order to determine the size buffer needed. 1034 1035 @retval EFI_SUCCESS Output parameters were updated successfully. 1036 @retval EFI_INVALID_PARAMETER BufferSize is NULL. 1037 Buffer is NULL and *BufferSize is not zero. 1038 @retval EFI_UNSUPPORTED AlternateSetting is greater than the number of alternate settings in this interface. 1039 @retval EFI_NOT_FOUND Index is greater than the number of class specific interfaces. 1040 @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small for the result. BufferSize has been updated with the size 1041 needed to complete the request. 1042 @retval EFI_DEVICE_ERROR Error reading device data. 1043 1044 **/ 1045 EFI_STATUS 1046 EFIAPI 1047 UsbGetCsInterfaceDescriptor ( 1048 IN EFI_USB_IO_PROTOCOL *This, 1049 IN UINT16 AlternateSetting, 1050 IN UINTN Index, 1051 IN OUT UINTN *BufferSize, 1052 OUT VOID *Buffer 1053 ) 1054 { 1055 EFI_STATUS Status; 1056 VOID *Data; 1057 UINT8 DescLength; 1058 EFI_TPL OldTpl; 1059 1060 if ((BufferSize == NULL) || ((Buffer == NULL) && (*BufferSize != 0))) { 1061 return EFI_INVALID_PARAMETER; 1062 } 1063 1064 OldTpl = gBS->RaiseTPL (TPL_NOTIFY); 1065 1066 Status = InitUsbConfigDescriptorData (This); 1067 if (EFI_ERROR (Status)) { 1068 Status = EFI_DEVICE_ERROR; 1069 goto ON_EXIT; 1070 } 1071 1072 Status = FindUsbDescriptor (This, USB_DESC_TYPE_CS_INTERFACE, AlternateSetting, Index, &Data); 1073 if (EFI_ERROR (Status)) { 1074 goto ON_EXIT; 1075 } 1076 1077 DescLength = ((UINT8 *)Data)[0]; 1078 1079 if ((Buffer == NULL) || (DescLength > *BufferSize)) { 1080 *BufferSize = DescLength; 1081 Status = EFI_BUFFER_TOO_SMALL; 1082 goto ON_EXIT; 1083 } 1084 1085 CopyMem (Buffer, Data, DescLength); 1086 1087 ON_EXIT: 1088 gBS->RestoreTPL (OldTpl); 1089 return Status; 1090 } 1091 1092 /** 1093 Retrieve class specific endpoint descriptor. 1094 1095 AlternateSetting parameter is the zero-based interface descriptor index that is used in USB 1096 interface descriptor as USB_INTERFACE_DESCRIPTOR.AlternateSetting. 1097 1098 @param[in] This A pointer to the EFI_USB_IO_PROTOCOL instance. 1099 @param[in] AlternateSetting Interface alternate setting. 1100 @param[in] Index Zero-based index of the non-zero endpoint. 1101 @param[in][out] BufferSize On input, the size in bytes of the return Descriptor buffer. 1102 On output the size of data returned in Descriptor. 1103 @param[out] Descriptor The buffer to return the contents of the class specific endpoint descriptor. May 1104 be NULL with a zero BufferSize in order to determine the size buffer needed. 1105 1106 @retval EFI_SUCCESS Output parameters were updated successfully. 1107 @retval EFI_INVALID_PARAMETER BufferSize is NULL. 1108 Buffer is NULL and *BufferSize is not zero. 1109 @retval EFI_UNSUPPORTED AlternateSetting is greater than the number of alternate settings in this interface. 1110 @retval EFI_NOT_FOUND Index is greater than the number of endpoints in this interface. 1111 Endpoint does not have class specific endpoint descriptor. 1112 @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small for the result. BufferSize has been updated with the size 1113 needed to complete the request. 1114 @retval EFI_DEVICE_ERROR Error reading device data. 1115 1116 **/ 1117 EFI_STATUS 1118 EFIAPI 1119 UsbGetCsEndpointDescriptor ( 1120 IN EFI_USB_IO_PROTOCOL *This, 1121 IN UINT16 AlternateSetting, 1122 IN UINTN Index, 1123 IN OUT UINTN *BufferSize, 1124 OUT VOID *Buffer 1125 ) 1126 { 1127 EFI_STATUS Status; 1128 VOID *Data; 1129 UINT8 DescLength; 1130 EFI_TPL OldTpl; 1131 1132 if ((BufferSize == NULL) || ((Buffer == NULL) && (*BufferSize != 0))) { 1133 return EFI_INVALID_PARAMETER; 1134 } 1135 1136 OldTpl = gBS->RaiseTPL (TPL_NOTIFY); 1137 1138 Status = InitUsbConfigDescriptorData (This); 1139 if (EFI_ERROR (Status)) { 1140 Status = EFI_DEVICE_ERROR; 1141 goto ON_EXIT; 1142 } 1143 1144 Status = FindUsbDescriptor (This, USB_DESC_TYPE_CS_ENDPOINT, AlternateSetting, Index, &Data); 1145 if (EFI_ERROR (Status)) { 1146 goto ON_EXIT; 1147 } 1148 1149 DescLength = ((UINT8 *)Data)[0]; 1150 1151 if ((Buffer == NULL) || (DescLength > *BufferSize)) { 1152 *BufferSize = DescLength; 1153 Status = EFI_BUFFER_TOO_SMALL; 1154 goto ON_EXIT; 1155 } 1156 1157 CopyMem (Buffer, Data, DescLength); 1158 1159 ON_EXIT: 1160 gBS->RestoreTPL (OldTpl); 1161 return Status; 1162 } 1163 1164 /** 1165 Destructor frees memory which was allocated by the library functions. 1166 1167 @param ImageHandle Handle that identifies the image to be unloaded. 1168 @param SystemTable The system table. 1169 1170 @retval EFI_SUCCESS The image has been unloaded. 1171 1172 **/ 1173 EFI_STATUS 1174 EFIAPI 1175 UefiUsbLibDestructor ( 1176 IN EFI_HANDLE ImageHandle, 1177 IN EFI_SYSTEM_TABLE *SystemTable 1178 ) 1179 { 1180 if (mConfigData != NULL) { 1181 gBS->FreePool (mConfigData); 1182 } 1183 1184 return EFI_SUCCESS; 1185 }
Note:
See TracChangeset
for help on using the changeset viewer.