systm.h revision 65708
11541Srgrimes/*-
21541Srgrimes * Copyright (c) 1982, 1988, 1991, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes * (c) UNIX System Laboratories, Inc.
51541Srgrimes * All or some portions of this file are derived from material licensed
61541Srgrimes * to the University of California by American Telephone and Telegraph
71541Srgrimes * Co. or Unix System Laboratories, Inc. and are reproduced herein with
81541Srgrimes * the permission of UNIX System Laboratories, Inc.
91541Srgrimes *
101541Srgrimes * Redistribution and use in source and binary forms, with or without
111541Srgrimes * modification, are permitted provided that the following conditions
121541Srgrimes * are met:
131541Srgrimes * 1. Redistributions of source code must retain the above copyright
141541Srgrimes *    notice, this list of conditions and the following disclaimer.
151541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
161541Srgrimes *    notice, this list of conditions and the following disclaimer in the
171541Srgrimes *    documentation and/or other materials provided with the distribution.
181541Srgrimes * 3. All advertising materials mentioning features or use of this software
191541Srgrimes *    must display the following acknowledgement:
201541Srgrimes *	This product includes software developed by the University of
211541Srgrimes *	California, Berkeley and its contributors.
221541Srgrimes * 4. Neither the name of the University nor the names of its contributors
231541Srgrimes *    may be used to endorse or promote products derived from this software
241541Srgrimes *    without specific prior written permission.
251541Srgrimes *
261541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
271541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
281541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
291541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
301541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
311541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
321541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
331541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
341541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
351541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
361541Srgrimes * SUCH DAMAGE.
371541Srgrimes *
3814508Shsu *	@(#)systm.h	8.7 (Berkeley) 3/29/95
3950477Speter * $FreeBSD: head/sys/sys/systm.h 65708 2000-09-11 00:20:02Z jake $
401541Srgrimes */
411541Srgrimes
422165Spaul#ifndef _SYS_SYSTM_H_
432865Sbde#define	_SYS_SYSTM_H_
442165Spaul
4549043Salc#include <machine/atomic.h>
461549Srgrimes#include <machine/cpufunc.h>
4729683Sgibbs#include <sys/callout.h>
481549Srgrimes
4918883Sbdeextern int securelevel;		/* system security level (see init(8)) */
507090Sbde
517090Sbdeextern int cold;		/* nonzero if we are doing a cold boot */
521541Srgrimesextern const char *panicstr;	/* panic message */
5331337Sbdeextern int safepri;		/* safe ipl when cold or panicing */
541541Srgrimesextern char version[];		/* system version */
551541Srgrimesextern char copyright[];	/* system copyright */
561541Srgrimes
571541Srgrimesextern int nswap;		/* size of swap space */
581541Srgrimes
591541Srgrimesextern int selwait;		/* select timeout address */
601541Srgrimes
611541Srgrimesextern u_char curpriority;	/* priority of current process */
621541Srgrimes
631541Srgrimesextern int physmem;		/* physical memory */
641541Srgrimes
651541Srgrimesextern dev_t dumpdev;		/* dump device */
661541Srgrimesextern long dumplo;		/* offset into dumpdev */
671541Srgrimes
681541Srgrimesextern dev_t rootdev;		/* root device */
6936809Sbdeextern dev_t rootdevs[2];	/* possible root devices */
7036809Sbdeextern char *rootdevnames[2];	/* names of possible root devices */
711541Srgrimesextern struct vnode *rootvp;	/* vnode equivalent to above */
721541Srgrimes
731541Srgrimesextern int boothowto;		/* reboot flags, from console subsystem */
7415113Sbdeextern int bootverbose;		/* nonzero to print verbose messages */
751541Srgrimes
7642453Seivind#ifdef	INVARIANTS		/* The option is always available */
7742453Seivind#define	KASSERT(exp,msg)	do { if (!(exp)) panic msg; } while (0)
7857294Sbde#define	SPLASSERT(level, msg)	__CONCAT(__CONCAT(spl,level),assert)(msg)
7958283Sps#define	CONDSPLASSERT(cond, level, msg) do {				\
8058283Sps	if (cond)							\
8158283Sps		SPLASSERT(level, msg);					\
8258283Sps} while (0)
8342408Seivind#else
8442453Seivind#define	KASSERT(exp,msg)
8558283Sps#define	SPLASSERT(level, msg)
8658283Sps#define	CONDSPLASSERT(cond, level, msg)
8742408Seivind#endif
8842408Seivind
891541Srgrimes/*
901541Srgrimes * General function declarations.
911541Srgrimes */
9230282Sphk
9333777Sbdestruct clockframe;
9430282Sphkstruct malloc_type;
9565708Sjakestruct mtx;
9633777Sbdestruct proc;
9733777Sbdestruct timeval;
9833777Sbdestruct tty;
9933777Sbdestruct uio;
10030282Sphk
10116875Sbdevoid	Debugger __P((const char *msg));
1021541Srgrimesint	nullop __P((void));
1031541Srgrimesint	eopnotsupp __P((void));
10414508Shsuint	einval __P((void));
1051541Srgrimesint	seltrue __P((dev_t dev, int which, struct proc *p));
1063304Sphkint	ureadc __P((int, struct uio *));
10730282Sphkvoid	*hashinit __P((int count, struct malloc_type *type, u_long *hashmask));
10830282Sphkvoid	*phashinit __P((int count, struct malloc_type *type, u_long *nentries));
1091541Srgrimes
11017975Sbdevoid	cpu_boot __P((int));
11129683Sgibbsvoid	cpu_rootconf __P((void));
1121541Srgrimesvoid	tablefull __P((const char *));
11337614Sbdeint	addlog __P((const char *, ...)) __printflike(1, 2);
11418556Sbdeint	kvprintf __P((char const *, void (*)(int, void*), void *, int,
11537614Sbde		      _BSD_VA_LIST_)) __printflike(1, 0);
11649047Sdfrint	log __P((int, const char *, ...)) __printflike(2, 3);
11729509Sbdevoid	logwakeup __P((void));
11837614Sbdeint	printf __P((const char *, ...)) __printflike(1, 2);
11941479Sarchieint	snprintf __P((char *, size_t, const char *, ...)) __printflike(3, 4);
12037614Sbdeint	sprintf __P((char *buf, const char *, ...)) __printflike(2, 3);
12149047Sdfrint	uprintf __P((const char *, ...)) __printflike(1, 2);
12249047Sdfrint	vprintf __P((const char *, _BSD_VA_LIST_)) __printflike(1, 0);
12341479Sarchieint	vsnprintf __P((char *, size_t, const char *, _BSD_VA_LIST_)) __printflike(3, 0);
12438874Sacheint     vsprintf __P((char *buf, const char *, _BSD_VA_LIST_)) __printflike(2, 0);
12549047Sdfrint	ttyprintf __P((struct tty *, const char *, ...)) __printflike(2, 3);
12642680Smsmithint	sscanf __P((const char *, char const *, ...));
12742680Smsmithint	vsscanf __P((const char *, char const *, _BSD_VA_LIST_));
12854216Sarchielong	strtol __P((const char *, char **, int));
12954216Sarchieu_long	strtoul __P((const char *, char **, int));
13054216Sarchiequad_t	strtoq __P((const char *, char **, int));
13154216Sarchieu_quad_t strtouq __P((const char *, char **, int));
1321541Srgrimes
1338215Sdgvoid	bcopy __P((const void *from, void *to, size_t len));
1348215Sdgvoid	ovbcopy __P((const void *from, void *to, size_t len));
13556079Sjmb
13636735Sdfr#ifdef __i386__
13713414Sphkextern void	(*bzero) __P((void *buf, size_t len));
13836735Sdfr#else
13936735Sdfrvoid	bzero __P((void *buf, size_t len));
14036735Sdfr#endif
1411541Srgrimes
1428215Sdgvoid	*memcpy __P((void *to, const void *from, size_t len));
1438215Sdg
14413456Sbdeint	copystr __P((const void *kfaddr, void *kdaddr, size_t len,
14513456Sbde		size_t *lencopied));
14613456Sbdeint	copyinstr __P((const void *udaddr, void *kaddr, size_t len,
14713456Sbde		size_t *lencopied));
14813456Sbdeint	copyin __P((const void *udaddr, void *kaddr, size_t len));
14913456Sbdeint	copyout __P((const void *kaddr, void *udaddr, size_t len));
1501541Srgrimes
15113456Sbdeint	fubyte __P((const void *base));
1521541Srgrimesint	subyte __P((void *base, int byte));
1531541Srgrimesint	suibyte __P((void *base, int byte));
15436735Sdfrlong	fuword __P((const void *base));
15536735Sdfrint	suword __P((void *base, long word));
15644495Sbdeint	fusword __P((void *base));
15744495Sbdeint	susword __P((void *base, int word));
1581541Srgrimes
1591541Srgrimesvoid	realitexpire __P((void *));
1601541Srgrimes
1611541Srgrimesvoid	hardclock __P((struct clockframe *frame));
16232390Sphkvoid	softclock __P((void));
1631541Srgrimesvoid	statclock __P((struct clockframe *frame));
1641541Srgrimes
1651541Srgrimesvoid	startprofclock __P((struct proc *));
1661541Srgrimesvoid	stopprofclock __P((struct proc *));
1671541Srgrimesvoid	setstatclockrate __P((int hzrate));
1681541Srgrimes
16940096Smsmithchar	*getenv __P((char *name));
17042706Smsmithint	getenv_int __P((char *name, int *data));
17152946Smjacobquad_t	getenv_quad __P((char *name, quad_t *data));
17240096Smsmithextern char *kern_envp;
17340096Smsmith
17431960Snate#ifdef APM_FIXUP_CALLTODO
17531960Snatevoid	adjust_timeout_calltodo __P((struct timeval *time_change));
17631960Snate#endif /* APM_FIXUP_CALLTODO */
17731960Snate
1787109Sphk#include <sys/libkern.h>
1792112Swollman
1802112Swollman/* Initialize the world */
18129509Sbdevoid	consinit __P((void));
18229509Sbdevoid	cpu_initclocks __P((void));
18329509Sbdevoid	nchinit __P((void));
18429509Sbdevoid	usrinfoinit __P((void));
18529509Sbdevoid	vntblinit __P((void));
1862112Swollman
1877090Sbde/* Finalize the world. */
18865268Smsmithvoid	shutdown_nice __P((int));
1897090Sbde
1907090Sbde/*
1917090Sbde * Kernel to clock driver interface.
1927090Sbde */
1937090Sbdevoid	inittodr __P((time_t base));
1947090Sbdevoid	resettodr __P((void));
1957090Sbdevoid	startrtclock __P((void));
1967090Sbde
1972112Swollman/* Timeouts */
19829509Sbdetypedef void timeout_t __P((void *));	/* timeout function type */
19929683Sgibbs#define CALLOUT_HANDLE_INITIALIZER(handle)	\
20029683Sgibbs	{ NULL }
2012112Swollman
20229683Sgibbsvoid	callout_handle_init __P((struct callout_handle *));
20329683Sgibbsstruct	callout_handle timeout __P((timeout_t *, void *, int));
20429683Sgibbsvoid	untimeout __P((timeout_t *, void *, struct callout_handle));
2052165Spaul
20638130Sbde/* Interrupt management */
20738130Sbde
20857294Sbde/*
20957294Sbde * For the alpha arch, some of these functions are static __inline, and
21057294Sbde * the others should be.
21157294Sbde */
21236735Sdfr#ifdef __i386__
21338130Sbdevoid		setdelayed __P((void));
21438130Sbdevoid		setsoftast __P((void));
21538130Sbdevoid		setsoftcambio __P((void));
21638130Sbdevoid		setsoftcamnet __P((void));
21738130Sbdevoid		setsoftclock __P((void));
21838130Sbdevoid		setsoftnet __P((void));
21938130Sbdevoid		setsofttty __P((void));
22038130Sbdevoid		setsoftvm __P((void));
22161033Sdfrvoid		setsofttq __P((void));
22238130Sbdevoid		schedsoftcamnet __P((void));
22338130Sbdevoid		schedsoftcambio __P((void));
22438130Sbdevoid		schedsoftnet __P((void));
22538130Sbdevoid		schedsofttty __P((void));
22638130Sbdevoid		schedsoftvm __P((void));
22761033Sdfrvoid		schedsofttq __P((void));
22838130Sbdeintrmask_t	softclockpending __P((void));
22938130Sbdevoid		spl0 __P((void));
23038130Sbdeintrmask_t	splbio __P((void));
23138130Sbdeintrmask_t	splcam __P((void));
23238130Sbdeintrmask_t	splclock __P((void));
23338130Sbdeintrmask_t	splhigh __P((void));
23438130Sbdeintrmask_t	splimp __P((void));
23538130Sbdeintrmask_t	splnet __P((void));
23638130Sbdeintrmask_t	splsoftcam __P((void));
23738130Sbdeintrmask_t	splsoftcambio __P((void));
23838130Sbdeintrmask_t	splsoftcamnet __P((void));
23938130Sbdeintrmask_t	splsoftclock __P((void));
24038130Sbdeintrmask_t	splsofttty __P((void));
24138130Sbdeintrmask_t	splsoftvm __P((void));
24261033Sdfrintrmask_t	splsofttq __P((void));
24338130Sbdeintrmask_t	splstatclock __P((void));
24438130Sbdeintrmask_t	spltty __P((void));
24538130Sbdeintrmask_t	splvm __P((void));
24638130Sbdevoid		splx __P((intrmask_t ipl));
24738130Sbdevoid		splz __P((void));
24838130Sbde#endif /* __i386__ */
24926312Speter
25036735Sdfr#ifdef __alpha__
25136735Sdfr#include <machine/ipl.h>
25236735Sdfr#endif
25336735Sdfr
25457294Sbde#ifdef INVARIANT_SUPPORT
25557294Sbdevoid	splbioassert __P((const char *msg));
25657294Sbdevoid	splcamassert __P((const char *msg));
25757294Sbdevoid	splclockassert __P((const char *msg));
25857294Sbdevoid	splhighassert __P((const char *msg));
25957294Sbdevoid	splimpassert __P((const char *msg));
26057294Sbdevoid	splnetassert __P((const char *msg));
26157294Sbdevoid	splsoftcamassert __P((const char *msg));
26257294Sbdevoid	splsoftcambioassert __P((const char *msg));
26357294Sbdevoid	splsoftcamnetassert __P((const char *msg));
26457294Sbdevoid	splsoftclockassert __P((const char *msg));
26557294Sbdevoid	splsoftttyassert __P((const char *msg));
26657294Sbdevoid	splsoftvmassert __P((const char *msg));
26761077Sdfrvoid	splsofttqassert __P((const char *msg));
26857294Sbdevoid	splstatclockassert __P((const char *msg));
26957294Sbdevoid	splttyassert __P((const char *msg));
27057294Sbdevoid	splvmassert __P((const char *msg));
27157294Sbde#endif /* INVARIANT_SUPPORT */
27257294Sbde
27326312Speter/*
27426312Speter * XXX It's not clear how "machine independent" these will be yet, but
27526312Speter * they are used all over the place especially in pci drivers.  We would
27626312Speter * have to modify lots of drivers since <machine/cpufunc.h> no longer
27726312Speter * implicitly causes these to be defined when it #included <machine/spl.h>
27826312Speter */
27926312Speterextern intrmask_t bio_imask;	/* group of interrupts masked with splbio() */
28029683Sgibbsextern intrmask_t cam_imask;	/* group of interrupts masked with splcam() */
28126312Speterextern intrmask_t net_imask;	/* group of interrupts masked with splimp() */
28226312Speterextern intrmask_t stat_imask;	/* interrupts masked with splstatclock() */
28326312Speterextern intrmask_t tty_imask;	/* group of interrupts masked with spltty() */
28426312Speter
28526312Speter/* Read only */
28627585Sbdeextern const intrmask_t soft_imask;    /* interrupts masked with splsoft*() */
28726312Speterextern const intrmask_t softnet_imask; /* interrupt masked with splnet() */
28826312Speterextern const intrmask_t softtty_imask; /* interrupt masked with splsofttty() */
28926312Speter
29029509Sbde/*
29129509Sbde * Various callout lists.
29229509Sbde */
29317658Sjulian
29429509Sbde/* Exit callout list declarations. */
29529509Sbdetypedef void (*exitlist_fn) __P((struct proc *procp));
29617658Sjulian
29729509Sbdeint	at_exit __P((exitlist_fn function));
29829509Sbdeint	rm_at_exit __P((exitlist_fn function));
29917658Sjulian
30029509Sbde/* Fork callout list declarations. */
30129509Sbdetypedef void (*forklist_fn) __P((struct proc *parent, struct proc *child,
30229509Sbde				 int flags));
30327997Sjulian
30429509Sbdeint	at_fork __P((forklist_fn function));
30529509Sbdeint	rm_at_fork __P((forklist_fn function));
30627997Sjulian
30729509Sbde/*
30829509Sbde * Not exactly a callout LIST, but a callout entry.
30929509Sbde * Allow an external module to define a hardware watchdog tickler.
31029509Sbde * Normally a process would do this, but there are times when the
31129509Sbde * kernel needs to be able to hold off the watchdog, when the process
31229509Sbde * is not active, e.g., when dumping core.
31329509Sbde */
31429509Sbdetypedef void (*watchdog_tickle_fn) __P((void));
31529509Sbde
31629509Sbdeextern watchdog_tickle_fn	wdog_tickler;
31729509Sbde
31818884Sbde/*
31918884Sbde * Common `proc' functions are declared here so that proc.h can be included
32018884Sbde * less often.
32118884Sbde */
32265708Sjakeint	msleep __P((void *chan, struct mtx *mtx, int pri, const char *wmesg,
32365708Sjake		    int timo));
32465708Sjake#define	tsleep(chan, pri, wmesg, timo)	msleep(chan, NULL, pri, wmesg, timo)
32541971Sdillonint	asleep __P((void *chan, int pri, const char *wmesg, int timo));
32641971Sdillonint	await  __P((int pri, int timo));
32718884Sbdevoid	wakeup __P((void *chan));
32854471Sgreenvoid	wakeup_one __P((void *chan));
32918884Sbde
33047028Sphk/*
33147028Sphk * Common `dev_t' stuff are declared here to avoid #include poisoning
33247028Sphk */
33347028Sphk
33447028Sphkint major(dev_t x);
33547028Sphkint minor(dev_t x);
33647028Sphkdev_t makedev(int x, int y);
33747028Sphkudev_t dev2udev(dev_t x);
33847028Sphkdev_t udev2dev(udev_t x, int b);
33947028Sphkint uminor(udev_t dev);
34047028Sphkint umajor(udev_t dev);
34148859Sphkudev_t makeudev(int x, int y);
3422865Sbde#endif /* !_SYS_SYSTM_H_ */
343