systm.h revision 56079
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 56079 2000-01-16 02:10:21Z jmb $
401541Srgrimes */
411541Srgrimes
422165Spaul#ifndef _SYS_SYSTM_H_
432865Sbde#define	_SYS_SYSTM_H_
442165Spaul
4549043Salc#include <machine/atomic.h>
461549Srgrimes#include <machine/cpufunc.h>
4756079Sjmb#include <machine/ipl.h>
4829683Sgibbs#include <sys/callout.h>
491549Srgrimes
5018883Sbdeextern int securelevel;		/* system security level (see init(8)) */
517090Sbde
527090Sbdeextern int cold;		/* nonzero if we are doing a cold boot */
531541Srgrimesextern const char *panicstr;	/* panic message */
5431337Sbdeextern int safepri;		/* safe ipl when cold or panicing */
551541Srgrimesextern char version[];		/* system version */
561541Srgrimesextern char copyright[];	/* system copyright */
571541Srgrimes
581541Srgrimesextern int nswap;		/* size of swap space */
591541Srgrimes
601541Srgrimesextern int selwait;		/* select timeout address */
611541Srgrimes
621541Srgrimesextern u_char curpriority;	/* priority of current process */
631541Srgrimes
641541Srgrimesextern int physmem;		/* physical memory */
651541Srgrimes
661541Srgrimesextern dev_t dumpdev;		/* dump device */
671541Srgrimesextern long dumplo;		/* offset into dumpdev */
681541Srgrimes
691541Srgrimesextern dev_t rootdev;		/* root device */
7036809Sbdeextern dev_t rootdevs[2];	/* possible root devices */
7136809Sbdeextern char *rootdevnames[2];	/* names of possible root devices */
721541Srgrimesextern struct vnode *rootvp;	/* vnode equivalent to above */
731541Srgrimes
741541Srgrimesextern int boothowto;		/* reboot flags, from console subsystem */
7515113Sbdeextern int bootverbose;		/* nonzero to print verbose messages */
761541Srgrimes
7742453Seivind#ifdef	INVARIANTS		/* The option is always available */
7842453Seivind#define	KASSERT(exp,msg)	do { if (!(exp)) panic msg; } while (0)
7956079Sjmb#define SPLSTRINGIZE(a) #a
8056079Sjmb#define SPLASSERT(level, msg)						\
8156079Sjmb	KASSERT(is_spl##level(), ("%s: not spl%s, cpl == 0x%08x\n",	\
8256079Sjmb		(msg), SPLSTRINGIZE(level), cpl))
8342408Seivind#else
8442453Seivind#define	KASSERT(exp,msg)
8556079Sjmb#define SPLASSERT(level, msg)
8642408Seivind#endif
8742408Seivind
881541Srgrimes/*
891541Srgrimes * General function declarations.
901541Srgrimes */
9130282Sphk
9233777Sbdestruct clockframe;
9330282Sphkstruct malloc_type;
9433777Sbdestruct proc;
9533777Sbdestruct timeval;
9633777Sbdestruct tty;
9733777Sbdestruct uio;
9830282Sphk
9916875Sbdevoid	Debugger __P((const char *msg));
1001541Srgrimesint	nullop __P((void));
1011541Srgrimesint	eopnotsupp __P((void));
10214508Shsuint	einval __P((void));
1031541Srgrimesint	seltrue __P((dev_t dev, int which, struct proc *p));
1043304Sphkint	ureadc __P((int, struct uio *));
10530282Sphkvoid	*hashinit __P((int count, struct malloc_type *type, u_long *hashmask));
10630282Sphkvoid	*phashinit __P((int count, struct malloc_type *type, u_long *nentries));
1071541Srgrimes
10817975Sbdevoid	cpu_boot __P((int));
10929683Sgibbsvoid	cpu_rootconf __P((void));
1101541Srgrimesvoid	tablefull __P((const char *));
11137614Sbdeint	addlog __P((const char *, ...)) __printflike(1, 2);
11218556Sbdeint	kvprintf __P((char const *, void (*)(int, void*), void *, int,
11337614Sbde		      _BSD_VA_LIST_)) __printflike(1, 0);
11449047Sdfrint	log __P((int, const char *, ...)) __printflike(2, 3);
11529509Sbdevoid	logwakeup __P((void));
11637614Sbdeint	printf __P((const char *, ...)) __printflike(1, 2);
11741479Sarchieint	snprintf __P((char *, size_t, const char *, ...)) __printflike(3, 4);
11837614Sbdeint	sprintf __P((char *buf, const char *, ...)) __printflike(2, 3);
11949047Sdfrint	uprintf __P((const char *, ...)) __printflike(1, 2);
12049047Sdfrint	vprintf __P((const char *, _BSD_VA_LIST_)) __printflike(1, 0);
12141479Sarchieint	vsnprintf __P((char *, size_t, const char *, _BSD_VA_LIST_)) __printflike(3, 0);
12238874Sacheint     vsprintf __P((char *buf, const char *, _BSD_VA_LIST_)) __printflike(2, 0);
12349047Sdfrint	ttyprintf __P((struct tty *, const char *, ...)) __printflike(2, 3);
12442680Smsmithint	sscanf __P((const char *, char const *, ...));
12542680Smsmithint	vsscanf __P((const char *, char const *, _BSD_VA_LIST_));
12654216Sarchielong	strtol __P((const char *, char **, int));
12754216Sarchieu_long	strtoul __P((const char *, char **, int));
12854216Sarchiequad_t	strtoq __P((const char *, char **, int));
12954216Sarchieu_quad_t strtouq __P((const char *, char **, int));
1301541Srgrimes
1318215Sdgvoid	bcopy __P((const void *from, void *to, size_t len));
1328215Sdgvoid	ovbcopy __P((const void *from, void *to, size_t len));
13356079Sjmb
13436735Sdfr#ifdef __i386__
13513414Sphkextern void	(*bzero) __P((void *buf, size_t len));
13636735Sdfr#else
13736735Sdfrvoid	bzero __P((void *buf, size_t len));
13836735Sdfr#endif
1391541Srgrimes
1408215Sdgvoid	*memcpy __P((void *to, const void *from, size_t len));
1418215Sdg
14213456Sbdeint	copystr __P((const void *kfaddr, void *kdaddr, size_t len,
14313456Sbde		size_t *lencopied));
14413456Sbdeint	copyinstr __P((const void *udaddr, void *kaddr, size_t len,
14513456Sbde		size_t *lencopied));
14613456Sbdeint	copyin __P((const void *udaddr, void *kaddr, size_t len));
14713456Sbdeint	copyout __P((const void *kaddr, void *udaddr, size_t len));
1481541Srgrimes
14913456Sbdeint	fubyte __P((const void *base));
1501541Srgrimesint	subyte __P((void *base, int byte));
1511541Srgrimesint	suibyte __P((void *base, int byte));
15236735Sdfrlong	fuword __P((const void *base));
15336735Sdfrint	suword __P((void *base, long word));
15444495Sbdeint	fusword __P((void *base));
15544495Sbdeint	susword __P((void *base, int word));
1561541Srgrimes
1571541Srgrimesvoid	realitexpire __P((void *));
1581541Srgrimes
1591541Srgrimesvoid	hardclock __P((struct clockframe *frame));
16032390Sphkvoid	softclock __P((void));
1611541Srgrimesvoid	statclock __P((struct clockframe *frame));
1621541Srgrimes
1631541Srgrimesvoid	startprofclock __P((struct proc *));
1641541Srgrimesvoid	stopprofclock __P((struct proc *));
1651541Srgrimesvoid	setstatclockrate __P((int hzrate));
1661541Srgrimes
16740096Smsmithchar	*getenv __P((char *name));
16842706Smsmithint	getenv_int __P((char *name, int *data));
16952946Smjacobquad_t	getenv_quad __P((char *name, quad_t *data));
17040096Smsmithextern char *kern_envp;
17140096Smsmith
17231960Snate#ifdef APM_FIXUP_CALLTODO
17331960Snatevoid	adjust_timeout_calltodo __P((struct timeval *time_change));
17431960Snate#endif /* APM_FIXUP_CALLTODO */
17531960Snate
1767109Sphk#include <sys/libkern.h>
1772112Swollman
1782112Swollman/* Initialize the world */
17929509Sbdevoid	consinit __P((void));
18029509Sbdevoid	cpu_initclocks __P((void));
18129509Sbdevoid	nchinit __P((void));
18229509Sbdevoid	usrinfoinit __P((void));
18329509Sbdevoid	vntblinit __P((void));
1842112Swollman
1857090Sbde/* Finalize the world. */
1867090Sbdevoid	shutdown_nice __P((void));
1877090Sbde
1887090Sbde/*
1897090Sbde * Kernel to clock driver interface.
1907090Sbde */
1917090Sbdevoid	inittodr __P((time_t base));
1927090Sbdevoid	resettodr __P((void));
1937090Sbdevoid	startrtclock __P((void));
1947090Sbde
1952112Swollman/* Timeouts */
19629509Sbdetypedef void timeout_t __P((void *));	/* timeout function type */
19729683Sgibbs#define CALLOUT_HANDLE_INITIALIZER(handle)	\
19829683Sgibbs	{ NULL }
1992112Swollman
20029683Sgibbsvoid	callout_handle_init __P((struct callout_handle *));
20129683Sgibbsstruct	callout_handle timeout __P((timeout_t *, void *, int));
20229683Sgibbsvoid	untimeout __P((timeout_t *, void *, struct callout_handle));
2032165Spaul
20438130Sbde/* Interrupt management */
20538130Sbde
20636735Sdfr#ifdef __i386__
20738130Sbdevoid		setdelayed __P((void));
20838130Sbdevoid		setsoftast __P((void));
20938130Sbdevoid		setsoftcambio __P((void));
21038130Sbdevoid		setsoftcamnet __P((void));
21138130Sbdevoid		setsoftclock __P((void));
21238130Sbdevoid		setsoftnet __P((void));
21338130Sbdevoid		setsofttty __P((void));
21438130Sbdevoid		setsoftvm __P((void));
21538130Sbdevoid		schedsoftcamnet __P((void));
21638130Sbdevoid		schedsoftcambio __P((void));
21738130Sbdevoid		schedsoftnet __P((void));
21838130Sbdevoid		schedsofttty __P((void));
21938130Sbdevoid		schedsoftvm __P((void));
22038130Sbdeintrmask_t	softclockpending __P((void));
22138130Sbdevoid		spl0 __P((void));
22238130Sbdeintrmask_t	splbio __P((void));
22338130Sbdeintrmask_t	splcam __P((void));
22438130Sbdeintrmask_t	splclock __P((void));
22538130Sbdeintrmask_t	splhigh __P((void));
22638130Sbdeintrmask_t	splimp __P((void));
22738130Sbdeintrmask_t	splnet __P((void));
22838130Sbdeintrmask_t	splsoftcam __P((void));
22938130Sbdeintrmask_t	splsoftcambio __P((void));
23038130Sbdeintrmask_t	splsoftcamnet __P((void));
23138130Sbdeintrmask_t	splsoftclock __P((void));
23238130Sbdeintrmask_t	splsofttty __P((void));
23338130Sbdeintrmask_t	splsoftvm __P((void));
23438130Sbdeintrmask_t	splstatclock __P((void));
23538130Sbdeintrmask_t	spltty __P((void));
23638130Sbdeintrmask_t	splvm __P((void));
23756079Sjmb#if defined (INVARIANT_SUPPORT)
23856079Sjmb/*
23956079Sjmb * The Alpha has all of these as static __inline.
24056079Sjmb */
24156079Sjmbint		is_splbio __P((void));
24256079Sjmbint		is_splcam __P((void));
24356079Sjmbint		is_splclock __P((void));
24456079Sjmbint		is_splhigh __P((void));
24556079Sjmbint		is_splimp __P((void));
24656079Sjmbint		is_splnet __P((void));
24756079Sjmbint		is_splsoftcam __P((void));
24856079Sjmbint		is_splsoftcambio __P((void));
24956079Sjmbint		is_splsoftcamnet __P((void));
25056079Sjmbint		is_splsoftclock __P((void));
25156079Sjmbint		is_splsofttty __P((void));
25256079Sjmbint		is_splsoftvm __P((void));
25356079Sjmbint		is_splstatclock __P((void));
25456079Sjmbint		is_spltty __P((void));
25556079Sjmbint		is_splvm __P((void));
25656079Sjmb#endif /* INVARIANT_SUPPORT */
25738130Sbdevoid		splx __P((intrmask_t ipl));
25838130Sbdevoid		splz __P((void));
25938130Sbde#endif /* __i386__ */
26026312Speter
26136735Sdfr#ifdef __alpha__
26236735Sdfr#include <machine/ipl.h>
26336735Sdfr#endif
26436735Sdfr
26526312Speter/*
26626312Speter * XXX It's not clear how "machine independent" these will be yet, but
26726312Speter * they are used all over the place especially in pci drivers.  We would
26826312Speter * have to modify lots of drivers since <machine/cpufunc.h> no longer
26926312Speter * implicitly causes these to be defined when it #included <machine/spl.h>
27026312Speter */
27126312Speterextern intrmask_t bio_imask;	/* group of interrupts masked with splbio() */
27229683Sgibbsextern intrmask_t cam_imask;	/* group of interrupts masked with splcam() */
27326312Speterextern intrmask_t net_imask;	/* group of interrupts masked with splimp() */
27426312Speterextern intrmask_t stat_imask;	/* interrupts masked with splstatclock() */
27526312Speterextern intrmask_t tty_imask;	/* group of interrupts masked with spltty() */
27626312Speter
27726312Speter/* Read only */
27827585Sbdeextern const intrmask_t soft_imask;    /* interrupts masked with splsoft*() */
27926312Speterextern const intrmask_t softnet_imask; /* interrupt masked with splnet() */
28026312Speterextern const intrmask_t softtty_imask; /* interrupt masked with splsofttty() */
28126312Speter
28229509Sbde/*
28329509Sbde * Various callout lists.
28429509Sbde */
28517658Sjulian
28629509Sbde/* Exit callout list declarations. */
28729509Sbdetypedef void (*exitlist_fn) __P((struct proc *procp));
28817658Sjulian
28929509Sbdeint	at_exit __P((exitlist_fn function));
29029509Sbdeint	rm_at_exit __P((exitlist_fn function));
29117658Sjulian
29229509Sbde/* Fork callout list declarations. */
29329509Sbdetypedef void (*forklist_fn) __P((struct proc *parent, struct proc *child,
29429509Sbde				 int flags));
29527997Sjulian
29629509Sbdeint	at_fork __P((forklist_fn function));
29729509Sbdeint	rm_at_fork __P((forklist_fn function));
29827997Sjulian
29929509Sbde/*
30029509Sbde * Not exactly a callout LIST, but a callout entry.
30129509Sbde * Allow an external module to define a hardware watchdog tickler.
30229509Sbde * Normally a process would do this, but there are times when the
30329509Sbde * kernel needs to be able to hold off the watchdog, when the process
30429509Sbde * is not active, e.g., when dumping core.
30529509Sbde */
30629509Sbdetypedef void (*watchdog_tickle_fn) __P((void));
30729509Sbde
30829509Sbdeextern watchdog_tickle_fn	wdog_tickler;
30929509Sbde
31018884Sbde/*
31118884Sbde * Common `proc' functions are declared here so that proc.h can be included
31218884Sbde * less often.
31318884Sbde */
31431333Sbdeint	tsleep __P((void *chan, int pri, const char *wmesg, int timo));
31541971Sdillonint	asleep __P((void *chan, int pri, const char *wmesg, int timo));
31641971Sdillonint	await  __P((int pri, int timo));
31718884Sbdevoid	wakeup __P((void *chan));
31854471Sgreenvoid	wakeup_one __P((void *chan));
31918884Sbde
32047028Sphk/*
32147028Sphk * Common `dev_t' stuff are declared here to avoid #include poisoning
32247028Sphk */
32347028Sphk
32447028Sphkint major(dev_t x);
32547028Sphkint minor(dev_t x);
32647028Sphkdev_t makedev(int x, int y);
32747028Sphkudev_t dev2udev(dev_t x);
32847028Sphkdev_t udev2dev(udev_t x, int b);
32947028Sphkint uminor(udev_t dev);
33047028Sphkint umajor(udev_t dev);
33148859Sphkudev_t makeudev(int x, int y);
3322865Sbde#endif /* !_SYS_SYSTM_H_ */
333