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