summaryrefslogtreecommitdiff
path: root/Chipset/SB/PchWrap/PchSpiWrap/PchSpiWrap.c
blob: 237366a2f441483276052f7bf7b08bd2eadb80d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//*************************************************************************
//*************************************************************************
//**                                                                     **
//**        (C)Copyright 1985-2011, American Megatrends, Inc.            **
//**                                                                     **
//**                       All Rights Reserved.                          **
//**                                                                     **
//**      5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093           **
//**                                                                     **
//**                       Phone: (770)-246-8600                         **
//**                                                                     **
//*************************************************************************
//*************************************************************************

//*************************************************************************
// $Header: /Alaska/BIN/Chipset/Intel/SouthBridge/LynxPoint/Intel Pch SB Chipset/PchWrap/PchSpiWrap/PchSpiWrap.c 2     11/17/14 7:31a Mirayang $
//
// $Revision: 2 $
//
// $Date: 11/17/14 7:31a $
//*************************************************************************
// Revision History
// ----------------
// $Log: /Alaska/BIN/Chipset/Intel/SouthBridge/LynxPoint/Intel Pch SB Chipset/PchWrap/PchSpiWrap/PchSpiWrap.c $
// 
// 2     11/17/14 7:31a Mirayang
// [TAG]  		EIP191661
// [Category]  	Improvement
// [Description]  	SUT can't generate UEFI SCT2.3.1 report completely.
// 
// 1     2/08/12 8:33a Yurenlai
// Intel Lynx Point/SB eChipset initially releases.
// 
//*************************************************************************
//----------------------------------------------------------------------
// Includes
#include <AmiDxeLib.h>
#include <Protocol\LoadPe32Image.h>
#include "token.h"


static EFI_GUID gDxeSvcTblGuid = DXE_SERVICES_TABLE_GUID;
EFI_GUID gPchSpiRuntimeFFsGuid = \
    {0xC194C6EA,0xB68C,0x4981,0xB6,0x4B,0x9B,0xD2,0x71,0x47,0x4B,0x20};

EFI_STATUS
FFsLoaderToRuntime( 
   IN  EFI_HANDLE    ImageHandle
);

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
//
// Procedure:   PchSpiWrapEntry
//
// Description: This function load PchSpi and execute it.
//
// Input:       ImageHandle       Image handle of this driver.
//              SystemTable       Global system service table.
//
// Output:      EFI_SUCCESS       Load and execute complete.
//              EFI_UNSUPPORTED       Image type is unsupported by this driver.
//              EFI_OUT_OF_RESOURCES  Do not have enough resources to initialize the driver.
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS
PchSpiWrapEntry(
  IN EFI_HANDLE       ImageHandle,
  IN EFI_SYSTEM_TABLE *SystemTable
  )
{
  EFI_STATUS                Status;
  
  InitAmiLib(ImageHandle, SystemTable);

  Status = FFsLoaderToRuntime( ImageHandle);
  ASSERT_EFI_ERROR (Status);

  return Status;
}


//<AMI_PHDR_START>
//----------------------------------------------------------------------------
//
// Procedure:   FFsLoaderToRuntime
//
// Description: Load FFs to Runtime.
//
// Input:       ImageHandle       Image handle of this driver.
//
// Output:      EFI_SUCCESS       FFs Load to Runtime complete.
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS
FFsLoaderToRuntime(
   IN  EFI_HANDLE    ImageHandle 
){
  EFI_STATUS                Status;
  EFI_PHYSICAL_ADDRESS      Dst;
  EFI_PHYSICAL_ADDRESS      EntryPoint;
  EFI_PE32_IMAGE_PROTOCOL   *LoadPeImageEx;
  VOID                      *Buffer;
  UINTN                     BufferSize;
  UINT32                    AuthenticationStatus;
  UINTN                     Pages;
  EFI_HANDLE                FFsImageHandle;
  EFI_DEVICE_PATH_PROTOCOL  EndOfDp = { 0x7F, 0xFF, 0x4 , 0x0 };

  Buffer = 0;

  Status = FvReadPe32Image (
             &gPchSpiRuntimeFFsGuid,
             &Buffer,
             &BufferSize,
             &AuthenticationStatus
             );

  if (EFI_ERROR (Status)) {
    return Status;
  }

  Pages = EFI_SIZE_TO_PAGES (BufferSize) + 2;
  Status = pBS->AllocatePages (
                  AllocateAnyPages,
                  EfiRuntimeServicesCode,
                  Pages,
                  &Dst
                  );

  Status = pBS->LocateProtocol (&gEfiLoadPeImageGuid, NULL, &LoadPeImageEx);
  if (EFI_ERROR (Status)) {
    pBS->FreePool (&Dst);
    return Status;
  }

  Status = LoadPeImageEx->LoadPeImage(
                            LoadPeImageEx,
                            ImageHandle,
//                            NULL,
                            &EndOfDp,
                            Buffer,
                            BufferSize,
                            Dst,
                            &Pages,
                            &FFsImageHandle,
                            &EntryPoint,
                            EFI_LOAD_PE_IMAGE_ATTRIBUTE_NONE
                            );
  if (EFI_ERROR (Status)) {
    pBS->FreePool (&Dst);
    return Status;
  }

  Status = pBS->StartImage(FFsImageHandle, NULL, NULL);
  pBS->FreePool(Buffer);

  return Status;
}
//*************************************************************************
//*************************************************************************
//**                                                                     **
//**        (C)Copyright 1985-2011, American Megatrends, Inc.            **
//**                                                                     **
//**                       All Rights Reserved.                          **
//**                                                                     **
//**      5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093           **
//**                                                                     **
//**                       Phone: (770)-246-8600                         **
//**                                                                     **
//*************************************************************************
//*************************************************************************