<?xml version="1.0"?>
<xs:schema xml:id="root"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:acrn="https://projectacrn.org">

  <xs:assert test="if (//VCAT_ENABLED = 'y')
                   then (//CDP_ENABLED = 'n' and //RDT_ENABLED = 'y')
                   else true()">
    <xs:annotation acrn:severity="error" acrn:report-on="//CDP_ENABLED">
      <xs:documentation>Hypervisor Virtual Cache Allocation Technology may be enabled only when hypervisor Code and Data Prioritization is disabled.</xs:documentation>
    </xs:annotation>
  </xs:assert>

  <xs:assert test="if (//RDT_ENABLED = 'y' and //CDP_ENABLED = 'y')
                   then (count(//capability[./@id = 'CDP']) = count(//cache[./@level = '2' or ./@level = '3']))
                   else true()">
    <xs:annotation acrn:severity="error" acrn:report-on="//CDP_ENABLED">
      <xs:documentation>Code and Data Prioritization can only be opened when all L2 and L3 cache region has 'CDP' capability.</xs:documentation>
    </xs:annotation>
  </xs:assert>

  <xs:assert test="if (count(//virtual_cat_support[text() = 'y']) > 0)
                   then (//RDT_ENABLED = 'y' and //VCAT_ENABLED = 'y')
                   else true()">
    <xs:annotation acrn:severity="error" acrn:report-on="//VCAT_ENABLED">
      <xs:documentation>VM Virtual Cache Allocation Technology may be enabled only when hypervisor Virtual Cache Allocation Technology is enabled.</xs:documentation>
    </xs:annotation>
  </xs:assert>

  <xs:assert test="every $vm in //vm satisfies $vm//load_order != 'SERVICE_VM' or count($vm//lapic_passthrough[text() = 'y']) = 0 or count(//nested_virtualization_support[text() = 'y']) > 0">
    <xs:annotation acrn:severity="error" acrn:report-on="$vm//lapic_passthrough">
      <xs:documentation>The Service VM may not use LAPIC passthrough unless hypervisor Nested Virtualization is enabled.</xs:documentation>
    </xs:annotation>
  </xs:assert>

  <xs:assert test="empty(vm[load_order ='PRE_LAUNCHED_VM' and vm_type='RTVM']) or
		   every $cap in caches/cache[@level=3]/capability[@id='Software SRAM'] satisfies
		   (compare($cap/end, '0x80000000') &lt; 0 or compare($cap/start, '0xf8000000') &gt;= 0)">
    <xs:annotation acrn:severity="warning" acrn:report-on="hv//SSRAM_ENABLED">
      <xs:documentation>The physical software SRAM region may not overlap with pre-defined regions in any VM.

When a pre-launched RTVM is enabled, the physical software SRAM is allocated to it at the same guest physical
address. Thus it is assumed that the software SRAM region does not overlap with any pre-defined region in the
pre-launched VM, such as the guest PCI hole which resides at 2GB - 3.5GB.

This error cannot be fixed by adjusting the configuration. Report a `GitHub issue &lt;https://github.com/projectacrn/acrn-hypervisor/issues&gt;`_ if you receive this error.</xs:documentation>
    </xs:annotation>
  </xs:assert>

  <xs:assert test="every $needed in number-of-clos-id-needed(/acrn-config) satisfies
                   every $capacity in min(//caches/cache/capability[@id='CAT']/clos_number) satisfies
                   $needed &lt; $capacity">
    <xs:annotation acrn:severity="error" acrn:report-on="/acrn-config/hv/CACHE_REGION">
      <xs:documentation>The current CAT configuration requires {string($needed)} CLOS IDs, which exceeds the capacity of the platform which supports {string($capacity)} at most.</xs:documentation>
    </xs:annotation>
  </xs:assert>

  <xs:assert test="every $cache in //CACHE_ALLOCATION satisfies
                   every $ssram in //caches/cache[@level=$cache/CACHE_LEVEL and @id=$cache/CACHE_ID]/capability[@id='Software SRAM'] satisfies
                   every $policy in $cache/POLICY satisfies
                   bitwise-and($policy/CLOS_MASK, $ssram/waymask) = 0">
    <xs:annotation acrn:severity="error" acrn:report-on="/acrn-config/hv/CACHE_REGION">
      <xs:documentation>VM '{$policy/VM}' vCPU '{$policy/VCPU}' cannot use chunk(s) {bits-of($ssram/waymask)} of L{$cache/CACHE_LEVEL} cache (cache ID: {$cache/CACHE_ID}) as those chunks are consumed by software SRAM. </xs:documentation>
    </xs:annotation>
  </xs:assert>

</xs:schema>
