pciextra.c File Reference

#include <stdint.h>
#include <gpxe/pci.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
int pci_find_capability (struct pci_device *pci, int cap)
 Look for a 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   ) 

int pci_find_capability ( struct pci_device pci,
int  cap 
)

Look for a PCI capability.

Parameters:
pci PCI device to query
cap Capability code
Return values:
address Address 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 18 of file pciextra.c.

References DBG, id, PCI_CAP_LIST_ID, PCI_CAP_LIST_NEXT, PCI_CAPABILITY_LIST, PCI_CB_CAPABILITY_LIST, PCI_HEADER_TYPE, PCI_HEADER_TYPE_BRIDGE, PCI_HEADER_TYPE_CARDBUS, PCI_HEADER_TYPE_NORMAL, pci_read_config_byte(), pci_read_config_word(), PCI_STATUS, and PCI_STATUS_CAP_LIST.

Referenced by ath5k_hw_attach(), ath5k_hw_nic_wakeup(), bnx2_init_board(), e1000_read_pcie_cap_reg(), e1000e_read_pcie_cap_reg(), igb_read_pcie_cap_reg(), igb_write_pcie_cap_reg(), mac_address_from_string_specs(), pci_set_power_state(), rtl8169_probe(), sky2_reset(), sky2_rx_start(), tg3_get_invariants(), and tg3_probe().

00018                                                             {
00019         uint16_t status;
00020         uint8_t pos, id;
00021         uint8_t hdr_type;
00022         int ttl = 48;
00023 
00024         pci_read_config_word ( pci, PCI_STATUS, &status );
00025         if ( ! ( status & PCI_STATUS_CAP_LIST ) )
00026                 return 0;
00027 
00028         pci_read_config_byte ( pci, PCI_HEADER_TYPE, &hdr_type );
00029         switch ( hdr_type & 0x7F ) {
00030         case PCI_HEADER_TYPE_NORMAL:
00031         case PCI_HEADER_TYPE_BRIDGE:
00032         default:
00033                 pci_read_config_byte ( pci, PCI_CAPABILITY_LIST, &pos );
00034                 break;
00035         case PCI_HEADER_TYPE_CARDBUS:
00036                 pci_read_config_byte ( pci, PCI_CB_CAPABILITY_LIST, &pos );
00037                 break;
00038         }
00039         while ( ttl-- && pos >= 0x40 ) {
00040                 pos &= ~3;
00041                 pci_read_config_byte ( pci, pos + PCI_CAP_LIST_ID, &id );
00042                 DBG ( "PCI Capability: %d\n", id );
00043                 if ( id == 0xff )
00044                         break;
00045                 if ( id == cap )
00046                         return pos;
00047                 pci_read_config_byte ( pci, pos + PCI_CAP_LIST_NEXT, &pos );
00048         }
00049         return 0;
00050 }

unsigned long pci_bar_size ( struct pci_device pci,
unsigned int  reg 
)

Find the size of a PCI BAR.

Parameters:
pci PCI device
reg PCI register number
Return values:
size BAR size
It should not be necessary for any Etherboot code to call this function.

Definition at line 62 of file pciextra.c.

References 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(), and size.

Referenced by amd8111e_probe(), e1000_probe(), e1000e_probe(), efab_probe(), forcedeth_probe(), igb_probe(), phantom_map_crb(), tg3_probe(), velocity_get_pci_info(), and vxge_probe().

00062                                                                         {
00063         uint16_t cmd;
00064         uint32_t start, size;
00065 
00066         /* Save the original command register */
00067         pci_read_config_word ( pci, PCI_COMMAND, &cmd );
00068         /* Save the original bar */
00069         pci_read_config_dword ( pci, reg, &start );
00070         /* Compute which bits can be set */
00071         pci_write_config_dword ( pci, reg, ~0 );
00072         pci_read_config_dword ( pci, reg, &size );
00073         /* Restore the original size */
00074         pci_write_config_dword ( pci, reg, start );
00075         /* Find the significant bits */
00076         /* Restore the original command register. This reenables decoding. */
00077         pci_write_config_word ( pci, PCI_COMMAND, cmd );
00078         if ( start & PCI_BASE_ADDRESS_SPACE_IO ) {
00079                 size &= PCI_BASE_ADDRESS_IO_MASK;
00080         } else {
00081                 size &= PCI_BASE_ADDRESS_MEM_MASK;
00082         }
00083         /* Find the lowest bit set */
00084         size = size & ~( size - 1 );
00085         return size;
00086 }


Generated on Tue Apr 6 20:01:16 2010 for gPXE by  doxygen 1.5.7.1