1 /**************************************************************************
3 * Copyright © 2000-2008 Alacritech, Inc. All rights reserved.
5 * $Id: sxgdbg.h,v 1.1 2008/06/27 12:49:28 mook Exp $
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY ALACRITECH, INC. ``AS IS'' AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ALACRITECH, INC. OR
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
25 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
28 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * The views and conclusions contained in the software and documentation
32 * are those of the authors and should not be interpreted as representing
33 * official policies, either expressed or implied, of Alacritech, Inc.
35 **************************************************************************/
40 * All debug and assertion-based definitions and macros are included
41 * in this file for the SXGOSS driver.
47 #define ATK_TRACE_ENABLED 1
49 #define DBG_ERROR(n, args...) printk(KERN_EMERG n, ##args)
55 #ifdef SXG_ASSERT_ENABLED
60 DBG_ERROR("ASSERT() Failure: file %s, function %s line %d\n",\
61 __FILE__, __func__, __LINE__); \
69 #endif /* SXG_ASSERT_ENABLED */
74 * Global for timer granularity; every driver must have an instance
75 * of this initialized to 0
78 extern ulong ATKTimerDiv
;
83 * This structure defines an entry in the trace buffer. The
84 * first few fields mean the same from entry to entry, while
85 * the meaning of last several fields change to suit the
86 * needs of the trace entry. Typically they are function call
89 struct trace_entry_t
{
90 char name
[8]; /* 8 character name - like 's'i'm'b'a'r'c'v' */
91 u32 time
; /* Current clock tic */
92 unsigned char cpu
; /* Current CPU */
93 unsigned char irql
; /* Current IRQL */
94 unsigned char driver
; /* The driver which added the trace call */
95 unsigned char pad2
; /* pad to 4 byte boundary - will probably get used */
96 u32 arg1
; /* Caller arg1 */
97 u32 arg2
; /* Caller arg2 */
98 u32 arg3
; /* Caller arg3 */
99 u32 arg4
; /* Caller arg4 */
103 * Driver types for driver field in trace_entry_t
109 #define TRACE_ENTRIES 1024
111 struct sxg_trace_buffer_t
{
112 unsigned int size
; /* aid for windbg extension */
113 unsigned int in
; /* Where to add */
114 unsigned int level
; /* Current Trace level */
115 spinlock_t lock
; /* For MP tracing */
116 struct trace_entry_t entries
[TRACE_ENTRIES
];/* The circular buffer */
122 * XXX At the moment I am only defining critical, important, and noisy.
123 * I am leaving room for more if anyone wants them.
125 #define TRACE_NONE 0 /* For trace level - if no tracing wanted */
126 #define TRACE_CRITICAL 1 /* minimal tracing - only critical stuff */
127 #define TRACE_IMPORTANT 5 /* more tracing - anything important */
128 #define TRACE_NOISY 10 /* Everything in the world */
131 /**********************************************************************
133 * The macros themselves -
135 *********************************************************************/
136 #if ATK_TRACE_ENABLED
137 #define SXG_TRACE_INIT(buffer, tlevel) \
139 memset((buffer), 0, sizeof(struct sxg_trace_buffer_t)); \
140 (buffer)->level = (tlevel); \
141 (buffer)->size = TRACE_ENTRIES; \
142 spin_lock_init(&(buffer)->lock); \
145 #define SXG_TRACE_INIT(buffer, tlevel)
149 * The trace macro. This is active only if ATK_TRACE_ENABLED is set.
151 #if ATK_TRACE_ENABLED
152 #define SXG_TRACE(tdriver, buffer, tlevel, tname, a1, a2, a3, a4) { \
153 if ((buffer) && ((buffer)->level >= (tlevel))) { \
154 unsigned int trace_irql = 0; /* ?????? FIX THIS */ \
155 unsigned int trace_len; \
156 struct trace_entry_t *trace_entry; \
157 struct timeval timev; \
159 spin_lock(&(buffer)->lock); \
160 trace_entry = &(buffer)->entries[(buffer)->in]; \
161 do_gettimeofday(&timev); \
163 memset(trace_entry->name, 0, 8); \
164 trace_len = strlen(tname); \
165 trace_len = trace_len > 8 ? 8 : trace_len; \
166 memcpy(trace_entry->name, (tname), trace_len); \
167 trace_entry->time = timev.tv_usec; \
168 trace_entry->cpu = (unsigned char)(smp_processor_id() & 0xFF); \
169 trace_entry->driver = (tdriver); \
170 trace_entry->irql = trace_irql; \
171 trace_entry->arg1 = (ulong)(a1); \
172 trace_entry->arg2 = (ulong)(a2); \
173 trace_entry->arg3 = (ulong)(a3); \
174 trace_entry->arg4 = (ulong)(a4); \
177 if ((buffer)->in == TRACE_ENTRIES) \
180 spin_unlock(&(buffer)->lock); \
184 #define SXG_TRACE(tdriver, buffer, tlevel, tname, a1, a2, a3, a4)
189 #endif /* _SXG_DEBUG_H_ */