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

<xs:simpleType name="Boolean">
  <xs:annotation acrn:widget="b-form-checkbox" acrn:widget-options="'value': 'y', 'unchecked-value': 'n'">
    <xs:documentation>A Boolean value, displayed as a check box.</xs:documentation>
  </xs:annotation>
  <xs:restriction base="xs:string">
    <xs:enumeration value="y" />
    <xs:enumeration value="n" />
  </xs:restriction>
</xs:simpleType>

<xs:simpleType name="HexFormat">
  <xs:annotation acrn:widget-options="'placeholder': 'A hexadecimal number with a leading 0x, e.g. 0x1000.'"
                 acrn:errormsg="'pattern': 'Must be a hexadecimal integer (case-insensitive).'">
    <xs:documentation>An Integer value in hexadecimal format (with a leading ``0x``).</xs:documentation>
  </xs:annotation>
  <xs:restriction base="xs:string">
    <xs:pattern value="0[Xx][0-9A-Fa-f]+|0" />
  </xs:restriction>
</xs:simpleType>

<xs:simpleType name="None">
  <xs:restriction base="xs:string">
    <xs:pattern value="[*]{0}" />
  </xs:restriction>
</xs:simpleType>

<xs:simpleType name="BuildType">
  <xs:annotation>
    <xs:documentation>A string with value ``Release`` or ``Debug`` that indicates the build type of the hypervisor.</xs:documentation>
  </xs:annotation>
  <xs:restriction base="xs:string">
    <xs:enumeration value="release">
      <xs:annotation acrn:title="Release" />
    </xs:enumeration>
    <xs:enumeration value="debug">
      <xs:annotation acrn:title="Debug" />
    </xs:enumeration>
  </xs:restriction>
</xs:simpleType>

<xs:simpleType name="KernLoadAddr">
  <xs:annotation>
    <xs:documentation>Either empty, or an Integer value in hexadecimal format.</xs:documentation>
  </xs:annotation>
  <xs:union memberTypes="None HexFormat" />
</xs:simpleType>

<xs:simpleType name="KernEntryAddr">
  <xs:annotation>
    <xs:documentation>Either empty, or an Integer value in hexadecimal format.</xs:documentation>
  </xs:annotation>
  <xs:union memberTypes="None HexFormat" />
</xs:simpleType>

<xs:simpleType name="MaxMsixTableNumType">
  <xs:annotation>
    <xs:documentation>Integer from 1 to 2048.</xs:documentation>
  </xs:annotation>
  <xs:restriction base="xs:integer">
    <xs:minInclusive value="1" />
    <xs:maxInclusive value="2048" />
  </xs:restriction>
</xs:simpleType>

<xs:simpleType name="MaxMsixTableSizeType">
  <xs:annotation>
    <xs:documentation>Either empty, or an Integer value between 1 and 2048.</xs:documentation>
  </xs:annotation>
  <xs:union memberTypes="None MaxMsixTableNumType" />
</xs:simpleType>

<xs:simpleType name="MemorySizeType">
  <xs:annotation>
    <xs:documentation>An Integer value in hexadecimal format.</xs:documentation>
  </xs:annotation>
  <xs:union memberTypes="HexFormat" />
</xs:simpleType>

<xs:simpleType name="LogLevelType">
  <xs:annotation>
    <xs:documentation>An Integer from 0 to 5 representing log message
severity and intent:

- ``0: None``: No log at all.
- ``1: Critical``: Messages about critical errors that cause the hypervisor to crash or hang (almost) immediately.
- ``2: Error``: Messages about significant errors that affect the main functions (for example, launch of VMs) of ACRN hypervisor.
- ``3: Warning``: Messages about detected abnormalities that have local effects on certain features.
- ``4: Information``: Informational messages
- ``5: Debug``: Debug-level messages

A lower value has a higher severity. Log messages with a
higher value (lower severity) are discarded.</xs:documentation>
  </xs:annotation>
  <xs:restriction base="xs:string">
    <xs:enumeration value="0">
      <xs:annotation acrn:title="0: None" />
    </xs:enumeration>
    <xs:enumeration value="1">
      <xs:annotation acrn:title="1: Critical" />
    </xs:enumeration>
    <xs:enumeration value="2">
      <xs:annotation acrn:title="2: Error" />
    </xs:enumeration>
    <xs:enumeration value="3">
      <xs:annotation acrn:title="3: Warning" />
    </xs:enumeration>
    <xs:enumeration value="4">
      <xs:annotation acrn:title="4: Information" />
    </xs:enumeration>
    <xs:enumeration value="5">
      <xs:annotation acrn:title="5: Debug" />
    </xs:enumeration>
  </xs:restriction>
</xs:simpleType>

<xs:simpleType name="SchedulerType">
  <xs:annotation>
    <xs:documentation>A string specifying the scheduling option:

- ``No-Operation (NOOP)``: The No-Operation (NOOP) scheduler means there is a
  strict one-to-one mapping between vCPUs and pCPUs.
- ``Borrowed Virtual Time``: The Borrowed Virtual Time (BVT) scheduler is a
  virtual time-based scheduling algorithm. It dispatches the runnable thread with the
  earliest effective virtual time.
- ``Priority Based Scheduling``: The priority based scheduler supports vCPU scheduling based on pre-configured priorities.
    </xs:documentation>
    <xs:documentation>Read more about the available scheduling options in :ref:`cpu_sharing`.</xs:documentation>
  </xs:annotation>
  <xs:restriction base="xs:string">
    <xs:enumeration value="SCHED_NOOP">
      <xs:annotation acrn:title="No-Operation (NOOP)" />
    </xs:enumeration>
    <xs:enumeration value="SCHED_IORR">
      <xs:annotation acrn:views="" />
    </xs:enumeration>
    <xs:enumeration value="SCHED_BVT">
      <xs:annotation acrn:title="Borrowed Virtual Time" />
    </xs:enumeration>
    <xs:enumeration value="SCHED_PRIO">
      <xs:annotation acrn:title="Priority Based Scheduling" />
    </xs:enumeration>
  </xs:restriction>
</xs:simpleType>

<xs:simpleType name="policyType">
  <xs:annotation>
    <xs:documentation>A string specifying the CPU frequency policy type:

- ``Performance``: CPU runs at its maximum frequency. Enable hardware autonomous frequency selection if the system supports Hardware-Controlled Performance States (HWP).
- ``Nominal``: CPU runs at its guaranteed frequency.
    </xs:documentation>
  </xs:annotation>
  <xs:restriction base="xs:string">
    <xs:enumeration value="Performance">
      <xs:annotation acrn:title="Performance" />
    </xs:enumeration>
    <xs:enumeration value="Nominal">
      <xs:annotation acrn:title="Nominal" />
    </xs:enumeration>
  </xs:restriction>
</xs:simpleType>

<xs:simpleType name="PriorityType">
  <xs:annotation>
    <xs:documentation>Two priorities are supported for priority based scheduler:

- ``PRIO_LOW``: low priority for vCPU scheduling.
- ``PRIO_HIGH``: high priority for vCPU scheduling.
    </xs:documentation>
  </xs:annotation>
  <xs:restriction base="xs:string">
    <xs:enumeration value="PRIO_LOW" />
    <xs:enumeration value="PRIO_HIGH" />
  </xs:restriction>
</xs:simpleType>

<xs:simpleType name="SerialConsoleType">
  <xs:restriction base="xs:string">
    <xs:pattern value="(.*ttyS[\d]+)|None" />
  </xs:restriction>
</xs:simpleType>

<xs:simpleType name="VMNameType">
  <xs:annotation acrn:widget-options="'placeholder': 'A string with at most 15 non-space characters, e.g. Linux-VM-1.'"
                 acrn:errormsg="'pattern': 'Must NOT be longer than 15 characters or contain characters other than letters, digits, \'_\' and \'-\'.'">
    <xs:documentation>A string of up to 15 letters, digits, ``_``, or ``-``.</xs:documentation>
  </xs:annotation>
  <xs:restriction base="xs:string">
    <xs:pattern value="([a-zA-Z0-9_\-]){1,15}" />
  </xs:restriction>
</xs:simpleType>

<xs:simpleType name="VBDFType">
  <xs:annotation acrn:errormsg="'pattern': 'A string with up to two hex digits, a ``:``, two hex digits, a ``.``, and one digit between 0-7.'">
    <xs:documentation>A string with up to two hex digits, a ``:``, two hex digits, a ``.``, and one digit between 0-7.</xs:documentation>
  </xs:annotation>
  <xs:restriction base="xs:string">
    <xs:pattern value="[0-9A-Fa-f]{1,2}:[0-1][0-9A-Fa-f]\.[0-7]" />
  </xs:restriction>
</xs:simpleType>

<xs:simpleType name="ProviderType">
  <xs:annotation>
    <xs:documentation>A string with value ``Hypervisor`` or ``Device Model``.</xs:documentation>
  </xs:annotation>
  <xs:restriction base="xs:string">
    <xs:enumeration value="Hypervisor" />
    <xs:enumeration value="Device Model" />
  </xs:restriction>
</xs:simpleType>

<xs:complexType name="IVSHMEMVM">
  <xs:sequence>
   <xs:element name="VM_NAME" type="VMNameType" minOccurs="1">
     <xs:annotation acrn:title="Shared VMs">
       <xs:documentation>Name of the VM that uses this shared memory region.</xs:documentation>
     </xs:annotation>
   </xs:element>
   <xs:element name="VBDF" type = "VBDFType">
     <xs:annotation acrn:title="Virtual BDF" acrn:defaults="[f'00:{i:02x}.0' for i in range(8, 16)]" acrn:unique-among="//IVSHMEM_VM[VM_NAME=$parent/VM_NAME]/VBDF/text()">
       <xs:documentation>Virtual BDF (Bus Device Function) is automatically assigned and can be changed if needed. Set in Hex.</xs:documentation>
     </xs:annotation>
   </xs:element>
  </xs:sequence>
</xs:complexType>

<xs:complexType name="IVSHMEMVMS">
  <xs:annotation>
    <xs:documentation>A sequence of Shared VM names and their Virtual BDF values.</xs:documentation>
  </xs:annotation>
  <xs:sequence>
   <xs:element name="IVSHMEM_VM" type="IVSHMEMVM" maxOccurs="unbounded">
     <xs:annotation>
       <xs:documentation>Select all VMs that use the shared memory region.</xs:documentation>
     </xs:annotation>
   </xs:element>
  </xs:sequence>
</xs:complexType>

<xs:simpleType name="IVSHMEMSize">
  <xs:annotation>
    <xs:documentation>An Integer with value a power of 2 between 2 and 512.</xs:documentation>
  </xs:annotation>
  <xs:restriction base="xs:integer">
    <xs:enumeration value="2" />
    <xs:enumeration value="4" />
    <xs:enumeration value="8" />
    <xs:enumeration value="16" />
    <xs:enumeration value="32" />
    <xs:enumeration value="64" />
    <xs:enumeration value="128" />
    <xs:enumeration value="256" />
    <xs:enumeration value="512" />
  </xs:restriction>
</xs:simpleType>

<xs:complexType name="IVSHMEMRegionType">
  <xs:all>
    <xs:element name="NAME" minOccurs="1">
      <xs:annotation acrn:title="Region Name">
        <xs:documentation>Name of the shared memory region. The name must be between 1-27 characters and contain only letters, digits and "_".</xs:documentation>
      </xs:annotation>
      <xs:simpleType>
  <xs:annotation>
    <xs:documentation>Must be 1-27 characters and only letters, digits and "_".</xs:documentation>
  </xs:annotation>
	<xs:restriction base="xs:string">
	  <xs:pattern value="\w{1,27}" />
	</xs:restriction>
      </xs:simpleType>
    </xs:element>
    <xs:element name="PROVIDED_BY" type="ProviderType" default="Hypervisor">
      <xs:annotation acrn:title="Emulated by">
        <xs:documentation>Whether the shared memory region is emulated by the hypervisor or Device Model.</xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element name="IVSHMEM_SIZE" type="IVSHMEMSize" default="2">
      <xs:annotation acrn:title="Region Size (MB)">
        <xs:documentation>Select the size of the shared memory region
in megabytes. The value should be a power of 2
and no more than 512.</xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element name="IVSHMEM_VMS" type="IVSHMEMVMS">
      <xs:annotation acrn:title="Shared VMs">
        <xs:documentation>Select all VMs that use the shared memory region.</xs:documentation>
      </xs:annotation>
    </xs:element>
  </xs:all>
</xs:complexType>

<xs:complexType name="IVSHMEMInfo">
  <xs:sequence>
    <xs:element name="IVSHMEM_REGION" type="IVSHMEMRegionType" minOccurs="0" maxOccurs="unbounded">
      <xs:annotation>
        <xs:documentation>Create a memory region for VMs to share: specify its name, size, and associated VMs.</xs:documentation>
      </xs:annotation>
    </xs:element>
  </xs:sequence>
</xs:complexType>

<xs:complexType name="RDTType">
  <xs:sequence>
    <xs:element name="RDT_ENABLED" type="Boolean" default="n">
      <xs:annotation acrn:title="Intel Resource Director Tech">
        <xs:documentation>Enable Cache Allocation Technology of Intel Resource Director Technology (RDT). If
the board hardware does not support RDT, enabling this option is ignored.</xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element name="CDP_ENABLED" type="Boolean" default="n">
      <xs:annotation acrn:title="Code and Data Prioritization">
        <xs:documentation>Enable Code and Data Prioritization (CDP). CDP provides control over code and data placement in cache to improve an application's real-time performance.</xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element name="VCAT_ENABLED" type="Boolean" default="n">
      <xs:annotation acrn:title="Virtual Cache Allocation Tech">
        <xs:documentation>Enable virtualization of the Cache Allocation Technology (CAT) feature in RDT. CAT enables you to allocate cache to VMs, providing isolation to avoid performance interference from other VMs.</xs:documentation>
      </xs:annotation>
    </xs:element>
  </xs:sequence>
</xs:complexType>

<xs:complexType name="SSRAMInfo">
  <xs:sequence>
    <xs:element name="SSRAM_ENABLED" type="Boolean" default="n">
      <xs:annotation acrn:title="Software SRAM">
        <xs:documentation>Enable Software SRAM. This feature reserves memory buffers as always-cached memory to improve an application's real-time performance.</xs:documentation>
      </xs:annotation>
    </xs:element>
  </xs:sequence>
</xs:complexType>

<xs:simpleType name="CacheType">
  <xs:annotation>
    <xs:documentation>Option: Unified, Code, Data</xs:documentation>
  </xs:annotation>
  <xs:restriction base="xs:string">
    <xs:enumeration value="Unified"/>
    <xs:enumeration value="Code" />
    <xs:enumeration value="Data" />
  </xs:restriction>
</xs:simpleType>

<xs:complexType name="CachePolicyType">
  <xs:sequence>
    <xs:element name="VM" type="xs:string">
      <xs:annotation acrn:title="VM Name">
        <xs:documentation>The Name of VM</xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element name="VCPU" type="xs:integer">
      <xs:annotation acrn:title="Virtual CPU ID">
        <xs:documentation>The Virtual CPU index of VM</xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element name="TYPE" type="CacheType" minOccurs="1">
      <xs:annotation acrn:title="Cache Type">
        <xs:documentation>The Type of Cache Region</xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element name="CLOS_MASK" type="HexFormat">
      <xs:annotation acrn:title="Cache CLOS Mask">
        <xs:documentation>The Cache Region Mask</xs:documentation>
      </xs:annotation>
    </xs:element>
  </xs:sequence>
</xs:complexType>

<xs:complexType name="CacheAllocationType">
  <xs:sequence>
    <xs:element name="CACHE_ID" type="HexFormat">
      <xs:annotation acrn:title="Cache ID">
        <xs:documentation>The Cache Region index</xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element name="CACHE_LEVEL" type="xs:integer">
      <xs:annotation acrn:title="Cache Level">
        <xs:documentation>The Cache Region Level</xs:documentation>
      </xs:annotation>
    </xs:element>
    <xs:element name="POLICY" type="CachePolicyType"  minOccurs="1" maxOccurs="unbounded"/>
  </xs:sequence>
</xs:complexType>

<xs:complexType name="CacheRegionType">
  <xs:sequence>
    <xs:element name="CACHE_ALLOCATION" type="CacheAllocationType"  minOccurs="1" maxOccurs="unbounded"/>
  </xs:sequence>
</xs:complexType>

</xs:schema>
