]> rtime.felk.cvut.cz Git - jailhouse.git/blob - hypervisor/arch/x86/include/asm/vtd.h
ecaf36916a7bfcd28c30c5c3aa6c3c2f30d248d8
[jailhouse.git] / hypervisor / arch / x86 / include / asm / vtd.h
1 /*
2  * Jailhouse, a Linux-based partitioning hypervisor
3  *
4  * Copyright (c) Siemens AG, 2013, 2014
5  *
6  * Authors:
7  *  Jan Kiszka <jan.kiszka@siemens.com>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2.  See
10  * the COPYING file in the top-level directory.
11  */
12
13 #ifndef _JAILHOUSE_ASM_VTD_H
14 #define _JAILHOUSE_ASM_VTD_H
15
16 #include <jailhouse/cell.h>
17 #include <jailhouse/pci.h>
18 #include <jailhouse/utils.h>
19 #include <asm/apic.h>
20
21 #include <jailhouse/cell-config.h>
22
23 #define VTD_ROOT_PRESENT                0x00000001
24
25 #define VTD_CTX_PRESENT                 0x00000001
26 #define VTD_CTX_FPD                     0x00000002
27 #define VTD_CTX_TTYPE_MLP_UNTRANS       0x00000000
28 #define VTD_CTX_TTYPE_MLP_ALL           0x00000004
29 #define VTD_CTX_TTYPE_PASSTHROUGH       0x00000008
30
31 #define VTD_CTX_AGAW_30                 0x00000000
32 #define VTD_CTX_AGAW_39                 0x00000001
33 #define VTD_CTX_AGAW_48                 0x00000002
34 #define VTD_CTX_AGAW_57                 0x00000003
35 #define VTD_CTX_AGAW_64                 0x00000004
36 #define VTD_CTX_DID_SHIFT               8
37
38 struct vtd_entry {
39         u64 lo_word;
40         u64 hi_word;
41 };
42
43 #define VTD_PAGE_READ                   0x00000001
44 #define VTD_PAGE_WRITE                  0x00000002
45
46 #define VTD_MAX_PAGE_TABLE_LEVELS       4
47
48 #define VTD_VER_REG                     0x00
49 # define VTD_VER_MASK                   BIT_MASK(7, 0)
50 # define VTD_VER_MIN                    0x10
51 #define VTD_CAP_REG                     0x08
52 # define VTD_CAP_NUM_DID_MASK           BIT_MASK(2, 0)
53 # define VTD_CAP_CM                     (1UL << 7)
54 # define VTD_CAP_SAGAW39                (1UL << 9)
55 # define VTD_CAP_SAGAW48                (1UL << 10)
56 # define VTD_CAP_SLLPS2M                (1UL << 34)
57 # define VTD_CAP_SLLPS1G                (1UL << 35)
58 # define VTD_CAP_FRO_MASK               BIT_MASK(33, 24)
59 #define  VTD_CAP_NFR_MASK               BIT_MASK(47, 40)
60 #define VTD_ECAP_REG                    0x10
61 # define VTD_ECAP_QI                    (1UL << 1)
62 # define VTD_ECAP_IR                    (1UL << 3)
63 # define VTD_ECAP_EIM                   (1UL << 4)
64 #define VTD_GCMD_REG                    0x18
65 # define VTD_GCMD_SIRTP                 (1UL << 24)
66 # define VTD_GCMD_IRE                   (1UL << 25)
67 # define VTD_GCMD_QIE                   (1UL << 26)
68 # define VTD_GCMD_SRTP                  (1UL << 30)
69 # define VTD_GCMD_TE                    (1UL << 31)
70 #define VTD_GSTS_REG                    0x1c
71 # define VTD_GSTS_IRES                  (1UL << 25)
72 # define VTD_GSTS_QIES                  (1UL << 26)
73 # define VTD_GSTS_TES                   (1UL << 31)
74 # define VTD_GSTS_USED_CTRLS \
75         (VTD_GSTS_IRES | VTD_GSTS_QIES | VTD_GSTS_TES)
76 #define VTD_RTADDR_REG                  0x20
77 #define VTD_FSTS_REG                    0x34
78 # define VTD_FSTS_PFO                   (1UL << 0)
79 # define VTD_FSTS_PFO_CLEAR             1
80 # define VTD_FSTS_PPF                   (1UL << 1)
81 # define VTD_FSTS_FRI_MASK              BIT_MASK(15, 8)
82 #define VTD_FECTL_REG                   0x38
83 #define  VTD_FECTL_IM                   (1UL << 31)
84 #define VTD_FEDATA_REG                  0x3c
85 #define VTD_FEADDR_REG                  0x40
86 #define VTD_FEUADDR_REG                 0x44
87 #define VTD_PMEN_REG                    0x64
88 #define VTD_PLMBASE_REG                 0x68
89 #define VTD_PLMLIMIT_REG                0x6c
90 #define VTD_PHMBASE_REG                 0x70
91 #define VTD_PHMLIMIT_REG                0x78
92 #define VTD_IQH_REG                     0x80
93 # define VTD_IQH_QH_SHIFT               4
94 #define VTD_IQT_REG                     0x88
95 # define VTD_IQT_QT_MASK                BIT_MASK(18, 4)
96 # define VTD_IQT_QT_SHIFT               4
97 #define VTD_IQA_REG                     0x90
98 # define VTD_IQA_ADDR_MASK              BIT_MASK(63, 12)
99 #define VTD_IRTA_REG                    0xb8
100 # define VTD_IRTA_SIZE_MASK             BIT_MASK(3, 0)
101 # define VTD_IRTA_EIME                  (1UL << 11)
102 # define VTD_IRTA_ADDR_MASK             BIT_MASK(63, 12)
103
104 #define VTD_REQ_INV_MASK                BIT_MASK(3, 0)
105
106 #define VTD_REQ_INV_CONTEXT             0x01
107 # define VTD_INV_CONTEXT_GLOBAL         (1UL << 4)
108 # define VTD_INV_CONTEXT_DOMAIN         (2UL << 4)
109 # define VTD_INV_CONTEXT_DOMAIN_SHIFT   16
110
111 #define VTD_REQ_INV_IOTLB               0x02
112 # define VTD_INV_IOTLB_GLOBAL           (1UL << 4)
113 # define VTD_INV_IOTLB_DOMAIN           (2UL << 4)
114 # define VTD_INV_IOTLB_DW               (1UL << 6)
115 # define VTD_INV_IOTLB_DR               (1UL << 7)
116 # define VTD_INV_IOTLB_DOMAIN_SHIFT     16
117
118 #define VTD_REQ_INV_INT                 0x04
119 # define VTD_INV_INT_GLOBAL             (0UL << 4)
120 # define VTD_INV_INT_INDEX              (1UL << 4)
121 # define VTD_INV_INT_IM_MASK            BIT_MASK(31, 27)
122 # define VTD_INV_INT_IM_SHIFT           27
123 # define VTD_INV_INT_IIDX_MASK          BIT_MASK(47, 32)
124 # define VTD_INV_INT_IIDX_SHIFT         32
125
126 #define VTD_REQ_INV_WAIT                0x05
127 #define  VTD_INV_WAIT_IF                (1UL << 4)
128 #define  VTD_INV_WAIT_SW                (1UL << 5)
129 #define  VTD_INV_WAIT_FN                (1UL << 6)
130 #define  VTD_INV_WAIT_SDATA_SHIFT       32
131
132 #define VTD_FRCD_LO_REG                 0x0
133 #define  VTD_FRCD_LO_FI_MASK            BIT_MASK(63, 12)
134 #define VTD_FRCD_HI_REG                 0x8
135 #define  VTD_FRCD_HI_SID_MASK           BIT_MASK(79-64, 64-64)
136 #define  VTD_FRCD_HI_FR_MASK            BIT_MASK(103-64, 96-64)
137 #define  VTD_FRCD_HI_TYPE               (1L << (126-64))
138 #define  VTD_FRCD_HI_F                  (1L << (127-64))
139 #define  VTD_FRCD_HI_F_CLEAR            1
140
141 union vtd_irte {
142         struct {
143                 u8 p:1;
144                 u8 fpd:1;
145                 u8 dest_logical:1;
146                 u8 redir_hint:1;
147                 u8 level_triggered:1;
148                 u8 delivery_mode:3;
149                 u8 assigned:1;
150                 u8 reserved:7;
151                 u8 vector;
152                 u8 reserved2;
153                 u32 destination;
154                 u16 sid;
155                 u16 sq:2;
156                 u16 svt:2;
157                 u16 reserved3:12;
158                 u32 reserved4;
159         } __attribute__((packed)) field;
160         u64 raw[2];
161 } __attribute__((packed));
162
163 #define VTD_IRTE_SQ_VERIFY_FULL_SID     0x0
164 #define VTD_IRTE_SVT_VERIFY_SID_SQ      0x1
165
166 #endif