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
20 //
21 // The package level header files this module uses
22 //
23 #include <Uefi.h>
24 #include <WinNtDxe.h>
25 //
26 // The protocols, PPI and GUID defintions for this module
27 //
28 #include <Protocol/WinNtThunk.h>
29 #include <Protocol/WinNtIo.h>
30 #include <Protocol/ComponentName.h>
31 #include <Protocol/DriverBinding.h>
32 #include <Protocol/DevicePath.h>
33
34
35 #include "WinNtBusDriver.h"
36
37 //
38 // EFI Component Name Functions
39 //
40 /**
41 Retrieves a Unicode string that is the user readable name of the driver.
42
43 This function retrieves the user readable name of a driver in the form of a
44 Unicode string. If the driver specified by This has a user readable name in
45 the language specified by Language, then a pointer to the driver name is
46 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
47 by This does not support the language specified by Language,
48 then EFI_UNSUPPORTED is returned.
49
50 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
51 EFI_COMPONENT_NAME_PROTOCOL instance.
52
53 @param Language[in] A pointer to a Null-terminated ASCII string
54 array indicating the language. This is the
55 language of the driver name that the caller is
56 requesting, and it must match one of the
57 languages specified in SupportedLanguages. The
58 number of languages supported by a driver is up
59 to the driver writer. Language is specified
60 in RFC 4646 or ISO 639-2 language code format.
61
62 @param DriverName[out] A pointer to the Unicode string to return.
63 This Unicode string is the name of the
64 driver specified by This in the language
65 specified by Language.
66
67 @retval EFI_SUCCESS The Unicode string for the Driver specified by
68 This and the language specified by Language was
69 returned in DriverName.
70
71 @retval EFI_INVALID_PARAMETER Language is NULL.
72
73 @retval EFI_INVALID_PARAMETER DriverName is NULL.
74
75 @retval EFI_UNSUPPORTED The driver specified by This does not support
76 the language specified by Language.
77
78 **/
79 EFI_STATUS
80 EFIAPI
81 WinNtBusDriverComponentNameGetDriverName (
82 IN EFI_COMPONENT_NAME_PROTOCOL *This,
83 IN CHAR8 *Language,
84 OUT CHAR16 **DriverName
85 );
86
87
88 /**
89 Retrieves a Unicode string that is the user readable name of the controller
90 that is being managed by a driver.
91
92 This function retrieves the user readable name of the controller specified by
93 ControllerHandle and ChildHandle in the form of a Unicode string. If the
94 driver specified by This has a user readable name in the language specified by
95 Language, then a pointer to the controller name is returned in ControllerName,
96 and EFI_SUCCESS is returned. If the driver specified by This is not currently
97 managing the controller specified by ControllerHandle and ChildHandle,
98 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
99 support the language specified by Language, then EFI_UNSUPPORTED is returned.
100
101 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
102 EFI_COMPONENT_NAME_PROTOCOL instance.
103
104 @param ControllerHandle[in] The handle of a controller that the driver
105 specified by This is managing. This handle
106 specifies the controller whose name is to be
107 returned.
108
109 @param ChildHandle[in] The handle of the child controller to retrieve
110 the name of. This is an optional parameter that
111 may be NULL. It will be NULL for device
112 drivers. It will also be NULL for a bus drivers
113 that wish to retrieve the name of the bus
114 controller. It will not be NULL for a bus
115 driver that wishes to retrieve the name of a
116 child controller.
117
118 @param Language[in] A pointer to a Null-terminated ASCII string
119 array indicating the language. This is the
120 language of the driver name that the caller is
121 requesting, and it must match one of the
122 languages specified in SupportedLanguages. The
123 number of languages supported by a driver is up
124 to the driver writer. Language is specified in
125 RFC 4646 or ISO 639-2 language code format.
126
127 @param ControllerName[out] A pointer to the Unicode string to return.
128 This Unicode string is the name of the
129 controller specified by ControllerHandle and
130 ChildHandle in the language specified by
131 Language from the point of view of the driver
132 specified by This.
133
134 @retval EFI_SUCCESS The Unicode string for the user readable name in
135 the language specified by Language for the
136 driver specified by This was returned in
137 DriverName.
138
139 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
140
141 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
142 EFI_HANDLE.
143
144 @retval EFI_INVALID_PARAMETER Language is NULL.
145
146 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
147
148 @retval EFI_UNSUPPORTED The driver specified by This is not currently
149 managing the controller specified by
150 ControllerHandle and ChildHandle.
151
152 @retval EFI_UNSUPPORTED The driver specified by This does not support
153 the language specified by Language.
154
155 **/
156 EFI_STATUS
157 EFIAPI
158 WinNtBusDriverComponentNameGetControllerName (
159 IN EFI_COMPONENT_NAME_PROTOCOL *This,
160 IN EFI_HANDLE ControllerHandle,
161 IN EFI_HANDLE ChildHandle OPTIONAL,
162 IN CHAR8 *Language,
163 OUT CHAR16 **ControllerName
164 );
165
166
167 //
168 // EFI Component Name Protocol
169 //
170 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gWinNtBusDriverComponentName = {
171 WinNtBusDriverComponentNameGetDriverName,
172 WinNtBusDriverComponentNameGetControllerName,
173 "eng"
174 };
175
176 //
177 // EFI Component Name 2 Protocol
178 //
179 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gWinNtBusDriverComponentName2 = {
180 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) WinNtBusDriverComponentNameGetDriverName,
181 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) WinNtBusDriverComponentNameGetControllerName,
182 "en"
183 };
184
185
186 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mWinNtBusDriverNameTable[] = {
187 { "eng;en", L"Windows Bus Driver" },
188 { NULL , NULL }
189 };
190
191 /**
192 Retrieves a Unicode string that is the user readable name of the driver.
193
194 This function retrieves the user readable name of a driver in the form of a
195 Unicode string. If the driver specified by This has a user readable name in
196 the language specified by Language, then a pointer to the driver name is
197 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
198 by This does not support the language specified by Language,
199 then EFI_UNSUPPORTED is returned.
200
201 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
202 EFI_COMPONENT_NAME_PROTOCOL instance.
203
204 @param Language[in] A pointer to a Null-terminated ASCII string
205 array indicating the language. This is the
206 language of the driver name that the caller is
207 requesting, and it must match one of the
208 languages specified in SupportedLanguages. The
209 number of languages supported by a driver is up
210 to the driver writer. Language is specified
211 in RFC 4646 or ISO 639-2 language code format.
212
213 @param DriverName[out] A pointer to the Unicode string to return.
214 This Unicode string is the name of the
215 driver specified by This in the language
216 specified by Language.
217
218 @retval EFI_SUCCESS The Unicode string for the Driver specified by
219 This and the language specified by Language was
220 returned in DriverName.
221
222 @retval EFI_INVALID_PARAMETER Language is NULL.
223
224 @retval EFI_INVALID_PARAMETER DriverName is NULL.
225
226 @retval EFI_UNSUPPORTED The driver specified by This does not support
227 the language specified by Language.
228
229 **/
230 EFI_STATUS
231 EFIAPI
WinNtBusDriverComponentNameGetDriverName(IN EFI_COMPONENT_NAME_PROTOCOL * This,IN CHAR8 * Language,OUT CHAR16 ** DriverName)232 WinNtBusDriverComponentNameGetDriverName (
233 IN EFI_COMPONENT_NAME_PROTOCOL *This,
234 IN CHAR8 *Language,
235 OUT CHAR16 **DriverName
236 )
237 {
238 return LookupUnicodeString2 (
239 Language,
240 This->SupportedLanguages,
241 mWinNtBusDriverNameTable,
242 DriverName,
243 (BOOLEAN)(This == &gWinNtBusDriverComponentName)
244 );
245 }
246
247 /**
248 Retrieves a Unicode string that is the user readable name of the controller
249 that is being managed by a driver.
250
251 This function retrieves the user readable name of the controller specified by
252 ControllerHandle and ChildHandle in the form of a Unicode string. If the
253 driver specified by This has a user readable name in the language specified by
254 Language, then a pointer to the controller name is returned in ControllerName,
255 and EFI_SUCCESS is returned. If the driver specified by This is not currently
256 managing the controller specified by ControllerHandle and ChildHandle,
257 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
258 support the language specified by Language, then EFI_UNSUPPORTED is returned.
259
260 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
261 EFI_COMPONENT_NAME_PROTOCOL instance.
262
263 @param ControllerHandle[in] The handle of a controller that the driver
264 specified by This is managing. This handle
265 specifies the controller whose name is to be
266 returned.
267
268 @param ChildHandle[in] The handle of the child controller to retrieve
269 the name of. This is an optional parameter that
270 may be NULL. It will be NULL for device
271 drivers. It will also be NULL for a bus drivers
272 that wish to retrieve the name of the bus
273 controller. It will not be NULL for a bus
274 driver that wishes to retrieve the name of a
275 child controller.
276
277 @param Language[in] A pointer to a Null-terminated ASCII string
278 array indicating the language. This is the
279 language of the driver name that the caller is
280 requesting, and it must match one of the
281 languages specified in SupportedLanguages. The
282 number of languages supported by a driver is up
283 to the driver writer. Language is specified in
284 RFC 4646 or ISO 639-2 language code format.
285
286 @param ControllerName[out] A pointer to the Unicode string to return.
287 This Unicode string is the name of the
288 controller specified by ControllerHandle and
289 ChildHandle in the language specified by
290 Language from the point of view of the driver
291 specified by This.
292
293 @retval EFI_SUCCESS The Unicode string for the user readable name in
294 the language specified by Language for the
295 driver specified by This was returned in
296 DriverName.
297
298 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
299
300 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
301 EFI_HANDLE.
302
303 @retval EFI_INVALID_PARAMETER Language is NULL.
304
305 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
306
307 @retval EFI_UNSUPPORTED The driver specified by This is not currently
308 managing the controller specified by
309 ControllerHandle and ChildHandle.
310
311 @retval EFI_UNSUPPORTED The driver specified by This does not support
312 the language specified by Language.
313
314 **/
315 EFI_STATUS
316 EFIAPI
WinNtBusDriverComponentNameGetControllerName(IN EFI_COMPONENT_NAME_PROTOCOL * This,IN EFI_HANDLE ControllerHandle,IN EFI_HANDLE ChildHandle OPTIONAL,IN CHAR8 * Language,OUT CHAR16 ** ControllerName)317 WinNtBusDriverComponentNameGetControllerName (
318 IN EFI_COMPONENT_NAME_PROTOCOL *This,
319 IN EFI_HANDLE ControllerHandle,
320 IN EFI_HANDLE ChildHandle OPTIONAL,
321 IN CHAR8 *Language,
322 OUT CHAR16 **ControllerName
323 )
324 {
325 EFI_STATUS Status;
326 EFI_WIN_NT_IO_PROTOCOL *WinNtIo;
327 WIN_NT_IO_DEVICE *Private;
328
329 //
330 // Make sure this driver is currently managing ControllHandle
331 //
332 Status = EfiTestManagedDevice (
333 ControllerHandle,
334 gWinNtBusDriverBinding.DriverBindingHandle,
335 &gEfiWinNtThunkProtocolGuid
336 );
337 if (EFI_ERROR (Status)) {
338 return Status;
339 }
340
341 //
342 // This is a bus driver, so ChildHandle can not be NULL.
343 //
344 if (ChildHandle == NULL) {
345 return EFI_UNSUPPORTED;
346 }
347
348 Status = EfiTestChildHandle (
349 ControllerHandle,
350 ChildHandle,
351 &gEfiWinNtThunkProtocolGuid
352 );
353 if (EFI_ERROR (Status)) {
354 return Status;
355 }
356
357 //
358 // Get our context back
359 //
360 Status = gBS->OpenProtocol (
361 ChildHandle,
362 &gEfiWinNtIoProtocolGuid,
363 (VOID **) &WinNtIo,
364 gWinNtBusDriverBinding.DriverBindingHandle,
365 ChildHandle,
366 EFI_OPEN_PROTOCOL_GET_PROTOCOL
367 );
368 if (EFI_ERROR (Status)) {
369 return EFI_UNSUPPORTED;
370 }
371
372 Private = WIN_NT_IO_DEVICE_FROM_THIS (WinNtIo);
373
374 return LookupUnicodeString2 (
375 Language,
376 This->SupportedLanguages,
377 Private->ControllerNameTable,
378 ControllerName,
379 (BOOLEAN)(This == &gWinNtBusDriverComponentName)
380 );
381 }
382