summaryrefslogtreecommitdiff
path: root/Board/EM/MeWrapper/MePciPlatform/MePciPlatform.c
blob: db1c1ee22983aa9358d1f597795794c8f9ea7bad (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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
//*************************************************************************
//*************************************************************************
//**                                                                     **
//**        (C)Copyright 1985-2010, American Megatrends, Inc.            **
//**                                                                     **
//**                       All Rights Reserved.                          **
//**                                                                     **
//**      5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093           **
//**                                                                     **
//**                       Phone: (770)-246-8600                         **
//**                                                                     **
//*************************************************************************
//*************************************************************************
//**********************************************************************
//
// $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/MeWrapper/MePciPlatform/MePciPlatform.c 1     2/08/12 1:05a Klzhan $
//
// $Revision: 1 $
//
// $Date: 2/08/12 1:05a $
//
//**********************************************************************
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/MeWrapper/MePciPlatform/MePciPlatform.c $
// 
// 1     2/08/12 1:05a Klzhan
// Initial Check in 
// 
// 1     2/25/11 1:41a Klzhan
// Initial Check-in
// 
// 1     12/03/10 5:09a Klzhan
// Initial Check-in.
// 
//
//**********************************************************************

//<AMI_FHDR_START>
//----------------------------------------------------------------------------
//
// Name:            MePciPlatform.c
//
// Description:
//
//----------------------------------------------------------------------------
//<AMI_FHDR_END>
/*++

This file contains a 'Sample Driver' and is licensed as such
under the terms of your license agreement with Intel or your
vendor.  This file may be modified by the user, subject to  
the additional terms of the license agreement               

--*/

/*++
Copyright (c)  2008 Intel Corporation. All rights reserved
This software and associated documentation (if any) is furnished
under a license and may only be used or copied in accordance
with the terms of the license. Except as permitted by such
license, no part of this software or documentation may be
reproduced, stored in a retrieval system, or transmitted in any
form or by any means without the express written consent of
Intel Corporation.
  
Module Name:

 MePciPlatform.c

Abstract:

  
--*/
#include "MePciPlatform.h"

#define SETUP_GUID \
  {0xEC87D643, 0xEBA4, 0x4BB5, 0xA1, 0xE5, 0x3F, 0x3E, 0x36, 0xB2, 0x0D, 0xA9}
EFI_GUID gSetupGuid                     = SETUP_GUID;
//-jeff PLATFORM_INFO_PROTOCOL                  *gPlatformInfoProtocol;

EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL   *PciRootBridgeIo;
EFI_PCI_PLATFORM_PROTOCOL         *MePciPlatformInstance;
PLATFORM_PCI_EXPRESS_BRIDGE       *mPlatformPciExpressBridge;

EFI_STATUS
EFIAPI
PhaseNotify (
  IN EFI_PCI_PLATFORM_PROTOCOL                       *This,
  IN  EFI_HANDLE                                     HostBridge,
  IN  EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PHASE  Phase,
  IN  EFI_PCI_CHIPSET_EXECUTION_PHASE                ChipsetPhase  
  )
/*++

  Routine Description:
    The PlatformNotify() function can be used to notify the platform driver so that 
    it can perform platform-specific actions. No specific actions are required. 
    Eight notification points are defined at this time. More synchronization points 
    may be added as required in the future. The PCI bus driver calls the platform driver 
    twice for every Phase-once before the PCI Host Bridge Resource Allocation Protocol 
    driver is notified, and once after the PCI Host Bridge Resource Allocation Protocol 
    driver has been notified. 
    This member function may not perform any error checking on the input parameters. It 
    also does not return any error codes. If this member function detects any error condition, 
    it needs to handle those errors on its own because there is no way to surface any 
    errors to the caller.
    
  Arguments:
    This         - Pointer to the EFI_PCI_PLATFORM_PROTOCOL instance.  
    HostBridge   - The handle of the host bridge controller. 
    Phase        - The phase of the PCI bus enumeration.
    ChipsetPhase - Defines the execution phase of the PCI chipset driver. 
    
  Returns:
    EFI_SUCCESS  - The function completed successfully.
    
--*/
{
/*
  EFI_STATUS                        Status;

  if (Phase == EfiPciHostBridgeEndBusAllocation && ChipsetPhase == ChipsetEntry) {
      Status = HeciSetClockEnables (CurrentClockMask, CurrentClockEnables, TRUE);
  }
*/
  return EFI_SUCCESS;
}

EFI_STATUS
EFIAPI
PlatformPrepController (
  IN  EFI_PCI_PLATFORM_PROTOCOL                      *This,
  IN  EFI_HANDLE                                     HostBridge,
  IN  EFI_HANDLE                                     RootBridge,
  IN  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS    PciAddress,
  IN  EFI_PCI_CONTROLLER_RESOURCE_ALLOCATION_PHASE   Phase,
  IN  EFI_PCI_CHIPSET_EXECUTION_PHASE                ChipsetPhase
  )
/*++

  Routine Description:
    The PlatformPrepController() function can be used to notify the platform driver so that 
    it can perform platform-specific actions. No specific actions are required. 
    Several notification points are defined at this time. More synchronization points may be 
    added as required in the future. The PCI bus driver calls the platform driver twice for 
    every PCI controller-once before the PCI Host Bridge Resource Allocation Protocol driver 
    is notified, and once after the PCI Host Bridge Resource Allocation Protocol driver has 
    been notified. 
    This member function may not perform any error checking on the input parameters. It also 
    does not return any error codes. If this member function detects any error condition, it 
    needs to handle those errors on its own because there is no way to surface any errors to 
    the caller.  
    
  Arguments:
    This         - Pointer to the EFI_PCI_PLATFORM_PROTOCOL instance.  
    HostBridge   - The associated PCI host bridge handle. 
    RootBridge   - The associated PCI root bridge handle.
    PciAddress   - The address of the PCI device on the PCI bus. 
    Phase        - The phase of the PCI controller enumeration. 
    ChipsetPhase - Defines the execution phase of the PCI chipset driver. 
    
  Returns:
    EFI_SUCCESS  - The function completed successfully.
    
--*/
{
  return EFI_SUCCESS;
}

EFI_STATUS
EFIAPI
GetPlatformPolicy (
  IN  EFI_PCI_PLATFORM_PROTOCOL           *This,
  OUT EFI_PCI_PLATFORM_POLICY             *PciPolicy
  )
/*++

  Routine Description:
    The GetPlatformPolicy() function retrieves the platform policy regarding PCI 
    enumeration. The PCI bus driver and the PCI Host Bridge Resource Allocation Protocol 
    driver can call this member function to retrieve the policy.
    
  Arguments:
    This      - Pointer to the EFI_PCI_PLATFORM_PROTOCOL instance.
    PciPolicy - The platform policy with respect to VGA and ISA aliasing. 
    
  Returns:
    EFI_SUCCESS           - The function completed successfully.
    EFI_INVALID_PARAMETER - PciPolicy is NULL.
    
--*/
{
  return EFI_SUCCESS;
}

EFI_STATUS
EFIAPI
GetPciRom (
  IN   EFI_PCI_PLATFORM_PROTOCOL    *This,
  IN   EFI_HANDLE                   PciHandle,
  OUT  VOID                         **RomImage,
  OUT  UINTN                        *RomSize 
  )
/*++

  Routine Description:
    The GetPciRom() function gets the PCI device's option ROM from a platform-specific location. 
    The option ROM will be loaded into memory. This member function is used to return an image 
    that is packaged as a PCI 2.2 option ROM. The image may contain both legacy and EFI option 
    ROMs. See the EFI 1.10 Specification for details. This member function can be used to return 
    option ROM images for embedded controllers. Option ROMs for embedded controllers are typically 
    stored in platform-specific storage, and this member function can retrieve it from that storage 
    and return it to the PCI bus driver. The PCI bus driver will call this member function before 
    scanning the ROM that is attached to any controller, which allows a platform to specify a ROM 
    image that is different from the ROM image on a PCI card.

  Arguments:
    This      - Pointer to the EFI_PCI_PLATFORM_PROTOCOL instance.
    PciHandle - The handle of the PCI device. 
    RomImage  - If the call succeeds, the pointer to the pointer to the option ROM image. 
                Otherwise, this field is undefined. The memory for RomImage is allocated 
                by EFI_PCI_PLATFORM_PROTOCOL.GetPciRom() using the EFI Boot Service AllocatePool(). 
                It is the caller's responsibility to free the memory using the EFI Boot Service 
                FreePool(), when the caller is done with the option ROM.
    RomSize   - If the call succeeds, a pointer to the size of the option ROM size. Otherwise, 
                this field is undefined.
                
  Returns:
    EFI_SUCCESS          - The option ROM was available for this device and loaded into memory.
    EFI_NOT_FOUND        - No option ROM was available for this device.
    EFI_OUT_OF_RESOURCES - No memory was available to load the option ROM.
    EFI_DEVICE_ERROR     - An error occurred in getting the option ROM.
        
--*/
{
  return EFI_NOT_FOUND;
}

//
// Driver entry point
//
EFI_DRIVER_ENTRY_POINT (MePlatformPolicyEntryPoint)

//
// Function implementations
//
EFI_STATUS
EFIAPI
MePciPlatformEntryPoint (
    IN EFI_HANDLE               ImageHandle,
    IN EFI_SYSTEM_TABLE         *SystemTable
)
/*++
 
Routine Description:
 
  Entry point for the Management Engine Driver.
  
Arguments:
 
  ImageHandle       Image handle of this driver.
  SystemTable       Global system service table.
 
Returns:
 
  EFI_SUCCESS           Initialization complete.
  EFI_UNSUPPORTED       The chipset is unsupported by this driver.
  EFI_OUT_OF_RESOURCES  Do not have enough resources to initialize the driver.
  EFI_DEVICE_ERROR      Device error, driver exits abnormally.
 
--*/
{
  EFI_STATUS            Status;
  EFI_HECI_PROTOCOL     *Heci;
  UINT32                MeMode;


  EfiInitializeDriverLib (ImageHandle, SystemTable);

  //
  // Locate Heci protocol
  //
  Status = gBS->LocateProtocol (&gEfiHeciProtocolGuid, NULL, &Heci);
  if (EFI_ERROR(Status)) {
    DEBUG ((EFI_D_ERROR, "MePciPlatform locate Heci failed and the Status is %r\n", Status));
    return Status;
  }

  Status = Heci->GetMeMode(&MeMode);
  if (EFI_ERROR(Status)) {
    DEBUG ((EFI_D_ERROR, "MePciPlatform Get Me mode failed and the Status is %r\n", Status));
    return Status;
  }
  if (MeMode == ME_MODE_SECOVER) {
    DEBUG ((EFI_D_ERROR, "SetICC doesn't supported in this mode\n"));
    return EFI_UNSUPPORTED;
  }

  MePciPlatformInstance = (EFI_PCI_PLATFORM_PROTOCOL *) (UINTN) AllocatePool (sizeof (EFI_PCI_PLATFORM_PROTOCOL));

 //-jeff Status = gBS->LocateProtocol(&gPlatformInfoProtocolGuid, NULL, &gPlatformInfoProtocol);
 //-jeff  ASSERT_EFI_ERROR (Status);

  // Locate root bridge IO protocol
  //
  Status = gBS->LocateProtocol (&gEfiPciRootBridgeIoProtocolGuid, NULL, &PciRootBridgeIo);
  if (EFI_ERROR(Status)) {
    return Status;
  }

  MePciPlatformInstance->PhaseNotify            = PhaseNotify;
  MePciPlatformInstance->PlatformPrepController = PlatformPrepController;
  MePciPlatformInstance->GetPlatformPolicy      = GetPlatformPolicy;
  MePciPlatformInstance->GetPciRom              = GetPciRom;

  //
  // Install the EFI_MANAGEMENT_ENGINE_PROTOCOL interface
  //
  Status = gBS->InstallProtocolInterface (
               &ImageHandle,
               &gEfiPciPlatformProtocolGuid,
               EFI_NATIVE_INTERFACE,
               MePciPlatformInstance
           );

  return Status;
}

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