1/*
2 * Copyright (c) 2008-2012 Apple Computer, Inc. All rights reserved.
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_IO_USB_MSC_DEBUGGING__
25#define __IOKIT_IO_USB_MSC_DEBUGGING__
26
27#if KERNEL
28#include <IOKit/IOLib.h>
29#else
30#include <IOKit/IOKitLib.h>
31#endif
32
33#ifndef DEBUG_ASSERT_COMPONENT_NAME_STRING
34	#define DEBUG_ASSERT_COMPONENT_NAME_STRING "USB_MSC"
35#endif
36
37#if KERNEL
38
39// Since we depend on IOSCSIArchitectureModelFamily and it has a debug
40// assert function we can use it here.
41
42extern void
43IOSCSIArchitectureModelFamilyDebugAssert ( 	const char * componentNameString,
44											const char * assertionString,
45											const char * exceptionLabelString,
46											const char * errorString,
47											const char * fileName,
48											long lineNumber,
49											int errorCode );
50
51
52#define DEBUG_ASSERT_MESSAGE( componentNameString, \
53	assertionString, \
54	exceptionLabelString, \
55	errorString, \
56	fileName, \
57	lineNumber, \
58	error ) \
59	IOSCSIArchitectureModelFamilyDebugAssert( componentNameString, \
60	assertionString, \
61	exceptionLabelString, \
62	errorString, \
63	fileName, \
64	lineNumber, \
65	error )
66
67
68#endif	/* KERNEL */
69
70#include <AssertMacros.h>
71
72// Other helpful macros (maybe some day these will make
73// their way into AssertMacros.h)
74
75#define require_success( errorCode, exceptionLabel ) \
76	require( kIOReturnSuccess == (errorCode), exceptionLabel )
77
78#define require_success_action( errorCode, exceptionLabel, action ) \
79	require_action( kIOReturnSuccess == (errorCode), exceptionLabel, action )
80
81#define require_success_quiet( errorCode, exceptionLabel ) \
82	require_quiet( kIOReturnSuccess == (errorCode), exceptionLabel )
83
84#define require_success_action_quiet( errorCode, exceptionLabel, action ) \
85	require_action_quiet( kIOReturnSuccess == (errorCode), exceptionLabel, action )
86
87#define require_success_string( errorCode, exceptionLabel, message ) \
88	require_string( kIOReturnSuccess == (errorCode), exceptionLabel, message )
89
90#define require_success_action_string( errorCode, exceptionLabel, action, message ) \
91	require_action_string( kIOReturnSuccess == (errorCode), exceptionLabel, action, message )
92
93
94#define require_nonzero( obj, exceptionLabel ) \
95	require( ( 0 != obj ), exceptionLabel )
96
97#define require_nonzero_action( obj, exceptionLabel, action ) \
98	require_action( ( 0 != obj ), exceptionLabel, action )
99
100#define require_nonzero_quiet( obj, exceptionLabel ) \
101	require_quiet( ( 0 != obj ), exceptionLabel )
102
103#define require_nonzero_action_quiet( obj, exceptionLabel, action ) \
104	require_action_quiet( ( 0 != obj ), exceptionLabel, action )
105
106#define require_nonzero_string( obj, exceptionLabel, message ) \
107	require_string( ( 0 != obj ), exceptionLabel, message )
108
109#define require_nonzero_action_string( obj, exceptionLabel, action, message ) \
110	require_action_string( ( 0 != obj ), exceptionLabel, action, message )
111
112
113// Macros for printing debugging information
114
115#define KPRINTF(LEVEL, FMT, ARGS...)	kprintf(FMT "\n", ## ARGS)
116
117// STATUS_LOG logging macros are controlled by USB_MASS_STORAGE_DEBUG,
118// which is in turn defined by the xcodebuild configuration:
119//
120//	xcodebuild			USB_MASS_STORAGE_DEBUG		STATUS_LOG
121//	configuration		value						disposition
122//
123//	"Deployment" 		(undefined)					(compiled out)
124//	"Logging"			1							USBLog
125//	"kprintf"			2							kprintf
126
127#if (USB_MASS_STORAGE_DEBUG == 2)
128
129#define PANIC_NOW(x)	panic x
130#define STATUS_LOG(x)	KPRINTF x
131
132#elif (USB_MASS_STORAGE_DEBUG == 1)
133
134#define PANIC_NOW(x)	panic x
135// Override the debug level for USBLog to make sure our logs make it out and then import
136// the logging header.
137#define DEBUG_LEVEL		1
138#include <IOKit/usb/IOUSBLog.h>
139#define STATUS_LOG(x)	USBLog x
140
141#else
142
143#define STATUS_LOG(x)
144#define PANIC_NOW(x)
145
146#endif
147
148#endif	/* __IOKIT_IO_USB_MSC_DEBUGGING__ */
149