13d8536b4Sopenharmony_ci/* 23d8536b4Sopenharmony_ci * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. 33d8536b4Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. 43d8536b4Sopenharmony_ci * 53d8536b4Sopenharmony_ci * Redistribution and use in source and binary forms, with or without modification, 63d8536b4Sopenharmony_ci * are permitted provided that the following conditions are met: 73d8536b4Sopenharmony_ci * 83d8536b4Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright notice, this list of 93d8536b4Sopenharmony_ci * conditions and the following disclaimer. 103d8536b4Sopenharmony_ci * 113d8536b4Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright notice, this list 123d8536b4Sopenharmony_ci * of conditions and the following disclaimer in the documentation and/or other materials 133d8536b4Sopenharmony_ci * provided with the distribution. 143d8536b4Sopenharmony_ci * 153d8536b4Sopenharmony_ci * 3. Neither the name of the copyright holder nor the names of its contributors may be used 163d8536b4Sopenharmony_ci * to endorse or promote products derived from this software without specific prior written 173d8536b4Sopenharmony_ci * permission. 183d8536b4Sopenharmony_ci * 193d8536b4Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 203d8536b4Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 213d8536b4Sopenharmony_ci * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 223d8536b4Sopenharmony_ci * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 233d8536b4Sopenharmony_ci * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 243d8536b4Sopenharmony_ci * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 253d8536b4Sopenharmony_ci * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 263d8536b4Sopenharmony_ci * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 273d8536b4Sopenharmony_ci * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 283d8536b4Sopenharmony_ci * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 293d8536b4Sopenharmony_ci * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 303d8536b4Sopenharmony_ci */ 313d8536b4Sopenharmony_ci 323d8536b4Sopenharmony_ci#include "trace_pipeline.h" 333d8536b4Sopenharmony_ci#include "trace_tlv.h" 343d8536b4Sopenharmony_ci#include "los_trace_pri.h" 353d8536b4Sopenharmony_ci 363d8536b4Sopenharmony_ci#if (LOSCFG_KERNEL_SMP == 1) 373d8536b4Sopenharmony_ciLITE_OS_SEC_BSS SPIN_LOCK_INIT(g_pipeSpin); 383d8536b4Sopenharmony_ci#define PIPE_LOCK(state) LOS_SpinLockSave(&g_pipeSpin, &(state)) 393d8536b4Sopenharmony_ci#define PIPE_UNLOCK(state) LOS_SpinUnlockRestore(&g_pipeSpin, (state)) 403d8536b4Sopenharmony_ci#else 413d8536b4Sopenharmony_ci#define PIPE_LOCK(state) (state) = LOS_IntLock() 423d8536b4Sopenharmony_ci#define PIPE_UNLOCK(state) LOS_IntRestore(state) 433d8536b4Sopenharmony_ci#endif 443d8536b4Sopenharmony_ci 453d8536b4Sopenharmony_ciSTATIC TlvTable g_traceTlvTblNotify[] = { 463d8536b4Sopenharmony_ci { CMD, LOS_OFF_SET_OF(TraceNotifyFrame, cmd), sizeof(UINT32) }, 473d8536b4Sopenharmony_ci { PARAMS, LOS_OFF_SET_OF(TraceNotifyFrame, param), sizeof(UINT32) }, 483d8536b4Sopenharmony_ci { TRACE_TLV_TYPE_NULL, 0, 0 }, 493d8536b4Sopenharmony_ci}; 503d8536b4Sopenharmony_ci 513d8536b4Sopenharmony_ciSTATIC TlvTable g_traceTlvTblHead[] = { 523d8536b4Sopenharmony_ci { ENDIAN, LOS_OFF_SET_OF(TraceBaseHeaderInfo, bigLittleEndian), sizeof(UINT32) }, 533d8536b4Sopenharmony_ci { VERSION, LOS_OFF_SET_OF(TraceBaseHeaderInfo, version), sizeof(UINT32) }, 543d8536b4Sopenharmony_ci { CLOCK_FREQ, LOS_OFF_SET_OF(TraceBaseHeaderInfo, clockFreq), sizeof(UINT32) }, 553d8536b4Sopenharmony_ci { TRACE_TLV_TYPE_NULL, 0, 0 }, 563d8536b4Sopenharmony_ci}; 573d8536b4Sopenharmony_ci 583d8536b4Sopenharmony_ciSTATIC TlvTable g_traceTlvTblObj[] = { 593d8536b4Sopenharmony_ci { ADDR, LOS_OFF_SET_OF(ObjData, id), sizeof(UINT32) }, 603d8536b4Sopenharmony_ci { PRIO, LOS_OFF_SET_OF(ObjData, prio), sizeof(UINT32) }, 613d8536b4Sopenharmony_ci { NAME, LOS_OFF_SET_OF(ObjData, name), sizeof(CHAR) * LOSCFG_TRACE_OBJ_MAX_NAME_SIZE }, 623d8536b4Sopenharmony_ci { TRACE_TLV_TYPE_NULL, 0, 0 }, 633d8536b4Sopenharmony_ci}; 643d8536b4Sopenharmony_ci 653d8536b4Sopenharmony_ciSTATIC TlvTable g_traceTlvTblEvent[] = { 663d8536b4Sopenharmony_ci#if (LOSCFG_TRACE_FRAME_CORE_MSG == 1) 673d8536b4Sopenharmony_ci { CORE, LOS_OFF_SET_OF(TraceEventFrame, core), sizeof(UINT32) }, 683d8536b4Sopenharmony_ci#endif 693d8536b4Sopenharmony_ci { EVENT_CODE, LOS_OFF_SET_OF(TraceEventFrame, eventType), sizeof(UINT32) }, 703d8536b4Sopenharmony_ci { CUR_TIME, LOS_OFF_SET_OF(TraceEventFrame, curTime), sizeof(UINT64) }, 713d8536b4Sopenharmony_ci 723d8536b4Sopenharmony_ci#if (LOSCFG_TRACE_FRAME_EVENT_COUNT == 1) 733d8536b4Sopenharmony_ci { EVENT_COUNT, LOS_OFF_SET_OF(TraceEventFrame, eventCount), sizeof(UINT32) }, 743d8536b4Sopenharmony_ci#endif 753d8536b4Sopenharmony_ci { CUR_TASK, LOS_OFF_SET_OF(TraceEventFrame, curTask), sizeof(UINT32) }, 763d8536b4Sopenharmony_ci { IDENTITY, LOS_OFF_SET_OF(TraceEventFrame, identity), sizeof(UINTPTR) }, 773d8536b4Sopenharmony_ci { EVENT_PARAMS, LOS_OFF_SET_OF(TraceEventFrame, params), sizeof(UINTPTR) * LOSCFG_TRACE_FRAME_MAX_PARAMS }, 783d8536b4Sopenharmony_ci { TRACE_TLV_TYPE_NULL, 0, 0 }, 793d8536b4Sopenharmony_ci}; 803d8536b4Sopenharmony_ci 813d8536b4Sopenharmony_ciSTATIC TlvTable *g_traceTlvTbl[] = { 823d8536b4Sopenharmony_ci g_traceTlvTblNotify, 833d8536b4Sopenharmony_ci g_traceTlvTblHead, 843d8536b4Sopenharmony_ci g_traceTlvTblObj, 853d8536b4Sopenharmony_ci g_traceTlvTblEvent 863d8536b4Sopenharmony_ci}; 873d8536b4Sopenharmony_ci 883d8536b4Sopenharmony_ciSTATIC UINT32 DefaultPipelineInit(VOID) 893d8536b4Sopenharmony_ci{ 903d8536b4Sopenharmony_ci return LOS_OK; 913d8536b4Sopenharmony_ci} 923d8536b4Sopenharmony_ci 933d8536b4Sopenharmony_ciSTATIC VOID DefaultDataSend(UINT16 len, UINT8 *data) 943d8536b4Sopenharmony_ci{ 953d8536b4Sopenharmony_ci (VOID)len; 963d8536b4Sopenharmony_ci (VOID)data; 973d8536b4Sopenharmony_ci} 983d8536b4Sopenharmony_ci 993d8536b4Sopenharmony_ciSTATIC UINT32 DefaultDataReceive(UINT8 *data, UINT32 size, UINT32 timeout) 1003d8536b4Sopenharmony_ci{ 1013d8536b4Sopenharmony_ci (VOID)data; 1023d8536b4Sopenharmony_ci (VOID)size; 1033d8536b4Sopenharmony_ci (VOID)timeout; 1043d8536b4Sopenharmony_ci return LOS_OK; 1053d8536b4Sopenharmony_ci} 1063d8536b4Sopenharmony_ci 1073d8536b4Sopenharmony_ciSTATIC UINT32 DefaultWait(VOID) 1083d8536b4Sopenharmony_ci{ 1093d8536b4Sopenharmony_ci return LOS_OK; 1103d8536b4Sopenharmony_ci} 1113d8536b4Sopenharmony_ci 1123d8536b4Sopenharmony_ciSTATIC TracePipelineOps g_defaultOps = { 1133d8536b4Sopenharmony_ci .init = DefaultPipelineInit, 1143d8536b4Sopenharmony_ci .dataSend = DefaultDataSend, 1153d8536b4Sopenharmony_ci .dataRecv = DefaultDataReceive, 1163d8536b4Sopenharmony_ci .wait = DefaultWait, 1173d8536b4Sopenharmony_ci}; 1183d8536b4Sopenharmony_ci 1193d8536b4Sopenharmony_ciSTATIC const TracePipelineOps *g_tracePipelineOps = &g_defaultOps; 1203d8536b4Sopenharmony_ci 1213d8536b4Sopenharmony_ciVOID OsTracePipelineReg(const TracePipelineOps *ops) 1223d8536b4Sopenharmony_ci{ 1233d8536b4Sopenharmony_ci g_tracePipelineOps = ops; 1243d8536b4Sopenharmony_ci} 1253d8536b4Sopenharmony_ci 1263d8536b4Sopenharmony_ciVOID OsTraceDataSend(UINT8 type, UINT16 len, UINT8 *data) 1273d8536b4Sopenharmony_ci{ 1283d8536b4Sopenharmony_ci UINT32 intSave; 1293d8536b4Sopenharmony_ci UINT8 outBuf[LOSCFG_TRACE_TLV_BUF_SIZE] = {0}; 1303d8536b4Sopenharmony_ci 1313d8536b4Sopenharmony_ci if ((type >= TRACE_MSG_MAX) || (len > LOSCFG_TRACE_TLV_BUF_SIZE)) { 1323d8536b4Sopenharmony_ci return; 1333d8536b4Sopenharmony_ci } 1343d8536b4Sopenharmony_ci 1353d8536b4Sopenharmony_ci len = OsTraceDataEncode(type, g_traceTlvTbl[type], data, &outBuf[0], sizeof(outBuf)); 1363d8536b4Sopenharmony_ci 1373d8536b4Sopenharmony_ci PIPE_LOCK(intSave); 1383d8536b4Sopenharmony_ci g_tracePipelineOps->dataSend(len, &outBuf[0]); 1393d8536b4Sopenharmony_ci PIPE_UNLOCK(intSave); 1403d8536b4Sopenharmony_ci} 1413d8536b4Sopenharmony_ci 1423d8536b4Sopenharmony_ciUINT32 OsTraceDataRecv(UINT8 *data, UINT32 size, UINT32 timeout) 1433d8536b4Sopenharmony_ci{ 1443d8536b4Sopenharmony_ci return g_tracePipelineOps->dataRecv(data, size, timeout); 1453d8536b4Sopenharmony_ci} 1463d8536b4Sopenharmony_ci 1473d8536b4Sopenharmony_ciUINT32 OsTraceDataWait(VOID) 1483d8536b4Sopenharmony_ci{ 1493d8536b4Sopenharmony_ci return g_tracePipelineOps->wait(); 1503d8536b4Sopenharmony_ci} 151