scoutos / prex-0.9.0 / include / sys / device.h @ 03e9c04a
History | View | Annotate | Download (3.35 KB)
1 |
/*
|
---|---|
2 |
* Copyright (c) 2008, Kohsuke Ohtani
|
3 |
* All rights reserved.
|
4 |
*
|
5 |
* Redistribution and use in source and binary forms, with or without
|
6 |
* modification, are permitted provided that the following conditions
|
7 |
* are met:
|
8 |
* 1. Redistributions of source code must retain the above copyright
|
9 |
* notice, this list of conditions and the following disclaimer.
|
10 |
* 2. Redistributions in binary form must reproduce the above copyright
|
11 |
* notice, this list of conditions and the following disclaimer in the
|
12 |
* documentation and/or other materials provided with the distribution.
|
13 |
* 3. Neither the name of the author nor the names of any co-contributors
|
14 |
* may be used to endorse or promote products derived from this software
|
15 |
* without specific prior written permission.
|
16 |
*
|
17 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
18 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
19 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
20 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
21 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
22 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
23 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
24 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
26 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
27 |
* SUCH DAMAGE.
|
28 |
*/
|
29 |
|
30 |
#ifndef _SYS_DEVICE_H
|
31 |
#define _SYS_DEVICE_H
|
32 |
|
33 |
#include <sys/cdefs.h> |
34 |
#include <sys/types.h> |
35 |
|
36 |
/*
|
37 |
* Device flags
|
38 |
*
|
39 |
* If D_PROT is set, the device can not be opened via devfs.
|
40 |
*/
|
41 |
#define D_CHR 0x00000001 /* character device */ |
42 |
#define D_BLK 0x00000002 /* block device */ |
43 |
#define D_REM 0x00000004 /* removable device */ |
44 |
#define D_PROT 0x00000008 /* protected device */ |
45 |
#define D_TTY 0x00000010 /* tty device */ |
46 |
|
47 |
|
48 |
#ifdef KERNEL
|
49 |
|
50 |
/*
|
51 |
* Device operations
|
52 |
*/
|
53 |
struct devops {
|
54 |
int (*open) (device_t, int); |
55 |
int (*close) (device_t);
|
56 |
int (*read) (device_t, char *, size_t *, int); |
57 |
int (*write) (device_t, char *, size_t *, int); |
58 |
int (*ioctl) (device_t, u_long, void *); |
59 |
int (*devctl) (device_t, u_long, void *); |
60 |
}; |
61 |
|
62 |
typedef int (*devop_open_t) (device_t, int); |
63 |
typedef int (*devop_close_t) (device_t); |
64 |
typedef int (*devop_read_t) (device_t, char *, size_t *, int); |
65 |
typedef int (*devop_write_t) (device_t, char *, size_t *, int); |
66 |
typedef int (*devop_ioctl_t) (device_t, u_long, void *); |
67 |
typedef int (*devop_devctl_t) (device_t, u_long, void *); |
68 |
|
69 |
#define no_open ((devop_open_t)nullop)
|
70 |
#define no_close ((devop_close_t)nullop)
|
71 |
#define no_read ((devop_read_t)enodev)
|
72 |
#define no_write ((devop_write_t)enodev)
|
73 |
#define no_ioctl ((devop_ioctl_t)enodev)
|
74 |
#define no_devctl ((devop_devctl_t)nullop)
|
75 |
|
76 |
/*
|
77 |
* Driver object
|
78 |
*/
|
79 |
struct driver {
|
80 |
const char *name; /* name of device driver */ |
81 |
struct devops *devops; /* device operations */ |
82 |
size_t devsz; /* size of private data */
|
83 |
int flags; /* state of driver */ |
84 |
int (*probe) (struct driver *); |
85 |
int (*init) (struct driver *); |
86 |
int (*unload) (struct driver *); |
87 |
}; |
88 |
|
89 |
/*
|
90 |
* flags for the driver.
|
91 |
*/
|
92 |
#define DS_INACTIVE 0x00 /* driver is inactive */ |
93 |
#define DS_ALIVE 0x01 /* probe succeded */ |
94 |
#define DS_ACTIVE 0x02 /* intialized */ |
95 |
#define DS_DEBUG 0x04 /* debug */ |
96 |
|
97 |
#endif /* !KERNEL */ |
98 |
#endif /* !_SYS_DEVICE_H */ |