xref: /csrg-svn/sys/hp300/include/param.h (revision 69399)
141474Smckusick /*
241474Smckusick  * Copyright (c) 1988 University of Utah.
363160Sbostic  * Copyright (c) 1982, 1986, 1990, 1993
463160Sbostic  *	The Regents of the University of California.  All rights reserved.
541474Smckusick  *
641474Smckusick  * This code is derived from software contributed to Berkeley by
741474Smckusick  * the Systems Programming Group of the University of Utah Computer
841474Smckusick  * Science Department.
941474Smckusick  *
1041474Smckusick  * %sccs.include.redist.c%
1141474Smckusick  *
1257319Shibler  * from: Utah $Hdr: machparam.h 1.16 92/12/20$
1341474Smckusick  *
14*69399Smckusick  *	@(#)param.h	8.4 (Berkeley) 05/13/95
1541474Smckusick  */
1641474Smckusick 
1741474Smckusick /*
1841474Smckusick  * Machine dependent constants for HP9000 series 300.
1941474Smckusick  */
2041474Smckusick #define	MACHINE "hp300"
2169398Smckusick #define NCPUS	1
2241474Smckusick 
2350140Ssklower /*
2452588Sbostic  * Round p (pointer or byte index) up to a correctly-aligned value for all
2552588Sbostic  * data types (int, long, ...).   The result is u_int and must be cast to
2652588Sbostic  * any desired pointer type.
2750140Ssklower  */
2853672Sbostic #define	ALIGNBYTES	3
2953672Sbostic #define	ALIGN(p)	(((u_int)(p) + ALIGNBYTES) &~ ALIGNBYTES)
3050140Ssklower 
3141474Smckusick #define	NBPG		4096		/* bytes/page */
3241474Smckusick #define	PGOFSET		(NBPG-1)	/* byte offset into page */
3341474Smckusick #define	PGSHIFT		12		/* LOG2(NBPG) */
3441474Smckusick #define	NPTEPG		(NBPG/(sizeof (struct pte)))
3541474Smckusick 
3653928Shibler #define NBSEG		0x400000	/* bytes/segment */
3741474Smckusick #define	SEGOFSET	(NBSEG-1)	/* byte offset into segment */
3841474Smckusick #define	SEGSHIFT	22		/* LOG2(NBSEG) */
3941474Smckusick 
4041474Smckusick #define	KERNBASE	0x00000000	/* start of kernel virtual */
4141474Smckusick #define	BTOPKERNBASE	((u_long)KERNBASE >> PGSHIFT)
4241474Smckusick 
4341474Smckusick #define	DEV_BSIZE	512
4441474Smckusick #define	DEV_BSHIFT	9		/* log2(DEV_BSIZE) */
4541474Smckusick #define BLKDEV_IOSIZE	2048
4641474Smckusick #define	MAXPHYS		(64 * 1024)	/* max raw I/O transfer size */
4741474Smckusick 
4841474Smckusick #define	CLSIZE		1
4941474Smckusick #define	CLSIZELOG2	0
5041474Smckusick 
5149136Skarels /* NOTE: SSIZE, SINCR and UPAGES must be multiples of CLSIZE */
5241474Smckusick #define	SSIZE		1		/* initial stack size/NBPG */
5341474Smckusick #define	SINCR		1		/* increment of stack/NBPG */
5441474Smckusick 
5557319Shibler #define	UPAGES		2		/* pages of u-area */
5641474Smckusick 
5741474Smckusick /*
5841474Smckusick  * Constants related to network buffer management.
5941474Smckusick  * MCLBYTES must be no larger than CLBYTES (the software page size), and,
6041474Smckusick  * on machines that exchange pages of input or output buffers with mbuf
6141474Smckusick  * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple
6241474Smckusick  * of the hardware page size.
6341474Smckusick  */
6441474Smckusick #define	MSIZE		128		/* size of an mbuf */
6557319Shibler #define	MCLBYTES	2048		/* large enough for ether MTU */
6657319Shibler #define	MCLSHIFT	11
6741474Smckusick #define	MCLOFSET	(MCLBYTES - 1)
6841474Smckusick #ifndef NMBCLUSTERS
6941474Smckusick #ifdef GATEWAY
7041474Smckusick #define	NMBCLUSTERS	512		/* map size, max cluster allocation */
7141474Smckusick #else
7241474Smckusick #define	NMBCLUSTERS	256		/* map size, max cluster allocation */
7341474Smckusick #endif
7441474Smckusick #endif
7541474Smckusick 
7641474Smckusick /*
7741474Smckusick  * Size of kernel malloc arena in CLBYTES-sized logical pages
7841474Smckusick  */
7941474Smckusick #ifndef NKMEMCLUSTERS
8050266Skarels #define	NKMEMCLUSTERS	(2048*1024/CLBYTES)
8141474Smckusick #endif
8241474Smckusick 
8349427Skarels /* pages ("clicks") (4096 bytes) to disk blocks */
8441474Smckusick #define	ctod(x)	((x)<<(PGSHIFT-DEV_BSHIFT))
8541474Smckusick #define	dtoc(x)	((x)>>(PGSHIFT-DEV_BSHIFT))
8641474Smckusick #define	dtob(x)	((x)<<DEV_BSHIFT)
8741474Smckusick 
8849427Skarels /* pages to bytes */
8941474Smckusick #define	ctob(x)	((x)<<PGSHIFT)
9041474Smckusick 
9149427Skarels /* bytes to pages */
9241474Smckusick #define	btoc(x)	(((unsigned)(x)+(NBPG-1))>>PGSHIFT)
9341474Smckusick 
9457319Shibler #define LABELSECTOR	(1024/DEV_BSIZE)
9557319Shibler #define LABELOFFSET	0
9657319Shibler 
9741474Smckusick #define	btodb(bytes)	 		/* calculates (bytes / DEV_BSIZE) */ \
9868631Smckusick 	((bytes) >> DEV_BSHIFT)
9941474Smckusick #define	dbtob(db)			/* calculates (db * DEV_BSIZE) */ \
10068631Smckusick 	((db) << DEV_BSHIFT)
10141474Smckusick 
10241474Smckusick /*
10341474Smckusick  * Map a ``block device block'' to a file system block.
10449136Skarels  * This should be device dependent, and should use the bsize
10549136Skarels  * field from the disk label.
10641474Smckusick  * For now though just use DEV_BSIZE.
10741474Smckusick  */
10841474Smckusick #define	bdbtofsb(bn)	((bn) / (BLKDEV_IOSIZE/DEV_BSIZE))
10941474Smckusick 
11041474Smckusick /*
11145755Smckusick  * Mach derived conversion macros
11245755Smckusick  */
11345755Smckusick #define hp300_round_page(x)	((((unsigned)(x)) + NBPG - 1) & ~(NBPG-1))
11445755Smckusick #define hp300_trunc_page(x)	((unsigned)(x) & ~(NBPG-1))
11545755Smckusick #define hp300_btop(x)		((unsigned)(x) >> PGSHIFT)
11645755Smckusick #define hp300_ptob(x)		((unsigned)(x) << PGSHIFT)
11745755Smckusick 
11845755Smckusick /*
11949136Skarels  * spl functions; all but spl0 are done in-line
12041474Smckusick  */
12149136Skarels #include <machine/psl.h>
12241474Smckusick 
12349136Skarels #define _spl(s) \
12449136Skarels ({ \
12549136Skarels         register int _spl_r; \
12649136Skarels \
12749136Skarels         asm __volatile ("clrl %0; movew sr,%0; movew %1,sr" : \
12849136Skarels                 "&=d" (_spl_r) : "di" (s)); \
12949136Skarels         _spl_r; \
13049136Skarels })
13149136Skarels 
13249136Skarels /* spl0 requires checking for software interrupts */
13349136Skarels #define spl1()  _spl(PSL_S|PSL_IPL1)
13449136Skarels #define spl2()  _spl(PSL_S|PSL_IPL2)
13549136Skarels #define spl3()  _spl(PSL_S|PSL_IPL3)
13649136Skarels #define spl4()  _spl(PSL_S|PSL_IPL4)
13749136Skarels #define spl5()  _spl(PSL_S|PSL_IPL5)
13849136Skarels #define spl6()  _spl(PSL_S|PSL_IPL6)
13949136Skarels #define spl7()  _spl(PSL_S|PSL_IPL7)
14049136Skarels 
14154794Smckusick #define splsoftclock()	spl1()
14254794Smckusick #define splnet()	spl1()
14354794Smckusick #define splbio()	spl5()
14454794Smckusick #define splimp()	spl5()
14554794Smckusick #define spltty()	spl5()
14654794Smckusick #define splclock()	spl6()
14754794Smckusick #define splstatclock()	spl6()
14854794Smckusick #define splvm()		spl6()
14954794Smckusick #define splhigh()	spl7()
15054794Smckusick #define splsched()	spl7()
15149136Skarels 
15249136Skarels /* watch out for side effects */
15349136Skarels #define splx(s)         (s & PSL_IPL ? _spl(s) : spl0())
15449136Skarels 
15541474Smckusick #ifdef KERNEL
15641474Smckusick #ifndef LOCORE
15741474Smckusick int	cpuspeed;
15841474Smckusick #define	DELAY(n)	{ register int N = cpuspeed * (n); while (--N > 0); }
15941474Smckusick #endif
16050030Sbostic #else
16141474Smckusick #define	DELAY(n)	{ register int N = (n); while (--N > 0); }
16250030Sbostic #endif
16341474Smckusick 
16441474Smckusick #ifdef HPUXCOMPAT
16541474Smckusick /*
16641474Smckusick  * Constants/macros for HPUX multiple mapping of user address space.
16741474Smckusick  * Pages in the first 256Mb are mapped in at every 256Mb segment.
16841474Smckusick  */
16941474Smckusick #define HPMMMASK	0xF0000000
17053928Shibler #define ISHPMMADDR(v) \
17157319Shibler 	((curproc->p_md.md_flags & MDP_HPUXMMAP) && \
17257319Shibler 	 ((unsigned)(v) & HPMMMASK) && \
17353928Shibler 	 ((unsigned)(v) & HPMMMASK) != HPMMMASK)
17453928Shibler #define HPMMBASEADDR(v) \
17553928Shibler 	((unsigned)(v) & ~HPMMMASK)
17641474Smckusick #endif
17769398Smckusick 
178*69399Smckusick #ifndef _SIMPLELOCK_H_
179*69399Smckusick #define _SIMPLELOCK_H_
18069398Smckusick /*
18169398Smckusick  * A simple spin lock.
18269398Smckusick  *
18369398Smckusick  * This structure only sets one bit of data, but is sized based on the
18469398Smckusick  * minimum word size that can be operated on by the hardware test-and-set
18569398Smckusick  * instruction. It is only needed for multiprocessors, as uniprocessors
18669398Smckusick  * will always run to completion or a sleep. It is an error to hold one
18769398Smckusick  * of these locks while a process is sleeping.
18869398Smckusick  */
18969398Smckusick struct simplelock {
19069398Smckusick 	int	lock_data;
19169398Smckusick };
19269398Smckusick 
19369398Smckusick #if !defined(DEBUG) && NCPUS > 1
19469398Smckusick /*
19569398Smckusick  * The simple-lock routines are the primitives out of which the lock
19669398Smckusick  * package is built. The machine-dependent code must implement an
19769398Smckusick  * atomic test_and_set operation that indivisibly sets the simple lock
19869398Smckusick  * to non-zero and returns its old value. It also assumes that the
19969398Smckusick  * setting of the lock to zero below is indivisible. Simple locks may
20069398Smckusick  * only be used for exclusive locks.
20169398Smckusick  */
20269398Smckusick static __inline void
simple_lock_init(lkp)20369398Smckusick simple_lock_init(lkp)
20469398Smckusick 	struct simplelock *lkp;
20569398Smckusick {
20669398Smckusick 
20769398Smckusick 	lkp->lock_data = 0;
20869398Smckusick }
20969398Smckusick 
21069398Smckusick static __inline void
simple_lock(lkp)21169398Smckusick simple_lock(lkp)
21269398Smckusick 	__volatile struct simplelock *lkp;
21369398Smckusick {
21469398Smckusick 
21569398Smckusick 	while (test_and_set(&lkp->lock_data))
21669398Smckusick 		continue;
21769398Smckusick }
21869398Smckusick 
21969398Smckusick static __inline int
simple_lock_try(lkp)22069398Smckusick simple_lock_try(lkp)
22169398Smckusick 	__volatile struct simplelock *lkp;
22269398Smckusick {
22369398Smckusick 
22469398Smckusick 	return (!test_and_set(&lkp->lock_data))
22569398Smckusick }
22669398Smckusick 
22769398Smckusick static __inline void
22869398Smckusick simple_unlock(lkp)
22969398Smckusick 	__volatile struct simplelock *lkp;
23069398Smckusick {
23169398Smckusick 
23269398Smckusick 	lkp->lock_data = 0;
23369398Smckusick }
23469398Smckusick #endif /* NCPUS > 1 */
235*69399Smckusick #endif /* !_SIMPLELOCK_H_ */
236