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