Runtime provisioning: Add partition

Add the runtime provisioning partition. This is a very basic partition
which allows platforms to hook in an interrupt from a provisioning comms
interface. The partition will wait for the interrupt and then process it
by calling into a platform specific HAL.

Change-Id: I478306c823e34cf6d18575039f5959d310b2afb2
Signed-off-by: Jackson Cooper-Driver <jackson.cooper-driver@arm.com>
diff --git a/partitions/runtime_provisioning/CMakeLists.txt b/partitions/runtime_provisioning/CMakeLists.txt
new file mode 100644
index 0000000..35a0dc4
--- /dev/null
+++ b/partitions/runtime_provisioning/CMakeLists.txt
@@ -0,0 +1,61 @@
+#-------------------------------------------------------------------------------
+# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
+#
+#-------------------------------------------------------------------------------
+
+if (NOT TFM_PARTITION_RUNTIME_PROVISIONING)
+    return()
+endif()
+
+cmake_minimum_required(VERSION 3.21)
+cmake_policy(SET CMP0079 NEW)
+
+# The name of the target is required to be of the pattern
+# tfm_app_rot_partition_x or tfm_psa_rot_partition_x, as it affects how the
+# linker script will lay the partition in memory.
+add_library(tfm_psa_rot_partition_runtime_provisioning STATIC)
+
+target_sources(tfm_psa_rot_partition_runtime_provisioning
+    PRIVATE
+        runtime_provisioning.c
+)
+
+# Add the source files generated by parse tools when building.
+# The intermedia file defines the partition stack.
+target_sources(tfm_psa_rot_partition_runtime_provisioning
+    PRIVATE
+        ${CMAKE_BINARY_DIR}/generated/secure_fw/partitions/runtime_provisioning/auto_generated/intermedia_runtime_provisioning.c
+)
+
+# The load info file includes the static data of the partition.
+target_sources(tfm_partitions
+    INTERFACE
+        ${CMAKE_BINARY_DIR}/generated/secure_fw/partitions/runtime_provisioning/auto_generated/load_info_runtime_provisioning.c
+)
+
+target_include_directories(tfm_psa_rot_partition_runtime_provisioning
+    PRIVATE
+        ${CMAKE_CURRENT_SOURCE_DIR}
+    PUBLIC
+        ${CMAKE_BINARY_DIR}/generated/secure_fw/partitions/runtime_provisioning
+)
+
+target_link_libraries(tfm_psa_rot_partition_runtime_provisioning
+    PRIVATE
+        tfm_sprt
+        runtime_provisioning_hal
+        platform_s
+)
+
+############################ Partition Defs ####################################
+
+target_link_libraries(tfm_partitions
+    INTERFACE
+        tfm_psa_rot_partition_runtime_provisioning
+)
+
+target_compile_definitions(tfm_config
+    INTERFACE
+        TFM_PARTITION_RUNTIME_PROVISIONING
+)
diff --git a/partitions/runtime_provisioning/runtime_provisioning.c b/partitions/runtime_provisioning/runtime_provisioning.c
new file mode 100644
index 0000000..eb0f4b8
--- /dev/null
+++ b/partitions/runtime_provisioning/runtime_provisioning.c
@@ -0,0 +1,38 @@
+/*
+ * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "runtime_provisioning_hal.h"
+#include "psa/service.h"
+#include "psa_manifest/runtime_provisioning.h"
+#include "tfm_log.h"
+
+void runtime_provisioning_main(void)
+{
+    enum runtime_provisioning_error_t err;
+
+    err = runtime_provisioning_hal_init();
+    if (err == RUNTIME_PROVISIONING_INVALID_STATE) {
+        /* Block forever without enabling interrupt as this partition is not
+         * required */
+        (void)psa_wait(RUNTIME_PROVISIONING_MESSAGE_SIGNAL, PSA_BLOCK);
+    } else if (err != RUNTIME_PROVISIONING_SUCCESS) {
+        psa_panic();
+    }
+
+    psa_irq_enable(RUNTIME_PROVISIONING_MESSAGE_SIGNAL);
+
+    INFO("Runtime provisioning partition initialised\n");
+
+    while (1) {
+        (void)psa_wait(RUNTIME_PROVISIONING_MESSAGE_SIGNAL, PSA_BLOCK);
+        err = runtime_provisioning_hal_process_message();
+        if (err != RUNTIME_PROVISIONING_SUCCESS) {
+            psa_panic();
+        }
+        psa_eoi(RUNTIME_PROVISIONING_MESSAGE_SIGNAL);
+    }
+}
diff --git a/partitions/runtime_provisioning/runtime_provisioning.yaml b/partitions/runtime_provisioning/runtime_provisioning.yaml
new file mode 100644
index 0000000..dbe9a0a
--- /dev/null
+++ b/partitions/runtime_provisioning/runtime_provisioning.yaml
@@ -0,0 +1,22 @@
+#-------------------------------------------------------------------------------
+# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
+#
+#-------------------------------------------------------------------------------
+
+{
+  "psa_framework_version": 1.1,
+  "name": "RUNTIME_PROVISIONING_PARTITION",
+  "type": "PSA-ROT",
+  "priority": "NORMAL",
+  "model": "IPC",
+  "entry_point": "runtime_provisioning_main",
+  "stack_size": "0x400",
+  "irqs": [
+    {
+      "source": "RUNTIME_PROVISIONING_MESSAGE_IRQ",
+      "name": "RUNTIME_PROVISIONING_MESSAGE",
+      "handling": "SLIH",
+    }
+  ],
+}
diff --git a/partitions/runtime_provisioning/runtime_provisioning_hal.h b/partitions/runtime_provisioning/runtime_provisioning_hal.h
new file mode 100644
index 0000000..aadb701
--- /dev/null
+++ b/partitions/runtime_provisioning/runtime_provisioning_hal.h
@@ -0,0 +1,22 @@
+/*
+ * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef __RUNTIME_PROVISIONING_HAL_H__
+#define __RUNTIME_PROVISIONING_HAL_H__
+
+enum runtime_provisioning_error_t {
+    RUNTIME_PROVISIONING_SUCCESS = 0,
+    RUNTIME_PROVISIONING_INVALID_STATE,
+    RUNTIME_PROVISIONING_NO_INTERRUPT,
+    RUNTIME_PROVISIONING_GENERIC_ERROR,
+};
+
+enum runtime_provisioning_error_t runtime_provisioning_hal_init(void);
+
+enum runtime_provisioning_error_t runtime_provisioning_hal_process_message(void);
+
+#endif /* __RUNTIME_PROVISIONING_HAL_H__ */
diff --git a/partitions/runtime_provisioning/runtime_provisioning_manifest_list.yaml b/partitions/runtime_provisioning/runtime_provisioning_manifest_list.yaml
new file mode 100644
index 0000000..5c6f8d4
--- /dev/null
+++ b/partitions/runtime_provisioning/runtime_provisioning_manifest_list.yaml
@@ -0,0 +1,28 @@
+#-------------------------------------------------------------------------------
+# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
+#
+#-------------------------------------------------------------------------------
+
+{
+  "description": "Runtime provisioning partition manifest",
+  "type": "manifest_list",
+  "version_major": 0,
+  "version_minor": 1,
+  "manifest_list": [
+    {
+      "description": "Runtime provisioning partition",
+      "manifest": "runtime_provisioning.yaml",
+      "output_path": "secure_fw/partitions/runtime_provisioning",
+      "conditional": "TFM_PARTITION_RUNTIME_PROVISIONING",
+      "version_major": 0,
+      "version_minor": 1,
+      "pid": 280,
+      "linker_pattern": {
+        "library_list": [
+           "*tfm_*partition_runtime_provisioning.*"
+        ]
+      }
+    }
+  ]
+}