mm.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include <linux/bootmem.h>
  2. #include <linux/gfp.h>
  3. #include <linux/export.h>
  4. #include <linux/slab.h>
  5. #include <linux/types.h>
  6. #include <linux/dma-mapping.h>
  7. #include <linux/vmalloc.h>
  8. #include <linux/swiotlb.h>
  9. #include <xen/xen.h>
  10. #include <xen/interface/memory.h>
  11. #include <xen/swiotlb-xen.h>
  12. #include <asm/cacheflush.h>
  13. #include <asm/xen/page.h>
  14. #include <asm/xen/hypercall.h>
  15. #include <asm/xen/interface.h>
  16. bool xen_arch_need_swiotlb(struct device *dev,
  17. unsigned long pfn,
  18. unsigned long mfn)
  19. {
  20. return (pfn != mfn);
  21. }
  22. int xen_create_contiguous_region(phys_addr_t pstart, unsigned int order,
  23. unsigned int address_bits,
  24. dma_addr_t *dma_handle)
  25. {
  26. if (!xen_initial_domain())
  27. return -EINVAL;
  28. /* we assume that dom0 is mapped 1:1 for now */
  29. *dma_handle = pstart;
  30. return 0;
  31. }
  32. EXPORT_SYMBOL_GPL(xen_create_contiguous_region);
  33. void xen_destroy_contiguous_region(phys_addr_t pstart, unsigned int order)
  34. {
  35. return;
  36. }
  37. EXPORT_SYMBOL_GPL(xen_destroy_contiguous_region);
  38. struct dma_map_ops *xen_dma_ops;
  39. EXPORT_SYMBOL_GPL(xen_dma_ops);
  40. static struct dma_map_ops xen_swiotlb_dma_ops = {
  41. .mapping_error = xen_swiotlb_dma_mapping_error,
  42. .alloc = xen_swiotlb_alloc_coherent,
  43. .free = xen_swiotlb_free_coherent,
  44. .sync_single_for_cpu = xen_swiotlb_sync_single_for_cpu,
  45. .sync_single_for_device = xen_swiotlb_sync_single_for_device,
  46. .sync_sg_for_cpu = xen_swiotlb_sync_sg_for_cpu,
  47. .sync_sg_for_device = xen_swiotlb_sync_sg_for_device,
  48. .map_sg = xen_swiotlb_map_sg_attrs,
  49. .unmap_sg = xen_swiotlb_unmap_sg_attrs,
  50. .map_page = xen_swiotlb_map_page,
  51. .unmap_page = xen_swiotlb_unmap_page,
  52. .dma_supported = xen_swiotlb_dma_supported,
  53. .set_dma_mask = xen_swiotlb_set_dma_mask,
  54. };
  55. int __init xen_mm_init(void)
  56. {
  57. if (!xen_initial_domain())
  58. return 0;
  59. xen_swiotlb_init(1, false);
  60. xen_dma_ops = &xen_swiotlb_dma_ops;
  61. return 0;
  62. }
  63. arch_initcall(xen_mm_init);