iPXE
Functions
pciea.c File Reference

PCI Enhanced Allocation. More...

#include <stdint.h>
#include <errno.h>
#include <ipxe/pci.h>
#include <ipxe/pciea.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static int pciea_offset (struct pci_device *pci, unsigned int bei)
 Locate PCI Enhanced Allocation BAR equivalent entry.
static unsigned long pciea_bar_value (struct pci_device *pci, unsigned int bei, unsigned int low_offset)
 Read PCI Enhanced Allocation BAR equivalent value.
unsigned long pciea_bar_start (struct pci_device *pci, unsigned int bei)
 Find the start of a PCI Enhanced Allocation BAR equivalent.
unsigned long pciea_bar_size (struct pci_device *pci, unsigned int bei)
 Find the size of a PCI Enhanced Allocation BAR equivalent.

Detailed Description

PCI Enhanced Allocation.

Definition in file pciea.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static int pciea_offset ( struct pci_device pci,
unsigned int  bei 
) [static]

Locate PCI Enhanced Allocation BAR equivalent entry.

Parameters:
pciPCI device
beiBAR equivalent indicator
Return values:
offsetPCI Enhanced Allocation entry offset, or negative error

Definition at line 44 of file pciea.c.

References ENOENT, offset, PCI_CAP_ID_EA, pci_find_capability(), pci_read_config_byte(), pci_read_config_dword(), PCIEA_DESC_BEI, PCIEA_DESC_ENABLED, PCIEA_DESC_SIZE, PCIEA_ENTRIES, PCIEA_ENTRIES_MASK, and PCIEA_FIRST.

Referenced by pciea_bar_value().

                                                                     {
        uint8_t entries;
        uint32_t desc;
        unsigned int i;
        int offset;

        /* Locate Enhanced Allocation capability */
        offset = pci_find_capability ( pci, PCI_CAP_ID_EA );
        if ( offset < 0 )
                return offset;

        /* Get number of entries */
        pci_read_config_byte ( pci, ( offset + PCIEA_ENTRIES ), &entries );
        entries &= PCIEA_ENTRIES_MASK;

        /* Locate first entry */
        offset += PCIEA_FIRST;

        /* Search for a matching entry */
        for ( i = 0 ; i < entries ; i++ ) {

                /* Read entry descriptor */
                pci_read_config_dword ( pci, offset, &desc );

                /* Check for a matching entry */
                if ( ( desc & PCIEA_DESC_ENABLED ) &&
                     ( bei == PCIEA_DESC_BEI ( desc ) ) )
                        return offset;

                /* Move to next entry */
                offset += ( ( PCIEA_DESC_SIZE ( desc ) + 1 ) << 2 );
        }

        return -ENOENT;
}
static unsigned long pciea_bar_value ( struct pci_device pci,
unsigned int  bei,
unsigned int  low_offset 
) [static]

Read PCI Enhanced Allocation BAR equivalent value.

Parameters:
pciPCI device
beiBAR equivalent indicator
low_offsetOffset to low dword of value
Return values:
valueBAR equivalent value

Definition at line 88 of file pciea.c.

References DBGC, high, low, offset, PCI_ARGS, PCI_FMT, pci_read_config_dword(), PCIEA_LOW_ATTR_64BIT, PCIEA_LOW_HIGH, and pciea_offset().

Referenced by pciea_bar_size(), and pciea_bar_start().

                                                                 {
        uint32_t low;
        uint32_t high;
        int offset;

        /* Locate Enhanced Allocation offset for this BEI */
        offset = pciea_offset ( pci, bei );
        if ( offset < 0 )
                return 0;

        /* Read BAR equivalent */
        offset += low_offset;
        pci_read_config_dword ( pci, offset, &low );
        if ( low & PCIEA_LOW_ATTR_64BIT ) {
                offset += PCIEA_LOW_HIGH;
                pci_read_config_dword ( pci, offset, &high );
                if ( high ) {
                        if ( sizeof ( unsigned long ) > sizeof ( uint32_t ) ) {
                                return ( ( ( uint64_t ) high << 32 ) | low );
                        } else {
                                DBGC ( pci, PCI_FMT " unhandled 64-bit EA BAR "
                                       "%08x%08x\n",
                                       PCI_ARGS ( pci ), high, low );
                                return 0;
                        }
                }
        }
        return low;
}
unsigned long pciea_bar_start ( struct pci_device pci,
unsigned int  bei 
)

Find the start of a PCI Enhanced Allocation BAR equivalent.

Parameters:
pciPCI device
beiBAR equivalent indicator
Return values:
startBAR start address

If the address exceeds the size of an unsigned long (i.e. if a 64-bit BAR has a non-zero high dword on a 32-bit machine), the return value will be zero.

Definition at line 130 of file pciea.c.

References base, pciea_bar_value(), PCIEA_LOW_ATTR_MASK, and PCIEA_LOW_BASE.

Referenced by txnic_bgx_probe(), and txnic_pf_probe().

                                                                           {
        unsigned long base;

        base = pciea_bar_value ( pci, bei, PCIEA_LOW_BASE );
        return ( base & ~PCIEA_LOW_ATTR_MASK );
}
unsigned long pciea_bar_size ( struct pci_device pci,
unsigned int  bei 
)

Find the size of a PCI Enhanced Allocation BAR equivalent.

Parameters:
pciPCI device
beiBAR equivalent indicator
Return values:
sizeBAR size

Definition at line 144 of file pciea.c.

References limit, pciea_bar_value(), PCIEA_LOW_ATTR_MASK, and PCIEA_LOW_LIMIT.

Referenced by txnic_pf_probe().

                                                                          {
        unsigned long limit;

        limit = pciea_bar_value ( pci, bei, PCIEA_LOW_LIMIT );
        return ( limit ? ( ( limit | PCIEA_LOW_ATTR_MASK ) + 1 ) : 0 );
}