/* Probe the nth BAR assigned to an endpoint. 
A PCI(e) endpoint has 0 or more BARs. This function allows the caller to enumerate them by calling with index=0..n. Value of n has to be below 6, as there is a maximum of 6 BARs. The indices are order-preserving with respect to the endpoint BARs: e.g., index 0 will return the lowest-numbered BAR on the endpoint. */
static bool pcie_probe_bar(pcie_bdf_t bdf, unsigned int index, struct pcie_bar *bar, bool io)
/* Probe the nth BAR assigned to an endpoint. 
A PCI(e) endpoint has 0 or more BARs. This function allows the caller to enumerate them by calling with index=0..n. Value of n has to be below 6, as there is a maximum of 6 BARs. The indices are order-preserving with respect to the endpoint BARs: e.g., index 0 will return the lowest-numbered BAR on the endpoint. */
static bool pcie_probe_bar(pcie_bdf_t bdf, unsigned int index, struct pcie_bar *bar, bool io)
{
	uint32_t reg;
	for (reg = PCIE_CONF_BAR0;
	     index > 0 && reg <= PCIE_CONF_BAR5; reg++, index--) {
		uintptr_t addr = pcie_conf_read(bdf, reg);
		if (PCIE_CONF_BAR_MEM(addr) && PCIE_CONF_BAR_64(addr)) {
			reg++;
		}
	}
	if (index != 0) {
		return false;
	}
	return pcie_get_bar(bdf, reg - PCIE_CONF_BAR0, bar, io);
}