Build: Follow the 'source_structure.rst'
This is the first patch to follow the first commit of source structure
document. The items under the 'secure_fw' folder are re-organized:
- Create/Move some folders/files to follow document.
- Rename some folders to foll, for example, 'secure_fw/services' to
'secure_fw/partitions'.
- Update affected files to make it work.
This is a big change, to make the structure meet the basic shape of
the structure document defined, and make it easier to be understood
for users. Staging changes are not applicable so they are combined
into one - and because it is not the final shape yet, so:
- Upcoming updates on the 'secure_fw' folder would follow up soon.
- Fine-tune about the 'source_structure.rst' would come, too.
Change-Id: I5c11175e0a4579cd9b42d3e3519dbffb87334d0b
Signed-off-by: Ken Liu <ken.liu@arm.com>
diff --git a/secure_fw/spm/runtime/spm_api.c b/secure_fw/spm/runtime/spm_api.c
new file mode 100644
index 0000000..a72b402
--- /dev/null
+++ b/secure_fw/spm/runtime/spm_api.c
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2017-2020, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+/* All the APIs defined in this file are common for library and IPC model. */
+
+#include <stdio.h>
+#include <string.h>
+#include "tfm/spm_api.h"
+#include "tfm_spm_hal.h"
+#include "tfm_memory_utils.h"
+#include "tfm/spm_db.h"
+#include "tfm_internal.h"
+#include "tfm_api.h"
+#include "tfm_nspm.h"
+#include "tfm_core.h"
+#include "tfm_peripherals_def.h"
+#include "tfm/spm_partition_defs.h"
+#include "region.h"
+
+#define NON_SECURE_INTERNAL_PARTITION_DB_IDX 0
+#define TFM_CORE_INTERNAL_PARTITION_DB_IDX 1
+
+/* Define SPM DB structure */
+#include "tfm_spm_db.inc"
+
+uint32_t get_partition_idx(uint32_t partition_id)
+{
+ uint32_t i;
+
+ if (partition_id == INVALID_PARTITION_ID) {
+ return SPM_INVALID_PARTITION_IDX;
+ }
+
+ for (i = 0; i < g_spm_partition_db.partition_count; ++i) {
+ if (g_spm_partition_db.partitions[i].static_data->partition_id ==
+ partition_id) {
+ return i;
+ }
+ }
+ return SPM_INVALID_PARTITION_IDX;
+}
+
+enum spm_err_t tfm_spm_db_init(void)
+{
+ uint32_t i;
+
+ /* This function initialises partition db */
+
+ /* For the non secure Execution environment */
+#ifndef TFM_PSA_API
+ tfm_nspm_configure_clients();
+#endif
+
+ for (i = 0; i < g_spm_partition_db.partition_count; i++) {
+#ifndef TFM_PSA_API
+ g_spm_partition_db.partitions[i].runtime_data.partition_state =
+ SPM_PARTITION_STATE_UNINIT;
+ g_spm_partition_db.partitions[i].runtime_data.caller_partition_idx =
+ SPM_INVALID_PARTITION_IDX;
+ g_spm_partition_db.partitions[i].runtime_data.caller_client_id =
+ TFM_INVALID_CLIENT_ID;
+ g_spm_partition_db.partitions[i].runtime_data.ctx_stack_ptr =
+ ctx_stack_list[i];
+#endif /* !defined(TFM_PSA_API) */
+ g_spm_partition_db.partitions[i].static_data = &static_data_list[i];
+ g_spm_partition_db.partitions[i].platform_data_list =
+ platform_data_list_list[i];
+#ifdef TFM_PSA_API
+ g_spm_partition_db.partitions[i].memory_data = &memory_data_list[i];
+#endif
+ }
+ g_spm_partition_db.is_init = 1;
+
+ return SPM_ERR_OK;
+}
+
+uint32_t tfm_spm_partition_get_partition_id(uint32_t partition_idx)
+{
+ return g_spm_partition_db.partitions[partition_idx].static_data->
+ partition_id;
+}
+
+uint32_t tfm_spm_partition_get_flags(uint32_t partition_idx)
+{
+ return g_spm_partition_db.partitions[partition_idx].static_data->
+ partition_flags;
+}
+
+uint32_t tfm_spm_partition_get_privileged_mode(uint32_t partition_flags)
+{
+ if (partition_flags & SPM_PART_FLAG_PSA_ROT) {
+ return TFM_PARTITION_PRIVILEGED_MODE;
+ } else {
+ return TFM_PARTITION_UNPRIVILEGED_MODE;
+ }
+}
+
+bool tfm_is_partition_privileged(uint32_t partition_idx)
+{
+ uint32_t flags = tfm_spm_partition_get_flags(partition_idx);
+
+ return tfm_spm_partition_get_privileged_mode(flags) ==
+ TFM_PARTITION_PRIVILEGED_MODE;
+}
+
+__attribute__((section("SFN")))
+void tfm_spm_partition_change_privilege(uint32_t privileged)
+{
+ CONTROL_Type ctrl;
+
+ ctrl.w = __get_CONTROL();
+
+ if (privileged == TFM_PARTITION_PRIVILEGED_MODE) {
+ ctrl.b.nPRIV = 0;
+ } else {
+ ctrl.b.nPRIV = 1;
+ }
+
+ __set_CONTROL(ctrl.w);
+}