blob: 6c96ced90aeb03079b9236d1a823890ab4a133ad [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
Ken Liu8fb61f12021-12-14 08:32:10 +080010#include <string.h>
Jimmy Brissona9052d72021-06-21 11:46:45 -050011#include "tfm_spm_log.h"
Edison Ai93dabfd2019-12-03 13:44:45 +080012
13/*
14 * CPU spin here.
15 * Note: this function is used to handle PROGRAMMER ERROR.
16 */
Edison Ai9059ea02019-11-28 13:46:14 +080017void tfm_core_panic(void);
Ken Liu91d44da2018-09-20 22:42:31 +080018
Edison Ai1e5822f2018-09-21 14:56:08 +080019/* Get container structure start address from member */
Ken Liuc25558c2021-05-20 15:31:28 +080020#define TO_CONTAINER(ptr, type, member) \
Edison Ai1e5822f2018-09-21 14:56:08 +080021 (type *)((unsigned long)(ptr) - offsetof(type, member))
22
Antonio de Angelisfa5d4602021-06-09 16:11:11 +010023/* FixMe: Replace ERROR_MSG() in platform code with a suitable API */
24#define ERROR_MSG(msg) SPMLOG_ERRMSG(msg "\r\n")
Summer Qin83214922020-06-22 15:07:08 +080025
Ken Liud4d6a5b2021-10-27 19:28:26 +080026/* Stringify preprocessors, no leading underscore. ('STRINGIFY') */
27#define STRINGIFY_EXPAND(x) #x
28#define M2S(m) STRINGIFY_EXPAND(m)
Kevin Peng300c68d2021-08-12 17:40:17 +080029
Ken Liu8fb61f12021-12-14 08:32:10 +080030/* Runtime memory operations forwarding */
Raef Coles2ed4c5d2022-11-21 13:02:43 +000031#ifndef spm_memcpy
Ken Liu8fb61f12021-12-14 08:32:10 +080032#define spm_memcpy memcpy
Jamie Foxc48bb6c2022-12-01 15:51:43 +000033#else
34void *spm_memcpy(void *dest, const void *src, size_t n);
Raef Coles2ed4c5d2022-11-21 13:02:43 +000035#endif /* spm_memcpy */
36
37#ifndef spm_memset
Ken Liu8fb61f12021-12-14 08:32:10 +080038#define spm_memset memset
Jamie Foxc48bb6c2022-12-01 15:51:43 +000039#else
40void *spm_memset(void *s, int c, size_t n);
Raef Coles2ed4c5d2022-11-21 13:02:43 +000041#endif /* spm_memset */
Ken Liu8fb61f12021-12-14 08:32:10 +080042
Ken Liuf250b8b2019-12-27 16:31:24 +080043#endif /* __TFM_UTILS_H__ */