Vijay Kumar Pendoti | 78b1a96 | 2017-01-12 22:48:41 +0530 | [diff] [blame^] | 1 | /* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved. |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 2 | * |
| 3 | * Redistribution and use in source and binary forms, with or without |
| 4 | * modification, are permitted provided that the following conditions are |
| 5 | * met: |
| 6 | * * Redistributions of source code must retain the above copyright |
| 7 | * notice, this list of conditions and the following disclaimer. |
| 8 | * * Redistributions in binary form must reproduce the above |
| 9 | * copyright notice, this list of conditions and the following |
| 10 | * disclaimer in the documentation and/or other materials provided |
| 11 | * with the distribution. |
| 12 | * * Neither the name of The Linux Foundation nor the names of its |
| 13 | * contributors may be used to endorse or promote products derived |
| 14 | * from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 23 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 25 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 26 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #include <Board.h> |
| 30 | #include <Protocol/EFICardInfo.h> |
lijuang | 834ebd2 | 2016-09-07 18:27:29 +0800 | [diff] [blame] | 31 | #include <Protocol/EFIPlatformInfoTypes.h> |
lijuang | 24de534 | 2016-09-07 18:09:10 +0800 | [diff] [blame] | 32 | #include <Library/UpdateDeviceTree.h> |
lijuang | 6a97bc5 | 2016-10-18 17:32:54 +0800 | [diff] [blame] | 33 | #include <Library/BootImage.h> |
| 34 | |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 35 | #include <LinuxLoaderLib.h> |
| 36 | |
Channagoud Kadabi | 539d307 | 2016-02-11 21:34:48 -0800 | [diff] [blame] | 37 | STATIC struct BoardInfo platform_board_info; |
| 38 | |
lijuang | 24de534 | 2016-09-07 18:09:10 +0800 | [diff] [blame] | 39 | STATIC CONST CHAR8 *DeviceType[] = { |
| 40 | [EMMC] = "EMMC", |
| 41 | [UFS] = "UFS", |
| 42 | [UNKNOWN] = "Unknown", |
| 43 | }; |
| 44 | |
Vijay Kumar Pendoti | c52e80b | 2016-10-12 16:47:50 +0530 | [diff] [blame] | 45 | EFI_STATUS GetRamPartitions(RamPartitionEntry **RamPartitions, UINT32 *NumPartitions) { |
| 46 | |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 47 | EFI_STATUS Status = EFI_NOT_FOUND; |
| 48 | EFI_RAMPARTITION_PROTOCOL *pRamPartProtocol = NULL; |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 49 | |
| 50 | Status = gBS->LocateProtocol(&gEfiRamPartitionProtocolGuid, NULL, (VOID**)&pRamPartProtocol); |
| 51 | if (EFI_ERROR(Status) || (&pRamPartProtocol == NULL)) |
| 52 | { |
| 53 | DEBUG((EFI_D_ERROR, "Locate EFI_RAMPARTITION_Protocol failed, Status = (0x%x)\r\n", Status)); |
| 54 | return EFI_NOT_FOUND; |
| 55 | } |
Vijay Kumar Pendoti | c52e80b | 2016-10-12 16:47:50 +0530 | [diff] [blame] | 56 | Status = pRamPartProtocol->GetRamPartitions (pRamPartProtocol, NULL, NumPartitions); |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 57 | if (Status == EFI_BUFFER_TOO_SMALL) |
| 58 | { |
Vijay Kumar Pendoti | c52e80b | 2016-10-12 16:47:50 +0530 | [diff] [blame] | 59 | *RamPartitions = AllocatePool (*NumPartitions * sizeof (RamPartitionEntry)); |
lijuang | a4c1b08 | 2016-12-08 19:12:48 +0800 | [diff] [blame] | 60 | if (*RamPartitions == NULL) |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 61 | return EFI_OUT_OF_RESOURCES; |
| 62 | |
Vijay Kumar Pendoti | c52e80b | 2016-10-12 16:47:50 +0530 | [diff] [blame] | 63 | Status = pRamPartProtocol->GetRamPartitions (pRamPartProtocol, *RamPartitions, NumPartitions); |
| 64 | if (EFI_ERROR (Status) || (*NumPartitions < 1) ) |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 65 | { |
| 66 | DEBUG((EFI_D_ERROR, "Failed to get RAM partitions")); |
| 67 | return EFI_NOT_FOUND; |
| 68 | } |
Vijay Kumar Pendoti | c52e80b | 2016-10-12 16:47:50 +0530 | [diff] [blame] | 69 | } else { |
| 70 | DEBUG((EFI_D_ERROR, "Error Occured while populating RamPartitions\n")); |
| 71 | return EFI_PROTOCOL_ERROR; |
| 72 | } |
| 73 | return Status; |
| 74 | } |
| 75 | |
lijuang | 9410995 | 2016-10-28 19:33:55 +0800 | [diff] [blame] | 76 | EFI_STATUS BaseMem(UINT64 *BaseMemory) |
Vijay Kumar Pendoti | c52e80b | 2016-10-12 16:47:50 +0530 | [diff] [blame] | 77 | { |
| 78 | EFI_STATUS Status = EFI_NOT_FOUND; |
| 79 | RamPartitionEntry *RamPartitions = NULL; |
| 80 | UINT32 NumPartitions = 0; |
lijuang | 9410995 | 2016-10-28 19:33:55 +0800 | [diff] [blame] | 81 | UINT64 SmallestBase; |
Vijay Kumar Pendoti | c52e80b | 2016-10-12 16:47:50 +0530 | [diff] [blame] | 82 | UINT32 i = 0; |
| 83 | |
| 84 | Status = GetRamPartitions(&RamPartitions, &NumPartitions); |
| 85 | if (EFI_ERROR (Status)) { |
| 86 | DEBUG((EFI_D_ERROR, "Error returned from GetRamPartitions %r\n",Status)); |
| 87 | return Status; |
| 88 | } |
| 89 | if (!RamPartitions) { |
| 90 | DEBUG((EFI_D_ERROR, "RamPartitions is NULL\n")); |
| 91 | return EFI_NOT_FOUND; |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 92 | } |
| 93 | SmallestBase = RamPartitions[0].Base; |
| 94 | for (i = 0; i < NumPartitions; i++) |
| 95 | { |
| 96 | if (SmallestBase > RamPartitions[i].Base) |
| 97 | SmallestBase = RamPartitions[i].Base; |
| 98 | } |
| 99 | *BaseMemory = SmallestBase; |
Vijay Kumar Pendoti | df4a1d4 | 2016-10-12 16:55:54 +0530 | [diff] [blame] | 100 | DEBUG((EFI_D_INFO, "Memory Base Address: 0x%x\n", *BaseMemory)); |
Vijay Kumar Pendoti | c52e80b | 2016-10-12 16:47:50 +0530 | [diff] [blame] | 101 | FreePool(RamPartitions); |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 102 | |
Vijay Kumar Pendoti | c52e80b | 2016-10-12 16:47:50 +0530 | [diff] [blame] | 103 | return Status; |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | STATIC EFI_STATUS GetChipInfo(struct BoardInfo *platform_board_info) |
| 107 | { |
| 108 | EFI_STATUS Status; |
| 109 | EFI_CHIPINFO_PROTOCOL *pChipInfoProtocol; |
| 110 | Status = gBS->LocateProtocol (&gEfiChipInfoProtocolGuid, NULL,(VOID **) &pChipInfoProtocol); |
| 111 | if (EFI_ERROR(Status)) |
| 112 | return Status; |
| 113 | Status = pChipInfoProtocol->GetChipId(pChipInfoProtocol, &platform_board_info->RawChipId); |
| 114 | if (EFI_ERROR(Status)) |
| 115 | return Status; |
| 116 | Status = pChipInfoProtocol->GetChipVersion(pChipInfoProtocol, &platform_board_info->ChipVersion); |
| 117 | if (EFI_ERROR(Status)) |
| 118 | return Status; |
| 119 | Status = pChipInfoProtocol->GetFoundryId(pChipInfoProtocol, &platform_board_info->FoundryId); |
| 120 | if (EFI_ERROR(Status)) |
| 121 | return Status; |
lijuang | 2120d97 | 2016-11-02 18:28:21 +0800 | [diff] [blame] | 122 | Status = pChipInfoProtocol->GetChipIdString(pChipInfoProtocol, platform_board_info->ChipBaseBand, EFICHIPINFO_MAX_ID_LENGTH); |
Vijay Kumar Pendoti | 582158c | 2016-09-29 23:47:37 +0530 | [diff] [blame] | 123 | if (EFI_ERROR(Status)) |
| 124 | return Status; |
Channagoud Kadabi | 539d307 | 2016-02-11 21:34:48 -0800 | [diff] [blame] | 125 | DEBUG((EFI_D_VERBOSE, "Raw Chip Id : 0x%x\n", platform_board_info->RawChipId)); |
| 126 | DEBUG((EFI_D_VERBOSE, "Chip Version : 0x%x\n", platform_board_info->ChipVersion)); |
| 127 | DEBUG((EFI_D_VERBOSE, "Foundry Id : 0x%x\n", platform_board_info->FoundryId)); |
Vijay Kumar Pendoti | 582158c | 2016-09-29 23:47:37 +0530 | [diff] [blame] | 128 | DEBUG((EFI_D_VERBOSE, "Chip BaseBand : %a\n", platform_board_info->ChipBaseBand)); |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 129 | return Status; |
| 130 | } |
| 131 | |
| 132 | STATIC EFI_STATUS GetPlatformInfo(struct BoardInfo *platform_board_info) |
| 133 | { |
| 134 | EFI_STATUS eResult; |
| 135 | EFI_PLATFORMINFO_PROTOCOL *hPlatformInfoProtocol; |
| 136 | |
| 137 | eResult = gBS->LocateProtocol(&gEfiPlatformInfoProtocolGuid, NULL, (VOID **) &hPlatformInfoProtocol); |
| 138 | if (eResult != EFI_SUCCESS) |
| 139 | { |
| 140 | AsciiPrint("Error: Failed to locate PlatformInfo protocol.\n"); |
| 141 | goto endtest; |
| 142 | } |
| 143 | |
| 144 | eResult = hPlatformInfoProtocol->GetPlatformInfo(hPlatformInfoProtocol, &platform_board_info->PlatformInfo); |
| 145 | if (eResult != EFI_SUCCESS) |
| 146 | { |
| 147 | AsciiPrint("Error: GetPlatformInfo failed.\n"); |
| 148 | goto endtest; |
| 149 | } |
| 150 | |
| 151 | if (platform_board_info->PlatformInfo.platform >= EFI_PLATFORMINFO_NUM_TYPES) |
| 152 | { |
| 153 | AsciiPrint("Error: Unknown platform type (%d).\n", platform_board_info->PlatformInfo.platform); |
| 154 | eResult = EFI_PROTOCOL_ERROR; |
| 155 | goto endtest; |
| 156 | } |
| 157 | |
Vijay Kumar Pendoti | 02cd05b | 2016-07-19 17:50:54 +0530 | [diff] [blame] | 158 | DEBUG((EFI_D_VERBOSE, "Platform Info : 0x%x\n", platform_board_info->PlatformInfo.platform)); |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 159 | endtest: |
| 160 | return eResult; |
| 161 | } |
| 162 | |
Vijay Kumar Pendoti | 0be2561 | 2016-11-18 18:52:46 +0530 | [diff] [blame] | 163 | STATIC EFI_STATUS GetPmicInfoExt(UINT32 PmicDeviceIndex, EFI_PM_DEVICE_INFO_EXT_TYPE *pmic_info_ext) |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 164 | { |
| 165 | EFI_STATUS Status; |
| 166 | EFI_QCOM_PMIC_VERSION_PROTOCOL *pPmicVersionProtocol; |
Vijay Kumar Pendoti | 0be2561 | 2016-11-18 18:52:46 +0530 | [diff] [blame] | 167 | |
| 168 | Status = gBS->LocateProtocol (&gQcomPmicVersionProtocolGuid, NULL, |
| 169 | (VOID **) &pPmicVersionProtocol); |
| 170 | if (EFI_ERROR(Status)) { |
| 171 | DEBUG((EFI_D_ERROR, "Error locating pmic protocol: %r\n", Status)); |
| 172 | return Status; |
| 173 | } |
| 174 | |
| 175 | Status = pPmicVersionProtocol->GetPmicInfoExt(PmicDeviceIndex, pmic_info_ext); |
| 176 | if (EFI_ERROR(Status)) { |
| 177 | DEBUG((EFI_D_ERROR, "Error getting pmic info ext: %r\n", Status)); |
| 178 | return Status; |
| 179 | } |
| 180 | return Status; |
| 181 | } |
| 182 | |
| 183 | STATIC EFI_STATUS GetPmicInfo(UINT32 PmicDeviceIndex, EFI_PM_DEVICE_INFO_TYPE *pmic_info, UINT64 *Revision) |
| 184 | { |
| 185 | EFI_STATUS Status; |
| 186 | EFI_QCOM_PMIC_VERSION_PROTOCOL *pPmicVersionProtocol; |
| 187 | |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 188 | Status = gBS->LocateProtocol (&gQcomPmicVersionProtocolGuid, NULL, |
| 189 | (VOID **) &pPmicVersionProtocol); |
| 190 | if (EFI_ERROR(Status)) |
Channagoud Kadabi | 5bd4099 | 2016-03-04 15:05:20 -0800 | [diff] [blame] | 191 | { |
| 192 | DEBUG((EFI_D_ERROR, "Error locating pmic protocol: %r\n", Status)); |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 193 | return Status; |
Channagoud Kadabi | 5bd4099 | 2016-03-04 15:05:20 -0800 | [diff] [blame] | 194 | } |
Vijay Kumar Pendoti | 0be2561 | 2016-11-18 18:52:46 +0530 | [diff] [blame] | 195 | |
| 196 | *Revision = pPmicVersionProtocol->Revision; |
| 197 | |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 198 | Status = pPmicVersionProtocol->GetPmicInfo(PmicDeviceIndex, pmic_info); |
| 199 | if (EFI_ERROR(Status)) |
Channagoud Kadabi | 5bd4099 | 2016-03-04 15:05:20 -0800 | [diff] [blame] | 200 | { |
| 201 | DEBUG((EFI_D_ERROR, "Error getting pmic info: %r\n", Status)); |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 202 | return Status; |
Channagoud Kadabi | 5bd4099 | 2016-03-04 15:05:20 -0800 | [diff] [blame] | 203 | } |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 204 | return Status; |
| 205 | } |
| 206 | |
lijuang | 24de534 | 2016-09-07 18:09:10 +0800 | [diff] [blame] | 207 | /** |
| 208 | Return a device type |
| 209 | @param[out] HanderInfo : Pointer to array of HandleInfo structures |
| 210 | in which the output is returned. |
| 211 | @param[in, out] MaxHandles : On input, max number of handle structures |
| 212 | the buffer can hold, On output, the number |
| 213 | of handle structures returned. |
| 214 | @retval Device type : UNKNOWN|UFS|EMMC, default is UNKNOWN |
| 215 | **/ |
Jeevan Shriram | ab43668 | 2016-09-23 07:08:06 -0700 | [diff] [blame] | 216 | UINT32 CheckRootDeviceType(VOID *HanderInfo, UINT32 MaxHandles) |
lijuang | 24de534 | 2016-09-07 18:09:10 +0800 | [diff] [blame] | 217 | { |
| 218 | EFI_STATUS Status = EFI_INVALID_PARAMETER; |
| 219 | UINT32 Attribs = 0; |
| 220 | UINT32 MaxBlKIOHandles = MaxHandles; |
| 221 | PartiSelectFilter HandleFilter; |
| 222 | extern EFI_GUID gEfiEmmcUserPartitionGuid; |
| 223 | extern EFI_GUID gEfiUfsLU0Guid; |
| 224 | HandleInfo *HandleInfoList = HanderInfo; |
| 225 | MemCardType Type = UNKNOWN; |
| 226 | |
| 227 | Attribs |= BLK_IO_SEL_MATCH_ROOT_DEVICE; |
| 228 | |
| 229 | HandleFilter.PartitionType = 0; |
| 230 | HandleFilter.VolumeName = 0; |
| 231 | HandleFilter.RootDeviceType = &gEfiEmmcUserPartitionGuid; |
| 232 | |
| 233 | Status = GetBlkIOHandles(Attribs, &HandleFilter, HandleInfoList, &MaxBlKIOHandles); |
| 234 | if (EFI_ERROR (Status) || MaxBlKIOHandles == 0) { |
| 235 | MaxBlKIOHandles = MaxHandles; |
| 236 | HandleFilter.PartitionType = 0; |
| 237 | HandleFilter.VolumeName = 0; |
| 238 | HandleFilter.RootDeviceType = &gEfiUfsLU0Guid; |
| 239 | |
| 240 | Status = GetBlkIOHandles(Attribs, &HandleFilter, HandleInfoList, &MaxBlKIOHandles); |
| 241 | if (Status == EFI_SUCCESS) |
| 242 | Type = UFS; |
| 243 | } else { |
| 244 | Type = EMMC; |
| 245 | } |
| 246 | return Type; |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | Get device type |
| 251 | @param[out] StrDeviceType : Pointer to array of device type string. |
| 252 | @param[in] Len : The size of the device type string |
| 253 | **/ |
| 254 | VOID GetRootDeviceType(CHAR8 *StrDeviceType, UINT32 Len) |
| 255 | { |
| 256 | HandleInfo HandleInfoList[HANDLE_MAX_INFO_LIST]; |
| 257 | UINT32 MaxHandles = ARRAY_SIZE(HandleInfoList); |
| 258 | UINT32 Type; |
| 259 | |
| 260 | Type = CheckRootDeviceType(HandleInfoList, MaxHandles); |
| 261 | |
| 262 | if (Type < ARRAY_SIZE(DeviceType)) |
| 263 | AsciiSPrint(StrDeviceType, Len, "%a", DeviceType[Type]); |
| 264 | else |
| 265 | AsciiSPrint(StrDeviceType, Len, "%a", DeviceType[UNKNOWN]); |
| 266 | } |
| 267 | |
lijuang | 6a97bc5 | 2016-10-18 17:32:54 +0800 | [diff] [blame] | 268 | /** |
| 269 | Get device page size |
| 270 | @param[out] PageSize : Pointer to the page size. |
| 271 | **/ |
| 272 | VOID GetPageSize(UINT32 *PageSize) |
| 273 | { |
| 274 | EFI_BLOCK_IO_PROTOCOL *BlkIo = NULL; |
| 275 | HandleInfo HandleInfoList[HANDLE_MAX_INFO_LIST]; |
| 276 | UINT32 MaxHandles = ARRAY_SIZE(HandleInfoList); |
| 277 | UINT32 Type; |
| 278 | |
| 279 | Type = CheckRootDeviceType(HandleInfoList, MaxHandles); |
| 280 | switch (Type) { |
| 281 | case EMMC: |
| 282 | *PageSize = BOOT_IMG_EMMC_PAGE_SIZE; |
| 283 | break; |
| 284 | case UFS: |
| 285 | BlkIo = HandleInfoList[0].BlkIo; |
| 286 | *PageSize = BlkIo->Media->BlockSize; |
| 287 | break; |
| 288 | default: |
| 289 | *PageSize = BOOT_IMG_MAX_PAGE_SIZE; |
| 290 | break; |
| 291 | } |
| 292 | } |
| 293 | |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 294 | UINT32 BoardPmicModel(UINT32 PmicDeviceIndex) |
| 295 | { |
Channagoud Kadabi | 5bd4099 | 2016-03-04 15:05:20 -0800 | [diff] [blame] | 296 | EFI_STATUS Status; |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 297 | EFI_PM_DEVICE_INFO_TYPE pmic_info; |
Vijay Kumar Pendoti | 0be2561 | 2016-11-18 18:52:46 +0530 | [diff] [blame] | 298 | UINT64 Revision; |
| 299 | |
| 300 | Status = GetPmicInfo(PmicDeviceIndex, &pmic_info, &Revision); |
Channagoud Kadabi | 5bd4099 | 2016-03-04 15:05:20 -0800 | [diff] [blame] | 301 | if (Status != EFI_SUCCESS) |
| 302 | { |
| 303 | DEBUG((EFI_D_ERROR, "Error getting pmic model info: %r\n", Status)); |
| 304 | ASSERT(0); |
| 305 | } |
| 306 | DEBUG((EFI_D_VERBOSE, "PMIC Model 0x%x: 0x%x\n", PmicDeviceIndex, pmic_info.PmicModel)); |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 307 | return pmic_info.PmicModel; |
| 308 | } |
| 309 | |
| 310 | UINT32 BoardPmicTarget(UINT32 PmicDeviceIndex) |
| 311 | { |
| 312 | UINT32 target; |
Channagoud Kadabi | 5bd4099 | 2016-03-04 15:05:20 -0800 | [diff] [blame] | 313 | EFI_STATUS Status; |
Vijay Kumar Pendoti | 0be2561 | 2016-11-18 18:52:46 +0530 | [diff] [blame] | 314 | UINT64 Revision; |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 315 | EFI_PM_DEVICE_INFO_TYPE pmic_info; |
Vijay Kumar Pendoti | 0be2561 | 2016-11-18 18:52:46 +0530 | [diff] [blame] | 316 | EFI_PM_DEVICE_INFO_EXT_TYPE pmic_info_ext; |
| 317 | |
| 318 | Status = GetPmicInfo(PmicDeviceIndex, &pmic_info, &Revision); |
Channagoud Kadabi | 5bd4099 | 2016-03-04 15:05:20 -0800 | [diff] [blame] | 319 | if (Status != EFI_SUCCESS) |
| 320 | { |
| 321 | DEBUG((EFI_D_ERROR, "Error finding board pmic info: %r\n", Status)); |
| 322 | ASSERT(0); |
| 323 | } |
Vijay Kumar Pendoti | 0be2561 | 2016-11-18 18:52:46 +0530 | [diff] [blame] | 324 | |
| 325 | if (Revision >= PMIC_VERSION_REVISION) { |
| 326 | Status = GetPmicInfoExt(PmicDeviceIndex, &pmic_info_ext); |
| 327 | if (Status != EFI_SUCCESS) { |
| 328 | DEBUG((EFI_D_ERROR, "Error finding board pmic info: %r\n", Status)); |
| 329 | return 0; |
| 330 | } |
| 331 | |
| 332 | target = (pmic_info_ext.PmicVariantRevision << 24 ) | (pmic_info_ext.PmicAllLayerRevision << 16) | |
| 333 | (pmic_info_ext.PmicMetalRevision << 8) | pmic_info_ext.PmicModel; |
| 334 | } else { |
| 335 | target = (pmic_info.PmicAllLayerRevision << 16) | (pmic_info.PmicMetalRevision << 8) | pmic_info.PmicModel; |
| 336 | } |
| 337 | |
Channagoud Kadabi | 5bd4099 | 2016-03-04 15:05:20 -0800 | [diff] [blame] | 338 | DEBUG((EFI_D_VERBOSE, "PMIC Target 0x%x: 0x%x\n", PmicDeviceIndex, target)); |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 339 | return target; |
| 340 | } |
| 341 | |
Channagoud Kadabi | 539d307 | 2016-02-11 21:34:48 -0800 | [diff] [blame] | 342 | EFI_STATUS BoardInit() |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 343 | { |
| 344 | EFI_STATUS Status; |
Channagoud Kadabi | 539d307 | 2016-02-11 21:34:48 -0800 | [diff] [blame] | 345 | Status = GetChipInfo(&platform_board_info); |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 346 | if (EFI_ERROR(Status)) |
| 347 | return Status; |
Channagoud Kadabi | 539d307 | 2016-02-11 21:34:48 -0800 | [diff] [blame] | 348 | Status = GetPlatformInfo(&platform_board_info); |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 349 | if (EFI_ERROR(Status)) |
| 350 | return Status; |
Channagoud Kadabi | 539d307 | 2016-02-11 21:34:48 -0800 | [diff] [blame] | 351 | |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 352 | return Status; |
| 353 | } |
| 354 | |
Vijay Kumar Pendoti | 09d572e | 2016-08-27 03:22:36 +0530 | [diff] [blame] | 355 | EFI_STATUS UfsGetSetBootLun(UINT32 *UfsBootlun, BOOLEAN IsGet) |
| 356 | { |
| 357 | EFI_STATUS Status = EFI_INVALID_PARAMETER; |
Vijay Kumar Pendoti | 09d572e | 2016-08-27 03:22:36 +0530 | [diff] [blame] | 358 | EFI_MEM_CARDINFO_PROTOCOL *CardInfo; |
Vijay Kumar Pendoti | 09d572e | 2016-08-27 03:22:36 +0530 | [diff] [blame] | 359 | HandleInfo HandleInfoList[MAX_HANDLE_INFO_LIST]; |
| 360 | UINT32 Attribs = 0; |
| 361 | UINT32 MaxHandles; |
| 362 | PartiSelectFilter HandleFilter; |
Vijay Kumar Pendoti | 09d572e | 2016-08-27 03:22:36 +0530 | [diff] [blame] | 363 | |
| 364 | Attribs |= BLK_IO_SEL_MATCH_ROOT_DEVICE; |
Vijay Kumar Pendoti | 09d572e | 2016-08-27 03:22:36 +0530 | [diff] [blame] | 365 | MaxHandles = ARRAY_SIZE(HandleInfoList); |
| 366 | HandleFilter.PartitionType = 0; |
| 367 | HandleFilter.VolumeName = 0; |
Vijay Kumar Pendoti | d420e2a | 2016-11-21 19:50:53 +0530 | [diff] [blame] | 368 | HandleFilter.RootDeviceType = &gEfiUfsLU0Guid; |
Vijay Kumar Pendoti | 09d572e | 2016-08-27 03:22:36 +0530 | [diff] [blame] | 369 | |
| 370 | Status = GetBlkIOHandles(Attribs, &HandleFilter, HandleInfoList, &MaxHandles); |
Vijay Kumar Pendoti | d420e2a | 2016-11-21 19:50:53 +0530 | [diff] [blame] | 371 | if (EFI_ERROR (Status)) |
| 372 | return EFI_NOT_FOUND; |
Vijay Kumar Pendoti | 09d572e | 2016-08-27 03:22:36 +0530 | [diff] [blame] | 373 | |
| 374 | Status = gBS->HandleProtocol(HandleInfoList[0].Handle, &gEfiMemCardInfoProtocolGuid, (VOID**)&CardInfo); |
| 375 | |
| 376 | if (Status != EFI_SUCCESS) |
| 377 | { |
| 378 | DEBUG((EFI_D_ERROR,"Error locating MemCardInfoProtocol:%x\n",Status)); |
| 379 | return Status; |
| 380 | } |
| 381 | |
| 382 | if (CardInfo->Revision < EFI_MEM_CARD_INFO_PROTOCOL_REVISION) { |
| 383 | DEBUG((EFI_D_ERROR,"This API not supported in Revision =%u\n",CardInfo->Revision)); |
| 384 | return EFI_NOT_FOUND; |
| 385 | } |
| 386 | |
| 387 | if (IsGet == TRUE) { |
| 388 | if (CardInfo->GetBootLU (CardInfo, UfsBootlun) == EFI_SUCCESS) |
Channagoud Kadabi | 0dbf869 | 2016-09-30 16:17:11 -0700 | [diff] [blame] | 389 | DEBUG((EFI_D_VERBOSE, "Get BootLun =%u\n",*UfsBootlun)); |
Vijay Kumar Pendoti | 09d572e | 2016-08-27 03:22:36 +0530 | [diff] [blame] | 390 | } else { |
| 391 | if (CardInfo->SetBootLU (CardInfo, *UfsBootlun) == EFI_SUCCESS) |
Channagoud Kadabi | 0dbf869 | 2016-09-30 16:17:11 -0700 | [diff] [blame] | 392 | DEBUG((EFI_D_VERBOSE, "SetBootLun =%u\n",*UfsBootlun)); |
Vijay Kumar Pendoti | 09d572e | 2016-08-27 03:22:36 +0530 | [diff] [blame] | 393 | } |
| 394 | return Status; |
| 395 | } |
| 396 | |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 397 | EFI_STATUS BoardSerialNum(CHAR8 *StrSerialNum, UINT32 Len) |
| 398 | { |
| 399 | EFI_STATUS Status = EFI_INVALID_PARAMETER; |
| 400 | MEM_CARD_INFO CardInfoData; |
| 401 | EFI_MEM_CARDINFO_PROTOCOL *CardInfo; |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 402 | UINT32 SerialNo; |
lijuang | 24de534 | 2016-09-07 18:09:10 +0800 | [diff] [blame] | 403 | HandleInfo HandleInfoList[HANDLE_MAX_INFO_LIST]; |
| 404 | UINT32 MaxHandles = ARRAY_SIZE(HandleInfoList); |
| 405 | MemCardType Type = EMMC; |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 406 | |
lijuang | 24de534 | 2016-09-07 18:09:10 +0800 | [diff] [blame] | 407 | Type = CheckRootDeviceType(HandleInfoList, MaxHandles); |
| 408 | if (Type == UNKNOWN) |
| 409 | return EFI_NOT_FOUND; |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 410 | |
| 411 | Status = gBS->HandleProtocol(HandleInfoList[0].Handle, |
| 412 | &gEfiMemCardInfoProtocolGuid, |
| 413 | (VOID**)&CardInfo); |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 414 | if (Status != EFI_SUCCESS) |
| 415 | { |
| 416 | DEBUG((EFI_D_ERROR,"Error locating MemCardInfoProtocol:%x\n",Status)); |
| 417 | return Status; |
| 418 | } |
| 419 | |
| 420 | if (CardInfo->GetCardInfo (CardInfo, &CardInfoData) == EFI_SUCCESS) |
| 421 | { |
| 422 | if (Type == UFS) |
| 423 | { |
| 424 | Status = gBS->CalculateCrc32(CardInfoData.product_serial_num, CardInfoData.serial_num_len, &SerialNo); |
| 425 | if (Status != EFI_SUCCESS) |
| 426 | { |
| 427 | DEBUG((EFI_D_ERROR, "Error calculating Crc of the unicode serial number: %x\n", Status)); |
| 428 | return Status; |
| 429 | } |
| 430 | AsciiSPrint(StrSerialNum, Len, "%x", SerialNo); |
Vijay Kumar Pendoti | 78b1a96 | 2017-01-12 22:48:41 +0530 | [diff] [blame^] | 431 | } else { |
| 432 | AsciiSPrint(StrSerialNum, Len, "%x", *(UINT32 *)CardInfoData.product_serial_num); |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 433 | } |
Vijay Kumar Pendoti | 78b1a96 | 2017-01-12 22:48:41 +0530 | [diff] [blame^] | 434 | |
| 435 | /* adb is case sensitive, convert the serial number to lower case |
| 436 | * to maintain uniformity across the system. */ |
| 437 | ToLower(StrSerialNum); |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 438 | } |
| 439 | return Status; |
| 440 | } |
Channagoud Kadabi | 539d307 | 2016-02-11 21:34:48 -0800 | [diff] [blame] | 441 | |
| 442 | /* Helper APIs for device tree selection */ |
| 443 | UINT32 BoardPlatformRawChipId() |
| 444 | { |
| 445 | return platform_board_info.RawChipId; |
| 446 | } |
| 447 | |
| 448 | EFIChipInfoVersionType BoardPlatformChipVersion() |
| 449 | { |
| 450 | return platform_board_info.ChipVersion; |
| 451 | } |
| 452 | |
| 453 | EFIChipInfoFoundryIdType BoardPlatformFoundryId() |
| 454 | { |
| 455 | return platform_board_info.FoundryId; |
| 456 | } |
| 457 | |
Vijay Kumar Pendoti | 582158c | 2016-09-29 23:47:37 +0530 | [diff] [blame] | 458 | CHAR8* BoardPlatformChipBaseBand() |
| 459 | { |
| 460 | return platform_board_info.ChipBaseBand; |
| 461 | } |
| 462 | |
Channagoud Kadabi | 539d307 | 2016-02-11 21:34:48 -0800 | [diff] [blame] | 463 | EFI_PLATFORMINFO_PLATFORM_TYPE BoardPlatformType() |
| 464 | { |
| 465 | return platform_board_info.PlatformInfo.platform; |
| 466 | } |
| 467 | |
| 468 | UINT32 BoardPlatformVersion() |
| 469 | { |
| 470 | return platform_board_info.PlatformInfo.version; |
| 471 | } |
| 472 | |
| 473 | UINT32 BoardPlatformSubType() |
| 474 | { |
| 475 | return platform_board_info.PlatformInfo.subtype; |
| 476 | } |
Channagoud Kadabi | 5bd4099 | 2016-03-04 15:05:20 -0800 | [diff] [blame] | 477 | |
| 478 | UINT32 BoardTargetId() |
| 479 | { |
| 480 | UINT32 Target; |
| 481 | |
| 482 | Target = (((platform_board_info.PlatformInfo.subtype & 0xff) << 24) | |
| 483 | (((platform_board_info.PlatformInfo.version >> 16) & 0xff) << 16) | |
| 484 | ((platform_board_info.PlatformInfo.version & 0xff) << 8) | |
| 485 | (platform_board_info.PlatformInfo.platform & 0xff)); |
| 486 | |
| 487 | return Target; |
| 488 | } |
lijuang | 834ebd2 | 2016-09-07 18:27:29 +0800 | [diff] [blame] | 489 | |
| 490 | VOID BoardHwPlatformName(CHAR8 *StrHwPlatform, UINT32 Len) |
| 491 | { |
| 492 | EFI_STATUS Status; |
Vijay Kumar Pendoti | d420e2a | 2016-11-21 19:50:53 +0530 | [diff] [blame] | 493 | EFI_CHIPINFO_PROTOCOL *pChipInfoProtocol; |
| 494 | UINT32 ChipIdValidLen = 4; |
lijuang | 834ebd2 | 2016-09-07 18:27:29 +0800 | [diff] [blame] | 495 | |
| 496 | if (StrHwPlatform == NULL) { |
| 497 | DEBUG((EFI_D_ERROR, "Error: HW Platform string is NULL\n")); |
| 498 | return; |
| 499 | } |
| 500 | |
Vijay Kumar Pendoti | d420e2a | 2016-11-21 19:50:53 +0530 | [diff] [blame] | 501 | Status = gBS->LocateProtocol (&gEfiChipInfoProtocolGuid, NULL,(VOID **) &pChipInfoProtocol); |
| 502 | if (EFI_ERROR(Status)) { |
| 503 | DEBUG((EFI_D_ERROR, "Locate Protocol failed for gEfiChipInfoProtocolGuid\n")); |
lijuang | 834ebd2 | 2016-09-07 18:27:29 +0800 | [diff] [blame] | 504 | return; |
| 505 | } |
| 506 | |
Vijay Kumar Pendoti | d420e2a | 2016-11-21 19:50:53 +0530 | [diff] [blame] | 507 | Status = pChipInfoProtocol->GetChipIdString(pChipInfoProtocol, StrHwPlatform, EFICHIPINFO_MAX_ID_LENGTH); |
| 508 | if (EFI_ERROR(Status)) { |
| 509 | DEBUG((EFI_D_ERROR, "Failed to Get the ChipIdString\n")); |
lijuang | 834ebd2 | 2016-09-07 18:27:29 +0800 | [diff] [blame] | 510 | return; |
| 511 | } |
Vijay Kumar Pendoti | d420e2a | 2016-11-21 19:50:53 +0530 | [diff] [blame] | 512 | StrHwPlatform[ChipIdValidLen-1] = '\0'; |
lijuang | 834ebd2 | 2016-09-07 18:27:29 +0800 | [diff] [blame] | 513 | } |