blob: 55bb8715329d8971ac1e3446bd03ab2d8bd1b5a0 [file] [log] [blame]
Lu Baolu56283172018-07-14 15:46:54 +08001/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * intel-pasid.h - PASID idr, table and entry header
4 *
5 * Copyright (C) 2018 Intel Corporation
6 *
7 * Author: Lu Baolu <baolu.lu@linux.intel.com>
8 */
9
10#ifndef __INTEL_PASID_H
11#define __INTEL_PASID_H
12
Lu Baoluef848b72018-12-10 09:59:01 +080013#define PASID_RID2PASID 0x0
Lu Baolu56283172018-07-14 15:46:54 +080014#define PASID_MIN 0x1
Lu Baolu0bbeb012018-12-10 09:58:56 +080015#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
Lu Baolu7373a8c2018-12-10 09:59:03 +080020#define MAX_NR_PASID_BITS 20
Lu Baolu0bbeb012018-12-10 09:58:56 +080021
Lu Baolu3b33d4a2018-12-10 09:58:59 +080022/*
23 * Domain ID reserved for pasid entries programmed for first-level
24 * only and pass-through transfer modes.
25 */
26#define FLPT_DEFAULT_DID 1
27
Lu Baolu0bbeb012018-12-10 09:58:56 +080028struct pasid_dir_entry {
29 u64 val;
30};
Lu Baolu56283172018-07-14 15:46:54 +080031
Lu Baolucc580e42018-07-14 15:46:59 +080032struct pasid_entry {
Lu Baolu0bbeb012018-12-10 09:58:56 +080033 u64 val[8];
Lu Baolucc580e42018-07-14 15:46:59 +080034};
35
36/* The representative of a PASID table */
37struct pasid_table {
38 void *table; /* pasid table pointer */
39 int order; /* page order of pasid table */
40 int max_pasid; /* max pasid */
41 struct list_head dev; /* device list */
42};
43
Lu Baolu56283172018-07-14 15:46:54 +080044extern u32 intel_pasid_max_id;
45int intel_pasid_alloc_id(void *ptr, int start, int end, gfp_t gfp);
46void intel_pasid_free_id(int pasid);
47void *intel_pasid_lookup_id(int pasid);
Lu Baolucc580e42018-07-14 15:46:59 +080048int intel_pasid_alloc_table(struct device *dev);
49void intel_pasid_free_table(struct device *dev);
50struct pasid_table *intel_pasid_get_table(struct device *dev);
51int intel_pasid_get_dev_max_id(struct device *dev);
52struct pasid_entry *intel_pasid_get_entry(struct device *dev, int pasid);
53void intel_pasid_clear_entry(struct device *dev, int pasid);
Lu Baolu6f7db752018-12-10 09:59:00 +080054int intel_pasid_setup_second_level(struct intel_iommu *iommu,
55 struct dmar_domain *domain,
56 struct device *dev, int pasid);
57int intel_pasid_setup_pass_through(struct intel_iommu *iommu,
58 struct dmar_domain *domain,
59 struct device *dev, int pasid);
60void intel_pasid_tear_down_entry(struct intel_iommu *iommu,
61 struct device *dev, int pasid);
Lu Baolu56283172018-07-14 15:46:54 +080062
63#endif /* __INTEL_PASID_H */