Root/
Source at commit 1166 created 13 years 10 days ago. By meklort, Fixed recent Makefile changes. Please do not use /Users/evan/SourceCode/tmp/chameleon/trunk or VPATH. the *only* time you should use /Users/evan/SourceCode/tmp/chameleon/trunk is when setting the SRCROOT variable. Also note that very soon make pkg is going to be removed. The pkg build script in trunk is very out of date. Instead please use the package maker at http://forge.voodooprojects.org/p/chameleonApplications/. Once this is ready for trunk it will be merged. | |
---|---|
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␊ |
32 | ␉extern "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 | #define␉DEBUG_LEVEL_PRODUCTION␉␉0␊ |
45 | #define␉DEBUG_LEVEL_DEVELOPMENT␉␉1␊ |
46 | #define␉DEBUG_LEVEL_ALPHA␉␉␉2␊ |
47 | #define␉DEBUG_LEVEL_BETA␉␉␉3␊ |
48 | #define␉DEBUG_LEVEL_FINAL␉␉␉DEBUG_LEVEL_PRODUCTION␊ |
49 | ␊ |
50 | // Allow clients to define their own debug level.␊ |
51 | ␊ |
52 | #if ( !defined( DEBUG_LEVEL ) )␊ |
53 | ␉#define␉DEBUG_LEVEL␉␉␉DEBUG_LEVEL_PRODUCTION␊ |
54 | #endif␊ |
55 | ␊ |
56 | // Index for user client methods␊ |
57 | //␊ |
58 | enum␊ |
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␊ |
78 | enum␊ |
79 | {␊ |
80 | ␉kIOUSBMessageControllerDoGPIOReset = 0x00000001␊ |
81 | };␊ |
82 | #endif␊ |
83 | ␊ |
84 | // Info Debug Output Types.␊ |
85 | ␊ |
86 | typedef UInt32␉␉KernelDebuggingOutputType;␊ |
87 | enum␊ |
88 | {␊ |
89 | ␉kKernelDebugOutputIOLogType␉␉= 0x00000001, ␊ |
90 | ␉kKernelDebugOutputKextLoggerType␉= 0x00000002␊ |
91 | };␊ |
92 | ␊ |
93 | ␊ |
94 | // Info Debug levels.␊ |
95 | ␊ |
96 | typedef UInt32␉␉KernelDebugLevel;␊ |
97 | enum␊ |
98 | {␊ |
99 | ␉kKernelDebugInfoLevel ␉␉= 1000, ␊ |
100 | ␉kKernelDebugRareInfoLevel␉= 2000, ␊ |
101 | ␉kKernelDebugAllowedErrorLevel␉= 3000, ␊ |
102 | ␉kKernelDebugAssertLevel ␉= 4000, ␊ |
103 | ␉kKernelDebugRequireLevel␉= 5000, ␊ |
104 | ␉kKernelDebugErrorLevel␉␉= 6000, ␊ |
105 | ␉kKernelDebugCriticalErrorLevel␉= 7000, ␊ |
106 | ␉kKernelDebugTragicErrorLevel␉= 8000, ␊ |
107 | ␉kKernelDebugAnyLevel␉␉= 0␊ |
108 | };␊ |
109 | ␊ |
110 | // Function prototypes.␊ |
111 | ␊ |
112 | void␉␉␉KernelDebugSetLevel( KernelDebugLevel inLevel );␊ |
113 | KernelDebugLevel␉KernelDebugGetLevel();␊ |
114 | void␉␉␉KernelDebugSetOutputType( KernelDebuggingOutputType inType );␊ |
115 | KernelDebuggingOutputType␉KernelDebugGetOutputType();␊ |
116 | IOReturn ␉␉KernelDebugFindKernelLogger();␊ |
117 | void␉␉␉KernelDebugEnable( 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 | ␊ |
123 | void␉␉␉KernelDebugLogInternal( KernelDebugLevel inLevel, UInt32 inTag, char const *inFormatString, ... ) __attribute__ ((format(printf,3,4)));;␊ |
124 | void ␉␉␉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... )␉␉␉␉␉␉␉\␊ |
129 | ␉if ( VALUE != kIOReturnSuccess )␉␉␉␉␉␉␉␉␉\␊ |
130 | ␉{␉␉␉␉␉␉␉␉␉␉␉␉\␊ |
131 | ␉␉KernelDebugLogInternal( kDebugInfoLevel, 'BluD', ## ARGS );␉␉␉␉\␊ |
132 | ␉␉goto LABEL;␉␉␉␉␉␉␉␉␉␉\␊ |
133 | ␉}␊ |
134 | ␊ |
135 | #define REQUIRE_PRINTF( TEST, LABEL, ARGS... )␉␉␉␉␉␉␉␉\␊ |
136 | ␉do␉␉␉␉␉␉␉␉␉␉␉␉\␊ |
137 | ␉{␉␉␉␉␉␉␉␉␉␉␉␉\␊ |
138 | ␉␉if ( !( TEST ) )␉␉␉␉␉␉␉␉␉␉\␊ |
139 | ␉␉{␉␉␉␉␉␉␉␉␉␉␉\␊ |
140 | ␉␉␉KernelDebugLogInternal( kDebugInfoLevel, 'BluD', ## ARGS );␉␉␉\␊ |
141 | ␉␉␉goto 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 | #define␉KernelDebugLog( LEVEL, ARGS... )␉␉␉KernelDebugLogInternal( ( LEVEL ), 'KDbg', ## ARGS ) __attribute__ ((format(printf,1,2)));␊ |
149 | ␉#define␉KernelDebugLogTag( LEVEL, TAG, ARGS... )␉␉KernelDebugLogInternal( ( LEVEL ), ( TAG ), ## ARGS )␊ |
150 | ␉#define KernelDebugLogData( LEVEL, TAG, BUFFER, SIZE, HOLD)␉KernelDebugLogDataInternal( ( LEVEL ), ( TAG ), ( BUFFER ), ( SIZE ), ( HOLD ))␊ |
151 | #else␊ |
152 | ␉#define␉KernelDebugLog( LEVEL, ARGS... )␊ |
153 | ␉#define␉KernelDebugLogTag( 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 | //================================================================================================␊ |
164 | class 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 | ␊ |
176 | typedef UInt32 KLogLevel;␊ |
177 | typedef UInt32 KLogTag;␊ |
178 | ␊ |
179 | //================================================================================================␊ |
180 | // com_apple_iokit_KLog␊ |
181 | //================================================================================================␊ |
182 | ␊ |
183 | class 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 | ␊ |
197 | public:␊ |
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 SInt8␉␉␉Log( KLogLevel level, KLogTag tag, const char *format, ... );␊ |
211 | virtual SInt8␉␉␉vLog( 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 | ␊ |
221 | class IOUSBLog : public IOService␊ |
222 | {␊ |
223 | OSDeclareAbstractStructors(IOUSBLog)␊ |
224 | ␊ |
225 | private:␊ |
226 | public:␊ |
227 | virtual bool␉init( OSDictionary * dictionary = 0 );␊ |
228 | ␉virtual const char *␉␉␉stringFromReturn( IOReturn rtn );␊ |
229 | ␉static IOUSBLog␉*usblog();␊ |
230 | virtual void ␉AddStatusLevel (UInt32 level, UInt32 ref, char *status, UInt32 value);␊ |
231 | virtual void␉AddStatus(char *message);␊ |
232 | virtual void␉AddStatus(UInt32 level, char *message);␊ |
233 | virtual void ␉USBLogPrintf(UInt32 level, char *format,...);␊ |
234 | ␉virtual char *␉strstr(const char *in, const char *str);␊ |
235 | };␊ |
236 | ␊ |
237 | ␊ |
238 | #endif␊ |
239 | #endif /* ! _IOKIT_IOUSBLOG_H */␊ |
240 | ␊ |
241 |