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