]> rtime.felk.cvut.cz Git - jailhouse.git/blob - hypervisor/include/jailhouse/cell-config.h
config, core: Improve irqchip configuration
[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         __u32 id;
105         __u32 pin_base;
106         __u32 pin_bitmap[4];
107 } __attribute__((packed));
108
109 #define JAILHOUSE_PCI_TYPE_DEVICE       0x01
110 #define JAILHOUSE_PCI_TYPE_BRIDGE       0x02
111 #define JAILHOUSE_PCI_TYPE_IVSHMEM      0x03
112
113 struct jailhouse_pci_device {
114         __u8 type;
115         __u8 iommu;
116         __u16 domain;
117         __u16 bdf;
118         __u32 bar_mask[6];
119         __u16 caps_start;
120         __u16 num_caps;
121         __u8 num_msi_vectors;
122         __u8 msi_64bits;
123         __u16 num_msix_vectors;
124         __u16 msix_region_size;
125         __u64 msix_address;
126         /** used to refer to memory in virtual PCI devices */
127         __u32 shmem_region;
128 } __attribute__((packed));
129
130 #define JAILHOUSE_PCI_EXT_CAP           0x8000
131
132 #define JAILHOUSE_PCICAPS_WRITE         0x0001
133
134 struct jailhouse_pci_capability {
135         __u16 id;
136         __u16 start;
137         __u16 len;
138         __u16 flags;
139 } __attribute__((packed));
140
141 #define JAILHOUSE_MAX_IOMMU_UNITS       8
142
143 struct jailhouse_iommu {
144         __u64 base;
145         __u32 size;
146         __u16 amd_bdf;
147         __u8 amd_base_cap;
148         __u8 amd_msi_cap;
149         __u32 amd_features;
150 } __attribute__((packed));
151
152 #define JAILHOUSE_SYSTEM_SIGNATURE      "JAILSYST"
153
154 struct jailhouse_system {
155         char signature[8];
156         struct jailhouse_memory hypervisor_memory;
157         struct jailhouse_memory debug_console;
158         union {
159                 struct {
160                         __u64 mmconfig_base;
161                         __u8 mmconfig_end_bus;
162                         __u8 padding[5];
163                         __u16 pm_timer_address;
164                         struct jailhouse_iommu
165                                 iommu_units[JAILHOUSE_MAX_IOMMU_UNITS];
166                 } __attribute__((packed)) x86;
167         } __attribute__((packed)) platform_info;
168         __u32 interrupt_limit;
169         struct jailhouse_cell_desc root_cell;
170 } __attribute__((packed));
171
172 static inline __u32
173 jailhouse_cell_config_size(struct jailhouse_cell_desc *cell)
174 {
175         return sizeof(struct jailhouse_cell_desc) +
176                 cell->cpu_set_size +
177                 cell->num_memory_regions * sizeof(struct jailhouse_memory) +
178                 cell->num_cache_regions * sizeof(struct jailhouse_cache) +
179                 cell->num_irqchips * sizeof(struct jailhouse_irqchip) +
180                 cell->pio_bitmap_size +
181                 cell->num_pci_devices * sizeof(struct jailhouse_pci_device) +
182                 cell->num_pci_caps * sizeof(struct jailhouse_pci_capability);
183 }
184
185 static inline __u32
186 jailhouse_system_config_size(struct jailhouse_system *system)
187 {
188         return sizeof(*system) - sizeof(system->root_cell) +
189                 jailhouse_cell_config_size(&system->root_cell);
190 }
191
192 static inline const unsigned long *
193 jailhouse_cell_cpu_set(const struct jailhouse_cell_desc *cell)
194 {
195         return (const unsigned long *)((const void *)cell +
196                 sizeof(struct jailhouse_cell_desc));
197 }
198
199 static inline const struct jailhouse_memory *
200 jailhouse_cell_mem_regions(const struct jailhouse_cell_desc *cell)
201 {
202         return (const struct jailhouse_memory *)
203                 ((void *)jailhouse_cell_cpu_set(cell) + cell->cpu_set_size);
204 }
205
206 static inline const struct jailhouse_cache *
207 jailhouse_cell_cache_regions(const struct jailhouse_cell_desc *cell)
208 {
209         return (const struct jailhouse_cache *)
210                 ((void *)jailhouse_cell_mem_regions(cell) +
211                  cell->num_memory_regions * sizeof(struct jailhouse_memory));
212 }
213
214 static inline const struct jailhouse_irqchip *
215 jailhouse_cell_irqchips(const struct jailhouse_cell_desc *cell)
216 {
217         return (const struct jailhouse_irqchip *)
218                 ((void *)jailhouse_cell_cache_regions(cell) +
219                  cell->num_cache_regions * sizeof(struct jailhouse_cache));
220 }
221
222 static inline const __u8 *
223 jailhouse_cell_pio_bitmap(const struct jailhouse_cell_desc *cell)
224 {
225         return (const __u8 *)((void *)jailhouse_cell_irqchips(cell) +
226                 cell->num_irqchips * sizeof(struct jailhouse_irqchip));
227 }
228
229 static inline const struct jailhouse_pci_device *
230 jailhouse_cell_pci_devices(const struct jailhouse_cell_desc *cell)
231 {
232         return (const struct jailhouse_pci_device *)
233                 ((void *)jailhouse_cell_pio_bitmap(cell) +
234                  cell->pio_bitmap_size);
235 }
236
237 static inline const struct jailhouse_pci_capability *
238 jailhouse_cell_pci_caps(const struct jailhouse_cell_desc *cell)
239 {
240         return (const struct jailhouse_pci_capability *)
241                 ((void *)jailhouse_cell_pci_devices(cell) +
242                  cell->num_pci_devices * sizeof(struct jailhouse_pci_device));
243 }
244
245 #endif /* !_JAILHOUSE_CELL_CONFIG_H */