StandaloneMmPkg: Add CPU driver suitable for ARM Platforms.
[mirror_edk2.git] / StandaloneMmPkg / Core / FwVol.c
CommitLineData
6b46d772
SV
1/**@file\r
2\r
3Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
4Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.<BR>\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "StandaloneMmCore.h"\r
16#include <Library/FvLib.h>\r
17\r
18//\r
19// List of file types supported by dispatcher\r
20//\r
21EFI_FV_FILETYPE mMmFileTypes[] = {\r
22 EFI_FV_FILETYPE_MM,\r
23 0xE, //EFI_FV_FILETYPE_MM_STANDALONE,\r
24 //\r
25 // Note: DXE core will process the FV image file, so skip it in MM core\r
26 // EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE\r
27 //\r
28};\r
29\r
30EFI_STATUS\r
31MmAddToDriverList (\r
32 IN EFI_HANDLE FvHandle,\r
33 IN VOID *Pe32Data,\r
34 IN UINTN Pe32DataSize,\r
35 IN VOID *Depex,\r
36 IN UINTN DepexSize,\r
37 IN EFI_GUID *DriverName\r
38 );\r
39\r
40BOOLEAN\r
41FvHasBeenProcessed (\r
42 IN EFI_HANDLE FvHandle\r
43 );\r
44\r
45VOID\r
46FvIsBeingProcesssed (\r
47 IN EFI_HANDLE FvHandle\r
48 );\r
49\r
50EFI_STATUS\r
51MmCoreFfsFindMmDriver (\r
52 IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader\r
53 )\r
54/*++\r
55\r
56Routine Description:\r
57 Given the pointer to the Firmware Volume Header find the\r
58 MM driver and return it's PE32 image.\r
59\r
60Arguments:\r
61 FwVolHeader - Pointer to memory mapped FV\r
62\r
63Returns:\r
64 other - Failure\r
65\r
66--*/\r
67{\r
68 EFI_STATUS Status;\r
69 EFI_STATUS DepexStatus;\r
70 EFI_FFS_FILE_HEADER *FileHeader;\r
71 EFI_FV_FILETYPE FileType;\r
72 VOID *Pe32Data;\r
73 UINTN Pe32DataSize;\r
74 VOID *Depex;\r
75 UINTN DepexSize;\r
76 UINTN Index;\r
77\r
78 DEBUG ((DEBUG_INFO, "MmCoreFfsFindMmDriver - 0x%x\n", FwVolHeader));\r
79\r
80 if (FvHasBeenProcessed (FwVolHeader)) {\r
81 return EFI_SUCCESS;\r
82 }\r
83\r
84 FvIsBeingProcesssed (FwVolHeader);\r
85\r
86 for (Index = 0; Index < sizeof (mMmFileTypes) / sizeof (mMmFileTypes[0]); Index++) {\r
87 DEBUG ((DEBUG_INFO, "Check MmFileTypes - 0x%x\n", mMmFileTypes[Index]));\r
88 FileType = mMmFileTypes[Index];\r
89 FileHeader = NULL;\r
90 do {\r
91 Status = FfsFindNextFile (FileType, FwVolHeader, &FileHeader);\r
92 if (!EFI_ERROR (Status)) {\r
93 Status = FfsFindSectionData (EFI_SECTION_PE32, FileHeader, &Pe32Data, &Pe32DataSize);\r
94 DEBUG ((DEBUG_INFO, "Find PE data - 0x%x\n", Pe32Data));\r
95 DepexStatus = FfsFindSectionData (EFI_SECTION_MM_DEPEX, FileHeader, &Depex, &DepexSize);\r
96 if (!EFI_ERROR (DepexStatus)) {\r
97 MmAddToDriverList (FwVolHeader, Pe32Data, Pe32DataSize, Depex, DepexSize, &FileHeader->Name);\r
98 }\r
99 }\r
100 } while (!EFI_ERROR (Status));\r
101 }\r
102\r
103 return Status;\r
104}\r