3 Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
23 #include EFI_PPI_CONSUMER (PciCfg)
24 #include EFI_PPI_CONSUMER (PciCfg2)
25 #include EFI_PROTOCOL_CONSUMER (PciRootBridgeIo)
28 // Modular variable used by common libiary in PEI phase
30 EFI_GUID mPeiCpuIoPpiGuid
= PEI_CPU_IO_PPI_GUID
;
31 #if (PI_SPECIFICATION_VERSION < 0x00010000)
32 EFI_GUID mPeiPciCfgPpiGuid
= PEI_PCI_CFG_PPI_GUID
;
33 PEI_PCI_CFG_PPI
*PciCfgPpi
= NULL
;
35 EFI_GUID mPeiPciCfgPpiGuid
= EFI_PEI_PCI_CFG2_PPI_GUID
;
36 EFI_PEI_PCI_CFG2_PPI
*PciCfgPpi
= NULL
;
38 EFI_PEI_SERVICES
**mPeiServices
= NULL
;
39 PEI_CPU_IO_PPI
*CpuIoPpi
= NULL
;
42 // Modular variable used by common libiary in DXE phase
44 EFI_SYSTEM_TABLE
*mST
= NULL
;
45 EFI_BOOT_SERVICES
*mBS
= NULL
;
46 EFI_RUNTIME_SERVICES
*mRT
= NULL
;
49 EfiInitializeCommonDriverLib (
50 IN EFI_HANDLE ImageHandle
,
57 Initialize lib function calling phase: PEI or DXE
61 ImageHandle - The firmware allocated handle for the EFI image.
63 SystemTable - A pointer to the EFI System Table.
67 EFI_STATUS always returns EFI_SUCCESS
75 if (ImageHandle
== NULL
) {
77 // The function is called in PEI phase, use PEI interfaces
79 mPeiServices
= (EFI_PEI_SERVICES
**) SystemTable
;
80 ASSERT (mPeiServices
== NULL
);
82 CpuIoPpi
= (**mPeiServices
).CpuIo
;
83 PciCfgPpi
= (**mPeiServices
).PciCfg
;
87 // ImageHandle is not NULL. The function is called in DXE phase
92 mBS
= mST
->BootServices
;
93 mRT
= mST
->RuntimeServices
;
98 // Should be at EFI_D_INFO, but lets us know things are running
100 DEBUG ((EFI_D_INFO
, "EfiInitializeCommonDriverLib: Started in DXE\n"));
123 Width - Width of write operation
124 Address - Start IO address to write
126 Buffer - Buffer to write to the address
135 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*RootBridgeIo
;
137 if (mPeiServices
!= NULL
) {
139 // The function is called in PEI phase, use PEI interfaces
141 Status
= CpuIoPpi
->Io
.Write (
151 // The function is called in DXE phase
153 Status
= mBS
->LocateProtocol (
154 &gEfiPciRootBridgeIoProtocolGuid
,
156 (VOID
**) &RootBridgeIo
158 if (EFI_ERROR (Status
)) {
162 Status
= RootBridgeIo
->Io
.Write (RootBridgeIo
, Width
, Address
, Count
, Buffer
);
184 Width - Width of read operation
185 Address - Start IO address to read
187 Buffer - Buffer to store result
196 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*RootBridgeIo
;
198 if (mPeiServices
!= NULL
) {
200 // The function is called in PEI phase, use PEI interfaces
202 Status
= CpuIoPpi
->Io
.Read (
212 // The function is called in DXE phase
214 Status
= mBS
->LocateProtocol (
215 &gEfiPciRootBridgeIoProtocolGuid
,
217 (VOID
**) &RootBridgeIo
219 if (EFI_ERROR (Status
)) {
223 Status
= RootBridgeIo
->Io
.Read (RootBridgeIo
, Width
, Address
, Count
, Buffer
);
245 Width - Width of PCI write
246 Address - PCI address to write
248 Buffer - Buffer to write to the address
259 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*RootBridgeIo
;
261 if (mPeiServices
!= NULL
) {
263 // The function is called in PEI phase, use PEI interfaces
266 for (Index
= 0; Index
< Count
; Index
++) {
267 Status
= PciCfgPpi
->Write (
275 if (EFI_ERROR (Status
)) {
284 // The function is called in DXE phase
286 Status
= mBS
->LocateProtocol (
287 &gEfiPciRootBridgeIoProtocolGuid
,
289 (VOID
**) &RootBridgeIo
291 if (EFI_ERROR (Status
)) {
295 Status
= RootBridgeIo
->Pci
.Write (
322 Width - Width of PCI read
323 Address - PCI address to read
325 Buffer - Output buffer for the read
336 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*RootBridgeIo
;
338 if (mPeiServices
!= NULL
) {
340 // The function is called in PEI phase, use PEI interfaces
343 for (Index
= 0; Index
< Count
; Index
++) {
344 Status
= PciCfgPpi
->Read (
352 if (EFI_ERROR (Status
)) {
361 // The function is called in DXE phase
363 Status
= mBS
->LocateProtocol (
364 &gEfiPciRootBridgeIoProtocolGuid
,
366 (VOID
**) &RootBridgeIo
368 if (EFI_ERROR (Status
)) {
372 Status
= RootBridgeIo
->Pci
.Read (