amd_iommu.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2009-2010 Advanced Micro Devices, Inc.
  4. * Author: Joerg Roedel <jroedel@suse.de>
  5. */
  6. #ifndef AMD_IOMMU_H
  7. #define AMD_IOMMU_H
  8. #include <linux/iommu.h>
  9. #include "amd_iommu_types.h"
  10. extern int amd_iommu_get_num_iommus(void);
  11. extern int amd_iommu_init_dma_ops(void);
  12. extern int amd_iommu_init_passthrough(void);
  13. extern irqreturn_t amd_iommu_int_thread(int irq, void *data);
  14. extern irqreturn_t amd_iommu_int_handler(int irq, void *data);
  15. extern void amd_iommu_apply_erratum_63(u16 devid);
  16. extern void amd_iommu_restart_event_logging(struct amd_iommu *iommu);
  17. extern void amd_iommu_reset_cmd_buffer(struct amd_iommu *iommu);
  18. extern int amd_iommu_init_devices(void);
  19. extern void amd_iommu_uninit_devices(void);
  20. extern void amd_iommu_init_notifier(void);
  21. extern int amd_iommu_init_api(void);
  22. #ifdef CONFIG_AMD_IOMMU_DEBUGFS
  23. void amd_iommu_debugfs_setup(struct amd_iommu *iommu);
  24. #else
  25. static inline void amd_iommu_debugfs_setup(struct amd_iommu *iommu) {}
  26. #endif
  27. /* Needed for interrupt remapping */
  28. extern int amd_iommu_prepare(void);
  29. extern int amd_iommu_enable(void);
  30. extern void amd_iommu_disable(void);
  31. extern int amd_iommu_reenable(int);
  32. extern int amd_iommu_enable_faulting(void);
  33. extern int amd_iommu_guest_ir;
  34. /* IOMMUv2 specific functions */
  35. struct iommu_domain;
  36. extern bool amd_iommu_v2_supported(void);
  37. extern struct amd_iommu *get_amd_iommu(unsigned int idx);
  38. extern u8 amd_iommu_pc_get_max_banks(unsigned int idx);
  39. extern bool amd_iommu_pc_supported(void);
  40. extern u8 amd_iommu_pc_get_max_counters(unsigned int idx);
  41. extern int amd_iommu_pc_get_reg(struct amd_iommu *iommu, u8 bank, u8 cntr,
  42. u8 fxn, u64 *value);
  43. extern int amd_iommu_pc_set_reg(struct amd_iommu *iommu, u8 bank, u8 cntr,
  44. u8 fxn, u64 *value);
  45. extern int amd_iommu_register_ppr_notifier(struct notifier_block *nb);
  46. extern int amd_iommu_unregister_ppr_notifier(struct notifier_block *nb);
  47. extern void amd_iommu_domain_direct_map(struct iommu_domain *dom);
  48. extern int amd_iommu_domain_enable_v2(struct iommu_domain *dom, int pasids);
  49. extern int amd_iommu_flush_page(struct iommu_domain *dom, u32 pasid,
  50. u64 address);
  51. extern int amd_iommu_flush_tlb(struct iommu_domain *dom, u32 pasid);
  52. extern int amd_iommu_domain_set_gcr3(struct iommu_domain *dom, u32 pasid,
  53. unsigned long cr3);
  54. extern int amd_iommu_domain_clear_gcr3(struct iommu_domain *dom, u32 pasid);
  55. extern struct iommu_domain *amd_iommu_get_v2_domain(struct pci_dev *pdev);
  56. #ifdef CONFIG_IRQ_REMAP
  57. extern int amd_iommu_create_irq_domain(struct amd_iommu *iommu);
  58. #else
  59. static inline int amd_iommu_create_irq_domain(struct amd_iommu *iommu)
  60. {
  61. return 0;
  62. }
  63. #endif
  64. #define PPR_SUCCESS 0x0
  65. #define PPR_INVALID 0x1
  66. #define PPR_FAILURE 0xf
  67. extern int amd_iommu_complete_ppr(struct pci_dev *pdev, u32 pasid,
  68. int status, int tag);
  69. static inline bool is_rd890_iommu(struct pci_dev *pdev)
  70. {
  71. return (pdev->vendor == PCI_VENDOR_ID_ATI) &&
  72. (pdev->device == PCI_DEVICE_ID_RD890_IOMMU);
  73. }
  74. static inline bool iommu_feature(struct amd_iommu *iommu, u64 mask)
  75. {
  76. return !!(iommu->features & mask);
  77. }
  78. static inline u64 iommu_virt_to_phys(void *vaddr)
  79. {
  80. return (u64)__sme_set(virt_to_phys(vaddr));
  81. }
  82. static inline void *iommu_phys_to_virt(unsigned long paddr)
  83. {
  84. return phys_to_virt(__sme_clr(paddr));
  85. }
  86. extern bool translation_pre_enabled(struct amd_iommu *iommu);
  87. extern bool amd_iommu_is_attach_deferred(struct iommu_domain *domain,
  88. struct device *dev);
  89. extern int __init add_special_device(u8 type, u8 id, u16 *devid,
  90. bool cmd_line);
  91. #ifdef CONFIG_DMI
  92. void amd_iommu_apply_ivrs_quirks(void);
  93. #else
  94. static inline void amd_iommu_apply_ivrs_quirks(void) { }
  95. #endif
  96. #endif