pci_emul_io_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes,
		    uint32_t *eax, void *arg)
{
	struct pci_vdev *pdi = arg;
	struct pci_vdev_ops *ops = pdi->dev_ops;
	uint64_t offset;
	int i;

	for (i = 0; i <= PCI_BARMAX; i++) {
		if (pdi->bar[i].type == PCIBAR_IO &&
		    port >= pdi->bar[i].addr &&
		    port + bytes <= pdi->bar[i].addr + pdi->bar[i].size) {
			offset = port - pdi->bar[i].addr;
			if (in) {
				*eax = (*ops->vdev_barread)(ctx, vcpu, pdi, i,
				                            offset, bytes);
				*eax = bar_value(bytes, *eax);
			} else
				(*ops->vdev_barwrite)(ctx, vcpu, pdi, i, offset,
				                      bytes, bar_value(bytes, *eax));
			return 0;
		}
	}
	return -1;
}
pci_emul_io_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes,
		    uint32_t *eax, void *arg)
{
	struct pci_vdev *pdi = arg;
	struct pci_vdev_ops *ops = pdi->dev_ops;
	uint64_t offset;
	int i;

	for (i = 0; i <= PCI_BARMAX; i++) {
		if (pdi->bar[i].type == PCIBAR_IO &&
		    port >= pdi->bar[i].addr &&
		    port + bytes <= pdi->bar[i].addr + pdi->bar[i].size) {
			offset = port - pdi->bar[i].addr;
			if (in) {
				*eax = (*ops->vdev_barread)(ctx, vcpu, pdi, i,
				                            offset, bytes);
				*eax = bar_value(bytes, *eax);
			} else
				(*ops->vdev_barwrite)(ctx, vcpu, pdi, i, offset,
				                      bytes, bar_value(bytes, *eax));
			return 0;
		}
	}
	return -1;
}