xref: /onnv-gate/usr/src/uts/sun4u/ngdr/sys/dr_util.h (revision 1772:78cca3d2cc4b)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*1772Sjl139090  * Common Development and Distribution License (the "License").
6*1772Sjl139090  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*1772Sjl139090  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23*1772Sjl139090  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef _SYS_DR_UTIL_H_
270Sstevel@tonic-gate #define	_SYS_DR_UTIL_H_
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #include <sys/types.h>
320Sstevel@tonic-gate #include <sys/memlist.h>
330Sstevel@tonic-gate #include <sys/sbd_ioctl.h>
340Sstevel@tonic-gate #include <sys/varargs.h>
350Sstevel@tonic-gate #include <sys/kmem.h>
360Sstevel@tonic-gate 
370Sstevel@tonic-gate #ifdef	__cplusplus
380Sstevel@tonic-gate extern "C" {
390Sstevel@tonic-gate #endif
400Sstevel@tonic-gate 
410Sstevel@tonic-gate #define	GETSTRUCT(t, n) \
420Sstevel@tonic-gate 		((t *)kmem_zalloc((size_t)(n) * sizeof (t), KM_SLEEP))
430Sstevel@tonic-gate #define	FREESTRUCT(p, t, n) \
440Sstevel@tonic-gate 		(kmem_free((caddr_t)(p), sizeof (t) * (size_t)(n)))
450Sstevel@tonic-gate 
460Sstevel@tonic-gate #define	DRERR_SET_C(epps, eppn)		\
470Sstevel@tonic-gate 	if (*(epps) == NULL)		\
480Sstevel@tonic-gate 		*(epps) = *(eppn);	\
490Sstevel@tonic-gate 	else				\
500Sstevel@tonic-gate 		sbd_err_clear(eppn)
510Sstevel@tonic-gate 
520Sstevel@tonic-gate #ifdef DEBUG
530Sstevel@tonic-gate #define	MEMLIST_DUMP(ml) memlist_dump(ml)
540Sstevel@tonic-gate #else
550Sstevel@tonic-gate #define	MEMLIST_DUMP(ml)
560Sstevel@tonic-gate #endif
570Sstevel@tonic-gate 
580Sstevel@tonic-gate extern sbd_error_t	*sbd_err_new(int e_code, char *fmt, va_list args);
590Sstevel@tonic-gate extern void		sbd_err_log(sbd_error_t *ep, int ce);
600Sstevel@tonic-gate extern void		sbd_err_clear(sbd_error_t **ep);
610Sstevel@tonic-gate extern void		sbd_err_set_c(sbd_error_t **ep, int ce,
620Sstevel@tonic-gate 				int e_code, char *fmt, ...);
630Sstevel@tonic-gate extern void		sbd_err_set(sbd_error_t **ep, int ce,
640Sstevel@tonic-gate 				int e_code, char *fmt, ...);
650Sstevel@tonic-gate 
660Sstevel@tonic-gate extern sbd_error_t	*drerr_new(int log, int e_code, char *fmt, ...);
670Sstevel@tonic-gate extern sbd_error_t	*drerr_new_v(int e_code, char *fmt, va_list args);
680Sstevel@tonic-gate extern void		drerr_set_c(int log, sbd_error_t **ep,
690Sstevel@tonic-gate 				int e_code, char *fmt, ...);
700Sstevel@tonic-gate 
71*1772Sjl139090 extern void		dr_memlist_delete(struct memlist *mlist);
720Sstevel@tonic-gate extern void		memlist_dump(struct memlist *mlist);
73*1772Sjl139090 extern int		dr_memlist_intersect(struct memlist *al,
740Sstevel@tonic-gate 				struct memlist *bl);
75*1772Sjl139090 extern void		dr_memlist_coalesce(struct memlist *mlist);
76*1772Sjl139090 extern struct memlist	*dr_memlist_dup(struct memlist *mlist);
77*1772Sjl139090 extern struct memlist	*dr_memlist_add_span(struct memlist *mlist,
78*1772Sjl139090 				uint64_t base, uint64_t len);
79*1772Sjl139090 extern struct memlist	*dr_memlist_del_span(struct memlist *mlist,
80*1772Sjl139090 				uint64_t base, uint64_t len);
81*1772Sjl139090 extern struct memlist	*dr_memlist_cat_span(struct memlist *mlist,
82*1772Sjl139090 				uint64_t base, uint64_t len);
83*1772Sjl139090 
84*1772Sjl139090 /*
85*1772Sjl139090  * These are all utilities internal for DR.  There are
86*1772Sjl139090  * similar functions in common/os which have similar names.
87*1772Sjl139090  * We rename them to make sure there is no name space
88*1772Sjl139090  * conflict.
89*1772Sjl139090  */
90*1772Sjl139090 #define	memlist_delete		dr_memlist_delete
91*1772Sjl139090 #define	memlist_intersect	dr_memlist_intersect
92*1772Sjl139090 #define	memlist_coalesce	dr_memlist_coalesce
93*1772Sjl139090 #define	memlist_dup		dr_memlist_dup
94*1772Sjl139090 #define	memlist_add_span	dr_memlist_add_span
95*1772Sjl139090 #define	memlist_del_span	dr_memlist_del_span
96*1772Sjl139090 #define	memlist_cat_span	dr_memlist_cat_span
970Sstevel@tonic-gate 
980Sstevel@tonic-gate #ifdef __cplusplus
990Sstevel@tonic-gate }
1000Sstevel@tonic-gate #endif
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate #endif /* _SYS_DR_UTIL_H_ */
103