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