blob: f52707140306df78fda947add70ef419c9df3031 [file] [log] [blame]
Ken Liu91d44da2018-09-20 22:42:31 +08001/*
Ken Liuc25558c2021-05-20 15:31:28 +08002 * Copyright (c) 2018-2021, 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>
Edison Ai93dabfd2019-12-03 13:44:45 +080011#include <stdio.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
Ken Liuf250b8b2019-12-27 16:31:24 +080020/* Core assert and spin */
21#ifndef NDEBUG
22#define TFM_CORE_ASSERT(cond) \
Ken Liu91d44da2018-09-20 22:42:31 +080023 do { \
24 if (!(cond)) { \
Ken Liu91d44da2018-09-20 22:42:31 +080025 while (1) \
26 ; \
27 } \
28 } while (0)
Ken Liuf250b8b2019-12-27 16:31:24 +080029#else
30#define TFM_CORE_ASSERT(cond)
31#endif
Ken Liu91d44da2018-09-20 22:42:31 +080032
Edison Ai1e5822f2018-09-21 14:56:08 +080033/* Get container structure start address from member */
Ken Liuc25558c2021-05-20 15:31:28 +080034#define TO_CONTAINER(ptr, type, member) \
Edison Ai1e5822f2018-09-21 14:56:08 +080035 (type *)((unsigned long)(ptr) - offsetof(type, member))
36
Antonio de Angelisfa5d4602021-06-09 16:11:11 +010037/* FixMe: Replace ERROR_MSG() in platform code with a suitable API */
38#define ERROR_MSG(msg) SPMLOG_ERRMSG(msg "\r\n")
Summer Qin83214922020-06-22 15:07:08 +080039
Ken Liuf250b8b2019-12-27 16:31:24 +080040#endif /* __TFM_UTILS_H__ */