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