]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Bus/Pci/IdeBusDxe/ComponentName.c
c36fc330bb854fab312dc176ad8c6c9625f2fbc5
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Pci / IdeBusDxe / ComponentName.c
1 /** @file
2 UEFI Component Name(2) protocol implementation for ConPlatform driver.
3
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "IdeBus.h"
10
11 //
12 // EFI Component Name Protocol
13 //
14 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gIDEBusComponentName = {
15 IDEBusComponentNameGetDriverName,
16 IDEBusComponentNameGetControllerName,
17 "eng"
18 };
19
20 //
21 // EFI Component Name 2 Protocol
22 //
23 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gIDEBusComponentName2 = {
24 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) IDEBusComponentNameGetDriverName,
25 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) IDEBusComponentNameGetControllerName,
26 "en"
27 };
28
29
30 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mIDEBusDriverNameTable[] = {
31 { "eng;en", (CHAR16 *) L"PCI IDE/ATAPI Bus Driver" },
32 { NULL , NULL }
33 };
34
35 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mIDEBusControllerNameTable[] = {
36 { "eng;en", (CHAR16 *) L"PCI IDE/ATAPI Controller" },
37 { NULL , NULL }
38 };
39
40 /**
41 Retrieves a Unicode string that is the user readable name of the driver.
42
43 This function retrieves the user readable name of a driver in the form of a
44 Unicode string. If the driver specified by This has a user readable name in
45 the language specified by Language, then a pointer to the driver name is
46 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
47 by This does not support the language specified by Language,
48 then EFI_UNSUPPORTED is returned.
49
50 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
51 EFI_COMPONENT_NAME_PROTOCOL instance.
52
53 @param Language[in] A pointer to a Null-terminated ASCII string
54 array indicating the language. This is the
55 language of the driver name that the caller is
56 requesting, and it must match one of the
57 languages specified in SupportedLanguages. The
58 number of languages supported by a driver is up
59 to the driver writer. Language is specified
60 in RFC 4646 or ISO 639-2 language code format.
61
62 @param DriverName[out] A pointer to the Unicode string to return.
63 This Unicode string is the name of the
64 driver specified by This in the language
65 specified by Language.
66
67 @retval EFI_SUCCESS The Unicode string for the Driver specified by
68 This and the language specified by Language was
69 returned in DriverName.
70
71 @retval EFI_INVALID_PARAMETER Language is NULL.
72
73 @retval EFI_INVALID_PARAMETER DriverName is NULL.
74
75 @retval EFI_UNSUPPORTED The driver specified by This does not support
76 the language specified by Language.
77
78 **/
79 EFI_STATUS
80 EFIAPI
81 IDEBusComponentNameGetDriverName (
82 IN EFI_COMPONENT_NAME_PROTOCOL *This,
83 IN CHAR8 *Language,
84 OUT CHAR16 **DriverName
85 )
86 {
87 return LookupUnicodeString2 (
88 Language,
89 This->SupportedLanguages,
90 mIDEBusDriverNameTable,
91 DriverName,
92 (BOOLEAN)(This == &gIDEBusComponentName)
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 4646 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 NULL.
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 IDEBusComponentNameGetControllerName (
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 EFI_STATUS Status;
175 EFI_BLOCK_IO_PROTOCOL *BlockIo;
176 IDE_BLK_IO_DEV *IdeBlkIoDevice;
177
178 //
179 // Make sure this driver is currently managing ControllHandle
180 //
181 Status = EfiTestManagedDevice (
182 ControllerHandle,
183 gIDEBusDriverBinding.DriverBindingHandle,
184 &gEfiIdeControllerInitProtocolGuid
185 );
186 if (EFI_ERROR (Status)) {
187 return Status;
188 }
189
190 if (ChildHandle == NULL) {
191 return LookupUnicodeString2 (
192 Language,
193 This->SupportedLanguages,
194 mIDEBusControllerNameTable,
195 ControllerName,
196 (BOOLEAN)(This == &gIDEBusComponentName)
197 );
198 }
199
200 Status = EfiTestChildHandle (
201 ControllerHandle,
202 ChildHandle,
203 &gEfiPciIoProtocolGuid
204 );
205 if (EFI_ERROR (Status)) {
206 return Status;
207 }
208
209 //
210 // Get the child context
211 //
212 Status = gBS->OpenProtocol (
213 ChildHandle,
214 &gEfiBlockIoProtocolGuid,
215 (VOID **) &BlockIo,
216 gIDEBusDriverBinding.DriverBindingHandle,
217 ChildHandle,
218 EFI_OPEN_PROTOCOL_GET_PROTOCOL
219 );
220 if (EFI_ERROR (Status)) {
221 return EFI_UNSUPPORTED;
222 }
223
224 IdeBlkIoDevice = IDE_BLOCK_IO_DEV_FROM_THIS (BlockIo);
225
226 return LookupUnicodeString2 (
227 Language,
228 This->SupportedLanguages,
229 IdeBlkIoDevice->ControllerNameTable,
230 ControllerName,
231 (BOOLEAN)(This == &gIDEBusComponentName)
232 );
233 }
234
235 /**
236 Add the component name for the IDE/ATAPI device
237
238 @param IdeBlkIoDevicePtr A pointer to the IDE_BLK_IO_DEV instance.
239
240 **/
241 VOID
242 AddName (
243 IN IDE_BLK_IO_DEV *IdeBlkIoDevicePtr
244 )
245 {
246 UINTN StringIndex;
247 CHAR16 ModelName[41];
248
249 //
250 // Add Component Name for the IDE/ATAPI device that was discovered.
251 //
252 IdeBlkIoDevicePtr->ControllerNameTable = NULL;
253 for (StringIndex = 0; StringIndex < 41; StringIndex++) {
254 ModelName[StringIndex] = IdeBlkIoDevicePtr->ModelName[StringIndex];
255 }
256
257 AddUnicodeString2 (
258 "eng",
259 gIDEBusComponentName.SupportedLanguages,
260 &IdeBlkIoDevicePtr->ControllerNameTable,
261 ModelName,
262 TRUE
263 );
264 AddUnicodeString2 (
265 "en",
266 gIDEBusComponentName2.SupportedLanguages,
267 &IdeBlkIoDevicePtr->ControllerNameTable,
268 ModelName,
269 FALSE
270 );
271
272 }