Home | History | Annotate | Download | only in EmuGopDxe
      1 /** @file
      2 
      3 Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
      4 Portions copyright (c) 2010,Apple Inc. 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 Module Name:
     14 
     15   ComponentName.c
     16 
     17 Abstract:
     18 
     19 **/
     20 
     21 #include "Gop.h"
     22 
     23 //
     24 // EFI Component Name Functions
     25 //
     26 EFI_STATUS
     27 EFIAPI
     28 EmuGopComponentNameGetDriverName (
     29   IN  EFI_COMPONENT_NAME_PROTOCOL  *This,
     30   IN  CHAR8                        *Language,
     31   OUT CHAR16                       **DriverName
     32   );
     33 
     34 EFI_STATUS
     35 EFIAPI
     36 EmuGopComponentNameGetControllerName (
     37   IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,
     38   IN  EFI_HANDLE                                      ControllerHandle,
     39   IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,
     40   IN  CHAR8                                           *Language,
     41   OUT CHAR16                                          **ControllerName
     42   );
     43 
     44 //
     45 // EFI Component Name Protocol
     46 //
     47 EFI_COMPONENT_NAME_PROTOCOL     gEmuGopComponentName = {
     48   EmuGopComponentNameGetDriverName,
     49   EmuGopComponentNameGetControllerName,
     50   "eng"
     51 };
     52 
     53 //
     54 // EFI Component Name 2 Protocol
     55 //
     56 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gEmuGopComponentName2 = {
     57   (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) EmuGopComponentNameGetDriverName,
     58   (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) EmuGopComponentNameGetControllerName,
     59   "en"
     60 };
     61 
     62 
     63 EFI_UNICODE_STRING_TABLE mEmuGopDriverNameTable[] = {
     64   { "eng", L"Emulator GOP Driver" },
     65   { NULL , NULL }
     66 };
     67 
     68 
     69 /**
     70   Retrieves a Unicode string that is the user readable name of the driver.
     71 
     72   This function retrieves the user readable name of a driver in the form of a
     73   Unicode string. If the driver specified by This has a user readable name in
     74   the language specified by Language, then a pointer to the driver name is
     75   returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
     76   by This does not support the language specified by Language,
     77   then EFI_UNSUPPORTED is returned.
     78 
     79   @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
     80                                 EFI_COMPONENT_NAME_PROTOCOL instance.
     81 
     82   @param  Language[in]          A pointer to a Null-terminated ASCII string
     83                                 array indicating the language. This is the
     84                                 language of the driver name that the caller is
     85                                 requesting, and it must match one of the
     86                                 languages specified in SupportedLanguages. The
     87                                 number of languages supported by a driver is up
     88                                 to the driver writer. Language is specified
     89                                 in RFC 4646 or ISO 639-2 language code format.
     90 
     91   @param  DriverName[out]       A pointer to the Unicode string to return.
     92                                 This Unicode string is the name of the
     93                                 driver specified by This in the language
     94                                 specified by Language.
     95 
     96   @retval EFI_SUCCESS           The Unicode string for the Driver specified by
     97                                 This and the language specified by Language was
     98                                 returned in DriverName.
     99 
    100   @retval EFI_INVALID_PARAMETER Language is NULL.
    101 
    102   @retval EFI_INVALID_PARAMETER DriverName is NULL.
    103 
    104   @retval EFI_UNSUPPORTED       The driver specified by This does not support
    105                                 the language specified by Language.
    106 
    107 **/
    108 EFI_STATUS
    109 EFIAPI
    110 EmuGopComponentNameGetDriverName (
    111   IN  EFI_COMPONENT_NAME_PROTOCOL  *This,
    112   IN  CHAR8                        *Language,
    113   OUT CHAR16                       **DriverName
    114   )
    115 {
    116   return LookupUnicodeString2 (
    117            Language,
    118            This->SupportedLanguages,
    119            mEmuGopDriverNameTable,
    120            DriverName,
    121            (BOOLEAN)(This == &gEmuGopComponentName)
    122            );
    123 }
    124 
    125 
    126 /**
    127   Retrieves a Unicode string that is the user readable name of the controller
    128   that is being managed by a driver.
    129 
    130   This function retrieves the user readable name of the controller specified by
    131   ControllerHandle and ChildHandle in the form of a Unicode string. If the
    132   driver specified by This has a user readable name in the language specified by
    133   Language, then a pointer to the controller name is returned in ControllerName,
    134   and EFI_SUCCESS is returned.  If the driver specified by This is not currently
    135   managing the controller specified by ControllerHandle and ChildHandle,
    136   then EFI_UNSUPPORTED is returned.  If the driver specified by This does not
    137   support the language specified by Language, then EFI_UNSUPPORTED is returned.
    138 
    139   @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
    140                                 EFI_COMPONENT_NAME_PROTOCOL instance.
    141 
    142   @param  ControllerHandle[in]  The handle of a controller that the driver
    143                                 specified by This is managing.  This handle
    144                                 specifies the controller whose name is to be
    145                                 returned.
    146 
    147   @param  ChildHandle[in]       The handle of the child controller to retrieve
    148                                 the name of.  This is an optional parameter that
    149                                 may be NULL.  It will be NULL for device
    150                                 drivers.  It will also be NULL for a bus drivers
    151                                 that wish to retrieve the name of the bus
    152                                 controller.  It will not be NULL for a bus
    153                                 driver that wishes to retrieve the name of a
    154                                 child controller.
    155 
    156   @param  Language[in]          A pointer to a Null-terminated ASCII string
    157                                 array indicating the language.  This is the
    158                                 language of the driver name that the caller is
    159                                 requesting, and it must match one of the
    160                                 languages specified in SupportedLanguages. The
    161                                 number of languages supported by a driver is up
    162                                 to the driver writer. Language is specified in
    163                                 RFC 4646 or ISO 639-2 language code format.
    164 
    165   @param  ControllerName[out]   A pointer to the Unicode string to return.
    166                                 This Unicode string is the name of the
    167                                 controller specified by ControllerHandle and
    168                                 ChildHandle in the language specified by
    169                                 Language from the point of view of the driver
    170                                 specified by This.
    171 
    172   @retval EFI_SUCCESS           The Unicode string for the user readable name in
    173                                 the language specified by Language for the
    174                                 driver specified by This was returned in
    175                                 DriverName.
    176 
    177   @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
    178 
    179   @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
    180                                 EFI_HANDLE.
    181 
    182   @retval EFI_INVALID_PARAMETER Language is NULL.
    183 
    184   @retval EFI_INVALID_PARAMETER ControllerName is NULL.
    185 
    186   @retval EFI_UNSUPPORTED       The driver specified by This is not currently
    187                                 managing the controller specified by
    188                                 ControllerHandle and ChildHandle.
    189 
    190   @retval EFI_UNSUPPORTED       The driver specified by This does not support
    191                                 the language specified by Language.
    192 
    193 **/
    194 EFI_STATUS
    195 EFIAPI
    196 EmuGopComponentNameGetControllerName (
    197   IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,
    198   IN  EFI_HANDLE                                      ControllerHandle,
    199   IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,
    200   IN  CHAR8                                           *Language,
    201   OUT CHAR16                                          **ControllerName
    202   )
    203 {
    204   EFI_STATUS                    Status;
    205   EFI_GRAPHICS_OUTPUT_PROTOCOL  *GraphicsOutput;
    206   GOP_PRIVATE_DATA              *Private;
    207 
    208   //
    209   // This is a device driver, so ChildHandle must be NULL.
    210   //
    211   if (ChildHandle != NULL) {
    212     return EFI_UNSUPPORTED;
    213   }
    214 
    215   //
    216   // Make sure this driver is currently managing ControllerHandle
    217   //
    218   Status = EfiTestManagedDevice (
    219              ControllerHandle,
    220              gEmuGopDriverBinding.DriverBindingHandle,
    221              &gEmuIoThunkProtocolGuid
    222              );
    223   if (EFI_ERROR (Status)) {
    224     return EFI_UNSUPPORTED;
    225   }
    226   //
    227   // Get our context back
    228   //
    229   Status = gBS->OpenProtocol (
    230                   ControllerHandle,
    231                   &gEfiGraphicsOutputProtocolGuid,
    232                   (VOID **)&GraphicsOutput,
    233                   gEmuGopDriverBinding.DriverBindingHandle,
    234                   ControllerHandle,
    235                   EFI_OPEN_PROTOCOL_GET_PROTOCOL
    236                   );
    237   if (EFI_ERROR (Status)) {
    238     return EFI_UNSUPPORTED;
    239   }
    240 
    241   Private = GOP_PRIVATE_DATA_FROM_THIS (GraphicsOutput);
    242 
    243   return LookupUnicodeString2 (
    244            Language,
    245            This->SupportedLanguages,
    246            Private->ControllerNameTable,
    247            ControllerName,
    248            (BOOLEAN)(This == &gEmuGopComponentName)
    249            );
    250 }
    251