dma-swiotlb.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Contains routines needed to support swiotlb for ppc.
  3. *
  4. * Copyright (C) 2009 Becky Bruce, Freescale Semiconductor
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. *
  11. */
  12. #include <linux/dma-mapping.h>
  13. #include <linux/pfn.h>
  14. #include <linux/of_platform.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/pci.h>
  17. #include <asm/machdep.h>
  18. #include <asm/swiotlb.h>
  19. #include <asm/dma.h>
  20. #include <asm/abs_addr.h>
  21. unsigned int ppc_swiotlb_enable;
  22. /*
  23. * At the moment, all platforms that use this code only require
  24. * swiotlb to be used if we're operating on HIGHMEM. Since
  25. * we don't ever call anything other than map_sg, unmap_sg,
  26. * map_page, and unmap_page on highmem, use normal dma_ops
  27. * for everything else.
  28. */
  29. struct dma_map_ops swiotlb_dma_ops = {
  30. .alloc_coherent = dma_direct_alloc_coherent,
  31. .free_coherent = dma_direct_free_coherent,
  32. .map_sg = swiotlb_map_sg_attrs,
  33. .unmap_sg = swiotlb_unmap_sg_attrs,
  34. .dma_supported = swiotlb_dma_supported,
  35. .map_page = swiotlb_map_page,
  36. .unmap_page = swiotlb_unmap_page,
  37. .sync_single_range_for_cpu = swiotlb_sync_single_range_for_cpu,
  38. .sync_single_range_for_device = swiotlb_sync_single_range_for_device,
  39. .sync_sg_for_cpu = swiotlb_sync_sg_for_cpu,
  40. .sync_sg_for_device = swiotlb_sync_sg_for_device,
  41. .mapping_error = swiotlb_dma_mapping_error,
  42. };
  43. void pci_dma_dev_setup_swiotlb(struct pci_dev *pdev)
  44. {
  45. struct pci_controller *hose;
  46. struct dev_archdata *sd;
  47. hose = pci_bus_to_host(pdev->bus);
  48. sd = &pdev->dev.archdata;
  49. sd->max_direct_dma_addr =
  50. hose->dma_window_base_cur + hose->dma_window_size;
  51. }
  52. static int ppc_swiotlb_bus_notify(struct notifier_block *nb,
  53. unsigned long action, void *data)
  54. {
  55. struct device *dev = data;
  56. struct dev_archdata *sd;
  57. /* We are only intereted in device addition */
  58. if (action != BUS_NOTIFY_ADD_DEVICE)
  59. return 0;
  60. sd = &dev->archdata;
  61. sd->max_direct_dma_addr = 0;
  62. /* May need to bounce if the device can't address all of DRAM */
  63. if (dma_get_mask(dev) < lmb_end_of_DRAM())
  64. set_dma_ops(dev, &swiotlb_dma_ops);
  65. return NOTIFY_DONE;
  66. }
  67. static struct notifier_block ppc_swiotlb_plat_bus_notifier = {
  68. .notifier_call = ppc_swiotlb_bus_notify,
  69. .priority = 0,
  70. };
  71. static struct notifier_block ppc_swiotlb_of_bus_notifier = {
  72. .notifier_call = ppc_swiotlb_bus_notify,
  73. .priority = 0,
  74. };
  75. int __init swiotlb_setup_bus_notifier(void)
  76. {
  77. bus_register_notifier(&platform_bus_type,
  78. &ppc_swiotlb_plat_bus_notifier);
  79. bus_register_notifier(&of_platform_bus_type,
  80. &ppc_swiotlb_of_bus_notifier);
  81. return 0;
  82. }