lightpcilib.c

来自「EFI BIOS是Intel提出的下一代的BIOS标准。这里上传的Edk源代码是」· C语言 代码 · 共 893 行 · 第 1/2 页

C
893
字号
/*++

Copyright (c) 2004 - 2006, Intel Corporation                                                         
All rights reserved. This program and the accompanying materials                          
are licensed and made available under the terms and conditions of the BSD License         
which accompanies this distribution.  The full text of the license may be found at        
http://opensource.org/licenses/bsd-license.php                                            
                                                                                          
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             

Module Name:

  LightPciLib.c
  
Abstract:

  Light PCI Bus Driver Lib file
  It abstracts some functions that can be different 
  between light PCI bus driver and full PCI bus driver

Revision History

--*/

#include "pcibus.h"

//
// Light PCI bus driver woundn't support hotplug device
// So just return
//
VOID
InstallHotPlugRequestProtocol (
  IN EFI_STATUS *Status
  )
/*++

Routine Description:


Arguments:

Returns:

  None

--*/
// TODO:    Status - add argument and description to function comment
{
  return ;
}

//
// Light PCI bus driver woundn't support hotplug device
// So just skip install this GUID
//
VOID
InstallPciHotplugGuid (
  IN  PCI_IO_DEVICE                  *PciIoDevice
  )
/*++

Routine Description:


Arguments:

Returns:

  None

--*/
// TODO:    PciIoDevice - add argument and description to function comment
{
  return ;
}

//
// Light PCI bus driver woundn't support hotplug device
// So just skip uninstall the GUID
//
VOID
UninstallPciHotplugGuid (
  IN  PCI_IO_DEVICE                  *PciIoDevice
  )
/*++

Routine Description:


Arguments:

Returns:

  None

--*/
// TODO:    PciIoDevice - add argument and description to function comment
{
  return ;
}

//
// Light PCI bus driver woundn't support PCCard
// So it needn't get the bar of CardBus
//
VOID
GetBackPcCardBar (
  IN  PCI_IO_DEVICE                  *PciIoDevice
  )
/*++

Routine Description:

  TODO: Add function description

Arguments:

  PciIoDevice - TODO: add argument description

Returns:

  TODO: add return values

--*/
{
  return ;
}

//
// Light PCI bus driver woundn't support resource reallocation
// So just return
//
EFI_STATUS
RemoveRejectedPciDevices (
  EFI_HANDLE        RootBridgeHandle,
  IN PCI_IO_DEVICE  *Bridge
  )
/*++

Routine Description:

  TODO: Add function description

Arguments:

  RootBridgeHandle  - TODO: add argument description
  Bridge            - TODO: add argument description

Returns:

  EFI_SUCCESS - TODO: Add description for return value

--*/
{
  return EFI_SUCCESS;
}

//
// Light PCI bus driver woundn't support resource reallocation
// Simplified the code
//
EFI_STATUS
PciHostBridgeResourceAllocator (
  IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL *PciResAlloc
  )
/*++

Routine Description:

Arguments:

Returns:

  None

--*/
// TODO:    PciResAlloc - add argument and description to function comment
// TODO:    EFI_NOT_FOUND - add return value to function comment
// TODO:    EFI_OUT_OF_RESOURCES - add return value to function comment
// TODO:    EFI_NOT_FOUND - add return value to function comment
// TODO:    EFI_SUCCESS - add return value to function comment
{
  PCI_IO_DEVICE                   *RootBridgeDev;
  EFI_HANDLE                      RootBridgeHandle;
  VOID                            *AcpiConfig;
  EFI_STATUS                      Status;
  UINT64                          IoBase;
  UINT64                          Mem32Base;
  UINT64                          PMem32Base;
  UINT64                          Mem64Base;
  UINT64                          PMem64Base;
  UINT64                          MaxOptionRomSize;
  PCI_RESOURCE_NODE               *IoBridge;
  PCI_RESOURCE_NODE               *Mem32Bridge;
  PCI_RESOURCE_NODE               *PMem32Bridge;
  PCI_RESOURCE_NODE               *Mem64Bridge;
  PCI_RESOURCE_NODE               *PMem64Bridge;
  PCI_RESOURCE_NODE               IoPool;
  PCI_RESOURCE_NODE               Mem32Pool;
  PCI_RESOURCE_NODE               PMem32Pool;
  PCI_RESOURCE_NODE               Mem64Pool;
  PCI_RESOURCE_NODE               PMem64Pool;
  EFI_DEVICE_HANDLE_EXTENDED_DATA ExtendedData;

  //
  // Initialize resource pool
  //
  
  InitializeResourcePool (&IoPool, PciBarTypeIo16);
  InitializeResourcePool (&Mem32Pool, PciBarTypeMem32);
  InitializeResourcePool (&PMem32Pool, PciBarTypePMem32);
  InitializeResourcePool (&Mem64Pool, PciBarTypeMem64);
  InitializeResourcePool (&PMem64Pool, PciBarTypePMem64);

  RootBridgeDev     = NULL;
  RootBridgeHandle  = 0;

  while (PciResAlloc->GetNextRootBridge (PciResAlloc, &RootBridgeHandle) == EFI_SUCCESS) {
    //
    // Get RootBridg Device by handle
    //
    RootBridgeDev = GetRootBridgeByHandle (RootBridgeHandle);

    if (RootBridgeDev == NULL) {
      return EFI_NOT_FOUND;
    }

    //
    // Get host bridge handle for status report
    //
    ExtendedData.Handle = RootBridgeDev->PciRootBridgeIo->ParentHandle;

    //
    // Create the entire system resource map from the information collected by
    // enumerator. Several resource tree was created
    //

    IoBridge = CreateResourceNode (
                RootBridgeDev,
                0,
                0xFFF,
                0,
                PciBarTypeIo16,
                PciResUsageTypical
                );

    Mem32Bridge = CreateResourceNode (
                    RootBridgeDev,
                    0,
                    0xFFFFF,
                    0,
                    PciBarTypeMem32,
                    PciResUsageTypical
                    );

    PMem32Bridge = CreateResourceNode (
                    RootBridgeDev,
                    0,
                    0xFFFFF,
                    0,
                    PciBarTypePMem32,
                    PciResUsageTypical
                    );

    Mem64Bridge = CreateResourceNode (
                    RootBridgeDev,
                    0,
                    0xFFFFF,
                    0,
                    PciBarTypeMem64,
                    PciResUsageTypical
                    );

    PMem64Bridge = CreateResourceNode (
                    RootBridgeDev,
                    0,
                    0xFFFFF,
                    0,
                    PciBarTypePMem64,
                    PciResUsageTypical
                    );

    //
    // Create resourcemap by going through all the devices subject to this root bridge
    //
    Status = CreateResourceMap (
              RootBridgeDev,
              IoBridge,
              Mem32Bridge,
              PMem32Bridge,
              Mem64Bridge,
              PMem64Bridge
              );

    //
    // Get the max ROM size that the root bridge can process
    //
    RootBridgeDev->RomSize = Mem32Bridge->Length;

    //
    // Get Max Option Rom size for current root bridge
    //
    MaxOptionRomSize = GetMaxOptionRomSize (RootBridgeDev);

    //
    // Enlarger the mem32 resource to accomdate the option rom
    // if the mem32 resource is not enough to hold the rom
    //
    if (MaxOptionRomSize > Mem32Bridge->Length) {

      Mem32Bridge->Length     = MaxOptionRomSize;
      RootBridgeDev->RomSize  = MaxOptionRomSize;

      //
      // Alignment should be adjusted as well
      //
      if (Mem32Bridge->Alignment < MaxOptionRomSize - 1) {
        Mem32Bridge->Alignment = MaxOptionRomSize - 1;
      }
    }
    
    //
    // Based on the all the resource tree, contruct ACPI resource node to
    // submit the resource aperture to pci host bridge protocol
    //
    Status = ConstructAcpiResourceRequestor (
              RootBridgeDev,
              IoBridge,
              Mem32Bridge,
              PMem32Bridge,
              Mem64Bridge,
              PMem64Bridge,
              &AcpiConfig
              );

    //
    // Insert these resource nodes into the database
    //
    InsertResourceNode (&IoPool, IoBridge);
    InsertResourceNode (&Mem32Pool, Mem32Bridge);
    InsertResourceNode (&PMem32Pool, PMem32Bridge);
    InsertResourceNode (&Mem64Pool, Mem64Bridge);
    InsertResourceNode (&PMem64Pool, PMem64Bridge);

    if (Status == EFI_SUCCESS) {
      //
      // Submit the resource requirement
      //
      Status = PciResAlloc->SubmitResources (
                              PciResAlloc,
                              RootBridgeDev->Handle,
                              AcpiConfig
                              );
    }
    //
    // Free acpi resource node
    //
    if (AcpiConfig) {
      gBS->FreePool (AcpiConfig);
    }

    if (EFI_ERROR (Status)) {
      //
      // Destroy all the resource tree
      //
      DestroyResourceTree (&IoPool);
      DestroyResourceTree (&Mem32Pool);
      DestroyResourceTree (&PMem32Pool);
      DestroyResourceTree (&Mem64Pool);
      DestroyResourceTree (&PMem64Pool);
      return Status;
    }
  }
  //
  // End while
  //

  //
  // Notify pci bus driver starts to program the resource
  //
  Status = NotifyPhase (PciResAlloc, EfiPciHostBridgeAllocateResources);

  if (EFI_ERROR (Status)) {
    //
    // Allocation failed, then return
    //
    return EFI_OUT_OF_RESOURCES;
  }
  //
  // Raise the EFI_IOB_PCI_RES_ALLOC status code
  //
  ExtendedData.DataHeader.HeaderSize  = sizeof (EFI_STATUS_CODE_DATA);
  ExtendedData.DataHeader.Size        = sizeof (EFI_DEVICE_HANDLE_EXTENDED_DATA) -
                                        sizeof (EFI_STATUS_CODE_DATA);

  EfiCommonLibCopyMem (
    &ExtendedData.DataHeader.Type,
    &gEfiStatusCodeSpecificDataGuid,
    sizeof (EFI_GUID)
    );

  EfiLibReportStatusCode (
    EFI_PROGRESS_CODE,
    EFI_IO_BUS_PCI | EFI_IOB_PCI_PC_RES_ALLOC,
    0,
    &gEfiCallerIdGuid,
    (EFI_STATUS_CODE_DATA *) &ExtendedData
    );

  //
  // Notify pci bus driver starts to program the resource
  //
  NotifyPhase (PciResAlloc, EfiPciHostBridgeSetResources);

  RootBridgeDev     = NULL;

  RootBridgeHandle  = 0;

  while (PciResAlloc->GetNextRootBridge (PciResAlloc, &RootBridgeHandle) == EFI_SUCCESS) {
    //
    // Get RootBridg Device by handle
    //
    RootBridgeDev = GetRootBridgeByHandle (RootBridgeHandle);

    if (RootBridgeDev == NULL) {
      return EFI_NOT_FOUND;
    }
    
    //
    // Get acpi resource node for all the resource types
    //
    AcpiConfig = NULL;
    Status = PciResAlloc->GetProposedResources (
                            PciResAlloc,
                            RootBridgeDev->Handle,
                            &AcpiConfig
                            );

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

    //
    // Get the resource base by interpreting acpi resource node
    //
    //

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?