1 /** @file
2   UEFI Component Name(2) protocol implementation for SCSI disk driver.
3 
4 Copyright (c) 2004 - 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 
16 #include "ScsiDisk.h"
17 
18 //
19 // EFI Component Name Protocol
20 //
21 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL  gScsiDiskComponentName = {
22   ScsiDiskComponentNameGetDriverName,
23   ScsiDiskComponentNameGetControllerName,
24   "eng"
25 };
26 
27 //
28 // EFI Component Name 2 Protocol
29 //
30 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gScsiDiskComponentName2 = {
31   (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) ScsiDiskComponentNameGetDriverName,
32   (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) ScsiDiskComponentNameGetControllerName,
33   "en"
34 };
35 
36 
37 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mScsiDiskDriverNameTable[] = {
38   { "eng;en", (CHAR16 *) L"Scsi Disk 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                  A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
53                                 EFI_COMPONENT_NAME_PROTOCOL instance.
54 
55   @param  Language              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            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
ScsiDiskComponentNameGetDriverName(IN EFI_COMPONENT_NAME_PROTOCOL * This,IN CHAR8 * Language,OUT CHAR16 ** DriverName)83 ScsiDiskComponentNameGetDriverName (
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            mScsiDiskDriverNameTable,
93            DriverName,
94            (BOOLEAN)(This == &gScsiDiskComponentName)
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                  A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
112                                 EFI_COMPONENT_NAME_PROTOCOL instance.
113 
114   @param  ControllerHandle      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           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              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        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 NULL.
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
ScsiDiskComponentNameGetControllerName(IN EFI_COMPONENT_NAME_PROTOCOL * This,IN EFI_HANDLE ControllerHandle,IN EFI_HANDLE ChildHandle OPTIONAL,IN CHAR8 * Language,OUT CHAR16 ** ControllerName)168 ScsiDiskComponentNameGetControllerName (
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   SCSI_DISK_DEV         *ScsiDiskDevice;
178   EFI_BLOCK_IO_PROTOCOL *BlockIo;
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              gScsiDiskDriverBinding.DriverBindingHandle,
193              &gEfiScsiIoProtocolGuid
194              );
195   if (EFI_ERROR (Status)) {
196     return Status;
197   }
198   //
199   // Get the device context
200   //
201   Status = gBS->OpenProtocol (
202                   ControllerHandle,
203                   &gEfiBlockIoProtocolGuid,
204                   (VOID **) &BlockIo,
205                   gScsiDiskDriverBinding.DriverBindingHandle,
206                   ControllerHandle,
207                   EFI_OPEN_PROTOCOL_GET_PROTOCOL
208                   );
209 
210   if (EFI_ERROR (Status)) {
211     return Status;
212   }
213 
214   ScsiDiskDevice = SCSI_DISK_DEV_FROM_BLKIO (BlockIo);
215 
216   return LookupUnicodeString2 (
217            Language,
218            This->SupportedLanguages,
219            ScsiDiskDevice->ControllerNameTable,
220            ControllerName,
221            (BOOLEAN)(This == &gScsiDiskComponentName)
222            );
223 
224 }
225