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