dma-swiotlb.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. int swiotlb __read_mostly;
  22. unsigned int ppc_swiotlb_enable;
  23. /*
  24. * At the moment, all platforms that use this code only require
  25. * swiotlb to be used if we're operating on HIGHMEM. Since
  26. * we don't ever call anything other than map_sg, unmap_sg,
  27. * map_page, and unmap_page on highmem, use normal dma_ops
  28. * for everything else.
  29. */
  30. struct dma_map_ops swiotlb_dma_ops = {
  31. .alloc_coherent = dma_direct_alloc_coherent,
  32. .free_coherent = dma_direct_free_coherent,
  33. .map_sg = swiotlb_map_sg_attrs,
  34. .unmap_sg = swiotlb_unmap_sg_attrs,
  35. .dma_supported = swiotlb_dma_supported,
  36. .map_page = swiotlb_map_page,
  37. .unmap_page = swiotlb_unmap_page,
  38. .sync_single_range_for_cpu = swiotlb_sync_single_range_for_cpu,
  39. .sync_single_range_for_device = swiotlb_sync_single_range_for_device,
  40. .sync_sg_for_cpu = swiotlb_sync_sg_for_cpu,
  41. .sync_sg_for_device = swiotlb_sync_sg_for_device,
  42. .mapping_error = swiotlb_dma_mapping_error,
  43. };
  44. void pci_dma_dev_setup_swiotlb(struct pci_dev *pdev)
  45. {
  46. struct pci_controller *hose;
  47. struct dev_archdata *sd;
  48. hose = pci_bus_to_host(pdev->bus);
  49. sd = &pdev->dev.archdata;
  50. sd->max_direct_dma_addr =
  51. hose->dma_window_base_cur + hose->dma_window_size;
  52. }
  53. static int ppc_swiotlb_bus_notify(struct notifier_block *nb,
  54. unsigned long action, void *data)
  55. {
  56. struct device *dev = data;
  57. struct dev_archdata *sd;
  58. /* We are only intereted in device addition */
  59. if (action != BUS_NOTIFY_ADD_DEVICE)
  60. return 0;
  61. sd = &dev->archdata;
  62. sd->max_direct_dma_addr = 0;
  63. /* May need to bounce if the device can't address all of DRAM */
  64. if (dma_get_mask(dev) < lmb_end_of_DRAM())
  65. set_dma_ops(dev, &swiotlb_dma_ops);
  66. return NOTIFY_DONE;
  67. }
  68. static struct notifier_block ppc_swiotlb_plat_bus_notifier = {
  69. .notifier_call = ppc_swiotlb_bus_notify,
  70. .priority = 0,
  71. };
  72. static struct notifier_block ppc_swiotlb_of_bus_notifier = {
  73. .notifier_call = ppc_swiotlb_bus_notify,
  74. .priority = 0,
  75. };
  76. int __init swiotlb_setup_bus_notifier(void)
  77. {
  78. bus_register_notifier(&platform_bus_type,
  79. &ppc_swiotlb_plat_bus_notifier);
  80. bus_register_notifier(&of_platform_bus_type,
  81. &ppc_swiotlb_of_bus_notifier);
  82. return 0;
  83. }