]> git.proxmox.com Git - mirror_edk2.git/blame - OptionRomPkg/Bus/Usb/FtdiUsbSerialDxe/ComponentName.c
OptionRomPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / OptionRomPkg / Bus / Usb / FtdiUsbSerialDxe / ComponentName.c
CommitLineData
3f1484f6
AD
1/** @file\r
2 UEFI Component Name(2) protocol implementation for USB Serial driver.\r
3\r
4Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>\r
96ae5934 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
3f1484f6
AD
6\r
7**/\r
8\r
9#include "FtdiUsbSerialDriver.h"\r
10\r
11//\r
12// EFI Component Name Protocol\r
13//\r
14GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gUsbSerialComponentName = {\r
15 (EFI_COMPONENT_NAME_GET_DRIVER_NAME) UsbSerialComponentNameGetDriverName,\r
16 (EFI_COMPONENT_NAME_GET_CONTROLLER_NAME) UsbSerialComponentNameGetControllerName,\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 gUsbSerialComponentName2 = {\r
24 UsbSerialComponentNameGetDriverName,\r
25 UsbSerialComponentNameGetControllerName,\r
26 "en"\r
27};\r
28\r
29//\r
30// Driver name string table\r
31//\r
32GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mUsbSerialDriverNameTable[] = {\r
33 { "eng;en", L"FTDI-232 USB Serial Driver" },\r
34 { NULL , NULL }\r
35};\r
36\r
37/**\r
38 Retrieves a Unicode string that is the user readable name of the driver.\r
39\r
40 This function retrieves the user readable name of a driver in the form of a\r
41 Unicode string. If the driver specified by This has a user readable name in\r
42 the language specified by Language, then a pointer to the driver name is\r
43 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
44 by This does not support the language specified by Language,\r
45 then EFI_UNSUPPORTED is returned.\r
46\r
47 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
48 EFI_COMPONENT_NAME_PROTOCOL instance.\r
49 @param Language A pointer to a Null-terminated ASCII string\r
50 array indicating the language. This is the\r
51 language of the driver name that the caller is\r
52 requesting, and it must match one of the\r
53 languages specified in SupportedLanguages. The\r
54 number of languages supported by a driver is up\r
55 to the driver writer. Language is specified\r
56 in RFC 4646 or ISO 639-2 language code format.\r
57 @param DriverName A pointer to the Unicode string to return.\r
58 This Unicode string is the name of the\r
59 driver specified by This in the language\r
60 specified by Language.\r
61\r
62 @retval EFI_SUCCESS The Unicode string for the Driver specified by\r
63 This and the language specified by Language was\r
64 returned in DriverName.\r
65 @retval EFI_INVALID_PARAMETER Language is NULL.\r
66 @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
67 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
68 the language specified by Language.\r
69\r
70**/\r
71EFI_STATUS\r
72EFIAPI\r
73UsbSerialComponentNameGetDriverName (\r
74 IN EFI_COMPONENT_NAME2_PROTOCOL *This,\r
75 IN CHAR8 *Language,\r
76 OUT CHAR16 **DriverName\r
77 )\r
78{\r
79 return LookupUnicodeString2 (\r
80 Language,\r
81 This->SupportedLanguages,\r
82 mUsbSerialDriverNameTable,\r
83 DriverName,\r
84 (BOOLEAN)(This == &gUsbSerialComponentName2)\r
85 );\r
86}\r
87\r
88\r
89/**\r
90 Retrieves a Unicode string that is the user readable name of the controller\r
91 that is being managed by a driver.\r
92\r
93 This function retrieves the user readable name of the controller specified by\r
94 ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
95 driver specified by This has a user readable name in the language specified by\r
96 Language, then a pointer to the controller name is returned in ControllerName,\r
97 and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
98 managing the controller specified by ControllerHandle and ChildHandle,\r
99 then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
100 support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
101\r
102 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
103 EFI_COMPONENT_NAME_PROTOCOL instance.\r
104 @param ControllerHandle The handle of a controller that the driver\r
105 specified by This is managing. This handle\r
106 specifies the controller whose name is to be\r
107 returned.\r
108 @param ChildHandle The handle of the child controller to retrieve\r
109 the name of. This is an optional parameter that\r
110 may be NULL. It will be NULL for device\r
111 drivers. It will also be NULL for a bus drivers\r
112 that wish to retrieve the name of the bus\r
113 controller. It will not be NULL for a bus\r
114 driver that wishes to retrieve the name of a\r
115 child controller.\r
116 @param Language A pointer to a Null-terminated ASCII string\r
117 array indicating the language. This is the\r
118 language of the driver name that the caller is\r
119 requesting, and it must match one of the\r
120 languages specified in SupportedLanguages. The\r
121 number of languages supported by a driver is up\r
122 to the driver writer. Language is specified in\r
123 RFC 4646 or ISO 639-2 language code format.\r
124 @param ControllerName A pointer to the Unicode string to return.\r
125 This Unicode string is the name of the\r
126 controller specified by ControllerHandle and\r
127 ChildHandle in the language specified by\r
128 Language from the point of view of the driver\r
129 specified by This.\r
130\r
131 @retval EFI_SUCCESS The Unicode string for the user readable name in\r
132 the language specified by Language for the\r
133 driver specified by This was returned in\r
134 DriverName.\r
135 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.\r
136 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
137 EFI_HANDLE.\r
138 @retval EFI_INVALID_PARAMETER Language is NULL.\r
139 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
140 @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
141 managing the controller specified by\r
142 ControllerHandle and ChildHandle.\r
143 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
144 the language specified by Language.\r
145\r
146**/\r
147EFI_STATUS\r
148EFIAPI\r
149UsbSerialComponentNameGetControllerName (\r
150 IN EFI_COMPONENT_NAME2_PROTOCOL *This,\r
151 IN EFI_HANDLE ControllerHandle,\r
152 IN EFI_HANDLE ChildHandle OPTIONAL,\r
153 IN CHAR8 *Language,\r
154 OUT CHAR16 **ControllerName\r
155 )\r
156{\r
157 EFI_STATUS Status;\r
158 USB_SER_DEV *UsbSerDev;\r
159 EFI_SERIAL_IO_PROTOCOL *SerialIo;\r
160 EFI_USB_IO_PROTOCOL *UsbIoProtocol;\r
161 \r
162 //\r
163 // This is a device driver, so ChildHandle must be NULL.\r
164 //\r
165 if (ChildHandle != NULL) {\r
166 return EFI_UNSUPPORTED;\r
167 }\r
168\r
169 //\r
170 // Check Controller's handle\r
171 //\r
172 Status = gBS->OpenProtocol (\r
173 ControllerHandle,\r
174 &gEfiUsbIoProtocolGuid,\r
175 (VOID **) &UsbIoProtocol,\r
176 gUsbSerialDriverBinding.DriverBindingHandle,\r
177 ControllerHandle,\r
178 EFI_OPEN_PROTOCOL_BY_DRIVER\r
179 );\r
180 if (!EFI_ERROR (Status)) {\r
181 gBS->CloseProtocol (\r
182 ControllerHandle,\r
183 &gEfiUsbIoProtocolGuid,\r
184 gUsbSerialDriverBinding.DriverBindingHandle,\r
185 ControllerHandle\r
186 );\r
187\r
188 return EFI_UNSUPPORTED;\r
189 }\r
190\r
191 if (Status != EFI_ALREADY_STARTED) {\r
192 return EFI_UNSUPPORTED;\r
193 }\r
194 //\r
195 // Get the device context\r
196 //\r
197 Status = gBS->OpenProtocol (\r
198 ControllerHandle,\r
199 &gEfiSerialIoProtocolGuid,\r
200 (VOID **) &SerialIo,\r
201 gUsbSerialDriverBinding.DriverBindingHandle,\r
202 ControllerHandle,\r
203 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
204 );\r
205 if (EFI_ERROR (Status)) {\r
206 return Status;\r
207 }\r
208\r
209 UsbSerDev = USB_SER_DEV_FROM_THIS (SerialIo);\r
210\r
211 return LookupUnicodeString2 (\r
212 Language,\r
213 This->SupportedLanguages,\r
214 UsbSerDev->ControllerNameTable,\r
215 ControllerName,\r
216 (BOOLEAN)(This == &gUsbSerialComponentName2)\r
217 );\r
218}\r