cross-tools: Do not install manpages during this stage.
[dragonfly.git] / sys / sys / systm.h
CommitLineData
984263bc
MD
1/*-
2 * Copyright (c) 1982, 1988, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
2c64e990 18 * 3. Neither the name of the University nor the names of its contributors
984263bc
MD
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * @(#)systm.h 8.7 (Berkeley) 3/29/95
35 * $FreeBSD: src/sys/sys/systm.h,v 1.111.2.18 2002/12/17 18:04:02 sam Exp $
36 */
37
38#ifndef _SYS_SYSTM_H_
39#define _SYS_SYSTM_H_
40
d9f3f6fa
CP
41#ifndef _KERNEL
42#error "This file should not be included by userland programs."
03d6a592 43#else
d9f3f6fa 44
e2565a42
MD
45#ifndef _MACHINE_TYPES_H_
46#include <machine/types.h>
47#endif
e2565a42 48#include <machine/stdarg.h>
984263bc
MD
49#include <machine/atomic.h>
50#include <machine/cpufunc.h>
984263bc
MD
51
52extern int securelevel; /* system security level (see init(8)) */
7e42c007 53extern int kernel_mem_readonly; /* disable writes to kernel memory */
984263bc
MD
54
55extern int cold; /* nonzero if we are doing a cold boot */
dbcd0c9b 56extern int tsleep_now_works; /* tsleep won't just return any more */
984263bc
MD
57extern const char *panicstr; /* panic message */
58extern int dumping; /* system is dumping */
59extern int safepri; /* safe ipl when cold or panicing */
315b8b8b 60extern int osreldate; /* System release date */
984263bc
MD
61extern char version[]; /* system version */
62extern char copyright[]; /* system copyright */
63
984263bc
MD
64extern int selwait; /* select timeout address */
65
66extern u_char curpriority; /* priority of current process */
a46b4a23 67extern int cpu_mwait_spin; /* typically set in machdep, used by lwkt */
984263bc 68
39d69dae 69extern long physmem; /* physical memory */
984263bc 70
b13267a5 71extern cdev_t dumpdev; /* dump device */
e0fc5693 72extern u_int64_t dumplo64; /* block number into dumpdev, start of dump */
984263bc 73
b13267a5
MD
74extern cdev_t rootdev; /* root device */
75extern cdev_t rootdevs[2]; /* possible root devices */
984263bc 76extern char *rootdevnames[2]; /* names of possible root devices */
c7841cbe 77extern char *ZeroPage;
984263bc
MD
78
79extern int boothowto; /* reboot flags, from console subsystem */
80extern int bootverbose; /* nonzero to print verbose messages */
81
82extern int maxusers; /* system tune hint */
83
17a9f566 84extern int ncpus; /* total number of cpus (real, hyper, virtual)*/
b45759e1
MD
85extern int ncpus_fit; /* round up to a power of 2 */
86extern int ncpus_fit_mask; /* ncpus_fit - 1 */
da3639ef 87extern int clocks_running; /* timing/timeout subsystem is operational */
17a9f566 88
0a80a445 89/* XXX TGEN these don't belong here, they're MD on pc64 */
527fddf7 90extern u_int cpu_feature; /* CPUID_* features */
97ee3efc 91extern u_int cpu_feature2; /* CPUID2_* features */
d87e79b9 92extern u_int cpu_mi_feature; /* CPU_MI_XXX machine-nonspecific features */
916e604f 93extern cpumask_t usched_global_cpumask;
97ee3efc 94
b9b7eb27
MD
95extern int nfs_diskless_valid; /* NFS diskless params were obtained */
96extern vm_paddr_t Maxmem; /* Highest physical memory address in system */
527fddf7 97
984263bc 98#ifdef INVARIANTS /* The option is always available */
a535608c
MD
99#define KASSERT(exp,msg) do { if (__predict_false(!(exp))) \
100 panic msg; } while (0)
6ef2e6b3
AH
101#define KKASSERT(exp) do { if (__predict_false(!(exp))) \
102 panic("assertion \"%s\" failed " \
103 "in %s at %s:%u", #exp, __func__, \
104 __FILE__, __LINE__); } while (0)
f64b567c 105#define __debugvar
984263bc 106#else
6b928fde 107#define KASSERT(exp,msg) do { } while (0)
108#define KKASSERT(exp) do { } while (0)
f64b567c 109#define __debugvar __attribute__((__unused__))
984263bc
MD
110#endif
111
112/*
113 * General function declarations.
114 */
115
88c4d2f6 116struct intrframe;
bf765287 117struct spinlock;
bed060de 118struct lock;
7f6220a9 119struct mtx;
362e59be 120struct lwkt_serialize;
984263bc
MD
121struct malloc_type;
122struct proc;
123struct timeval;
124struct tty;
125struct uio;
8ad65e08 126struct globaldata;
41c20dac 127struct thread;
4a22e893 128struct trapframe;
6bf59cd2 129struct user;
135d7199 130struct vmspace;
4e7c41c5 131struct savetls;
c8dfd00d 132struct krate;
09c0e0d6 133struct _jmp_buf;
984263bc 134
b153f746 135void Debugger (const char *msg);
7ce2998e 136void print_backtrace(int count);
b153f746 137void mi_gdinit (struct globaldata *gd, int cpu);
c1b91053 138void slab_gdinit (struct globaldata *gd);
6bf59cd2 139void mi_proc0init(struct globaldata *gd, struct user *proc0paddr);
09c0e0d6
SW
140int setjmp(struct _jmp_buf *) __returns_twice;
141void longjmp(struct _jmp_buf *, int) __dead2;
b153f746 142int nullop (void);
b13267a5 143int seltrue (cdev_t dev, int which);
b153f746
RG
144int ureadc (int, struct uio *);
145void *hashinit (int count, struct malloc_type *type, u_long *hashmask);
add23450 146void hashdestroy(void *vhashtbl, struct malloc_type *type, u_long hashmask);
b153f746 147void *phashinit (int count, struct malloc_type *type, u_long *nentries);
c02197ac
MD
148void *hashinit_ext (int count, size_t size,
149 struct malloc_type *type, u_long *hashmask);
150void *phashinit_ext (int count, size_t size,
151 struct malloc_type *type, u_long *nentries);
b153f746 152
4a22e893 153int cpu_sanitize_frame (struct trapframe *);
4e7c41c5 154int cpu_sanitize_tls (struct savetls *);
06615ccb 155void cpu_spinlock_contested(void);
e64c3faa 156void cpu_halt (void) __dead2;
704d2129 157void cpu_idle_halt (void);
527fddf7 158void cpu_reset (void);
b153f746
RG
159void cpu_boot (int);
160void cpu_rootconf (void);
135d7199
MD
161void cpu_vmspace_alloc(struct vmspace *);
162void cpu_vmspace_free(struct vmspace *);
bb47c072 163void cpu_vkernel_trap(struct trapframe *, int);
5a1223c1 164enum vmm_guest_type detect_virtual(void);
4e7c41c5 165void set_user_TLS(void);
431d0fef 166void set_vkernel_fp(struct trapframe *);
460426e6 167int kvm_access_check(vm_offset_t, vm_offset_t, int);
1184892f
MD
168
169vm_paddr_t kvtop(void *addr);
1184892f 170
d557434b
MD
171/*
172 * Old CRC32 API
173 */
174extern const uint32_t crc32_tab[];
984263bc 175uint32_t crc32(const void *buf, size_t size);
432417ed 176uint32_t crc32_ext(const void *buf, size_t size, uint32_t ocrc);
d557434b
MD
177
178/*
179 * Newer (fast) iscsi CRC32 APIs.
180 *
181 * NOTE: iscsi_crc32_ext() inverts ocrc input and output as expected,
182 * pass a seed of 0 for the equivalent of iscsi_crc32().
183 *
184 * calculate_crc32c() does not invert crc32c input and output
185 * to maintain FreeBSD API compatibility.
186 */
3a5aa68f
MD
187uint32_t iscsi_crc32(const void *buf, size_t size);
188uint32_t iscsi_crc32_ext(const void *buf, size_t size, uint32_t ocrc);
d557434b
MD
189uint32_t calculate_crc32c(uint32_t crc32c, const unsigned char *buffer,
190 unsigned int length);
191
b153f746
RG
192void init_param1 (void);
193void init_param2 (int physpages);
194void tablefull (const char *);
ae71ac09 195int kvcprintf (char const *, void (*)(int, void*), void *,
5400db7f 196 __va_list) __printf0like(1, 0);
5fddbda2 197void kvcreinitspin(void);
b153f746
RG
198int log (int, const char *, ...) __printflike(2, 3);
199void logwakeup (void);
200void log_console (struct uio *);
169276ba 201int kprintf (const char *, ...) __printflike(1, 2);
b84c2783 202void kprintf0 (const char *, ...) __printflike(1, 2);
c8dfd00d 203void krateprintf (struct krate *, const char *, ...) __printflike(2, 3);
169276ba 204int ksnprintf (char *, size_t, const char *, ...) __printflike(3, 4);
169276ba 205int ksprintf (char *buf, const char *, ...) __printflike(2, 3);
b153f746 206int uprintf (const char *, ...) __printflike(1, 2);
379210cb 207int kvprintf (const char *, __va_list) __printflike(1, 0);
93c46bf9
MD
208int kvsnprintf (char *, size_t, const char *,
209 __va_list) __printflike(3, 0);
ae71ac09 210int kvasnprintf (char **, size_t, const char *,
211 __va_list) __printflike(3, 0);
77dd98f3 212int kvsprintf (char *buf, const char *,
93c46bf9 213 __va_list) __printflike(2, 0);
b153f746 214int ttyprintf (struct tty *, const char *, ...) __printflike(2, 3);
37f44315 215void hexdump (const void *ptr, int length, const char *hdr, int flags);
399efd7f 216void kprint_cpuset(cpumask_t *mask);
37f44315
SW
217#define HD_COLUMN_MASK 0xff
218#define HD_DELIM_MASK 0xff00
219#define HD_OMIT_COUNT (1 << 16)
220#define HD_OMIT_HEX (1 << 17)
221#define HD_OMIT_CHARS (1 << 18)
f07483c3 222int ksscanf(const char *, char const *, ...)
466b1c70 223 __nonnull(1, 2) __scanflike(2, 3);
f07483c3 224int kvsscanf(const char *, char const *, __va_list)
466b1c70 225 __nonnull(1, 2) __scanflike(2, 0);
93c46bf9 226void kvasfree(char **);
44a09dd6 227
f07483c3
SW
228long strtol(const char *, char **, int) __nonnull(1);
229u_long strtoul(const char *, char **, int) __nonnull(1);
230quad_t strtoq(const char *, char **, int) __nonnull(1);
231u_quad_t strtouq(const char *, char **, int) __nonnull(1);
984263bc 232
f15db79e 233/*
7367f280
MD
234 * NOTE: some functions commonly used by device drivers may be passed
235 * pointers to volatile storage, volatile set to avoid warnings.
236 *
237 * NOTE: When using builtin's, GCC does enormous optimizations and makes
238 * a number of assumptions that can cause later unrelated conditionals
239 * to be optimized out. In the case of memset and memmove, GCC
240 * assumes that (to) and (from) cannot be NULL (even when (len) might
241 * be 0), and will optimize-out later NULL tests on (to) or (from).
f15db79e 242 */
7367f280
MD
243#if 1
244#define bcopy(from, to, len) \
245 __builtin_memmove(__DEQUALIFY(void *, (to)), \
246 __DEQUALIFY(void *, (from)), \
247 (len))
407e8612
MD
248#define memcpy(to, from, len) \
249 __builtin_memcpy(__DEQUALIFY(void *, (to)), \
250 __DEQUALIFY(void *, (from)), \
251 (len))
252#define memset(ptr, c, len) \
253 __builtin_memset(__DEQUALIFY(void *, (ptr)), (c), (len))
254#define memmove(to, from, len) \
255 __builtin_memmove(__DEQUALIFY(void *, (to)), \
256 __DEQUALIFY(void *, (from)), \
257 (len))
7367f280
MD
258#define bzero(buf, len) \
259 __builtin_memset(__DEQUALIFY(void *, (buf)), 0, (len))
260#else
407e8612
MD
261void bcopy(volatile const void *from, volatile void *to, size_t len)
262 __nonnull(1, 2);
263void *memcpy(void *to, const void *from, size_t len)
264 __nonnull(1, 2);
265void *memmove(void *, const void *, size_t);
266void *memset(void *, int, size_t);
f07483c3 267void bzero(volatile void *buf, size_t len) __nonnull(1);
7367f280
MD
268#endif
269void _bcopy(volatile const void *from, volatile void *to, size_t len)
270 __nonnull(1, 2);
407e8612
MD
271void *_memcpy(void *to, const void *from, size_t len)
272 __nonnull(1, 2);
273void *_memmove(void *, const void *, size_t);
274void *_memset(void *, int, size_t);
7367f280 275void _bzero(volatile void *buf, size_t len) __nonnull(1);
f07483c3 276void bzeront(volatile void *buf, size_t len) __nonnull(1);
984263bc 277
afd7f124
MD
278long kreadmem64(const void *addr);
279
b153f746 280int copystr (const void *kfaddr, void *kdaddr, size_t len,
466b1c70 281 size_t *lencopied) __nonnull(1, 2);
b153f746 282int copyinstr (const void *udaddr, void *kaddr, size_t len,
466b1c70
SW
283 size_t *lencopied) __nonnull(1, 2);
284int copyin(const void *udaddr, void *kaddr, size_t len) __nonnull(1, 2);
f07483c3 285int copyin_nofault(const void *udaddr, void *kaddr, size_t len)
466b1c70
SW
286 __nonnull(1, 2);
287int copyout(const void *kaddr, void *udaddr, size_t len) __nonnull(1, 2);
f07483c3 288int copyout_nofault(const void *kaddr, void *udaddr, size_t len)
466b1c70 289 __nonnull(1, 2);
984263bc 290
5947157e
MD
291int fubyte (const uint8_t *base);
292int subyte (uint8_t *base, uint8_t byte);
293int32_t fuword32 (const uint32_t *base);
294int64_t fuword64 (const uint64_t *base);
295int suword32 (uint32_t *base, int word);
296int suword64 (uint64_t *base, uint64_t word);
297uint32_t casu32(volatile uint32_t *p, uint32_t oldval, uint32_t newval);
298uint64_t casu64(volatile uint64_t *p, uint64_t oldval, uint64_t newval);
299uint32_t swapu32(volatile uint32_t *p, uint32_t val);
300uint64_t swapu64(volatile uint64_t *p, uint64_t val);
6481baf4
MD
301uint32_t fuwordadd32(volatile uint32_t *p, uint32_t val);
302uint64_t fuwordadd64(volatile uint64_t *p, uint64_t val);
984263bc 303
f0f0df1c 304void DELAY(int usec);
dbcd0c9b 305void DRIVERSLEEP(int usec);
984263bc 306
b153f746
RG
307void startprofclock (struct proc *);
308void stopprofclock (struct proc *);
309void setstatclockrate (int hzrate);
984263bc 310
a01a0504
TS
311/*
312 * Kernel environment support functions and sundry.
313 */
bc01a404 314char *kgetenv (const char *name);
a01a0504
TS
315int ksetenv(const char *name, const char *value);
316int kunsetenv(const char *name);
317void kfreeenv(char *env);
318int ktestenv(const char *name);
bc01a404
MD
319int kgetenv_int (const char *name, int *data);
320int kgetenv_string (const char *name, char *data, int size);
28a93126 321int kgetenv_ulong(const char *name, unsigned long *data);
bc01a404 322int kgetenv_quad (const char *name, quad_t *data);
79634a66 323int kgetenv_long(const char *name, long *data);
984263bc
MD
324extern char *kern_envp;
325
984263bc
MD
326#include <sys/libkern.h>
327
328/* Initialize the world */
a8a86718 329void mi_startup (void);
b153f746 330void nchinit (void);
984263bc
MD
331
332/* Finalize the world. */
b153f746 333void shutdown_nice (int);
984263bc
MD
334
335/*
336 * Kernel to clock driver interface.
337 */
b153f746
RG
338void inittodr (time_t base);
339void resettodr (void);
340void startrtclock (void);
984263bc
MD
341
342/* Timeouts */
b153f746 343typedef void timeout_t (void *); /* timeout function type */
984263bc
MD
344
345/* Interrupt management */
346
347/*
348 * For the alpha arch, some of these functions are static __inline, and
349 * the others should be.
350 */
bfc0d4cd 351#if defined(__x86_64__)
b153f746 352void setdelayed (void);
b153f746
RG
353void setsoftcambio (void);
354void setsoftcamnet (void);
0fb6ec96 355void setsoftunused02 (void);
b153f746 356void setsoftcrypto (void);
0fb6ec96 357void setsoftunused01 (void);
b153f746
RG
358void setsofttty (void);
359void setsoftvm (void);
360void setsofttq (void);
b153f746 361void schedsofttty (void);
b153f746 362void splz (void);
faaeffac 363void splz_check (void);
e5c52dd7
SZ
364void cpu_mmw_pause_int(int*, int, int, int);
365void cpu_mmw_pause_long(long*, long, int, int);
63cff036 366void cpu_smp_stopped(void);
bfc0d4cd 367#endif /* __x86_64__ */
984263bc 368
984263bc
MD
369/*
370 * Various callout lists.
371 */
372
373/* Exit callout list declarations. */
b153f746 374typedef void (*exitlist_fn) (struct thread *td);
984263bc 375
b153f746
RG
376int at_exit (exitlist_fn function);
377int rm_at_exit (exitlist_fn function);
984263bc
MD
378
379/* Fork callout list declarations. */
b153f746
RG
380typedef void (*forklist_fn) (struct proc *parent, struct proc *child,
381 int flags);
984263bc 382
b153f746
RG
383int at_fork (forklist_fn function);
384int rm_at_fork (forklist_fn function);
984263bc 385
5fddbda2 386extern struct globaldata *panic_cpu_gd;
984263bc
MD
387
388/*
389 * Common `proc' functions are declared here so that proc.h can be included
390 * less often.
391 */
5400db7f 392int tsleep(const volatile void *, int, const char *, int);
f07483c3
SW
393int ssleep(const volatile void *, struct spinlock *, int, const char *, int)
394 __nonnull(1);
395int lksleep(const volatile void *, struct lock *, int, const char *, int)
396 __nonnull(1);
397int mtxsleep(const volatile void *, struct mtx *, int, const char *, int)
398 __nonnull(1);
399int zsleep(const volatile void *, struct lwkt_serialize *, int, const char *, int)
400 __nonnull(1);
401void tsleep_interlock(const volatile void *, int) __nonnull(1);
ae8e83e6 402void tsleep_remove (struct thread *);
a22c590e 403int lwkt_sleep (const char *, int);
9a379a4a 404void tstop (void);
f07483c3
SW
405void wakeup(const volatile void *chan) __nonnull(1);
406void wakeup_one(const volatile void *chan) __nonnull(1);
407void wakeup_mycpu(const volatile void *chan) __nonnull(1);
408void wakeup_mycpu_one(const volatile void *chan) __nonnull(1);
409void wakeup_oncpu(struct globaldata *gd, const volatile void *chan)
410 __nonnull(2);
411void wakeup_oncpu_one(struct globaldata *gd, const volatile void *chan)
412 __nonnull(2);
413void wakeup_domain(const volatile void *chan, int domain) __nonnull(1);
414void wakeup_domain_one(const volatile void *chan, int domain) __nonnull(1);
b0da0c88
MD
415void wakeup_start_delayed(void);
416void wakeup_end_delayed(void);
984263bc
MD
417
418/*
b13267a5 419 * Common `cdev_t' stuff are declared here to avoid #include poisoning
984263bc
MD
420 */
421
b13267a5
MD
422int major(cdev_t x);
423int minor(cdev_t x);
424udev_t dev2udev(cdev_t x);
425cdev_t udev2dev(udev_t x, int b);
984263bc
MD
426int uminor(udev_t dev);
427int umajor(udev_t dev);
428udev_t makeudev(int x, int y);
03d6a592 429
c18a5ab7
FT
430/*
431 * Unit number allocation API. (kern/subr_unit.c)
432 */
433struct unrhdr;
434struct unrhdr *new_unrhdr(int low, int high, struct lock *lock);
435void delete_unrhdr(struct unrhdr *uh);
436int alloc_unr(struct unrhdr *uh);
437int alloc_unrl(struct unrhdr *uh);
438void free_unr(struct unrhdr *uh, u_int item);
439
5b447fa3
FT
440/*
441 * Population count algorithm using SWAR approach
442 * - "SIMD Within A Register".
443 */
444
445static __inline uint16_t
446bitcount16(uint32_t x)
447{
448
449 x = (x & 0x5555) + ((x & 0xaaaa) >> 1);
450 x = (x & 0x3333) + ((x & 0xcccc) >> 2);
451 x = (x + (x >> 4)) & 0x0f0f;
452 x = (x + (x >> 8)) & 0x00ff;
453 return (x);
454}
455
7b86369a
FT
456static __inline uint32_t
457bitcount32(uint32_t x)
458{
459
460 x = (x & 0x55555555) + ((x & 0xaaaaaaaa) >> 1);
461 x = (x & 0x33333333) + ((x & 0xcccccccc) >> 2);
462 x = (x + (x >> 4)) & 0x0f0f0f0f;
463 x = (x + (x >> 8));
464 x = (x + (x >> 16)) & 0x000000ff;
465 return (x);
466}
467
34a9f612
FT
468static __inline uint64_t
469bitcount64(uint64_t x)
470{
471
472 x = (x & 0x5555555555555555) + ((x & 0xaaaaaaaaaaaaaaaa) >> 1);
473 x = (x & 0x3333333333333333) + ((x & 0xcccccccccccccccc) >> 2);
474 x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f;
475 x = (x + (x >> 8));
476 x = (x + (x >> 16));
477 x = (x + (x >> 32)) & 0x000000ff;
478 return (x);
479}
480
03d6a592 481#endif /* _KERNEL */
984263bc 482#endif /* !_SYS_SYSTM_H_ */