]> git.proxmox.com Git - mirror_edk2.git/blame - InOsEmuPkg/EmuBusDriverDxe/ComponentName.c
Clarify the requirements for the Destination parameter of UnicodeStrToAsciiStr.
[mirror_edk2.git] / InOsEmuPkg / EmuBusDriverDxe / ComponentName.c
CommitLineData
949f388f 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
9**/\r
10\r
11#include "EmuBusDriverDxe.h"\r
12\r
13//\r
14// EFI Component Name Functions\r
15//\r
16EFI_STATUS\r
17EFIAPI\r
18EmuBusDriverComponentNameGetDriverName (\r
19 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
20 IN CHAR8 *Language,\r
21 OUT CHAR16 **DriverName\r
22 );\r
23\r
24EFI_STATUS\r
25EFIAPI\r
26EmuBusDriverComponentNameGetControllerName (\r
27 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
28 IN EFI_HANDLE ControllerHandle,\r
29 IN EFI_HANDLE ChildHandle OPTIONAL,\r
30 IN CHAR8 *Language,\r
31 OUT CHAR16 **ControllerName\r
32 );\r
33\r
34//\r
35// EFI Component Name Protocol\r
36//\r
37GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gEmuBusDriverComponentName = {\r
38 EmuBusDriverComponentNameGetDriverName,\r
39 EmuBusDriverComponentNameGetControllerName,\r
40 "eng"\r
41};\r
42\r
43//\r
44// EFI Component Name 2 Protocol\r
45//\r
46GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gEmuBusDriverComponentName2 = {\r
47 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) EmuBusDriverComponentNameGetDriverName,\r
48 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) EmuBusDriverComponentNameGetControllerName,\r
49 "en"\r
50};\r
51\r
52GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mEmuBusDriverNameTable[] = {\r
53 { "eng", L"Emu Bus Driver" },\r
54 { NULL , NULL }\r
55};\r
56\r
57/**\r
58 Retrieves a Unicode string that is the user readable name of the driver.\r
59\r
60 This function retrieves the user readable name of a driver in the form of a\r
61 Unicode string. If the driver specified by This has a user readable name in\r
62 the language specified by Language, then a pointer to the driver name is\r
63 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
64 by This does not support the language specified by Language,\r
65 then EFI_UNSUPPORTED is returned.\r
66\r
67 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
68 EFI_COMPONENT_NAME_PROTOCOL instance.\r
69\r
70 @param Language[in] A pointer to a Null-terminated ASCII string\r
71 array indicating the language. This is the\r
72 language of the driver name that the caller is\r
73 requesting, and it must match one of the\r
74 languages specified in SupportedLanguages. The\r
75 number of languages supported by a driver is up\r
76 to the driver writer. Language is specified\r
77 in RFC 4646 or ISO 639-2 language code format.\r
78\r
79 @param DriverName[out] A pointer to the Unicode string to return.\r
80 This Unicode string is the name of the\r
81 driver specified by This in the language\r
82 specified by Language.\r
83\r
84 @retval EFI_SUCCESS The Unicode string for the Driver specified by\r
85 This and the language specified by Language was\r
86 returned in DriverName.\r
87\r
88 @retval EFI_INVALID_PARAMETER Language is NULL.\r
89\r
90 @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
91\r
92 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
93 the language specified by Language.\r
94\r
95**/\r
96EFI_STATUS\r
97EFIAPI\r
98EmuBusDriverComponentNameGetDriverName (\r
99 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
100 IN CHAR8 *Language,\r
101 OUT CHAR16 **DriverName\r
102 )\r
103{\r
104 return LookupUnicodeString2 (\r
105 Language,\r
106 This->SupportedLanguages,\r
107 mEmuBusDriverNameTable,\r
108 DriverName,\r
109 (BOOLEAN)(This == &gEmuBusDriverComponentName)\r
110 );\r
111}\r
112\r
113/**\r
114 Retrieves a Unicode string that is the user readable name of the controller\r
115 that is being managed by a driver.\r
116\r
117 This function retrieves the user readable name of the controller specified by\r
118 ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
119 driver specified by This has a user readable name in the language specified by\r
120 Language, then a pointer to the controller name is returned in ControllerName,\r
121 and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
122 managing the controller specified by ControllerHandle and ChildHandle,\r
123 then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
124 support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
125\r
126 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
127 EFI_COMPONENT_NAME_PROTOCOL instance.\r
128\r
129 @param ControllerHandle[in] The handle of a controller that the driver\r
130 specified by This is managing. This handle\r
131 specifies the controller whose name is to be\r
132 returned.\r
133\r
134 @param ChildHandle[in] The handle of the child controller to retrieve\r
135 the name of. This is an optional parameter that\r
136 may be NULL. It will be NULL for device\r
137 drivers. It will also be NULL for a bus drivers\r
138 that wish to retrieve the name of the bus\r
139 controller. It will not be NULL for a bus\r
140 driver that wishes to retrieve the name of a\r
141 child controller.\r
142\r
143 @param Language[in] A pointer to a Null-terminated ASCII string\r
144 array indicating the language. This is the\r
145 language of the driver name that the caller is\r
146 requesting, and it must match one of the\r
147 languages specified in SupportedLanguages. The\r
148 number of languages supported by a driver is up\r
149 to the driver writer. Language is specified in\r
150 RFC 4646 or ISO 639-2 language code format.\r
151\r
152 @param ControllerName[out] A pointer to the Unicode string to return.\r
153 This Unicode string is the name of the\r
154 controller specified by ControllerHandle and\r
155 ChildHandle in the language specified by\r
156 Language from the point of view of the driver\r
157 specified by This.\r
158\r
159 @retval EFI_SUCCESS The Unicode string for the user readable name in\r
160 the language specified by Language for the\r
161 driver specified by This was returned in\r
162 DriverName.\r
163\r
164 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.\r
165\r
166 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
167 EFI_HANDLE.\r
168\r
169 @retval EFI_INVALID_PARAMETER Language is NULL.\r
170\r
171 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
172\r
173 @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
174 managing the controller specified by\r
175 ControllerHandle and ChildHandle.\r
176\r
177 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
178 the language specified by Language.\r
179\r
180**/\r
181EFI_STATUS\r
182EFIAPI\r
183EmuBusDriverComponentNameGetControllerName (\r
184 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
185 IN EFI_HANDLE ControllerHandle,\r
186 IN EFI_HANDLE ChildHandle OPTIONAL,\r
187 IN CHAR8 *Language,\r
188 OUT CHAR16 **ControllerName\r
189 )\r
190{\r
191 EFI_STATUS Status;\r
192 EMU_IO_THUNK_PROTOCOL *EmuIo;\r
193 EMU_IO_DEVICE *Private;\r
194\r
195 //\r
196 // Make sure this driver is currently managing ControllHandle\r
197 //\r
198 Status = EfiTestManagedDevice (\r
199 ControllerHandle,\r
200 gEmuBusDriverBinding.DriverBindingHandle,\r
201 &gEmuThunkProtocolGuid\r
202 );\r
203 if (EFI_ERROR (Status)) {\r
204 return Status;\r
205 }\r
206\r
207 //\r
208 // This is a bus driver, so ChildHandle can not be NULL.\r
209 //\r
210 if (ChildHandle == NULL) {\r
211 return EFI_UNSUPPORTED;\r
212 }\r
213\r
214 Status = EfiTestChildHandle (\r
215 ControllerHandle,\r
216 ChildHandle,\r
217 &gEmuThunkProtocolGuid\r
218 );\r
219 if (EFI_ERROR (Status)) {\r
220 return Status;\r
221 }\r
222\r
223 //\r
224 // Get our context back\r
225 //\r
226 Status = gBS->OpenProtocol (\r
227 ChildHandle,\r
228 &gEmuIoThunkProtocolGuid,\r
229 (VOID**)&EmuIo,\r
230 gEmuBusDriverBinding.DriverBindingHandle,\r
231 ChildHandle,\r
232 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
233 );\r
234 if (EFI_ERROR (Status)) {\r
235 return EFI_UNSUPPORTED;\r
236 }\r
237\r
238 Private = EMU_IO_DEVICE_FROM_THIS (EmuIo);\r
239\r
240 return LookupUnicodeString2 (\r
241 Language,\r
242 This->SupportedLanguages,\r
243 Private->ControllerNameTable,\r
244 ControllerName,\r
245 (BOOLEAN)(This == &gEmuBusDriverComponentName)\r
246 );\r
247}\r