• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**@file
2 
3 Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution.  The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8 
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11 
12 Module Name:
13 
14   ComponentName.c
15 
16 Abstract:
17 
18 **/
19 #include <Uefi.h>
20 #include <WinNtDxe.h>
21 #include <Protocol/ComponentName.h>
22 #include <Protocol/DriverBinding.h>
23 
24 #include "WinNtBlockIo.h"
25 
26 //
27 // EFI Component Name Functions
28 //
29 /**
30   Retrieves a Unicode string that is the user readable name of the driver.
31 
32   This function retrieves the user readable name of a driver in the form of a
33   Unicode string. If the driver specified by This has a user readable name in
34   the language specified by Language, then a pointer to the driver name is
35   returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
36   by This does not support the language specified by Language,
37   then EFI_UNSUPPORTED is returned.
38 
39   @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
40                                 EFI_COMPONENT_NAME_PROTOCOL instance.
41 
42   @param  Language[in]          A pointer to a Null-terminated ASCII string
43                                 array indicating the language. This is the
44                                 language of the driver name that the caller is
45                                 requesting, and it must match one of the
46                                 languages specified in SupportedLanguages. The
47                                 number of languages supported by a driver is up
48                                 to the driver writer. Language is specified
49                                 in RFC 4646 or ISO 639-2 language code format.
50 
51   @param  DriverName[out]       A pointer to the Unicode string to return.
52                                 This Unicode string is the name of the
53                                 driver specified by This in the language
54                                 specified by Language.
55 
56   @retval EFI_SUCCESS           The Unicode string for the Driver specified by
57                                 This and the language specified by Language was
58                                 returned in DriverName.
59 
60   @retval EFI_INVALID_PARAMETER Language is NULL.
61 
62   @retval EFI_INVALID_PARAMETER DriverName is NULL.
63 
64   @retval EFI_UNSUPPORTED       The driver specified by This does not support
65                                 the language specified by Language.
66 
67 **/
68 EFI_STATUS
69 EFIAPI
70 WinNtBlockIoComponentNameGetDriverName (
71   IN  EFI_COMPONENT_NAME_PROTOCOL  *This,
72   IN  CHAR8                        *Language,
73   OUT CHAR16                       **DriverName
74   );
75 
76 
77 /**
78   Retrieves a Unicode string that is the user readable name of the controller
79   that is being managed by a driver.
80 
81   This function retrieves the user readable name of the controller specified by
82   ControllerHandle and ChildHandle in the form of a Unicode string. If the
83   driver specified by This has a user readable name in the language specified by
84   Language, then a pointer to the controller name is returned in ControllerName,
85   and EFI_SUCCESS is returned.  If the driver specified by This is not currently
86   managing the controller specified by ControllerHandle and ChildHandle,
87   then EFI_UNSUPPORTED is returned.  If the driver specified by This does not
88   support the language specified by Language, then EFI_UNSUPPORTED is returned.
89 
90   @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
91                                 EFI_COMPONENT_NAME_PROTOCOL instance.
92 
93   @param  ControllerHandle[in]  The handle of a controller that the driver
94                                 specified by This is managing.  This handle
95                                 specifies the controller whose name is to be
96                                 returned.
97 
98   @param  ChildHandle[in]       The handle of the child controller to retrieve
99                                 the name of.  This is an optional parameter that
100                                 may be NULL.  It will be NULL for device
101                                 drivers.  It will also be NULL for a bus drivers
102                                 that wish to retrieve the name of the bus
103                                 controller.  It will not be NULL for a bus
104                                 driver that wishes to retrieve the name of a
105                                 child controller.
106 
107   @param  Language[in]          A pointer to a Null-terminated ASCII string
108                                 array indicating the language.  This is the
109                                 language of the driver name that the caller is
110                                 requesting, and it must match one of the
111                                 languages specified in SupportedLanguages. The
112                                 number of languages supported by a driver is up
113                                 to the driver writer. Language is specified in
114                                 RFC 4646 or ISO 639-2 language code format.
115 
116   @param  ControllerName[out]   A pointer to the Unicode string to return.
117                                 This Unicode string is the name of the
118                                 controller specified by ControllerHandle and
119                                 ChildHandle in the language specified by
120                                 Language from the point of view of the driver
121                                 specified by This.
122 
123   @retval EFI_SUCCESS           The Unicode string for the user readable name in
124                                 the language specified by Language for the
125                                 driver specified by This was returned in
126                                 DriverName.
127 
128   @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
129 
130   @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
131                                 EFI_HANDLE.
132 
133   @retval EFI_INVALID_PARAMETER Language is NULL.
134 
135   @retval EFI_INVALID_PARAMETER ControllerName is NULL.
136 
137   @retval EFI_UNSUPPORTED       The driver specified by This is not currently
138                                 managing the controller specified by
139                                 ControllerHandle and ChildHandle.
140 
141   @retval EFI_UNSUPPORTED       The driver specified by This does not support
142                                 the language specified by Language.
143 
144 **/
145 EFI_STATUS
146 EFIAPI
147 WinNtBlockIoComponentNameGetControllerName (
148   IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,
149   IN  EFI_HANDLE                                      ControllerHandle,
150   IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,
151   IN  CHAR8                                           *Language,
152   OUT CHAR16                                          **ControllerName
153   );
154 
155 
156 //
157 // EFI Component Name Protocol
158 //
159 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL  gWinNtBlockIoComponentName = {
160   WinNtBlockIoComponentNameGetDriverName,
161   WinNtBlockIoComponentNameGetControllerName,
162   "eng"
163 };
164 
165 //
166 // EFI Component Name 2 Protocol
167 //
168 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gWinNtBlockIoComponentName2 = {
169   (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) WinNtBlockIoComponentNameGetDriverName,
170   (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) WinNtBlockIoComponentNameGetControllerName,
171   "en"
172 };
173 
174 
175 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mWinNtBlockIoDriverNameTable[] = {
176   { "eng;en", L"Windows Block I/O Driver" },
177   { NULL , NULL }
178 };
179 
180 /**
181   Retrieves a Unicode string that is the user readable name of the driver.
182 
183   This function retrieves the user readable name of a driver in the form of a
184   Unicode string. If the driver specified by This has a user readable name in
185   the language specified by Language, then a pointer to the driver name is
186   returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
187   by This does not support the language specified by Language,
188   then EFI_UNSUPPORTED is returned.
189 
190   @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
191                                 EFI_COMPONENT_NAME_PROTOCOL instance.
192 
193   @param  Language[in]          A pointer to a Null-terminated ASCII string
194                                 array indicating the language. This is the
195                                 language of the driver name that the caller is
196                                 requesting, and it must match one of the
197                                 languages specified in SupportedLanguages. The
198                                 number of languages supported by a driver is up
199                                 to the driver writer. Language is specified
200                                 in RFC 4646 or ISO 639-2 language code format.
201 
202   @param  DriverName[out]       A pointer to the Unicode string to return.
203                                 This Unicode string is the name of the
204                                 driver specified by This in the language
205                                 specified by Language.
206 
207   @retval EFI_SUCCESS           The Unicode string for the Driver specified by
208                                 This and the language specified by Language was
209                                 returned in DriverName.
210 
211   @retval EFI_INVALID_PARAMETER Language is NULL.
212 
213   @retval EFI_INVALID_PARAMETER DriverName is NULL.
214 
215   @retval EFI_UNSUPPORTED       The driver specified by This does not support
216                                 the language specified by Language.
217 
218 **/
219 EFI_STATUS
220 EFIAPI
WinNtBlockIoComponentNameGetDriverName(IN EFI_COMPONENT_NAME_PROTOCOL * This,IN CHAR8 * Language,OUT CHAR16 ** DriverName)221 WinNtBlockIoComponentNameGetDriverName (
222   IN  EFI_COMPONENT_NAME_PROTOCOL  *This,
223   IN  CHAR8                        *Language,
224   OUT CHAR16                       **DriverName
225   )
226 {
227   return LookupUnicodeString2 (
228            Language,
229            This->SupportedLanguages,
230            mWinNtBlockIoDriverNameTable,
231            DriverName,
232            (BOOLEAN)(This == &gWinNtBlockIoComponentName)
233            );
234 }
235 
236 /**
237   Retrieves a Unicode string that is the user readable name of the controller
238   that is being managed by a driver.
239 
240   This function retrieves the user readable name of the controller specified by
241   ControllerHandle and ChildHandle in the form of a Unicode string. If the
242   driver specified by This has a user readable name in the language specified by
243   Language, then a pointer to the controller name is returned in ControllerName,
244   and EFI_SUCCESS is returned.  If the driver specified by This is not currently
245   managing the controller specified by ControllerHandle and ChildHandle,
246   then EFI_UNSUPPORTED is returned.  If the driver specified by This does not
247   support the language specified by Language, then EFI_UNSUPPORTED is returned.
248 
249   @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
250                                 EFI_COMPONENT_NAME_PROTOCOL instance.
251 
252   @param  ControllerHandle[in]  The handle of a controller that the driver
253                                 specified by This is managing.  This handle
254                                 specifies the controller whose name is to be
255                                 returned.
256 
257   @param  ChildHandle[in]       The handle of the child controller to retrieve
258                                 the name of.  This is an optional parameter that
259                                 may be NULL.  It will be NULL for device
260                                 drivers.  It will also be NULL for a bus drivers
261                                 that wish to retrieve the name of the bus
262                                 controller.  It will not be NULL for a bus
263                                 driver that wishes to retrieve the name of a
264                                 child controller.
265 
266   @param  Language[in]          A pointer to a Null-terminated ASCII string
267                                 array indicating the language.  This is the
268                                 language of the driver name that the caller is
269                                 requesting, and it must match one of the
270                                 languages specified in SupportedLanguages. The
271                                 number of languages supported by a driver is up
272                                 to the driver writer. Language is specified in
273                                 RFC 4646 or ISO 639-2 language code format.
274 
275   @param  ControllerName[out]   A pointer to the Unicode string to return.
276                                 This Unicode string is the name of the
277                                 controller specified by ControllerHandle and
278                                 ChildHandle in the language specified by
279                                 Language from the point of view of the driver
280                                 specified by This.
281 
282   @retval EFI_SUCCESS           The Unicode string for the user readable name in
283                                 the language specified by Language for the
284                                 driver specified by This was returned in
285                                 DriverName.
286 
287   @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
288 
289   @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
290                                 EFI_HANDLE.
291 
292   @retval EFI_INVALID_PARAMETER Language is NULL.
293 
294   @retval EFI_INVALID_PARAMETER ControllerName is NULL.
295 
296   @retval EFI_UNSUPPORTED       The driver specified by This is not currently
297                                 managing the controller specified by
298                                 ControllerHandle and ChildHandle.
299 
300   @retval EFI_UNSUPPORTED       The driver specified by This does not support
301                                 the language specified by Language.
302 
303 **/
304 EFI_STATUS
305 EFIAPI
WinNtBlockIoComponentNameGetControllerName(IN EFI_COMPONENT_NAME_PROTOCOL * This,IN EFI_HANDLE ControllerHandle,IN EFI_HANDLE ChildHandle OPTIONAL,IN CHAR8 * Language,OUT CHAR16 ** ControllerName)306 WinNtBlockIoComponentNameGetControllerName (
307   IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,
308   IN  EFI_HANDLE                                      ControllerHandle,
309   IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,
310   IN  CHAR8                                           *Language,
311   OUT CHAR16                                          **ControllerName
312   )
313 {
314   EFI_STATUS              Status;
315   EFI_BLOCK_IO_PROTOCOL   *BlockIo;
316   WIN_NT_BLOCK_IO_PRIVATE *Private;
317 
318   //
319   // This is a device driver, so ChildHandle must be NULL.
320   //
321   if (ChildHandle != NULL) {
322     return EFI_UNSUPPORTED;
323   }
324   //
325   // Make sure this driver is currently managing ControllerHandle
326   //
327   Status = EfiTestManagedDevice (
328              ControllerHandle,
329              gWinNtBlockIoDriverBinding.DriverBindingHandle,
330              &gEfiWinNtIoProtocolGuid
331              );
332   if (EFI_ERROR (Status)) {
333     return EFI_UNSUPPORTED;
334   }
335   //
336   // Get our context back
337   //
338   Status = gBS->OpenProtocol (
339                   ControllerHandle,
340                   &gEfiBlockIoProtocolGuid,
341                   (VOID **) &BlockIo,
342                   gWinNtBlockIoDriverBinding.DriverBindingHandle,
343                   ControllerHandle,
344                   EFI_OPEN_PROTOCOL_GET_PROTOCOL
345                   );
346   if (EFI_ERROR (Status)) {
347     return EFI_UNSUPPORTED;
348   }
349 
350   Private = WIN_NT_BLOCK_IO_PRIVATE_DATA_FROM_THIS (BlockIo);
351 
352   return LookupUnicodeString2 (
353            Language,
354            This->SupportedLanguages,
355            Private->ControllerNameTable,
356            ControllerName,
357            (BOOLEAN)(This == &gWinNtBlockIoComponentName)
358            );
359 }
360