FreeBSD/sys/contrib/dev/acpica/components/hardware/hwpci.c
/*******************************************************************************
 *
 * FUNCTION:    AcpiHwGetPciDeviceInfo
 *
 * PARAMETERS:  PciId               - Initial values for the PCI ID. May be
 *                                    modified by this function.
 *              PciDevice           - Handle for the PCI device object
 *              BusNumber           - Where a PCI bridge bus number is returned
 *              IsBridge            - Return value, indicates if this PCI
 *                                    device is a PCI bridge
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Get the device info for a single PCI device object. Get the
 *              _ADR (contains PCI device and function numbers), and for PCI
 *              bridge devices, get the bus number from PCI configuration
 *              space.
 *
 ******************************************************************************/
AcpiHwGetPciDeviceInfo
PARAMETERS:  PciId               - Initial values for the PCI ID. May be
modified by this function.
PciDevice           - Handle for the PCI device object
BusNumber           - Where a PCI bridge bus number is returned
IsBridge            - Return value, indicates if this PCI
device is a PCI bridge

Status

Get the device info for a single PCI device object. Get the
_ADR (contains PCI device and function numbers), and for PCI
bridge devices, get the bus number from PCI configuration
space.
AcpiHwGetPciDeviceInfo PARAMETERS : PciId - Initial values for the PCI ID . May be modified by this function . PciDevice - Handle for the PCI device object BusNumber - Where a PCI bridge bus number is returned IsBridge - Return value indicates if this PCI device is a PCI bridge Status Get the device info for a single PCI device object . Get the _ADR ( contains PCI device and function numbers ) and for PCI bridge devices get the bus number from PCI configuration space .
static ACPI_STATUS
AcpiHwGetPciDeviceInfo (
    ACPI_PCI_ID             *PciId,
    ACPI_HANDLE             PciDevice,
    UINT16                  *BusNumber,
    BOOLEAN                 *IsBridge)
{
    ACPI_STATUS             Status;
    ACPI_OBJECT_TYPE        ObjectType;
    UINT64                  ReturnValue;
    UINT64                  PciValue;
    Status = AcpiGetType (PciDevice, &ObjectType);
    if (ACPI_FAILURE (Status))
    {
        return (Status);
    }
    if (ObjectType != ACPI_TYPE_DEVICE)
    {
        return (AE_OK);
    }
    Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR,
        PciDevice, &ReturnValue);
    if (ACPI_FAILURE (Status))
    {
        return (AE_OK);
    }
    PciId->Device = ACPI_HIWORD (ACPI_LODWORD (ReturnValue));
    PciId->Function = ACPI_LOWORD (ACPI_LODWORD (ReturnValue));
    if (*IsBridge)
    {
        PciId->Bus = *BusNumber;
    }
    *IsBridge = FALSE;
    Status = AcpiOsReadPciConfiguration (PciId,
        PCI_CFG_HEADER_TYPE_REG, &PciValue, 8);
    if (ACPI_FAILURE (Status))
    {
        return (Status);
    }
    PciValue &= PCI_HEADER_TYPE_MASK;
    if ((PciValue != PCI_TYPE_BRIDGE) &&
        (PciValue != PCI_TYPE_CARDBUS_BRIDGE))
    {
        return (AE_OK);
    }
    Status = AcpiOsReadPciConfiguration (PciId,
        PCI_CFG_PRIMARY_BUS_NUMBER_REG, &PciValue, 8);
    if (ACPI_FAILURE (Status))
    {
        return (Status);
    }
    *IsBridge = TRUE;
    PciId->Bus = (UINT16) PciValue;
    Status = AcpiOsReadPciConfiguration (PciId,
        PCI_CFG_SECONDARY_BUS_NUMBER_REG, &PciValue, 8);
    if (ACPI_FAILURE (Status))
    {
        return (Status);
    }
    *BusNumber = (UINT16) PciValue;
    return (AE_OK);
}
static ACPI_STATUS AcpiHwGetPciDeviceInfo ( ACPI_PCI_ID * PciId , ACPI_HANDLE PciDevice , UINT16 * BusNumber , BOOLEAN * IsBridge ) { ACPI_STATUS Status ; ACPI_OBJECT_TYPE ObjectType ; UINT64 ReturnValue ; UINT64 PciValue ; Status = AcpiGetType ( PciDevice , & ObjectType ) ; if ( ACPI_FAILURE ( Status ) ) { return ( Status ) ; } if ( ObjectType != ACPI_TYPE_DEVICE ) { return ( AE_OK ) ; } Status = AcpiUtEvaluateNumericObject ( METHOD_NAME__ADR , PciDevice , & ReturnValue ) ; if ( ACPI_FAILURE ( Status ) ) { return ( AE_OK ) ; } PciId -> Device = ACPI_HIWORD ( ACPI_LODWORD ( ReturnValue ) ) ; PciId -> Function = ACPI_LOWORD ( ACPI_LODWORD ( ReturnValue ) ) ; if ( * IsBridge ) { PciId -> Bus = * BusNumber ; } * IsBridge = FALSE ; Status = AcpiOsReadPciConfiguration ( PciId , PCI_CFG_HEADER_TYPE_REG , & PciValue , 8 ) ; if ( ACPI_FAILURE ( Status ) ) { return ( Status ) ; } PciValue &= PCI_HEADER_TYPE_MASK ; if ( ( PciValue != PCI_TYPE_BRIDGE ) && ( PciValue != PCI_TYPE_CARDBUS_BRIDGE ) ) { return ( AE_OK ) ; } Status = AcpiOsReadPciConfiguration ( PciId , PCI_CFG_PRIMARY_BUS_NUMBER_REG , & PciValue , 8 ) ; if ( ACPI_FAILURE ( Status ) ) { return ( Status ) ; } * IsBridge = TRUE ; PciId -> Bus = ( UINT16 ) PciValue ; Status = AcpiOsReadPciConfiguration ( PciId , PCI_CFG_SECONDARY_BUS_NUMBER_REG , & PciValue , 8 ) ; if ( ACPI_FAILURE ( Status ) ) { return ( Status ) ; } * BusNumber = ( UINT16 ) PciValue ; return ( AE_OK ) ; }
FUNCTION:    AcpiHwGetPciDeviceInfo
 PARAMETERS:  PciId               - Initial values for the PCI ID.
FUNCTION : AcpiHwGetPciDeviceInfo PARAMETERS : PciId - Initial values for the PCI ID .
/* We only care about objects of type Device */ /* We need an _ADR. Ignore device if not present */ /*
     * From _ADR, get the PCI Device and Function and
     * update the PCI ID.
     */ /*
     * If the previous device was a bridge, use the previous
     * device bus number
     */ /*
     * Get the bus numbers from PCI Config space:
     *
     * First, get the PCI HeaderType
     */ /* We only care about bridges (1=PciBridge, 2=CardBusBridge) */ /* Bridge: Get the Primary BusNumber */ /* Bridge: Get the Secondary BusNumber */