1 /**@file 2 3 Copyright (c) 2006, Intel Corporation. All rights reserved.<BR> 4 This program and the accompanying materials 5 are licensed and made available under the terms and conditions of the BSD License 6 which accompanies this distribution. The full text of the license may be found at 7 http://opensource.org/licenses/bsd-license.php 8 9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 12 Module Name: 13 14 ComponentName.c 15 16 Abstract: 17 18 **/ 19 20 #include "EmuBlockIo.h" 21 22 // 23 // EFI Component Name Functions 24 // 25 /** 26 Retrieves a Unicode string that is the user readable name of the driver. 27 28 This function retrieves the user readable name of a driver in the form of a 29 Unicode string. If the driver specified by This has a user readable name in 30 the language specified by Language, then a pointer to the driver name is 31 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified 32 by This does not support the language specified by Language, 33 then EFI_UNSUPPORTED is returned. 34 35 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or 36 EFI_COMPONENT_NAME_PROTOCOL instance. 37 38 @param Language[in] A pointer to a Null-terminated ASCII string 39 array indicating the language. This is the 40 language of the driver name that the caller is 41 requesting, and it must match one of the 42 languages specified in SupportedLanguages. The 43 number of languages supported by a driver is up 44 to the driver writer. Language is specified 45 in RFC 4646 or ISO 639-2 language code format. 46 47 @param DriverName[out] A pointer to the Unicode string to return. 48 This Unicode string is the name of the 49 driver specified by This in the language 50 specified by Language. 51 52 @retval EFI_SUCCESS The Unicode string for the Driver specified by 53 This and the language specified by Language was 54 returned in DriverName. 55 56 @retval EFI_INVALID_PARAMETER Language is NULL. 57 58 @retval EFI_INVALID_PARAMETER DriverName is NULL. 59 60 @retval EFI_UNSUPPORTED The driver specified by This does not support 61 the language specified by Language. 62 63 **/ 64 EFI_STATUS 65 EFIAPI 66 EmuBlockIoComponentNameGetDriverName ( 67 IN EFI_COMPONENT_NAME_PROTOCOL *This, 68 IN CHAR8 *Language, 69 OUT CHAR16 **DriverName 70 ); 71 72 73 /** 74 Retrieves a Unicode string that is the user readable name of the controller 75 that is being managed by a driver. 76 77 This function retrieves the user readable name of the controller specified by 78 ControllerHandle and ChildHandle in the form of a Unicode string. If the 79 driver specified by This has a user readable name in the language specified by 80 Language, then a pointer to the controller name is returned in ControllerName, 81 and EFI_SUCCESS is returned. If the driver specified by This is not currently 82 managing the controller specified by ControllerHandle and ChildHandle, 83 then EFI_UNSUPPORTED is returned. If the driver specified by This does not 84 support the language specified by Language, then EFI_UNSUPPORTED is returned. 85 86 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or 87 EFI_COMPONENT_NAME_PROTOCOL instance. 88 89 @param ControllerHandle[in] The handle of a controller that the driver 90 specified by This is managing. This handle 91 specifies the controller whose name is to be 92 returned. 93 94 @param ChildHandle[in] The handle of the child controller to retrieve 95 the name of. This is an optional parameter that 96 may be NULL. It will be NULL for device 97 drivers. It will also be NULL for a bus drivers 98 that wish to retrieve the name of the bus 99 controller. It will not be NULL for a bus 100 driver that wishes to retrieve the name of a 101 child controller. 102 103 @param Language[in] A pointer to a Null-terminated ASCII string 104 array indicating the language. This is the 105 language of the driver name that the caller is 106 requesting, and it must match one of the 107 languages specified in SupportedLanguages. The 108 number of languages supported by a driver is up 109 to the driver writer. Language is specified in 110 RFC 4646 or ISO 639-2 language code format. 111 112 @param ControllerName[out] A pointer to the Unicode string to return. 113 This Unicode string is the name of the 114 controller specified by ControllerHandle and 115 ChildHandle in the language specified by 116 Language from the point of view of the driver 117 specified by This. 118 119 @retval EFI_SUCCESS The Unicode string for the user readable name in 120 the language specified by Language for the 121 driver specified by This was returned in 122 DriverName. 123 124 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE. 125 126 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid 127 EFI_HANDLE. 128 129 @retval EFI_INVALID_PARAMETER Language is NULL. 130 131 @retval EFI_INVALID_PARAMETER ControllerName is NULL. 132 133 @retval EFI_UNSUPPORTED The driver specified by This is not currently 134 managing the controller specified by 135 ControllerHandle and ChildHandle. 136 137 @retval EFI_UNSUPPORTED The driver specified by This does not support 138 the language specified by Language. 139 140 **/ 141 EFI_STATUS 142 EFIAPI 143 EmuBlockIoComponentNameGetControllerName ( 144 IN EFI_COMPONENT_NAME_PROTOCOL *This, 145 IN EFI_HANDLE ControllerHandle, 146 IN EFI_HANDLE ChildHandle OPTIONAL, 147 IN CHAR8 *Language, 148 OUT CHAR16 **ControllerName 149 ); 150 151 // 152 // EFI Component Name Protocol 153 // 154 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gEmuBlockIoComponentName = { 155 EmuBlockIoComponentNameGetDriverName, 156 EmuBlockIoComponentNameGetControllerName, 157 "eng" 158 }; 159 160 // 161 // EFI Component Name 2 Protocol 162 // 163 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gEmuBlockIoComponentName2 = { 164 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) EmuBlockIoComponentNameGetDriverName, 165 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) EmuBlockIoComponentNameGetControllerName, 166 "en" 167 }; 168 169 170 EFI_UNICODE_STRING_TABLE mEmuBlockIoDriverNameTable[] = { 171 { "eng;en", L"Emu Block I/O Driver" }, 172 { NULL , NULL } 173 }; 174 175 /** 176 Retrieves a Unicode string that is the user readable name of the driver. 177 178 This function retrieves the user readable name of a driver in the form of a 179 Unicode string. If the driver specified by This has a user readable name in 180 the language specified by Language, then a pointer to the driver name is 181 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified 182 by This does not support the language specified by Language, 183 then EFI_UNSUPPORTED is returned. 184 185 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or 186 EFI_COMPONENT_NAME_PROTOCOL instance. 187 188 @param Language[in] A pointer to a Null-terminated ASCII string 189 array indicating the language. This is the 190 language of the driver name that the caller is 191 requesting, and it must match one of the 192 languages specified in SupportedLanguages. The 193 number of languages supported by a driver is up 194 to the driver writer. Language is specified 195 in RFC 4646 or ISO 639-2 language code format. 196 197 @param DriverName[out] A pointer to the Unicode string to return. 198 This Unicode string is the name of the 199 driver specified by This in the language 200 specified by Language. 201 202 @retval EFI_SUCCESS The Unicode string for the Driver specified by 203 This and the language specified by Language was 204 returned in DriverName. 205 206 @retval EFI_INVALID_PARAMETER Language is NULL. 207 208 @retval EFI_INVALID_PARAMETER DriverName is NULL. 209 210 @retval EFI_UNSUPPORTED The driver specified by This does not support 211 the language specified by Language. 212 213 **/ 214 EFI_STATUS 215 EFIAPI 216 EmuBlockIoComponentNameGetDriverName ( 217 IN EFI_COMPONENT_NAME_PROTOCOL *This, 218 IN CHAR8 *Language, 219 OUT CHAR16 **DriverName 220 ) 221 { 222 return LookupUnicodeString2 ( 223 Language, 224 This->SupportedLanguages, 225 mEmuBlockIoDriverNameTable, 226 DriverName, 227 (BOOLEAN)(This == &gEmuBlockIoComponentName) 228 ); 229 } 230 231 /** 232 Retrieves a Unicode string that is the user readable name of the controller 233 that is being managed by a driver. 234 235 This function retrieves the user readable name of the controller specified by 236 ControllerHandle and ChildHandle in the form of a Unicode string. If the 237 driver specified by This has a user readable name in the language specified by 238 Language, then a pointer to the controller name is returned in ControllerName, 239 and EFI_SUCCESS is returned. If the driver specified by This is not currently 240 managing the controller specified by ControllerHandle and ChildHandle, 241 then EFI_UNSUPPORTED is returned. If the driver specified by This does not 242 support the language specified by Language, then EFI_UNSUPPORTED is returned. 243 244 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or 245 EFI_COMPONENT_NAME_PROTOCOL instance. 246 247 @param ControllerHandle[in] The handle of a controller that the driver 248 specified by This is managing. This handle 249 specifies the controller whose name is to be 250 returned. 251 252 @param ChildHandle[in] The handle of the child controller to retrieve 253 the name of. This is an optional parameter that 254 may be NULL. It will be NULL for device 255 drivers. It will also be NULL for a bus drivers 256 that wish to retrieve the name of the bus 257 controller. It will not be NULL for a bus 258 driver that wishes to retrieve the name of a 259 child controller. 260 261 @param Language[in] A pointer to a Null-terminated ASCII string 262 array indicating the language. This is the 263 language of the driver name that the caller is 264 requesting, and it must match one of the 265 languages specified in SupportedLanguages. The 266 number of languages supported by a driver is up 267 to the driver writer. Language is specified in 268 RFC 4646 or ISO 639-2 language code format. 269 270 @param ControllerName[out] A pointer to the Unicode string to return. 271 This Unicode string is the name of the 272 controller specified by ControllerHandle and 273 ChildHandle in the language specified by 274 Language from the point of view of the driver 275 specified by This. 276 277 @retval EFI_SUCCESS The Unicode string for the user readable name in 278 the language specified by Language for the 279 driver specified by This was returned in 280 DriverName. 281 282 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE. 283 284 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid 285 EFI_HANDLE. 286 287 @retval EFI_INVALID_PARAMETER Language is NULL. 288 289 @retval EFI_INVALID_PARAMETER ControllerName is NULL. 290 291 @retval EFI_UNSUPPORTED The driver specified by This is not currently 292 managing the controller specified by 293 ControllerHandle and ChildHandle. 294 295 @retval EFI_UNSUPPORTED The driver specified by This does not support 296 the language specified by Language. 297 298 **/ 299 EFI_STATUS 300 EFIAPI 301 EmuBlockIoComponentNameGetControllerName ( 302 IN EFI_COMPONENT_NAME_PROTOCOL *This, 303 IN EFI_HANDLE ControllerHandle, 304 IN EFI_HANDLE ChildHandle OPTIONAL, 305 IN CHAR8 *Language, 306 OUT CHAR16 **ControllerName 307 ) 308 { 309 EFI_STATUS Status; 310 EFI_BLOCK_IO_PROTOCOL *BlockIo; 311 EMU_BLOCK_IO_PRIVATE *Private; 312 313 // 314 // This is a device driver, so ChildHandle must be NULL. 315 // 316 if (ChildHandle != NULL) { 317 return EFI_UNSUPPORTED; 318 } 319 // 320 // Make sure this driver is currently managing ControllerHandle 321 // 322 Status = EfiTestManagedDevice ( 323 ControllerHandle, 324 gEmuBlockIoDriverBinding.DriverBindingHandle, 325 &gEmuIoThunkProtocolGuid 326 ); 327 if (EFI_ERROR (Status)) { 328 return EFI_UNSUPPORTED; 329 } 330 // 331 // Get our context back 332 // 333 Status = gBS->OpenProtocol ( 334 ControllerHandle, 335 &gEfiBlockIoProtocolGuid, 336 (VOID **)&BlockIo, 337 gEmuBlockIoDriverBinding.DriverBindingHandle, 338 ControllerHandle, 339 EFI_OPEN_PROTOCOL_GET_PROTOCOL 340 ); 341 if (EFI_ERROR (Status)) { 342 return EFI_UNSUPPORTED; 343 } 344 345 Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (BlockIo); 346 347 return LookupUnicodeString2 ( 348 Language, 349 This->SupportedLanguages, 350 Private->ControllerNameTable, 351 ControllerName, 352 (BOOLEAN)(This == &gEmuBlockIoComponentName) 353 ); 354 } 355