pci-swiotlb-xen.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* Glue code to lib/swiotlb-xen.c */
  2. #include <linux/dma-mapping.h>
  3. #include <xen/swiotlb-xen.h>
  4. #include <asm/xen/hypervisor.h>
  5. #include <xen/xen.h>
  6. int xen_swiotlb __read_mostly;
  7. static struct dma_map_ops xen_swiotlb_dma_ops = {
  8. .mapping_error = xen_swiotlb_dma_mapping_error,
  9. .alloc_coherent = xen_swiotlb_alloc_coherent,
  10. .free_coherent = xen_swiotlb_free_coherent,
  11. .sync_single_for_cpu = xen_swiotlb_sync_single_for_cpu,
  12. .sync_single_for_device = xen_swiotlb_sync_single_for_device,
  13. .sync_sg_for_cpu = xen_swiotlb_sync_sg_for_cpu,
  14. .sync_sg_for_device = xen_swiotlb_sync_sg_for_device,
  15. .map_sg = xen_swiotlb_map_sg_attrs,
  16. .unmap_sg = xen_swiotlb_unmap_sg_attrs,
  17. .map_page = xen_swiotlb_map_page,
  18. .unmap_page = xen_swiotlb_unmap_page,
  19. .dma_supported = xen_swiotlb_dma_supported,
  20. };
  21. /*
  22. * pci_xen_swiotlb_detect - set xen_swiotlb to 1 if necessary
  23. *
  24. * This returns non-zero if we are forced to use xen_swiotlb (by the boot
  25. * option).
  26. */
  27. int __init pci_xen_swiotlb_detect(void)
  28. {
  29. /* If running as PV guest, either iommu=soft, or swiotlb=force will
  30. * activate this IOMMU. If running as PV privileged, activate it
  31. * irregardlesss.
  32. */
  33. if ((xen_initial_domain() || swiotlb || swiotlb_force) &&
  34. (xen_pv_domain()))
  35. xen_swiotlb = 1;
  36. /* If we are running under Xen, we MUST disable the native SWIOTLB.
  37. * Don't worry about swiotlb_force flag activating the native, as
  38. * the 'swiotlb' flag is the only one turning it on. */
  39. if (xen_pv_domain())
  40. swiotlb = 0;
  41. return xen_swiotlb;
  42. }
  43. void __init pci_xen_swiotlb_init(void)
  44. {
  45. if (xen_swiotlb) {
  46. xen_swiotlb_init(1);
  47. dma_ops = &xen_swiotlb_dma_ops;
  48. }
  49. }