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