@@ -143,12 +143,12 @@ void xen_snd_front_evtchnl_flush(struct xen_snd_front_evtchnl *channel)
143
143
static void evtchnl_free (struct xen_snd_front_info * front_info ,
144
144
struct xen_snd_front_evtchnl * channel )
145
145
{
146
- unsigned long page = 0 ;
146
+ void * page = NULL ;
147
147
148
148
if (channel -> type == EVTCHNL_TYPE_REQ )
149
- page = ( unsigned long ) channel -> u .req .ring .sring ;
149
+ page = channel -> u .req .ring .sring ;
150
150
else if (channel -> type == EVTCHNL_TYPE_EVT )
151
- page = ( unsigned long ) channel -> u .evt .page ;
151
+ page = channel -> u .evt .page ;
152
152
153
153
if (!page )
154
154
return ;
@@ -167,10 +167,7 @@ static void evtchnl_free(struct xen_snd_front_info *front_info,
167
167
xenbus_free_evtchn (front_info -> xb_dev , channel -> port );
168
168
169
169
/* End access and free the page. */
170
- if (channel -> gref != INVALID_GRANT_REF )
171
- gnttab_end_foreign_access (channel -> gref , page );
172
- else
173
- free_page (page );
170
+ xenbus_teardown_ring (& page , 1 , & channel -> gref );
174
171
175
172
memset (channel , 0 , sizeof (* channel ));
176
173
}
@@ -196,8 +193,7 @@ static int evtchnl_alloc(struct xen_snd_front_info *front_info, int index,
196
193
enum xen_snd_front_evtchnl_type type )
197
194
{
198
195
struct xenbus_device * xb_dev = front_info -> xb_dev ;
199
- unsigned long page ;
200
- grant_ref_t gref ;
196
+ void * page ;
201
197
irq_handler_t handler ;
202
198
char * handler_name = NULL ;
203
199
int ret ;
@@ -207,12 +203,9 @@ static int evtchnl_alloc(struct xen_snd_front_info *front_info, int index,
207
203
channel -> index = index ;
208
204
channel -> front_info = front_info ;
209
205
channel -> state = EVTCHNL_STATE_DISCONNECTED ;
210
- channel -> gref = INVALID_GRANT_REF ;
211
- page = get_zeroed_page (GFP_KERNEL );
212
- if (!page ) {
213
- ret = - ENOMEM ;
206
+ ret = xenbus_setup_ring (xb_dev , GFP_KERNEL , & page , 1 , & channel -> gref );
207
+ if (ret )
214
208
goto fail ;
215
- }
216
209
217
210
handler_name = kasprintf (GFP_KERNEL , "%s-%s" , XENSND_DRIVER_NAME ,
218
211
type == EVTCHNL_TYPE_REQ ?
@@ -226,33 +219,18 @@ static int evtchnl_alloc(struct xen_snd_front_info *front_info, int index,
226
219
mutex_init (& channel -> ring_io_lock );
227
220
228
221
if (type == EVTCHNL_TYPE_REQ ) {
229
- struct xen_sndif_sring * sring = ( struct xen_sndif_sring * ) page ;
222
+ struct xen_sndif_sring * sring = page ;
230
223
231
224
init_completion (& channel -> u .req .completion );
232
225
mutex_init (& channel -> u .req .req_io_lock );
233
- SHARED_RING_INIT (sring );
234
- FRONT_RING_INIT (& channel -> u .req .ring , sring , XEN_PAGE_SIZE );
235
-
236
- ret = xenbus_grant_ring (xb_dev , sring , 1 , & gref );
237
- if (ret < 0 ) {
238
- channel -> u .req .ring .sring = NULL ;
239
- goto fail ;
240
- }
226
+ XEN_FRONT_RING_INIT (& channel -> u .req .ring , sring , XEN_PAGE_SIZE );
241
227
242
228
handler = evtchnl_interrupt_req ;
243
229
} else {
244
- ret = gnttab_grant_foreign_access (xb_dev -> otherend_id ,
245
- virt_to_gfn ((void * )page ), 0 );
246
- if (ret < 0 )
247
- goto fail ;
248
-
249
- channel -> u .evt .page = (struct xensnd_event_page * )page ;
250
- gref = ret ;
230
+ channel -> u .evt .page = page ;
251
231
handler = evtchnl_interrupt_evt ;
252
232
}
253
233
254
- channel -> gref = gref ;
255
-
256
234
ret = xenbus_alloc_evtchn (xb_dev , & channel -> port );
257
235
if (ret < 0 )
258
236
goto fail ;
@@ -279,8 +257,6 @@ static int evtchnl_alloc(struct xen_snd_front_info *front_info, int index,
279
257
return 0 ;
280
258
281
259
fail :
282
- if (page )
283
- free_page (page );
284
260
kfree (handler_name );
285
261
dev_err (& xb_dev -> dev , "Failed to allocate ring: %d\n" , ret );
286
262
return ret ;
0 commit comments