1/* 2 * Copyright 2009, Colin G��nther, coling@gmx.de. 3 * Copyright 2007, Hugo Santos. All Rights Reserved. 4 * Distributed under the terms of the MIT License. 5 */ 6#ifndef _FBSD_COMPAT_SYS_SYSTM_H_ 7#define _FBSD_COMPAT_SYS_SYSTM_H_ 8 9 10#include <stdint.h> 11#include <stdio.h> 12#include <string.h> 13#include <strings.h> 14 15#include <machine/atomic.h> 16#include <machine/cpufunc.h> 17 18#include <sys/callout.h> 19#include <sys/cdefs.h> 20#include <sys/queue.h> 21 22#include <sys/libkern.h> 23 24__BEGIN_DECLS 25 26 27#define printf freebsd_printf 28int printf(const char *format, ...) __printflike(1, 2); 29 30 31#define ovbcopy(f, t, l) bcopy((f), (t), (l)) 32 33#if KDEBUG_LEVEL_2 34#define INVARIANTS 35#endif 36 37#if KDEBUG_LEVEL_1 38#define bootverbose 1 39#else 40#define bootverbose 0 41#endif 42 43#ifdef INVARIANTS 44#define KASSERT_FREEBSD(cond,msg) do { \ 45 if (!(cond)) \ 46 panic msg; \ 47} while (0) 48#define KASSERT(cond,msg) KASSERT_FREEBSD(cond,msg) 49#else 50#define KASSERT_FREEBSD(exp,msg) do {} while (0) 51#define KASSERT(cond,msg) KASSERT_FREEBSD(cond,msg) 52#endif 53 54#define DELAY(n) \ 55 do { \ 56 if (n < 1000) \ 57 spin(n); \ 58 else \ 59 snooze(n); \ 60 } while (0) 61 62#define cold 0 63 64void wakeup(void *); 65void wakeup_one(void *); 66 67#ifndef CTASSERT /* Allow lint to override */ 68#define CTASSERT(x) _Static_assert(x, "compile-time assertion failed") 69#endif 70 71 72static inline int 73copyin(const void * __restrict udaddr, void * __restrict kaddr, 74 size_t len) 75{ 76 return user_memcpy(kaddr, udaddr, len); 77} 78 79 80static inline int 81copyout(const void * __restrict kaddr, void * __restrict udaddr, 82 size_t len) 83{ 84 return user_memcpy(udaddr, kaddr, len); 85} 86 87 88static inline void log(int level, const char *fmt, ...) { } 89 90 91int snprintf(char *, size_t, const char *, ...) __printflike(3, 4); 92extern int sprintf(char *buf, const char *, ...); 93 94extern int driver_vprintf(const char *format, va_list vl); 95#define vprintf(fmt, vl) driver_vprintf(fmt, vl) 96 97extern int vsnprintf(char *, size_t, const char *, __va_list) 98 __printflike(3, 0); 99 100int msleep(void *, struct mtx *, int, const char *, int); 101int _pause(const char *, int); 102#define pause(waitMessage, timeout) _pause((waitMessage), (timeout)) 103#define msleep_spin(chan, mtx, wmesg, timo) \ 104 msleep(chan, mtx, PZERO, wmesg, timo) 105#define mtx_sleep msleep 106 107void critical_enter(void); 108void critical_exit(void); 109 110struct unrhdr; 111struct unrhdr *new_unrhdr(int low, int high, struct mtx *mutex); 112void delete_unrhdr(struct unrhdr *); 113int alloc_unr(struct unrhdr *); 114void free_unr(struct unrhdr *, u_int); 115 116extern char *getenv(const char *name); 117extern void freeenv(char *env); 118extern char *kern_getenv(const char *name); 119 120__END_DECLS 121 122#endif /* _FBSD_COMPAT_SYS_SYSTM_H_ */ 123