Skip to content

Commit c913311

Browse files
committed
xen/virtio: restructure xen grant dma setup
In order to prepare supporting other means than device tree for setting up virtio devices under Xen, restructure the functions xen_is_grant_dma_device() and xen_grant_setup_dma_ops() a little bit. Signed-off-by: Juergen Gross <[email protected]> Reviewed-by: Oleksandr Tyshchenko <[email protected]> Tested-by: Oleksandr Tyshchenko <[email protected]> # Arm64 only Acked-by: Stefano Stabellini <[email protected]> Signed-off-by: Juergen Gross <[email protected]>
1 parent 2849752 commit c913311

File tree

1 file changed

+43
-25
lines changed

1 file changed

+43
-25
lines changed

drivers/xen/grant-dma-ops.c

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -289,22 +289,28 @@ static const struct dma_map_ops xen_grant_dma_ops = {
289289
.dma_supported = xen_grant_dma_supported,
290290
};
291291

292-
bool xen_is_grant_dma_device(struct device *dev)
292+
static bool xen_is_dt_grant_dma_device(struct device *dev)
293293
{
294294
struct device_node *iommu_np;
295295
bool has_iommu;
296296

297-
/* XXX Handle only DT devices for now */
298-
if (!dev->of_node)
299-
return false;
300-
301297
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");
303300
of_node_put(iommu_np);
304301

305302
return has_iommu;
306303
}
307304

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+
308314
bool xen_virtio_mem_acc(struct virtio_device *dev)
309315
{
310316
if (IS_ENABLED(CONFIG_XEN_VIRTIO_FORCE_GRANT))
@@ -313,45 +319,56 @@ bool xen_virtio_mem_acc(struct virtio_device *dev)
313319
return xen_is_grant_dma_device(dev->dev.parent);
314320
}
315321

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)
317324
{
318-
struct xen_grant_dma_data *data;
319325
struct of_phandle_args iommu_spec;
320326

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-
331327
if (of_parse_phandle_with_args(dev->of_node, "iommus", "#iommu-cells",
332328
0, &iommu_spec)) {
333329
dev_err(dev, "Cannot parse iommus property\n");
334-
goto err;
330+
return -ESRCH;
335331
}
336332

337333
if (!of_device_is_compatible(iommu_spec.np, "xen,grant-dma") ||
338334
iommu_spec.args_count != 1) {
339335
dev_err(dev, "Incompatible IOMMU node\n");
340336
of_node_put(iommu_spec.np);
341-
goto err;
337+
return -ESRCH;
342338
}
343339

344340
of_node_put(iommu_spec.np);
345341

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+
346361
data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
347362
if (!data)
348363
goto err;
349364

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+
}
355372

356373
if (store_xen_grant_dma_data(dev, data)) {
357374
dev_err(dev, "Cannot store Xen grant DMA data\n");
@@ -363,6 +380,7 @@ void xen_grant_setup_dma_ops(struct device *dev)
363380
return;
364381

365382
err:
383+
devm_kfree(dev, data);
366384
dev_err(dev, "Cannot set up Xen grant DMA ops, retain platform DMA ops\n");
367385
}
368386

0 commit comments

Comments
 (0)