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