feat(tools/shrinkwrap): add overlay to build CCA stack with DA feature

Brings together a software stack to demonstrate Arm CCA running on FVP
in a three-world configuration with Device Assignment (DA) feature
based on RMM specification 1.1-alp12.

Signed-off-by: Arunachalam Ganapathy <arunachalam.ganapathy@arm.com>
Change-Id: I35ef09f2f1929557157a4b08daf65a52119dd890
diff --git a/docs/getting_started/building-with-shrinkwrap.rst b/docs/getting_started/building-with-shrinkwrap.rst
index 50d54b2..e27bf17 100644
--- a/docs/getting_started/building-with-shrinkwrap.rst
+++ b/docs/getting_started/building-with-shrinkwrap.rst
@@ -25,6 +25,8 @@
 `3 world configuration`_. In case that the Secure World also needs to be
 included, please refer to the `4 world configuration`_
 
+.. _Setup_local_RMM_with_Shrinkwrap:
+
 Setup local RMM with Shrinkwrap
 _______________________________
 
@@ -95,6 +97,96 @@
 
        shrinkwrap run cca-3world.yaml --rtvar=ROOTFS=${SHRINKWRAP_PACKAGE}/cca-3world/rootfs.ext2
 
+3-World testing with CCA DA
+___________________________
+
+Clone TF-RMM repository at branch ``topics/da_alp12``
+
+    .. code-block:: shell
+
+       git clone https://git.trustedfirmware.org/TF-RMM/tf-rmm.git -b topics/da_alp12
+
+Follow the instructions in :ref:`Setup_local_RMM_with_Shrinkwrap` to setup the
+local RMM with shrinkwrap.
+
+RMM provides ``cca_da.yaml`` overlay that can be used along with the
+``cca-3world.yaml`` to build a 3 World demonstrator using the ``master`` branch
+of |TF-A|, ``cca-1.1/da/proto/rmm-1.1-alp12/v1`` branch of Linux kernel,
+kvmtool, and the local clone of RMM repository from ``topics/da_alp12`` branch.
+
+As an example, the following command line would build the 3-World demonstrator.
+It assumes that Shrinkwrap is called from within the ``<RMM_ROOT>`` directory
+that was created in the last step:
+
+    .. code-block:: shell
+
+       shrinkwrap build cca-3world.yaml --overlay=cca_da.yaml --btvar GUEST_ROOTFS='${artifact:BUILDROOT}' --btvar RMM_SRC=${PWD} --no-sync=rmm
+
+Follow the steps mentioned in  `3 world configuration`_ documentation to copy
+guest-disk.img, KVMTOOL_EFI.fd and lkvm to the host filesystem.
+
+Shrinkwrap expects the FVP binary (e.g. FVP_Base_RevC-2xAEMvA) to be on your
+path.
+
+Now you can boot the host, using the rootfs we just modified, this assumes the
+FVP version used is ``11.29.27`` that has support for DA.
+
+    .. code-block:: shell
+
+       shrinkwrap run cca-3world.yaml --overlay=cca_da.yaml --rtvar ROOTFS=${SHRINKWRAP_PACKAGE}/cca-3world/rootfs.ext2
+
+Finally, once the host has booted, log in as “root” (no password). Below are the
+device assignment workflow based on the `DA workflow`_ cover letter from the
+Linux kernel cca-1.1 branch.
+
+Connect the device with TSM, this establishes secure session to the device and
+enables IDE in the link.
+
+    .. code-block:: shell
+
+       echo 0000:01:00.0 > /sys/bus/pci/devices/0000:01:00.0/driver/unbind
+       echo vfio-pci > /sys/bus/pci/devices/0000:01:00.0/driver_override
+       echo 0000:01:00.0 > /sys/bus/pci/drivers_probe
+       echo 1 > /sys/bus/pci/devices/0000:01:00.0/tsm/connect
+
+Now, launch a realm using kvmtool from the /cca directory (that was created
+above):
+
+    .. code-block:: shell
+
+       cd /cca
+       ./lkvm run --realm --in-kernel-smccc --firmware KVMTOOL_EFI.fd -c 2 -m 256 --no-pvtime --force-pci --disk guest-disk.img --measurement-algo=sha256 --vfio-secure-pci 0000:01:00.0
+
+Be patient while this boots to the UEFI shell. Navigate to “Boot Manager”, then
+“UEFI Shell” and wait for the startup.nsh script to execute, which will launch
+the kernel. Continue to be patient, and eventually you will land at a login
+prompt. Login as “root” (no password). In case if the user interrupts boot and
+enters to EFI shell, then use this command to continue boot.
+
+    .. code-block:: shell
+
+       Shell> bootaa64.efi root=/dev/vda2 acpi=force ip=on
+
+Now in the Realm we follow the below steps on the assigned device to move the
+device to TDISP LOCKED and RUN state:
+
+Moves the device to TDISP LOCKED state. At this step the Realm verifies the
+device attestation evidence that it got from the Host are valid by computing the
+digest and comparing it with the value it got from the RMM.
+
+    .. code-block:: shell
+
+       echo 0000:00:00.0 > /sys/bus/pci/devices/0000:00:00.0/driver/unbind
+       echo 1 > /sys/bus/pci/devices/0000:00:00.0/tsm/connect
+       echo 3 > /sys/bus/pci/devices/0000:00:00.0/tsm/connect
+
+
+Moves the device to TDISP RUN state
+
+    .. code-block:: shell
+
+       echo 4 > /sys/bus/pci/devices/0000:00:00.0/tsm/connect
+
 Testing RMM with TFTF
 _____________________
 
@@ -192,3 +284,4 @@
 .. _TF-A-Tests: https://trustedfirmware-a-tests.readthedocs.io/en/latest/index.html
 .. _btvar: https://shrinkwrap.docs.arm.com/en/latest/userguide/configmodel.html#defined-macros
 .. _rtvar: https://shrinkwrap.docs.arm.com/en/latest/userguide/configmodel.html#defined-macros
+.. _DA workflow: https://gitlab.arm.com/linux-arm/linux-cca/-/commit/8bdd9d4c98af43b28f8378515b75ea73077d22ee
diff --git a/tools/shrinkwrap/configs/cca_da.yaml b/tools/shrinkwrap/configs/cca_da.yaml
new file mode 100644
index 0000000..32677d4
--- /dev/null
+++ b/tools/shrinkwrap/configs/cca_da.yaml
@@ -0,0 +1,76 @@
+#
+# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-FileCopyrightText: Copyright TF-RMM Contributors.
+#
+
+%YAML 1.2
+---
+description: >-
+  Brings together a software stack to demonstrate Arm CCA running on FVP in a
+  three-world configuration with Device Assignment (DA) feature based on RMM
+  specification 1.1-alp12. This overlay enables necessary config options for
+  build in RMM and Linux. Enables FVP run config with extra command line
+  parameters to support DA.
+
+layers:
+  # Include layers from shrinkwrap repo
+  - buildroot.yaml
+  # Include layers from RMM repo
+  - rmm.yaml
+  - rmm-debug.yaml
+
+build:
+  rmm:
+    repo:
+      revision: topics/da_alp12
+    params:
+      -DRMM_V1_1: ON
+    build:
+      # Copy sample_keys from libspdm that will be used as device certificates
+      - cp -r ext/libspdm/unit_test/sample_key ${param:builddir}
+    artifacts:
+      SAMPLE_KEY: ${param:builddir}/sample_key
+
+  linux:
+    repo:
+      revision: cca-1.1/da/proto/rmm-1.1-alp12/v1
+    prebuild:
+      - ./scripts/config --file ${param:builddir}/.config --enable CONFIG_ARM_CCA_HOST
+      - ./scripts/config --file ${param:builddir}/.config --enable CONFIG_PCI_TSM
+      - ./scripts/config --file ${param:builddir}/.config --enable CONFIG_ARM_CCA_GUEST_REPORTS
+
+  kvmtool:
+    repo:
+      dtc:
+        revision: v1.6.1
+      kvmtool:
+        revision: cca-1.1/da/proto/rmm-1.1-alp12/v1
+
+run:
+  rtvars:
+    SAMPLE_KEY:
+      type: path
+      value: ${artifact:SAMPLE_KEY}
+
+  prerun:
+    # Create a sample disk image for AHCI controller
+    - DISK_IMG_DIR=`mktemp -d`
+    - function rm_disk_img_dir { rm -rf $$DISK_IMG_DIR; }
+    - trap rm_disk_img_dir EXIT
+    - dd if=/dev/zero of=$${DISK_IMG_DIR}/ahci1_disk.img bs=1M count=64 status=none
+
+  params:
+    # Enable DVSEC, IDE and support TDISP at RootPort
+    -C pci.pcie_rc.rootport0.rmeda_dvsec_enable: 1
+    -C pci.pcie_rc.rootport0.ide_supported: 1
+    -C pci.pcie_rc.rootport0.tee_io_supported: 1
+    # Enable DOE,IDE,TDISP at Endpoint
+    -C pci.pcie_rc.ahci1.endpoint.doe_supported: 1
+    -C pci.pcie_rc.ahci1.endpoint.ide_supported: 1
+    -C pci.pcie_rc.ahci1.endpoint.tee_io_supported: 1
+    # Use RSA3072 certificate bundle
+    -C pci.pcie_rc.ahci1.endpoint.bit_mask_of_base_asym_alg: 4
+    -C pci.pcie_rc.ahci1.endpoint.certificate_der_filename: ${rtvar:SAMPLE_KEY}/rsa3072/bundle_responder.certchain.der
+    -C pci.pcie_rc.ahci1.endpoint.private_key_filename: ${rtvar:SAMPLE_KEY}/rsa3072/end_responder.key
+    # Set the disk image
+    -C pci.pcie_rc.ahci1.ahci.image_path: $${DISK_IMG_DIR}/ahci1_disk.img