1 /** @file
2 UEFI Component Name(2) protocol implementation for Terminal driver.
3
4 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "Terminal.h"
10
11 //
12 // EFI Component Name Protocol
13 //
14 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gTerminalComponentName = {
15 TerminalComponentNameGetDriverName,
16 TerminalComponentNameGetControllerName,
17 "eng"
18 };
19
20 //
21 // EFI Component Name 2 Protocol
22 //
23 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gTerminalComponentName2 = {
24 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) TerminalComponentNameGetDriverName,
25 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) TerminalComponentNameGetControllerName,
26 "en"
27 };
28
29
30 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mTerminalDriverNameTable[] = {
31 {
32 "eng;en",
33 (CHAR16 *) L"Serial Terminal Driver"
34 },
35 {
36 NULL,
37 NULL
38 }
39 };
40
41 /**
42 Retrieves a Unicode string that is the user readable name of the driver.
43
44 This function retrieves the user readable name of a driver in the form of a
45 Unicode string. If the driver specified by This has a user readable name in
46 the language specified by Language, then a pointer to the driver name is
47 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
48 by This does not support the language specified by Language,
49 then EFI_UNSUPPORTED is returned.
50
51 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
52 EFI_COMPONENT_NAME_PROTOCOL instance.
53
54 @param Language[in] A pointer to a Null-terminated ASCII string
55 array indicating the language. This is the
56 language of the driver name that the caller is
57 requesting, and it must match one of the
58 languages specified in SupportedLanguages. The
59 number of languages supported by a driver is up
60 to the driver writer. Language is specified
61 in RFC 4646 or ISO 639-2 language code format.
62
63 @param DriverName[out] 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
72 @retval EFI_INVALID_PARAMETER Language is NULL.
73
74 @retval EFI_INVALID_PARAMETER DriverName is NULL.
75
76 @retval EFI_UNSUPPORTED The driver specified by This does not support
77 the language specified by Language.
78
79 **/
80 EFI_STATUS
81 EFIAPI
TerminalComponentNameGetDriverName(IN EFI_COMPONENT_NAME_PROTOCOL * This,IN CHAR8 * Language,OUT CHAR16 ** DriverName)82 TerminalComponentNameGetDriverName (
83 IN EFI_COMPONENT_NAME_PROTOCOL *This,
84 IN CHAR8 *Language,
85 OUT CHAR16 **DriverName
86 )
87 {
88 return LookupUnicodeString2 (
89 Language,
90 This->SupportedLanguages,
91 mTerminalDriverNameTable,
92 DriverName,
93 (BOOLEAN)(This == &gTerminalComponentName)
94 );
95 }
96
97 /**
98 Retrieves a Unicode string that is the user readable name of the controller
99 that is being managed by a driver.
100
101 This function retrieves the user readable name of the controller specified by
102 ControllerHandle and ChildHandle in the form of a Unicode string. If the
103 driver specified by This has a user readable name in the language specified by
104 Language, then a pointer to the controller name is returned in ControllerName,
105 and EFI_SUCCESS is returned. If the driver specified by This is not currently
106 managing the controller specified by ControllerHandle and ChildHandle,
107 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
108 support the language specified by Language, then EFI_UNSUPPORTED is returned.
109
110 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
111 EFI_COMPONENT_NAME_PROTOCOL instance.
112
113 @param ControllerHandle[in] The handle of a controller that the driver
114 specified by This is managing. This handle
115 specifies the controller whose name is to be
116 returned.
117
118 @param ChildHandle[in] The handle of the child controller to retrieve
119 the name of. This is an optional parameter that
120 may be NULL. It will be NULL for device
121 drivers. It will also be NULL for a bus drivers
122 that wish to retrieve the name of the bus
123 controller. It will not be NULL for a bus
124 driver that wishes to retrieve the name of a
125 child controller.
126
127 @param Language[in] A pointer to a Null-terminated ASCII string
128 array indicating the language. This is the
129 language of the driver name that the caller is
130 requesting, and it must match one of the
131 languages specified in SupportedLanguages. The
132 number of languages supported by a driver is up
133 to the driver writer. Language is specified in
134 RFC 4646 or ISO 639-2 language code format.
135
136 @param ControllerName[out] A pointer to the Unicode string to return.
137 This Unicode string is the name of the
138 controller specified by ControllerHandle and
139 ChildHandle in the language specified by
140 Language from the point of view of the driver
141 specified by This.
142
143 @retval EFI_SUCCESS The Unicode string for the user readable name in
144 the language specified by Language for the
145 driver specified by This was returned in
146 DriverName.
147
148 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
149
150 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
151 EFI_HANDLE.
152
153 @retval EFI_INVALID_PARAMETER Language is NULL.
154
155 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
156
157 @retval EFI_UNSUPPORTED The driver specified by This is not currently
158 managing the controller specified by
159 ControllerHandle and ChildHandle.
160
161 @retval EFI_UNSUPPORTED The driver specified by This does not support
162 the language specified by Language.
163
164 **/
165 EFI_STATUS
166 EFIAPI
TerminalComponentNameGetControllerName(IN EFI_COMPONENT_NAME_PROTOCOL * This,IN EFI_HANDLE ControllerHandle,IN EFI_HANDLE ChildHandle OPTIONAL,IN CHAR8 * Language,OUT CHAR16 ** ControllerName)167 TerminalComponentNameGetControllerName (
168 IN EFI_COMPONENT_NAME_PROTOCOL *This,
169 IN EFI_HANDLE ControllerHandle,
170 IN EFI_HANDLE ChildHandle OPTIONAL,
171 IN CHAR8 *Language,
172 OUT CHAR16 **ControllerName
173 )
174 {
175 EFI_STATUS Status;
176 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOutput;
177 TERMINAL_DEV *TerminalDevice;
178
179 //
180 // Make sure this driver is currently managing ControllHandle
181 //
182 Status = EfiTestManagedDevice (
183 ControllerHandle,
184 gTerminalDriverBinding.DriverBindingHandle,
185 &gEfiSerialIoProtocolGuid
186 );
187 if (EFI_ERROR (Status)) {
188 return Status;
189 }
190
191 //
192 // This is a bus driver, so ChildHandle can not be NULL.
193 //
194 if (ChildHandle == NULL) {
195 return EFI_UNSUPPORTED;
196 }
197
198 Status = EfiTestChildHandle (
199 ControllerHandle,
200 ChildHandle,
201 &gEfiSerialIoProtocolGuid
202 );
203 if (EFI_ERROR (Status)) {
204 return Status;
205 }
206
207 //
208 // Get our context back
209 //
210 Status = gBS->OpenProtocol (
211 ChildHandle,
212 &gEfiSimpleTextOutProtocolGuid,
213 (VOID **) &SimpleTextOutput,
214 gTerminalDriverBinding.DriverBindingHandle,
215 ChildHandle,
216 EFI_OPEN_PROTOCOL_GET_PROTOCOL
217 );
218 if (EFI_ERROR (Status)) {
219 return EFI_UNSUPPORTED;
220 }
221
222 TerminalDevice = TERMINAL_CON_OUT_DEV_FROM_THIS (SimpleTextOutput);
223
224 return LookupUnicodeString2 (
225 Language,
226 This->SupportedLanguages,
227 TerminalDevice->ControllerNameTable,
228 ControllerName,
229 (BOOLEAN)(This == &gTerminalComponentName)
230 );
231 }
232