blob: df9eb65854756994fb1eb61d7e5b2561145474d6 [file] [log] [blame]
Ken Liu91d44da2018-09-20 22:42:31 +08001/*
Summer Qin1056d1c2022-10-19 16:07:15 +08002 * Copyright (c) 2018-2022, Arm Limited. All rights reserved.
Ken Liu91d44da2018-09-20 22:42:31 +08003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7#ifndef __TFM_UTILS_H__
8#define __TFM_UTILS_H__
9
Summer Qin83214922020-06-22 15:07:08 +080010#include <stdbool.h>
Ken Liu8fb61f12021-12-14 08:32:10 +080011#include <string.h>
Jimmy Brissona9052d72021-06-21 11:46:45 -050012#include "tfm_spm_log.h"
Edison Ai93dabfd2019-12-03 13:44:45 +080013
14/*
15 * CPU spin here.
16 * Note: this function is used to handle PROGRAMMER ERROR.
17 */
Edison Ai9059ea02019-11-28 13:46:14 +080018void tfm_core_panic(void);
Ken Liu91d44da2018-09-20 22:42:31 +080019
Summer Qin1056d1c2022-10-19 16:07:15 +080020/* SPM assert */
Ken Liuf250b8b2019-12-27 16:31:24 +080021#ifndef NDEBUG
Summer Qin1056d1c2022-10-19 16:07:15 +080022#define SPM_ASSERT(cond) \
23 do { \
24 if (!(cond)) { \
25 SPMLOG_INFMSG("Assert:"); \
26 SPMLOG_INFMSG(__func__); \
27 SPMLOG_INFMSGVAL(",", __LINE__); \
28 while (1) \
29 ; \
30 } \
Ken Liu91d44da2018-09-20 22:42:31 +080031 } while (0)
Ken Liuf250b8b2019-12-27 16:31:24 +080032#else
Summer Qin1056d1c2022-10-19 16:07:15 +080033#define SPM_ASSERT(cond)
Ken Liuf250b8b2019-12-27 16:31:24 +080034#endif
Ken Liu91d44da2018-09-20 22:42:31 +080035
Edison Ai1e5822f2018-09-21 14:56:08 +080036/* Get container structure start address from member */
Ken Liuc25558c2021-05-20 15:31:28 +080037#define TO_CONTAINER(ptr, type, member) \
Edison Ai1e5822f2018-09-21 14:56:08 +080038 (type *)((unsigned long)(ptr) - offsetof(type, member))
39
Antonio de Angelisfa5d4602021-06-09 16:11:11 +010040/* FixMe: Replace ERROR_MSG() in platform code with a suitable API */
41#define ERROR_MSG(msg) SPMLOG_ERRMSG(msg "\r\n")
Summer Qin83214922020-06-22 15:07:08 +080042
Ken Liud4d6a5b2021-10-27 19:28:26 +080043/* Stringify preprocessors, no leading underscore. ('STRINGIFY') */
44#define STRINGIFY_EXPAND(x) #x
45#define M2S(m) STRINGIFY_EXPAND(m)
Kevin Peng300c68d2021-08-12 17:40:17 +080046
Ken Liu8fb61f12021-12-14 08:32:10 +080047/* Runtime memory operations forwarding */
48#define spm_memcpy memcpy
49#define spm_memset memset
50
Ken Liuf250b8b2019-12-27 16:31:24 +080051#endif /* __TFM_UTILS_H__ */