/* @(#) $Revision: 1.74.106.2 $ */

#ifndef _SYS_PARAM_INCLUDED /* allows multiple inclusion */
#define _SYS_PARAM_INCLUDED

#ifndef _SYS_STDSYMS_INCLUDED
#ifdef _KERNEL_BUILD
#    include "../h/stdsyms.h"
#else  /* ! _KERNEL_BUILD */
#    include <sys/stdsyms.h>
#endif /* _KERNEL_BUILD */
#endif   /* _SYS_STDSYMS_INCLUDED  */

/*
 * Kernel Type Declarations
 */
#ifdef _KERNEL_BUILD
#ifndef LOCORE
#include "../h/types.h"
#endif /* not LOCORE */
#include "../machine/param.h"
#include "../h/time.h"
#include "../machine/spl.h"
#else /* ! _KERNEL_BUILD */
#include <sys/types.h>
#include <machine/param.h>
#include <sys/time.h>
#include <machine/spl.h>
#endif /* _KERNEL_BUILD */

/*
 * Machine-independent constants
 */

/* defines for the front panel led lights */
#define led0            0x01
#define led1            0x02
#define led2            0x04
#define led3            0x08
#define KERN_OK_LED     0x10
#define DISK_DRV_LED    0x20
#define LAN_RCV_LED     0x40
#define LAN_XMIT_LED    0x80

/* See DSDe428700: */
#ifndef MAXINT
#ifndef MAXINT
#define	MAXINT	0x7fffffff	/* max value for integer  */
#endif
#endif  /** MAXINT **/

#ifndef KERNELSPACE
#define KERNELSPACE 0		/* see also vmparam.h */
#endif
#define MAXCOMLEN 14		/* size of process name buffer for accounting */
#define	NOFILE	60		/* max open files per process */

#define TWO_GIG              2147483648LL

#define MAX_SMALL_FILE_BITS  32
#define MAX_LARGE_FILE_BITS  42

#define MAX_SMALL_FILE       0x7FFFFFFF
#define MAX_LARGE_FILE       0xFFFFFFFFFFLL

#if defined(_LARGEFILE64_SOURCE) || defined(_KERNEL)
# define MAX_LOCK32_SIZE (uint32_t)((uint32_t)MAX_SMALL_FILE + 1) /* 32-bit lock size */
# define MAX_LOCK64_SIZE (uint64_t)(MAX_LARGE_FILE + 1) /* 64-bit lock size */
#endif

/* max lockable offset in file */
# if defined(__64BIT_OFF_T) || defined(_KERNEL)
#   define MAX_LOCK_SIZE   (uint64_t)(MAX_LARGE_FILE+1) 
# else
#   define MAX_LOCK_SIZE   (uint32_t)(MAX_SMALL_FILE+1)
# endif

#define	MAXPID	30000		/* max process id */
#define MAXTID  30000           /* max kthread id */
#define	MAXUID	MAXINT		/* smallest unattainable value for a user or
				 * group id */
#define	OLD_MAXUID	60000	/* old max user id */
#ifndef UID_NOBODY
#define UID_NOBODY	-2	/* nobody user id */
#endif
#define OLD_UID_NOBODY  65534   /* old nobody user id */

#define	MAXLINK	0x7fff		/* max # links to a file */
#ifndef MAX_CNODE		/* see also MAXCNODE in <cluster.h> */
#define MAX_CNODE 255           /* max cnode id */
#endif

#define MAXHOSTNAMELEN 64	/* max length of hostname */

#if NBPG==4096
#define SSIZE	2		/* initial stack size/NBPG */
#define SINCR	2		/* increment of stack/NBPG */
#else /* NBPG == 4096 */
#define SSIZE	4		/* initial stack size/NBPG */
#define SINCR	4		/* increment of stack/NBPG */
#endif /* NBPG==4096 */

#define	CANBSIZ	256		/* max size of typewriter line	*/

#define	HZ	CLK_TCK		/* Ticks/second of the clock (in kernel land) */

/*
 * Maximum values (in seconds) for alarms, interval timers, and timeouts
 */
#ifdef _INCLUDE_XOPEN_SOURCE_EXTENDED 
#  if !defined(_KERNEL) && defined (_XPG4_EXTENDED)
#    define MAX_ALARM 	((long)(0x7fffffff / HZ))
#    define MAX_VTALARM 	((long)(0x7fffffff)) 
#    define MAX_PROF 		((long)(0x7fffffff))
#  else /* _KERNEL OR !_XPG4_EXTENDED */ 
#    define MAX_ALARM       ((unsigned long)(0x7fffffff / HZ)) 
#    define MAX_VTALARM     ((unsigned long)0x7fffffff)
#    define MAX_PROF        ((unsigned long)0x7fffffff)
#  endif /* !_KERNEL && _XPG4_EXTENDED */
#endif /* _INCLUDE_XOPEN_SOURCE_EXTENDED */

#define	MAX_VT_ALARM	(MAX_VTALARM)	/* please use MAX_VTALARM instead */

#ifdef _KERNEL
#define USEC_PER_CLK_TCK	(1000000/HZ) /* # of usecs in a clock tick. */
#endif /* _KERNEL */

/*
 * Note that the value of ARG_MAX, defined in <limits.h>, in shared source,
 * is the same as NCARGS. If you change NCARGS, please also update
 * the value of ARG_MAX
 *
 * Also NOTE that NCARGS needs to be a multiple of EXEC_STR_BUF_SIZE.
 */
#define	NCARGS	2048000		/* max # characters in exec arg/env list */

/*
 * priorities
 * should not be altered too much
 */

#define	PMASK	0xffff
#define	PCATCH	0x10000

/*
 * Internal to the kernel, smallest (strongest) RTSCHED priority
 */
#define PRTSCHEDBASE		0

/*
 * Internal to the kernel, maximum on (gen-able) number of RTSCHED priorities
 */
#define MAX_RTSCHED_PRI		512

/*
 * Internal to the kernel, smallest (strongest) RTPRIO priority
 */
#define PRTBASE			(PRTSCHEDBASE + MAX_RTSCHED_PRI)

/*
 * Internal to the kernel, smallest (strongest) timeshare priority
 */
#define PTIMESHARE		(PRTBASE + 128)

/*
 * Priorities stronger (smaller number) than (or equal to) PZERO
 * are not signalable.
 */

#define	PSWP	(0+PTIMESHARE)
#define PMEM	(0+PTIMESHARE)
#define PRIRWLOCK (5+PTIMESHARE)
#define PRIBETA	(6+PTIMESHARE)
#define PRIALPHA (7+PTIMESHARE)
#define PRISYNC	(8+PTIMESHARE)
#define	PINOD	(10+PTIMESHARE)
#define	PRIBIO	(20+PTIMESHARE)
#define	PRIUBA	(24+PTIMESHARE)
#define	PLLIO	(24+PTIMESHARE)
#define	PZERO	(25+PTIMESHARE)
#define IPCPRI  (25+PTIMESHARE)

/*
 * Priorities weaker (bigger number) than PZERO are signalable.
 */

#define	PPIPE	(26+PTIMESHARE)
#define PVFS	(27+PTIMESHARE)
#define	PWAIT	(30+PTIMESHARE)
#define	PLOCK	(35+PTIMESHARE)
#define	PSLEP	(40+PTIMESHARE)
#define	PUSER	(50+PTIMESHARE)

/*
 * Internal to the kernel, largest (weakest) timeshare priority
 */
#define PMAX_TIMESHARE	(127+PTIMESHARE)

/*
 * Special argument to changepri(), meaning "the appropriate non-real-time
 * priority".
 */
#define PNOT_REALTIME	(0x7FFF)

/*
 * Used in nice(2) calculations.
 */
#define NZERO 20
#define MAXNICE (2 * NZERO - 1) /* used by vhand */
#define MINNICE  0		/* used by vhand */

/*
 * fundamental constants of the implementation--
 * cannot be changed easily
 */

#define	NBPW	sizeof(int)	/* number of bytes in an integer */
#define NBTSPW	(NBBY*NBPW)	/* number of bits in an integer */

#define BSIZE   DEV_BSIZE
#define BSHIFT  DEV_BSHIFT

/*
 * NINDIR is the number of indirects in a file system block.
 */
#define	NINDIR(fs)	((fs)->fs_nindir)
/*
 * INOPB is the number of inodes in a secondary storage block.
 */
#define	INOPB(fs)	((fs)->fs_inopb)
#define INOPF(fs)       ((fs)->fs_inopb >> (fs)->fs_fragshift)

#ifndef NULL
#  ifdef __cplusplus
#     if __cplusplus < 199707L
#         define NULL 0                  /* old compiler requires 0 not 0L */
#     else  /* __cplusplus < 199707L */
#         define NULL 0L                 /* new compiler allows preferred 0L */
#     endif /* __cplusplus < 199707L */
#  else
#     define NULL 0L
#  endif /* __cplusplus */
#endif /* NULL */

#define	CMASK	0		/* default mask for file creation */
#define	CDLIMIT	0x1FFFFFFF	/* default max write address */
#define	NODEV	(dev_t)(-1)
#define	SWDEF	(dev_t)(-2)
/* The root inode is the root of the file system.
 * Inode 0 can't be used for normal purposes and
 * historically bad blocks were linked to inode 1,
 * thus the root inode is 2. (inode 1 is no longer used for
 * this purpose, however numerous dump tapes make this
 * assumption, so we are stuck with it)
 * The lost+found directory is given the next available
 * inode when it is created by ``mkfs''.
 */
#define	ROOTINO		((ino_t)2)	/* i number of all roots */
#define LOSTFOUNDINO    (ROOTINO + 1)
/*
 * Decode privilege level for HP-PA.
 */
#define PC_PRIV_MASK	3
#define PC_PRIV_KERN	0
#define PC_PRIV_USER	3

#define USERMODE(pc)	(((pc) & PC_PRIV_MASK) != PC_PRIV_KERN)

#define	lobyte(X)	(((unsigned char *)&X)[1])
#define	hibyte(X)	(((unsigned char *)&X)[0])
#define	loword(X)	(((ushort *)&X)[1])
#define	hiword(X)	(((ushort *)&X)[0])


#define	NGROUPS	20		/* max number groups */
#define	NOGROUP	((gid_t) -1)	/* marker for empty group set member */
/*
 * Signals.  Only include if defining _KERNEL.
 */
#ifdef _KERNEL
#ifdef _KERNEL_BUILD
#include "../h/signal.h"
#else /* ! _KERNEL_BUILD */
#include <sys/signal.h>
#endif /* _KERNEL_BUILD */
#endif /* _KERNEL */

/* There are places where we would like to know if we have a possible
 * signal that we might have to handle.  If so, we have to grab the
 * kernel semaphore.  Note, this is a hint, and does not include the
 * call to issig...
 */
#define	ISSIG_SLEEP(t,ret) \
	(((t->kt_suspendcnt) || \
	 (!ksigisempty((t)->kt_procp->p_sig)) || \
	 ((!ksigisempty((t)->kt_sig)) && \
	 ((t)->kt_procp->p_flag&STRC || \
 	 (ksigxsectinv((t)->kt_sig, (t)->kt_sigmask)))))  && \
	 (thread_unlock(t), \
	 ret = issig(KT_NOT_CLEAN_PT), \
	 thread_lock(t),ret) \
	 )

#define	ISSIG(t) \
 	((t->kt_suspendcnt || \
	(!ksigisempty((t)->kt_procp->p_sig)) || \
	(!(ksigisempty((t)->kt_sig)) &&	\
 	((t)->kt_procp->p_flag&STRC ||  \
	(ksigxsectinv((t)->kt_sig,(t)->kt_sigmask))))) &&  \
 	issig(KT_NOT_CLEAN_PT) )



/*
 * Fundamental constants of the implementation.
 */
#ifndef NBBY
#define	NBBY	8		/* number of bits in a byte */
 				/* NOTE: this is also defined	*/
 				/* in fs.h (filsys.h).  So if	*/
 				/* NBBY gets changed, change it	*/
 				/* in fs.h (filsys.h) also	*/
#endif /* NBBY */

/*
 * File system parameters and macros.
 *
 * The file system is made out of blocks of at most MAXBSIZE units,
 * with smaller units (fragments) only in the last direct block.
 * MAXBSIZE primarily determines the size of buffers in the buffer
 * pool. It may be made larger without any effect on existing
 * file systems; however making it smaller make make some file
 * systems unmountable.
 *
 * Note that the blocked devices are assumed to have DEV_BSIZE
 * "sectors" and that fragments must be some multiple of this size.
 * Block devices are read in BLKDEV_IOSIZE units. This number must
 * be a power of two and in the range of
 *	DEV_BSIZE <= BLKDEV_IOSIZE <= MAXBSIZE
 * This size has no effect upon the file system, but is usually set
 * to the block size of the root file system, so as to maximize the
 * speed of ``fsck''.
 */
#define	MAXBSIZE	65536
#ifndef	DEV_BSIZE
#define	DEV_BSIZE	1024
#define	DEV_BSHIFT	10      	/* log2(DEV_BSIZE) */
#define DEV_BMASK	(DEV_BSIZE-1)	/* For doing modulo functions */
#endif /* DEV_BSIZE */

#define BLKDEV_IOSIZE	2048
#define	BLKDEV_IOSHIFT	11
#define BLKDEV_IOMASK	(BLKDEV_IOSIZE-1)

#if !defined(__STDC_32_MODE__)
#  define btodb(bytes)	 		/* calculates (bytes / DEV_BSIZE) */ \
	(sizeof(bytes) == sizeof(int64_t)? \
	(unsigned)((uint64_t)(bytes) >> DEV_BSHIFT): \
	((unsigned)(bytes) >> DEV_BSHIFT))
#else
#  define btodb(bytes)	 		/* calculates (bytes / DEV_BSIZE) */ \
	((unsigned)(bytes) >> DEV_BSHIFT)
#endif

# define dbtob(db)			/* calculates (db * DEV_BSIZE) */ \
	((unsigned)(db) << DEV_BSHIFT)

#if !defined(_KERNEL)
# ifdef __64BIT_OFF_T
#  define dbtoo(db)	/* generate 64-bit byte offsets */ \
	  ((uint64_t)((uint32_t)db) << DEV_BSHIFT)
# else
#  define dbtoo(db)	/* generate 32-bit byte offsets */ \
	  ((uint32_t)(db) << DEV_BSHIFT)
# endif
#endif

#define btodbup(bytes)			/* same as btodb but round up */ \
	(((unsigned)(bytes) + (DEV_BSIZE-1)) >> DEV_BSHIFT)

/*
 * Map a ``block device block'' to a file system block.
 * This should be device dependent, and will be after we
 * add an entry to cdevsw for that purpose.  For now though
 * just use DEV_BSIZE.
 */
#define	bdbtofsb(bn)	((bn) / (BLKDEV_IOSIZE/DEV_BSIZE))

/*
 * MAXPATHLEN defines the longest permissable path length
 * after expanding symbolic links. It is used to allocate
 * a temporary buffer from the buffer pool in which to do the
 * name expansion, hence should be a power of two, and must
 * be less than or equal to MAXBSIZE.
 * MAXSYMLINKS defines the maximum number of symbolic links
 * that may be expanded in a path name. It should be set high
 * enough to allow all legitimate uses, but halt infinite loops
 * reasonably quickly.
 */
#define MAXPATHLEN	1024
#define MAXSYMLINKS	20

/*
 * bit map related macros
 */
#define	setbit(a,i)	((a)[(i)/NBBY] |= 1<<((i)%NBBY))
#define	clrbit(a,i)	((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
#define	isset(a,i)	((a)[(i)/NBBY] & (1<<((i)%NBBY)))
#define	isclr(a,i)	(((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)

/*
 * bit map related macros done on a word basis
 */
#define wsetbit(a,i)	((a)[(i)/NBTSPW] |= 1<<((i)%NBTSPW))
#define wclrbit(a,i)	((a)[(i)/NBTSPW] &= ~(1<<((i)%NBTSPW)))
#define wisset(a,i)	((a)[(i)/NBTSPW] & (1<<((i)%NBTSPW)))
#define wisclr(a,i)	(((a)[(i)/NBTSPW] & (1<<((i)%NBTSPW))) == 0)

/*
 * Macros for fast min/max.
 */
#define	MIN(a,b) (((a)<(b))?(a):(b))
#define	MAX(a,b) (((a)>(b))?(a):(b))

/*
 * Macros for counting and rounding.
 */
#ifndef howmany
#	define	howmany(x, y)	(((x)+((y)-1))/(y))
#endif
#define	roundup(x, y)	((((x)+((y)-1))/(y))*(y))

#ifdef _KERNEL
/*
 * Macro used to get integer value for sizeof(object)
 * Should only be used when dealing with integer sized
 * objects.
 * The comment before the macro will turn off the lint
 * warning.
 */
/*lint -emacro(921,isizeof)*/
#define	isizeof(x)	(int)sizeof(x)
#endif /* _KERNEL */

#ifdef _UNSUPPORTED

	/* 
	 * NOTE: The following header file contains information specific
	 * to the internals of the HP-UX implementation. The contents of 
	 * this header file are subject to change without notice. Such
	 * changes may affect source code, object code, or binary
	 * compatibility between releases of HP-UX. Code which uses 
	 * the symbols contained within this header file is inherently
	 * non-portable (even between HP-UX implementations).
	*/
#ifdef _KERNEL_BUILD
#	include "../h/_param.h"
#else  /* ! _KERNEL_BUILD */
#	include <.unsupp/sys/_param.h>
#endif /* _KERNEL_BUILD */
#endif /* _UNSUPPORTED */

#endif /* _SYS_PARAM_INCLUDED */
