Home | History | Annotate | Download | only in DevicePathTextLib
      1 /** @file
      2   Null Platform Hook Library instance.
      3 
      4   Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
      5   This program and the accompanying materials
      6   are licensed and made available under the terms and conditions of the BSD License
      7   which accompanies this distribution.  The full text of the license may be found at
      8   http://opensource.org/licenses/bsd-license.php
      9 
     10   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     11   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     12 
     13 **/
     14 
     15 #include <Base.h>
     16 
     17 #include <Protocol/EmuThunk.h>
     18 #include <Protocol/EmuGraphicsWindow.h>
     19 #include <Protocol/EmuBlockIo.h>
     20 #include <Protocol/SimpleFileSystem.h>
     21 #include <Protocol/EmuThread.h>
     22 
     23 #include <Library/BaseLib.h>
     24 #include <Library/DevicePathToTextLib.h>
     25 #include <Library/BaseMemoryLib.h>
     26 #include <Library/DevicePathLib.h>
     27 
     28 
     29 /**
     30   Converts a Vendor device path structure to its string representative.
     31 
     32   @param Str             The string representative of input device.
     33   @param DevPath         The input device path structure.
     34   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
     35                          of the display node is used, where applicable. If DisplayOnly
     36                          is FALSE, then the longer text representation of the display node
     37                          is used.
     38   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
     39                          representation for a device node can be used, where applicable.
     40 
     41   @return EFI_NOT_FOUND if no string representation exists.
     42   @return EFI_SUCCESS   a string representation was created.
     43 **/
     44 EFI_STATUS
     45 EFIAPI
     46 DevPathToTextVendorLib (
     47   IN OUT POOL_PRINT  *Str,
     48   IN VOID            *DevPath,
     49   IN BOOLEAN         DisplayOnly,
     50   IN BOOLEAN         AllowShortcuts
     51   )
     52 {
     53   EMU_VENDOR_DEVICE_PATH_NODE  *Vendor;
     54   CHAR16                       *Type;
     55 
     56   Vendor = (EMU_VENDOR_DEVICE_PATH_NODE *)DevPath;
     57   if (CompareGuid (&Vendor->VendorDevicePath.Guid, &gEmuThunkProtocolGuid)) {
     58     CatPrint (Str, L"EmuThunk()");
     59     return EFI_SUCCESS;
     60   }
     61   if (CompareGuid (&Vendor->VendorDevicePath.Guid, &gEmuGraphicsWindowProtocolGuid)) {
     62     CatPrint (Str, L"EmuGraphics(%d)", Vendor->Instance);
     63     return EFI_SUCCESS;
     64   }
     65   if (CompareGuid (&Vendor->VendorDevicePath.Guid, &gEfiSimpleFileSystemProtocolGuid)) {
     66     CatPrint (Str, L"EmuFs(%d)", Vendor->Instance);
     67     return EFI_SUCCESS;
     68   }
     69   if (CompareGuid (&Vendor->VendorDevicePath.Guid, &gEmuBlockIoProtocolGuid)) {
     70     CatPrint (Str, L"EmuBlk(%d)", Vendor->Instance);
     71     return EFI_SUCCESS;
     72   }
     73   if (CompareGuid (&Vendor->VendorDevicePath.Guid, &gEmuThreadThunkProtocolGuid)) {
     74     CatPrint (Str, L"EmuThread()");
     75     return EFI_SUCCESS;
     76   }
     77 
     78   return EFI_NOT_FOUND;
     79 }
     80 
     81 /**
     82   Converts a text device path node to Hardware Vendor device path structure.
     83 
     84   @param TextDeviceNode  The input Text device path node.
     85 
     86   @return A pointer to the newly-created Hardware Vendor device path structure.
     87 
     88 **/
     89 EFI_DEVICE_PATH_PROTOCOL *
     90 DevPathFromTextEmuThunk (
     91   IN CHAR16 *TextDeviceNode
     92   )
     93 {
     94   CHAR16              *Str;
     95   VENDOR_DEVICE_PATH  *Vendor;
     96 
     97   Str    = GetNextParamStr (&TextDeviceNode);
     98   Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
     99                                      HARDWARE_DEVICE_PATH,
    100                                      HW_VENDOR_DP,
    101                                      (UINT16) sizeof (VENDOR_DEVICE_PATH)
    102                                      );
    103   CopyGuid (&Vendor->Guid, &gEmuThunkProtocolGuid);
    104   return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
    105 }
    106 
    107 /**
    108   Converts a text device path node to Hardware Vendor device path structure.
    109 
    110   @param TextDeviceNode  The input Text device path node.
    111 
    112   @return A pointer to the newly-created Hardware Vendor device path structure.
    113 
    114 **/
    115 EFI_DEVICE_PATH_PROTOCOL *
    116 DevPathFromTextEmuThread (
    117   IN CHAR16 *TextDeviceNode
    118   )
    119 {
    120   CHAR16              *Str;
    121   VENDOR_DEVICE_PATH  *Vendor;
    122 
    123   Str    = GetNextParamStr (&TextDeviceNode);
    124   Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
    125                                      HARDWARE_DEVICE_PATH,
    126                                      HW_VENDOR_DP,
    127                                      (UINT16) sizeof (VENDOR_DEVICE_PATH)
    128                                      );
    129   CopyGuid (&Vendor->Guid, &gEmuThreadThunkProtocolGuid);
    130   return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
    131 }
    132 
    133 /**
    134   Converts a text device path node to Hardware Vendor device path structure.
    135 
    136   @param TextDeviceNode  The input Text device path node.
    137 
    138   @return A pointer to the newly-created Hardware Vendor device path structure.
    139 
    140 **/
    141 EFI_DEVICE_PATH_PROTOCOL *
    142 DevPathFromTextEmuFs (
    143   IN CHAR16 *TextDeviceNode
    144   )
    145 {
    146   CHAR16                       *Str;
    147   EMU_VENDOR_DEVICE_PATH_NODE  *Vendor;
    148 
    149   Str = GetNextParamStr (&TextDeviceNode);
    150   Vendor    = (EMU_VENDOR_DEVICE_PATH_NODE *) CreateDeviceNode (
    151                                                    HARDWARE_DEVICE_PATH,
    152                                                    HW_VENDOR_DP,
    153                                                    (UINT16) sizeof (EMU_VENDOR_DEVICE_PATH_NODE)
    154                                                    );
    155   CopyGuid (&Vendor->VendorDevicePath.Guid, &gEfiSimpleFileSystemProtocolGuid);
    156   Vendor->Instance = (UINT32) StrDecimalToUintn (Str);
    157 
    158   return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
    159 }
    160 
    161 /**
    162   Register the Filter function
    163 
    164   @param  ImageHandle   The firmware allocated handle for the EFI image.
    165   @param  SystemTable   A pointer to the EFI System Table.
    166 
    167   @retval EFI_SUCCESS   The constructor executed correctly.
    168 
    169 **/
    170 EFI_STATUS
    171 EFIAPI
    172 DevicePathToTextLibConstructor (
    173   IN EFI_HANDLE        ImageHandle,
    174   IN EFI_SYSTEM_TABLE  *SystemTable
    175   )
    176 
    177 {
    178   DevPathToTextSetVendorDevicePathFilter (DevPathToTextVendorLib);
    179   DevicePathFromTextAddFilter (L"EmuThunk", DevPathFromTextEmuThunk);
    180   DevicePathFromTextAddFilter (L"EmuThread", DevPathFromTextEmuThread);
    181   DevicePathFromTextAddFilter (L"EmuFs", DevPathFromTextEmuFs);
    182   return EFI_SUCCESS;
    183 }