]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Bus/Isa/IsaFloppyDxe/ComponentName.c
IntelFrameworkModulePkg IsaFloppyDxe: Use safe string functions
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Isa / IsaFloppyDxe / ComponentName.c
CommitLineData
d6321d6e 1/** @file\r
2 UEFI Component Name(2) protocol implementation for Isa Floppy driver.\r
11f43dfd 3\r
35e471db 4Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
180a5a35 5This program and the accompanying materials\r
f8cd287b 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
6db49ee6 9\r
f8cd287b 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
11f43dfd 12\r
f8cd287b 13**/\r
11f43dfd 14\r
15#include "IsaFloppy.h"\r
16\r
17//\r
18// EFI Component Name Protocol\r
19//\r
1307dcd7 20GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gIsaFloppyComponentName = {\r
11f43dfd 21 IsaFloppyComponentNameGetDriverName,\r
22 IsaFloppyComponentNameGetControllerName,\r
23 "eng"\r
1307dcd7 24};\r
f3d08ccf 25\r
26//\r
27// EFI Component Name 2 Protocol\r
28//\r
1307dcd7 29GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gIsaFloppyComponentName2 = {\r
f3d08ccf 30 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) IsaFloppyComponentNameGetDriverName,\r
31 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) IsaFloppyComponentNameGetControllerName,\r
32 "en"\r
1307dcd7 33};\r
f3d08ccf 34\r
11f43dfd 35\r
d1aeb0bd 36GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mIsaFloppyDriverNameTable[] = {\r
11f43dfd 37 {\r
f3d08ccf 38 "eng;en",\r
11f43dfd 39 L"ISA Floppy Driver"\r
40 },\r
41 {\r
42 NULL,\r
43 NULL\r
44 }\r
45};\r
46\r
f3d08ccf 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
d6321d6e 57 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
f3d08ccf 58 EFI_COMPONENT_NAME_PROTOCOL instance.\r
d6321d6e 59 @param[in] Language A pointer to a Null-terminated ASCII string\r
f3d08ccf 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
4bca47e1 66 in RFC 4646 or ISO 639-2 language code format.\r
d6321d6e 67 @param[out] DriverName A pointer to the Unicode string to return.\r
f3d08ccf 68 This Unicode string is the name of the\r
69 driver specified by This in the language\r
70 specified by Language.\r
f3d08ccf 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
f3d08ccf 76 @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
f3d08ccf 77 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
78 the language specified by Language.\r
f3d08ccf 79**/\r
11f43dfd 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
11f43dfd 87{\r
f3d08ccf 88 return LookupUnicodeString2 (\r
11f43dfd 89 Language,\r
f3d08ccf 90 This->SupportedLanguages,\r
11f43dfd 91 mIsaFloppyDriverNameTable,\r
f3d08ccf 92 DriverName,\r
93 (BOOLEAN)(This == &gIsaFloppyComponentName)\r
11f43dfd 94 );\r
95}\r
96\r
f3d08ccf 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
d6321d6e 110 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
f3d08ccf 111 EFI_COMPONENT_NAME_PROTOCOL instance.\r
d6321d6e 112 @param[in] ControllerHandle The handle of a controller that the driver\r
f3d08ccf 113 specified by This is managing. This handle\r
114 specifies the controller whose name is to be\r
115 returned.\r
d6321d6e 116 @param[in] ChildHandle The handle of the child controller to retrieve\r
f3d08ccf 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
d6321d6e 124 @param[in] Language A pointer to a Null-terminated ASCII string\r
f3d08ccf 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
4bca47e1 131 RFC 4646 or ISO 639-2 language code format.\r
d6321d6e 132 @param[out] ControllerName A pointer to the Unicode string to return.\r
f3d08ccf 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
c2d9a4d2 143 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
f3d08ccf 144 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
145 EFI_HANDLE.\r
f3d08ccf 146 @retval EFI_INVALID_PARAMETER Language is NULL.\r
f3d08ccf 147 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
f3d08ccf 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
f3d08ccf 151 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
152 the language specified by Language.\r
f3d08ccf 153**/\r
11f43dfd 154EFI_STATUS\r
155EFIAPI\r
156IsaFloppyComponentNameGetControllerName (\r
d6321d6e 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
11f43dfd 162 )\r
11f43dfd 163{\r
d6321d6e 164 EFI_STATUS Status;\r
165 EFI_BLOCK_IO_PROTOCOL *BlkIo;\r
166 FDC_BLK_IO_DEV *FdcDev;\r
11f43dfd 167\r
d6321d6e 168 if (Language == NULL || ControllerName == NULL) {\r
169 return EFI_INVALID_PARAMETER;\r
170 }\r
11f43dfd 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
d6321d6e 177\r
11f43dfd 178 //\r
d6321d6e 179 // Check if this driver is currently managing ControllerHandle\r
11f43dfd 180 //\r
d6321d6e 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
11f43dfd 188 }\r
189\r
11f43dfd 190 //\r
d6321d6e 191 // Get the device context\r
11f43dfd 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
d6321d6e 204\r
11f43dfd 205 FdcDev = FDD_BLK_IO_FROM_THIS (BlkIo);\r
206\r
f3d08ccf 207 return LookupUnicodeString2 (\r
11f43dfd 208 Language,\r
f3d08ccf 209 This->SupportedLanguages,\r
11f43dfd 210 FdcDev->ControllerNameTable,\r
f3d08ccf 211 ControllerName,\r
212 (BOOLEAN)(This == &gIsaFloppyComponentName)\r
11f43dfd 213 );\r
214}\r
215\r
bcd70414 216/**\r
217 Add the component name for the floppy device\r
218\r
d6321d6e 219 @param[in] FdcDev A pointer to the FDC_BLK_IO_DEV instance.\r
bcd70414 220\r
221**/\r
11f43dfd 222VOID\r
223AddName (\r
d6321d6e 224 IN FDC_BLK_IO_DEV *FdcDev\r
11f43dfd 225 )\r
11f43dfd 226{\r
d6321d6e 227 CHAR16 FloppyDriveName[FLOPPY_DRIVE_NAME_LEN + 1];\r
228\r
229 if (!(FeaturePcdGet(PcdComponentNameDisable) && FeaturePcdGet(PcdComponentName2Disable))) {\r
35e471db 230 StrCpyS (FloppyDriveName, FLOPPY_DRIVE_NAME_LEN + 1, FLOPPY_DRIVE_NAME);\r
d6321d6e 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
11f43dfd 248}\r
bcd70414 249\r