source: rtems-libbsd/freebsd/sys/sys/systm.h @ e1e10cd

55-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since e1e10cd was e1e10cd, checked in by Chris Johns <chrisj@…>, on 04/23/16 at 07:37:27

waf: Add the ability to set FreeBSD options on the configure command line.

Add --freebsd-options to add specific FreeBSD compile time options to
the build. This is a developer tool.

  • Property mode set to 100644
File size: 17.6 KB
Line 
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.
18 * 4. Neither the name of the University nor the names of its contributors
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$
36 */
37
38#ifndef _SYS_SYSTM_H_
39#define _SYS_SYSTM_H_
40
41#include <machine/atomic.h>
42#include <machine/cpufunc.h>
43#include <sys/callout.h>
44#include <sys/cdefs.h>
45#include <sys/queue.h>
46#include <sys/stdint.h>         /* for people using printf mainly */
47
48#ifndef __rtems__
49extern int cold;                /* nonzero if we are doing a cold boot */
50extern int rebooting;           /* kern_reboot() has been called. */
51#else /* __rtems__ */
52/* In RTEMS there is no cold boot and reboot */
53#define cold 0
54#define rebooting 0
55#endif /* __rtems__ */
56#ifndef __rtems__
57extern const char *panicstr;    /* panic message */
58#else /* __rtems__ */
59#define panicstr NULL
60#endif /* __rtems__ */
61extern char version[];          /* system version */
62extern char compiler_version[]; /* compiler version */
63extern char copyright[];        /* system copyright */
64extern int kstack_pages;        /* number of kernel stack pages */
65
66extern u_long pagesizes[];      /* supported page sizes */
67extern long physmem;            /* physical memory */
68extern long realmem;            /* 'real' memory */
69
70extern char *rootdevnames[2];   /* names of possible root devices */
71
72extern int boothowto;           /* reboot flags, from console subsystem */
73#ifndef __rtems__
74extern int bootverbose;         /* nonzero to print verbose messages */
75#else /* __rtems__ */
76#ifdef BOOTVERBOSE
77extern int bootverbose;         /* nonzero to print verbose messages */
78#else
79#define bootverbose    0        /* Remove all verbose code for the standard RTEMS build */
80#endif /* BOOTVERBOSE */
81#endif /* __rtems__ */
82
83
84extern int maxusers;            /* system tune hint */
85extern int ngroups_max;         /* max # of supplemental groups */
86#ifndef __rtems__
87extern int vm_guest;            /* Running as virtual machine guest? */
88#else /* __rtems__ */
89#define vm_guest VM_GUEST_NO
90#endif /* __rtems__ */
91
92/*
93 * Detected virtual machine guest types. The intention is to expand
94 * and/or add to the VM_GUEST_VM type if specific VM functionality is
95 * ever implemented (e.g. vendor-specific paravirtualization features).
96 */
97enum VM_GUEST { VM_GUEST_NO = 0, VM_GUEST_VM, VM_GUEST_XEN };
98
99#ifdef  INVARIANTS              /* The option is always available */
100#define KASSERT(exp,msg) do {                                           \
101        if (__predict_false(!(exp)))                                    \
102                panic msg;                                              \
103} while (0)
104#define VNASSERT(exp, vp, msg) do {                                     \
105        if (__predict_false(!(exp))) {                                  \
106                vn_printf(vp, "VNASSERT failed\n");                     \
107                panic msg;                                              \
108        }                                                               \
109} while (0)
110#else
111#define KASSERT(exp,msg) do { \
112} while (0)
113
114#define VNASSERT(exp, vp, msg) do { \
115} while (0)
116#endif
117
118#ifndef CTASSERT        /* Allow lint to override */
119#define CTASSERT(x)     _Static_assert(x, "compile-time assertion failed")
120#endif
121
122/*
123 * Assert that a pointer can be loaded from memory atomically.
124 *
125 * This assertion enforces stronger alignment than necessary.  For example,
126 * on some architectures, atomicity for unaligned loads will depend on
127 * whether or not the load spans multiple cache lines.
128 */
129#define ASSERT_ATOMIC_LOAD_PTR(var, msg)                                \
130        KASSERT(sizeof(var) == sizeof(void *) &&                        \
131            ((uintptr_t)&(var) & (sizeof(void *) - 1)) == 0, msg)
132
133/*
134 * If we have already panic'd and this is the thread that called
135 * panic(), then don't block on any mutexes but silently succeed.
136 * Otherwise, the kernel will deadlock since the scheduler isn't
137 * going to run the thread that holds any lock we need.
138 */
139#ifndef __rtems__
140#define SCHEDULER_STOPPED() __predict_false(curthread->td_stopsched)
141#else /* __rtems__ */
142#define SCHEDULER_STOPPED() 0
143#endif /* __rtems__ */
144
145/*
146 * XXX the hints declarations are even more misplaced than most declarations
147 * in this file, since they are needed in one file (per arch) and only used
148 * in two files.
149 * XXX most of these variables should be const.
150 */
151extern int osreldate;
152extern int envmode;
153extern int hintmode;            /* 0 = off. 1 = config, 2 = fallback */
154extern int dynamic_kenv;
155extern struct mtx kenv_lock;
156extern char *kern_envp;
157extern char static_env[];
158extern char static_hints[];     /* by config for now */
159
160extern char **kenvp;
161
162extern const void *zero_region; /* address space maps to a zeroed page  */
163
164extern int unmapped_buf_allowed;
165extern int iosize_max_clamp;
166extern int devfs_iosize_max_clamp;
167#define IOSIZE_MAX      (iosize_max_clamp ? INT_MAX : SSIZE_MAX)
168#define DEVFS_IOSIZE_MAX        (devfs_iosize_max_clamp ? INT_MAX : SSIZE_MAX)
169
170/*
171 * General function declarations.
172 */
173
174struct inpcb;
175struct lock_object;
176struct malloc_type;
177struct mtx;
178struct proc;
179struct socket;
180struct thread;
181struct tty;
182struct ucred;
183struct uio;
184struct _jmp_buf;
185struct trapframe;
186
187#ifndef __rtems__
188int     setjmp(struct _jmp_buf *) __returns_twice;
189void    longjmp(struct _jmp_buf *, int) __dead2;
190#endif /* __rtems__ */
191int     dumpstatus(vm_offset_t addr, off_t count);
192int     nullop(void);
193int     eopnotsupp(void);
194int     ureadc(int, struct uio *);
195void    hashdestroy(void *, struct malloc_type *, u_long);
196void    *hashinit(int count, struct malloc_type *type, u_long *hashmask);
197void    *hashinit_flags(int count, struct malloc_type *type,
198    u_long *hashmask, int flags);
199#define HASH_NOWAIT     0x00000001
200#define HASH_WAITOK     0x00000002
201
202void    *phashinit(int count, struct malloc_type *type, u_long *nentries);
203void    g_waitidle(void);
204
205void    panic(const char *, ...) __dead2 __printflike(1, 2);
206
207void    cpu_boot(int);
208void    cpu_flush_dcache(void *, size_t);
209void    cpu_rootconf(void);
210#ifndef __rtems__
211void    critical_enter(void);
212void    critical_exit(void);
213#else /* __rtems__ */
214#include <rtems/score/threaddispatch.h>
215
216static __inline void
217critical_enter(void)
218{
219        _Thread_Dispatch_disable();
220}
221
222static __inline void
223critical_exit(void)
224{
225        _Thread_Dispatch_enable(_Per_CPU_Get());
226}
227#endif /* __rtems__ */
228void    init_param1(void);
229void    init_param2(long physpages);
230void    init_static_kenv(char *, size_t);
231void    tablefull(const char *);
232int     kvprintf(char const *, void (*)(int, void*), void *, int,
233            __va_list) __printflike(1, 0);
234void    log(int, const char *, ...) __printflike(2, 3);
235void    log_console(struct uio *);
236int     printf(const char *, ...) __printflike(1, 2);
237int     snprintf(char *, size_t, const char *, ...) __printflike(3, 4);
238int     sprintf(char *buf, const char *, ...) __printflike(2, 3);
239int     uprintf(const char *, ...) __printflike(1, 2);
240int     vprintf(const char *, __va_list) __printflike(1, 0);
241int     vsnprintf(char *, size_t, const char *, __va_list) __printflike(3, 0);
242int     vsnrprintf(char *, size_t, int, const char *, __va_list) __printflike(4, 0);
243int     vsprintf(char *buf, const char *, __va_list) __printflike(2, 0);
244int     ttyprintf(struct tty *, const char *, ...) __printflike(2, 3);
245int     sscanf(const char *, char const *, ...) __nonnull(1) __nonnull(2);
246int     vsscanf(const char *, char const *, __va_list) __nonnull(1) __nonnull(2);
247long    strtol(const char *, char **, int) __nonnull(1);
248u_long  strtoul(const char *, char **, int) __nonnull(1);
249quad_t  strtoq(const char *, char **, int) __nonnull(1);
250u_quad_t strtouq(const char *, char **, int) __nonnull(1);
251void    tprintf(struct proc *p, int pri, const char *, ...) __printflike(3, 4);
252void    hexdump(const void *ptr, int length, const char *hdr, int flags);
253#define HD_COLUMN_MASK  0xff
254#define HD_DELIM_MASK   0xff00
255#define HD_OMIT_COUNT   (1 << 16)
256#define HD_OMIT_HEX     (1 << 17)
257#define HD_OMIT_CHARS   (1 << 18)
258
259#define ovbcopy(f, t, l) bcopy((f), (t), (l))
260#ifndef __rtems__
261void    bcopy(const void *from, void *to, size_t len) __nonnull(1) __nonnull(2);
262void    bzero(void *buf, size_t len) __nonnull(1);
263#else /* __rtems__ */
264#define bcopy(src, dst, len) memmove((dst), (src), (len))
265#define bzero(buf, size) memset((buf), 0, (size))
266#endif /* __rtems__ */
267
268void    *memcpy(void *to, const void *from, size_t len) __nonnull(1) __nonnull(2);
269void    *memmove(void *dest, const void *src, size_t n) __nonnull(1) __nonnull(2);
270
271int     copystr(const void * __restrict kfaddr, void * __restrict kdaddr,
272            size_t len, size_t * __restrict lencopied)
273            __nonnull(1) __nonnull(2);
274#ifndef __rtems__
275int     copyinstr(const void * __restrict udaddr, void * __restrict kaddr,
276            size_t len, size_t * __restrict lencopied)
277            __nonnull(1) __nonnull(2);
278int     copyin(const void * __restrict udaddr, void * __restrict kaddr,
279            size_t len) __nonnull(1) __nonnull(2);
280int     copyin_nofault(const void * __restrict udaddr, void * __restrict kaddr,
281            size_t len) __nonnull(1) __nonnull(2);
282int     copyout(const void * __restrict kaddr, void * __restrict udaddr,
283            size_t len) __nonnull(1) __nonnull(2);
284int     copyout_nofault(const void * __restrict kaddr, void * __restrict udaddr,
285            size_t len) __nonnull(1) __nonnull(2);
286#else /* __rtems__ */
287static inline int __nonnull(1) __nonnull(2)
288copyinstr(const void * __restrict udaddr, void * __restrict kaddr,
289            size_t len, size_t * __restrict lencopied)
290{
291        if (lencopied != NULL) {
292                *lencopied = len;
293        }
294
295        memcpy(kaddr, udaddr, len);
296
297        return (0);
298}
299
300static inline int __nonnull(1) __nonnull(2)
301copyin(const void * __restrict udaddr, void * __restrict kaddr,
302    size_t len)
303{
304        memcpy(kaddr, udaddr, len);
305
306        return (0);
307}
308
309static inline int __nonnull(1) __nonnull(2)
310copyin_nofault(const void * __restrict udaddr, void * __restrict kaddr,
311    size_t len)
312{
313        return copyin(udaddr, kaddr, len);
314}
315
316static inline int __nonnull(1) __nonnull(2)
317copyout(const void * __restrict kaddr, void * __restrict udaddr,
318    size_t len)
319{
320        memcpy(udaddr, kaddr, len);
321
322        return (0);
323}
324
325static inline int __nonnull(1) __nonnull(2)
326copyout_nofault(const void * __restrict kaddr, void * __restrict udaddr,
327    size_t len)
328{
329        return copyout(kaddr, udaddr, len);
330}
331#endif /* __rtems__ */
332
333#ifndef __rtems__
334int     fubyte(const void *base);
335#else /* __rtems__ */
336static inline int
337fubyte(const void *base)
338{
339  const unsigned char *byte_base = (const unsigned char *)base;
340
341  return byte_base[0];
342}
343#endif /* __rtems__ */
344long    fuword(const void *base);
345int     fuword16(void *base);
346int32_t fuword32(const void *base);
347int64_t fuword64(const void *base);
348int     subyte(void *base, int byte);
349int     suword(void *base, long word);
350int     suword16(void *base, int word);
351int     suword32(void *base, int32_t word);
352int     suword64(void *base, int64_t word);
353uint32_t casuword32(volatile uint32_t *base, uint32_t oldval, uint32_t newval);
354u_long   casuword(volatile u_long *p, u_long oldval, u_long newval);
355
356void    realitexpire(void *);
357
358int     sysbeep(int hertz, int period);
359
360void    hardclock(int usermode, uintfptr_t pc);
361void    hardclock_cnt(int cnt, int usermode);
362void    hardclock_cpu(int usermode);
363void    hardclock_sync(int cpu);
364void    softclock(void *);
365void    statclock(int usermode);
366void    statclock_cnt(int cnt, int usermode);
367void    profclock(int usermode, uintfptr_t pc);
368void    profclock_cnt(int cnt, int usermode, uintfptr_t pc);
369
370int     hardclockintr(void);
371
372void    startprofclock(struct proc *);
373void    stopprofclock(struct proc *);
374void    cpu_startprofclock(void);
375void    cpu_stopprofclock(void);
376void    cpu_idleclock(void);
377void    cpu_activeclock(void);
378extern int      cpu_deepest_sleep;
379extern int      cpu_disable_c2_sleep;
380extern int      cpu_disable_c3_sleep;
381
382#ifndef __rtems__
383int     cr_cansee(struct ucred *u1, struct ucred *u2);
384int     cr_canseesocket(struct ucred *cred, struct socket *so);
385int     cr_canseeinpcb(struct ucred *cred, struct inpcb *inp);
386#else /* __rtems__ */
387#define cr_cansee(u1, u2) 0
388#define cr_canseesocket(cred, so) 0
389#define cr_canseeinpcb(cred, inp) 0
390#endif /* __rtems__ */
391
392char    *getenv(const char *name);
393void    freeenv(char *env);
394int     getenv_int(const char *name, int *data);
395int     getenv_uint(const char *name, unsigned int *data);
396int     getenv_long(const char *name, long *data);
397int     getenv_ulong(const char *name, unsigned long *data);
398int     getenv_string(const char *name, char *data, int size);
399int     getenv_quad(const char *name, quad_t *data);
400#ifndef __rtems__
401int     setenv(const char *name, const char *value);
402#endif /* __rtems__ */
403int     unsetenv(const char *name);
404int     testenv(const char *name);
405
406typedef uint64_t (cpu_tick_f)(void);
407void set_cputicker(cpu_tick_f *func, uint64_t freq, unsigned var);
408extern cpu_tick_f *cpu_ticks;
409uint64_t cpu_tickrate(void);
410uint64_t cputick2usec(uint64_t tick);
411
412#ifdef APM_FIXUP_CALLTODO
413struct timeval;
414void    adjust_timeout_calltodo(struct timeval *time_change);
415#endif /* APM_FIXUP_CALLTODO */
416
417#include <sys/libkern.h>
418
419/* Initialize the world */
420void    consinit(void);
421void    cpu_initclocks(void);
422void    cpu_initclocks_bsp(void);
423void    cpu_initclocks_ap(void);
424void    usrinfoinit(void);
425
426/* Finalize the world */
427void    kern_reboot(int) __dead2;
428void    shutdown_nice(int);
429
430/* Timeouts */
431typedef void timeout_t(void *); /* timeout function type */
432#define CALLOUT_HANDLE_INITIALIZER(handle)      \
433        { NULL }
434
435void    callout_handle_init(struct callout_handle *);
436struct  callout_handle timeout(timeout_t *, void *, int);
437void    untimeout(timeout_t *, void *, struct callout_handle);
438caddr_t kern_timeout_callwheel_alloc(caddr_t v);
439void    kern_timeout_callwheel_init(void);
440
441/* Stubs for obsolete functions that used to be for interrupt management */
442#ifdef __rtems__
443typedef int intrmask_t;
444#endif /* __rtems__ */
445static __inline void            spl0(void)              { return; }
446static __inline intrmask_t      splbio(void)            { return 0; }
447static __inline intrmask_t      splcam(void)            { return 0; }
448static __inline intrmask_t      splclock(void)          { return 0; }
449static __inline intrmask_t      splhigh(void)           { return 0; }
450static __inline intrmask_t      splimp(void)            { return 0; }
451static __inline intrmask_t      splnet(void)            { return 0; }
452static __inline intrmask_t      splsoftcam(void)        { return 0; }
453static __inline intrmask_t      splsoftclock(void)      { return 0; }
454static __inline intrmask_t      splsofttty(void)        { return 0; }
455static __inline intrmask_t      splsoftvm(void)         { return 0; }
456static __inline intrmask_t      splsofttq(void)         { return 0; }
457static __inline intrmask_t      splstatclock(void)      { return 0; }
458static __inline intrmask_t      spltty(void)            { return 0; }
459static __inline intrmask_t      splvm(void)             { return 0; }
460static __inline void            splx(intrmask_t ipl __unused)   { return; }
461
462/*
463 * Common `proc' functions are declared here so that proc.h can be included
464 * less often.
465 */
466int     _sleep(void *chan, struct lock_object *lock, int pri, const char *wmesg,
467            int timo) __nonnull(1);
468#define msleep(chan, mtx, pri, wmesg, timo)                             \
469        _sleep((chan), &(mtx)->lock_object, (pri), (wmesg), (timo))
470#ifndef __rtems__
471int     msleep_spin(void *chan, struct mtx *mtx, const char *wmesg, int timo)
472            __nonnull(1);
473#else /* __rtems__ */
474#define msleep_spin(chan, mtx, wmesg, timo)                             \
475        msleep((chan), (mtx), 0, (wmesg), (timo))
476#endif /* __rtems__ */
477#ifdef __rtems__
478#include <unistd.h>
479#define pause _bsd_pause
480#endif /* __rtems__ */
481int     pause(const char *wmesg, int timo);
482#define tsleep(chan, pri, wmesg, timo)                                  \
483        _sleep((chan), NULL, (pri), (wmesg), (timo))
484void    wakeup(void *chan) __nonnull(1);
485void    wakeup_one(void *chan) __nonnull(1);
486
487/*
488 * Common `struct cdev *' stuff are declared here to avoid #include poisoning
489 */
490
491struct cdev;
492dev_t dev2udev(struct cdev *x);
493const char *devtoname(struct cdev *cdev);
494
495int poll_no_poll(int events);
496
497/* XXX: Should be void nanodelay(u_int nsec); */
498void    DELAY(int usec);
499
500/* Root mount holdback API */
501struct root_hold_token;
502
503struct root_hold_token *root_mount_hold(const char *identifier);
504void root_mount_rel(struct root_hold_token *h);
505void root_mount_wait(void);
506int root_mounted(void);
507
508
509/*
510 * Unit number allocation API. (kern/subr_unit.c)
511 */
512struct unrhdr;
513struct unrhdr *new_unrhdr(int low, int high, struct mtx *mutex);
514void delete_unrhdr(struct unrhdr *uh);
515void clean_unrhdr(struct unrhdr *uh);
516void clean_unrhdrl(struct unrhdr *uh);
517int alloc_unr(struct unrhdr *uh);
518int alloc_unr_specific(struct unrhdr *uh, u_int item);
519int alloc_unrl(struct unrhdr *uh);
520void free_unr(struct unrhdr *uh, u_int item);
521
522/*
523 * Population count algorithm using SWAR approach
524 * - "SIMD Within A Register".
525 */
526static __inline uint32_t
527bitcount32(uint32_t x)
528{
529
530        x = (x & 0x55555555) + ((x & 0xaaaaaaaa) >> 1);
531        x = (x & 0x33333333) + ((x & 0xcccccccc) >> 2);
532        x = (x + (x >> 4)) & 0x0f0f0f0f;
533        x = (x + (x >> 8));
534        x = (x + (x >> 16)) & 0x000000ff;
535        return (x);
536}
537
538static __inline uint16_t
539bitcount16(uint32_t x)
540{
541
542        x = (x & 0x5555) + ((x & 0xaaaa) >> 1);
543        x = (x & 0x3333) + ((x & 0xcccc) >> 2);
544        x = (x + (x >> 4)) & 0x0f0f;
545        x = (x + (x >> 8)) & 0x00ff;
546        return (x);
547}
548
549#endif /* !_SYS_SYSTM_H_ */
Note: See TracBrowser for help on using the repository browser.