iPXE
Functions
pciextra.c File Reference
#include <stdint.h>
#include <ipxe/pci.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static int pci_find_capability_common (struct pci_device *pci, uint8_t pos, int cap)
int pci_find_capability (struct pci_device *pci, int cap)
 Look for a PCI capability.
int pci_find_next_capability (struct pci_device *pci, int pos, int cap)
 Look for another PCI capability.
unsigned long pci_bar_size (struct pci_device *pci, unsigned int reg)
 Find the size of a PCI BAR.

Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static int pci_find_capability_common ( struct pci_device pci,
uint8_t  pos,
int  cap 
) [static]

Definition at line 6 of file pciextra.c.

References DBG, id, PCI_CAP_ID, PCI_CAP_NEXT, and pci_read_config_byte().

Referenced by pci_find_capability(), and pci_find_next_capability().

                                                               {
        uint8_t id;
        int ttl = 48;

        while ( ttl-- && pos >= 0x40 ) {
                pos &= ~3;
                pci_read_config_byte ( pci, pos + PCI_CAP_ID, &id );
                DBG ( "PCI Capability: %d\n", id );
                if ( id == 0xff )
                        break;
                if ( id == cap )
                        return pos;
                pci_read_config_byte ( pci, pos + PCI_CAP_NEXT, &pos );
        }
        return 0;
}
int pci_find_capability ( struct pci_device pci,
int  cap 
)

Look for a PCI capability.

Parameters:
pciPCI device to query
capCapability code
Return values:
addressAddress of capability, or 0 if not found

Determine whether or not a device supports a given PCI capability. Returns the address of the requested capability structure within the device's PCI configuration space, or 0 if the device does not support it.

Definition at line 36 of file pciextra.c.

References PCI_CAPABILITY_LIST, PCI_CB_CAPABILITY_LIST, pci_find_capability_common(), PCI_HEADER_TYPE, PCI_HEADER_TYPE_BRIDGE, PCI_HEADER_TYPE_CARDBUS, PCI_HEADER_TYPE_MASK, PCI_HEADER_TYPE_NORMAL, pci_read_config_byte(), pci_read_config_word(), PCI_STATUS, PCI_STATUS_CAP_LIST, and status.

Referenced by ath5k_hw_attach(), ath5k_hw_nic_wakeup(), bnx2_init_board(), myri10ge_pci_probe(), pci_vpd_init(), pciea_offset(), sky2_reset(), sky2_rx_start(), tg3_get_invariants(), and virtio_pci_find_capability().

                                                            {
        uint16_t status;
        uint8_t pos;
        uint8_t hdr_type;

        pci_read_config_word ( pci, PCI_STATUS, &status );
        if ( ! ( status & PCI_STATUS_CAP_LIST ) )
                return 0;

        pci_read_config_byte ( pci, PCI_HEADER_TYPE, &hdr_type );
        switch ( hdr_type & PCI_HEADER_TYPE_MASK ) {
        case PCI_HEADER_TYPE_NORMAL:
        case PCI_HEADER_TYPE_BRIDGE:
        default:
                pci_read_config_byte ( pci, PCI_CAPABILITY_LIST, &pos );
                break;
        case PCI_HEADER_TYPE_CARDBUS:
                pci_read_config_byte ( pci, PCI_CB_CAPABILITY_LIST, &pos );
                break;
        }
        return pci_find_capability_common ( pci, pos, cap );
}
int pci_find_next_capability ( struct pci_device pci,
int  pos,
int  cap 
)

Look for another PCI capability.

Parameters:
pciPCI device to query
posAddress of the current capability
capCapability code
Return values:
addressAddress of capability, or 0 if not found

Determine whether or not a device supports a given PCI capability starting the search at a given address within the device's PCI configuration space. Returns the address of the next capability structure within the device's PCI configuration space, or 0 if the device does not support another such capability.

Definition at line 73 of file pciextra.c.

References PCI_CAP_NEXT, pci_find_capability_common(), and pci_read_config_byte().

Referenced by virtio_pci_find_capability().

                                                                          {
        uint8_t new_pos;

        pci_read_config_byte ( pci, pos + PCI_CAP_NEXT, &new_pos );
        return pci_find_capability_common ( pci, new_pos, cap );
}
unsigned long pci_bar_size ( struct pci_device pci,
unsigned int  reg 
)

Find the size of a PCI BAR.

Parameters:
pciPCI device
regPCI register number
Return values:
sizeBAR size

It should not be necessary for any Etherboot code to call this function.

Definition at line 90 of file pciextra.c.

References cmd, PCI_BASE_ADDRESS_IO_MASK, PCI_BASE_ADDRESS_MEM_MASK, PCI_BASE_ADDRESS_SPACE_IO, PCI_COMMAND, pci_read_config_dword(), pci_read_config_word(), pci_write_config_dword(), pci_write_config_word(), size, and start.

Referenced by __vxge_hw_device_get_legacy_reg(), amd8111e_probe(), efab_probe(), efx_probe(), ehci_probe(), exanic_probe(), forcedeth_map_regs(), hvm_probe(), igbvf_probe(), phantom_map_crb(), tg3_init_one(), virtio_pci_map_capability(), vxge_probe(), and xhci_probe().

                                                                        {
        uint16_t cmd;
        uint32_t start, size;

        /* Save the original command register */
        pci_read_config_word ( pci, PCI_COMMAND, &cmd );
        /* Save the original bar */
        pci_read_config_dword ( pci, reg, &start );
        /* Compute which bits can be set */
        pci_write_config_dword ( pci, reg, ~0 );
        pci_read_config_dword ( pci, reg, &size );
        /* Restore the original size */
        pci_write_config_dword ( pci, reg, start );
        /* Find the significant bits */
        /* Restore the original command register. This reenables decoding. */
        pci_write_config_word ( pci, PCI_COMMAND, cmd );
        if ( start & PCI_BASE_ADDRESS_SPACE_IO ) {
                size &= ~PCI_BASE_ADDRESS_IO_MASK;
        } else {
                size &= ~PCI_BASE_ADDRESS_MEM_MASK;
        }
        /* Find the lowest bit set */
        size = size & ~( size - 1 );
        return size;
}