code:
/*-
 * Copyright (c) 1991, 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * This code is derived from software contributed to Berkeley by
 * Berkeley Software Design, Inc.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	@(#)cdefs.h	8.8 (Berkeley) 1/9/95
 * $FreeBSD: release/9.0.0/sys/sys/cdefs.h 218824 2011-02-18 21:44:53Z nwhitehorn $
 */

#ifndef	_SYS_CDEFS_H_
#define	_SYS_CDEFS_H_

#if defined(__cplusplus)
#define	__BEGIN_DECLS	extern "C" {
#define	__END_DECLS	}
#else
#define	__BEGIN_DECLS
#define	__END_DECLS
#endif

/*
 * This code has been put in place to help reduce the addition of
 * compiler specific defines in FreeBSD code.  It helps to aid in
 * having a compiler-agnostic source tree.
 */

#if defined(__GNUC__) || defined(__INTEL_COMPILER)

#if __GNUC__ >= 3 || defined(__INTEL_COMPILER)
#define __GNUCLIKE_ASM 3
#define __GNUCLIKE_MATH_BUILTIN_CONSTANTS
#else
#define __GNUCLIKE_ASM 2
#endif
#define __GNUCLIKE___TYPEOF 1
#define __GNUCLIKE___OFFSETOF 1
#define __GNUCLIKE___SECTION 1

#ifndef __INTEL_COMPILER
# define __GNUCLIKE_CTOR_SECTION_HANDLING 1
#endif

#define __GNUCLIKE_BUILTIN_CONSTANT_P 1
# if defined(__INTEL_COMPILER) && defined(__cplusplus) \
    && __INTEL_COMPILER < 800
#  undef __GNUCLIKE_BUILTIN_CONSTANT_P
# endif

#if (__GNUC_MINOR__ > 95 || __GNUC__ >= 3) && !defined(__INTEL_COMPILER)
# define __GNUCLIKE_BUILTIN_VARARGS 1
# define __GNUCLIKE_BUILTIN_STDARG 1
# define __GNUCLIKE_BUILTIN_VAALIST 1
#endif

#if defined(__GNUC__)
# define __GNUC_VA_LIST_COMPATIBILITY 1
#endif

#ifndef __INTEL_COMPILER
# define __GNUCLIKE_BUILTIN_NEXT_ARG 1
# define __GNUCLIKE_MATH_BUILTIN_RELOPS
#endif

#define __GNUCLIKE_BUILTIN_MEMCPY 1

/* XXX: if __GNUC__ >= 2: not tested everywhere originally, where replaced */
#define __CC_SUPPORTS_INLINE 1
#define __CC_SUPPORTS___INLINE 1
#define __CC_SUPPORTS___INLINE__ 1

#define __CC_SUPPORTS___FUNC__ 1
#define __CC_SUPPORTS_WARNING 1

#define __CC_SUPPORTS_VARADIC_XXX 1 /* see varargs.h */

#define __CC_SUPPORTS_DYNAMIC_ARRAY_INIT 1

#endif /* __GNUC__ || __INTEL_COMPILER */

/*
 * Macro to test if we're using a specific version of gcc or later.
 */
#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
#define	__GNUC_PREREQ__(ma, mi)	\
	(__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi))
#else
#define	__GNUC_PREREQ__(ma, mi)	0
#endif

/*
 * The __CONCAT macro is used to concatenate parts of symbol names, e.g.
 * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
 * The __CONCAT macro is a bit tricky to use if it must work in non-ANSI
 * mode -- there must be no spaces between its arguments, and for nested
 * __CONCAT's, all the __CONCAT's must be at the left.  __CONCAT can also
 * concatenate double-quoted strings produced by the __STRING macro, but
 * this only works with ANSI C.
 *
 * __XSTRING is like __STRING, but it expands any macros in its argument
 * first.  It is only available with ANSI C.
 */
#if defined(__STDC__) || defined(__cplusplus)
#define	__P(protos)	protos		/* full-blown ANSI C */
#define	__CONCAT1(x,y)	x ## y
#define	__CONCAT(x,y)	__CONCAT1(x,y)
#define	__STRING(x)	#x		/* stringify without expanding x */
#define	__XSTRING(x)	__STRING(x)	/* expand x, then stringify */

#define	__const		const		/* define reserved names to standard */
#define	__signed	signed
#define	__volatile	volatile
#if defined(__cplusplus)
#define	__inline	inline		/* convert to C++ keyword */
#else
#if !(defined(__CC_SUPPORTS___INLINE))
#define	__inline			/* delete GCC keyword */
#endif /* ! __CC_SUPPORTS___INLINE */
#endif /* !__cplusplus */

#else	/* !(__STDC__ || __cplusplus) */
#define	__P(protos)	()		/* traditional C preprocessor */
#define	__CONCAT(x,y)	x/**/y
#define	__STRING(x)	"x"

#if !defined(__CC_SUPPORTS___INLINE)
#define	__const				/* delete pseudo-ANSI C keywords */
#define	__inline
#define	__signed
#define	__volatile
/*
 * In non-ANSI C environments, new programs will want ANSI-only C keywords
 * deleted from the program and old programs will want them left alone.
 * When using a compiler other than gcc, programs using the ANSI C keywords
 * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS.
 * When using "gcc -traditional", we assume that this is the intent; if
 * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone.
 */
#ifndef	NO_ANSI_KEYWORDS
#define	const				/* delete ANSI C keywords */
#define	inline
#define	signed
#define	volatile
#endif	/* !NO_ANSI_KEYWORDS */
#endif	/* !__CC_SUPPORTS___INLINE */
#endif	/* !(__STDC__ || __cplusplus) */

/*
 * Compiler-dependent macros to help declare dead (non-returning) and
 * pure (no side effects) functions, and unused variables.  They are
 * null except for versions of gcc that are known to support the features
 * properly (old versions of gcc-2 supported the dead and pure features
 * in a different (wrong) way).  If we do not provide an implementation
 * for a given compiler, let the compile fail if it is told to use
 * a feature that we cannot live without.
 */
#ifdef lint
#define	__dead2
#define	__pure2
#define	__unused
#define	__packed
#define	__aligned(x)
#define	__section(x)
#else
#if !__GNUC_PREREQ__(2, 5) && !defined(__INTEL_COMPILER)
#define	__dead2
#define	__pure2
#define	__unused
#endif
#if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7 && !defined(__INTEL_COMPILER)
#define	__dead2		__attribute__((__noreturn__))
#define	__pure2		__attribute__((__const__))
#define	__unused
/* XXX Find out what to do for __packed, __aligned and __section */
#endif
#if __GNUC_PREREQ__(2, 7)
#define	__dead2		__attribute__((__noreturn__))
#define	__pure2		__attribute__((__const__))
#define	__unused	__attribute__((__unused__))
#define	__used		__attribute__((__used__))
#define	__packed	__attribute__((__packed__))
#define	__aligned(x)	__attribute__((__aligned__(x)))
#define	__section(x)	__attribute__((__section__(x)))
#endif
#if defined(__INTEL_COMPILER)
#define __dead2		__attribute__((__noreturn__))
#define __pure2		__attribute__((__const__))
#define __unused	__attribute__((__unused__))
#define __used		__attribute__((__used__))
#define __packed	__attribute__((__packed__))
#define __aligned(x)	__attribute__((__aligned__(x)))
#define __section(x)	__attribute__((__section__(x)))
#endif
#endif

#if __GNUC_PREREQ__(2, 96)
// __attribute__((__malloc__))
#define	__malloc_like
#define	__pure		__attribute__((__pure__))
#else
#define	__malloc_like
#define	__pure
#endif

#if __GNUC_PREREQ__(3, 1) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800)
#define	__always_inline	__attribute__((__always_inline__))
#else
#define	__always_inline
#endif

#if __GNUC_PREREQ__(3, 1)
#define	__noinline	__attribute__ ((__noinline__))
#else
#define	__noinline
#endif

#if __GNUC_PREREQ__(3, 3)
#define __nonnull(x)	__attribute__((__nonnull__(x)))
#else
#define __nonnull(x)
#endif

/* XXX: should use `#if __STDC_VERSION__ < 199901'. */
#if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER)
#define	__func__	NULL
#endif

#if (defined(__INTEL_COMPILER) || (defined(__GNUC__) && __GNUC__ >= 2)) && !defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901
#define	__LONG_LONG_SUPPORTED
#endif

/*
 * GCC 2.95 provides `__restrict' as an extension to C90 to support the
 * C99-specific `restrict' type qualifier.  We happen to use `__restrict' as
 * a way to define the `restrict' type qualifier without disturbing older
 * software that is unaware of C99 keywords.
 */
#if !(__GNUC__ == 2 && __GNUC_MINOR__ == 95)
#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901 || defined(lint)
#define	__restrict
#else
#define	__restrict	restrict
#endif
#endif

/*
 * GNU C version 2.96 adds explicit branch prediction so that
 * the CPU back-end can hint the processor and also so that
 * code blocks can be reordered such that the predicted path
 * sees a more linear flow, thus improving cache behavior, etc.
 *
 * The following two macros provide us with a way to utilize this
 * compiler feature.  Use __predict_true() if you expect the expression
 * to evaluate to true, and __predict_false() if you expect the
 * expression to evaluate to false.
 *
 * A few notes about usage:
 *
 *	* Generally, __predict_false() error condition checks (unless
 *	  you have some _strong_ reason to do otherwise, in which case
 *	  document it), and/or __predict_true() `no-error' condition
 *	  checks, assuming you want to optimize for the no-error case.
 *
 *	* Other than that, if you don't know the likelihood of a test
 *	  succeeding from empirical or other `hard' evidence, don't
 *	  make predictions.
 *
 *	* These are meant to be used in places that are run `a lot'.
 *	  It is wasteful to make predictions in code that is run
 *	  seldomly (e.g. at subsystem initialization time) as the
 *	  basic block reordering that this affects can often generate
 *	  larger code.
 */
#if __GNUC_PREREQ__(2, 96)
#define __predict_true(exp)     __builtin_expect((exp), 1)
#define __predict_false(exp)    __builtin_expect((exp), 0)
#else
#define __predict_true(exp)     (exp)
#define __predict_false(exp)    (exp)
#endif

#if __GNUC_PREREQ__(4, 2)
#define	__hidden	__attribute__((__visibility__("hidden")))
#define	__exported	__attribute__((__visibility__("default")))
#else
#define	__hidden
#define	__exported
#endif

/*
 * We define this here since <stddef.h>, <sys/queue.h>, and <sys/types.h>
 * require it.
 */
#if __GNUC_PREREQ__(4, 1)
#define __offsetof(type, field)	 __builtin_offsetof(type, field)
#else
#ifndef __cplusplus
#define	__offsetof(type, field)	((size_t)(&((type *)0)->field))
#else
#define __offsetof(type, field)					\
  (__offsetof__ (reinterpret_cast <size_t>			\
                 (&reinterpret_cast <const volatile char &>	\
                  (static_cast<type *> (0)->field))))
#endif
#endif
#define	__rangeof(type, start, end) \
	(__offsetof(type, end) - __offsetof(type, start))

/*
 * Compiler-dependent macros to declare that functions take printf-like
 * or scanf-like arguments.  They are null except for versions of gcc
 * that are known to support the features properly (old versions of gcc-2
 * didn't permit keeping the keywords out of the application namespace).
 */
#if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER)
#define	__printflike(fmtarg, firstvararg)
#define	__scanflike(fmtarg, firstvararg)
#define	__format_arg(fmtarg)
#else
#define	__printflike(fmtarg, firstvararg) \
	    __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
#define	__scanflike(fmtarg, firstvararg) \
	    __attribute__((__format__ (__scanf__, fmtarg, firstvararg)))
#define	__format_arg(fmtarg)	__attribute__((__format_arg__ (fmtarg)))
#endif

/* Compiler-dependent macros that rely on FreeBSD-specific extensions. */
#if __FreeBSD_cc_version >= 300001 && defined(__GNUC__) && !defined(__INTEL_COMPILER)
#define	__printf0like(fmtarg, firstvararg) \
	    __attribute__((__format__ (__printf0__, fmtarg, firstvararg)))
#else
#define	__printf0like(fmtarg, firstvararg)
#endif

#if defined(__GNUC__) || defined(__INTEL_COMPILER)
#ifndef __INTEL_COMPILER
#define	__strong_reference(sym,aliassym)	\
	extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym)))
#endif
#ifdef __STDC__
#define	__weak_reference(sym,alias)	\
	__asm__(".weak " #alias);	\
	__asm__(".equ "  #alias ", " #sym)
#define	__warn_references(sym,msg)	\
	__asm__(".section .gnu.warning." #sym);	\
	__asm__(".asciz \"" msg "\"");	\
	__asm__(".previous")
#define	__sym_compat(sym,impl,verid)	\
	__asm__(".symver " #impl ", " #sym "@" #verid)
#define	__sym_default(sym,impl,verid)	\
	__asm__(".symver " #impl ", " #sym "@@" #verid)
#else
#define	__weak_reference(sym,alias)	\
	__asm__(".weak alias");		\
	__asm__(".equ alias, sym")
#define	__warn_references(sym,msg)	\
	__asm__(".section .gnu.warning.sym"); \
	__asm__(".asciz \"msg\"");	\
	__asm__(".previous")
#define	__sym_compat(sym,impl,verid)	\
	__asm__(".symver impl, sym@verid")
#define	__sym_default(impl,sym,verid)	\
	__asm__(".symver impl, sym@@verid")
#endif	/* __STDC__ */
#endif	/* __GNUC__ || __INTEL_COMPILER */

#define	__GLOBL1(sym)	__asm__(".globl " #sym)
#define	__GLOBL(sym)	__GLOBL1(sym)

#if defined(__GNUC__) || defined(__INTEL_COMPILER)
#define	__IDSTRING(name,string)	__asm__(".ident\t\"" string "\"")
#else
/*
 * The following definition might not work well if used in header files,
 * but it should be better than nothing.  If you want a "do nothing"
 * version, then it should generate some harmless declaration, such as:
 *    #define __IDSTRING(name,string)	struct __hack
 */
#define	__IDSTRING(name,string)	static const char name[] __unused = string
#endif

/*
 * Embed the rcs id of a source file in the resulting library.  Note that in
 * more recent ELF binutils, we use .ident allowing the ID to be stripped.
 * Usage:
 *	__FBSDID("$FreeBSD: release/9.0.0/sys/sys/cdefs.h 218824 2011-02-18 21:44:53Z nwhitehorn $");
 */
#ifndef	__FBSDID
#if !defined(lint) && !defined(STRIP_FBSDID)
#define	__FBSDID(s)	__IDSTRING(__CONCAT(__rcsid_,__LINE__),s)
#else
#define	__FBSDID(s)	struct __hack
#endif
#endif

#ifndef	__RCSID
#ifndef	NO__RCSID
#define	__RCSID(s)	__IDSTRING(__CONCAT(__rcsid_,__LINE__),s)
#else
#define	__RCSID(s)	struct __hack
#endif
#endif

#ifndef	__RCSID_SOURCE
#ifndef	NO__RCSID_SOURCE
#define	__RCSID_SOURCE(s)	__IDSTRING(__CONCAT(__rcsid_source_,__LINE__),s)
#else
#define	__RCSID_SOURCE(s)	struct __hack
#endif
#endif

#ifndef	__SCCSID
#ifndef	NO__SCCSID
#define	__SCCSID(s)	__IDSTRING(__CONCAT(__sccsid_,__LINE__),s)
#else
#define	__SCCSID(s)	struct __hack
#endif
#endif

#ifndef	__COPYRIGHT
#ifndef	NO__COPYRIGHT
#define	__COPYRIGHT(s)	__IDSTRING(__CONCAT(__copyright_,__LINE__),s)
#else
#define	__COPYRIGHT(s)	struct __hack
#endif
#endif

#ifndef	__DECONST
#define	__DECONST(type, var)	((type)(uintptr_t)(const void *)(var))
#endif

#ifndef	__DEVOLATILE
#define	__DEVOLATILE(type, var)	((type)(uintptr_t)(volatile void *)(var))
#endif

#ifndef	__DEQUALIFY
#define	__DEQUALIFY(type, var)	((type)(uintptr_t)(const volatile void *)(var))
#endif

/*-
 * The following definitions are an extension of the behavior originally
 * implemented in <sys/_posix.h>, but with a different level of granularity.
 * POSIX.1 requires that the macros we test be defined before any standard
 * header file is included.
 *
 * Here's a quick run-down of the versions:
 *  defined(_POSIX_SOURCE)		1003.1-1988
 *  _POSIX_C_SOURCE == 1		1003.1-1990
 *  _POSIX_C_SOURCE == 2		1003.2-1992 C Language Binding Option
 *  _POSIX_C_SOURCE == 199309		1003.1b-1993
 *  _POSIX_C_SOURCE == 199506		1003.1c-1995, 1003.1i-1995,
 *					and the omnibus ISO/IEC 9945-1: 1996
 *  _POSIX_C_SOURCE == 200112		1003.1-2001
 *  _POSIX_C_SOURCE == 200809		1003.1-2008
 *
 * In addition, the X/Open Portability Guide, which is now the Single UNIX
 * Specification, defines a feature-test macro which indicates the version of
 * that specification, and which subsumes _POSIX_C_SOURCE.
 *
 * Our macros begin with two underscores to avoid namespace screwage.
 */

/* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */
#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1
#undef _POSIX_C_SOURCE		/* Probably illegal, but beyond caring now. */
#define	_POSIX_C_SOURCE		199009
#endif

/* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2. */
#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 2
#undef _POSIX_C_SOURCE
#define	_POSIX_C_SOURCE		199209
#endif

/* Deal with various X/Open Portability Guides and Single UNIX Spec. */
#ifdef _XOPEN_SOURCE
#if _XOPEN_SOURCE - 0 >= 700
#define	__XSI_VISIBLE		700
#undef _POSIX_C_SOURCE
#define	_POSIX_C_SOURCE		200809
#elif _XOPEN_SOURCE - 0 >= 600
#define	__XSI_VISIBLE		600
#undef _POSIX_C_SOURCE
#define	_POSIX_C_SOURCE		200112
#elif _XOPEN_SOURCE - 0 >= 500
#define	__XSI_VISIBLE		500
#undef _POSIX_C_SOURCE
#define	_POSIX_C_SOURCE		199506
#endif
#endif

/*
 * Deal with all versions of POSIX.  The ordering relative to the tests above is
 * important.
 */
#if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)
#define	_POSIX_C_SOURCE		198808
#endif
#ifdef _POSIX_C_SOURCE
#if _POSIX_C_SOURCE >= 200809
#define	__POSIX_VISIBLE		200809
#define	__ISO_C_VISIBLE		1999
#elif _POSIX_C_SOURCE >= 200112
#define	__POSIX_VISIBLE		200112
#define	__ISO_C_VISIBLE		1999
#elif _POSIX_C_SOURCE >= 199506
#define	__POSIX_VISIBLE		199506
#define	__ISO_C_VISIBLE		1990
#elif _POSIX_C_SOURCE >= 199309
#define	__POSIX_VISIBLE		199309
#define	__ISO_C_VISIBLE		1990
#elif _POSIX_C_SOURCE >= 199209
#define	__POSIX_VISIBLE		199209
#define	__ISO_C_VISIBLE		1990
#elif _POSIX_C_SOURCE >= 199009
#define	__POSIX_VISIBLE		199009
#define	__ISO_C_VISIBLE		1990
#else
#define	__POSIX_VISIBLE		198808
#define	__ISO_C_VISIBLE		0
#endif /* _POSIX_C_SOURCE */
#else
/*-
 * Deal with _ANSI_SOURCE:
 * If it is defined, and no other compilation environment is explicitly
 * requested, then define our internal feature-test macros to zero.  This
 * makes no difference to the preprocessor (undefined symbols in preprocessing
 * expressions are defined to have value zero), but makes it more convenient for
 * a test program to print out the values.
 *
 * If a program mistakenly defines _ANSI_SOURCE and some other macro such as
 * _POSIX_C_SOURCE, we will assume that it wants the broader compilation
 * environment (and in fact we will never get here).
 */
#if defined(_ANSI_SOURCE)	/* Hide almost everything. */
#define	__POSIX_VISIBLE		0
#define	__XSI_VISIBLE		0
#define	__BSD_VISIBLE		0
#define	__ISO_C_VISIBLE		1990
#elif defined(_C99_SOURCE)	/* Localism to specify strict C99 env. */
#define	__POSIX_VISIBLE		0
#define	__XSI_VISIBLE		0
#define	__BSD_VISIBLE		0
#define	__ISO_C_VISIBLE		1999
#else				/* Default environment: show everything. */
#define	__POSIX_VISIBLE		200809
#define	__XSI_VISIBLE		700
#define	__BSD_VISIBLE		1
#define	__ISO_C_VISIBLE		1999
#endif
#endif

#endif /* !_SYS_CDEFS_H_ */


code:
/*
 * 16 Feb 93	Julian Elischer	(julian@dialix.oz.au)
 *
 * $FreeBSD: release/9.0.0/sys/sys/cdio.h 141031 2005-01-30 08:12:37Z sobomax $
 */

/*
<1>	Fixed a conflict with ioctl usage.  There were two different
	functions using code #25.  Made file formatting consistent.
	Added two new ioctl codes: door closing and audio pitch playback.
	Added a STEREO union called STEREO.
	5-Mar-95  Frank Durda IV	bsdmail@nemesis.lonestar.org

<2>	Added a new ioctl that allows you to find out what capabilities
	a drive has and what commands it will accept.  This allows a
	user application to only offer controls (buttons, sliders, etc)
	for functions that drive can actually do.   Things it can't do
	can disappear or be greyed-out (like some other system).
	If the driver doesn't respond to this call, well, handle it the
	way you used to do it.
	2-Apr-95  Frank Durda IV	bsdmail@nemesis.lonestar.org
*/

/* Shared between kernel & process */

#ifndef	_SYS_CDIO_H_
#define	_SYS_CDIO_H_

#ifndef _KERNEL
#include <sys/types.h>
#endif
#include <sys/ioccom.h>

union msf_lba {
	struct {
		unsigned char   unused;
		unsigned char   minute;
		unsigned char   second;
		unsigned char   frame;
	} msf;
	int     lba;    /* network byte order */
	u_char	addr[4];
};

struct cd_toc_entry {
#if BYTE_ORDER == LITTLE_ENDIAN
	u_int	:8;
	u_int	control:4;
	u_int	addr_type:4;
#else
	u_int	:8;
	u_int	addr_type:4;
	u_int	control:4;
#endif
	u_char  track;
	u_int	:8;
	union msf_lba  addr;
};

struct cd_sub_channel_header {
	u_int	:8;
	u_char	audio_status;
#define CD_AS_AUDIO_INVALID        0x00
#define CD_AS_PLAY_IN_PROGRESS     0x11
#define CD_AS_PLAY_PAUSED          0x12
#define CD_AS_PLAY_COMPLETED       0x13
#define CD_AS_PLAY_ERROR           0x14
#define CD_AS_NO_STATUS            0x15
	u_char	data_len[2];
};

struct cd_sub_channel_position_data {
	u_char	data_format;
	u_int	control:4;
	u_int	addr_type:4;
	u_char	track_number;
	u_char	index_number;
	union msf_lba  absaddr;
	union msf_lba  reladdr;
};

struct cd_sub_channel_media_catalog {
        u_char  data_format;
        u_int   :8;
        u_int   :8;
        u_int   :8;
        u_int   :7;
        u_int   mc_valid:1;
        u_char  mc_number[15];
};

struct cd_sub_channel_track_info {
        u_char  data_format;
        u_int   :8;
        u_char  track_number;
        u_int   :8;
        u_int   :7;
        u_int   ti_valid:1;
        u_char  ti_number[15];
};

struct cd_sub_channel_info {
	struct cd_sub_channel_header header;
	union {
		struct cd_sub_channel_position_data position;
		struct cd_sub_channel_media_catalog media_catalog;
		struct cd_sub_channel_track_info track_info;
	} what;
};

/***************************************************************\
* Ioctls for the CD drive					*
\***************************************************************/

struct ioc_play_track {
	u_char	start_track;
	u_char	start_index;
	u_char	end_track;
	u_char	end_index;
};
#define	CDIOCPLAYTRACKS	_IOW('c',1,struct ioc_play_track)

struct ioc_play_blocks {
	int	blk;
	int	len;
};
#define	CDIOCPLAYBLOCKS	_IOW('c',2,struct ioc_play_blocks)

struct ioc_read_subchannel {
	u_char address_format;
#define CD_LBA_FORMAT	1
#define CD_MSF_FORMAT	2
	u_char data_format;
#define CD_SUBQ_DATA		0
#define CD_CURRENT_POSITION	1
#define CD_MEDIA_CATALOG	2
#define CD_TRACK_INFO		3
	u_char track;
	int	data_len;
	struct  cd_sub_channel_info *data;
};
#define CDIOCREADSUBCHANNEL _IOWR('c', 3 , struct ioc_read_subchannel )

struct ioc_toc_header {
	u_short len;
	u_char  starting_track;
	u_char  ending_track;
};
#define CDIOREADTOCHEADER _IOR('c',4,struct ioc_toc_header)

struct ioc_read_toc_entry {
	u_char	address_format;
	u_char	starting_track;
	u_short	data_len;
	struct  cd_toc_entry *data;
};
#define CDIOREADTOCENTRYS _IOWR('c',5,struct ioc_read_toc_entry)

struct ioc_read_toc_single_entry {
	u_char	address_format;
	u_char	track;
	struct  cd_toc_entry entry;
};
#define CDIOREADTOCENTRY _IOWR('c',6,struct ioc_read_toc_single_entry)

struct ioc_patch {
	u_char	patch[4];	/* one for each channel */
};
#define	CDIOCSETPATCH	_IOW('c',9,struct ioc_patch)

struct ioc_vol {
	u_char	vol[4];	/* one for each channel */
};
#define	CDIOCGETVOL	_IOR('c',10,struct ioc_vol)

#define	CDIOCSETVOL	_IOW('c',11,struct ioc_vol)

#define	CDIOCSETMONO	_IO('c',12)

#define	CDIOCSETSTERIO	_IO('c',13)
#define	CDIOCSETSTEREO	_IO('c',13)

#define	CDIOCSETMUTE	_IO('c',14)

#define	CDIOCSETLEFT	_IO('c',15)

#define	CDIOCSETRIGHT	_IO('c',16)

#define	CDIOCSETDEBUG	_IO('c',17)

#define	CDIOCCLRDEBUG	_IO('c',18)

#define	CDIOCPAUSE	_IO('c',19)

#define	CDIOCRESUME	_IO('c',20)

#define	CDIOCRESET	_IO('c',21)

#define	CDIOCSTART	_IO('c',22)

#define	CDIOCSTOP	_IO('c',23)

#define	CDIOCEJECT	_IO('c',24)

struct ioc_play_msf {
	u_char	start_m;
	u_char	start_s;
	u_char	start_f;
	u_char	end_m;
	u_char	end_s;
	u_char	end_f;
};
#define	CDIOCPLAYMSF	_IOW('c',25,struct ioc_play_msf)

#define	CDIOCALLOW	_IO('c',26)

#define	CDIOCPREVENT	_IO('c',27)

				/*<1>For drives that support it, this*/
				/*<1>causes the drive to close its door*/
				/*<1>and make the media (if any) ready*/
#define CDIOCCLOSE	_IO('c',28)	/*<1>*/

struct ioc_pitch {		/*<1>For drives that support it, this*/
				/*<1>call instructs the drive to play the*/
	short	speed;		/*<1>audio at a faster or slower-than-normal*/
};				/*<1>rate. -32767 to -1 is slower, 0==normal,*/
				/*<1>and 1 to 32767 is faster.  LSB bits are*/
				/*<1>discarded first by drives with less res.*/
#define	CDIOCPITCH	_IOW('c',29,struct ioc_pitch)	/*<1>*/

struct ioc_capability {			/*<2>*/
	u_long	play_function;		/*<2>*/
#define CDDOPLAYTRK	0x00000001	/*<2>Can Play tracks/index*/
#define	CDDOPLAYMSF	0x00000002	/*<2>Can Play msf to msf*/
#define	CDDOPLAYBLOCKS	0x00000004	/*<2>Can Play range of blocks*/
#define	CDDOPAUSE	0x00000100	/*<2>Output can be paused*/
#define	CDDORESUME	0x00000200	/*<2>Output can be resumed*/
#define	CDDORESET	0x00000400	/*<2>Drive can be completely reset*/
#define	CDDOSTART	0x00000800	/*<2>Audio can be started*/
#define CDDOSTOP	0x00001000	/*<2>Audio can be stopped*/
#define CDDOPITCH	0x00002000	/*<2>Audio pitch */

	u_long	routing_function;	/*<2>*/
#define CDREADVOLUME	0x00000001	/*<2>Volume settings can be read*/
#define CDSETVOLUME	0x00000002	/*<2>Volume settings can be set*/
#define	CDSETMONO	0x00000100	/*<2>Output can be set to mono*/
#define CDSETSTEREO	0x00000200	/*<2>Output can be set to stereo (def)*/
#define	CDSETLEFT	0x00000400	/*<2>Output can be set to left only*/
#define	CDSETRIGHT	0x00000800	/*<2>Output can be set to right only*/
#define	CDSETMUTE	0x00001000	/*<2>Output can be muted*/
#define CDSETPATCH	0x00008000	/*<2>Direct routing control allowed*/

	u_long	special_function;	/*<2>*/
#define	CDDOEJECT	0x00000001	/*<2>The tray can be opened*/
#define	CDDOCLOSE	0x00000002	/*<2>The tray can be closed*/
#define	CDDOLOCK	0x00000004	/*<2>The tray can be locked*/
#define CDREADHEADER	0x00000100	/*<2>Can read Table of Contents*/
#define	CDREADENTRIES	0x00000200	/*<2>Can read TOC Entries*/
#define	CDREADSUBQ	0x00000200	/*<2>Can read Subchannel info*/
#define CDREADRW	0x00000400	/*<2>Can read subcodes R-W*/
#define	CDHASDEBUG	0x00004000	/*<2>The tray has dynamic debugging*/
};					/*<2>*/

#define	CDIOCCAPABILITY	_IOR('c',30,struct ioc_capability)	/*<2>*/

/*
 * Special version of CDIOCREADSUBCHANNEL which assumes that
 * ioc_read_subchannel->data points to the kernel memory. For
 * use in compatibility layers.
 */
#define CDIOCREADSUBCHANNEL_SYSSPACE _IOWR('c', 31, struct ioc_read_subchannel)

#endif /* !_SYS_CDIO_H_ */

repo_name: veiledmerc/mira

license: mit


code:
/*-
 * Copyright (c) 2000,2001,2002 S�ren Schmidt <sos@FreeBSD.org>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer,
 *    without modification, immediately at the beginning of the file.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * $FreeBSD: release/9.0.0/sys/sys/cdrio.h 105421 2002-10-18 22:03:39Z njl $
 */

#ifndef	_SYS_CDRIO_H_
#define	_SYS_CDRIO_H_

#include <sys/ioccom.h>

struct cdr_track {
        int datablock_type;         	/* data type code */
#define CDR_DB_RAW              0x0     /* 2352 bytes of raw data */
#define CDR_DB_RAW_PQ           0x1     /* 2368 bytes raw data + P/Q subchan */
#define CDR_DB_RAW_PW           0x2     /* 2448 bytes raw data + P-W subchan */
#define CDR_DB_RAW_PW_R         0x3     /* 2448 bytes raw data + P-W raw sub */
#define CDR_DB_RES_4            0x4     /* reserved */
#define CDR_DB_RES_5            0x5     /* reserved */
#define CDR_DB_RES_6            0x6     /* reserved */
#define CDR_DB_VS_7             0x7     /* vendor specific */
#define CDR_DB_ROM_MODE1        0x8     /* 2048 bytes Mode 1 (ISO/IEC 10149) */
#define CDR_DB_ROM_MODE2        0x9     /* 2336 bytes Mode 2 (ISO/IEC 10149) */
#define CDR_DB_XA_MODE1         0xa     /* 2048 bytes Mode 1 (CD-ROM XA 1) */
#define CDR_DB_XA_MODE2_F1      0xb     /* 2056 bytes Mode 2 (CD-ROM XA 1) */
#define CDR_DB_XA_MODE2_F2      0xc     /* 2324 bytes Mode 2 (CD-ROM XA 2) */
#define CDR_DB_XA_MODE2_MIX     0xd     /* 2332 bytes Mode 2 (CD-ROM XA 1/2) */
#define CDR_DB_RES_14           0xe     /* reserved */
#define CDR_DB_VS_15            0xf     /* vendor specific */

	int preemp;			/* preemphasis if audio track*/
	int test_write;			/* use test writes, laser turned off */
};

struct cdr_cue_entry {
	u_int8_t adr:4;
    	u_int8_t ctl:4;
	u_int8_t track;
	u_int8_t index;
	u_int8_t dataform;
	u_int8_t scms;
	u_int8_t min;
	u_int8_t sec;
	u_int8_t frame;
};

struct cdr_cuesheet {
    	int32_t len;
	struct cdr_cue_entry *entries;
	int session_format;
#define CDR_SESS_CDROM          0x00
#define CDR_SESS_CDI            0x10
#define CDR_SESS_CDROM_XA       0x20

	int session_type;
#define CDR_SESS_NONE           0x00
#define CDR_SESS_FINAL          0x01
#define CDR_SESS_RESERVED       0x02
#define CDR_SESS_MULTI          0x03

	int test_write;
};

struct cdr_format_capacity {
	u_int32_t blocks;
	u_int32_t reserved:2;
	u_int32_t type:6;
	u_int32_t param:24;
};

struct cdr_format_capacities {
	u_int8_t reserved1[3];
	u_int8_t length;
	u_int32_t blocks;
	u_int32_t type:2;
	u_int32_t reserved2:6;
	u_int32_t block_size:24;
	struct cdr_format_capacity format[32];
};

struct cdr_format_params {
	u_int8_t reserved;
	u_int8_t vs:1;
	u_int8_t immed:1;
	u_int8_t try_out:1;
	u_int8_t ip:1;
	u_int8_t stpf:1;
	u_int8_t dcrt:1;
	u_int8_t dpry:1;
	u_int8_t fov:1;
	u_int16_t length;
	struct cdr_format_capacity format;
};

#define CDRIOCBLANK		_IOW('c', 100, int)
#define CDR_B_ALL		0x0
#define CDR_B_MIN		0x1
#define CDR_B_SESSION		0x6

#define CDRIOCNEXTWRITEABLEADDR	_IOR('c', 101, int)
#define CDRIOCINITWRITER	_IOW('c', 102, int)
#define CDRIOCINITTRACK		_IOW('c', 103, struct cdr_track)
#define CDRIOCSENDCUE		_IOW('c', 104, struct cdr_cuesheet)
#define CDRIOCFLUSH		_IO('c', 105)
#define CDRIOCFIXATE		_IOW('c', 106, int)
#define CDRIOCREADSPEED		_IOW('c', 107, int)
#define CDRIOCWRITESPEED	_IOW('c', 108, int)
#define CDR_MAX_SPEED		0xffff
#define CDRIOCGETBLOCKSIZE	_IOR('c', 109, int)
#define CDRIOCSETBLOCKSIZE	_IOW('c', 110, int)
#define CDRIOCGETPROGRESS	_IOR('c', 111, int)
#define CDRIOCREADFORMATCAPS	_IOR('c', 112, struct cdr_format_capacities)
#define CDRIOCFORMAT		_IOW('c', 113, struct cdr_format_params)

#endif /* !_SYS_CDRIO_H_ */


code:
/*-
 * Copyright (c) 2007, Juniper Networks, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the author nor the names of any co-contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD: release/9.0.0/sys/sys/cfictl.h 188156 2009-02-05 18:12:07Z sam $
 */

#ifndef _SYS_CFICTL_H_
#define _SYS_CFICTL_H_

/*
 * Allow reading of the CFI query structure.
 */

struct cfiocqry {
	unsigned long	offset;
	unsigned long	count;
	u_char		*buffer;
};

#define	CFIOCQRY	_IOWR('q', 0, struct cfiocqry)

/* Intel StrataFlash Protection Register support */
#define	CFIOCGFACTORYPR	_IOR('q', 1, uint64_t)	/* get factory protection reg */
#define	CFIOCGOEMPR	_IOR('q', 2, uint64_t)	/* get oem protection reg */
#define	CFIOCSOEMPR	_IOW('q', 3, uint64_t)	/* set oem protection reg */
#define	CFIOCGPLR	_IOR('q', 4, uint32_t)	/* get protection lock reg */
#define	CFIOCSPLR	_IO('q', 5)		/* set protection log reg */
#endif	/* _SYS_CFICTL_H_ */


code:
/*-
 * Copyright (c) 1996 Jason R. Thorpe <thorpej@and.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgements:
 *	This product includes software developed by Jason R. Thorpe
 *	for And Communications, http://www.and.com/
 * 4. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD: release/9.0.0/sys/sys/chio.h 139825 2005-01-07 02:29:27Z imp $
 */

#ifndef	_SYS_CHIO_H_
#define	_SYS_CHIO_H_

#ifndef _KERNEL
#include <sys/types.h>
#endif
#include <sys/ioccom.h>

/*
 * Element types.  Used as "to" and "from" type indicators in move
 * and exchange operations.
 *
 * Note that code in sys/scsi/ch.c relies on these values (uses them
 * as offsets in an array, and other evil), so don't muck with them
 * unless you know what you're doing.
 */
#define CHET_MT		0	/* medium transport (picker) */
#define CHET_ST		1	/* storage transport (slot) */
#define CHET_IE		2	/* import/export (portal) */
#define CHET_DT		3	/* data transfer (drive) */
#define CHET_MAX	CHET_DT

/*
 * Maximum length of a volume identification string
 */
#define CH_VOLTAG_MAXLEN	32

/*
 * Structure used to execute a MOVE MEDIUM command.
 */
struct changer_move {
	u_int16_t	cm_fromtype;	/* element type to move from */
	u_int16_t	cm_fromunit;	/* logical unit of from element */
	u_int16_t	cm_totype;	/* element type to move to */
	u_int16_t	cm_tounit;	/* logical unit of to element */
	u_int16_t	cm_flags;	/* misc. flags */
};

/* cm_flags */
#define CM_INVERT	0x01	/* invert media */

/*
 * Structure used to execute an EXCHANGE MEDIUM command.  In an
 * exchange operation, the following steps occur:
 *
 *	- media from source is moved to first destination.
 *
 *	- media previously occupying first destination is moved
 *	  to the second destination.
 *
 * The second destination may or may not be the same as the source.
 * In the case of a simple exchange, the source and second destination
 * are the same.
 */
struct changer_exchange {
	u_int16_t	ce_srctype;	/* element type of source */
	u_int16_t	ce_srcunit;	/* logical unit of source */
	u_int16_t	ce_fdsttype;	/* element type of first destination */
	u_int16_t	ce_fdstunit;	/* logical unit of first destination */
	u_int16_t	ce_sdsttype;	/* element type of second destination */
	u_int16_t	ce_sdstunit;	/* logical unit of second destination */
	u_int16_t	ce_flags;	/* misc. flags */
};

/* ce_flags */
#define CE_INVERT1	0x01	/* invert media 1 */
#define CE_INVERT2	0x02	/* invert media 2 */

/*
 * Structure used to execute a POSITION TO ELEMENT command.  This
 * moves the current picker in front of the specified element.
 */
struct changer_position {
	u_int16_t	cp_type;	/* element type */
	u_int16_t	cp_unit;	/* logical unit of element */
	u_int16_t	cp_flags;	/* misc. flags */
};

/* cp_flags */
#define CP_INVERT	0x01	/* invert picker */

/*
 * Data returned by CHIOGPARAMS.
 */
struct changer_params {
	u_int16_t	cp_npickers;	/* number of pickers */
	u_int16_t	cp_nslots;	/* number of slots */
	u_int16_t	cp_nportals;	/* number of import/export portals */
	u_int16_t	cp_ndrives;	/* number of drives */
};

/*
 * Command used to get element status.
 */

struct changer_voltag {
	u_char		cv_volid[CH_VOLTAG_MAXLEN+1];
	u_int16_t	cv_serial;
};

typedef struct changer_voltag changer_voltag_t;

/*
 * Flags definitions for ces_status
 * Not all flags have meaning for all element types.
 */
typedef enum {
	CES_STATUS_FULL	  = 0x001,	/* element is full */
	CES_STATUS_IMPEXP = 0x002,	/* media deposited by operator */
	CES_STATUS_EXCEPT = 0x004,	/* element in abnormal state */
	CES_PICKER_MASK	  = 0x005,	/* flags valid for pickers */
	CES_STATUS_ACCESS = 0x008,	/* media accessible by picker */
	CES_SLOT_MASK	  = 0x00c,	/* flags valid for slots */
	CES_DRIVE_MASK	  = 0x00c,	/* flags valid for drives */
	CES_STATUS_EXENAB = 0x010,	/* element supports exporting */
	CES_STATUS_INENAB = 0x020,	/* element supports importing */
	CES_PORTAL_MASK	  = 0x03f,	/* flags valid for portals */
	CES_INVERT	  = 0x040,	/* invert bit */
	CES_SOURCE_VALID  = 0x080,	/* source address (ces_source) valid */
	CES_SCSIID_VALID  = 0x100,	/* ces_scsi_id is valid */
	CES_LUN_VALID	  = 0x200	/* ces_scsi_lun is valid */
} ces_status_flags;

struct changer_element_status {
	u_int8_t		ces_type;	  /* element type */
	u_int16_t		ces_addr;	  /* logical element address */
	u_int16_t		ces_int_addr;	  /* changer element address */
	ces_status_flags	ces_flags;	  /*
						   * see CESTATUS definitions
						   * below
						   */
	u_int8_t		ces_sensecode;	  /*
						   * additional sense
						   * code for element */
	u_int8_t		ces_sensequal;	  /*
						   * additional sense
						   * code qualifier
						   */
	u_int8_t		ces_source_type;  /*
						   * element type of
						   * source address
						   */
	u_int16_t		ces_source_addr;  /*
						   * source address of medium
						   */
	changer_voltag_t     	ces_pvoltag;	  /* primary volume tag */
	changer_voltag_t	ces_avoltag;	  /* alternate volume tag */
	u_int8_t		ces_scsi_id;	  /* SCSI id of element */
	u_int8_t		ces_scsi_lun;	  /* SCSI lun of element */
};

struct changer_element_status_request {
	u_int16_t			cesr_element_type;
	u_int16_t			cesr_element_base;
	u_int16_t			cesr_element_count;

	u_int16_t			cesr_flags;
#define CESR_VOLTAGS	0x01

	struct changer_element_status	*cesr_element_status;
};

struct changer_set_voltag_request {
	u_int16_t		csvr_type;
	u_int16_t		csvr_addr;

	u_int16_t		csvr_flags;
#define CSVR_MODE_MASK		0x0f	/* mode mask, acceptable modes below: */
#define	CSVR_MODE_SET		0x00	/* set volume tag if not set */
#define CSVR_MODE_REPLACE	0x01	/* unconditionally replace volume tag */
#define CSVR_MODE_CLEAR		0x02	/* clear volume tag */

#define CSVR_ALTERNATE		0x10	/* set to work with alternate voltag */

	changer_voltag_t     	csvr_voltag;
};

#define CESTATUS_BITS	\
	"\20\6INEAB\5EXENAB\4ACCESS\3EXCEPT\2IMPEXP\1FULL"

#define CHIOMOVE	_IOW('c', 0x01, struct changer_move)
#define CHIOEXCHANGE	_IOW('c', 0x02, struct changer_exchange)
#define CHIOPOSITION	_IOW('c', 0x03, struct changer_position)
#define CHIOGPICKER	_IOR('c', 0x04, int)
#define CHIOSPICKER	_IOW('c', 0x05, int)
#define CHIOGPARAMS	_IOR('c', 0x06, struct changer_params)
#define CHIOIELEM	_IOW('c', 0x07, u_int32_t)
#define CHIOGSTATUS	_IOW('c', 0x08, struct changer_element_status_request)
#define CHIOSETVOLTAG	_IOW('c', 0x09, struct changer_set_voltag_request)

#endif /* !_SYS_CHIO_H_ */


code:
/*-
 * Copyright (c) 1996 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Gordon W. Ross
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 *	$NetBSD: clock_subr.h,v 1.7 2000/10/03 13:41:07 tsutsui Exp $
 *
 *
 * This file is the central clearing-house for calendrical issues.
 *
 * In general the kernel does not know about minutes, hours, days, timezones,
 * daylight savings time, leap-years and such.  All that is theoretically a
 * matter for userland only.
 *
 * Parts of kernel code does however care: badly designed filesystems store
 * timestamps in local time and RTC chips sometimes track time in a local
 * timezone instead of UTC and so on.
 *
 * All that code should go here for service.
 *
 * $FreeBSD: release/9.0.0/sys/sys/clock.h 204646 2010-03-03 17:55:51Z joel $
 */

#ifndef _SYS_CLOCK_H_
#define _SYS_CLOCK_H_

#ifdef _KERNEL		/* No user serviceable parts */

/*
 * Timezone info from settimeofday(2), usually not used
 */
extern int tz_minuteswest;
extern int tz_dsttime;

int utc_offset(void);

/*
 * Structure to hold the values typically reported by time-of-day clocks.
 * This can be passed to the generic conversion functions to be converted
 * to a struct timespec.
 */
struct clocktime {
	int	year;			/* year (4 digit year) */
	int	mon;			/* month (1 - 12) */
	int	day;			/* day (1 - 31) */
	int	hour;			/* hour (0 - 23) */
	int	min;			/* minute (0 - 59) */
	int	sec;			/* second (0 - 59) */
	int	dow;			/* day of week (0 - 6; 0 = Sunday) */
	long	nsec;			/* nano seconds */
};

int clock_ct_to_ts(struct clocktime *, struct timespec *);
void clock_ts_to_ct(struct timespec *, struct clocktime *);
void clock_register(device_t, long);

/*
 * BCD to decimal and decimal to BCD.
 */
#define	FROMBCD(x)	bcd2bin(x)
#define	TOBCD(x)	bin2bcd(x)

/* Some handy constants. */
#define SECDAY		(24 * 60 * 60)
#define SECYR		(SECDAY * 365)

/* Traditional POSIX base year */
#define	POSIX_BASE_YEAR	1970

void timespec2fattime(struct timespec *tsp, int utc, u_int16_t *ddp, u_int16_t *dtp, u_int8_t *dhp);
void fattime2timespec(unsigned dd, unsigned dt, unsigned dh, int utc, struct timespec *tsp);

#endif /* _KERNEL */

#endif /* !_SYS_CLOCK_H_ */


code:
/*-
 * Copyright (c) 2000 Jake Burkholder <jake@freebsd.org>.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD: release/9.0.0/sys/sys/condvar.h 177085 2008-03-12 06:31:06Z jeff $
 */

#ifndef	_SYS_CONDVAR_H_
#define	_SYS_CONDVAR_H_

#ifndef	LOCORE
#include <sys/queue.h>

struct lock_object;
struct thread;

TAILQ_HEAD(cv_waitq, thread);

/*
 * Condition variable.  The waiters count is protected by the mutex that
 * protects the condition; that is, the mutex that is passed to cv_wait*()
 * and is held across calls to cv_signal() and cv_broadcast().  It is an
 * optimization to avoid looking up the sleep queue if there are no waiters.
 */
struct cv {
	const char	*cv_description;
	int		cv_waiters;
};

#ifdef _KERNEL
void	cv_init(struct cv *cvp, const char *desc);
void	cv_destroy(struct cv *cvp);

void	_cv_wait(struct cv *cvp, struct lock_object *lock);
void	_cv_wait_unlock(struct cv *cvp, struct lock_object *lock);
int	_cv_wait_sig(struct cv *cvp, struct lock_object *lock);
int	_cv_timedwait(struct cv *cvp, struct lock_object *lock, int timo);
int	_cv_timedwait_sig(struct cv *cvp, struct lock_object *lock, int timo);

void	cv_signal(struct cv *cvp);
void	cv_broadcastpri(struct cv *cvp, int pri);

#define	cv_wait(cvp, lock)						\
	_cv_wait((cvp), &(lock)->lock_object)
#define	cv_wait_unlock(cvp, lock)					\
	_cv_wait_unlock((cvp), &(lock)->lock_object)
#define	cv_wait_sig(cvp, lock)						\
	_cv_wait_sig((cvp), &(lock)->lock_object)
#define	cv_timedwait(cvp, lock, timo)					\
	_cv_timedwait((cvp), &(lock)->lock_object, (timo))
#define	cv_timedwait_sig(cvp, lock, timo)				\
	_cv_timedwait_sig((cvp), &(lock)->lock_object, (timo))

#define cv_broadcast(cvp)	cv_broadcastpri(cvp, 0)

#define	cv_wmesg(cvp)		((cvp)->cv_description)

#endif	/* _KERNEL */
#endif	/* !LOCORE */
#endif	/* _SYS_CONDVAR_H_ */


code:
/*-
 * Copyright (c) 1990, 1993
 *	The Regents of the University of California.  All rights reserved.
 * Copyright (c) 2000
 *	Poul-Henning Kamp.  All rights reserved.
 * (c) UNIX System Laboratories, Inc.
 * All or some portions of this file are derived from material licensed
 * to the University of California by American Telephone and Telegraph
 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
 * the permission of UNIX System Laboratories, Inc.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	@(#)conf.h	8.5 (Berkeley) 1/9/95
 * $FreeBSD: release/9.0.0/sys/sys/conf.h 226577 2011-10-20 18:47:58Z kib $
 */

#ifndef _SYS_CONF_H_
#define	_SYS_CONF_H_

#ifdef _KERNEL
#include <sys/eventhandler.h>
#else
#include <sys/queue.h>
#endif

struct snapdata;
struct devfs_dirent;
struct cdevsw;
struct file;

struct cdev {
	void		*__si_reserved;
	u_int		si_flags;
#define	SI_ETERNAL	0x0001	/* never destroyed */
#define SI_ALIAS	0x0002	/* carrier of alias name */
#define SI_NAMED	0x0004	/* make_dev{_alias} has been called */
#define SI_CHEAPCLONE	0x0008	/* can be removed_dev'ed when vnode reclaims */
#define SI_CHILD	0x0010	/* child of another struct cdev **/
#define SI_DEVOPEN	0x0020	/* opened by device */
#define SI_CONSOPEN	0x0040	/* opened by console */
#define SI_DUMPDEV	0x0080	/* is kernel dumpdev */
#define SI_CANDELETE	0x0100	/* can do BIO_DELETE */
#define SI_CLONELIST	0x0200	/* on a clone list */
	struct timespec	si_atime;
	struct timespec	si_ctime;
	struct timespec	si_mtime;
	uid_t		si_uid;
	gid_t		si_gid;
	mode_t		si_mode;
	struct ucred	*si_cred;	/* cached clone-time credential */
	int		si_drv0;
	int		si_refcount;
	LIST_ENTRY(cdev)	si_list;
	LIST_ENTRY(cdev)	si_clone;
	LIST_HEAD(, cdev)	si_children;
	LIST_ENTRY(cdev)	si_siblings;
	struct cdev *si_parent;
	char		*si_name;
	void		*si_drv1, *si_drv2;
	struct cdevsw	*si_devsw;
	int		si_iosize_max;	/* maximum I/O size (for physio &al) */
	u_long		si_usecount;
	u_long		si_threadcount;
	union {
		struct snapdata *__sid_snapdata;
	} __si_u;
	char		__si_namebuf[SPECNAMELEN + 1];
};

#define si_snapdata	__si_u.__sid_snapdata

#ifdef _KERNEL

/*
 * Definitions of device driver entry switches
 */

struct bio;
struct buf;
struct thread;
struct uio;
struct knote;
struct clonedevs;
struct vm_object;
struct vnode;

/*
 * Note: d_thread_t is provided as a transition aid for those drivers
 * that treat struct proc/struct thread as an opaque data type and
 * exist in substantially the same form in both 4.x and 5.x.  Writers
 * of drivers that dips into the d_thread_t structure should use
 * struct thread or struct proc as appropriate for the version of the
 * OS they are using.  It is provided in lieu of each device driver
 * inventing its own way of doing this.  While it does violate style(9)
 * in a number of ways, this violation is deemed to be less
 * important than the benefits that a uniform API between releases
 * gives.
 *
 * Users of struct thread/struct proc that aren't device drivers should
 * not use d_thread_t.
 */

typedef struct thread d_thread_t;

typedef int d_open_t(struct cdev *dev, int oflags, int devtype, struct thread *td);
typedef int d_fdopen_t(struct cdev *dev, int oflags, struct thread *td, struct file *fp);
typedef int d_close_t(struct cdev *dev, int fflag, int devtype, struct thread *td);
typedef void d_strategy_t(struct bio *bp);
typedef int d_ioctl_t(struct cdev *dev, u_long cmd, caddr_t data,
		      int fflag, struct thread *td);

typedef int d_read_t(struct cdev *dev, struct uio *uio, int ioflag);
typedef int d_write_t(struct cdev *dev, struct uio *uio, int ioflag);
typedef int d_poll_t(struct cdev *dev, int events, struct thread *td);
typedef int d_kqfilter_t(struct cdev *dev, struct knote *kn);
typedef int d_mmap_t(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr,
		     int nprot, vm_memattr_t *memattr);
typedef int d_mmap_single_t(struct cdev *cdev, vm_ooffset_t *offset,
    vm_size_t size, struct vm_object **object, int nprot);
typedef void d_purge_t(struct cdev *dev);

typedef int dumper_t(
	void *_priv,		/* Private to the driver. */
	void *_virtual,		/* Virtual (mapped) address. */
	vm_offset_t _physical,	/* Physical address of virtual. */
	off_t _offset,		/* Byte-offset to write at. */
	size_t _length);	/* Number of bytes to dump. */

#endif /* _KERNEL */

/*
 * Types for d_flags.
 */
#define	D_TAPE	0x0001
#define	D_DISK	0x0002
#define	D_TTY	0x0004
#define	D_MEM	0x0008

#ifdef _KERNEL

#define	D_TYPEMASK	0xffff

/*
 * Flags for d_flags which the drivers can set.
 */
#define	D_TRACKCLOSE	0x00080000	/* track all closes */
#define D_MMAP_ANON	0x00100000	/* special treatment in vm_mmap.c */
#define D_PSEUDO	0x00200000	/* make_dev() can return NULL */
#define D_NEEDGIANT	0x00400000	/* driver want Giant */
#define	D_NEEDMINOR	0x00800000	/* driver uses clone_create() */

/*
 * Version numbers.
 */
#define D_VERSION_00	0x20011966
#define D_VERSION_01	0x17032005	/* Add d_uid,gid,mode & kind */
#define D_VERSION_02	0x28042009	/* Add d_mmap_single */
#define D_VERSION_03	0x17122009	/* d_mmap takes memattr,vm_ooffset_t */
#define D_VERSION	D_VERSION_03

/*
 * Flags used for internal housekeeping
 */
#define D_INIT		0x80000000	/* cdevsw initialized */

/*
 * Character device switch table
 */
struct cdevsw {
	int			d_version;
	u_int			d_flags;
	const char		*d_name;
	d_open_t		*d_open;
	d_fdopen_t		*d_fdopen;
	d_close_t		*d_close;
	d_read_t		*d_read;
	d_write_t		*d_write;
	d_ioctl_t		*d_ioctl;
	d_poll_t		*d_poll;
	d_mmap_t		*d_mmap;
	d_strategy_t		*d_strategy;
	dumper_t		*d_dump;
	d_kqfilter_t		*d_kqfilter;
	d_purge_t		*d_purge;
	d_mmap_single_t		*d_mmap_single;

	int32_t			d_spare0[3];
	void			*d_spare1[3];

	/* These fields should not be messed with by drivers */
	LIST_HEAD(, cdev)	d_devs;
	int			d_spare2;
	union {
		struct cdevsw		*gianttrick;
		SLIST_ENTRY(cdevsw)	postfree_list;
	} __d_giant;
};
#define	d_gianttrick		__d_giant.gianttrick
#define	d_postfree_list		__d_giant.postfree_list

struct module;

struct devsw_module_data {
	int	(*chainevh)(struct module *, int, void *); /* next handler */
	void	*chainarg;	/* arg for next event handler */
	/* Do not initialize fields hereafter */
};

#define DEV_MODULE(name, evh, arg)					\
static moduledata_t name##_mod = {					\
    #name,								\
    evh,								\
    arg									\
};									\
DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE)

void clone_setup(struct clonedevs **cdp);
void clone_cleanup(struct clonedevs **);
#define CLONE_UNITMASK 0xfffff
#define CLONE_FLAG0 (CLONE_UNITMASK + 1)
int clone_create(struct clonedevs **, struct cdevsw *, int *unit, struct cdev **dev, int extra);

int	count_dev(struct cdev *_dev);
void	destroy_dev(struct cdev *_dev);
int	destroy_dev_sched(struct cdev *dev);
int	destroy_dev_sched_cb(struct cdev *dev, void (*cb)(void *), void *arg);
void	destroy_dev_drain(struct cdevsw *csw);
void	drain_dev_clone_events(void);
struct cdevsw *dev_refthread(struct cdev *_dev, int *_ref);
struct cdevsw *devvn_refthread(struct vnode *vp, struct cdev **devp, int *_ref);
void	dev_relthread(struct cdev *_dev, int _ref);
void	dev_depends(struct cdev *_pdev, struct cdev *_cdev);
void	dev_ref(struct cdev *dev);
void	dev_refl(struct cdev *dev);
void	dev_rel(struct cdev *dev);
void	dev_strategy(struct cdev *dev, struct buf *bp);
struct cdev *make_dev(struct cdevsw *_devsw, int _unit, uid_t _uid, gid_t _gid,
		int _perms, const char *_fmt, ...) __printflike(6, 7);
struct cdev *make_dev_cred(struct cdevsw *_devsw, int _unit,
		struct ucred *_cr, uid_t _uid, gid_t _gid, int _perms,
		const char *_fmt, ...) __printflike(7, 8);
#define	MAKEDEV_REF		0x01
#define	MAKEDEV_WHTOUT		0x02
#define	MAKEDEV_NOWAIT		0x04
#define	MAKEDEV_WAITOK		0x08
#define	MAKEDEV_ETERNAL		0x10
#define	MAKEDEV_CHECKNAME	0x20
struct cdev *make_dev_credf(int _flags,
		struct cdevsw *_devsw, int _unit,
		struct ucred *_cr, uid_t _uid, gid_t _gid, int _mode,
		const char *_fmt, ...) __printflike(8, 9);
int	make_dev_p(int _flags, struct cdev **_cdev, struct cdevsw *_devsw,
		struct ucred *_cr, uid_t _uid, gid_t _gid, int _mode,
		const char *_fmt, ...) __printflike(8, 9);
struct cdev *make_dev_alias(struct cdev *_pdev, const char *_fmt, ...)
		__printflike(2, 3);
int	make_dev_alias_p(int _flags, struct cdev **_cdev, struct cdev *_pdev,
		const char *_fmt, ...) __printflike(4, 5);
int	make_dev_physpath_alias(int _flags, struct cdev **_cdev,
	        struct cdev *_pdev, struct cdev *_old_alias,
                const char *_physpath);
void	dev_lock(void);
void	dev_unlock(void);
void	setconf(void);

#ifdef KLD_MODULE
#define	MAKEDEV_ETERNAL_KLD	0
#else
#define	MAKEDEV_ETERNAL_KLD	MAKEDEV_ETERNAL
#endif

#define	dev2unit(d)	((d)->si_drv0)

typedef	void (*cdevpriv_dtr_t)(void *data);
int	devfs_get_cdevpriv(void **datap);
int	devfs_set_cdevpriv(void *priv, cdevpriv_dtr_t dtr);
void	devfs_clear_cdevpriv(void);
void	devfs_fpdrop(struct file *fp);	/* XXX This is not public KPI */

ino_t	devfs_alloc_cdp_inode(void);
void	devfs_free_cdp_inode(ino_t ino);

#define		UID_ROOT	0
#define		UID_BIN		3
#define		UID_UUCP	66
#define		UID_NOBODY	65534

#define		GID_WHEEL	0
#define		GID_KMEM	2
#define		GID_TTY		4
#define		GID_OPERATOR	5
#define		GID_BIN		7
#define		GID_GAMES	13
#define		GID_DIALER	68
#define		GID_NOBODY	65534

typedef void (*dev_clone_fn)(void *arg, struct ucred *cred, char *name,
	    int namelen, struct cdev **result);

int dev_stdclone(char *_name, char **_namep, const char *_stem, int *_unit);
EVENTHANDLER_DECLARE(dev_clone, dev_clone_fn);

/* Stuff relating to kernel-dump */

struct dumperinfo {
	dumper_t *dumper;	/* Dumping function. */
	void    *priv;		/* Private parts. */
	u_int   blocksize;	/* Size of block in bytes. */
	u_int	maxiosize;	/* Max size allowed for an individual I/O */
	off_t   mediaoffset;	/* Initial offset in bytes. */
	off_t   mediasize;	/* Space available in bytes. */
};

int set_dumper(struct dumperinfo *);
int dump_write(struct dumperinfo *, void *, vm_offset_t, off_t, size_t);
void dumpsys(struct dumperinfo *);
int doadump(boolean_t);
extern int dumping;		/* system is dumping */

#endif /* _KERNEL */

#endif /* !_SYS_CONF_H_ */


code:
/*-
 * Copyright (c) 1988 University of Utah.
 * Copyright (c) 1991 The Regents of the University of California.
 * All rights reserved.
 *
 * This code is derived from software contributed to Berkeley by
 * the Systems Programming Group of the University of Utah Computer
 * Science Department.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	from: @(#)cons.h	7.2 (Berkeley) 5/9/91
 * $FreeBSD: release/9.0.0/sys/sys/cons.h 196506 2009-08-24 10:53:30Z ed $
 */

#ifndef _MACHINE_CONS_H_
#define	_MACHINE_CONS_H_

struct consdev;
struct tty;

typedef	void	cn_probe_t(struct consdev *);
typedef	void	cn_init_t(struct consdev *);
typedef	void	cn_term_t(struct consdev *);
typedef	int	cn_getc_t(struct consdev *);
typedef	void	cn_putc_t(struct consdev *, int);

struct consdev_ops {
	cn_probe_t	*cn_probe;
				/* probe hardware and fill in consdev info */
	cn_init_t	*cn_init;
				/* turn on as console */
	cn_term_t	*cn_term;
				/* turn off as console */
	cn_getc_t	*cn_getc;
				/* kernel getchar interface */
	cn_putc_t	*cn_putc;
				/* kernel putchar interface */
};

struct consdev {
	const struct consdev_ops *cn_ops;
				/* console device operations. */
	short	cn_pri;		/* pecking order; the higher the better */
	void	*cn_arg;	/* drivers method argument */
	int	cn_flags;	/* capabilities of this console */
	char	cn_name[SPECNAMELEN + 1];	/* console (device) name */
};

/* values for cn_pri - reflect our policy for console selection */
#define	CN_DEAD		0	/* device doesn't exist */
#define CN_LOW		1	/* device is a last restort only */
#define CN_NORMAL	2	/* device exists but is nothing special */
#define CN_INTERNAL	3	/* "internal" bit-mapped display */
#define CN_REMOTE	4	/* serial interface with remote bit set */

/* Values for cn_flags. */
#define	CN_FLAG_NODEBUG	0x00000001	/* Not supported with debugger. */
#define	CN_FLAG_NOAVAIL	0x00000002	/* Temporarily not available. */

#ifdef _KERNEL

extern	struct msgbuf consmsgbuf; /* Message buffer for constty. */
extern	struct tty *constty;	/* Temporary virtual console. */

#define	CONSOLE_DEVICE(name, ops, arg)					\
	static struct consdev name = {					\
		.cn_ops = &ops,						\
		.cn_arg = (arg),					\
	};								\
	DATA_SET(cons_set, name)

#define	CONSOLE_DRIVER(name)						\
	static const struct consdev_ops name##_consdev_ops = {		\
		.cn_probe = name##_cnprobe,				\
		.cn_init = name##_cninit,				\
		.cn_term = name##_cnterm,				\
		.cn_getc = name##_cngetc,				\
		.cn_putc = name##_cnputc,				\
	};								\
	CONSOLE_DEVICE(name##_consdev, name##_consdev_ops, NULL)

/* Other kernel entry points. */
void	cninit(void);
void	cninit_finish(void);
int	cnadd(struct consdev *);
void	cnavailable(struct consdev *, int);
void	cnremove(struct consdev *);
void	cnselect(struct consdev *);
int	cncheckc(void);
int	cngetc(void);
void	cnputc(int);
void	cnputs(char *);
int	cnunavailable(void);
void	constty_set(struct tty *tp);
void	constty_clear(void);

#endif /* _KERNEL */

#endif /* !_MACHINE_CONS_H_ */


code:
/*-
 * Copyright (c) 1991-1996 S�ren Schmidt
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer
 *    in this position and unchanged.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * $FreeBSD: release/9.0.0/sys/sys/consio.h 162711 2006-09-27 19:57:02Z ru $
 */

#ifndef	_SYS_CONSIO_H_
#define	_SYS_CONSIO_H_

#ifndef _KERNEL
#include <sys/types.h>
#endif
#include <sys/ioccom.h>

/*
 * Console ioctl commands.  Some commands are named as KDXXXX, GIO_XXX, and
 * PIO_XXX, rather than CONS_XXX, for historical and compatibility reasons.
 * Some other CONS_XXX commands are works as wrapper around frame buffer
 * ioctl commands FBIO_XXX.  Do not try to change all these commands,
 * otherwise we shall have compatibility problems.
 */

/* get/set video mode */
#define KD_TEXT		0		/* set text mode restore fonts  */
#define KD_TEXT0	0		/* ditto			*/
#define KD_GRAPHICS	1		/* set graphics mode 		*/
#define KD_TEXT1	2		/* set text mode !restore fonts */
#define KD_PIXEL	3		/* set pixel mode		*/
#define KDGETMODE	_IOR('K', 9, int)
#define KDSETMODE	_IOWINT('K', 10)

/* set border color */
#define KDSBORDER	_IOWINT('K', 13)

/* set up raster(pixel) text mode */
struct _scr_size {
	int		scr_size[3];
};
typedef struct _scr_size	scr_size_t;

#define KDRASTER	_IOW('K', 100, scr_size_t)

/* get/set screen char map */
struct _scrmap {
	char		scrmap[256];
};
typedef struct _scrmap	scrmap_t;

#define GIO_SCRNMAP	_IOR('k', 2, scrmap_t)
#define PIO_SCRNMAP	_IOW('k', 3, scrmap_t)

/* get the current text attribute */
#define GIO_ATTR	_IOR('a', 0, int)

/* get the current text color */
#define GIO_COLOR	_IOR('c', 0, int)

/* get the adapter type (equivalent to FBIO_ADPTYPE) */
#define CONS_CURRENT	_IOR('c', 1, int)

/* get the current video mode (equivalent to FBIO_GETMODE) */
#define CONS_GET	_IOR('c', 2, int)

/* not supported? */
#define CONS_IO		_IO('c', 3)

/* set blank time interval */
#define CONS_BLANKTIME	_IOW('c', 4, int)

/* set/get the screen saver (these ioctls are current noop) */
struct ssaver	{
#define MAXSSAVER	16
	char		name[MAXSSAVER];
	int		num;
	long		time;
};
typedef struct ssaver	ssaver_t;

#define CONS_SSAVER	_IOW('c', 5, ssaver_t)
#define CONS_GSAVER	_IOWR('c', 6, ssaver_t)

/* set the text cursor type (obsolete, see CONS_CURSORSHAPE below) */
/*
#define CONS_BLINK_CURSOR (1 << 0)
#define CONS_CHAR_CURSOR (1 << 1)
*/
#define CONS_CURSORTYPE	_IOW('c', 7, int)

/* set the bell type to audible or visual */
#define CONS_VISUAL_BELL (1 << 0)
#define CONS_QUIET_BELL	(1 << 1)
#define CONS_BELLTYPE	_IOW('c', 8, int)

/* set the history (scroll back) buffer size (in lines) */
#define CONS_HISTORY	_IOW('c', 9, int)

/* clear the history (scroll back) buffer */
#define CONS_CLRHIST	_IO('c', 10)

/* mouse cursor ioctl */
struct mouse_data {
	int		x;
	int 		y;
	int 		z;
	int 		buttons;
};
typedef struct mouse_data mouse_data_t;

struct mouse_mode {
	int		mode;
	int		signal;
};
typedef struct mouse_mode mouse_mode_t;

struct mouse_event {
	int		id;			/* one based */
	int		value;
};
typedef struct mouse_event mouse_event_t;

struct mouse_info {
	int		operation;
#define MOUSE_SHOW	0x01
#define MOUSE_HIDE	0x02
#define MOUSE_MOVEABS	0x03
#define MOUSE_MOVEREL	0x04
#define MOUSE_GETINFO	0x05
#define MOUSE_MODE	0x06
#define MOUSE_ACTION	0x07
#define MOUSE_MOTION_EVENT	0x08
#define MOUSE_BUTTON_EVENT	0x09
#define MOUSE_MOUSECHAR	0x0a
	union {
		mouse_data_t	data;
		mouse_mode_t	mode;
		mouse_event_t	event;
		int		mouse_char;
	}		u;
};
typedef struct mouse_info mouse_info_t;

#define CONS_MOUSECTL	_IOWR('c', 10, mouse_info_t)

/* see if the vty has been idle */
#define CONS_IDLE	_IOR('c', 11, int)

/* set the screen saver mode */
#define CONS_NO_SAVER	(-1)
#define CONS_LKM_SAVER	0
#define CONS_USR_SAVER	1
#define CONS_SAVERMODE	_IOW('c', 12, int)

/* start the screen saver */
#define CONS_SAVERSTART	_IOW('c', 13, int)

/* set the text cursor shape (see also CONS_CURSORTYPE above) */
#define CONS_BLINK_CURSOR	(1 << 0)
#define CONS_CHAR_CURSOR	(1 << 1)
#define CONS_HIDDEN_CURSOR	(1 << 2)
#define CONS_CURSOR_ATTRS	(CONS_BLINK_CURSOR | CONS_CHAR_CURSOR |	\
				 CONS_HIDDEN_CURSOR)
#define CONS_RESET_CURSOR	(1 << 30)
#define CONS_LOCAL_CURSOR	(1 << 31)
#define CONS_CURSOR_FLAGS	(CONS_RESET_CURSOR | CONS_LOCAL_CURSOR)
struct cshape {
	/* shape[0]: flags, shape[1]: base, shape[2]: height */
	int		shape[3];
};
#define CONS_GETCURSORSHAPE _IOWR('c', 14, struct cshape)
#define CONS_SETCURSORSHAPE _IOW('c', 15, struct cshape)

/* set/get font data */
struct fnt8 {
	char		fnt8x8[8*256];
};
typedef struct fnt8	fnt8_t;

struct fnt14 {
	char		fnt8x14[14*256];
};
typedef struct fnt14	fnt14_t;

struct fnt16 {
	char		fnt8x16[16*256];
};
typedef struct fnt16	fnt16_t;

#define PIO_FONT8x8	_IOW('c', 64, fnt8_t)
#define GIO_FONT8x8	_IOR('c', 65, fnt8_t)
#define PIO_FONT8x14	_IOW('c', 66, fnt14_t)
#define GIO_FONT8x14	_IOR('c', 67, fnt14_t)
#define PIO_FONT8x16	_IOW('c', 68, fnt16_t)
#define GIO_FONT8x16	_IOR('c', 69, fnt16_t)

/* get video mode information */
struct colors	{
	char		fore;
	char		back;
};

struct vid_info {
	short		size;
	short		m_num;
	u_short		font_size;
	u_short		mv_row, mv_col;
	u_short		mv_rsz, mv_csz;
	u_short		mv_hsz;
	struct colors	mv_norm,
			mv_rev,
			mv_grfc;
	u_char		mv_ovscan;
	u_char		mk_keylock;
};
typedef struct vid_info vid_info_t;

#define CONS_GETINFO    _IOWR('c', 73, vid_info_t)

/* get version */
#define CONS_GETVERS	_IOR('c', 74, int)

/* get the video adapter index (equivalent to FBIO_ADAPTER) */
#define CONS_CURRENTADP	_IOR('c', 100, int)

/* get the video adapter information (equivalent to FBIO_ADPINFO) */
#define CONS_ADPINFO	_IOWR('c', 101, video_adapter_info_t)

/* get the video mode information (equivalent to FBIO_MODEINFO) */
#define CONS_MODEINFO	_IOWR('c', 102, video_info_t)

/* find a video mode (equivalent to FBIO_FINDMODE) */
#define CONS_FINDMODE	_IOWR('c', 103, video_info_t)

/* set the frame buffer window origin (equivalent to FBIO_SETWINORG) */
#define CONS_SETWINORG	_IOWINT('c', 104)

/* use the specified keyboard */
#define CONS_SETKBD	_IOWINT('c', 110)

/* release the current keyboard */
#define CONS_RELKBD	_IO('c', 111)

struct scrshot {
	int		x;
	int		y;
	int		xsize;
	int		ysize;
	u_int16_t*	buf;
};
typedef struct scrshot scrshot_t;

/* Snapshot the current video buffer */
#define CONS_SCRSHOT	_IOWR('c', 105, scrshot_t)

/* get/set the current terminal emulator info. */
#define TI_NAME_LEN	32
#define TI_DESC_LEN	64

struct term_info {
	int		ti_index;
	int		ti_flags;
	u_char		ti_name[TI_NAME_LEN];
	u_char		ti_desc[TI_DESC_LEN];
};
typedef struct term_info term_info_t;

#define CONS_GETTERM	_IOWR('c', 112, term_info_t)
#define CONS_SETTERM	_IOW('c', 113, term_info_t)

/*
 * Vty switching ioctl commands.
 */

/* get the next available vty */
#define VT_OPENQRY	_IOR('v', 1, int)

/* set/get vty switching mode */
#ifndef _VT_MODE_DECLARED
#define	_VT_MODE_DECLARED
struct vt_mode {
	char		mode;
#define VT_AUTO		0		/* switching is automatic 	*/
#define VT_PROCESS	1		/* switching controlled by prog */
#define VT_KERNEL	255		/* switching controlled in kernel */
	char		waitv;		/* not implemented yet 	SOS	*/
	short		relsig;
	short		acqsig;
	short		frsig;		/* not implemented yet	SOS	*/
};
typedef struct vt_mode vtmode_t;
#endif /* !_VT_MODE_DECLARED */

#define VT_SETMODE	_IOW('v', 2, vtmode_t)
#define VT_GETMODE	_IOR('v', 3, vtmode_t)

/* acknowledge release or acquisition of a vty */
#define VT_FALSE	0
#define VT_TRUE		1
#define VT_ACKACQ	2
#define VT_RELDISP	_IOWINT('v', 4)

/* activate the specified vty */
#define VT_ACTIVATE	_IOWINT('v', 5)

/* wait until the specified vty is activate */
#define VT_WAITACTIVE	_IOWINT('v', 6)

/* get the currently active vty */
#define VT_GETACTIVE	_IOR('v', 7, int)

/* get the index of the vty */
#define VT_GETINDEX	_IOR('v', 8, int)

/* prevent switching vtys */
#define VT_LOCKSWITCH	_IOW('v', 9, int)

/*
 * Video mode switching ioctl.  See sys/fbio.h for mode numbers.
 */

#define SW_B40x25 	_IO('S', M_B40x25)
#define SW_C40x25  	_IO('S', M_C40x25)
#define SW_B80x25  	_IO('S', M_B80x25)
#define SW_C80x25  	_IO('S', M_C80x25)
#define SW_BG320   	_IO('S', M_BG320)
#define SW_CG320   	_IO('S', M_CG320)
#define SW_BG640   	_IO('S', M_BG640)
#define SW_EGAMONO80x25 _IO('S', M_EGAMONO80x25)
#define SW_CG320_D    	_IO('S', M_CG320_D)
#define SW_CG640_E    	_IO('S', M_CG640_E)
#define SW_EGAMONOAPA 	_IO('S', M_EGAMONOAPA)
#define SW_CG640x350  	_IO('S', M_CG640x350)
#define SW_ENH_MONOAPA2 _IO('S', M_ENHMONOAPA2)
#define SW_ENH_CG640  	_IO('S', M_ENH_CG640)
#define SW_ENH_B40x25  	_IO('S', M_ENH_B40x25)
#define SW_ENH_C40x25  	_IO('S', M_ENH_C40x25)
#define SW_ENH_B80x25  	_IO('S', M_ENH_B80x25)
#define SW_ENH_C80x25  	_IO('S', M_ENH_C80x25)
#define SW_ENH_B80x43  	_IO('S', M_ENH_B80x43)
#define SW_ENH_C80x43  	_IO('S', M_ENH_C80x43)
#define SW_MCAMODE    	_IO('S', M_MCA_MODE)
#define SW_VGA_C40x25	_IO('S', M_VGA_C40x25)
#define SW_VGA_C80x25	_IO('S', M_VGA_C80x25)
#define SW_VGA_C80x30	_IO('S', M_VGA_C80x30)
#define SW_VGA_C80x50	_IO('S', M_VGA_C80x50)
#define SW_VGA_C80x60	_IO('S', M_VGA_C80x60)
#define SW_VGA_M80x25	_IO('S', M_VGA_M80x25)
#define SW_VGA_M80x30	_IO('S', M_VGA_M80x30)
#define SW_VGA_M80x50	_IO('S', M_VGA_M80x50)
#define SW_VGA_M80x60	_IO('S', M_VGA_M80x60)
#define SW_VGA11	_IO('S', M_VGA11)
#define SW_BG640x480	_IO('S', M_VGA11)
#define SW_VGA12	_IO('S', M_VGA12)
#define SW_CG640x480	_IO('S', M_VGA12)
#define SW_VGA13	_IO('S', M_VGA13)
#define SW_VGA_CG320	_IO('S', M_VGA13)
#define SW_VGA_CG640	_IO('S', M_VGA_CG640)
#define SW_VGA_MODEX	_IO('S', M_VGA_MODEX)

#define SW_PC98_80x25		_IO('S', M_PC98_80x25)
#define SW_PC98_80x30		_IO('S', M_PC98_80x30)
#define SW_PC98_EGC640x400	_IO('S', M_PC98_EGC640x400)
#define SW_PC98_PEGC640x400	_IO('S', M_PC98_PEGC640x400)
#define SW_PC98_PEGC640x480	_IO('S', M_PC98_PEGC640x480)

#define SW_VGA_C90x25	_IO('S', M_VGA_C90x25)
#define SW_VGA_M90x25	_IO('S', M_VGA_M90x25)
#define SW_VGA_C90x30	_IO('S', M_VGA_C90x30)
#define SW_VGA_M90x30	_IO('S', M_VGA_M90x30)
#define SW_VGA_C90x43	_IO('S', M_VGA_C90x43)
#define SW_VGA_M90x43	_IO('S', M_VGA_M90x43)
#define SW_VGA_C90x50	_IO('S', M_VGA_C90x50)
#define SW_VGA_M90x50	_IO('S', M_VGA_M90x50)
#define SW_VGA_C90x60	_IO('S', M_VGA_C90x60)
#define SW_VGA_M90x60	_IO('S', M_VGA_M90x60)

#define SW_TEXT_80x25	_IO('S', M_TEXT_80x25)
#define SW_TEXT_80x30	_IO('S', M_TEXT_80x30)
#define SW_TEXT_80x43	_IO('S', M_TEXT_80x43)
#define SW_TEXT_80x50	_IO('S', M_TEXT_80x50)
#define SW_TEXT_80x60	_IO('S', M_TEXT_80x60)
#define SW_TEXT_132x25	_IO('S', M_TEXT_132x25)
#define SW_TEXT_132x30	_IO('S', M_TEXT_132x30)
#define SW_TEXT_132x43	_IO('S', M_TEXT_132x43)
#define SW_TEXT_132x50	_IO('S', M_TEXT_132x50)
#define SW_TEXT_132x60	_IO('S', M_TEXT_132x60)

#define SW_VESA_CG640x400	_IO('V', M_VESA_CG640x400 - M_VESA_BASE)
#define SW_VESA_CG640x480	_IO('V', M_VESA_CG640x480 - M_VESA_BASE)
#define SW_VESA_800x600		_IO('V', M_VESA_800x600 - M_VESA_BASE)
#define SW_VESA_CG800x600	_IO('V', M_VESA_CG800x600 - M_VESA_BASE)
#define SW_VESA_1024x768	_IO('V', M_VESA_1024x768 - M_VESA_BASE)
#define SW_VESA_CG1024x768	_IO('V', M_VESA_CG1024x768 - M_VESA_BASE)
#define SW_VESA_1280x1024	_IO('V', M_VESA_1280x1024 - M_VESA_BASE)
#define SW_VESA_CG1280x1024	_IO('V', M_VESA_CG1280x1024 - M_VESA_BASE)
#define SW_VESA_C80x60		_IO('V', M_VESA_C80x60 - M_VESA_BASE)
#define SW_VESA_C132x25		_IO('V', M_VESA_C132x25 - M_VESA_BASE)
#define SW_VESA_C132x43		_IO('V', M_VESA_C132x43 - M_VESA_BASE)
#define SW_VESA_C132x50		_IO('V', M_VESA_C132x50 - M_VESA_BASE)
#define SW_VESA_C132x60		_IO('V', M_VESA_C132x60 - M_VESA_BASE)
#define SW_VESA_32K_320		_IO('V', M_VESA_32K_320 - M_VESA_BASE)
#define SW_VESA_64K_320		_IO('V', M_VESA_64K_320 - M_VESA_BASE)
#define SW_VESA_FULL_320	_IO('V', M_VESA_FULL_320 - M_VESA_BASE)
#define SW_VESA_32K_640		_IO('V', M_VESA_32K_640 - M_VESA_BASE)
#define SW_VESA_64K_640		_IO('V', M_VESA_64K_640 - M_VESA_BASE)
#define SW_VESA_FULL_640	_IO('V', M_VESA_FULL_640 - M_VESA_BASE)
#define SW_VESA_32K_800		_IO('V', M_VESA_32K_800 - M_VESA_BASE)
#define SW_VESA_64K_800		_IO('V', M_VESA_64K_800 - M_VESA_BASE)
#define SW_VESA_FULL_800	_IO('V', M_VESA_FULL_800 - M_VESA_BASE)
#define SW_VESA_32K_1024	_IO('V', M_VESA_32K_1024 - M_VESA_BASE)
#define SW_VESA_64K_1024	_IO('V', M_VESA_64K_1024 - M_VESA_BASE)
#define SW_VESA_FULL_1024	_IO('V', M_VESA_FULL_1024 - M_VESA_BASE)
#define SW_VESA_32K_1280	_IO('V', M_VESA_32K_1280 - M_VESA_BASE)
#define SW_VESA_64K_1280	_IO('V', M_VESA_64K_1280 - M_VESA_BASE)
#define SW_VESA_FULL_1280	_IO('V', M_VESA_FULL_1280 - M_VESA_BASE)

#endif /* !_SYS_CONSIO_H_ */


code:
/*-
 * Copyright (C) 1992-2012 The FreeBSD Project. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD: release/9.0.0/sys/sys/copyright.h 229089 2011-12-31 13:44:10Z bz $
 */

/* Copyrights macros  */

/* FreeBSD */
#define COPYRIGHT_FreeBSD \
	"Copyright (c) 1992-2012 The FreeBSD Project.\n"

/* Foundation */
#define	TRADEMARK_Foundation \
	"FreeBSD is a registered trademark of The FreeBSD Foundation.\n"

/* Berkeley */
#define COPYRIGHT_UCB \
	"Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994\n\tThe Regents of the University of California. All rights reserved.\n"

/* a port of FreeBSD to the NEC PC98, Japan */
#if defined(PC98)
#define COPYRIGHT_PC98 \
	"Copyright (c) 1994-2003 FreeBSD(98) porting team.\nCopyright (c) 1992  A.Kojima F.Ukai M.Ishii (KMC).\n"
#else
#define COPYRIGHT_PC98
#endif

char copyright[] = COPYRIGHT_FreeBSD COPYRIGHT_PC98 COPYRIGHT_UCB;
char trademark[] = TRADEMARK_Foundation;


code:
/*-
 * Copyright (c) 2005-2007 Nate Lawson (SDG)
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD: release/9.0.0/sys/sys/cpu.h 193155 2009-05-31 08:59:15Z nwhitehorn $
 */

#ifndef _SYS_CPU_H_
#define _SYS_CPU_H_

#include <sys/eventhandler.h>

/*
 * CPU device support.
 */

#define CPU_IVAR_PCPU		1
#define CPU_IVAR_NOMINAL_MHZ	2

static __inline struct pcpu *cpu_get_pcpu(device_t dev)
{
	uintptr_t v = 0;
	BUS_READ_IVAR(device_get_parent(dev), dev, CPU_IVAR_PCPU, &v);
	return ((struct pcpu *)v);
}

static __inline int32_t cpu_get_nominal_mhz(device_t dev)
{
	uintptr_t v = 0;
	if (BUS_READ_IVAR(device_get_parent(dev), dev,
	    CPU_IVAR_NOMINAL_MHZ, &v) != 0)
		return (-1);
	return ((int32_t)v);
}

/*
 * CPU frequency control interface.
 */

/* Each driver's CPU frequency setting is exported in this format. */
struct cf_setting {
	int	freq;	/* CPU clock in Mhz or 100ths of a percent. */
	int	volts;	/* Voltage in mV. */
	int	power;	/* Power consumed in mW. */
	int	lat;	/* Transition latency in us. */
	device_t dev;	/* Driver providing this setting. */
	int	spec[4];/* Driver-specific storage for non-standard info. */
};

/* Maximum number of settings a given driver can have. */
#define MAX_SETTINGS		24

/* A combination of settings is a level. */
struct cf_level {
	struct cf_setting	total_set;
	struct cf_setting	abs_set;
	struct cf_setting	rel_set[MAX_SETTINGS];
	int			rel_count;
	TAILQ_ENTRY(cf_level)	link;
};

TAILQ_HEAD(cf_level_lst, cf_level);

/* Drivers should set all unknown values to this. */
#define CPUFREQ_VAL_UNKNOWN	(-1)

/*
 * Every driver offers a type of CPU control.  Absolute levels are mutually
 * exclusive while relative levels modify the current absolute level.  There
 * may be multiple absolute and relative drivers available on a given
 * system.
 *
 * For example, consider a system with two absolute drivers that provide
 * frequency settings of 100, 200 and 300, 400 and a relative driver that
 * provides settings of 50%, 100%.  The cpufreq core would export frequency
 * levels of 50, 100, 150, 200, 300, 400.
 *
 * The "info only" flag signifies that settings returned by
 * CPUFREQ_DRV_SETTINGS cannot be passed to the CPUFREQ_DRV_SET method and
 * are only informational.  This is for some drivers that can return
 * information about settings but rely on another machine-dependent driver
 * for actually performing the frequency transition (e.g., ACPI performance
 * states of type "functional fixed hardware.")
 */
#define CPUFREQ_TYPE_MASK	0xffff
#define CPUFREQ_TYPE_RELATIVE	(1<<0)
#define CPUFREQ_TYPE_ABSOLUTE	(1<<1)
#define CPUFREQ_FLAG_INFO_ONLY	(1<<16)

/*
 * When setting a level, the caller indicates the priority of this request.
 * Priorities determine, among other things, whether a level can be
 * overridden by other callers.  For example, if the user sets a level but
 * the system thermal driver needs to override it for emergency cooling,
 * the driver would use a higher priority.  Once the event has passed, the
 * driver would call cpufreq to resume any previous level.
 */
#define CPUFREQ_PRIO_HIGHEST	1000000
#define CPUFREQ_PRIO_KERN	1000
#define CPUFREQ_PRIO_USER	100
#define CPUFREQ_PRIO_LOWEST	0

/*
 * Register and unregister a driver with the cpufreq core.  Once a driver
 * is registered, it must support calls to its CPUFREQ_GET, CPUFREQ_GET_LEVEL,
 * and CPUFREQ_SET methods.  It must also unregister before returning from
 * its DEVICE_DETACH method.
 */
int	cpufreq_register(device_t dev);
int	cpufreq_unregister(device_t dev);

/*
 * Notify the cpufreq core that the number of or values for settings have
 * changed.
 */
int	cpufreq_settings_changed(device_t dev);

/*
 * Eventhandlers that are called before and after a change in frequency.
 * The new level and the result of the change (0 is success) is passed in.
 * If the driver wishes to revoke the change from cpufreq_pre_change, it
 * stores a non-zero error code in the result parameter and the change will
 * not be made.  If the post-change eventhandler gets a non-zero result,
 * no change was made and the previous level remains in effect.  If a change
 * is revoked, the post-change eventhandler is still called with the error
 * value supplied by the revoking driver.  This gives listeners who cached
 * some data in preparation for a level change a chance to clean up.
 */
typedef void (*cpufreq_pre_notify_fn)(void *, const struct cf_level *, int *);
typedef void (*cpufreq_post_notify_fn)(void *, const struct cf_level *, int);
EVENTHANDLER_DECLARE(cpufreq_pre_change, cpufreq_pre_notify_fn);
EVENTHANDLER_DECLARE(cpufreq_post_change, cpufreq_post_notify_fn);

/*
 * Eventhandler called when the available list of levels changed.
 * The unit number of the device (i.e. "cpufreq0") whose levels changed
 * is provided so the listener can retrieve the new list of levels.
 */
typedef void (*cpufreq_levels_notify_fn)(void *, int);
EVENTHANDLER_DECLARE(cpufreq_levels_changed, cpufreq_levels_notify_fn);

/* Allow values to be +/- a bit since sometimes we have to estimate. */
#define CPUFREQ_CMP(x, y)	(abs((x) - (y)) < 25)

/*
 * Machine-dependent functions.
 */

/* Estimate the current clock rate for the given CPU id. */
int	cpu_est_clockrate(int cpu_id, uint64_t *rate);

#endif /* !_SYS_CPU_H_ */


code:
/*-
 * Copyright (c) 2006-2008 Stanislav Sedov <stas@FreeBSD.org>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD: release/9.0.0/sys/sys/cpuctl.h 195189 2009-06-30 12:35:47Z stas $
 */

#ifndef _CPUCTL_H_
#define	_CPUCTL_H_

typedef struct {
	int		msr;	/* MSR to read */
	uint64_t	data;
} cpuctl_msr_args_t;

typedef struct {
	int		level;	/* CPUID level */
	uint32_t	data[4];
} cpuctl_cpuid_args_t;

typedef struct {
	void	*data;
	size_t	size;
} cpuctl_update_args_t;

#define	CPUCTL_RDMSR	_IOWR('c', 1, cpuctl_msr_args_t)
#define	CPUCTL_WRMSR	_IOWR('c', 2, cpuctl_msr_args_t)
#define	CPUCTL_CPUID	_IOWR('c', 3, cpuctl_cpuid_args_t)
#define	CPUCTL_UPDATE	_IOWR('c', 4, cpuctl_update_args_t)
#define	CPUCTL_MSRSBIT	_IOWR('c', 5, cpuctl_msr_args_t)
#define	CPUCTL_MSRCBIT	_IOWR('c', 6, cpuctl_msr_args_t)

#endif /* _CPUCTL_H_ */


code:
/*-
 * Copyright (c) 2008,	Jeffrey Roberson <jeff@freebsd.org>
 * All rights reserved.
 *
 * Copyright (c) 2008 Nokia Corporation
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice unmodified, this list of conditions, and the following
 *    disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * $FreeBSD: release/9.0.0/sys/sys/cpuset.h 223759 2011-07-04 12:18:12Z attilio $
 */

#ifndef _SYS_CPUSET_H_
#define	_SYS_CPUSET_H_

#include <sys/_cpuset.h>

#define	CPUSETBUFSIZ	((2 + sizeof(long) * 2) * _NCPUWORDS)

#define	__cpuset_mask(n)	((long)1 << ((n) % _NCPUBITS))
#define	CPU_CLR(n, p)	((p)->__bits[(n)/_NCPUBITS] &= ~__cpuset_mask(n))
#define	CPU_COPY(f, t)	(void)(*(t) = *(f))
#define	CPU_ISSET(n, p)	(((p)->__bits[(n)/_NCPUBITS] & __cpuset_mask(n)) != 0)
#define	CPU_SET(n, p)	((p)->__bits[(n)/_NCPUBITS] |= __cpuset_mask(n))
#define	CPU_ZERO(p) do {				\
	__size_t __i;					\
	for (__i = 0; __i < _NCPUWORDS; __i++)		\
		(p)->__bits[__i] = 0;			\
} while (0)

#define	CPU_FILL(p) do {				\
	__size_t __i;					\
	for (__i = 0; __i < _NCPUWORDS; __i++)		\
		(p)->__bits[__i] = -1;			\
} while (0)

#define	CPU_SETOF(n, p) do {					\
	CPU_ZERO(p);						\
	((p)->__bits[(n)/_NCPUBITS] = __cpuset_mask(n));	\
} while (0)

/* Is p empty. */
#define	CPU_EMPTY(p) __extension__ ({			\
	__size_t __i;					\
	for (__i = 0; __i < _NCPUWORDS; __i++)		\
		if ((p)->__bits[__i])			\
			break;				\
	__i == _NCPUWORDS;				\
})

/* Is p full set. */
#define	CPU_ISFULLSET(p) __extension__ ({		\
	__size_t __i;					\
	for (__i = 0; __i < _NCPUWORDS; __i++)		\
		if ((p)->__bits[__i] != (long)-1)	\
			break;				\
	__i == _NCPUWORDS;				\
})

/* Is c a subset of p. */
#define	CPU_SUBSET(p, c) __extension__ ({		\
	__size_t __i;					\
	for (__i = 0; __i < _NCPUWORDS; __i++)		\
		if (((c)->__bits[__i] &			\
		    (p)->__bits[__i]) !=		\
		    (c)->__bits[__i])			\
			break;				\
	__i == _NCPUWORDS;				\
})

/* Are there any common bits between b & c? */
#define	CPU_OVERLAP(p, c) __extension__ ({		\
	__size_t __i;					\
	for (__i = 0; __i < _NCPUWORDS; __i++)		\
		if (((c)->__bits[__i] &			\
		    (p)->__bits[__i]) != 0)		\
			break;				\
	__i != _NCPUWORDS;				\
})

/* Compare two sets, returns 0 if equal 1 otherwise. */
#define	CPU_CMP(p, c) __extension__ ({			\
	__size_t __i;					\
	for (__i = 0; __i < _NCPUWORDS; __i++)		\
		if (((c)->__bits[__i] !=		\
		    (p)->__bits[__i]))			\
			break;				\
	__i != _NCPUWORDS;				\
})

#define	CPU_OR(d, s) do {				\
	__size_t __i;					\
	for (__i = 0; __i < _NCPUWORDS; __i++)		\
		(d)->__bits[__i] |= (s)->__bits[__i];	\
} while (0)

#define	CPU_AND(d, s) do {				\
	__size_t __i;					\
	for (__i = 0; __i < _NCPUWORDS; __i++)		\
		(d)->__bits[__i] &= (s)->__bits[__i];	\
} while (0)

#define	CPU_NAND(d, s) do {				\
	__size_t __i;					\
	for (__i = 0; __i < _NCPUWORDS; __i++)		\
		(d)->__bits[__i] &= ~(s)->__bits[__i];	\
} while (0)

#define	CPU_CLR_ATOMIC(n, p)						\
	atomic_clear_long(&(p)->__bits[(n)/_NCPUBITS], __cpuset_mask(n))

#define	CPU_SET_ATOMIC(n, p)						\
	atomic_set_long(&(p)->__bits[(n)/_NCPUBITS], __cpuset_mask(n))

/* Convenience functions catering special cases. */
#define	CPU_OR_ATOMIC(d, s) do {			\
	__size_t __i;					\
	for (__i = 0; __i < _NCPUWORDS; __i++)		\
		atomic_set_long(&(d)->__bits[__i],	\
		    (s)->__bits[__i]);			\
} while (0)

#define	CPU_COPY_STORE_REL(f, t) do {				\
	__size_t __i;						\
	for (__i = 0; __i < _NCPUWORDS; __i++)			\
		atomic_store_rel_long(&(t)->__bits[__i],	\
		    (f)->__bits[__i]);				\
} while (0)

/*
 * Valid cpulevel_t values.
 */
#define	CPU_LEVEL_ROOT		1	/* All system cpus. */
#define	CPU_LEVEL_CPUSET	2	/* Available cpus for which. */
#define	CPU_LEVEL_WHICH		3	/* Actual mask/id for which. */

/*
 * Valid cpuwhich_t values.
 */
#define	CPU_WHICH_TID		1	/* Specifies a thread id. */
#define	CPU_WHICH_PID		2	/* Specifies a process id. */
#define	CPU_WHICH_CPUSET	3	/* Specifies a set id. */
#define	CPU_WHICH_IRQ		4	/* Specifies an irq #. */
#define	CPU_WHICH_JAIL		5	/* Specifies a jail id. */

/*
 * Reserved cpuset identifiers.
 */
#define	CPUSET_INVALID	-1
#define	CPUSET_DEFAULT	0

#ifdef _KERNEL
LIST_HEAD(setlist, cpuset);

/*
 * cpusets encapsulate cpu binding information for one or more threads.
 *
 * 	a - Accessed with atomics.
 *	s - Set at creation, never modified.  Only a ref required to read.
 *	c - Locked internally by a cpuset lock.
 *
 * The bitmask is only modified while holding the cpuset lock.  It may be
 * read while only a reference is held but the consumer must be prepared
 * to deal with inconsistent results.
 */
struct cpuset {
	cpuset_t		cs_mask;	/* bitmask of valid cpus. */
	volatile u_int		cs_ref;		/* (a) Reference count. */
	int			cs_flags;	/* (s) Flags from below. */
	cpusetid_t		cs_id;		/* (s) Id or INVALID. */
	struct cpuset		*cs_parent;	/* (s) Pointer to our parent. */
	LIST_ENTRY(cpuset)	cs_link;	/* (c) All identified sets. */
	LIST_ENTRY(cpuset)	cs_siblings;	/* (c) Sibling set link. */
	struct setlist		cs_children;	/* (c) List of children. */
};

#define CPU_SET_ROOT    0x0001  /* Set is a root set. */
#define CPU_SET_RDONLY  0x0002  /* No modification allowed. */

extern cpuset_t *cpuset_root;
struct prison;
struct proc;

struct cpuset *cpuset_thread0(void);
struct cpuset *cpuset_ref(struct cpuset *);
void	cpuset_rel(struct cpuset *);
int	cpuset_setthread(lwpid_t id, cpuset_t *);
int	cpuset_create_root(struct prison *, struct cpuset **);
int	cpuset_setproc_update_set(struct proc *, struct cpuset *);
int	cpusetobj_ffs(const cpuset_t *);
char	*cpusetobj_strprint(char *, const cpuset_t *);
int	cpusetobj_strscan(cpuset_t *, const char *);

#else
__BEGIN_DECLS
int	cpuset(cpusetid_t *);
int	cpuset_setid(cpuwhich_t, id_t, cpusetid_t);
int	cpuset_getid(cpulevel_t, cpuwhich_t, id_t, cpusetid_t *);
int	cpuset_getaffinity(cpulevel_t, cpuwhich_t, id_t, size_t, cpuset_t *);
int	cpuset_setaffinity(cpulevel_t, cpuwhich_t, id_t, size_t, const cpuset_t *);
__END_DECLS
#endif
#endif /* !_SYS_CPUSET_H_ */


code:
/*-
 * Copyright (c) 1982, 1988, 1991, 1993
 *	The Regents of the University of California.  All rights reserved.
 * (c) UNIX System Laboratories, Inc.
 * All or some portions of this file are derived from material licensed
 * to the University of California by American Telephone and Telegraph
 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
 * the permission of UNIX System Laboratories, Inc.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD: release/9.0.0/sys/sys/ctype.h 127976 2004-04-07 04:19:52Z imp $
 */

#ifndef _SYS_CTYPE_H_
#define	_SYS_CTYPE_H_

#ifdef _KERNEL

#define isspace(c)	((c) == ' ' || ((c) >= '\t' && (c) <= '\r'))
#define isascii(c)	(((c) & ~0x7f) == 0)
#define isupper(c)	((c) >= 'A' && (c) <= 'Z')
#define islower(c)	((c) >= 'a' && (c) <= 'z')
#define isalpha(c)	(isupper(c) || islower(c))
#define isdigit(c)	((c) >= '0' && (c) <= '9')
#define isxdigit(c)	(isdigit(c) \
			  || ((c) >= 'A' && (c) <= 'F') \
			  || ((c) >= 'a' && (c) <= 'f'))
#define isprint(c)	((c) >= ' ' && (c) <= '~')

#define toupper(c)	((c) - 0x20 * (((c) >= 'a') && ((c) <= 'z')))
#define tolower(c)	((c) + 0x20 * (((c) >= 'A') && ((c) <= 'Z')))

#endif
#endif /* !_SYS_CTYPE_H_ */