xref: /netbsd-src/sys/dev/raidframe/rf_general.h (revision 7126f386571adf201536193f5679d0698b159e8e)
1*7126f386Smaya /*	$NetBSD: rf_general.h,v 1.22 2016/12/10 23:03:27 maya Exp $	*/
238a3987bSoster /*
338a3987bSoster  * Copyright (c) 1995 Carnegie-Mellon University.
438a3987bSoster  * All rights reserved.
538a3987bSoster  *
638a3987bSoster  * Author: Mark Holland
738a3987bSoster  *
838a3987bSoster  * Permission to use, copy, modify and distribute this software and
938a3987bSoster  * its documentation is hereby granted, provided that both the copyright
1038a3987bSoster  * notice and this permission notice appear in all copies of the
1138a3987bSoster  * software, derivative works or modified versions, and any portions
1238a3987bSoster  * thereof, and that both notices appear in supporting documentation.
1338a3987bSoster  *
1438a3987bSoster  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
1538a3987bSoster  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
1638a3987bSoster  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
1738a3987bSoster  *
1838a3987bSoster  * Carnegie Mellon requests users of this software to return to
1938a3987bSoster  *
2038a3987bSoster  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
2138a3987bSoster  *  School of Computer Science
2238a3987bSoster  *  Carnegie Mellon University
2338a3987bSoster  *  Pittsburgh PA 15213-3890
2438a3987bSoster  *
2538a3987bSoster  * any improvements or extensions that they make and grant Carnegie the
2638a3987bSoster  * rights to redistribute these changes.
2738a3987bSoster  */
2838a3987bSoster 
2938a3987bSoster /*
3038a3987bSoster  * rf_general.h -- some general-use definitions
3138a3987bSoster  */
3238a3987bSoster 
33765e00d3Soster /* #define NOASSERT */
34765e00d3Soster 
3538a3987bSoster #ifndef _RF__RF_GENERAL_H_
3638a3987bSoster #define _RF__RF_GENERAL_H_
3738a3987bSoster 
381cbbd5c3Sthorpej #ifdef _KERNEL_OPT
391cbbd5c3Sthorpej #include "opt_raid_diagnostic.h"
401cbbd5c3Sthorpej #endif /* _KERNEL_OPT */
411cbbd5c3Sthorpej 
4238a3987bSoster /* error reporting and handling */
4338a3987bSoster 
44268d7559Schristos #include <sys/systm.h>		/* printf, snprintf, and friends */
451eecf8e4Soster 
4638a3987bSoster #define RF_ERRORMSG(s)            printf((s))
4738a3987bSoster #define RF_ERRORMSG1(s,a)         printf((s),(a))
4838a3987bSoster #define RF_ERRORMSG2(s,a,b)       printf((s),(a),(b))
4938a3987bSoster #define RF_ERRORMSG3(s,a,b,c)     printf((s),(a),(b),(c))
507b113952Soster 
51ba757432Schristos void rf_print_panic_message(int, const char *);
52ba757432Schristos void rf_print_assert_panic_message(int, const char *, const char *);
53ba757432Schristos void rf_print_unable_to_init_mutex(const char *, int, int);
54ba757432Schristos void rf_print_unable_to_add_shutdown(const char *, int, int);
55a2b91428Soster 
56b36a1a08Soster 
57*7126f386Smaya #define RF_PANIC() {rf_print_panic_message(__LINE__,__FILE__);}
5838a3987bSoster 
594d098765Schristos #if defined(RAID_DIAGNOSTIC) || defined(__COVERITY__)
6038a3987bSoster #define RF_ASSERT(_x_) { \
6138a3987bSoster   if (!(_x_)) { \
62b36a1a08Soster     rf_print_assert_panic_message(__LINE__, __FILE__, #_x_); \
6338a3987bSoster   } \
6438a3987bSoster }
651cbbd5c3Sthorpej #else /* RAID_DIAGNOSTIC */
667d841619Smartin #define RF_ASSERT(x) { /*noop*/ (void)(x); }
671cbbd5c3Sthorpej #endif /* RAID_DIAGNOSTIC */
6838a3987bSoster 
6938a3987bSoster /* random stuff */
7038a3987bSoster #define RF_MAX(a,b) (((a) > (b)) ? (a) : (b))
7138a3987bSoster #define RF_MIN(a,b) (((a) < (b)) ? (a) : (b))
7238a3987bSoster 
7338a3987bSoster /* divide-by-zero check */
7438a3987bSoster #define RF_DB0_CHECK(a,b) ( ((b)==0) ? 0 : (a)/(b) )
7538a3987bSoster 
7638a3987bSoster /* get time of day */
7738a3987bSoster #define RF_GETTIME(_t) microtime(&(_t))
7838a3987bSoster 
7938a3987bSoster #define RF_UL(x)           ((unsigned long) (x))
8024a4b8faSthorpej #define RF_PGMASK          PAGE_MASK
8124a4b8faSthorpej #define RF_BLIP(x)         (PAGE_SIZE - (RF_UL(x) & RF_PGMASK))	/* bytes left in page */
8238a3987bSoster #define RF_PAGE_ALIGNED(x) ((RF_UL(x) & RF_PGMASK) == 0)
8338a3987bSoster 
8438a3987bSoster #ifdef __STDC__
8538a3987bSoster #define RF_STRING(_str_) #_str_
8638a3987bSoster #else				/* __STDC__ */
8738a3987bSoster #define RF_STRING(_str_) "_str_"
8838a3987bSoster #endif				/* __STDC__ */
8938a3987bSoster 
9038a3987bSoster #endif				/* !_RF__RF_GENERAL_H_ */
91