David Woodhouse | 2f26e0a | 2015-09-09 11:40:47 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright © 2015 Intel Corporation. |
| 3 | * |
| 4 | * Authors: David Woodhouse <David.Woodhouse@intel.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms and conditions of the GNU General Public License, |
| 8 | * version 2, as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | * more details. |
| 14 | */ |
| 15 | |
| 16 | #ifndef __INTEL_SVM_H__ |
| 17 | #define __INTEL_SVM_H__ |
| 18 | |
| 19 | #ifdef CONFIG_INTEL_IOMMU_SVM |
| 20 | |
| 21 | struct device; |
| 22 | |
| 23 | /** |
| 24 | * intel_svm_bind_mm() - Bind the current process to a PASID |
| 25 | * @dev: Device to be granted acccess |
| 26 | * @pasid: Address for allocated PASID |
| 27 | * |
| 28 | * This function attempts to enable PASID support for the given device. |
| 29 | * If the @pasid argument is non-%NULL, a PASID is allocated for access |
| 30 | * to the MM of the current process. |
| 31 | * |
| 32 | * By using a %NULL value for the @pasid argument, this function can |
| 33 | * be used to simply validate that PASID support is available for the |
| 34 | * given device — i.e. that it is behind an IOMMU which has the |
| 35 | * requisite support, and is enabled. |
| 36 | * |
| 37 | * Page faults are handled transparently by the IOMMU code, and there |
| 38 | * should be no need for the device driver to be involved. If a page |
| 39 | * fault cannot be handled (i.e. is an invalid address rather than |
| 40 | * just needs paging in), then the page request will be completed by |
| 41 | * the core IOMMU code with appropriate status, and the device itself |
| 42 | * can then report the resulting fault to its driver via whatever |
| 43 | * mechanism is appropriate. |
| 44 | * |
| 45 | * Multiple calls from the same process may result in the same PASID |
| 46 | * being re-used. A reference count is kept. |
| 47 | */ |
| 48 | extern int intel_svm_bind_mm(struct device *dev, int *pasid); |
| 49 | |
| 50 | /** |
| 51 | * intel_svm_unbind_mm() - Unbind a specified PASID |
| 52 | * @dev: Device for which PASID was allocated |
| 53 | * @pasid: PASID value to be unbound |
| 54 | * |
| 55 | * This function allows a PASID to be retired when the device no |
| 56 | * longer requires access to the address space of a given process. |
| 57 | * |
| 58 | * If the use count for the PASID in question reaches zero, the |
| 59 | * PASID is revoked and may no longer be used by hardware. |
| 60 | * |
| 61 | * Device drivers are required to ensure that no access (including |
| 62 | * page requests) is currently outstanding for the PASID in question, |
| 63 | * before calling this function. |
| 64 | */ |
| 65 | extern int intel_svm_unbind_mm(struct device *dev, int pasid); |
| 66 | |
| 67 | #else /* CONFIG_INTEL_IOMMU_SVM */ |
| 68 | |
| 69 | static inline int intel_svm_bind_mm(struct device *dev, int *pasid) |
| 70 | { |
| 71 | return -ENOSYS; |
| 72 | } |
| 73 | |
| 74 | static inline int intel_svm_unbind_mm(struct device *dev, int pasid) |
| 75 | { |
| 76 | BUG(); |
| 77 | } |
| 78 | #endif /* CONFIG_INTEL_IOMMU_SVM */ |
| 79 | |
| 80 | #define intel_svm_available(dev) (!intel_svm_bind_mm((dev), NULL)) |
| 81 | |
| 82 | #endif /* __INTEL_SVM_H__ */ |