Esempio n. 1
0
int
pirq_alloc_pin(struct pci_devinst *pi)
{
	struct vmctx *ctx = pi->pi_vmctx;
	int best_count, best_irq, best_pin, irq, pin;

	pirq_cold = 0;

	if (lpc_bootrom()) {
		/* For external bootrom use fixed mapping. */
		best_pin = (4 + pi->pi_slot + pi->pi_lintr.pin) % 8;
	} else {
		/* Find the least-used PIRQ pin. */
		best_pin = 0;
		best_count = pirqs[0].use_count;
		for (pin = 1; pin < nitems(pirqs); pin++) {
			if (pirqs[pin].use_count < best_count) {
				best_pin = pin;
				best_count = pirqs[pin].use_count;
			}
		}
	}
	pirqs[best_pin].use_count++;

	/* Second, route this pin to an IRQ. */
	if (pirqs[best_pin].reg == PIRQ_DIS) {
		best_irq = -1;
		best_count = 0;
		for (irq = 0; irq < nitems(irq_counts); irq++) {
			if (irq_counts[irq] == IRQ_DISABLED)
				continue;
			if (best_irq == -1 || irq_counts[irq] < best_count) {
				best_irq = irq;
				best_count = irq_counts[irq];
			}
		}
		assert(best_irq >= 0);
		irq_counts[best_irq]++;
		pirqs[best_pin].reg = best_irq;
		vm_isa_set_irq_trigger(ctx, best_irq, LEVEL_TRIGGER);
	}

	return (best_pin + 1);
}
Esempio n. 2
0
int
pirq_alloc_pin(struct vmctx *ctx)
{
	int best_count, best_irq, best_pin, irq, pin;

	pirq_cold = 0;

	/* First, find the least-used PIRQ pin. */
	best_pin = 0;
	best_count = pirqs[0].use_count;
	for (pin = 1; pin < nitems(pirqs); pin++) {
		if (pirqs[pin].use_count < best_count) {
			best_pin = pin;
			best_count = pirqs[pin].use_count;
		}
	}
	pirqs[best_pin].use_count++;

	/* Second, route this pin to an IRQ. */
	if (pirqs[best_pin].reg == PIRQ_DIS) {
		best_irq = -1;
		best_count = 0;
		for (irq = 0; irq < nitems(irq_counts); irq++) {
			if (irq_counts[irq] == IRQ_DISABLED)
				continue;
			if (best_irq == -1 || irq_counts[irq] < best_count) {
				best_irq = irq;
				best_count = irq_counts[irq];
			}
		}
		assert(best_irq >= 0);
		irq_counts[best_irq]++;
		pirqs[best_pin].reg = best_irq;
		vm_isa_set_irq_trigger(ctx, best_irq, LEVEL_TRIGGER);
	}

	return (best_pin + 1);
}