Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

of: Move of_dma_configure() to device.c to help re-use

Move of_dma_configure() to device.c so it can be re-used for PCI devices to
obtain DMA configuration from DT. Also add a second argument so that for
PCI, the DT node of root bus host bridge can be used to obtain the DMA
configuration for the slave PCI device.

Tested-by: Suravee Suthikulpanit <Suravee.Suthikulpanit@amd.com> (AMD Seattle)
Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Acked-by: Will Deacon <will.deacon@arm.com>
Acked-by: Rob Herring <robh+dt@kernel.org>
CC: Joerg Roedel <joro@8bytes.org>
CC: Grant Likely <grant.likely@linaro.org>
CC: Russell King <linux@arm.linux.org.uk>
CC: Arnd Bergmann <arnd@arndb.de>

authored by

Murali Karicheri and committed by
Bjorn Helgaas
1f5c69aa ed748621

+64 -56
+59
drivers/of/device.c
··· 2 2 #include <linux/kernel.h> 3 3 #include <linux/of.h> 4 4 #include <linux/of_device.h> 5 + #include <linux/of_address.h> 6 + #include <linux/of_iommu.h> 7 + #include <linux/dma-mapping.h> 5 8 #include <linux/init.h> 6 9 #include <linux/module.h> 7 10 #include <linux/mod_devicetable.h> ··· 68 65 69 66 return device_add(&ofdev->dev); 70 67 } 68 + 69 + /** 70 + * of_dma_configure - Setup DMA configuration 71 + * @dev: Device to apply DMA configuration 72 + * @np: Pointer to OF node having DMA configuration 73 + * 74 + * Try to get devices's DMA configuration from DT and update it 75 + * accordingly. 76 + * 77 + * If platform code needs to use its own special DMA configuration, it 78 + * can use a platform bus notifier and handle BUS_NOTIFY_ADD_DEVICE events 79 + * to fix up DMA configuration. 80 + */ 81 + void of_dma_configure(struct device *dev, struct device_node *np) 82 + { 83 + u64 dma_addr, paddr, size; 84 + int ret; 85 + bool coherent; 86 + unsigned long offset; 87 + struct iommu_ops *iommu; 88 + 89 + /* 90 + * Set default dma-mask to 32 bit. Drivers are expected to setup 91 + * the correct supported dma_mask. 92 + */ 93 + dev->coherent_dma_mask = DMA_BIT_MASK(32); 94 + 95 + /* 96 + * Set it to coherent_dma_mask by default if the architecture 97 + * code has not set it. 98 + */ 99 + if (!dev->dma_mask) 100 + dev->dma_mask = &dev->coherent_dma_mask; 101 + 102 + ret = of_dma_get_range(np, &dma_addr, &paddr, &size); 103 + if (ret < 0) { 104 + dma_addr = offset = 0; 105 + size = dev->coherent_dma_mask; 106 + } else { 107 + offset = PFN_DOWN(paddr - dma_addr); 108 + dev_dbg(dev, "dma_pfn_offset(%#08lx)\n", offset); 109 + } 110 + 111 + dev->dma_pfn_offset = offset; 112 + 113 + coherent = of_dma_is_coherent(np); 114 + dev_dbg(dev, "device is%sdma coherent\n", 115 + coherent ? " " : " not "); 116 + 117 + iommu = of_iommu_configure(dev, np); 118 + dev_dbg(dev, "device is%sbehind an iommu\n", 119 + iommu ? " " : " not "); 120 + 121 + arch_setup_dma_ops(dev, dma_addr, size, iommu, coherent); 122 + } 123 + EXPORT_SYMBOL_GPL(of_dma_configure); 71 124 72 125 int of_device_register(struct platform_device *pdev) 73 126 {
+2 -56
drivers/of/platform.c
··· 19 19 #include <linux/slab.h> 20 20 #include <linux/of_address.h> 21 21 #include <linux/of_device.h> 22 - #include <linux/of_iommu.h> 23 22 #include <linux/of_irq.h> 24 23 #include <linux/of_platform.h> 25 24 #include <linux/platform_device.h> ··· 149 150 } 150 151 EXPORT_SYMBOL(of_device_alloc); 151 152 152 - /** 153 - * of_dma_configure - Setup DMA configuration 154 - * @dev: Device to apply DMA configuration 155 - * 156 - * Try to get devices's DMA configuration from DT and update it 157 - * accordingly. 158 - * 159 - * In case if platform code need to use own special DMA configuration,it 160 - * can use Platform bus notifier and handle BUS_NOTIFY_ADD_DEVICE event 161 - * to fix up DMA configuration. 162 - */ 163 - static void of_dma_configure(struct device *dev) 164 - { 165 - u64 dma_addr, paddr, size; 166 - int ret; 167 - bool coherent; 168 - unsigned long offset; 169 - struct iommu_ops *iommu; 170 - 171 - /* 172 - * Set default dma-mask to 32 bit. Drivers are expected to setup 173 - * the correct supported dma_mask. 174 - */ 175 - dev->coherent_dma_mask = DMA_BIT_MASK(32); 176 - 177 - /* 178 - * Set it to coherent_dma_mask by default if the architecture 179 - * code has not set it. 180 - */ 181 - if (!dev->dma_mask) 182 - dev->dma_mask = &dev->coherent_dma_mask; 183 - 184 - ret = of_dma_get_range(dev->of_node, &dma_addr, &paddr, &size); 185 - if (ret < 0) { 186 - dma_addr = offset = 0; 187 - size = dev->coherent_dma_mask; 188 - } else { 189 - offset = PFN_DOWN(paddr - dma_addr); 190 - dev_dbg(dev, "dma_pfn_offset(%#08lx)\n", offset); 191 - } 192 - dev->dma_pfn_offset = offset; 193 - 194 - coherent = of_dma_is_coherent(dev->of_node); 195 - dev_dbg(dev, "device is%sdma coherent\n", 196 - coherent ? " " : " not "); 197 - 198 - iommu = of_iommu_configure(dev, dev->of_node); 199 - dev_dbg(dev, "device is%sbehind an iommu\n", 200 - iommu ? " " : " not "); 201 - 202 - arch_setup_dma_ops(dev, dma_addr, size, iommu, coherent); 203 - } 204 - 205 153 static void of_dma_deconfigure(struct device *dev) 206 154 { 207 155 arch_teardown_dma_ops(dev); ··· 182 236 183 237 dev->dev.bus = &platform_bus_type; 184 238 dev->dev.platform_data = platform_data; 185 - of_dma_configure(&dev->dev); 239 + of_dma_configure(&dev->dev, dev->dev.of_node); 186 240 187 241 if (of_device_add(dev) != 0) { 188 242 of_dma_deconfigure(&dev->dev); ··· 245 299 dev_set_name(&dev->dev, "%s", bus_id); 246 300 else 247 301 of_device_make_bus_id(&dev->dev); 248 - of_dma_configure(&dev->dev); 302 + of_dma_configure(&dev->dev, dev->dev.of_node); 249 303 250 304 /* Allow the HW Peripheral ID to be overridden */ 251 305 prop = of_get_property(node, "arm,primecell-periphid", NULL);
+3
include/linux/of_device.h
··· 53 53 return of_node_get(cpu_dev->of_node); 54 54 } 55 55 56 + void of_dma_configure(struct device *dev, struct device_node *np); 56 57 #else /* CONFIG_OF */ 57 58 58 59 static inline int of_driver_match_device(struct device *dev, ··· 91 90 { 92 91 return NULL; 93 92 } 93 + static inline void of_dma_configure(struct device *dev, struct device_node *np) 94 + {} 94 95 #endif /* CONFIG_OF */ 95 96 96 97 #endif /* _LINUX_OF_DEVICE_H */