blob: f830e728426d087ae2385fe2f09ed3783ac6b4fa [file] [log] [blame]
Vijay Kumar Pendoti78b1a962017-01-12 22:48:41 +05301/* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved.
Sridhar Parasuramc8f50022015-12-05 10:36:04 -08002 *
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>
lijuang834ebd22016-09-07 18:27:29 +080031#include <Protocol/EFIPlatformInfoTypes.h>
lijuang24de5342016-09-07 18:09:10 +080032#include <Library/UpdateDeviceTree.h>
lijuang6a97bc52016-10-18 17:32:54 +080033#include <Library/BootImage.h>
34
Sridhar Parasuramc8f50022015-12-05 10:36:04 -080035#include <LinuxLoaderLib.h>
36
Channagoud Kadabi539d3072016-02-11 21:34:48 -080037STATIC struct BoardInfo platform_board_info;
38
lijuang24de5342016-09-07 18:09:10 +080039STATIC CONST CHAR8 *DeviceType[] = {
40 [EMMC] = "EMMC",
41 [UFS] = "UFS",
42 [UNKNOWN] = "Unknown",
43};
44
Vijay Kumar Pendotic52e80b2016-10-12 16:47:50 +053045EFI_STATUS GetRamPartitions(RamPartitionEntry **RamPartitions, UINT32 *NumPartitions) {
46
Sridhar Parasuramc8f50022015-12-05 10:36:04 -080047 EFI_STATUS Status = EFI_NOT_FOUND;
48 EFI_RAMPARTITION_PROTOCOL *pRamPartProtocol = NULL;
Sridhar Parasuramc8f50022015-12-05 10:36:04 -080049
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 Pendotic52e80b2016-10-12 16:47:50 +053056 Status = pRamPartProtocol->GetRamPartitions (pRamPartProtocol, NULL, NumPartitions);
Sridhar Parasuramc8f50022015-12-05 10:36:04 -080057 if (Status == EFI_BUFFER_TOO_SMALL)
58 {
Vijay Kumar Pendotic52e80b2016-10-12 16:47:50 +053059 *RamPartitions = AllocatePool (*NumPartitions * sizeof (RamPartitionEntry));
lijuanga4c1b082016-12-08 19:12:48 +080060 if (*RamPartitions == NULL)
Sridhar Parasuramc8f50022015-12-05 10:36:04 -080061 return EFI_OUT_OF_RESOURCES;
62
Vijay Kumar Pendotic52e80b2016-10-12 16:47:50 +053063 Status = pRamPartProtocol->GetRamPartitions (pRamPartProtocol, *RamPartitions, NumPartitions);
64 if (EFI_ERROR (Status) || (*NumPartitions < 1) )
Sridhar Parasuramc8f50022015-12-05 10:36:04 -080065 {
66 DEBUG((EFI_D_ERROR, "Failed to get RAM partitions"));
67 return EFI_NOT_FOUND;
68 }
Vijay Kumar Pendotic52e80b2016-10-12 16:47:50 +053069 } else {
70 DEBUG((EFI_D_ERROR, "Error Occured while populating RamPartitions\n"));
71 return EFI_PROTOCOL_ERROR;
72 }
73 return Status;
74}
75
lijuang94109952016-10-28 19:33:55 +080076EFI_STATUS BaseMem(UINT64 *BaseMemory)
Vijay Kumar Pendotic52e80b2016-10-12 16:47:50 +053077{
78 EFI_STATUS Status = EFI_NOT_FOUND;
79 RamPartitionEntry *RamPartitions = NULL;
80 UINT32 NumPartitions = 0;
lijuang94109952016-10-28 19:33:55 +080081 UINT64 SmallestBase;
Vijay Kumar Pendotic52e80b2016-10-12 16:47:50 +053082 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 Parasuramc8f50022015-12-05 10:36:04 -080092 }
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 Pendotidf4a1d42016-10-12 16:55:54 +0530100 DEBUG((EFI_D_INFO, "Memory Base Address: 0x%x\n", *BaseMemory));
Vijay Kumar Pendotic52e80b2016-10-12 16:47:50 +0530101 FreePool(RamPartitions);
Sridhar Parasuramc8f50022015-12-05 10:36:04 -0800102
Vijay Kumar Pendotic52e80b2016-10-12 16:47:50 +0530103 return Status;
Sridhar Parasuramc8f50022015-12-05 10:36:04 -0800104}
105
106STATIC 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;
lijuang2120d972016-11-02 18:28:21 +0800122 Status = pChipInfoProtocol->GetChipIdString(pChipInfoProtocol, platform_board_info->ChipBaseBand, EFICHIPINFO_MAX_ID_LENGTH);
Vijay Kumar Pendoti582158c2016-09-29 23:47:37 +0530123 if (EFI_ERROR(Status))
124 return Status;
Channagoud Kadabi539d3072016-02-11 21:34:48 -0800125 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 Pendoti582158c2016-09-29 23:47:37 +0530128 DEBUG((EFI_D_VERBOSE, "Chip BaseBand : %a\n", platform_board_info->ChipBaseBand));
Sridhar Parasuramc8f50022015-12-05 10:36:04 -0800129 return Status;
130}
131
132STATIC 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 Pendoti02cd05b2016-07-19 17:50:54 +0530158 DEBUG((EFI_D_VERBOSE, "Platform Info : 0x%x\n", platform_board_info->PlatformInfo.platform));
Sridhar Parasuramc8f50022015-12-05 10:36:04 -0800159endtest:
160 return eResult;
161}
162
Vijay Kumar Pendoti0be25612016-11-18 18:52:46 +0530163STATIC EFI_STATUS GetPmicInfoExt(UINT32 PmicDeviceIndex, EFI_PM_DEVICE_INFO_EXT_TYPE *pmic_info_ext)
Sridhar Parasuramc8f50022015-12-05 10:36:04 -0800164{
165 EFI_STATUS Status;
166 EFI_QCOM_PMIC_VERSION_PROTOCOL *pPmicVersionProtocol;
Vijay Kumar Pendoti0be25612016-11-18 18:52:46 +0530167
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
183STATIC 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 Parasuramc8f50022015-12-05 10:36:04 -0800188 Status = gBS->LocateProtocol (&gQcomPmicVersionProtocolGuid, NULL,
189 (VOID **) &pPmicVersionProtocol);
190 if (EFI_ERROR(Status))
Channagoud Kadabi5bd40992016-03-04 15:05:20 -0800191 {
192 DEBUG((EFI_D_ERROR, "Error locating pmic protocol: %r\n", Status));
Sridhar Parasuramc8f50022015-12-05 10:36:04 -0800193 return Status;
Channagoud Kadabi5bd40992016-03-04 15:05:20 -0800194 }
Vijay Kumar Pendoti0be25612016-11-18 18:52:46 +0530195
196 *Revision = pPmicVersionProtocol->Revision;
197
Sridhar Parasuramc8f50022015-12-05 10:36:04 -0800198 Status = pPmicVersionProtocol->GetPmicInfo(PmicDeviceIndex, pmic_info);
199 if (EFI_ERROR(Status))
Channagoud Kadabi5bd40992016-03-04 15:05:20 -0800200 {
201 DEBUG((EFI_D_ERROR, "Error getting pmic info: %r\n", Status));
Sridhar Parasuramc8f50022015-12-05 10:36:04 -0800202 return Status;
Channagoud Kadabi5bd40992016-03-04 15:05:20 -0800203 }
Sridhar Parasuramc8f50022015-12-05 10:36:04 -0800204 return Status;
205}
206
lijuang24de5342016-09-07 18:09:10 +0800207/**
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 Shriramab436682016-09-23 07:08:06 -0700216UINT32 CheckRootDeviceType(VOID *HanderInfo, UINT32 MaxHandles)
lijuang24de5342016-09-07 18:09:10 +0800217{
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 **/
254VOID 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
lijuang6a97bc52016-10-18 17:32:54 +0800268/**
269 Get device page size
270 @param[out] PageSize : Pointer to the page size.
271 **/
272VOID 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 Parasuramc8f50022015-12-05 10:36:04 -0800294UINT32 BoardPmicModel(UINT32 PmicDeviceIndex)
295{
Channagoud Kadabi5bd40992016-03-04 15:05:20 -0800296 EFI_STATUS Status;
Sridhar Parasuramc8f50022015-12-05 10:36:04 -0800297 EFI_PM_DEVICE_INFO_TYPE pmic_info;
Vijay Kumar Pendoti0be25612016-11-18 18:52:46 +0530298 UINT64 Revision;
299
300 Status = GetPmicInfo(PmicDeviceIndex, &pmic_info, &Revision);
Channagoud Kadabi5bd40992016-03-04 15:05:20 -0800301 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 Parasuramc8f50022015-12-05 10:36:04 -0800307 return pmic_info.PmicModel;
308}
309
310UINT32 BoardPmicTarget(UINT32 PmicDeviceIndex)
311{
312 UINT32 target;
Channagoud Kadabi5bd40992016-03-04 15:05:20 -0800313 EFI_STATUS Status;
Vijay Kumar Pendoti0be25612016-11-18 18:52:46 +0530314 UINT64 Revision;
Sridhar Parasuramc8f50022015-12-05 10:36:04 -0800315 EFI_PM_DEVICE_INFO_TYPE pmic_info;
Vijay Kumar Pendoti0be25612016-11-18 18:52:46 +0530316 EFI_PM_DEVICE_INFO_EXT_TYPE pmic_info_ext;
317
318 Status = GetPmicInfo(PmicDeviceIndex, &pmic_info, &Revision);
Channagoud Kadabi5bd40992016-03-04 15:05:20 -0800319 if (Status != EFI_SUCCESS)
320 {
321 DEBUG((EFI_D_ERROR, "Error finding board pmic info: %r\n", Status));
322 ASSERT(0);
323 }
Vijay Kumar Pendoti0be25612016-11-18 18:52:46 +0530324
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 Kadabi5bd40992016-03-04 15:05:20 -0800338 DEBUG((EFI_D_VERBOSE, "PMIC Target 0x%x: 0x%x\n", PmicDeviceIndex, target));
Sridhar Parasuramc8f50022015-12-05 10:36:04 -0800339 return target;
340}
341
Channagoud Kadabi539d3072016-02-11 21:34:48 -0800342EFI_STATUS BoardInit()
Sridhar Parasuramc8f50022015-12-05 10:36:04 -0800343{
344 EFI_STATUS Status;
Channagoud Kadabi539d3072016-02-11 21:34:48 -0800345 Status = GetChipInfo(&platform_board_info);
Sridhar Parasuramc8f50022015-12-05 10:36:04 -0800346 if (EFI_ERROR(Status))
347 return Status;
Channagoud Kadabi539d3072016-02-11 21:34:48 -0800348 Status = GetPlatformInfo(&platform_board_info);
Sridhar Parasuramc8f50022015-12-05 10:36:04 -0800349 if (EFI_ERROR(Status))
350 return Status;
Channagoud Kadabi539d3072016-02-11 21:34:48 -0800351
Sridhar Parasuramc8f50022015-12-05 10:36:04 -0800352 return Status;
353}
354
Vijay Kumar Pendoti09d572e2016-08-27 03:22:36 +0530355EFI_STATUS UfsGetSetBootLun(UINT32 *UfsBootlun, BOOLEAN IsGet)
356{
357 EFI_STATUS Status = EFI_INVALID_PARAMETER;
Vijay Kumar Pendoti09d572e2016-08-27 03:22:36 +0530358 EFI_MEM_CARDINFO_PROTOCOL *CardInfo;
Vijay Kumar Pendoti09d572e2016-08-27 03:22:36 +0530359 HandleInfo HandleInfoList[MAX_HANDLE_INFO_LIST];
360 UINT32 Attribs = 0;
361 UINT32 MaxHandles;
362 PartiSelectFilter HandleFilter;
Vijay Kumar Pendoti09d572e2016-08-27 03:22:36 +0530363
364 Attribs |= BLK_IO_SEL_MATCH_ROOT_DEVICE;
Vijay Kumar Pendoti09d572e2016-08-27 03:22:36 +0530365 MaxHandles = ARRAY_SIZE(HandleInfoList);
366 HandleFilter.PartitionType = 0;
367 HandleFilter.VolumeName = 0;
Vijay Kumar Pendotid420e2a2016-11-21 19:50:53 +0530368 HandleFilter.RootDeviceType = &gEfiUfsLU0Guid;
Vijay Kumar Pendoti09d572e2016-08-27 03:22:36 +0530369
370 Status = GetBlkIOHandles(Attribs, &HandleFilter, HandleInfoList, &MaxHandles);
Vijay Kumar Pendotid420e2a2016-11-21 19:50:53 +0530371 if (EFI_ERROR (Status))
372 return EFI_NOT_FOUND;
Vijay Kumar Pendoti09d572e2016-08-27 03:22:36 +0530373
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 Kadabi0dbf8692016-09-30 16:17:11 -0700389 DEBUG((EFI_D_VERBOSE, "Get BootLun =%u\n",*UfsBootlun));
Vijay Kumar Pendoti09d572e2016-08-27 03:22:36 +0530390 } else {
391 if (CardInfo->SetBootLU (CardInfo, *UfsBootlun) == EFI_SUCCESS)
Channagoud Kadabi0dbf8692016-09-30 16:17:11 -0700392 DEBUG((EFI_D_VERBOSE, "SetBootLun =%u\n",*UfsBootlun));
Vijay Kumar Pendoti09d572e2016-08-27 03:22:36 +0530393 }
394 return Status;
395}
396
Sridhar Parasuramc8f50022015-12-05 10:36:04 -0800397EFI_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 Parasuramc8f50022015-12-05 10:36:04 -0800402 UINT32 SerialNo;
lijuang24de5342016-09-07 18:09:10 +0800403 HandleInfo HandleInfoList[HANDLE_MAX_INFO_LIST];
404 UINT32 MaxHandles = ARRAY_SIZE(HandleInfoList);
405 MemCardType Type = EMMC;
Sridhar Parasuramc8f50022015-12-05 10:36:04 -0800406
lijuang24de5342016-09-07 18:09:10 +0800407 Type = CheckRootDeviceType(HandleInfoList, MaxHandles);
408 if (Type == UNKNOWN)
409 return EFI_NOT_FOUND;
Sridhar Parasuramc8f50022015-12-05 10:36:04 -0800410
411 Status = gBS->HandleProtocol(HandleInfoList[0].Handle,
412 &gEfiMemCardInfoProtocolGuid,
413 (VOID**)&CardInfo);
Sridhar Parasuramc8f50022015-12-05 10:36:04 -0800414 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 Pendoti78b1a962017-01-12 22:48:41 +0530431 } else {
432 AsciiSPrint(StrSerialNum, Len, "%x", *(UINT32 *)CardInfoData.product_serial_num);
Sridhar Parasuramc8f50022015-12-05 10:36:04 -0800433 }
Vijay Kumar Pendoti78b1a962017-01-12 22:48:41 +0530434
435 /* adb is case sensitive, convert the serial number to lower case
436 * to maintain uniformity across the system. */
437 ToLower(StrSerialNum);
Sridhar Parasuramc8f50022015-12-05 10:36:04 -0800438 }
439 return Status;
440}
Channagoud Kadabi539d3072016-02-11 21:34:48 -0800441
442/* Helper APIs for device tree selection */
443UINT32 BoardPlatformRawChipId()
444{
445 return platform_board_info.RawChipId;
446}
447
448EFIChipInfoVersionType BoardPlatformChipVersion()
449{
450 return platform_board_info.ChipVersion;
451}
452
453EFIChipInfoFoundryIdType BoardPlatformFoundryId()
454{
455 return platform_board_info.FoundryId;
456}
457
Vijay Kumar Pendoti582158c2016-09-29 23:47:37 +0530458CHAR8* BoardPlatformChipBaseBand()
459{
460 return platform_board_info.ChipBaseBand;
461}
462
Channagoud Kadabi539d3072016-02-11 21:34:48 -0800463EFI_PLATFORMINFO_PLATFORM_TYPE BoardPlatformType()
464{
465 return platform_board_info.PlatformInfo.platform;
466}
467
468UINT32 BoardPlatformVersion()
469{
470 return platform_board_info.PlatformInfo.version;
471}
472
473UINT32 BoardPlatformSubType()
474{
475 return platform_board_info.PlatformInfo.subtype;
476}
Channagoud Kadabi5bd40992016-03-04 15:05:20 -0800477
478UINT32 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}
lijuang834ebd22016-09-07 18:27:29 +0800489
490VOID BoardHwPlatformName(CHAR8 *StrHwPlatform, UINT32 Len)
491{
492 EFI_STATUS Status;
Vijay Kumar Pendotid420e2a2016-11-21 19:50:53 +0530493 EFI_CHIPINFO_PROTOCOL *pChipInfoProtocol;
494 UINT32 ChipIdValidLen = 4;
lijuang834ebd22016-09-07 18:27:29 +0800495
496 if (StrHwPlatform == NULL) {
497 DEBUG((EFI_D_ERROR, "Error: HW Platform string is NULL\n"));
498 return;
499 }
500
Vijay Kumar Pendotid420e2a2016-11-21 19:50:53 +0530501 Status = gBS->LocateProtocol (&gEfiChipInfoProtocolGuid, NULL,(VOID **) &pChipInfoProtocol);
502 if (EFI_ERROR(Status)) {
503 DEBUG((EFI_D_ERROR, "Locate Protocol failed for gEfiChipInfoProtocolGuid\n"));
lijuang834ebd22016-09-07 18:27:29 +0800504 return;
505 }
506
Vijay Kumar Pendotid420e2a2016-11-21 19:50:53 +0530507 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"));
lijuang834ebd22016-09-07 18:27:29 +0800510 return;
511 }
Vijay Kumar Pendotid420e2a2016-11-21 19:50:53 +0530512 StrHwPlatform[ChipIdValidLen-1] = '\0';
lijuang834ebd22016-09-07 18:27:29 +0800513}