summaryrefslogtreecommitdiff
path: root/Board/EM/Platform/EfiCombineImage/EfiCombineImage.c
blob: 34dd3214a198e6f194d47e04b48a2f6b982407d2 (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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
//*************************************************************************
//*************************************************************************
//**                                                                     **
//**        (C)Copyright 1985-2012, American Megatrends, Inc.            **
//**                                                                     **
//**                       All Rights Reserved.                          **
//**                                                                     **
//**      5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093           **
//**                                                                     **
//**                       Phone: (770)-246-8600                         **
//**                                                                     **
//*************************************************************************
//*************************************************************************

//*************************************************************************
// $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/Platform/EfiCombineImage/EfiCombineImage.c 1     12/18/12 11:10p Alanlin $
//
// $Revision: 1 $
//
// $Date: 12/18/12 11:10p $
//*************************************************************************
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/Platform/EfiCombineImage/EfiCombineImage.c $
// 
// 1     12/18/12 11:10p Alanlin
// 
// 
//*************************************************************************
//<AMI_FHDR_START>
//
// Name:
//
// Description:
//
//<AMI_FHDR_END>
//*************************************************************************

// Include(s)

#include "Efi.h"
#include "token.h"
#include <AmiLib.h>
#include <AmiCspLib.h>
#include <AmiDxeLib.h>
#include <Pci.h>
#include <Setup.h>
#include <Protocol\PciIo.h>

// Constant Definition(s)

// Macro Definition(s)

// Type Definition(s)

// Function Prototype(s)


// Variable Declaration(s)

// GUID Definition(s)
#if (PI_SPECIFICATION_VERSION < 0x00010000)    
EFI_GUID gFvProtocolGuid = EFI_FIRMWARE_VOLUME_PROTOCOL_GUID;
#else
EFI_GUID gFvProtocolGuid = EFI_FIRMWARE_VOLUME2_PROTOCOL_GUID;
#endif

#if NVidia_Optimus_dGPU == 1
EFI_GUID gEfiCombineImageGuid = NVidia_dGPU_HEADER_GUID;
#endif
#if AMD_PX_CHELSEA_dGPU == 1
EFI_GUID gEfiCombineImageGuid1 = AMD_CHELSEA_HEADER_GUID;
#endif
#if AMD_PX_THAMES_dGPU == 1
EFI_GUID gEfiCombineImageGuid2 = AMD_THAMES_HEADER_GUID;
#endif

// Protocol Definition(s)

// External Declaration(s)

// Function Definition(s)


//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Name:        GetEfiCombineImage
//
// Description: None.
//
// Input:       None.
//
// Output:      None.
//
// Notes:       None.
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>

EFI_STATUS GetEfiCombineImage (
    IN  PCI_DEV_INFO    *Device,
    OUT VOID            *RomImage,
    OUT UINT64          RomSize
)
{
    EFI_STATUS                      Status;
    UINTN                           FvProtocolCount;
    EFI_HANDLE                      *FvHandles = NULL;
#if (PI_SPECIFICATION_VERSION < 0x00010000)
    EFI_FIRMWARE_VOLUME_PROTOCOL    *Fv;
#else
    EFI_FIRMWARE_VOLUME2_PROTOCOL   *Fv;
#endif
    UINTN                           Index;
    UINT32                          AuthenticationStatus;
    UINT8                           *Buffer = NULL;
    UINTN                           BufferSize;

    Status = pBS->LocateHandleBuffer (
                  ByProtocol,
                  &gFvProtocolGuid,
                  NULL,
                  &FvProtocolCount,
                  &FvHandles
                  );
    if (!EFI_ERROR (Status)) {
        for (Index = 0; Index < FvProtocolCount; Index++) {
            Status = pBS->HandleProtocol (
                          FvHandles[Index],
                          &gFvProtocolGuid,
                          (VOID **) &Fv
                          );
            if (!EFI_ERROR (Status)) {

	      switch (Device->DevVenId.DevId) 
	      {
#if NVidia_Optimus_dGPU == 1
		case NVidia_dGPU_DID :	
		Status = Fv->ReadSection(
			Fv,&gEfiCombineImageGuid,
			EFI_SECTION_RAW,0,
			&Buffer,&BufferSize,
			&AuthenticationStatus
		);
		  break;
#endif

#if AMD_PX_CHELSEA_dGPU == 1
		case AMD_CHELSEA_DID :	
		Status = Fv->ReadSection(
			Fv,&gEfiCombineImageGuid1,
			EFI_SECTION_RAW,0,
			&Buffer,&BufferSize,
			&AuthenticationStatus
		);
		  break;
#endif

#if AMD_PX_THAMES_dGPU == 1
		case AMD_THAMES_DID :	
		Status = Fv->ReadSection(
			Fv,&gEfiCombineImageGuid2,
			EFI_SECTION_RAW,0,
			&Buffer,&BufferSize,
			&AuthenticationStatus
		);
		  break;
#endif
		default :
		  break;
	      }

                if (!EFI_ERROR (Status)) {
                    if(Device->PciIo.RomImage != NULL) {
                        pBS->FreePool (Device->PciIo.RomImage);
                        Device->PciIo.RomImage = NULL;
                        Device->PciIo.RomSize = 0;
                    }
                    //Check if Embeded Op ROM is valid...
                    if(*((UINT16*)Buffer)!=PCI_OPT_ROM_SIG) Status=EFI_NOT_FOUND;
                    else{
                        //Allocate buffer for ROM Image.
                        Device->PciIo.RomImage = Malloc (BufferSize);
                        if(Device->PciIo.RomImage == NULL) Status = EFI_OUT_OF_RESOURCES;
                        else {
                            MemCpy (Device->PciIo.RomImage, Buffer, BufferSize);
                            Device->PciIo.RomSize = BufferSize;
                            Device->Capab |= (EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE + EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM);
                            Device->Attrib |= (EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE + EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM);
                            Status = EFI_SUCCESS;
                        }
                    }
                    break;
                }
            }
        }
    }
    else {
        Status = EFI_NOT_FOUND;
    }

    if (FvHandles != NULL) {
        pBS->FreePool (FvHandles);
        FvHandles = NULL;
    }

    return Status;
}


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