1 /*
2  * domain.h: HVM per domain definitions
3  *
4  * Copyright (c) 2004, Intel Corporation.
5  * Copyright (c) 2005, International Business Machines Corporation
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms and conditions of the GNU General Public License,
9  * version 2, as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * this program; If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef __ASM_X86_HVM_DOMAIN_H__
21 #define __ASM_X86_HVM_DOMAIN_H__
22 
23 #include <xen/list.h>
24 #include <xen/mm.h>
25 #include <xen/radix-tree.h>
26 
27 #include <asm/hvm/io.h>
28 #include <asm/hvm/vmx/vmcs.h>
29 #include <asm/hvm/svm/vmcb.h>
30 
31 #include <public/hvm/dm_op.h>
32 
33 struct hvm_ioreq_page {
34     gfn_t gfn;
35     struct page_info *page;
36     void *va;
37 };
38 
39 struct hvm_ioreq_vcpu {
40     struct list_head list_entry;
41     struct vcpu      *vcpu;
42     evtchn_port_t    ioreq_evtchn;
43     bool             pending;
44 };
45 
46 #define NR_IO_RANGE_TYPES (XEN_DMOP_IO_RANGE_PCI + 1)
47 #define MAX_NR_IO_RANGES  256
48 
49 struct hvm_ioreq_server {
50     struct domain          *target, *emulator;
51 
52     /* Lock to serialize toolstack modifications */
53     spinlock_t             lock;
54 
55     struct hvm_ioreq_page  ioreq;
56     struct list_head       ioreq_vcpu_list;
57     struct hvm_ioreq_page  bufioreq;
58 
59     /* Lock to serialize access to buffered ioreq ring */
60     spinlock_t             bufioreq_lock;
61     evtchn_port_t          bufioreq_evtchn;
62     struct rangeset        *range[NR_IO_RANGE_TYPES];
63     bool                   enabled;
64     uint8_t                bufioreq_handling;
65 };
66 
67 #ifdef CONFIG_MEM_SHARING
68 struct mem_sharing_domain
69 {
70     bool enabled, block_interrupts;
71 
72     /*
73      * When releasing shared gfn's in a preemptible manner, recall where
74      * to resume the search.
75      */
76     unsigned long next_shared_gfn_to_relinquish;
77 };
78 #endif
79 
80 /*
81  * This structure defines function hooks to support hardware-assisted
82  * virtual interrupt delivery to guest. (e.g. VMX PI and SVM AVIC).
83  *
84  * These hooks are defined by the underlying arch-specific code
85  * as needed. For example:
86  *   - When the domain is enabled with virtual IPI delivery
87  *   - When the domain is enabled with virtual I/O int delivery
88  *     and actually has a physical device assigned .
89  */
90 struct hvm_pi_ops {
91     unsigned int flags;
92 
93     /*
94      * Hook into arch_vcpu_block(), which is called
95      * from vcpu_block() and vcpu_do_poll().
96      */
97     void (*vcpu_block)(struct vcpu *);
98 };
99 
100 #define MAX_NR_IOREQ_SERVERS 8
101 
102 struct hvm_domain {
103     /* Guest page range used for non-default ioreq servers */
104     struct {
105         unsigned long base;
106         unsigned long mask; /* indexed by GFN minus base */
107         unsigned long legacy_mask; /* indexed by HVM param number */
108     } ioreq_gfn;
109 
110     /* Lock protects all other values in the sub-struct and the default */
111     struct {
112         spinlock_t              lock;
113         struct hvm_ioreq_server *server[MAX_NR_IOREQ_SERVERS];
114     } ioreq_server;
115 
116     /* Cached CF8 for guest PCI config cycles */
117     uint32_t                pci_cf8;
118 
119     struct pl_time         *pl_time;
120 
121     struct hvm_io_handler *io_handler;
122     unsigned int          io_handler_count;
123 
124     /* Lock protects access to irq, vpic and vioapic. */
125     spinlock_t             irq_lock;
126     struct hvm_irq        *irq;
127     struct hvm_hw_vpic     vpic[2]; /* 0=master; 1=slave */
128     struct hvm_vioapic    **vioapic;
129     unsigned int           nr_vioapics;
130     struct hvm_hw_stdvga   stdvga;
131 
132     /*
133      * hvm_hw_pmtimer is a publicly-visible name. We will defer renaming
134      * it to the more appropriate hvm_hw_acpi until the expected
135      * comprehensive rewrte of migration code, thus avoiding code churn
136      * in public header files.
137      * Internally, however, we will be using hvm_hw_acpi.
138      */
139 #define hvm_hw_acpi hvm_hw_pmtimer
140     struct hvm_hw_acpi     acpi;
141 
142     /* VCPU which is current target for 8259 interrupts. */
143     struct vcpu           *i8259_target;
144 
145     /* emulated irq to pirq */
146     struct radix_tree_root emuirq_pirq;
147 
148     uint64_t              *params;
149 
150     /* Memory ranges with pinned cache attributes. */
151     struct list_head       pinned_cacheattr_ranges;
152 
153     /* VRAM dirty support.  Protect with the domain paging lock. */
154     struct sh_dirty_vram *dirty_vram;
155 
156     /* If one of vcpus of this domain is in no_fill_mode or
157      * mtrr/pat between vcpus is not the same, set is_in_uc_mode
158      */
159     spinlock_t             uc_lock;
160     bool_t                 is_in_uc_mode;
161 
162     /* hypervisor intercepted msix table */
163     struct list_head       msixtbl_list;
164 
165     struct viridian_domain *viridian;
166 
167     bool_t                 qemu_mapcache_invalidate;
168     bool_t                 is_s3_suspended;
169 
170     /*
171      * TSC value that VCPUs use to calculate their tsc_offset value.
172      * Used during initialization and save/restore.
173      */
174     uint64_t sync_tsc;
175 
176     uint64_t tsc_scaling_ratio;
177 
178     unsigned long *io_bitmap;
179 
180     /* List of guest to machine IO ports mapping. */
181     struct list_head g2m_ioport_list;
182 
183     /* List of MMCFG regions trapped by Xen. */
184     struct list_head mmcfg_regions;
185     rwlock_t mmcfg_lock;
186 
187     /* List of MSI-X tables. */
188     struct list_head msix_tables;
189 
190     /* List of permanently write-mapped pages. */
191     struct {
192         spinlock_t lock;
193         struct list_head list;
194     } write_map;
195 
196     struct hvm_pi_ops pi_ops;
197 
198     union {
199         struct vmx_domain vmx;
200         struct svm_domain svm;
201     };
202 
203 #ifdef CONFIG_MEM_SHARING
204     struct mem_sharing_domain mem_sharing;
205 #endif
206 };
207 
208 #endif /* __ASM_X86_HVM_DOMAIN_H__ */
209 
210 /*
211  * Local variables:
212  * mode: C
213  * c-file-style: "BSD"
214  * c-basic-offset: 4
215  * tab-width: 4
216  * indent-tabs-mode: nil
217  * End:
218  */
219