@@ -289,22 +289,28 @@ static const struct dma_map_ops xen_grant_dma_ops = {
289
289
.dma_supported = xen_grant_dma_supported ,
290
290
};
291
291
292
- bool xen_is_grant_dma_device (struct device * dev )
292
+ static bool xen_is_dt_grant_dma_device (struct device * dev )
293
293
{
294
294
struct device_node * iommu_np ;
295
295
bool has_iommu ;
296
296
297
- /* XXX Handle only DT devices for now */
298
- if (!dev -> of_node )
299
- return false;
300
-
301
297
iommu_np = of_parse_phandle (dev -> of_node , "iommus" , 0 );
302
- has_iommu = iommu_np && of_device_is_compatible (iommu_np , "xen,grant-dma" );
298
+ has_iommu = iommu_np &&
299
+ of_device_is_compatible (iommu_np , "xen,grant-dma" );
303
300
of_node_put (iommu_np );
304
301
305
302
return has_iommu ;
306
303
}
307
304
305
+ bool xen_is_grant_dma_device (struct device * dev )
306
+ {
307
+ /* XXX Handle only DT devices for now */
308
+ if (dev -> of_node )
309
+ return xen_is_dt_grant_dma_device (dev );
310
+
311
+ return false;
312
+ }
313
+
308
314
bool xen_virtio_mem_acc (struct virtio_device * dev )
309
315
{
310
316
if (IS_ENABLED (CONFIG_XEN_VIRTIO_FORCE_GRANT ))
@@ -313,45 +319,56 @@ bool xen_virtio_mem_acc(struct virtio_device *dev)
313
319
return xen_is_grant_dma_device (dev -> dev .parent );
314
320
}
315
321
316
- void xen_grant_setup_dma_ops (struct device * dev )
322
+ static int xen_dt_grant_init_backend_domid (struct device * dev ,
323
+ struct xen_grant_dma_data * data )
317
324
{
318
- struct xen_grant_dma_data * data ;
319
325
struct of_phandle_args iommu_spec ;
320
326
321
- data = find_xen_grant_dma_data (dev );
322
- if (data ) {
323
- dev_err (dev , "Xen grant DMA data is already created\n" );
324
- return ;
325
- }
326
-
327
- /* XXX ACPI device unsupported for now */
328
- if (!dev -> of_node )
329
- goto err ;
330
-
331
327
if (of_parse_phandle_with_args (dev -> of_node , "iommus" , "#iommu-cells" ,
332
328
0 , & iommu_spec )) {
333
329
dev_err (dev , "Cannot parse iommus property\n" );
334
- goto err ;
330
+ return - ESRCH ;
335
331
}
336
332
337
333
if (!of_device_is_compatible (iommu_spec .np , "xen,grant-dma" ) ||
338
334
iommu_spec .args_count != 1 ) {
339
335
dev_err (dev , "Incompatible IOMMU node\n" );
340
336
of_node_put (iommu_spec .np );
341
- goto err ;
337
+ return - ESRCH ;
342
338
}
343
339
344
340
of_node_put (iommu_spec .np );
345
341
342
+ /*
343
+ * The endpoint ID here means the ID of the domain where the
344
+ * corresponding backend is running
345
+ */
346
+ data -> backend_domid = iommu_spec .args [0 ];
347
+
348
+ return 0 ;
349
+ }
350
+
351
+ void xen_grant_setup_dma_ops (struct device * dev )
352
+ {
353
+ struct xen_grant_dma_data * data ;
354
+
355
+ data = find_xen_grant_dma_data (dev );
356
+ if (data ) {
357
+ dev_err (dev , "Xen grant DMA data is already created\n" );
358
+ return ;
359
+ }
360
+
346
361
data = devm_kzalloc (dev , sizeof (* data ), GFP_KERNEL );
347
362
if (!data )
348
363
goto err ;
349
364
350
- /*
351
- * The endpoint ID here means the ID of the domain where the corresponding
352
- * backend is running
353
- */
354
- data -> backend_domid = iommu_spec .args [0 ];
365
+ if (dev -> of_node ) {
366
+ if (xen_dt_grant_init_backend_domid (dev , data ))
367
+ goto err ;
368
+ } else {
369
+ /* XXX ACPI device unsupported for now */
370
+ goto err ;
371
+ }
355
372
356
373
if (store_xen_grant_dma_data (dev , data )) {
357
374
dev_err (dev , "Cannot store Xen grant DMA data\n" );
@@ -363,6 +380,7 @@ void xen_grant_setup_dma_ops(struct device *dev)
363
380
return ;
364
381
365
382
err :
383
+ devm_kfree (dev , data );
366
384
dev_err (dev , "Cannot set up Xen grant DMA ops, retain platform DMA ops\n" );
367
385
}
368
386
0 commit comments