summaryrefslogtreecommitdiffstats
path: root/src/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/include')
-rw-r--r--src/include/trace_adal.h249
-rw-r--r--src/include/tracinterface.H315
-rw-r--r--src/include/usr/trace/interface.H350
3 files changed, 350 insertions, 564 deletions
diff --git a/src/include/trace_adal.h b/src/include/trace_adal.h
deleted file mode 100644
index fb8e1501e..000000000
--- a/src/include/trace_adal.h
+++ /dev/null
@@ -1,249 +0,0 @@
-/******************************************************************************
- * IBM Confidential
- *
- * Licensed Internal Code Source Materials
- *
- * IBM Flexible Support Processor Licensed Internal Code
- *
- * (c) Copyright IBM Corp. 2004, 2009
- *
- * The source code is for this program is not published or otherwise divested
- * of its trade secrets, irrespective of what has been deposited with the
- * U.S. Copyright Office.
- *****************************************************************************
- * \file trace_adal.h
- * \brief Contains header data for trace component..
- *
- * The trace component allows an application to trace its execution into
- * circular buffers (like a flight recorder) with low performance and
- * memory usage impact. This implementation focuses on the Linux operating
- * system running on embedded controllers.
- *
- * \note Please see the document trace_doc.lyx for full documentation on this
- * \note component.
- *****************************************************************************/
-
-
-#ifndef _TRACE_ADAL_H
-#define _TRACE_ADAL_H
-
-#include <stdint.h>
-
-/**
- * @brief Maximum size of component name
- * @note Make sure to also change in include/linux/trac.h -
- * TRACER_FSP_TRACE_NAME_SIZE
-*/
-#define TRACE_MAX_COMP_NAME_SIZE 16
-
-#define TRACE_DEBUG_ON 1 //Set to this when debug trace on
-#define TRACE_DEBUG_OFF 0 //Set to this when debug trace off
-#define TRACE_DEBUG 1 //Pass this when trace is debug
-#define TRACE_FIELD 0 //Pass this when trace is field
-
-#define TRACE_COMP_TRACE 0x434F //Identifies trace as a component trace (printf)
-#define TRACE_BINARY_TRACE 0x4249 //Identifies trace as a binary trace
-#define TRACE_INTERNAL_BLOCKED 0xFF42 //Identifies trace as an dd internal trace
-
-#define TRACE_BUFFER_VERSION 1 //Trace buffer version
-#define TRACE_BUFFER_BINARY_VERSION 2 //Trace buffer version when collected by fsp-trace from pipe
-
-#define TRACE_DEFAULT_TD 0 //Default trace descriptor
-
-
-/*
- * Parsing and output modifier flags
- */
-
-/* When multiple buffers are given the traces of all buffers are sorted by timestamp and printed as one list.
- * If this flag is not given the traces are printed separatly for each trace buffers (i.e. grouped by buffer).
- */
-#define TRACE_MIX_BUFFERS 1
-
-/* Show the name of a trace buffer for each trace. The buffer name will be inserted between timestamp and trace text.
- * Only one of TRACE_APPEND_BUFFERNAME and TRACE_PREPEND_BUFFERNAME can be given.
- */
-#define TRACE_PREPEND_BUFFERNAME 2
-
-/* Show the name of a trace buffer for each trace. The buffer name will be appended at the end of the line
- * (after trace text). Only one of TRACE_APPEND_BUFFERNAME and TRACE_PREPEND_BUFFERNAME can be given.
- */
-#define TRACE_APPEND_BUFFERNAME 4
-
-/* When set timestamps are translated to timeofday values (date/time). This needs "timeref" to be given.
- * If timeref is not given the timestamps are treated as if the PPC timebase counter was started at epoch time
- * (i.e. the printed timestamp will be the time since FSP boot time).
- */
-#define TRACE_TIMEOFDAY 8
-
-/* If a TIMEREF trace is found in a trace buffer and timeref is a valid
- * pointer the values from the TIMEREF trace are written to timeref. This flag is independent of TRACE_TIMEOFDAY.
- */
-#define TRACE_SET_TIMEOFDAY 16
-
-/* Show the name of the source file that contains the trace statement for each trace.
- * (at the end of the line, after buffer name if this is printed too).
- */
-#define TRACE_FILENAME 32
-#define TRACE_VERBOSE 64 //some messages are printed to STDERR.
-#define TRACE_IGNORE_VERSION 128
-#define TRACE_OVERWRITE 256
-#define TRACE_BINARY 512
-
-/* When this is set trace pipe isn't turned off after pipe read
- */
-#define TRACE_DONTSTOP 1024
-
-
-/* MSB of tid field is used as trace-in-irq flag
- */
-#define TRACE_TID_IRQ (1<<31)
-#define TRACE_TID_TID(tid) ((tid) & ~(TRACE_TID_IRQ))
-
-/*!
- * @brief Device driver fills in this structure for each trace entry.
- * It will put this data first in the trace buffer.
- */
-typedef struct trace_entry_stamp {
- uint32_t tbh; /*!< timestamp upper part */
- uint32_t tbl; /*!< timestamp lower part */
- uint32_t tid; /*!< process/thread id */
-} trace_entry_stamp_t;
-
-
-/*
- * @brief Structure is used by adal app. layer to fill in trace info.
- */
-typedef struct trace_entry_head {
- uint16_t length; /*!< size of trace entry */
- uint16_t tag; /*!< type of entry: xTRACE xDUMP, (un)packed */
- uint32_t hash; /*!< a value for the (format) string */
- uint32_t line; /*!< source file line number of trace call */
- uint32_t args[0]; /*!< trace args or data of binary trace */
-} trace_entry_head_t;
-
-
-/*
- * @brief Structure is used to return current components tracing
- */
-typedef struct trace_buf_list {
- char name[TRACE_MAX_COMP_NAME_SIZE]; /*!< component name */
- size_t size; /*!< size of component trace buffer */
-} trace_buf_list_t;
-
-
-typedef uint64_t trace_desc_t; //Type definition for users trace descriptor data type
-typedef uint64_t tracDesc_t; //Type definition for older trace descriptor type
-typedef unsigned long trace_strings_t; /* type for trace strings */
-
-
-/*
- * @brief Will use this to hold hash value.
- *
- */
-enum trace_hash_val { trace_hash };
-
-/* struct for time */
-struct trace_tbtime {
- uint32_t high;
- uint32_t low;
-};
-
-
-/*----------------------------------------------------------------------------*/
-/* Constants */
-/*----------------------------------------------------------------------------*/
-/* only define if not defined by trace_dd.h (make different versions of
- * these files compatible). check only for one define instead of all */
-#ifndef TRACE_FIELDTRACE
-
-/* a component trace of type field (non-debug): x4654 = "FT" */
-#define TRACE_FIELDTRACE 0x4654
-/* a component trace of type debug: x4454 = "DT" */
-#define TRACE_DEBUGTRACE 0x4454
-/* a binary trace of type field (non-debug): x4644 = "FD" */
-#define TRACE_FIELDBIN 0x4644
-/* a binary trace of type debug: x4644 = "DD" */
-#define TRACE_DEBUGBIN 0x4444
-/* a string trace of type field (non-debug): x4653 = "FS" */
-#define TRACE_FIELDSTRING 0x4653
-/* a string trace of type debug: x4453 = "DS" */
-#define TRACE_DEBUGSTRING 0x4453
-
-#endif
-
-/*----------------------------------------------------------------------------*/
-/* Function Prototypes */
-/*----------------------------------------------------------------------------*/
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*!
- * @brief Initialize a trace buffer for a component.
- *
- * @param td Device driver will assign caller a trace descriptor.
- * @param comp Pointer to 16 character null terminated string.
- * @param size Requested buffer size.
- *
- * @return 0 for success, negative value for failure.
- * @retval #TRACE_INIT_BUFF_IOCTL_ERR device driver refused to create buffer
- * @retval #TRACE_INIT_BUFF_NAME_ERR buffer name was too long, a buffer with the
- name "BADN" was created instead
- * @retval #TRACE_INIT_FD_ERR cannot open trace device (module not loaded?), errno set
- */
-int32_t trace_adal_init_buffer(trace_desc_t *,const char *,const size_t);
-
-/*!
- * @brief Set trace debug level
- *
- * @param td Assigned trace descriptor.
- * @param level If 0 only field traces will be active. If > 0 debug traces
- * with level <= 'level' will be active.
- *
- * @return 0 for success, negative value for failure.
- * @retval #TRACE_SETDEBUG_IOCTL_ERR error from device driver, errno set
- * @retval #TRACE_SETDEBUG_INV_PARM_ERR second parm must be TRACE_DEBUG_ON or TRACE_DEBUG_OFF
- * @retval #TRACE_INIT_FD_ERR cannot open trace device (module not loaded?), errno set
- */
-int32_t trace_adal_setdebug(const trace_desc_t, const int32_t);
-
-/*!
- * @brief Write some data to trace buffer.
- *
- * @param td Assigned trace descriptor.
- * @param debug Is it a debug trace or field.
- * @param size Size of data.
- * @param data Data to write to buffer.
- * @param size2 Size of second data block.
- * @param data2 Second data block to write to buffer.
- *
- * @return 0 for success, negative value for failure.
- * @retval #TRACE_WRITE_IOCTL_ERR error from device driver, errno set
- * @retval #TRACE_INIT_FD_ERR cannot open trace device (module not loaded?), errno set
- */
-int32_t trace_adal_write2(const trace_desc_t, const int32_t,
- const size_t,const void *,const size_t,const void *);
-
-/*!
- * @brief Write trace data (can handle all data types)
- *
- * @return 0 for success, negative value for failure.
- * @retval #TRACE_WRITE_ALL_IOCTL_ERR error from device driver, errno set
- * @retval #TRACE_WRITE_NOT_INIT trying to trace without device driver
- * @retval #TRACE_THREAD_LOCK_FAIL error locking thread lock
- * @retval #TRACE_THREAD_UNLOCK_FAIL error unlocking thread lock
- * @retval #TRACE_INIT_FD_ERR cannot open trace device (module not loaded?), errno set
- * @retval #TRACE_WRITE_ALL_BAD_TD bad trace descriptor
- */
-int32_t trace_adal_write_all(const trace_desc_t i_td,const enum trace_hash_val i_hash,
- const char *i_fmt,
- const uint32_t i_line, const int32_t i_type,...)
- __attribute__ ((format (printf, 3, 6)));
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/include/tracinterface.H b/src/include/tracinterface.H
deleted file mode 100644
index a6d885314..000000000
--- a/src/include/tracinterface.H
+++ /dev/null
@@ -1,315 +0,0 @@
-/******************************************************************************
- * IBM Confidential
- *
- * Licensed Internal Code Source Materials
- *
- * IBM Flexible Support Processor Licensed Internal Code
- *
- * (c) Copyright IBM Corp. 2004, 2010
- *
- * The source code is for this program is not published or otherwise divested
- * of its trade secrets, irrespective of what has been deposited with the
- * U.S. Copyright Office.
- *****************************************************************************/
-
-#ifndef TRACINTERFACE_H
-#define TRACINTERFACE_H
-
-/*!@file tracinterface.H
- * @brief Contains macros for trace interface
- *
- * This header file provides a common interface for the Trace
- * mechanism. Trace is a way for developers to debug their code. They
- * can use the trace Macro's to write to standar out, to wraparound files and
- * to a wraparound buffer which will be stored in shared memory.
- *
- * There are two types of trace, debug and field, that you can use when tracing.
- * Debug traces will be compiled out of the code when the system is released to the field.
- * Field traces will be remain in the code permenantly.
- *
- * TRACxSYSn calls will always go to syslog
- *
- * There are three different environments trace will operate in.
- *
- * Unit Test / Simulation: All component traces (debug and field) are sent to standard out by default.
- * The developer has the option to do define an evironmental variable:
- * 'export FIPS_TRACE_PATH="<path>"' where path is the location to write the files (ex. "./").
- *
- * Lab: All component traces will, by default, follow the same implementation as the
- * Unit Test / Simulation env. However, drivers flashed onto the system (built by the
- * build team) will use the memory wrapping implementation. Code built in a local
- * sandbox will continue to use the file wrapping implementation. This will give
- * the developer the speed of the memory wrapping trace (for code they don't really
- * care about) and ease of debug with the file wrapping code (for their own code).
- *
- * Field: Only component traces of type field will be sent to the shared memory wraparound
- * buffer. Debug traces will be compiled out of the code.
- *
- * In Unit Test / Simulation, The file will have the name "trac" + 'component name'.
- * For example the error logger component would be <path>/tracERRL
-*/
-/* Change Log *****************************************************************/
-/* */
-/* ch# Feat/def# Userid Date Description */
-/* --- ---------- -------- -------- ----------------------------------------*/
-/* 00 N/A andrewg 08/27/01 Created */
-/* 01 N/A andrewg 10/03/01 Removed duplicate copyright and other housekeeping */
-/* 02 N/A andrewg 10/17/01 Added deallocateBuffer flag to TRAC_FREE_BUFFER */
-/* 03 N/A andrewg 10/19/01 Added 'using namespace std;', vector.h -> vector */
-/* included iostream.h, printf bug. */
-/* 04 354052 andrewg 11/09/01 Took out file writing portion, only go to printf */
-/* ag05 354388 andrewg 11/14/01 Changed binary macro name and added typedef */
-/* ag06 354696 andrewg 11/19/01 Removed ag05 change flags, causing errors */
-/* n/a 355095 andrewg 11/28/01 Put common.h include first */
-/* ag07 354971 andrewg 11/28/01 Added file wrapping code */
-/* ag08 359225 andrewg 02/11/01 Added memory wrapping code, removed USE_PRINTF defined flag */
-/* ag09 360869 andrewg 03/04/02 Added persistant writing macro */
-/* ag10 361649 andrewg 03/08/02 Added the constants */
-/* n/a 363697 andrewg 03/28/02 Modified to use new file object */
-/* n/a 376324 andrewg 07/24/02 Fixed bad define of TRACDCOMP9 */
-/* ag11 382759 andrewg 09/09/02 Support compile flag to remove debug trace */
-/* n/a 385314 andrewg 09/27/02 Remove use of STL */
-/* n/a 388981 andrewg 11/12/02 Add new static variable constructor */
-/* n/a HBIBASE iawilllia 10/05/10 Removed a lot of stuff for HBI trace base. */
-/* End Change Log *************************************************************/
-
-//--------------------------------------------------------------------//
-// Constants //
-//--------------------------------------------------------------------//
-#define ENTER_MRK ">>" // -- ag10
-#define EXIT_MRK "<<" // -- ag10
-#define ERR_MRK "E>" // -- ag10
-#define INFO_MRK "I>" // -- ag10
-#define ARG_MRK "A>" // -- ag10
-
-#ifndef NFP_CLIENT // dc99
-#include <stdint.h>
-#include <trace_adal.h>
-#else
-typedef int tracDesc_t;
-typedef int trace_desc_t;
-#endif
-
-#if( defined(NFP_LIBRARY) || defined(NFP_CLIENT) ) // dc99
-
-#define TRACSCOMP(des,printf_string,args...) do {} while(0)
-#define TRACDCOMP(des,printf_string,args...) do {} while(0)
-#define TRACDBIN(des,descString,address,length) do {} while(0)
-
-#define TRACFCOMP(des,printf_string,args...) \
- printf(printf_string "\n", ##args)
-#define TRACFBIN(des,descString,address,length) \
- printf("%s pointer:%p size:%d\n",descString,address,length)
-
-#define TRAC_INIT_BUFFER(des,comp_name, bufferSize) \
- *(des) = 1
-
-#define TRAC_INIT(des,comp_name, bufferSize)
-
-#define TRAC_FREE_BUFFER(des,deallocateBuff) do {} while(0)
-
-#else
-
-// check compatibility of header file/macros and preprocessor tracepp
-// if tracepp was used
-#define TRAC_MACROVER 1
-#ifdef TRAC_TRACEPP
-#if !defined(TRAC_PPVER)
-#warning fsptrace preprocessor version unknown, might be incompatible with header file
-#elif TRAC_PPVER < TRAC_MACROVER
-#error fsptrace header file version and preprocessor version dont fit
-#endif
-#endif
-
-//------------------------------------------------------------------------------
-// INCLUDES
-//------------------------------------------------------------------------------
-
-#include <trace_adal.h>
-
-/* for any trace_adal_write_all call we need the printf_string in addition to
- * the hash value. if tracepp is used it will add a (shortened) printf string,
- * otherwise the macros has to add it
- */
-
-#ifdef TRAC_TRACEPP
-#define __ALL_HASH(printf_string,num) trace_adal_hash(printf_string,num)
-#else
-#define __ALL_HASH(printf_string,num) trace_adal_hash(printf_string,num),printf_string
-#endif
-
-#ifdef TRAC_DEBUG_OUT /* compile out everyones debug traces */
-
-#define TRACDCOMP(des,printf_string,args...) do {} while(0)
-#define TRACDBIN(des,descString,address,length) do {} while(0)
-
-#else /* direct them to real function calls */
-
-/**
- @fn void TRACDCOMP0(des, printf_string)
- @brief Defines all Debug Component Traces
-
- The user can pass 0 to 9 parameters to the macro. In the field environment,
- these trace calls will be compiled out of the code. Use these for early bringup
- needs. These trace calls are written to a memory buffer.
- @note If you are passing parameters then make sure 'printf_string' has the
- @note necessary parameter formatting i.e. 'p1' = "hello" make sure
- @note 'printf_string' has "%s" somewhere in it to corretcly format p1.
- @return void The user will not be impacted by the failure of this function
- @param des This is assigned by TRAC_INIT_BUFFER
- @param printf_string string describing the trace entry and providing the formatting flags for any parameters passed.
- @param p1,p2... Optional parameters
-*/
-
-/* a macro w/o the param number suffix. number is calculated from printf string */
-#define TRACDCOMP(des,printf_string,args...) \
- trace_adal_write_all((des),__ALL_HASH(printf_string,-1),__LINE__,TRACE_DEBUG, ##args)
-
-/**
- @fn void TRACDBIN(des,descString,address,length)
- @brief Defines debug binary trace
-
- The binary trace should be used to write out a section of memory. The debug
- binary trace will be compiled out in the field environment so only use for early
- bringup debug. When this is being written to a file, it will be displayed in
- hexidecimal.
- @return void The user will not be impacted by the failure of this function
- @param des This is assigned by TRAC_INIT_BUFFER
- @param descString A string that will be put in front of the binary dump, developer assigns anything they want.
- @param address Address of beginning of data to dump.
- @param length lenght of the binary data.
-*/
-#define TRACDBIN(des,descString,address,len) \
- do{ trace_entry_head_t __e; \
- __e.tag = TRACE_DEBUGBIN; \
- __e.line = __LINE__; \
- __e.length = (len); \
- __e.hash = trace_adal_hash(descString, 0); \
- trace_adal_write2((des), TRACE_DEBUG, sizeof(trace_entry_head_t), &__e, \
- (uint32_t) (__e.length), (uint32_t *) (address)); \
- } while(0)
-
-#endif /* TRAC_DEBUG_OUT */
-
-/**
- @fn void TRACFCOMP0(des, printf_string)
- @brief Defines all Field Component Traces
-
- The user can pass 0 to 9 parameters to the macro. These trace calls will
- always be written to the trace memory buffer.
- @note If you are passing parameters then make sure 'printf_string' has the
- @note necessary parameter formatting
- @note i.e. 'p1' = "hello" make sure 'printf_string' has "%s" somewhere in
- @note it to corretcly format p1.
- @return void The user will not be impacted by the failure of this function
- @param des This is assigned by TRAC_INIT_BUFFER
- @param printf_string string describing the trace entry and providing the formatting flags for any parameters passed.
- @param p1,p2... Optional parameters
-*/
-
-/* a macro w/o the param number suffix. number is calculated from printf string */
-#define TRACFCOMP(des,printf_string,args...) \
- trace_adal_write_all((des),__ALL_HASH(printf_string,-1),__LINE__,TRACE_FIELD, ##args)
-
-/**
- @fn void TRACSCOMP0(des, printf_string)
- @brief Defines all Strace Component Traces
-
- The user can pass 0 to 9 parameters to the macro. These traces will be treated
- as debug traces but will never be compiled out of the code so that they can always be
- dynamically turned on/off.
-
- @note If you are passing parameters then make sure 'printf_string' has the
- @note necessary parameter formatting i.e. 'p1' = "hello" make sure
- @note 'printf_string' has '%s' somewhere in it to corretcly format p1.
- @return void The user will not be impacted by the failure of this function
- @param des This is assigned by TRAC_INIT_BUFFER
- @param printf_string string describing the trace entry and providing the formatting flags for any parameters passed.
- @param p1,p2... Optional parameters
-
- tracepp replaces trace_adal_hash() with hash value and reduced format string
-*/
-
-/* a macro w/o the param number suffix. number is calculated from printf string */
-#define TRACSCOMP(des,printf_string,args...) \
- trace_adal_write_all((des),__ALL_HASH(printf_string,-1),__LINE__,TRACE_DEBUG, ##args)
-
-/**
- @fn void TRACFBIN(des,descString,address,length)
- @brief Defines field binary trace
-
- The binary trace should be used to write out a section of memory. The field
- binary trace will always be logged so use for important information.
- When this is being written to a file, it will be displayed in hexidecimal.
- @return void The user will not be impacted by the failure of this function
- @param des This is assigned by TRAC_INIT_BUFFER
- @param descString A string that will be put in front of the binary dump, developer assigns anything they want.
- @param address Address of beginning of data to dump.
- @param length lenght of the binary data.
-*/
-#define TRACFBIN(des,descString,address,len) \
- do{ trace_entry_head_t __e; \
- __e.tag = TRACE_FIELDBIN; \
- __e.line = __LINE__; \
- __e.length = (len); \
- __e.hash = trace_adal_hash(descString, 0); \
- trace_adal_write2((des), TRACE_FIELD, sizeof(trace_entry_head_t), &__e, \
- (uint32_t) (__e.length), (uint32_t *) (address)); \
- } while(0)
-
-
-/**
- @fn void TRAC_INIT_BUFFER(des,comp_name, bufferSize)
- @brief Initializes trace buffer for component
-
- This function must be called before any other trace calls. It
- initializes a file for the calling component and returns a trace
- descriptor which is used by the trace calls to find the correct file to write to.
- @return void The user will not be impacted by the failure of this function. If des is a positive value, success.
- @param des This is assigned by this function.
- @param comp_name This is the four character name of the component requesting the trace buffer.
- @param bufferSize Requested length of the buffer, if 0 is entered the user will get default buffer size.
-*/
-#define TRAC_INIT_BUFFER(des,comp_name, bufferSize) \
- trace_adal_init_buffer((des), (comp_name), (bufferSize))
-
-
-class TracInit
-{
- public:
-
- /*------------------------------------------------------------------------*/
- /* Constructor */
- /*------------------------------------------------------------------------*/
-
- TracInit(tracDesc_t *o_td, const char *i_comp,const size_t i_size)
- {
- // printf("TracInit constructor called for %s, size %u\n",i_comp,i_size);
- TRAC_INIT_BUFFER(o_td,i_comp,i_size);
- }
-
- ~TracInit()
- {
- // printf("in the TracInit destructor\n");
- }
-
-};
-
-/*******************************************************************************
- TRAC_INIT: Class for creating trace descriptor object.
-
- About the macros.
- TRAC_INIT -- Called by users, adds __LINE__ for uniqueness.
- TRAC_INIT_LINE -- Translates __LINE__ into the line number. Using
- macro expansion in this statement would result in
- tracInit static g_trac_"__LINE__"
- TRAC_INIT_UNIQ -- With line number translated, use the '##' operator to
- append number in variable name.
-*******************************************************************************/
-
-#define TRAC_INIT_UNIQ(des, name, sz, ln) TracInit static g_trac_##ln(des, name, sz)
-#define TRAC_INIT_LINE(des, name, sz, ln) TRAC_INIT_UNIQ(des, name, sz, ln)
-#define TRAC_INIT(des, name, sz) TRAC_INIT_LINE(des, name, sz, __LINE__)
-
-#endif //! -- NFP Library
-#endif //! -- !defined TRACINTERFACE_H
diff --git a/src/include/usr/trace/interface.H b/src/include/usr/trace/interface.H
new file mode 100644
index 000000000..6d62efca0
--- /dev/null
+++ b/src/include/usr/trace/interface.H
@@ -0,0 +1,350 @@
+/******************************************************************************
+ * IBM Confidential
+ *
+ * Licensed Internal Code Source Materials
+ *
+ * IBM Flexible Support Processor Licensed Internal Code
+ *
+ * (c) Copyright IBM Corp. 2004, 2010
+ *
+ * The source code is for this program is not published or otherwise divested
+ * of its trade secrets, irrespective of what has been deposited with the
+ * U.S. Copyright Office.
+ *****************************************************************************/
+
+#ifndef __TRACE_INTERFACE_H
+#define __TRACE_INTERFACE_H
+
+/*!@file interface.H
+ * @brief Contains macros for trace interface
+ *
+ * Note that this file was for the most parted ported in from the fsp-trace
+ * implementation.
+ *
+ * This header file provides a common interface for the Trace
+ * mechanism.
+ *
+ * There are two types of trace, debug and field, that you can use when tracing.
+ * Debug traces are not enabled by default, they must be enabled by the user.
+ * Field traces will always be enabled.
+*/
+
+/******************************************************************************/
+// Includes
+/******************************************************************************/
+#include <stdint.h>
+
+/******************************************************************************/
+// Globals/Constants
+/******************************************************************************/
+#define ENTER_MRK ">>"
+#define EXIT_MRK "<<"
+#define ERR_MRK "E>"
+#define INFO_MRK "I>"
+#define ARG_MRK "A>"
+
+#define TRAC_COMP_SIZE 16 // Max component name size
+#define TRAC_MAX_ARGS 9 // Max number of arguments in trace
+
+
+#define TRACE_DEBUG 1 //Indicates trace is debug
+#define TRACE_FIELD 0 //Indicates trace is field
+
+// check compatibility of header file/macros and preprocessor tracepp
+// if tracepp was used
+#define TRAC_MACROVER 1
+#ifdef TRAC_TRACEPP
+#if !defined(TRAC_PPVER)
+#warning fsptrace preprocessor version unknown, might be incompatible with header file
+#elif TRAC_PPVER < TRAC_MACROVER
+#error fsptrace header file version and preprocessor version dont fit
+#endif
+#endif
+
+
+/* for any trace_adal_write_all call we need the printf_string in addition to
+ * the hash value. if tracepp is used it will add a (shortened) printf string,
+ * otherwise the macros has to add it
+ */
+#ifdef TRAC_TRACEPP
+#define __ALL_HASH(printf_string,num) trace_adal_hash(printf_string,num)
+#else
+#define __ALL_HASH(printf_string,num) trace_adal_hash(printf_string,num),printf_string
+#endif
+
+/******************************************************************************/
+// Macros
+/******************************************************************************/
+
+#ifdef TRAC_DEBUG_OUT /* compile out everyones debug traces */
+
+#define TRACDCOMP(des,printf_string,args...) do {} while(0)
+#define TRACDBIN(des,descString,address,length) do {} while(0)
+
+#else /* direct them to real function calls */
+
+/**
+ * @fn void TRACDCOMP0(des, printf_string)
+ * @brief Defines all Debug Component Traces
+ *
+ * The user can pass 0 to 9 parameters to the macro. In the field environment,
+ * these trace calls will be compiled out of the code. Use these for early bringup
+ * needs. These trace calls are written to a memory buffer.
+ *
+ * @param des This is assigned by TRAC_INIT_BUFFER
+ * @param printf_string String describing the trace entry and providing the
+ * formatting flags for any parameters passed.
+ * @param p1,p2... Optional parameters
+ *
+ * @return void
+*/
+
+/* a macro w/o the param number suffix. number is calculated from printf string */
+#define TRACDCOMP(des,printf_string,args...) \
+ TRACE::trace_adal_write_all((des),__ALL_HASH(printf_string,-1),__LINE__,TRACE_DEBUG, ##args)
+
+/**
+ * @fn void TRACDBIN(des,descString,address,length)
+ * @brief Defines debug binary trace
+ *
+ * The binary trace should be used to write out a section of memory.
+ *
+ * @param des This is assigned by TRAC_INIT_BUFFER
+ * @param descString A string that will be put in front of the binary dump,
+ * developer assigns anything they want.
+ * @param address Address of beginning of data to dump.
+ * @param length length of the binary data.
+ *
+ * @return void
+
+*/
+#define TRACDBIN(des,printf_string,address,len) \
+ TRACE::trace_adal_write_bin(des,__ALL_HASH(printf_string,0), \
+ __LINE__, \
+ address, \
+ len, \
+ TRACE_DEBUG)
+#endif /* TRAC_DEBUG_OUT */
+
+/**
+ * @fn void TRACFCOMP0(des, printf_string)
+ * @brief Defines all Field Component Traces
+ *
+ * The user can pass 0 to 9 parameters to the macro. These trace calls will
+ * always be written to the trace memory buffer.
+ *
+ * @param des This is assigned by TRAC_INIT_BUFFER
+ * @param printf_string String describing the trace entry and providing the
+ * formatting flags for any parameters passed.
+ * @param p1,p2... Optional parameters
+ *
+ * @return void
+*/
+
+/* a macro w/o the param number suffix. number is calculated from printf string */
+#define TRACFCOMP(des,printf_string,args...) \
+ TRACE::trace_adal_write_all((des),__ALL_HASH(printf_string,-1),__LINE__,TRACE_FIELD, ##args)
+
+
+/**
+ * @fn void TRACFBIN(des,descString,address,len)
+ * @brief Defines field binary trace
+ *
+ * The binary trace should be used to write out a section of memory.
+ *
+ * @param des This is assigned by TRAC_INIT_BUFFER
+ * @param descString A string that will be put in front of the binary dump,
+ * developer assigns anything they want.
+ * @param address Address of beginning of data to dump.
+ * @param length lenght of the binary data.
+ *
+ * @return void
+*/
+#define TRACFBIN(des,printf_string,address,len) \
+ TRACE::trace_adal_write_bin(des,__ALL_HASH(printf_string,0), \
+ __LINE__, \
+ address, \
+ len, \
+ TRACE_FIELD)
+
+/**
+ * @fn void TRAC_INIT_BUFFER(des,comp_name, bufferSize)
+ * @brief Initializes trace buffer for component
+ *
+ * This function must be called before any other trace calls. It
+ * initializes a buffer for the calling component and returns a trace
+ * descriptor which is used by the trace calls to find the correct
+ * buffer to write to.
+ *
+ * @param des This is assigned by this function.
+ * @param comp_name This is the four character name of the component requesting
+ * the trace buffer.
+ * @param bufferSize Requested length of the buffer, if 0 is entered the user will
+ * get default buffer size.
+ * @return void
+*/
+#define TRAC_INIT_BUFFER(des,comp_name, bufferSize) \
+ TRACE::trace_adal_init_buffer((des), (comp_name), (bufferSize))
+
+/*******************************************************************************
+ TRAC_INIT: Class for creating trace descriptor object.
+
+ About the macros.
+ TRAC_INIT -- Called by users, adds __LINE__ for uniqueness.
+ TRAC_INIT_LINE -- Translates __LINE__ into the line number. Using
+ macro expansion in this statement would result in
+ tracInit static g_trac_"__LINE__"
+ TRAC_INIT_UNIQ -- With line number translated, use the '##' operator to
+ append number in variable name.
+*******************************************************************************/
+
+#define TRAC_INIT_UNIQ(des, name, sz, ln) TRACE::TracInit static g_trac_##ln(des, name, sz)
+#define TRAC_INIT_LINE(des, name, sz, ln) TRAC_INIT_UNIQ(des, name, sz, ln)
+#define TRAC_INIT(des, name, sz) TRAC_INIT_LINE(des, name, sz, __LINE__)
+
+
+/******************************************************************************/
+// Internals - Not to be called or used directly by host boot code
+/******************************************************************************/
+
+
+typedef uint32_t trace_hash_val; // Hash values are 32 bytes
+
+/*
+ * @brief Structure is put at beginning of all trace buffers
+ */
+typedef struct trace_buf_head {
+ unsigned char ver; /*!< version of this struct (1) */
+ unsigned char hdr_len; /*!< size of this struct in bytes */
+ unsigned char time_flg; /*!< meaning of timestamp entry field */
+ unsigned char endian_flg; /*!< flag for big ('B') or little ('L') endian*/
+ char comp[TRAC_COMP_SIZE]; /*!< the buffer name as specified in init call*/
+ uint32_t size; /*!< size of buffer, including this struct */
+ uint32_t times_wrap; /*!< how often the buffer wrapped */
+ uint32_t next_free; /*!< offset of the byte behind the latest entry*/
+ uint32_t te_count; /*!< Updated each time a trace is done */
+ uint32_t extracted; /*!< Not currently used */
+}trace_buf_head_t;
+
+/*!
+ * @brief Timestamp and thread id for each trace entry.
+ */
+typedef struct trace_entry_stamp {
+ //uint32_t tbh; /*!< timestamp upper part */
+ //uint32_t tbl; /*!< timestamp lower part */
+ uint32_t tb[2];
+ //uint64_t tb;
+ uint32_t tid; /*!< process/thread id */
+}trace_entry_stamp_t;
+
+/*
+ * @brief Structure is used by adal app. layer to fill in trace info.
+ */
+typedef struct trace_entry_head {
+ uint16_t length; /*!< size of trace entry */
+ uint16_t tag; /*!< type of entry: xTRACE xDUMP, (un)packed */
+ uint32_t hash; /*!< a value for the (format) string */
+ uint32_t line; /*!< source file line number of trace call */
+}trace_entry_head_t;
+
+/*
+ * @brief Parameter traces can be all contained in one write.
+ */
+typedef struct trace_entire_entry {
+ trace_entry_stamp_t stamp;
+ trace_entry_head_t head;
+ uint64_t args[TRAC_MAX_ARGS + 1];
+} trace_entire_entry_t;
+
+
+/*
+ * @brief Binary first writes header and time stamp.
+ */
+typedef struct trace_bin_entry {
+ trace_entry_stamp_t stamp;
+ trace_entry_head_t head;
+} trace_bin_entry_t;
+
+/**
+ * @brief New version name of this typedef
+ */
+typedef trace_buf_head_t trace_desc_t;
+
+namespace TRACE
+{
+
+/**
+ * @brief Initialize a trace buffer
+ *
+ * @param o_td[out] Trace descriptor to initialize
+ * @param i_comp[in] Component name for trace buffer
+ * @param i_size[in] Size to allocate for trace buffer
+ *
+ * @return void
+ */
+void trace_adal_init_buffer(trace_desc_t **o_td,
+ const char* i_comp,
+ const size_t i_size );
+
+/**
+ * @brief Write component trace out to input buffer
+ *
+ * @param io_td[inout] Trace descriptor of buffer to write to.
+ * @param i_hash[in] Descriptive string hash value
+ * @param i_fmt [in] Formatting string
+ * @param i_line[in] Line number trace was done at
+ * @param i_type[in] Type of trace (TRACE_DEBUG, TRACE_FIELD)
+ *
+ * @return void
+ */
+void trace_adal_write_all(trace_desc_t *io_td,
+ const trace_hash_val i_hash,
+ const char * i_fmt,
+ const uint32_t i_line,
+ const int32_t i_type, ...);
+
+/**
+ * @brief Write binary data out to trace buffer
+ *
+ * @param io_td[inout] Trace descriptor of buffer to write to.
+ * @param i_hash[in] Descriptive string hash value
+ * @param i_line[in] Line number trace was done at
+ * @param i_ptr[in] Pointer to binary data
+ * @param i_size[in] Size of binary data
+ * @param i_type[in] Type of trace (TRACE_DEBUG, TRACE_FIELD)
+ *
+ * @return void
+ */
+void trace_adal_write_bin(trace_desc_t * io_td,
+ const trace_hash_val i_hash,
+ const uint32_t i_line,
+ const void *i_ptr,
+ const uint32_t i_size,
+ const int32_t type);
+
+
+/******************************************************************************/
+// Allow users to init trace buffer outside of a function
+/******************************************************************************/
+class TracInit
+{
+ public:
+
+ /*------------------------------------------------------------------------*/
+ /* Constructor */
+ /*------------------------------------------------------------------------*/
+
+ TracInit(trace_desc_t **o_td, const char *i_comp,const size_t i_size)
+ {
+ TRAC_INIT_BUFFER(o_td,i_comp,i_size);
+ }
+
+ ~TracInit()
+ {
+ }
+
+};
+
+}; // Namespace
+
+#endif //! -- !defined __TRACE_INTERFACE_H
OpenPOWER on IntegriCloud