netbsd dirent.h, import sys/sys *.h, mfs cleanup

. add all sys/sys headers not already present to help compiling
	. take netbsd dirent.h and struct dirent; main result is
	  introducing d_type and d_namlen that have to be set by getdents()
	  in all FS code implementing it
	. d_off is gone
	. alignment of the struct has become 8 bytes instead of 4
	. remove _MAX_BLOCK_SIZE, _MIN_BLOCK_SIZE, _STATIC_BLOCK_SIZE
	. libminlib: cleanup unused yet duplicate code
	. mfs: throw out the long-broken v1, v2 support
	. new test for dirent contents filled by getdents()

Change-Id: I1459755c7ba5e5d1c9396d3a587ce6e63ddc283e
This commit is contained in:
Ben Gras 2013-09-16 22:52:36 +02:00 committed by Lionel Sambuc
parent 664b726cd3
commit 6c8f7fc3ba
260 changed files with 37541 additions and 529 deletions

View file

@ -1543,7 +1543,7 @@ char *f, **clist, **ilist, **zlist;
rw_super(SUPER_GET);
if(block_size < _MIN_BLOCK_SIZE)
if(block_size < SUPER_BLOCK_BYTES)
fatal("funny block size");
if(!(rwbuf = malloc(block_size))) fatal("couldn't allocate fs buf (1)");
@ -1663,3 +1663,10 @@ char **argv;
}
return(0);
}
void panic(char *fmt, ...)
{
fprintf(stderr, "%s\n", fmt);
exit(1);
}

View file

@ -45,6 +45,7 @@
./usr/include/arm/mcontext.h minix-sys
./usr/include/arm/mutex.h minix-sys
./usr/include/arm/param.h minix-sys
./usr/include/arm/proc.h minix-sys
./usr/include/arm/profile.h minix-sys
./usr/include/arm/rwlock.h minix-sys
./usr/include/arm/setjmp.h minix-sys
@ -85,6 +86,7 @@
./usr/include/evbarm/mutex.h minix-sys
./usr/include/evbarm/param.h minix-sys
./usr/include/evbarm/partition.h minix-sys
./usr/include/evbarm/proc.h minix-sys
./usr/include/evbarm/profile.h minix-sys
./usr/include/evbarm/rwlock.h minix-sys
./usr/include/evbarm/setjmp.h minix-sys

View file

@ -68,6 +68,7 @@
./usr/include/i386/fenv.h minix-sys
./usr/include/i386/float.h minix-sys
./usr/include/i386/fpu.h minix-sys
./usr/include/i386/frame.h minix-sys
./usr/include/i386/ieeefp.h minix-sys
./usr/include/i386/ieee.h minix-sys
./usr/include/i386/int86.h minix-sys
@ -79,6 +80,7 @@
./usr/include/i386/int_types.h minix-sys
./usr/include/i386/ipcconst.h minix-sys
./usr/include/i386/limits.h minix-sys
./usr/include/i386/lock.h minix-sys
./usr/include/i386/math.h minix-sys
./usr/include/i386/mcontext.h minix-sys
./usr/include/i386/memory.h minix-sys
@ -87,6 +89,7 @@
./usr/include/i386/npx.h minix-sys
./usr/include/i386/param.h minix-sys
./usr/include/i386/partition.h minix-sys
./usr/include/i386/pcb.h minix-sys
./usr/include/i386/pci_amd.h minix-sys
./usr/include/i386/pci.h minix-sys
./usr/include/i386/pci_intel.h minix-sys
@ -94,11 +97,15 @@
./usr/include/i386/pci_via.h minix-sys
./usr/include/i386/pio.h minix-sys
./usr/include/i386/ports.h minix-sys
./usr/include/i386/proc.h minix-sys
./usr/include/i386/profile.h minix-sys
./usr/include/i386/rwlock.h minix-sys
./usr/include/i386/segments.h minix-sys
./usr/include/i386/setjmp.h minix-sys
./usr/include/i386/signal.h minix-sys
./usr/include/i386/stackframe.h minix-sys
./usr/include/i386/sysarch.h minix-sys
./usr/include/i386/tss.h minix-sys
./usr/include/i386/types.h minix-sys
./usr/include/i386/vm.h minix-sys
./usr/include/i386/vmparam.h minix-sys

View file

@ -1165,7 +1165,7 @@
./usr/include/minix/debug.h minix-sys
./usr/include/minix/devio.h minix-sys
./usr/include/minix/devman.h minix-sys
./usr/include/minix/dirent.h minix-sys
./usr/include/minix/dirent.h minix-sys obsolete
./usr/include/minix/dmap.h minix-sys
./usr/include/minix/driver.h minix-sys
./usr/include/minix/drivers.h minix-sys
@ -1363,42 +1363,79 @@
./usr/include/strings.h minix-sys
./usr/include/struct.h minix-sys
./usr/include/sys minix-sys
./usr/include/sys/acct.h minix-sys
./usr/include/sys/agpio.h minix-sys
./usr/include/sys/aio.h minix-sys
./usr/include/sys/ansi.h minix-sys
./usr/include/sys/aout_mids.h minix-sys
./usr/include/sys/asynchio.h minix-sys
./usr/include/sys/ataio.h minix-sys
./usr/include/sys/atomic.h minix-sys
./usr/include/sys/audioio.h minix-sys
./usr/include/sys/bitops.h minix-sys
./usr/include/sys/bootblock.h minix-sys
./usr/include/sys/bswap.h minix-sys
./usr/include/sys/buf.h minix-sys
./usr/include/sys/callback.h minix-sys
./usr/include/sys/callout.h minix-sys
./usr/include/sys/cdefs_aout.h minix-sys
./usr/include/sys/cdefs_elf.h minix-sys
./usr/include/sys/cdefs.h minix-sys
./usr/include/sys/cdio.h minix-sys
./usr/include/sys/chio.h minix-sys
./usr/include/sys/clockctl.h minix-sys
./usr/include/sys/condvar.h minix-sys
./usr/include/sys/conf.h minix-sys
./usr/include/sys/core.h minix-sys
./usr/include/sys/cpufreq.h minix-sys
./usr/include/sys/cpuio.h minix-sys
./usr/include/sys/ctype_bits.h minix-sys
./usr/include/sys/ctype_inline.h minix-sys
./usr/include/sys/device.h minix-sys
./usr/include/sys/device_if.h minix-sys
./usr/include/sys/dirent.h minix-sys
./usr/include/sys/dir.h minix-sys
./usr/include/sys/disk.h minix-sys
./usr/include/sys/disklabel_acorn.h minix-sys
./usr/include/sys/disklabel_gpt.h minix-sys
./usr/include/sys/disklabel.h minix-sys
./usr/include/sys/disklabel_rdb.h minix-sys
./usr/include/sys/dkbad.h minix-sys
./usr/include/sys/dkio.h minix-sys
./usr/include/sys/dkstat.h minix-sys
./usr/include/sys/domain.h minix-sys
./usr/include/sys/drvctlio.h minix-sys
./usr/include/sys/dvdio.h minix-sys
./usr/include/sys/elf64.h minix-sys
./usr/include/sys/elf_common.h minix-sys
./usr/include/sys/elf_core.h minix-sys
./usr/include/sys/elf_generic.h minix-sys
./usr/include/sys/endian.h minix-sys
./usr/include/sys/envsys.h minix-sys
./usr/include/sys/errno.h minix-sys
./usr/include/sys/evcnt.h minix-sys
./usr/include/sys/event.h minix-sys
./usr/include/sys/exec_aout.h minix-sys
./usr/include/sys/exec_coff.h minix-sys
./usr/include/sys/exec_ecoff.h minix-sys
./usr/include/sys/exec_elf.h minix-sys
./usr/include/sys/exec.h minix-sys
./usr/include/sys/exec_script.h minix-sys
./usr/include/sys/extattr.h minix-sys
./usr/include/sys/extent.h minix-sys
./usr/include/sys/fcntl.h minix-sys
./usr/include/sys/fdio.h minix-sys
./usr/include/sys/fd_set.h minix-sys
./usr/include/sys/featuretest.h minix-sys
./usr/include/sys/filedesc.h minix-sys
./usr/include/sys/file.h minix-sys
./usr/include/sys/filio.h minix-sys
./usr/include/sys/flashio.h minix-sys
./usr/include/sys/float_ieee754.h minix-sys
./usr/include/sys/fstypes.h minix-sys
./usr/include/sys/gcq.h minix-sys
./usr/include/sys/gmon.h minix-sys
./usr/include/sys/gpio.h minix-sys
./usr/include/sys/hash.h minix-sys
./usr/include/sys/ieee754.h minix-sys
./usr/include/sys/inttypes.h minix-sys
@ -1412,43 +1449,88 @@
./usr/include/sys/ioc_net.h minix-sys
./usr/include/sys/ioc_sound.h minix-sys
./usr/include/sys/ioc_tape.h minix-sys
./usr/include/sys/ioctl_compat.h minix-sys
./usr/include/sys/ioctl.h minix-sys
./usr/include/sys/ioc_tty.h minix-sys
./usr/include/sys/iostat.h minix-sys
./usr/include/sys/ipc.h minix-sys
./usr/include/sys/jmp_buf.h minix-sys
./usr/include/sys/joystick.h minix-sys
./usr/include/sys/kbdio.h minix-sys
./usr/include/sys/kcore.h minix-sys
./usr/include/sys/kcpuset.h minix-sys
./usr/include/sys/kgdb.h minix-sys
./usr/include/sys/kmem.h minix-sys
./usr/include/sys/ksem.h minix-sys
./usr/include/sys/ksyms.h minix-sys
./usr/include/sys/ktrace.h minix-sys
./usr/include/sys/localedef.h minix-sys
./usr/include/sys/lockf.h minix-sys
./usr/include/sys/lock.h minix-sys
./usr/include/sys/lwpctl.h minix-sys
./usr/include/sys/lwp.h minix-sys
./usr/include/sys/malloc.h minix-sys
./usr/include/sys/mallocvar.h minix-sys
./usr/include/sys/mbuf.h minix-sys
./usr/include/sys/md4.h minix-sys
./usr/include/sys/md5.h minix-sys
./usr/include/sys/midiio.h minix-sys
./usr/include/sys/mman.h minix-sys
./usr/include/sys/module.h minix-sys
./usr/include/sys/mount.h minix-sys
./usr/include/sys/mqueue.h minix-sys
./usr/include/sys/msgbuf.h minix-sys
./usr/include/sys/msg.h minix-sys
./usr/include/sys/mtio.h minix-sys
./usr/include/sys/mutex.h minix-sys
./usr/include/sys/namei.h minix-sys
./usr/include/sys/null.h minix-sys
./usr/include/sys/param.h minix-sys
./usr/include/sys/pcu.h minix-sys
./usr/include/sys/pipe.h minix-sys
./usr/include/sys/pmc.h minix-sys
./usr/include/sys/poll.h minix-sys
./usr/include/sys/pool.h minix-sys
./usr/include/sys/power.h minix-sys
./usr/include/sys/procfs.h minix-sys
./usr/include/sys/proc.h minix-sys
./usr/include/sys/protosw.h minix-sys
./usr/include/sys/pset.h minix-sys
./usr/include/sys/ptrace.h minix-sys
./usr/include/sys/ptree.h minix-sys
./usr/include/sys/queue.h minix-sys
./usr/include/sys/quotactl.h minix-sys
./usr/include/sys/quota.h minix-sys
./usr/include/sys/radioio.h minix-sys
./usr/include/sys/ras.h minix-sys
./usr/include/sys/rbtree.h minix-sys
./usr/include/sys/reboot.h minix-sys
./usr/include/sys/resource.h minix-sys
./usr/include/sys/resourcevar.h minix-sys
./usr/include/sys/rmd160.h minix-sys
./usr/include/sys/rnd.h minix-sys
./usr/include/sys/rwlock.h minix-sys
./usr/include/sys/scanio.h minix-sys
./usr/include/sys/sched.h minix-sys
./usr/include/sys/scsiio.h minix-sys
./usr/include/sys/sdt.h minix-sys
./usr/include/sys/select.h minix-sys
./usr/include/sys/selinfo.h minix-sys
./usr/include/sys/sem.h minix-sys
./usr/include/sys/sha1.h minix-sys
./usr/include/sys/sha2.h minix-sys
./usr/include/sys/shm.h minix-sys
./usr/include/sys/siginfo.h minix-sys
./usr/include/sys/signal.h minix-sys
./usr/include/sys/signalvar.h minix-sys
./usr/include/sys/sigtypes.h minix-sys
./usr/include/sys/simplelock.h minix-sys
./usr/include/sys/sleepq.h minix-sys
./usr/include/sys/socket.h minix-sys
./usr/include/sys/socketvar.h minix-sys
./usr/include/sys/sockio.h minix-sys
./usr/include/sys/soundcard.h minix-sys
./usr/include/sys/spawn.h minix-sys
./usr/include/sys/specificdata.h minix-sys
./usr/include/sys/statfs.h minix-sys
./usr/include/sys/stat.h minix-sys
@ -1456,27 +1538,51 @@
./usr/include/sys/stdarg.h minix-sys
./usr/include/sys/stdint.h minix-sys
./usr/include/sys/svrctl.h minix-sys
./usr/include/sys/swap.h minix-sys
./usr/include/sys/syncobj.h minix-sys
./usr/include/sys/syscallargs.h minix-sys
./usr/include/sys/syscall.h minix-sys
./usr/include/sys/sysctl.h minix-sys
./usr/include/sys/syslimits.h minix-sys
./usr/include/sys/syslog.h minix-sys
./usr/include/sys/tape.h minix-sys
./usr/include/sys/termios.h minix-sys
./usr/include/sys/timeb.h minix-sys
./usr/include/sys/time.h minix-sys
./usr/include/sys/timepps.h minix-sys
./usr/include/sys/times.h minix-sys
./usr/include/sys/timex.h minix-sys
./usr/include/sys/tls.h minix-sys
./usr/include/sys/trace.h minix-sys
./usr/include/sys/tree.h minix-sys
./usr/include/sys/ttychars.h minix-sys
./usr/include/sys/ttycom.h minix-sys
./usr/include/sys/ttydefaults.h minix-sys
./usr/include/sys/ttydev.h minix-sys
./usr/include/sys/tty.h minix-sys
./usr/include/sys/types.h minix-sys
./usr/include/sys/ucontext.h minix-sys
./usr/include/sys/ucred.h minix-sys
./usr/include/sys/uio.h minix-sys
./usr/include/sys/un.h minix-sys
./usr/include/sys/unistd.h minix-sys
./usr/include/sys/unpcb.h minix-sys
./usr/include/sys/user.h minix-sys
./usr/include/sys/utsname.h minix-sys
./usr/include/sys/uuid.h minix-sys
./usr/include/sys/vadvise.h minix-sys
./usr/include/sys/verified_exec.h minix-sys
./usr/include/sys/video.h minix-sys
./usr/include/sys/videoio.h minix-sys
./usr/include/sys/vm.h minix-sys
./usr/include/sys/vmmeter.h minix-sys
./usr/include/sys/vnode.h minix-sys
./usr/include/sys/vnode_if.h minix-sys
./usr/include/sys/wait.h minix-sys
./usr/include/sys/wapbl.h minix-sys
./usr/include/sys/wapbl_replay.h minix-sys
./usr/include/sys/wdog.h minix-sys
./usr/include/sys/xattr.h minix-sys
./usr/include/sysexits.h minix-sys
./usr/include/syslog.h minix-sys
./usr/include/tar.h minix-sys
@ -1526,6 +1632,29 @@
./usr/include/utmp.h minix-sys
./usr/include/utmpx.h minix-sys
./usr/include/uuid.h minix-sys
./usr/include/uvm minix-sys
./usr/include/uvm/uvm_amap.h minix-sys
./usr/include/uvm/uvm_anon.h minix-sys
./usr/include/uvm/uvm_aobj.h minix-sys
./usr/include/uvm/uvm_device.h minix-sys
./usr/include/uvm/uvm_extern.h minix-sys
./usr/include/uvm/uvm_fault.h minix-sys
./usr/include/uvm/uvm_fault_i.h minix-sys
./usr/include/uvm/uvm_glue.h minix-sys
./usr/include/uvm/uvm.h minix-sys
./usr/include/uvm/uvm_km.h minix-sys
./usr/include/uvm/uvm_loan.h minix-sys
./usr/include/uvm/uvm_map.h minix-sys
./usr/include/uvm/uvm_object.h minix-sys
./usr/include/uvm/uvm_page.h minix-sys
./usr/include/uvm/uvm_pager.h minix-sys
./usr/include/uvm/uvm_param.h minix-sys
./usr/include/uvm/uvm_pdaemon.h minix-sys
./usr/include/uvm/uvm_pglist.h minix-sys
./usr/include/uvm/uvm_pmap.h minix-sys
./usr/include/uvm/uvm_prot.h minix-sys
./usr/include/uvm/uvm_stat.h minix-sys
./usr/include/uvm/uvm_swap.h minix-sys
./usr/include/varargs.h minix-sys
./usr/include/vis.h minix-sys
./usr/include/wchar.h minix-sys
@ -5670,6 +5799,7 @@
./usr/tests/minix-posix/test75 minix-sys
./usr/tests/minix-posix/test76 minix-sys
./usr/tests/minix-posix/test77 minix-sys
./usr/tests/minix-posix/test78 minix-sys
./usr/tests/minix-posix/test8 minix-sys
./usr/tests/minix-posix/test9 minix-sys
./usr/tests/minix-posix/testinterp minix-sys

View file

@ -6,6 +6,10 @@
LIB= utils
.if defined(__MINIX)
WARNS= # empty
.endif
WARNS?= 2
SRCS= datetime.cpp \

View file

@ -43,11 +43,9 @@
*/
#include <sys/dirent.h>
#ifndef __minix
#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
#define d_ino d_fileno /* backward compatibility */
#endif
#endif /* !__minix */
typedef struct _dirdesc DIR;

View file

@ -75,9 +75,7 @@ typedef struct {
#define FTS_PHYSICAL 0x010 /* physical walk */
#define FTS_SEEDOT 0x020 /* return dot and dot-dot */
#define FTS_XDEV 0x040 /* don't cross devices */
#ifndef __minix
#define FTS_WHITEOUT 0x080 /* return whiteout information */
#endif
#define FTS_OPTIONMASK 0x0ff /* valid user option mask */
#define FTS_NAMEONLY 0x100 /* (private) child names only */

View file

@ -2,7 +2,7 @@
INCSDIR= /usr/include/minix
INCS+= dirent.h paths.h param.h
INCS+= paths.h param.h
INCS+= acpi.h audio_fw.h bitmap.h \
bdev.h blockdriver.h blockdriver_mt.h \
board.h btrace.h \

View file

@ -1,34 +0,0 @@
/* dirent.h - Declarations for directory reading routines.
* Author: Kees J. Bot
* 24 Apr 1989
*
* Note: The V7 format directory entries used under Minix must be transformed
* into a struct dirent with a d_name of at least 15 characters. Given that
* we have to transform V7 entries anyhow it is little trouble to let the
* routines understand the so-called "flex" directory format too.
*/
#ifndef _DIRENT_H
#define _DIRENT_H
#include <sys/cdefs.h>
/* Name of length len needs _EXTENT(len) extra slots. */
#define _EXTENT(len) (((len) + 5) >> 3)
/* The block size must be at least 1024 bytes, because otherwise
* the superblock (at 1024 bytes) overlaps with other filesystem data.
*/
#define _MIN_BLOCK_SIZE 1024
/* The below is allocated in some parts of the system as the largest
* a filesystem block can be. For instance, the boot monitor allocates
* 3 of these blocks and has to fit within 64kB, so this can't be
* increased without taking that into account.
*/
#define _MAX_BLOCK_SIZE 4096
/* This is the block size for the fixed versions of the filesystem (V1/V2) */
#define _STATIC_BLOCK_SIZE 1024
#endif /* _DIRENT_H */

View file

@ -3,9 +3,4 @@
int bitmapsize(bit_t _nr_bits, int block_size);
unsigned conv2(int _norm, int _w);
long conv4(int _norm, long _x);
void conv_inode(struct inode *_rip, d1_inode *_dip, d2_inode *_dip2, int
_rw_flag, int _magic);
void old_icopy(struct inode *_rip, d1_inode *_dip, int _direction, int
_norm);
void new_icopy(struct inode *_rip, d2_inode *_dip, int _direction, int
_norm);
void new_icopy(struct inode *_rip, d2_inode *_dip, int _direction, int _norm);

View file

@ -13,6 +13,7 @@ int fsversion(char *_dev, char *_prog);
int getprocessor(void);
void _cpuid(u32_t *eax, u32_t *ebx, u32_t *ecx, u32_t *edx);
int load_mtab(char *_prog_name);
uint8_t fs_mode_to_type(mode_t mode);
int get_mtab_entry(char dev[PATH_MAX], char mount_point[PATH_MAX],
char type[MNTNAMELEN], char flags[MNTFLAGLEN]);

View file

@ -44,6 +44,7 @@ SRCS+= _errno.c alarm.c alphasort.c arc4random.c assert.c basename.c clock.c \
rewinddir.c scandir.c seekdir.c \
setjmperr.c setmode.c \
shquote.c shquotev.c sighold.c sigignore.c siginterrupt.c \
sysctl.c sysctlbyname.c sysctlgetmibinfo.c sysctlnametomib.c \
siglist.c signal.c signame.c sigrelse.c \
sigset.c sigsetops.c sleep.c \
stringlist.c sysconf.c \

View file

@ -69,6 +69,15 @@ static size_t __cvt_node_out(uint, const struct sysctlnode *, void **,
#include <stdlib.h>
#ifdef __minix
int __sysctl(const int *name, unsigned int namelen,
void *oldp, size_t *oldlenp,
const void *newp, size_t newlen)
{
return ENOENT;
}
#endif
int
sysctl(const int *name, unsigned int namelen,
void *oldp, size_t *oldlenp,

View file

@ -6,11 +6,13 @@
#include <sys/types.h>
#include <minix/const.h>
#include <minix/type.h> /* for unshort :-( */
#include <minix/sysutil.h>
#include "mfs/const.h" /* depends of -I flag in Makefile */
#include "mfs/type.h" /* ditto */
#include "mfs/inode.h" /* ditto */
#include "mfs/super.h"
#include <minix/fslib.h>
#include <sys/stat.h>
/* The next routine is copied from fsck.c and mkfs.c... (Re)define some
* things for consistency. Some things should be done better.
@ -41,150 +43,16 @@ int block_size;
return(nr_blocks);
}
/*===========================================================================*
* conv2 *
*===========================================================================*/
unsigned conv2(norm, w)
int norm; /* TRUE if no swap, FALSE for byte swap */
int w; /* promotion of 16-bit word to be swapped */
uint8_t fs_mode_to_type(mode_t mode)
{
/* Possibly swap a 16-bit word between 8086 and 68000 byte order. */
if(S_ISREG(mode)) return DT_REG;
else if(S_ISDIR(mode)) return DT_DIR;
else if(S_ISLNK(mode)) return DT_LNK;
else if(S_ISCHR(mode)) return DT_CHR;
else if(S_ISBLK(mode)) return DT_BLK;
else if(S_ISFIFO(mode)) return DT_FIFO;
else if(S_ISSOCK(mode)) return DT_SOCK;
if (norm) return( (unsigned) w & 0xFFFF);
return( ((w&BYTE) << 8) | ( (w>>8) & BYTE));
panic("unknown type, mode 0x%x", mode);
}
/*===========================================================================*
* conv4 *
*===========================================================================*/
long conv4(norm, x)
int norm; /* TRUE if no swap, FALSE for byte swap */
long x; /* 32-bit long to be byte swapped */
{
/* Possibly swap a 32-bit long between 8086 and 68000 byte order. */
unsigned lo, hi;
long l;
if (norm) return(x); /* byte order was already ok */
lo = conv2(FALSE, (int) x & 0xFFFF); /* low-order half, byte swapped */
hi = conv2(FALSE, (int) (x>>16) & 0xFFFF); /* high-order half, swapped */
l = ( (long) lo <<16) | hi;
return(l);
}
/*===========================================================================*
* conv_inode *
*===========================================================================*/
void conv_inode(rip, dip, dip2, rw_flag, magic)
register struct inode *rip; /* pointer to the in-core inode struct */
register d1_inode *dip; /* pointer to the V1 on-disk inode struct */
register d2_inode *dip2; /* pointer to the V2 on-disk inode struct */
int rw_flag; /* READING or WRITING */
int magic; /* magic number of file system */
{
/* Copy the inode from the disk block to the in-core table or vice versa.
* If the fourth parameter below is FALSE, the bytes are swapped.
*/
switch (magic) {
case SUPER_MAGIC: old_icopy(rip, dip, rw_flag, TRUE); break;
case SUPER_REV: old_icopy(rip, dip, rw_flag, FALSE); break;
case SUPER_V3:
case SUPER_V2: new_icopy(rip, dip2, rw_flag, TRUE); break;
case SUPER_V2_REV: new_icopy(rip, dip2, rw_flag, FALSE); break;
}
}
/*===========================================================================*
* old_icopy *
*===========================================================================*/
void old_icopy(rip, dip, direction, norm)
register struct inode *rip; /* pointer to the in-core inode struct */
register d1_inode *dip; /* pointer to the d1_inode inode struct */
int direction; /* READING (from disk) or WRITING (to disk) */
int norm; /* TRUE = do not swap bytes; FALSE = swap */
{
/* 4 different on-disk inode layouts are supported, one for each combination
* of V1.x/V2.x * bytes-swapped/not-swapped. When an inode is read or written
* this routine handles the conversions so that the information in the inode
* table is independent of the disk structure from which the inode came.
* The old_icopy routine copies to and from V1 disks.
*/
int i;
if (direction == READING) {
/* Copy V1.x inode to the in-core table, swapping bytes if need be. */
rip->i_mode = conv2(norm, dip->d1_mode);
rip->i_uid = conv2(norm,dip->d1_uid );
rip->i_size = conv4(norm,dip->d1_size);
rip->i_mtime = conv4(norm,dip->d1_mtime);
rip->i_atime = 0;
rip->i_ctime = 0;
rip->i_nlinks = (nlink_t) dip->d1_nlinks; /* 1 char */
rip->i_gid = (gid_t) dip->d1_gid; /* 1 char */
rip->i_ndzones = V1_NR_DZONES;
rip->i_nindirs = V1_INDIRECTS;
for (i = 0; i < V1_NR_TZONES; i++)
rip->i_zone[i] = conv2(norm, (int) dip->d1_zone[i]);
} else {
/* Copying V1.x inode to disk from the in-core table. */
dip->d1_mode = conv2(norm,rip->i_mode);
dip->d1_uid = conv2(norm,rip->i_uid );
dip->d1_size = conv4(norm,rip->i_size);
dip->d1_mtime = conv4(norm,rip->i_mtime);
dip->d1_nlinks = (nlink_t) rip->i_nlinks; /* 1 char */
dip->d1_gid = (gid_t) rip->i_gid; /* 1 char */
for (i = 0; i < V1_NR_TZONES; i++)
dip->d1_zone[i] = conv2(norm, (int) rip->i_zone[i]);
}
}
/*===========================================================================*
* new_icopy *
*===========================================================================*/
void new_icopy(rip, dip, direction, norm)
register struct inode *rip; /* pointer to the in-core inode struct */
register d2_inode *dip; /* pointer to the d2_inode struct */
int direction; /* READING (from disk) or WRITING (to disk) */
int norm; /* TRUE = do not swap bytes; FALSE = swap */
{
/* Same as old_icopy, but to/from V2 disk layout. */
int i;
if (direction == READING) {
/* Copy V2.x inode to the in-core table, swapping bytes if need be. */
rip->i_mode = conv2(norm,dip->d2_mode);
rip->i_uid = conv4(norm,dip->d2_uid );
rip->i_nlinks = conv2(norm,(int) dip->d2_nlinks);
rip->i_gid = conv4(norm,(int) dip->d2_gid );
rip->i_size = conv4(norm,dip->d2_size);
rip->i_atime = conv4(norm,dip->d2_atime);
rip->i_ctime = conv4(norm,dip->d2_ctime);
rip->i_mtime = conv4(norm,dip->d2_mtime);
rip->i_ndzones = V2_NR_DZONES;
rip->i_nindirs = V2_INDIRECTS(rip->i_sp->s_block_size);
for (i = 0; i < V2_NR_TZONES; i++)
rip->i_zone[i] = conv4(norm, (long) dip->d2_zone[i]);
} else {
/* Copying V2.x inode to disk from the in-core table. */
dip->d2_mode = conv2(norm,rip->i_mode);
dip->d2_uid = conv4(norm,rip->i_uid );
dip->d2_nlinks = conv2(norm,rip->i_nlinks);
dip->d2_gid = conv4(norm,rip->i_gid );
dip->d2_size = conv4(norm,rip->i_size);
dip->d2_atime = conv4(norm,rip->i_atime);
dip->d2_ctime = conv4(norm,rip->i_ctime);
dip->d2_mtime = conv4(norm,rip->i_mtime);
for (i = 0; i < V2_NR_TZONES; i++)
dip->d2_zone[i] = conv4(norm, (long) rip->i_zone[i]);
}
}

View file

@ -85,9 +85,6 @@ puffs_nextdent(struct dirent **dent, const char *name, ino_t id, uint8_t dtype,
if (o != 0)
reclen += sizeof(long) - o;
/* FIXME: Set d_off?
* dep->d_off =
*/
d->d_reclen = (unsigned short) reclen;
(void)memcpy(d->d_name, name, (size_t)len);
d->d_name[len] = '\0';

View file

@ -87,7 +87,7 @@ int do_getdents()
struct sffs_attr attr;
size_t len, off, user_off, user_left;
off_t pos;
int r;
int r, namelen;
/* must be at least sizeof(struct dirent) + NAME_MAX */
static char buf[BLOCK_SIZE];
@ -171,7 +171,9 @@ int do_getdents()
}
}
len = DWORD_ALIGN(sizeof(struct dirent) + strlen(name));
/* record length incl. alignment. */
namelen = strlen(name);
len = _DIRENT_RECLEN(dent, namelen);
/* Is the user buffer too small to store another record?
* Note that we will be rerequesting the same dentry upon a subsequent
@ -206,8 +208,9 @@ int do_getdents()
/* Fill in the actual directory entry. */
dent = (struct dirent *) &buf[off];
dent->d_ino = INODE_NR(child);
dent->d_off = pos;
dent->d_reclen = len;
dent->d_namlen = namelen;
dent->d_type = IS_DIR(child) ? DT_DIR : DT_REG;
strcpy(dent->d_name, name);
off += len;

View file

@ -2,6 +2,7 @@
#include "inc.h"
#include <dirent.h>
#include <minix/minlib.h>
#define GETDENTS_BUFSIZ 4096
#define DWORD_ALIGN(len) (((len) + sizeof(long) - 1) & ~(sizeof(long) - 1))
@ -161,7 +162,8 @@ int fs_getdents(void)
name = child->i_name;
}
len = DWORD_ALIGN(sizeof(struct dirent) + strlen(name));
/* record length incl. alignment. */
len = _DIRENT_RECLEN(dent, strlen(name));
/* Is the user buffer too small to store another record? */
if (user_off + off + len > user_left) {
@ -190,8 +192,9 @@ int fs_getdents(void)
/* Fill in the actual directory entry. */
dent = (struct dirent *) &buf[off];
dent->d_ino = (ino_t) get_inode_number(child);
dent->d_off = (off_t) pos;
dent->d_reclen = len;
dent->d_type = fs_mode_to_type(child->i_stat.mode);
dent->d_namlen = strlen(name);
strcpy(dent->d_name, name);
off += len;

View file

@ -5,4 +5,8 @@ PROG= mknod
SRCS= mknod.c pack_dev.c
MAN= mknod.8
# LSC Does not compile without any warnings...
NOGCCERROR:=yes
NOCLANGERROR:=yes
.include <bsd.prog.mk>

View file

@ -333,6 +333,9 @@ callPack(pack_t *f, int n, u_long *numbers)
static void
get_device_info(void)
{
#ifdef __minix
err(1, "no kern.drivers on minix" );
#else
static int mib[2] = {CTL_KERN, KERN_DRIVERS};
size_t len;
@ -345,6 +348,7 @@ get_device_info(void)
err(1, "kern.drivers" );
num_drivers = len / sizeof *kern_drivers;
#endif
}
static void

View file

@ -3,8 +3,8 @@ PROG = devman
SRCS = main.c device.c buf.c bind.c
DPADD+= ${LIBSYS}
LDADD = -lvtreefs -lsys
DPADD+= ${LIBSYS} ${LIBMINLIB}
LDADD = -lvtreefs -lsys -lminlib
BINDIR?= /sbin
MAN=

View file

@ -5,8 +5,8 @@ SRCS= balloc.c link.c \
stadir.c table.c time.c utility.c \
write.c ialloc.c inode.c main.c path.c \
super.c
DPADD+= ${LIBMINIXFS} ${LIBBDEV} ${LIBSYS}
LDADD+= -lminixfs -lbdev -lsys
DPADD+= ${LIBMINIXFS} ${LIBBDEV} ${LIBSYS} ${LIBMINLIB}
LDADD+= -lminixfs -lbdev -lsys -lminlib
WARNS=3

View file

@ -14,14 +14,14 @@
#ifndef EXT2_BUF_H
#define EXT2_BUF_H
#include <dirent.h>
#include <sys/dirent.h>
union fsdata_u {
char b__data[_MAX_BLOCK_SIZE]; /* ordinary user data */
char b__data[1]; /* ordinary user data */
/* indirect block */
block_t b__ind[_MAX_BLOCK_SIZE/sizeof(block_t)];
block_t b__ind[1];
/* bit map block */
bitchunk_t b__bitmap[FS_BITMAP_CHUNKS(_MAX_BLOCK_SIZE)];
bitchunk_t b__bitmap[1];
};
/* A block is free if b_dev == NO_DEV. */

View file

@ -12,6 +12,7 @@
#include "inode.h"
#include "super.h"
#include <minix/vfsif.h>
#include <minix/minlib.h>
#include <sys/param.h>
#include <assert.h>
#include <sys/param.h>
@ -619,7 +620,7 @@ int fs_getdents(void)
#define GETDENTS_ENTRIES 8
static char getdents_buf[GETDENTS_BUFSIZE * GETDENTS_ENTRIES];
struct inode *rip;
int o, r, done;
int r, done;
unsigned int block_size, len, reclen;
pino_t ino;
cp_grant_id_t gid;
@ -694,11 +695,8 @@ int fs_getdents(void)
assert(len <= NAME_MAX);
assert(len <= EXT2_NAME_MAX);
/* Compute record length */
reclen = offsetof(struct dirent, d_name) + len + 1;
o = (reclen % sizeof(long));
if (o != 0)
reclen += sizeof(long) - o;
/* Compute record length, incl alignment. */
reclen = _DIRENT_RECLEN(dep, len);
/* Need the position of this entry in the directory */
ent_pos = block_pos + ((char *)d_desc - b_data(bp));
@ -729,11 +727,18 @@ int fs_getdents(void)
}
dep = (struct dirent *) &getdents_buf[tmpbuf_off];
dep->d_ino = (ino_t) conv4(le_CPU, d_desc->d_ino);
dep->d_off = (off_t) ent_pos;
dep->d_fileno = (ino_t) conv4(le_CPU, d_desc->d_ino);
dep->d_reclen = (unsigned short) reclen;
dep->d_namlen = len;
memcpy(dep->d_name, d_desc->d_name, len);
dep->d_name[len] = '\0';
{
struct inode *entrip;
if(!(entrip = get_inode(fs_dev, dep->d_fileno)))
panic("unexpected get_inode failure");
dep->d_type = fs_mode_to_type(entrip->i_mode);
put_inode(entrip);
}
tmpbuf_off += reclen;
}

View file

@ -15,6 +15,7 @@
#include <minix/com.h>
#include <minix/u64.h>
#include <minix/bdev.h>
#include <machine/vmparam.h>
#include "buf.h"
#include "inode.h"
#include "super.h"
@ -74,6 +75,9 @@ register struct super_block *sp; /* pointer to a superblock */
char *buf;
block_t gd_size; /* group descriptors table size in blocks */
int gdt_position;
static char superblock_buf[1024];
ondisk_superblock = (struct super_block *) superblock_buf;
dev = sp->s_dev; /* save device (will be overwritten by copy) */
if (dev == NO_DEV)
@ -86,16 +90,10 @@ register struct super_block *sp; /* pointer to a superblock */
super_block_offset = opt.block_with_super * 1024;
}
STATICINIT(ondisk_superblock, 1);
if (!ondisk_superblock)
panic("can't allocate memory for super_block buffers");
assert(_MIN_BLOCK_SIZE <= sizeof(*ondisk_superblock));
r = bdev_read(dev, ((u64_t)(super_block_offset)), (char*) ondisk_superblock,
_MIN_BLOCK_SIZE, BDEV_NOFLAGS);
sizeof(superblock_buf), BDEV_NOFLAGS);
if (r != _MIN_BLOCK_SIZE)
if (r != sizeof(superblock_buf))
return(EINVAL);
super_copy(sp, ondisk_superblock);
@ -107,8 +105,7 @@ register struct super_block *sp; /* pointer to a superblock */
sp->s_block_size = 1024*(1<<sp->s_log_block_size);
if (sp->s_block_size < _MIN_BLOCK_SIZE
|| sp->s_block_size >_MAX_BLOCK_SIZE) {
if (sp->s_block_size < PAGE_SIZE) {
printf("data block size (%u) is invalid\n", sp->s_block_size);
return(EINVAL);
}

View file

@ -100,20 +100,6 @@ void mfs_nul_f(const char *file, int line, const char *str, unsigned int len,
file, line, #c); panic("sanity check " #c " failed: %d", __LINE__); }
/*===========================================================================*
* sanity_check *
*===========================================================================*/
void sanitycheck(char *file, int line)
{
MYASSERT(SELF_E > 0);
if(superblock->s_dev != NO_DEV) {
MYASSERT(superblock->s_dev == fs_dev);
MYASSERT(superblock->s_block_size == lmfs_fs_block_size());
} else {
MYASSERT(_MIN_BLOCK_SIZE == lmfs_fs_block_size());
}
}
/*===========================================================================*
* ansi_strcmp *
*===========================================================================*/

View file

@ -3,8 +3,8 @@ PROG= isofs
SRCS= main.c table.c mount.c super.c inode.c \
utility.c misc.c path.c read.c stadir.c
DPADD+= ${LIBBDEV} ${LIBSYS}
LDADD+= -lbdev -lsys -lc -lminixfs
DPADD+= ${LIBBDEV} ${LIBSYS} ${LIBMINLIB}
LDADD+= -lbdev -lsys -lc -lminixfs -lminlib
MAN=

View file

@ -1,4 +1,4 @@
#include <dirent.h>
#include <sys/dirent.h>
#define b_data(bp) ((char *) (bp->data))

View file

@ -1,6 +1,7 @@
#include "inc.h"
#include <minix/com.h>
#include <minix/vfsif.h>
#include <minix/minlib.h>
#include <fcntl.h>
#include <stddef.h>
#include "buf.h"
@ -139,7 +140,8 @@ int fs_bread(void)
/*===========================================================================*
* fs_getdents *
*===========================================================================*/
int fs_getdents(void) {
int fs_getdents(void)
{
struct dir_record *dir;
pino_t ino;
cp_grant_id_t gid;
@ -222,14 +224,13 @@ int fs_getdents(void) {
/* Compute the length of the name */
cp = memchr(name, '\0', NAME_MAX);
if (cp == NULL) len = NAME_MAX;
else len= cp - name;
if (cp == NULL)
len = NAME_MAX;
else
len= cp - name;
/* Compute record length */
reclen = offsetof(struct dirent, d_name) + len + 1;
o = (reclen % sizeof(long));
if (o != 0)
reclen += sizeof(long) - o;
/* Compute record length; also does alignment. */
reclen = _DIRENT_RECLEN(dirp, len);
/* If the new record does not fit, then copy the buffer
* and start from the beginning. */
@ -246,9 +247,10 @@ int fs_getdents(void) {
/* The standard data structure is created using the
* data in the buffer. */
dirp = (struct dirent *) &getdents_buf[tmpbuf_offset];
dirp->d_ino = (u32_t)(b_data(bp) + (size_t)block_pos);
dirp->d_off= cur_pos;
dirp->d_fileno = (u32_t)(b_data(bp) + (size_t)block_pos);
dirp->d_reclen= reclen;
dirp->d_type = fs_mode_to_type(dir_tmp->d_mode);
dirp->d_namlen = len;
memcpy(dirp->d_name, name, len);
dirp->d_name[len]= '\0';
tmpbuf_offset += reclen;

View file

@ -16,22 +16,18 @@
* will eventually be rewritten to the disk.
*/
#include <dirent.h>
#include <sys/dirent.h>
union fsdata_u {
char b__data[_MAX_BLOCK_SIZE]; /* ordinary user data */
char b__data[1]; /* ordinary user data */
/* directory block */
struct direct b__dir[NR_DIR_ENTRIES(_MAX_BLOCK_SIZE)];
/* V1 indirect block */
zone1_t b__v1_ind[V1_INDIRECTS];
struct direct b__dir[1];
/* V2 indirect block */
zone_t b__v2_ind[V2_INDIRECTS(_MAX_BLOCK_SIZE)];
/* V1 inode block */
d1_inode b__v1_ino[V1_INODES_PER_BLOCK];
zone_t b__v2_ind[1];
/* V2 inode block */
d2_inode b__v2_ino[V2_INODES_PER_BLOCK(_MAX_BLOCK_SIZE)];
d2_inode b__v2_ino[1];
/* bit map block */
bitchunk_t b__bitmap[FS_BITMAP_CHUNKS(_MAX_BLOCK_SIZE)];
bitchunk_t b__bitmap[1];
};
/* A block is free if b_dev == NO_DEV. */
@ -40,9 +36,7 @@ union fsdata_u {
/* These defs make it possible to use to bp->b_data instead of bp->b.b__data */
#define b_data(b) ((union fsdata_u *) b->data)->b__data
#define b_dir(b) ((union fsdata_u *) b->data)->b__dir
#define b_v1_ind(b) ((union fsdata_u *) b->data)->b__v1_ind
#define b_v2_ind(b) ((union fsdata_u *) b->data)->b__v2_ind
#define b_v1_ino(b) ((union fsdata_u *) b->data)->b__v1_ino
#define b_v2_ino(b) ((union fsdata_u *) b->data)->b__v2_ino
#define b_bitmap(b) ((union fsdata_u *) b->data)->b__bitmap

View file

@ -2,8 +2,6 @@
#define __MFS_CONST_H__
/* Tables sizes */
#define V1_NR_DZONES 7 /* # direct zone numbers in a V1 inode */
#define V1_NR_TZONES 9 /* total # zone numbers in a V1 inode */
#define V2_NR_DZONES 7 /* # direct zone numbers in a V2 inode */
#define V2_NR_TZONES 10 /* total # zone numbers in a V2 inode */
@ -33,7 +31,6 @@
#define SUPER_V2_REV 0x6824 /* V2 magic written on PC, read on 68K or vv */
#define SUPER_V3 0x4d5a /* magic # for V3 file systems */
#define V1 1 /* version number of V1 file systems */
#define V2 2 /* version number of V2 file systems */
#define V3 3 /* version number of V3 file systems */
@ -76,16 +73,6 @@
#define FS_BITCHUNK_BITS (usizeof(bitchunk_t) * CHAR_BIT)
#define FS_BITS_PER_BLOCK(b) (FS_BITMAP_CHUNKS(b) * FS_BITCHUNK_BITS)
/* Derived sizes pertaining to the V1 file system. */
#define V1_ZONE_NUM_SIZE usizeof (zone1_t) /* # bytes in V1 zone */
#define V1_INODE_SIZE usizeof (d1_inode) /* bytes in V1 dsk ino */
/* # zones/indir block */
#define V1_INDIRECTS (_STATIC_BLOCK_SIZE/V1_ZONE_NUM_SIZE)
/* # V1 dsk inodes/blk */
#define V1_INODES_PER_BLOCK (_STATIC_BLOCK_SIZE/V1_INODE_SIZE)
/* Derived sizes pertaining to the V2 file system. */
#define V2_ZONE_NUM_SIZE usizeof (zone_t) /* # bytes in V2 zone */
#define V2_INODE_SIZE usizeof (d2_inode) /* bytes in V2 dsk ino */

View file

@ -21,14 +21,13 @@
#include "inode.h"
#include "super.h"
#include <minix/vfsif.h>
#include <assert.h>
static void addhash_inode(struct inode *node);
static void free_inode(dev_t dev, pino_t numb);
static void new_icopy(struct inode *rip, d2_inode *dip, int direction,
int norm);
static void old_icopy(struct inode *rip, d1_inode *dip, int direction,
int norm);
static void unhash_inode(struct inode *node);
static void wipe_inode(struct inode *rip);
@ -388,7 +387,6 @@ int rw_flag; /* READING or WRITING */
register struct buf *bp;
register struct super_block *sp;
d1_inode *dip;
d2_inode *dip2;
block_t b, offset;
@ -398,7 +396,6 @@ int rw_flag; /* READING or WRITING */
offset = START_BLOCK + sp->s_imap_blocks + sp->s_zmap_blocks;
b = (block_t) (rip->i_num - 1)/sp->s_inodes_per_block + offset;
bp = get_block(rip->i_dev, b, NORMAL);
dip = b_v1_ino(bp) + (rip->i_num - 1) % V1_INODES_PER_BLOCK;
dip2 = b_v2_ino(bp) + (rip->i_num - 1) %
V2_INODES_PER_BLOCK(sp->s_block_size);
@ -411,62 +408,13 @@ int rw_flag; /* READING or WRITING */
/* Copy the inode from the disk block to the in-core table or vice versa.
* If the fourth parameter below is FALSE, the bytes are swapped.
*/
if (sp->s_version == V1)
old_icopy(rip, dip, rw_flag, sp->s_native);
else
assert(sp->s_version == V3);
new_icopy(rip, dip2, rw_flag, sp->s_native);
put_block(bp, INODE_BLOCK);
IN_MARKCLEAN(rip);
}
/*===========================================================================*
* old_icopy *
*===========================================================================*/
static void old_icopy(rip, dip, direction, norm)
register struct inode *rip; /* pointer to the in-core inode struct */
register d1_inode *dip; /* pointer to the d1_inode inode struct */
int direction; /* READING (from disk) or WRITING (to disk) */
int norm; /* TRUE = do not swap bytes; FALSE = swap */
{
/* The V1.x IBM disk, the V1.x 68000 disk, and the V2 disk (same for IBM and
* 68000) all have different inode layouts. When an inode is read or written
* this routine handles the conversions so that the information in the inode
* table is independent of the disk structure from which the inode came.
* The old_icopy routine copies to and from V1 disks.
*/
int i;
if (direction == READING) {
/* Copy V1.x inode to the in-core table, swapping bytes if need be. */
rip->i_mode = (pmode_t) conv2(norm, (int) dip->d1_mode);
rip->i_uid = (uid_t) conv2(norm, (int) dip->d1_uid );
rip->i_size = (off_t) conv4(norm, dip->d1_size);
rip->i_mtime = (time_t) conv4(norm, dip->d1_mtime);
rip->i_atime = (time_t) rip->i_mtime;
rip->i_ctime = (time_t) rip->i_mtime;
rip->i_nlinks = (nlink_t) dip->d1_nlinks; /* 1 char */
rip->i_gid = (gid_t) dip->d1_gid; /* 1 char */
rip->i_ndzones = V1_NR_DZONES;
rip->i_nindirs = V1_INDIRECTS;
for (i = 0; i < V1_NR_TZONES; i++)
rip->i_zone[i] = (zone_t) conv2(norm, (int) dip->d1_zone[i]);
} else {
/* Copying V1.x inode to disk from the in-core table. */
dip->d1_mode = (u16_t) conv2(norm, (int) rip->i_mode);
dip->d1_uid = (i16_t) conv2(norm, (int) rip->i_uid );
dip->d1_size = (i32_t) conv4(norm, rip->i_size);
dip->d1_mtime = (i32_t) conv4(norm, rip->i_mtime);
dip->d1_nlinks = (u8_t) rip->i_nlinks; /* 1 char */
dip->d1_gid = (u8_t) rip->i_gid; /* 1 char */
for (i = 0; i < V1_NR_TZONES; i++)
dip->d1_zone[i] = (u16_t) conv2(norm, (int) rip->i_zone[i]);
}
}
/*===========================================================================*
* new_icopy *
*===========================================================================*/
@ -476,8 +424,6 @@ register d2_inode *dip; /* pointer to the d2_inode struct */
int direction; /* READING (from disk) or WRITING (to disk) */
int norm; /* TRUE = do not swap bytes; FALSE = swap */
{
/* Same as old_icopy, but to/from V2 disk layout. */
int i;
if (direction == READING) {

View file

@ -7,8 +7,6 @@
* such as to search a directory for a path name.
* The first part of the struct holds fields that are present on the
* disk; the second part holds fields not present on the disk.
* The disk inode part is also declared in "type.h" as 'd1_inode' for V1
* file systems and 'd2_inode' for V2 file systems.
*
* Updates:
* 2007-01-06: jfdsmit@gmail.com added i_zsearch

View file

@ -199,17 +199,23 @@ int fs_slink()
/* Allocate a disk block for the contents of the symlink.
* Copy contents of symlink (the name pointed to) into first disk block. */
if( (r = err_code) == OK) {
size_t namelen = (size_t) fs_m_in.REQ_MEM_SIZE;
bp = new_block(sip, (off_t) 0);
if (bp == NULL)
r = err_code;
else
else {
if(get_block_size(sip->i_dev) <= namelen) {
r = ENAMETOOLONG;
} else {
r = sys_safecopyfrom(VFS_PROC_NR,
(cp_grant_id_t) fs_m_in.REQ_GRANT3,
(vir_bytes) 0, (vir_bytes) b_data(bp),
(size_t) fs_m_in.REQ_MEM_SIZE);
namelen);
b_data(bp)[namelen] = '\0';
}
}
if(bp != NULL && r == OK) {
b_data(bp)[_MIN_BLOCK_SIZE-1] = '\0';
sip->i_size = (off_t) strlen(b_data(bp));
if(sip->i_size != fs_m_in.REQ_MEM_SIZE) {
/* This can happen if the user provides a buffer

View file

@ -8,6 +8,7 @@
#include "inode.h"
#include "super.h"
#include <minix/vfsif.h>
#include <minix/minlib.h>
#include <sys/param.h>
#include <assert.h>
@ -420,13 +421,8 @@ zone_t rd_indir(bp, index)
struct buf *bp; /* pointer to indirect block */
int index; /* index into *bp */
{
/* Given a pointer to an indirect block, read one entry. The reason for
* making a separate routine out of this is that there are four cases:
* V1 (IBM and 68000), and V2 (IBM and 68000).
*/
struct super_block *sp;
zone_t zone; /* V2 zones are longs (shorts in V1) */
zone_t zone;
if(bp == NULL)
panic("rd_indir() on NULL");
@ -434,9 +430,7 @@ int index; /* index into *bp */
sp = get_super(lmfs_dev(bp)); /* need super block to find file sys type */
/* read a zone from an indirect block */
if (sp->s_version == V1)
zone = (zone_t) conv2(sp->s_native, (int) b_v1_ind(bp)[index]);
else
assert(sp->s_version == V3);
zone = (zone_t) conv4(sp->s_native, (long) b_v2_ind(bp)[index]);
if (zone != NO_ZONE &&
@ -670,11 +664,8 @@ int fs_getdents(void)
else
len = cp - (dp->mfs_d_name);
/* Compute record length */
reclen = offsetof(struct dirent, d_name) + len + 1;
o = (reclen % sizeof(long));
if (o != 0)
reclen += sizeof(long) - o;
/* Compute record length; also does alignment. */
reclen = _DIRENT_RECLEN(dep, len);
/* Need the position of this entry in the directory */
ent_pos = block_pos + ((char *) dp - (char *) bp->data);
@ -706,10 +697,17 @@ int fs_getdents(void)
}
dep = (struct dirent *) &getdents_buf[tmpbuf_off];
dep->d_ino = (ino_t) dp->mfs_d_ino;
dep->d_off = (off_t) ent_pos;
dep->d_fileno = (ino_t) dp->mfs_d_ino;
dep->d_reclen = (unsigned short) reclen;
dep->d_namlen = len;
memcpy(dep->d_name, dp->mfs_d_name, len);
{
struct inode *entrip;
if(!(entrip = get_inode(fs_dev, dep->d_fileno)))
panic("unexpected get_inode failure");
dep->d_type = fs_mode_to_type(entrip->i_mode);
put_inode(entrip);
}
dep->d_name[len] = '\0';
tmpbuf_off += reclen;
}

View file

@ -17,6 +17,7 @@
#include <minix/com.h>
#include <minix/u64.h>
#include <minix/bdev.h>
#include <machine/vmparam.h>
#include "buf.h"
#include "inode.h"
#include "super.h"
@ -204,7 +205,7 @@ static int rw_super(struct super_block *sp, int writing)
+ sizeof(sp->LAST_ONDISK_FIELD);
assert(ondisk_bytes > 0);
assert(ondisk_bytes < _MIN_BLOCK_SIZE);
assert(ondisk_bytes < PAGE_SIZE);
assert(ondisk_bytes < sizeof(struct super_block));
if (sp->s_dev == NO_DEV)
@ -219,7 +220,6 @@ static int rw_super(struct super_block *sp, int writing)
* disk block.
*/
assert(lmfs_fs_block_size() >= sizeof(struct super_block) + SUPER_BLOCK_BYTES);
assert(lmfs_fs_block_size() >= _MIN_BLOCK_SIZE + SUPER_BLOCK_BYTES);
assert(SUPER_BLOCK_BYTES >= sizeof(struct super_block));
assert(SUPER_BLOCK_BYTES >= ondisk_bytes);
if(!(bp = get_block(sp->s_dev, 0, NORMAL)))
@ -229,7 +229,7 @@ static int rw_super(struct super_block *sp, int writing)
sbbuf = (char *) b_data(bp) + SUPER_BLOCK_BYTES;
if(writing) {
memset(sbbuf, 0, _MIN_BLOCK_SIZE);
memset(b_data(bp), 0, lmfs_fs_block_size());
memcpy(sbbuf, sp, ondisk_bytes);
lmfs_markdirty(bp);
} else {
@ -258,19 +258,13 @@ int read_super(struct super_block *sp)
magic = sp->s_magic; /* determines file system type */
/* Get file system version and type. */
if (magic == SUPER_MAGIC || magic == conv2(BYTE_SWAP, SUPER_MAGIC)) {
version = V1;
native = (magic == SUPER_MAGIC);
} else if (magic == SUPER_V2 || magic == conv2(BYTE_SWAP, SUPER_V2)) {
version = V2;
native = (magic == SUPER_V2);
} else if (magic == SUPER_V3) {
/* Get file system version and type - only support v3. */
if(magic != SUPER_V3) {
printf("MFS: only supports V3 filesystems.\n");
return EINVAL;
}
version = V3;
native = 1;
} else {
return(EINVAL);
}
/* If the super block has the wrong byte order, swap the fields; the magic
* number doesn't need conversion. */
@ -283,37 +277,17 @@ int read_super(struct super_block *sp)
sp->s_max_size = (off_t) conv4(native, sp->s_max_size);
sp->s_zones = (zone_t)conv4(native, sp->s_zones);
/* In V1, the device size was kept in a short, s_nzones, which limited
* devices to 32K zones. For V2, it was decided to keep the size as a
* long. However, just changing s_nzones to a long would not work, since
* then the position of s_magic in the super block would not be the same
* in V1 and V2 file systems, and there would be no way to tell whether
* a newly mounted file system was V1 or V2. The solution was to introduce
* a new variable, s_zones, and copy the size there.
*
* Calculate some other numbers that depend on the version here too, to
/* Calculate some other numbers that depend on the version here too, to
* hide some of the differences.
*/
if (version == V1) {
sp->s_block_size = _STATIC_BLOCK_SIZE;
sp->s_zones = (zone_t) sp->s_nzones; /* only V1 needs this copy */
sp->s_inodes_per_block = V1_INODES_PER_BLOCK;
sp->s_ndzones = V1_NR_DZONES;
sp->s_nindirs = V1_INDIRECTS;
} else {
if (version == V2) {
sp->s_block_size = _STATIC_BLOCK_SIZE;
} else {
sp->s_block_size = (unsigned short)
conv2(native,(int) sp->s_block_size);
}
if (sp->s_block_size < _MIN_BLOCK_SIZE) {
assert(version == V3);
sp->s_block_size = (unsigned short) conv2(native,(int) sp->s_block_size);
if (sp->s_block_size < PAGE_SIZE) {
return EINVAL;
}
sp->s_inodes_per_block = V2_INODES_PER_BLOCK(sp->s_block_size);
sp->s_ndzones = V2_NR_DZONES;
sp->s_nindirs = V2_INDIRECTS(sp->s_block_size);
}
/* For even larger disks, a similar problem occurs with s_firstdatazone.
* If the on-disk field contains zero, we assume that the value was too
@ -330,7 +304,7 @@ int read_super(struct super_block *sp)
sp->s_firstdatazone = (zone_t) sp->s_firstdatazone_old;
}
if (sp->s_block_size < _MIN_BLOCK_SIZE)
if (sp->s_block_size < PAGE_SIZE)
return(EINVAL);
if ((sp->s_block_size % 512) != 0)
@ -339,8 +313,7 @@ int read_super(struct super_block *sp)
if (SUPER_SIZE > sp->s_block_size)
return(EINVAL);
if ((sp->s_block_size % V2_INODE_SIZE) != 0 ||
(sp->s_block_size % V1_INODE_SIZE) != 0) {
if ((sp->s_block_size % V2_INODE_SIZE) != 0) {
return(EINVAL);
}

View file

@ -35,10 +35,6 @@ EXTERN struct super_block {
/* The following items are valid on disk only for V3 and above */
/* The block size in bytes. Minimum MIN_BLOCK SIZE. SECTOR_SIZE
* multiple. If V1 or V2 filesystem, this should be
* initialised to STATIC_BLOCK_SIZE.
*/
short s_pad2; /* try to avoid compiler-dependent padding */
unsigned short s_block_size; /* block size in bytes. */
char s_disk_version; /* filesystem format sub-version */

View file

@ -3,17 +3,6 @@
#include <minix/libminixfs.h>
/* Declaration of the V1 inode as it is on the disk (not in core). */
typedef struct { /* V1.x disk inode */
u16_t d1_mode; /* file type, protection, etc. */
i16_t d1_uid; /* user id of the file's owner */
i32_t d1_size; /* current file size in bytes */
i32_t d1_mtime; /* when was file data last changed */
u8_t d1_gid; /* group number */
u8_t d1_nlinks; /* how many links to this file */
u16_t d1_zone[V1_NR_TZONES]; /* block nums for direct, ind, and dbl ind */
} d1_inode;
/* Declaration of the V2 inode as it is on the disk (not in core). */
typedef struct { /* V2.x disk inode */
u16_t d2_mode; /* file type, protection, etc. */

View file

@ -95,18 +95,3 @@ unsigned int maxlen)
#define MYASSERT(c) if(!(c)) { printf("MFS:%s:%d: sanity check: %s failed\n", \
file, line, #c); panic("sanity check " #c " failed: %d", __LINE__); }
/*===========================================================================*
* sanity_check *
*===========================================================================*/
void sanitycheck(char *file, int line)
{
MYASSERT(SELF_E > 0);
if(superblock.s_dev != NO_DEV) {
MYASSERT(superblock.s_dev == fs_dev);
MYASSERT(superblock.s_block_size == lmfs_fs_block_size());
} else {
MYASSERT(_MIN_BLOCK_SIZE == lmfs_fs_block_size());
}
}

View file

@ -204,9 +204,7 @@ zone_t zone; /* zone to write */
sp = get_super(lmfs_dev(bp)); /* need super block to find file sys type */
/* write a zone into an indirect block */
if (sp->s_version == V1)
b_v1_ind(bp)[index] = (zone1_t) conv2(sp->s_native, (int) zone);
else
assert(sp->s_version == V3);
b_v2_ind(bp)[index] = (zone_t) conv4(sp->s_native, (long) zone);
}

View file

@ -8,8 +8,8 @@ SRCS= buf.c main.c pid.c root.c tree.c util.c cpuinfo.c
CPPFLAGS+= -I${NETBSDSRCDIR} -I${NETBSDSRCDIR}/servers
DPADD+= ${LIBVTREEFS}
LDADD+= -lvtreefs
DPADD+= ${LIBVTREEFS} ${LIBMINLIB}
LDADD+= -lvtreefs -lminlib
MAN=

View file

@ -15,7 +15,7 @@
#include <fcntl.h>
#include <lib.h>
#include <minix/timers.h>
#include <dirent.h>
#include <sys/dirent.h>
#include <minix/callnr.h>
#include <minix/type.h>

View file

@ -24,7 +24,7 @@
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <sys/dirent.h>
#include <sys/exec.h>
#include <sys/param.h>
#include "path.h"
@ -548,7 +548,7 @@ vir_bytes *vsp;
off_t pos, new_pos;
char *sp, *interp = NULL;
unsigned int cum_io;
char buf[_MAX_BLOCK_SIZE];
char buf[PAGE_SIZE];
/* Make 'path' the new argv[0]. */
if (!insert_arg(stack, stk_bytes, path, vsp, REPLACE)) return(ENOMEM);
@ -557,13 +557,13 @@ vir_bytes *vsp;
/* Issue request */
r = req_readwrite(vp->v_fs_e, vp->v_inode_nr, pos, READING, VFS_PROC_NR,
(vir_bytes) buf, _MAX_BLOCK_SIZE, &new_pos, &cum_io);
(vir_bytes) buf, sizeof(buf), &new_pos, &cum_io);
if (r != OK) return(r);
n = vp->v_size;
if (n > _MAX_BLOCK_SIZE)
n = _MAX_BLOCK_SIZE;
if (n > sizeof(buf))
n = sizeof(buf);
if (n < 2) return ENOEXEC;
sp = &(buf[2]); /* just behind the #! */

View file

@ -17,7 +17,7 @@
#include <minix/com.h>
#include <minix/callnr.h>
#include <minix/vfsif.h>
#include <dirent.h>
#include <sys/dirent.h>
#include <assert.h>
#include "file.h"
#include "path.h"

View file

@ -20,7 +20,7 @@
#include <unistd.h>
#include <sys/stat.h>
#include <sys/mount.h>
#include <dirent.h>
#include <sys/dirent.h>
#include <assert.h>
#include "file.h"
#include <minix/vfsif.h>

View file

@ -21,7 +21,7 @@
#include "scratchpad.h"
#include "lock.h"
#include "param.h"
#include <dirent.h>
#include <sys/dirent.h>
#include <assert.h>
#include <minix/vfsif.h>
#include "vnode.h"

View file

@ -16,7 +16,7 @@
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/un.h>
#include <dirent.h>
#include <sys/dirent.h>
#include "vmnt.h"
#include "vnode.h"
#include "path.h"
@ -640,7 +640,7 @@ char ename[NAME_MAX + 1];
if(cur->d_name + name_len+1 > &buf[sizeof(buf)])
return(EINVAL); /* Rubbish in dir entry */
if (entry->v_inode_nr == cur->d_ino) {
if (entry->v_inode_nr == cur->d_fileno) {
/* found the entry we were looking for */
int copylen = MIN(name_len + 1, NAME_MAX + 1);
if (strlcpy(ename, cur->d_name, copylen) >= copylen) {

View file

@ -16,7 +16,7 @@
#include <minix/u64.h>
#include <minix/vfsif.h>
#include <assert.h>
#include <dirent.h>
#include <sys/dirent.h>
#include <fcntl.h>
#include <unistd.h>
#include "file.h"

View file

@ -5,7 +5,7 @@
SUBDIR= arch dev \
net netinet netinet6 \
\
sys ufs
sys ufs uvm
.if !defined(__MINIX)
# LSC the test is OR, but as it is not relevant to MINIX, we have

View file

@ -9,7 +9,7 @@ INCS= aeabi.h ansi.h asm.h \
elf_machdep.h endian.h endian_machdep.h \
float.h \
ieee.h ieeefp.h \
int_const.h int_fmtio.h int_limits.h int_mwgwtypes.h int_types.h \
proc.h int_const.h int_fmtio.h int_limits.h int_mwgwtypes.h int_types.h \
\
limits.h lock.h \
math.h mcontext.h mutex.h \

View file

@ -0,0 +1,61 @@
/* $NetBSD: proc.h,v 1.12 2012/08/16 17:35:01 matt Exp $ */
/*
* Copyright (c) 1994 Mark Brinicombe.
* 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 acknowledgement:
* This product includes software developed by the RiscBSD team.
* 4. The name "RiscBSD" nor the name of the author may be used to
* endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY RISCBSD ``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 RISCBSD 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.
*/
#ifndef _ARM32_PROC_H_
#define _ARM32_PROC_H_
/*
* Machine-dependent part of the proc structure for arm.
*/
struct trapframe;
struct lwp;
struct mdlwp {
struct trapframe *md_tf;
int md_flags;
};
/* Flags setttings for md_flags */
#define MDLWP_VFPUSED 0x00000001 /* Process used the VFP */
#define MDLWP_NOALIGNFLT 0x00000002 /* For EXEC_AOUT */
struct mdproc {
void (*md_syscall)(struct trapframe *, struct lwp *, uint32_t);
int pmc_enabled; /* bitfield of enabled counters */
void *pmc_state; /* port-specific pmc state */
};
#endif /* _ARM32_PROC_H_ */

View file

@ -13,7 +13,7 @@ INCS= ansi.h asm.h \
\
limits.h lock.h \
math.h mcontext.h mutex.h \
param.h profile.h \
param.h proc.h profile.h \
rwlock.h \
setjmp.h signal.h \
types.h \

View file

@ -0,0 +1,3 @@
/* $NetBSD: proc.h,v 1.1 2001/11/25 15:56:05 thorpej Exp $ */
#include <arm/proc.h>

View file

@ -7,8 +7,8 @@ INCS= ansi.h asm.h \
cdefs.h cpu.h \
disklabel.h \
elf_machdep.h endian.h endian_machdep.h \
fenv.h float.h \
\
fenv.h float.h proc.h frame.h pcb.h segments.h tss.h sysarch.h \
lock.h \
ieee.h ieeefp.h \
int_const.h int_fmtio.h int_limits.h int_mwgwtypes.h int_types.h \
\

View file

@ -0,0 +1,178 @@
/* $NetBSD: frame.h,v 1.35 2012/02/19 21:06:11 rmind Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Charles M. Hannum.
*
* 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.
*/
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* William Jolitz.
*
* 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 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.
*
* @(#)frame.h 5.2 (Berkeley) 1/18/91
*/
#ifndef _I386_FRAME_H_
#define _I386_FRAME_H_
#include <sys/signal.h>
/*
* System stack frames.
*/
/*
* Exception/Trap Stack Frame
*/
struct trapframe {
uint16_t tf_gs;
uint16_t tf_gs_pad;
uint16_t tf_fs;
uint16_t tf_fs_pad;
uint16_t tf_es;
uint16_t tf_es_pad;
uint16_t tf_ds;
uint16_t tf_ds_pad;
int tf_edi;
int tf_esi;
int tf_ebp;
int tf_ebx;
int tf_edx;
int tf_ecx;
int tf_eax;
int tf_trapno;
/* below portion defined in 386 hardware */
int tf_err;
int tf_eip;
int tf_cs;
int tf_eflags;
/* below used when transitting rings (e.g. user to kernel) */
int tf_esp;
int tf_ss;
/* below used when switching out of VM86 mode */
int tf_vm86_es;
int tf_vm86_ds;
int tf_vm86_fs;
int tf_vm86_gs;
};
/*
* Interrupt stack frame
*/
struct intrframe {
int if_ppl;
int if_gs;
int if_fs;
int if_es;
int if_ds;
int if_edi;
int if_esi;
int if_ebp;
int if_ebx;
int if_edx;
int if_ecx;
int if_eax;
uint32_t __if_trapno; /* for compat with trap frame - trapno */
uint32_t __if_err; /* for compat with trap frame - err */
/* below portion defined in 386 hardware */
int if_eip;
int if_cs;
int if_eflags;
/* below only when transitting rings (e.g. user to kernel) */
int if_esp;
int if_ss;
};
/*
* Stack frame inside cpu_switchto()
*/
struct switchframe {
int sf_edi;
int sf_esi;
int sf_ebx;
int sf_eip;
};
#ifdef _KERNEL
/*
* Old-style signal frame
*/
struct sigframe_sigcontext {
int sf_ra; /* return address for handler */
int sf_signum; /* "signum" argument for handler */
int sf_code; /* "code" argument for handler */
struct sigcontext *sf_scp; /* "scp" argument for handler */
struct sigcontext sf_sc; /* actual saved context */
};
#endif
/*
* New-style signal frame
*/
struct sigframe_siginfo {
int sf_ra; /* return address for handler */
int sf_signum; /* "signum" argument for handler */
siginfo_t *sf_sip; /* "sip" argument for handler */
ucontext_t *sf_ucp; /* "ucp" argument for handler */
siginfo_t sf_si; /* actual saved siginfo */
ucontext_t sf_uc; /* actual saved ucontext */
};
#ifdef _KERNEL
void *getframe(struct lwp *, int, int *);
void buildcontext(struct lwp *, int, void *, void *);
void sendsig_sigcontext(const ksiginfo_t *, const sigset_t *);
#endif
#endif /* _I386_FRAME_H_ */

View file

@ -0,0 +1,3 @@
/* $NetBSD: lock.h,v 1.9 2003/02/27 00:12:22 fvdl Exp $ */
#include <x86/lock.h>

View file

@ -42,7 +42,6 @@
#ifndef _I386_NPX_H_
#define _I386_NPX_H_
#ifndef __minix
/* Environment information of floating point unit */
struct env87 {
long en_cw; /* control word (16bits) */
@ -121,7 +120,6 @@ union savefpu {
struct save87 sv_87;
struct savexmm sv_xmm;
};
#endif /* !__minix */
/*
* The i387 defaults to Intel extended precision mode and round to nearest,

115
sys/arch/i386/include/pcb.h Normal file
View file

@ -0,0 +1,115 @@
/* $NetBSD: pcb.h,v 1.48 2010/04/23 16:07:33 joerg Exp $ */
/*-
* Copyright (c) 1998, 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Charles M. Hannum, and by Andrew Doran.
*
* 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.
*/
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* William Jolitz.
*
* 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 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.
*
* @(#)pcb.h 5.10 (Berkeley) 5/12/91
*/
/*
* Intel 386 process control block
*/
#ifndef _I386_PCB_H_
#define _I386_PCB_H_
#if defined(_KERNEL_OPT)
#include "opt_multiprocessor.h"
#endif
#include <sys/signal.h>
#include <machine/segments.h>
#include <machine/tss.h>
#include <i386/npx.h>
#include <i386/sysarch.h>
struct pcb {
int pcb_esp0; /* ring0 esp */
int pcb_esp; /* kernel esp */
int pcb_ebp; /* kernel ebp */
int pcb_unused; /* unused */
int pcb_cr0; /* saved image of CR0 */
int pcb_cr2; /* page fault address (CR2) */
int pcb_cr3; /* page directory pointer */
int pcb_iopl; /* i/o privilege level */
/* floating point state for FPU */
union savefpu pcb_savefpu __aligned(16);
struct segment_descriptor pcb_fsd; /* %fs descriptor */
struct segment_descriptor pcb_gsd; /* %gs descriptor */
void * pcb_onfault; /* copyin/out fault recovery */
int vm86_eflags; /* virtual eflags for vm86 mode */
int vm86_flagmask; /* flag mask for vm86 mode */
void *vm86_userp; /* XXX performance hack */
struct cpu_info *pcb_fpcpu; /* cpu holding our fp state. */
char *pcb_iomap; /* I/O permission bitmap */
};
/*
* The pcb is augmented with machine-dependent additional data for
* core dumps. For the i386, there is nothing to add.
*/
struct md_coredump {
long md_pad[8];
};
#endif /* _I386_PCB_H_ */

View file

@ -0,0 +1,73 @@
/* $NetBSD: proc.h,v 1.38 2011/01/14 02:06:26 rmind Exp $ */
/*
* Copyright (c) 1991 Regents of the University of California.
* 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 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.
*
* @(#)proc.h 7.1 (Berkeley) 5/15/91
*/
#ifndef _I386_PROC_H_
#define _I386_PROC_H_
#include <machine/frame.h>
#include <machine/pcb.h>
/*
* Machine-dependent part of the lwp structure for i386.
*/
struct pmap;
struct vm_page;
struct mdlwp {
struct trapframe *md_regs; /* registers on current frame */
int md_flags; /* machine-dependent flags */
volatile int md_astpending; /* AST pending for this process */
struct pmap *md_gc_pmap; /* pmap being garbage collected */
struct vm_page *md_gc_ptp; /* pages from pmap g/c */
};
/* md_flags */
#define MDL_USEDFPU 0x0001 /* has used the FPU */
#define MDL_IOPL 0x0002 /* XEN: i/o privilege */
struct mdproc {
int md_flags;
void (*md_syscall)(struct trapframe *);
/* Syscall handling function */
};
/* md_flags */
#define MDP_USEDMTRR 0x0002 /* has set volatile MTRRs */
/* Kernel stack parameters. */
#define UAREA_PCB_OFFSET (USPACE - ALIGN(sizeof(struct pcb)))
#define KSTACK_LOWEST_ADDR(l) \
((void *)((vaddr_t)(l)->l_addr - UAREA_PCB_OFFSET))
#define KSTACK_SIZE UAREA_PCB_OFFSET
#endif /* _I386_PROC_H_ */

View file

@ -0,0 +1,340 @@
/* $NetBSD: segments.h,v 1.54 2011/04/26 15:51:23 joerg Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* William Jolitz.
*
* 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 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.
*
* @(#)segments.h 7.1 (Berkeley) 5/9/91
*/
/*-
* Copyright (c) 1995, 1997
* Charles M. Hannum. All rights reserved.
* Copyright (c) 1989, 1990 William F. Jolitz
*
* This code is derived from software contributed to Berkeley by
* William Jolitz.
*
* 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 acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 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.
*
* @(#)segments.h 7.1 (Berkeley) 5/9/91
*/
/*
* 386 Segmentation Data Structures and definitions
* William F. Jolitz (william@ernie.berkeley.edu) 6/20/1989
*/
#ifndef _I386_SEGMENTS_H_
#define _I386_SEGMENTS_H_
#ifdef _KERNEL_OPT
#include "opt_xen.h"
#endif
/*
* Selectors
*/
#define ISPL(s) ((s) & SEL_RPL) /* what is the priority level of a selector */
#ifndef XEN
#define SEL_KPL 0 /* kernel privilege level */
#else
#define SEL_XEN 0 /* Xen privilege level */
#define SEL_KPL 1 /* kernel privilege level */
#endif /* XEN */
#define SEL_UPL 3 /* user privilege level */
#define SEL_RPL 3 /* requester's privilege level mask */
#ifdef XEN
#define CHK_UPL 2 /* user privilege level mask */
#else
#define CHK_UPL SEL_RPL
#endif /* XEN */
#define ISLDT(s) ((s) & SEL_LDT) /* is it local or global */
#define SEL_LDT 4 /* local descriptor table */
#define IDXSEL(s) (((s) >> 3) & 0x1fff) /* index of selector */
#define IDXSELN(s) (((s) >> 3)) /* index of selector */
#define GSEL(s,r) (((s) << 3) | r) /* a global selector */
#define LSEL(s,r) (((s) << 3) | r | SEL_LDT) /* a local selector */
#define GSYSSEL(s,r) GSEL(s,r) /* compat with amd64 */
#if defined(_KERNEL_OPT)
#include "opt_vm86.h"
#endif
#ifdef VM86
#define USERMODE(c, f) (ISPL(c) == SEL_UPL || ((f) & PSL_VM) != 0)
#define KERNELMODE(c, f) (ISPL(c) == SEL_KPL && ((f) & PSL_VM) == 0)
#else
#define USERMODE(c, f) (ISPL(c) == SEL_UPL)
#define KERNELMODE(c, f) (ISPL(c) == SEL_KPL)
#endif
#ifndef _LOCORE
#if __GNUC__ == 2 && __GNUC_MINOR__ < 7
#pragma pack(1)
#endif
/*
* Memory and System segment descriptors
*/
struct segment_descriptor {
unsigned sd_lolimit:16; /* segment extent (lsb) */
unsigned sd_lobase:24; /* segment base address (lsb) */
unsigned sd_type:5; /* segment type */
unsigned sd_dpl:2; /* segment descriptor priority level */
unsigned sd_p:1; /* segment descriptor present */
unsigned sd_hilimit:4; /* segment extent (msb) */
unsigned sd_xx:2; /* unused */
unsigned sd_def32:1; /* default 32 vs 16 bit size */
unsigned sd_gran:1; /* limit granularity (byte/page) */
unsigned sd_hibase:8; /* segment base address (msb) */
} __packed;
/*
* Gate descriptors (e.g. indirect descriptors)
*/
struct gate_descriptor {
unsigned gd_looffset:16; /* gate offset (lsb) */
unsigned gd_selector:16; /* gate segment selector */
unsigned gd_stkcpy:5; /* number of stack wds to cpy */
unsigned gd_xx:3; /* unused */
unsigned gd_type:5; /* segment type */
unsigned gd_dpl:2; /* segment descriptor priority level */
unsigned gd_p:1; /* segment descriptor present */
unsigned gd_hioffset:16; /* gate offset (msb) */
} __packed;
struct ldt_descriptor {
vaddr_t ld_base;
uint32_t ld_entries;
} __packed;
/*
* Generic descriptor
*/
union descriptor {
struct segment_descriptor sd;
struct gate_descriptor gd;
struct ldt_descriptor ld;
uint32_t raw[2];
uint64_t raw64;
} __packed;
/*
* region descriptors, used to load gdt/idt tables before segments yet exist.
*/
struct region_descriptor {
unsigned rd_limit:16; /* segment extent */
unsigned rd_base:32; /* base address */
} __packed;
#if __GNUC__ == 2 && __GNUC_MINOR__ < 7
#pragma pack(4)
#endif
#ifdef _KERNEL
extern union descriptor *gdt, *ldt;
extern struct gate_descriptor *idt;
void setgate(struct gate_descriptor *, void *, int, int, int, int);
void setregion(struct region_descriptor *, void *, size_t);
void setsegment(struct segment_descriptor *, const void *, size_t, int, int,
int, int);
void setgdt(int, const void *, size_t, int, int, int, int);
void unsetgate(struct gate_descriptor *);
void cpu_init_idt(void);
void update_descriptor(union descriptor *, union descriptor *);
#if !defined(XEN)
void idt_init(void);
void idt_vec_reserve(int);
int idt_vec_alloc(int, int);
void idt_vec_set(int, void (*)(void));
void idt_vec_free(int);
#endif
#endif /* _KERNEL */
#endif /* !_LOCORE */
/* system segments and gate types */
#define SDT_SYSNULL 0 /* system null */
#define SDT_SYS286TSS 1 /* system 286 TSS available */
#define SDT_SYSLDT 2 /* system local descriptor table */
#define SDT_SYS286BSY 3 /* system 286 TSS busy */
#define SDT_SYS286CGT 4 /* system 286 call gate */
#define SDT_SYSTASKGT 5 /* system task gate */
#define SDT_SYS286IGT 6 /* system 286 interrupt gate */
#define SDT_SYS286TGT 7 /* system 286 trap gate */
#define SDT_SYSNULL2 8 /* system null again */
#define SDT_SYS386TSS 9 /* system 386 TSS available */
#define SDT_SYSNULL3 10 /* system null again */
#define SDT_SYS386BSY 11 /* system 386 TSS busy */
#define SDT_SYS386CGT 12 /* system 386 call gate */
#define SDT_SYSNULL4 13 /* system null again */
#define SDT_SYS386IGT 14 /* system 386 interrupt gate */
#define SDT_SYS386TGT 15 /* system 386 trap gate */
/* memory segment types */
#define SDT_MEMRO 16 /* memory read only */
#define SDT_MEMROA 17 /* memory read only accessed */
#define SDT_MEMRW 18 /* memory read write */
#define SDT_MEMRWA 19 /* memory read write accessed */
#define SDT_MEMROD 20 /* memory read only expand dwn limit */
#define SDT_MEMRODA 21 /* memory read only expand dwn limit accessed */
#define SDT_MEMRWD 22 /* memory read write expand dwn limit */
#define SDT_MEMRWDA 23 /* memory read write expand dwn limit acessed */
#define SDT_MEME 24 /* memory execute only */
#define SDT_MEMEA 25 /* memory execute only accessed */
#define SDT_MEMER 26 /* memory execute read */
#define SDT_MEMERA 27 /* memory execute read accessed */
#define SDT_MEMEC 28 /* memory execute only conforming */
#define SDT_MEMEAC 29 /* memory execute only accessed conforming */
#define SDT_MEMERC 30 /* memory execute read conforming */
#define SDT_MEMERAC 31 /* memory execute read accessed conforming */
#define SDTYPE(p) (((const struct segment_descriptor *)(p))->sd_type)
/* is memory segment descriptor pointer ? */
#define ISMEMSDP(s) (SDTYPE(s) >= SDT_MEMRO && \
SDTYPE(s) <= SDT_MEMERAC)
/* is 286 gate descriptor pointer ? */
#define IS286GDP(s) (SDTYPE(s) >= SDT_SYS286CGT && \
SDTYPE(s) < SDT_SYS286TGT)
/* is 386 gate descriptor pointer ? */
#define IS386GDP(s) (SDTYPE(s) >= SDT_SYS386CGT && \
SDTYPE(s) < SDT_SYS386TGT)
/* is gate descriptor pointer ? */
#define ISGDP(s) (IS286GDP(s) || IS386GDP(s))
/* is segment descriptor pointer ? */
#define ISSDP(s) (ISMEMSDP(s) || !ISGDP(s))
/* is system segment descriptor pointer ? */
#define ISSYSSDP(s) (!ISMEMSDP(s) && !ISGDP(s))
/*
* Segment Protection Exception code bits
*/
#define SEGEX_EXT 0x01 /* recursive or externally induced */
#define SEGEX_IDT 0x02 /* interrupt descriptor table */
#define SEGEX_TI 0x04 /* local descriptor table */
/*
* Entries in the Interrupt Descriptor Table (IDT)
*/
#define NIDT 256
#define NRSVIDT 32 /* reserved entries for CPU exceptions */
/*
* Entries in the Global Descriptor Table (GDT).
*
* NB: If you change GBIOSCODE/GBIOSDATA, you *must* rebuild arch/i386/
* bioscall/biostramp.inc, as that relies on GBIOSCODE/GBIOSDATA and a
* normal kernel build does not rebuild it (it's merely included whole-
* sale from i386/bioscall.s)
*
* Also, note that the GEXTBIOSDATA_SEL selector is special, as it maps
* to the value 0x0040 (when created as a KPL global selector). Some
* BIOSes reference the extended BIOS data area at segment 0040 in a non
* relocatable fashion (even when in protected mode); mapping the zero page
* via the GEXTBIOSDATA_SEL allows these buggy BIOSes to continue to work
* under NetBSD.
*
* The order if the first 5 descriptors is special; the sysenter/sysexit
* instructions depend on them.
*/
#define GNULL_SEL 0 /* Null descriptor */
#define GCODE_SEL 1 /* Kernel code descriptor */
#define GDATA_SEL 2 /* Kernel data descriptor */
#define GUCODE_SEL 3 /* User code descriptor */
#define GUDATA_SEL 4 /* User data descriptor */
#define GLDT_SEL 5 /* Default LDT descriptor */
#define GCPU_SEL 6 /* per-CPU segment */
#define GEXTBIOSDATA_SEL 8 /* magic to catch BIOS refs to EBDA */
#define GAPM32CODE_SEL 9 /* 3 APM segments must be consecutive */
#define GAPM16CODE_SEL 10 /* and in the specified order: code32 */
#define GAPMDATA_SEL 11 /* code16 and then data per APM spec */
#define GBIOSCODE_SEL 12
#define GBIOSDATA_SEL 13
#define GPNPBIOSCODE_SEL 14
#define GPNPBIOSDATA_SEL 15
#define GPNPBIOSSCRATCH_SEL 16
#define GPNPBIOSTRAMP_SEL 17
#define GTRAPTSS_SEL 18
#define GIPITSS_SEL 19
#define GUCODEBIG_SEL 20 /* User code with executable stack */
#define GUFS_SEL 21 /* Per-thread %fs */
#define GUGS_SEL 22 /* Per-thread %gs */
#define NGDT 23
/*
* Entries in the Local Descriptor Table (LDT).
* DO NOT ADD KERNEL DATA/CODE SEGMENTS TO THIS TABLE.
*/
#define LSYS5CALLS_SEL 0 /* iBCS system call gate */
#define LSYS5SIGR_SEL 1 /* iBCS sigreturn gate */
#define LUCODE_SEL 2 /* User code descriptor */
#define LUDATA_SEL 3 /* User data descriptor */
#define LSOL26CALLS_SEL 4 /* Solaris 2.6 system call gate */
#define LUCODEBIG_SEL 5 /* User code with executable stack */
#define LBSDICALLS_SEL 16 /* BSDI system call gate */
#define NLDT 17
#endif /* _I386_SEGMENTS_H_ */

View file

@ -0,0 +1,3 @@
/* $NetBSD: sysarch.h,v 1.18 2007/04/16 19:12:19 ad Exp $ */
#include <x86/sysarch.h>

View file

@ -0,0 +1,79 @@
/* $NetBSD: tss.h,v 1.10 2008/01/05 21:45:00 yamt Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* William Jolitz.
*
* 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 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.
*
* @(#)tss.h 5.4 (Berkeley) 1/18/91
*/
#ifndef _I386_TSS_H_
#define _I386_TSS_H_
/*
* Intel 386 Context Data Type
*/
struct i386tss {
int __tss_link;
int tss_esp0; /* kernel stack pointer at privilege level 0 */
int tss_ss0; /* kernel stack segment at privilege level 0 */
int __tss_esp1;
int __tss_ss1;
int __tss_esp2;
int __tss_ss2;
int tss_cr3; /* page directory paddr */
int __tss_eip;
int __tss_eflags;
int __tss_eax;
int __tss_ecx;
int __tss_edx;
int __tss_ebx;
int tss_esp; /* saved stack pointer */
int tss_ebp; /* saved frame pointer */
int __tss_esi;
int __tss_edi;
int __tss_es;
int __tss_cs;
int __tss_ss;
int __tss_ds;
int tss_fs; /* saved segment register */
int tss_gs; /* saved segment register */
int tss_ldt; /* LDT selector */
int tss_iobase; /* options and I/O permission map offset */
};
/*
* I/O bitmap offset beyond TSS's segment limit means no bitmaps.
* (i.e. any I/O attempt generates an exception.)
*/
#define IOMAP_INVALOFF 0xffff
#endif /* #ifndef _I386_TSS_H_ */

View file

@ -4,43 +4,43 @@
INCSDIR= /usr/include/sys
INCS= ansi.h atomic.h \
bitops.h bootblock.h bswap.h \
cdefs.h cdefs_aout.h \
cdefs_elf.h condvar.h \
ctype_bits.h ctype_inline.h \
\
dirent.h \
disk.h disklabel.h disklabel_acorn.h disklabel_gpt.h \
dkbad.h dkio.h \
endian.h errno.h exec.h \
exec_elf.h extattr.h \
fcntl.h fd_set.h featuretest.h file.h \
float_ieee754.h fstypes.h gcq.h gmon.h hash.h \
ieee754.h inttypes.h ioccom.h ioctl.h iostat.h ipc.h \
\
lwp.h \
localedef.h lock.h \
md4.h md5.h \
mman.h mount.h mtio.h mutex.h \
null.h \
param.h poll.h \
ptrace.h ptree.h \
queue.h \
ras.h rbtree.h reboot.h resource.h rmd160.h \
rwlock.h \
select.h sem.h sha1.h \
sha2.h shm.h siginfo.h signal.h sigtypes.h \
socket.h specificdata.h \
stat.h \
statvfs.h sysctl.h stdarg.h stdint.h \
syslimits.h syslog.h \
termios.h time.h times.h \
tls.h tree.h ttycom.h \
ttydefaults.h types.h \
ucontext.h ucred.h uio.h un.h unistd.h utsname.h uuid.h \
\
wait.h
INCS= acct.h agpio.h aio.h ansi.h aout_mids.h ataio.h atomic.h audioio.h \
bitops.h bootblock.h bswap.h buf.h \
callback.h callout.h cdefs.h cdefs_aout.h \
cdefs_elf.h cdio.h chio.h clockctl.h condvar.h conf.h core.h \
cpufreq.h cpuio.h ctype_bits.h ctype_inline.h \
device.h device_if.h \
dir.h dirent.h \
disk.h disklabel.h disklabel_acorn.h disklabel_gpt.h disklabel_rdb.h \
dkbad.h dkio.h dkstat.h domain.h drvctlio.h dvdio.h \
endian.h envsys.h errno.h evcnt.h event.h exec.h exec_aout.h \
exec_coff.h exec_ecoff.h exec_elf.h exec_script.h extattr.h extent.h \
fcntl.h fd_set.h fdio.h featuretest.h file.h filedesc.h filio.h \
flashio.h float_ieee754.h fstypes.h gcq.h gmon.h gpio.h hash.h \
ieee754.h inttypes.h ioccom.h ioctl.h ioctl_compat.h iostat.h ipc.h \
joystick.h \
kcore.h kcpuset.h kgdb.h kmem.h ksem.h ksyms.h ktrace.h \
localedef.h lock.h lockf.h lwp.h lwpctl.h \
malloc.h mallocvar.h mbuf.h md4.h md5.h midiio.h \
mman.h module.h mount.h mqueue.h msg.h msgbuf.h mtio.h mutex.h \
namei.h null.h \
param.h pcu.h pipe.h pmc.h poll.h pool.h power.h proc.h \
protosw.h pset.h ptrace.h ptree.h \
queue.h quota.h quotactl.h \
ras.h rbtree.h reboot.h radioio.h resource.h resourcevar.h rmd160.h \
rnd.h rwlock.h \
scanio.h sched.h scsiio.h sdt.h select.h selinfo.h sem.h sha1.h \
sha2.h shm.h siginfo.h signal.h signalvar.h sigtypes.h simplelock.h \
sleepq.h socket.h \
socketvar.h sockio.h spawn.h specificdata.h stat.h \
statvfs.h syscall.h syscallargs.h sysctl.h stdarg.h stdint.h swap.h \
syncobj.h syslimits.h syslog.h \
tape.h termios.h time.h timeb.h timepps.h times.h \
timex.h tls.h trace.h tree.h tty.h ttychars.h ttycom.h \
ttydefaults.h ttydev.h types.h \
ucontext.h ucred.h uio.h un.h unistd.h unpcb.h user.h utsname.h uuid.h \
vadvise.h verified_exec.h videoio.h vmmeter.h vnode.h vnode_if.h \
wait.h wapbl.h wapbl_replay.h wdog.h xattr.h
INCSYMLINKS=\
sys/exec_elf.h /usr/include/elf.h \
@ -56,7 +56,7 @@ INCSYMLINKS=\
sys/md4.h /usr/include/md4.h \
sys/md5.h /usr/include/md5.h
#INCSYMLINKS+= ../soundcard.h ${INCSDIR}/soundcard.h
INCSYMLINKS+= ../soundcard.h ${INCSDIR}/soundcard.h
namei: namei.src gennameih.awk
${TOOL_AWK} -f gennameih.awk < namei.src

80
sys/sys/acct.h Normal file
View file

@ -0,0 +1,80 @@
/* $NetBSD: acct.h,v 1.27 2009/01/11 02:45:55 christos Exp $ */
/*-
* Copyright (c) 1990, 1993, 1994
* 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.
* 3. 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.
*
* @(#)acct.h 8.3 (Berkeley) 7/10/94
*/
#ifndef _SYS_ACCT_H_
#define _SYS_ACCT_H_
/*
* Accounting structures; these use a comp_t type which is a 3 bits base 8
* exponent, 13 bit fraction ``floating point'' number. Units are 1/AHZ
* seconds.
*/
typedef uint16_t comp_t;
struct acct {
char ac_comm[16]; /* command name */
comp_t ac_utime; /* user time */
comp_t ac_stime; /* system time */
comp_t ac_etime; /* elapsed time */
time_t ac_btime; /* starting time */
uid_t ac_uid; /* user id */
gid_t ac_gid; /* group id */
uint16_t ac_mem; /* average memory usage */
comp_t ac_io; /* count of IO blocks */
dev_t ac_tty; /* controlling tty */
#define AFORK 0x01 /* fork'd but not exec'd */
#define ASU 0x02 /* used super-user permissions */
#define ACOMPAT 0x04 /* used compatibility mode */
#define ACORE 0x08 /* dumped core */
#define AXSIG 0x10 /* killed by a signal */
uint8_t ac_flag; /* accounting flags */
};
/*
* 1/AHZ is the granularity of the data encoded in the comp_t fields.
* This is not necessarily equal to hz.
*/
#define AHZ 64
#ifdef _KERNEL
void acct_init(void);
int acct_process(struct lwp *);
#endif
#endif /* !_SYS_ACCT_H_ */

144
sys/sys/agpio.h Normal file
View file

@ -0,0 +1,144 @@
/* $NetBSD: agpio.h,v 1.10 2011/02/15 08:57:01 jmcneill Exp $ */
/*-
* Copyright (c) 2000 Doug Rabson
* 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: src/sys/sys/agpio.h,v 1.1 2000/06/09 16:04:30 dfr Exp $
*/
#ifndef _SYS_AGPIO_H_
#define _SYS_AGPIO_H_
/*
* The AGP gatt uses 4k pages irrespective of the host page size.
*/
#define AGP_PAGE_SIZE 4096
#define AGP_PAGE_SHIFT 12
/*
* Macros to manipulate AGP mode words.
*/
#define AGP_MODE_GET_RQ(x) (((x) & 0xff000000U) >> 24)
#define AGP_MODE_GET_ARQSZ(x) (((x) & 0x0000e000U) >> 13)
#define AGP_MODE_GET_CAL(x) (((x) & 0x00001c00U) >> 10)
#define AGP_MODE_GET_SBA(x) (((x) & 0x00000200U) >> 9)
#define AGP_MODE_GET_AGP(x) (((x) & 0x00000100U) >> 8)
#define AGP_MODE_GET_4G(x) (((x) & 0x00000020U) >> 5)
#define AGP_MODE_GET_FW(x) (((x) & 0x00000010U) >> 4)
#define AGP_MODE_GET_MODE_3(x) (((x) & 0x00000008U) >> 3)
#define AGP_MODE_GET_RATE(x) ((x) & 0x00000007U)
#define AGP_MODE_SET_RQ(x,v) (((x) & ~0xff000000U) | ((v) << 24))
#define AGP_MODE_SET_ARQSZ(x,v) (((x) & ~0x0000e000U) | ((v) << 13))
#define AGP_MODE_SET_CAL(x,v) (((x) & ~0x00001c00U) | ((v) << 10))
#define AGP_MODE_SET_SBA(x,v) (((x) & ~0x00000200U) | ((v) << 9))
#define AGP_MODE_SET_AGP(x,v) (((x) & ~0x00000100U) | ((v) << 8))
#define AGP_MODE_SET_4G(x,v) (((x) & ~0x00000020U) | ((v) << 5))
#define AGP_MODE_SET_FW(x,v) (((x) & ~0x00000010U) | ((v) << 4))
#define AGP_MODE_SET_MODE_3(x,v) (((x) & ~0x00000008U) | ((v) << 3))
#define AGP_MODE_SET_RATE(x,v) (((x) & ~0x00000007U) | (v))
#define AGP_MODE_V2_RATE_1x 0x00000001
#define AGP_MODE_V2_RATE_2x 0x00000002
#define AGP_MODE_V2_RATE_4x 0x00000004
#define AGP_MODE_V3_RATE_4x 0x00000001
#define AGP_MODE_V3_RATE_8x 0x00000002
#define AGP_MODE_V3_RATE_RSVD 0x00000004
/* compat */
#define AGP_MODE_RATE_1x AGP_MODE_V2_RATE_1x
#define AGP_MODE_RATE_2x AGP_MODE_V2_RATE_2x
#define AGP_MODE_RATE_4x AGP_MODE_V2_RATE_4x
#define AGPIOC_BASE 'A'
#define AGPIOC_INFO _IOR (AGPIOC_BASE, 0, agp_info)
#define AGPIOC_ACQUIRE _IO (AGPIOC_BASE, 1)
#define AGPIOC_RELEASE _IO (AGPIOC_BASE, 2)
#define AGPIOC_SETUP _IOW (AGPIOC_BASE, 3, agp_setup)
#if 0
#define AGPIOC_RESERVE _IOW (AGPIOC_BASE, 4, agp_region)
#define AGPIOC_PROTECT _IOW (AGPIOC_BASE, 5, agp_region)
#endif
#define AGPIOC_ALLOCATE _IOWR(AGPIOC_BASE, 6, agp_allocate)
#define AGPIOC_DEALLOCATE _IOW (AGPIOC_BASE, 7, int)
#define AGPIOC_BIND _IOW (AGPIOC_BASE, 8, agp_bind)
#define AGPIOC_UNBIND _IOW (AGPIOC_BASE, 9, agp_unbind)
typedef struct _agp_version {
uint16_t major;
uint16_t minor;
} agp_version;
typedef struct _agp_info {
agp_version version; /* version of the driver */
uint32_t bridge_id; /* bridge vendor/device */
uint32_t agp_mode; /* mode info of bridge */
off_t aper_base; /* base of aperture */
size_t aper_size; /* size of aperture */
size_t pg_total; /* max pages (swap + system) */
size_t pg_system; /* max pages (system) */
size_t pg_used; /* current pages used */
} agp_info;
typedef struct _agp_setup {
uint32_t agp_mode; /* mode info of bridge */
} agp_setup;
#if 0
/*
* The "prot" down below needs still a "sleep" flag somehow ...
*/
typedef struct _agp_segment {
off_t pg_start; /* starting page to populate */
size_t pg_count; /* number of pages */
int prot; /* prot flags for mmap */
} agp_segment;
typedef struct _agp_region {
pid_t pid; /* pid of process */
size_t seg_count; /* number of segments */
struct _agp_segment *seg_list;
} agp_region;
#endif
typedef struct _agp_allocate {
int key; /* tag of allocation */
size_t pg_count; /* number of pages */
uint32_t type; /* 0 == normal, other devspec */
uint32_t physical; /* device specific (some devices
* need a phys address of the
* actual page behind the gatt
* table) */
} agp_allocate;
typedef struct _agp_bind {
int key; /* tag of allocation */
off_t pg_start; /* starting page to populate */
} agp_bind;
typedef struct _agp_unbind {
int key; /* tag of allocation */
uint32_t priority; /* priority for paging out */
} agp_unbind;
#endif /* !_SYS_AGPIO_H_ */

126
sys/sys/aio.h Normal file
View file

@ -0,0 +1,126 @@
/* $NetBSD: aio.h,v 1.12 2012/01/07 19:48:19 christos Exp $ */
/*
* Copyright (c) 2007, Mindaugas Rasiukevicius <rmind at NetBSD 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.
*/
#ifndef _SYS_AIO_H_
#define _SYS_AIO_H_
#include <sys/types.h>
#include <sys/signal.h>
/* Returned by aio_cancel() */
#define AIO_CANCELED 0x1
#define AIO_NOTCANCELED 0x2
#define AIO_ALLDONE 0x3
/* LIO opcodes */
#define LIO_NOP 0x0
#define LIO_WRITE 0x1
#define LIO_READ 0x2
/* LIO modes */
#define LIO_NOWAIT 0x0
#define LIO_WAIT 0x1
/*
* Asynchronous I/O structure.
* Defined in the Base Definitions volume of IEEE Std 1003.1-2001 .
*/
struct aiocb {
off_t aio_offset; /* File offset */
volatile void *aio_buf; /* I/O buffer in process space */
size_t aio_nbytes; /* Length of transfer */
int aio_fildes; /* File descriptor */
int aio_lio_opcode; /* LIO opcode */
int aio_reqprio; /* Request priority offset */
struct sigevent aio_sigevent; /* Signal to deliver */
/* Internal kernel variables */
int _state; /* State of the job */
int _errno; /* Error value */
ssize_t _retval; /* Return value */
};
/* Internal kernel data */
#ifdef _KERNEL
/* Default limits of allowed AIO operations */
#define AIO_LISTIO_MAX 512
#define AIO_MAX AIO_LISTIO_MAX * 16
#include <sys/condvar.h>
#include <sys/lwp.h>
#include <sys/mutex.h>
#include <sys/pool.h>
#include <sys/queue.h>
/* Operations (as flags) */
#define AIO_LIO 0x00
#define AIO_READ 0x01
#define AIO_WRITE 0x02
#define AIO_SYNC 0x04
#define AIO_DSYNC 0x08
/* Job states */
#define JOB_NONE 0x0
#define JOB_WIP 0x1
#define JOB_DONE 0x2
/* Structure of AIO job */
struct aio_job {
int aio_op; /* Operation code */
struct aiocb aiocbp; /* AIO data structure */
void *aiocb_uptr; /* User-space pointer for identification of job */
TAILQ_ENTRY(aio_job) list;
struct lio_req *lio;
};
/* LIO structure */
struct lio_req {
u_int refcnt; /* Reference counter */
struct sigevent sig; /* Signal of lio_listio() calls */
};
/* Structure of AIO data for process */
struct aioproc {
kmutex_t aio_mtx; /* Protects the entire structure */
kcondvar_t aio_worker_cv; /* Signals on a new job */
kcondvar_t done_cv; /* Signals when the job is done */
struct aio_job *curjob; /* Currently processing AIO job */
unsigned int jobs_count; /* Count of the jobs */
TAILQ_HEAD(, aio_job) jobs_queue;/* Queue of the AIO jobs */
struct lwp *aio_worker; /* AIO worker thread */
};
extern u_int aio_listio_max;
/* Prototypes */
void aio_print_jobs(void (*)(const char *, ...) __printflike(1, 2));
int aio_suspend1(struct lwp *, struct aiocb **, int, struct timespec *);
#endif /* _KERNEL */
#endif /* _SYS_AIO_H_ */

68
sys/sys/aout_mids.h Normal file
View file

@ -0,0 +1,68 @@
/* $NetBSD: aout_mids.h,v 1.1 2009/08/20 22:07:49 he Exp $ */
/*
* Copyright (c) 2009, The NetBSD Foundation, 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.
*
* 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.
*/
#ifndef _SYS_MACHINE_IDS_H_
#define _SYS_MACHINE_IDS_H_
/*
* a_mid - keep sorted in numerical order for sanity's sake
* ensure that: 0 < mid < 0x3ff
*/
#define MID_ZERO 0 /* unknown - implementation dependent */
#define MID_SUN010 1 /* sun 68010/68020 binary */
#define MID_SUN020 2 /* sun 68020-only binary */
#define MID_PC386 100 /* 386 PC binary. (so quoth BFD) */
#define MID_HP200 200 /* hp200 (68010) BSD binary */
#define MID_I386 134 /* i386 BSD binary */
#define MID_M68K 135 /* m68k BSD binary with 8K page sizes */
#define MID_M68K4K 136 /* m68k BSD binary with 4K page sizes */
#define MID_NS32532 137 /* ns32532 */
#define MID_SPARC 138 /* sparc */
#define MID_PMAX 139 /* pmax */
#define MID_VAX1K 140 /* VAX 1K page size binaries */
#define MID_ALPHA 141 /* Alpha BSD binary */
#define MID_MIPS 142 /* big-endian MIPS */
#define MID_ARM6 143 /* ARM6 */
#define MID_M680002K 144 /* m68000 with 2K page sizes */
#define MID_SH3 145 /* SH3 */
#define MID_POWERPC 149 /* big-endian PowerPC */
#define MID_VAX 150 /* VAX */
/* 151 - MIPS1 */
/* 152 - MIPS2 */
#define MID_M88K 153 /* m88k BSD */
#define MID_HPPA 154 /* HP PARISC */
#define MID_SH5_64 155 /* LP64 SH5 */
#define MID_SPARC64 156 /* LP64 sparc */
#define MID_X86_64 157 /* AMD x86-64 */
#define MID_SH5_32 158 /* ILP32 SH5 */
#define MID_HP200 200 /* hp200 (68010) BSD binary */
#define MID_HP300 300 /* hp300 (68020+68881) BSD binary */
#define MID_HPUX 0x20C /* hp200/300 HP-UX binary */
#define MID_HPUX800 0x20B /* hp800 HP-UX binary */
#endif /* _SYS_MACHINE_IDS_H_ */

56
sys/sys/ataio.h Normal file
View file

@ -0,0 +1,56 @@
/* $NetBSD: ataio.h,v 1.9 2012/01/24 20:04:07 jakllsch Exp $ */
#ifndef _SYS_ATAIO_H_
#define _SYS_ATAIO_H_
#include <sys/types.h>
#include <sys/ioctl.h>
typedef struct atareq {
u_long flags; /* info about the request status and type */
u_char command; /* command code */
u_char features; /* feature modifier bits for command */
u_char sec_count; /* sector count */
u_char sec_num; /* sector number */
u_char head; /* head number */
u_short cylinder; /* cylinder/lba address */
void * databuf; /* Pointer to I/O data buffer */
u_long datalen; /* length of data buffer */
int timeout; /* Command timeout */
u_char retsts; /* the return status for the command */
u_char error; /* error bits */
} atareq_t;
/* bit definitions for flags */
#define ATACMD_READ 0x00000001
#define ATACMD_WRITE 0x00000002
#define ATACMD_READREG 0x00000004
#define ATACMD_LBA 0x00000008
/* definitions for the return status (retsts) */
#define ATACMD_OK 0x00
#define ATACMD_TIMEOUT 0x01
#define ATACMD_ERROR 0x02
#define ATACMD_DF 0x03
#define ATAIOCCOMMAND _IOWR('Q', 8, atareq_t)
/*
* ATA bus IOCTL
*/
/* Scan bus for new devices. */
struct atabusioscan_args {
int at_dev; /* device to scan, -1 for wildcard */
};
#define ATABUSIOSCAN _IOW('A', 50, struct atabusioscan_args)
#define ATABUSIORESET _IO('A', 51) /* reset ATA bus */
struct atabusiodetach_args {
int at_dev; /* device to detach; -1 for wildcard */
};
#define ATABUSIODETACH _IOW('A', 52, struct atabusiodetach_args)
#endif /* _SYS_ATAIO_H_ */

338
sys/sys/audioio.h Normal file
View file

@ -0,0 +1,338 @@
/* $NetBSD: audioio.h,v 1.34 2011/09/06 01:16:43 jmcneill Exp $ */
/*
* Copyright (c) 1991-1993 Regents of the University of California.
* 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 acknowledgement:
* This product includes software developed by the Computer Systems
* Engineering Group at Lawrence Berkeley Laboratory.
* 4. Neither the name of the University nor of the Laboratory 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.
*
*/
#ifndef _SYS_AUDIOIO_H_
#define _SYS_AUDIOIO_H_
#include <sys/types.h>
#include <sys/ioccom.h>
#ifndef _KERNEL
#include <string.h> /* Required for memset(3) prototype (AUDIO_INITINFO) */
#endif /* _KERNEL */
/*
* Audio device
*/
struct audio_prinfo {
u_int sample_rate; /* sample rate in bit/s */
u_int channels; /* number of channels, usually 1 or 2 */
u_int precision; /* number of bits/sample */
u_int encoding; /* data encoding (AUDIO_ENCODING_* below) */
u_int gain; /* volume level */
u_int port; /* selected I/O port */
u_int seek; /* BSD extension */
u_int avail_ports; /* available I/O ports */
u_int buffer_size; /* total size audio buffer */
u_int _ispare[1];
/* Current state of device: */
u_int samples; /* number of samples */
u_int eof; /* End Of File (zero-size writes) counter */
u_char pause; /* non-zero if paused, zero to resume */
u_char error; /* non-zero if underflow/overflow ocurred */
u_char waiting; /* non-zero if another process hangs in open */
u_char balance; /* stereo channel balance */
u_char cspare[2];
u_char open; /* non-zero if currently open */
u_char active; /* non-zero if I/O is currently active */
};
typedef struct audio_prinfo audio_prinfo_t;
struct audio_info {
struct audio_prinfo play; /* Info for play (output) side */
struct audio_prinfo record; /* Info for record (input) side */
u_int monitor_gain; /* input to output mix */
/* BSD extensions */
u_int blocksize; /* H/W read/write block size */
u_int hiwat; /* output high water mark */
u_int lowat; /* output low water mark */
u_int _ispare1;
u_int mode; /* current device mode */
#define AUMODE_PLAY 0x01
#define AUMODE_RECORD 0x02
#define AUMODE_PLAY_ALL 0x04 /* don't do real-time correction */
};
typedef struct audio_info audio_info_t;
#define AUDIO_INITINFO(p) \
(void)memset((void *)(p), 0xff, sizeof(struct audio_info))
/*
* Parameter for the AUDIO_GETDEV ioctl to determine current
* audio devices.
*/
#define MAX_AUDIO_DEV_LEN 16
typedef struct audio_device {
char name[MAX_AUDIO_DEV_LEN];
char version[MAX_AUDIO_DEV_LEN];
char config[MAX_AUDIO_DEV_LEN];
} audio_device_t;
typedef struct audio_offset {
u_int samples; /* Total number of bytes transferred */
u_int deltablks; /* Blocks transferred since last checked */
u_int offset; /* Physical transfer offset in buffer */
} audio_offset_t;
/*
* Supported audio encodings
*/
/* Encoding ID's */
#define AUDIO_ENCODING_NONE 0 /* no encoding assigned */
#define AUDIO_ENCODING_ULAW 1 /* ITU G.711 mu-law */
#define AUDIO_ENCODING_ALAW 2 /* ITU G.711 A-law */
#define AUDIO_ENCODING_PCM16 3 /* signed linear PCM, obsolete */
#define AUDIO_ENCODING_LINEAR AUDIO_ENCODING_PCM16 /* SunOS compat */
#define AUDIO_ENCODING_PCM8 4 /* unsigned linear PCM, obsolete */
#define AUDIO_ENCODING_LINEAR8 AUDIO_ENCODING_PCM8 /* SunOS compat */
#define AUDIO_ENCODING_ADPCM 5 /* adaptive differential PCM */
#define AUDIO_ENCODING_SLINEAR_LE 6
#define AUDIO_ENCODING_SLINEAR_BE 7
#define AUDIO_ENCODING_ULINEAR_LE 8
#define AUDIO_ENCODING_ULINEAR_BE 9
#define AUDIO_ENCODING_SLINEAR 10
#define AUDIO_ENCODING_ULINEAR 11
#define AUDIO_ENCODING_MPEG_L1_STREAM 12
#define AUDIO_ENCODING_MPEG_L1_PACKETS 13
#define AUDIO_ENCODING_MPEG_L1_SYSTEM 14
#define AUDIO_ENCODING_MPEG_L2_STREAM 15
#define AUDIO_ENCODING_MPEG_L2_PACKETS 16
#define AUDIO_ENCODING_MPEG_L2_SYSTEM 17
#define AUDIO_ENCODING_AC3 18
typedef struct audio_encoding {
int index;
char name[MAX_AUDIO_DEV_LEN];
int encoding;
int precision;
int flags;
#define AUDIO_ENCODINGFLAG_EMULATED 1 /* software emulation mode */
} audio_encoding_t;
/*
* Balance settings.
*/
#define AUDIO_LEFT_BALANCE 0 /* left channel only */
#define AUDIO_MID_BALANCE 32 /* equal left/right channel */
#define AUDIO_RIGHT_BALANCE 64 /* right channel only */
#define AUDIO_BALANCE_SHIFT 3
/*
* Output ports
*/
#define AUDIO_SPEAKER 0x01 /* built-in speaker */
#define AUDIO_HEADPHONE 0x02 /* headphone jack */
#define AUDIO_LINE_OUT 0x04 /* line out */
/*
* Input ports
*/
#define AUDIO_MICROPHONE 0x01 /* microphone */
#define AUDIO_LINE_IN 0x02 /* line in */
#define AUDIO_CD 0x04 /* on-board CD inputs */
#define AUDIO_INTERNAL_CD_IN AUDIO_CD /* internal CDROM */
/*
* Audio device operations
*/
#define AUDIO_GETINFO _IOR('A', 21, struct audio_info)
#define AUDIO_SETINFO _IOWR('A', 22, struct audio_info)
#define AUDIO_DRAIN _IO('A', 23)
#define AUDIO_FLUSH _IO('A', 24)
#define AUDIO_WSEEK _IOR('A', 25, u_long)
#define AUDIO_RERROR _IOR('A', 26, int)
#define AUDIO_GETDEV _IOR('A', 27, struct audio_device)
#define AUDIO_GETENC _IOWR('A', 28, struct audio_encoding)
#define AUDIO_GETFD _IOR('A', 29, int)
#define AUDIO_SETFD _IOWR('A', 30, int)
#define AUDIO_PERROR _IOR('A', 31, int)
#define AUDIO_GETIOFFS _IOR('A', 32, struct audio_offset)
#define AUDIO_GETOOFFS _IOR('A', 33, struct audio_offset)
#define AUDIO_GETPROPS _IOR('A', 34, int)
#define AUDIO_PROP_FULLDUPLEX 0x01
#define AUDIO_PROP_MMAP 0x02
#define AUDIO_PROP_INDEPENDENT 0x04
#define AUDIO_PROP_PLAYBACK 0x10
#define AUDIO_PROP_CAPTURE 0x20
#define AUDIO_GETBUFINFO _IOR('A', 35, struct audio_info)
/*
* Mixer device
*/
#define AUDIO_MIN_GAIN 0
#define AUDIO_MAX_GAIN 255
typedef struct mixer_level {
int num_channels;
u_char level[8]; /* [num_channels] */
} mixer_level_t;
#define AUDIO_MIXER_LEVEL_MONO 0
#define AUDIO_MIXER_LEVEL_LEFT 0
#define AUDIO_MIXER_LEVEL_RIGHT 1
/*
* Device operations
*/
typedef struct audio_mixer_name {
char name[MAX_AUDIO_DEV_LEN];
int msg_id;
} audio_mixer_name_t;
typedef struct mixer_devinfo {
int index;
audio_mixer_name_t label;
int type;
#define AUDIO_MIXER_CLASS 0
#define AUDIO_MIXER_ENUM 1
#define AUDIO_MIXER_SET 2
#define AUDIO_MIXER_VALUE 3
int mixer_class;
int next, prev;
#define AUDIO_MIXER_LAST -1
union {
struct audio_mixer_enum {
int num_mem;
struct {
audio_mixer_name_t label;
int ord;
} member[32];
} e;
struct audio_mixer_set {
int num_mem;
struct {
audio_mixer_name_t label;
int mask;
} member[32];
} s;
struct audio_mixer_value {
audio_mixer_name_t units;
int num_channels;
int delta;
} v;
} un;
} mixer_devinfo_t;
typedef struct mixer_ctrl {
int dev;
int type;
union {
int ord; /* enum */
int mask; /* set */
mixer_level_t value; /* value */
} un;
} mixer_ctrl_t;
/*
* Mixer operations
*/
#define AUDIO_MIXER_READ _IOWR('M', 0, mixer_ctrl_t)
#define AUDIO_MIXER_WRITE _IOWR('M', 1, mixer_ctrl_t)
#define AUDIO_MIXER_DEVINFO _IOWR('M', 2, mixer_devinfo_t)
/*
* Well known device names
*/
#define AudioNmicrophone "mic"
#define AudioNline "line"
#define AudioNcd "cd"
#define AudioNdac "dac"
#define AudioNaux "aux"
#define AudioNrecord "record"
#define AudioNvolume "volume"
#define AudioNmonitor "monitor"
#define AudioNtreble "treble"
#define AudioNmid "mid"
#define AudioNbass "bass"
#define AudioNbassboost "bassboost"
#define AudioNspeaker "speaker"
#define AudioNheadphone "headphones"
#define AudioNoutput "output"
#define AudioNinput "input"
#define AudioNmaster "master"
#define AudioNstereo "stereo"
#define AudioNmono "mono"
#define AudioNloudness "loudness"
#define AudioNspatial "spatial"
#define AudioNsurround "surround"
#define AudioNpseudo "pseudo"
#define AudioNmute "mute"
#define AudioNenhanced "enhanced"
#define AudioNpreamp "preamp"
#define AudioNon "on"
#define AudioNoff "off"
#define AudioNmode "mode"
#define AudioNsource "source"
#define AudioNfmsynth "fmsynth"
#define AudioNwave "wave"
#define AudioNmidi "midi"
#define AudioNmixerout "mixerout"
#define AudioNswap "swap" /* swap left and right channels */
#define AudioNagc "agc"
#define AudioNdelay "delay"
#define AudioNselect "select" /* select destination */
#define AudioNvideo "video"
#define AudioNcenter "center"
#define AudioNdepth "depth"
#define AudioNlfe "lfe"
#define AudioEmulaw "mulaw"
#define AudioEalaw "alaw"
#define AudioEadpcm "adpcm"
#define AudioEslinear "slinear"
#define AudioEslinear_le "slinear_le"
#define AudioEslinear_be "slinear_be"
#define AudioEulinear "ulinear"
#define AudioEulinear_le "ulinear_le"
#define AudioEulinear_be "ulinear_be"
#define AudioEmpeg_l1_stream "mpeg_l1_stream"
#define AudioEmpeg_l1_packets "mpeg_l1_packets"
#define AudioEmpeg_l1_system "mpeg_l1_system"
#define AudioEmpeg_l2_stream "mpeg_l2_stream"
#define AudioEmpeg_l2_packets "mpeg_l2_packets"
#define AudioEmpeg_l2_system "mpeg_l2_system"
#define AudioEac3 "ac3"
#define AudioCinputs "inputs"
#define AudioCoutputs "outputs"
#define AudioCrecord "record"
#define AudioCmonitor "monitor"
#define AudioCequalization "equalization"
#define AudioCmodem "modem"
#endif /* !_SYS_AUDIOIO_H_ */

90
sys/sys/blist.h Normal file
View file

@ -0,0 +1,90 @@
/* $NetBSD: blist.h,v 1.7 2005/12/11 12:25:20 christos Exp $ */
/*-
* Copyright (c) 1998 Matthew Dillon. 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.
* 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 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.
*/
/*
* Implements bitmap resource lists.
*
* Usage:
* blist = blist_create(blocks)
* (void) blist_destroy(blist)
* blkno = blist_alloc(blist, count)
* (void) blist_free(blist, blkno, count)
* nblks = blist_fill(blist, blkno, count)
* (void) blist_resize(&blist, count, freeextra)
*
*
* Notes:
* on creation, the entire list is marked reserved. You should
* first blist_free() the sections you want to make available
* for allocation before doing general blist_alloc()/free()
* ops.
*
* BLIST_NONE is returned on failure. This module is typically
* capable of managing up to (2^31) blocks per blist, though
* the memory utilization would be insane if you actually did
* that. Managing something like 512MB worth of 4K blocks
* eats around 32 KBytes of memory.
*
* $FreeBSD: src/sys/sys/blist.h,v 1.9 2005/01/07 02:29:23 imp Exp $
*/
#ifndef _SYS_BLIST_H_
#define _SYS_BLIST_H_
/*
* for space efficiency, sizeof(blist_bitmap_t) should be
* greater than or equal to sizeof(blist_blkno_t).
*/
typedef uint32_t blist_bitmap_t;
typedef uint32_t blist_blkno_t;
/*
* note: currently use BLIST_NONE as an absolute value rather then
* a flag bit.
*/
#define BLIST_NONE ((blist_blkno_t)-1)
typedef struct blist *blist_t;
#define BLIST_BMAP_RADIX (sizeof(blist_bitmap_t)*8)
#define BLIST_MAX_ALLOC BLIST_BMAP_RADIX
extern blist_t blist_create(blist_blkno_t blocks);
extern void blist_destroy(blist_t blist);
extern blist_blkno_t blist_alloc(blist_t blist, blist_blkno_t count);
extern void blist_free(blist_t blist, blist_blkno_t blkno, blist_blkno_t count);
extern blist_blkno_t blist_fill(blist_t bl, blist_blkno_t blkno,
blist_blkno_t count);
extern void blist_print(blist_t blist);
extern void blist_resize(blist_t *pblist, blist_blkno_t count, int freenew);
#endif /* _SYS_BLIST_H_ */

310
sys/sys/buf.h Normal file
View file

@ -0,0 +1,310 @@
/* $NetBSD: buf.h,v 1.119 2012/02/17 08:45:11 yamt Exp $ */
/*-
* Copyright (c) 1999, 2000, 2007, 2008 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
* NASA Ames Research Center, and by Andrew Doran.
*
* 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.
*/
/*
* Copyright (c) 1982, 1986, 1989, 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.
* 3. 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.
*
* @(#)buf.h 8.9 (Berkeley) 3/30/95
*/
#ifndef _SYS_BUF_H_
#define _SYS_BUF_H_
#include <sys/pool.h>
#include <sys/queue.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/rbtree.h>
#if defined(_KERNEL)
#include <sys/workqueue.h>
#endif /* defined(_KERNEL) */
struct buf;
struct mount;
struct vnode;
struct kauth_cred;
#define NOLIST ((struct buf *)0x87654321)
extern kmutex_t bufcache_lock;
extern kmutex_t buffer_lock;
/*
* The buffer header describes an I/O operation in the kernel.
*
* Field markings and the corresponding locks:
*
* b thread of execution that holds BC_BUSY, does not correspond
* directly to any particular LWP
* c bufcache_lock
* o b_objlock
*
* For buffers associated with a vnode, b_objlock points to vp->v_interlock.
* If not associated with a vnode, it points to the generic buffer_lock.
*/
struct buf {
union {
TAILQ_ENTRY(buf) u_actq;
rb_node_t u_rbnode;
#if defined(_KERNEL) /* u_work is smaller than u_actq. XXX */
struct work u_work;
#endif /* defined(_KERNEL) */
} b_u; /* b: device driver queue */
#define b_actq b_u.u_actq
#define b_work b_u.u_work
void (*b_iodone)(struct buf *);/* b: call when done */
int b_error; /* b: errno value. */
int b_resid; /* b: remaining I/O. */
u_int b_flags; /* b: B_* flags */
int b_prio; /* b: priority for queue */
int b_bufsize; /* b: allocated size */
int b_bcount; /* b: valid bytes in buffer */
dev_t b_dev; /* b: associated device */
void *b_data; /* b: fs private data */
daddr_t b_blkno; /* b: physical block number
(partition relative) */
daddr_t b_rawblkno; /* b: raw physical block number
(volume relative) */
struct proc *b_proc; /* b: proc if BB_PHYS */
void *b_saveaddr; /* b: saved b_data for physio */
/*
* b: private data for owner.
* - buffer cache buffers are owned by corresponding filesystem.
* - non-buffer cache buffers are owned by subsystem which
* allocated them. (filesystem, disk driver, etc)
*/
void *b_private;
off_t b_dcookie; /* NFS: Offset cookie if dir block */
kcondvar_t b_busy; /* c: threads waiting on buf */
u_int b_refcnt; /* c: refcount for b_busy */
void *b_unused; /* : unused */
LIST_ENTRY(buf) b_hash; /* c: hash chain */
LIST_ENTRY(buf) b_vnbufs; /* c: associated vnode */
TAILQ_ENTRY(buf) b_freelist; /* c: position if not active */
LIST_ENTRY(buf) b_wapbllist; /* c: transaction buffer list */
daddr_t b_lblkno; /* c: logical block number */
int b_freelistindex;/* c: free list index (BQ_) */
u_int b_cflags; /* c: BC_* flags */
struct vnode *b_vp; /* c: file vnode */
kcondvar_t b_done; /* o: waiting on completion */
u_int b_oflags; /* o: BO_* flags */
kmutex_t *b_objlock; /* o: completion lock */
};
/*
* For portability with historic industry practice, the cylinder number has
* to be maintained in the `b_resid' field.
*/
#define b_cylinder b_resid /* Cylinder number for disksort(). */
/*
* These flags are kept in b_cflags (owned by buffer cache).
*/
#define BC_AGE 0x00000001 /* Move to age queue when I/O done. */
#define BC_BUSY 0x00000010 /* I/O in progress. */
#define BC_INVAL 0x00002000 /* Does not contain valid info. */
#define BC_NOCACHE 0x00008000 /* Do not cache block after use. */
#define BC_WANTED 0x00800000 /* Process wants this buffer. */
#define BC_VFLUSH 0x04000000 /* Buffer is being synced. */
/*
* These flags are kept in b_oflags (owned by associated object).
*/
#define BO_DELWRI 0x00000080 /* Delay I/O until buffer reused. */
#define BO_DONE 0x00000200 /* I/O completed. */
/*
* These flags are kept in b_flags (owned by buffer holder).
*/
#define B_WRITE 0x00000000 /* Write buffer (pseudo flag). */
#define B_ASYNC 0x00000004 /* Start I/O, do not wait. */
#define B_COWDONE 0x00000400 /* Copy-on-write already done. */
#define B_GATHERED 0x00001000 /* LFS: already in a segment. */
#define B_LOCKED 0x00004000 /* Locked in core (not reusable). */
#define B_PHYS 0x00040000 /* I/O to user memory. */
#define B_RAW 0x00080000 /* Set by physio for raw transfers. */
#define B_READ 0x00100000 /* Read buffer. */
#define B_DEVPRIVATE 0x02000000 /* Device driver private flag. */
#define BUF_FLAGBITS \
"\20\1AGE\3ASYNC\4BAD\5BUSY\10DELWRI" \
"\12DONE\13COWDONE\15GATHERED\16INVAL\17LOCKED\20NOCACHE" \
"\23PHYS\24RAW\25READ\32DEVPRIVATE\33VFLUSH"
/* Avoid weird code due to B_WRITE being a "pseudo flag" */
#define BUF_ISREAD(bp) (((bp)->b_flags & B_READ) == B_READ)
#define BUF_ISWRITE(bp) (((bp)->b_flags & B_READ) == B_WRITE)
/*
* This structure describes a clustered I/O. It is stored in the b_saveaddr
* field of the buffer on which I/O is done. At I/O completion, cluster
* callback uses the structure to parcel I/O's to individual buffers, and
* then free's this structure.
*/
struct cluster_save {
long bs_bcount; /* Saved b_bcount. */
long bs_bufsize; /* Saved b_bufsize. */
void *bs_saveaddr; /* Saved b_addr. */
int bs_nchildren; /* Number of associated buffers. */
struct buf *bs_children; /* List of associated buffers. */
};
/*
* Zero out the buffer's data area.
*/
#define clrbuf(bp) \
do { \
memset((bp)->b_data, 0, (u_int)(bp)->b_bcount); \
(bp)->b_resid = 0; \
} while (/* CONSTCOND */ 0)
/* Flags to low-level allocation routines. */
#define B_CLRBUF 0x01 /* Request allocated buffer be cleared. */
#define B_SYNC 0x02 /* Do all allocations synchronously. */
#define B_METAONLY 0x04 /* Return indirect block buffer. */
#define B_CONTIG 0x08 /* Allocate file contiguously. */
/* Flags to bread() and breadn(). */
#define B_MODIFY 0x01 /* Hint: caller might modify buffer */
#ifdef _KERNEL
#define BIO_GETPRIO(bp) ((bp)->b_prio)
#define BIO_SETPRIO(bp, prio) (bp)->b_prio = (prio)
#define BIO_COPYPRIO(bp1, bp2) BIO_SETPRIO(bp1, BIO_GETPRIO(bp2))
#define BPRIO_NPRIO 3
#define BPRIO_TIMECRITICAL 2
#define BPRIO_TIMELIMITED 1
#define BPRIO_TIMENONCRITICAL 0
#define BPRIO_DEFAULT BPRIO_TIMELIMITED
extern u_int nbuf; /* The number of buffer headers */
/*
* Definitions for the buffer free lists.
*/
#define BQUEUES 4 /* number of free buffer queues */
#define BQ_LOCKED 0 /* super-blocks &c */
#define BQ_LRU 1 /* lru, useful buffers */
#define BQ_AGE 2 /* rubbish */
#define BQ_EMPTY 3 /* buffer headers with no memory */
struct bqueue {
TAILQ_HEAD(, buf) bq_queue;
uint64_t bq_bytes;
buf_t *bq_marker;
};
extern struct bqueue bufqueues[BQUEUES];
__BEGIN_DECLS
int allocbuf(buf_t *, int, int);
void bawrite(buf_t *);
void bdwrite(buf_t *);
void biodone(buf_t *);
int biowait(buf_t *);
int bread(struct vnode *, daddr_t, int, struct kauth_cred *, int, buf_t **);
int breadn(struct vnode *, daddr_t, int, daddr_t *, int *, int,
struct kauth_cred *, int, buf_t **);
void brelsel(buf_t *, int);
void brelse(buf_t *, int);
void bremfree(buf_t *);
void bufinit(void);
void bufinit2(void);
int bwrite(buf_t *);
buf_t *getblk(struct vnode *, daddr_t, int, int, int);
buf_t *geteblk(int);
buf_t *incore(struct vnode *, daddr_t);
void minphys(buf_t *);
int physio(void (*)(buf_t *), buf_t *, dev_t, int,
void (*)(buf_t *), struct uio *);
void brelvp(buf_t *);
void reassignbuf(buf_t *, struct vnode *);
void bgetvp(struct vnode *, buf_t *);
int buf_syncwait(void);
u_long buf_memcalc(void);
int buf_drain(int);
int buf_setvalimit(vsize_t);
#if defined(DDB) || defined(DEBUGPRINT)
void vfs_buf_print(buf_t *, int, void (*)(const char *, ...)
__printflike(1, 2));
#endif
buf_t *getiobuf(struct vnode *, bool);
void putiobuf(buf_t *);
void buf_init(buf_t *);
void buf_destroy(buf_t *);
int bbusy(buf_t *, bool, int, kmutex_t *);
void nestiobuf_iodone(buf_t *);
void nestiobuf_setup(buf_t *, buf_t *, int, size_t);
void nestiobuf_done(buf_t *, int, int);
__END_DECLS
#endif /* _KERNEL */
#endif /* !_SYS_BUF_H_ */

105
sys/sys/bufq.h Normal file
View file

@ -0,0 +1,105 @@
/* $NetBSD: bufq.h,v 1.10 2009/01/13 13:35:54 yamt Exp $ */
/* NetBSD: buf.h,v 1.75 2004/09/18 16:40:11 yamt Exp */
/*-
* Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
* NASA Ames Research Center.
*
* 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.
*/
/*
* Copyright (c) 1982, 1986, 1989, 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.
* 3. 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.
*
* @(#)buf.h 8.9 (Berkeley) 3/30/95
*/
#if !defined(_KERNEL)
#error not supposed to be exposed to userland.
#endif
struct buf;
struct bufq_state;
/*
* Special strategies for bufq_alloc.
*/
#define BUFQ_STRAT_ANY NULL /* let bufq_alloc select one. */
#define BUFQ_DISK_DEFAULT_STRAT BUFQ_STRAT_ANY /* default for disks. */
/*
* Flags for bufq_alloc.
*/
#define BUFQ_SORT_RAWBLOCK 0x0001 /* Sort by b_rawblkno */
#define BUFQ_SORT_CYLINDER 0x0002 /* Sort by b_cylinder, b_rawblkno */
#define BUFQ_SORT_MASK 0x000f
#define BUFQ_EXACT 0x0010 /* Don't fall back to other strategy */
int bufq_alloc(struct bufq_state **, const char *, int);
void bufq_drain(struct bufq_state *);
void bufq_free(struct bufq_state *);
/* Put buffer in queue */
void bufq_put(struct bufq_state *, struct buf *);
/* Get and remove buffer from queue */
struct buf *bufq_get(struct bufq_state *);
/* Get buffer from queue */
struct buf *bufq_peek(struct bufq_state *);
/* Remove specified buffer from queue */
struct buf *bufq_cancel(struct bufq_state *, struct buf *);
const char *bufq_getstrategyname(struct bufq_state *);
void bufq_move(struct bufq_state *, struct bufq_state *);

139
sys/sys/bufq_impl.h Normal file
View file

@ -0,0 +1,139 @@
/* $NetBSD: bufq_impl.h,v 1.9 2011/11/02 13:52:34 yamt Exp $ */
/* NetBSD: bufq.h,v 1.3 2005/03/31 11:28:53 yamt Exp */
/* NetBSD: buf.h,v 1.75 2004/09/18 16:40:11 yamt Exp */
/*-
* Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
* NASA Ames Research Center.
*
* 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.
*/
/*
* Copyright (c) 1982, 1986, 1989, 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.
* 3. 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.
*
* @(#)buf.h 8.9 (Berkeley) 3/30/95
*/
#if !defined(_KERNEL)
#error not supposed to be exposed to userland.
#endif
struct bufq_strat;
/*
* Device driver buffer queue.
*/
struct bufq_state {
void (*bq_put)(struct bufq_state *, struct buf *);
struct buf *(*bq_get)(struct bufq_state *, int);
struct buf *(*bq_cancel)(struct bufq_state *, struct buf *);
void (*bq_fini)(struct bufq_state *);
void *bq_private;
int bq_flags; /* Flags from bufq_alloc() */
const struct bufq_strat *bq_strat;
};
static __inline void *bufq_private(const struct bufq_state *) __unused;
static __inline bool buf_inorder(const struct buf *, const struct buf *, int)
__unused;
#include <sys/null.h> /* for NULL */
static __inline void *
bufq_private(const struct bufq_state *bufq)
{
return bufq->bq_private;
}
/*
* Check if two buf's are in ascending order.
*
* this function consider a NULL buf is after any non-NULL buf.
*
* this function returns false if two are "same".
*/
static __inline bool
buf_inorder(const struct buf *bp, const struct buf *bq, int sortby)
{
KASSERT(bp != NULL || bq != NULL);
if (bp == NULL || bq == NULL)
return (bq == NULL);
if (sortby == BUFQ_SORT_CYLINDER) {
if (bp->b_cylinder != bq->b_cylinder)
return bp->b_cylinder < bq->b_cylinder;
else
return bp->b_rawblkno < bq->b_rawblkno;
} else
return bp->b_rawblkno < bq->b_rawblkno;
}
struct bufq_strat {
const char *bs_name;
void (*bs_initfn)(struct bufq_state *);
int bs_prio;
};
#define BUFQ_DEFINE(name, prio, initfn) \
static const struct bufq_strat bufq_strat_##name = { \
.bs_name = #name, \
.bs_prio = prio, \
.bs_initfn = initfn \
}; \
__link_set_add_rodata(bufq_strats, bufq_strat_##name)

248
sys/sys/bus.h Normal file
View file

@ -0,0 +1,248 @@
/* $NetBSD: bus.h,v 1.11 2012/05/07 18:16:38 tsutsui Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, 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.
*
* 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.
*/
#ifndef _SYS_BUS_H_
#define _SYS_BUS_H_
#include <sys/types.h>
#ifdef __HAVE_NEW_STYLE_BUS_H
#include <machine/bus_defs.h>
struct bus_space_reservation {
bus_addr_t _bsr_start;
bus_size_t _bsr_size;
};
typedef struct bus_space_reservation bus_space_reservation_t;
static inline bus_size_t
bus_space_reservation_size(bus_space_reservation_t *bsr)
{
return bsr->_bsr_size;
}
static inline bus_space_reservation_t *
bus_space_reservation_init(bus_space_reservation_t *bsr,
bus_addr_t addr, bus_size_t size)
{
bsr->_bsr_start = addr;
bsr->_bsr_size = size;
return bsr;
}
static inline bus_addr_t
bus_space_reservation_addr(bus_space_reservation_t *bsr)
{
return bsr->_bsr_start;
}
enum bus_space_override_idx {
BUS_SPACE_OVERRIDE_MAP = __BIT(0)
, BUS_SPACE_OVERRIDE_UNMAP = __BIT(1)
, BUS_SPACE_OVERRIDE_ALLOC = __BIT(2)
, BUS_SPACE_OVERRIDE_FREE = __BIT(3)
, BUS_SPACE_OVERRIDE_RESERVE = __BIT(4)
, BUS_SPACE_OVERRIDE_RELEASE = __BIT(5)
, BUS_SPACE_OVERRIDE_RESERVATION_MAP = __BIT(6)
, BUS_SPACE_OVERRIDE_RESERVATION_UNMAP = __BIT(7)
, BUS_SPACE_OVERRIDE_RESERVE_SUBREGION = __BIT(8)
#if 0
, BUS_SPACE_OVERRIDE_EXTEND = __BIT(9)
, BUS_SPACE_OVERRIDE_TRIM = __BIT(10)
#endif
};
enum bus_dma_override_idx {
BUS_DMAMAP_OVERRIDE_CREATE = __BIT(0)
, BUS_DMAMAP_OVERRIDE_DESTROY = __BIT(1)
, BUS_DMAMAP_OVERRIDE_LOAD = __BIT(2)
, BUS_DMAMAP_OVERRIDE_LOAD_MBUF = __BIT(3)
, BUS_DMAMAP_OVERRIDE_LOAD_UIO = __BIT(4)
, BUS_DMAMAP_OVERRIDE_LOAD_RAW = __BIT(5)
, BUS_DMAMAP_OVERRIDE_UNLOAD = __BIT(6)
, BUS_DMAMAP_OVERRIDE_SYNC = __BIT(7)
, BUS_DMAMEM_OVERRIDE_ALLOC = __BIT(8)
, BUS_DMAMEM_OVERRIDE_FREE = __BIT(9)
, BUS_DMAMEM_OVERRIDE_MAP = __BIT(10)
, BUS_DMAMEM_OVERRIDE_UNMAP = __BIT(11)
, BUS_DMAMEM_OVERRIDE_MMAP = __BIT(12)
, BUS_DMATAG_OVERRIDE_SUBREGION = __BIT(13)
, BUS_DMATAG_OVERRIDE_DESTROY = __BIT(14)
};
/* Only add new members at the end of this struct! */
struct bus_space_overrides {
int (*ov_space_map)(void *, bus_space_tag_t, bus_addr_t, bus_size_t,
int, bus_space_handle_t *);
void (*ov_space_unmap)(void *, bus_space_tag_t, bus_space_handle_t,
bus_size_t);
int (*ov_space_alloc)(void *, bus_space_tag_t, bus_addr_t, bus_addr_t,
bus_size_t, bus_size_t, bus_size_t, int, bus_addr_t *,
bus_space_handle_t *);
void (*ov_space_free)(void *, bus_space_tag_t, bus_space_handle_t,
bus_size_t);
int (*ov_space_reserve)(void *, bus_space_tag_t, bus_addr_t, bus_size_t,
int, bus_space_reservation_t *);
void (*ov_space_release)(void *, bus_space_tag_t,
bus_space_reservation_t *);
int (*ov_space_reservation_map)(void *, bus_space_tag_t,
bus_space_reservation_t *, int, bus_space_handle_t *);
void (*ov_space_reservation_unmap)(void *, bus_space_tag_t,
bus_space_handle_t, bus_size_t);
int (*ov_space_reserve_subregion)(void *, bus_space_tag_t,
bus_addr_t, bus_addr_t, bus_size_t, bus_size_t, bus_size_t,
int, bus_space_reservation_t *);
#if 0
int (*ov_space_extend)(void *, bus_space_tag_t,
bus_space_reservation_t *, bus_size_t, bus_size_t);
void (*ov_space_trim)(void *, bus_space_tag_t,
bus_space_reservation_t *, bus_size_t, bus_size_t);
#endif
};
struct mbuf;
struct uio;
/* Only add new members at the end of this struct! */
struct bus_dma_overrides {
int (*ov_dmamap_create)(void *, bus_dma_tag_t, bus_size_t, int,
bus_size_t, bus_size_t, int, bus_dmamap_t *);
void (*ov_dmamap_destroy)(void *, bus_dma_tag_t, bus_dmamap_t);
int (*ov_dmamap_load)(void *, bus_dma_tag_t, bus_dmamap_t, void *,
bus_size_t, struct proc *, int);
int (*ov_dmamap_load_mbuf)(void *, bus_dma_tag_t, bus_dmamap_t,
struct mbuf *, int);
int (*ov_dmamap_load_uio)(void *, bus_dma_tag_t, bus_dmamap_t,
struct uio *, int);
int (*ov_dmamap_load_raw)(void *, bus_dma_tag_t, bus_dmamap_t,
bus_dma_segment_t *, int, bus_size_t, int);
void (*ov_dmamap_unload)(void *, bus_dma_tag_t, bus_dmamap_t);
void (*ov_dmamap_sync)(void *, bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
bus_size_t, int);
int (*ov_dmamem_alloc)(void *, bus_dma_tag_t, bus_size_t, bus_size_t,
bus_size_t, bus_dma_segment_t *, int, int *, int);
void (*ov_dmamem_free)(void *, bus_dma_tag_t, bus_dma_segment_t *, int);
int (*ov_dmamem_map)(void *, bus_dma_tag_t, bus_dma_segment_t *, int,
size_t, void **, int);
void (*ov_dmamem_unmap)(void *, bus_dma_tag_t, void *, size_t);
paddr_t (*ov_dmamem_mmap)(void *, bus_dma_tag_t, bus_dma_segment_t *,
int, off_t, int, int);
int (*ov_dmatag_subregion)(void *, bus_dma_tag_t, bus_addr_t,
bus_addr_t, bus_dma_tag_t *, int);
void (*ov_dmatag_destroy)(void *, bus_dma_tag_t);
};
int bus_space_tag_create(bus_space_tag_t, uint64_t, uint64_t,
const struct bus_space_overrides *, void *,
bus_space_tag_t *);
void bus_space_tag_destroy(bus_space_tag_t);
int bus_dma_tag_create(bus_dma_tag_t, uint64_t,
const struct bus_dma_overrides *, void *, bus_dma_tag_t *);
void bus_dma_tag_destroy(bus_dma_tag_t);
/* Reserve a region of bus space. Reserved bus space cannot be allocated
* with bus_space_alloc(). Reserved space has not been bus_space_map()'d.
*/
int bus_space_reserve(bus_space_tag_t, bus_addr_t, bus_size_t, int,
bus_space_reservation_t *);
int
bus_space_reserve_subregion(bus_space_tag_t,
bus_addr_t, bus_addr_t, bus_size_t, bus_size_t, bus_size_t,
int, bus_space_reservation_t *);
/* Cancel a reservation. */
void bus_space_release(bus_space_tag_t, bus_space_reservation_t *);
int bus_space_reservation_map(bus_space_tag_t, bus_space_reservation_t *,
int, bus_space_handle_t *);
void bus_space_reservation_unmap(bus_space_tag_t, bus_space_handle_t,
bus_size_t);
#if 0
/* Extend a reservation to the left and/or to the right. The extension
* has not been bus_space_map()'d.
*/
int bus_space_extend(bus_space_tag_t, bus_space_reservation_t *, bus_size_t,
bus_size_t);
/* Trim bus space from a reservation on the left and/or on the right. */
void bus_space_trim(bus_space_tag_t, bus_space_reservation_t *, bus_size_t,
bus_size_t);
#endif
#include <sys/bus_proto.h>
#include <machine/bus_funcs.h>
#else /* !__HAVE_NEW_STYLE_BUS_H */
#include <machine/bus.h>
bool bus_space_is_equal(bus_space_tag_t, bus_space_tag_t);
bool bus_space_handle_is_equal(bus_space_tag_t, bus_space_handle_t,
bus_space_handle_t);
#endif /* __HAVE_NEW_STYLE_BUS_H */
#ifdef __HAVE_NO_BUS_DMA
/*
* XXX
* Dummy bus_dma(9) stuff for ports which don't bother to have
* unnecessary bus_dma(9) implementation to appease MI driver modules etc.
*/
typedef void *bus_dma_tag_t;
typedef struct bus_dma_segment {
bus_addr_t ds_addr;
bus_size_t ds_len;
} bus_dma_segment_t;
typedef struct bus_dmamap {
bus_size_t dm_maxsegsz;
bus_size_t dm_mapsize;
int dm_nsegs;
bus_dma_segment_t *dm_segs;
} *bus_dmamap_t;
#endif /* __HAVE_NO_BUS_DMA */
#endif /* _SYS_BUS_H_ */

358
sys/sys/bus_proto.h Normal file
View file

@ -0,0 +1,358 @@
/* $NetBSD: bus_proto.h,v 1.6 2011/08/17 10:46:38 martin Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998, 2001, 2007 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
* NASA Ames Research Center, and by Andrew Doran.
*
* 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.
*/
/*
* Copyright (c) 1996 Charles M. Hannum. All rights reserved.
* Copyright (c) 1996 Christopher G. Demetriou. 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 acknowledgement:
* This product includes software developed by Christopher G. Demetriou
* for the NetBSD Project.
* 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.
*/
#ifndef _SYS_BUS_PROTO_H_
#define _SYS_BUS_PROTO_H_
/*
* Forwards needed by prototypes below.
*/
struct mbuf;
struct uio;
/*
* bus_space(9)
*/
/* Map types. */
#define BUS_SPACE_MAP_CACHEABLE 0x01
#define BUS_SPACE_MAP_LINEAR 0x02
#define BUS_SPACE_MAP_PREFETCHABLE 0x04
/* Bus read/write barrier methods. */
#define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */
#define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */
int bus_space_map(bus_space_tag_t, bus_addr_t, bus_size_t, int,
bus_space_handle_t *);
void bus_space_unmap(bus_space_tag_t, bus_space_handle_t, bus_size_t);
int bus_space_subregion(bus_space_tag_t, bus_space_handle_t,
bus_size_t, bus_size_t, bus_space_handle_t *);
int bus_space_alloc(bus_space_tag_t, bus_addr_t, bus_addr_t,
bus_size_t, bus_size_t, bus_size_t,
int, bus_addr_t *, bus_space_handle_t *);
void bus_space_free(bus_space_tag_t, bus_space_handle_t, bus_size_t);
paddr_t bus_space_mmap(bus_space_tag_t, bus_addr_t, off_t, int, int);
void *bus_space_vaddr(bus_space_tag_t, bus_space_handle_t);
void bus_space_barrier(bus_space_tag_t tag, bus_space_handle_t bsh,
bus_size_t offset, bus_size_t len, int flags);
/*
* bus_space(9) accessors
*/
uint8_t bus_space_read_1(bus_space_tag_t, bus_space_handle_t,
bus_size_t);
uint8_t bus_space_read_stream_1(bus_space_tag_t, bus_space_handle_t,
bus_size_t);
uint16_t bus_space_read_2(bus_space_tag_t, bus_space_handle_t,
bus_size_t);
uint16_t bus_space_read_stream_2(bus_space_tag_t, bus_space_handle_t,
bus_size_t);
uint32_t bus_space_read_4(bus_space_tag_t, bus_space_handle_t,
bus_size_t);
uint32_t bus_space_read_stream_4(bus_space_tag_t, bus_space_handle_t,
bus_size_t);
uint64_t bus_space_read_8(bus_space_tag_t, bus_space_handle_t,
bus_size_t);
uint64_t bus_space_read_stream_8(bus_space_tag_t, bus_space_handle_t,
bus_size_t);
void bus_space_read_multi_1(bus_space_tag_t, bus_space_handle_t,
bus_size_t, uint8_t *, bus_size_t);
void bus_space_read_multi_stream_1(bus_space_tag_t, bus_space_handle_t,
bus_size_t, uint8_t *, bus_size_t);
void bus_space_read_region_1(bus_space_tag_t, bus_space_handle_t,
bus_size_t, uint8_t *, bus_size_t);
void bus_space_read_region_stream_1(bus_space_tag_t, bus_space_handle_t,
bus_size_t, uint8_t *, bus_size_t);
void bus_space_read_multi_2(bus_space_tag_t, bus_space_handle_t,
bus_size_t, uint16_t *, bus_size_t);
void bus_space_read_multi_stream_2(bus_space_tag_t, bus_space_handle_t,
bus_size_t, uint16_t *, bus_size_t);
void bus_space_read_region_2(bus_space_tag_t, bus_space_handle_t,
bus_size_t, uint16_t *, bus_size_t);
void bus_space_read_region_stream_2(bus_space_tag_t, bus_space_handle_t,
bus_size_t, uint16_t *, bus_size_t);
void bus_space_read_multi_4(bus_space_tag_t, bus_space_handle_t,
bus_size_t, uint32_t *, bus_size_t);
void bus_space_read_multi_stream_4(bus_space_tag_t, bus_space_handle_t,
bus_size_t, uint32_t *, bus_size_t);
void bus_space_read_region_4(bus_space_tag_t, bus_space_handle_t,
bus_size_t, uint32_t *, bus_size_t);
void bus_space_read_region_stream_4(bus_space_tag_t, bus_space_handle_t,
bus_size_t, uint32_t *, bus_size_t);
void bus_space_read_multi_8(bus_space_tag_t, bus_space_handle_t,
bus_size_t, uint64_t *, bus_size_t);
void bus_space_read_multi_stream_8(bus_space_tag_t, bus_space_handle_t,
bus_size_t, uint64_t *, bus_size_t);
void bus_space_read_region_8(bus_space_tag_t, bus_space_handle_t,
bus_size_t, uint64_t *, bus_size_t);
void bus_space_read_region_stream_8(bus_space_tag_t, bus_space_handle_t,
bus_size_t, uint64_t *, bus_size_t);
void bus_space_write_1(bus_space_tag_t, bus_space_handle_t,
bus_size_t, uint8_t);
void bus_space_write_stream_1(bus_space_tag_t, bus_space_handle_t,
bus_size_t, uint8_t);
void bus_space_write_2(bus_space_tag_t, bus_space_handle_t,
bus_size_t, uint16_t);
void bus_space_write_stream_2(bus_space_tag_t, bus_space_handle_t,
bus_size_t, uint16_t);
void bus_space_write_4(bus_space_tag_t, bus_space_handle_t,
bus_size_t, uint32_t);
void bus_space_write_stream_4(bus_space_tag_t, bus_space_handle_t,
bus_size_t, uint32_t);
void bus_space_write_8(bus_space_tag_t, bus_space_handle_t,
bus_size_t, uint64_t);
void bus_space_write_stream_8(bus_space_tag_t, bus_space_handle_t,
bus_size_t, uint64_t);
void bus_space_write_multi_1(bus_space_tag_t, bus_space_handle_t,
bus_size_t, const uint8_t *,
bus_size_t);
void bus_space_write_multi_stream_1(bus_space_tag_t, bus_space_handle_t,
bus_size_t, const uint8_t *,
bus_size_t);
void bus_space_write_region_1(bus_space_tag_t, bus_space_handle_t,
bus_size_t, const uint8_t *,
bus_size_t);
void bus_space_write_region_stream_1(bus_space_tag_t, bus_space_handle_t,
bus_size_t, const uint8_t *,
bus_size_t);
void bus_space_write_multi_2(bus_space_tag_t, bus_space_handle_t,
bus_size_t, const uint16_t *,
bus_size_t);
void bus_space_write_multi_stream_2(bus_space_tag_t, bus_space_handle_t,
bus_size_t, const uint16_t *,
bus_size_t);
void bus_space_write_region_2(bus_space_tag_t, bus_space_handle_t,
bus_size_t, const uint16_t *,
bus_size_t);
void bus_space_write_region_stream_2(bus_space_tag_t, bus_space_handle_t,
bus_size_t, const uint16_t *,
bus_size_t);
void bus_space_write_multi_4(bus_space_tag_t, bus_space_handle_t,
bus_size_t, const uint32_t *,
bus_size_t);
void bus_space_write_multi_stream_4(bus_space_tag_t, bus_space_handle_t,
bus_size_t, const uint32_t *,
bus_size_t);
void bus_space_write_region_4(bus_space_tag_t, bus_space_handle_t,
bus_size_t, const uint32_t *,
bus_size_t);
void bus_space_write_region_stream_4(bus_space_tag_t, bus_space_handle_t,
bus_size_t, const uint32_t *,
bus_size_t);
void bus_space_write_multi_8(bus_space_tag_t, bus_space_handle_t,
bus_size_t, const uint64_t *,
bus_size_t);
void bus_space_write_multi_stream_8(bus_space_tag_t, bus_space_handle_t,
bus_size_t, const uint64_t *,
bus_size_t);
void bus_space_write_region_8(bus_space_tag_t, bus_space_handle_t,
bus_size_t, const uint64_t *,
bus_size_t);
void bus_space_write_region_stream_8(bus_space_tag_t, bus_space_handle_t,
bus_size_t, const uint64_t *,
bus_size_t);
void bus_space_set_multi_1(bus_space_tag_t, bus_space_handle_t,
bus_size_t, u_int8_t, bus_size_t);
void bus_space_set_multi_2(bus_space_tag_t, bus_space_handle_t,
bus_size_t, u_int16_t, bus_size_t);
void bus_space_set_multi_4(bus_space_tag_t, bus_space_handle_t,
bus_size_t, u_int32_t, bus_size_t);
void bus_space_set_multi_8(bus_space_tag_t, bus_space_handle_t,
bus_size_t, u_int64_t, bus_size_t);
void bus_space_set_multi_stream_1(bus_space_tag_t, bus_space_handle_t,
bus_size_t, u_int8_t, bus_size_t);
void bus_space_set_multi_stream_2(bus_space_tag_t, bus_space_handle_t,
bus_size_t, u_int16_t, bus_size_t);
void bus_space_set_multi_stream_4(bus_space_tag_t, bus_space_handle_t,
bus_size_t, u_int32_t, bus_size_t);
void bus_space_set_multi_stream_8(bus_space_tag_t, bus_space_handle_t,
bus_size_t, u_int64_t, bus_size_t);
void bus_space_set_region_1(bus_space_tag_t, bus_space_handle_t,
bus_size_t, u_int8_t, bus_size_t);
void bus_space_set_region_2(bus_space_tag_t, bus_space_handle_t,
bus_size_t, u_int16_t, bus_size_t);
void bus_space_set_region_4(bus_space_tag_t, bus_space_handle_t,
bus_size_t, u_int32_t, bus_size_t);
void bus_space_set_region_8(bus_space_tag_t, bus_space_handle_t,
bus_size_t, u_int64_t, bus_size_t);
void bus_space_set_region_stream_1(bus_space_tag_t, bus_space_handle_t,
bus_size_t, u_int8_t, bus_size_t);
void bus_space_set_region_stream_2(bus_space_tag_t, bus_space_handle_t,
bus_size_t, u_int16_t, bus_size_t);
void bus_space_set_region_stream_4(bus_space_tag_t, bus_space_handle_t,
bus_size_t, u_int32_t, bus_size_t);
void bus_space_set_region_stream_8(bus_space_tag_t, bus_space_handle_t,
bus_size_t, u_int64_t, bus_size_t);
void bus_space_copy_region_1(bus_space_tag_t, bus_space_handle_t,
bus_size_t, bus_space_handle_t,
bus_size_t, bus_size_t);
void bus_space_copy_region_2(bus_space_tag_t, bus_space_handle_t,
bus_size_t, bus_space_handle_t,
bus_size_t, bus_size_t);
void bus_space_copy_region_4(bus_space_tag_t, bus_space_handle_t,
bus_size_t, bus_space_handle_t,
bus_size_t, bus_size_t);
void bus_space_copy_region_8(bus_space_tag_t, bus_space_handle_t,
bus_size_t, bus_space_handle_t,
bus_size_t, bus_size_t);
void bus_space_copy_region_stream_1(bus_space_tag_t, bus_space_handle_t,
bus_size_t, bus_space_handle_t,
bus_size_t, bus_size_t);
void bus_space_copy_region_stream_2(bus_space_tag_t, bus_space_handle_t,
bus_size_t, bus_space_handle_t,
bus_size_t, bus_size_t);
void bus_space_copy_region_stream_4(bus_space_tag_t, bus_space_handle_t,
bus_size_t, bus_space_handle_t,
bus_size_t, bus_size_t);
void bus_space_copy_region_stream_8(bus_space_tag_t, bus_space_handle_t,
bus_size_t, bus_space_handle_t,
bus_size_t, bus_size_t);
bool bus_space_is_equal(bus_space_tag_t, bus_space_tag_t);
bool bus_space_handle_is_equal(bus_space_tag_t, bus_space_handle_t,
bus_space_handle_t);
/*
* bus_dma(9)
*/
/* Flags used in various bus DMA methods. */
#define BUS_DMA_WAITOK 0x000 /* safe to sleep (pseudo-flag) */
#define BUS_DMA_NOWAIT 0x001 /* not safe to sleep */
#define BUS_DMA_ALLOCNOW 0x002 /* perform resource allocation now */
#define BUS_DMA_COHERENT 0x004 /* hint: map memory DMA coherent */
#define BUS_DMA_STREAMING 0x008 /* hint: sequential, unidirectional */
#define BUS_DMA_BUS1 0x010 /* placeholders for bus functions... */
#define BUS_DMA_BUS2 0x020
#define BUS_DMA_BUS3 0x040
#define BUS_DMA_BUS4 0x080
#define BUS_DMA_READ 0x100 /* mapping is device -> memory only */
#define BUS_DMA_WRITE 0x200 /* mapping is memory -> device only */
#define BUS_DMA_NOCACHE 0x400 /* hint: map non-cached memory */
/* Operations performed by bus_dmamap_sync(). */
#define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */
#define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */
#define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */
#define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */
int bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t,
bus_size_t, int, bus_dmamap_t *);
void bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t);
int bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, bus_size_t,
struct proc *, int);
int bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t,
struct mbuf *, int);
int bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t,
struct uio *, int);
int bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t,
bus_dma_segment_t *, int, bus_size_t, int);
void bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t);
void bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
bus_size_t, int);
int bus_dmamem_alloc(bus_dma_tag_t, bus_size_t, bus_size_t,
bus_size_t, bus_dma_segment_t *,
int, int *, int);
void bus_dmamem_free(bus_dma_tag_t, bus_dma_segment_t *, int);
int bus_dmamem_map(bus_dma_tag_t, bus_dma_segment_t *, int,
size_t, void **, int);
void bus_dmamem_unmap(bus_dma_tag_t, void *, size_t);
paddr_t bus_dmamem_mmap(bus_dma_tag_t, bus_dma_segment_t *, int,
off_t, int, int);
int bus_dmatag_subregion(bus_dma_tag_t, bus_addr_t, bus_addr_t,
bus_dma_tag_t *, int);
void bus_dmatag_destroy(bus_dma_tag_t);
#endif /* _SYS_BUS_PROTO_H_ */

63
sys/sys/callback.h Normal file
View file

@ -0,0 +1,63 @@
/* $NetBSD: callback.h,v 1.3 2007/07/09 21:11:32 ad Exp $ */
/*-
* Copyright (c)2006 YAMAMOTO Takashi,
* 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.
*/
#ifndef _SYS_CALLBACK_H_
#define _SYS_CALLBACK_H_
#include <sys/queue.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
struct callback_entry {
TAILQ_ENTRY(callback_entry) ce_q;
int (*ce_func)(struct callback_entry *, void *, void *);
void *ce_obj;
};
struct callback_head {
kmutex_t ch_lock;
kcondvar_t ch_cv;
TAILQ_HEAD(, callback_entry) ch_q;
struct callback_entry *ch_next;
int ch_nentries;
int ch_running;
int ch_flags;
};
/* return values of ce_func */
#define CALLBACK_CHAIN_CONTINUE 0
#define CALLBACK_CHAIN_ABORT 1
int callback_run_roundrobin(struct callback_head *, void *);
void callback_register(struct callback_head *, struct callback_entry *,
void *, int (*)(struct callback_entry *, void *, void *));
void callback_unregister(struct callback_head *, struct callback_entry *);
void callback_head_init(struct callback_head *, int);
void callback_head_destroy(struct callback_head *);
#endif /* !_SYS_CALLBACK_H_ */

119
sys/sys/callout.h Normal file
View file

@ -0,0 +1,119 @@
/* $NetBSD: callout.h,v 1.31 2008/04/28 20:24:10 martin Exp $ */
/*-
* Copyright (c) 2000, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
* NASA Ames Research Center, and by Andrew Doran.
*
* 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.
*/
#ifndef _SYS_CALLOUT_H_
#define _SYS_CALLOUT_H_
#include <sys/types.h>
/*
* The callout implementation is private to kern_timeout.c yet uses
* caller-supplied storage, as lightweight callout operations are
* critical to system performance.
*
* The size of callout_t must remain constant in order to ensure ABI
* compatibility for kernel modules: it may become smaller, but must
* not grow. If more space is required, rearrange the members of
* callout_impl_t.
*/
typedef struct callout {
void *_c_store[10];
} callout_t;
/* Internal flags. */
#define CALLOUT_BOUND 0x0001 /* bound to a specific CPU */
#define CALLOUT_PENDING 0x0002 /* callout is on the queue */
#define CALLOUT_FIRED 0x0004 /* callout has fired */
#define CALLOUT_INVOKING 0x0008 /* callout function is being invoked */
/* End-user flags. */
#define CALLOUT_MPSAFE 0x0100 /* does not need kernel_lock */
#define CALLOUT_FLAGMASK 0xff00
#ifdef _CALLOUT_PRIVATE
/* The following funkyness is to appease gcc3's strict aliasing. */
struct callout_circq {
/* next element */
union {
struct callout_impl *elem;
struct callout_circq *list;
} cq_next;
/* previous element */
union {
struct callout_impl *elem;
struct callout_circq *list;
} cq_prev;
};
#define cq_next_e cq_next.elem
#define cq_prev_e cq_prev.elem
#define cq_next_l cq_next.list
#define cq_prev_l cq_prev.list
struct callout_cpu;
typedef struct callout_impl {
struct callout_circq c_list; /* linkage on queue */
void (*c_func)(void *); /* function to call */
void *c_arg; /* function argument */
struct callout_cpu * volatile c_cpu; /* associated CPU */
int c_time; /* when callout fires */
u_int c_flags; /* state of this entry */
u_int c_magic; /* magic number */
} callout_impl_t;
#define CALLOUT_MAGIC 0x11deeba1
#endif /* _CALLOUT_PRIVATE */
#ifdef _KERNEL
struct cpu_info;
void callout_startup(void);
void callout_init_cpu(struct cpu_info *);
void callout_hardclock(void);
void callout_init(callout_t *, u_int);
void callout_destroy(callout_t *);
void callout_setfunc(callout_t *, void (*)(void *), void *);
void callout_reset(callout_t *, int, void (*)(void *), void *);
void callout_schedule(callout_t *, int);
bool callout_stop(callout_t *);
bool callout_halt(callout_t *, void *);
bool callout_pending(callout_t *);
bool callout_expired(callout_t *);
bool callout_active(callout_t *);
bool callout_invoking(callout_t *);
void callout_ack(callout_t *);
void callout_bind(callout_t *, struct cpu_info *);
#endif /* _KERNEL */
#endif /* !_SYS_CALLOUT_H_ */

53
sys/sys/cctr.h Normal file
View file

@ -0,0 +1,53 @@
/* $NetBSD: cctr.h,v 1.3 2008/04/28 20:24:10 martin Exp $ */
/*-
* Copyright (c) 2004 The NetBSD Foundation, 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.
*
* 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.
*/
#ifndef _SYS_CCTR_H_
#define _SYS_CCTR_H_
#include <sys/timetc.h>
/*
* Variables used by cycle counter in kern_cctr.c.
*/
struct cctr_state {
volatile u_int cc_gen; /* generation number for this data set */
volatile int64_t cc_val; /* reference CC value at calibration time */
volatile int64_t cc_cc; /* local CC value at calibration time */
volatile int64_t cc_delta; /* reference CC difference for
last calibration period */
volatile int64_t cc_denom; /* local CC difference for
last calibration period */
};
struct cpu_info;
void cc_calibrate_cpu(struct cpu_info *);
struct timecounter *cc_init(timecounter_get_t, uint64_t, const char *, int);
u_int cc_get_timecount(struct timecounter *);
#endif /* _SYS_CCTR_H_ */

425
sys/sys/cdio.h Normal file
View file

@ -0,0 +1,425 @@
/* $NetBSD: cdio.h,v 1.33 2009/01/29 19:36:28 reinoud Exp $ */
#ifndef _SYS_CDIO_H_
#define _SYS_CDIO_H_
/* Shared between kernel & process */
union msf_lba {
struct {
u_char unused;
u_char minute;
u_char second;
u_char frame;
} msf;
uint32_t lba;
u_char addr[4];
};
struct cd_toc_entry {
u_char nothing1;
#if BYTE_ORDER == LITTLE_ENDIAN
uint32_t control:4;
uint32_t addr_type:4;
#endif
#if BYTE_ORDER == BIG_ENDIAN
uint32_t addr_type:4;
uint32_t control:4;
#endif
u_char track;
u_char nothing2;
union msf_lba addr;
};
struct cd_sub_channel_header {
u_char nothing1;
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_q_data {
u_char data_format;
#if BYTE_ORDER == LITTLE_ENDIAN
uint32_t control:4;
uint32_t addr_type:4;
#endif
#if BYTE_ORDER == BIG_ENDIAN
uint32_t addr_type:4;
uint32_t control:4;
#endif
u_char track_number;
u_char index_number;
u_char absaddr[4];
u_char reladdr[4];
#if BYTE_ORDER == LITTLE_ENDIAN
uint32_t :7;
uint32_t mc_valid:1;
#endif
#if BYTE_ORDER == BIG_ENDIAN
uint32_t mc_valid:1;
uint32_t :7;
#endif
u_char mc_number[15];
#if BYTE_ORDER == LITTLE_ENDIAN
uint32_t :7;
uint32_t ti_valid:1;
#endif
#if BYTE_ORDER == BIG_ENDIAN
uint32_t ti_valid:1;
uint32_t :7;
#endif
u_char ti_number[15];
};
struct cd_sub_channel_position_data {
u_char data_format;
#if BYTE_ORDER == LITTLE_ENDIAN
uint32_t control:4;
uint32_t addr_type:4;
#endif
#if BYTE_ORDER == BIG_ENDIAN
uint32_t addr_type:4;
uint32_t control:4;
#endif
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_char nothing1;
u_char nothing2;
u_char nothing3;
#if BYTE_ORDER == LITTLE_ENDIAN
uint32_t :7;
uint32_t mc_valid:1;
#endif
#if BYTE_ORDER == BIG_ENDIAN
uint32_t mc_valid:1;
uint32_t :7;
#endif
u_char mc_number[15];
};
struct cd_sub_channel_track_info {
u_char data_format;
u_char nothing1;
u_char track_number;
u_char nothing2;
#if BYTE_ORDER == LITTLE_ENDIAN
uint32_t :7;
uint32_t ti_valid:1;
#endif
#if BYTE_ORDER == BIG_ENDIAN
uint32_t ti_valid:1;
uint32_t :7;
#endif
u_char ti_number[15];
};
struct cd_sub_channel_info {
struct cd_sub_channel_header header;
union {
struct cd_sub_channel_q_data q_data;
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 )
#ifdef _KERNEL
/* As above, but with the buffer following the request for in-kernel users. */
struct ioc_read_subchannel_buf {
struct ioc_read_subchannel req;
struct cd_sub_channel_info info;
};
#define CDIOCREADSUBCHANNEL_BUF _IOWR('c', 3, struct ioc_read_subchannel_buf)
#endif
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 CDIOREADTOCENTRIES _IOWR('c', 5, struct ioc_read_toc_entry)
#define CDIOREADTOCENTRYS CDIOREADTOCENTRIES
#ifdef _KERNEL
/* As above, but with the buffer following the request for in-kernel users. */
struct ioc_read_toc_entry_buf {
struct ioc_read_toc_entry req;
struct cd_toc_entry entry[100]; /* NB: 8 bytes each */
};
#define CDIOREADTOCENTRIES_BUF _IOWR('c', 5, struct ioc_read_toc_entry_buf)
#endif
/* read LBA start of a given session; 0=last, others not yet supported */
#define CDIOREADMSADDR _IOWR('c', 6, int)
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 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)
#define CDIOCALLOW _IO('c', 25)
#define CDIOCPREVENT _IO('c', 26)
#define CDIOCCLOSE _IO('c', 27)
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)
struct ioc_load_unload {
u_char options;
#define CD_LU_ABORT 0x1 /* NOTE: These are the same as the ATAPI */
#define CD_LU_UNLOAD 0x2 /* op values for the LOAD_UNLOAD command */
#define CD_LU_LOAD 0x3
u_char slot;
};
#define CDIOCLOADUNLOAD _IOW('c', 26, struct ioc_load_unload)
#if defined(_KERNEL) || defined(_EXPOSE_MMC)
/* not exposed to userland yet until its completely mature */
/*
* MMC device abstraction interface.
*
* It gathers information from GET_CONFIGURATION, READ_DISCINFO,
* READ_TRACKINFO, READ_TOC2, READ_CD_CAPACITY and GET_CONFIGURATION
* SCSI/ATAPI calls regardless if its a legacy CD-ROM/DVD-ROM device or a MMC
* standard recordable device.
*/
struct mmc_discinfo {
uint16_t mmc_profile;
uint16_t mmc_class;
uint8_t disc_state;
uint8_t last_session_state;
uint8_t bg_format_state;
uint8_t link_block_penalty; /* in sectors */
uint64_t mmc_cur; /* current MMC_CAPs */
uint64_t mmc_cap; /* possible MMC_CAPs */
uint32_t disc_flags; /* misc flags */
uint32_t disc_id;
uint64_t disc_barcode;
uint8_t application_code; /* 8 bit really */
uint8_t unused1[3]; /* padding */
uint32_t last_possible_lba; /* last leadout start adr. */
uint32_t sector_size;
uint16_t num_sessions;
uint16_t num_tracks; /* derived */
uint16_t first_track;
uint16_t first_track_last_session;
uint16_t last_track_last_session;
uint16_t unused2; /* padding/misc info resv. */
uint16_t reserved1[4]; /* MMC-5 track resources */
uint32_t reserved2[3]; /* MMC-5 POW resources */
uint32_t reserved3[8]; /* MMC-5+ */
};
#define MMCGETDISCINFO _IOR('c', 28, struct mmc_discinfo)
#define MMC_CLASS_UNKN 0
#define MMC_CLASS_DISC 1
#define MMC_CLASS_CD 2
#define MMC_CLASS_DVD 3
#define MMC_CLASS_MO 4
#define MMC_CLASS_BD 5
#define MMC_CLASS_FILE 0xffff /* emulation mode */
#define MMC_DFLAGS_BARCODEVALID (1 << 0) /* barcode is present and valid */
#define MMC_DFLAGS_DISCIDVALID (1 << 1) /* discid is present and valid */
#define MMC_DFLAGS_APPCODEVALID (1 << 2) /* application code valid */
#define MMC_DFLAGS_UNRESTRICTED (1 << 3) /* restricted, then set app. code */
#define MMC_DFLAGS_FLAGBITS \
"\10\1BARCODEVALID\2DISCIDVALID\3APPCODEVALID\4UNRESTRICTED"
#define MMC_CAP_SEQUENTIAL (1 << 0) /* sequential writable only */
#define MMC_CAP_RECORDABLE (1 << 1) /* record-able; i.e. not static */
#define MMC_CAP_ERASABLE (1 << 2) /* drive can erase sectors */
#define MMC_CAP_BLANKABLE (1 << 3) /* media can be blanked */
#define MMC_CAP_FORMATTABLE (1 << 4) /* media can be formatted */
#define MMC_CAP_REWRITABLE (1 << 5) /* media can be rewritten */
#define MMC_CAP_MRW (1 << 6) /* Mount Rainier formatted */
#define MMC_CAP_PACKET (1 << 7) /* using packet recording */
#define MMC_CAP_STRICTOVERWRITE (1 << 8) /* only writes a packet at a time */
#define MMC_CAP_PSEUDOOVERWRITE (1 << 9) /* overwrite through replacement */
#define MMC_CAP_ZEROLINKBLK (1 << 10) /* zero link block length capable */
#define MMC_CAP_HW_DEFECTFREE (1 << 11) /* hardware defect management */
#define MMC_CAP_FLAGBITS \
"\10\1SEQUENTIAL\2RECORDABLE\3ERASABLE\4BLANKABLE\5FORMATTABLE" \
"\6REWRITABLE\7MRW\10PACKET\11STRICTOVERWRITE\12PSEUDOOVERWRITE" \
"\13ZEROLINKBLK\14HW_DEFECTFREE"
#define MMC_STATE_EMPTY 0
#define MMC_STATE_INCOMPLETE 1
#define MMC_STATE_FULL 2
#define MMC_STATE_CLOSED 3
#define MMC_BGFSTATE_UNFORM 0
#define MMC_BGFSTATE_STOPPED 1
#define MMC_BGFSTATE_RUNNING 2
#define MMC_BGFSTATE_COMPLETED 3
struct mmc_trackinfo {
uint16_t tracknr; /* IN/OUT */
uint16_t sessionnr;
uint8_t track_mode;
uint8_t data_mode;
uint16_t flags;
uint32_t track_start;
uint32_t next_writable;
uint32_t free_blocks;
uint32_t packet_size;
uint32_t track_size;
uint32_t last_recorded;
};
#define MMCGETTRACKINFO _IOWR('c', 29, struct mmc_trackinfo)
#define MMC_TRACKINFO_COPY (1 << 0)
#define MMC_TRACKINFO_DAMAGED (1 << 1)
#define MMC_TRACKINFO_FIXED_PACKET (1 << 2)
#define MMC_TRACKINFO_INCREMENTAL (1 << 3)
#define MMC_TRACKINFO_BLANK (1 << 4)
#define MMC_TRACKINFO_RESERVED (1 << 5)
#define MMC_TRACKINFO_NWA_VALID (1 << 6)
#define MMC_TRACKINFO_LRA_VALID (1 << 7)
#define MMC_TRACKINFO_DATA (1 << 8)
#define MMC_TRACKINFO_AUDIO (1 << 9)
#define MMC_TRACKINFO_AUDIO_4CHAN (1 << 10)
#define MMC_TRACKINFO_PRE_EMPH (1 << 11)
#define MMC_TRACKINFO_FLAGBITS \
"\10\1COPY\2DAMAGED\3FIXEDPACKET\4INCREMENTAL\5BLANK" \
"\6RESERVED\7NWA_VALID\10LRA_VALID\11DATA\12AUDIO" \
"\13AUDIO_4CHAN\14PRE_EMPH"
struct mmc_op {
uint16_t operation; /* IN */
uint16_t mmc_profile; /* IN */
/* parameters to operation */
uint16_t tracknr; /* IN */
uint16_t sessionnr; /* IN */
uint32_t extent; /* IN */
uint32_t reserved[4];
};
#define MMCOP _IOWR('c', 30, struct mmc_op)
#define MMC_OP_SYNCHRONISECACHE 1
#define MMC_OP_CLOSETRACK 2
#define MMC_OP_CLOSESESSION 3
#define MMC_OP_FINALISEDISC 4
#define MMC_OP_RESERVETRACK 5
#define MMC_OP_RESERVETRACK_NWA 6
#define MMC_OP_UNRESERVETRACK 7
#define MMC_OP_REPAIRTRACK 8
#define MMC_OP_UNCLOSELASTSESSION 9
#define MMC_OP_MAX 9
struct mmc_writeparams {
uint16_t tracknr; /* IN */
uint16_t mmc_class; /* IN */
uint32_t mmc_cur; /* IN */
uint32_t blockingnr; /* IN */
/* when tracknr == 0 */
uint8_t track_mode; /* IN; normally 5 */
uint8_t data_mode; /* IN; normally 2 */
};
#define MMC_TRACKMODE_DEFAULT 5 /* data, incremental recording */
#define MMC_DATAMODE_DEFAULT 2 /* CDROM XA disc */
#define MMCSETUPWRITEPARAMS _IOW('c', 31, struct mmc_writeparams)
#endif /* _KERNEL || _EXPOSE_MMC */
#endif /* !_SYS_CDIO_H_ */

280
sys/sys/chio.h Normal file
View file

@ -0,0 +1,280 @@
/* $NetBSD: chio.h,v 1.12 2008/04/28 20:24:10 martin Exp $ */
/*-
* Copyright (c) 1996, 1999 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
* NASA Ames Research Center.
*
* 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.
*/
#ifndef _SYS_CHIO_H_
#define _SYS_CHIO_H_
/*
* Element types. Used as "to" and "from" type indicators in move
* and exchange operations.
*
* Note that code in sys/dev/scsipi/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) */
/*
* Structure used to execute a MOVE MEDIUM command.
*/
struct changer_move_request {
int cm_fromtype; /* element type to move from */
int cm_fromunit; /* logical unit of from element */
int cm_totype; /* element type to move to */
int cm_tounit; /* logical unit of to element */
int 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_request {
int ce_srctype; /* element type of source */
int ce_srcunit; /* logical unit of source */
int ce_fdsttype; /* element type of first destination */
int ce_fdstunit; /* logical unit of first destination */
int ce_sdsttype; /* element type of second destination */
int ce_sdstunit; /* logical unit of second destination */
int 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_request {
int cp_type; /* element type */
int cp_unit; /* logical unit of element */
int cp_flags; /* misc. flags */
};
/* cp_flags */
#define CP_INVERT 0x01 /* invert picker */
/*
* Data returned by CHIOGPARAMS.
*/
struct changer_params {
int cp_curpicker; /* current picker */
int cp_npickers; /* number of pickers */
int cp_nslots; /* number of slots */
int cp_nportals; /* number of import/export portals */
int cp_ndrives; /* number of drives */
};
/*
* Old-style command used to get element status.
*/
struct ochanger_element_status_request {
int cesr_type; /* element type */
uint8_t *cesr_data; /* pre-allocated data storage */
};
/*
* Structure of a changer volume tag.
*/
#define CHANGER_VOLTAG_SIZE 32 /* same as SCSI voltag size */
struct changer_voltag {
char cv_tag[CHANGER_VOLTAG_SIZE + 1]; /* ASCII tag */
uint16_t cv_serial; /* serial number */
};
/*
* Data returned by CHIOGSTATUS.
*/
struct changer_element_status {
int ces_flags; /* CESTATUS_* flags; see below */
/*
* The following is only valid on Data Transport elements (drives).
*/
char ces_xname[16]; /* external name of drive device */
/*
* The following fieds indicate the element the medium was
* moved from in order to arrive in this element.
*/
int ces_from_type; /* type of element */
int ces_from_unit; /* logical unit of element */
/*
* Volume tag information.
*/
struct changer_voltag ces_pvoltag; /* primary volume tag */
struct changer_voltag ces_avoltag; /* alternate volume tag */
size_t ces_vendor_len; /* length of any vendor-specific data */
/*
* These two fields are only valid if CESTATUS_EXCEPT is
* set in ces_flags, and are only valid on SCSI changers.
*/
uint8_t ces_asc; /* Additional Sense Code */
uint8_t ces_ascq; /* Additional Sense Code Qualifier */
/*
* These two fields may be useful if ces_xname is not valid.
* They indicate the target and lun of a drive element. These
* are only valid on SCSI changers.
*/
uint8_t ces_target; /* SCSI target of drive */
uint8_t ces_lun; /* SCSI LUN of drive */
};
/*
* Flags for changer_element_status. These are flags that are returned
* by hardware. Not all flags have meaning for all element types.
*/
#define CESTATUS_FULL 0x0001 /* element is full */
#define CESTATUS_IMPEXP 0x0002 /* media deposited by operator */
#define CESTATUS_EXCEPT 0x0004 /* element in abnormal state */
#define CESTATUS_ACCESS 0x0008 /* media accessible by picker */
#define CESTATUS_EXENAB 0x0010 /* element supports exporting */
#define CESTATUS_INENAB 0x0020 /* element supports importing */
#define CESTATUS_PICKER_MASK 0x0005 /* flags valid for pickers */
#define CESTATUS_SLOT_MASK 0x000c /* flags valid for slots */
#define CESTATUS_PORTAL_MASK 0x003f /* flags valid for portals */
#define CESTATUS_DRIVE_MASK 0x000c /* flags valid for drives */
#define CESTATUS_INVERTED 0x0040 /* medium inverted from storage */
#define CESTATUS_NOTBUS 0x0080 /* drive not on same bus as changer */
/*
* These changer_element_status flags indicate the validity of fields
* in the returned data.
*/
#define CESTATUS_STATUS_VALID 0x0100 /* entire structure valid */
#define CESTATUS_XNAME_VALID 0x0200 /* ces_xname valid */
#define CESTATUS_FROM_VALID 0x0400 /* ces_from_* valid */
#define CESTATUS_PVOL_VALID 0x0800 /* ces_pvoltag valid */
#define CESTATUS_AVOL_VALID 0x1000 /* ces_avoltag valid */
#define CESTATUS_TARGET_VALID 0x2000 /* ces_target valid */
#define CESTATUS_LUN_VALID 0x4000 /* ces_lun valid */
#define CESTATUS_BITS \
"\20\6INEAB\5EXENAB\4ACCESS\3EXCEPT\2IMPEXP\1FULL"
/*
* Command used to get element status.
*/
struct changer_element_status_request {
int cesr_type; /* element type */
int cesr_unit; /* start at this unit */
int cesr_count; /* for this many units */
int cesr_flags; /* flags; see below */
/* pre-allocated data storage */
/*
* These fields point to the data to be returned to the
* user:
*
* cesr_deta: pointer to array of cesr_count status descriptors
*
* cesr_vendor_data: pointer to array of void *'s which point
* to pre-allocated areas for vendor-specific data. Optional.
*/
struct changer_element_status *cesr_data;
void **cesr_vendor_data;
};
#define CESR_VOLTAGS 0x01 /* request volume tags */
/*
* Command used to modify a media element's volume tag.
*/
struct changer_set_voltag_request {
int csvr_type; /* element type */
int csvr_unit; /* unit to modify */
int csvr_flags; /* flags; see below */
/* the actual volume tag; ignored if clearing
the tag */
struct changer_voltag csvr_voltag;
};
#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_MODE_MASK 0x0f
#define CSVR_ALTERNATE 0x10 /* modify alternate volume tag */
/*
* Changer events.
*
* When certain events occur, the kernel can indicate this by setting
* a bit in a bitmask.
*
* When a read is issued to the changer, the kernel returns this event
* bitmask. The read never blocks; if no events are pending, the bitmask
* will be all-clear.
*
* A process may select for read to wait for an event to occur.
*
* The event mask is cleared when the changer is closed.
*/
#define CHANGER_EVENT_SIZE sizeof(u_int)
#define CHEV_ELEMENT_STATUS_CHANGED 0x00000001
/*
* ioctls applicable to changers.
*/
#define CHIOMOVE _IOW('c', 0x01, struct changer_move_request)
#define CHIOEXCHANGE _IOW('c', 0x02, struct changer_exchange_request)
#define CHIOPOSITION _IOW('c', 0x03, struct changer_position_request)
#define CHIOGPICKER _IOR('c', 0x04, int)
#define CHIOSPICKER _IOW('c', 0x05, int)
#define CHIOGPARAMS _IOR('c', 0x06, struct changer_params)
#define CHIOIELEM _IO('c', 0x07)
#define OCHIOGSTATUS _IOW('c', 0x08, struct ochanger_element_status_request)
#define CHIOGSTATUS _IOW('c', 0x09, struct changer_element_status_request)
#define CHIOSVOLTAG _IOW('c', 0x0a, struct changer_set_voltag_request)
#endif /* _SYS_CHIO_H_ */

76
sys/sys/clockctl.h Normal file
View file

@ -0,0 +1,76 @@
/* $NetBSD: clockctl.h,v 1.15 2009/01/11 02:45:55 christos Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Emmanuel Dreyfus.
*
* 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. 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.
*
*
*/
#ifndef _SYS_CLOCKCTL_H_
#define _SYS_CLOCKCTL_H_
#include <sys/time.h>
#include <sys/timex.h>
struct clockctl_settimeofday {
const struct timeval *tv;
const void *tzp;
};
#define CLOCKCTL_SETTIMEOFDAY _IOW('C', 0x5, struct clockctl_settimeofday)
struct clockctl_adjtime {
const struct timeval *delta;
struct timeval *olddelta;
};
#define CLOCKCTL_ADJTIME _IOWR('C', 0x6, struct clockctl_adjtime)
struct clockctl_clock_settime {
clockid_t clock_id;
const struct timespec *tp;
};
#define CLOCKCTL_CLOCK_SETTIME _IOW('C', 0x7, struct clockctl_clock_settime)
struct clockctl_ntp_adjtime {
struct timex *tp;
register_t retval;
};
#define CLOCKCTL_NTP_ADJTIME _IOWR('C', 0x8, struct clockctl_ntp_adjtime)
#ifdef _KERNEL
void clockctlattach(int);
int clockctlopen(dev_t, int, int, struct lwp *);
int clockctlclose(dev_t, int, int, struct lwp *);
int clockctlioctl(dev_t, u_long, void *, int, struct lwp *);
#endif
#endif /* _SYS_CLOCKCTL_H_ */

273
sys/sys/conf.h Normal file
View file

@ -0,0 +1,273 @@
/* $NetBSD: conf.h,v 1.143 2012/07/29 18:05:48 mlelstv Exp $ */
/*-
* Copyright (c) 1990, 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.
* 3. 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
*/
#ifndef _SYS_CONF_H_
#define _SYS_CONF_H_
/*
* Definitions of device driver entry switches
*/
#include <sys/queue.h>
struct buf;
struct knote;
struct lwp;
struct tty;
struct uio;
struct vnode;
/*
* Types for d_flag
*/
#define D_OTHER 0x0000
#define D_TAPE 0x0001
#define D_DISK 0x0002
#define D_TTY 0x0003
#define D_TYPEMASK 0x00ff
#define D_MPSAFE 0x0100
#define D_NEGOFFSAFE 0x0200
/*
* Block device switch table
*/
struct bdevsw {
int (*d_open)(dev_t, int, int, struct lwp *);
int (*d_close)(dev_t, int, int, struct lwp *);
void (*d_strategy)(struct buf *);
int (*d_ioctl)(dev_t, u_long, void *, int, struct lwp *);
int (*d_dump)(dev_t, daddr_t, void *, size_t);
int (*d_psize)(dev_t);
int d_flag;
};
/*
* Character device switch table
*/
struct cdevsw {
int (*d_open)(dev_t, int, int, struct lwp *);
int (*d_close)(dev_t, int, int, struct lwp *);
int (*d_read)(dev_t, struct uio *, int);
int (*d_write)(dev_t, struct uio *, int);
int (*d_ioctl)(dev_t, u_long, void *, int, struct lwp *);
void (*d_stop)(struct tty *, int);
struct tty * (*d_tty)(dev_t);
int (*d_poll)(dev_t, int, struct lwp *);
paddr_t (*d_mmap)(dev_t, off_t, int);
int (*d_kqfilter)(dev_t, struct knote *);
int d_flag;
};
#ifdef _KERNEL
#include <sys/mutex.h>
extern kmutex_t device_lock;
int devsw_attach(const char *, const struct bdevsw *, devmajor_t *,
const struct cdevsw *, devmajor_t *);
int devsw_detach(const struct bdevsw *, const struct cdevsw *);
const struct bdevsw *bdevsw_lookup(dev_t);
const struct cdevsw *cdevsw_lookup(dev_t);
devmajor_t bdevsw_lookup_major(const struct bdevsw *);
devmajor_t cdevsw_lookup_major(const struct cdevsw *);
#define dev_type_open(n) int n (dev_t, int, int, struct lwp *)
#define dev_type_close(n) int n (dev_t, int, int, struct lwp *)
#define dev_type_read(n) int n (dev_t, struct uio *, int)
#define dev_type_write(n) int n (dev_t, struct uio *, int)
#define dev_type_ioctl(n) \
int n (dev_t, u_long, void *, int, struct lwp *)
#define dev_type_stop(n) void n (struct tty *, int)
#define dev_type_tty(n) struct tty * n (dev_t)
#define dev_type_poll(n) int n (dev_t, int, struct lwp *)
#define dev_type_mmap(n) paddr_t n (dev_t, off_t, int)
#define dev_type_strategy(n) void n (struct buf *)
#define dev_type_dump(n) int n (dev_t, daddr_t, void *, size_t)
#define dev_type_size(n) int n (dev_t)
#define dev_type_kqfilter(n) int n (dev_t, struct knote *)
#define noopen ((dev_type_open((*)))enodev)
#define noclose ((dev_type_close((*)))enodev)
#define noread ((dev_type_read((*)))enodev)
#define nowrite ((dev_type_write((*)))enodev)
#define noioctl ((dev_type_ioctl((*)))enodev)
#define nostop ((dev_type_stop((*)))enodev)
#define notty NULL
#define nopoll seltrue
#define nommap ((dev_type_mmap((*)))enodev)
#define nodump ((dev_type_dump((*)))enodev)
#define nosize NULL
#define nokqfilter seltrue_kqfilter
#define nullopen ((dev_type_open((*)))nullop)
#define nullclose ((dev_type_close((*)))nullop)
#define nullread ((dev_type_read((*)))nullop)
#define nullwrite ((dev_type_write((*)))nullop)
#define nullioctl ((dev_type_ioctl((*)))nullop)
#define nullstop ((dev_type_stop((*)))nullop)
#define nullpoll ((dev_type_poll((*)))nullop)
#define nullmmap ((dev_type_mmap((*)))nullop)
#define nulldump ((dev_type_dump((*)))nullop)
#define nullkqfilter ((dev_type_kqfilter((*)))eopnotsupp)
/* device access wrappers. */
dev_type_open(bdev_open);
dev_type_close(bdev_close);
dev_type_strategy(bdev_strategy);
dev_type_ioctl(bdev_ioctl);
dev_type_dump(bdev_dump);
dev_type_size(bdev_size);
dev_type_open(cdev_open);
dev_type_close(cdev_close);
dev_type_read(cdev_read);
dev_type_write(cdev_write);
dev_type_ioctl(cdev_ioctl);
dev_type_stop(cdev_stop);
dev_type_tty(cdev_tty);
dev_type_poll(cdev_poll);
dev_type_mmap(cdev_mmap);
dev_type_kqfilter(cdev_kqfilter);
int cdev_type(dev_t);
int bdev_type(dev_t);
/* symbolic sleep message strings */
extern const char devopn[], devio[], devwait[], devin[], devout[];
extern const char devioc[], devcls[];
#endif /* _KERNEL */
/*
* Line discipline switch table
*/
struct linesw {
const char *l_name; /* Linesw name */
LIST_ENTRY(linesw) l_list;
u_int l_refcnt; /* locked by ttyldisc_list_slock */
int l_no; /* legacy discipline number (for TIOCGETD) */
int (*l_open) (dev_t, struct tty *);
int (*l_close) (struct tty *, int);
int (*l_read) (struct tty *, struct uio *, int);
int (*l_write) (struct tty *, struct uio *, int);
int (*l_ioctl) (struct tty *, u_long, void *, int,
struct lwp *);
int (*l_rint) (int, struct tty *);
int (*l_start) (struct tty *);
int (*l_modem) (struct tty *, int);
int (*l_poll) (struct tty *, int, struct lwp *);
};
#ifdef _KERNEL
void ttyldisc_init(void);
int ttyldisc_attach(struct linesw *);
int ttyldisc_detach(struct linesw *);
struct linesw *ttyldisc_lookup(const char *);
struct linesw *ttyldisc_lookup_bynum(int);
struct linesw *ttyldisc_default(void);
void ttyldisc_release(struct linesw *);
/* For those defining their own line disciplines: */
#define ttynodisc ((int (*)(dev_t, struct tty *))enodev)
#define ttyerrclose ((int (*)(struct tty *, int))enodev)
#define ttyerrio ((int (*)(struct tty *, struct uio *, int))enodev)
#define ttyerrinput ((int (*)(int, struct tty *))enodev)
#define ttyerrstart ((int (*)(struct tty *))enodev)
int ttyerrpoll (struct tty *, int, struct lwp *);
int ttynullioctl(struct tty *, u_long, void *, int, struct lwp *);
int iskmemdev(dev_t);
int seltrue_kqfilter(dev_t, struct knote *);
#endif
#ifdef _KERNEL
#define DEV_MEM 0 /* minor device 0 is physical memory */
#define DEV_KMEM 1 /* minor device 1 is kernel memory */
#define DEV_NULL 2 /* minor device 2 is EOF/rathole */
#ifdef COMPAT_16
#define _DEV_ZERO_oARM 3 /* reserved: old ARM /dev/zero minor */
#endif
#define DEV_ZERO 12 /* minor device 12 is '\0'/rathole */
enum devnode_class {
DEVNODE_DONTBOTHER,
DEVNODE_SINGLE,
DEVNODE_VECTOR,
};
#define DEVNODE_FLAG_LINKZERO 0x01 /* create name -> name0 link */
#define DEVNODE_FLAG_ISMINOR0 0x02 /* vector[0] specifies minor */
#ifdef notyet
#define DEVNODE_FLAG_ISMINOR1 0x04 /* vector[1] specifies starting minor */
#endif
struct devsw_conv {
const char *d_name;
devmajor_t d_bmajor;
devmajor_t d_cmajor;
/* information about /dev nodes related to the device */
enum devnode_class d_class;
int d_flags;
int d_vectdim[2];
};
void devsw_init(void);
const char *devsw_blk2name(devmajor_t);
const char *cdevsw_getname(devmajor_t);
const char *bdevsw_getname(devmajor_t);
devmajor_t devsw_name2blk(const char *, char *, size_t);
devmajor_t devsw_name2chr(const char *, char *, size_t);
dev_t devsw_chr2blk(dev_t);
dev_t devsw_blk2chr(dev_t);
void mm_init(void);
#endif /* _KERNEL */
#ifdef _KERNEL
struct device;
void setroot(struct device *, int);
void rootconf(void);
void swapconf(void);
#endif /* _KERNEL */
#endif /* !_SYS_CONF_H_ */

116
sys/sys/core.h Normal file
View file

@ -0,0 +1,116 @@
/* $NetBSD: core.h,v 1.12 2009/08/20 22:07:49 he Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Paul Kranenburg.
*
* 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.
*/
#ifndef _SYS_CORE_H_
#define _SYS_CORE_H_
#define COREMAGIC 0507
#define CORESEGMAGIC 0510
/*
* The core structure's c_midmag field (like exec's a_midmag) is a
* network-byteorder encoding of this int
* FFFFFFmmmmmmmmmmMMMMMMMMMMMMMMMM
* Where `F' is 6 bits of flag (currently unused),
* `m' is 10 bits of machine-id, and
* `M' is 16 bits worth of magic number, ie. COREMAGIC.
* The macros below will set/get the needed fields.
*/
#define CORE_GETMAGIC(c) ( ntohl(((c).c_midmag)) & 0xffff )
#define CORE_GETMID(c) ( (ntohl(((c).c_midmag)) >> 16) & 0x03ff )
#define CORE_GETFLAG(c) ( (ntohl(((c).c_midmag)) >> 26) & 0x03f )
#define CORE_SETMAGIC(c,mag,mid,flag) ( (c).c_midmag = htonl ( \
( ((flag) & 0x3f) << 26) | \
( ((mid) & 0x03ff) << 16) | \
( ((mag) & 0xffff) ) ) )
/* Flag definitions */
#define CORE_CPU 1
#define CORE_DATA 2
#define CORE_STACK 4
#include <sys/aout_mids.h>
/*
* A core file consists of a header followed by a number of segments.
* Each segment is preceded by a `coreseg' structure giving the
* segment's type, the virtual address where the bits resided in
* process address space and the size of the segment.
*
* The core header specifies the lengths of the core header itself and
* each of the following core segment headers to allow for any machine
* dependent alignment requirements.
*/
struct core {
uint32_t c_midmag; /* magic, id, flags */
uint16_t c_hdrsize; /* Size of this header (machdep algn) */
uint16_t c_seghdrsize; /* Size of a segment header */
uint32_t c_nseg; /* # of core segments */
char c_name[MAXCOMLEN+1]; /* Copy of p->p_comm */
uint32_t c_signo; /* Killing signal */
u_long c_ucode; /* Hmm ? */
u_long c_cpusize; /* Size of machine dependent segment */
u_long c_tsize; /* Size of traditional text segment */
u_long c_dsize; /* Size of traditional data segment */
u_long c_ssize; /* Size of traditional stack segment */
};
struct coreseg {
uint32_t c_midmag; /* magic, id, flags */
u_long c_addr; /* Virtual address of segment */
u_long c_size; /* Size of this segment */
};
/*
* 32-bit versions of the above.
*/
struct core32 {
uint32_t c_midmag; /* magic, id, flags */
uint16_t c_hdrsize; /* Size of this header (machdep algn) */
uint16_t c_seghdrsize; /* Size of a segment header */
uint32_t c_nseg; /* # of core segments */
char c_name[MAXCOMLEN+1]; /* Copy of p->p_comm */
uint32_t c_signo; /* Killing signal */
u_int c_ucode; /* Hmm ? */
u_int c_cpusize; /* Size of machine dependent segment */
u_int c_tsize; /* Size of traditional text segment */
u_int c_dsize; /* Size of traditional data segment */
u_int c_ssize; /* Size of traditional stack segment */
};
struct coreseg32 {
uint32_t c_midmag; /* magic, id, flags */
u_int c_addr; /* Virtual address of segment */
u_int c_size; /* Size of this segment */
};
#endif /* !_SYS_CORE_H_ */

151
sys/sys/cprng.h Normal file
View file

@ -0,0 +1,151 @@
/* $NetBSD: cprng.h,v 1.5 2012/04/17 02:50:39 tls Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Thor Lancelot Simon.
*
* 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.
*/
#ifndef _CPRNG_H
#define _CPRNG_H
#include <sys/types.h>
#include <sys/fcntl.h>
#include <lib/libkern/libkern.h>
#include <sys/rnd.h>
#include <crypto/nist_ctr_drbg/nist_ctr_drbg.h>
#include <sys/condvar.h>
#include <sys/select.h>
/*
* NIST SP800-90 says 2^19 bytes per request for the CTR_DRBG.
*/
#define CPRNG_MAX_LEN 524288
#if !defined(_RUMPKERNEL) && !defined(_RUMP_NATIVE_ABI)
/*
* We do not want an arc4random() prototype available to anyone.
*/
void _arc4randbytes(void *, size_t);
uint32_t _arc4random(void);
static inline size_t
cprng_fast(void *p, size_t len)
{
_arc4randbytes(p, len);
return len;
}
static inline uint32_t
cprng_fast32(void)
{
return _arc4random();
}
static inline uint64_t
cprng_fast64(void)
{
uint64_t r;
_arc4randbytes(&r, sizeof(r));
return r;
}
#else
size_t cprng_fast(void *, size_t);
uint32_t cprng_fast32(void);
uint64_t cprng_fast64(void);
#endif
typedef struct _cprng_strong {
kmutex_t mtx;
kcondvar_t cv;
struct selinfo selq;
NIST_CTR_DRBG drbg;
int flags;
char name[16];
int reseed_pending;
int entropy_serial;
rndsink_t reseed;
} cprng_strong_t;
#define CPRNG_INIT_ANY 0x00000001
#define CPRNG_REKEY_ANY 0x00000002
#define CPRNG_USE_CV 0x00000004
cprng_strong_t *cprng_strong_create(const char *const, int, int);
size_t cprng_strong(cprng_strong_t *const, void *const, size_t, int);
void cprng_strong_destroy(cprng_strong_t *);
extern cprng_strong_t * kern_cprng;
static inline uint32_t
cprng_strong32(void)
{
uint32_t r;
cprng_strong(kern_cprng, &r, sizeof(r), 0);
return r;
}
static inline uint64_t
cprng_strong64(void)
{
uint64_t r;
cprng_strong(kern_cprng, &r, sizeof(r), 0);
return r;
}
static inline int
cprng_strong_ready(cprng_strong_t *c)
{
int ret = 0;
mutex_enter(&c->mtx);
if (c->drbg.reseed_counter < NIST_CTR_DRBG_RESEED_INTERVAL) {
ret = 1;
}
mutex_exit(&c->mtx);
return ret;
}
static inline void
cprng_strong_deplete(cprng_strong_t *c)
{
mutex_enter(&c->mtx);
c->drbg.reseed_counter = NIST_CTR_DRBG_RESEED_INTERVAL + 1;
mutex_exit(&c->mtx);
}
static inline int
cprng_strong_strength(cprng_strong_t *c)
{
return NIST_BLOCK_KEYLEN_BYTES;
}
void cprng_init(void);
int cprng_strong_getflags(cprng_strong_t *const);
void cprng_strong_setflags(cprng_strong_t *const, int);
#endif

140
sys/sys/cpu.h Normal file
View file

@ -0,0 +1,140 @@
/* $NetBSD: cpu.h,v 1.36 2012/08/29 17:13:22 drochner Exp $ */
/*-
* Copyright (c) 2007 YAMAMOTO Takashi,
* 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.
*/
#ifndef _SYS_CPU_H_
#define _SYS_CPU_H_
#ifndef _LOCORE
#include <machine/cpu.h>
#include <sys/lwp.h>
struct cpu_info;
#ifdef _KERNEL
#ifndef cpu_idle
void cpu_idle(void);
#endif
#ifdef CPU_UCODE
#include <sys/cpuio.h>
#include <dev/firmload.h>
/* XXX ifdef COMPAT */
#include <compat/sys/cpuio.h>
#endif
/*
* cpu_need_resched() must always be called with the target CPU
* locked (via spc_lock() or another route), unless called locally.
* If called locally, the caller need only be at IPL_SCHED.
*/
#ifndef cpu_need_resched
void cpu_need_resched(struct cpu_info *, int);
#endif
#ifndef cpu_did_resched
#define cpu_did_resched(l) /* nothing */
#endif
#ifndef CPU_INFO_ITERATOR
#define CPU_INFO_ITERATOR int
#define CPU_INFO_FOREACH(cii, ci) \
(void)cii, ci = curcpu(); ci != NULL; ci = NULL
#endif
#ifndef CPU_IS_PRIMARY
#define CPU_IS_PRIMARY(ci) ((void)ci, 1)
#endif
#ifdef __HAVE_MD_CPU_OFFLINE
void cpu_offline_md(void);
#endif
struct lwp *cpu_switchto(struct lwp *, struct lwp *, bool);
struct cpu_info *cpu_lookup(u_int);
int cpu_setstate(struct cpu_info *, bool);
int cpu_setintr(struct cpu_info *, bool);
bool cpu_intr_p(void);
bool cpu_softintr_p(void);
bool cpu_kpreempt_enter(uintptr_t, int);
void cpu_kpreempt_exit(uintptr_t);
bool cpu_kpreempt_disabled(void);
int cpu_lwp_setprivate(struct lwp *, void *);
void cpu_intr_redistribute(void);
u_int cpu_intr_count(struct cpu_info *);
#endif
CIRCLEQ_HEAD(cpuqueue, cpu_info);
#ifdef _KERNEL
extern kmutex_t cpu_lock;
extern u_int maxcpus;
extern struct cpuqueue cpu_queue;
extern kcpuset_t *kcpuset_attached;
extern kcpuset_t *kcpuset_running;
static inline u_int
cpu_index(struct cpu_info *ci)
{
return ci->ci_index;
}
static inline char *
cpu_name(struct cpu_info *ci)
{
return ci->ci_data.cpu_name;
}
#ifdef CPU_UCODE
struct cpu_ucode_softc {
int loader_version;
char *sc_blob;
off_t sc_blobsize;
};
int cpu_ucode_get_version(struct cpu_ucode_version *);
/* XXX ifdef COMPAT */
int compat6_cpu_ucode_get_version(struct compat6_cpu_ucode *);
int cpu_ucode_apply(const struct cpu_ucode *);
/* XXX ifdef COMPAT */
int compat6_cpu_ucode_apply(const struct compat6_cpu_ucode *);
int cpu_ucode_load(struct cpu_ucode_softc *, const char *);
int cpu_ucode_md_open(firmware_handle_t *, int, const char *);
#endif
#endif
#endif /* !_LOCORE */
/* flags for cpu_need_resched */
#define RESCHED_LAZY 0x01 /* request a ctx switch */
#define RESCHED_IMMED 0x02 /* request an immediate ctx switch */
#define RESCHED_KPREEMPT 0x04 /* request in-kernel preemption */
#endif /* !_SYS_CPU_H_ */

135
sys/sys/cpu_data.h Normal file
View file

@ -0,0 +1,135 @@
/* $NetBSD: cpu_data.h,v 1.35 2012/09/01 00:24:44 matt Exp $ */
/*-
* Copyright (c) 2004, 2006, 2007, 2008 The NetBSD Foundation, 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.
*
* 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.
*/
/*
* based on arch/i386/include/cpu.h:
* NetBSD: cpu.h,v 1.115 2004/05/16 12:32:53 yamt Exp
*/
#ifndef _SYS_CPU_DATA_H_
#define _SYS_CPU_DATA_H_
struct callout;
struct lwp;
#include <sys/sched.h> /* for schedstate_percpu */
#include <sys/condvar.h>
#include <sys/pcu.h>
#include <sys/percpu_types.h>
#include <sys/queue.h>
#include <sys/kcpuset.h>
/*
* MI per-cpu data
*
* this structure is intended to be included in MD cpu_info structure.
* struct cpu_info {
* struct cpu_data ci_data;
* }
*
* note that cpu_data is not expected to contain much data,
* as cpu_info is size-limited on most ports.
*/
struct lockdebug;
struct cpu_data {
/*
* The first section is likely to be touched by other CPUs -
* it is cache hot.
*/
lwp_t *cpu_biglock_wanted; /* LWP spinning on biglock */
void *cpu_callout; /* per-CPU callout state */
void *cpu_unused1; /* unused */
u_int cpu_unused2; /* unused */
struct schedstate_percpu cpu_schedstate; /* scheduler state */
kcondvar_t cpu_xcall; /* cross-call support */
int cpu_xcall_pending; /* cross-call support */
lwp_t *cpu_onproc; /* bottom level LWP */
CIRCLEQ_ENTRY(cpu_info) cpu_qchain; /* circleq of all CPUs */
cpuid_t cpu_package_id;
cpuid_t cpu_core_id;
cpuid_t cpu_smt_id;
struct lwp * volatile cpu_pcu_curlwp[PCU_UNIT_COUNT];
/*
* This section is mostly CPU-private.
*/
lwp_t *cpu_idlelwp; /* idle lwp */
void *cpu_lockstat; /* lockstat private tables */
u_int cpu_index; /* CPU index */
u_int cpu_biglock_count; /* # recursive holds */
u_int cpu_spin_locks; /* # of spinlockmgr locks */
u_int cpu_simple_locks; /* # of simple locks held */
u_int cpu_spin_locks2; /* # of spin locks held XXX */
u_int cpu_lkdebug_recurse; /* LOCKDEBUG recursion */
u_int cpu_softints; /* pending (slow) softints */
uint64_t cpu_nsyscall; /* syscall counter */
uint64_t cpu_ntrap; /* trap counter */
uint64_t cpu_nswtch; /* context switch counter */
uint64_t cpu_nintr; /* interrupt count */
uint64_t cpu_nsoft; /* soft interrupt count */
uint64_t cpu_nfault; /* pagefault counter */
void *cpu_uvm; /* uvm per-cpu data */
void *cpu_softcpu; /* soft interrupt table */
TAILQ_HEAD(,buf) cpu_biodone; /* finished block xfers */
percpu_cpu_t cpu_percpu; /* per-cpu data */
struct selcluster *cpu_selcluster; /* per-CPU select() info */
void *cpu_nch; /* per-cpu vfs_cache data */
_TAILQ_HEAD(,struct lockdebug,volatile) cpu_ld_locks;/* !: lockdebug */
__cpu_simple_lock_t cpu_ld_lock; /* lockdebug */
uint64_t cpu_cc_freq; /* cycle counter frequency */
int64_t cpu_cc_skew; /* counter skew vs cpu0 */
char cpu_name[8]; /* eg, "cpu4" */
kcpuset_t *cpu_kcpuset; /* kcpuset_t of this cpu only */
};
/* compat definitions */
#define ci_schedstate ci_data.cpu_schedstate
#define ci_index ci_data.cpu_index
#define ci_biglock_count ci_data.cpu_biglock_count
#define ci_biglock_wanted ci_data.cpu_biglock_wanted
#define ci_cpuname ci_data.cpu_name
#define ci_spin_locks ci_data.cpu_spin_locks
#define ci_simple_locks ci_data.cpu_simple_locks
#define ci_lockstat ci_data.cpu_lockstat
#define ci_spin_locks2 ci_data.cpu_spin_locks2
#define ci_lkdebug_recurse ci_data.cpu_lkdebug_recurse
#define ci_pcu_curlwp ci_data.cpu_pcu_curlwp
#define ci_kcpuset ci_data.cpu_kcpuset
#define ci_package_id ci_data.cpu_package_id
#define ci_core_id ci_data.cpu_core_id
#define ci_smt_id ci_data.cpu_smt_id
void mi_cpu_init(void);
int mi_cpu_attach(struct cpu_info *);
#endif /* _SYS_CPU_DATA_H_ */

93
sys/sys/cpufreq.h Normal file
View file

@ -0,0 +1,93 @@
/* $NetBSD: cpufreq.h,v 1.5 2011/10/27 05:13:04 jruoho Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jukka Ruohonen.
*
* 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.
*/
#ifndef _SYS_CPUFREQ_H_
#define _SYS_CPUFREQ_H_
#ifndef _KERNEL
#include <stdbool.h>
#endif
#ifdef _KERNEL
#ifndef _SYS_XCALL_H_
#include <sys/xcall.h>
#endif
#endif
#define CPUFREQ_NAME_MAX 16
#define CPUFREQ_STATE_MAX 32
#define CPUFREQ_LATENCY_MAX UINT32_MAX
#define CPUFREQ_STATE_ENABLED UINT32_MAX
#define CPUFREQ_STATE_DISABLED UINT32_MAX - 1
struct cpufreq_state {
uint32_t cfs_freq; /* MHz */
uint32_t cfs_power; /* mW */
uint32_t cfs_latency; /* usec */
uint32_t cfs_index;
uint32_t cfs_reserved[5];
};
struct cpufreq {
char cf_name[CPUFREQ_NAME_MAX];
uint32_t cf_state_count;
uint32_t cf_state_target;
uint32_t cf_state_current;
uint32_t cf_reserved[5];
u_int cf_index;
#ifdef _KERNEL
bool cf_mp;
bool cf_init;
void *cf_cookie;
xcfunc_t cf_get_freq;
xcfunc_t cf_set_freq;
uint32_t cf_state_saved;
struct cpufreq_state cf_state[CPUFREQ_STATE_MAX];
#endif /* _KERNEL */
};
#ifdef _KERNEL
void cpufreq_init(void);
int cpufreq_register(struct cpufreq *);
void cpufreq_deregister(void);
void cpufreq_suspend(struct cpu_info *);
void cpufreq_resume(struct cpu_info *);
uint32_t cpufreq_get(struct cpu_info *);
int cpufreq_get_backend(struct cpufreq *);
int cpufreq_get_state(uint32_t, struct cpufreq_state *);
int cpufreq_get_state_index(uint32_t, struct cpufreq_state *);
void cpufreq_set(struct cpu_info *, uint32_t);
void cpufreq_set_all(uint32_t);
#endif /* _KERNEL */
#endif /* _SYS_CPUFREQ_H_ */

83
sys/sys/cpuio.h Normal file
View file

@ -0,0 +1,83 @@
/* $NetBSD: cpuio.h,v 1.8 2012/08/29 17:13:22 drochner Exp $ */
/*-
* Copyright (c) 2007, 2009, 2012 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Andrew Doran.
*
* 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.
*/
#if !defined(_SYS_CPUIO_H_)
#define _SYS_CPUIO_H_
#include <sys/types.h>
#include <sys/time.h>
#include <sys/ioccom.h>
#ifndef _KERNEL
#include <limits.h>
#include <stdbool.h>
#endif
/*
* This is not a great place to describe CPU properties, those
* are better returned via autoconf.
*/
typedef struct cpustate {
u_int cs_id; /* matching ci_cpuid */
bool cs_online; /* running unbound LWPs */
bool cs_intr; /* fielding interrupts */
bool cs_unused[2]; /* reserved */
int32_t cs_lastmod; /* time of last state change */
char cs_name[16]; /* reserved */
int32_t cs_lastmodhi; /* time of last state change */
uint32_t cs_intrcnt; /* count of interrupt handlers + 1 */
uint32_t cs_hwid; /* hardware id */
uint32_t cs_reserved; /* reserved */
} cpustate_t;
#define IOC_CPU_SETSTATE _IOW('c', 0, cpustate_t)
#define IOC_CPU_GETSTATE _IOWR('c', 1, cpustate_t)
#define IOC_CPU_GETCOUNT _IOR('c', 2, int)
#define IOC_CPU_MAPID _IOWR('c', 3, int)
/* 4 and 5 reserved for compat nb6 x86 amd ucode loader */
struct cpu_ucode_version {
int loader_version; /* IN: md version number */
void *data; /* OUT: CPU ID data */
};
struct cpu_ucode {
int loader_version; /* md version number */
int cpu_nr; /* CPU index or special value below */
#define CPU_UCODE_ALL_CPUS (-1)
#define CPU_UCODE_CURRENT_CPU (-2)
char fwname[PATH_MAX];
};
#define IOC_CPU_UCODE_GET_VERSION _IOWR('c', 6, struct cpu_ucode_version)
#define IOC_CPU_UCODE_APPLY _IOW('c', 7, struct cpu_ucode)
#endif /* !_SYS_CPUIO_H_ */

52
sys/sys/debug.h Normal file
View file

@ -0,0 +1,52 @@
/* $NetBSD: debug.h,v 1.4 2012/04/15 19:07:40 martin Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Andrew Doran.
*
* 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.
*/
#ifndef __SYS_DEBUG_H__
#define __SYS_DEBUG_H__
#ifndef _KERNEL
#error "Sorry, nothing of interest to user level programs here."
#endif
void debug_init(void);
void freecheck_out(void **, void *);
void freecheck_in(void **, void *);
#if defined(DEBUG) && defined(_HARDKERNEL)
#define FREECHECK_OUT(h, a) freecheck_out((h), (a))
#define FREECHECK_IN(h, a) freecheck_in((h), (a))
#else
#define FREECHECK_OUT(h, a) /* nothing */
#define FREECHECK_IN(h, a) /* nothing */
#endif
#endif /* __SYS_DEBUG_H__ */

585
sys/sys/device.h Normal file
View file

@ -0,0 +1,585 @@
/* $NetBSD: device.h,v 1.142 2012/07/07 16:15:21 tsutsui Exp $ */
/*
* Copyright (c) 1996, 2000 Christopher G. Demetriou
* 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 acknowledgement:
* This product includes software developed for the
* NetBSD Project. See http://www.NetBSD.org/ for
* information about NetBSD.
* 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.
*
* --(license Id: LICENSE.proto,v 1.1 2000/06/13 21:40:26 cgd Exp )--
*/
/*
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* This software was developed by the Computer Systems Engineering group
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
* contributed to Berkeley.
*
* All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Lawrence Berkeley Laboratories.
*
* 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 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.
*
* @(#)device.h 8.2 (Berkeley) 2/17/94
*/
#ifndef _SYS_DEVICE_H_
#define _SYS_DEVICE_H_
#include <sys/device_if.h>
#include <sys/evcnt.h>
#include <sys/queue.h>
#ifdef _KERNEL
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/pmf.h>
#endif
#include <prop/proplib.h>
/*
* Minimal device structures.
* Note that all ``system'' device types are listed here.
*/
typedef enum devclass {
DV_DULL, /* generic, no special info */
DV_CPU, /* CPU (carries resource utilization) */
DV_DISK, /* disk drive (label, etc) */
DV_IFNET, /* network interface */
DV_TAPE, /* tape device */
DV_TTY, /* serial line interface (?) */
DV_AUDIODEV, /* audio device */
DV_DISPLAYDEV, /* display device */
DV_BUS, /* bus device */
DV_VIRTUAL, /* unbacked virtual device */
} devclass_t;
/*
* Actions for ca_activate.
*/
typedef enum devact {
DVACT_DEACTIVATE /* deactivate the device */
} devact_t;
typedef enum {
DVA_SYSTEM,
DVA_HARDWARE
} devactive_t;
typedef struct cfdata *cfdata_t;
typedef struct cfdriver *cfdriver_t;
typedef struct cfattach *cfattach_t;
#ifdef _KERNEL
struct device_lock {
int dvl_nwait;
int dvl_nlock;
lwp_t *dvl_holder;
kmutex_t dvl_mtx;
kcondvar_t dvl_cv;
};
struct device_suspensor {
const device_suspensor_t *ds_delegator;
char ds_name[32];
};
#define DEVICE_SUSPENSORS_MAX 16
struct device {
devclass_t dv_class; /* this device's classification */
TAILQ_ENTRY(device) dv_list; /* entry on list of all devices */
cfdata_t dv_cfdata; /* config data that found us
(NULL if pseudo-device) */
cfdriver_t dv_cfdriver; /* our cfdriver */
cfattach_t dv_cfattach; /* our cfattach */
int dv_unit; /* device unit number */
char dv_xname[16]; /* external name (name + unit) */
device_t dv_parent; /* pointer to parent device
(NULL if pseudo- or root node) */
int dv_depth; /* number of parents until root */
int dv_flags; /* misc. flags; see below */
void *dv_private; /* this device's private storage */
int *dv_locators; /* our actual locators (optional) */
prop_dictionary_t dv_properties;/* properties dictionary */
size_t dv_activity_count;
void (**dv_activity_handlers)(device_t, devactive_t);
bool (*dv_driver_suspend)(device_t, const pmf_qual_t *);
bool (*dv_driver_resume)(device_t, const pmf_qual_t *);
bool (*dv_driver_shutdown)(device_t, int);
bool (*dv_driver_child_register)(device_t);
void *dv_bus_private;
bool (*dv_bus_suspend)(device_t, const pmf_qual_t *);
bool (*dv_bus_resume)(device_t, const pmf_qual_t *);
bool (*dv_bus_shutdown)(device_t, int);
void (*dv_bus_deregister)(device_t);
void *dv_class_private;
bool (*dv_class_suspend)(device_t, const pmf_qual_t *);
bool (*dv_class_resume)(device_t, const pmf_qual_t *);
void (*dv_class_deregister)(device_t);
devgen_t dv_add_gen,
dv_del_gen;
struct device_lock dv_lock;
const device_suspensor_t
*dv_bus_suspensors[DEVICE_SUSPENSORS_MAX],
*dv_driver_suspensors[DEVICE_SUSPENSORS_MAX],
*dv_class_suspensors[DEVICE_SUSPENSORS_MAX];
struct device_garbage {
device_t *dg_devs;
int dg_ndevs;
} dv_garbage;
};
/* dv_flags */
#define DVF_ACTIVE 0x0001 /* device is activated */
#define DVF_PRIV_ALLOC 0x0002 /* device private storage != device */
#define DVF_POWER_HANDLERS 0x0004 /* device has suspend/resume support */
#define DVF_CLASS_SUSPENDED 0x0008 /* device class suspend was called */
#define DVF_DRIVER_SUSPENDED 0x0010 /* device driver suspend was called */
#define DVF_BUS_SUSPENDED 0x0020 /* device bus suspend was called */
#define DVF_DETACH_SHUTDOWN 0x0080 /* device detaches safely at shutdown */
TAILQ_HEAD(devicelist, device);
enum deviter_flags {
DEVITER_F_RW = 0x1
, DEVITER_F_SHUTDOWN = 0x2
, DEVITER_F_LEAVES_FIRST = 0x4
, DEVITER_F_ROOT_FIRST = 0x8
};
typedef enum deviter_flags deviter_flags_t;
struct deviter {
device_t di_prev;
deviter_flags_t di_flags;
int di_curdepth;
int di_maxdepth;
devgen_t di_gen;
};
typedef struct deviter deviter_t;
struct shutdown_state {
bool initialized;
deviter_t di;
};
#endif
/*
* Description of a locator, as part of interface attribute definitions.
*/
struct cflocdesc {
const char *cld_name;
const char *cld_defaultstr; /* NULL if no default */
int cld_default;
};
/*
* Description of an interface attribute, provided by potential
* parent device drivers, referred to by child device configuration data.
*/
struct cfiattrdata {
const char *ci_name;
int ci_loclen;
const struct cflocdesc ci_locdesc[
#if defined(__GNUC__) && __GNUC__ <= 2
0
#endif
];
};
/*
* Description of a configuration parent. Each device attachment attaches
* to an "interface attribute", which is given in this structure. The parent
* *must* carry this attribute. Optionally, an individual device instance
* may also specify a specific parent device instance.
*/
struct cfparent {
const char *cfp_iattr; /* interface attribute */
const char *cfp_parent; /* optional specific parent */
int cfp_unit; /* optional specific unit
(DVUNIT_ANY to wildcard) */
};
/*
* Configuration data (i.e., data placed in ioconf.c).
*/
struct cfdata {
const char *cf_name; /* driver name */
const char *cf_atname; /* attachment name */
short cf_unit; /* unit number */
short cf_fstate; /* finding state (below) */
int *cf_loc; /* locators (machine dependent) */
int cf_flags; /* flags from config */
const struct cfparent *cf_pspec;/* parent specification */
};
#define FSTATE_NOTFOUND 0 /* has not been found */
#define FSTATE_FOUND 1 /* has been found */
#define FSTATE_STAR 2 /* duplicable */
#define FSTATE_DSTAR 3 /* has not been found, and disabled */
#define FSTATE_DNOTFOUND 4 /* duplicate, and disabled */
/*
* Multiple configuration data tables may be maintained. This structure
* provides the linkage.
*/
struct cftable {
cfdata_t ct_cfdata; /* pointer to cfdata table */
TAILQ_ENTRY(cftable) ct_list; /* list linkage */
};
TAILQ_HEAD(cftablelist, cftable);
typedef int (*cfsubmatch_t)(device_t, cfdata_t, const int *, void *);
/*
* `configuration' attachment and driver (what the machine-independent
* autoconf uses). As devices are found, they are applied against all
* the potential matches. The one with the best match is taken, and a
* device structure (plus any other data desired) is allocated. Pointers
* to these are placed into an array of pointers. The array itself must
* be dynamic since devices can be found long after the machine is up
* and running.
*
* Devices can have multiple configuration attachments if they attach
* to different attributes (busses, or whatever), to allow specification
* of multiple match and attach functions. There is only one configuration
* driver per driver, so that things like unit numbers and the device
* structure array will be shared.
*/
struct cfattach {
const char *ca_name; /* name of attachment */
LIST_ENTRY(cfattach) ca_list; /* link on cfdriver's list */
size_t ca_devsize; /* size of dev data (for alloc) */
int ca_flags; /* flags for driver allocation etc */
int (*ca_match)(device_t, cfdata_t, void *);
void (*ca_attach)(device_t, device_t, void *);
int (*ca_detach)(device_t, int);
int (*ca_activate)(device_t, devact_t);
/* technically, the next 2 belong into "struct cfdriver" */
int (*ca_rescan)(device_t, const char *,
const int *); /* scan for new children */
void (*ca_childdetached)(device_t, device_t);
};
LIST_HEAD(cfattachlist, cfattach);
#define CFATTACH_DECL(name, ddsize, matfn, attfn, detfn, actfn) \
struct cfattach __CONCAT(name,_ca) = { \
.ca_name = ___STRING(name), \
.ca_devsize = ddsize, \
.ca_flags = 0, \
.ca_match = matfn, \
.ca_attach = attfn, \
.ca_detach = detfn, \
.ca_activate = actfn, \
.ca_rescan = NULL, \
.ca_childdetached = NULL, \
}
#define CFATTACH_DECL3_NEW(name, ddsize, matfn, attfn, detfn, actfn, \
rescanfn, chdetfn, __flags) \
struct cfattach __CONCAT(name,_ca) = { \
.ca_name = ___STRING(name), \
.ca_devsize = ddsize, \
.ca_flags = (__flags) | DVF_PRIV_ALLOC, \
.ca_match = matfn, \
.ca_attach = attfn, \
.ca_detach = detfn, \
.ca_activate = actfn, \
.ca_rescan = rescanfn, \
.ca_childdetached = chdetfn, \
}
#define CFATTACH_DECL2_NEW(name, ddsize, matfn, attfn, detfn, actfn, \
rescanfn, chdetfn) \
CFATTACH_DECL3_NEW(name, ddsize, matfn, attfn, detfn, actfn, \
rescanfn, chdetfn, 0)
#define CFATTACH_DECL_NEW(name, ddsize, matfn, attfn, detfn, actfn) \
CFATTACH_DECL2_NEW(name, ddsize, matfn, attfn, detfn, actfn, NULL, NULL)
/* Flags given to config_detach(), and the ca_detach function. */
#define DETACH_FORCE 0x01 /* force detachment; hardware gone */
#define DETACH_QUIET 0x02 /* don't print a notice */
#define DETACH_SHUTDOWN 0x04 /* detach because of system shutdown */
struct cfdriver {
LIST_ENTRY(cfdriver) cd_list; /* link on allcfdrivers */
struct cfattachlist cd_attach; /* list of all attachments */
device_t *cd_devs; /* devices found */
const char *cd_name; /* device name */
enum devclass cd_class; /* device classification */
int cd_ndevs; /* size of cd_devs array */
const struct cfiattrdata * const *cd_attrs; /* attributes provided */
};
LIST_HEAD(cfdriverlist, cfdriver);
#define CFDRIVER_DECL(name, class, attrs) \
struct cfdriver __CONCAT(name,_cd) = { \
.cd_name = ___STRING(name), \
.cd_class = class, \
.cd_attrs = attrs, \
}
/*
* The cfattachinit is a data structure used to associate a list of
* cfattach's with cfdrivers as found in the static kernel configuration.
*/
struct cfattachinit {
const char *cfai_name; /* driver name */
struct cfattach * const *cfai_list;/* list of attachments */
};
/*
* the same, but with a non-constant list so it can be modified
* for module bookkeeping
*/
struct cfattachlkminit {
const char *cfai_name; /* driver name */
struct cfattach **cfai_list; /* list of attachments */
};
/*
* Configuration printing functions, and their return codes. The second
* argument is NULL if the device was configured; otherwise it is the name
* of the parent device. The return value is ignored if the device was
* configured, so most functions can return UNCONF unconditionally.
*/
typedef int (*cfprint_t)(void *, const char *); /* XXX const char * */
#define QUIET 0 /* print nothing */
#define UNCONF 1 /* print " not configured\n" */
#define UNSUPP 2 /* print " not supported\n" */
/*
* Pseudo-device attach information (function + number of pseudo-devs).
*/
struct pdevinit {
void (*pdev_attach)(int);
int pdev_count;
};
/* This allows us to wildcard a device unit. */
#define DVUNIT_ANY -1
#ifdef _KERNEL
extern struct cfdriverlist allcfdrivers;/* list of all cfdrivers */
extern struct cftablelist allcftables; /* list of all cfdata tables */
extern device_t booted_device; /* the device we booted from */
extern int booted_partition; /* the partition on that device */
extern daddr_t booted_startblk; /* or the start of a wedge */
extern uint64_t booted_nblks; /* and the size of that wedge */
struct vnode *opendisk(struct device *);
int getdisksize(struct vnode *, uint64_t *, unsigned int *);
struct dkwedge_info;
int getdiskinfo(struct vnode *, struct dkwedge_info *);
void config_init(void);
int config_init_component(struct cfdriver *const*,
const struct cfattachinit *, struct cfdata *);
int config_fini_component(struct cfdriver *const*,
const struct cfattachinit *, struct cfdata *);
void config_init_mi(void);
void drvctl_init(void);
int config_cfdriver_attach(struct cfdriver *);
int config_cfdriver_detach(struct cfdriver *);
int config_cfattach_attach(const char *, struct cfattach *);
int config_cfattach_detach(const char *, struct cfattach *);
int config_cfdata_attach(cfdata_t, int);
int config_cfdata_detach(cfdata_t);
struct cfdriver *config_cfdriver_lookup(const char *);
struct cfattach *config_cfattach_lookup(const char *, const char *);
const struct cfiattrdata *cfiattr_lookup(const char *, const struct cfdriver *);
const char *cfdata_ifattr(const struct cfdata *);
int config_stdsubmatch(device_t, cfdata_t, const int *, void *);
cfdata_t config_search_loc(cfsubmatch_t, device_t,
const char *, const int *, void *);
cfdata_t config_search_ia(cfsubmatch_t, device_t,
const char *, void *);
cfdata_t config_rootsearch(cfsubmatch_t, const char *, void *);
device_t config_found_sm_loc(device_t, const char *, const int *,
void *, cfprint_t, cfsubmatch_t);
device_t config_found_ia(device_t, const char *, void *, cfprint_t);
device_t config_found(device_t, void *, cfprint_t);
device_t config_rootfound(const char *, void *);
device_t config_attach_loc(device_t, cfdata_t, const int *, void *, cfprint_t);
device_t config_attach(device_t, cfdata_t, void *, cfprint_t);
int config_match(device_t, cfdata_t, void *);
bool ifattr_match(const char *, const char *);
device_t config_attach_pseudo(cfdata_t);
int config_detach(device_t, int);
int config_detach_children(device_t, int flags);
bool config_detach_all(int);
int config_deactivate(device_t);
void config_defer(device_t, void (*)(device_t));
void config_deferred(device_t);
void config_interrupts(device_t, void (*)(device_t));
void config_mountroot(device_t, void (*)(device_t));
void config_pending_incr(void);
void config_pending_decr(void);
void config_create_interruptthreads(void);
void config_create_mountrootthreads(void);
int config_finalize_register(device_t, int (*)(device_t));
void config_finalize(void);
void config_twiddle_init(void);
void config_twiddle_fn(void *);
void null_childdetached(device_t, device_t);
device_t device_lookup(cfdriver_t, int);
void *device_lookup_private(cfdriver_t, int);
void device_register(device_t, void *);
void device_register_post_config(device_t, void *);
devclass_t device_class(device_t);
cfdata_t device_cfdata(device_t);
cfdriver_t device_cfdriver(device_t);
cfattach_t device_cfattach(device_t);
int device_unit(device_t);
const char *device_xname(device_t);
device_t device_parent(device_t);
bool device_is_active(device_t);
bool device_activation(device_t, devact_level_t);
bool device_is_enabled(device_t);
bool device_has_power(device_t);
int device_locator(device_t, u_int);
void *device_private(device_t);
prop_dictionary_t device_properties(device_t);
device_t deviter_first(deviter_t *, deviter_flags_t);
void deviter_init(deviter_t *, deviter_flags_t);
device_t deviter_next(deviter_t *);
void deviter_release(deviter_t *);
bool device_active(device_t, devactive_t);
bool device_active_register(device_t,
void (*)(device_t, devactive_t));
void device_active_deregister(device_t,
void (*)(device_t, devactive_t));
bool device_is_a(device_t, const char *);
device_t device_find_by_xname(const char *);
device_t device_find_by_driver_unit(const char *, int);
bool device_pmf_is_registered(device_t);
bool device_pmf_driver_suspend(device_t, const pmf_qual_t *);
bool device_pmf_driver_resume(device_t, const pmf_qual_t *);
bool device_pmf_driver_shutdown(device_t, int);
bool device_pmf_driver_register(device_t,
bool (*)(device_t, const pmf_qual_t *),
bool (*)(device_t, const pmf_qual_t *),
bool (*)(device_t, int));
void device_pmf_driver_deregister(device_t);
bool device_pmf_driver_child_register(device_t);
void device_pmf_driver_set_child_register(device_t,
bool (*)(device_t));
void *device_pmf_bus_private(device_t);
bool device_pmf_bus_suspend(device_t, const pmf_qual_t *);
bool device_pmf_bus_resume(device_t, const pmf_qual_t *);
bool device_pmf_bus_shutdown(device_t, int);
device_lock_t device_getlock(device_t);
void device_pmf_unlock(device_t);
bool device_pmf_lock(device_t);
bool device_is_self_suspended(device_t);
void device_pmf_self_suspend(device_t, const pmf_qual_t *);
void device_pmf_self_resume(device_t, const pmf_qual_t *);
bool device_pmf_self_wait(device_t, const pmf_qual_t *);
void device_pmf_bus_register(device_t, void *,
bool (*)(device_t, const pmf_qual_t *),
bool (*)(device_t, const pmf_qual_t *),
bool (*)(device_t, int),
void (*)(device_t));
void device_pmf_bus_deregister(device_t);
void *device_pmf_class_private(device_t);
bool device_pmf_class_suspend(device_t, const pmf_qual_t *);
bool device_pmf_class_resume(device_t, const pmf_qual_t *);
void device_pmf_class_register(device_t, void *,
bool (*)(device_t, const pmf_qual_t *),
bool (*)(device_t, const pmf_qual_t *),
void (*)(device_t));
void device_pmf_class_deregister(device_t);
device_t shutdown_first(struct shutdown_state *);
device_t shutdown_next(struct shutdown_state *);
#endif /* _KERNEL */
#endif /* !_SYS_DEVICE_H_ */

27
sys/sys/device_if.h Normal file
View file

@ -0,0 +1,27 @@
/* $NetBSD: device_if.h,v 1.5 2010/02/24 22:38:10 dyoung Exp $ */
#ifndef _SYS_DEVICE_IF_H
#define _SYS_DEVICE_IF_H
struct device;
typedef struct device *device_t;
#ifdef _KERNEL
typedef enum devact_level {
DEVACT_LEVEL_CLASS = 0
, DEVACT_LEVEL_DRIVER = 1
, DEVACT_LEVEL_BUS = 2
} devact_level_t;
#define DEVACT_LEVEL_FULL DEVACT_LEVEL_CLASS
struct device_lock;
struct device_suspensor;
typedef uint64_t devgen_t;
typedef struct device_lock *device_lock_t;
typedef struct device_suspensor device_suspensor_t;
#endif
#endif /* _SYS_DEVICE_IF_H */

36
sys/sys/devmon.h Normal file
View file

@ -0,0 +1,36 @@
/* $NetBSD: devmon.h,v 1.1 2008/05/25 12:30:40 jmcneill Exp $ */
/*
* Copyright (c) 2007
* Jachym Holecek <freza@NetBSD.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.
*/
#include <prop/proplib.h>
#ifndef _SYS_DEVMON_H_
#define _SYS_DEVMON_H_
void devmon_insert(const char *, prop_dictionary_t);
#endif /*_SYS_DEVMON_H_*/

64
sys/sys/dir.h Normal file
View file

@ -0,0 +1,64 @@
/* $NetBSD: dir.h,v 1.11 2005/12/11 12:25:20 christos Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1993
* The Regents of the University of California. 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 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.
*
* @(#)dir.h 8.2 (Berkeley) 1/4/94
*/
/*
* The information in this file should be obtained from <dirent.h>
* and is provided solely (and temporarily) for backward compatibility.
*/
#ifndef _SYS_DIR_H_
#define _SYS_DIR_H_
#ifdef _KERNEL
/* This file should only be used by old user-level code. */
#error "Please use <sys/dirent.h> instead"
#endif
#include <dirent.h>
/*
* Backwards compatibility.
*/
#define direct dirent
/*
* The DIRSIZ macro gives the minimum record length which will hold
* the directory entry. This requires the amount of space in struct direct
* without the d_name field, plus enough space for the name with a terminating
* null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
*/
#undef DIRSIZ
#define DIRSIZ(dp) \
((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
#endif /* !_SYS_DIR_H_ */

View file

@ -1,58 +1,115 @@
/* $NetBSD: dirent.h,v 1.28 2011/09/27 01:40:32 christos Exp $ */
/*-
* Copyright (c) 1989, 1993
* The Regents of the University of California. 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 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.
*
* @(#)dirent.h 8.3 (Berkeley) 8/10/94
*/
#ifndef _SYS_DIRENT_H_
#define _SYS_DIRENT_H_
#include <sys/cdefs.h>
#include <sys/featuretest.h>
#include <minix/dirent.h>
/*
* The dirent structure defines the format of directory entries returned by
* the getdents(2) system call.
*
* A directory entry has a struct dirent at the front of it, containing its
* inode number, the length of the entry, and the length of the name
* contained in the entry. These are followed by the name padded to
* _DIRENT_ALIGN() byte boundary with null bytes. All names are guaranteed
* NUL terminated. The maximum length of a name in a directory is MAXNAMLEN.
*/
struct dirent { /* Largest entry (8 slots) */
ino_t d_ino; /* I-node number */
off_t d_off; /* Offset in directory */
unsigned short d_reclen; /* Length of this record */
char d_name[1]; /* Null terminated name */
struct dirent {
ino_t d_fileno; /* file number of entry */
uint16_t d_reclen; /* length of this record */
uint16_t d_namlen; /* length of string in d_name */
uint8_t d_type; /* file type, see below */
#if defined(_NETBSD_SOURCE)
#define MAXNAMLEN 511 /* must be kept in sync with NAME_MAX */
char d_name[MAXNAMLEN + 1]; /* name must be no longer than this */
#else
char d_name[511 + 1]; /* name must be no longer than this */
#endif
};
#if defined(_NETBSD_SOURCE)
#define MAXNAMLEN 511
#define d_fileno d_ino
#endif
/*
* File types
*/
#define DT_UNKNOWN 0
#define DT_FIFO 1
#define DT_CHR 2
#define DT_DIR 4
#define DT_BLK 6
#define DT_REG 8
#define DT_LNK 10
#define DT_SOCK 12
#define DT_WHT 14
/*
* The _DIRENT_ALIGN macro returns the alignment of struct dirent. It
* is used to check for bogus pointers and to calculate in advance the
* memory required to store a dirent.
* Unfortunately Minix doesn't use any standard alignment in dirents
* at the moment, so, in order to calculate a safe dirent size, we add
* an arbitrary number of bytes to the structure (_DIRENT_PAD), and we
* set _DIRENT_ALIGN to zero to pass the pointers checks.
* Please, FIXME.
* Caution: the following macros are used by the ufs/ffs code on ffs's
* struct direct as well as the exposed struct dirent. The two
* structures are not the same, so it's important (until ufs is fixed,
* XXX) that the macro definitions remain type-polymorphic.
*/
#define _DIRENT_ALIGN(dp) 0
#define _DIRENT_PAD 64
/*
* The _DIRENT_ALIGN macro returns the alignment of struct dirent.
* struct direct and struct dirent12 used 4 byte alignment but
* struct dirent uses 8.
*/
#define _DIRENT_ALIGN(dp) (sizeof((dp)->d_fileno) - 1)
/*
* The _DIRENT_NAMEOFF macro returns the offset of the d_name field in
* struct dirent
*/
#if __GNUC_PREREQ__(4, 0)
#define _DIRENT_NAMEOFF(dp) __builtin_offsetof(__typeof__(*dp), d_name)
#else
#define _DIRENT_NAMEOFF(dp) \
((char *)(void *)&(dp)->d_name - (char *)(void *)dp)
#endif
/*
* The _DIRENT_RECLEN macro gives the minimum record length which will hold
* a name of size "namlen".
* a name of size "namlen". This requires the amount of space in struct dirent
* without the d_name field, plus enough space for the name with a terminating
* null byte (namlen+1), rounded up to a the appropriate byte boundary.
*/
#define _DIRENT_RECLEN(dp, namlen) \
((_DIRENT_NAMEOFF(dp) + (namlen) + 1 + _DIRENT_PAD + _DIRENT_ALIGN(dp)) & \
((_DIRENT_NAMEOFF(dp) + (namlen) + 1 + _DIRENT_ALIGN(dp)) & \
~_DIRENT_ALIGN(dp))
/*
* The _DIRENT_SIZE macro returns the minimum record length required for
* name name stored in the current record.
*/
#define _DIRENT_SIZE(dp) _DIRENT_RECLEN(dp, strlen(dp->d_name))
#define _DIRENT_SIZE(dp) _DIRENT_RECLEN(dp, (dp)->d_namlen)
/*
* The _DIRENT_NEXT macro advances to the next dirent record.
*/
@ -62,4 +119,11 @@ struct dirent { /* Largest entry (8 slots) */
*/
#define _DIRENT_MINSIZE(dp) _DIRENT_RECLEN(dp, 0)
/*
* Convert between stat structure types and directory types.
*/
#define IFTODT(mode) (((mode) & 0170000) >> 12)
#define DTTOIF(dirtype) ((dirtype) << 12)
#endif
#endif /* !_SYS_DIRENT_H_ */

83
sys/sys/dirhash.h Normal file
View file

@ -0,0 +1,83 @@
/* $NetBSD: dirhash.h,v 1.5 2009/09/27 21:50:48 reinoud Exp $ */
/*
* Copyright (c) 2008 Reinoud Zandijk
* 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 ``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.
*/
#ifndef _SYS_DIRHASH_H_
#define _SYS_DIRHASH_H_
#include <sys/queue.h>
#include <sys/dirent.h>
#ifndef DIRHASH_SIZE
#define DIRHASH_SIZE (1024*1024)
#endif
#define DIRHASH_HASHBITS 5
#define DIRHASH_HASHSIZE (1 << DIRHASH_HASHBITS)
#define DIRHASH_HASHMASK (DIRHASH_HASHSIZE - 1)
/* dirent's d_namlen is to avoid useless costly fid->dirent translations */
struct dirhash_entry {
uint32_t hashvalue;
uint64_t offset;
uint32_t d_namlen;
uint32_t entry_size;
LIST_ENTRY(dirhash_entry) next;
};
struct dirhash {
uint32_t flags;
uint32_t size; /* in bytes */
uint32_t refcnt;
LIST_HEAD(, dirhash_entry) entries[DIRHASH_HASHSIZE];
LIST_HEAD(, dirhash_entry) free_entries;
TAILQ_ENTRY(dirhash) next;
};
#define DIRH_PURGED 0x0001 /* dirhash has been purged */
#define DIRH_COMPLETE 0x0002 /* dirhash is complete */
#define DIRH_BROKEN 0x0004 /* dirhash is broken on readin */
#define DIRH_COMPACTABLE 0x0008 /* free space can be compacted */
#define DIRH_FLAGBITS "\10\1PURGED\2COMPLETE\3BROKEN\4COMPACTABLE"
void dirhash_init(void);
/* void dirhash_finish(void); */
void dirhash_purge(struct dirhash **);
void dirhash_purge_entries(struct dirhash *);
void dirhash_get(struct dirhash **);
void dirhash_put(struct dirhash *);
void dirhash_enter(struct dirhash *, struct dirent *, uint64_t,
uint32_t, int);
void dirhash_enter_freed(struct dirhash *, uint64_t, uint32_t);
void dirhash_remove(struct dirhash *, struct dirent *dirent,
uint64_t, uint32_t);
int dirhash_lookup(struct dirhash *, const char *, int,
struct dirhash_entry **);
int dirhash_lookup_freed(struct dirhash *, uint32_t,
struct dirhash_entry **);
#endif /* _SYS_DIRHASH_H_ */

231
sys/sys/disklabel_rdb.h Normal file
View file

@ -0,0 +1,231 @@
/* $NetBSD: disklabel_rdb.h,v 1.2 2010/06/19 08:45:25 kiyohara Exp $ */
/*
* Copyright (c) 1994 Christian E. Hopps
* 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 acknowledgement:
* This product includes software developed by Christian E. Hopps.
* 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.
*/
#ifndef _SYS_DISKLABEL_RDB_H_
#define _SYS_DISKLABEL_RDB_H_
/*
* describes ados Rigid Disk Blocks
* which are used to partition a drive
*/
#define RDBNULL ((u_long)0xffffffff)
/*
* you will find rdblock somewhere in [0, RDBMAXBLOCKS)
*/
#define RDB_MAXBLOCKS 16
struct rdblock {
u_long id; /* 'RDSK' */
u_long nsumlong; /* number of longs in check sum */
u_long chksum; /* simple additive with wrap checksum */
u_long hostid; /* scsi target of host */
u_long nbytes; /* size of disk blocks */
u_long flags;
u_long badbhead; /* linked list of badblocks */
u_long partbhead; /* linked list of partblocks */
u_long fsbhead; /* " " of fsblocks */
u_long driveinit;
u_long resv1[6]; /* RDBNULL */
u_long ncylinders; /* number of cylinders on drive */
u_long nsectors; /* number of sectors per track */
u_long nheads; /* number of tracks per cylinder */
u_long interleave;
u_long park; /* only used with st506 i.e. not */
u_long resv2[3];
u_long wprecomp; /* start cyl for write precomp */
u_long reducedwrite; /* start cyl for reduced write current */
u_long steprate; /* driver step rate in ?s */
u_long resv3[5];
u_long rdblowb; /* lowblock of range for rdb's */
u_long rdbhighb; /* high block of range for rdb's */
u_long lowcyl; /* low cylinder of partition area */
u_long highcyl; /* upper cylinder of partition area */
u_long secpercyl; /* number of sectors per cylinder */
u_long parkseconds; /* zero if no park needed */
u_long resv4[2];
char diskvendor[8]; /* inquiry stuff */
char diskproduct[16]; /* inquiry stuff */
char diskrevision[4]; /* inquiry stuff */
char contvendor[8]; /* inquiry stuff */
char contproduct[16]; /* inquiry stuff */
char contrevision[4]; /* inquiry stuff */
#if never_use_secsize
u_long resv5[0];
#endif
};
#define RDBF_LAST 0x1 /* last drive available */
#define RDBF_LASTLUN 0x2 /* last LUN available */
#define RDBF_LASTUNIT 0x4 /* last target available */
#define RDBF_NORESELECT 0x8 /* do not use reselect */
#define RDBF_DISKID 0x10 /* disk id is valid ?? */
#define RDBF_CTRLID 0x20 /* ctrl id is valid ?? */
#define RDBF_SYNC 0x40 /* drive supports SCSI synchronous mode */
struct ados_environ {
u_long tabsize; /* 0: environ table size */
u_long sizeblock; /* 1: n long words in a block */
u_long secorg; /* 2: not used must be zero */
u_long numheads; /* 3: number of surfaces */
u_long secperblk; /* 4: must be 1 */
u_long secpertrk; /* 5: blocks per track */
u_long resvblocks; /* 6: reserved blocks at start */
u_long prefac; /* 7: must be 0 */
u_long interleave; /* 8: normally 1 */
u_long lowcyl; /* 9: low cylinder of partition */
u_long highcyl; /* 10: upper cylinder of partition */
u_long numbufs; /* 11: ados: number of buffers */
u_long membuftype; /* 12: ados: type of bufmem */
u_long maxtrans; /* 13: maxtrans the ctrlr supports */
u_long mask; /* 14: mask for valid address */
u_long bootpri; /* 15: boot priority for autoboot */
u_long dostype; /* 16: filesystem type */
u_long baud; /* 17: serial handler baud rate */
u_long control; /* 18: control word for fs */
u_long bootblocks; /* 19: blocks containing boot code */
u_long fsize; /* 20: file system block size */
u_long frag; /* 21: allowable frags per block */
u_long cpg; /* 22: cylinders per group */
};
struct partblock {
u_long id; /* 'PART' */
u_long nsumlong; /* number of longs in check sum */
u_long chksum; /* simple additive with wrap checksum */
u_long hostid; /* scsi target of host */
u_long next; /* next in chain */
u_long flags; /* see below */
u_long resv1[3];
u_char partname[32]; /* (BCPL) part name (may not be unique) */
u_long resv2[15];
struct ados_environ e;
#if never_use_secsize
u_long extra[9]; /* 8 for extra added to environ */
#endif
};
#define PBF_BOOTABLE 0x1 /* partition is bootable */
#define PBF_NOMOUNT 0x2 /* partition should be mounted */
struct badblock {
u_long id; /* 'BADB' */
u_long nsumlong; /* number of longs in check sum */
u_long chksum; /* simple additive with wrap checksum */
u_long hostid; /* scsi target of host */
u_long next; /* next in chain */
u_long resv;
struct badblockent {
u_long badblock;
u_long goodblock;
} badtab[0]; /* 61 for secsize == 512 */
};
struct fsblock {
u_long id; /* 'FSHD' */
u_long nsumlong; /* number of longs in check sum */
u_long chksum; /* simple additive with wrap checksum */
u_long hostid; /* scsi target of host */
u_long next; /* next in chain */
u_long flags;
u_long resv1[2];
u_long dostype; /* this is a file system for this type */
u_long version; /* version of this fs */
u_long patchflags; /* describes which functions to replace */
u_long type; /* zero */
u_long task; /* zero */
u_long lock; /* zero */
u_long handler; /* zero */
u_long stacksize; /* to use when loading handler */
u_long priority; /* to run the fs at. */
u_long startup; /* zero */
u_long lsegblocks; /* linked list of lsegblocks of fs code */
u_long globalvec; /* bcpl vector not used mostly */
#if never_use_secsize
u_long resv2[44];
#endif
};
struct lsegblock {
u_long id; /* 'LSEG' */
u_long nsumlong; /* number of longs in check sum */
u_long chksum; /* simple additive with wrap checksum */
u_long hostid; /* scsi target of host */
u_long next; /* next in chain */
u_long loaddata[0]; /* load segment data, 123 for secsize == 512 */
};
#define RDBLOCK_ID 0x5244534b /* 'RDSK' */
#define PARTBLOCK_ID 0x50415254 /* 'PART' */
#define BADBLOCK_ID 0x42414442 /* 'BADB' */
#define FSBLOCK_ID 0x46534844 /* 'FSHD' */
#define LSEGBLOCK_ID 0x4c534547 /* 'LSEG' */
/*
* Dos types for identifying file systems
* bsd file systems will be 'N','B',x,y where y is the fstype found in
* disklabel.h (for DOST_DOS it will be the version number)
*/
#define DOST_XXXBSD 0x42534400 /* Old type back compat*/
#define DOST_NBR 0x4e425200 /* 'NBRx' NetBSD root partition */
#define DOST_NBS 0x4e425300 /* 'NBS0' NetBSD swap partition */
#define DOST_NBU 0x4e425500 /* 'NBUx' NetBSD user partition */
#define DOST_DOS 0x444f5300 /* 'DOSx' AmigaDos partition */
#define DOST_AMIX 0x554e4900 /* 'UNIx' AmigaDos partition */
#define DOST_MUFS 0x6d754600 /* 'muFx' AmigaDos partition (muFS) */
#define DOST_EXT2 0x4c4e5800 /* 'LNX0' Linux fs partition (ext2fs) */
#define DOST_LNXSWP 0x53575000 /* 'SWP0' Linux swap partition */
#define DOST_RAID 0x52414900 /* 'RAID' Raidframe partition */
#define DOST_MSD 0x4d534400 /* 'MSDx' MSDOS partition */
#define DOST_SFS 0x53465300 /* 'SFSx' Smart fs partition */
struct adostype {
u_char archtype; /* see ADT_xxx below */
u_char fstype; /* byte 3 from amiga dostype */
};
/* archtypes */
#define ADT_UNKNOWN 0
#define ADT_AMIGADOS 1
#define ADT_NETBSDROOT 2
#define ADT_NETBSDSWAP 3
#define ADT_NETBSDUSER 4
#define ADT_AMIX 5
#define ADT_EXT2 6
#define ADT_RAID 7
#define ADT_MSD 8
#define ADT_SFS 9
#define ISFSARCH_NETBSD(adt) \
((adt).archtype >= ADT_NETBSDROOT && (adt).archtype <= ADT_NETBSDUSER)
#endif /* _SYS_DISKLABEL_RDB_H_ */

49
sys/sys/dkstat.h Normal file
View file

@ -0,0 +1,49 @@
/* $NetBSD: dkstat.h,v 1.17 2005/12/26 18:41:36 perry Exp $ */
/*-
* Copyright (c) 1990, 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.
* 3. 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.
*
* @(#)dkstat.h 8.2 (Berkeley) 1/21/94
*/
#ifndef _SYS_DKSTAT_H_
#define _SYS_DKSTAT_H_
#ifdef _KERNEL
extern uint64_t tk_cancc;
extern uint64_t tk_nin;
extern uint64_t tk_nout;
extern uint64_t tk_rawcc;
#endif
#endif /* _SYS_DKSTAT_H_ */

103
sys/sys/domain.h Normal file
View file

@ -0,0 +1,103 @@
/* $NetBSD: domain.h,v 1.31 2011/06/26 16:43:12 christos Exp $ */
/*
* Copyright (c) 1982, 1986, 1993
* The Regents of the University of California. 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 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.
*
* @(#)domain.h 8.1 (Berkeley) 6/2/93
*/
#ifndef _SYS_DOMAIN_H_
#define _SYS_DOMAIN_H_
/*
* Structure per communications domain.
*/
#include <sys/mbuf.h>
#include <sys/socket.h>
#include <net/route.h>
/*
* Forward structure declarations for function prototypes [sic].
*/
struct lwp;
struct mbuf;
struct ifnet;
struct ifqueue;
struct sockaddr;
LIST_HEAD(dom_rtlist, route);
struct domain {
int dom_family; /* AF_xxx */
const char *dom_name;
void (*dom_init) /* initialize domain data structures */
(void);
int (*dom_externalize) /* externalize access rights */
(struct mbuf *, struct lwp *, int);
void (*dom_dispose) /* dispose of internalized rights */
(struct mbuf *);
const struct protosw *dom_protosw, *dom_protoswNPROTOSW;
int (*dom_rtattach) /* initialize routing table */
(rtbl_t **, int);
int dom_rtoffset; /* an arg to rtattach, in bits */
int dom_maxrtkey; /* for routing layer */
void *(*dom_ifattach) /* attach af-dependent data on ifnet */
(struct ifnet *);
void (*dom_ifdetach) /* detach af-dependent data on ifnet */
(struct ifnet *, void *);
const void *(*dom_sockaddr_const_addr)(const struct sockaddr *,
socklen_t *);
void *(*dom_sockaddr_addr)(struct sockaddr *, socklen_t *);
int (*dom_sockaddr_cmp)(const struct sockaddr *,
const struct sockaddr *);
struct sockaddr *(*dom_sockaddr_externalize)(struct sockaddr *,
socklen_t,
const struct sockaddr *);
const struct sockaddr *dom_sa_any;
struct ifqueue *dom_ifqueues[2]; /* ifqueue for domain */
STAILQ_ENTRY(domain) dom_link;
struct mowner dom_mowner;
uint_fast8_t dom_sa_cmpofs;
uint_fast8_t dom_sa_cmplen;
struct dom_rtlist dom_rtcache;
};
STAILQ_HEAD(domainhead,domain);
#ifdef _KERNEL
#define DOMAIN_DEFINE(name) \
extern struct domain name; \
__link_set_add_data(domains, name)
#define DOMAIN_FOREACH(dom) STAILQ_FOREACH(dom, &domains, dom_link)
extern struct domainhead domains;
void domain_attach(struct domain *);
void domaininit(bool);
#endif
#endif /* !_SYS_DOMAIN_H_ */

130
sys/sys/drvctlio.h Normal file
View file

@ -0,0 +1,130 @@
/* $NetBSD: drvctlio.h,v 1.7 2008/05/31 13:24:57 freza Exp $ */
/*-
* Copyright (c) 2006 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe.
*
* 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.
*/
/* This interface is experimental and may change. */
#ifndef _SYS_DRVCTLIO_H_
#define _SYS_DRVCTLIO_H_
#include <prop/proplib.h>
#include <sys/ioccom.h>
#define DRVCTLDEV "/dev/drvctl"
struct devdetachargs {
char devname[16];
};
struct devlistargs {
char l_devname[16];
char (*l_childname)[16];
size_t l_children;
};
enum devpmflags {
DEVPM_F_SUBTREE = 0x1
};
struct devpmargs {
char devname[16];
uint32_t flags;
};
struct devrescanargs {
char busname[16];
char ifattr[16];
unsigned int numlocators;
int *locators;
};
#define DRVDETACHDEV _IOW('D', 123, struct devdetachargs)
#define DRVRESCANBUS _IOW('D', 124, struct devrescanargs)
#define DRVCTLCOMMAND _IOWR('D', 125, struct plistref)
#define DRVRESUMEDEV _IOW('D', 126, struct devpmargs)
#define DRVLISTDEV _IOWR('D', 127, struct devlistargs)
#define DRVGETEVENT _IOR('D', 128, struct plistref)
#define DRVSUSPENDDEV _IOW('D', 129, struct devpmargs)
/*
* DRVCTLCOMMAND documentation
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* Generic ioctl that takes a dictionary as an argument (specifies the
* command and arguments) and returns a dictionary with the results.
*
* Command arguments are structured like so:
*
* <dict>
* <key>drvctl-command</key>
* <string>...</string>
* <!-- optional arguments -->
* <key>drvctl-arguments</key>
* <dict>
* <!-- arguments vary with command -->
* </dict>
* </dict>
*
* Results are returned like so:
*
* <dict>
* <key>drvctl-error</key>
* <!-- 0 == success, otherwise an errno value -->
* <integer>...</integer>
* <!-- optional additional error message -->
* <key>drvctl-error-message</key>
* <string>...</string>
* <!-- optional results dictionary -->
* <key>drvctl-result-data</key>
* <dict>
* <!-- results vary with command -->
* </dict>
* </dict>
*
*
* Commands recognized by DRVCTLCOMMAND
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* get-properties
*
* Arguments:
*
* <dict>
* <key>device-name</key>
* <string>...</string>
* </dict>
*
* Results:
* <dict>
* <!-- contents of device's properties dictionary -->
* </dict>
*/
#endif /* _SYS_DRVCTLIO_H_ */

245
sys/sys/dtrace_bsd.h Normal file
View file

@ -0,0 +1,245 @@
/* $NetBSD: dtrace_bsd.h,v 1.5 2012/01/30 23:31:27 matt Exp $ */
/*-
* Copyright (c) 2007-2008 John Birrell (jb@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: src/sys/sys/dtrace_bsd.h,v 1.3.2.1 2009/08/03 08:13:06 kensmith Exp $
*
* This file contains BSD shims for Sun's DTrace code.
*/
#ifndef _SYS_DTRACE_BSD_H
#define _SYS_DTRACE_BSD_H
#if defined(_KERNEL_OPT)
#include "opt_dtrace.h"
#endif
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/kmem.h>
#include <sys/proc.h>
/* Forward definitions: */
struct mbuf;
struct trapframe;
struct lwp;
struct vattr;
struct vnode;
struct ucred;
/*
* Cyclic clock function type definition used to hook the cyclic
* subsystem into the appropriate timer interrupt.
*/
typedef void (*cyclic_clock_func_t)(struct trapframe *);
/*
* These external variables are actually machine-dependent, so
* they might not actually exist.
*
* Defining them here avoids a proliferation of header files.
*/
extern cyclic_clock_func_t lapic_cyclic_clock_func[];
/*
* The dtrace module handles traps that occur during a DTrace probe.
* This type definition is used in the trap handler to provide a
* hook for the dtrace module to register it's handler with.
*/
typedef int (*dtrace_trap_func_t)(struct trapframe *, u_int);
int dtrace_trap(struct trapframe *, u_int);
extern dtrace_trap_func_t dtrace_trap_func;
/* Used by the machine dependent trap() code. */
typedef int (*dtrace_invop_func_t)(uintptr_t, uintptr_t *, uintptr_t);
typedef void (*dtrace_doubletrap_func_t)(void);
/* Global variables in trap.c */
extern dtrace_invop_func_t dtrace_invop_func;
extern dtrace_doubletrap_func_t dtrace_doubletrap_func;
/* Virtual time hook function type. */
typedef void (*dtrace_vtime_switch_func_t)(struct lwp *);
extern int dtrace_vtime_active;
extern dtrace_vtime_switch_func_t dtrace_vtime_switch_func;
/* The fasttrap module hooks into the fork, exit and exit. */
typedef void (*dtrace_fork_func_t)(struct proc *, struct proc *);
typedef void (*dtrace_execexit_func_t)(struct proc *);
/* Global variable in kern_fork.c */
extern dtrace_fork_func_t dtrace_fasttrap_fork;
/* Global variable in kern_exec.c */
extern dtrace_execexit_func_t dtrace_fasttrap_exec;
/* Global variable in kern_exit.c */
extern dtrace_execexit_func_t dtrace_fasttrap_exit;
/* The dtmalloc provider hooks into malloc. */
typedef void (*dtrace_malloc_probe_func_t)(u_int32_t, uintptr_t arg0,
uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, uintptr_t arg4);
extern dtrace_malloc_probe_func_t dtrace_malloc_probe;
/* dtnfsclient NFSv3 access cache provider hooks. */
typedef void (*dtrace_nfsclient_accesscache_flush_probe_func_t)(uint32_t,
struct vnode *);
extern dtrace_nfsclient_accesscache_flush_probe_func_t
dtrace_nfsclient_accesscache_flush_done_probe;
typedef void (*dtrace_nfsclient_accesscache_get_probe_func_t)(uint32_t,
struct vnode *, uid_t, uint32_t);
extern dtrace_nfsclient_accesscache_get_probe_func_t
dtrace_nfsclient_accesscache_get_hit_probe,
dtrace_nfsclient_accesscache_get_miss_probe;
typedef void (*dtrace_nfsclient_accesscache_load_probe_func_t)(uint32_t,
struct vnode *, uid_t, uint32_t, int);
extern dtrace_nfsclient_accesscache_load_probe_func_t
dtrace_nfsclient_accesscache_load_done_probe;
/* dtnfsclient NFSv[23] attribute cache provider hooks. */
typedef void (*dtrace_nfsclient_attrcache_flush_probe_func_t)(uint32_t,
struct vnode *);
extern dtrace_nfsclient_attrcache_flush_probe_func_t
dtrace_nfsclient_attrcache_flush_done_probe;
typedef void (*dtrace_nfsclient_attrcache_get_hit_probe_func_t)(uint32_t,
struct vnode *, struct vattr *);
extern dtrace_nfsclient_attrcache_get_hit_probe_func_t
dtrace_nfsclient_attrcache_get_hit_probe;
typedef void (*dtrace_nfsclient_attrcache_get_miss_probe_func_t)(uint32_t,
struct vnode *);
extern dtrace_nfsclient_attrcache_get_miss_probe_func_t
dtrace_nfsclient_attrcache_get_miss_probe;
typedef void (*dtrace_nfsclient_attrcache_load_probe_func_t)(uint32_t,
struct vnode *, struct vattr *, int);
extern dtrace_nfsclient_attrcache_load_probe_func_t
dtrace_nfsclient_attrcache_load_done_probe;
/* dtnfsclient NFSv[23] RPC provider hooks. */
typedef void (*dtrace_nfsclient_nfs23_start_probe_func_t)(uint32_t,
struct vnode *, struct mbuf *, struct ucred *, int);
extern dtrace_nfsclient_nfs23_start_probe_func_t
dtrace_nfsclient_nfs23_start_probe;
typedef void (*dtrace_nfsclient_nfs23_done_probe_func_t)(uint32_t,
struct vnode *, struct mbuf *, struct ucred *, int, int);
extern dtrace_nfsclient_nfs23_done_probe_func_t
dtrace_nfsclient_nfs23_done_probe;
/*
* OpenSolaris compatible time functions returning nanoseconds.
* On OpenSolaris these return hrtime_t which we define as uint64_t.
*/
uint64_t dtrace_gethrtime(void);
uint64_t dtrace_gethrestime(void);
/* sizes based on DTrace structure requirements */
#define KDTRACE_PROC_SIZE 64
#define KDTRACE_PROC_ZERO 8
#define KDTRACE_THREAD_SIZE 256
#define KDTRACE_THREAD_ZERO 64
/*
* Functions for managing the opaque DTrace memory areas for
* processes and lwps.
*/
static inline size_t kdtrace_proc_size(void);
static inline void kdtrace_proc_ctor(void *, struct proc *);
static inline void kdtrace_proc_dtor(void *, struct proc *);
static inline size_t kdtrace_thread_size(void);
static inline void kdtrace_thread_ctor(void *, struct lwp *);
static inline void kdtrace_thread_dtor(void *, struct lwp *);
/* Return the DTrace process data size compiled in the kernel hooks. */
static inline size_t
kdtrace_proc_size(void)
{
return KDTRACE_PROC_SIZE;
}
/* Return the DTrace thread data size compiled in the kernel hooks. */
static inline size_t
kdtrace_thread_size(void)
{
return KDTRACE_THREAD_SIZE;
}
static inline void
kdtrace_proc_ctor(void *arg, struct proc *p)
{
#ifdef KDTRACE_HOOKS
p->p_dtrace = kmem_zalloc(KDTRACE_PROC_SIZE, KM_SLEEP);
#endif
}
static inline void
kdtrace_proc_dtor(void *arg, struct proc *p)
{
#ifdef KDTRACE_HOOKS
if (p->p_dtrace != NULL) {
kmem_free(p->p_dtrace, KDTRACE_PROC_SIZE);
p->p_dtrace = NULL;
}
#endif
}
static inline void
kdtrace_thread_ctor(void *arg, struct lwp *l)
{
#ifdef KDTRACE_HOOKS
l->l_dtrace = kmem_zalloc(KDTRACE_THREAD_SIZE, KM_SLEEP);
#endif
}
static inline void
kdtrace_thread_dtor(void *arg, struct lwp *l)
{
#ifdef KDTRACE_HOOKS
if (l->l_dtrace != NULL) {
kmem_free(l->l_dtrace, KDTRACE_THREAD_SIZE);
l->l_dtrace = NULL;
}
#endif
}
#endif /* _SYS_DTRACE_BSD_H */

206
sys/sys/dvdio.h Normal file
View file

@ -0,0 +1,206 @@
/* $NetBSD: dvdio.h,v 1.8 2005/12/26 18:41:36 perry Exp $ */
#ifndef _SYS_DVDIO_H_
#define _SYS_DVDIO_H_
#include <sys/types.h>
#include <sys/ioccom.h>
/* DVD-ROM Specific ioctls */
#define DVD_READ_STRUCT _IOWR('d', 0, dvd_struct)
#define DVD_WRITE_STRUCT _IOWR('d', 1, dvd_struct)
#define DVD_AUTH _IOWR('d', 2, dvd_authinfo)
#define GPCMD_READ_DVD_STRUCTURE 0xad
#define GPCMD_SEND_DVD_STRUCTURE 0xad
#define GPCMD_REPORT_KEY 0xa4
#define GPCMD_SEND_KEY 0xa3
/* DVD struct types */
#define DVD_STRUCT_PHYSICAL 0x00
#define DVD_STRUCT_COPYRIGHT 0x01
#define DVD_STRUCT_DISCKEY 0x02
#define DVD_STRUCT_BCA 0x03
#define DVD_STRUCT_MANUFACT 0x04
struct dvd_layer {
uint8_t book_version : 4;
uint8_t book_type : 4;
uint8_t min_rate : 4;
uint8_t disc_size : 4;
uint8_t layer_type : 4;
uint8_t track_path : 1;
uint8_t nlayers : 2;
uint8_t track_density : 4;
uint8_t linear_density : 4;
uint8_t bca : 1;
uint32_t start_sector;
uint32_t end_sector;
uint32_t end_sector_l0;
};
struct dvd_physical {
uint8_t type;
uint8_t layer_num;
struct dvd_layer layer[4];
};
struct dvd_copyright {
uint8_t type;
uint8_t layer_num;
uint8_t cpst;
uint8_t rmi;
};
struct dvd_disckey {
uint8_t type;
unsigned agid : 2;
uint8_t value[2048];
};
struct dvd_bca {
uint8_t type;
int len;
uint8_t value[188];
};
struct dvd_manufact {
uint8_t type;
uint8_t layer_num;
int len;
uint8_t value[2048];
};
typedef union {
uint8_t type;
struct dvd_physical physical;
struct dvd_copyright copyright;
struct dvd_disckey disckey;
struct dvd_bca bca;
struct dvd_manufact manufact;
} dvd_struct;
/*
* DVD authentication ioctl
*/
/* Authentication states */
#define DVD_LU_SEND_AGID 0
#define DVD_HOST_SEND_CHALLENGE 1
#define DVD_LU_SEND_KEY1 2
#define DVD_LU_SEND_CHALLENGE 3
#define DVD_HOST_SEND_KEY2 4
/* Termination states */
#define DVD_AUTH_ESTABLISHED 5
#define DVD_AUTH_FAILURE 6
/* Other functions */
#define DVD_LU_SEND_TITLE_KEY 7
#define DVD_LU_SEND_ASF 8
#define DVD_INVALIDATE_AGID 9
#define DVD_LU_SEND_RPC_STATE 10
#define DVD_HOST_SEND_RPC_STATE 11
/* State data */
typedef uint8_t dvd_key[5]; /* 40-bit value, MSB is first elem. */
typedef uint8_t dvd_challenge[10]; /* 80-bit value, MSB is first elem. */
struct dvd_lu_send_agid {
uint8_t type;
unsigned agid : 2;
};
struct dvd_host_send_challenge {
uint8_t type;
unsigned agid : 2;
dvd_challenge chal;
};
struct dvd_send_key {
uint8_t type;
unsigned agid : 2;
dvd_key key;
};
struct dvd_lu_send_challenge {
uint8_t type;
unsigned agid : 2;
dvd_challenge chal;
};
#define DVD_CPM_NO_COPYRIGHT 0
#define DVD_CPM_COPYRIGHTED 1
#define DVD_CP_SEC_NONE 0
#define DVD_CP_SEC_EXIST 1
#define DVD_CGMS_UNRESTRICTED 0
#define DVD_CGMS_SINGLE 2
#define DVD_CGMS_RESTRICTED 3
struct dvd_lu_send_title_key {
uint8_t type;
unsigned agid : 2;
dvd_key title_key;
int lba;
unsigned cpm : 1;
unsigned cp_sec : 1;
unsigned cgms : 2;
};
struct dvd_lu_send_asf {
uint8_t type;
unsigned agid : 2;
unsigned asf : 1;
};
struct dvd_host_send_rpcstate {
uint8_t type;
uint8_t pdrc;
};
struct dvd_lu_send_rpcstate {
uint8_t type : 2;
uint8_t vra : 3;
uint8_t ucca : 3;
uint8_t region_mask;
uint8_t rpc_scheme;
};
typedef union {
uint8_t type;
struct dvd_lu_send_agid lsa;
struct dvd_host_send_challenge hsc;
struct dvd_send_key lsk;
struct dvd_lu_send_challenge lsc;
struct dvd_send_key hsk;
struct dvd_lu_send_title_key lstk;
struct dvd_lu_send_asf lsasf;
struct dvd_host_send_rpcstate hrpcs;
struct dvd_lu_send_rpcstate lrpcs;
} dvd_authinfo;
typedef struct {
uint16_t report_key_length;
uint8_t reserved1[2];
uint8_t ucca : 3;
uint8_t vra : 3;
uint8_t type_code : 2;
uint8_t region_mask;
uint8_t rpc_scheme;
uint8_t reserved2;
} dvd_rpc_state_t;
#endif /* _SYS_DVDIO_H_ */

Some files were not shown because too many files have changed in this diff Show more