]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Application/LinuxLoader/LinuxLoaderHelper.c
BeagleBoardPkg/BeagleBoardPkg.dsc: remove the LinuxLoader application
[mirror_edk2.git] / ArmPkg / Application / LinuxLoader / LinuxLoaderHelper.c
CommitLineData
23b01c83
RC
1/** @file\r
2*\r
3* Copyright (c) 2011-2015, ARM Limited. All rights reserved.\r
4*\r
5* This program and the accompanying materials\r
6* are licensed and made available under the terms and conditions of the BSD License\r
7* which accompanies this distribution. The full text of the license may be found at\r
8* http://opensource.org/licenses/bsd-license.php\r
9*\r
10* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12*\r
13**/\r
14\r
15#include <PiDxe.h>\r
16#include <Library/HobLib.h>\r
17#include <Library/TimerLib.h>\r
18#include <Library/SerialPortLib.h>\r
19\r
20#include "LinuxLoader.h"\r
21\r
22STATIC CONST CHAR8 *mTokenList[] = {\r
23 /*"SEC",*/\r
24 "PEI",\r
25 "DXE",\r
26 "BDS",\r
27 NULL\r
28};\r
29\r
30VOID\r
31PrintPerformance (\r
32 VOID\r
33 )\r
34{\r
35 UINTN Key;\r
36 CONST VOID *Handle;\r
37 CONST CHAR8 *Token, *Module;\r
38 UINT64 Start, Stop, TimeStamp;\r
39 UINT64 Delta, TicksPerSecond, Milliseconds;\r
40 UINTN Index;\r
41 CHAR8 Buffer[100];\r
42 UINTN CharCount;\r
43 BOOLEAN CountUp;\r
44\r
45 TicksPerSecond = GetPerformanceCounterProperties (&Start, &Stop);\r
46 if (Start < Stop) {\r
47 CountUp = TRUE;\r
48 } else {\r
49 CountUp = FALSE;\r
50 }\r
51\r
52 TimeStamp = 0;\r
53 Key = 0;\r
54 do {\r
55 Key = GetPerformanceMeasurement (Key, (CONST VOID **)&Handle, &Token, &Module, &Start, &Stop);\r
56 if (Key != 0) {\r
57 for (Index = 0; mTokenList[Index] != NULL; Index++) {\r
58 if (AsciiStriCmp (mTokenList[Index], Token) == 0) {\r
59 Delta = CountUp ? (Stop - Start) : (Start - Stop);\r
60 TimeStamp += Delta;\r
61 Milliseconds = DivU64x64Remainder (MultU64x32 (Delta, 1000), TicksPerSecond, NULL);\r
62 CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "%6a %6ld ms\n", Token, Milliseconds);\r
63 SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
64 break;\r
65 }\r
66 }\r
67 }\r
68 } while (Key != 0);\r
69\r
70 CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "Total Time = %ld ms\n\n",\r
71 DivU64x64Remainder (MultU64x32 (TimeStamp, 1000), TicksPerSecond, NULL));\r
72 SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
73}\r
74\r
75STATIC\r
76EFI_STATUS\r
77InsertSystemMemoryResources (\r
78 LIST_ENTRY *ResourceList,\r
79 EFI_HOB_RESOURCE_DESCRIPTOR *ResHob\r
80 )\r
81{\r
82 SYSTEM_MEMORY_RESOURCE *NewResource;\r
83 LIST_ENTRY *Link;\r
84 LIST_ENTRY *NextLink;\r
85 LIST_ENTRY AttachedResources;\r
86 SYSTEM_MEMORY_RESOURCE *Resource;\r
87 EFI_PHYSICAL_ADDRESS NewResourceEnd;\r
88\r
89 if (IsListEmpty (ResourceList)) {\r
90 NewResource = AllocateZeroPool (sizeof (SYSTEM_MEMORY_RESOURCE));\r
91 NewResource->PhysicalStart = ResHob->PhysicalStart;\r
92 NewResource->ResourceLength = ResHob->ResourceLength;\r
93 InsertTailList (ResourceList, &NewResource->Link);\r
94 return EFI_SUCCESS;\r
95 }\r
96\r
97 InitializeListHead (&AttachedResources);\r
98\r
99 Link = ResourceList->ForwardLink;\r
100 ASSERT (Link != NULL);\r
101 while (Link != ResourceList) {\r
102 Resource = (SYSTEM_MEMORY_RESOURCE*)Link;\r
103\r
104 // Sanity Check. The resources should not overlapped.\r
105 ASSERT (!((ResHob->PhysicalStart >= Resource->PhysicalStart) && (ResHob->PhysicalStart < (Resource->PhysicalStart + Resource->ResourceLength))));\r
106 ASSERT (!((ResHob->PhysicalStart + ResHob->ResourceLength - 1 >= Resource->PhysicalStart) &&\r
107 ((ResHob->PhysicalStart + ResHob->ResourceLength - 1) < (Resource->PhysicalStart + Resource->ResourceLength))));\r
108\r
109 // The new resource is attached after this resource descriptor\r
110 if (ResHob->PhysicalStart == Resource->PhysicalStart + Resource->ResourceLength) {\r
111 Resource->ResourceLength = Resource->ResourceLength + ResHob->ResourceLength;\r
112\r
113 NextLink = RemoveEntryList (&Resource->Link);\r
114 InsertTailList (&AttachedResources, &Resource->Link);\r
115 Link = NextLink;\r
116 }\r
117 // The new resource is attached before this resource descriptor\r
118 else if (ResHob->PhysicalStart + ResHob->ResourceLength == Resource->PhysicalStart) {\r
119 Resource->PhysicalStart = ResHob->PhysicalStart;\r
120 Resource->ResourceLength = Resource->ResourceLength + ResHob->ResourceLength;\r
121\r
122 NextLink = RemoveEntryList (&Resource->Link);\r
123 InsertTailList (&AttachedResources, &Resource->Link);\r
124 Link = NextLink;\r
125 } else {\r
126 Link = Link->ForwardLink;\r
127 }\r
128 }\r
129\r
130 if (!IsListEmpty (&AttachedResources)) {\r
131 // See if we can merge the attached resource with other resources\r
132\r
133 NewResource = (SYSTEM_MEMORY_RESOURCE*)GetFirstNode (&AttachedResources);\r
134 Link = RemoveEntryList (&NewResource->Link);\r
135 while (!IsListEmpty (&AttachedResources)) {\r
136 // Merge resources\r
137 Resource = (SYSTEM_MEMORY_RESOURCE*)Link;\r
138\r
139 // Ensure they overlap each other\r
140 ASSERT (\r
141 ((NewResource->PhysicalStart >= Resource->PhysicalStart) && (NewResource->PhysicalStart < (Resource->PhysicalStart + Resource->ResourceLength))) ||\r
142 (((NewResource->PhysicalStart + NewResource->ResourceLength) >= Resource->PhysicalStart) && ((NewResource->PhysicalStart + NewResource->ResourceLength) < (Resource->PhysicalStart + Resource->ResourceLength)))\r
143 );\r
144\r
145 NewResourceEnd = MAX (NewResource->PhysicalStart + NewResource->ResourceLength, Resource->PhysicalStart + Resource->ResourceLength);\r
146 NewResource->PhysicalStart = MIN (NewResource->PhysicalStart, Resource->PhysicalStart);\r
147 NewResource->ResourceLength = NewResourceEnd - NewResource->PhysicalStart;\r
148\r
149 Link = RemoveEntryList (Link);\r
150 }\r
151 } else {\r
152 // None of the Resource of the list is attached to this ResHob. Create a new entry for it\r
153 NewResource = AllocateZeroPool (sizeof (SYSTEM_MEMORY_RESOURCE));\r
154 NewResource->PhysicalStart = ResHob->PhysicalStart;\r
155 NewResource->ResourceLength = ResHob->ResourceLength;\r
156 }\r
157 InsertTailList (ResourceList, &NewResource->Link);\r
158 return EFI_SUCCESS;\r
159}\r
160\r
161EFI_STATUS\r
162GetSystemMemoryResources (\r
163 IN LIST_ENTRY *ResourceList\r
164 )\r
165{\r
166 EFI_HOB_RESOURCE_DESCRIPTOR *ResHob;\r
167\r
168 InitializeListHead (ResourceList);\r
169\r
170 // Find the first System Memory Resource Descriptor\r
171 ResHob = (EFI_HOB_RESOURCE_DESCRIPTOR *)GetFirstHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR);\r
172 while ((ResHob != NULL) && (ResHob->ResourceType != EFI_RESOURCE_SYSTEM_MEMORY)) {\r
173 ResHob = (EFI_HOB_RESOURCE_DESCRIPTOR *)GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, (VOID *)((UINTN)ResHob + ResHob->Header.HobLength));\r
174 }\r
175\r
176 // Did not find any\r
177 if (ResHob == NULL) {\r
178 return EFI_NOT_FOUND;\r
179 } else {\r
180 InsertSystemMemoryResources (ResourceList, ResHob);\r
181 }\r
182\r
183 ResHob = (EFI_HOB_RESOURCE_DESCRIPTOR *)GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, (VOID *)((UINTN)ResHob + ResHob->Header.HobLength));\r
184 while (ResHob != NULL) {\r
185 if (ResHob->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) {\r
186 InsertSystemMemoryResources (ResourceList, ResHob);\r
187 }\r
188 ResHob = (EFI_HOB_RESOURCE_DESCRIPTOR *)GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, (VOID *)((UINTN)ResHob + ResHob->Header.HobLength));\r
189 }\r
190\r
191 return EFI_SUCCESS;\r
192}\r