3 # Jailhouse, a Linux-based partitioning hypervisor
5 # Copyright (c) Siemens AG, 2014
7 # This work is licensed under the terms of the GNU GPL, version 2. See
8 # the COPYING file in the top-level directory.
10 # This script should help to create a basic jailhouse configuration file.
11 # It needs to be executed on the target machine, where it will gather
12 # information about the system. For more advanced scenarios you will have
13 # to change the generated C-code.
15 from __future__ import print_function
22 from mako.template import Template
27 template_default_dir = datadir + "/jailhouse"
29 template_default_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
33 # pretend to be part of the jailhouse tool
34 sys.argv[0] = sys.argv[0].replace('-', ' ')
36 parser = argparse.ArgumentParser()
37 parser.add_argument('-g', '--generate-collector',
38 help='generate a script to collect input files on '
41 parser.add_argument('-r', '--root',
42 help='gather information in ROOT/, the default is "/" '
43 'which means creating a config for localhost',
47 parser.add_argument('-t', '--template-dir',
48 help='the directory where the templates are located,'
49 'the default is "' + template_default_dir + '"',
50 default=template_default_dir,
54 memargs = [['--mem-inmates', '2M', 'inmate'],
55 ['--mem-hv', '64M', 'hypervisor']]
58 parser.add_argument(entry[0],
59 help='the amount of ' + entry[2] +
60 ' memory, default is "' + entry[1] +
61 '", format "xxx[K|M|G]"',
66 parser.add_argument('file', metavar='FILE',
67 help='name of file to write out',
70 options = parser.parse_args()
80 inputs['files'].add('/proc/iomem')
81 inputs['files'].add('/proc/cpuinfo')
82 inputs['files'].add('/proc/cmdline')
83 inputs['files'].add('/proc/ioports')
84 inputs['files'].add('/sys/bus/pci/devices/*/config')
85 inputs['files'].add('/sys/bus/pci/devices/*/resource')
86 inputs['files'].add('/sys/devices/system/cpu/cpu*/uevent')
87 inputs['files'].add('/sys/firmware/acpi/tables/APIC')
88 inputs['files'].add('/sys/firmware/acpi/tables/MCFG')
90 inputs['files_opt'].add('/sys/class/dmi/id/product_name')
91 inputs['files_opt'].add('/sys/class/dmi/id/sys_vendor')
92 inputs['files_opt'].add('/sys/devices/jailhouse/enabled')
93 # platform specific files
94 inputs['files_intel'].add('/sys/firmware/acpi/tables/DMAR')
95 inputs['files_amd'].add('/sys/firmware/acpi/tables/IVRS')
98 def kmg_multiply(value, kmg):
99 if (kmg == 'K' or kmg == 'k'):
101 if (kmg == 'M' or kmg == 'm'):
102 return 1024**2 * value
103 if (kmg == 'G' or kmg == 'g'):
104 return 1024**3 * value
108 def kmg_multiply_str(str):
109 m = re.match(r'([0-9a-fA-FxX]+)([KMG]?)', str)
111 return kmg_multiply(int(m.group(1)), m.group(2))
112 raise RuntimeError('kmg_multiply_str can not parse input "' + str + '"')
115 def check_input_listed(name, optional=False):
116 set = inputs['files_opt']
117 if optional is False:
118 set = inputs['files']
120 if cpuvendor == 'GenuineIntel':
121 set = set.union(inputs['files_intel'])
122 elif cpuvendor == 'AuthenticAMD':
123 set = set.union(inputs['files_amd'])
126 if fnmatch.fnmatch(name, file):
128 raise RuntimeError('"' + name + '" is not a listed input file')
131 def input_open(name, mode='r', optional=False):
132 check_input_listed(name, optional)
134 f = open(options.root + name, mode)
135 except Exception as e:
137 return open("/dev/null", mode)
142 def input_readline(name, optional=False):
143 f = input_open(name, optional=optional)
149 def input_listdir(dir, wildcards):
151 check_input_listed(os.path.join(dir, w))
152 dirs = os.listdir(options.root + dir)
158 IORESOURCE_IO = 0x00000100
159 IORESOURCE_MEM = 0x00000200
160 IORESOURCE_MEM_64 = 0x00100000
162 def __init__(self, dir):
164 f = input_open(os.path.join(dir, 'resource'), 'r')
166 (start, end, flags) = f.readline().split()
167 flags = int(flags, 16)
168 if flags & PCIBARs.IORESOURCE_IO:
169 mask = ~(int(end, 16) - int(start, 16))
170 elif flags & PCIBARs.IORESOURCE_MEM:
171 mask = ~(int(end, 16) - int(start, 16))
172 if flags & PCIBARs.IORESOURCE_MEM_64:
173 self.mask.append(mask & 0xffffffff)
178 self.mask.append(mask & 0xffffffff)
183 def __init__(self, id, start, len, flags, content, msix_address):
188 self.content = content
189 self.msix_address = msix_address
192 def __eq__(self, other):
193 return self.id == other.id and self.start == other.start and \
194 self.len == other.len and self.flags == other.flags
197 RW = 'JAILHOUSE_PCICAPS_WRITE'
200 def parse_pcicaps(dir):
202 f = input_open(os.path.join(dir, 'config'), 'rb')
204 (status,) = struct.unpack('<H', f.read(2))
205 # capability list supported?
206 if (status & (1 << 4)) == 0:
209 # walk capability list
211 (next,) = struct.unpack('B', f.read(1))
216 (id, next) = struct.unpack('<BB', f.read(2))
217 if id == 0x01: # Power Management
218 # this cap can be handed out completely
220 flags = PCICapability.RW
221 elif id == 0x05: # MSI
222 # access will be moderated by hypervisor
224 (msgctl,) = struct.unpack('<H', f.read(2))
225 if (msgctl & (1 << 7)) != 0: # 64-bit support
227 if (msgctl & (1 << 8)) != 0: # per-vector masking support
229 flags = PCICapability.RW
230 elif id == 0x11: # MSI-X
231 # access will be moderated by hypervisor
233 (table,) = struct.unpack('<xxI', f.read(6))
234 f.seek(0x10 + (table & 7) * 4)
235 (bar,) = struct.unpack('<I', f.read(4))
237 raise RuntimeError('Invalid MSI-X BAR found')
239 bar |= struct.unpack('<I', f.read(4))[0] << 32
240 msix_address = (bar & 0xfffffffffffffff0) + table & 0xfffffff8
241 flags = PCICapability.RW
243 # unknown/unhandled cap, mark its existence
245 flags = PCICapability.RD
247 content = f.read(len - 2)
248 caps.append(PCICapability(id, cap, len, flags, content,
255 def __init__(self, type, domain, bus, dev, fn, bars, caps, path):
266 self.num_caps = len(caps)
267 self.num_msi_vectors = 0
269 self.num_msix_vectors = 0
270 self.msix_region_size = 0
271 self.msix_address = 0
273 if c.id in (0x05, 0x11):
274 msg_ctrl = struct.unpack('<H', c.content[:2])[0]
275 if c.id == 0x05: # MSI
276 self.num_msi_vectors = 1 << ((msg_ctrl >> 1) & 0x7)
277 self.msi_64bits = (msg_ctrl >> 7) & 1
279 if c.msix_address != 0:
280 vectors = (msg_ctrl & 0x7ff) + 1
281 self.num_msix_vectors = vectors
282 self.msix_region_size = (vectors * 16 + 0xfff) & 0xf000
283 self.msix_address = c.msix_address
285 print('WARNING: Ignoring invalid MSI-X configuration'
286 ' of device %02x:%02x.%x' % (bus, dev, fn))
289 return 'PCIDevice: %02x:%02x.%x' % (self.bus, self.dev, self.fn)
292 return self.bus << 8 | self.dev << 3 | self.fn
295 def parse_pcidevice_sysfsdir(basedir, dir):
296 dpath = os.path.join(basedir, dir)
297 f = input_open(os.path.join(dpath, 'config'), 'rb')
299 (classcode,) = struct.unpack('<H', f.read(2))
301 if classcode == 0x0604:
302 type = 'JAILHOUSE_PCI_TYPE_BRIDGE'
304 type = 'JAILHOUSE_PCI_TYPE_DEVICE'
306 domain = int(a[0], 16)
309 bars = PCIBARs(dpath)
310 caps = PCICapability.parse_pcicaps(dpath)
311 return PCIDevice(type, domain, bus, int(df[0], 16), int(df[1], 16),
315 class PCIPCIBridge(PCIDevice):
317 def get_2nd_busses(dev):
318 assert dev.type == 'JAILHOUSE_PCI_TYPE_BRIDGE'
319 f = input_open(os.path.join(dev.path, 'config'), 'rb')
321 (secondbus, subordinate) = struct.unpack('<BB', f.read(2))
323 return (secondbus, subordinate)
327 def __init__(self, start, stop, typestr, comments=None):
330 self.typestr = typestr
334 self.comments = comments
337 return 'MemRegion: %08x-%08x : %s' % \
338 (self.start, self.stop, self.typestr)
341 # round up to full PAGE_SIZE
342 return int((self.stop - self.start + 0xfff) / 0x1000) * 0x1000
344 def flagstr(self, p=''):
346 self.typestr == 'System RAM' or
347 self.typestr == 'Kernel' or
348 self.typestr == 'RAM buffer' or
349 self.typestr == 'ACPI DMAR RMRR' or
350 self.typestr == 'ACPI IVRS'
352 s = 'JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE |\n'
353 s += p + '\t\tJAILHOUSE_MEM_EXECUTE | JAILHOUSE_MEM_DMA'
355 return 'JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE'
359 def __init__(self, id, address, gsi_base, iommu=0, bdf=0):
361 self.address = address
362 self.gsi_base = gsi_base
367 return 'IOAPIC %d, GSI base %d' % (self.id, self.gsi_base)
369 def irqchip_id(self):
370 # encode the IOMMU number into the irqchip ID
371 return (self.iommu << 16) | self.bdf
374 class IOMemRegionTree:
375 def __init__(self, region, level):
384 s = (' ' * (self.level - 1)) + str(self.region)
385 if self.parent and self.parent.region:
386 s += ' --> ' + self.parent.region.typestr
388 for c in self.children:
392 def regions_split_by_kernel(self):
393 kernel = [x for x in self.children if
394 x.region.typestr.startswith('Kernel ')]
396 if (len(kernel) == 0):
402 kernel_start = kernel[0].region.start
403 kernel_stop = kernel[len(kernel) - 1].region.stop
405 # align this for 16M, but only if we have enough space
406 kernel_stop = (kernel_stop & ~0xFFFFFF) + 0xFFFFFF
407 if (kernel_stop > r.stop):
413 # before Kernel if any
414 if (r.start < kernel_start):
415 before_kernel = MemRegion(r.start, kernel_start - 1, s)
417 kernel_region = MemRegion(kernel_start, kernel_stop, "Kernel")
419 # after Kernel if any
420 if (r.stop > kernel_stop):
421 after_kernel = MemRegion(kernel_stop + 1, r.stop, s)
423 return [before_kernel, kernel_region, after_kernel]
426 def parse_iomem_line(line):
427 a = line.split(':', 1)
428 level = int(a[0].count(' ') / 2) + 1
429 region = a[0].split('-', 1)
431 return level, MemRegion(int(region[0], 16), int(region[1], 16), a[1])
434 def parse_iomem_file():
435 root = IOMemRegionTree(None, 0)
436 f = input_open('/proc/iomem')
440 (level, r) = IOMemRegionTree.parse_iomem_line(line)
441 t = IOMemRegionTree(r, level)
442 if (t.level > lastlevel):
444 if (t.level == lastlevel):
445 t.parent = lastnode.parent
446 if (t.level < lastlevel):
448 while(t.level < p.level):
452 t.parent.children.append(t)
459 # find HPET regions in tree
461 def find_hpet_regions(tree):
464 for tree in tree.children:
468 if (s.find('HPET') >= 0):
471 # if the tree continues recurse further down ...
472 if (len(tree.children) > 0):
473 regions.extend(IOMemRegionTree.find_hpet_regions(tree))
477 # recurse down the tree
479 def parse_iomem_tree(tree):
482 for tree in tree.children:
486 # System RAM on the first level will be added completely,
487 # if they don't contain the kernel itself, if they do,
489 if (tree.level == 1 and s == 'System RAM'):
490 regions.extend(tree.regions_split_by_kernel())
493 # blacklisted on all levels
495 (s.find('PCI MMCONFIG') >= 0) or
496 (s.find('APIC') >= 0) or # covers both APIC and IOAPIC
497 (s.find('dmar') >= 0)
501 # generally blacklisted, unless we find an HPET behind it
502 if (s == 'reserved'):
503 regions.extend(IOMemRegionTree.find_hpet_regions(tree))
506 # if the tree continues recurse further down ...
507 if (len(tree.children) > 0):
508 regions.extend(IOMemRegionTree.parse_iomem_tree(tree))
511 # add all remaining leaves
517 def parse_iomem(pcidevices):
518 regions = IOMemRegionTree.parse_iomem_tree(
519 IOMemRegionTree.parse_iomem_file())
521 rom_region = MemRegion(0xc0000, 0xdffff, 'ROMs')
522 add_rom_region = False
527 # filter the list for MSI-X pages
529 if d.msix_address >= r.start and d.msix_address <= r.stop:
530 if d.msix_address > r.start:
531 head_r = MemRegion(r.start, d.msix_address - 1,
532 r.typestr, r.comments)
534 if d.msix_address + d.msix_region_size < r.stop:
535 tail_r = MemRegion(d.msix_address + d.msix_region_size,
536 r.stop, r.typestr, r.comments)
540 # filter out the ROMs
541 if (r.start >= rom_region.start and r.stop <= rom_region.stop):
542 add_rom_region = True
547 # add a region that covers all potential ROMs
549 ret.append(rom_region)
551 # newer Linux kernels will report the first page as reserved
552 # it is needed for CPU init so include it anyways
553 if (ret[0].typestr == 'System RAM' and ret[0].start == 0x1000):
559 def parse_pcidevices():
562 basedir = '/sys/bus/pci/devices'
563 list = input_listdir(basedir, ['*/config'])
565 d = PCIDevice.parse_pcidevice_sysfsdir(basedir, dir)
569 # look for duplicate capability patterns
571 if d2.caps == d.caps:
572 # reused existing capability list, but record all users
573 d2.caps[0].comments.append(str(d))
574 d.caps_start = d2.caps_start
578 d.caps[0].comments.append(str(d))
579 d.caps_start = len(caps)
582 return (devices, caps)
585 def parse_kernel_cmdline():
586 line = input_readline('/proc/cmdline')
587 m = re.match(r'.*memmap=([0-9a-fA-FxX]+)([KMG]?)\$'
588 '([0-9a-fA-FxX]+)([KMG]?).*',
591 size = kmg_multiply(int(m.group(1), 0), m.group(2))
592 start = kmg_multiply(int(m.group(3), 0), m.group(4))
597 def alloc_mem(regions, size):
598 mem = [0x3b000000, size]
601 r.typestr == 'System RAM' and
602 r.start <= mem[0] and
603 r.stop + 1 >= mem[0] + mem[1]
606 head_r = MemRegion(r.start, mem[0] - 1, r.typestr, r.comments)
607 regions.insert(regions.index(r), head_r)
608 if r.stop + 1 > mem[0] + mem[1]:
609 tail_r = MemRegion(mem[0] + mem[1], r.stop, r.typestr,
611 regions.insert(regions.index(r), tail_r)
614 for r in reversed(regions):
615 if (r.typestr == 'System RAM' and r.size() >= mem[1]):
619 raise RuntimeError('failed to allocate memory')
623 list = input_listdir('/sys/devices/system/cpu', ['cpu*/uevent'])
626 if re.match(r'cpu[0-9]+', f):
632 f = input_open('/sys/firmware/acpi/tables/APIC', 'rb')
633 signature = f.read(4)
634 if signature != b'APIC':
635 raise RuntimeError('MADT: incorrect input file format %s' % signature)
636 (length,) = struct.unpack('<I', f.read(4))
643 (struct_type, struct_len) = struct.unpack('<BB', f.read(2))
648 (id, address, gsi_base) = struct.unpack('<BxII', f.read(10))
650 ioapics.append(IOAPIC(id, address, gsi_base))
652 f.seek(struct_len - offset, os.SEEK_CUR)
658 def parse_dmar_devscope(f):
659 (scope_type, scope_len, id, bus, dev, fn) = \
660 struct.unpack('<BBxxBBBB', f.read(8))
662 raise RuntimeError('Unsupported DMAR Device Scope Structure')
663 return (scope_type, scope_len, id, bus, dev, fn)
666 # parsing of DMAR ACPI Table
667 # see Intel VT-d Spec chapter 8
668 def parse_dmar(pcidevices, ioapics):
669 f = input_open('/sys/firmware/acpi/tables/DMAR', 'rb')
670 signature = f.read(4)
671 if signature != b'DMAR':
672 raise RuntimeError('DMAR: incorrect input file format %s' % signature)
673 (length,) = struct.unpack('<I', f.read(4))
681 (struct_type, struct_len) = struct.unpack('<HH', f.read(4))
685 # DMA Remapping Hardware Unit Definition
687 (flags, segment, base) = struct.unpack('<BxHQ', f.read(12))
689 raise RuntimeError('We do not support multiple PCI segments')
691 raise RuntimeError('Too many DMAR units. '
692 'Raise JAILHOUSE_MAX_IOMMU_UNITS.')
697 d.iommu = len(units) - 1
698 offset += 16 - offset
699 while offset < struct_len:
700 (scope_type, scope_len, id, bus, dev, fn) =\
701 parse_dmar_devscope(f)
702 # PCI Endpoint Device
704 assert not (flags & 1)
706 if d.bus == bus and d.dev == dev and d.fn == fn:
707 d.iommu = len(units) - 1
710 elif scope_type == 2:
711 assert not (flags & 1)
713 if d.bus == bus and d.dev == dev and d.fn == fn:
714 (secondbus, subordinate) = \
715 PCIPCIBridge.get_2nd_busses(d)
716 for d2 in pcidevices:
718 d2.bus >= secondbus and
719 d2.bus <= subordinate
721 d2.iommu = len(units) - 1
724 elif scope_type == 3:
725 ioapic = next(chip for chip in ioapics if chip.id == id)
726 bdf = (bus << 8) | (dev << 3) | fn
729 raise RuntimeError('IOAPICs with identical BDF')
731 ioapic.iommu = len(units) - 1
734 # Reserved Memory Region Reporting Structure
736 f.seek(8 - offset, os.SEEK_CUR)
738 (base, limit) = struct.unpack('<QQ', f.read(16))
742 while offset < struct_len:
743 (scope_type, scope_len, id, bus, dev, fn) =\
744 parse_dmar_devscope(f)
746 comments.append('PCI device: %02x:%02x.%x' %
749 comments.append('DMAR parser could not decode device path')
752 reg = MemRegion(base, limit, 'ACPI DMAR RMRR', comments)
755 f.seek(struct_len - offset, os.SEEK_CUR)
762 'PCI device %02x:%02x.%x outside the scope of an '
763 'IOMMU' % (d.bus, d.dev, d.fn))
765 return units, regions
768 def parse_ivrs(pcidevices, ioapics):
770 bus, dev, fun = (bdf >> 8) & 0xff, (bdf >> 3) & 0x1f, bdf & 0x7
771 return '%02x:%02x.%x' % (bus, dev, fun)
773 f = input_open('/sys/firmware/acpi/tables/IVRS', 'rb')
774 signature = f.read(4)
775 if signature != b'IVRS':
776 raise RuntimeError('IVRS: incorrect input file format %s' % signature)
778 (length, revision) = struct.unpack('<IB', f.read(5))
780 raise RuntimeError('IVRS: unsupported Revision %02x' % revision)
782 f.seek(48, os.SEEK_SET)
787 # BDF of devices that are permitted outside IOMMU: root complex
788 iommu_skiplist = set([0x0])
790 (block_type, block_length) = struct.unpack('<BxH', f.read(4))
791 if block_type in [0x10, 0x11]:
793 (iommu_id, base_addr, pci_seg) = \
794 struct.unpack('<HxxQH', f.read(14))
795 length -= block_length
798 # IOMMU EFR image and reserved area
799 skip_bytes = 6 if block_type == 0x10 else 22
800 f.seek(skip_bytes, os.SEEK_CUR)
801 block_length -= skip_bytes
804 raise RuntimeError('We do not support multiple PCI segments')
807 raise RuntimeError('Too many IOMMU units. '
808 'Raise JAILHOUSE_MAX_IOMMU_UNITS.')
810 # We shouldn't map IOMMU to the cells
811 for i, d in enumerate(pcidevices):
812 if d.bdf() == iommu_id:
815 units.append(base_addr)
817 bdf_start_range = None
818 while block_length > 0:
819 (entry_type, device_id) = struct.unpack('<BHx', f.read(4))
822 if entry_type == 0x01:
825 d.iommu = len(units) - 1
826 elif entry_type == 0x02:
829 if d.bdf() == device_id:
830 d.iommu = len(units) - 1
831 elif entry_type == 0x03:
833 bdf_start_range = device_id
834 elif entry_type == 0x04:
836 if bdf_start_range is None:
839 if d.bdf() >= bdf_start_range and d.bdf() <= device_id:
840 d.iommu = len(units) - 1
841 bdf_start_range = None
842 elif entry_type == 0x42:
844 (device_id_b,) = struct.unpack('<xHx', f.read(4))
847 if d.bdf() == device_id_b:
848 d.iommu = len(units) - 1
849 elif entry_type == 0x43:
850 # Alias start of range
851 (device_id_b,) = struct.unpack('<xHx', f.read(4))
853 bdf_start_range = device_id_b
854 elif entry_type == 0x48:
856 (handle, device_id_b, variety) = struct.unpack(
859 if variety == 0x01: # IOAPIC
861 if chip.id == handle:
863 chip.iommu = len(units) - 1
865 # Reserved or ignored entries
866 if entry_type >= 0x40:
867 f.seek(4, os.SEEK_CUR)
870 elif type in [0x20, 0x21, 0x22]:
872 (block_type, block_flags, block_length,
873 device_id, aux_data, mem_addr, mem_len) = struct.unpack(
875 length -= block_length
878 bdf_str = format_bdf(device_id)
880 'WARNING: Jailhouse doesn\'t support configurable '
881 '(eg. read-only) device memory. Device %s may not '
882 'work properly, especially in non-root cell.' % bdf_str)
884 if block_type == 0x20:
887 elif block_type == 0x21:
889 comment = 'PCI Device: %s' % format_bdf(device_id)
890 elif block_type == 0x22:
892 comment = 'PCI Device: %s - %s' % (
893 format_bdf(device_id), format_bdf(aux_data))
896 print('WARNING: Jailhouse doesn\'t support per-device memory '
897 'regions. The memory at 0x%x will be mapped accessible '
898 'to all devices.' % mem_addr)
900 regions.append(MemRegion(mem_addr, mem_len, 'ACPI IVRS', comment))
903 'You board uses IVRS Rev. 2 feature Jailhouse doesn\'t '
904 'support yet. Please report this to '
905 'jailhouse-dev@googlegroups.com.')
908 'WARNING: Skipping unknown IVRS '
909 'block type 0x%02x' % block_type)
912 if d.bdf() not in iommu_skiplist and d.iommu is None:
914 'PCI device %02x:%02x.%x outside the scope of an '
915 'IOMMU' % (d.bus, d.dev, d.fn))
918 return units, regions
923 f = input_open('/proc/ioports')
925 if line.endswith('ACPI PM_TMR\n'):
926 pm_timer_base = int(line.split('-')[0], 16)
933 def __init__(self, base, end_bus):
935 self.end_bus = end_bus
939 f = input_open('/sys/firmware/acpi/tables/MCFG', 'rb')
940 signature = f.read(4)
941 if signature != b'MCFG':
942 raise RuntimeError('MCFG: incorrect input file format %s' %
944 (length,) = struct.unpack('<I', f.read(4))
946 raise RuntimeError('Multiple MMCONFIG regions found! '
947 'This is not supported')
949 (base, segment, start_bus, end_bus) = \
950 struct.unpack('<QHBB', f.read(12))
951 if segment != 0 or start_bus != 0:
952 raise RuntimeError('Invalid MCFG structure found')
953 return MMConfig(base, end_bus)
956 def get_cpu_vendor():
958 if cpuvendor is not None:
960 with input_open('/proc/cpuinfo', 'r') as f:
964 key, value = line.split(':')
965 if key.strip() == 'vendor_id':
966 cpuvendor = value.strip()
970 if options.generate_collector:
971 f = open(options.file, 'w')
972 filelist = ' '.join(inputs['files'])
973 filelist_opt = ' '.join(inputs['files_opt'])
974 filelist_intel = ' '.join(inputs['files_intel'])
975 filelist_amd = ' '.join(inputs['files_amd'])
977 tmpl = Template(filename=os.path.join(options.template_dir,
978 'jailhouse-config-collect.tmpl'))
979 f.write(tmpl.render(filelist=filelist, filelist_opt=filelist_opt,
980 filelist_intel=filelist_intel, filelist_amd=filelist_amd))
984 if ((options.root is '/') and (os.geteuid() is not 0)):
985 print('ERROR: You have to be root to work on "/"!', file=sys.stderr)
988 jh_enabled = input_readline('/sys/devices/jailhouse/enabled', True).rstrip()
989 if jh_enabled == '1':
990 print('ERROR: Jailhouse was enabled when collecting input files! '
991 'Disable jailhouse and try again.',
995 (pcidevices, pcicaps) = parse_pcidevices()
997 product = [input_readline('/sys/class/dmi/id/sys_vendor',
999 input_readline('/sys/class/dmi/id/product_name',
1003 inmatemem = kmg_multiply_str(options.mem_inmates)
1004 hvmem = [0, kmg_multiply_str(options.mem_hv)]
1006 regions = parse_iomem(pcidevices)
1007 ourmem = parse_kernel_cmdline()
1008 total = hvmem[1] + inmatemem
1010 mmconfig = MMConfig.parse()
1012 ioapics = parse_madt()
1014 vendor = get_cpu_vendor()
1015 if vendor == 'GenuineIntel':
1016 (iommu_units, extra_memregs) = parse_dmar(pcidevices, ioapics)
1018 (iommu_units, extra_memregs) = parse_ivrs(pcidevices, ioapics)
1019 regions += extra_memregs
1021 # kernel does not have memmap region, pick one
1023 ourmem = alloc_mem(regions, total)
1024 elif (total > ourmem[1]):
1025 raise RuntimeError('Your memmap reservation is too small you need >="' +
1028 hvmem[0] = ourmem[0]
1030 inmatereg = MemRegion(ourmem[0] + hvmem[1],
1031 ourmem[0] + hvmem[1] + inmatemem - 1,
1032 'JAILHOUSE Inmate Memory')
1033 regions.append(inmatereg)
1035 cpucount = count_cpus()
1037 pm_timer_base = parse_ioports()
1040 f = open(options.file, 'w')
1041 tmpl = Template(filename=os.path.join(options.template_dir,
1042 'root-cell-config.c.tmpl'))
1046 'argstr': ' '.join(sys.argv),
1049 'pcidevices': pcidevices,
1051 'cpucount': cpucount,
1052 'irqchips': ioapics,
1053 'pm_timer_base': pm_timer_base,
1054 'mmconfig': mmconfig,
1055 'iommu_units': iommu_units
1058 f.write(tmpl.render(**kwargs))