/*****************************************************************************/

/*
 *      common.h -- C preprocessor facilities
 *
 *      Copyright (C) 1999-2000  Sigma Designs
 *                    written by Emmanuel Michon <emmanuel_michon@sdesigns.com>
 *
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/*****************************************************************************/

#define RAS "RAS"

#define GIVELINE printk( __FILE__ "(%d): ", __LINE__ )

/* The following macro executes CALL (a call to a function
   like

   int dosomething()

   where return not zero means trouble).
   
   If CALL fails, logs error and return code whatever VERBOSE is.
   If CALL succeeds, logs and displays USEFULINFO only if VERBOSE is 1.
*/
#define VERBOSECALL(VERBOSE,CALL,RETURNEDERROR,USEFULINFO...) \
{ \
	int rc; \
	\
	if ((rc=CALL)) { \
		GIVELINE; \
		printk( # CALL " failed with return code %d",rc); \
		printk("\n"); \
 		return RETURNEDERROR; \
	} \
	else { \
		if (VERBOSE) { \
			GIVELINE; \
			printk( # CALL " completed (" USEFULINFO ); \
			printk(")\n"); \
		} \
	} \
}

/* same thing, verifies that a VAR is not zero */
#define ASSERT(VERBOSE,VAR,RETURNEDERROR,USEFULINFO...) \
{ \
	if (VAR==0) { \
		GIVELINE; \
		printk( # VAR " is null"); \
		printk("\n"); \
		return RETURNEDERROR; \
	} \
	else { \
		if (VERBOSE) { \
			GIVELINE; \
			printk(# VAR " is non null (" USEFULINFO ); \
			printk(")\n"); \
		} \
	} \
}

#define LOGTHIS(VERBOSE,TYPE,USEFULINFO...) \
{ \
	if (VERBOSE) { \
		GIVELINE; \
		printk( # TYPE " " USEFULINFO ); \
		printk("\n"); \
	} \
}

#define LOGINFO(VERBOSE,USEFULINFO...) LOGTHIS(VERBOSE, [info] , USEFULINFO ) 
#define LOGERROR(VERBOSE,USEFULINFO...) LOGTHIS(VERBOSE, [error] , USEFULINFO ) 

#if DEBUG==0
#define DUMPDMABUF(OPERATION)
#else
#define DUMPDMABUF(OPERATION) printk(# OPERATION " index%d inuse%d Size%ld PV%08lx KV%08lx PH%08lx\n", \
					   i,									    \
					   dev->dmabuf_table[i].inuse,						    \
					   dev->dmabuf_table[i].Size,						    \
					   dev->dmabuf_table[i].ProcessVirtualAddress,				    \
					   dev->dmabuf_table[i].KernelVirtualAddress,				    \
					   dev->dmabuf_table[i].PhysicalAddress);
#endif
