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