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