|
22 | 22 | #include <linux/slab.h>
|
23 | 23 | #include <linux/dma-mapping.h>
|
24 | 24 | #include <linux/dma-contiguous.h>
|
| 25 | +#include <linux/of.h> |
| 26 | +#include <linux/platform_device.h> |
25 | 27 | #include <linux/vmalloc.h>
|
26 | 28 | #include <linux/swiotlb.h>
|
| 29 | +#include <linux/amba/bus.h> |
27 | 30 |
|
28 | 31 | #include <asm/cacheflush.h>
|
29 | 32 |
|
@@ -305,17 +308,45 @@ struct dma_map_ops coherent_swiotlb_dma_ops = {
|
305 | 308 | };
|
306 | 309 | EXPORT_SYMBOL(coherent_swiotlb_dma_ops);
|
307 | 310 |
|
| 311 | +static int dma_bus_notifier(struct notifier_block *nb, |
| 312 | + unsigned long event, void *_dev) |
| 313 | +{ |
| 314 | + struct device *dev = _dev; |
| 315 | + |
| 316 | + if (event != BUS_NOTIFY_ADD_DEVICE) |
| 317 | + return NOTIFY_DONE; |
| 318 | + |
| 319 | + if (of_property_read_bool(dev->of_node, "dma-coherent")) |
| 320 | + set_dma_ops(dev, &coherent_swiotlb_dma_ops); |
| 321 | + |
| 322 | + return NOTIFY_OK; |
| 323 | +} |
| 324 | + |
| 325 | +static struct notifier_block platform_bus_nb = { |
| 326 | + .notifier_call = dma_bus_notifier, |
| 327 | +}; |
| 328 | + |
| 329 | +static struct notifier_block amba_bus_nb = { |
| 330 | + .notifier_call = dma_bus_notifier, |
| 331 | +}; |
| 332 | + |
308 | 333 | extern int swiotlb_late_init_with_default_size(size_t default_size);
|
309 | 334 |
|
310 | 335 | static int __init swiotlb_late_init(void)
|
311 | 336 | {
|
312 | 337 | size_t swiotlb_size = min(SZ_64M, MAX_ORDER_NR_PAGES << PAGE_SHIFT);
|
313 | 338 |
|
| 339 | + /* |
| 340 | + * These must be registered before of_platform_populate(). |
| 341 | + */ |
| 342 | + bus_register_notifier(&platform_bus_type, &platform_bus_nb); |
| 343 | + bus_register_notifier(&amba_bustype, &amba_bus_nb); |
| 344 | + |
314 | 345 | dma_ops = &noncoherent_swiotlb_dma_ops;
|
315 | 346 |
|
316 | 347 | return swiotlb_late_init_with_default_size(swiotlb_size);
|
317 | 348 | }
|
318 |
| -subsys_initcall(swiotlb_late_init); |
| 349 | +arch_initcall(swiotlb_late_init); |
319 | 350 |
|
320 | 351 | #define PREALLOC_DMA_DEBUG_ENTRIES 4096
|
321 | 352 |
|
|
0 commit comments