2 * Jailhouse, a Linux-based partitioning hypervisor
4 * Copyright (c) Siemens AG, 2014-2016
7 * Jan Kiszka <jan.kiszka@siemens.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
12 * Alternatively, you can use or redistribute this file under the following
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
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.
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.
39 #ifndef _JAILHOUSE_CELL_CONFIG_H
40 #define _JAILHOUSE_CELL_CONFIG_H
42 #define JAILHOUSE_CELL_NAME_MAXLEN 31
44 #define JAILHOUSE_CELL_PASSIVE_COMMREG 0x00000001
46 #define JAILHOUSE_CELL_DESC_SIGNATURE "JAILCELL"
48 struct jailhouse_cell_desc {
50 char name[JAILHOUSE_CELL_NAME_MAXLEN+1];
54 __u32 num_memory_regions;
55 __u32 num_cache_regions;
57 __u32 pio_bitmap_size;
58 __u32 num_pci_devices;
60 } __attribute__((packed));
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)
77 struct jailhouse_memory {
82 } __attribute__((packed));
84 #define JAILHOUSE_MEMORY_IS_SUBPAGE(mem) \
85 ((mem)->virt_start & ~PAGE_MASK || (mem)->size & ~PAGE_MASK)
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)
92 #define JAILHOUSE_CACHE_ROOTSHARED 0x0001
94 struct jailhouse_cache {
100 } __attribute__((packed));
102 struct jailhouse_irqchip {
107 } __attribute__((packed));
109 #define JAILHOUSE_PCI_TYPE_DEVICE 0x01
110 #define JAILHOUSE_PCI_TYPE_BRIDGE 0x02
111 #define JAILHOUSE_PCI_TYPE_IVSHMEM 0x03
113 struct jailhouse_pci_device {
121 __u8 num_msi_vectors;
123 __u16 num_msix_vectors;
124 __u16 msix_region_size;
126 /** used to refer to memory in virtual PCI devices */
128 } __attribute__((packed));
130 #define JAILHOUSE_PCI_EXT_CAP 0x8000
132 #define JAILHOUSE_PCICAPS_WRITE 0x0001
134 struct jailhouse_pci_capability {
139 } __attribute__((packed));
141 #define JAILHOUSE_MAX_IOMMU_UNITS 8
143 struct jailhouse_iommu {
150 } __attribute__((packed));
152 #define JAILHOUSE_SYSTEM_SIGNATURE "JAILSYST"
154 struct jailhouse_system {
156 struct jailhouse_memory hypervisor_memory;
157 struct jailhouse_memory debug_console;
161 __u8 mmconfig_end_bus;
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));
173 jailhouse_cell_config_size(struct jailhouse_cell_desc *cell)
175 return sizeof(struct jailhouse_cell_desc) +
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);
186 jailhouse_system_config_size(struct jailhouse_system *system)
188 return sizeof(*system) - sizeof(system->root_cell) +
189 jailhouse_cell_config_size(&system->root_cell);
192 static inline const unsigned long *
193 jailhouse_cell_cpu_set(const struct jailhouse_cell_desc *cell)
195 return (const unsigned long *)((const void *)cell +
196 sizeof(struct jailhouse_cell_desc));
199 static inline const struct jailhouse_memory *
200 jailhouse_cell_mem_regions(const struct jailhouse_cell_desc *cell)
202 return (const struct jailhouse_memory *)
203 ((void *)jailhouse_cell_cpu_set(cell) + cell->cpu_set_size);
206 static inline const struct jailhouse_cache *
207 jailhouse_cell_cache_regions(const struct jailhouse_cell_desc *cell)
209 return (const struct jailhouse_cache *)
210 ((void *)jailhouse_cell_mem_regions(cell) +
211 cell->num_memory_regions * sizeof(struct jailhouse_memory));
214 static inline const struct jailhouse_irqchip *
215 jailhouse_cell_irqchips(const struct jailhouse_cell_desc *cell)
217 return (const struct jailhouse_irqchip *)
218 ((void *)jailhouse_cell_cache_regions(cell) +
219 cell->num_cache_regions * sizeof(struct jailhouse_cache));
222 static inline const __u8 *
223 jailhouse_cell_pio_bitmap(const struct jailhouse_cell_desc *cell)
225 return (const __u8 *)((void *)jailhouse_cell_irqchips(cell) +
226 cell->num_irqchips * sizeof(struct jailhouse_irqchip));
229 static inline const struct jailhouse_pci_device *
230 jailhouse_cell_pci_devices(const struct jailhouse_cell_desc *cell)
232 return (const struct jailhouse_pci_device *)
233 ((void *)jailhouse_cell_pio_bitmap(cell) +
234 cell->pio_bitmap_size);
237 static inline const struct jailhouse_pci_capability *
238 jailhouse_cell_pci_caps(const struct jailhouse_cell_desc *cell)
240 return (const struct jailhouse_pci_capability *)
241 ((void *)jailhouse_cell_pci_devices(cell) +
242 cell->num_pci_devices * sizeof(struct jailhouse_pci_device));
245 #endif /* !_JAILHOUSE_CELL_CONFIG_H */