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