1/*
2 * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
3 * Copyright (c) 2024, Cypress Semiconductor Corporation (an Infineon company)
4 * or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 *
8 */
9/***********{{utilities.donotedit_warning}}***********/
10
11#ifndef __CONFIG_IMPL_H__
12#define __CONFIG_IMPL_H__
13
14#include "config_tfm.h"
15
16/* Backends */
17#define {{"%-56s"|format("CONFIG_TFM_SPM_BACKEND_IPC")}} {{config_impl['CONFIG_TFM_SPM_BACKEND_IPC']}}
18#define {{"%-56s"|format("CONFIG_TFM_SPM_BACKEND_SFN")}} {{config_impl['CONFIG_TFM_SPM_BACKEND_SFN']}}
19
20#define {{"%-56s"|format("CONFIG_TFM_CONNECTION_BASED_SERVICE_API")}} {{config_impl['CONFIG_TFM_CONNECTION_BASED_SERVICE_API']}}
21#define {{"%-56s"|format("CONFIG_TFM_MMIO_REGION_ENABLE")}} {{config_impl['CONFIG_TFM_MMIO_REGION_ENABLE']}}
22#define {{"%-56s"|format("CONFIG_TFM_FLIH_API")}} {{config_impl['CONFIG_TFM_FLIH_API']}}
23#define {{"%-56s"|format("CONFIG_TFM_SLIH_API")}} {{config_impl['CONFIG_TFM_SLIH_API']}}
24
25#if CONFIG_TFM_SPM_BACKEND_IPC == 1
26/* Trustzone NS agent working stack size. */
27#if defined(TFM_FIH_PROFILE_ON) && TFM_ISOLATION_LEVEL == 1
28#define {{"%-56s"|format("CONFIG_TFM_NS_AGENT_TZ_STACK_SIZE")}} 1256
29#else
30#define {{"%-56s"|format("CONFIG_TFM_NS_AGENT_TZ_STACK_SIZE")}} 1024
31#endif
32
33#if !defined CONFIG_TFM_USE_TRUSTZONE
34/* SPM has to have its own stack if Trustzone isn't present. */
35#if defined(TFM_FIH_PROFILE_ON)
36#define {{"%-56s"|format("CONFIG_TFM_SPM_THREAD_STACK_SIZE")}}  1536
37#else
38#define {{"%-56s"|format("CONFIG_TFM_SPM_THREAD_STACK_SIZE")}}  1024
39#endif
40#endif
41
42#elif CONFIG_TFM_SPM_BACKEND_SFN == 1
43    {% set total_stk = namespace(size="0") %}
44    {% for partition in partitions %}
45        {% set total_stk.size = total_stk.size + " + " + partition.manifest.stack_size %}
46    {% endfor %}
47/*
48 * In isolation level 1 SFN model, all subsequent components work on NS agent
49 * stack. It is observed that half of the sum of all partition stack sizes is
50 * enough for working. Define a divisor factor
51 * CONFIG_TFM_NS_AGENT_TZ_STK_SIZE_SHIFT_FACTOR for reference, and allow
52 * modification of the factor based on application situation. The stack size
53 * value is aligned to 8 bytes.
54 * The minimum value is 0x400 to satisfy the SPM functional requirement.
55 * Manifest tool will assure this.
56 */
57#define {{"%-56s"|format("CONFIG_TFM_TOTAL_STACK_SIZE")}} ({{total_stk.size}})
58#if (CONFIG_TFM_TOTAL_STACK_SIZE < 2048)
59#undef {{"%-56s"|format("CONFIG_TFM_TOTAL_STACK_SIZE")}}
60#define {{"%-56s"|format("CONFIG_TFM_TOTAL_STACK_SIZE")}} 2048
61#endif
62
63#define CONFIG_TFM_NS_AGENT_TZ_STK_SIZE_SHIFT_FACTOR             1
64#define {{"%-56s"|format("CONFIG_TFM_NS_AGENT_TZ_STACK_SIZE")}}  \
65    (((CONFIG_TFM_TOTAL_STACK_SIZE >> CONFIG_TFM_NS_AGENT_TZ_STK_SIZE_SHIFT_FACTOR) + 0x7) & (~0x7))
66
67#endif /* CONFIG_TFM_SPM_BACKEND_IPC == 1 */
68
69{% set arot = namespace(CONFIG_TFM_AROT_PRESENT="0") %}
70{% for partition in partitions %}
71    {% if partition.manifest.type == 'APPLICATION-ROT' %}
72        {% set arot.CONFIG_TFM_AROT_PRESENT = 1 %}
73    {% endif %}
74{% endfor %}
75/* Define whether ARoT partitions are present. Can be used when applying protections. */
76#define CONFIG_TFM_AROT_PRESENT                                  {{arot.CONFIG_TFM_AROT_PRESENT}}
77
78#endif /* __CONFIG_IMPL_H__ */
79