Home | History | Annotate | Download | only in WinNtGopDxe
      1 /** @file
      2 
      3 Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
      4 This program and the accompanying materials
      5 are licensed and made available under the terms and conditions of the BSD License
      6 which accompanies this distribution.  The full text of the license may be found at
      7 http://opensource.org/licenses/bsd-license.php
      8 
      9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     11 
     12 Module Name:
     13 
     14   ComponentName.c
     15 
     16 Abstract:
     17 
     18 
     19 **/
     20 
     21 //
     22 // The package level header files this module uses
     23 //
     24 #include <Uefi.h>
     25 #include <WinNtDxe.h>
     26 //
     27 // The protocols, PPI and GUID defintions for this module
     28 //
     29 #include <Guid/EventGroup.h>
     30 #include <Protocol/WinNtIo.h>
     31 #include <Protocol/ComponentName.h>
     32 #include <Protocol/SimpleTextIn.h>
     33 #include <Protocol/DriverBinding.h>
     34 #include <Protocol/GraphicsOutput.h>
     35 //
     36 // The Library classes this module consumes
     37 //
     38 #include <Library/DebugLib.h>
     39 #include <Library/BaseLib.h>
     40 #include <Library/UefiDriverEntryPoint.h>
     41 #include <Library/UefiLib.h>
     42 #include <Library/BaseMemoryLib.h>
     43 #include <Library/UefiBootServicesTableLib.h>
     44 #include <Library/MemoryAllocationLib.h>
     45 
     46 #include "WinNtGop.h"
     47 
     48 //
     49 // EFI Component Name Functions
     50 //
     51 /**
     52   Retrieves a Unicode string that is the user readable name of the driver.
     53 
     54   This function retrieves the user readable name of a driver in the form of a
     55   Unicode string. If the driver specified by This has a user readable name in
     56   the language specified by Language, then a pointer to the driver name is
     57   returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
     58   by This does not support the language specified by Language,
     59   then EFI_UNSUPPORTED is returned.
     60 
     61   @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
     62                                 EFI_COMPONENT_NAME_PROTOCOL instance.
     63 
     64   @param  Language[in]          A pointer to a Null-terminated ASCII string
     65                                 array indicating the language. This is the
     66                                 language of the driver name that the caller is
     67                                 requesting, and it must match one of the
     68                                 languages specified in SupportedLanguages. The
     69                                 number of languages supported by a driver is up
     70                                 to the driver writer. Language is specified
     71                                 in RFC 4646 or ISO 639-2 language code format.
     72 
     73   @param  DriverName[out]       A pointer to the Unicode string to return.
     74                                 This Unicode string is the name of the
     75                                 driver specified by This in the language
     76                                 specified by Language.
     77 
     78   @retval EFI_SUCCESS           The Unicode string for the Driver specified by
     79                                 This and the language specified by Language was
     80                                 returned in DriverName.
     81 
     82   @retval EFI_INVALID_PARAMETER Language is NULL.
     83 
     84   @retval EFI_INVALID_PARAMETER DriverName is NULL.
     85 
     86   @retval EFI_UNSUPPORTED       The driver specified by This does not support
     87                                 the language specified by Language.
     88 
     89 **/
     90 EFI_STATUS
     91 EFIAPI
     92 WinNtGopComponentNameGetDriverName (
     93   IN  EFI_COMPONENT_NAME_PROTOCOL  *This,
     94   IN  CHAR8                        *Language,
     95   OUT CHAR16                       **DriverName
     96   );
     97 
     98 
     99 /**
    100   Retrieves a Unicode string that is the user readable name of the controller
    101   that is being managed by a driver.
    102 
    103   This function retrieves the user readable name of the controller specified by
    104   ControllerHandle and ChildHandle in the form of a Unicode string. If the
    105   driver specified by This has a user readable name in the language specified by
    106   Language, then a pointer to the controller name is returned in ControllerName,
    107   and EFI_SUCCESS is returned.  If the driver specified by This is not currently
    108   managing the controller specified by ControllerHandle and ChildHandle,
    109   then EFI_UNSUPPORTED is returned.  If the driver specified by This does not
    110   support the language specified by Language, then EFI_UNSUPPORTED is returned.
    111 
    112   @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
    113                                 EFI_COMPONENT_NAME_PROTOCOL instance.
    114 
    115   @param  ControllerHandle[in]  The handle of a controller that the driver
    116                                 specified by This is managing.  This handle
    117                                 specifies the controller whose name is to be
    118                                 returned.
    119 
    120   @param  ChildHandle[in]       The handle of the child controller to retrieve
    121                                 the name of.  This is an optional parameter that
    122                                 may be NULL.  It will be NULL for device
    123                                 drivers.  It will also be NULL for a bus drivers
    124                                 that wish to retrieve the name of the bus
    125                                 controller.  It will not be NULL for a bus
    126                                 driver that wishes to retrieve the name of a
    127                                 child controller.
    128 
    129   @param  Language[in]          A pointer to a Null-terminated ASCII string
    130                                 array indicating the language.  This is the
    131                                 language of the driver name that the caller is
    132                                 requesting, and it must match one of the
    133                                 languages specified in SupportedLanguages. The
    134                                 number of languages supported by a driver is up
    135                                 to the driver writer. Language is specified in
    136                                 RFC 4646 or ISO 639-2 language code format.
    137 
    138   @param  ControllerName[out]   A pointer to the Unicode string to return.
    139                                 This Unicode string is the name of the
    140                                 controller specified by ControllerHandle and
    141                                 ChildHandle in the language specified by
    142                                 Language from the point of view of the driver
    143                                 specified by This.
    144 
    145   @retval EFI_SUCCESS           The Unicode string for the user readable name in
    146                                 the language specified by Language for the
    147                                 driver specified by This was returned in
    148                                 DriverName.
    149 
    150   @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
    151 
    152   @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
    153                                 EFI_HANDLE.
    154 
    155   @retval EFI_INVALID_PARAMETER Language is NULL.
    156 
    157   @retval EFI_INVALID_PARAMETER ControllerName is NULL.
    158 
    159   @retval EFI_UNSUPPORTED       The driver specified by This is not currently
    160                                 managing the controller specified by
    161                                 ControllerHandle and ChildHandle.
    162 
    163   @retval EFI_UNSUPPORTED       The driver specified by This does not support
    164                                 the language specified by Language.
    165 
    166 **/
    167 EFI_STATUS
    168 EFIAPI
    169 WinNtGopComponentNameGetControllerName (
    170   IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,
    171   IN  EFI_HANDLE                                      ControllerHandle,
    172   IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,
    173   IN  CHAR8                                           *Language,
    174   OUT CHAR16                                          **ControllerName
    175   );
    176 
    177 
    178 //
    179 // EFI Component Name Protocol
    180 //
    181 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL  gWinNtGopComponentName = {
    182   WinNtGopComponentNameGetDriverName,
    183   WinNtGopComponentNameGetControllerName,
    184   "eng"
    185 };
    186 
    187 //
    188 // EFI Component Name 2 Protocol
    189 //
    190 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gWinNtGopComponentName2 = {
    191   (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) WinNtGopComponentNameGetDriverName,
    192   (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) WinNtGopComponentNameGetControllerName,
    193   "en"
    194 };
    195 
    196 
    197 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mWinNtGopDriverNameTable[] = {
    198   { "eng;en", L"Windows GOP Driver" },
    199   { NULL , NULL }
    200 };
    201 
    202 
    203 /**
    204   Retrieves a Unicode string that is the user readable name of the driver.
    205 
    206   This function retrieves the user readable name of a driver in the form of a
    207   Unicode string. If the driver specified by This has a user readable name in
    208   the language specified by Language, then a pointer to the driver name is
    209   returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
    210   by This does not support the language specified by Language,
    211   then EFI_UNSUPPORTED is returned.
    212 
    213   @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
    214                                 EFI_COMPONENT_NAME_PROTOCOL instance.
    215 
    216   @param  Language[in]          A pointer to a Null-terminated ASCII string
    217                                 array indicating the language. This is the
    218                                 language of the driver name that the caller is
    219                                 requesting, and it must match one of the
    220                                 languages specified in SupportedLanguages. The
    221                                 number of languages supported by a driver is up
    222                                 to the driver writer. Language is specified
    223                                 in RFC 4646 or ISO 639-2 language code format.
    224 
    225   @param  DriverName[out]       A pointer to the Unicode string to return.
    226                                 This Unicode string is the name of the
    227                                 driver specified by This in the language
    228                                 specified by Language.
    229 
    230   @retval EFI_SUCCESS           The Unicode string for the Driver specified by
    231                                 This and the language specified by Language was
    232                                 returned in DriverName.
    233 
    234   @retval EFI_INVALID_PARAMETER Language is NULL.
    235 
    236   @retval EFI_INVALID_PARAMETER DriverName is NULL.
    237 
    238   @retval EFI_UNSUPPORTED       The driver specified by This does not support
    239                                 the language specified by Language.
    240 
    241 **/
    242 EFI_STATUS
    243 EFIAPI
    244 WinNtGopComponentNameGetDriverName (
    245   IN  EFI_COMPONENT_NAME_PROTOCOL  *This,
    246   IN  CHAR8                        *Language,
    247   OUT CHAR16                       **DriverName
    248   )
    249 {
    250   return LookupUnicodeString2 (
    251            Language,
    252            This->SupportedLanguages,
    253            mWinNtGopDriverNameTable,
    254            DriverName,
    255            (BOOLEAN)(This == &gWinNtGopComponentName)
    256            );
    257 }
    258 
    259 
    260 /**
    261   Retrieves a Unicode string that is the user readable name of the controller
    262   that is being managed by a driver.
    263 
    264   This function retrieves the user readable name of the controller specified by
    265   ControllerHandle and ChildHandle in the form of a Unicode string. If the
    266   driver specified by This has a user readable name in the language specified by
    267   Language, then a pointer to the controller name is returned in ControllerName,
    268   and EFI_SUCCESS is returned.  If the driver specified by This is not currently
    269   managing the controller specified by ControllerHandle and ChildHandle,
    270   then EFI_UNSUPPORTED is returned.  If the driver specified by This does not
    271   support the language specified by Language, then EFI_UNSUPPORTED is returned.
    272 
    273   @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
    274                                 EFI_COMPONENT_NAME_PROTOCOL instance.
    275 
    276   @param  ControllerHandle[in]  The handle of a controller that the driver
    277                                 specified by This is managing.  This handle
    278                                 specifies the controller whose name is to be
    279                                 returned.
    280 
    281   @param  ChildHandle[in]       The handle of the child controller to retrieve
    282                                 the name of.  This is an optional parameter that
    283                                 may be NULL.  It will be NULL for device
    284                                 drivers.  It will also be NULL for a bus drivers
    285                                 that wish to retrieve the name of the bus
    286                                 controller.  It will not be NULL for a bus
    287                                 driver that wishes to retrieve the name of a
    288                                 child controller.
    289 
    290   @param  Language[in]          A pointer to a Null-terminated ASCII string
    291                                 array indicating the language.  This is the
    292                                 language of the driver name that the caller is
    293                                 requesting, and it must match one of the
    294                                 languages specified in SupportedLanguages. The
    295                                 number of languages supported by a driver is up
    296                                 to the driver writer. Language is specified in
    297                                 RFC 4646 or ISO 639-2 language code format.
    298 
    299   @param  ControllerName[out]   A pointer to the Unicode string to return.
    300                                 This Unicode string is the name of the
    301                                 controller specified by ControllerHandle and
    302                                 ChildHandle in the language specified by
    303                                 Language from the point of view of the driver
    304                                 specified by This.
    305 
    306   @retval EFI_SUCCESS           The Unicode string for the user readable name in
    307                                 the language specified by Language for the
    308                                 driver specified by This was returned in
    309                                 DriverName.
    310 
    311   @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
    312 
    313   @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
    314                                 EFI_HANDLE.
    315 
    316   @retval EFI_INVALID_PARAMETER Language is NULL.
    317 
    318   @retval EFI_INVALID_PARAMETER ControllerName is NULL.
    319 
    320   @retval EFI_UNSUPPORTED       The driver specified by This is not currently
    321                                 managing the controller specified by
    322                                 ControllerHandle and ChildHandle.
    323 
    324   @retval EFI_UNSUPPORTED       The driver specified by This does not support
    325                                 the language specified by Language.
    326 
    327 **/
    328 EFI_STATUS
    329 EFIAPI
    330 WinNtGopComponentNameGetControllerName (
    331   IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,
    332   IN  EFI_HANDLE                                      ControllerHandle,
    333   IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,
    334   IN  CHAR8                                           *Language,
    335   OUT CHAR16                                          **ControllerName
    336   )
    337 {
    338   EFI_STATUS                   Status;
    339   EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
    340   GOP_PRIVATE_DATA             *Private;
    341 
    342   //
    343   // This is a device driver, so ChildHandle must be NULL.
    344   //
    345   if (ChildHandle != NULL) {
    346     return EFI_UNSUPPORTED;
    347   }
    348   //
    349   // Make sure this driver is currently managing ControllerHandle
    350   //
    351   Status = EfiTestManagedDevice (
    352              ControllerHandle,
    353              gWinNtGopDriverBinding.DriverBindingHandle,
    354              &gEfiWinNtIoProtocolGuid
    355              );
    356   if (EFI_ERROR (Status)) {
    357     return EFI_UNSUPPORTED;
    358   }
    359   //
    360   // Get our context back
    361   //
    362   Status = gBS->OpenProtocol (
    363                   ControllerHandle,
    364                   &gEfiGraphicsOutputProtocolGuid,
    365                   (VOID **) &GraphicsOutput,
    366                   gWinNtGopDriverBinding.DriverBindingHandle,
    367                   ControllerHandle,
    368                   EFI_OPEN_PROTOCOL_GET_PROTOCOL
    369                   );
    370   if (EFI_ERROR (Status)) {
    371     return EFI_UNSUPPORTED;
    372   }
    373 
    374   Private = GOP_PRIVATE_DATA_FROM_THIS (GraphicsOutput);
    375 
    376   return LookupUnicodeString2 (
    377            Language,
    378            This->SupportedLanguages,
    379            Private->ControllerNameTable,
    380            ControllerName,
    381            (BOOLEAN)(This == &gWinNtGopComponentName)
    382            );
    383 }
    384