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