3 Copyright (c) 2004 - 2009, Intel Corporation
4 All rights reserved. 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.
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
77 if (ImageHandle
== NULL
) {
79 // The function is called in PEI phase, use PEI interfaces
81 mPeiServices
= (EFI_PEI_SERVICES
**) SystemTable
;
82 ASSERT (mPeiServices
== NULL
);
84 CpuIoPpi
= (**mPeiServices
).CpuIo
;
85 PciCfgPpi
= (**mPeiServices
).PciCfg
;
89 // ImageHandle is not NULL. The function is called in DXE phase
94 mBS
= mST
->BootServices
;
95 mRT
= mST
->RuntimeServices
;
100 // Should be at EFI_D_INFO, but lets us know things are running
102 DEBUG ((EFI_D_INFO
, "EfiInitializeCommonDriverLib: Started in DXE\n"));
125 Width - Width of write operation
126 Address - Start IO address to write
128 Buffer - Buffer to write to the address
137 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*RootBridgeIo
;
139 if (mPeiServices
== NULL
) {
141 // The function is called in PEI phase, use PEI interfaces
143 Status
= CpuIoPpi
->Io
.Write (
153 // The function is called in DXE phase
155 Status
= mBS
->LocateProtocol (
156 &gEfiPciRootBridgeIoProtocolGuid
,
158 (VOID
**) &RootBridgeIo
160 if (EFI_ERROR (Status
)) {
164 Status
= RootBridgeIo
->Io
.Write (RootBridgeIo
, Width
, Address
, Count
, Buffer
);
186 Width - Width of read operation
187 Address - Start IO address to read
189 Buffer - Buffer to store result
198 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*RootBridgeIo
;
200 if (mPeiServices
== NULL
) {
202 // The function is called in PEI phase, use PEI interfaces
204 Status
= CpuIoPpi
->Io
.Read (
214 // The function is called in DXE phase
216 Status
= mBS
->LocateProtocol (
217 &gEfiPciRootBridgeIoProtocolGuid
,
219 (VOID
**) &RootBridgeIo
221 if (EFI_ERROR (Status
)) {
225 Status
= RootBridgeIo
->Io
.Read (RootBridgeIo
, Width
, Address
, Count
, Buffer
);
247 Width - Width of PCI write
248 Address - PCI address to write
250 Buffer - Buffer to write to the address
261 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*RootBridgeIo
;
263 if (mPeiServices
== NULL
) {
265 // The function is called in PEI phase, use PEI interfaces
268 for (Index
= 0; Index
< Count
; Index
++) {
269 Status
= PciCfgPpi
->Write (
277 if (EFI_ERROR (Status
)) {
286 // The function is called in DXE phase
288 Status
= mBS
->LocateProtocol (
289 &gEfiPciRootBridgeIoProtocolGuid
,
291 (VOID
**) &RootBridgeIo
293 if (EFI_ERROR (Status
)) {
297 Status
= RootBridgeIo
->Pci
.Write (
324 Width - Width of PCI read
325 Address - PCI address to read
327 Buffer - Output buffer for the read
338 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*RootBridgeIo
;
340 if (mPeiServices
!= NULL
) {
342 // The function is called in PEI phase, use PEI interfaces
345 for (Index
= 0; Index
< Count
; Index
++) {
346 Status
= PciCfgPpi
->Read (
354 if (EFI_ERROR (Status
)) {
363 // The function is called in DXE phase
365 Status
= mBS
->LocateProtocol (
366 &gEfiPciRootBridgeIoProtocolGuid
,
368 (VOID
**) &RootBridgeIo
370 if (EFI_ERROR (Status
)) {
374 Status
= RootBridgeIo
->Pci
.Read (