pci_emul_dior(struct vmctx *ctx, int vcpu, struct pci_vdev *dev, int baridx,
	      uint64_t offset, int size)
{
	struct pci_emul_dummy *dummy = dev->arg;
	uint32_t value = 0;
	int i;
	void *offset_ptr;

	if (baridx == 0) {
		if (offset + size > DIOSZ) {
			printf("dior: ior too large, offset %ld size %d\n",
			       offset, size);
			return 0;
		}

		value = 0;
		offset_ptr = (void *) &dummy->ioregs[offset];
		if (size == 1)
			value = *(uint8_t *)offset_ptr;
		else if (size == 2)
			value = *(uint16_t *)offset_ptr;
		else if (size == 4)
			value = *(uint32_t *)offset_ptr;
		else
			printf("dior: ior unknown size %d\n", size);
	}

	if (baridx == 1 || baridx == 2) {
		if (offset + size > DMEMSZ) {
			printf("dior: memr too large, offset %ld size %d\n",
			       offset, size);
			return 0;
		}

		i = baridx - 1;		/* 'memregs' index */

		offset_ptr = (void *) &dummy->memregs[i][offset];
		if (size == 1)
			value = *(uint8_t *)offset_ptr;
		else if (size == 2)
			value = *(uint16_t *)offset_ptr;
		else if (size == 4)
			value = *(uint32_t *)offset_ptr;
		else if (size == 8)
			value = *(uint64_t *)offset_ptr;
		else
			printf("dior: ior unknown size %d\n", size);
	}


	if (baridx > 2 || baridx < 0) {
		printf("dior: unknown bar idx %d\n", baridx);
		return 0;
	}

	return value;
}
pci_emul_dior(struct vmctx *ctx, int vcpu, struct pci_vdev *dev, int baridx,
	      uint64_t offset, int size)
{
	struct pci_emul_dummy *dummy = dev->arg;
	uint32_t value = 0;
	int i;
	void *offset_ptr;

	if (baridx == 0) {
		if (offset + size > DIOSZ) {
			printf("dior: ior too large, offset %ld size %d\n",
			       offset, size);
			return 0;
		}

		value = 0;
		offset_ptr = (void *) &dummy->ioregs[offset];
		if (size == 1)
			value = *(uint8_t *)offset_ptr;
		else if (size == 2)
			value = *(uint16_t *)offset_ptr;
		else if (size == 4)
			value = *(uint32_t *)offset_ptr;
		else
			printf("dior: ior unknown size %d\n", size);
	}

	if (baridx == 1 || baridx == 2) {
		if (offset + size > DMEMSZ) {
			printf("dior: memr too large, offset %ld size %d\n",
			       offset, size);
			return 0;
		}

		i = baridx - 1;		 

		offset_ptr = (void *) &dummy->memregs[i][offset];
		if (size == 1)
			value = *(uint8_t *)offset_ptr;
		else if (size == 2)
			value = *(uint16_t *)offset_ptr;
		else if (size == 4)
			value = *(uint32_t *)offset_ptr;
		else if (size == 8)
			value = *(uint64_t *)offset_ptr;
		else
			printf("dior: ior unknown size %d\n", size);
	}


	if (baridx > 2 || baridx < 0) {
		printf("dior: unknown bar idx %d\n", baridx);
		return 0;
	}

	return value;
}