]> rtime.felk.cvut.cz Git - jailhouse.git/blob - hypervisor/include/jailhouse/cell-config.h
hypervisor, driver: Added signature for .cell files
[jailhouse.git] / hypervisor / include / jailhouse / cell-config.h
1 /*
2  * Jailhouse, a Linux-based partitioning hypervisor
3  *
4  * Copyright (c) Siemens AG, 2014, 2015
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_irqchips;
56         __u32 pio_bitmap_size;
57         __u32 num_pci_devices;
58         __u32 num_pci_caps;
59 } __attribute__((packed));
60
61 #define JAILHOUSE_MEM_READ              0x0001
62 #define JAILHOUSE_MEM_WRITE             0x0002
63 #define JAILHOUSE_MEM_EXECUTE           0x0004
64 #define JAILHOUSE_MEM_DMA               0x0008
65 #define JAILHOUSE_MEM_IO                0x0010
66 #define JAILHOUSE_MEM_COMM_REGION       0x0020
67 #define JAILHOUSE_MEM_LOADABLE          0x0040
68 #define JAILHOUSE_MEM_ROOTSHARED        0x0080
69
70 #define JAILHOUSE_MEM_VALID_FLAGS       (JAILHOUSE_MEM_READ | \
71                                          JAILHOUSE_MEM_WRITE | \
72                                          JAILHOUSE_MEM_EXECUTE | \
73                                          JAILHOUSE_MEM_DMA | \
74                                          JAILHOUSE_MEM_IO | \
75                                          JAILHOUSE_MEM_COMM_REGION | \
76                                          JAILHOUSE_MEM_LOADABLE | \
77                                          JAILHOUSE_MEM_ROOTSHARED)
78
79 struct jailhouse_memory {
80         __u64 phys_start;
81         __u64 virt_start;
82         __u64 size;
83         __u64 flags;
84 } __attribute__((packed));
85
86 struct jailhouse_irqchip {
87         __u64 address;
88         __u64 id;
89         __u64 pin_bitmap;
90 } __attribute__((packed));
91
92 #define JAILHOUSE_PCI_TYPE_DEVICE       0x01
93 #define JAILHOUSE_PCI_TYPE_BRIDGE       0x02
94 #define JAILHOUSE_PCI_TYPE_IVSHMEM      0x03
95
96 struct jailhouse_pci_device {
97         __u8 type;
98         __u8 iommu;
99         __u16 domain;
100         __u16 bdf;
101         __u32 bar_mask[6];
102         __u16 caps_start;
103         __u16 num_caps;
104         __u8 num_msi_vectors;
105         __u8 msi_64bits;
106         __u16 num_msix_vectors;
107         __u16 msix_region_size;
108         __u64 msix_address;
109         /** used to refer to memory in virtual PCI devices */
110         __u32 shmem_region;
111 } __attribute__((packed));
112
113 #define JAILHOUSE_PCICAPS_WRITE         0x0001
114
115 struct jailhouse_pci_capability {
116         __u16 id;
117         __u16 start;
118         __u16 len;
119         __u16 flags;
120 } __attribute__((packed));
121
122 #define JAILHOUSE_MAX_IOMMU_UNITS       8
123
124 #define JAILHOUSE_SYSTEM_SIGNATURE      "JAILSYST"
125
126 struct jailhouse_system {
127         char signature[8];
128         struct jailhouse_memory hypervisor_memory;
129         struct jailhouse_memory debug_uart;
130         union {
131                 struct {
132                         __u64 mmconfig_base;
133                         __u8 mmconfig_end_bus;
134                         __u8 padding[5];
135                         __u16 pm_timer_address;
136                         __u64 iommu_base[JAILHOUSE_MAX_IOMMU_UNITS];
137                 } __attribute__((packed)) x86;
138         } __attribute__((packed)) platform_info;
139         __u32 device_limit;
140         __u32 interrupt_limit;
141         struct jailhouse_cell_desc root_cell;
142 } __attribute__((packed));
143
144 static inline __u32
145 jailhouse_cell_config_size(struct jailhouse_cell_desc *cell)
146 {
147         return sizeof(struct jailhouse_cell_desc) +
148                 cell->cpu_set_size +
149                 cell->num_memory_regions * sizeof(struct jailhouse_memory) +
150                 cell->num_irqchips * sizeof(struct jailhouse_irqchip) +
151                 cell->pio_bitmap_size +
152                 cell->num_pci_devices * sizeof(struct jailhouse_pci_device) +
153                 cell->num_pci_caps * sizeof(struct jailhouse_pci_capability);
154 }
155
156 static inline __u32
157 jailhouse_system_config_size(struct jailhouse_system *system)
158 {
159         return sizeof(*system) - sizeof(system->root_cell) +
160                 jailhouse_cell_config_size(&system->root_cell);
161 }
162
163 static inline const unsigned long *
164 jailhouse_cell_cpu_set(const struct jailhouse_cell_desc *cell)
165 {
166         return (const unsigned long *)((const void *)cell +
167                 sizeof(struct jailhouse_cell_desc));
168 }
169
170 static inline const struct jailhouse_memory *
171 jailhouse_cell_mem_regions(const struct jailhouse_cell_desc *cell)
172 {
173         return (const struct jailhouse_memory *)
174                 ((void *)jailhouse_cell_cpu_set(cell) + cell->cpu_set_size);
175 }
176
177 static inline const struct jailhouse_irqchip *
178 jailhouse_cell_irqchips(const struct jailhouse_cell_desc *cell)
179 {
180         return (const struct jailhouse_irqchip *)
181                 ((void *)jailhouse_cell_mem_regions(cell) +
182                  cell->num_memory_regions * sizeof(struct jailhouse_memory));
183 }
184
185 static inline const __u8 *
186 jailhouse_cell_pio_bitmap(const struct jailhouse_cell_desc *cell)
187 {
188         return (const __u8 *)((void *)jailhouse_cell_irqchips(cell) +
189                 cell->num_irqchips * sizeof(struct jailhouse_irqchip));
190 }
191
192 static inline const struct jailhouse_pci_device *
193 jailhouse_cell_pci_devices(const struct jailhouse_cell_desc *cell)
194 {
195         return (const struct jailhouse_pci_device *)
196                 ((void *)jailhouse_cell_pio_bitmap(cell) +
197                  cell->pio_bitmap_size);
198 }
199
200 static inline const struct jailhouse_pci_capability *
201 jailhouse_cell_pci_caps(const struct jailhouse_cell_desc *cell)
202 {
203         return (const struct jailhouse_pci_capability *)
204                 ((void *)jailhouse_cell_pci_devices(cell) +
205                  cell->num_pci_devices * sizeof(struct jailhouse_pci_device));
206 }
207
208 #endif /* !_JAILHOUSE_CELL_CONFIG_H */