1<?xml version="1.0"?>
2<!-- Copyright (C) 2022 Intel Corporation. -->
3<!-- SPDX-License-Identifier: BSD-3-Clause -->
4<xs:schema xml:id="root"
5           xmlns:xs="http://www.w3.org/2001/XMLSchema"
6           xmlns:acrn="https://projectacrn.org">
7
8  <xs:assert test="every $root in /acrn-config satisfies
9                   every $vm in $root/vm satisfies
10		   every $vbdf in $root/hv//vuart_connection[type='pci']/endpoint[vm_name=$vm/name]/vbdf/text() | $root/hv//IVSHMEM_VM[VM_NAME=$vm/name]/VBDF/text() satisfies
11		   count($root/hv//vuart_connection[type='pci']/endpoint[vm_name=$vm/name and vbdf=$vbdf] | $root/hv//IVSHMEM_VM[VM_NAME=$vm/name and VBDF=$vbdf]) = 1">
12    <xs:annotation acrn:severity="error" acrn:report-on="$root/hv//vuart_connection[type='pci']/endpoint[vm_name=$vm/name and vbdf=$vbdf] | $root/hv//IVSHMEM_VM[VM_NAME=$vm/name and VBDF=$vbdf]">
13      <xs:documentation>VM "{$vm/name}" contains multiple virtual UART controllers or IVSHMEM interfaces using BDF {$vbdf}. Adjust the BDF of those devices to be unique.</xs:documentation>
14    </xs:annotation>
15  </xs:assert>
16
17
18  <xs:assert test="every $root in /acrn-config satisfies
19                   every $vm in $root/vm[./load_order/text()='SERVICE_VM'] satisfies
20                   every $vbdf in $root/hv//vuart_connection[type='pci']/endpoint[vm_name=$vm/name]/vbdf/text() | $root/hv//IVSHMEM_VM[VM_NAME=$vm/name]/VBDF/text() satisfies
21                   contains(/acrn-config//PCI_DEVICE/text(), $vbdf) = false()">
22    <xs:annotation acrn:severity="error" acrn:report-on="$root/hv//vuart_connection[type='pci']/endpoint[vm_name=$vm/name and vbdf=$vbdf] | $root/hv//IVSHMEM_VM[VM_NAME=$vm/name and VBDF=$vbdf]">
23      <xs:documentation>VM "{$vm/name}" virtual UART controllers or IVSHMEM interfaces using BDF {$vbdf} conflict with native PCI device. Adjust the BDF of those devices to be unique.</xs:documentation>
24    </xs:annotation>
25  </xs:assert>
26
27  <xs:assert test="every $vm in /acrn-config//vm[./load_order/text() = 'PRE_LAUNCHED_VM' and ./mmio_resources/p2sb/text() = 'y'] satisfies
28                   count(/acrn-config//HIDDEN_PDEV[./text() = '00:1f.1']) = 0">
29    <xs:annotation acrn:severity="error" acrn:report-on="/acrn-config//p2sb[./text() = 'y']">
30      <xs:documentation>Can't passthrough P2SB to VM {/acrn-config//vm[./load_order/text() = 'PRE_LAUNCHED_VM' and .//p2sb/text() = 'y']/name/text()} because '00:1f.1' is set as a hidden device".</xs:documentation>
31    </xs:annotation>
32  </xs:assert>
33
34  <xs:assert test="every $ivshmem in /acrn-config//IVSHMEM_VM satisfies
35                   if (/acrn-config//vm[./name/text() = $ivshmem/VM_NAME/text()]/load_order/text() = 'POST_LAUNCHED_VM')
36                   then (substring-before(substring-after($ivshmem/VBDF/text(), ':'), '.') &gt; '02') and (substring-before(substring-after($ivshmem/VBDF/text(), ':'), '.') &lt; '1f')
37	           else true()">
38    <xs:annotation acrn:severity="error" acrn:report-on="$ivshmem">
39      <xs:documentation>For post launched VM, the "device" value of a virtual BDF, which is used by {$ivshmem/VM_NAME/text()}, shall not be '00', '01', '02' or '1f', i.e., the allowed values are between 03 and 1e, inclusive.</xs:documentation>
40    </xs:annotation>
41  </xs:assert>
42
43  <xs:assert test="every $endpoint in /acrn-config//endpoint satisfies
44                   if (/acrn-config//vm[./name/text() = $endpoint/vm_name/text()]/load_order/text() = 'POST_LAUNCHED_VM')
45                   then (substring-before(substring-after($endpoint/vbdf/text(), ':'), '.') &gt; '02') and (substring-before(substring-after($endpoint/VBDF/text(), ':'), '.') &lt; '1f')
46	           else true()">
47    <xs:annotation acrn:severity="error" acrn:report-on="$endpoint">
48      <xs:documentation>For post launched VM, the "device" value of a virtual BDF, which is used by {$endpoint/vm_name/text()}, shall not be '00', '01', '02' or '1f', i.e., the allowed values are between 03 and 1e, inclusive.</xs:documentation>
49    </xs:annotation>
50  </xs:assert>
51
52</xs:schema>
53