]> rtime.felk.cvut.cz Git - jailhouse.git/blob - hypervisor/include/jailhouse/cell-config.h
core, configs, tools: Introduce struct jailhouse_iommu
[jailhouse.git] / hypervisor / include / jailhouse / cell-config.h
1 /*
2  * Jailhouse, a Linux-based partitioning hypervisor
3  *
4  * Copyright (c) Siemens AG, 2014-2016
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  * Alternatively, you can use or redistribute this file under the following
13  * BSD license:
14  *
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions
17  * are met:
18  *
19  * 1. Redistributions of source code must retain the above copyright
20  *    notice, this list of conditions and the following disclaimer.
21  *
22  * 2. Redistributions in binary form must reproduce the above copyright
23  *    notice, this list of conditions and the following disclaimer in the
24  *    documentation and/or other materials provided with the distribution.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
30  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
36  * THE POSSIBILITY OF SUCH DAMAGE.
37  */
38
39 #ifndef _JAILHOUSE_CELL_CONFIG_H
40 #define _JAILHOUSE_CELL_CONFIG_H
41
42 #define JAILHOUSE_CELL_NAME_MAXLEN      31
43
44 #define JAILHOUSE_CELL_PASSIVE_COMMREG  0x00000001
45
46 #define JAILHOUSE_CELL_DESC_SIGNATURE   "JAILCELL"
47
48 struct jailhouse_cell_desc {
49         char signature[8];
50         char name[JAILHOUSE_CELL_NAME_MAXLEN+1];
51         __u32 flags;
52
53         __u32 cpu_set_size;
54         __u32 num_memory_regions;
55         __u32 num_cache_regions;
56         __u32 num_irqchips;
57         __u32 pio_bitmap_size;
58         __u32 num_pci_devices;
59         __u32 num_pci_caps;
60 } __attribute__((packed));
61
62 #define JAILHOUSE_MEM_READ              0x0001
63 #define JAILHOUSE_MEM_WRITE             0x0002
64 #define JAILHOUSE_MEM_EXECUTE           0x0004
65 #define JAILHOUSE_MEM_DMA               0x0008
66 #define JAILHOUSE_MEM_IO                0x0010
67 #define JAILHOUSE_MEM_COMM_REGION       0x0020
68 #define JAILHOUSE_MEM_LOADABLE          0x0040
69 #define JAILHOUSE_MEM_ROOTSHARED        0x0080
70 #define JAILHOUSE_MEM_IO_UNALIGNED      0x0100
71 #define JAILHOUSE_MEM_IO_WIDTH_SHIFT    16 /* uses bits 8..11 */
72 #define JAILHOUSE_MEM_IO_8              (1 << JAILHOUSE_MEM_IO_WIDTH_SHIFT)
73 #define JAILHOUSE_MEM_IO_16             (2 << JAILHOUSE_MEM_IO_WIDTH_SHIFT)
74 #define JAILHOUSE_MEM_IO_32             (4 << JAILHOUSE_MEM_IO_WIDTH_SHIFT)
75 #define JAILHOUSE_MEM_IO_64             (8 << JAILHOUSE_MEM_IO_WIDTH_SHIFT)
76
77 struct jailhouse_memory {
78         __u64 phys_start;
79         __u64 virt_start;
80         __u64 size;
81         __u64 flags;
82 } __attribute__((packed));
83
84 #define JAILHOUSE_MEMORY_IS_SUBPAGE(mem)        \
85         ((mem)->virt_start & ~PAGE_MASK || (mem)->size & ~PAGE_MASK)
86
87 #define JAILHOUSE_CACHE_L3_CODE         0x01
88 #define JAILHOUSE_CACHE_L3_DATA         0x02
89 #define JAILHOUSE_CACHE_L3              (JAILHOUSE_CACHE_L3_CODE | \
90                                          JAILHOUSE_CACHE_L3_DATA)
91
92 #define JAILHOUSE_CACHE_ROOTSHARED      0x0001
93
94 struct jailhouse_cache {
95         __u32 start;
96         __u32 size;
97         __u8 type;
98         __u8 padding;
99         __u16 flags;
100 } __attribute__((packed));
101
102 struct jailhouse_irqchip {
103         __u64 address;
104         __u64 id;
105         __u64 pin_bitmap;
106 } __attribute__((packed));
107
108 #define JAILHOUSE_PCI_TYPE_DEVICE       0x01
109 #define JAILHOUSE_PCI_TYPE_BRIDGE       0x02
110 #define JAILHOUSE_PCI_TYPE_IVSHMEM      0x03
111
112 struct jailhouse_pci_device {
113         __u8 type;
114         __u8 iommu;
115         __u16 domain;
116         __u16 bdf;
117         __u32 bar_mask[6];
118         __u16 caps_start;
119         __u16 num_caps;
120         __u8 num_msi_vectors;
121         __u8 msi_64bits;
122         __u16 num_msix_vectors;
123         __u16 msix_region_size;
124         __u64 msix_address;
125         /** used to refer to memory in virtual PCI devices */
126         __u32 shmem_region;
127 } __attribute__((packed));
128
129 #define JAILHOUSE_PCI_EXT_CAP           0x8000
130
131 #define JAILHOUSE_PCICAPS_WRITE         0x0001
132
133 struct jailhouse_pci_capability {
134         __u16 id;
135         __u16 start;
136         __u16 len;
137         __u16 flags;
138 } __attribute__((packed));
139
140 #define JAILHOUSE_MAX_IOMMU_UNITS       8
141
142 struct jailhouse_iommu {
143         __u64 base;
144 } __attribute__((packed));
145
146 #define JAILHOUSE_SYSTEM_SIGNATURE      "JAILSYST"
147
148 struct jailhouse_system {
149         char signature[8];
150         struct jailhouse_memory hypervisor_memory;
151         struct jailhouse_memory debug_console;
152         union {
153                 struct {
154                         __u64 mmconfig_base;
155                         __u8 mmconfig_end_bus;
156                         __u8 padding[5];
157                         __u16 pm_timer_address;
158                         struct jailhouse_iommu
159                                 iommu_units[JAILHOUSE_MAX_IOMMU_UNITS];
160                 } __attribute__((packed)) x86;
161         } __attribute__((packed)) platform_info;
162         __u32 device_limit;
163         __u32 interrupt_limit;
164         struct jailhouse_cell_desc root_cell;
165 } __attribute__((packed));
166
167 static inline __u32
168 jailhouse_cell_config_size(struct jailhouse_cell_desc *cell)
169 {
170         return sizeof(struct jailhouse_cell_desc) +
171                 cell->cpu_set_size +
172                 cell->num_memory_regions * sizeof(struct jailhouse_memory) +
173                 cell->num_cache_regions * sizeof(struct jailhouse_cache) +
174                 cell->num_irqchips * sizeof(struct jailhouse_irqchip) +
175                 cell->pio_bitmap_size +
176                 cell->num_pci_devices * sizeof(struct jailhouse_pci_device) +
177                 cell->num_pci_caps * sizeof(struct jailhouse_pci_capability);
178 }
179
180 static inline __u32
181 jailhouse_system_config_size(struct jailhouse_system *system)
182 {
183         return sizeof(*system) - sizeof(system->root_cell) +
184                 jailhouse_cell_config_size(&system->root_cell);
185 }
186
187 static inline const unsigned long *
188 jailhouse_cell_cpu_set(const struct jailhouse_cell_desc *cell)
189 {
190         return (const unsigned long *)((const void *)cell +
191                 sizeof(struct jailhouse_cell_desc));
192 }
193
194 static inline const struct jailhouse_memory *
195 jailhouse_cell_mem_regions(const struct jailhouse_cell_desc *cell)
196 {
197         return (const struct jailhouse_memory *)
198                 ((void *)jailhouse_cell_cpu_set(cell) + cell->cpu_set_size);
199 }
200
201 static inline const struct jailhouse_cache *
202 jailhouse_cell_cache_regions(const struct jailhouse_cell_desc *cell)
203 {
204         return (const struct jailhouse_cache *)
205                 ((void *)jailhouse_cell_mem_regions(cell) +
206                  cell->num_memory_regions * sizeof(struct jailhouse_memory));
207 }
208
209 static inline const struct jailhouse_irqchip *
210 jailhouse_cell_irqchips(const struct jailhouse_cell_desc *cell)
211 {
212         return (const struct jailhouse_irqchip *)
213                 ((void *)jailhouse_cell_cache_regions(cell) +
214                  cell->num_cache_regions * sizeof(struct jailhouse_cache));
215 }
216
217 static inline const __u8 *
218 jailhouse_cell_pio_bitmap(const struct jailhouse_cell_desc *cell)
219 {
220         return (const __u8 *)((void *)jailhouse_cell_irqchips(cell) +
221                 cell->num_irqchips * sizeof(struct jailhouse_irqchip));
222 }
223
224 static inline const struct jailhouse_pci_device *
225 jailhouse_cell_pci_devices(const struct jailhouse_cell_desc *cell)
226 {
227         return (const struct jailhouse_pci_device *)
228                 ((void *)jailhouse_cell_pio_bitmap(cell) +
229                  cell->pio_bitmap_size);
230 }
231
232 static inline const struct jailhouse_pci_capability *
233 jailhouse_cell_pci_caps(const struct jailhouse_cell_desc *cell)
234 {
235         return (const struct jailhouse_pci_capability *)
236                 ((void *)jailhouse_cell_pci_devices(cell) +
237                  cell->num_pci_devices * sizeof(struct jailhouse_pci_device));
238 }
239
240 #endif /* !_JAILHOUSE_CELL_CONFIG_H */