dma-swiotlb.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Contains routines needed to support swiotlb for ppc.
  3. *
  4. * Copyright (C) 2009-2010 Freescale Semiconductor, Inc.
  5. * Author: Becky Bruce
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. *
  12. */
  13. #include <linux/dma-mapping.h>
  14. #include <linux/pfn.h>
  15. #include <linux/of_platform.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/pci.h>
  18. #include <asm/machdep.h>
  19. #include <asm/swiotlb.h>
  20. #include <asm/dma.h>
  21. #include <asm/abs_addr.h>
  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_for_cpu = swiotlb_sync_single_for_cpu,
  39. .sync_single_for_device = swiotlb_sync_single_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) + 1) < memblock_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. int __init swiotlb_setup_bus_notifier(void)
  73. {
  74. bus_register_notifier(&platform_bus_type,
  75. &ppc_swiotlb_plat_bus_notifier);
  76. return 0;
  77. }