]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/staging/sxg/sxgdbg.h
Merge branch 'for-linus' of git://git.o-hand.com/linux-rpurdie-leds
[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 typedef struct _trace_entry_s {
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 } trace_entry_t, *ptrace_entry_t;
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 typedef struct _sxg_trace_buffer_t
112 {
113         unsigned int                    size;                  /* aid for windbg extension */
114         unsigned int                    in;                    /* Where to add */
115         unsigned int                    level;                 /* Current Trace level */
116         spinlock_t      lock;                  /* For MP tracing */
117         trace_entry_t           entries[TRACE_ENTRIES];/* The circular buffer */
118 } sxg_trace_buffer_t;
119
120 /*
121  * The trace levels
122  *
123  * XXX At the moment I am only defining critical, important, and noisy.
124  * I am leaving room for more if anyone wants them.
125  */
126 #define TRACE_NONE              0   /* For trace level - if no tracing wanted */
127 #define TRACE_CRITICAL          1   /* minimal tracing - only critical stuff */
128 #define TRACE_IMPORTANT         5   /* more tracing - anything important */
129 #define TRACE_NOISY             10  /* Everything in the world */
130
131
132 /**********************************************************************
133  *
134  * The macros themselves -
135  *
136  *********************************************************************/
137 #if ATK_TRACE_ENABLED
138 #define SXG_TRACE_INIT(buffer, tlevel)                          \
139 {                                                               \
140         memset((buffer), 0, sizeof(sxg_trace_buffer_t));        \
141         (buffer)->level = (tlevel);                             \
142         (buffer)->size = TRACE_ENTRIES;                         \
143         spin_lock_init(&(buffer)->lock);                        \
144 }
145 #else
146 #define SXG_TRACE_INIT(buffer, tlevel)
147 #endif
148
149 /*
150  * The trace macro.  This is active only if ATK_TRACE_ENABLED is set.
151  */
152 #if ATK_TRACE_ENABLED
153 #define SXG_TRACE(tdriver, buffer, tlevel, tname, a1, a2, a3, a4) {        \
154         if ((buffer) && ((buffer)->level >= (tlevel))) {                      \
155                 unsigned int            trace_irql = 0;    /* ?????? FIX THIS  */    \
156                 unsigned int            trace_len;                                   \
157                 ptrace_entry_t  trace_entry;                                 \
158                 struct timeval  timev;                                       \
159                                                                              \
160                 spin_lock(&(buffer)->lock);                       \
161                 trace_entry = &(buffer)->entries[(buffer)->in];              \
162                 do_gettimeofday(&timev);                                     \
163                                                                              \
164                 memset(trace_entry->name, 0, 8);                             \
165                 trace_len = strlen(tname);                                   \
166                 trace_len = trace_len > 8 ? 8 : trace_len;                   \
167                 memcpy(trace_entry->name, (tname), trace_len);               \
168                 trace_entry->time = timev.tv_usec;                           \
169                 trace_entry->cpu = (unsigned char)(smp_processor_id() & 0xFF);       \
170                 trace_entry->driver = (tdriver);                             \
171                 trace_entry->irql = trace_irql;                              \
172                 trace_entry->arg1 = (ulong)(a1);                             \
173                 trace_entry->arg2 = (ulong)(a2);                             \
174                 trace_entry->arg3 = (ulong)(a3);                             \
175                 trace_entry->arg4 = (ulong)(a4);                             \
176                                                                              \
177                 (buffer)->in++;                                              \
178                 if ((buffer)->in == TRACE_ENTRIES)                           \
179                         (buffer)->in = 0;                                    \
180                                                                              \
181                 spin_unlock(&(buffer)->lock);                       \
182         }                                                                    \
183 }
184 #else
185 #define SXG_TRACE(tdriver, buffer, tlevel, tname, a1, a2, a3, a4)
186 #endif
187
188 #endif
189
190 #endif  /*  _SXG_DEBUG_H_  */