xref: /titanic_50/usr/src/uts/sun4u/ngdr/sys/dr_util.h (revision e07d9cb85217949d497b02d7211de8a197d2f2eb)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SYS_DR_UTIL_H_
27 #define	_SYS_DR_UTIL_H_
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/types.h>
32 #include <sys/memlist.h>
33 #include <sys/sbd_ioctl.h>
34 #include <sys/varargs.h>
35 #include <sys/kmem.h>
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 #define	GETSTRUCT(t, n) \
42 		((t *)kmem_zalloc((size_t)(n) * sizeof (t), KM_SLEEP))
43 #define	FREESTRUCT(p, t, n) \
44 		(kmem_free((caddr_t)(p), sizeof (t) * (size_t)(n)))
45 
46 #define	DRERR_SET_C(epps, eppn)		\
47 	if (*(epps) == NULL)		\
48 		*(epps) = *(eppn);	\
49 	else				\
50 		sbd_err_clear(eppn)
51 
52 #ifdef DEBUG
53 #define	MEMLIST_DUMP(ml) memlist_dump(ml)
54 #else
55 #define	MEMLIST_DUMP(ml)
56 #endif
57 
58 extern sbd_error_t	*sbd_err_new(int e_code, char *fmt, va_list args);
59 extern void		sbd_err_log(sbd_error_t *ep, int ce);
60 extern void		sbd_err_clear(sbd_error_t **ep);
61 extern void		sbd_err_set_c(sbd_error_t **ep, int ce,
62 				int e_code, char *fmt, ...);
63 extern void		sbd_err_set(sbd_error_t **ep, int ce,
64 				int e_code, char *fmt, ...);
65 
66 extern sbd_error_t	*drerr_new(int log, int e_code, char *fmt, ...);
67 extern sbd_error_t	*drerr_new_v(int e_code, char *fmt, va_list args);
68 extern void		drerr_set_c(int log, sbd_error_t **ep,
69 				int e_code, char *fmt, ...);
70 
71 extern void		dr_memlist_delete(struct memlist *mlist);
72 extern void		memlist_dump(struct memlist *mlist);
73 extern int		dr_memlist_intersect(struct memlist *al,
74 				struct memlist *bl);
75 extern void		dr_memlist_coalesce(struct memlist *mlist);
76 extern struct memlist	*dr_memlist_dup(struct memlist *mlist);
77 extern struct memlist	*dr_memlist_add_span(struct memlist *mlist,
78 				uint64_t base, uint64_t len);
79 extern struct memlist	*dr_memlist_del_span(struct memlist *mlist,
80 				uint64_t base, uint64_t len);
81 extern struct memlist	*dr_memlist_cat_span(struct memlist *mlist,
82 				uint64_t base, uint64_t len);
83 
84 /*
85  * These are all utilities internal for DR.  There are
86  * similar functions in common/os which have similar names.
87  * We rename them to make sure there is no name space
88  * conflict.
89  */
90 #define	memlist_delete		dr_memlist_delete
91 #define	memlist_intersect	dr_memlist_intersect
92 #define	memlist_coalesce	dr_memlist_coalesce
93 #define	memlist_dup		dr_memlist_dup
94 #define	memlist_add_span	dr_memlist_add_span
95 #define	memlist_del_span	dr_memlist_del_span
96 #define	memlist_cat_span	dr_memlist_cat_span
97 
98 #ifdef __cplusplus
99 }
100 #endif
101 
102 #endif /* _SYS_DR_UTIL_H_ */
103