Skip to content

Commit

Permalink
vhost_iotlb: split out IOTLB initialization
Browse files Browse the repository at this point in the history
This patch splits out IOTLB initialization to make sure it could be
reused by external modules.

Signed-off-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Gautam Dawar <gdawar@xilinx.com>
Message-Id: <20220330180436.24644-9-gdawar@xilinx.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
  • Loading branch information
Gautam Dawar authored and Michael S. Tsirkin committed May 31, 2022
1 parent 46d554b commit 1cb1089
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 18 additions & 5 deletions drivers/vhost/iotlb.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,23 @@ void vhost_iotlb_del_range(struct vhost_iotlb *iotlb, u64 start, u64 last)
}
EXPORT_SYMBOL_GPL(vhost_iotlb_del_range);

/**
* vhost_iotlb_init - initialize a vhost IOTLB
* @iotlb: the IOTLB that needs to be initialized
* @limit: maximum number of IOTLB entries
* @flags: VHOST_IOTLB_FLAG_XXX
*/
void vhost_iotlb_init(struct vhost_iotlb *iotlb, unsigned int limit,
unsigned int flags)
{
iotlb->root = RB_ROOT_CACHED;
iotlb->limit = limit;
iotlb->nmaps = 0;
iotlb->flags = flags;
INIT_LIST_HEAD(&iotlb->list);
}
EXPORT_SYMBOL_GPL(vhost_iotlb_init);

/**
* vhost_iotlb_alloc - add a new vhost IOTLB
* @limit: maximum number of IOTLB entries
Expand All @@ -139,11 +156,7 @@ struct vhost_iotlb *vhost_iotlb_alloc(unsigned int limit, unsigned int flags)
if (!iotlb)
return NULL;

iotlb->root = RB_ROOT_CACHED;
iotlb->limit = limit;
iotlb->nmaps = 0;
iotlb->flags = flags;
INIT_LIST_HEAD(&iotlb->list);
vhost_iotlb_init(iotlb, limit, flags);

return iotlb;
}
Expand Down
2 changes: 2 additions & 0 deletions include/linux/vhost_iotlb.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ int vhost_iotlb_add_range(struct vhost_iotlb *iotlb, u64 start, u64 last,
u64 addr, unsigned int perm);
void vhost_iotlb_del_range(struct vhost_iotlb *iotlb, u64 start, u64 last);

void vhost_iotlb_init(struct vhost_iotlb *iotlb, unsigned int limit,
unsigned int flags);
struct vhost_iotlb *vhost_iotlb_alloc(unsigned int limit, unsigned int flags);
void vhost_iotlb_free(struct vhost_iotlb *iotlb);
void vhost_iotlb_reset(struct vhost_iotlb *iotlb);
Expand Down

0 comments on commit 1cb1089

Please sign in to comment.