Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016, Intel Corporation |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * * Neither the name of the Intel Corporation nor the |
| 13 | * names of its contributors may be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 26 | * POSSIBILITY OF SUCH DAMAGE. |
| 27 | * |
| 28 | * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com> |
| 29 | * Keyon Jie <yang.jie@linux.intel.com> |
| 30 | */ |
| 31 | |
| 32 | #ifndef __INCLUDE_TRACE__ |
| 33 | #define __INCLUDE_TRACE__ |
| 34 | |
| 35 | #include <stdint.h> |
| 36 | #include <stdlib.h> |
Pierre-Louis Bossart | 81708a5 | 2018-04-04 18:46:50 -0500 | [diff] [blame] | 37 | #include <sof/sof.h> |
| 38 | #include <sof/mailbox.h> |
| 39 | #include <sof/debug.h> |
| 40 | #include <sof/timer.h> |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 41 | #include <platform/platform.h> |
| 42 | #include <platform/timer.h> |
| 43 | |
Rander Wang | 9b34b4d | 2018-01-23 14:15:52 +0000 | [diff] [blame] | 44 | /* bootloader trace values */ |
| 45 | #define TRACE_BOOT_LDR_ENTRY 0x100 |
| 46 | #define TRACE_BOOT_LDR_HPSRAM 0x110 |
| 47 | #define TRACE_BOOT_LDR_MANIFEST 0x120 |
| 48 | #define TRACE_BOOT_LDR_JUMP 0x150 |
Liam Girdwood | 2104ff8 | 2018-01-23 14:00:26 +0000 | [diff] [blame] | 49 | |
Tomasz Lauda | 80f3d47 | 2018-06-05 18:25:37 +0200 | [diff] [blame] | 50 | #define TRACE_BOOT_LDR_PARSE_MODULE 0x210 |
| 51 | #define TRACE_BOOT_LDR_PARSE_SEGMENT 0x220 |
| 52 | |
Pierre-Louis Bossart | f945809 | 2017-11-09 15:24:07 -0600 | [diff] [blame] | 53 | /* general trace init codes - only used at boot when main trace is not available */ |
Liam Girdwood | 2104ff8 | 2018-01-23 14:00:26 +0000 | [diff] [blame] | 54 | #define TRACE_BOOT_START 0x1000 |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 55 | #define TRACE_BOOT_ARCH 0x2000 |
Liam Girdwood | 2104ff8 | 2018-01-23 14:00:26 +0000 | [diff] [blame] | 56 | #define TRACE_BOOT_SYS 0x3000 |
| 57 | #define TRACE_BOOT_PLATFORM 0x4000 |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 58 | |
| 59 | /* system specific codes */ |
| 60 | #define TRACE_BOOT_SYS_WORK (TRACE_BOOT_SYS + 0x100) |
Liam Girdwood | d65a18a | 2017-06-06 16:37:05 +0100 | [diff] [blame] | 61 | #define TRACE_BOOT_SYS_CPU_FREQ (TRACE_BOOT_SYS + 0x200) |
| 62 | #define TRACE_BOOT_SYS_HEAP (TRACE_BOOT_SYS + 0x300) |
| 63 | #define TRACE_BOOT_SYS_NOTE (TRACE_BOOT_SYS + 0x400) |
| 64 | #define TRACE_BOOT_SYS_SCHED (TRACE_BOOT_SYS + 0x500) |
Tomasz Lauda | 14ca1fa | 2018-06-19 16:55:34 +0200 | [diff] [blame] | 65 | #define TRACE_BOOT_SYS_POWER (TRACE_BOOT_SYS + 0x600) |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 66 | |
| 67 | /* platform/device specific codes */ |
Liam Girdwood | 2104ff8 | 2018-01-23 14:00:26 +0000 | [diff] [blame] | 68 | #define TRACE_BOOT_PLATFORM_ENTRY (TRACE_BOOT_PLATFORM + 0x100) |
| 69 | #define TRACE_BOOT_PLATFORM_MBOX (TRACE_BOOT_PLATFORM + 0x110) |
| 70 | #define TRACE_BOOT_PLATFORM_SHIM (TRACE_BOOT_PLATFORM + 0x120) |
| 71 | #define TRACE_BOOT_PLATFORM_PMC (TRACE_BOOT_PLATFORM + 0x130) |
| 72 | #define TRACE_BOOT_PLATFORM_TIMER (TRACE_BOOT_PLATFORM + 0x140) |
| 73 | #define TRACE_BOOT_PLATFORM_CLOCK (TRACE_BOOT_PLATFORM + 0x150) |
| 74 | #define TRACE_BOOT_PLATFORM_SSP_FREQ (TRACE_BOOT_PLATFORM + 0x160) |
| 75 | #define TRACE_BOOT_PLATFORM_IPC (TRACE_BOOT_PLATFORM + 0x170) |
| 76 | #define TRACE_BOOT_PLATFORM_DMA (TRACE_BOOT_PLATFORM + 0x180) |
| 77 | #define TRACE_BOOT_PLATFORM_SSP (TRACE_BOOT_PLATFORM + 0x190) |
Seppo Ingalsuo | 6be7b1d | 2018-05-04 18:01:08 +0300 | [diff] [blame] | 78 | #define TRACE_BOOT_PLATFORM_DMIC (TRACE_BOOT_PLATFORM + 0x1a0) |
Tomasz Lauda | b31c743 | 2018-07-03 11:52:29 +0200 | [diff] [blame] | 79 | #define TRACE_BOOT_PLATFORM_IDC (TRACE_BOOT_PLATFORM + 0x1b0) |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 80 | |
| 81 | /* trace event classes - high 8 bits*/ |
| 82 | #define TRACE_CLASS_IRQ (1 << 24) |
| 83 | #define TRACE_CLASS_IPC (2 << 24) |
| 84 | #define TRACE_CLASS_PIPE (3 << 24) |
| 85 | #define TRACE_CLASS_HOST (4 << 24) |
| 86 | #define TRACE_CLASS_DAI (5 << 24) |
| 87 | #define TRACE_CLASS_DMA (6 << 24) |
| 88 | #define TRACE_CLASS_SSP (7 << 24) |
| 89 | #define TRACE_CLASS_COMP (8 << 24) |
| 90 | #define TRACE_CLASS_WAIT (9 << 24) |
| 91 | #define TRACE_CLASS_LOCK (10 << 24) |
| 92 | #define TRACE_CLASS_MEM (11 << 24) |
| 93 | #define TRACE_CLASS_MIXER (12 << 24) |
Liam Girdwood | d65a18a | 2017-06-06 16:37:05 +0100 | [diff] [blame] | 94 | #define TRACE_CLASS_BUFFER (13 << 24) |
| 95 | #define TRACE_CLASS_VOLUME (14 << 24) |
| 96 | #define TRACE_CLASS_SWITCH (15 << 24) |
| 97 | #define TRACE_CLASS_MUX (16 << 24) |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 98 | #define TRACE_CLASS_SRC (17 << 24) |
Seppo Ingalsuo | 29566ee | 2017-06-07 14:17:56 +0300 | [diff] [blame] | 99 | #define TRACE_CLASS_TONE (18 << 24) |
Seppo Ingalsuo | 6f03aa5 | 2017-06-07 14:17:57 +0300 | [diff] [blame] | 100 | #define TRACE_CLASS_EQ_FIR (19 << 24) |
Seppo Ingalsuo | 6a24a29 | 2017-06-07 14:17:58 +0300 | [diff] [blame] | 101 | #define TRACE_CLASS_EQ_IIR (20 << 24) |
Liam Girdwood | d163f6d | 2017-12-21 17:12:50 +0000 | [diff] [blame] | 102 | #define TRACE_CLASS_SA (21 << 24) |
Seppo Ingalsuo | 6be7b1d | 2018-05-04 18:01:08 +0300 | [diff] [blame] | 103 | #define TRACE_CLASS_DMIC (22 << 24) |
Tomasz Lauda | 14ca1fa | 2018-06-19 16:55:34 +0200 | [diff] [blame] | 104 | #define TRACE_CLASS_POWER (23 << 24) |
Tomasz Lauda | b31c743 | 2018-07-03 11:52:29 +0200 | [diff] [blame] | 105 | #define TRACE_CLASS_IDC (24 << 24) |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 106 | |
| 107 | /* move to config.h */ |
| 108 | #define TRACE 1 |
| 109 | #define TRACEV 0 |
| 110 | #define TRACEE 1 |
Ranjani Sridharan | 1c417f9 | 2018-03-27 22:07:19 -0700 | [diff] [blame] | 111 | #define TRACEM 0 /* send all trace messages to mbox and local trace buffer */ |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 112 | |
| 113 | void _trace_event(uint32_t event); |
Ranjani Sridharan | 7616ca4 | 2018-03-27 22:07:18 -0700 | [diff] [blame] | 114 | void _trace_event_mbox(uint32_t event); |
Liam Girdwood | 3dca7b7 | 2017-10-19 17:18:34 +0100 | [diff] [blame] | 115 | void _trace_event_atomic(uint32_t event); |
Ranjani Sridharan | 7616ca4 | 2018-03-27 22:07:18 -0700 | [diff] [blame] | 116 | void _trace_event_mbox_atomic(uint32_t event); |
Ranjani Sridharan | cb1fc87 | 2018-03-27 22:07:17 -0700 | [diff] [blame] | 117 | void trace_flush(void); |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 118 | void trace_off(void); |
Pierre-Louis Bossart | 81708a5 | 2018-04-04 18:46:50 -0500 | [diff] [blame] | 119 | void trace_init(struct sof *sof); |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 120 | |
| 121 | #if TRACE |
| 122 | |
Ranjani Sridharan | 1c417f9 | 2018-03-27 22:07:19 -0700 | [diff] [blame] | 123 | /* send all trace to mbox and local trace buffer */ |
| 124 | #if TRACEM |
| 125 | #define trace_event(__c, __e) \ |
| 126 | _trace_event_mbox(__c | (__e[0] << 16) | (__e[1] << 8) | __e[2]) |
| 127 | #define trace_event_atomic(__c, __e) \ |
| 128 | _trace_event_mbox_atomic(__c | (__e[0] << 16) | (__e[1] << 8) | __e[2]) |
| 129 | /* send trace events only to the local trace buffer */ |
| 130 | #else |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 131 | #define trace_event(__c, __e) \ |
| 132 | _trace_event(__c | (__e[0] << 16) | (__e[1] <<8) | __e[2]) |
Liam Girdwood | 3dca7b7 | 2017-10-19 17:18:34 +0100 | [diff] [blame] | 133 | #define trace_event_atomic(__c, __e) \ |
| 134 | _trace_event_atomic(__c | (__e[0] << 16) | (__e[1] <<8) | __e[2]) |
Ranjani Sridharan | 1c417f9 | 2018-03-27 22:07:19 -0700 | [diff] [blame] | 135 | #endif |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 136 | #define trace_value(x) _trace_event(x) |
Liam Girdwood | 3dca7b7 | 2017-10-19 17:18:34 +0100 | [diff] [blame] | 137 | #define trace_value_atomic(x) _trace_event_atomic(x) |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 138 | |
| 139 | #define trace_point(x) platform_trace_point(x) |
| 140 | |
| 141 | /* verbose tracing */ |
| 142 | #if TRACEV |
| 143 | #define tracev_event(__c, __e) trace_event(__c, __e) |
| 144 | #define tracev_value(x) _trace_event(x) |
Liam Girdwood | 3dca7b7 | 2017-10-19 17:18:34 +0100 | [diff] [blame] | 145 | #define tracev_event_atomic(__c, __e) trace_event_atomic(__c, __e) |
| 146 | #define tracev_value_atomic(x) _trace_event_atomic(x) |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 147 | #else |
| 148 | #define tracev_event(__c, __e) |
| 149 | #define tracev_value(x) |
Liam Girdwood | 3dca7b7 | 2017-10-19 17:18:34 +0100 | [diff] [blame] | 150 | #define tracev_event_atomic(__c, __e) |
| 151 | #define tracev_value_atomic(x) |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 152 | #endif |
| 153 | |
| 154 | /* error tracing */ |
| 155 | #if TRACEE |
Yan Wang | 58e952d | 2017-10-12 16:35:36 +0800 | [diff] [blame] | 156 | #define trace_error(__c, __e) \ |
Ranjani Sridharan | 7616ca4 | 2018-03-27 22:07:18 -0700 | [diff] [blame] | 157 | _trace_event_mbox_atomic(__c | (__e[0] << 16) | (__e[1] << 8) | __e[2]) |
Liam Girdwood | 3dca7b7 | 2017-10-19 17:18:34 +0100 | [diff] [blame] | 158 | #define trace_error_atomic(__c, __e) \ |
Ranjani Sridharan | 7616ca4 | 2018-03-27 22:07:18 -0700 | [diff] [blame] | 159 | _trace_event_mbox_atomic(__c | (__e[0] << 16) | (__e[1] << 8) | __e[2]) |
| 160 | /* write back error value to mbox */ |
| 161 | #define trace_error_value(x) _trace_event_mbox_atomic(x) |
| 162 | #define trace_error_value_atomic(x) _trace_event_mbox_atomic(x) |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 163 | #else |
| 164 | #define trace_error(__c, __e) |
Liam Girdwood | 3dca7b7 | 2017-10-19 17:18:34 +0100 | [diff] [blame] | 165 | #define trace_error_atomic(__c, __e) |
Ranjani Sridharan | 210989d | 2018-03-25 17:34:04 -0700 | [diff] [blame] | 166 | #define trace_error_value(x) |
| 167 | #define trace_error_value_atomic(x) |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 168 | #endif |
| 169 | |
| 170 | #else |
| 171 | |
| 172 | #define trace_event(x, e) |
| 173 | #define trace_error(c, e) |
| 174 | #define trace_value(x) |
| 175 | #define trace_point(x) |
| 176 | #define tracev_event(__c, __e) |
| 177 | #define tracev_value(x) |
| 178 | |
| 179 | #endif |
| 180 | |
| 181 | #endif |