/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* bos72Q src/bos/kernel/sys/dump.h 1.110.2.3                             */
/*                                                                        */
/* Licensed Materials - Property of IBM                                   */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 1988,2019              */
/* All Rights Reserved                                                    */
/*                                                                        */
/* US Government Users Restricted Rights - Use, duplication or            */
/* disclosure restricted by GSA ADP Schedule Contract with IBM Corp.      */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
/* @(#)02	1.110.2.3  src/bos/kernel/sys/dump.h, sysdump, bos72Q, q2019_13A4 2/6/19 00:42:22 */

/*
 * FUNCTIONS:  header file for system dumpfile formats
 */

#ifndef	_H_DUMP
#define	_H_DUMP

#include <sys/types.h>
#include <sys/err_rec.h>
#include <sys/ras.h>

/* Defined to eliminate forward references. */
struct xmem;
struct mbuf;

/* For 64-bit, we need two general "cookies" to	use as segment values -	one
 * to indicate that this is part of the	general	kernel segment mapping,	and
 * another to indicate that this is actually a real address.  For 32-bit, we
 * already have	a flag to indicate real	addresses (D_REAL), but	we need	to
 * identify a dump area	as being part of the general kernel segment mapping,
 * since the kernel heap now spans segments, etc.  For binary compatibility,
 * the 32-bit "general"	segment	value will be 0.
 */
#define	DUMP_GEN_SEGVAL32	((uint)0)
#define	DUMP_GEN_SEGVAL64	((u_longlong_t)-1L)
#define	DUMP_REAL_SEGVAL32	(uint)0x007fffff
#define	DUMP_REAL_SEGVAL64	((u_longlong_t)-2L)
#define DUMP_DUPMEM_SEGVAL      ((u_longlong_t)-3L)
#define DUMP_NONMEM_SEGVAL      ((u_longlong_t)-4L)
#ifdef _KERNEL
#ifdef __64BIT__
#define	DUMP_GEN_SEGVAL		((vmhandle_t)DUMP_GEN_SEGVAL64)
#define	DUMP_REAL_SEGVAL	((vmhandle_t)DUMP_REAL_SEGVAL64)
#else /* !__64BIT__ */
#define	DUMP_GEN_SEGVAL		((vmhandle_t)DUMP_GEN_SEGVAL32)
#define	DUMP_REAL_SEGVAL	((vmhandle_t)DUMP_REAL_SEGVAL32)
#endif
#else /* !_KERNEL */
#define	DUMP_GEN_SEGVAL		DUMP_GEN_SEGVAL32
/* DUMP_REAL_SEGVAL is DUMP_REAL_SEGVAL64 for backward compatibility. */
#define	DUMP_REAL_SEGVAL	DUMP_REAL_SEGVAL64
#endif /* _KERNEL */

/*
 * See if this is a DUMP_GEN_SEGVAL.
 * For 64-bit dumps, the only ones in 5.4 and beyond, the segval may be 0
 * or DUMP_GEN_SEGVAL.
 */
#define DUMP_GEN_SEG(s) (!(s) || ((s) == DUMP_GEN_SEGVAL))

/*
 * XMEM	NOTE:
 * The xmem pointer is only used in the	unlimited dump table.
 * Thus	you must use the unlimited dump	table to dump a	discontiguous
 * multi-segment area.
 * You may dump	a contiguous, multi-segment, area in the 64-bit	environment
 * by simply specifying	the length, d_len, accordingly.
 */

/*
 * Except for the 32-bit dump, taken only by kernels prior to 5.4, this is
 * the data entry name length.
 */
#define CDT_ENTRY_NAMLEN 16		/* not valid for cdt_entry32 */

/*
 * The following structures are	invariant dump entry definitions.
 */
struct cdt_entry64 {				/* component dump table	entry */
	char			d_name[CDT_ENTRY_NAMLEN];/* name of data area */
	unsigned long long	d_len;		/* length of data area to be dumped */
	__ptr64			d_ptr;		/* offset of data area to be dumped */
	unsigned long long	__d_segval;     /* segment value for d_ptr */
#ifdef __64BIT__
	struct xmem *		d_xmemp;	/* see "XMEM NOTE" above. */
#else /* !__64BIT__ */
	unsigned long long	d_xmemp;	/* see "XMEM NOTE" above. */
#endif
};

struct cdt_entry32 {			/* 32-bit component dump table entry */
	char		 d_name[8];	/* name	of data	area to	be dumped */
	__ulong32_t d_len;		/* length of data area to be dumped */
	__cptr32 d_ptr;			/* offset of data area to be dumped */
	union {
#ifdef __64BIT__
		vmhandle32_t _d_segval;	/* segment value for xmem operations */
		__ptr32	d_xmemp;	/* see "XMEM NOTE" above. */
#else /* !__64BIT__ */
		vmhandle_t _d_segval;	/* segment value for xmem operations */
		struct xmem *d_xmemp;	/* see "XMEM NOTE" above. */
#endif /* __64BIT__ */
	} _d;
};

/*
 * cdt_entry_vr	is for dumping real memory by virtual or real address.
 * It is only valid for	dump tables with the DMP_MAGIC_VR magic	number.
 * It is also only valid in a 32-bit dump.
 */
struct cdt_entry_vr {			/* dump	table entry for	v/r addresses*/
	char		 d_name[CDT_ENTRY_NAMLEN]; /* name of data area */
	uint		 d_len;		/* length of data area to be dumped */
	int		 d_addrflags;	/* Address flags. */
	union {
		struct {
		    __cptr32 _d_ptr;	/* data	pointer	*/
#ifdef __64BIT__
		    union {
			vmhandle32_t _d_segval; /* segment id */
			vmid32_t _d_vmid;	/* segment id. */
		    } _ud;
#else /* !__64BIT__ */
		    union {
			vmhandle_t _d_segval; /* segment id	*/
			vmid_t _d_vmid;	/* segment id. */
		    } _ud;
#endif /* __64BIT__ */
		} _d;
		unsigned long long _d_realaddr;	/* real	address	*/
	} _u;
};

#define	d_realaddr _u._d_realaddr
#define	d_segval_v _u._d._ud._d_segval
#define	d_vmid_v _u._d._ud._d_vmid
#define	d_ptr_v	_u._d._d_ptr

/*
 * Flag	definitions for	d_addrflags.
 * All unused flag bits	must be	zero.
 */
#define	D_REAL 0x1		/* The address is a real address.
				 * if off, the address is virtual. */
#define D_VMID 0x2			/* The vmid is passed rather than the vmhandle. */

#ifdef __64BIT__
#define	cdt_entry cdt_entry64
#define d_segval __d_segval
#else /* !__64BIT__ */
#define	cdt_entry cdt_entry32		/* Base	dump table entry. */
#define	d_segval _d._d_segval
#define	d_xmemdp d_segval
#endif /* __64BIT__ */

struct cdt_head	{
	int  _cdt_magic;
	char _cdt_name[16];		/* component dump name */
	int  _cdt_len;			/* length of component dump table */
};

/*
 * We use a different magic number for each dump table.
 * Note	that cdt_entry_vr and associated structures is not
 * valid in 64-bit mode.
 * Note	also that all magic numbers are	available in either
 * mode	so a dump reader can at	least tell if it's a valid
 * dump.
 */
#define	DMP_MAGIC_32 0xEEEEEEEE
#define	DMP_MAGIC_VR 0xEEEEEEEF
#define	DMP_MAGIC_64 0xEEEEEEED
#define	DMP_MAGIC_U32 0xEEEEEEEC
#define	DMP_MAGIC_U64 0xEEEEEEEB
#define	DMP_MAGIC_UD32 0xEEEEEEEA
#define	DMP_MAGIC_UD64 0xEEEEEEE9
#define	DMP_MAGIC_RAS 0xEEEEEEE8	/* cdt_head_ras, in dump only */
#define	DMP_MAGIC_RAS_U 0xEEEEEEE7	/* cdt_head_ras_u, in dump only */
#define	DMP_MAGIC_UL 0xEEEEEEE6
#define DMP_MAGIC_UA 0xEEEEEEE5
#define DMP_MAGIC_N  0xEEEEEEE4
#define DMP_MAGIC_NU 0xEEEEEEE3

#define	DMP_MAGIC_END 0xEEEEEEE0	/* Magic no. at	the end	of the dump. */

#ifdef __64BIT__
#define	DMP_MAGIC DMP_MAGIC_64
#define	DMP_MAGIC_U DMP_MAGIC_U64
#define	DMP_MAGIC_UD DMP_MAGIC_UD64
#else /* !__64BIT__ */
#define	DMP_MAGIC  DMP_MAGIC_32
#define	DMP_MAGIC_U DMP_MAGIC_U32
#define	DMP_MAGIC_UD DMP_MAGIC_UD32
#endif /* __64BIT__ */

struct cdt0 {						/* component dump table	*/
	struct cdt_head	 _cdt_head;		/* minus the variable length table */
};

struct cdt {						/* component dump table	*/
	struct cdt_head	 _cdt_head;
	struct cdt_entry  cdt_entry[1];	/* component dump table	entries	*/
};

/*
 * Component dump table	which may contain real or virtual addresses.
 * This	is only	valid in 32-bit	dumps.
 */
struct cdt_vr {
	struct cdt_head	 _cdt_head;
	struct cdt_entry_vr cdt_entry[1];	/* component dump table	entries	*/
};

#define	cdt_magic _cdt_head._cdt_magic
#define	cdt_name  _cdt_head._cdt_name
#define	cdt_len	  _cdt_head._cdt_len

/*
 * Header for an unlimited size	dump table.
 * cdtu_magic must be DMP_MAGIC_U.
 * cdtu_nentries must be at least 1 when passed	to dump.
 * It will be 0	in the dump, indicating	an unlimited number of entries.
 * This	header is the same size	as cdt_head.
 * Note there are separate magic numbers for 32 or 64 bit dumps.
 */
struct cdt_head_u {
	int  cdtu_magic;		/* Set to DMP_MAGIC_U */
	char cdtu_name[16];		/* component dump name */
	int cdtu_nentries;		/* Number of entries. */
};

/* Unlimited dump table	data entry. */
struct cdt_entry_u {
	int du_magic;			/* Set to DMP_MAGIC_UD */
	char du_name[CDT_ENTRY_NAMLEN];	/* name	of data	area to	be dumped */
	unsigned long long du_len;	/* length of data area to be dumped */
	__ptr64 du_ptr;			/* offset of data area to be dumped */
#ifdef _KERNEL
#ifdef __64BIT__
	vmhandle_t du_segval;		/* segment value for d_ptr */
	struct xmem * du_xmemp;   	/* Must be null if not used. */
#else /* !__64BIT__ (32-bit kernel) */
	uint du_fill1;			/* filler */
	vmhandle_t du_segval;		/* segment value for d_ptr */
	uint du_fill2;			/* filler */
	struct xmem * du_xmemp;   	/* Must be null if not used. */
#endif
#else /* !_KERNEL */
	unsigned long long du_segval;	/* 32/64 segment value for d_ptr */
	unsigned long long du_xmemp;   /* 32/64 xmem ptr. */
#endif
};

/* Unlimited aliased dump table data entry.
 * Note that this will never be in a dump - 
 * it will be converted to a cdt_entry_u
 * during live dump or system dump buffering.
 */
struct cdt_entry_ua {
	int	dua_magic;	/* Set to DMP_MAGIC_UA */
	char	dua_name[CDT_ENTRY_NAMLEN]; /* name of data area to be dumped */
	ulong 	dua_len;	/* length of data area to be dumped */
	__ptr64	dua_ptr;	/* actual location of data to dump */
	__ptr64 dua_alias_ptr;	/* location dua_ptr will represent in dump */
	vmhandle_t	dua_segval;	/* segment value for dua_ptr */
	vmhandle_t	dua_alias_segval; /* seg val for dua_alias_ptr */
	struct xmem 	*dua_xmemp;	/* Must be null if not used */
};
#define ISDMPUA(cp)(((struct cdt_entry_ua *)(cp))->dua_magic == DMP_MAGIC_UA)

/* Test	for a real address in this unlimited table. */
#define	ISADDRREALU32(ceu) ((ceu)->du_segval ==	DUMP_REAL_SEGVAL32)
#define	ISADDRREALU64(ceu) (CDT_U_SEGVAL(ceu)==	DUMP_REAL_SEGVAL64)
#ifdef __64BIT__
#define	ISADDRREALU(ceu) ISADDRREALU64(ceu)
#else /* !__64BIT__ */
#define	ISADDRREALU(ceu) ISADDRREALU32(ceu)
#endif /* __64BIT__ */

/* A cdt_u dump	table must have	at least one entry. */
struct cdt_u {
	struct cdt_head_u cdtu_head;
	struct cdt_entry_u cdtu_entry[1];
};

/* See if this is an unlimited dump table. */
#define	ISDMPU32(cp) (((struct cdt_head_u *)(cp))->cdtu_magic == DMP_MAGIC_U32)
#define	ISDMPU64(cp) \
	((((struct cdt_head_u *)(cp))->cdtu_magic == DMP_MAGIC_U64) || \
	 (((struct cdt_head_ras_u *)(cp))->cdtru_magic == DMP_MAGIC_RAS_U) || \
	 (((struct cdt_nn_head_u *)(cp))->cdtnu_magic == DMP_MAGIC_NU))
#define ISDMPU3264(cp) (ISDMPU32(cp) || ISDMPU64(cp))
/* See if this component data entry is from an unlimited table.	*/
#define	ISCEU32(cep) (((struct cdt_entry_u *)(cep))->du_magic == DMP_MAGIC_UD32)
#define	ISCEU64(cep) (((struct cdt_entry_u *)(cep))->du_magic == DMP_MAGIC_UD64)
#define ISCEU3264(cep) (ISCEU32(cep) || ISCEU64(cep))
#ifdef __64BIT__
#define	ISDMPU(cp) ISDMPU64(cp)
#define ISCEU(cep) ISCEU64(cep)
#else
#define	ISDMPU(cp) ISDMPU32(cp)
#define ISCEU(cep) ISCEU32(cep)
#endif

#define ISDMPNN(cp) ((((struct cdt_nn_head *)(cp))->cdtn_magic == DMP_MAGIC_N) ||\
                    (((struct cdt_nn_head_u *)(cp))->cdtnu_magic == DMP_MAGIC_NU))

/* Validate the	magic number, dump file only. */
#define	VALID_DMP_MAGIC_32_64(n) (((n) == DMP_MAGIC_32)	||\
				  ((n) == DMP_MAGIC_64)	||\
				  ((n) == DMP_MAGIC_VR)	||\
				  ((n) == DMP_MAGIC_U32) ||\
				  ((n) == DMP_MAGIC_U64) ||\
				  ((n) == DMP_MAGIC_RAS) ||\
				  ((n) == DMP_MAGIC_RAS_U))

/* Only valid for use on a dump file. */
#define	CDT_ENTRY_SIZE_32_64(comp_head)	\
	( (((comp_head)->cdt_magic==DMP_MAGIC_64) || \
	   ((comp_head)->cdt_magic==DMP_MAGIC_RAS)) ? \
		sizeof(struct cdt_entry64):	\
		( (((comp_head)->cdt_magic==DMP_MAGIC_U32) || \
		  ((comp_head)->cdt_magic==DMP_MAGIC_U64)|| \
		  ((comp_head)->cdt_magic==DMP_MAGIC_RAS_U)) ? \
			sizeof(struct cdt_entry_u):	\
			( ((ISDMPVR(comp_head))	?	\
				sizeof(struct cdt_entry_vr) :\
				sizeof(struct cdt_entry32))) ) )

/* This	doesn't	include	the unlimited dump table. */
#define	NUM_ENTRIES_32_64(cp) \
	(((cp)->cdt_len	- sizeof(struct	cdt_head)) /\
	CDT_ENTRY_SIZE_32_64(cp) )

/* Address macros */
/* ISADDRREAL32, ADDR_VR32, and ISVMID must be used with a cdt_entry_vr. */
#define	ISADDRREAL32(cde) ((cde)->d_addrflags & D_REAL)
#define	ADDR_VR32(cde) (ISADDRREAL32(cde)) ? (cde)->d_realaddr :\
		      (unsigned	long long)(cde)->d_ptr_v
#define	ISVMID(cde) ((cde)->d_addrflags & D_VMID)

#define	ISADDRREAL64(cde) ((cde)->__d_segval == DUMP_REAL_SEGVAL64)
#define	ADDR_VR64(cde) (cde)->d_ptr

#ifdef __64BIT__
#define ADDR_VR ADDR_VR64
#else
#define ADDR_VR ADDR_VR32
#endif

/* ISADDRREAL works for unlimited dump tables also. */
#ifdef __64BIT__
#define	ISADDRREAL(cde)	\
	(ISCEU(cde)? ISADDRREALU((struct cdt_entry_u *)cde): ISADDRREAL64((struct cdt_entry *)cde))
#else
#define	ISADDRREAL(cde)	\
	(ISCEU(cde)? ISADDRREALU((struct cdt_entry_u *)cde): ISADDRREAL32((struct cdt_entry_vr *)cde))
#endif

#ifdef __64BIT__
#define VALID_DMP_MAGIC(n) (((n) == DMP_MAGIC) || \
                            ((n) == DMP_MAGIC_U) ||\
                            ((n) == DMP_MAGIC_RAS) ||\
                            ((n) == DMP_MAGIC_RAS_U) ||\
			    ((n) == DMP_MAGIC_N) ||\
			    ((n) == DMP_MAGIC_NU))
#else /* !__64BIT__ */
#define	VALID_DMP_MAGIC(n) (((n) == DMP_MAGIC) ||\
			    ((n) == DMP_MAGIC_U) ||\
			    ((n) == DMP_MAGIC_VR))
#endif /* __64BIT__ */

#define	VALID_CDT_MAGIC(cp) VALID_DMP_MAGIC((cp)->cdt_magic)
#define	VALID_CDT_MAGIC_32_64(cp) VALID_DMP_MAGIC_32_64((cp)->cdt_magic)

#define	ISDMPVR(cp) ((cp)->cdt_magic ==	DMP_MAGIC_VR)

/* See if it's a 32 or 64 bit dump. */
#define ISDMP32(cp) (ISDMPU32(cp) || ISDMPVR(cp) || \
	((cp)->cdt_magic == DMP_MAGIC_32))
#define ISDMP64(cp) (ISDMPU64(cp) || ISDMPRAS(cp) || \
	((cp)->cdt_magic == DMP_MAGIC_64))

#define ISDMPRASR(cp) \
	(((struct cdt_head_ras *)(cp))->cdtr_magic == DMP_MAGIC_RAS)
#define ISDMPRASU(cp) \
	(((struct cdt_head_ras_u *)(cp))->cdtru_magic == DMP_MAGIC_RAS_U)
#define ISDMPRAS(cp) (ISDMPRASR((struct cdt_head_ras *)(cp)) || \
		       ISDMPRASU((struct cdt_head_ras_u *)(cp)))

/* cdt_entry size for this table */
#define	CDT_ENTRY_SIZE(cp) (ISDMPVR(cp)	? sizeof(struct	cdt_entry_vr) :\
		(ISDMPU(cp)? sizeof(struct cdt_entry_u): \
			sizeof(struct cdt_entry)))

#define	NUM_ENTRIES_OLD(cp)	\
	(((cp)->cdt_len	- sizeof(struct	cdt_head)) /\
	CDT_ENTRY_SIZE(cp) )

#define CDTR_ENTRIES_LEN(cp) \
	((cp)->cdtr_len- \
	 offsetof(struct cdt_head_ras, cdtr_pathname)- \
	 (cp)->cdtr_pathlen) 
	
#define NUM_ENTRIES_RAS(cp) \
	ISDMPRASU(cp) ? \
	((struct cdt_head_ras_u *)(cp))->cdtru_nentries: \
        CDTR_ENTRIES_LEN((struct cdt_head_ras *)(cp))/ \
        sizeof(struct cdt_entry64)

/*
 * Get the number of entries regardless	of the table type.
 * Note	that for the unlimited dump table this value will not be valid
 * if the data has just	been read, since the cdtu_nentries is 0	in the dump.
 */
#define	NUM_ENTRIES(cp)	\
	((ISDMPRAS(cp))? NUM_ENTRIES_RAS(cp) : \
	(ISDMPNN(cp))? NUM_ENTRIES_NN(cp) : \
	(ISDMPU(cp)? ((struct cdt_head_u *)(cp))->cdtu_nentries: \
	  NUM_ENTRIES_OLD((struct cdt *)(cp))))


/* This is not for an unlimited dump table. */
#define CDT_ENTRY_PTR(p, i) \
	(ISDMPNN(p) ? (&((struct cdt_nn*)(p))->cdtn_entry[i]) : \
		       (&((struct cdt *)(p))->cdt_entry[i]))

#define CDT_U_XMEM(p) \
	((ISDMPUA(p)) ? ((struct cdt_entry_ua*)(p))->dua_xmemp : \
	 (ISCEUL(p)) ? NULL : \
		      ((struct cdt_entry_u*) (p))->du_xmemp)

#define CDT_U_NAME(p) \
	((ISDMPUA(p)) ? ((struct cdt_entry_ua*)(p))->dua_name : \
	 (ISCEUL(p)) ? ((struct cdt_entry_ul*)(p))->dul_name : \
		      ((struct cdt_entry_u*) (p))->du_name)

#define CDT_U_LEN(p) \
	((ISDMPUA(p)) ? ((struct cdt_entry_ua*)(p))->dua_len : \
	 (ISCEUL(p)) ? ((struct cdt_entry_ul*)(p))->dul_len : \
		      ((struct cdt_entry_u*) (p))->du_len)

#define CDT_U_PTR(p) \
	(ISDMPUA(p) ? ((struct cdt_entry_ua*)(p))->dua_ptr : \
		      ((struct cdt_entry_u*) (p))->du_ptr)

#define CDT_U_SEGVAL(p) \
	(ISDMPUA(p) ? ((struct cdt_entry_ua*)(p))->dua_segval : \
		      ((struct cdt_entry_u*) (p))->du_segval)

/*
 * Copy	data from an old format, cdt_entry, to the new cdt_entry_vr
 * structure.  Since there's not much data to move, we use this
 * method rather than using bcopy().
 *
 * This	is only	valid for a cdt_entry32.
 *
 * Input:
 *   oldp = pointer to a struct	cdt_entry32.
 *   newp = pointer to a struct	cdt_entry_vr.
 */
#define	CDT_OLD2NEW(oldp, newp)	{\
		int *iold = (int *)(oldp), *inew = (int	*)(newp);\
		/* d_name[0-3] */ *inew++ = *iold++; \
		/* d_name[4-7] */ *inew++ = *iold++; \
		/* d_name[8-11]	*/ *inew++ = 0;	\
		/* d_name[12-15] */ *inew++ = 0; \
		/* d_len */ *inew++ = *iold++; \
		/* set d_addrflags off */ *inew++ = 0; \
		/* d_ptr */ *inew++ = *iold++; \
		/* d_segval */ *inew = *iold;\
	}

/*
 * these definitions are mainly	for formatting the raw dump data
 */

#ifndef	_UW7_
typedef	unsigned char bitmap_t;
#endif

#define	DMP_MAXSEGS32 1
#define	DMP_MAXSEGS64 4*1024*1024	/* Allow for 10**15 bytes. */
#define	DMP_MAXPAGES32 ((size_t)((ulong)((ulong)DMP_MAXSEGS32 *	256 * 1024 * 1024) / PAGESIZE))
#define	DMP_MAXPAGES64 ((size_t)((u_longlong_t)DMP_MAXSEGS64 * (256*1024*1024/PAGESIZE)))

#ifdef __64BIT__
#define	DMP_MAXSEGS DMP_MAXSEGS64
#define	DMP_MAXPAGES DMP_MAXPAGES64
#else
#define	DMP_MAXSEGS DMP_MAXSEGS32
#define	DMP_MAXPAGES DMP_MAXPAGES32
#endif

/* BITS_BM is the number of bits per bitmap.  DMP_BMBITS is the	max number of
 * bits	that can be written to a dump file per write operation (i.e. the
 * chunksize" of the bitmap).  DMP_BMMASK is used on loop indices to change the
 * index to identify the bit within the	current	chunk, rather than the bit
 * within the whole bitmap.
 */
#define	BITS_BM		(8 * sizeof(bitmap_t))	/* must	be a power of 2	*/
#define	DMP_BMBITS	(512 * BITS_BM)		/* must	be a power of 2	*/
#define	DMP_BMMASK	(512 * BITS_BM - 1)	/* so that this	works	*/

#define	ISBITMAP(bm,bit) \
	( bm[(bit)/BITS_BM] &  (1 << ((bit) % BITS_BM))	)

#define	SETBITMAP(bm,bit) \
	( bm[(bit)/BITS_BM] |= (1 << ((bit) % BITS_BM))	)

#define	BTOP32(addr) (((uint)(addr) & 0x0FFFFFFF) / PAGESIZE)
#define	BTOPR(addr) ((u_longlong_t)(addr) / PAGESIZE)
#define	BTOP_VR(f,addr)	((f) ? BTOPR(addr) : BTOP32(addr))
#define	BTOP64(addr) (((u_longlong_t)(addr) & (SEGSIZE-1)) / PAGESIZE)

#ifdef __64BIT__
#define	BTOP(addr) BTOP64(addr)
#else
#define	BTOP(addr) BTOP32(addr)
#endif /* __64BIT__ */

#define	DMPSEG32(x) ((uint)(x) & 0xF0000000)
#define	DMPSEG64(x) ((u_longlong_t)(x) & 0xFFFFFFFFF0000000LL)
#define	DMPLIM32(ptr,len) \
	(uint)( DMPSEG32((ptr)+(len)-1)	== DMPSEG32(ptr) ? \
		((uint)(ptr)+(len)-1) :	0x0FFFFFFF )
#define	DMPLIMR(ptr,len) (u_longlong_t)((u_longlong_t)(ptr)+(len)-1)
#define	DMPLIM_VR(f,addr,len) \
	((f) ? (u_longlong_t)DMPLIMR(addr,len) : \
	  (u_longlong_t)DMPLIM32(addr,len))
#define	DMPLIM64(ptr,len) (u_longlong_t)((u_longlong_t)(ptr)+(len)-1)

#ifdef __64BIT__
#define	DMPSEG(x) DMPSEG64(x)
#define	DMPLIM(ptr,len)	DMPLIM64(ptr,len)
#else /* !__64BIT__ */
#define	DMPSEG(x) DMPSEG32(x)
#define	DMPLIM(ptr,len)	DMPLIM32(ptr,len)
#endif	/* __64BIT__ */

#define	NPAGES32(ptr,len) \
	( (len)	== 0 ? 0 : BTOP32(DMPLIM32(ptr,len)) - BTOP32(ptr) + 1 )
#define	NPAGES_VR(f,ptr,len) \
	( (len)	== 0 ? 0 : \
	  (uint)(BTOP_VR(f,DMPLIM_VR(f,ptr,len)) - \
	    BTOP_VR(f,ptr) + 1)	)
/* NPAGES_CDE32 must be used with a cdt_entry_vr structure
 * which can represent both real and virtual addresses
 */
#define	NPAGES_CDE32(cep) \
	NPAGES_VR(ISADDRREAL(cep), \
		  ADDR_VR32(cep), (cep)->d_len)
/* A 64-bit dump data area can span segments. */
#define	NPAGES64(ptr,len) \
	((len) == 0 ? 0	: \
	  ((u_longlong_t)(((uint)(ptr) & (PAGESIZE-1)) + (len) + PAGESIZE - 1) / PAGESIZE))
#define	NPAGES_CDE64(cep) \
	NPAGES64((cep)->d_ptr, (cep)->d_len)
#define	NPAGES_U(cep) \
	NPAGES64((cep)->du_ptr,	(cep)->du_len)
#ifdef __64BIT__
#define	NPAGES(ptr,len)	NPAGES64(ptr,len)
#define	NPAGES_CDE(cep)	(ISCEU(cep)? NPAGES_U((struct cdt_entry_u *)cep): \
		NPAGES_CDE64((struct cdt_entry *)cep))
#else /* !__64BIT__ */
#define	NPAGES(ptr,len)	NPAGES32(ptr,len)
/* NPAGES_CDE (32-bit) must be used with either a cdt_entry_vr or cdt_entry_u. */
#define	NPAGES_CDE(cep)	(ISCEU(cep)? NPAGES_U((struct cdt_entry_u *)cep): \
		NPAGES_CDE32((struct cdt_entry_vr *)cep))
#endif /* __64BIT__ */

/*
 * # of	pages:	# of bitmap_t elements (bytes)
 *	0		 0
 *	1		 1
 *	8		 1
 *	9		 2
 *	16		 2
 *	17		 3
 */
#define	BITMAPSIZE64(ptr,len) \
	( (NPAGES64(ptr,len) + BITS_BM - 1) / BITS_BM )
#define	BITMAPSIZE_CDE64(cep) \
	BITMAPSIZE64((cep)->d_ptr, (cep)->d_len)
#define	BITMAPSIZE_U(cep) \
	BITMAPSIZE64((cep)->du_ptr, (cep)->du_len)
#define	BITMAPSIZE32(ptr,len) \
	( (NPAGES32(ptr,len) + BITS_BM - 1) / BITS_BM )
#define	BITMAPSIZE_VR(f,ptr,len) \
	( (NPAGES_VR(f,ptr,len)	+ BITS_BM - 1) / BITS_BM )
/* BITMAPSIZE_CDE32 must be used with a cdt_entry_vr */
#define	BITMAPSIZE_CDE32(cep) \
	BITMAPSIZE_VR(ISADDRREAL(cep), \
	ADDR_VR32(cep),	(cep)->d_len)
#ifdef __64BIT__
#define	BITMAPSIZE(ptr,len) BITMAPSIZE64(ptr,len)
#define	BITMAPSIZE_CDE(cep) (ISCEU(cep)? BITMAPSIZE_U((struct cdt_entry_u *)cep): \
		BITMAPSIZE_CDE64((struct cdt_entry *)cep))
#else /* !__64BIT__ */
#define	BITMAPSIZE(ptr,len) BITMAPSIZE32(ptr,len)
/* BITMAPSIZE_CDE (32-bit) must be used with either a cdt_entry_vr or cdt_entry_u. */
#define	BITMAPSIZE_CDE(cep) (ISCEU(cep)? BITMAPSIZE_U((struct cdt_entry_u *)cep): \
		BITMAPSIZE_CDE32((struct cdt_entry_vr *)cep))
#endif /* __64BIT__ */

#define	DMPD_PRIM	1		/* must	be 1 */
#define	DMPD_SEC	2		/* must	be 2 */
#define	DMPD_AUTO	3
#define	DMPD_PRIM_HALT	4
#define	DMPD_SEC_HALT	5

/*
 * Return codes	from the system	dump.
 */
#define	DMPDO_SUCCESS	  0
#define	DMPDO_DISABLED	 -1
#define	DMPDO_PART	 -2
#define	DMPDO_FAIL	 -3
#define	DMPDO_IOERROR	 -4

/* 
 * Thin server dump
 */
struct dump_control_block {
	unsigned int		eyec;		/* "DPCB" */
	int		 	        version;	/* 1 */
	unsigned long long	block_start; 
	unsigned long long	size;		/* in 512 bytes block */
	char			    pad[512 - 3 * sizeof (unsigned long long)];
};
#define DMPCB_EYEC      0x44504342   /* "DPCB" */
struct dumpdd {
 unsigned long long     comp_size; /* compressed dump size */
    unsigned long long  real_size;
    time32_t            timestamp;
    int                 status;
    int                 legacy;
};

#ifdef _KERNEL
#include <sys/mstsave.h>

#ifdef __cplusplus
extern "C" {
#endif

/*
 * These defines stand for the reason that the system
 * is dumping.	It was automatic, a key	sequence was
 * entered, or the reset button	was hit.
 */
#define	AUTO_DUMP	0
#define	KEYSEQ_DUMP 1
#define	RESET_DUMP  2

struct dump_read {
	struct mbuf *dump_bufread;
	int    wait_time;
};

/*
 * Used	by dump	I/O routines to	report status.
 */
struct dumpio_stat {
	unsigned int version;			/* Version of this structure */
	unsigned int status;			/* returned status value */
};
#define	DUMPIO_STAT_V1 1

/* dmp_add and dmp_ dmp_del take a function pointer. */
#ifdef __64BIT_KERNEL
typedef	struct cdt *((*__CDTFUNC)(int, void *));
#else
typedef	struct cdt *((*__CDTFUNC)());
#endif

/* Note: the dmp_add_buffer service allows dump	routines to share
 * a temporary buffer for staging large	quantities of data that	are
 * not directly	"dumpable".  They must specify the size	of buffer
 * they	need via the bufsize parameter.	 These routines	will be
 * invoked with	a pointer to the buffer	that they can use.  Note that
 * these routines must be capable of being called twice	with the "1"
 * parameter, and must be able to copy the data	twice, so that they can
 * be invoked a	second time in case of a dump device failure and a
 * failover to the secondary device.
 *
 * It is now recommended that dmp_ctl()	be used	instead	of dmp_add(),
 * dmp_add_buffer() and	dmp_del().
 */

#if defined(__64BIT_KERNEL) || defined(__FULL_PROTO)

extern void dmp_prinit(int dmp_proto, void *proto_info);
extern int dmp_add_buffer(__CDTFUNC func, size_t bufsize);
extern int dmp_add(__CDTFUNC func);
extern int dmp_del(__CDTFUNC func);
extern void dmp_errlog(kerrno_t kerrno, dev_t dev, long dword);
extern void dmp_trchk0(ulong_t);
extern void dmp_trchk1(ulong_t, ulong_t);
extern void dmp_trchk2(ulong_t, ulong_t, ulong_t);
extern void dmp_trchk3(ulong_t, ulong_t, ulong_t, ulong_t);
extern void dmp_trchk4(ulong_t, ulong_t, ulong_t, ulong_t, ulong_t);
extern void dmp_trchk5(ulong_t, ulong_t, ulong_t, ulong_t, ulong_t, ulong_t);
#define DMP_TRCHK0(hkwd)
#define DMP_TRCHK1(hkwd, d1)
#define DMP_TRCHK2(hkwd, d1, d2)
#define DMP_TRCHK3(hkwd, d1, d2, d3)
#define DMP_TRCHK4(hkwd, d1, d2, d3, d4)
#define DMP_TRCHK5(hkwd,d1, d2, d3, d4, d5)
#endif

/* Dump Routine failures data. */
struct __rtnf {
	ulong rv;				/* error code. */
	ulong vaddr;			/* address. */
	vmhandle_t handle;		/* handle */
};

/* dmp_ctl invocation. */
typedef	void *((*__CDTFUNCENH)(int op, void *buf));

#define EXNAMESIZE 128

/* Record dump routine failures	here. */
#define	DMPF_MAX 4
#define MSTPRESENT -2
#define NOMST -3
struct dmpf {
	uint id;		/* Number of entries */
	struct dfail {
	    __CDTFUNCENH f;
	    struct __rtnf rtnf;
	    ulong mst_flag;
	    struct  kmstsave mst;
	    char ldname[EXNAMESIZE];
	} dfail[DMPF_MAX];
};

#define dmpfd_rv rtnf.rv
#define dmpfd_vaddr rtnf.vaddr
#define dmpfd_handle rtnf.handle

struct dmpctl_data {
	int dmpc_magic;			/* magic number	*/
	int dmpc_flags;			/* dump	routine	flags. */
	__CDTFUNCENH dmpc_func;
	union {
		u_longlong_t bsize;	/* Global buffer size requested. */
		struct __rtnf rtnf;
	} dmpc_u;
};
#define	DMPC_MAGIC1 0xdcdcdc01
#define	DMPC_MAGIC DMPC_MAGIC1
#define	dmpc_bsize dmpc_u.bsize
#define dmpcf_rv dmpc_u.rtnf.rv
#define dmpcf_vaddr dmpc_u.rtnf.vaddr
#define dmpcf_handle dmpc_u.rtnf.handle

#ifdef _NO_PROTO
extern int dmp_ctl();
#else
extern int dmp_ctl(int op, struct dmpctl_data *parmp);
#endif

/* dmp_ctl operations. */
#define	DMPCTL_ADD 1
#define	DMPCTL_DEL 2
#define DMPCTL_RTNFAILURE 3		/* dump routine failure */
/*
 * dmpc_flag values.
 * The CALL_ON_RESTART value is	set if the routine should be called each time
 * the dump is restarted.  It must be set if the GLOBAL_BUFFER flag is set.
 * It must also	be set if the routine returns an unlimited dump	table.
 * The GLOBAL_BUFFER flag is set if the	routine	uses global buffer space.
 * The dmpc_bsize value	must also be set to the	number of bytes	being
 * requested.  This value may not exceed DMPBUF_MAX.
 */
#define	DMPFUNC_CALL_ON_RESTART	0x1
#define	DMPFUNC_GLOBAL_BUFFER 0x2
#define DMPFUNC_LEGACY_CRITICAL 0x4
#define DMPFUNC_RETRY 0x8
#define DMPFUNC_SERIALIO 0x10
#define DMPFUNC_CDT_SKIP 0X20

/* Operations passed to	dump routines. */
#define	DMPRTN_START 1
#define	DMPRTN_DONE 2
#define	DMPRTN_AGAIN 3
#define	DMPRTN_ESTIMATE	4
#define DMPRTN_RETRY 5

/* Max retries for callback retry on error.         */
/* ie, original failure + two retries per callback. */
#define MAX_CBR 3

/*
 * Dump	size estimate type.
 * A dump routine, added with dmp_ctl(), must return a pointer to
 * dmp_sizeest_t when requested	to provide an estimate.
 */
typedef	unsigned long long dmp_sizeest_t;

/* Dump	device buffer size query structure. */
struct dmp_query {
	size_t min_tsize;
	size_t max_tsize;
};


/* minidump error log entry types */
struct minidump_log {
        struct err_rec0 erec;
        char minidump_buf[ERR_REC_MAX];
};

struct minidump_err_log {
        struct err_rec0 erec;
        int error_code;
};

struct minidump_info_log {
        struct err_rec0 erec;
        int op_code;
};


#ifdef _KERNSYS
extern int dmp_do(int dmptype, int reason);
extern int dmp_do_excp(int dmptype, int reason, int excp_code);
#endif /* _KERNSYS */

#ifdef __cplusplus
}
#endif

#endif /* _KERNEL */

#ifdef __cplusplus
extern "C" {
#endif

/* Dump levels for system and live dump */
enum {
    CD_LEVEL_0,
    CD_LEVEL_1,
    CD_LEVEL_2,
    CD_LEVEL_3,
    CD_LEVEL_4,
    CD_LEVEL_5,
    CD_LEVEL_6,
    CD_LEVEL_7,
    CD_LEVEL_8,
    CD_LEVEL_9
};
#define CD_LVL_MINIMAL	CD_LEVEL_1
#define CD_LVL_NORMAL	CD_LEVEL_3
#define CD_LVL_DETAIL	CD_LEVEL_7
#define CD_LVL_DEFAULT	CD_LVL_NORMAL

#define CDTR_VERS       0
#define CDTRU_VERS      0

/*
 * Component dump table headers containing the component full path name.
 * Note that these headers can be processed by 32 and 64-bit applications.
 */
struct cdt_head_ras_h {
	int		cdtrh_magic;	/* set to DMP_MAGIC_RAS */
	int		cdtrh_vers;	/* set to CDTR_VERS */
	int		cdtrh_len;	/* length of component dump table */
	int		cdtrh_pathlen;	/* path name length */
};

/* flexible declaration */
struct cdt_head_ras {
	struct cdt_head_ras_h cdtr_h;
	char		          cdtr_pathname[];/* variable length path name */
};

#define cdtr_magic   cdtr_h.cdtrh_magic
#define cdtr_vers    cdtr_h.cdtrh_vers
#define cdtr_len     cdtr_h.cdtrh_len
#define cdtr_pathlen cdtr_h.cdtrh_pathlen

/* Unlimited table */
struct cdt_head_ras_uh {
	int		cdtruh_magic;	/* set to DMP_MAGIC_RAS_U */
	int		cdtruh_vers;	/* set to CDTRU_VERS */
	int		cdtruh_nentries;	/* Number of entries. */
	int		cdtruh_pathlen;	/* path name length */
};

struct cdt_head_ras_u {
	struct cdt_head_ras_uh cdtru_h;
	char		cdtru_pathname[]; /* variable length path name */
};

#define cdtru_magic      cdtru_h.cdtruh_magic
#define cdtru_vers       cdtru_h.cdtruh_vers
#define cdtru_nentries   cdtru_h.cdtruh_nentries
#define cdtru_pathlen    cdtru_h.cdtruh_pathlen


#define CDTR_VERS1            0x0

#define XMEMP_REAL -1

#ifdef __64BIT_KERNEL
/*
 * This is used for the system dump estimate.
 * It applies to components registered via the component infrastructure.
 */
typedef struct sysdump_estimate {
	short                   se_eyec;
	short                   se_vers;
	dmp_lvl_t               se_lvl; /* The level at which to estimate */
        dmp_sizeest_t   se_value;           /* estimate set by callback */
} sysdump_estimate_t;

#define EYEC_SE               __EYEC4('s','e','s','t') /* sest */
#define SE_VERS1      0               /* version */


#define DMP_WKSZ 256                    /* dump work area size */

/*
 * This structure is passed to a callback when it is to dump its data for a
 * live dump, RASCD_SDMP_START.
 */

typedef struct sdmp_start {
       eye_catch4b_t sdmpst_eyec;
       int           sdmpst_vers;        /* version */
       int           sdmpst_flags;       /* type flags */
       dmp_lvl_t     sdmpst_lvl;         /* level at which to dump */
       size_t        sdmpst_plen;        /* parameters length */
       char          *sdmpst_parms;      /* passed parameters */
       void          *sdmpst_buffer;     /* staging buffer if requested */
       size_t	     sdmpst_bufsz;	 /* size of staging buffer */
       void          *sdmpst_table;      /* dump table ptr set by callback */
       char          sdmpst_wk[DMP_WKSZ]; /* Work area */
       eye_catch4b_t sdmpst_eyec2; /* for integrity check */
} sdmp_start_t;

#define EYEC_SDMPST               __EYEC4('s','d','s','t') /* sdst */
#define SDMPST_VERS1      0               /* version */
#define INVALID_SDMPST_PTR INVALID_PTR((int)EYEC_SDMPST)
#endif

/*
 * cdt headers for use by components registered in the component
 * infrastructure.
 */
struct cdt_nn_head	{
	int  cdtn_magic;
	int  cdtn_len;			/* length of component dump table */
};

struct cdt_nn	{
	struct cdt_nn_head	_cdt_nn_head;
	struct cdt_entry 	cdtn_entry[1];
};

/* Unlimited dump table header. */
struct cdt_nn_head_u {
	int  cdtnu_magic;		/* Set to DMP_MAGIC_NU */
	int cdtnu_nentries;		/* Number of entries. */
};

struct cdt_nn_u	{
	struct cdt_nn_head_u	_cdt_nn_head_u;
	struct cdt_entry_u 	cdtnu_entry[1];
};

#define ISDMPNNU(cp)(((struct cdt_nn_head_u *)(cp))->cdtnu_magic == DMP_MAGIC_NU)
#define NUM_ENTRIES_NN(cp)     \
        (ISDMPNNU(cp) ? \
		((struct cdt_nn_u*)(cp))->_cdt_nn_head_u.cdtnu_nentries: \
	        (((struct cdt_nn*)(cp))->_cdt_nn_head.cdtn_len - \
			sizeof(struct cdt_nn_head)) / sizeof(struct cdt_entry))

/*
 * Unlimited dump table entry to dump a discontiguous list of elements.
 * This may be used in both the system and live dump.
 * dul_entry is used to specify the elements' addresses.
 */
struct dul_entry {
#ifdef __64BIT__
	vmhandle_t dle_vmhandle;		/* vmid */
#else
	u_longlong_t dle_vmhandle;		/* vmid */
#endif
	__ptr64 dle_ptr;			/* offset/address */
};

/* Return TRUE if dul_entry is the end indicator. */
#define DMP_DULENTRY_KEY 0x444d50554cULL
#define	DMP_DULENTRY_FINAL(_d) \
	((((_d)->dle_vmhandle == INVALID_PTR64(DMP_DULENTRY_KEY)) && \
	  (((unsigned long long)(_d)->dle_ptr) == INVALID_PTR64(DMP_DULENTRY_KEY)))?1 :0)

struct cdt_entry_ul {
	int dul_magic;				/* eyecatcher */
	char dul_name[CDT_ENTRY_NAMLEN]; /* name applied to all entries */
	int dul_nentries;			/* # entries */
	unsigned long long dul_len;	/* length of all entries */
	struct dul_entry dul_entry[1]; /* element addresses */
 /* element addresses */
};
#define ISCEUL(cp) (((struct cdt_entry_ul *)(cp))->dul_magic == DMP_MAGIC_UL)
#define ISADDRREALUL(cep,i) \
	(((struct cdt_entry_ul*)cep)->dul_entry[i].dle_vmhandle == \
	 DUMP_REAL_SEGVAL64)
#define DMP_DUL_SIZE(n) (offsetof(struct cdt_entry_ul, dul_entry) + \
		      (n)*sizeof(struct dul_entry))

#if (defined _RAS_INTERNAL) || (defined _KERNEL)
/* providing Components and parameters */
/*
 * dmp_compspec flags 
 * If changing or adding any of these flags, update DCF_MASK and __dcf_descr.
 */
#define DCF_MASK 0xFC00000001F1F3FFLL
/* If none of these are set, the component is dumped at its current level. */
#define DCF_LEVEL_MASK	0x3ffLL
#define DCF_LEVEL_SHIFT	0
#define DCF_LEVEL0	0x1LL
#define DCF_LEVEL1	0x2LL
#define DCF_LEVEL2	0x4LL
#define DCF_LEVEL3	0x8LL
#define DCF_LEVEL4	0x10LL
#define DCF_LEVEL5	0x20LL
#define DCF_LEVEL6	0x40LL
#define DCF_LEVEL7	0x80LL
#define DCF_LEVEL8	0x100LL
#define DCF_LEVEL9	0x200LL
#define DCF_MINIMAL	DCF_LEVEL1
#define DCF_NORMAL	DCF_LEVEL3
#define DCF_DETAIL	DCF_LEVEL7
/* Component type flags */
#define DCF_COMPTYPE_MASK 0x1f000LL
#define DCF_PSEUDO	0x1000LL	/* pseudo-component */
#define DCF_BYPNAME	0x2000LL	/* spec by name */
#define DCF_BYLNAME	0x4000LL	/* spec by logical alias */
#define DCF_BYTYPE	0x8000LL	/* spec by type/subtype */
#define DCF_BYCB	0x10000LL	/* spec by ras_block_t */
/* misc. flags */
#define DCF_FAILING	0x100000LL	/* failing component */
#define DCF_FIRST	0x200000LL	/* dump first */
#define DCF_KEYWORD	0x400000LL	/* keyword parameters given */
#define DCF_LONG	0x800000LL	/* Pseudo-comp parms, 2 longs */
#define DCF_UNIQUE	0x1000000LL	/* pseudo-comp must be unique */
/* These flags are for internal use only. */
#define DCF_MOREDATA 	0x0400000000000000LL /* Component set LDPF_MOREDATA */
#define DCF_NEEDSPUT 	0x0800000000000000LL /* Component needs rasp_put */
#define DCF_PREPARED 	0x1000000000000000LL /* Component got a prepare cmd */
#define DCF_START_BAD 	0x2000000000000000LL /* Component wrecked start struct*/
#define DCF_PREPARE_BAD 0x4000000000000000LL /* Component wrecked prep struct */
#define DCF_FINISH	0x8000000000000000LL /* RASCD_LDMP_FINISH needed */

/*
 * dmp_extid_t is returned by dmp_compspec to be used with dmp_compext when
 * providing additional component parameters.
 */
typedef long dmp_extid_t;
extern kerrno_t dmp_compspec(long flags, long comp, void *anchor,
  dmp_extid_t *extid, ...);
extern kerrno_t dmp_compext(dmp_extid_t extid, ...);

/* dmp_context: function to dump system context */
extern kerrno_t
dmp_context(
	long flags,     /* See the DCF_ flags in dump.h */
	void *anchor,   /* associated data (ldmp_prepare_t* or ldmp_parms_t*) */
	char *name,     /* unused here */
	long ctx_type,  /* See the DMP_CTX_* flags in dump.h */
	long p2);       /* Parameter dependent on ctx_type */

/* dmp_context flags */
#define DMP_CTX_MASK	0x7F	/* Change this if adding a new DMP_CTX_* */
#define DMP_CTX_CUR	0x1	/* Dump the current context */
#define DMP_CTX_PREV	0x2	/* Dump the previous context */
#define DMP_CTX_SPEC	0x4	/* Dump the specified context */
#define DMP_CTX_RWA	0x8	/* Dump the context for a recovery work area */
#define DMP_CTX_BID	0x10	/* Dump the context for a CPU bind ID */
#define DMP_CTX_LCPUID	0x20	/* Dump the context for a CPU logical ID */
#define DMP_CTX_TID	0x40	/* Dump the context for a thread */

/* Flag that indicates to the dump the MST chain.
 * Valid only with DMP_CTX_CUR/PREV/SPEC/RWA/BID/LCPUID.
 * For instance, if DMP_CTX_CUR|DMP_CTX_CHAIN is specified, detailed information
 * on the current context will be dumped along with minimal (register state,
 * stack trace) of all other MSTs.
 */
#define DMP_CTX_CHAIN		0x8000000000000000ll
#define DMP_CTX_CHAIN_MASK	(DMP_CTX_CHAIN | DMP_CTX_CUR |\
				 DMP_CTX_PREV | DMP_CTX_SPEC | DMP_CTX_RWA |\
				 DMP_CTX_BID | DMP_CTX_LCPUID)

/* Dump minimal context info (register state, stack trace).
 * NOTE: Without another full fledged context dump, any
 * contexts dumped with the following flag will result in
 * dumps that are not fully usable with KDB.
 */
#define DMP_CTX_LITE		0x4000000000000000ll

/* dmp_mtrc: function to dump a system's memory trace (LMT) buffers */
extern kerrno_t
dmp_mtrc(
	long flags,     /* See the DCF_ flags in dump.h */
	void *anchor,   /* associated data (ldmp_prepare_t* or ldmp_parms_t*) */
	char *name,     /* unneeded here */
	size_t com_sz, 	/* amount of the LMT common buffer to dump */
	size_t rar_sz); /* amount of the LMT rare buffer to dump */
	
/* dmp_ct: function to dump a RAS component's CT buffer */
kerrno_t
extern dmp_ct(
	long flags,     /* See the DCF_ flags in dump.h */
	void *anchor,   /* associated data (ldmp_prepare_t* or ldmp_parms_t*) */
	char *name,     /* unneeded here */
	ras_block_t rasb,  	/* Component's ras_block_t */
	size_t sz);       /* Amount of CT buffer to dump */
	
/* dmp_pid: function to dump a PID's information */
extern kerrno_t
dmp_pid(
	long flags,     /* See the DCF_ flags in dump.h */
	void *anchor,   /* associated data (ldmp_prepare_t* or ldmp_parms_t*) */
	char *name,     
	pid_t pid, 	/* pid to dump */
	void *unused); 	
	
/* dmp_tid: function to dump a TID's information */
extern kerrno_t
dmp_tid(
	long flags,     /* See the DCF_ flags in dump.h */
	void *anchor,   /* associated data (ldmp_prepare_t* or ldmp_parms_t*) */
	char *name,     
	tid_t tid, 	/* tid to dump */
	void *unused); 	
	
/* dmp_errbuf: function to dump error logging data */
extern kerrno_t
dmp_errbuf(
	long flags,     /* See the DCF_ flags in dump.h */
	void *anchor,   /* associated data (ldmp_prepare_t* or ldmp_parms_t*) */
	char *name,     
	ulong erridx,	/* NULL for global errlg, or wpar number */
	long p2);	/* Unused */
	
/* dmp_eaddr: function to dump a region of memory */
extern kerrno_t
dmp_eaddr(
	long flags,     /* See the DCF_ flags in dump.h */
	void *anchor,   /* associated data (ldmp_prepare_t* or ldmp_parms_t*) */
	char *name,     
	long p1,	/* Start address */
	long p2);	/* Size in bytes */
	
/* dmp_systrace: function to dump system trace data */
extern kerrno_t
dmp_systrace(
	long flags,     /* See the DCF_ flags in dump.h */
	void *anchor,   /* associated data (ldmp_prepare_t* or ldmp_parms_t*) */
	char *name,     /* unused here */
	long sz,	/* amount of trace data to dump */
	long p2);       /* unused */

/* dmp_kernext: function to allow symbol resolution for a kernel extension */
extern kerrno_t
dmp_kernext(
	void *anchor,   /* associated data (ldmp_prepare_t* or ldmp_parms_t*) */
	void *ptr);	/* ptr to txt or data addr in the kernel extension */

/* Given the head of an unlimited dump table, return the ith entry in the table.
 * This abstracts the different types of unlimited entries
 * (regular, alias, list).
 */
extern void * dmp_cdt_entry_u_ptr(void *p, int i, int ck);

/* 
 * dump kerrnos
 */
#define LDMP_SUBBLK     0x800           /* sub-block for livedump.h */
#define DMP_SUBBLK_I    0xc00           /* sub-block for dump internal */

					/* 0x96220001/0xEEEE000096220000 */
#define	EINVAL_RAS_DMP_COMPSPEC_ANCHOR KERROR(EINVAL, sysdump_BLOCK_00, 0)
#define	EFAULT_RAS_DMP_COMPSPEC_ANCHOR KERROR(EFAULT, sysdump_BLOCK_00, 1)
#define	EINVAL_RAS_DMP_COMPSPEC_NOADD KERROR(EINVAL, sysdump_BLOCK_00, 2)
#define	EINVAL_RAS_DMP_COMPSPEC_FLAGS KERROR(EINVAL, sysdump_BLOCK_00, 3)
#define	EINVAL_RAS_DMP_COMPSPEC_FAILING KERROR(EINVAL, sysdump_BLOCK_00, 4)
#define	EINVAL_RAS_DMP_COMPSPEC_COMP KERROR(EINVAL, sysdump_BLOCK_00, 5)
#define	EFAULT_RAS_DMP_COMPSPEC_EXTID KERROR(EFAULT, sysdump_BLOCK_00, 6)
#define	EINVAL_RAS_DMP_COMPSPEC_NOTAWARE KERROR(EINVAL, sysdump_BLOCK_00, 7)
#define	ENOMEM_RAS_DMP_COMPSPEC KERROR(ENOMEM, sysdump_BLOCK_00, 8)
#define	EFAULT_RAS_DMP_COMPSPEC_PARMS KERROR(EFAULT, sysdump_BLOCK_00, 9)
#define	EINVAL_RAS_DMP_COMPEXT_EXTID KERROR(EINVAL, sysdump_BLOCK_00, 10)
#define	EFAULT_RAS_DMP_COMPEXT_EXTID KERROR(EFAULT, sysdump_BLOCK_00, 11)
#define	EFAULT_RAS_DMP_COMPEXT_PARMS KERROR(EFAULT, sysdump_BLOCK_00, 12)
#define	ENOMEM_RAS_DMP_COMPEXT KERROR(ENOMEM, sysdump_BLOCK_00, 13)
#define	EFAULT_RAS_DMP_CONTEXT KERROR(EFAULT, sysdump_BLOCK_00, 14)
#define	EINVAL_RAS_DMP_CONTEXT KERROR(EINVAL, sysdump_BLOCK_00, 15)
#define	ENOENT_RAS_DMP_CONTEXT KERROR(ENOENT, sysdump_BLOCK_00, 16)
#define	EINVAL_RAS_DMP_MTRC KERROR(EINVAL, sysdump_BLOCK_00, 17)
#define	ENOENT_RAS_DMP_MTRC KERROR(ENOENT, sysdump_BLOCK_00, 18)
#define EINVAL_RAS_DMP_CONTEXT_CTX_PREV KERROR(EINVAL, sysdump_BLOCK_00, 19)
#define EINVAL_RAS_DMP_EADDR KERROR(EINVAL, sysdump_BLOCK_00, 20)
#define EFAULT_RAS_DMP_EADDR KERROR(EFAULT, sysdump_BLOCK_00, 21)
#define EINVAL_RAS_DMP_EADDR_CB KERROR(EINVAL, sysdump_BLOCK_00, 22)
#define EBUSY_RAS_DMP_COMPEXT KERROR(EBUSY, sysdump_BLOCK_00, 23)
#define EINVAL_RAS_DMP_MTRC_CB KERROR(EINVAL, sysdump_BLOCK_00, 24)
#define EINVAL_RAS_DMP_CONTEXT_CB_PARM KERROR(EINVAL, sysdump_BLOCK_00, 25)
#define EINVAL_RAS_DMP_CONTEXT_CB_BADCMD KERROR(EINVAL, sysdump_BLOCK_00, 26)
#define EINVAL_RAS_DMP_TID KERROR(EINVAL, sysdump_BLOCK_00, 27)
#define EINVAL_RAS_DMP_PID KERROR(EINVAL, sysdump_BLOCK_00, 28)
#define EINVAL_RAS_DMP_TID_CB KERROR(EINVAL, sysdump_BLOCK_00, 29)
#define ENOENT_RAS_DMP_TID_CB KERROR(ENOENT, sysdump_BLOCK_00, 30)
#define EINVAL_RAS_DMP_PID_CB KERROR(EINVAL, sysdump_BLOCK_00, 31)
#define ENOENT_RAS_DMP_PID_CB KERROR(ENOENT, sysdump_BLOCK_00, 32)
#define EINVAL_RAS_DMP_CONTEXT_BAD_PVT KERROR(EINVAL, sysdump_BLOCK_00, 33)
#define ENOENT_RAS_DMP_CONTEXT_CTX_NOTFOUND KERROR(ENOENT, sysdump_BLOCK_00, 34)
#define EINVAL_RAS_DMP_CONTEXT_UNSER_TID KERROR(EINVAL, sysdump_BLOCK_00, 35)
#define EINVAL_RAS_DMP_CONTEXT_XMEM_CTX KERROR(EINVAL, sysdump_BLOCK_00, 36)
#define ENOENT_RAS_DMP_CONTEXT_CPU_GONE KERROR(ENOENT, sysdump_BLOCK_00, 37)
#define EINVAL_RAS_DMP_CT KERROR(EINVAL, sysdump_BLOCK_00, 38)
#define ENOMEM_RAS_DMP_CT KERROR(ENOMEM, sysdump_BLOCK_00, 39)
#define EINVAL_RAS_DMP_CT_GETPATH KERROR(EINVAL, sysdump_BLOCK_00, 40)
#define EINVAL_RAS_DMP_CT_LOOKUP KERROR(EINVAL, sysdump_BLOCK_00, 41)
#define ENOTSUP_RAS_DMP_CT KERROR(ENOTSUP, sysdump_BLOCK_00, 42)
#define EINVAL_RAS_DMP_CT_CB KERROR(EINVAL, sysdump_BLOCK_00, 43)
#define EINVAL_RAS_DMP_ERRBUF KERROR(EINVAL, sysdump_BLOCK_00, 44)
#define EINVAL_RAS_DMP_ERRBUF_CB KERROR(EINVAL, sysdump_BLOCK_00, 45)
#define ECHRNG_RAS_DMP_ERRBUF KERROR(ECHRNG, sysdump_BLOCK_00, 46)
#define EINVAL_RAS_DMP_SYSTRACE KERROR(EINVAL, sysdump_BLOCK_00, 47)
#define ENOENT_RAS_DMP_SYSTRACE KERROR(ENOENT, sysdump_BLOCK_00, 48)
#define EINVAL_RAS_DMP_SYSTRACE_CB KERROR(EINVAL, sysdump_BLOCK_00, 48)
#define ENOENT_RAS_DMP_SYSTRACE_CB_PREP KERROR(ENOENT, sysdump_BLOCK_00, 49)
#define ENOENT_RAS_DMP_SYSTRACE_CB_START KERROR(ENOENT, sysdump_BLOCK_00, 50)
#define EFAULT_RAS_DMP_SYSTRACE_CB_PREP KERROR(EFAULT, sysdump_BLOCK_00, 51)
#define EINVAL_RAS_DMP_KERNEXT KERROR(EINVAL, sysdump_BLOCK_00, 52)
#define EINVAL_RAS_DMP_KERNEXT_CB KERROR(EINVAL, sysdump_BLOCK_00, 53)
#define EBUSY_RAS_DMP_KERNEXT_LA KERROR(EBUSY, sysdump_BLOCK_00, 54)
#define ENOMEM_RAS_DMP_KERNEXT_LA KERROR(ENOMEM, sysdump_BLOCK_00, 55)
#define EINVAL_RAS_DMP_KERNEXT_LA KERROR(EINVAL, sysdump_BLOCK_00, 56)
#define	EINVAL_RAS_DMP_CTX_CHAIN_FLAGS KERROR(EINVAL, sysdump_BLOCK_00, 57)
#define	EINVAL_RAS_DMP_CTX_CHAIN_TYPE KERROR(EINVAL, sysdump_BLOCK_00, 58)
#define	EINVAL_RAS_DMP_CTX_CHAIN_BADCPU KERROR(EINVAL, sysdump_BLOCK_00, 59)
#define	EFAULT_RAS_DMP_CT KERROR(EFAULT, sysdump_BLOCK_00, 60)
#define ENOSPC_RAS_DMP_EADDR KERROR(ENOSPC, sysdump_BLOCK_00, 61)
#define EFAULT_RAS_DMP_SYSTRACE_CB_START KERROR(EFAULT, sysdump_BLOCK_00, 62)
#define ENOMEM_RAS_DMP_DMPCTLADD KERROR(ENOMEM, sysdump_BLOCK_00, 63)
#define EEXIST_RAS_DMP_DMPCTLADD KERROR(EEXIST, sysdump_BLOCK_00, 64)
#define EINVAL_RAS_DMP_DMPCTLADD_PARMS KERROR(EINVAL, sysdump_BLOCK_00, 65)
#define EINVAL_RAS_DMP_DMPCTLADD_BUFSIZE KERROR(EINVAL, sysdump_BLOCK_00, 66)
#define EINVAL_RAS_DMP_DMPCTLADD_NOPARMS KERROR(EINVAL, sysdump_BLOCK_00, 67)

#define ENOSPC_XDMP_ERROR KERROR(ENOSPC, sysdump_BLOCK_00, 68)
#define DISABLED_XDMP_ERROR KERROR(EINVAL, sysdump_BLOCK_00, 69)
#define FAIL_XDMP_ERROR KERROR(EINVAL, sysdump_BLOCK_00, 70)
#define UNKN_XDMP_ERROR KERROR(EINVAL, sysdump_BLOCK_00, 71)
#define ENOMEM_RAS_DMP_CONTEXT_CSA KERROR(ENOMEM, sysdump_BLOCK_00, 72)
#define DUMPQUERY_SDMP_DEVERROR KERROR(ENODEV, sysdump_BLOCK_00, 74)
#define DUMPSTART_SDMP_DEVERROR KERROR(EINVAL, sysdump_BLOCK_00, 76)
#define DUMPTERM_SDMP_DEVERROR KERROR(EIO, sysdump_BLOCK_00, 82)
#define DUMPSTARTBUF_SDMP_DEVERROR KERROR(ENOMEM, sysdump_BLOCK_00, 83)
#define DUMPSTART_FDMP_DEVERROR KERROR(EIO, sysdump_BLOCK_00, 85)
#define WRCDTCDP_SDMP_ERROR KERROR(EINVAL, sysdump_BLOCK_00, 88)
#define WRCDTDATA_SDMP_ERROR KERROR(EINVAL, sysdump_BLOCK_00, 89)
#define WRCDTU_SDMP_ERROR KERROR(EINVAL, sysdump_BLOCK_00, 90)
#define WRCDTURAS_SDMP_ERROR KERROR(EINVAL, sysdump_BLOCK_00, 91)
#define WRCDTUENTRY1_SDMP_ERROR KERROR(EINVAL, sysdump_BLOCK_00, 92)
#define WRCDTRAS_SDMP_ERROR KERROR(EINVAL, sysdump_BLOCK_00, 93)
#define WRCDTUDATA_SDMP_ERROR KERROR(EINVAL, sysdump_BLOCK_00, 94)
#define DUMPRESET_SDMP_ERROR KERROR(EINVAL, sysdump_BLOCK_00, 95)
#define DDCOMP1_SDMP_ERROR KERROR(ENOMEM, sysdump_BLOCK_00, 96)
#define DDCOMP2_SDMP_ERROR KERROR(ENOMEM, sysdump_BLOCK_00, 97)
#define DDCOMPIO_SDMP_ERROR KERROR(ENOMEM, sysdump_BLOCK_00, 98)
#define PUSHDUMP1_SDMP_ERROR KERROR(ENOMEM, sysdump_BLOCK_00, 99)
#define PUSHDUMP2_SDMP_ERROR KERROR(ENOMEM, sysdump_BLOCK_00, 100)
#define PULLDUMP_SDMP_ERROR KERROR(ENOMEM, sysdump_BLOCK_00, 101)
#define JWRITEBUF_SDMP_ERROR KERROR(ENOMEM, sysdump_BLOCK_00, 104)
#define EINVAL_JFLUSH_SDMP_ERROR KERROR(EINVAL, sysdump_BLOCK_00, 105)
#define ENOSPC_JWRITEIO1_SDMP_ERROR KERROR(ENOSPC, sysdump_BLOCK_00, 106)
#define EFAULT_DMP_IOWORKER KERROR(EFAULT, sysdump_BLOCK_00, 109)
#define EFAULT_DMP_COMPRESSWORKER KERROR(EFAULT, sysdump_BLOCK_00, 110)
#define QUIT_SDMP_ON_ERROR KERROR(EINVAL, sysdump_BLOCK_00, 111)
#define ENVAL_SDMP_NOHARD_ERROR KERROR(EINVAL, sysdump_BLOCK_00, 112)
#define EINVAL_CDT_HEADER_MAGIC KERROR(EINVAL, sysdump_BLOCK_00, 113)
#define EINVAL_RAS_CALLBACK_KERR KERROR(EINVAL, sysdump_BLOCK_00, 114)
#define EFAULT_CDT_DATA_AREA KERROR(EFAULT, sysdump_BLOCK_00, 115)
#define EINVAL_WRCDTUENTRY2_SDMP_ERROR KERROR(EINVAL, sysdump_BLOCK_00, 116)
#define EIO_SDMP_DUMPSTART KERROR(EIO, sysdump_BLOCK_00, 117)
#define ENODEV_IDMP_DO_NODEVICE KERROR(ENODEV, sysdump_BLOCK_00, 119)
#define EINAVL_IDMP_DO_RMDEVICE KERROR(EINVAL, sysdump_BLOCK_00, 120)
#define EBUSY_SDMP_LOG_HANG_ERROR KERROR(EBUSY, sysdump_BLOCK_00, 121)
#define EIO_SDMP_DEVERROR KERROR(EIO, sysdump_BLOCK_00, 123)
#define EFAULT_SDMP_MINIDUMP KERROR(EFAULT, sysdump_BLOCK_00, 124)
#define EFAULT_DMP_MASTER KERROR(EFAULT, sysdump_BLOCK_00, 125)
#endif /* _RAS_INTERNAL || _KERNEL */

/*
 * ras_stat structure for the dump domain.
 * This structure size must not exceed 128 bytes.
 */
typedef struct rstat_dump {
	dmp_lvl_t	rst_sdmp_lvl;
	dmp_lvl_t	rst_ldmp_lvl;
	int		rst_dmp_flags;	/* see rdb_flags */
	int 		rst_dump_reserved[30];
} rstat_dump_t;

/*
 * Dump-domain-specific information for persistent customizations.
 */
typedef struct rasp_pdump_stat
{
	char		rst_flags;
	signed		rst_sdmp_on_off	:2;
	signed  	rst_ldmp_on_off	:2;
	short		rst_length; 	/* Length of structure for extensibility */
	dmp_lvl_t	rst_sdmp_lvl;
	dmp_lvl_t	rst_ldmp_lvl;	
} rpstat_dump_t;

#ifdef __KDB_LDMP_COMPFLAGS
/* This is used to display the flags in kdb. */
static char *__dcf_descr[] = {
"LVL0", "LVL1", "LVL2", "LVL3", "LVL4", "LVL5", "LVL6", "LVL7", "LVL8", "LVL9",
"PSDO", "PNAM", "LNAM", "TYPE", "BYCB",
"FAIL", "FRST", "KYWD", "LONG", "UNIQ",
"MOREDATA", "NEEDSPUT", "PREPD", "ST_BAD", "PR_BAD", "FINISH"};
#endif /* __KDB_LDMP_COMPFLAGS */

#ifdef __cplusplus
}
#endif

#endif	/* _H_DUMP */