Mukesh Ojha | 82c0fa3 | 2018-02-01 17:19:44 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2015-2018, 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 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 29 | #include "AutoGen.h" |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 30 | #include <Board.h> |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 31 | #include <Library/BootImage.h> |
| 32 | #include <Library/UpdateDeviceTree.h> |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 33 | #include <Protocol/EFICardInfo.h> |
lijuang | 834ebd2 | 2016-09-07 18:27:29 +0800 | [diff] [blame] | 34 | #include <Protocol/EFIPlatformInfoTypes.h> |
lijuang | 6a97bc5 | 2016-10-18 17:32:54 +0800 | [diff] [blame] | 35 | |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 36 | #include <LinuxLoaderLib.h> |
| 37 | |
Channagoud Kadabi | 539d307 | 2016-02-11 21:34:48 -0800 | [diff] [blame] | 38 | STATIC struct BoardInfo platform_board_info; |
| 39 | |
lijuang | 24de534 | 2016-09-07 18:09:10 +0800 | [diff] [blame] | 40 | STATIC CONST CHAR8 *DeviceType[] = { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 41 | [EMMC] = "EMMC", [UFS] = "UFS", [NAND] = "NAND", [UNKNOWN] = "Unknown", |
lijuang | 24de534 | 2016-09-07 18:09:10 +0800 | [diff] [blame] | 42 | }; |
| 43 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 44 | EFI_STATUS |
| 45 | GetRamPartitions (RamPartitionEntry **RamPartitions, UINT32 *NumPartitions) |
| 46 | { |
Vijay Kumar Pendoti | c52e80b | 2016-10-12 16:47:50 +0530 | [diff] [blame] | 47 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 48 | EFI_STATUS Status = EFI_NOT_FOUND; |
| 49 | EFI_RAMPARTITION_PROTOCOL *pRamPartProtocol = NULL; |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 50 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 51 | Status = gBS->LocateProtocol (&gEfiRamPartitionProtocolGuid, NULL, |
| 52 | (VOID **)&pRamPartProtocol); |
| 53 | if (EFI_ERROR (Status) || (pRamPartProtocol == NULL)) { |
| 54 | DEBUG ((EFI_D_ERROR, |
| 55 | "Locate EFI_RAMPARTITION_Protocol failed, Status = (0x%x)\r\n", |
| 56 | Status)); |
| 57 | return EFI_NOT_FOUND; |
| 58 | } |
| 59 | Status = pRamPartProtocol->GetRamPartitions (pRamPartProtocol, NULL, |
| 60 | NumPartitions); |
| 61 | if (Status == EFI_BUFFER_TOO_SMALL) { |
| 62 | *RamPartitions = AllocatePool (*NumPartitions * sizeof (RamPartitionEntry)); |
| 63 | if (*RamPartitions == NULL) |
| 64 | return EFI_OUT_OF_RESOURCES; |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 65 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 66 | Status = pRamPartProtocol->GetRamPartitions (pRamPartProtocol, |
| 67 | *RamPartitions, NumPartitions); |
| 68 | if (EFI_ERROR (Status) || (*NumPartitions < 1)) { |
| 69 | DEBUG ((EFI_D_ERROR, "Failed to get RAM partitions")); |
| 70 | FreePool (*RamPartitions); |
| 71 | *RamPartitions = NULL; |
| 72 | return EFI_NOT_FOUND; |
| 73 | } |
| 74 | } else { |
| 75 | DEBUG ((EFI_D_ERROR, "Error Occured while populating RamPartitions\n")); |
| 76 | return EFI_PROTOCOL_ERROR; |
| 77 | } |
| 78 | return Status; |
Vijay Kumar Pendoti | c52e80b | 2016-10-12 16:47:50 +0530 | [diff] [blame] | 79 | } |
| 80 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 81 | EFI_STATUS |
Jeevan Shriram | 067bbb5 | 2018-05-08 17:48:47 -0700 | [diff] [blame] | 82 | GetGranuleSize (UINT32 *MinPasrGranuleSize) |
| 83 | { |
| 84 | EFI_STATUS Status = EFI_NOT_FOUND; |
| 85 | EFI_RAMPARTITION_PROTOCOL *pRamPartProtocol = NULL; |
| 86 | |
| 87 | Status = gBS->LocateProtocol (&gEfiRamPartitionProtocolGuid, NULL, |
| 88 | (VOID **)&pRamPartProtocol); |
| 89 | if (EFI_ERROR (Status) || |
| 90 | (pRamPartProtocol == NULL)) { |
| 91 | DEBUG ((EFI_D_ERROR, |
| 92 | "Locate EFI_RAMPARTITION_Protocol failed, Status = %r \n", |
| 93 | Status)); |
| 94 | return Status; |
| 95 | } |
| 96 | |
Jeevan Shriram | 97ec78e | 2018-06-12 20:31:12 -0700 | [diff] [blame] | 97 | if (pRamPartProtocol->Revision < EFI_RAMPARTITION_PROTOCOL_REVISION) { |
| 98 | DEBUG ((EFI_D_ERROR, "WARNING: Unsupported EFI_RAMPARTITION_PROTOCOL\n")); |
| 99 | return EFI_UNSUPPORTED; |
| 100 | } |
| 101 | |
Jeevan Shriram | 067bbb5 | 2018-05-08 17:48:47 -0700 | [diff] [blame] | 102 | Status = pRamPartProtocol->GetMinPasrSize (pRamPartProtocol, |
| 103 | MinPasrGranuleSize); |
| 104 | if (EFI_ERROR (Status)) { |
| 105 | DEBUG ((EFI_D_ERROR, |
| 106 | "Failed to get MinPasrSize, Status = %r\n", |
| 107 | Status)); |
| 108 | return Status; |
| 109 | } |
| 110 | return Status; |
| 111 | } |
| 112 | |
| 113 | EFI_STATUS |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 114 | BaseMem (UINT64 *BaseMemory) |
Vijay Kumar Pendoti | c52e80b | 2016-10-12 16:47:50 +0530 | [diff] [blame] | 115 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 116 | EFI_STATUS Status = EFI_NOT_FOUND; |
| 117 | RamPartitionEntry *RamPartitions = NULL; |
| 118 | UINT32 NumPartitions = 0; |
| 119 | UINT64 SmallestBase; |
| 120 | UINT32 i = 0; |
Vijay Kumar Pendoti | c52e80b | 2016-10-12 16:47:50 +0530 | [diff] [blame] | 121 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 122 | Status = GetRamPartitions (&RamPartitions, &NumPartitions); |
| 123 | if (EFI_ERROR (Status)) { |
| 124 | DEBUG ((EFI_D_ERROR, "Error returned from GetRamPartitions %r\n", Status)); |
| 125 | return Status; |
| 126 | } |
| 127 | if (!RamPartitions) { |
| 128 | DEBUG ((EFI_D_ERROR, "RamPartitions is NULL\n")); |
| 129 | return EFI_NOT_FOUND; |
| 130 | } |
| 131 | SmallestBase = RamPartitions[0].Base; |
| 132 | for (i = 0; i < NumPartitions; i++) { |
| 133 | if (SmallestBase > RamPartitions[i].Base) |
| 134 | SmallestBase = RamPartitions[i].Base; |
| 135 | } |
| 136 | *BaseMemory = SmallestBase; |
| 137 | DEBUG ((EFI_D_INFO, "Memory Base Address: 0x%x\n", *BaseMemory)); |
| 138 | FreePool (RamPartitions); |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 139 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 140 | return Status; |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 141 | } |
| 142 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 143 | STATIC EFI_STATUS |
| 144 | GetChipInfo (struct BoardInfo *platform_board_info) |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 145 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 146 | EFI_STATUS Status; |
| 147 | EFI_CHIPINFO_PROTOCOL *pChipInfoProtocol; |
Saranya Chidura | 6f047e2 | 2018-09-05 10:09:45 +0530 | [diff] [blame^] | 148 | EFIChipInfoModemType ModemType; |
| 149 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 150 | Status = gBS->LocateProtocol (&gEfiChipInfoProtocolGuid, NULL, |
| 151 | (VOID **)&pChipInfoProtocol); |
| 152 | if (EFI_ERROR (Status)) |
| 153 | return Status; |
| 154 | Status = pChipInfoProtocol->GetChipId (pChipInfoProtocol, |
| 155 | &platform_board_info->RawChipId); |
| 156 | if (EFI_ERROR (Status)) |
| 157 | return Status; |
| 158 | Status = pChipInfoProtocol->GetChipVersion ( |
| 159 | pChipInfoProtocol, &platform_board_info->ChipVersion); |
| 160 | if (EFI_ERROR (Status)) |
| 161 | return Status; |
| 162 | Status = pChipInfoProtocol->GetFoundryId (pChipInfoProtocol, |
| 163 | &platform_board_info->FoundryId); |
| 164 | if (EFI_ERROR (Status)) |
| 165 | return Status; |
Saranya Chidura | 6f047e2 | 2018-09-05 10:09:45 +0530 | [diff] [blame^] | 166 | Status = pChipInfoProtocol->GetModemSupport ( |
| 167 | pChipInfoProtocol, &ModemType); |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 168 | if (EFI_ERROR (Status)) |
| 169 | return Status; |
Saranya Chidura | 6f047e2 | 2018-09-05 10:09:45 +0530 | [diff] [blame^] | 170 | |
| 171 | if (BoardPlatformFusion ()) { |
| 172 | AsciiSPrint ((CHAR8 *)platform_board_info->ChipBaseBand, |
| 173 | CHIP_BASE_BAND_LEN, "%a", CHIP_BASE_BAND_MDM); |
| 174 | } else if (ModemType == 0) { |
| 175 | AsciiSPrint ((CHAR8 *)platform_board_info->ChipBaseBand, |
| 176 | CHIP_BASE_BAND_LEN, "%a", CHIP_BASE_BAND_APQ); |
| 177 | } else { |
| 178 | AsciiSPrint ((CHAR8 *)platform_board_info->ChipBaseBand, |
| 179 | CHIP_BASE_BAND_LEN, "%a", CHIP_BASE_BAND_MSM); |
| 180 | } |
| 181 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 182 | DEBUG ((EFI_D_VERBOSE, "Raw Chip Id : 0x%x\n", |
| 183 | platform_board_info->RawChipId)); |
| 184 | DEBUG ((EFI_D_VERBOSE, "Chip Version : 0x%x\n", |
| 185 | platform_board_info->ChipVersion)); |
| 186 | DEBUG ((EFI_D_VERBOSE, "Foundry Id : 0x%x\n", |
| 187 | platform_board_info->FoundryId)); |
| 188 | DEBUG ((EFI_D_VERBOSE, "Chip BaseBand : %a\n", |
| 189 | platform_board_info->ChipBaseBand)); |
Bhanuprakash Modem | 027aae5 | 2017-11-07 14:58:02 -0800 | [diff] [blame] | 190 | DEBUG ((EFI_D_VERBOSE, "Fusion Value : %d\n", |
| 191 | platform_board_info->PlatformInfo.fusion)); |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 192 | return Status; |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 193 | } |
| 194 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 195 | STATIC EFI_STATUS |
| 196 | GetPlatformInfo (struct BoardInfo *platform_board_info) |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 197 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 198 | EFI_STATUS eResult; |
| 199 | EFI_PLATFORMINFO_PROTOCOL *hPlatformInfoProtocol; |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 200 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 201 | eResult = gBS->LocateProtocol (&gEfiPlatformInfoProtocolGuid, NULL, |
| 202 | (VOID **)&hPlatformInfoProtocol); |
| 203 | if (eResult != EFI_SUCCESS) { |
| 204 | AsciiPrint ("Error: Failed to locate PlatformInfo protocol.\n"); |
| 205 | goto endtest; |
| 206 | } |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 207 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 208 | eResult = hPlatformInfoProtocol->GetPlatformInfo ( |
| 209 | hPlatformInfoProtocol, &platform_board_info->PlatformInfo); |
| 210 | if (eResult != EFI_SUCCESS) { |
| 211 | AsciiPrint ("Error: GetPlatformInfo failed.\n"); |
| 212 | goto endtest; |
| 213 | } |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 214 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 215 | if (platform_board_info->PlatformInfo.platform >= |
| 216 | EFI_PLATFORMINFO_NUM_TYPES) { |
| 217 | AsciiPrint ("Error: Unknown platform type (%d).\n", |
| 218 | platform_board_info->PlatformInfo.platform); |
| 219 | eResult = EFI_PROTOCOL_ERROR; |
| 220 | goto endtest; |
| 221 | } |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 222 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 223 | DEBUG ((EFI_D_VERBOSE, "Platform Info : 0x%x\n", |
| 224 | platform_board_info->PlatformInfo.platform)); |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 225 | endtest: |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 226 | return eResult; |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 227 | } |
| 228 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 229 | STATIC EFI_STATUS |
| 230 | GetPmicInfoExt (UINT32 PmicDeviceIndex, |
| 231 | EFI_PM_DEVICE_INFO_EXT_TYPE *pmic_info_ext) |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 232 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 233 | EFI_STATUS Status; |
| 234 | EFI_QCOM_PMIC_VERSION_PROTOCOL *pPmicVersionProtocol; |
Vijay Kumar Pendoti | 0be2561 | 2016-11-18 18:52:46 +0530 | [diff] [blame] | 235 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 236 | Status = gBS->LocateProtocol (&gQcomPmicVersionProtocolGuid, NULL, |
| 237 | (VOID **)&pPmicVersionProtocol); |
| 238 | if (EFI_ERROR (Status)) { |
| 239 | DEBUG ((EFI_D_ERROR, "Error locating pmic protocol: %r\n", Status)); |
| 240 | return Status; |
| 241 | } |
Vijay Kumar Pendoti | 0be2561 | 2016-11-18 18:52:46 +0530 | [diff] [blame] | 242 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 243 | Status = |
| 244 | pPmicVersionProtocol->GetPmicInfoExt (PmicDeviceIndex, pmic_info_ext); |
| 245 | if (EFI_ERROR (Status)) { |
| 246 | DEBUG ((EFI_D_VERBOSE, "Error getting pmic info ext: %r\n", Status)); |
| 247 | return Status; |
| 248 | } |
| 249 | return Status; |
Vijay Kumar Pendoti | 0be2561 | 2016-11-18 18:52:46 +0530 | [diff] [blame] | 250 | } |
| 251 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 252 | STATIC EFI_STATUS |
| 253 | GetPmicInfo (UINT32 PmicDeviceIndex, |
| 254 | EFI_PM_DEVICE_INFO_TYPE *pmic_info, |
| 255 | UINT64 *Revision) |
Vijay Kumar Pendoti | 0be2561 | 2016-11-18 18:52:46 +0530 | [diff] [blame] | 256 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 257 | EFI_STATUS Status; |
| 258 | EFI_QCOM_PMIC_VERSION_PROTOCOL *pPmicVersionProtocol; |
Vijay Kumar Pendoti | 0be2561 | 2016-11-18 18:52:46 +0530 | [diff] [blame] | 259 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 260 | Status = gBS->LocateProtocol (&gQcomPmicVersionProtocolGuid, NULL, |
| 261 | (VOID **)&pPmicVersionProtocol); |
| 262 | if (EFI_ERROR (Status)) { |
| 263 | DEBUG ((EFI_D_ERROR, "Error locating pmic protocol: %r\n", Status)); |
| 264 | return Status; |
| 265 | } |
Vijay Kumar Pendoti | 0be2561 | 2016-11-18 18:52:46 +0530 | [diff] [blame] | 266 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 267 | *Revision = pPmicVersionProtocol->Revision; |
Vijay Kumar Pendoti | 0be2561 | 2016-11-18 18:52:46 +0530 | [diff] [blame] | 268 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 269 | Status = pPmicVersionProtocol->GetPmicInfo (PmicDeviceIndex, pmic_info); |
| 270 | if (EFI_ERROR (Status)) { |
| 271 | DEBUG ((EFI_D_ERROR, "Error getting pmic info: %r\n", Status)); |
| 272 | return Status; |
| 273 | } |
| 274 | return Status; |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 275 | } |
| 276 | |
lijuang | 24de534 | 2016-09-07 18:09:10 +0800 | [diff] [blame] | 277 | /** |
Jeevan Shriram | cf9ea6d | 2017-09-11 19:04:40 -0700 | [diff] [blame] | 278 | Device Handler Info |
| 279 | |
Mukesh Ojha | 82c0fa3 | 2018-02-01 17:19:44 +0530 | [diff] [blame] | 280 | @param[out] HndlInfo : Pointer to array of HandleInfo structures |
lijuang | 24de534 | 2016-09-07 18:09:10 +0800 | [diff] [blame] | 281 | in which the output is returned. |
| 282 | @param[in, out] MaxHandles : On input, max number of handle structures |
| 283 | the buffer can hold, On output, the number |
| 284 | of handle structures returned. |
Jeevan Shriram | cf9ea6d | 2017-09-11 19:04:40 -0700 | [diff] [blame] | 285 | @param[in] Type : Device Type : UNKNOWN, UFS, EMMC, NAND |
| 286 | @retval EFI_STATUS : Return Success on getting Handler Info |
| 287 | **/ |
| 288 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 289 | STATIC EFI_STATUS |
Mukesh Ojha | 82c0fa3 | 2018-02-01 17:19:44 +0530 | [diff] [blame] | 290 | GetDeviceHandleInfo (VOID *HndlInfo, UINT32 MaxHandles, MemCardType Type) |
Jeevan Shriram | cf9ea6d | 2017-09-11 19:04:40 -0700 | [diff] [blame] | 291 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 292 | EFI_STATUS Status = EFI_INVALID_PARAMETER; |
| 293 | UINT32 Attribs = 0; |
| 294 | PartiSelectFilter HandleFilter; |
Mukesh Ojha | 82c0fa3 | 2018-02-01 17:19:44 +0530 | [diff] [blame] | 295 | HandleInfo *HandleInfoList = HndlInfo; |
Jeevan Shriram | cf9ea6d | 2017-09-11 19:04:40 -0700 | [diff] [blame] | 296 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 297 | Attribs |= BLK_IO_SEL_MATCH_ROOT_DEVICE; |
| 298 | HandleFilter.PartitionType = NULL; |
| 299 | HandleFilter.VolumeName = NULL; |
Jeevan Shriram | cf9ea6d | 2017-09-11 19:04:40 -0700 | [diff] [blame] | 300 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 301 | switch (Type) { |
| 302 | case UFS: |
| 303 | HandleFilter.RootDeviceType = &gEfiUfsLU0Guid; |
| 304 | break; |
| 305 | case EMMC: |
| 306 | HandleFilter.RootDeviceType = &gEfiEmmcUserPartitionGuid; |
| 307 | break; |
| 308 | case NAND: |
| 309 | HandleFilter.RootDeviceType = &gEfiNandUserPartitionGuid; |
| 310 | break; |
| 311 | case UNKNOWN: |
| 312 | DEBUG ((EFI_D_ERROR, "Device type unknown\n")); |
Jeevan Shriram | cf9ea6d | 2017-09-11 19:04:40 -0700 | [diff] [blame] | 313 | return Status; |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | Status = |
Mukesh Ojha | 82c0fa3 | 2018-02-01 17:19:44 +0530 | [diff] [blame] | 317 | GetBlkIOHandles (Attribs, &HandleFilter, HandleInfoList, &MaxHandles); |
| 318 | if (EFI_ERROR (Status) || |
| 319 | MaxHandles == 0) { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 320 | DEBUG ((EFI_D_ERROR, "Get BlkIohandles failed\n")); |
| 321 | return Status; |
| 322 | } |
| 323 | return Status; |
Jeevan Shriram | cf9ea6d | 2017-09-11 19:04:40 -0700 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | /** |
| 327 | Return a device type |
Mukesh Ojha | 82c0fa3 | 2018-02-01 17:19:44 +0530 | [diff] [blame] | 328 | @retval Device type : UNKNOWN | UFS | EMMC | NAND |
| 329 | **/ |
| 330 | STATIC UINT32 |
| 331 | GetCompatibleRootDeviceType (VOID) |
| 332 | { |
| 333 | EFI_STATUS Status = EFI_INVALID_PARAMETER; |
| 334 | HandleInfo HandleInfoList[HANDLE_MAX_INFO_LIST]; |
| 335 | UINT32 MaxHandles = ARRAY_SIZE (HandleInfoList); |
| 336 | UINT32 Index; |
| 337 | |
| 338 | for (Index = 0; Index < UNKNOWN; Index++) { |
| 339 | Status = GetDeviceHandleInfo (HandleInfoList, MaxHandles, Index); |
| 340 | if (Status == EFI_SUCCESS) { |
| 341 | return Index; |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | return Index; |
| 346 | } |
| 347 | |
| 348 | /** |
| 349 | Return a device type |
| 350 | @retval Device type : UNKNOWN | UFS | EMMC | NAND, default is UNKNOWN |
lijuang | 24de534 | 2016-09-07 18:09:10 +0800 | [diff] [blame] | 351 | **/ |
Jeevan Shriram | cf9ea6d | 2017-09-11 19:04:40 -0700 | [diff] [blame] | 352 | |
Jeevan Shriram | 9f8489e | 2018-03-12 16:45:59 -0700 | [diff] [blame] | 353 | MemCardType |
| 354 | CheckRootDeviceType (VOID) |
lijuang | 24de534 | 2016-09-07 18:09:10 +0800 | [diff] [blame] | 355 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 356 | EFI_STATUS Status = EFI_INVALID_PARAMETER; |
| 357 | STATIC MemCardType Type = UNKNOWN; |
| 358 | MEM_CARD_INFO CardInfoData; |
| 359 | EFI_MEM_CARDINFO_PROTOCOL *CardInfo; |
lijuang | 24de534 | 2016-09-07 18:09:10 +0800 | [diff] [blame] | 360 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 361 | if (Type == UNKNOWN) { |
| 362 | Status = gBS->LocateProtocol (&gEfiMemCardInfoProtocolGuid, NULL, |
| 363 | (VOID **)&CardInfo); |
| 364 | if (!EFI_ERROR (Status)) { |
lijuang | 24de534 | 2016-09-07 18:09:10 +0800 | [diff] [blame] | 365 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 366 | Status = CardInfo->GetCardInfo (CardInfo, &CardInfoData); |
lijuang | 24de534 | 2016-09-07 18:09:10 +0800 | [diff] [blame] | 367 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 368 | if (!EFI_ERROR (Status)) { |
lijuang | 24de534 | 2016-09-07 18:09:10 +0800 | [diff] [blame] | 369 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 370 | if (!AsciiStrnCmp ((CHAR8 *)CardInfoData.card_type, "UFS", |
| 371 | AsciiStrLen ("UFS"))) { |
| 372 | Type = UFS; |
| 373 | } else if (!AsciiStrnCmp ((CHAR8 *)CardInfoData.card_type, "EMMC", |
| 374 | AsciiStrLen ("EMMC"))) { |
| 375 | Type = EMMC; |
| 376 | } else if (!AsciiStrnCmp ((CHAR8 *)CardInfoData.card_type, "NAND", |
| 377 | AsciiStrLen ("NAND"))) { |
| 378 | Type = NAND; |
| 379 | } else { |
Mukesh Ojha | 82c0fa3 | 2018-02-01 17:19:44 +0530 | [diff] [blame] | 380 | Type = GetCompatibleRootDeviceType (); |
Jeevan Shriram | cf9ea6d | 2017-09-11 19:04:40 -0700 | [diff] [blame] | 381 | } |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 382 | } |
Jeevan Shriram | cf9ea6d | 2017-09-11 19:04:40 -0700 | [diff] [blame] | 383 | } |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 384 | } |
| 385 | return Type; |
lijuang | 24de534 | 2016-09-07 18:09:10 +0800 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | /** |
| 389 | Get device type |
| 390 | @param[out] StrDeviceType : Pointer to array of device type string. |
| 391 | @param[in] Len : The size of the device type string |
| 392 | **/ |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 393 | VOID |
| 394 | GetRootDeviceType (CHAR8 *StrDeviceType, UINT32 Len) |
lijuang | 24de534 | 2016-09-07 18:09:10 +0800 | [diff] [blame] | 395 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 396 | UINT32 Type; |
lijuang | 24de534 | 2016-09-07 18:09:10 +0800 | [diff] [blame] | 397 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 398 | Type = CheckRootDeviceType (); |
| 399 | AsciiSPrint (StrDeviceType, Len, "%a", DeviceType[Type]); |
lijuang | 24de534 | 2016-09-07 18:09:10 +0800 | [diff] [blame] | 400 | } |
| 401 | |
lijuang | 6a97bc5 | 2016-10-18 17:32:54 +0800 | [diff] [blame] | 402 | /** |
| 403 | Get device page size |
| 404 | @param[out] PageSize : Pointer to the page size. |
| 405 | **/ |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 406 | VOID |
| 407 | GetPageSize (UINT32 *PageSize) |
lijuang | 6a97bc5 | 2016-10-18 17:32:54 +0800 | [diff] [blame] | 408 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 409 | EFI_BLOCK_IO_PROTOCOL *BlkIo = NULL; |
| 410 | HandleInfo HandleInfoList[HANDLE_MAX_INFO_LIST]; |
| 411 | UINT32 MaxHandles = ARRAY_SIZE (HandleInfoList); |
| 412 | UINT32 Type; |
| 413 | EFI_STATUS Status = EFI_INVALID_PARAMETER; |
lijuang | 6a97bc5 | 2016-10-18 17:32:54 +0800 | [diff] [blame] | 414 | |
Mukesh Ojha | c6d501a | 2018-04-25 13:45:41 +0530 | [diff] [blame] | 415 | *PageSize = BOOT_IMG_MAX_PAGE_SIZE; |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 416 | Type = CheckRootDeviceType (); |
Mukesh Ojha | c6d501a | 2018-04-25 13:45:41 +0530 | [diff] [blame] | 417 | Status = GetDeviceHandleInfo (HandleInfoList, MaxHandles, Type); |
| 418 | if (Status == EFI_SUCCESS) { |
| 419 | BlkIo = HandleInfoList[0].BlkIo; |
| 420 | *PageSize = BlkIo->Media->BlockSize; |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 421 | } |
lijuang | 6a97bc5 | 2016-10-18 17:32:54 +0800 | [diff] [blame] | 422 | } |
| 423 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 424 | UINT32 |
| 425 | BoardPmicModel (UINT32 PmicDeviceIndex) |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 426 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 427 | EFI_STATUS Status; |
| 428 | EFI_PM_DEVICE_INFO_TYPE pmic_info; |
| 429 | UINT64 Revision; |
Vijay Kumar Pendoti | 0be2561 | 2016-11-18 18:52:46 +0530 | [diff] [blame] | 430 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 431 | Status = GetPmicInfo (PmicDeviceIndex, &pmic_info, &Revision); |
| 432 | if (Status != EFI_SUCCESS) { |
| 433 | DEBUG ((EFI_D_ERROR, "Error getting pmic model info: %r\n", Status)); |
| 434 | ASSERT (0); |
| 435 | } |
| 436 | DEBUG ((EFI_D_VERBOSE, "PMIC Model 0x%x: 0x%x\n", PmicDeviceIndex, |
| 437 | pmic_info.PmicModel)); |
| 438 | return pmic_info.PmicModel; |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 439 | } |
| 440 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 441 | UINT32 |
| 442 | BoardPmicTarget (UINT32 PmicDeviceIndex) |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 443 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 444 | UINT32 target; |
| 445 | EFI_STATUS Status; |
| 446 | UINT64 Revision; |
| 447 | EFI_PM_DEVICE_INFO_TYPE pmic_info; |
| 448 | EFI_PM_DEVICE_INFO_EXT_TYPE pmic_info_ext; |
Vijay Kumar Pendoti | 0be2561 | 2016-11-18 18:52:46 +0530 | [diff] [blame] | 449 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 450 | Status = GetPmicInfo (PmicDeviceIndex, &pmic_info, &Revision); |
| 451 | if (Status != EFI_SUCCESS) { |
| 452 | DEBUG ((EFI_D_ERROR, "Error finding board pmic info: %r\n", Status)); |
| 453 | ASSERT (0); |
| 454 | } |
Vijay Kumar Pendoti | 0be2561 | 2016-11-18 18:52:46 +0530 | [diff] [blame] | 455 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 456 | if (Revision >= PMIC_VERSION_REVISION) { |
| 457 | Status = GetPmicInfoExt (PmicDeviceIndex, &pmic_info_ext); |
| 458 | if (Status != EFI_SUCCESS) { |
| 459 | DEBUG ((EFI_D_VERBOSE, "Error finding board pmic info: %r\n", Status)); |
| 460 | return 0; |
| 461 | } |
Vijay Kumar Pendoti | 0be2561 | 2016-11-18 18:52:46 +0530 | [diff] [blame] | 462 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 463 | target = (pmic_info_ext.PmicVariantRevision << 24) | |
| 464 | (pmic_info_ext.PmicAllLayerRevision << 16) | |
| 465 | (pmic_info_ext.PmicMetalRevision << 8) | pmic_info_ext.PmicModel; |
| 466 | } else { |
| 467 | target = (pmic_info.PmicAllLayerRevision << 16) | |
| 468 | (pmic_info.PmicMetalRevision << 8) | pmic_info.PmicModel; |
| 469 | } |
Vijay Kumar Pendoti | 0be2561 | 2016-11-18 18:52:46 +0530 | [diff] [blame] | 470 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 471 | DEBUG ((EFI_D_VERBOSE, "PMIC Target 0x%x: 0x%x\n", PmicDeviceIndex, target)); |
| 472 | return target; |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 473 | } |
| 474 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 475 | EFI_STATUS BoardInit (VOID) |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 476 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 477 | EFI_STATUS Status; |
| 478 | Status = GetChipInfo (&platform_board_info); |
| 479 | if (EFI_ERROR (Status)) |
| 480 | return Status; |
| 481 | Status = GetPlatformInfo (&platform_board_info); |
| 482 | if (EFI_ERROR (Status)) |
| 483 | return Status; |
Channagoud Kadabi | 539d307 | 2016-02-11 21:34:48 -0800 | [diff] [blame] | 484 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 485 | return Status; |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 486 | } |
| 487 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 488 | EFI_STATUS |
| 489 | UfsGetSetBootLun (UINT32 *UfsBootlun, BOOLEAN IsGet) |
Vijay Kumar Pendoti | 09d572e | 2016-08-27 03:22:36 +0530 | [diff] [blame] | 490 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 491 | EFI_STATUS Status = EFI_INVALID_PARAMETER; |
| 492 | EFI_MEM_CARDINFO_PROTOCOL *CardInfo; |
| 493 | HandleInfo HandleInfoList[MAX_HANDLE_INFO_LIST]; |
| 494 | UINT32 Attribs = 0; |
| 495 | UINT32 MaxHandles; |
| 496 | PartiSelectFilter HandleFilter; |
Vijay Kumar Pendoti | 09d572e | 2016-08-27 03:22:36 +0530 | [diff] [blame] | 497 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 498 | Attribs |= BLK_IO_SEL_MATCH_ROOT_DEVICE; |
| 499 | MaxHandles = ARRAY_SIZE (HandleInfoList); |
| 500 | HandleFilter.PartitionType = NULL; |
| 501 | HandleFilter.VolumeName = NULL; |
| 502 | HandleFilter.RootDeviceType = &gEfiUfsLU0Guid; |
Vijay Kumar Pendoti | 09d572e | 2016-08-27 03:22:36 +0530 | [diff] [blame] | 503 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 504 | Status = |
| 505 | GetBlkIOHandles (Attribs, &HandleFilter, HandleInfoList, &MaxHandles); |
| 506 | if (EFI_ERROR (Status)) |
| 507 | return EFI_NOT_FOUND; |
Vijay Kumar Pendoti | 09d572e | 2016-08-27 03:22:36 +0530 | [diff] [blame] | 508 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 509 | Status = |
| 510 | gBS->HandleProtocol (HandleInfoList[0].Handle, |
| 511 | &gEfiMemCardInfoProtocolGuid, (VOID **)&CardInfo); |
Vijay Kumar Pendoti | 09d572e | 2016-08-27 03:22:36 +0530 | [diff] [blame] | 512 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 513 | if (Status != EFI_SUCCESS) { |
| 514 | DEBUG ((EFI_D_ERROR, "Error locating MemCardInfoProtocol:%x\n", Status)); |
| 515 | return Status; |
| 516 | } |
Vijay Kumar Pendoti | 09d572e | 2016-08-27 03:22:36 +0530 | [diff] [blame] | 517 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 518 | if (CardInfo->Revision < EFI_MEM_CARD_INFO_PROTOCOL_REVISION) { |
| 519 | DEBUG ((EFI_D_ERROR, "This API not supported in Revision =%u\n", |
| 520 | CardInfo->Revision)); |
| 521 | return EFI_NOT_FOUND; |
| 522 | } |
Vijay Kumar Pendoti | 09d572e | 2016-08-27 03:22:36 +0530 | [diff] [blame] | 523 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 524 | if (IsGet == TRUE) { |
| 525 | if (CardInfo->GetBootLU (CardInfo, UfsBootlun) == EFI_SUCCESS) |
| 526 | DEBUG ((EFI_D_VERBOSE, "Get BootLun =%u\n", *UfsBootlun)); |
| 527 | } else { |
| 528 | if (CardInfo->SetBootLU (CardInfo, *UfsBootlun) == EFI_SUCCESS) |
| 529 | DEBUG ((EFI_D_VERBOSE, "SetBootLun =%u\n", *UfsBootlun)); |
| 530 | } |
| 531 | return Status; |
Vijay Kumar Pendoti | 09d572e | 2016-08-27 03:22:36 +0530 | [diff] [blame] | 532 | } |
| 533 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 534 | EFI_STATUS |
| 535 | BoardSerialNum (CHAR8 *StrSerialNum, UINT32 Len) |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 536 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 537 | EFI_STATUS Status = EFI_INVALID_PARAMETER; |
| 538 | MEM_CARD_INFO CardInfoData; |
| 539 | EFI_MEM_CARDINFO_PROTOCOL *CardInfo; |
| 540 | UINT32 SerialNo; |
| 541 | HandleInfo HandleInfoList[HANDLE_MAX_INFO_LIST]; |
| 542 | UINT32 MaxHandles = ARRAY_SIZE (HandleInfoList); |
| 543 | MemCardType Type = EMMC; |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 544 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 545 | Type = CheckRootDeviceType (); |
| 546 | if (Type == UNKNOWN) |
| 547 | return EFI_NOT_FOUND; |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 548 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 549 | Status = GetDeviceHandleInfo (HandleInfoList, MaxHandles, Type); |
| 550 | if (EFI_ERROR (Status)) { |
| 551 | return Status; |
| 552 | } |
Jeevan Shriram | cf9ea6d | 2017-09-11 19:04:40 -0700 | [diff] [blame] | 553 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 554 | Status = |
| 555 | gBS->HandleProtocol (HandleInfoList[0].Handle, |
| 556 | &gEfiMemCardInfoProtocolGuid, (VOID **)&CardInfo); |
| 557 | if (Status != EFI_SUCCESS) { |
| 558 | DEBUG ((EFI_D_ERROR, "Error locating MemCardInfoProtocol:%x\n", Status)); |
| 559 | return Status; |
| 560 | } |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 561 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 562 | if (CardInfo->GetCardInfo (CardInfo, &CardInfoData) == EFI_SUCCESS) { |
| 563 | if (Type == UFS) { |
| 564 | Status = gBS->CalculateCrc32 (CardInfoData.product_serial_num, |
| 565 | CardInfoData.serial_num_len, &SerialNo); |
| 566 | if (Status != EFI_SUCCESS) { |
| 567 | DEBUG ((EFI_D_ERROR, |
| 568 | "Error calculating Crc of the unicode serial number: %x\n", |
| 569 | Status)); |
| 570 | return Status; |
| 571 | } |
| 572 | AsciiSPrint (StrSerialNum, Len, "%x", SerialNo); |
| 573 | } else { |
| 574 | AsciiSPrint (StrSerialNum, Len, "%x", |
| 575 | *(UINT32 *)CardInfoData.product_serial_num); |
| 576 | } |
Vijay Kumar Pendoti | 78b1a96 | 2017-01-12 22:48:41 +0530 | [diff] [blame] | 577 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 578 | /* adb is case sensitive, convert the serial number to lower case |
| 579 | * to maintain uniformity across the system. */ |
| 580 | ToLower (StrSerialNum); |
| 581 | } |
| 582 | return Status; |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 583 | } |
Channagoud Kadabi | 539d307 | 2016-02-11 21:34:48 -0800 | [diff] [blame] | 584 | |
| 585 | /* Helper APIs for device tree selection */ |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 586 | UINT32 BoardPlatformRawChipId (VOID) |
Channagoud Kadabi | 539d307 | 2016-02-11 21:34:48 -0800 | [diff] [blame] | 587 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 588 | return platform_board_info.RawChipId; |
Channagoud Kadabi | 539d307 | 2016-02-11 21:34:48 -0800 | [diff] [blame] | 589 | } |
| 590 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 591 | EFIChipInfoVersionType BoardPlatformChipVersion (VOID) |
Channagoud Kadabi | 539d307 | 2016-02-11 21:34:48 -0800 | [diff] [blame] | 592 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 593 | return platform_board_info.ChipVersion; |
Channagoud Kadabi | 539d307 | 2016-02-11 21:34:48 -0800 | [diff] [blame] | 594 | } |
| 595 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 596 | EFIChipInfoFoundryIdType BoardPlatformFoundryId (VOID) |
Channagoud Kadabi | 539d307 | 2016-02-11 21:34:48 -0800 | [diff] [blame] | 597 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 598 | return platform_board_info.FoundryId; |
Channagoud Kadabi | 539d307 | 2016-02-11 21:34:48 -0800 | [diff] [blame] | 599 | } |
| 600 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 601 | CHAR8 *BoardPlatformChipBaseBand (VOID) |
Vijay Kumar Pendoti | 582158c | 2016-09-29 23:47:37 +0530 | [diff] [blame] | 602 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 603 | return platform_board_info.ChipBaseBand; |
Vijay Kumar Pendoti | 582158c | 2016-09-29 23:47:37 +0530 | [diff] [blame] | 604 | } |
| 605 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 606 | EFI_PLATFORMINFO_PLATFORM_TYPE BoardPlatformType (VOID) |
Channagoud Kadabi | 539d307 | 2016-02-11 21:34:48 -0800 | [diff] [blame] | 607 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 608 | return platform_board_info.PlatformInfo.platform; |
Channagoud Kadabi | 539d307 | 2016-02-11 21:34:48 -0800 | [diff] [blame] | 609 | } |
| 610 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 611 | UINT32 BoardPlatformVersion (VOID) |
Channagoud Kadabi | 539d307 | 2016-02-11 21:34:48 -0800 | [diff] [blame] | 612 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 613 | return platform_board_info.PlatformInfo.version; |
Channagoud Kadabi | 539d307 | 2016-02-11 21:34:48 -0800 | [diff] [blame] | 614 | } |
| 615 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 616 | UINT32 BoardPlatformSubType (VOID) |
Channagoud Kadabi | 539d307 | 2016-02-11 21:34:48 -0800 | [diff] [blame] | 617 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 618 | return platform_board_info.PlatformInfo.subtype; |
Channagoud Kadabi | 539d307 | 2016-02-11 21:34:48 -0800 | [diff] [blame] | 619 | } |
Channagoud Kadabi | 5bd4099 | 2016-03-04 15:05:20 -0800 | [diff] [blame] | 620 | |
Bhanuprakash Modem | 027aae5 | 2017-11-07 14:58:02 -0800 | [diff] [blame] | 621 | BOOLEAN BoardPlatformFusion (VOID) |
| 622 | { |
| 623 | return platform_board_info.PlatformInfo.fusion; |
| 624 | } |
| 625 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 626 | UINT32 BoardTargetId (VOID) |
Channagoud Kadabi | 5bd4099 | 2016-03-04 15:05:20 -0800 | [diff] [blame] | 627 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 628 | UINT32 Target; |
Channagoud Kadabi | 5bd4099 | 2016-03-04 15:05:20 -0800 | [diff] [blame] | 629 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 630 | Target = (((platform_board_info.PlatformInfo.subtype & 0xff) << 24) | |
| 631 | (((platform_board_info.PlatformInfo.version >> 16) & 0xff) << 16) | |
| 632 | ((platform_board_info.PlatformInfo.version & 0xff) << 8) | |
| 633 | (platform_board_info.PlatformInfo.platform & 0xff)); |
Channagoud Kadabi | 5bd4099 | 2016-03-04 15:05:20 -0800 | [diff] [blame] | 634 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 635 | return Target; |
Channagoud Kadabi | 5bd4099 | 2016-03-04 15:05:20 -0800 | [diff] [blame] | 636 | } |
lijuang | 834ebd2 | 2016-09-07 18:27:29 +0800 | [diff] [blame] | 637 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 638 | VOID |
| 639 | BoardHwPlatformName (CHAR8 *StrHwPlatform, UINT32 Len) |
lijuang | 834ebd2 | 2016-09-07 18:27:29 +0800 | [diff] [blame] | 640 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 641 | EFI_STATUS Status; |
| 642 | EFI_CHIPINFO_PROTOCOL *pChipInfoProtocol; |
| 643 | UINT32 ChipIdValidLen = 4; |
lijuang | 834ebd2 | 2016-09-07 18:27:29 +0800 | [diff] [blame] | 644 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 645 | if (StrHwPlatform == NULL) { |
| 646 | DEBUG ((EFI_D_ERROR, "Error: HW Platform string is NULL\n")); |
| 647 | return; |
| 648 | } |
lijuang | 834ebd2 | 2016-09-07 18:27:29 +0800 | [diff] [blame] | 649 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 650 | Status = gBS->LocateProtocol (&gEfiChipInfoProtocolGuid, NULL, |
| 651 | (VOID **)&pChipInfoProtocol); |
| 652 | if (EFI_ERROR (Status)) { |
| 653 | DEBUG ( |
| 654 | (EFI_D_ERROR, "Locate Protocol failed for gEfiChipInfoProtocolGuid\n")); |
| 655 | return; |
| 656 | } |
lijuang | 834ebd2 | 2016-09-07 18:27:29 +0800 | [diff] [blame] | 657 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 658 | Status = pChipInfoProtocol->GetChipIdString ( |
| 659 | pChipInfoProtocol, StrHwPlatform, |
| 660 | EFICHIPINFO_MAX_ID_LENGTH > Len ? Len : EFICHIPINFO_MAX_ID_LENGTH); |
| 661 | if (EFI_ERROR (Status)) { |
| 662 | DEBUG ((EFI_D_ERROR, "Failed to Get the ChipIdString\n")); |
| 663 | return; |
| 664 | } |
lijuang | a0136d3 | 2017-09-07 15:22:51 +0800 | [diff] [blame] | 665 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 666 | if (Len < ChipIdValidLen) |
| 667 | StrHwPlatform[Len - 1] = '\0'; |
| 668 | else |
| 669 | StrHwPlatform[ChipIdValidLen - 1] = '\0'; |
lijuang | 834ebd2 | 2016-09-07 18:27:29 +0800 | [diff] [blame] | 670 | } |