mirror of
https://github.com/acidanthera/audk.git
synced 2025-07-29 08:34:07 +02:00
Add PciBusNoEnumeration module
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@5157 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
c64feb92ef
commit
10590588cc
161
DuetPkg/PciBusNoEnumerationDxe/ComponentName.c
Normal file
161
DuetPkg/PciBusNoEnumerationDxe/ComponentName.c
Normal file
@ -0,0 +1,161 @@
|
|||||||
|
/*++
|
||||||
|
|
||||||
|
Copyright (c) 2005 - 2007, 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:
|
||||||
|
ComponentName.c
|
||||||
|
|
||||||
|
Abstract:
|
||||||
|
|
||||||
|
--*/
|
||||||
|
|
||||||
|
#include "PciBus.h"
|
||||||
|
|
||||||
|
//
|
||||||
|
// EFI Component Name Functions
|
||||||
|
//
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
PciBusComponentNameGetDriverName (
|
||||||
|
IN EFI_COMPONENT_NAME_PROTOCOL *This,
|
||||||
|
IN CHAR8 *Language,
|
||||||
|
OUT CHAR16 **DriverName
|
||||||
|
);
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
PciBusComponentNameGetControllerName (
|
||||||
|
IN EFI_COMPONENT_NAME_PROTOCOL *This,
|
||||||
|
IN EFI_HANDLE ControllerHandle,
|
||||||
|
IN EFI_HANDLE ChildHandle OPTIONAL,
|
||||||
|
IN CHAR8 *Language,
|
||||||
|
OUT CHAR16 **ControllerName
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// EFI Component Name Protocol
|
||||||
|
//
|
||||||
|
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gPciBusComponentName = {
|
||||||
|
PciBusComponentNameGetDriverName,
|
||||||
|
PciBusComponentNameGetControllerName,
|
||||||
|
"eng"
|
||||||
|
};
|
||||||
|
|
||||||
|
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gPciBusComponentName2 = {
|
||||||
|
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME) PciBusComponentNameGetDriverName,
|
||||||
|
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) PciBusComponentNameGetControllerName,
|
||||||
|
"en"
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
STATIC EFI_UNICODE_STRING_TABLE mPciBusDriverNameTable[] = {
|
||||||
|
{ "eng;en", L"PCI Bus Driver" },
|
||||||
|
{ NULL, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
PciBusComponentNameGetDriverName (
|
||||||
|
IN EFI_COMPONENT_NAME_PROTOCOL *This,
|
||||||
|
IN CHAR8 *Language,
|
||||||
|
OUT CHAR16 **DriverName
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
Retrieves a Unicode string that is the user readable name of the EFI Driver.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
|
||||||
|
Language - A pointer to a three character ISO 639-2 language identifier.
|
||||||
|
This is the language of the driver name that that the caller
|
||||||
|
is requesting, and it must match one of the languages specified
|
||||||
|
in SupportedLanguages. The number of languages supported by a
|
||||||
|
driver is up to the driver writer.
|
||||||
|
DriverName - A pointer to the Unicode string to return. This Unicode string
|
||||||
|
is the name of the driver specified by This in the language
|
||||||
|
specified by Language.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
EFI_SUCCESS - The Unicode string for the Driver specified by This
|
||||||
|
and the language specified by Language was returned
|
||||||
|
in DriverName.
|
||||||
|
EFI_INVALID_PARAMETER - Language is NULL.
|
||||||
|
EFI_INVALID_PARAMETER - DriverName is NULL.
|
||||||
|
EFI_UNSUPPORTED - The driver specified by This does not support the
|
||||||
|
language specified by Language.
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
return LookupUnicodeString2 (
|
||||||
|
Language,
|
||||||
|
This->SupportedLanguages,
|
||||||
|
mPciBusDriverNameTable,
|
||||||
|
DriverName,
|
||||||
|
(BOOLEAN)(This == &gPciBusComponentName)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
PciBusComponentNameGetControllerName (
|
||||||
|
IN EFI_COMPONENT_NAME_PROTOCOL *This,
|
||||||
|
IN EFI_HANDLE ControllerHandle,
|
||||||
|
IN EFI_HANDLE ChildHandle OPTIONAL,
|
||||||
|
IN CHAR8 *Language,
|
||||||
|
OUT CHAR16 **ControllerName
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
Retrieves a Unicode string that is the user readable name of the controller
|
||||||
|
that is being managed by an EFI Driver.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
|
||||||
|
ControllerHandle - The handle of a controller that the driver specified by
|
||||||
|
This is managing. This handle specifies the controller
|
||||||
|
whose name is to be returned.
|
||||||
|
ChildHandle - The handle of the child controller to retrieve the name
|
||||||
|
of. This is an optional parameter that may be NULL. It
|
||||||
|
will be NULL for device drivers. It will also be NULL
|
||||||
|
for a bus drivers that wish to retrieve the name of the
|
||||||
|
bus controller. It will not be NULL for a bus driver
|
||||||
|
that wishes to retrieve the name of a child controller.
|
||||||
|
Language - A pointer to a three character ISO 639-2 language
|
||||||
|
identifier. This is the language of the controller name
|
||||||
|
that that the caller is requesting, and it must match one
|
||||||
|
of the languages specified in SupportedLanguages. The
|
||||||
|
number of languages supported by a driver is up to the
|
||||||
|
driver writer.
|
||||||
|
ControllerName - A pointer to the Unicode string to return. This Unicode
|
||||||
|
string is the name of the controller specified by
|
||||||
|
ControllerHandle and ChildHandle in the language specified
|
||||||
|
by Language from the point of view of the driver specified
|
||||||
|
by This.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
EFI_SUCCESS - The Unicode string for the user readable name in the
|
||||||
|
language specified by Language for the driver
|
||||||
|
specified by This was returned in DriverName.
|
||||||
|
EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
|
||||||
|
EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
|
||||||
|
EFI_INVALID_PARAMETER - Language is NULL.
|
||||||
|
EFI_INVALID_PARAMETER - ControllerName is NULL.
|
||||||
|
EFI_UNSUPPORTED - The driver specified by This is not currently managing
|
||||||
|
the controller specified by ControllerHandle and
|
||||||
|
ChildHandle.
|
||||||
|
EFI_UNSUPPORTED - The driver specified by This does not support the
|
||||||
|
language specified by Language.
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
return EFI_UNSUPPORTED;
|
||||||
|
}
|
343
DuetPkg/PciBusNoEnumerationDxe/PciBus.c
Normal file
343
DuetPkg/PciBusNoEnumerationDxe/PciBus.c
Normal file
@ -0,0 +1,343 @@
|
|||||||
|
/*++
|
||||||
|
|
||||||
|
Copyright (c) 2005 - 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:
|
||||||
|
|
||||||
|
PciBus.c
|
||||||
|
|
||||||
|
Abstract:
|
||||||
|
|
||||||
|
PCI Bus Driver
|
||||||
|
|
||||||
|
Revision History
|
||||||
|
|
||||||
|
--*/
|
||||||
|
|
||||||
|
#include "PciBus.h"
|
||||||
|
|
||||||
|
//
|
||||||
|
// PCI Bus Support Function Prototypes
|
||||||
|
//
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
PciBusEntryPoint (
|
||||||
|
IN EFI_HANDLE ImageHandle,
|
||||||
|
IN EFI_SYSTEM_TABLE *SystemTable
|
||||||
|
);
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
PciBusDriverBindingSupported (
|
||||||
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||||
|
IN EFI_HANDLE Controller,
|
||||||
|
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
||||||
|
);
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
PciBusDriverBindingStart (
|
||||||
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||||
|
IN EFI_HANDLE Controller,
|
||||||
|
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
||||||
|
);
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
PciBusDriverBindingStop (
|
||||||
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||||
|
IN EFI_HANDLE Controller,
|
||||||
|
IN UINTN NumberOfChildren,
|
||||||
|
IN EFI_HANDLE *ChildHandleBuffer
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// PCI Bus Driver Global Variables
|
||||||
|
//
|
||||||
|
|
||||||
|
EFI_DRIVER_BINDING_PROTOCOL gPciBusDriverBinding = {
|
||||||
|
PciBusDriverBindingSupported,
|
||||||
|
PciBusDriverBindingStart,
|
||||||
|
PciBusDriverBindingStop,
|
||||||
|
0xa,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
BOOLEAN gFullEnumeration;
|
||||||
|
|
||||||
|
//
|
||||||
|
// PCI Bus Driver Support Functions
|
||||||
|
//
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
PciBusEntryPoint (
|
||||||
|
IN EFI_HANDLE ImageHandle,
|
||||||
|
IN EFI_SYSTEM_TABLE *SystemTable
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Initialize the global variables
|
||||||
|
publish the driver binding protocol
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
IN EFI_HANDLE ImageHandle,
|
||||||
|
IN EFI_SYSTEM_TABLE *SystemTable
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
EFI_SUCCESS
|
||||||
|
EFI_DEVICE_ERROR
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Initialize the EFI Driver Library
|
||||||
|
//
|
||||||
|
Status = EfiLibInstallDriverBindingComponentName2 (
|
||||||
|
ImageHandle,
|
||||||
|
SystemTable,
|
||||||
|
&gPciBusDriverBinding,
|
||||||
|
ImageHandle,
|
||||||
|
&gPciBusComponentName,
|
||||||
|
&gPciBusComponentName2
|
||||||
|
);
|
||||||
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
|
||||||
|
InitializePciDevicePool ();
|
||||||
|
|
||||||
|
gFullEnumeration = TRUE;
|
||||||
|
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
PciBusDriverBindingSupported (
|
||||||
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||||
|
IN EFI_HANDLE Controller,
|
||||||
|
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Check to see if pci bus driver supports the given controller
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||||
|
IN EFI_HANDLE Controller,
|
||||||
|
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
EFI_SUCCESS
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
|
||||||
|
EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;
|
||||||
|
EFI_DEV_PATH_PTR Node;
|
||||||
|
|
||||||
|
if (RemainingDevicePath != NULL) {
|
||||||
|
Node.DevPath = RemainingDevicePath;
|
||||||
|
if (Node.DevPath->Type != HARDWARE_DEVICE_PATH ||
|
||||||
|
Node.DevPath->SubType != HW_PCI_DP ||
|
||||||
|
DevicePathNodeLength(Node.DevPath) != sizeof(PCI_DEVICE_PATH)) {
|
||||||
|
return EFI_UNSUPPORTED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// Open the IO Abstraction(s) needed to perform the supported test
|
||||||
|
//
|
||||||
|
Status = gBS->OpenProtocol (
|
||||||
|
Controller,
|
||||||
|
&gEfiDevicePathProtocolGuid,
|
||||||
|
(VOID **) &ParentDevicePath,
|
||||||
|
This->DriverBindingHandle,
|
||||||
|
Controller,
|
||||||
|
EFI_OPEN_PROTOCOL_BY_DRIVER
|
||||||
|
);
|
||||||
|
if (Status == EFI_ALREADY_STARTED) {
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
gBS->CloseProtocol (
|
||||||
|
Controller,
|
||||||
|
&gEfiDevicePathProtocolGuid,
|
||||||
|
This->DriverBindingHandle,
|
||||||
|
Controller
|
||||||
|
);
|
||||||
|
|
||||||
|
Status = gBS->OpenProtocol (
|
||||||
|
Controller,
|
||||||
|
&gEfiPciRootBridgeIoProtocolGuid,
|
||||||
|
(VOID **) &PciRootBridgeIo,
|
||||||
|
This->DriverBindingHandle,
|
||||||
|
Controller,
|
||||||
|
EFI_OPEN_PROTOCOL_BY_DRIVER
|
||||||
|
);
|
||||||
|
if (Status == EFI_ALREADY_STARTED) {
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
gBS->CloseProtocol (
|
||||||
|
Controller,
|
||||||
|
&gEfiPciRootBridgeIoProtocolGuid,
|
||||||
|
This->DriverBindingHandle,
|
||||||
|
Controller
|
||||||
|
);
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
PciBusDriverBindingStart (
|
||||||
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||||
|
IN EFI_HANDLE Controller,
|
||||||
|
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Start to management the controller passed in
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||||
|
IN EFI_HANDLE Controller,
|
||||||
|
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Enumerate the entire host bridge
|
||||||
|
// After enumeration, a database that records all the device information will be created
|
||||||
|
//
|
||||||
|
//
|
||||||
|
Status = PciEnumerator (Controller);
|
||||||
|
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Enable PCI device specified by remaining device path. BDS or other driver can call the
|
||||||
|
// start more than once.
|
||||||
|
//
|
||||||
|
|
||||||
|
StartPciDevices (Controller, RemainingDevicePath);
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
PciBusDriverBindingStop (
|
||||||
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||||
|
IN EFI_HANDLE Controller,
|
||||||
|
IN UINTN NumberOfChildren,
|
||||||
|
IN EFI_HANDLE *ChildHandleBuffer
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Stop one or more children created at start of pci bus driver
|
||||||
|
if all the the children get closed, close the protocol
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||||
|
IN EFI_HANDLE Controller,
|
||||||
|
IN UINTN NumberOfChildren,
|
||||||
|
IN EFI_HANDLE *ChildHandleBuffer
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
UINTN Index;
|
||||||
|
BOOLEAN AllChildrenStopped;
|
||||||
|
|
||||||
|
if (NumberOfChildren == 0) {
|
||||||
|
//
|
||||||
|
// Close the bus driver
|
||||||
|
//
|
||||||
|
gBS->CloseProtocol (
|
||||||
|
Controller,
|
||||||
|
&gEfiDevicePathProtocolGuid,
|
||||||
|
This->DriverBindingHandle,
|
||||||
|
Controller
|
||||||
|
);
|
||||||
|
gBS->CloseProtocol (
|
||||||
|
Controller,
|
||||||
|
&gEfiPciRootBridgeIoProtocolGuid,
|
||||||
|
This->DriverBindingHandle,
|
||||||
|
Controller
|
||||||
|
);
|
||||||
|
|
||||||
|
DestroyRootBridgeByHandle (
|
||||||
|
Controller
|
||||||
|
);
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Stop all the children
|
||||||
|
//
|
||||||
|
|
||||||
|
AllChildrenStopped = TRUE;
|
||||||
|
|
||||||
|
for (Index = 0; Index < NumberOfChildren; Index++) {
|
||||||
|
|
||||||
|
//
|
||||||
|
// De register all the pci device
|
||||||
|
//
|
||||||
|
Status = DeRegisterPciDevice (Controller, ChildHandleBuffer[Index]);
|
||||||
|
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
AllChildrenStopped = FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!AllChildrenStopped) {
|
||||||
|
return EFI_DEVICE_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
224
DuetPkg/PciBusNoEnumerationDxe/PciBus.h
Normal file
224
DuetPkg/PciBusNoEnumerationDxe/PciBus.h
Normal file
@ -0,0 +1,224 @@
|
|||||||
|
/*++
|
||||||
|
|
||||||
|
Copyright (c) 2005 - 2007, 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:
|
||||||
|
|
||||||
|
PciBus.h
|
||||||
|
|
||||||
|
Abstract:
|
||||||
|
|
||||||
|
PCI Bus Driver
|
||||||
|
|
||||||
|
Revision History
|
||||||
|
|
||||||
|
--*/
|
||||||
|
|
||||||
|
#ifndef _EFI_PCI_BUS_H
|
||||||
|
#define _EFI_PCI_BUS_H
|
||||||
|
|
||||||
|
#include <FrameworkDxe.h>
|
||||||
|
|
||||||
|
#include <Protocol/PciIo.h>
|
||||||
|
#include <Protocol/PciRootBridgeIo.h>
|
||||||
|
#include <Protocol/DevicePath.h>
|
||||||
|
#include <Protocol/Decompress.h>
|
||||||
|
#include <Protocol/UgaIo.h>
|
||||||
|
#include <Protocol/LoadedImage.h>
|
||||||
|
#include <Protocol/BusSpecificDriverOverride.h>
|
||||||
|
|
||||||
|
#include <Guid/PciOptionRomTable.h>
|
||||||
|
|
||||||
|
#include <IndustryStandard/Pci23.h>
|
||||||
|
#include <IndustryStandard/Acpi.h>
|
||||||
|
#include <IndustryStandard/PeImage.h>
|
||||||
|
|
||||||
|
#include <Library/DebugLib.h>
|
||||||
|
#include <Library/UefiDriverEntryPoint.h>
|
||||||
|
#include <Library/BaseLib.h>
|
||||||
|
#include <Library/UefiLib.h>
|
||||||
|
#include <Library/BaseMemoryLib.h>
|
||||||
|
#include <Library/ReportStatusCodeLib.h>
|
||||||
|
#include <Library/MemoryAllocationLib.h>
|
||||||
|
#include <Library/UefiBootServicesTableLib.h>
|
||||||
|
#include <Library/DevicePathLib.h>
|
||||||
|
#include <Library/PcdLib.h>
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Driver Produced Protocol Prototypes
|
||||||
|
//
|
||||||
|
|
||||||
|
#define VGABASE1 0x3B0
|
||||||
|
#define VGALIMIT1 0x3BB
|
||||||
|
|
||||||
|
#define VGABASE2 0x3C0
|
||||||
|
#define VGALIMIT2 0x3DF
|
||||||
|
|
||||||
|
#define ISABASE 0x100
|
||||||
|
#define ISALIMIT 0x3FF
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
PciBarTypeUnknown = 0,
|
||||||
|
PciBarTypeIo16,
|
||||||
|
PciBarTypeIo32,
|
||||||
|
PciBarTypeMem32,
|
||||||
|
PciBarTypePMem32,
|
||||||
|
PciBarTypeMem64,
|
||||||
|
PciBarTypePMem64,
|
||||||
|
PciBarTypeIo,
|
||||||
|
PciBarTypeMem,
|
||||||
|
PciBarTypeMaxType
|
||||||
|
} PCI_BAR_TYPE;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
UINT64 BaseAddress;
|
||||||
|
UINT64 Length;
|
||||||
|
UINT64 Alignment;
|
||||||
|
PCI_BAR_TYPE BarType;
|
||||||
|
BOOLEAN Prefetchable;
|
||||||
|
UINT8 MemType;
|
||||||
|
UINT8 Offset;
|
||||||
|
} PCI_BAR;
|
||||||
|
|
||||||
|
#define PCI_IO_DEVICE_SIGNATURE EFI_SIGNATURE_32 ('p','c','i','o')
|
||||||
|
|
||||||
|
#define EFI_BRIDGE_IO32_DECODE_SUPPORTED 0x0001
|
||||||
|
#define EFI_BRIDGE_PMEM32_DECODE_SUPPORTED 0x0002
|
||||||
|
#define EFI_BRIDGE_PMEM64_DECODE_SUPPORTED 0x0004
|
||||||
|
#define EFI_BRIDGE_IO16_DECODE_SUPPORTED 0x0008
|
||||||
|
#define EFI_BRIDGE_PMEM_MEM_COMBINE_SUPPORTED 0x0010
|
||||||
|
#define EFI_BRIDGE_MEM64_DECODE_SUPPORTED 0x0020
|
||||||
|
#define EFI_BRIDGE_MEM32_DECODE_SUPPORTED 0x0040
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct _PCI_IO_DEVICE {
|
||||||
|
UINT32 Signature;
|
||||||
|
EFI_HANDLE Handle;
|
||||||
|
EFI_PCI_IO_PROTOCOL PciIo;
|
||||||
|
LIST_ENTRY Link;
|
||||||
|
|
||||||
|
EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL PciDriverOverride;
|
||||||
|
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
|
||||||
|
EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;
|
||||||
|
|
||||||
|
//
|
||||||
|
// PCI configuration space header type
|
||||||
|
//
|
||||||
|
PCI_TYPE00 Pci;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Bus number, Device number, Function number
|
||||||
|
//
|
||||||
|
UINT8 BusNumber;
|
||||||
|
UINT8 DeviceNumber;
|
||||||
|
UINT8 FunctionNumber;
|
||||||
|
|
||||||
|
//
|
||||||
|
// BAR for this PCI Device
|
||||||
|
//
|
||||||
|
PCI_BAR PciBar[PCI_MAX_BAR];
|
||||||
|
|
||||||
|
//
|
||||||
|
// The bridge device this pci device is subject to
|
||||||
|
//
|
||||||
|
struct _PCI_IO_DEVICE *Parent;
|
||||||
|
|
||||||
|
//
|
||||||
|
// A linked list for children Pci Device if it is bridge device
|
||||||
|
//
|
||||||
|
LIST_ENTRY ChildList;
|
||||||
|
|
||||||
|
//
|
||||||
|
// TURE if the PCI bus driver creates the handle for this PCI device
|
||||||
|
//
|
||||||
|
BOOLEAN Registered;
|
||||||
|
|
||||||
|
//
|
||||||
|
// TRUE if the PCI bus driver successfully allocates the resource required by
|
||||||
|
// this PCI device
|
||||||
|
//
|
||||||
|
BOOLEAN Allocated;
|
||||||
|
|
||||||
|
//
|
||||||
|
// The attribute this PCI device currently set
|
||||||
|
//
|
||||||
|
UINT64 Attributes;
|
||||||
|
|
||||||
|
//
|
||||||
|
// The attributes this PCI device actually supports
|
||||||
|
//
|
||||||
|
UINT64 Supports;
|
||||||
|
|
||||||
|
//
|
||||||
|
// The resource decode the bridge supports
|
||||||
|
//
|
||||||
|
UINT32 Decodes;
|
||||||
|
|
||||||
|
//
|
||||||
|
// The OptionRom Size
|
||||||
|
//
|
||||||
|
UINT64 RomSize;
|
||||||
|
|
||||||
|
//
|
||||||
|
// TRUE if there is any EFI driver in the OptionRom
|
||||||
|
//
|
||||||
|
BOOLEAN BusOverride;
|
||||||
|
|
||||||
|
//
|
||||||
|
// A list tracking reserved resource on a bridge device
|
||||||
|
//
|
||||||
|
LIST_ENTRY ReservedResourceList;
|
||||||
|
|
||||||
|
//
|
||||||
|
// A list tracking image handle of platform specific overriding driver
|
||||||
|
//
|
||||||
|
LIST_ENTRY OptionRomDriverList;
|
||||||
|
|
||||||
|
BOOLEAN IsPciExp;
|
||||||
|
|
||||||
|
} PCI_IO_DEVICE;
|
||||||
|
|
||||||
|
|
||||||
|
#define PCI_IO_DEVICE_FROM_PCI_IO_THIS(a) \
|
||||||
|
CR (a, PCI_IO_DEVICE, PciIo, PCI_IO_DEVICE_SIGNATURE)
|
||||||
|
|
||||||
|
#define PCI_IO_DEVICE_FROM_PCI_DRIVER_OVERRIDE_THIS(a) \
|
||||||
|
CR (a, PCI_IO_DEVICE, PciDriverOverride, PCI_IO_DEVICE_SIGNATURE)
|
||||||
|
|
||||||
|
#define PCI_IO_DEVICE_FROM_LINK(a) \
|
||||||
|
CR (a, PCI_IO_DEVICE, Link, PCI_IO_DEVICE_SIGNATURE)
|
||||||
|
|
||||||
|
//
|
||||||
|
// Global Variables
|
||||||
|
//
|
||||||
|
extern GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gPciBusComponentName;
|
||||||
|
extern GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gPciBusComponentName2;
|
||||||
|
extern EFI_DRIVER_BINDING_PROTOCOL gPciBusDriverBinding;
|
||||||
|
|
||||||
|
extern BOOLEAN gFullEnumeration;
|
||||||
|
static UINT64 gAllOne = 0xFFFFFFFFFFFFFFFF;
|
||||||
|
static UINT64 gAllZero = 0;
|
||||||
|
|
||||||
|
#include "PciIo.h"
|
||||||
|
#include "PciCommand.h"
|
||||||
|
#include "PciDeviceSupport.h"
|
||||||
|
#include "PciEnumerator.h"
|
||||||
|
#include "PciEnumeratorSupport.h"
|
||||||
|
#include "PciDriverOverride.h"
|
||||||
|
#include "PciRomTable.h"
|
||||||
|
#include "PciOptionRomSupport.h"
|
||||||
|
#include "PciPowerManagement.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define IS_ISA_BRIDGE(_p) IS_CLASS2 (_p, PCI_CLASS_BRIDGE, PCI_CLASS_ISA)
|
||||||
|
#define IS_INTEL_ISA_BRIDGE(_p) (IS_CLASS2 (_p, PCI_CLASS_BRIDGE, PCI_CLASS_ISA_POSITIVE_DECODE) && ((_p)->Hdr.VendorId == 0x8086) && ((_p)->Hdr.DeviceId == 0x7110))
|
||||||
|
|
||||||
|
#endif
|
72
DuetPkg/PciBusNoEnumerationDxe/PciBusNoEnumeration.inf
Normal file
72
DuetPkg/PciBusNoEnumerationDxe/PciBusNoEnumeration.inf
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
#/*++
|
||||||
|
#
|
||||||
|
# Copyright (c) 2005, 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:
|
||||||
|
#
|
||||||
|
# Abstract:
|
||||||
|
#
|
||||||
|
#--*/
|
||||||
|
[Defines]
|
||||||
|
INF_VERSION = 0x00010005
|
||||||
|
BASE_NAME = PciBusNoEnumerationDxe
|
||||||
|
FILE_GUID = 35C0C168-2607-4e51-BB53-448E3ED1A87F
|
||||||
|
MODULE_TYPE = DXE_DRIVER
|
||||||
|
VERSION_STRING = 1.0
|
||||||
|
EDK_RELEASE_VERSION = 0x00020000
|
||||||
|
EFI_SPECIFICATION_VERSION = 0x00020000
|
||||||
|
|
||||||
|
ENTRY_POINT = PciBusEntryPoint
|
||||||
|
|
||||||
|
[Packages]
|
||||||
|
MdePkg/MdePkg.dec
|
||||||
|
IntelFrameworkPkg/IntelFrameworkPkg.dec
|
||||||
|
IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec
|
||||||
|
|
||||||
|
[LibraryClasses]
|
||||||
|
DebugLib
|
||||||
|
BaseLib
|
||||||
|
UefiLib
|
||||||
|
UefiBootServicesTableLib
|
||||||
|
UefiDriverEntryPoint
|
||||||
|
BaseMemoryLib
|
||||||
|
ReportStatusCodeLib
|
||||||
|
DevicePathLib
|
||||||
|
|
||||||
|
[Sources]
|
||||||
|
PciBus.h
|
||||||
|
PciIo.h
|
||||||
|
PciCommand.h
|
||||||
|
PciDeviceSupport.h
|
||||||
|
PciEnumerator.h
|
||||||
|
PciEnumeratorSupport.h
|
||||||
|
PciOptionRomSupport.h
|
||||||
|
PciRomTable.h
|
||||||
|
PciPowerManagement.h
|
||||||
|
PciPowerManagement.c
|
||||||
|
PciRomTable.c
|
||||||
|
PciDriverOverride.h
|
||||||
|
PciDriverOverride.c
|
||||||
|
PciOptionRomSupport.c
|
||||||
|
PciEnumerator.c
|
||||||
|
PciEnumeratorSupport.c
|
||||||
|
PciCommand.c
|
||||||
|
ComponentName.c
|
||||||
|
PciDeviceSupport.c
|
||||||
|
PciBus.c
|
||||||
|
PciIo.c
|
||||||
|
|
||||||
|
[Protocols]
|
||||||
|
gEfiPciRootBridgeIoProtocolGuid
|
||||||
|
gEfiPciIoProtocolGuid
|
||||||
|
gEfiDevicePathProtocolGuid
|
||||||
|
gEfiBusSpecificDriverOverrideProtocolGuid
|
||||||
|
gEfiPciOptionRomTableGuid
|
||||||
|
gEfiDecompressProtocolGuid
|
464
DuetPkg/PciBusNoEnumerationDxe/PciCommand.c
Normal file
464
DuetPkg/PciBusNoEnumerationDxe/PciCommand.c
Normal file
@ -0,0 +1,464 @@
|
|||||||
|
/*++
|
||||||
|
|
||||||
|
Copyright (c) 2005 - 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:
|
||||||
|
|
||||||
|
PciCommand.c
|
||||||
|
|
||||||
|
Abstract:
|
||||||
|
|
||||||
|
PCI Bus Driver
|
||||||
|
|
||||||
|
Revision History
|
||||||
|
|
||||||
|
--*/
|
||||||
|
|
||||||
|
#include "Pcibus.h"
|
||||||
|
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
PciReadCommandRegister (
|
||||||
|
IN PCI_IO_DEVICE *PciIoDevice,
|
||||||
|
OUT UINT16 *Command
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
|
||||||
|
EFI_PCI_IO_PROTOCOL *PciIo;
|
||||||
|
|
||||||
|
*Command = 0;
|
||||||
|
PciIo = &PciIoDevice->PciIo;
|
||||||
|
|
||||||
|
return PciIo->Pci.Read (
|
||||||
|
PciIo,
|
||||||
|
EfiPciIoWidthUint16,
|
||||||
|
PCI_COMMAND_OFFSET,
|
||||||
|
1,
|
||||||
|
Command
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
PciSetCommandRegister (
|
||||||
|
IN PCI_IO_DEVICE *PciIoDevice,
|
||||||
|
IN UINT16 Command
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
UINT16 Temp;
|
||||||
|
EFI_PCI_IO_PROTOCOL *PciIo;
|
||||||
|
|
||||||
|
Temp = Command;
|
||||||
|
PciIo = &PciIoDevice->PciIo;
|
||||||
|
|
||||||
|
return PciIo->Pci.Write (
|
||||||
|
PciIo,
|
||||||
|
EfiPciIoWidthUint16,
|
||||||
|
PCI_COMMAND_OFFSET,
|
||||||
|
1,
|
||||||
|
&Temp
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
PciEnableCommandRegister (
|
||||||
|
IN PCI_IO_DEVICE *PciIoDevice,
|
||||||
|
IN UINT16 Command
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
UINT16 OldCommand;
|
||||||
|
EFI_PCI_IO_PROTOCOL *PciIo;
|
||||||
|
|
||||||
|
OldCommand = 0;
|
||||||
|
PciIo = &PciIoDevice->PciIo;
|
||||||
|
|
||||||
|
PciIo->Pci.Read (
|
||||||
|
PciIo,
|
||||||
|
EfiPciIoWidthUint16,
|
||||||
|
PCI_COMMAND_OFFSET,
|
||||||
|
1,
|
||||||
|
&OldCommand
|
||||||
|
);
|
||||||
|
|
||||||
|
OldCommand |= Command;
|
||||||
|
|
||||||
|
return PciIo->Pci.Write (
|
||||||
|
PciIo,
|
||||||
|
EfiPciIoWidthUint16,
|
||||||
|
PCI_COMMAND_OFFSET,
|
||||||
|
1,
|
||||||
|
&OldCommand
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
PciDisableCommandRegister (
|
||||||
|
IN PCI_IO_DEVICE *PciIoDevice,
|
||||||
|
IN UINT16 Command
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
UINT16 OldCommand;
|
||||||
|
EFI_PCI_IO_PROTOCOL *PciIo;
|
||||||
|
|
||||||
|
OldCommand = 0;
|
||||||
|
PciIo = &PciIoDevice->PciIo;
|
||||||
|
|
||||||
|
PciIo->Pci.Read (
|
||||||
|
PciIo,
|
||||||
|
EfiPciIoWidthUint16,
|
||||||
|
PCI_COMMAND_OFFSET,
|
||||||
|
1,
|
||||||
|
&OldCommand
|
||||||
|
);
|
||||||
|
|
||||||
|
OldCommand &= ~(Command);
|
||||||
|
|
||||||
|
return PciIo->Pci.Write (
|
||||||
|
PciIo,
|
||||||
|
EfiPciIoWidthUint16,
|
||||||
|
PCI_COMMAND_OFFSET,
|
||||||
|
1,
|
||||||
|
&OldCommand
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
PciSetBridgeControlRegister (
|
||||||
|
IN PCI_IO_DEVICE *PciIoDevice,
|
||||||
|
IN UINT16 Command
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
UINT16 Temp;
|
||||||
|
EFI_PCI_IO_PROTOCOL *PciIo;
|
||||||
|
|
||||||
|
Temp = Command;
|
||||||
|
PciIo = &PciIoDevice->PciIo;
|
||||||
|
|
||||||
|
return PciIo->Pci.Write (
|
||||||
|
PciIo,
|
||||||
|
EfiPciIoWidthUint16,
|
||||||
|
PCI_BRIDGE_CONTROL_REGISTER_OFFSET,
|
||||||
|
1,
|
||||||
|
&Temp
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
PciEnableBridgeControlRegister (
|
||||||
|
IN PCI_IO_DEVICE *PciIoDevice,
|
||||||
|
IN UINT16 Command
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
UINT16 OldCommand;
|
||||||
|
EFI_PCI_IO_PROTOCOL *PciIo;
|
||||||
|
|
||||||
|
OldCommand = 0;
|
||||||
|
PciIo = &PciIoDevice->PciIo;
|
||||||
|
|
||||||
|
PciIo->Pci.Read (
|
||||||
|
PciIo,
|
||||||
|
EfiPciIoWidthUint16,
|
||||||
|
PCI_BRIDGE_CONTROL_REGISTER_OFFSET,
|
||||||
|
1,
|
||||||
|
&OldCommand
|
||||||
|
);
|
||||||
|
|
||||||
|
OldCommand |= Command;
|
||||||
|
|
||||||
|
return PciIo->Pci.Write (
|
||||||
|
PciIo,
|
||||||
|
EfiPciIoWidthUint16,
|
||||||
|
PCI_BRIDGE_CONTROL_REGISTER_OFFSET,
|
||||||
|
1,
|
||||||
|
&OldCommand
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
PciDisableBridgeControlRegister (
|
||||||
|
IN PCI_IO_DEVICE *PciIoDevice,
|
||||||
|
IN UINT16 Command
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
UINT16 OldCommand;
|
||||||
|
EFI_PCI_IO_PROTOCOL *PciIo;
|
||||||
|
|
||||||
|
OldCommand = 0;
|
||||||
|
PciIo = &PciIoDevice->PciIo;
|
||||||
|
|
||||||
|
PciIo->Pci.Read (
|
||||||
|
PciIo,
|
||||||
|
EfiPciIoWidthUint16,
|
||||||
|
PCI_BRIDGE_CONTROL_REGISTER_OFFSET,
|
||||||
|
1,
|
||||||
|
&OldCommand
|
||||||
|
);
|
||||||
|
|
||||||
|
OldCommand &= ~(Command);
|
||||||
|
|
||||||
|
return PciIo->Pci.Write (
|
||||||
|
PciIo,
|
||||||
|
EfiPciIoWidthUint16,
|
||||||
|
PCI_BRIDGE_CONTROL_REGISTER_OFFSET,
|
||||||
|
1,
|
||||||
|
&OldCommand
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
PciReadBridgeControlRegister (
|
||||||
|
IN PCI_IO_DEVICE *PciIoDevice,
|
||||||
|
OUT UINT16 *Command
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
|
||||||
|
EFI_PCI_IO_PROTOCOL *PciIo;
|
||||||
|
|
||||||
|
*Command = 0;
|
||||||
|
PciIo = &PciIoDevice->PciIo;
|
||||||
|
|
||||||
|
return PciIo->Pci.Read (
|
||||||
|
PciIo,
|
||||||
|
EfiPciIoWidthUint16,
|
||||||
|
PCI_BRIDGE_CONTROL_REGISTER_OFFSET,
|
||||||
|
1,
|
||||||
|
Command
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOLEAN
|
||||||
|
PciCapabilitySupport (
|
||||||
|
IN PCI_IO_DEVICE *PciIoDevice
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
--*/
|
||||||
|
// TODO: PciIoDevice - add argument and description to function comment
|
||||||
|
{
|
||||||
|
|
||||||
|
if (PciIoDevice->Pci.Hdr.Status & EFI_PCI_STATUS_CAPABILITY) {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
LocateCapabilityRegBlock (
|
||||||
|
IN PCI_IO_DEVICE *PciIoDevice,
|
||||||
|
IN UINT8 CapId,
|
||||||
|
IN OUT UINT8 *Offset,
|
||||||
|
OUT UINT8 *NextRegBlock OPTIONAL
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Locate Capability register.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
PciIoDevice - A pointer to the PCI_IO_DEVICE.
|
||||||
|
CapId - The capability ID.
|
||||||
|
Offset - A pointer to the offset.
|
||||||
|
As input: the default offset;
|
||||||
|
As output: the offset of the found block.
|
||||||
|
NextRegBlock - An optional pointer to return the value of next block.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
EFI_UNSUPPORTED - The Pci Io device is not supported.
|
||||||
|
EFI_NOT_FOUND - The Pci Io device cannot be found.
|
||||||
|
EFI_SUCCESS - The Pci Io device is successfully located.
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
UINT8 CapabilityPtr;
|
||||||
|
UINT16 CapabilityEntry;
|
||||||
|
UINT8 CapabilityID;
|
||||||
|
UINT32 Temp;
|
||||||
|
|
||||||
|
//
|
||||||
|
// To check the capability of this device supports
|
||||||
|
//
|
||||||
|
if (!PciCapabilitySupport (PciIoDevice)) {
|
||||||
|
return EFI_UNSUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*Offset != 0) {
|
||||||
|
CapabilityPtr = *Offset;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
CapabilityPtr = 0;
|
||||||
|
if (IS_CARDBUS_BRIDGE (&PciIoDevice->Pci)) {
|
||||||
|
|
||||||
|
PciIoDevice->PciIo.Pci.Read (
|
||||||
|
&PciIoDevice->PciIo,
|
||||||
|
EfiPciIoWidthUint8,
|
||||||
|
EFI_PCI_CARDBUS_BRIDGE_CAPABILITY_PTR,
|
||||||
|
1,
|
||||||
|
&CapabilityPtr
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
PciIoDevice->PciIo.Pci.Read (
|
||||||
|
&PciIoDevice->PciIo,
|
||||||
|
EfiPciIoWidthUint32,
|
||||||
|
EFI_PCI_CAPABILITY_PTR,
|
||||||
|
1,
|
||||||
|
&Temp
|
||||||
|
);
|
||||||
|
//
|
||||||
|
// Do not get byte read directly, because some PCI card will return 0xFF
|
||||||
|
// when perform PCI-Express byte read, while return correct 0x00
|
||||||
|
// when perform PCI-Express dword read, or PCI dword read.
|
||||||
|
//
|
||||||
|
CapabilityPtr = (UINT8)Temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (CapabilityPtr > 0x3F) {
|
||||||
|
//
|
||||||
|
// Mask it to DWORD alignment per PCI spec
|
||||||
|
//
|
||||||
|
CapabilityPtr &= 0xFC;
|
||||||
|
PciIoDevice->PciIo.Pci.Read (
|
||||||
|
&PciIoDevice->PciIo,
|
||||||
|
EfiPciIoWidthUint16,
|
||||||
|
CapabilityPtr,
|
||||||
|
1,
|
||||||
|
&CapabilityEntry
|
||||||
|
);
|
||||||
|
|
||||||
|
CapabilityID = (UINT8) CapabilityEntry;
|
||||||
|
|
||||||
|
if (CapabilityID == CapId) {
|
||||||
|
*Offset = CapabilityPtr;
|
||||||
|
if (NextRegBlock != NULL) {
|
||||||
|
*NextRegBlock = (UINT8) (CapabilityEntry >> 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
CapabilityPtr = (UINT8) (CapabilityEntry >> 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
return EFI_NOT_FOUND;
|
||||||
|
}
|
167
DuetPkg/PciBusNoEnumerationDxe/PciCommand.h
Normal file
167
DuetPkg/PciBusNoEnumerationDxe/PciCommand.h
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
/*++
|
||||||
|
|
||||||
|
Copyright (c) 2005 - 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:
|
||||||
|
|
||||||
|
PciCommand.h
|
||||||
|
|
||||||
|
Abstract:
|
||||||
|
|
||||||
|
PCI Bus Driver
|
||||||
|
|
||||||
|
Revision History
|
||||||
|
|
||||||
|
--*/
|
||||||
|
|
||||||
|
#ifndef _EFI_PCI_COMMAND_H
|
||||||
|
#define _EFI_PCI_COMMAND_H
|
||||||
|
|
||||||
|
#include "PciBus.h"
|
||||||
|
|
||||||
|
//
|
||||||
|
// The PCI Command register bits owned by PCI Bus driver.
|
||||||
|
//
|
||||||
|
// They should be cleared at the beginning. The other registers
|
||||||
|
// are owned by chipset, we should not touch them.
|
||||||
|
//
|
||||||
|
#define EFI_PCI_COMMAND_BITS_OWNED ( \
|
||||||
|
EFI_PCI_COMMAND_IO_SPACE | \
|
||||||
|
EFI_PCI_COMMAND_MEMORY_SPACE | \
|
||||||
|
EFI_PCI_COMMAND_BUS_MASTER | \
|
||||||
|
EFI_PCI_COMMAND_MEMORY_WRITE_AND_INVALIDATE | \
|
||||||
|
EFI_PCI_COMMAND_VGA_PALETTE_SNOOP | \
|
||||||
|
EFI_PCI_COMMAND_FAST_BACK_TO_BACK \
|
||||||
|
)
|
||||||
|
|
||||||
|
//
|
||||||
|
// The PCI Bridge Control register bits owned by PCI Bus driver.
|
||||||
|
//
|
||||||
|
// They should be cleared at the beginning. The other registers
|
||||||
|
// are owned by chipset, we should not touch them.
|
||||||
|
//
|
||||||
|
#define EFI_PCI_BRIDGE_CONTROL_BITS_OWNED ( \
|
||||||
|
EFI_PCI_BRIDGE_CONTROL_ISA | \
|
||||||
|
EFI_PCI_BRIDGE_CONTROL_VGA | \
|
||||||
|
EFI_PCI_BRIDGE_CONTROL_VGA_16 | \
|
||||||
|
EFI_PCI_BRIDGE_CONTROL_FAST_BACK_TO_BACK \
|
||||||
|
)
|
||||||
|
|
||||||
|
//
|
||||||
|
// The PCCard Bridge Control register bits owned by PCI Bus driver.
|
||||||
|
//
|
||||||
|
// They should be cleared at the beginning. The other registers
|
||||||
|
// are owned by chipset, we should not touch them.
|
||||||
|
//
|
||||||
|
#define EFI_PCCARD_BRIDGE_CONTROL_BITS_OWNED ( \
|
||||||
|
EFI_PCI_BRIDGE_CONTROL_ISA | \
|
||||||
|
EFI_PCI_BRIDGE_CONTROL_VGA | \
|
||||||
|
EFI_PCI_BRIDGE_CONTROL_FAST_BACK_TO_BACK \
|
||||||
|
)
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
PciReadCommandRegister (
|
||||||
|
IN PCI_IO_DEVICE *PciIoDevice,
|
||||||
|
OUT UINT16 *Command
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
PciSetCommandRegister (
|
||||||
|
IN PCI_IO_DEVICE *PciIoDevice,
|
||||||
|
IN UINT16 Command
|
||||||
|
);
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
PciEnableCommandRegister (
|
||||||
|
IN PCI_IO_DEVICE *PciIoDevice,
|
||||||
|
IN UINT16 Command
|
||||||
|
);
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
PciDisableCommandRegister (
|
||||||
|
IN PCI_IO_DEVICE *PciIoDevice,
|
||||||
|
IN UINT16 Command
|
||||||
|
);
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
PciDisableBridgeControlRegister (
|
||||||
|
IN PCI_IO_DEVICE *PciIoDevice,
|
||||||
|
IN UINT16 Command
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
PciEnableBridgeControlRegister (
|
||||||
|
IN PCI_IO_DEVICE *PciIoDevice,
|
||||||
|
IN UINT16 Command
|
||||||
|
);
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
PciReadBridgeControlRegister (
|
||||||
|
IN PCI_IO_DEVICE *PciIoDevice,
|
||||||
|
OUT UINT16 *Command
|
||||||
|
);
|
||||||
|
|
||||||
|
BOOLEAN
|
||||||
|
PciCapabilitySupport (
|
||||||
|
IN PCI_IO_DEVICE *PciIoDevice
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
TODO: Add function description
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
PciIoDevice - TODO: add argument description
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
TODO: add return values
|
||||||
|
|
||||||
|
--*/
|
||||||
|
;
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
LocateCapabilityRegBlock (
|
||||||
|
IN PCI_IO_DEVICE *PciIoDevice,
|
||||||
|
IN UINT8 CapId,
|
||||||
|
IN OUT UINT8 *Offset,
|
||||||
|
OUT UINT8 *NextRegBlock OPTIONAL
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Locate Capability register.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
PciIoDevice - A pointer to the PCI_IO_DEVICE.
|
||||||
|
CapId - The capability ID.
|
||||||
|
Offset - A pointer to the offset.
|
||||||
|
As input: the default offset;
|
||||||
|
As output: the offset of the found block.
|
||||||
|
NextRegBlock - An optional pointer to return the value of next block.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
EFI_UNSUPPORTED - The Pci Io device is not supported.
|
||||||
|
EFI_NOT_FOUND - The Pci Io device cannot be found.
|
||||||
|
EFI_SUCCESS - The Pci Io device is successfully located.
|
||||||
|
|
||||||
|
--*/
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
973
DuetPkg/PciBusNoEnumerationDxe/PciDeviceSupport.c
Normal file
973
DuetPkg/PciBusNoEnumerationDxe/PciDeviceSupport.c
Normal file
@ -0,0 +1,973 @@
|
|||||||
|
/*++
|
||||||
|
|
||||||
|
Copyright (c) 2005 - 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:
|
||||||
|
|
||||||
|
PciDeviceSupport.c
|
||||||
|
|
||||||
|
Abstract:
|
||||||
|
|
||||||
|
This file provides routine to support Pci device node manipulation
|
||||||
|
|
||||||
|
Revision History
|
||||||
|
|
||||||
|
--*/
|
||||||
|
|
||||||
|
#include "Pcibus.h"
|
||||||
|
|
||||||
|
//
|
||||||
|
// This device structure is serviced as a header.
|
||||||
|
// Its Next field points to the first root bridge device node
|
||||||
|
//
|
||||||
|
LIST_ENTRY gPciDevicePool;
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
InitializePciDevicePool (
|
||||||
|
VOID
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Initialize the gPciDevicePool
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
InitializeListHead (&gPciDevicePool);
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
InsertRootBridge (
|
||||||
|
IN PCI_IO_DEVICE *RootBridge
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Insert a root bridge into PCI device pool
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
RootBridge - A pointer to the PCI_IO_DEVICE.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
InsertTailList (&gPciDevicePool, &(RootBridge->Link));
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
InsertPciDevice (
|
||||||
|
PCI_IO_DEVICE *Bridge,
|
||||||
|
PCI_IO_DEVICE *PciDeviceNode
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
This function is used to insert a PCI device node under
|
||||||
|
a bridge
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
Bridge - A pointer to the PCI_IO_DEVICE.
|
||||||
|
PciDeviceNode - A pointer to the PCI_IO_DEVICE.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
--*/
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
InsertTailList (&Bridge->ChildList, &(PciDeviceNode->Link));
|
||||||
|
PciDeviceNode->Parent = Bridge;
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
DestroyRootBridge (
|
||||||
|
IN PCI_IO_DEVICE *RootBridge
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
RootBridge - A pointer to the PCI_IO_DEVICE.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
DestroyPciDeviceTree (RootBridge);
|
||||||
|
|
||||||
|
gBS->FreePool (RootBridge);
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
DestroyPciDeviceTree (
|
||||||
|
IN PCI_IO_DEVICE *Bridge
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Destroy all the pci device node under the bridge.
|
||||||
|
Bridge itself is not included.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Bridge - A pointer to the PCI_IO_DEVICE.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
LIST_ENTRY *CurrentLink;
|
||||||
|
PCI_IO_DEVICE *Temp;
|
||||||
|
|
||||||
|
while (!IsListEmpty (&Bridge->ChildList)) {
|
||||||
|
|
||||||
|
CurrentLink = Bridge->ChildList.ForwardLink;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Remove this node from the linked list
|
||||||
|
//
|
||||||
|
RemoveEntryList (CurrentLink);
|
||||||
|
|
||||||
|
Temp = PCI_IO_DEVICE_FROM_LINK (CurrentLink);
|
||||||
|
|
||||||
|
if (IS_PCI_BRIDGE (&(Temp->Pci))) {
|
||||||
|
DestroyPciDeviceTree (Temp);
|
||||||
|
}
|
||||||
|
gBS->FreePool (Temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
DestroyRootBridgeByHandle (
|
||||||
|
EFI_HANDLE Controller
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Destroy all device nodes under the root bridge
|
||||||
|
specified by Controller.
|
||||||
|
The root bridge itself is also included.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Controller - An efi handle.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
|
||||||
|
LIST_ENTRY *CurrentLink;
|
||||||
|
PCI_IO_DEVICE *Temp;
|
||||||
|
|
||||||
|
CurrentLink = gPciDevicePool.ForwardLink;
|
||||||
|
|
||||||
|
while (CurrentLink && CurrentLink != &gPciDevicePool) {
|
||||||
|
Temp = PCI_IO_DEVICE_FROM_LINK (CurrentLink);
|
||||||
|
|
||||||
|
if (Temp->Handle == Controller) {
|
||||||
|
|
||||||
|
RemoveEntryList (CurrentLink);
|
||||||
|
|
||||||
|
DestroyPciDeviceTree (Temp);
|
||||||
|
|
||||||
|
gBS->FreePool(Temp);
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrentLink = CurrentLink->ForwardLink;
|
||||||
|
}
|
||||||
|
|
||||||
|
return EFI_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
RegisterPciDevice (
|
||||||
|
IN EFI_HANDLE Controller,
|
||||||
|
IN PCI_IO_DEVICE *PciIoDevice,
|
||||||
|
OUT EFI_HANDLE *Handle OPTIONAL
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
This function registers the PCI IO device. It creates a handle for this PCI IO device
|
||||||
|
(if the handle does not exist), attaches appropriate protocols onto the handle, does
|
||||||
|
necessary initialization, and sets up parent/child relationship with its bus controller.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Controller - An EFI handle for the PCI bus controller.
|
||||||
|
PciIoDevice - A PCI_IO_DEVICE pointer to the PCI IO device to be registered.
|
||||||
|
Handle - A pointer to hold the EFI handle for the PCI IO device.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
EFI_SUCCESS - The PCI device is successfully registered.
|
||||||
|
Others - An error occurred when registering the PCI device.
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
UINT8 PciExpressCapRegOffset;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Install the pciio protocol, device path protocol and
|
||||||
|
// Bus Specific Driver Override Protocol
|
||||||
|
//
|
||||||
|
|
||||||
|
if (PciIoDevice->BusOverride) {
|
||||||
|
Status = gBS->InstallMultipleProtocolInterfaces (
|
||||||
|
&PciIoDevice->Handle,
|
||||||
|
&gEfiDevicePathProtocolGuid,
|
||||||
|
PciIoDevice->DevicePath,
|
||||||
|
&gEfiPciIoProtocolGuid,
|
||||||
|
&PciIoDevice->PciIo,
|
||||||
|
&gEfiBusSpecificDriverOverrideProtocolGuid,
|
||||||
|
&PciIoDevice->PciDriverOverride,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
Status = gBS->InstallMultipleProtocolInterfaces (
|
||||||
|
&PciIoDevice->Handle,
|
||||||
|
&gEfiDevicePathProtocolGuid,
|
||||||
|
PciIoDevice->DevicePath,
|
||||||
|
&gEfiPciIoProtocolGuid,
|
||||||
|
&PciIoDevice->PciIo,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
return Status;
|
||||||
|
} else {
|
||||||
|
Status = gBS->OpenProtocol (
|
||||||
|
Controller,
|
||||||
|
&gEfiPciRootBridgeIoProtocolGuid,
|
||||||
|
(VOID **)&(PciIoDevice->PciRootBridgeIo),
|
||||||
|
gPciBusDriverBinding.DriverBindingHandle,
|
||||||
|
PciIoDevice->Handle,
|
||||||
|
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
|
||||||
|
);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Handle != NULL) {
|
||||||
|
*Handle = PciIoDevice->Handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Detect if PCI Express Device
|
||||||
|
//
|
||||||
|
PciExpressCapRegOffset = 0;
|
||||||
|
Status = LocateCapabilityRegBlock (
|
||||||
|
PciIoDevice,
|
||||||
|
EFI_PCI_CAPABILITY_ID_PCIEXP,
|
||||||
|
&PciExpressCapRegOffset,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
if (!EFI_ERROR (Status)) {
|
||||||
|
PciIoDevice->IsPciExp = TRUE;
|
||||||
|
DEBUG ((EFI_D_ERROR, "PciExp - %x (B-%x, D-%x, F-%x)\n", PciIoDevice->IsPciExp, PciIoDevice->BusNumber, PciIoDevice->DeviceNumber, PciIoDevice->FunctionNumber));
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Indicate the pci device is registered
|
||||||
|
//
|
||||||
|
PciIoDevice->Registered = TRUE;
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
DeRegisterPciDevice (
|
||||||
|
IN EFI_HANDLE Controller,
|
||||||
|
IN EFI_HANDLE Handle
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
This function is used to de-register the PCI device from the EFI,
|
||||||
|
That includes un-installing PciIo protocol from the specified PCI
|
||||||
|
device handle.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Controller - An efi handle.
|
||||||
|
Handle - An efi handle.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
EFI_PCI_IO_PROTOCOL *PciIo;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
PCI_IO_DEVICE *PciIoDevice;
|
||||||
|
PCI_IO_DEVICE *Node;
|
||||||
|
LIST_ENTRY *CurrentLink;
|
||||||
|
EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;
|
||||||
|
|
||||||
|
Status = gBS->OpenProtocol (
|
||||||
|
Handle,
|
||||||
|
&gEfiPciIoProtocolGuid,
|
||||||
|
(VOID **) &PciIo,
|
||||||
|
gPciBusDriverBinding.DriverBindingHandle,
|
||||||
|
Controller,
|
||||||
|
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
||||||
|
);
|
||||||
|
if (!EFI_ERROR (Status)) {
|
||||||
|
PciIoDevice = PCI_IO_DEVICE_FROM_PCI_IO_THIS (PciIo);
|
||||||
|
|
||||||
|
//
|
||||||
|
// If it is already de-registered
|
||||||
|
//
|
||||||
|
if (!PciIoDevice->Registered) {
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// If it is PPB, first de-register its children
|
||||||
|
//
|
||||||
|
|
||||||
|
if (IS_PCI_BRIDGE (&(PciIoDevice->Pci))) {
|
||||||
|
|
||||||
|
CurrentLink = PciIoDevice->ChildList.ForwardLink;
|
||||||
|
|
||||||
|
while (CurrentLink && CurrentLink != &PciIoDevice->ChildList) {
|
||||||
|
Node = PCI_IO_DEVICE_FROM_LINK (CurrentLink);
|
||||||
|
Status = DeRegisterPciDevice (Controller, Node->Handle);
|
||||||
|
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrentLink = CurrentLink->ForwardLink;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// First disconnect this device
|
||||||
|
//
|
||||||
|
// PciIoDevice->PciIo.Attributes(&(PciIoDevice->PciIo),
|
||||||
|
// EfiPciIoAttributeOperationDisable,
|
||||||
|
// EFI_PCI_DEVICE_ENABLE,
|
||||||
|
// NULL
|
||||||
|
// );
|
||||||
|
|
||||||
|
//
|
||||||
|
// Close the child handle
|
||||||
|
//
|
||||||
|
Status = gBS->CloseProtocol (
|
||||||
|
Controller,
|
||||||
|
&gEfiPciRootBridgeIoProtocolGuid,
|
||||||
|
gPciBusDriverBinding.DriverBindingHandle,
|
||||||
|
Handle
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Un-install the device path protocol and pci io protocol
|
||||||
|
//
|
||||||
|
if (PciIoDevice->BusOverride) {
|
||||||
|
Status = gBS->UninstallMultipleProtocolInterfaces (
|
||||||
|
Handle,
|
||||||
|
&gEfiDevicePathProtocolGuid,
|
||||||
|
PciIoDevice->DevicePath,
|
||||||
|
&gEfiPciIoProtocolGuid,
|
||||||
|
&PciIoDevice->PciIo,
|
||||||
|
&gEfiBusSpecificDriverOverrideProtocolGuid,
|
||||||
|
&PciIoDevice->PciDriverOverride,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
Status = gBS->UninstallMultipleProtocolInterfaces (
|
||||||
|
Handle,
|
||||||
|
&gEfiDevicePathProtocolGuid,
|
||||||
|
PciIoDevice->DevicePath,
|
||||||
|
&gEfiPciIoProtocolGuid,
|
||||||
|
&PciIoDevice->PciIo,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
gBS->OpenProtocol (
|
||||||
|
Controller,
|
||||||
|
&gEfiPciRootBridgeIoProtocolGuid,
|
||||||
|
(VOID **) &PciRootBridgeIo,
|
||||||
|
gPciBusDriverBinding.DriverBindingHandle,
|
||||||
|
Handle,
|
||||||
|
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
|
||||||
|
);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// The Device Driver should disable this device after disconnect
|
||||||
|
// so the Pci Bus driver will not touch this device any more.
|
||||||
|
// Restore the register field to the original value
|
||||||
|
//
|
||||||
|
PciIoDevice->Registered = FALSE;
|
||||||
|
PciIoDevice->Handle = NULL;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
//
|
||||||
|
// Handle may be closed before
|
||||||
|
//
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
EnableBridgeAttributes (
|
||||||
|
IN PCI_IO_DEVICE *PciIoDevice
|
||||||
|
)
|
||||||
|
{
|
||||||
|
PCI_TYPE01 PciData;
|
||||||
|
|
||||||
|
//
|
||||||
|
// NOTE: We should not set EFI_PCI_DEVICE_ENABLE for a bridge
|
||||||
|
// directly, because some legacy BIOS will NOT assign
|
||||||
|
// IO or Memory resource for a bridge who has no child
|
||||||
|
// device. So we add check IO or Memory here.
|
||||||
|
//
|
||||||
|
|
||||||
|
PciIoDevice->PciIo.Pci.Read (
|
||||||
|
&PciIoDevice->PciIo,
|
||||||
|
EfiPciIoWidthUint8,
|
||||||
|
0,
|
||||||
|
sizeof (PciData),
|
||||||
|
&PciData
|
||||||
|
);
|
||||||
|
|
||||||
|
if ((((PciData.Bridge.IoBase & 0xF) == 0) &&
|
||||||
|
(PciData.Bridge.IoBase != 0 || PciData.Bridge.IoLimit != 0)) ||
|
||||||
|
(((PciData.Bridge.IoBase & 0xF) == 1) &&
|
||||||
|
((PciData.Bridge.IoBase & 0xF0) != 0 || (PciData.Bridge.IoLimit & 0xF0) != 0 || PciData.Bridge.IoBaseUpper16 != 0 || PciData.Bridge.IoLimitUpper16 != 0))) {
|
||||||
|
PciIoDevice->PciIo.Attributes(
|
||||||
|
&(PciIoDevice->PciIo),
|
||||||
|
EfiPciIoAttributeOperationEnable,
|
||||||
|
(EFI_PCI_IO_ATTRIBUTE_IO | EFI_PCI_IO_ATTRIBUTE_BUS_MASTER),
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ((PciData.Bridge.MemoryBase & 0xFFF0) != 0 || (PciData.Bridge.MemoryLimit & 0xFFF0) != 0) {
|
||||||
|
PciIoDevice->PciIo.Attributes(
|
||||||
|
&(PciIoDevice->PciIo),
|
||||||
|
EfiPciIoAttributeOperationEnable,
|
||||||
|
(EFI_PCI_IO_ATTRIBUTE_MEMORY | EFI_PCI_IO_ATTRIBUTE_BUS_MASTER),
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ((((PciData.Bridge.PrefetchableMemoryBase & 0xF) == 0) &&
|
||||||
|
(PciData.Bridge.PrefetchableMemoryBase != 0 || PciData.Bridge.PrefetchableMemoryLimit != 0)) ||
|
||||||
|
(((PciData.Bridge.PrefetchableMemoryBase & 0xF) == 1) &&
|
||||||
|
((PciData.Bridge.PrefetchableMemoryBase & 0xFFF0) != 0 || (PciData.Bridge.PrefetchableMemoryLimit & 0xFFF0) != 0 || PciData.Bridge.PrefetchableBaseUpper32 != 0 || PciData.Bridge.PrefetchableLimitUpper32 != 0))) {
|
||||||
|
PciIoDevice->PciIo.Attributes(
|
||||||
|
&(PciIoDevice->PciIo),
|
||||||
|
EfiPciIoAttributeOperationEnable,
|
||||||
|
(EFI_PCI_IO_ATTRIBUTE_MEMORY | EFI_PCI_IO_ATTRIBUTE_BUS_MASTER),
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
StartPciDevicesOnBridge (
|
||||||
|
IN EFI_HANDLE Controller,
|
||||||
|
IN PCI_IO_DEVICE *RootBridge,
|
||||||
|
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Start to manage the PCI device on specified the root bridge or PCI-PCI Bridge
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Controller - An efi handle.
|
||||||
|
RootBridge - A pointer to the PCI_IO_DEVICE.
|
||||||
|
RemainingDevicePath - A pointer to the EFI_DEVICE_PATH_PROTOCOL.
|
||||||
|
NumberOfChildren - Children number.
|
||||||
|
ChildHandleBuffer - A pointer to the child handle buffer.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
PCI_IO_DEVICE *Temp;
|
||||||
|
PCI_IO_DEVICE *PciIoDevice;
|
||||||
|
EFI_DEV_PATH_PTR Node;
|
||||||
|
EFI_DEVICE_PATH_PROTOCOL *CurrentDevicePath;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
LIST_ENTRY *CurrentLink;
|
||||||
|
|
||||||
|
CurrentLink = RootBridge->ChildList.ForwardLink;
|
||||||
|
|
||||||
|
while (CurrentLink && CurrentLink != &RootBridge->ChildList) {
|
||||||
|
|
||||||
|
Temp = PCI_IO_DEVICE_FROM_LINK (CurrentLink);
|
||||||
|
if (RemainingDevicePath != NULL) {
|
||||||
|
|
||||||
|
Node.DevPath = RemainingDevicePath;
|
||||||
|
|
||||||
|
if (Node.Pci->Device != Temp->DeviceNumber ||
|
||||||
|
Node.Pci->Function != Temp->FunctionNumber) {
|
||||||
|
CurrentLink = CurrentLink->ForwardLink;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check if the device has been assigned with required resource
|
||||||
|
//
|
||||||
|
if (!Temp->Allocated) {
|
||||||
|
return EFI_NOT_READY;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check if the current node has been registered before
|
||||||
|
// If it is not, register it
|
||||||
|
//
|
||||||
|
if (!Temp->Registered) {
|
||||||
|
PciIoDevice = Temp;
|
||||||
|
|
||||||
|
Status = RegisterPciDevice (
|
||||||
|
Controller,
|
||||||
|
PciIoDevice,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Get the next device path
|
||||||
|
//
|
||||||
|
CurrentDevicePath = EfiNextDevicePathNode (RemainingDevicePath);
|
||||||
|
if (EfiIsDevicePathEnd (CurrentDevicePath)) {
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// If it is a PPB
|
||||||
|
//
|
||||||
|
if (IS_PCI_BRIDGE (&(Temp->Pci))) {
|
||||||
|
Status = StartPciDevicesOnBridge (
|
||||||
|
Controller,
|
||||||
|
Temp,
|
||||||
|
CurrentDevicePath
|
||||||
|
);
|
||||||
|
EnableBridgeAttributes (Temp);
|
||||||
|
|
||||||
|
return Status;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
//
|
||||||
|
// Currently, the PCI bus driver only support PCI-PCI bridge
|
||||||
|
//
|
||||||
|
return EFI_UNSUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
//
|
||||||
|
// If remaining device path is NULL,
|
||||||
|
// try to enable all the pci devices under this bridge
|
||||||
|
//
|
||||||
|
|
||||||
|
if (!Temp->Registered && Temp->Allocated) {
|
||||||
|
|
||||||
|
PciIoDevice = Temp;
|
||||||
|
|
||||||
|
Status = RegisterPciDevice (
|
||||||
|
Controller,
|
||||||
|
PciIoDevice,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IS_PCI_BRIDGE (&(Temp->Pci))) {
|
||||||
|
Status = StartPciDevicesOnBridge (
|
||||||
|
Controller,
|
||||||
|
Temp,
|
||||||
|
RemainingDevicePath
|
||||||
|
);
|
||||||
|
EnableBridgeAttributes (Temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrentLink = CurrentLink->ForwardLink;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return EFI_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
StartPciDevices (
|
||||||
|
IN EFI_HANDLE Controller,
|
||||||
|
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Start to manage the PCI device according to RemainingDevicePath
|
||||||
|
If RemainingDevicePath == NULL, the PCI bus driver will start
|
||||||
|
to manage all the PCI devices it found previously
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
Controller - An efi handle.
|
||||||
|
RemainingDevicePath - A pointer to the EFI_DEVICE_PATH_PROTOCOL.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
EFI_DEV_PATH_PTR Node;
|
||||||
|
PCI_IO_DEVICE *RootBridge;
|
||||||
|
LIST_ENTRY *CurrentLink;
|
||||||
|
|
||||||
|
if (RemainingDevicePath != NULL) {
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check if the RemainingDevicePath is valid
|
||||||
|
//
|
||||||
|
Node.DevPath = RemainingDevicePath;
|
||||||
|
if (Node.DevPath->Type != HARDWARE_DEVICE_PATH ||
|
||||||
|
Node.DevPath->SubType != HW_PCI_DP &&
|
||||||
|
DevicePathNodeLength (Node.DevPath) != sizeof (PCI_DEVICE_PATH)
|
||||||
|
) {
|
||||||
|
return EFI_UNSUPPORTED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrentLink = gPciDevicePool.ForwardLink;
|
||||||
|
|
||||||
|
while (CurrentLink && CurrentLink != &gPciDevicePool) {
|
||||||
|
|
||||||
|
RootBridge = PCI_IO_DEVICE_FROM_LINK (CurrentLink);
|
||||||
|
//
|
||||||
|
// Locate the right root bridge to start
|
||||||
|
//
|
||||||
|
if (RootBridge->Handle == Controller) {
|
||||||
|
StartPciDevicesOnBridge (
|
||||||
|
Controller,
|
||||||
|
RootBridge,
|
||||||
|
RemainingDevicePath
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrentLink = CurrentLink->ForwardLink;
|
||||||
|
}
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
PCI_IO_DEVICE *
|
||||||
|
CreateRootBridge (
|
||||||
|
IN EFI_HANDLE RootBridgeHandle
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
RootBridgeHandle - An efi handle.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
|
||||||
|
EFI_STATUS Status;
|
||||||
|
PCI_IO_DEVICE *Dev;
|
||||||
|
|
||||||
|
Dev = NULL;
|
||||||
|
Status = gBS->AllocatePool (
|
||||||
|
EfiBootServicesData,
|
||||||
|
sizeof (PCI_IO_DEVICE),
|
||||||
|
(VOID **) &Dev
|
||||||
|
);
|
||||||
|
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ZeroMem (Dev, sizeof (PCI_IO_DEVICE));
|
||||||
|
Dev->Signature = PCI_IO_DEVICE_SIGNATURE;
|
||||||
|
Dev->Handle = RootBridgeHandle;
|
||||||
|
InitializeListHead (&Dev->ChildList);
|
||||||
|
|
||||||
|
return Dev;
|
||||||
|
}
|
||||||
|
|
||||||
|
PCI_IO_DEVICE *
|
||||||
|
GetRootBridgeByHandle (
|
||||||
|
EFI_HANDLE RootBridgeHandle
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
RootBridgeHandle - An efi handle.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
PCI_IO_DEVICE *RootBridgeDev;
|
||||||
|
LIST_ENTRY *CurrentLink;
|
||||||
|
|
||||||
|
CurrentLink = gPciDevicePool.ForwardLink;
|
||||||
|
|
||||||
|
while (CurrentLink && CurrentLink != &gPciDevicePool) {
|
||||||
|
|
||||||
|
RootBridgeDev = PCI_IO_DEVICE_FROM_LINK (CurrentLink);
|
||||||
|
if (RootBridgeDev->Handle == RootBridgeHandle) {
|
||||||
|
return RootBridgeDev;
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrentLink = CurrentLink->ForwardLink;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOLEAN
|
||||||
|
RootBridgeExisted (
|
||||||
|
IN EFI_HANDLE RootBridgeHandle
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
This function searches if RootBridgeHandle has already existed
|
||||||
|
in current device pool.
|
||||||
|
|
||||||
|
If so, it means the given root bridge has been already enumerated.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
RootBridgeHandle - An efi handle.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
PCI_IO_DEVICE *Bridge;
|
||||||
|
|
||||||
|
Bridge = GetRootBridgeByHandle (RootBridgeHandle);
|
||||||
|
|
||||||
|
if (Bridge != NULL) {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOLEAN
|
||||||
|
PciDeviceExisted (
|
||||||
|
IN PCI_IO_DEVICE *Bridge,
|
||||||
|
IN PCI_IO_DEVICE *PciIoDevice
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Bridge - A pointer to the PCI_IO_DEVICE.
|
||||||
|
PciIoDevice - A pointer to the PCI_IO_DEVICE.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
|
||||||
|
PCI_IO_DEVICE *Temp;
|
||||||
|
LIST_ENTRY *CurrentLink;
|
||||||
|
|
||||||
|
CurrentLink = Bridge->ChildList.ForwardLink;
|
||||||
|
|
||||||
|
while (CurrentLink && CurrentLink != &Bridge->ChildList) {
|
||||||
|
|
||||||
|
Temp = PCI_IO_DEVICE_FROM_LINK (CurrentLink);
|
||||||
|
|
||||||
|
if (Temp == PciIoDevice) {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!IsListEmpty (&Temp->ChildList)) {
|
||||||
|
if (PciDeviceExisted (Temp, PciIoDevice)) {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrentLink = CurrentLink->ForwardLink;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PCI_IO_DEVICE *
|
||||||
|
ActiveVGADeviceOnTheSameSegment (
|
||||||
|
IN PCI_IO_DEVICE *VgaDevice
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
VgaDevice - A pointer to the PCI_IO_DEVICE.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
LIST_ENTRY *CurrentLink;
|
||||||
|
PCI_IO_DEVICE *Temp;
|
||||||
|
|
||||||
|
CurrentLink = gPciDevicePool.ForwardLink;
|
||||||
|
|
||||||
|
while (CurrentLink && CurrentLink != &gPciDevicePool) {
|
||||||
|
|
||||||
|
Temp = PCI_IO_DEVICE_FROM_LINK (CurrentLink);
|
||||||
|
|
||||||
|
if (Temp->PciRootBridgeIo->SegmentNumber == VgaDevice->PciRootBridgeIo->SegmentNumber) {
|
||||||
|
|
||||||
|
Temp = ActiveVGADeviceOnTheRootBridge (Temp);
|
||||||
|
|
||||||
|
if (Temp != NULL) {
|
||||||
|
return Temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrentLink = CurrentLink->ForwardLink;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
PCI_IO_DEVICE *
|
||||||
|
ActiveVGADeviceOnTheRootBridge (
|
||||||
|
IN PCI_IO_DEVICE *RootBridge
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
RootBridge - A pointer to the PCI_IO_DEVICE.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
LIST_ENTRY *CurrentLink;
|
||||||
|
PCI_IO_DEVICE *Temp;
|
||||||
|
|
||||||
|
CurrentLink = RootBridge->ChildList.ForwardLink;
|
||||||
|
|
||||||
|
while (CurrentLink && CurrentLink != &RootBridge->ChildList) {
|
||||||
|
|
||||||
|
Temp = PCI_IO_DEVICE_FROM_LINK (CurrentLink);
|
||||||
|
|
||||||
|
if (IS_PCI_VGA(&Temp->Pci) &&
|
||||||
|
(Temp->Attributes &
|
||||||
|
(EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY |
|
||||||
|
EFI_PCI_IO_ATTRIBUTE_VGA_IO |
|
||||||
|
EFI_PCI_IO_ATTRIBUTE_VGA_IO_16))) {
|
||||||
|
return Temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IS_PCI_BRIDGE (&Temp->Pci)) {
|
||||||
|
|
||||||
|
Temp = ActiveVGADeviceOnTheRootBridge (Temp);
|
||||||
|
|
||||||
|
if (Temp != NULL) {
|
||||||
|
return Temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrentLink = CurrentLink->ForwardLink;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
324
DuetPkg/PciBusNoEnumerationDxe/PciDeviceSupport.h
Normal file
324
DuetPkg/PciBusNoEnumerationDxe/PciDeviceSupport.h
Normal file
@ -0,0 +1,324 @@
|
|||||||
|
/*++
|
||||||
|
|
||||||
|
Copyright (c) 2005 - 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:
|
||||||
|
|
||||||
|
PciDeviceSupport.h
|
||||||
|
|
||||||
|
Abstract:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Revision History
|
||||||
|
|
||||||
|
--*/
|
||||||
|
|
||||||
|
#ifndef _EFI_PCI_DEVICE_SUPPORT_H
|
||||||
|
#define _EFI_PCI_DEVICE_SUPPORT_H
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
InitializePciDevicePool (
|
||||||
|
VOID
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
TODO: Add function description
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
TODO: add return values
|
||||||
|
|
||||||
|
--*/
|
||||||
|
;
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
InsertPciDevice (
|
||||||
|
PCI_IO_DEVICE *Bridge,
|
||||||
|
PCI_IO_DEVICE *PciDeviceNode
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
TODO: Add function description
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Bridge - TODO: add argument description
|
||||||
|
PciDeviceNode - TODO: add argument description
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
TODO: add return values
|
||||||
|
|
||||||
|
--*/
|
||||||
|
;
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
DestroyPciDeviceTree (
|
||||||
|
IN PCI_IO_DEVICE *Bridge
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
TODO: Add function description
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Bridge - TODO: add argument description
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
TODO: add return values
|
||||||
|
|
||||||
|
--*/
|
||||||
|
;
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
DestroyRootBridgeByHandle (
|
||||||
|
EFI_HANDLE Controller
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
TODO: Add function description
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Controller - TODO: add argument description
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
TODO: add return values
|
||||||
|
|
||||||
|
--*/
|
||||||
|
;
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
RegisterPciDevice (
|
||||||
|
IN EFI_HANDLE Controller,
|
||||||
|
IN PCI_IO_DEVICE *PciIoDevice,
|
||||||
|
OUT EFI_HANDLE *Handle OPTIONAL
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
This function registers the PCI IO device. It creates a handle for this PCI IO device
|
||||||
|
(if the handle does not exist), attaches appropriate protocols onto the handle, does
|
||||||
|
necessary initialization, and sets up parent/child relationship with its bus controller.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Controller - An EFI handle for the PCI bus controller.
|
||||||
|
PciIoDevice - A PCI_IO_DEVICE pointer to the PCI IO device to be registered.
|
||||||
|
Handle - A pointer to hold the EFI handle for the PCI IO device.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
EFI_SUCCESS - The PCI device is successfully registered.
|
||||||
|
Others - An error occurred when registering the PCI device.
|
||||||
|
|
||||||
|
--*/
|
||||||
|
;
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
DeRegisterPciDevice (
|
||||||
|
IN EFI_HANDLE Controller,
|
||||||
|
IN EFI_HANDLE Handle
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
TODO: Add function description
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Controller - TODO: add argument description
|
||||||
|
Handle - TODO: add argument description
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
TODO: add return values
|
||||||
|
|
||||||
|
--*/
|
||||||
|
;
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
StartPciDevices (
|
||||||
|
IN EFI_HANDLE Controller,
|
||||||
|
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
TODO: Add function description
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Controller - TODO: add argument description
|
||||||
|
RemainingDevicePath - TODO: add argument description
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
TODO: add return values
|
||||||
|
|
||||||
|
--*/
|
||||||
|
;
|
||||||
|
|
||||||
|
PCI_IO_DEVICE *
|
||||||
|
CreateRootBridge (
|
||||||
|
IN EFI_HANDLE RootBridgeHandle
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
TODO: Add function description
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
RootBridgeHandle - TODO: add argument description
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
TODO: add return values
|
||||||
|
|
||||||
|
--*/
|
||||||
|
;
|
||||||
|
|
||||||
|
PCI_IO_DEVICE *
|
||||||
|
GetRootBridgeByHandle (
|
||||||
|
EFI_HANDLE RootBridgeHandle
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
TODO: Add function description
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
RootBridgeHandle - TODO: add argument description
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
TODO: add return values
|
||||||
|
|
||||||
|
--*/
|
||||||
|
;
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
InsertRootBridge (
|
||||||
|
PCI_IO_DEVICE *RootBridge
|
||||||
|
);
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
DestroyRootBridge (
|
||||||
|
IN PCI_IO_DEVICE *RootBridge
|
||||||
|
);
|
||||||
|
|
||||||
|
BOOLEAN
|
||||||
|
RootBridgeExisted (
|
||||||
|
IN EFI_HANDLE RootBridgeHandle
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
TODO: Add function description
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
RootBridgeHandle - TODO: add argument description
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
TODO: add return values
|
||||||
|
|
||||||
|
--*/
|
||||||
|
;
|
||||||
|
|
||||||
|
BOOLEAN
|
||||||
|
PciDeviceExisted (
|
||||||
|
IN PCI_IO_DEVICE *Bridge,
|
||||||
|
IN PCI_IO_DEVICE *PciIoDevice
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
TODO: Add function description
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Bridge - TODO: add argument description
|
||||||
|
PciIoDevice - TODO: add argument description
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
TODO: add return values
|
||||||
|
|
||||||
|
--*/
|
||||||
|
;
|
||||||
|
|
||||||
|
PCI_IO_DEVICE *
|
||||||
|
ActiveVGADeviceOnTheSameSegment (
|
||||||
|
IN PCI_IO_DEVICE *VgaDevice
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
TODO: Add function description
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
VgaDevice - TODO: add argument description
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
TODO: add return values
|
||||||
|
|
||||||
|
--*/
|
||||||
|
;
|
||||||
|
|
||||||
|
PCI_IO_DEVICE *
|
||||||
|
ActiveVGADeviceOnTheRootBridge (
|
||||||
|
IN PCI_IO_DEVICE *RootBridge
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
TODO: Add function description
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
RootBridge - TODO: add argument description
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
TODO: add return values
|
||||||
|
|
||||||
|
--*/
|
||||||
|
;
|
||||||
|
#endif
|
290
DuetPkg/PciBusNoEnumerationDxe/PciDriverOverride.c
Normal file
290
DuetPkg/PciBusNoEnumerationDxe/PciDriverOverride.c
Normal file
@ -0,0 +1,290 @@
|
|||||||
|
/*++
|
||||||
|
|
||||||
|
Copyright (c) 2005 - 2007, 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:
|
||||||
|
|
||||||
|
PciDriverOverride.c
|
||||||
|
|
||||||
|
Abstract:
|
||||||
|
|
||||||
|
PCI Bus Driver
|
||||||
|
|
||||||
|
Revision History
|
||||||
|
|
||||||
|
--*/
|
||||||
|
|
||||||
|
#include "pcibus.h"
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
GetDriver(
|
||||||
|
IN struct _EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL *This,
|
||||||
|
IN OUT EFI_HANDLE *DriverImageHandle
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
InitializePciDriverOverrideInstance (
|
||||||
|
PCI_IO_DEVICE *PciIoDevice
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Initializes a PCI Driver Override Instance
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
--*/
|
||||||
|
|
||||||
|
{
|
||||||
|
PciIoDevice->PciDriverOverride.GetDriver = GetDriver;
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
GetDriver (
|
||||||
|
IN EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL *This,
|
||||||
|
IN OUT EFI_HANDLE *DriverImageHandle
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Get a overriding driver image
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
PCI_IO_DEVICE *PciIoDevice;
|
||||||
|
LIST_ENTRY *CurrentLink;
|
||||||
|
PCI_DRIVER_OVERRIDE_LIST *Node;
|
||||||
|
|
||||||
|
PciIoDevice = PCI_IO_DEVICE_FROM_PCI_DRIVER_OVERRIDE_THIS (This);
|
||||||
|
|
||||||
|
CurrentLink = PciIoDevice->OptionRomDriverList.ForwardLink;
|
||||||
|
|
||||||
|
while (CurrentLink && CurrentLink != &PciIoDevice->OptionRomDriverList) {
|
||||||
|
|
||||||
|
Node = DRIVER_OVERRIDE_FROM_LINK (CurrentLink);
|
||||||
|
|
||||||
|
if (*DriverImageHandle == NULL) {
|
||||||
|
|
||||||
|
*DriverImageHandle = Node->DriverImageHandle;
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*DriverImageHandle == Node->DriverImageHandle) {
|
||||||
|
|
||||||
|
if (CurrentLink->ForwardLink == &PciIoDevice->OptionRomDriverList ||
|
||||||
|
CurrentLink->ForwardLink == NULL) {
|
||||||
|
return EFI_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Get next node
|
||||||
|
//
|
||||||
|
Node = DRIVER_OVERRIDE_FROM_LINK (CurrentLink->ForwardLink);
|
||||||
|
*DriverImageHandle = Node->DriverImageHandle;
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrentLink = CurrentLink->ForwardLink;
|
||||||
|
}
|
||||||
|
|
||||||
|
return EFI_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
AddDriver (
|
||||||
|
IN PCI_IO_DEVICE *PciIoDevice,
|
||||||
|
IN EFI_HANDLE DriverImageHandle
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Add a overriding driver image
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
--*/
|
||||||
|
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
EFI_IMAGE_DOS_HEADER *DosHdr;
|
||||||
|
EFI_IMAGE_NT_HEADERS *PeHdr;
|
||||||
|
EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
|
||||||
|
PCI_DRIVER_OVERRIDE_LIST *Node;
|
||||||
|
#if (EFI_SPECIFICATION_VERSION < 0x00020000)
|
||||||
|
EFI_DRIVER_OS_HANDOFF_HEADER *DriverOsHandoffHeader;
|
||||||
|
EFI_DRIVER_OS_HANDOFF_HEADER *NewDriverOsHandoffHeader;
|
||||||
|
EFI_DRIVER_OS_HANDOFF *DriverOsHandoff;
|
||||||
|
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
|
||||||
|
EFI_HANDLE DeviceHandle;
|
||||||
|
UINTN NumberOfEntries;
|
||||||
|
UINTN Size;
|
||||||
|
UINTN Index;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
Status = gBS->HandleProtocol (DriverImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &LoadedImage);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
Node = AllocatePool (sizeof (PCI_DRIVER_OVERRIDE_LIST));
|
||||||
|
if (Node == NULL) {
|
||||||
|
return EFI_OUT_OF_RESOURCES;
|
||||||
|
}
|
||||||
|
|
||||||
|
Node->Signature = DRIVER_OVERRIDE_SIGNATURE;
|
||||||
|
Node->DriverImageHandle = DriverImageHandle;
|
||||||
|
|
||||||
|
InsertTailList (&PciIoDevice->OptionRomDriverList, &(Node->Link));
|
||||||
|
|
||||||
|
PciIoDevice->BusOverride = TRUE;
|
||||||
|
|
||||||
|
DosHdr = (EFI_IMAGE_DOS_HEADER *) LoadedImage->ImageBase;
|
||||||
|
if (DosHdr->e_magic != EFI_IMAGE_DOS_SIGNATURE) {
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
PeHdr = (EFI_IMAGE_NT_HEADERS *) ((UINTN) LoadedImage->ImageBase + DosHdr->e_lfanew);
|
||||||
|
|
||||||
|
if (PeHdr->FileHeader.Machine != EFI_IMAGE_MACHINE_EBC) {
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if (EFI_SPECIFICATION_VERSION < 0x00020000)
|
||||||
|
DriverOsHandoffHeader = NULL;
|
||||||
|
Status = EfiLibGetSystemConfigurationTable (&gEfiUgaIoProtocolGuid, (VOID **) &DriverOsHandoffHeader);
|
||||||
|
if (!EFI_ERROR (Status) && DriverOsHandoffHeader != NULL) {
|
||||||
|
for (Index = 0; Index < DriverOsHandoffHeader->NumberOfEntries; Index++) {
|
||||||
|
DriverOsHandoff = (EFI_DRIVER_OS_HANDOFF *)((UINTN)(DriverOsHandoffHeader) +
|
||||||
|
DriverOsHandoffHeader->HeaderSize +
|
||||||
|
Index * DriverOsHandoffHeader->SizeOfEntries);
|
||||||
|
DevicePath = DriverOsHandoff->DevicePath;
|
||||||
|
Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &DevicePath, &DeviceHandle);
|
||||||
|
if (!EFI_ERROR (Status) && DeviceHandle != NULL && IsDevicePathEnd (DevicePath)) {
|
||||||
|
if (DeviceHandle == PciIoDevice->Handle) {
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NumberOfEntries = DriverOsHandoffHeader->NumberOfEntries + 1;
|
||||||
|
} else {
|
||||||
|
NumberOfEntries = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Status = gBS->AllocatePool (
|
||||||
|
EfiRuntimeServicesData,
|
||||||
|
sizeof (EFI_DRIVER_OS_HANDOFF_HEADER) + NumberOfEntries * sizeof (EFI_DRIVER_OS_HANDOFF),
|
||||||
|
(VOID **) &NewDriverOsHandoffHeader
|
||||||
|
);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DriverOsHandoffHeader == NULL) {
|
||||||
|
NewDriverOsHandoffHeader->Version = 0;
|
||||||
|
NewDriverOsHandoffHeader->HeaderSize = sizeof (EFI_DRIVER_OS_HANDOFF_HEADER);
|
||||||
|
NewDriverOsHandoffHeader->SizeOfEntries = sizeof (EFI_DRIVER_OS_HANDOFF);
|
||||||
|
NewDriverOsHandoffHeader->NumberOfEntries = (UINT32) NumberOfEntries;
|
||||||
|
} else {
|
||||||
|
gBS->CopyMem (
|
||||||
|
NewDriverOsHandoffHeader,
|
||||||
|
DriverOsHandoffHeader,
|
||||||
|
DriverOsHandoffHeader->HeaderSize + (NumberOfEntries - 1) * DriverOsHandoffHeader->SizeOfEntries
|
||||||
|
);
|
||||||
|
NewDriverOsHandoffHeader->NumberOfEntries = (UINT32) NumberOfEntries;
|
||||||
|
}
|
||||||
|
|
||||||
|
DriverOsHandoff = (EFI_DRIVER_OS_HANDOFF *)((UINTN)NewDriverOsHandoffHeader +
|
||||||
|
NewDriverOsHandoffHeader->HeaderSize +
|
||||||
|
(NumberOfEntries - 1) * NewDriverOsHandoffHeader->SizeOfEntries);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Fill in the EFI_DRIVER_OS_HANDOFF structure
|
||||||
|
//
|
||||||
|
DriverOsHandoff->Type = EfiUgaDriverFromPciRom;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Compute the size of the device path
|
||||||
|
//
|
||||||
|
Size = EfiDevicePathSize (PciIoDevice->DevicePath);
|
||||||
|
if (Size == 0) {
|
||||||
|
DriverOsHandoff->DevicePath = NULL;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
//
|
||||||
|
// Allocate space for duplicate device path
|
||||||
|
//
|
||||||
|
Status = gBS->AllocatePool (
|
||||||
|
EfiRuntimeServicesData,
|
||||||
|
Size,
|
||||||
|
(VOID **) &DriverOsHandoff->DevicePath
|
||||||
|
);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
gBS->FreePool (NewDriverOsHandoffHeader);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Make copy of device path
|
||||||
|
//
|
||||||
|
CopyMem (DriverOsHandoff->DevicePath, PciIoDevice->DevicePath, Size);
|
||||||
|
}
|
||||||
|
|
||||||
|
DriverOsHandoff->PciRomSize = (UINT64) PciIoDevice->PciIo.RomSize;
|
||||||
|
Status = gBS->AllocatePool (
|
||||||
|
EfiRuntimeServicesData,
|
||||||
|
(UINTN) DriverOsHandoff->PciRomSize,
|
||||||
|
(VOID **) &DriverOsHandoff->PciRomImage
|
||||||
|
);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
gBS->FreePool (NewDriverOsHandoffHeader);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
gBS->CopyMem (
|
||||||
|
DriverOsHandoff->PciRomImage,
|
||||||
|
PciIoDevice->PciIo.RomImage,
|
||||||
|
(UINTN) DriverOsHandoff->PciRomSize
|
||||||
|
);
|
||||||
|
|
||||||
|
Status = gBS->InstallConfigurationTable (&gEfiUgaIoProtocolGuid, NewDriverOsHandoffHeader);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DriverOsHandoffHeader != NULL) {
|
||||||
|
gBS->FreePool (DriverOsHandoffHeader);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
110
DuetPkg/PciBusNoEnumerationDxe/PciDriverOverride.h
Normal file
110
DuetPkg/PciBusNoEnumerationDxe/PciDriverOverride.h
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
/*++
|
||||||
|
|
||||||
|
Copyright (c) 2005 - 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:
|
||||||
|
|
||||||
|
PciDriverOverride.h
|
||||||
|
|
||||||
|
Abstract:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Revision History
|
||||||
|
|
||||||
|
--*/
|
||||||
|
|
||||||
|
#ifndef _EFI_PCI_DRIVER_OVERRRIDE_H
|
||||||
|
#define _EFI_PCI_DRIVER_OVERRRIDE_H
|
||||||
|
|
||||||
|
#include "PciBus.h"
|
||||||
|
|
||||||
|
#define DRIVER_OVERRIDE_SIGNATURE EFI_SIGNATURE_32 ('d', 'r', 'o', 'v')
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
UINT32 Signature;
|
||||||
|
LIST_ENTRY Link;
|
||||||
|
EFI_HANDLE DriverImageHandle;
|
||||||
|
} PCI_DRIVER_OVERRIDE_LIST;
|
||||||
|
|
||||||
|
|
||||||
|
#define DRIVER_OVERRIDE_FROM_LINK(a) \
|
||||||
|
CR (a, PCI_DRIVER_OVERRIDE_LIST, Link, DRIVER_OVERRIDE_SIGNATURE)
|
||||||
|
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
InitializePciDriverOverrideInstance (
|
||||||
|
PCI_IO_DEVICE *PciIoDevice
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
TODO: Add function description
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
PciIoDevice - TODO: add argument description
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
TODO: add return values
|
||||||
|
|
||||||
|
--*/
|
||||||
|
;
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
AddDriver (
|
||||||
|
IN PCI_IO_DEVICE *PciIoDevice,
|
||||||
|
IN EFI_HANDLE DriverImageHandle
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
TODO: Add function description
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
PciIoDevice - TODO: add argument description
|
||||||
|
DriverImageHandle - TODO: add argument description
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
TODO: add return values
|
||||||
|
|
||||||
|
--*/
|
||||||
|
;
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
GetDriver (
|
||||||
|
IN EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL *This,
|
||||||
|
IN OUT EFI_HANDLE *DriverImageHandle
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
TODO: Add function description
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
This - TODO: add argument description
|
||||||
|
DriverImageHandle - TODO: add argument description
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
TODO: add return values
|
||||||
|
|
||||||
|
--*/
|
||||||
|
;
|
||||||
|
|
||||||
|
#endif
|
57
DuetPkg/PciBusNoEnumerationDxe/PciEnumerator.c
Normal file
57
DuetPkg/PciBusNoEnumerationDxe/PciEnumerator.c
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
/*++
|
||||||
|
|
||||||
|
Copyright (c) 2005 - 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:
|
||||||
|
|
||||||
|
PciEnumerator.c
|
||||||
|
|
||||||
|
Abstract:
|
||||||
|
|
||||||
|
PCI Bus Driver
|
||||||
|
|
||||||
|
Revision History
|
||||||
|
|
||||||
|
--*/
|
||||||
|
|
||||||
|
#include "Pcibus.h"
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
PciEnumerator (
|
||||||
|
IN EFI_HANDLE Controller
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
This routine is used to enumerate entire pci bus system
|
||||||
|
in a given platform
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// This PCI bus driver depends on the legacy BIOS
|
||||||
|
// to do the resource allocation
|
||||||
|
//
|
||||||
|
gFullEnumeration = FALSE;
|
||||||
|
|
||||||
|
return PciEnumeratorLight (Controller) ;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
47
DuetPkg/PciBusNoEnumerationDxe/PciEnumerator.h
Normal file
47
DuetPkg/PciBusNoEnumerationDxe/PciEnumerator.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*++
|
||||||
|
|
||||||
|
Copyright (c) 2005 - 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:
|
||||||
|
|
||||||
|
PciEnumerator.h
|
||||||
|
|
||||||
|
Abstract:
|
||||||
|
|
||||||
|
PCI Bus Driver
|
||||||
|
|
||||||
|
Revision History
|
||||||
|
|
||||||
|
--*/
|
||||||
|
|
||||||
|
#ifndef _EFI_PCI_ENUMERATOR_H
|
||||||
|
#define _EFI_PCI_ENUMERATOR_H
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
PciEnumerator (
|
||||||
|
IN EFI_HANDLE Controller
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
TODO: Add function description
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Controller - TODO: add argument description
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
TODO: add return values
|
||||||
|
|
||||||
|
--*/
|
||||||
|
;
|
||||||
|
#endif
|
1384
DuetPkg/PciBusNoEnumerationDxe/PciEnumeratorSupport.c
Normal file
1384
DuetPkg/PciBusNoEnumerationDxe/PciEnumeratorSupport.c
Normal file
File diff suppressed because it is too large
Load Diff
108
DuetPkg/PciBusNoEnumerationDxe/PciEnumeratorSupport.h
Normal file
108
DuetPkg/PciBusNoEnumerationDxe/PciEnumeratorSupport.h
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
/*++
|
||||||
|
|
||||||
|
Copyright (c) 2005 - 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:
|
||||||
|
|
||||||
|
PciEnumeratorSupport.h
|
||||||
|
|
||||||
|
Abstract:
|
||||||
|
|
||||||
|
PCI Bus Driver
|
||||||
|
|
||||||
|
Revision History
|
||||||
|
|
||||||
|
--*/
|
||||||
|
|
||||||
|
#ifndef _EFI_PCI_ENUMERATOR_SUPPORT_H
|
||||||
|
#define _EFI_PCI_ENUMERATOR_SUPPORT_H
|
||||||
|
|
||||||
|
#include "PciBus.h"
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
PciPciDeviceInfoCollector (
|
||||||
|
IN PCI_IO_DEVICE *Bridge,
|
||||||
|
UINT8 StartBusNumber
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
TODO: Add function description
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Bridge - TODO: add argument description
|
||||||
|
StartBusNumber - TODO: add argument description
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
TODO: add return values
|
||||||
|
|
||||||
|
--*/
|
||||||
|
;
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
PciDevicePresent(
|
||||||
|
IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo,
|
||||||
|
PCI_TYPE00 *Pci,
|
||||||
|
UINT8 Bus,
|
||||||
|
UINT8 Device,
|
||||||
|
UINT8 Func
|
||||||
|
);
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
PciEnumeratorLight (
|
||||||
|
IN EFI_HANDLE Controller
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
TODO: Add function description
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Controller - TODO: add argument description
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
TODO: add return values
|
||||||
|
|
||||||
|
--*/
|
||||||
|
;
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
PciGetBusRange (
|
||||||
|
IN EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptors,
|
||||||
|
OUT UINT16 *MinBus,
|
||||||
|
OUT UINT16 *MaxBus,
|
||||||
|
OUT UINT16 *BusRange
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
TODO: Add function description
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Descriptors - TODO: add argument description
|
||||||
|
MinBus - TODO: add argument description
|
||||||
|
MaxBus - TODO: add argument description
|
||||||
|
BusRange - TODO: add argument description
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
TODO: add return values
|
||||||
|
|
||||||
|
--*/
|
||||||
|
;
|
||||||
|
#endif
|
1867
DuetPkg/PciBusNoEnumerationDxe/PciIo.c
Normal file
1867
DuetPkg/PciBusNoEnumerationDxe/PciIo.c
Normal file
File diff suppressed because it is too large
Load Diff
48
DuetPkg/PciBusNoEnumerationDxe/PciIo.h
Normal file
48
DuetPkg/PciBusNoEnumerationDxe/PciIo.h
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
/*++
|
||||||
|
|
||||||
|
Copyright (c) 2005 - 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:
|
||||||
|
|
||||||
|
PciIo.h
|
||||||
|
|
||||||
|
Abstract:
|
||||||
|
|
||||||
|
PCI Bus Driver
|
||||||
|
|
||||||
|
Revision History
|
||||||
|
|
||||||
|
--*/
|
||||||
|
|
||||||
|
#ifndef _EFI_PCI_IO_PROTOCOL_H
|
||||||
|
#define _EFI_PCI_IO_PROTOCOL_H
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
InitializePciIoInstance (
|
||||||
|
PCI_IO_DEVICE *PciIoDevice
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
TODO: Add function description
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
PciIoDevice - TODO: add argument description
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
TODO: add return values
|
||||||
|
|
||||||
|
--*/
|
||||||
|
;
|
||||||
|
|
||||||
|
#endif
|
537
DuetPkg/PciBusNoEnumerationDxe/PciOptionRomSupport.c
Normal file
537
DuetPkg/PciBusNoEnumerationDxe/PciOptionRomSupport.c
Normal file
@ -0,0 +1,537 @@
|
|||||||
|
/*++
|
||||||
|
|
||||||
|
Copyright (c) 2005 - 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:
|
||||||
|
|
||||||
|
PciOptionRomSupport.c
|
||||||
|
|
||||||
|
Abstract:
|
||||||
|
|
||||||
|
PCI Bus Driver
|
||||||
|
|
||||||
|
Revision History
|
||||||
|
|
||||||
|
--*/
|
||||||
|
|
||||||
|
#include "PciBus.h"
|
||||||
|
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
RomDecode (
|
||||||
|
IN PCI_IO_DEVICE *PciDevice,
|
||||||
|
IN UINT8 RomBarIndex,
|
||||||
|
IN UINT32 RomBar,
|
||||||
|
IN BOOLEAN Enable
|
||||||
|
);
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
GetOpRomInfo (
|
||||||
|
IN PCI_IO_DEVICE *PciIoDevice
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
UINT8 RomBarIndex;
|
||||||
|
UINT32 AllOnes;
|
||||||
|
UINT64 Address;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
UINT8 Bus;
|
||||||
|
UINT8 Device;
|
||||||
|
UINT8 Function;
|
||||||
|
EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;
|
||||||
|
|
||||||
|
Bus = PciIoDevice->BusNumber;
|
||||||
|
Device = PciIoDevice->DeviceNumber;
|
||||||
|
Function = PciIoDevice->FunctionNumber;
|
||||||
|
|
||||||
|
PciRootBridgeIo = PciIoDevice->PciRootBridgeIo;
|
||||||
|
|
||||||
|
//
|
||||||
|
// offset is 0x30 if is not ppb
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// 0x30
|
||||||
|
//
|
||||||
|
RomBarIndex = PCI_DEVICE_ROMBAR;
|
||||||
|
|
||||||
|
if (IS_PCI_BRIDGE (&PciIoDevice->Pci)) {
|
||||||
|
//
|
||||||
|
// if is ppb
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// 0x38
|
||||||
|
//
|
||||||
|
RomBarIndex = PCI_BRIDGE_ROMBAR;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// the bit0 is 0 to prevent the enabling of the Rom address decoder
|
||||||
|
//
|
||||||
|
AllOnes = 0xfffffffe;
|
||||||
|
Address = EFI_PCI_ADDRESS (Bus, Device, Function, RomBarIndex);
|
||||||
|
|
||||||
|
Status = PciRootBridgeIo->Pci.Write (
|
||||||
|
PciRootBridgeIo,
|
||||||
|
EfiPciWidthUint32,
|
||||||
|
Address,
|
||||||
|
1,
|
||||||
|
&AllOnes
|
||||||
|
);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// read back
|
||||||
|
//
|
||||||
|
Status = PciRootBridgeIo->Pci.Read (
|
||||||
|
PciRootBridgeIo,
|
||||||
|
EfiPciWidthUint32,
|
||||||
|
Address,
|
||||||
|
1,
|
||||||
|
&AllOnes
|
||||||
|
);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Bits [1, 10] are reserved
|
||||||
|
//
|
||||||
|
AllOnes &= 0xFFFFF800;
|
||||||
|
if ((AllOnes == 0) || (AllOnes == 0xFFFFF800)) {
|
||||||
|
return EFI_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG ((EFI_D_ERROR, "PCIBUS: GetOpRomInfo: OPROM detected!\n"));
|
||||||
|
DEBUG ((EFI_D_ERROR, "PCIBUS: GetOpRomInfo: B-%x, D-%x, F-%x\n", (UINTN)Bus, (UINTN)Device, (UINTN)Function));
|
||||||
|
|
||||||
|
PciIoDevice->RomSize = (UINT64) ((~AllOnes) + 1);
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
LoadOpRomImage (
|
||||||
|
IN PCI_IO_DEVICE *PciDevice,
|
||||||
|
IN UINT64 ReservedMemoryBase
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Load option rom image for specified PCI device
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
UINT8 RomBarIndex;
|
||||||
|
UINT8 Indicator;
|
||||||
|
UINT16 OffsetPcir;
|
||||||
|
UINT32 RomBarOffset;
|
||||||
|
UINT32 RomBar;
|
||||||
|
UINT64 Temp;
|
||||||
|
EFI_STATUS retStatus;
|
||||||
|
BOOLEAN FirstCheck;
|
||||||
|
UINT8 *Image;
|
||||||
|
PCI_EXPANSION_ROM_HEADER *RomHeader;
|
||||||
|
PCI_DATA_STRUCTURE *RomPcir;
|
||||||
|
UINT64 RomSize;
|
||||||
|
UINT64 RomImageSize;
|
||||||
|
UINT8 *RomInMemory;
|
||||||
|
UINT8 CodeType;
|
||||||
|
|
||||||
|
RomSize = PciDevice->RomSize;
|
||||||
|
|
||||||
|
Indicator = 0;
|
||||||
|
RomImageSize = 0;
|
||||||
|
RomInMemory = NULL;
|
||||||
|
Temp = 0;
|
||||||
|
CodeType = 0xFF;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Get the RomBarIndex
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// 0x30
|
||||||
|
//
|
||||||
|
RomBarIndex = PCI_DEVICE_ROMBAR;
|
||||||
|
if (IS_PCI_BRIDGE (&(PciDevice->Pci))) {
|
||||||
|
//
|
||||||
|
// if is ppb
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// 0x38
|
||||||
|
//
|
||||||
|
RomBarIndex = PCI_BRIDGE_ROMBAR;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// Allocate memory for Rom header and PCIR
|
||||||
|
//
|
||||||
|
RomHeader = AllocatePool (sizeof (PCI_EXPANSION_ROM_HEADER));
|
||||||
|
if (RomHeader == NULL) {
|
||||||
|
return EFI_OUT_OF_RESOURCES;
|
||||||
|
}
|
||||||
|
|
||||||
|
RomPcir = AllocatePool (sizeof (PCI_DATA_STRUCTURE));
|
||||||
|
if (RomPcir == NULL) {
|
||||||
|
gBS->FreePool (RomHeader);
|
||||||
|
return EFI_OUT_OF_RESOURCES;
|
||||||
|
}
|
||||||
|
|
||||||
|
RomBar = (UINT32)ReservedMemoryBase;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Enable RomBar
|
||||||
|
//
|
||||||
|
RomDecode (PciDevice, RomBarIndex, RomBar, TRUE);
|
||||||
|
|
||||||
|
RomBarOffset = RomBar;
|
||||||
|
retStatus = EFI_NOT_FOUND;
|
||||||
|
FirstCheck = TRUE;
|
||||||
|
|
||||||
|
do {
|
||||||
|
PciDevice->PciRootBridgeIo->Mem.Read (
|
||||||
|
PciDevice->PciRootBridgeIo,
|
||||||
|
EfiPciWidthUint8,
|
||||||
|
RomBarOffset,
|
||||||
|
sizeof (PCI_EXPANSION_ROM_HEADER),
|
||||||
|
(UINT8 *) RomHeader
|
||||||
|
);
|
||||||
|
|
||||||
|
if (RomHeader->Signature != PCI_EXPANSION_ROM_HEADER_SIGNATURE) {
|
||||||
|
RomBarOffset = RomBarOffset + 512;
|
||||||
|
if (FirstCheck) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
RomImageSize = RomImageSize + 512;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FirstCheck = FALSE;
|
||||||
|
OffsetPcir = RomHeader->PcirOffset;
|
||||||
|
PciDevice->PciRootBridgeIo->Mem.Read (
|
||||||
|
PciDevice->PciRootBridgeIo,
|
||||||
|
EfiPciWidthUint8,
|
||||||
|
RomBarOffset + OffsetPcir,
|
||||||
|
sizeof (PCI_DATA_STRUCTURE),
|
||||||
|
(UINT8 *) RomPcir
|
||||||
|
);
|
||||||
|
if (RomPcir->CodeType == PCI_CODE_TYPE_PCAT_IMAGE) {
|
||||||
|
CodeType = PCI_CODE_TYPE_PCAT_IMAGE;
|
||||||
|
}
|
||||||
|
Indicator = RomPcir->Indicator;
|
||||||
|
RomImageSize = RomImageSize + RomPcir->ImageLength * 512;
|
||||||
|
RomBarOffset = RomBarOffset + RomPcir->ImageLength * 512;
|
||||||
|
} while (((Indicator & 0x80) == 0x00) && ((RomBarOffset - RomBar) < RomSize));
|
||||||
|
|
||||||
|
//
|
||||||
|
// Some Legacy Cards do not report the correct ImageLength so used the maximum
|
||||||
|
// of the legacy length and the PCIR Image Length
|
||||||
|
//
|
||||||
|
if (CodeType == PCI_CODE_TYPE_PCAT_IMAGE) {
|
||||||
|
RomImageSize = MAX(RomImageSize, (((EFI_LEGACY_EXPANSION_ROM_HEADER *)RomHeader)->Size512 * 512));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RomImageSize > 0) {
|
||||||
|
retStatus = EFI_SUCCESS;
|
||||||
|
Image = AllocatePool ((UINT32) RomImageSize);
|
||||||
|
if (Image == NULL) {
|
||||||
|
RomDecode (PciDevice, RomBarIndex, RomBar, FALSE);
|
||||||
|
gBS->FreePool (RomHeader);
|
||||||
|
gBS->FreePool (RomPcir);
|
||||||
|
return EFI_OUT_OF_RESOURCES;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Copy Rom image into memory
|
||||||
|
//
|
||||||
|
PciDevice->PciRootBridgeIo->Mem.Read (
|
||||||
|
PciDevice->PciRootBridgeIo,
|
||||||
|
EfiPciWidthUint8,
|
||||||
|
RomBar,
|
||||||
|
(UINT32) RomImageSize,
|
||||||
|
Image
|
||||||
|
);
|
||||||
|
RomInMemory = Image;
|
||||||
|
}
|
||||||
|
|
||||||
|
RomDecode (PciDevice, RomBarIndex, RomBar, FALSE);
|
||||||
|
|
||||||
|
PciDevice->PciIo.RomSize = RomImageSize;
|
||||||
|
PciDevice->PciIo.RomImage = RomInMemory;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Free allocated memory
|
||||||
|
//
|
||||||
|
gBS->FreePool (RomHeader);
|
||||||
|
gBS->FreePool (RomPcir);
|
||||||
|
|
||||||
|
return retStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
RomDecode (
|
||||||
|
IN PCI_IO_DEVICE *PciDevice,
|
||||||
|
IN UINT8 RomBarIndex,
|
||||||
|
IN UINT32 RomBar,
|
||||||
|
IN BOOLEAN Enable
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
UINT16 CommandValue;
|
||||||
|
UINT32 Value32;
|
||||||
|
UINT64 Address;
|
||||||
|
//EFI_STATUS Status;
|
||||||
|
EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;
|
||||||
|
|
||||||
|
PciRootBridgeIo = PciDevice->PciRootBridgeIo;
|
||||||
|
if (Enable) {
|
||||||
|
Address = EFI_PCI_ADDRESS (PciDevice->BusNumber, PciDevice->DeviceNumber, PciDevice->FunctionNumber, RomBarIndex);
|
||||||
|
//
|
||||||
|
// set the Rom base address: now is hardcode
|
||||||
|
//
|
||||||
|
PciRootBridgeIo->Pci.Write(
|
||||||
|
PciRootBridgeIo,
|
||||||
|
EfiPciWidthUint32,
|
||||||
|
Address,
|
||||||
|
1,
|
||||||
|
&RomBar);
|
||||||
|
|
||||||
|
//
|
||||||
|
// enable its decoder
|
||||||
|
//
|
||||||
|
Value32 = RomBar | 0x1;
|
||||||
|
PciRootBridgeIo->Pci.Write(
|
||||||
|
PciRootBridgeIo,
|
||||||
|
EfiPciWidthUint32,
|
||||||
|
Address,
|
||||||
|
1,
|
||||||
|
&Value32);
|
||||||
|
|
||||||
|
//
|
||||||
|
//setting the memory space bit in the function's command register
|
||||||
|
//
|
||||||
|
Address = EFI_PCI_ADDRESS (PciDevice->BusNumber, PciDevice->DeviceNumber, PciDevice->FunctionNumber, 0x04);
|
||||||
|
PciRootBridgeIo->Pci.Read(
|
||||||
|
PciRootBridgeIo,
|
||||||
|
EfiPciWidthUint16,
|
||||||
|
Address,
|
||||||
|
1,
|
||||||
|
&CommandValue);
|
||||||
|
|
||||||
|
CommandValue = (UINT16)(CommandValue | 0x0002); //0x0003
|
||||||
|
PciRootBridgeIo->Pci.Write(
|
||||||
|
PciRootBridgeIo,
|
||||||
|
EfiPciWidthUint16,
|
||||||
|
Address,
|
||||||
|
1,
|
||||||
|
&CommandValue);
|
||||||
|
} else {
|
||||||
|
//
|
||||||
|
// disable rom decode
|
||||||
|
//
|
||||||
|
Address = EFI_PCI_ADDRESS (PciDevice->BusNumber, PciDevice->DeviceNumber, PciDevice->FunctionNumber, RomBarIndex);
|
||||||
|
Value32 = 0xfffffffe;
|
||||||
|
PciRootBridgeIo->Pci.Write(
|
||||||
|
PciRootBridgeIo,
|
||||||
|
EfiPciWidthUint32,
|
||||||
|
Address,
|
||||||
|
1,
|
||||||
|
&Value32);
|
||||||
|
}
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
ProcessOpRomImage (
|
||||||
|
PCI_IO_DEVICE *PciDevice
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Process the oprom image.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
PciDevice A pointer to a pci device.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
EFI Status.
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
UINT8 Indicator;
|
||||||
|
UINT32 ImageSize;
|
||||||
|
UINT16 ImageOffset;
|
||||||
|
VOID *RomBar;
|
||||||
|
UINT8 *RomBarOffset;
|
||||||
|
EFI_HANDLE ImageHandle;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
EFI_STATUS retStatus;
|
||||||
|
BOOLEAN FirstCheck;
|
||||||
|
BOOLEAN SkipImage;
|
||||||
|
UINT32 DestinationSize;
|
||||||
|
UINT32 ScratchSize;
|
||||||
|
UINT8 *Scratch;
|
||||||
|
VOID *ImageBuffer;
|
||||||
|
VOID *DecompressedImageBuffer;
|
||||||
|
UINT32 ImageLength;
|
||||||
|
EFI_DECOMPRESS_PROTOCOL *Decompress;
|
||||||
|
EFI_PCI_EXPANSION_ROM_HEADER *EfiRomHeader;
|
||||||
|
PCI_DATA_STRUCTURE *Pcir;
|
||||||
|
|
||||||
|
Indicator = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Get the Address of the Rom image
|
||||||
|
//
|
||||||
|
RomBar = PciDevice->PciIo.RomImage;
|
||||||
|
RomBarOffset = (UINT8 *) RomBar;
|
||||||
|
retStatus = EFI_NOT_FOUND;
|
||||||
|
FirstCheck = TRUE;
|
||||||
|
|
||||||
|
do {
|
||||||
|
EfiRomHeader = (EFI_PCI_EXPANSION_ROM_HEADER *) RomBarOffset;
|
||||||
|
if (EfiRomHeader->Signature != PCI_EXPANSION_ROM_HEADER_SIGNATURE) {
|
||||||
|
RomBarOffset = RomBarOffset + 512;
|
||||||
|
if (FirstCheck) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FirstCheck = FALSE;
|
||||||
|
Pcir = (PCI_DATA_STRUCTURE *) (RomBarOffset + EfiRomHeader->PcirOffset);
|
||||||
|
ImageSize = (UINT32) (Pcir->ImageLength * 512);
|
||||||
|
Indicator = Pcir->Indicator;
|
||||||
|
|
||||||
|
if ((Pcir->CodeType == PCI_CODE_TYPE_EFI_IMAGE) &&
|
||||||
|
(EfiRomHeader->EfiSignature == EFI_PCI_EXPANSION_ROM_HEADER_EFISIGNATURE)) {
|
||||||
|
|
||||||
|
if ((EfiRomHeader->EfiSubsystem == EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER) ||
|
||||||
|
(EfiRomHeader->EfiSubsystem == EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER)) {
|
||||||
|
|
||||||
|
ImageOffset = EfiRomHeader->EfiImageHeaderOffset;
|
||||||
|
ImageSize = (UINT32) (EfiRomHeader->InitializationSize * 512);
|
||||||
|
|
||||||
|
ImageBuffer = (VOID *) (RomBarOffset + ImageOffset);
|
||||||
|
ImageLength = ImageSize - (UINT32)ImageOffset;
|
||||||
|
DecompressedImageBuffer = NULL;
|
||||||
|
|
||||||
|
//
|
||||||
|
// decompress here if needed
|
||||||
|
//
|
||||||
|
SkipImage = FALSE;
|
||||||
|
if (EfiRomHeader->CompressionType > EFI_PCI_EXPANSION_ROM_HEADER_COMPRESSED) {
|
||||||
|
SkipImage = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (EfiRomHeader->CompressionType == EFI_PCI_EXPANSION_ROM_HEADER_COMPRESSED) {
|
||||||
|
Status = gBS->LocateProtocol (&gEfiDecompressProtocolGuid, NULL, (VOID **) &Decompress);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
SkipImage = TRUE;
|
||||||
|
} else {
|
||||||
|
SkipImage = TRUE;
|
||||||
|
Status = Decompress->GetInfo (
|
||||||
|
Decompress,
|
||||||
|
ImageBuffer,
|
||||||
|
ImageLength,
|
||||||
|
&DestinationSize,
|
||||||
|
&ScratchSize
|
||||||
|
);
|
||||||
|
if (!EFI_ERROR (Status)) {
|
||||||
|
DecompressedImageBuffer = NULL;
|
||||||
|
DecompressedImageBuffer = AllocatePool (DestinationSize);
|
||||||
|
if (DecompressedImageBuffer != NULL) {
|
||||||
|
Scratch = AllocatePool (ScratchSize);
|
||||||
|
if (Scratch != NULL) {
|
||||||
|
Status = Decompress->Decompress (
|
||||||
|
Decompress,
|
||||||
|
ImageBuffer,
|
||||||
|
ImageLength,
|
||||||
|
DecompressedImageBuffer,
|
||||||
|
DestinationSize,
|
||||||
|
Scratch,
|
||||||
|
ScratchSize
|
||||||
|
);
|
||||||
|
if (!EFI_ERROR (Status)) {
|
||||||
|
ImageBuffer = DecompressedImageBuffer;
|
||||||
|
ImageLength = DestinationSize;
|
||||||
|
SkipImage = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
gBS->FreePool (Scratch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!SkipImage) {
|
||||||
|
//
|
||||||
|
// load image and start image
|
||||||
|
//
|
||||||
|
Status = gBS->LoadImage (
|
||||||
|
FALSE,
|
||||||
|
gPciBusDriverBinding.DriverBindingHandle,
|
||||||
|
NULL,
|
||||||
|
ImageBuffer,
|
||||||
|
ImageLength,
|
||||||
|
&ImageHandle
|
||||||
|
);
|
||||||
|
if (!EFI_ERROR (Status)) {
|
||||||
|
Status = gBS->StartImage (ImageHandle, NULL, NULL);
|
||||||
|
if (!EFI_ERROR (Status)) {
|
||||||
|
AddDriver (PciDevice, ImageHandle);
|
||||||
|
retStatus = EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RomBarOffset = RomBarOffset + ImageSize;
|
||||||
|
} else {
|
||||||
|
RomBarOffset = RomBarOffset + ImageSize;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
RomBarOffset = RomBarOffset + ImageSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
} while (((Indicator & 0x80) == 0x00) && ((UINTN) (RomBarOffset - (UINT8 *) RomBar) < PciDevice->RomSize));
|
||||||
|
|
||||||
|
return retStatus;
|
||||||
|
|
||||||
|
}
|
92
DuetPkg/PciBusNoEnumerationDxe/PciOptionRomSupport.h
Normal file
92
DuetPkg/PciBusNoEnumerationDxe/PciOptionRomSupport.h
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
/*++
|
||||||
|
|
||||||
|
Copyright (c) 2005 - 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:
|
||||||
|
|
||||||
|
PciOptionRomSupport.h
|
||||||
|
|
||||||
|
Abstract:
|
||||||
|
|
||||||
|
PCI Bus Driver
|
||||||
|
|
||||||
|
Revision History
|
||||||
|
|
||||||
|
--*/
|
||||||
|
|
||||||
|
#ifndef _EFI_PCI_OP_ROM_SUPPORT_H
|
||||||
|
#define _EFI_PCI_OP_ROM_SUPPORT_H
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
GetOpRomInfo (
|
||||||
|
IN PCI_IO_DEVICE *PciIoDevice
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
TODO: Add function description
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
PciIoDevice - TODO: add argument description
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
TODO: add return values
|
||||||
|
|
||||||
|
--*/
|
||||||
|
;
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
LoadOpRomImage (
|
||||||
|
IN PCI_IO_DEVICE *PciDevice,
|
||||||
|
IN UINT64 ReservedMemoryBase
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
TODO: Add function description
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
PciDevice - TODO: add argument description
|
||||||
|
RomBase - TODO: add argument description
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
TODO: add return values
|
||||||
|
|
||||||
|
--*/
|
||||||
|
;
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
ProcessOpRomImage (
|
||||||
|
PCI_IO_DEVICE *PciDevice
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
TODO: Add function description
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
PciDevice - TODO: add argument description
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
TODO: add return values
|
||||||
|
|
||||||
|
--*/
|
||||||
|
;
|
||||||
|
|
||||||
|
#endif
|
80
DuetPkg/PciBusNoEnumerationDxe/PciPowerManagement.c
Normal file
80
DuetPkg/PciBusNoEnumerationDxe/PciPowerManagement.c
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
/*++
|
||||||
|
|
||||||
|
Copyright (c) 2005 - 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:
|
||||||
|
|
||||||
|
PciPowerManagement.c
|
||||||
|
|
||||||
|
Abstract:
|
||||||
|
|
||||||
|
PCI Bus Driver
|
||||||
|
|
||||||
|
Revision History
|
||||||
|
|
||||||
|
--*/
|
||||||
|
|
||||||
|
#include "Pcibus.h"
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
ResetPowerManagementFeature (
|
||||||
|
IN PCI_IO_DEVICE *PciIoDevice
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
This function is intended to turn off PWE assertion and
|
||||||
|
put the device to D0 state if the device supports
|
||||||
|
PCI Power Management.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
UINT8 PowerManagementRegBlock;
|
||||||
|
UINT16 PMCSR;
|
||||||
|
|
||||||
|
PowerManagementRegBlock = 0;
|
||||||
|
|
||||||
|
Status = LocateCapabilityRegBlock (
|
||||||
|
PciIoDevice,
|
||||||
|
EFI_PCI_CAPABILITY_ID_PMI,
|
||||||
|
&PowerManagementRegBlock,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
return EFI_UNSUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Turn off the PWE assertion and put the device into D0 State
|
||||||
|
//
|
||||||
|
PMCSR = 0x8000;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Write PMCSR
|
||||||
|
//
|
||||||
|
PciIoDevice->PciIo.Pci.Write (
|
||||||
|
&PciIoDevice->PciIo,
|
||||||
|
EfiPciIoWidthUint16,
|
||||||
|
PowerManagementRegBlock + 4,
|
||||||
|
1,
|
||||||
|
&PMCSR
|
||||||
|
);
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
48
DuetPkg/PciBusNoEnumerationDxe/PciPowerManagement.h
Normal file
48
DuetPkg/PciBusNoEnumerationDxe/PciPowerManagement.h
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
/*++
|
||||||
|
|
||||||
|
Copyright (c) 2005 - 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:
|
||||||
|
|
||||||
|
PciPowerManagement.h
|
||||||
|
|
||||||
|
Abstract:
|
||||||
|
|
||||||
|
PCI Bus Driver
|
||||||
|
|
||||||
|
Revision History
|
||||||
|
|
||||||
|
--*/
|
||||||
|
|
||||||
|
#ifndef _EFI_PCI_POWER_MANAGEMENT_H
|
||||||
|
#define _EFI_PCI_POWER_MANAGEMENT_H
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
ResetPowerManagementFeature (
|
||||||
|
IN PCI_IO_DEVICE *PciIoDevice
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
TODO: Add function description
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
PciIoDevice - TODO: add argument description
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
TODO: add return values
|
||||||
|
|
||||||
|
--*/
|
||||||
|
;
|
||||||
|
|
||||||
|
#endif
|
374
DuetPkg/PciBusNoEnumerationDxe/PciRomTable.c
Normal file
374
DuetPkg/PciBusNoEnumerationDxe/PciRomTable.c
Normal file
@ -0,0 +1,374 @@
|
|||||||
|
/*++
|
||||||
|
|
||||||
|
Copyright (c) 2005 - 2007, 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:
|
||||||
|
|
||||||
|
PciRomTable.c
|
||||||
|
|
||||||
|
Abstract:
|
||||||
|
|
||||||
|
Option Rom Support for PCI Bus Driver
|
||||||
|
|
||||||
|
Revision History
|
||||||
|
|
||||||
|
--*/
|
||||||
|
|
||||||
|
#include "pcibus.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
EFI_HANDLE ImageHandle;
|
||||||
|
UINTN Seg;
|
||||||
|
UINT8 Bus;
|
||||||
|
UINT8 Dev;
|
||||||
|
UINT8 Func;
|
||||||
|
} EFI_PCI_ROM_IMAGE_MAPPING;
|
||||||
|
|
||||||
|
static UINTN mNumberOfPciRomImages = 0;
|
||||||
|
static UINTN mMaxNumberOfPciRomImages = 0;
|
||||||
|
static EFI_PCI_ROM_IMAGE_MAPPING *mRomImageTable = NULL;
|
||||||
|
|
||||||
|
static CHAR16 mHexDigit[17] = L"0123456789ABCDEF";
|
||||||
|
|
||||||
|
static
|
||||||
|
VOID
|
||||||
|
PciRomAddImageMapping (
|
||||||
|
IN EFI_HANDLE ImageHandle,
|
||||||
|
IN UINTN Seg,
|
||||||
|
IN UINT8 Bus,
|
||||||
|
IN UINT8 Dev,
|
||||||
|
IN UINT8 Func
|
||||||
|
)
|
||||||
|
|
||||||
|
{
|
||||||
|
EFI_PCI_ROM_IMAGE_MAPPING *TempMapping;
|
||||||
|
|
||||||
|
if (mNumberOfPciRomImages >= mMaxNumberOfPciRomImages) {
|
||||||
|
|
||||||
|
mMaxNumberOfPciRomImages += 0x20;
|
||||||
|
|
||||||
|
TempMapping = NULL;
|
||||||
|
TempMapping = AllocatePool (mMaxNumberOfPciRomImages * sizeof (EFI_PCI_ROM_IMAGE_MAPPING));
|
||||||
|
if (TempMapping == NULL) {
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
CopyMem (TempMapping, mRomImageTable, mNumberOfPciRomImages * sizeof (EFI_PCI_ROM_IMAGE_MAPPING));
|
||||||
|
|
||||||
|
if (mRomImageTable != NULL) {
|
||||||
|
gBS->FreePool (mRomImageTable);
|
||||||
|
}
|
||||||
|
|
||||||
|
mRomImageTable = TempMapping;
|
||||||
|
}
|
||||||
|
|
||||||
|
mRomImageTable[mNumberOfPciRomImages].ImageHandle = ImageHandle;
|
||||||
|
mRomImageTable[mNumberOfPciRomImages].Seg = Seg;
|
||||||
|
mRomImageTable[mNumberOfPciRomImages].Bus = Bus;
|
||||||
|
mRomImageTable[mNumberOfPciRomImages].Dev = Dev;
|
||||||
|
mRomImageTable[mNumberOfPciRomImages].Func = Func;
|
||||||
|
mNumberOfPciRomImages++;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
VOID
|
||||||
|
HexToString (
|
||||||
|
CHAR16 *String,
|
||||||
|
UINTN Value,
|
||||||
|
UINTN Digits
|
||||||
|
)
|
||||||
|
|
||||||
|
{
|
||||||
|
for (; Digits > 0; Digits--, String++) {
|
||||||
|
*String = mHexDigit[((Value >> (4*(Digits-1))) & 0x0f)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
PciRomLoadEfiDriversFromRomImage (
|
||||||
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||||
|
IN EFI_PCI_OPTION_ROM_DESCRIPTOR *PciOptionRomDescriptor
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
Command entry point.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
ImageHandle The image handle.
|
||||||
|
SystemTable The system table.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
EFI_SUCCESS - The command completed successfully
|
||||||
|
EFI_INVALID_PARAMETER - Command usage error
|
||||||
|
EFI_UNSUPPORTED - Protocols unsupported
|
||||||
|
EFI_OUT_OF_RESOURCES - Out of memory
|
||||||
|
Other value - Unknown error
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
VOID *RomBar;
|
||||||
|
UINTN RomSize;
|
||||||
|
CHAR16 *FileName;
|
||||||
|
EFI_PCI_EXPANSION_ROM_HEADER *EfiRomHeader;
|
||||||
|
PCI_DATA_STRUCTURE *Pcir;
|
||||||
|
UINTN ImageIndex;
|
||||||
|
UINTN RomBarOffset;
|
||||||
|
UINT32 ImageSize;
|
||||||
|
UINT16 ImageOffset;
|
||||||
|
EFI_HANDLE ImageHandle;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
EFI_STATUS retStatus;
|
||||||
|
EFI_DEVICE_PATH_PROTOCOL *FilePath;
|
||||||
|
BOOLEAN SkipImage;
|
||||||
|
UINT32 DestinationSize;
|
||||||
|
UINT32 ScratchSize;
|
||||||
|
UINT8 *Scratch;
|
||||||
|
VOID *ImageBuffer;
|
||||||
|
VOID *DecompressedImageBuffer;
|
||||||
|
UINT32 ImageLength;
|
||||||
|
EFI_DECOMPRESS_PROTOCOL *Decompress;
|
||||||
|
|
||||||
|
RomBar = (VOID *) (UINTN) PciOptionRomDescriptor->RomAddress;
|
||||||
|
RomSize = (UINTN) PciOptionRomDescriptor->RomLength;
|
||||||
|
FileName = L"PciRom Seg=00000000 Bus=00 Dev=00 Func=00 Image=0000";
|
||||||
|
|
||||||
|
HexToString (&FileName[11], PciOptionRomDescriptor->Seg, 8);
|
||||||
|
HexToString (&FileName[24], PciOptionRomDescriptor->Bus, 2);
|
||||||
|
HexToString (&FileName[31], PciOptionRomDescriptor->Dev, 2);
|
||||||
|
HexToString (&FileName[39], PciOptionRomDescriptor->Func, 2);
|
||||||
|
|
||||||
|
ImageIndex = 0;
|
||||||
|
retStatus = EFI_NOT_FOUND;
|
||||||
|
RomBarOffset = (UINTN) RomBar;
|
||||||
|
|
||||||
|
do {
|
||||||
|
|
||||||
|
EfiRomHeader = (EFI_PCI_EXPANSION_ROM_HEADER *) (UINTN) RomBarOffset;
|
||||||
|
|
||||||
|
if (EfiRomHeader->Signature != 0xaa55) {
|
||||||
|
return retStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pcir = (PCI_DATA_STRUCTURE *) (UINTN) (RomBarOffset + EfiRomHeader->PcirOffset);
|
||||||
|
ImageSize = Pcir->ImageLength * 512;
|
||||||
|
|
||||||
|
if ((Pcir->CodeType == PCI_CODE_TYPE_EFI_IMAGE) &&
|
||||||
|
(EfiRomHeader->EfiSignature == EFI_PCI_EXPANSION_ROM_HEADER_EFISIGNATURE) ) {
|
||||||
|
|
||||||
|
if ((EfiRomHeader->EfiSubsystem == EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER) ||
|
||||||
|
(EfiRomHeader->EfiSubsystem == EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER) ) {
|
||||||
|
|
||||||
|
ImageOffset = EfiRomHeader->EfiImageHeaderOffset;
|
||||||
|
ImageSize = EfiRomHeader->InitializationSize * 512;
|
||||||
|
|
||||||
|
ImageBuffer = (VOID *) (UINTN) (RomBarOffset + ImageOffset);
|
||||||
|
ImageLength = ImageSize - ImageOffset;
|
||||||
|
DecompressedImageBuffer = NULL;
|
||||||
|
|
||||||
|
//
|
||||||
|
// decompress here if needed
|
||||||
|
//
|
||||||
|
SkipImage = FALSE;
|
||||||
|
if (EfiRomHeader->CompressionType > EFI_PCI_EXPANSION_ROM_HEADER_COMPRESSED) {
|
||||||
|
SkipImage = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (EfiRomHeader->CompressionType == EFI_PCI_EXPANSION_ROM_HEADER_COMPRESSED) {
|
||||||
|
Status = gBS->LocateProtocol (&gEfiDecompressProtocolGuid, NULL, (VOID **) &Decompress);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
SkipImage = TRUE;
|
||||||
|
} else {
|
||||||
|
SkipImage = TRUE;
|
||||||
|
Status = Decompress->GetInfo (
|
||||||
|
Decompress,
|
||||||
|
ImageBuffer,
|
||||||
|
ImageLength,
|
||||||
|
&DestinationSize,
|
||||||
|
&ScratchSize
|
||||||
|
);
|
||||||
|
if (!EFI_ERROR (Status)) {
|
||||||
|
DecompressedImageBuffer = NULL;
|
||||||
|
DecompressedImageBuffer = AllocatePool (DestinationSize);
|
||||||
|
if (DecompressedImageBuffer != NULL) {
|
||||||
|
Scratch = AllocatePool (ScratchSize);
|
||||||
|
if (Scratch != NULL) {
|
||||||
|
Status = Decompress->Decompress (
|
||||||
|
Decompress,
|
||||||
|
ImageBuffer,
|
||||||
|
ImageLength,
|
||||||
|
DecompressedImageBuffer,
|
||||||
|
DestinationSize,
|
||||||
|
Scratch,
|
||||||
|
ScratchSize
|
||||||
|
);
|
||||||
|
if (!EFI_ERROR (Status)) {
|
||||||
|
ImageBuffer = DecompressedImageBuffer;
|
||||||
|
ImageLength = DestinationSize;
|
||||||
|
SkipImage = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
gBS->FreePool (Scratch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!SkipImage) {
|
||||||
|
|
||||||
|
//
|
||||||
|
// load image and start image
|
||||||
|
//
|
||||||
|
|
||||||
|
HexToString (&FileName[48], ImageIndex, 4);
|
||||||
|
FilePath = FileDevicePath (NULL, FileName);
|
||||||
|
|
||||||
|
Status = gBS->LoadImage (
|
||||||
|
FALSE,
|
||||||
|
This->ImageHandle,
|
||||||
|
FilePath,
|
||||||
|
ImageBuffer,
|
||||||
|
ImageLength,
|
||||||
|
&ImageHandle
|
||||||
|
);
|
||||||
|
if (!EFI_ERROR (Status)) {
|
||||||
|
Status = gBS->StartImage (ImageHandle, NULL, NULL);
|
||||||
|
if (!EFI_ERROR (Status)) {
|
||||||
|
PciRomAddImageMapping (
|
||||||
|
ImageHandle,
|
||||||
|
PciOptionRomDescriptor->Seg,
|
||||||
|
PciOptionRomDescriptor->Bus,
|
||||||
|
PciOptionRomDescriptor->Dev,
|
||||||
|
PciOptionRomDescriptor->Func
|
||||||
|
);
|
||||||
|
retStatus = Status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (FilePath != NULL) {
|
||||||
|
gBS->FreePool (FilePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DecompressedImageBuffer != NULL) {
|
||||||
|
gBS->FreePool (DecompressedImageBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RomBarOffset = RomBarOffset + ImageSize;
|
||||||
|
ImageIndex++;
|
||||||
|
} while (((Pcir->Indicator & 0x80) == 0x00) && ((RomBarOffset - (UINTN) RomBar) < RomSize));
|
||||||
|
|
||||||
|
return retStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
PciRomLoadEfiDriversFromOptionRomTable (
|
||||||
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||||
|
IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
EFI_PCI_OPTION_ROM_TABLE *PciOptionRomTable;
|
||||||
|
EFI_PCI_OPTION_ROM_DESCRIPTOR *PciOptionRomDescriptor;
|
||||||
|
UINTN Index;
|
||||||
|
EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptors;
|
||||||
|
UINT16 MinBus;
|
||||||
|
UINT16 MaxBus;
|
||||||
|
|
||||||
|
Status = EfiGetSystemConfigurationTable (&gEfiPciOptionRomTableGuid, (VOID **) &PciOptionRomTable);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
return EFI_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
Status = EFI_NOT_FOUND;
|
||||||
|
|
||||||
|
for (Index = 0; Index < PciOptionRomTable->PciOptionRomCount; Index++) {
|
||||||
|
PciOptionRomDescriptor = &PciOptionRomTable->PciOptionRomDescriptors[Index];
|
||||||
|
if (!PciOptionRomDescriptor->DontLoadEfiRom) {
|
||||||
|
if (PciOptionRomDescriptor->Seg == PciRootBridgeIo->SegmentNumber) {
|
||||||
|
Status = PciRootBridgeIo->Configuration (PciRootBridgeIo, (VOID **) &Descriptors);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
PciGetBusRange (Descriptors, &MinBus, &MaxBus, NULL);
|
||||||
|
if ((MinBus <= PciOptionRomDescriptor->Bus) && (PciOptionRomDescriptor->Bus <= MaxBus)) {
|
||||||
|
Status = PciRomLoadEfiDriversFromRomImage (This, PciOptionRomDescriptor);
|
||||||
|
PciOptionRomDescriptor->DontLoadEfiRom |= 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
PciRomGetRomResourceFromPciOptionRomTable (
|
||||||
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||||
|
IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo,
|
||||||
|
PCI_IO_DEVICE *PciIoDevice
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
EFI_PCI_OPTION_ROM_TABLE *PciOptionRomTable;
|
||||||
|
EFI_PCI_OPTION_ROM_DESCRIPTOR *PciOptionRomDescriptor;
|
||||||
|
UINTN Index;
|
||||||
|
|
||||||
|
Status = EfiGetSystemConfigurationTable (&gEfiPciOptionRomTableGuid, (VOID **) &PciOptionRomTable);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
return EFI_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Index = 0; Index < PciOptionRomTable->PciOptionRomCount; Index++) {
|
||||||
|
PciOptionRomDescriptor = &PciOptionRomTable->PciOptionRomDescriptors[Index];
|
||||||
|
if (PciOptionRomDescriptor->Seg == PciRootBridgeIo->SegmentNumber &&
|
||||||
|
PciOptionRomDescriptor->Bus == PciIoDevice->BusNumber &&
|
||||||
|
PciOptionRomDescriptor->Dev == PciIoDevice->DeviceNumber &&
|
||||||
|
PciOptionRomDescriptor->Func == PciIoDevice->FunctionNumber ) {
|
||||||
|
|
||||||
|
PciIoDevice->PciIo.RomImage = (VOID *) (UINTN) PciOptionRomDescriptor->RomAddress;
|
||||||
|
PciIoDevice->PciIo.RomSize = (UINTN) PciOptionRomDescriptor->RomLength;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Index = 0; Index < mNumberOfPciRomImages; Index++) {
|
||||||
|
if (mRomImageTable[Index].Seg == PciRootBridgeIo->SegmentNumber &&
|
||||||
|
mRomImageTable[Index].Bus == PciIoDevice->BusNumber &&
|
||||||
|
mRomImageTable[Index].Dev == PciIoDevice->DeviceNumber &&
|
||||||
|
mRomImageTable[Index].Func == PciIoDevice->FunctionNumber ) {
|
||||||
|
|
||||||
|
AddDriver (PciIoDevice, mRomImageTable[Index].ImageHandle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
58
DuetPkg/PciBusNoEnumerationDxe/PciRomTable.h
Normal file
58
DuetPkg/PciBusNoEnumerationDxe/PciRomTable.h
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/*++
|
||||||
|
|
||||||
|
Copyright (c) 2005 - 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:
|
||||||
|
|
||||||
|
PciRomTable.h
|
||||||
|
|
||||||
|
Abstract:
|
||||||
|
|
||||||
|
Option Rom Support for PCI Bus Driver
|
||||||
|
|
||||||
|
Revision History
|
||||||
|
|
||||||
|
--*/
|
||||||
|
|
||||||
|
#ifndef _EFI_PCI_ROM_TABLE_H
|
||||||
|
#define _EFI_PCI_ROM_TABLE_H
|
||||||
|
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
PciRomLoadEfiDriversFromOptionRomTable (
|
||||||
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||||
|
IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo
|
||||||
|
);
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
PciRomGetRomResourceFromPciOptionRomTable (
|
||||||
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||||
|
IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo,
|
||||||
|
PCI_IO_DEVICE *PciIoDevice
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
TODO: Add function description
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
This - TODO: add argument description
|
||||||
|
PciRootBridgeIo - TODO: add argument description
|
||||||
|
PciIoDevice - TODO: add argument description
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
TODO: add return values
|
||||||
|
|
||||||
|
--*/
|
||||||
|
;
|
||||||
|
#endif
|
Loading…
x
Reference in New Issue
Block a user