Skip to content

Commit ae19265

Browse files
committed
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: Juergen Gross <[email protected]> Reviewed-by: Oleksandr Tyshchenko <[email protected]> Tested-by: Oleksandr Tyshchenko <[email protected]> # Arm64 only Signed-off-by: Juergen Gross <[email protected]>
1 parent 5e0afd8 commit ae19265

File tree

1 file changed

+11
-32
lines changed

1 file changed

+11
-32
lines changed

drivers/gpu/drm/xen/xen_drm_front_evtchnl.c

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ static irqreturn_t evtchnl_interrupt_evt(int irq, void *dev_id)
123123
static void evtchnl_free(struct xen_drm_front_info *front_info,
124124
struct xen_drm_front_evtchnl *evtchnl)
125125
{
126-
unsigned long page = 0;
126+
void *page = NULL;
127127

128128
if (evtchnl->type == EVTCHNL_TYPE_REQ)
129-
page = (unsigned long)evtchnl->u.req.ring.sring;
129+
page = evtchnl->u.req.ring.sring;
130130
else if (evtchnl->type == EVTCHNL_TYPE_EVT)
131-
page = (unsigned long)evtchnl->u.evt.page;
131+
page = evtchnl->u.evt.page;
132132
if (!page)
133133
return;
134134

@@ -147,8 +147,7 @@ static void evtchnl_free(struct xen_drm_front_info *front_info,
147147
xenbus_free_evtchn(front_info->xb_dev, evtchnl->port);
148148

149149
/* end access and free the page */
150-
if (evtchnl->gref != INVALID_GRANT_REF)
151-
gnttab_end_foreign_access(evtchnl->gref, page);
150+
xenbus_teardown_ring(&page, 1, &evtchnl->gref);
152151

153152
memset(evtchnl, 0, sizeof(*evtchnl));
154153
}
@@ -158,8 +157,7 @@ static int evtchnl_alloc(struct xen_drm_front_info *front_info, int index,
158157
enum xen_drm_front_evtchnl_type type)
159158
{
160159
struct xenbus_device *xb_dev = front_info->xb_dev;
161-
unsigned long page;
162-
grant_ref_t gref;
160+
void *page;
163161
irq_handler_t handler;
164162
int ret;
165163

@@ -168,44 +166,25 @@ static int evtchnl_alloc(struct xen_drm_front_info *front_info, int index,
168166
evtchnl->index = index;
169167
evtchnl->front_info = front_info;
170168
evtchnl->state = EVTCHNL_STATE_DISCONNECTED;
171-
evtchnl->gref = INVALID_GRANT_REF;
172169

173-
page = get_zeroed_page(GFP_NOIO | __GFP_HIGH);
174-
if (!page) {
175-
ret = -ENOMEM;
170+
ret = xenbus_setup_ring(xb_dev, GFP_NOIO | __GFP_HIGH, &page,
171+
1, &evtchnl->gref);
172+
if (ret)
176173
goto fail;
177-
}
178174

179175
if (type == EVTCHNL_TYPE_REQ) {
180176
struct xen_displif_sring *sring;
181177

182178
init_completion(&evtchnl->u.req.completion);
183179
mutex_init(&evtchnl->u.req.req_io_lock);
184-
sring = (struct xen_displif_sring *)page;
185-
SHARED_RING_INIT(sring);
186-
FRONT_RING_INIT(&evtchnl->u.req.ring, sring, XEN_PAGE_SIZE);
187-
188-
ret = xenbus_grant_ring(xb_dev, sring, 1, &gref);
189-
if (ret < 0) {
190-
evtchnl->u.req.ring.sring = NULL;
191-
free_page(page);
192-
goto fail;
193-
}
180+
sring = page;
181+
XEN_FRONT_RING_INIT(&evtchnl->u.req.ring, sring, XEN_PAGE_SIZE);
194182

195183
handler = evtchnl_interrupt_ctrl;
196184
} else {
197-
ret = gnttab_grant_foreign_access(xb_dev->otherend_id,
198-
virt_to_gfn((void *)page), 0);
199-
if (ret < 0) {
200-
free_page(page);
201-
goto fail;
202-
}
203-
204-
evtchnl->u.evt.page = (struct xendispl_event_page *)page;
205-
gref = ret;
185+
evtchnl->u.evt.page = page;
206186
handler = evtchnl_interrupt_evt;
207187
}
208-
evtchnl->gref = gref;
209188

210189
ret = xenbus_alloc_evtchn(xb_dev, &evtchnl->port);
211190
if (ret < 0)

0 commit comments

Comments
 (0)