Home | History | Annotate | Download | only in XhciDxe
      1 /** @file
      2   UEFI Component Name(2) protocol implementation for XHCI driver.
      3 
      4 Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
      5 
      6 This program and the accompanying materials
      7 are licensed and made available under the terms and conditions
      8 of the BSD License which accompanies this distribution.  The
      9 full text of the license may be found at
     10 http://opensource.org/licenses/bsd-license.php
     11 
     12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     14 
     15 **/
     16 
     17 #include "Xhci.h"
     18 
     19 //
     20 // EFI Component Name Protocol
     21 //
     22 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL  gXhciComponentName = {
     23   XhciComponentNameGetDriverName,
     24   XhciComponentNameGetControllerName,
     25   "eng"
     26 };
     27 
     28 //
     29 // EFI Component Name 2 Protocol
     30 //
     31 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gXhciComponentName2 = {
     32   (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) XhciComponentNameGetDriverName,
     33   (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) XhciComponentNameGetControllerName,
     34   "en"
     35 };
     36 
     37 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mXhciDriverNameTable[] = {
     38   { "eng;en", L"Usb Xhci Driver" },
     39   { NULL , NULL }
     40 };
     41 
     42 /**
     43   Retrieves a Unicode string that is the user readable name of the driver.
     44 
     45   This function retrieves the user readable name of a driver in the form of a
     46   Unicode string. If the driver specified by This has a user readable name in
     47   the language specified by Language, then a pointer to the driver name is
     48   returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
     49   by This does not support the language specified by Language,
     50   then EFI_UNSUPPORTED is returned.
     51 
     52   @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
     53                                 EFI_COMPONENT_NAME_PROTOCOL instance.
     54 
     55   @param  Language[in]          A pointer to a Null-terminated ASCII string
     56                                 array indicating the language. This is the
     57                                 language of the driver name that the caller is
     58                                 requesting, and it must match one of the
     59                                 languages specified in SupportedLanguages. The
     60                                 number of languages supported by a driver is up
     61                                 to the driver writer. Language is specified
     62                                 in RFC 4646 or ISO 639-2 language code format.
     63 
     64   @param  DriverName[out]       A pointer to the Unicode string to return.
     65                                 This Unicode string is the name of the
     66                                 driver specified by This in the language
     67                                 specified by Language.
     68 
     69   @retval EFI_SUCCESS           The Unicode string for the Driver specified by
     70                                 This and the language specified by Language was
     71                                 returned in DriverName.
     72 
     73   @retval EFI_INVALID_PARAMETER Language is NULL.
     74 
     75   @retval EFI_INVALID_PARAMETER DriverName is NULL.
     76 
     77   @retval EFI_UNSUPPORTED       The driver specified by This does not support
     78                                 the language specified by Language.
     79 
     80 **/
     81 EFI_STATUS
     82 EFIAPI
     83 XhciComponentNameGetDriverName (
     84   IN  EFI_COMPONENT_NAME_PROTOCOL  *This,
     85   IN  CHAR8                        *Language,
     86   OUT CHAR16                       **DriverName
     87   )
     88 {
     89   return LookupUnicodeString2 (
     90            Language,
     91            This->SupportedLanguages,
     92            mXhciDriverNameTable,
     93            DriverName,
     94            (BOOLEAN)(This == &gXhciComponentName)
     95            );
     96 }
     97 
     98 /**
     99   Retrieves a Unicode string that is the user readable name of the controller
    100   that is being managed by a driver.
    101 
    102   This function retrieves the user readable name of the controller specified by
    103   ControllerHandle and ChildHandle in the form of a Unicode string. If the
    104   driver specified by This has a user readable name in the language specified by
    105   Language, then a pointer to the controller name is returned in ControllerName,
    106   and EFI_SUCCESS is returned.  If the driver specified by This is not currently
    107   managing the controller specified by ControllerHandle and ChildHandle,
    108   then EFI_UNSUPPORTED is returned.  If the driver specified by This does not
    109   support the language specified by Language, then EFI_UNSUPPORTED is returned.
    110 
    111   @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
    112                                 EFI_COMPONENT_NAME_PROTOCOL instance.
    113 
    114   @param  ControllerHandle[in]  The handle of a controller that the driver
    115                                 specified by This is managing.  This handle
    116                                 specifies the controller whose name is to be
    117                                 returned.
    118 
    119   @param  ChildHandle[in]       The handle of the child controller to retrieve
    120                                 the name of.  This is an optional parameter that
    121                                 may be NULL.  It will be NULL for device
    122                                 drivers.  It will also be NULL for a bus drivers
    123                                 that wish to retrieve the name of the bus
    124                                 controller.  It will not be NULL for a bus
    125                                 driver that wishes to retrieve the name of a
    126                                 child controller.
    127 
    128   @param  Language[in]          A pointer to a Null-terminated ASCII string
    129                                 array indicating the language.  This is the
    130                                 language of the driver name that the caller is
    131                                 requesting, and it must match one of the
    132                                 languages specified in SupportedLanguages. The
    133                                 number of languages supported by a driver is up
    134                                 to the driver writer. Language is specified in
    135                                 RFC 4646 or ISO 639-2 language code format.
    136 
    137   @param  ControllerName[out]   A pointer to the Unicode string to return.
    138                                 This Unicode string is the name of the
    139                                 controller specified by ControllerHandle and
    140                                 ChildHandle in the language specified by
    141                                 Language from the point of view of the driver
    142                                 specified by This.
    143 
    144   @retval EFI_SUCCESS           The Unicode string for the user readable name in
    145                                 the language specified by Language for the
    146                                 driver specified by This was returned in
    147                                 DriverName.
    148 
    149   @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
    150 
    151   @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
    152                                 EFI_HANDLE.
    153 
    154   @retval EFI_INVALID_PARAMETER Language is NULL.
    155 
    156   @retval EFI_INVALID_PARAMETER ControllerName is NULL.
    157 
    158   @retval EFI_UNSUPPORTED       The driver specified by This is not currently
    159                                 managing the controller specified by
    160                                 ControllerHandle and ChildHandle.
    161 
    162   @retval EFI_UNSUPPORTED       The driver specified by This does not support
    163                                 the language specified by Language.
    164 
    165 **/
    166 EFI_STATUS
    167 EFIAPI
    168 XhciComponentNameGetControllerName (
    169   IN  EFI_COMPONENT_NAME_PROTOCOL  *This,
    170   IN  EFI_HANDLE                   ControllerHandle,
    171   IN  EFI_HANDLE                   ChildHandle OPTIONAL,
    172   IN  CHAR8                        *Language,
    173   OUT CHAR16                       **ControllerName
    174   )
    175 {
    176   EFI_STATUS           Status;
    177   EFI_USB2_HC_PROTOCOL *Usb2Hc;
    178   USB_XHCI_INSTANCE    *XhciDev;
    179 
    180   //
    181   // This is a device driver, so ChildHandle must be NULL.
    182   //
    183   if (ChildHandle != NULL) {
    184     return EFI_UNSUPPORTED;
    185   }
    186 
    187   //
    188   // Make sure this driver is currently managing ControllerHandle
    189   //
    190   Status = EfiTestManagedDevice (
    191              ControllerHandle,
    192              gXhciDriverBinding.DriverBindingHandle,
    193              &gEfiPciIoProtocolGuid
    194              );
    195   if (EFI_ERROR (Status)) {
    196     return Status;
    197   }
    198 
    199   //
    200   // Get the device context
    201   //
    202   Status = gBS->OpenProtocol (
    203                   ControllerHandle,
    204                   &gEfiUsb2HcProtocolGuid,
    205                   (VOID **) &Usb2Hc,
    206                   gXhciDriverBinding.DriverBindingHandle,
    207                   ControllerHandle,
    208                   EFI_OPEN_PROTOCOL_GET_PROTOCOL
    209                   );
    210   if (EFI_ERROR (Status)) {
    211     return Status;
    212   }
    213 
    214   XhciDev = XHC_FROM_THIS (Usb2Hc);
    215 
    216   return LookupUnicodeString2 (
    217            Language,
    218            This->SupportedLanguages,
    219            XhciDev->ControllerNameTable,
    220            ControllerName,
    221            (BOOLEAN)(This == &gXhciComponentName)
    222            );
    223 
    224 }
    225