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