]> rtime.felk.cvut.cz Git - jailhouse.git/blob - tools/root-cell-config.c.tmpl
core, configs, tools: Add AMD-specific fields to struct jailhouse_iommu
[jailhouse.git] / tools / root-cell-config.c.tmpl
1 /*
2  * Jailhouse, a Linux-based partitioning hypervisor
3  *
4  * Copyright (c) Siemens AG, 2014-2016
5  *
6  * This work is licensed under the terms of the GNU GPL, version 2.  See
7  * the COPYING file in the top-level directory.
8  *
9  * Alternatively, you can use or redistribute this file under the following
10  * BSD license:
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  *
16  * 1. Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer.
18  *
19  * 2. Redistributions in binary form must reproduce the above copyright
20  *    notice, this list of conditions and the following disclaimer in the
21  *    documentation and/or other materials provided with the distribution.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
33  * THE POSSIBILITY OF SUCH DAMAGE.
34  *
35  * Configuration for ${product[0]} ${product[1]}
36  * created with '${argstr}'
37  *
38  * NOTE: This config expects the following to be appended to your kernel cmdline
39  *       "memmap=${hex(ourmem[1])}$${hex(ourmem[0])}"
40  */
41
42 #include <linux/types.h>
43 #include <jailhouse/cell-config.h>
44
45 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
46
47 struct {
48         struct jailhouse_system header;
49         __u64 cpus[${int((cpucount + 63) / 64)}];
50         struct jailhouse_memory mem_regions[${len(regions)}];
51         struct jailhouse_irqchip irqchips[${len(irqchips)}];
52         __u8 pio_bitmap[0x2000];
53         struct jailhouse_pci_device pci_devices[${len(pcidevices)}];
54         struct jailhouse_pci_capability pci_caps[${len(pcicaps)}];
55 } __attribute__((packed)) config = {
56         .header = {
57                 .signature = JAILHOUSE_SYSTEM_SIGNATURE,
58                 .hypervisor_memory = {
59                         .phys_start = ${hex(hvmem[0])},
60                         .size = ${hex(hvmem[1])},
61                 },
62                 .debug_console = {
63                         .phys_start = 0x3f8,
64                 },
65                 .platform_info.x86 = {
66                         .mmconfig_base = ${hex(mmconfig.base)},
67                         .mmconfig_end_bus = ${hex(mmconfig.end_bus)},
68                         .pm_timer_address = ${hex(pm_timer_base)},
69                         % if iommu_units:
70                         .iommu_units = {
71                                 % for unit in iommu_units:
72                                 {
73                                         .base = ${hex(unit.base_addr)},
74                                         .size = ${hex(unit.mmio_size)},
75                                         % if unit.is_amd_iommu:
76                                         .amd_bdf = ${hex(unit.amd_bdf)},
77                                         .amd_base_cap = ${hex(unit.amd_base_cap)},
78                                         .amd_msi_cap = ${hex(unit.amd_msi_cap)},
79                                         .amd_features = ${hex(unit.amd_features)},
80                                         % endif
81                                 },
82                                 % endfor
83                         },
84                         % endif
85                 },
86                 .device_limit = 128,
87                 .interrupt_limit = 256,
88                 .root_cell = {
89                         .name = "RootCell",
90                         .cpu_set_size = sizeof(config.cpus),
91                         .num_memory_regions = ARRAY_SIZE(config.mem_regions),
92                         .num_irqchips = ARRAY_SIZE(config.irqchips),
93                         .pio_bitmap_size = ARRAY_SIZE(config.pio_bitmap),
94                         .num_pci_devices = ARRAY_SIZE(config.pci_devices),
95                         .num_pci_caps = ARRAY_SIZE(config.pci_caps),
96                 },
97         },
98
99         .cpus = {
100                 % for n in range(int(cpucount / 64)):
101                 0xffffffffffffffff,
102                 % endfor
103                 % if (cpucount % 64):
104                 ${'0x%016x,' % ((1 << (cpucount % 64)) - 1)}
105                 % endif
106         },
107
108         .mem_regions = {
109                 % for r in regions:
110                 /* ${str(r)} */
111                 % for c in r.comments:
112                 /* ${c} */
113                 % endfor
114                 {
115                         .phys_start = ${hex(r.start).strip('L')},
116                         .virt_start = ${hex(r.start).strip('L')},
117                         .size = ${hex(r.size()).strip('L')},
118                         .flags = ${r.flagstr('\t\t')},
119                 },
120                 % endfor
121         },
122
123         .irqchips = {
124                 % for i in irqchips:
125                 /* ${str(i)} */
126                 {
127                         .address = ${hex(i.address)},
128                         .id = ${hex(i.irqchip_id())},
129                         .pin_bitmap = 0xffffff,
130                 },
131                 % endfor
132         },
133
134         .pio_bitmap = {
135                 [     0/8 ...   0x3f/8] = -1,
136                 [  0x40/8 ...   0x47/8] = 0xf0, /* PIT */
137                 [  0x48/8 ...   0x5f/8] = -1,
138                 [  0x60/8 ...   0x67/8] = 0xec, /* HACK: NMI status/control */
139                 [  0x68/8 ...   0x6f/8] = -1,
140                 [  0x70/8 ...   0x77/8] = 0xfc, /* RTC */
141                 [  0x78/8 ...   0x7f/7] = -1,
142                 [  0x80/8 ...   0x87/8] = 0xfe, /* Linux: native_io_delay() */
143                 [  0x88/8 ...  0x3af/8] = -1,
144                 [ 0x3b0/8 ...  0x3df/8] = 0x00, /* VGA */
145                 [ 0x3e0/8 ...  0xcff/8] = -1,
146                 [ 0xd00/8 ... 0xffff/8] = 0, /* HACK: PCI bus */
147         },
148
149         .pci_devices = {
150                 % for d in pcidevices:
151                 /* ${str(d)} */
152                 {
153                         .type = ${d.type},
154                         % if d.iommu is not None:
155                         .iommu = ${d.iommu},
156                         % endif
157                         .domain = ${hex(d.domain)},
158                         .bdf = ${hex(d.bdf())},
159                         .bar_mask = {
160                                 ${'0x%08x' % d.bars.mask[0]}, ${'0x%08x' % d.bars.mask[1]}, ${'0x%08x' % d.bars.mask[2]},
161                                 ${'0x%08x' % d.bars.mask[3]}, ${'0x%08x' % d.bars.mask[4]}, ${'0x%08x' % d.bars.mask[5]},
162                         },
163                         .caps_start = ${d.caps_start},
164                         .num_caps = ${d.num_caps},
165                         .num_msi_vectors = ${d.num_msi_vectors},
166                         .msi_64bits = ${d.msi_64bits},
167                         .num_msix_vectors = ${d.num_msix_vectors},
168                         .msix_region_size = ${hex(d.msix_region_size)},
169                         .msix_address = ${hex(d.msix_address).strip('L')},
170                 },
171                 % endfor
172         },
173
174         .pci_caps = {
175                 % for c in pcicaps:
176                 % for comment in c.comments:
177                 /* ${comment} */
178                 % endfor
179                 {
180                         % if (c.id & 0x8000) != 0:
181                         .id = ${hex(c.id & 0x7fff)} | JAILHOUSE_PCI_EXT_CAP,
182                         % else:
183                         .id = ${hex(c.id)},
184                         % endif
185                         .start = ${hex(c.start)},
186                         .len = ${c.len},
187                         .flags = ${c.flags},
188                 },
189                 % endfor
190         },
191 };