VirtualBox

Ignore:
Timestamp:
Oct 28, 2015 8:17:18 PM (9 years ago)
Author:
vboxsync
Message:

EFI/Firmware: 'svn merge /vendor/edk2/UDK2010.SR1 /vendor/edk2/current .', reverting and removing files+dirs listed in ReadMe.vbox, resolving conflicts with help from ../UDK2014.SP1/. This is a raw untested merge.

Location:
trunk/src/VBox/Devices/EFI/Firmware
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/EFI/Firmware

  • trunk/src/VBox/Devices/EFI/Firmware/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c

    r48674 r58459  
    33  gEfiDevicePathUtilitiesProtocolGuid.
    44
    5   Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
     5  Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
    66  This program and the accompanying materials
    77  are licensed and made available under the terms and conditions of the BSD License
     
    1818
    1919#include <Protocol/DevicePathUtilities.h>
     20#include <Protocol/DevicePathToText.h>
     21#include <Protocol/DevicePathFromText.h>
    2022
    2123#include <Library/DevicePathLib.h>
     
    2527#include <Library/BaseMemoryLib.h>
    2628#include <Library/UefiBootServicesTableLib.h>
    27 
    28 EFI_DEVICE_PATH_UTILITIES_PROTOCOL          *mDevicePathUtilities = NULL;
     29#include <Library/PcdLib.h>
     30
     31GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_UTILITIES_PROTOCOL *mDevicePathLibDevicePathUtilities = NULL;
     32GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_TO_TEXT_PROTOCOL   *mDevicePathLibDevicePathToText    = NULL;
     33GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL *mDevicePathLibDevicePathFromText  = NULL;
    2934
    3035//
     
    6469                  &gEfiDevicePathUtilitiesProtocolGuid,
    6570                  NULL,
    66                   (VOID**) &mDevicePathUtilities
     71                  (VOID**) &mDevicePathLibDevicePathUtilities
    6772                  );
    6873  ASSERT_EFI_ERROR (Status);
    69   ASSERT (mDevicePathUtilities != NULL);
    70 
     74  ASSERT (mDevicePathLibDevicePathUtilities != NULL);
    7175  return Status;
     76}
     77
     78/**
     79  Determine whether a given device path is valid.
     80  If DevicePath is NULL, then ASSERT().
     81
     82  @param  DevicePath  A pointer to a device path data structure.
     83  @param  MaxSize     The maximum size of the device path data structure.
     84
     85  @retval TRUE        DevicePath is valid.
     86  @retval FALSE       The length of any node node in the DevicePath is less
     87                      than sizeof (EFI_DEVICE_PATH_PROTOCOL).
     88  @retval FALSE       If MaxSize is not zero, the size of the DevicePath
     89                      exceeds MaxSize.
     90  @retval FALSE       If PcdMaximumDevicePathNodeCount is not zero, the node
     91                      count of the DevicePath exceeds PcdMaximumDevicePathNodeCount.
     92**/
     93BOOLEAN
     94EFIAPI
     95IsDevicePathValid (
     96  IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
     97  IN       UINTN                    MaxSize
     98  )
     99{
     100  UINTN Count;
     101  UINTN Size;
     102  UINTN NodeLength;
     103
     104  ASSERT (DevicePath != NULL);
     105
     106  for (Count = 0, Size = 0; !IsDevicePathEnd (DevicePath); DevicePath = NextDevicePathNode (DevicePath)) {
     107    NodeLength = DevicePathNodeLength (DevicePath);
     108    if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {
     109      return FALSE;
     110    }
     111
     112    if (MaxSize > 0) {
     113      Size += NodeLength;
     114      if (Size + END_DEVICE_PATH_LENGTH > MaxSize) {
     115        return FALSE;
     116      }
     117    }
     118
     119    if (PcdGet32 (PcdMaximumDevicePathNodeCount) > 0) {
     120      Count++;
     121      if (Count >= PcdGet32 (PcdMaximumDevicePathNodeCount)) {
     122        return FALSE;
     123      }
     124    }
     125  }
     126
     127  //
     128  // Only return TRUE when the End Device Path node is valid.
     129  //
     130  return (BOOLEAN) (DevicePathNodeLength (DevicePath) == END_DEVICE_PATH_LENGTH);
    72131}
    73132
     
    257316
    258317  If Node is NULL, then ASSERT().
    259   If NodeLength >= 0x10000, then ASSERT().
     318  If NodeLength >= SIZE_64KB, then ASSERT().
     319  If NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL), then ASSERT().
    260320
    261321  @param  Node      A pointer to a device path node data structure.
     
    273333{
    274334  ASSERT (Node != NULL);
    275   ASSERT (Length < 0x10000);
     335  ASSERT ((Length >= sizeof (EFI_DEVICE_PATH_PROTOCOL)) && (Length < SIZE_64KB));
    276336  return WriteUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Length[0], (UINT16)(Length));
    277337}
     
    306366  Returns the size of a device path in bytes.
    307367
    308   This function returns the size, in bytes, of the device path data structure specified by
    309   DevicePath including the end of device path node.  If DevicePath is NULL, then 0 is returned.
    310 
    311   @param  DevicePath                 A pointer to a device path data structure.
    312  
    313   @retval 0       If DevicePath is NULL.
    314   @retval Others  The size of a device path in bytes.
     368  This function returns the size, in bytes, of the device path data structure
     369  specified by DevicePath including the end of device path node.
     370  If DevicePath is NULL or invalid, then 0 is returned.
     371
     372  @param  DevicePath  A pointer to a device path data structure.
     373
     374  @retval 0           If DevicePath is NULL or invalid.
     375  @retval Others      The size of a device path in bytes.
    315376
    316377**/
     
    321382  )
    322383{
    323   return mDevicePathUtilities->GetDevicePathSize (DevicePath);
     384  return mDevicePathLibDevicePathUtilities->GetDevicePathSize (DevicePath);
    324385}
    325386
     
    337398  @param  DevicePath                 A pointer to a device path data structure.
    338399
    339   @retval NULL    If DevicePath is NULL.
     400  @retval NULL    If DevicePath is NULL or invalid.
    340401  @retval Others  A pointer to the duplicated device path.
    341402 
     
    347408  )
    348409{
    349   return mDevicePathUtilities->DuplicateDevicePath (DevicePath);
     410  return mDevicePathLibDevicePathUtilities->DuplicateDevicePath (DevicePath);
    350411}
    351412
     
    368429 
    369430  @retval NULL      If there is not enough memory for the newly allocated buffer.
     431  @retval NULL      If FirstDevicePath or SecondDevicePath is invalid.
    370432  @retval Others    A pointer to the new device path if success.
    371433                    Or a copy an end-of-device-path if both FirstDevicePath and
     
    380442  )
    381443{
    382   return mDevicePathUtilities->AppendDevicePath (FirstDevicePath, SecondDevicePath);
     444  return mDevicePathLibDevicePathUtilities->AppendDevicePath (FirstDevicePath, SecondDevicePath);
    383445}
    384446
     
    418480  )
    419481{
    420   return mDevicePathUtilities->AppendDeviceNode (DevicePath, DevicePathNode);
     482  return mDevicePathLibDevicePathUtilities->AppendDeviceNode (DevicePath, DevicePathNode);
    421483}
    422484
     
    432494  If DevicePath is NULL, then a copy if DevicePathInstance is returned.
    433495  If DevicePathInstance is NULL, then NULL is returned.
     496  If DevicePath or DevicePathInstance is invalid, then NULL is returned.
    434497  If there is not enough memory to allocate space for the new device path, then
    435498  NULL is returned.   
     
    450513  )
    451514{
    452   return mDevicePathUtilities->AppendDevicePathInstance (DevicePath, DevicePathInstance);
     515  return mDevicePathLibDevicePathUtilities->AppendDevicePathInstance (DevicePath, DevicePathInstance);
    453516}
    454517
     
    488551{
    489552  ASSERT (Size != NULL);
    490   return mDevicePathUtilities->GetNextDevicePathInstance (DevicePath, Size);
     553  return mDevicePathLibDevicePathUtilities->GetNextDevicePathInstance (DevicePath, Size);
    491554}
    492555
     
    501564  NULL is returned. 
    502565  The memory is allocated from EFI boot services memory. It is the responsibility
    503   of the caller to
    504   free the memory allocated.
     566  of the caller to free the memory allocated.
    505567
    506568  @param  NodeType                   The device node type for the new device node.
     
    519581  )
    520582{
    521   return mDevicePathUtilities->CreateDeviceNode (NodeType, NodeSubType, NodeLength);
     583  return mDevicePathLibDevicePathUtilities->CreateDeviceNode (NodeType, NodeSubType, NodeLength);
    522584}
    523585
     
    525587  Determines if a device path is single or multi-instance.
    526588
    527   This function returns TRUE if the device path specified by DevicePath is 
     589  This function returns TRUE if the device path specified by DevicePath is
    528590  multi-instance.
    529   Otherwise, FALSE is returned.  If DevicePath is NULL, then FALSE is returned.
     591  Otherwise, FALSE is returned.
     592  If DevicePath is NULL or invalid, then FALSE is returned.
    530593
    531594  @param  DevicePath                 A pointer to a device path data structure.
    532595
    533596  @retval  TRUE                      DevicePath is multi-instance.
    534   @retval  FALSE                     DevicePath is not multi-instance or DevicePath
    535                                      is NULL.
     597  @retval  FALSE                     DevicePath is not multi-instance, or DevicePath
     598                                     is NULL or invalid.
    536599
    537600**/
     
    542605  )
    543606{
    544   return mDevicePathUtilities->IsDevicePathMultiInstance (DevicePath);
     607  return mDevicePathLibDevicePathUtilities->IsDevicePathMultiInstance (DevicePath);
    545608}
    546609
     
    634697  return DevicePath;
    635698}
     699
     700/**
     701  Locate and return the protocol instance identified by the ProtocolGuid.
     702
     703  @param ProtocolGuid     The GUID of the protocol.
     704
     705  @return A pointer to the protocol instance or NULL when absent.
     706**/
     707VOID *
     708UefiDevicePathLibLocateProtocol (
     709  EFI_GUID                         *ProtocolGuid
     710  )
     711{
     712  EFI_STATUS Status;
     713  VOID       *Protocol;
     714  Status = gBS->LocateProtocol (
     715                  ProtocolGuid,
     716                  NULL,
     717                  (VOID**) &Protocol
     718                  );
     719  if (EFI_ERROR (Status)) {
     720    return NULL;
     721  } else {
     722    return Protocol;
     723  }
     724}
     725
     726/**
     727  Converts a device node to its string representation.
     728
     729  @param DeviceNode        A Pointer to the device node to be converted.
     730  @param DisplayOnly       If DisplayOnly is TRUE, then the shorter text representation
     731                           of the display node is used, where applicable. If DisplayOnly
     732                           is FALSE, then the longer text representation of the display node
     733                           is used.
     734  @param AllowShortcuts    If AllowShortcuts is TRUE, then the shortcut forms of text
     735                           representation for a device node can be used, where applicable.
     736
     737  @return A pointer to the allocated text representation of the device node or NULL if DeviceNode
     738          is NULL or there was insufficient memory.
     739
     740**/
     741CHAR16 *
     742EFIAPI
     743ConvertDeviceNodeToText (
     744  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DeviceNode,
     745  IN BOOLEAN                         DisplayOnly,
     746  IN BOOLEAN                         AllowShortcuts
     747  )
     748{
     749  if (mDevicePathLibDevicePathToText == NULL) {
     750    mDevicePathLibDevicePathToText = UefiDevicePathLibLocateProtocol (&gEfiDevicePathToTextProtocolGuid);
     751  }
     752  if (mDevicePathLibDevicePathToText != NULL) {
     753    return mDevicePathLibDevicePathToText->ConvertDeviceNodeToText (DeviceNode, DisplayOnly, AllowShortcuts);
     754  } else {
     755    return NULL;
     756  }
     757}
     758
     759/**
     760  Converts a device path to its text representation.
     761
     762  @param DevicePath      A Pointer to the device to be converted.
     763  @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
     764                         of the display node is used, where applicable. If DisplayOnly
     765                         is FALSE, then the longer text representation of the display node
     766                         is used.
     767  @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
     768                         representation for a device node can be used, where applicable.
     769
     770  @return A pointer to the allocated text representation of the device path or
     771          NULL if DeviceNode is NULL or there was insufficient memory.
     772
     773**/
     774CHAR16 *
     775EFIAPI
     776ConvertDevicePathToText (
     777  IN CONST EFI_DEVICE_PATH_PROTOCOL   *DevicePath,
     778  IN BOOLEAN                          DisplayOnly,
     779  IN BOOLEAN                          AllowShortcuts
     780  )
     781{
     782  if (mDevicePathLibDevicePathToText == NULL) {
     783    mDevicePathLibDevicePathToText = UefiDevicePathLibLocateProtocol (&gEfiDevicePathToTextProtocolGuid);
     784  }
     785  if (mDevicePathLibDevicePathToText != NULL) {
     786    return mDevicePathLibDevicePathToText->ConvertDevicePathToText (DevicePath, DisplayOnly, AllowShortcuts);
     787  } else {
     788    return NULL;
     789  }
     790}
     791
     792/**
     793  Convert text to the binary representation of a device node.
     794
     795  @param TextDeviceNode  TextDeviceNode points to the text representation of a device
     796                         node. Conversion starts with the first character and continues
     797                         until the first non-device node character.
     798
     799  @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was
     800          insufficient memory or text unsupported.
     801
     802**/
     803EFI_DEVICE_PATH_PROTOCOL *
     804EFIAPI
     805ConvertTextToDeviceNode (
     806  IN CONST CHAR16 *TextDeviceNode
     807  )
     808{
     809  if (mDevicePathLibDevicePathFromText == NULL) {
     810    mDevicePathLibDevicePathFromText = UefiDevicePathLibLocateProtocol (&gEfiDevicePathFromTextProtocolGuid);
     811  }
     812  if (mDevicePathLibDevicePathFromText != NULL) {
     813    return mDevicePathLibDevicePathFromText->ConvertTextToDeviceNode (TextDeviceNode);
     814  } else {
     815    return NULL;
     816  }
     817}
     818
     819/**
     820  Convert text to the binary representation of a device path.
     821
     822
     823  @param TextDevicePath  TextDevicePath points to the text representation of a device
     824                         path. Conversion starts with the first character and continues
     825                         until the first non-device node character.
     826
     827  @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or
     828          there was insufficient memory.
     829
     830**/
     831EFI_DEVICE_PATH_PROTOCOL *
     832EFIAPI
     833ConvertTextToDevicePath (
     834  IN CONST CHAR16 *TextDevicePath
     835  )
     836{
     837  if (mDevicePathLibDevicePathFromText == NULL) {
     838    mDevicePathLibDevicePathFromText = UefiDevicePathLibLocateProtocol (&gEfiDevicePathFromTextProtocolGuid);
     839  }
     840  if (mDevicePathLibDevicePathFromText != NULL) {
     841    return mDevicePathLibDevicePathFromText->ConvertTextToDevicePath (TextDevicePath);
     842  } else {
     843    return NULL;
     844  }
     845}
     846
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette