Chameleon

Chameleon Svn Source Tree

Root/trunk/i386/include/IOKit/usb/IOUSBLog.h

1/*
2
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24#ifndef _IOKIT_IOUSBLOG_H
25#define _IOKIT_IOUSBLOG_H
26
27#include <IOKit/IOService.h>
28#include<IOKit/IOLib.h>
29
30
31#ifdef__cplusplus
32extern "C" {
33#endif
34
35// USB Specific defines
36#define USBLog( LEVEL, ARGS...)KernelDebugLogTag( LEVEL, 'USBF', ## ARGS )
37#define USBError( LEVEL, ARGS...)KernelDebugLogInternal( ( LEVEL ), 'USBF', ## ARGS )
38#define USBStringFromReturn( IORETURN)(IOUSBController::_log)->stringFromReturn( IORETURN )
39
40
41// Possible Debug levels. If DEBUG_LEVEL is set to DEBUG_LEVEL_PRODUCTION, all debug logs will be
42// stripped of the final code.
43
44#defineDEBUG_LEVEL_PRODUCTION0
45#defineDEBUG_LEVEL_DEVELOPMENT1
46#defineDEBUG_LEVEL_ALPHA2
47#defineDEBUG_LEVEL_BETA3
48#defineDEBUG_LEVEL_FINALDEBUG_LEVEL_PRODUCTION
49
50// Allow clients to define their own debug level.
51
52#if ( !defined( DEBUG_LEVEL ) )
53#defineDEBUG_LEVELDEBUG_LEVEL_PRODUCTION
54#endif
55
56// Index for user client methods
57//
58enum
59{
60 kUSBControllerUserClientOpen = 0,
61 kUSBControllerUserClientClose,
62 kUSBControllerUserClientEnableLogger,
63 kUSBControllerUserClientSetDebuggingLevel,
64 kUSBControllerUserClientSetDebuggingType,
65 kUSBControllerUserClientGetDebuggingLevel,
66 kUSBControllerUserClientGetDebuggingType,
67#ifndef __OPEN_SOURCE__
68 kUSBControllerUserClientSetTestMode,
69 kUSBControllerUserClientReadRegister,
70 kUSBControllerUserClientWriteRegister,
71 kUSBControllerUserClientMessageController,
72#endif
73 kNumUSBControllerMethods
74};
75
76#ifndef __OPEN_SOURCE__
77// Enums for the private kIOUSBMessageController message
78enum
79{
80kIOUSBMessageControllerDoGPIOReset = 0x00000001
81};
82#endif
83
84// Info Debug Output Types.
85
86typedef UInt32KernelDebuggingOutputType;
87enum
88{
89kKernelDebugOutputIOLogType= 0x00000001,
90kKernelDebugOutputKextLoggerType= 0x00000002
91};
92
93
94// Info Debug levels.
95
96typedef UInt32KernelDebugLevel;
97enum
98{
99kKernelDebugInfoLevel = 1000,
100kKernelDebugRareInfoLevel= 2000,
101kKernelDebugAllowedErrorLevel= 3000,
102kKernelDebugAssertLevel = 4000,
103kKernelDebugRequireLevel= 5000,
104kKernelDebugErrorLevel= 6000,
105kKernelDebugCriticalErrorLevel= 7000,
106kKernelDebugTragicErrorLevel= 8000,
107kKernelDebugAnyLevel= 0
108};
109
110// Function prototypes.
111
112voidKernelDebugSetLevel( KernelDebugLevel inLevel );
113KernelDebugLevelKernelDebugGetLevel();
114voidKernelDebugSetOutputType( KernelDebuggingOutputType inType );
115KernelDebuggingOutputTypeKernelDebugGetOutputType();
116IOReturn KernelDebugFindKernelLogger();
117voidKernelDebugEnable( bool enable );
118
119//Yes, you can call this directly. But, why? If you use the macros declared below, such as
120//KernelIOLog, you get the benefit of having your logs compiled out when you set the
121//DEBUG_LEVEL to production mode and recompile. Dude. Sweet. What's mine say?
122
123voidKernelDebugLogInternal( KernelDebugLevel inLevel, UInt32 inTag, char const *inFormatString, ... ) __attribute__ ((format(printf,3,4)));;
124void KernelDebugLogDataInternal( UInt32 inLevel, UInt32 inTag, void *buffer, UInt32 byteCount, bool preBuffer);
125
126// Handy macros.
127
128#define REQUIRE_NO_ERR_PRINTF( VALUE, LABEL, ARGS... )\
129if ( VALUE != kIOReturnSuccess )\
130{\
131KernelDebugLogInternal( kDebugInfoLevel, 'BluD', ## ARGS );\
132goto LABEL;\
133}
134
135#define REQUIRE_PRINTF( TEST, LABEL, ARGS... )\
136do\
137{\
138if ( !( TEST ) )\
139{\
140KernelDebugLogInternal( kDebugInfoLevel, 'BluD', ## ARGS );\
141goto LABEL;\
142}\
143} while( false )
144
145// Some macros to call the debugging outputs. We'll strip out the debug logs if we are production code.
146
147#if DEBUG_LEVEL != DEBUG_LEVEL_PRODUCTION
148#defineKernelDebugLog( LEVEL, ARGS... )KernelDebugLogInternal( ( LEVEL ), 'KDbg', ## ARGS ) __attribute__ ((format(printf,1,2)));
149#defineKernelDebugLogTag( LEVEL, TAG, ARGS... )KernelDebugLogInternal( ( LEVEL ), ( TAG ), ## ARGS )
150#define KernelDebugLogData( LEVEL, TAG, BUFFER, SIZE, HOLD)KernelDebugLogDataInternal( ( LEVEL ), ( TAG ), ( BUFFER ), ( SIZE ), ( HOLD ))
151#else
152#defineKernelDebugLog( LEVEL, ARGS... )
153#defineKernelDebugLogTag( LEVEL, TAG, ARGS... )
154#define KernelDebugLogData( LEVEL, TAG, BUFFER, SIZE, HOLD)
155#endif
156
157
158#ifdef__cplusplus
159}
160
161//================================================================================================
162// Forward declarations
163//================================================================================================
164class com_apple_iokit_KLogClient;
165
166//================================================================================================
167// Defines
168//================================================================================================
169#define kLogKextName "com_apple_iokit_KLog"
170#define MAXUSERS 5
171
172//================================================================================================
173// Custom Types
174//================================================================================================
175
176typedef UInt32 KLogLevel;
177typedef UInt32 KLogTag;
178
179//================================================================================================
180// com_apple_iokit_KLog
181//================================================================================================
182
183class com_apple_iokit_KLog : public IOService
184{
185
186 OSDeclareDefaultStructors(com_apple_iokit_KLog)
187
188 com_apple_iokit_KLogClient *mClientPtr[MAXUSERS+1];
189
190 unsigned char *mMsgBuffer;
191 UInt8 mClientCount;
192 UInt8 mMsgSize;
193 bool mErrFlag;
194 struct timeval *mTimeVal;
195 IOLock *mLogLock;
196
197public:
198
199 static com_apple_iokit_KLog*logger;
200
201 virtual bool init(OSDictionary *dictionary = 0);
202 virtual void free(void);
203
204 virtual IOService *probe(IOService *provider, SInt32 *score);
205 virtual bool start(IOService *provider);
206 virtual void stop(IOService *provider);
207 virtual IOReturn newUserClient( task_t owningTask, void * securityID,
208 UInt32 type, IOUserClient ** handler );
209
210 virtual SInt8Log( KLogLevel level, KLogTag tag, const char *format, ... );
211 virtual SInt8vLog( KLogLevel level, KLogTag tag, const char *format, va_list in_va_list );
212
213 void closeChild(com_apple_iokit_KLogClient *ptr);
214 void setErr(bool set);
215
216};
217
218#define kMaxStatusBufSize(8*1024)
219
220
221class IOUSBLog : public IOService
222{
223 OSDeclareAbstractStructors(IOUSBLog)
224
225private:
226public:
227 virtual boolinit( OSDictionary * dictionary = 0 );
228 virtual const char *stringFromReturn( IOReturn rtn );
229static IOUSBLog*usblog();
230 virtual void AddStatusLevel (UInt32 level, UInt32 ref, char *status, UInt32 value);
231 virtual voidAddStatus(char *message);
232 virtual voidAddStatus(UInt32 level, char *message);
233 virtual void USBLogPrintf(UInt32 level, char *format,...);
234virtual char *strstr(const char *in, const char *str);
235};
236
237
238#endif
239#endif /* ! _IOKIT_IOUSBLOG_H */
240
241

Archive Download this file

Revision: 881