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