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