1 /* SPDX-License-Identifier: GPL-2.0 */
3 * intel-pasid.h - PASID idr, table and entry header
5 * Copyright (C) 2018 Intel Corporation
7 * Author: Lu Baolu <baolu.lu@linux.intel.com>
10 #ifndef __INTEL_PASID_H
11 #define __INTEL_PASID_H
13 #define PASID_RID2PASID 0x0
15 #define PASID_MAX 0x100000
16 #define PASID_PTE_MASK 0x3F
17 #define PASID_PTE_PRESENT 1
18 #define PDE_PFN_MASK PAGE_MASK
19 #define PASID_PDE_SHIFT 6
20 #define MAX_NR_PASID_BITS 20
23 * Domain ID reserved for pasid entries programmed for first-level
24 * only and pass-through transfer modes.
26 #define FLPT_DEFAULT_DID 1
29 * The SUPERVISOR_MODE flag indicates a first level translation which
30 * can be used for access to kernel addresses. It is valid only for
31 * access to the kernel's static 1:1 mapping of physical memory — not
32 * to vmalloc or even module mappings.
34 #define PASID_FLAG_SUPERVISOR_MODE BIT(0)
36 struct pasid_dir_entry
{
44 /* The representative of a PASID table */
46 void *table
; /* pasid table pointer */
47 int order
; /* page order of pasid table */
48 int max_pasid
; /* max pasid */
49 struct list_head dev
; /* device list */
52 extern u32 intel_pasid_max_id
;
53 int intel_pasid_alloc_id(void *ptr
, int start
, int end
, gfp_t gfp
);
54 void intel_pasid_free_id(int pasid
);
55 void *intel_pasid_lookup_id(int pasid
);
56 int intel_pasid_alloc_table(struct device
*dev
);
57 void intel_pasid_free_table(struct device
*dev
);
58 struct pasid_table
*intel_pasid_get_table(struct device
*dev
);
59 int intel_pasid_get_dev_max_id(struct device
*dev
);
60 struct pasid_entry
*intel_pasid_get_entry(struct device
*dev
, int pasid
);
61 int intel_pasid_setup_first_level(struct intel_iommu
*iommu
,
62 struct device
*dev
, pgd_t
*pgd
,
63 int pasid
, u16 did
, int flags
);
64 int intel_pasid_setup_second_level(struct intel_iommu
*iommu
,
65 struct dmar_domain
*domain
,
66 struct device
*dev
, int pasid
);
67 int intel_pasid_setup_pass_through(struct intel_iommu
*iommu
,
68 struct dmar_domain
*domain
,
69 struct device
*dev
, int pasid
);
70 void intel_pasid_tear_down_entry(struct intel_iommu
*iommu
,
71 struct device
*dev
, int pasid
);
73 #endif /* __INTEL_PASID_H */