mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2024-12-29 17:23:36 +00:00
xen/grant-dma-ops: Retrieve the ID of backend's domain for DT devices
Use the presence of "iommus" property pointed to the IOMMU node with recently introduced "xen,grant-dma" compatible as a clear indicator of enabling Xen grant mappings scheme for that device and read the ID of Xen domain where the corresponding backend is running. The domid (domain ID) is used as an argument to the Xen grant mapping APIs. To avoid the deferred probe timeout which takes place after reusing generic IOMMU device tree bindings (because the IOMMU device never becomes available) enable recently introduced stub IOMMU driver by selecting XEN_GRANT_DMA_IOMMU. Also introduce xen_is_grant_dma_device() to check whether xen-grant DMA ops need to be set for a passed device. Remove the hardcoded domid 0 in xen_grant_setup_dma_ops(). Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org> Link: https://lore.kernel.org/r/1654197833-25362-8-git-send-email-olekstysh@gmail.com Signed-off-by: Juergen Gross <jgross@suse.com>
This commit is contained in:
parent
1ca55d50e5
commit
625ab90ecd
@ -347,6 +347,7 @@ config XEN_VIRTIO
|
||||
bool "Xen virtio support"
|
||||
depends on VIRTIO
|
||||
select XEN_GRANT_DMA_OPS
|
||||
select XEN_GRANT_DMA_IOMMU if OF
|
||||
help
|
||||
Enable virtio support for running as Xen guest. Depending on the
|
||||
guest type this will require special support on the backend side
|
||||
|
@ -56,11 +56,6 @@ static struct xen_grant_dma_data *find_xen_grant_dma_data(struct device *dev)
|
||||
* Such a DMA address is formed by using the grant reference as a frame
|
||||
* number and setting the highest address bit (this bit is for the backend
|
||||
* to be able to distinguish it from e.g. a mmio address).
|
||||
*
|
||||
* Note that for now we hard wire dom0 to be the backend domain. In order
|
||||
* to support any domain as backend we'd need to add a way to communicate
|
||||
* the domid of this backend, e.g. via Xenstore, via the PCI-device's
|
||||
* config space or DT/ACPI.
|
||||
*/
|
||||
static void *xen_grant_dma_alloc(struct device *dev, size_t size,
|
||||
dma_addr_t *dma_handle, gfp_t gfp,
|
||||
@ -276,9 +271,26 @@ static const struct dma_map_ops xen_grant_dma_ops = {
|
||||
.dma_supported = xen_grant_dma_supported,
|
||||
};
|
||||
|
||||
bool xen_is_grant_dma_device(struct device *dev)
|
||||
{
|
||||
struct device_node *iommu_np;
|
||||
bool has_iommu;
|
||||
|
||||
/* XXX Handle only DT devices for now */
|
||||
if (!dev->of_node)
|
||||
return false;
|
||||
|
||||
iommu_np = of_parse_phandle(dev->of_node, "iommus", 0);
|
||||
has_iommu = iommu_np && of_device_is_compatible(iommu_np, "xen,grant-dma");
|
||||
of_node_put(iommu_np);
|
||||
|
||||
return has_iommu;
|
||||
}
|
||||
|
||||
void xen_grant_setup_dma_ops(struct device *dev)
|
||||
{
|
||||
struct xen_grant_dma_data *data;
|
||||
struct of_phandle_args iommu_spec;
|
||||
|
||||
data = find_xen_grant_dma_data(dev);
|
||||
if (data) {
|
||||
@ -286,12 +298,34 @@ void xen_grant_setup_dma_ops(struct device *dev)
|
||||
return;
|
||||
}
|
||||
|
||||
/* XXX ACPI device unsupported for now */
|
||||
if (!dev->of_node)
|
||||
goto err;
|
||||
|
||||
if (of_parse_phandle_with_args(dev->of_node, "iommus", "#iommu-cells",
|
||||
0, &iommu_spec)) {
|
||||
dev_err(dev, "Cannot parse iommus property\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!of_device_is_compatible(iommu_spec.np, "xen,grant-dma") ||
|
||||
iommu_spec.args_count != 1) {
|
||||
dev_err(dev, "Incompatible IOMMU node\n");
|
||||
of_node_put(iommu_spec.np);
|
||||
goto err;
|
||||
}
|
||||
|
||||
of_node_put(iommu_spec.np);
|
||||
|
||||
data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
|
||||
if (!data)
|
||||
goto err;
|
||||
|
||||
/* XXX The dom0 is hardcoded as the backend domain for now */
|
||||
data->backend_domid = 0;
|
||||
/*
|
||||
* The endpoint ID here means the ID of the domain where the corresponding
|
||||
* backend is running
|
||||
*/
|
||||
data->backend_domid = iommu_spec.args[0];
|
||||
|
||||
if (xa_err(xa_store(&xen_grant_dma_devices, (unsigned long)dev, data,
|
||||
GFP_KERNEL))) {
|
||||
|
@ -216,10 +216,15 @@ static inline void xen_preemptible_hcall_end(void) { }
|
||||
|
||||
#ifdef CONFIG_XEN_GRANT_DMA_OPS
|
||||
void xen_grant_setup_dma_ops(struct device *dev);
|
||||
bool xen_is_grant_dma_device(struct device *dev);
|
||||
#else
|
||||
static inline void xen_grant_setup_dma_ops(struct device *dev)
|
||||
{
|
||||
}
|
||||
static inline bool xen_is_grant_dma_device(struct device *dev)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif /* CONFIG_XEN_GRANT_DMA_OPS */
|
||||
|
||||
#endif /* INCLUDE_XEN_OPS_H */
|
||||
|
Loading…
Reference in New Issue
Block a user