]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Pci/PciSioSerialDxe/ComponentName.c
MdePkg/BaseMemoryLibOptDxe: replace deprecated uses of IT blocks
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / PciSioSerialDxe / ComponentName.c
CommitLineData
a59e2ede
RN
1/** @file\r
2 UEFI Component Name and Name2 protocol for Isa serial driver.\r
3\r
4Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "Serial.h"\r
16\r
17//\r
18// EFI Component Name Protocol\r
19//\r
20GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gPciSioSerialComponentName = {\r
21 SerialComponentNameGetDriverName,\r
22 SerialComponentNameGetControllerName,\r
23 "eng"\r
24};\r
25\r
26//\r
27// EFI Component Name 2 Protocol\r
28//\r
29GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gPciSioSerialComponentName2 = {\r
30 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) SerialComponentNameGetDriverName,\r
31 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) SerialComponentNameGetControllerName,\r
32 "en"\r
33};\r
34\r
35\r
36GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mSerialDriverNameTable[] = {\r
37 {\r
38 "eng;en",\r
39 L"PCI SIO Serial Driver"\r
40 },\r
41 {\r
42 NULL,\r
43 NULL\r
44 }\r
45};\r
46\r
47GLOBAL_REMOVE_IF_UNREFERENCED CHAR16 mSioSerialPortName[] = L"SIO Serial Port #%d";\r
48GLOBAL_REMOVE_IF_UNREFERENCED CHAR16 mPciSerialPortName[] = L"PCI Serial Port #%d";\r
49\r
50/**\r
51 Retrieves a Unicode string that is the user readable name of the driver.\r
52\r
53 This function retrieves the user readable name of a driver in the form of a\r
54 Unicode string. If the driver specified by This has a user readable name in\r
55 the language specified by Language, then a pointer to the driver name is\r
56 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
57 by This does not support the language specified by Language,\r
58 then EFI_UNSUPPORTED is returned.\r
59\r
60 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
61 EFI_COMPONENT_NAME_PROTOCOL instance.\r
62\r
63 @param Language[in] A pointer to a Null-terminated ASCII string\r
64 array indicating the language. This is the\r
65 language of the driver name that the caller is\r
66 requesting, and it must match one of the\r
67 languages specified in SupportedLanguages. The\r
68 number of languages supported by a driver is up\r
69 to the driver writer. Language is specified\r
70 in RFC 4646 or ISO 639-2 language code format.\r
71\r
72 @param DriverName[out] A pointer to the Unicode string to return.\r
73 This Unicode string is the name of the\r
74 driver specified by This in the language\r
75 specified by Language.\r
76\r
77 @retval EFI_SUCCESS The Unicode string for the Driver specified by\r
78 This and the language specified by Language was\r
79 returned in DriverName.\r
80\r
81 @retval EFI_INVALID_PARAMETER Language is NULL.\r
82\r
83 @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
84\r
85 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
86 the language specified by Language.\r
87\r
88**/\r
89EFI_STATUS\r
90EFIAPI\r
91SerialComponentNameGetDriverName (\r
92 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
93 IN CHAR8 *Language,\r
94 OUT CHAR16 **DriverName\r
95 )\r
96{\r
97 return LookupUnicodeString2 (\r
98 Language,\r
99 This->SupportedLanguages,\r
100 mSerialDriverNameTable,\r
101 DriverName,\r
102 (BOOLEAN)(This == &gPciSioSerialComponentName)\r
103 );\r
104}\r
105\r
106/**\r
107 Retrieves a Unicode string that is the user readable name of the controller\r
108 that is being managed by a driver.\r
109\r
110 This function retrieves the user readable name of the controller specified by\r
111 ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
112 driver specified by This has a user readable name in the language specified by\r
113 Language, then a pointer to the controller name is returned in ControllerName,\r
114 and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
115 managing the controller specified by ControllerHandle and ChildHandle,\r
116 then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
117 support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
118\r
119 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
120 EFI_COMPONENT_NAME_PROTOCOL instance.\r
121\r
122 @param ControllerHandle[in] The handle of a controller that the driver\r
123 specified by This is managing. This handle\r
124 specifies the controller whose name is to be\r
125 returned.\r
126\r
127 @param ChildHandle[in] The handle of the child controller to retrieve\r
128 the name of. This is an optional parameter that\r
129 may be NULL. It will be NULL for device\r
130 drivers. It will also be NULL for a bus drivers\r
131 that wish to retrieve the name of the bus\r
132 controller. It will not be NULL for a bus\r
133 driver that wishes to retrieve the name of a\r
134 child controller.\r
135\r
136 @param Language[in] A pointer to a Null-terminated ASCII string\r
137 array indicating the language. This is the\r
138 language of the driver name that the caller is\r
139 requesting, and it must match one of the\r
140 languages specified in SupportedLanguages. The\r
141 number of languages supported by a driver is up\r
142 to the driver writer. Language is specified in\r
143 RFC 4646 or ISO 639-2 language code format.\r
144\r
145 @param ControllerName[out] A pointer to the Unicode string to return.\r
146 This Unicode string is the name of the\r
147 controller specified by ControllerHandle and\r
148 ChildHandle in the language specified by\r
149 Language from the point of view of the driver\r
150 specified by This.\r
151\r
152 @retval EFI_SUCCESS The Unicode string for the user readable name in\r
153 the language specified by Language for the\r
154 driver specified by This was returned in\r
155 DriverName.\r
156\r
157 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
158\r
159 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
160 EFI_HANDLE.\r
161\r
162 @retval EFI_INVALID_PARAMETER Language is NULL.\r
163\r
164 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
165\r
166 @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
167 managing the controller specified by\r
168 ControllerHandle and ChildHandle.\r
169\r
170 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
171 the language specified by Language.\r
172\r
173**/\r
174EFI_STATUS\r
175EFIAPI\r
176SerialComponentNameGetControllerName (\r
177 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
178 IN EFI_HANDLE ControllerHandle,\r
179 IN EFI_HANDLE ChildHandle OPTIONAL,\r
180 IN CHAR8 *Language,\r
181 OUT CHAR16 **ControllerName\r
182 )\r
183{\r
184 EFI_STATUS Status;\r
185 EFI_SERIAL_IO_PROTOCOL *SerialIo;\r
186 SERIAL_DEV *SerialDevice;\r
187 EFI_UNICODE_STRING_TABLE *ControllerNameTable;\r
188 EFI_GUID *IoProtocolGuid;\r
189\r
190 //\r
191 // Make sure this driver is currently managing ControllerHandle\r
192 //\r
193 IoProtocolGuid = &gEfiSioProtocolGuid;\r
194 Status = EfiTestManagedDevice (\r
195 ControllerHandle,\r
196 gSerialControllerDriver.DriverBindingHandle,\r
197 IoProtocolGuid\r
198 );\r
199 if (EFI_ERROR (Status)) {\r
200 IoProtocolGuid = &gEfiPciIoProtocolGuid;\r
201 Status = EfiTestManagedDevice (\r
202 ControllerHandle,\r
203 gSerialControllerDriver.DriverBindingHandle,\r
204 IoProtocolGuid\r
205 );\r
206 }\r
207\r
208 if (EFI_ERROR (Status)) {\r
209 return Status;\r
210 }\r
211\r
212 ControllerNameTable = NULL;\r
213 if (ChildHandle != NULL) {\r
214 Status = EfiTestChildHandle (\r
215 ControllerHandle,\r
216 ChildHandle,\r
217 IoProtocolGuid\r
218 );\r
219 if (EFI_ERROR (Status)) {\r
220 return Status;\r
221 }\r
222\r
223 //\r
224 // Get the Serial I/O Protocol from the child handle\r
225 //\r
226 Status = gBS->OpenProtocol (\r
227 ChildHandle,\r
228 &gEfiSerialIoProtocolGuid,\r
229 (VOID **) &SerialIo,\r
230 gSerialControllerDriver.DriverBindingHandle,\r
231 ChildHandle,\r
232 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
233 );\r
234 if (EFI_ERROR (Status)) {\r
235 return Status;\r
236 }\r
237\r
238 //\r
239 // Get the Serial Controller's Device structure\r
240 //\r
241 SerialDevice = SERIAL_DEV_FROM_THIS (SerialIo);\r
242 ControllerNameTable = SerialDevice->ControllerNameTable;\r
243 }\r
244\r
245 return LookupUnicodeString2 (\r
246 Language,\r
247 This->SupportedLanguages,\r
248 ControllerNameTable,\r
249 ControllerName,\r
250 (BOOLEAN)(This == &gPciSioSerialComponentName)\r
251 );\r
252}\r
253\r
254/**\r
255 Add the ISO639-2 and RFC4646 component name both for the Serial IO device\r
256\r
257 @param SerialDevice A pointer to the SERIAL_DEV instance.\r
258 @param Instance Instance ID for the serial device.\r
259**/\r
260VOID\r
261AddName (\r
262 IN SERIAL_DEV *SerialDevice,\r
263 IN UINT32 Instance\r
264 )\r
265{\r
266 CHAR16 SerialPortName[SERIAL_PORT_NAME_LEN];\r
267 UnicodeSPrint (\r
268 SerialPortName,\r
269 sizeof (SerialPortName),\r
270 (SerialDevice->PciDeviceInfo != NULL) ? PCI_SERIAL_PORT_NAME : SIO_SERIAL_PORT_NAME,\r
271 Instance\r
272 );\r
273 AddUnicodeString2 (\r
274 "eng",\r
275 gPciSioSerialComponentName.SupportedLanguages,\r
276 &SerialDevice->ControllerNameTable,\r
277 SerialPortName,\r
278 TRUE\r
279 );\r
280 AddUnicodeString2 (\r
281 "en",\r
282 gPciSioSerialComponentName2.SupportedLanguages,\r
283 &SerialDevice->ControllerNameTable,\r
284 SerialPortName,\r
285 FALSE\r
286 );\r
287\r
288}\r