iommu/vt-d: Implement SVM_FLAG_PRIVATE_PASID to allocate unique PASIDs
[deliverable/linux.git] / include / linux / intel-svm.h
CommitLineData
2f26e0a9
DW
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
21struct device;
22
0204a496
DW
23struct svm_dev_ops {
24 void (*fault_cb)(struct device *dev, int pasid, u64 address,
25 u32 private, int rwxp, int response);
26};
27
28/* Values for rxwp in fault_cb callback */
29#define SVM_REQ_READ (1<<3)
30#define SVM_REQ_WRITE (1<<2)
31#define SVM_REQ_EXEC (1<<1)
32#define SVM_REQ_PRIV (1<<0)
33
569e4f77
DW
34
35/*
36 * The SVM_FLAG_PRIVATE_PASID flag requests a PASID which is *not* the "main"
37 * PASID for the current process. Even if a PASID already exists, a new one
38 * will be allocated. And the PASID allocated with SVM_FLAG_PRIVATE_PASID
39 * will not be given to subsequent callers. This facility allows a driver to
40 * disambiguate between multiple device contexts which access the same MM,
41 * if there is no other way to do so. It should be used sparingly, if at all.
42 */
43#define SVM_FLAG_PRIVATE_PASID (1<<0)
44
2f26e0a9
DW
45/**
46 * intel_svm_bind_mm() - Bind the current process to a PASID
47 * @dev: Device to be granted acccess
48 * @pasid: Address for allocated PASID
0204a496
DW
49 * @flags: Flags. Later for requesting supervisor mode, etc.
50 * @ops: Callbacks to device driver
2f26e0a9
DW
51 *
52 * This function attempts to enable PASID support for the given device.
53 * If the @pasid argument is non-%NULL, a PASID is allocated for access
54 * to the MM of the current process.
55 *
56 * By using a %NULL value for the @pasid argument, this function can
57 * be used to simply validate that PASID support is available for the
58 * given device — i.e. that it is behind an IOMMU which has the
59 * requisite support, and is enabled.
60 *
61 * Page faults are handled transparently by the IOMMU code, and there
62 * should be no need for the device driver to be involved. If a page
63 * fault cannot be handled (i.e. is an invalid address rather than
64 * just needs paging in), then the page request will be completed by
65 * the core IOMMU code with appropriate status, and the device itself
66 * can then report the resulting fault to its driver via whatever
67 * mechanism is appropriate.
68 *
69 * Multiple calls from the same process may result in the same PASID
70 * being re-used. A reference count is kept.
71 */
0204a496
DW
72extern int intel_svm_bind_mm(struct device *dev, int *pasid, int flags,
73 struct svm_dev_ops *ops);
2f26e0a9
DW
74
75/**
76 * intel_svm_unbind_mm() - Unbind a specified PASID
77 * @dev: Device for which PASID was allocated
78 * @pasid: PASID value to be unbound
79 *
80 * This function allows a PASID to be retired when the device no
81 * longer requires access to the address space of a given process.
82 *
83 * If the use count for the PASID in question reaches zero, the
84 * PASID is revoked and may no longer be used by hardware.
85 *
86 * Device drivers are required to ensure that no access (including
87 * page requests) is currently outstanding for the PASID in question,
88 * before calling this function.
89 */
90extern int intel_svm_unbind_mm(struct device *dev, int pasid);
91
92#else /* CONFIG_INTEL_IOMMU_SVM */
93
0204a496
DW
94static inline int intel_svm_bind_mm(struct device *dev, int *pasid,
95 int flags, struct svm_dev_ops *ops)
2f26e0a9
DW
96{
97 return -ENOSYS;
98}
99
100static inline int intel_svm_unbind_mm(struct device *dev, int pasid)
101{
102 BUG();
103}
104#endif /* CONFIG_INTEL_IOMMU_SVM */
105
0204a496 106#define intel_svm_available(dev) (!intel_svm_bind_mm((dev), NULL, 0, NULL))
2f26e0a9
DW
107
108#endif /* __INTEL_SVM_H__ */
This page took 0.027775 seconds and 5 git commands to generate.