#ifndef _SYS_DEVICE_H_
#define _SYS_DEVICE_H_
#ifdef _KERNEL
#ifndef _SYS_TYPES_H_
#include <sys/types.h>
#endif
#ifndef _SYS_TREE_H_
#include <sys/tree.h>
#endif
#ifndef _SYS_SYSLINK_RPC_H_
#include <sys/syslink_rpc.h>
#endif
struct cdev;
struct ucred;
struct devfs_bitmap;
struct vm_page;
struct vm_map_backing;
struct vnode;
struct dev_generic_args {
struct syslink_desc *a_desc;
struct cdev *a_dev;
};
typedef struct dev_generic_args dev_default_args;
struct dev_open_args {
struct dev_generic_args a_head;
int a_oflags;
int a_devtype;
struct ucred *a_cred;
struct file **a_fpp;
};
struct dev_close_args {
struct dev_generic_args a_head;
int a_fflag;
int a_devtype;
struct file *a_fp;
};
struct dev_read_args {
struct dev_generic_args a_head;
struct uio *a_uio;
int a_ioflag;
struct file *a_fp;
};
struct dev_write_args {
struct dev_generic_args a_head;
struct uio *a_uio;
int a_ioflag;
struct file *a_fp;
};
struct dev_ioctl_args {
struct dev_generic_args a_head;
u_long a_cmd;
caddr_t a_data;
int a_fflag;
struct ucred *a_cred;
struct sysmsg *a_sysmsg;
struct file *a_fp;
};
struct dev_mmap_args {
struct dev_generic_args a_head;
vm_offset_t a_offset;
int a_nprot;
int64_t a_result;
struct file *a_fp;
};
struct dev_mmap_single_args {
struct dev_generic_args a_head;
vm_ooffset_t *a_offset;
vm_size_t a_size;
struct vm_object **a_object;
int a_nprot;
struct file *a_fp;
};
struct dev_strategy_args {
struct dev_generic_args a_head;
struct bio *a_bio;
};
struct dev_dump_args {
struct dev_generic_args a_head;
u_int64_t a_count;
u_int64_t a_blkno;
u_int a_secsize;
void *a_virtual;
vm_offset_t a_physical;
off_t a_offset;
size_t a_length;
};
struct dev_psize_args {
struct dev_generic_args a_head;
int64_t a_result;
};
struct dev_kqfilter_args {
struct dev_generic_args a_head;
struct knote *a_kn;
int a_result;
struct file *a_fp;
};
struct dev_clone_args {
struct dev_generic_args a_head;
struct cdev *a_dev;
const char *a_name;
size_t a_namelen;
struct ucred *a_cred;
int a_mode;
};
struct dev_revoke_args {
struct dev_generic_args a_head;
};
typedef int d_default_t (struct dev_generic_args *ap);
typedef int d_open_t (struct dev_open_args *ap);
typedef int d_close_t (struct dev_close_args *ap);
typedef int d_read_t (struct dev_read_args *ap);
typedef int d_write_t (struct dev_write_args *ap);
typedef int d_ioctl_t (struct dev_ioctl_args *ap);
typedef int d_mmap_t (struct dev_mmap_args *ap);
typedef int d_mmap_single_t (struct dev_mmap_single_args *ap);
typedef int d_strategy_t (struct dev_strategy_args *ap);
typedef int d_dump_t (struct dev_dump_args *ap);
typedef int d_psize_t (struct dev_psize_args *ap);
typedef int d_kqfilter_t (struct dev_kqfilter_args *ap);
typedef int d_clone_t (struct dev_clone_args *ap);
typedef int d_revoke_t (struct dev_revoke_args *ap);
struct dev_ops {
struct {
const char *name;
int maj;
u_int flags;
void *data;
int refs;
int id;
} head;
#define dev_ops_first_field d_default
d_default_t *d_default;
d_open_t *d_open;
d_close_t *d_close;
d_read_t *d_read;
d_write_t *d_write;
d_ioctl_t *d_ioctl;
d_mmap_t *d_mmap;
d_mmap_single_t *d_mmap_single;
d_strategy_t *d_strategy;
d_dump_t *d_dump;
d_psize_t *d_psize;
d_kqfilter_t *d_kqfilter;
d_clone_t *d_clone;
d_revoke_t *d_revoke;
int (*d_uksmap)(struct vm_map_backing *ba, int op,
struct cdev *dev, struct vm_page *fake);
#define dev_ops_last_field d_uksmap
};
#endif
#define D_TAPE 0x0001
#define D_DISK 0x0002
#define D_TTY 0x0004
#define D_MEM 0x0008
#define D_TYPEMASK 0xffff
#define D_SEEKABLE (D_TAPE | D_DISK | D_MEM)
#ifdef _KERNEL
#define D_MEMDISK 0x00010000
#define D_UNUSED17 0x00020000
#define D_CANFREE 0x00040000
#define D_TRACKCLOSE 0x00080000
#define D_MASTER 0x00100000
#define D_NOEMERGPGR 0x00200000
#define D_MPSAFE 0x00400000
#define D_KVABIO 0x00800000
#define D_QUICK 0x01000000
#endif
#if 0
union dev_args_union {
struct dev_generic_args du_head;
struct dev_open_args du_open;
struct dev_close_args du_close;
struct dev_read_args du_read;
struct dev_write_args du_write;
struct dev_ioctl_args du_ioctl;
struct dev_mmap_args du_mmap;
struct dev_strategy_args du_strategy;
struct dev_dump_args du_dump;
struct dev_psize_args du_psize;
struct dev_kqfilter_args du_kqfilter;
struct dev_clone_args du_clone;
};
#endif
#ifdef _KERNEL
struct dev_ops_link {
struct dev_ops_link *next;
u_int mask;
u_int match;
struct dev_ops *ops;
};
struct dev_ops_maj {
RB_ENTRY(dev_ops_maj) rbnode;
struct dev_ops_link *link;
int maj;
};
RB_HEAD(dev_ops_rb_tree, dev_ops_maj);
RB_PROTOTYPE2(dev_ops_rb_tree, dev_ops_maj, rbnode, rb_dev_ops_compare, int);
#endif
#ifdef _KERNEL
extern struct dev_ops dead_dev_ops;
struct disk;
struct sysmsg;
int dev_dopen(cdev_t dev, int oflags, int devtype, struct ucred *cred,
struct file **fpp, struct vnode *vp);
int dev_dclose(cdev_t dev, int fflag, int devtype, struct file *fp);
void dev_dstrategy(cdev_t dev, struct bio *bio);
void dev_dstrategy_chain(cdev_t dev, struct bio *bio);
int dev_dioctl(cdev_t dev, u_long cmd, caddr_t data,
int fflag, struct ucred *cred, struct sysmsg *msg, struct file *fp);
int dev_ddump(cdev_t dev, void *virtual, vm_offset_t physical, off_t offset,
size_t length);
int64_t dev_dpsize(cdev_t dev);
int dev_dread(cdev_t dev, struct uio *uio, int ioflag, struct file *fp);
int dev_dwrite(cdev_t dev, struct uio *uio, int ioflag, struct file *fp);
int dev_dkqfilter(cdev_t dev, struct knote *kn, struct file *fp);
int64_t dev_dmmap(cdev_t dev, vm_offset_t offset, int nprot, struct file *fp);
int dev_dmmap_single(cdev_t dev, vm_ooffset_t *offset, vm_size_t size,
struct vm_object **object, int nprot, struct file *fp);
int dev_dclone(cdev_t dev);
int dev_drevoke(cdev_t dev);
int dev_drefs(cdev_t dev);
const char *dev_dname(cdev_t dev);
int dev_dmaj(cdev_t dev);
int dev_dflags(cdev_t dev);
int dev_doperate(struct dev_generic_args *ap);
int dev_doperate_ops(struct dev_ops *, struct dev_generic_args *ap);
d_open_t nullopen;
d_close_t nullclose;
extern struct syslink_desc dev_default_desc;
extern struct syslink_desc dev_open_desc;
extern struct syslink_desc dev_close_desc;
extern struct syslink_desc dev_read_desc;
extern struct syslink_desc dev_write_desc;
extern struct syslink_desc dev_ioctl_desc;
extern struct syslink_desc dev_dump_desc;
extern struct syslink_desc dev_psize_desc;
extern struct syslink_desc dev_mmap_desc;
extern struct syslink_desc dev_mmap_single_desc;
extern struct syslink_desc dev_strategy_desc;
extern struct syslink_desc dev_kqfilter_desc;
extern struct syslink_desc dev_clone_desc;
void compile_dev_ops(struct dev_ops *);
int dev_ops_remove_all(struct dev_ops *ops);
int dev_ops_remove_minor(struct dev_ops *ops, int minor);
struct dev_ops *dev_ops_intercept(cdev_t, struct dev_ops *);
void dev_ops_restore(cdev_t, struct dev_ops *);
#define MAKEDEV_MINNBUF 14
char *makedev_unit_b32(char *nbuf, uintmax_t num);
cdev_t make_dev(struct dev_ops *ops, int minor, uid_t uid, gid_t gid,
int perms, const char *fmt, ...) __printflike(6, 7);
cdev_t make_dev_covering(struct dev_ops *ops, struct dev_ops *bops, int minor,
uid_t uid, gid_t gid, int perms, const char *fmt, ...) __printflike(7, 8);
cdev_t make_only_dev(struct dev_ops *ops, int minor, uid_t uid, gid_t gid,
int perms, const char *fmt, ...) __printflike(6, 7);
cdev_t make_only_dev_covering(struct dev_ops *ops, struct dev_ops *bops, int minor,
uid_t uid, gid_t gid, int perms, const char *fmt, ...) __printflike(7,8);
cdev_t make_only_devfs_dev(struct dev_ops *ops, int minor, uid_t uid, gid_t gid,
int perms, const char *fmt, ...) __printflike(6, 7);
void destroy_only_dev(cdev_t dev);
int make_dev_alias(cdev_t target, const char *fmt, ...) __printflike(2, 3);
int destroy_dev_alias(cdev_t target, const char *fmt, ...) __printflike(2, 3);
cdev_t make_autoclone_dev(struct dev_ops *ops, struct devfs_bitmap *bitmap,
d_clone_t *nhandler, uid_t uid, gid_t gid, int perms,
const char *fmt, ...) __printflike(7, 8);
void destroy_autoclone_dev(cdev_t dev, struct devfs_bitmap *bitmap);
void sync_devs(void);
#endif
#endif