]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - IntelFrameworkModulePkg/Bus/Isa/IsaFloppyDxe/ComponentName.c
IntelFrameworkModulePkg IsaFloppyDxe: Use safe string functions
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Isa / IsaFloppyDxe / ComponentName.c
... / ...
CommitLineData
1/** @file\r
2 UEFI Component Name(2) protocol implementation for Isa Floppy driver.\r
3\r
4Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "IsaFloppy.h"\r
16\r
17//\r
18// EFI Component Name Protocol\r
19//\r
20GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gIsaFloppyComponentName = {\r
21 IsaFloppyComponentNameGetDriverName,\r
22 IsaFloppyComponentNameGetControllerName,\r
23 "eng"\r
24};\r
25\r
26//\r
27// EFI Component Name 2 Protocol\r
28//\r
29GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gIsaFloppyComponentName2 = {\r
30 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) IsaFloppyComponentNameGetDriverName,\r
31 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) IsaFloppyComponentNameGetControllerName,\r
32 "en"\r
33};\r
34\r
35\r
36GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mIsaFloppyDriverNameTable[] = {\r
37 {\r
38 "eng;en",\r
39 L"ISA Floppy Driver"\r
40 },\r
41 {\r
42 NULL,\r
43 NULL\r
44 }\r
45};\r
46\r
47/**\r
48 Retrieves a Unicode string that is the user readable name of the driver.\r
49\r
50 This function retrieves the user readable name of a driver in the form of a\r
51 Unicode string. If the driver specified by This has a user readable name in\r
52 the language specified by Language, then a pointer to the driver name is\r
53 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
54 by This does not support the language specified by Language,\r
55 then EFI_UNSUPPORTED is returned.\r
56\r
57 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
58 EFI_COMPONENT_NAME_PROTOCOL instance.\r
59 @param[in] Language A pointer to a Null-terminated ASCII string\r
60 array indicating the language. This is the\r
61 language of the driver name that the caller is\r
62 requesting, and it must match one of the\r
63 languages specified in SupportedLanguages. The\r
64 number of languages supported by a driver is up\r
65 to the driver writer. Language is specified\r
66 in RFC 4646 or ISO 639-2 language code format.\r
67 @param[out] DriverName A pointer to the Unicode string to return.\r
68 This Unicode string is the name of the\r
69 driver specified by This in the language\r
70 specified by Language.\r
71 @retval EFI_SUCCESS The Unicode string for the Driver specified by\r
72 This and the language specified by Language was\r
73 returned in DriverName.\r
74\r
75 @retval EFI_INVALID_PARAMETER Language is NULL.\r
76 @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
77 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
78 the language specified by Language.\r
79**/\r
80EFI_STATUS\r
81EFIAPI\r
82IsaFloppyComponentNameGetDriverName (\r
83 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
84 IN CHAR8 *Language,\r
85 OUT CHAR16 **DriverName\r
86 )\r
87{\r
88 return LookupUnicodeString2 (\r
89 Language,\r
90 This->SupportedLanguages,\r
91 mIsaFloppyDriverNameTable,\r
92 DriverName,\r
93 (BOOLEAN)(This == &gIsaFloppyComponentName)\r
94 );\r
95}\r
96\r
97/**\r
98 Retrieves a Unicode string that is the user readable name of the controller\r
99 that is being managed by a driver.\r
100\r
101 This function retrieves the user readable name of the controller specified by\r
102 ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
103 driver specified by This has a user readable name in the language specified by\r
104 Language, then a pointer to the controller name is returned in ControllerName,\r
105 and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
106 managing the controller specified by ControllerHandle and ChildHandle,\r
107 then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
108 support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
109\r
110 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
111 EFI_COMPONENT_NAME_PROTOCOL instance.\r
112 @param[in] ControllerHandle The handle of a controller that the driver\r
113 specified by This is managing. This handle\r
114 specifies the controller whose name is to be\r
115 returned.\r
116 @param[in] ChildHandle The handle of the child controller to retrieve\r
117 the name of. This is an optional parameter that\r
118 may be NULL. It will be NULL for device\r
119 drivers. It will also be NULL for a bus drivers\r
120 that wish to retrieve the name of the bus\r
121 controller. It will not be NULL for a bus\r
122 driver that wishes to retrieve the name of a\r
123 child controller.\r
124 @param[in] Language A pointer to a Null-terminated ASCII string\r
125 array indicating the language. This is the\r
126 language of the driver name that the caller is\r
127 requesting, and it must match one of the\r
128 languages specified in SupportedLanguages. The\r
129 number of languages supported by a driver is up\r
130 to the driver writer. Language is specified in\r
131 RFC 4646 or ISO 639-2 language code format.\r
132 @param[out] ControllerName A pointer to the Unicode string to return.\r
133 This Unicode string is the name of the\r
134 controller specified by ControllerHandle and\r
135 ChildHandle in the language specified by\r
136 Language from the point of view of the driver\r
137 specified by This.\r
138\r
139 @retval EFI_SUCCESS The Unicode string for the user readable name in\r
140 the language specified by Language for the\r
141 driver specified by This was returned in\r
142 DriverName.\r
143 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
144 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
145 EFI_HANDLE.\r
146 @retval EFI_INVALID_PARAMETER Language is NULL.\r
147 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
148 @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
149 managing the controller specified by\r
150 ControllerHandle and ChildHandle.\r
151 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
152 the language specified by Language.\r
153**/\r
154EFI_STATUS\r
155EFIAPI\r
156IsaFloppyComponentNameGetControllerName (\r
157 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
158 IN EFI_HANDLE ControllerHandle,\r
159 IN EFI_HANDLE ChildHandle OPTIONAL,\r
160 IN CHAR8 *Language,\r
161 OUT CHAR16 **ControllerName\r
162 )\r
163{\r
164 EFI_STATUS Status;\r
165 EFI_BLOCK_IO_PROTOCOL *BlkIo;\r
166 FDC_BLK_IO_DEV *FdcDev;\r
167\r
168 if (Language == NULL || ControllerName == NULL) {\r
169 return EFI_INVALID_PARAMETER;\r
170 }\r
171 //\r
172 // This is a device driver, so ChildHandle must be NULL.\r
173 //\r
174 if (ChildHandle != NULL) {\r
175 return EFI_UNSUPPORTED;\r
176 }\r
177\r
178 //\r
179 // Check if this driver is currently managing ControllerHandle\r
180 //\r
181 Status = EfiTestManagedDevice (\r
182 ControllerHandle,\r
183 gFdcControllerDriver.DriverBindingHandle,\r
184 &gEfiIsaIoProtocolGuid\r
185 );\r
186 if (EFI_ERROR (Status)) {\r
187 return Status;\r
188 }\r
189\r
190 //\r
191 // Get the device context\r
192 //\r
193 Status = gBS->OpenProtocol (\r
194 ControllerHandle,\r
195 &gEfiBlockIoProtocolGuid,\r
196 (VOID **) &BlkIo,\r
197 gFdcControllerDriver.DriverBindingHandle,\r
198 ControllerHandle,\r
199 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
200 );\r
201 if (EFI_ERROR (Status)) {\r
202 return Status;\r
203 }\r
204\r
205 FdcDev = FDD_BLK_IO_FROM_THIS (BlkIo);\r
206\r
207 return LookupUnicodeString2 (\r
208 Language,\r
209 This->SupportedLanguages,\r
210 FdcDev->ControllerNameTable,\r
211 ControllerName,\r
212 (BOOLEAN)(This == &gIsaFloppyComponentName)\r
213 );\r
214}\r
215\r
216/**\r
217 Add the component name for the floppy device\r
218\r
219 @param[in] FdcDev A pointer to the FDC_BLK_IO_DEV instance.\r
220\r
221**/\r
222VOID\r
223AddName (\r
224 IN FDC_BLK_IO_DEV *FdcDev\r
225 )\r
226{\r
227 CHAR16 FloppyDriveName[FLOPPY_DRIVE_NAME_LEN + 1];\r
228\r
229 if (!(FeaturePcdGet(PcdComponentNameDisable) && FeaturePcdGet(PcdComponentName2Disable))) {\r
230 StrCpyS (FloppyDriveName, FLOPPY_DRIVE_NAME_LEN + 1, FLOPPY_DRIVE_NAME);\r
231 FloppyDriveName[FLOPPY_DRIVE_NAME_LEN - 1] = (CHAR16) (L'0' + FdcDev->Disk);\r
232\r
233 AddUnicodeString2 (\r
234 "eng",\r
235 gIsaFloppyComponentName.SupportedLanguages,\r
236 &FdcDev->ControllerNameTable,\r
237 FloppyDriveName,\r
238 TRUE\r
239 );\r
240 AddUnicodeString2 (\r
241 "en",\r
242 gIsaFloppyComponentName2.SupportedLanguages,\r
243 &FdcDev->ControllerNameTable,\r
244 FloppyDriveName,\r
245 FALSE\r
246 );\r
247 }\r
248}\r
249\r