FreeBSD/sys/dev/pci/pci.c
/*
 * Find the requested capability and return the offset in
 * configuration space via the pointer provided.  The function returns
 * 0 on success and an error code otherwise.
 */
Find the requested capability and return the offset in
configuration space via the pointer provided.  The function returns
0 on success and an error code otherwise.
Find the requested capability and return the offset in configuration space via the pointer provided . The function returns 0 on success and an error code otherwise .
int
pci_find_cap_method(device_t dev, device_t child, int capability,
    int *capreg)
{
	struct pci_devinfo *dinfo = device_get_ivars(child);
	pcicfgregs *cfg = &dinfo->cfg;
	u_int32_t status;
	u_int8_t ptr;
	status = pci_read_config(child, PCIR_STATUS, 2);
	if (!(status & PCIM_STATUS_CAPPRESENT))
		return (ENXIO);
	switch (cfg->hdrtype & PCIM_HDRTYPE) {
	case PCIM_HDRTYPE_NORMAL:
	case PCIM_HDRTYPE_BRIDGE:
		ptr = PCIR_CAP_PTR;
		break;
	case PCIM_HDRTYPE_CARDBUS:
		ptr = PCIR_CAP_PTR_2;
		break;
	default:
		return (ENXIO);		
	}
	ptr = pci_read_config(child, ptr, 1);
	while (ptr != 0) {
		if (pci_read_config(child, ptr + PCICAP_ID, 1) == capability) {
			if (capreg != NULL)
				*capreg = ptr;
			return (0);
		}
		ptr = pci_read_config(child, ptr + PCICAP_NEXTPTR, 1);
	}
	return (ENOENT);
}
int pci_find_cap_method ( device_t dev , device_t child , int capability , int * capreg ) { struct pci_devinfo * dinfo = device_get_ivars ( child ) ; pcicfgregs * cfg = & dinfo -> cfg ; u_int32_t status ; u_int8_t ptr ; status = pci_read_config ( child , PCIR_STATUS , 2 ) ; if ( ! ( status & PCIM_STATUS_CAPPRESENT ) ) return ( ENXIO ) ; switch ( cfg -> hdrtype & PCIM_HDRTYPE ) { case PCIM_HDRTYPE_NORMAL : case PCIM_HDRTYPE_BRIDGE : ptr = PCIR_CAP_PTR ; break ; case PCIM_HDRTYPE_CARDBUS : ptr = PCIR_CAP_PTR_2 ; break ; default : return ( ENXIO ) ; } ptr = pci_read_config ( child , ptr , 1 ) ; while ( ptr != 0 ) { if ( pci_read_config ( child , ptr + PCICAP_ID , 1 ) == capability ) { if ( capreg != NULL ) * capreg = ptr ; return ( 0 ) ; } ptr = pci_read_config ( child , ptr + PCICAP_NEXTPTR , 1 ) ; } return ( ENOENT ) ; }
Find the requested capability and return the offset in
 configuration space via the pointer provided.
Find the requested capability and return the offset in configuration space via the pointer provided .
/*
	 * Check the CAP_LIST bit of the PCI status register first.
	 */ /*
	 * Determine the start pointer of the capabilities list.
	 */ /* XXX: panic? */ /* no extended capabilities support */ /*
	 * Traverse the capabilities list.
	 */