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