of: Add plumbing for restricted DMA pool

If a device is not behind an IOMMU, we look up the device node and set
up the restricted DMA when the restricted-dma-pool is presented.

Signed-off-by: Claire Chang <tientzu@chromium.org>
Tested-by: Stefano Stabellini <sstabellini@kernel.org>
Tested-by: Will Deacon <will@kernel.org>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
This commit is contained in:
Claire Chang 2021-06-19 11:40:43 +08:00 коммит произвёл Konrad Rzeszutek Wilk
Родитель b12fe99954
Коммит fec9b62509
3 изменённых файлов: 42 добавлений и 0 удалений

Просмотреть файл

@ -8,6 +8,7 @@
#include <linux/logic_pio.h> #include <linux/logic_pio.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/of_address.h> #include <linux/of_address.h>
#include <linux/of_reserved_mem.h>
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/pci_regs.h> #include <linux/pci_regs.h>
#include <linux/sizes.h> #include <linux/sizes.h>
@ -995,6 +996,38 @@ out:
of_node_put(node); of_node_put(node);
return ret; return ret;
} }
int of_dma_set_restricted_buffer(struct device *dev, struct device_node *np)
{
struct device_node *node, *of_node = dev->of_node;
int count, i;
count = of_property_count_elems_of_size(of_node, "memory-region",
sizeof(u32));
/*
* If dev->of_node doesn't exist or doesn't contain memory-region, try
* the OF node having DMA configuration.
*/
if (count <= 0) {
of_node = np;
count = of_property_count_elems_of_size(
of_node, "memory-region", sizeof(u32));
}
for (i = 0; i < count; i++) {
node = of_parse_phandle(of_node, "memory-region", i);
/*
* There might be multiple memory regions, but only one
* restricted-dma-pool region is allowed.
*/
if (of_device_is_compatible(node, "restricted-dma-pool") &&
of_device_is_available(node))
return of_reserved_mem_device_init_by_idx(dev, of_node,
i);
}
return 0;
}
#endif /* CONFIG_HAS_DMA */ #endif /* CONFIG_HAS_DMA */
/** /**

Просмотреть файл

@ -165,6 +165,9 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
arch_setup_dma_ops(dev, dma_start, size, iommu, coherent); arch_setup_dma_ops(dev, dma_start, size, iommu, coherent);
if (!iommu)
return of_dma_set_restricted_buffer(dev, np);
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(of_dma_configure_id); EXPORT_SYMBOL_GPL(of_dma_configure_id);

Просмотреть файл

@ -163,12 +163,18 @@ struct bus_dma_region;
#if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_HAS_DMA) #if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_HAS_DMA)
int of_dma_get_range(struct device_node *np, int of_dma_get_range(struct device_node *np,
const struct bus_dma_region **map); const struct bus_dma_region **map);
int of_dma_set_restricted_buffer(struct device *dev, struct device_node *np);
#else #else
static inline int of_dma_get_range(struct device_node *np, static inline int of_dma_get_range(struct device_node *np,
const struct bus_dma_region **map) const struct bus_dma_region **map)
{ {
return -ENODEV; return -ENODEV;
} }
static inline int of_dma_set_restricted_buffer(struct device *dev,
struct device_node *np)
{
return -ENODEV;
}
#endif #endif
void fdt_init_reserved_mem(void); void fdt_init_reserved_mem(void);