Home | History | Annotate | Download | only in IsaSerialDxe
      1 /** @file
      2   UEFI Component Name and Name2 protocol for Isa serial driver.
      3 
      4 Copyright (c) 2006 - 2015, 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 "Serial.h"
     16 
     17 //
     18 // EFI Component Name Protocol
     19 //
     20 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL  gIsaSerialComponentName = {
     21   IsaSerialComponentNameGetDriverName,
     22   IsaSerialComponentNameGetControllerName,
     23   "eng"
     24 };
     25 
     26 //
     27 // EFI Component Name 2 Protocol
     28 //
     29 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gIsaSerialComponentName2 = {
     30   (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) IsaSerialComponentNameGetDriverName,
     31   (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) IsaSerialComponentNameGetControllerName,
     32   "en"
     33 };
     34 
     35 
     36 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mIsaSerialDriverNameTable[] = {
     37   {
     38     "eng;en",
     39     L"ISA Serial Driver"
     40   },
     41   {
     42     NULL,
     43     NULL
     44   }
     45 };
     46 
     47 GLOBAL_REMOVE_IF_UNREFERENCED CHAR16 mSerialPortName[] = L"ISA Serial Port # ";
     48 
     49 /**
     50   Retrieves a Unicode string that is the user readable name of the driver.
     51 
     52   This function retrieves the user readable name of a driver in the form of a
     53   Unicode string. If the driver specified by This has a user readable name in
     54   the language specified by Language, then a pointer to the driver name is
     55   returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
     56   by This does not support the language specified by Language,
     57   then EFI_UNSUPPORTED is returned.
     58 
     59   @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
     60                                 EFI_COMPONENT_NAME_PROTOCOL instance.
     61 
     62   @param  Language[in]          A pointer to a Null-terminated ASCII string
     63                                 array indicating the language. This is the
     64                                 language of the driver name that the caller is
     65                                 requesting, and it must match one of the
     66                                 languages specified in SupportedLanguages. The
     67                                 number of languages supported by a driver is up
     68                                 to the driver writer. Language is specified
     69                                 in RFC 4646 or ISO 639-2 language code format.
     70 
     71   @param  DriverName[out]       A pointer to the Unicode string to return.
     72                                 This Unicode string is the name of the
     73                                 driver specified by This in the language
     74                                 specified by Language.
     75 
     76   @retval EFI_SUCCESS           The Unicode string for the Driver specified by
     77                                 This and the language specified by Language was
     78                                 returned in DriverName.
     79 
     80   @retval EFI_INVALID_PARAMETER Language is NULL.
     81 
     82   @retval EFI_INVALID_PARAMETER DriverName is NULL.
     83 
     84   @retval EFI_UNSUPPORTED       The driver specified by This does not support
     85                                 the language specified by Language.
     86 
     87 **/
     88 EFI_STATUS
     89 EFIAPI
     90 IsaSerialComponentNameGetDriverName (
     91   IN  EFI_COMPONENT_NAME_PROTOCOL  *This,
     92   IN  CHAR8                        *Language,
     93   OUT CHAR16                       **DriverName
     94   )
     95 {
     96   return LookupUnicodeString2 (
     97            Language,
     98            This->SupportedLanguages,
     99            mIsaSerialDriverNameTable,
    100            DriverName,
    101            (BOOLEAN)(This == &gIsaSerialComponentName)
    102            );
    103 }
    104 
    105 /**
    106   Retrieves a Unicode string that is the user readable name of the controller
    107   that is being managed by a driver.
    108 
    109   This function retrieves the user readable name of the controller specified by
    110   ControllerHandle and ChildHandle in the form of a Unicode string. If the
    111   driver specified by This has a user readable name in the language specified by
    112   Language, then a pointer to the controller name is returned in ControllerName,
    113   and EFI_SUCCESS is returned.  If the driver specified by This is not currently
    114   managing the controller specified by ControllerHandle and ChildHandle,
    115   then EFI_UNSUPPORTED is returned.  If the driver specified by This does not
    116   support the language specified by Language, then EFI_UNSUPPORTED is returned.
    117 
    118   @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
    119                                 EFI_COMPONENT_NAME_PROTOCOL instance.
    120 
    121   @param  ControllerHandle[in]  The handle of a controller that the driver
    122                                 specified by This is managing.  This handle
    123                                 specifies the controller whose name is to be
    124                                 returned.
    125 
    126   @param  ChildHandle[in]       The handle of the child controller to retrieve
    127                                 the name of.  This is an optional parameter that
    128                                 may be NULL.  It will be NULL for device
    129                                 drivers.  It will also be NULL for a bus drivers
    130                                 that wish to retrieve the name of the bus
    131                                 controller.  It will not be NULL for a bus
    132                                 driver that wishes to retrieve the name of a
    133                                 child controller.
    134 
    135   @param  Language[in]          A pointer to a Null-terminated ASCII string
    136                                 array indicating the language.  This is the
    137                                 language of the driver name that the caller is
    138                                 requesting, and it must match one of the
    139                                 languages specified in SupportedLanguages. The
    140                                 number of languages supported by a driver is up
    141                                 to the driver writer. Language is specified in
    142                                 RFC 4646 or ISO 639-2 language code format.
    143 
    144   @param  ControllerName[out]   A pointer to the Unicode string to return.
    145                                 This Unicode string is the name of the
    146                                 controller specified by ControllerHandle and
    147                                 ChildHandle in the language specified by
    148                                 Language from the point of view of the driver
    149                                 specified by This.
    150 
    151   @retval EFI_SUCCESS           The Unicode string for the user readable name in
    152                                 the language specified by Language for the
    153                                 driver specified by This was returned in
    154                                 DriverName.
    155 
    156   @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
    157 
    158   @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
    159                                 EFI_HANDLE.
    160 
    161   @retval EFI_INVALID_PARAMETER Language is NULL.
    162 
    163   @retval EFI_INVALID_PARAMETER ControllerName is NULL.
    164 
    165   @retval EFI_UNSUPPORTED       The driver specified by This is not currently
    166                                 managing the controller specified by
    167                                 ControllerHandle and ChildHandle.
    168 
    169   @retval EFI_UNSUPPORTED       The driver specified by This does not support
    170                                 the language specified by Language.
    171 
    172 **/
    173 EFI_STATUS
    174 EFIAPI
    175 IsaSerialComponentNameGetControllerName (
    176   IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,
    177   IN  EFI_HANDLE                                      ControllerHandle,
    178   IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,
    179   IN  CHAR8                                           *Language,
    180   OUT CHAR16                                          **ControllerName
    181   )
    182 {
    183   EFI_STATUS                Status;
    184   EFI_SERIAL_IO_PROTOCOL    *SerialIo;
    185   SERIAL_DEV                *SerialDevice;
    186   EFI_UNICODE_STRING_TABLE  *ControllerNameTable;
    187 
    188   //
    189   // Make sure this driver is currently managing ControllerHandle
    190   //
    191   Status = EfiTestManagedDevice (
    192              ControllerHandle,
    193              gSerialControllerDriver.DriverBindingHandle,
    194              &gEfiIsaIoProtocolGuid
    195              );
    196   if (EFI_ERROR (Status)) {
    197     return Status;
    198   }
    199 
    200   ControllerNameTable = NULL;
    201   if (ChildHandle != NULL) {
    202     Status = EfiTestChildHandle (
    203                ControllerHandle,
    204                ChildHandle,
    205                &gEfiIsaIoProtocolGuid
    206                );
    207     if (EFI_ERROR (Status)) {
    208       return Status;
    209     }
    210 
    211     //
    212     // Get the Serial I/O Protocol from the child handle
    213     //
    214     Status = gBS->OpenProtocol (
    215                     ChildHandle,
    216                     &gEfiSerialIoProtocolGuid,
    217                     (VOID **) &SerialIo,
    218                     gSerialControllerDriver.DriverBindingHandle,
    219                     ChildHandle,
    220                     EFI_OPEN_PROTOCOL_GET_PROTOCOL
    221                     );
    222     if (EFI_ERROR (Status)) {
    223       return Status;
    224     }
    225 
    226     //
    227     // Get the Serial Controller's Device structure
    228     //
    229     SerialDevice = SERIAL_DEV_FROM_THIS (SerialIo);
    230     ControllerNameTable = SerialDevice->ControllerNameTable;
    231   }
    232 
    233   return LookupUnicodeString2 (
    234            Language,
    235            This->SupportedLanguages,
    236            ControllerNameTable,
    237            ControllerName,
    238            (BOOLEAN)(This == &gIsaSerialComponentName)
    239            );
    240 }
    241 
    242 /**
    243   Add the ISO639-2 and RFC4646 component name both for the Serial IO device
    244 
    245   @param SerialDevice     A pointer to the SERIAL_DEV instance.
    246 
    247   @param IsaIo            A pointer to the EFI_ISA_IO_PROTOCOL instance.
    248 
    249 **/
    250 VOID
    251 AddName (
    252   IN  SERIAL_DEV                               *SerialDevice,
    253   IN  EFI_ISA_IO_PROTOCOL                      *IsaIo
    254   )
    255 {
    256   mSerialPortName[(sizeof (mSerialPortName) / 2) - 2] = (CHAR16) (L'0' + (UINT8) IsaIo->ResourceList->Device.UID);
    257   AddUnicodeString2 (
    258     "eng",
    259     gIsaSerialComponentName.SupportedLanguages,
    260     &SerialDevice->ControllerNameTable,
    261     mSerialPortName,
    262     TRUE
    263     );
    264   AddUnicodeString2 (
    265     "en",
    266     gIsaSerialComponentName2.SupportedLanguages,
    267     &SerialDevice->ControllerNameTable,
    268     mSerialPortName,
    269     FALSE
    270     );
    271 
    272 }
    273