Commit ae19265c authored by Juergen Gross's avatar Juergen Gross

xen/drmfront: use xenbus_setup_ring() and xenbus_teardown_ring()

Simplify drmfront's ring creation and removal via xenbus_setup_ring()
and xenbus_teardown_ring().
Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
Reviewed-by: default avatarOleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Tested-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com> # Arm64 only
Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
parent 5e0afd8e
...@@ -123,12 +123,12 @@ static irqreturn_t evtchnl_interrupt_evt(int irq, void *dev_id) ...@@ -123,12 +123,12 @@ static irqreturn_t evtchnl_interrupt_evt(int irq, void *dev_id)
static void evtchnl_free(struct xen_drm_front_info *front_info, static void evtchnl_free(struct xen_drm_front_info *front_info,
struct xen_drm_front_evtchnl *evtchnl) struct xen_drm_front_evtchnl *evtchnl)
{ {
unsigned long page = 0; void *page = NULL;
if (evtchnl->type == EVTCHNL_TYPE_REQ) if (evtchnl->type == EVTCHNL_TYPE_REQ)
page = (unsigned long)evtchnl->u.req.ring.sring; page = evtchnl->u.req.ring.sring;
else if (evtchnl->type == EVTCHNL_TYPE_EVT) else if (evtchnl->type == EVTCHNL_TYPE_EVT)
page = (unsigned long)evtchnl->u.evt.page; page = evtchnl->u.evt.page;
if (!page) if (!page)
return; return;
...@@ -147,8 +147,7 @@ static void evtchnl_free(struct xen_drm_front_info *front_info, ...@@ -147,8 +147,7 @@ static void evtchnl_free(struct xen_drm_front_info *front_info,
xenbus_free_evtchn(front_info->xb_dev, evtchnl->port); xenbus_free_evtchn(front_info->xb_dev, evtchnl->port);
/* end access and free the page */ /* end access and free the page */
if (evtchnl->gref != INVALID_GRANT_REF) xenbus_teardown_ring(&page, 1, &evtchnl->gref);
gnttab_end_foreign_access(evtchnl->gref, page);
memset(evtchnl, 0, sizeof(*evtchnl)); memset(evtchnl, 0, sizeof(*evtchnl));
} }
...@@ -158,8 +157,7 @@ static int evtchnl_alloc(struct xen_drm_front_info *front_info, int index, ...@@ -158,8 +157,7 @@ static int evtchnl_alloc(struct xen_drm_front_info *front_info, int index,
enum xen_drm_front_evtchnl_type type) enum xen_drm_front_evtchnl_type type)
{ {
struct xenbus_device *xb_dev = front_info->xb_dev; struct xenbus_device *xb_dev = front_info->xb_dev;
unsigned long page; void *page;
grant_ref_t gref;
irq_handler_t handler; irq_handler_t handler;
int ret; int ret;
...@@ -168,44 +166,25 @@ static int evtchnl_alloc(struct xen_drm_front_info *front_info, int index, ...@@ -168,44 +166,25 @@ static int evtchnl_alloc(struct xen_drm_front_info *front_info, int index,
evtchnl->index = index; evtchnl->index = index;
evtchnl->front_info = front_info; evtchnl->front_info = front_info;
evtchnl->state = EVTCHNL_STATE_DISCONNECTED; evtchnl->state = EVTCHNL_STATE_DISCONNECTED;
evtchnl->gref = INVALID_GRANT_REF;
page = get_zeroed_page(GFP_NOIO | __GFP_HIGH); ret = xenbus_setup_ring(xb_dev, GFP_NOIO | __GFP_HIGH, &page,
if (!page) { 1, &evtchnl->gref);
ret = -ENOMEM; if (ret)
goto fail; goto fail;
}
if (type == EVTCHNL_TYPE_REQ) { if (type == EVTCHNL_TYPE_REQ) {
struct xen_displif_sring *sring; struct xen_displif_sring *sring;
init_completion(&evtchnl->u.req.completion); init_completion(&evtchnl->u.req.completion);
mutex_init(&evtchnl->u.req.req_io_lock); mutex_init(&evtchnl->u.req.req_io_lock);
sring = (struct xen_displif_sring *)page; sring = page;
SHARED_RING_INIT(sring); XEN_FRONT_RING_INIT(&evtchnl->u.req.ring, sring, XEN_PAGE_SIZE);
FRONT_RING_INIT(&evtchnl->u.req.ring, sring, XEN_PAGE_SIZE);
ret = xenbus_grant_ring(xb_dev, sring, 1, &gref);
if (ret < 0) {
evtchnl->u.req.ring.sring = NULL;
free_page(page);
goto fail;
}
handler = evtchnl_interrupt_ctrl; handler = evtchnl_interrupt_ctrl;
} else { } else {
ret = gnttab_grant_foreign_access(xb_dev->otherend_id, evtchnl->u.evt.page = page;
virt_to_gfn((void *)page), 0);
if (ret < 0) {
free_page(page);
goto fail;
}
evtchnl->u.evt.page = (struct xendispl_event_page *)page;
gref = ret;
handler = evtchnl_interrupt_evt; handler = evtchnl_interrupt_evt;
} }
evtchnl->gref = gref;
ret = xenbus_alloc_evtchn(xb_dev, &evtchnl->port); ret = xenbus_alloc_evtchn(xb_dev, &evtchnl->port);
if (ret < 0) if (ret < 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment