SPM: Set STATIC_HANDLE_IDX_BIT_WIDTH as 5
The current used number of stateless handle is 32, which occupies only
5 bits. So change STATIC_HANDLE_IDX_BIT_WIDTH from 8 to 5 to avoid
unnecessary static handle index validation because it can not be larger
than 32.
Related document is also updated in this patch.
Signed-off-by: Xinyu Zhang <xinyu.zhang@arm.com>
Change-Id: I5bb9119ff7c03cc6a067fb291e3cbff2627ba49d
diff --git a/docs/design_docs/services/stateless_rot_service.rst b/docs/design_docs/services/stateless_rot_service.rst
index 964c18c..96b65ce 100644
--- a/docs/design_docs/services/stateless_rot_service.rst
+++ b/docs/design_docs/services/stateless_rot_service.rst
@@ -46,7 +46,9 @@
- reserved
* - bit 15 - bit 8
- service version requested by client - for client version check
- * - bit 7 - bit 0
+ * - bit 7 - bit 5
+ - reserved
+ * - bit 4 - bit 0
- the handle index, [0, 31]
Since connection-based services and stateless services share the same PSA API
@@ -84,7 +86,7 @@
==========================
This chapter describes the changes in programming API for stateless services.
-The following APIs' bebavious and message data structure members are updated to
+The following APIs' behavious and message data structure members are updated to
support the stateless service.
psa_connect()
diff --git a/secure_fw/spm/cmsis_psa/spm.h b/secure_fw/spm/cmsis_psa/spm.h
index 98e732b..7b4db44 100644
--- a/secure_fw/spm/cmsis_psa/spm.h
+++ b/secure_fw/spm/cmsis_psa/spm.h
@@ -33,7 +33,11 @@
#define STATIC_HANDLE_NUM_LIMIT 32
#define CLIENT_HANDLE_VALUE_MIN 1
-#define STATIC_HANDLE_IDX_BIT_WIDTH 8
+/*
+ * Bit width can be increased to match STATIC_HANDLE_NUM_LIMIT,
+ * current allowed maximum bit width is 8 for 256 handles.
+ */
+#define STATIC_HANDLE_IDX_BIT_WIDTH 5
#define STATIC_HANDLE_IDX_MASK \
(uint32_t)((1UL << STATIC_HANDLE_IDX_BIT_WIDTH) - 1)
#define GET_INDEX_FROM_STATIC_HANDLE(handle) \
@@ -51,10 +55,6 @@
#define IS_STATIC_HANDLE(handle) \
((handle) & (1UL << STATIC_HANDLE_INDICATOR_OFFSET))
-/* Valid index should be [0, STATIC_HANDLE_NUM_LIMIT-1] */
-#define IS_VALID_STATIC_HANDLE_IDX(index) \
- ((uint32_t)(index) < STATIC_HANDLE_NUM_LIMIT)
-
#define SPM_INVALID_PARTITION_IDX (~0U)
/* Get partition by thread or context data */
diff --git a/secure_fw/spm/ffm/psa_call_api.c b/secure_fw/spm/ffm/psa_call_api.c
index e9e81e5..3c4d563 100644
--- a/secure_fw/spm/ffm/psa_call_api.c
+++ b/secure_fw/spm/ffm/psa_call_api.c
@@ -60,10 +60,6 @@
if (IS_STATIC_HANDLE(handle)) {
index = GET_INDEX_FROM_STATIC_HANDLE(handle);
- if (!IS_VALID_STATIC_HANDLE_IDX(index)) {
- return PSA_ERROR_PROGRAMMER_ERROR;
- }
-
service = stateless_services_ref_tbl[index];
if (!service) {
return PSA_ERROR_PROGRAMMER_ERROR;
diff --git a/tools/tfm_parse_manifest_list.py b/tools/tfm_parse_manifest_list.py
index 9a9ba16..ed8d3fb 100644
--- a/tools/tfm_parse_manifest_list.py
+++ b/tools/tfm_parse_manifest_list.py
@@ -596,7 +596,7 @@
else:
raise Exception('Invalid stateless_handle setting: {handle}.'.format(handle=service['stateless_handle']))
- STATIC_HANDLE_IDX_BIT_WIDTH = 8
+ STATIC_HANDLE_IDX_BIT_WIDTH = 5
STATIC_HANDLE_IDX_MASK = (1 << STATIC_HANDLE_IDX_BIT_WIDTH) - 1
STATIC_HANDLE_INDICATOR_OFFSET = 30
STATIC_HANDLE_VER_OFFSET = 8