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