1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. 3 */ 4 #ifndef __LINUX_IOMMU_PRIV_H 5 #define __LINUX_IOMMU_PRIV_H 6 7 #include <linux/iommu.h> 8 #include <linux/msi.h> 9 10 static inline const struct iommu_ops *dev_iommu_ops(struct device *dev) 11 { 12 /* 13 * Assume that valid ops must be installed if iommu_probe_device() 14 * has succeeded. The device ops are essentially for internal use 15 * within the IOMMU subsystem itself, so we should be able to trust 16 * ourselves not to misuse the helper. 17 */ 18 return dev->iommu->iommu_dev->ops; 19 } 20 21 void dev_iommu_free(struct device *dev); 22 23 const struct iommu_ops *iommu_ops_from_fwnode(const struct fwnode_handle *fwnode); 24 25 static inline const struct iommu_ops *iommu_fwspec_ops(struct iommu_fwspec *fwspec) 26 { 27 return iommu_ops_from_fwnode(fwspec ? fwspec->iommu_fwnode : NULL); 28 } 29 30 void iommu_fwspec_free(struct device *dev); 31 32 int iommu_device_register_bus(struct iommu_device *iommu, 33 const struct iommu_ops *ops, 34 const struct bus_type *bus, 35 struct notifier_block *nb); 36 void iommu_device_unregister_bus(struct iommu_device *iommu, 37 const struct bus_type *bus, 38 struct notifier_block *nb); 39 40 struct iommu_attach_handle *iommu_attach_handle_get(struct iommu_group *group, 41 ioasid_t pasid, 42 unsigned int type); 43 int iommu_attach_group_handle(struct iommu_domain *domain, 44 struct iommu_group *group, 45 struct iommu_attach_handle *handle); 46 void iommu_detach_group_handle(struct iommu_domain *domain, 47 struct iommu_group *group); 48 int iommu_replace_group_handle(struct iommu_group *group, 49 struct iommu_domain *new_domain, 50 struct iommu_attach_handle *handle); 51 52 #if IS_ENABLED(CONFIG_IOMMUFD_DRIVER_CORE) && IS_ENABLED(CONFIG_IRQ_MSI_IOMMU) 53 int iommufd_sw_msi(struct iommu_domain *domain, struct msi_desc *desc, 54 phys_addr_t msi_addr); 55 #else /* !CONFIG_IOMMUFD_DRIVER_CORE || !CONFIG_IRQ_MSI_IOMMU */ 56 static inline int iommufd_sw_msi(struct iommu_domain *domain, 57 struct msi_desc *desc, phys_addr_t msi_addr) 58 { 59 return -EOPNOTSUPP; 60 } 61 #endif /* CONFIG_IOMMUFD_DRIVER_CORE && CONFIG_IRQ_MSI_IOMMU */ 62 63 int iommu_replace_device_pasid(struct iommu_domain *domain, 64 struct device *dev, ioasid_t pasid, 65 struct iommu_attach_handle *handle); 66 #endif /* __LINUX_IOMMU_PRIV_H */ 67