rf_general.h revision 1.2 1 /* $NetBSD: rf_general.h,v 1.2 1999/01/26 02:33:58 oster Exp $ */
2 /*
3 * Copyright (c) 1995 Carnegie-Mellon University.
4 * All rights reserved.
5 *
6 * Author: Mark Holland
7 *
8 * Permission to use, copy, modify and distribute this software and
9 * its documentation is hereby granted, provided that both the copyright
10 * notice and this permission notice appear in all copies of the
11 * software, derivative works or modified versions, and any portions
12 * thereof, and that both notices appear in supporting documentation.
13 *
14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
16 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17 *
18 * Carnegie Mellon requests users of this software to return to
19 *
20 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
21 * School of Computer Science
22 * Carnegie Mellon University
23 * Pittsburgh PA 15213-3890
24 *
25 * any improvements or extensions that they make and grant Carnegie the
26 * rights to redistribute these changes.
27 */
28
29 /*
30 * rf_general.h -- some general-use definitions
31 */
32
33 /*#define NOASSERT*/
34
35 #ifndef _RF__RF_GENERAL_H_
36 #define _RF__RF_GENERAL_H_
37
38 /* error reporting and handling */
39
40 #ifdef _KERNEL
41 #include<sys/systm.h> /* printf, sprintf, and friends */
42 #endif
43
44 #define RF_ERRORMSG(s) printf((s))
45 #define RF_ERRORMSG1(s,a) printf((s),(a))
46 #define RF_ERRORMSG2(s,a,b) printf((s),(a),(b))
47 #define RF_ERRORMSG3(s,a,b,c) printf((s),(a),(b),(c))
48 #define RF_ERRORMSG4(s,a,b,c,d) printf((s),(a),(b),(c),(d))
49 #define RF_ERRORMSG5(s,a,b,c,d,e) printf((s),(a),(b),(c),(d),(e))
50 #define perror(x)
51 extern char rf_panicbuf[];
52 #define RF_PANIC() {sprintf(rf_panicbuf,"raidframe error at line %d file %s",__LINE__,__FILE__); panic(rf_panicbuf);}
53
54 #ifdef _KERNEL
55 #ifdef RF_ASSERT
56 #undef RF_ASSERT
57 #endif /* RF_ASSERT */
58 #ifndef NOASSERT
59 #define RF_ASSERT(_x_) { \
60 if (!(_x_)) { \
61 sprintf(rf_panicbuf, \
62 "raidframe error at line %d file %s (failed asserting %s)\n", \
63 __LINE__, __FILE__, #_x_); \
64 panic(rf_panicbuf); \
65 } \
66 }
67 #else /* !NOASSERT */
68 #define RF_ASSERT(x) {/*noop*/}
69 #endif /* !NOASSERT */
70 #else /* _KERNEL */
71 #define RF_ASSERT(x) {/*noop*/}
72 #endif /* _KERNEL */
73
74 /* random stuff */
75 #define RF_MAX(a,b) (((a) > (b)) ? (a) : (b))
76 #define RF_MIN(a,b) (((a) < (b)) ? (a) : (b))
77
78 /* divide-by-zero check */
79 #define RF_DB0_CHECK(a,b) ( ((b)==0) ? 0 : (a)/(b) )
80
81 /* get time of day */
82 #define RF_GETTIME(_t) microtime(&(_t))
83
84 /*
85 * zero memory- not all bzero calls go through here, only
86 * those which in the kernel may have a user address
87 */
88
89 #define RF_BZERO(_bp,_b,_l) bzero(_b,_l) /* XXX This is likely incorrect. GO*/
90
91
92 #define RF_UL(x) ((unsigned long) (x))
93 #define RF_PGMASK RF_UL(NBPG-1)
94 #define RF_BLIP(x) (NBPG - (RF_UL(x) & RF_PGMASK)) /* bytes left in page */
95 #define RF_PAGE_ALIGNED(x) ((RF_UL(x) & RF_PGMASK) == 0)
96
97 #if DKUSAGE > 0
98 #define RF_DKU_END_IO(_unit_,_bp_) { \
99 int s = splbio(); \
100 dku_end_io(DKU_RAIDFRAME_BUS, _unit_, 0, \
101 (((_bp_)->b_flags&(B_READ|B_WRITE) == B_READ) ? \
102 CAM_DIR_IN : CAM_DIR_OUT), \
103 (_bp_)->b_bcount); \
104 splx(s); \
105 }
106 #else /* DKUSAGE > 0 */
107 #define RF_DKU_END_IO(unit) { /* noop */ }
108 #endif /* DKUSAGE > 0 */
109
110 #ifdef __STDC__
111 #define RF_STRING(_str_) #_str_
112 #else /* __STDC__ */
113 #define RF_STRING(_str_) "_str_"
114 #endif /* __STDC__ */
115
116 #endif /* !_RF__RF_GENERAL_H_ */
117