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