FreeBSD/sys/mips/sibyte/sb_zbpci.c
/*
 * This function is expected to be called in a critical section since it
 * changes the per-cpu pci config space va-to-pa mappings.
 */
This function is expected to be called in a critical section since it
changes the per-cpu pci config space va-to-pa mappings.
This function is expected to be called in a critical section since it changes the per - cpu pci config space va - to - pa mappings .
static vm_offset_t
zbpci_config_space_va(int bus, int slot, int func, int reg, int bytes)
{
	int cpu;
	vm_offset_t va_page;
	vm_paddr_t pa, pa_page;
	if (bus <= PCI_BUSMAX && slot <= PCI_SLOTMAX && func <= PCI_FUNCMAX &&
	    reg <= PCI_REGMAX && (bytes == 1 || bytes == 2 || bytes == 4) &&
	    ((reg & (bytes - 1)) == 0)) {
		cpu = PCPU_GET(cpuid);
		va_page = zbpci_config_space[cpu].vaddr;
		pa = CFG_PADDR_BASE |
		     (bus << 16) | (slot << 11) | (func << 8) | reg;
#if _BYTE_ORDER == _BIG_ENDIAN
		pa = pa ^ (4 - bytes);
#endif
		pa_page = rounddown2(pa, PAGE_SIZE);
		if (zbpci_config_space[cpu].paddr != pa_page) {
			pmap_kremove(va_page);
			pmap_kenter_attr(va_page, pa_page, PTE_C_UNCACHED);
			zbpci_config_space[cpu].paddr = pa_page;
		}
		return (va_page + (pa - pa_page));
	} else {
		return (0);
	}
}
static vm_offset_t zbpci_config_space_va ( int bus , int slot , int func , int reg , int bytes ) { int cpu ; vm_offset_t va_page ; vm_paddr_t pa , pa_page ; if ( bus <= PCI_BUSMAX && slot <= PCI_SLOTMAX && func <= PCI_FUNCMAX && reg <= PCI_REGMAX && ( bytes == 1 || bytes == 2 || bytes == 4 ) && ( ( reg & ( bytes - 1 ) ) == 0 ) ) { cpu = PCPU_GET ( cpuid ) ; va_page = zbpci_config_space [ cpu ] . vaddr ; pa = CFG_PADDR_BASE | ( bus << 16 ) | ( slot << 11 ) | ( func << 8 ) | reg ; #if _BYTE_ORDER == _BIG_ENDIAN pa = pa ^ ( 4 - bytes ) ; #endif pa_page = rounddown2 ( pa , PAGE_SIZE ) ; if ( zbpci_config_space [ cpu ] . paddr != pa_page ) { pmap_kremove ( va_page ) ; pmap_kenter_attr ( va_page , pa_page , PTE_C_UNCACHED ) ; zbpci_config_space [ cpu ] . paddr = pa_page ; } return ( va_page + ( pa - pa_page ) ) ; } else { return ( 0 ) ; } }
This function is expected to be called in a critical section since it
 changes the per-cpu pci config space va-to-pa mappings.
This function is expected to be called in a critical section since it changes the per - cpu pci config space va - to - pa mappings .