]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/staging/sxg/sxgdbg.h
Merge branch 'linus' into x86/setup-lzma
[linux-2.6-omap-h63xx.git] / drivers / staging / sxg / sxgdbg.h
1 /**************************************************************************
2  *
3  * Copyright © 2000-2008 Alacritech, Inc.  All rights reserved.
4  *
5  * $Id: sxgdbg.h,v 1.1 2008/06/27 12:49:28 mook Exp $
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
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.
17  *
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
29  * SUCH DAMAGE.
30  *
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.
34  *
35  **************************************************************************/
36
37 /*
38  * FILENAME: sxgdbg.h
39  *
40  * All debug and assertion-based definitions and macros are included
41  * in this file for the SXGOSS driver.
42  */
43 #ifndef _SXG_DEBUG_H_
44 #define _SXG_DEBUG_H_
45
46 #define ATKDBG  1
47 #define ATK_TRACE_ENABLED 1
48
49 #define DBG_ERROR(n, args...)   printk(KERN_EMERG n, ##args)
50
51 #ifdef ASSERT
52 #undef ASSERT
53 #endif
54
55 #ifdef SXG_ASSERT_ENABLED
56 #ifndef ASSERT
57 #define ASSERT(a)                                                                 \
58     {                                                                             \
59         if (!(a)) {                                                               \
60             DBG_ERROR("ASSERT() Failure: file %s, function %s  line %d\n",\
61                 __FILE__, __func__, __LINE__);                                \
62         }                                                                         \
63     }
64 #endif
65 #else
66 #ifndef ASSERT
67 #define ASSERT(a)
68 #endif
69 #endif /* SXG_ASSERT_ENABLED  */
70
71
72 #ifdef ATKDBG
73 /*
74  *  Global for timer granularity; every driver must have an instance
75  *  of this initialized to 0
76  */
77
78 extern ulong ATKTimerDiv;
79
80 /*
81  * trace_entry_t -
82  *
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
87  * parameters.
88  */
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 */
100 };
101
102 /*
103  * Driver types for driver field in trace_entry_t
104  */
105 #define TRACE_SXG             1
106 #define TRACE_VPCI            2
107 #define TRACE_SLIC            3
108
109 #define TRACE_ENTRIES   1024
110
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 */
117 };
118
119 /*
120  * The trace levels
121  *
122  * XXX At the moment I am only defining critical, important, and noisy.
123  * I am leaving room for more if anyone wants them.
124  */
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 */
129
130
131 /**********************************************************************
132  *
133  * The macros themselves -
134  *
135  *********************************************************************/
136 #if ATK_TRACE_ENABLED
137 #define SXG_TRACE_INIT(buffer, tlevel)                          \
138 {                                                               \
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);                        \
143 }
144 #else
145 #define SXG_TRACE_INIT(buffer, tlevel)
146 #endif
147
148 /*
149  * The trace macro.  This is active only if ATK_TRACE_ENABLED is set.
150  */
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;                                       \
158                                                                              \
159                 spin_lock(&(buffer)->lock);                       \
160                 trace_entry = &(buffer)->entries[(buffer)->in];              \
161                 do_gettimeofday(&timev);                                     \
162                                                                              \
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);                             \
175                                                                              \
176                 (buffer)->in++;                                              \
177                 if ((buffer)->in == TRACE_ENTRIES)                           \
178                         (buffer)->in = 0;                                    \
179                                                                              \
180                 spin_unlock(&(buffer)->lock);                       \
181         }                                                                    \
182 }
183 #else
184 #define SXG_TRACE(tdriver, buffer, tlevel, tname, a1, a2, a3, a4)
185 #endif
186
187 #endif
188
189 #endif  /*  _SXG_DEBUG_H_  */