static int mbochs_get_region_info(struct mdev_state *mdev_state,
				  struct vfio_region_info_ext *ext)
{
	struct vfio_region_info *region_info = &ext->base;

	if (region_info->index >= MBOCHS_NUM_REGIONS)
		return -EINVAL;

	switch (region_info->index) {
	case VFIO_PCI_CONFIG_REGION_INDEX:
		region_info->offset = 0;
		region_info->size   = MBOCHS_CONFIG_SPACE_SIZE;
		region_info->flags  = (VFIO_REGION_INFO_FLAG_READ |
				       VFIO_REGION_INFO_FLAG_WRITE);
		break;
	case VFIO_PCI_BAR0_REGION_INDEX:
		region_info->offset = MBOCHS_MEMORY_BAR_OFFSET;
		region_info->size   = mdev_state->memsize;
		region_info->flags  = (VFIO_REGION_INFO_FLAG_READ  |
				       VFIO_REGION_INFO_FLAG_WRITE |
				       VFIO_REGION_INFO_FLAG_MMAP);
		break;
	case VFIO_PCI_BAR2_REGION_INDEX:
		region_info->offset = MBOCHS_MMIO_BAR_OFFSET;
		region_info->size   = MBOCHS_MMIO_BAR_SIZE;
		region_info->flags  = (VFIO_REGION_INFO_FLAG_READ  |
				       VFIO_REGION_INFO_FLAG_WRITE);
		break;
	case MBOCHS_EDID_REGION_INDEX:
		ext->base.argsz = sizeof(*ext);
		ext->base.offset = MBOCHS_EDID_OFFSET;
		ext->base.size = MBOCHS_EDID_SIZE;
		ext->base.flags = (VFIO_REGION_INFO_FLAG_READ  |
				   VFIO_REGION_INFO_FLAG_WRITE |
				   VFIO_REGION_INFO_FLAG_CAPS);
		ext->base.cap_offset = offsetof(typeof(*ext), type);
		ext->type.header.id = VFIO_REGION_INFO_CAP_TYPE;
		ext->type.header.version = 1;
		ext->type.header.next = 0;
		ext->type.type = VFIO_REGION_TYPE_GFX;
		ext->type.subtype = VFIO_REGION_SUBTYPE_GFX_EDID;
		break;
	default:
		region_info->size   = 0;
		region_info->offset = 0;
		region_info->flags  = 0;
	}

	return 0;
}
static int mbochs_get_region_info(struct mdev_state *mdev_state,
				  struct vfio_region_info_ext *ext)
{
	struct vfio_region_info *region_info = &ext->base;

	if (region_info->index >= MBOCHS_NUM_REGIONS)
		return -EINVAL;

	switch (region_info->index) {
	case VFIO_PCI_CONFIG_REGION_INDEX:
		region_info->offset = 0;
		region_info->size   = MBOCHS_CONFIG_SPACE_SIZE;
		region_info->flags  = (VFIO_REGION_INFO_FLAG_READ |
				       VFIO_REGION_INFO_FLAG_WRITE);
		break;
	case VFIO_PCI_BAR0_REGION_INDEX:
		region_info->offset = MBOCHS_MEMORY_BAR_OFFSET;
		region_info->size   = mdev_state->memsize;
		region_info->flags  = (VFIO_REGION_INFO_FLAG_READ  |
				       VFIO_REGION_INFO_FLAG_WRITE |
				       VFIO_REGION_INFO_FLAG_MMAP);
		break;
	case VFIO_PCI_BAR2_REGION_INDEX:
		region_info->offset = MBOCHS_MMIO_BAR_OFFSET;
		region_info->size   = MBOCHS_MMIO_BAR_SIZE;
		region_info->flags  = (VFIO_REGION_INFO_FLAG_READ  |
				       VFIO_REGION_INFO_FLAG_WRITE);
		break;
	case MBOCHS_EDID_REGION_INDEX:
		ext->base.argsz = sizeof(*ext);
		ext->base.offset = MBOCHS_EDID_OFFSET;
		ext->base.size = MBOCHS_EDID_SIZE;
		ext->base.flags = (VFIO_REGION_INFO_FLAG_READ  |
				   VFIO_REGION_INFO_FLAG_WRITE |
				   VFIO_REGION_INFO_FLAG_CAPS);
		ext->base.cap_offset = offsetof(typeof(*ext), type);
		ext->type.header.id = VFIO_REGION_INFO_CAP_TYPE;
		ext->type.header.version = 1;
		ext->type.header.next = 0;
		ext->type.type = VFIO_REGION_TYPE_GFX;
		ext->type.subtype = VFIO_REGION_SUBTYPE_GFX_EDID;
		break;
	default:
		region_info->size   = 0;
		region_info->offset = 0;
		region_info->flags  = 0;
	}

	return 0;
}