Remove OP-TEE dependency on trace functions

Introducing a custom trace component which replaces the one that comes
from the SP dev kit. The new component provides the same DMSG, IMSG,
EMSG macros for printing trace messages with different levels.

Signed-off-by: Imre Kis <imre.kis@arm.com>
Change-Id: I5f9466c5a32fefeb9ef350b179dc22ee33324f7e
diff --git a/environments/opteesp/component.cmake b/environments/opteesp/component.cmake
index f7e391f..bd6e036 100644
--- a/environments/opteesp/component.cmake
+++ b/environments/opteesp/component.cmake
@@ -11,9 +11,23 @@
 
 target_sources(${TGT} PRIVATE
 	"${CMAKE_CURRENT_LIST_DIR}/libsp_entry.c"
+	"${CMAKE_CURRENT_LIST_DIR}/sp_trace.c"
 	)
 
 target_include_directories(${TGT}
-         PUBLIC
-                "${CMAKE_CURRENT_LIST_DIR}/include"
-        )
+	PUBLIC
+		"${CMAKE_CURRENT_LIST_DIR}/include"
+	)
+
+if (NOT DEFINED TRACE_PREFIX)
+	set(TRACE_PREFIX "SP" CACHE STRING "Trace prefix")
+endif()
+
+if (NOT DEFINED TRACE_LEVEL)
+	set(TRACE_LEVEL "TRACE_LEVEL_ERROR" CACHE STRING "Trace level")
+endif()
+
+target_compile_definitions(${TGT} PRIVATE
+	TRACE_LEVEL=${TRACE_LEVEL}
+	TRACE_PREFIX="${TRACE_PREFIX}"
+)
diff --git a/environments/opteesp/libsp_entry.c b/environments/opteesp/libsp_entry.c
index 683b37c..68f410b 100644
--- a/environments/opteesp/libsp_entry.c
+++ b/environments/opteesp/libsp_entry.c
@@ -18,13 +18,6 @@
 	sp_main((struct ffa_init_info *)a0);
 }
 
-void optee_sp_log_puts(const char *str)
-{
-	struct ffa_params resp;
-
-	ffa_svc(0xdeadbeef, (uintptr_t)str, 0, 0, 0, 0, 0, 0, &resp);
-}
-
 void __noreturn optee_sp_panic(void)
 {
 	while (1)
diff --git a/environments/opteesp/sp_trace.c b/environments/opteesp/sp_trace.c
new file mode 100644
index 0000000..6ac0ddc
--- /dev/null
+++ b/environments/opteesp/sp_trace.c
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: BSD-3-Clause
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ */
+
+#include "trace.h"
+#include "ffa_internal_api.h"
+
+#if TRACE_LEVEL >= TRACE_LEVEL_ERROR
+
+void trace_puts(const char *str)
+{
+	struct ffa_params resp;
+
+	ffa_svc(0xdeadbeef, (uintptr_t)str, 0, 0, 0, 0, 0, 0, &resp);
+}
+
+#endif  /* TRACE_LEVEL >= TRACE_LEVEL_ERROR */