/* Part of this file is ported from coreboot src/arch/x86/boot/pirq_routing.c  */
static u8 pirq_get_next_free_irq(struct udevice *dev, u8 *pirq, u16 bitmap, bool irq_already_routed[])
/* Part of this file is ported from coreboot src/arch/x86/boot/pirq_routing.c  */
static u8 pirq_get_next_free_irq(struct udevice *dev, u8 *pirq, u16 bitmap, bool irq_already_routed[])
{
	int i, link;
	u8 irq = 0;
	for (i = 3; i < 16; i++) {
		if (!((bitmap >> i) & 1))
			continue;
		irq = i;
		if (irq_already_routed[irq])
			continue;
		for (link = 0; link < CONFIG_MAX_PIRQ_LINKS; link++) {
			if (pirq_check_irq_routed(dev, link, irq)) {
				irq_already_routed[irq] = true;
				break;
			}
		}
		if (!irq_already_routed[irq]) {
			irq_already_routed[irq] = true;
			break;
		}
	}
	return irq;
}