pci-swiotlb-xen.c 1.8 KB

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