2 * Copyright (c) 2005-2007, Kohsuke Ohtani
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
36 #define DEVICE_MAGIC 0x4465763f /* 'Dev?' */
41 * "order" is initialize order which must be between 0 and 15.
42 * The driver with order 0 is called first.
45 const char *name
; /* Name of device driver */
46 const int order
; /* Initialize order */
47 int (*init
)(); /* Initialize routine */
49 typedef struct driver
*driver_t
;
51 extern struct driver __driver_table
, __driver_table_end
;
64 typedef struct devio
*devio_t
;
70 int magic
; /* Magic number */
71 int ref_count
; /* Reference count */
72 struct list link
; /* Link for device list */
73 devio_t devio
; /* Device I/O table */
74 char name
[MAX_DEVNAME
]; /* Name of device */
76 typedef struct device
*device_t
;
78 #define device_valid(dev) (kern_area(dev) && ((dev)->magic == DEVICE_MAGIC))
80 extern void device_init(void);
81 extern int device_open(char *name
, int mode
, device_t
*pdev
);
82 extern int device_close(device_t dev
);
83 extern int device_read(device_t dev
, void *buf
, size_t *nbyte
, int blkno
);
84 extern int device_write(device_t dev
, void *buf
, size_t *nbyte
, int blkno
);
85 extern int device_ioctl(device_t dev
, int cmd
, u_long arg
);
86 extern int device_info(struct info_device
*info
);
89 #endif /* !_DEVICE_H */