xref: /minix3/minix/servers/devman/devman.h (revision 5eefd0fec2bd5bc6ad818ba164bcc653f954426c)
1433d6423SLionel Sambuc #ifndef _SERVERS_DEVMAN_DEVMAN_H
2433d6423SLionel Sambuc #define _SERVERS_DEVMAN_DEVMAN_H
3433d6423SLionel Sambuc #define _SYSTEM		1	/* tell headers that this is the kernel */
4433d6423SLionel Sambuc #define DEVMAN_SERVER	1
5433d6423SLionel Sambuc 
6433d6423SLionel Sambuc #include <minix/config.h>
7433d6423SLionel Sambuc #include <errno.h>
8433d6423SLionel Sambuc #include <unistd.h>
9433d6423SLionel Sambuc #include <stdlib.h>
10433d6423SLionel Sambuc #include <stdio.h>
11433d6423SLionel Sambuc #include <string.h>
12433d6423SLionel Sambuc #include <lib.h>
13433d6423SLionel Sambuc #include <minix/timers.h>
14433d6423SLionel Sambuc 
15433d6423SLionel Sambuc #include <minix/callnr.h>
16433d6423SLionel Sambuc #include <minix/type.h>
17433d6423SLionel Sambuc #include <minix/const.h>
18433d6423SLionel Sambuc #include <minix/com.h>
19433d6423SLionel Sambuc #include <minix/syslib.h>
20433d6423SLionel Sambuc #include <minix/sysutil.h>
21433d6423SLionel Sambuc #include <minix/vfsif.h>
22433d6423SLionel Sambuc #include <minix/endpoint.h>
23433d6423SLionel Sambuc #include <minix/sysinfo.h>
24433d6423SLionel Sambuc #include <minix/u64.h>
25433d6423SLionel Sambuc #include <minix/sysinfo.h>
26433d6423SLionel Sambuc #include <minix/type.h>
27433d6423SLionel Sambuc #include <minix/ipc.h>
28433d6423SLionel Sambuc 
29433d6423SLionel Sambuc #include <sys/time.h>
30433d6423SLionel Sambuc #include <sys/times.h>
31433d6423SLionel Sambuc #include <sys/types.h>
32433d6423SLionel Sambuc #include <sys/stat.h>
33433d6423SLionel Sambuc 
34433d6423SLionel Sambuc #include <minix/vtreefs.h>
35433d6423SLionel Sambuc 
36433d6423SLionel Sambuc #include <minix/devman.h>
37433d6423SLionel Sambuc #include <sys/queue.h>
38433d6423SLionel Sambuc 
39*5eefd0feSDavid van Moolenbroek #define BUF_SIZE 4097
40*5eefd0feSDavid van Moolenbroek 
41433d6423SLionel Sambuc #define DEVMAN_DEFAULT_MODE   (S_IRUSR | S_IRGRP | S_IROTH)
42433d6423SLionel Sambuc #define DEVMAN_STRING_LEN 128
43433d6423SLionel Sambuc 
44433d6423SLionel Sambuc #define ADD_STRING "ADD "
45433d6423SLionel Sambuc #define REMOVE_STRING "REMOVE "
46433d6423SLionel Sambuc 
47433d6423SLionel Sambuc enum devman_inode_type {
48433d6423SLionel Sambuc 	DEVMAN_DEVINFO_STATIC,
49433d6423SLionel Sambuc 	DEVMAN_DEVINFO_DYNAMIC,
50433d6423SLionel Sambuc 	DEVMAN_DEVICE
51433d6423SLionel Sambuc };
52433d6423SLionel Sambuc 
53*5eefd0feSDavid van Moolenbroek typedef ssize_t (*devman_read_fn)
54*5eefd0feSDavid van Moolenbroek     (char *ptr, size_t len, off_t offset, void *data);
55433d6423SLionel Sambuc 
56433d6423SLionel Sambuc struct devman_device_file {
57433d6423SLionel Sambuc 	int minor;
58433d6423SLionel Sambuc 	int type;
59433d6423SLionel Sambuc };
60433d6423SLionel Sambuc 
61433d6423SLionel Sambuc struct devman_static_info_inode {
62433d6423SLionel Sambuc 	struct devman_device *dev;
63433d6423SLionel Sambuc 	char data[DEVMAN_STRING_LEN];
64433d6423SLionel Sambuc };
65433d6423SLionel Sambuc 
66433d6423SLionel Sambuc struct devman_event {
67433d6423SLionel Sambuc 	char data[DEVMAN_STRING_LEN];
68433d6423SLionel Sambuc 	TAILQ_ENTRY(devman_event) events;
69433d6423SLionel Sambuc };
70433d6423SLionel Sambuc 
71433d6423SLionel Sambuc struct devman_event_inode {
72433d6423SLionel Sambuc 	TAILQ_HEAD(event_head, devman_event) event_queue;
73433d6423SLionel Sambuc };
74433d6423SLionel Sambuc 
75433d6423SLionel Sambuc struct devman_inode {
76433d6423SLionel Sambuc 	struct inode *inode;
77433d6423SLionel Sambuc 	devman_read_fn read_fn;
78433d6423SLionel Sambuc 	void *data;
79433d6423SLionel Sambuc 	TAILQ_ENTRY(devman_inode) inode_list;
80433d6423SLionel Sambuc };
81433d6423SLionel Sambuc 
82433d6423SLionel Sambuc struct devman_device {
83433d6423SLionel Sambuc 	int dev_id;
84433d6423SLionel Sambuc 	char * name;
85433d6423SLionel Sambuc 
86433d6423SLionel Sambuc 	int ref_count;
87433d6423SLionel Sambuc 
88433d6423SLionel Sambuc 	int major;
89433d6423SLionel Sambuc #define DEVMAN_DEVICE_ZOMBIE 2
90433d6423SLionel Sambuc #define DEVMAN_DEVICE_BOUND 1
91433d6423SLionel Sambuc #define DEVMAN_DEVICE_UNBOUND 0
92433d6423SLionel Sambuc 	int state;
93433d6423SLionel Sambuc 
94433d6423SLionel Sambuc 	endpoint_t owner;
95433d6423SLionel Sambuc 
96433d6423SLionel Sambuc 	struct devman_inode inode;
97433d6423SLionel Sambuc 	struct devman_device *parent;
98433d6423SLionel Sambuc 
99433d6423SLionel Sambuc 	/* the serialized information on this device */
100433d6423SLionel Sambuc 	struct devman_device_info *info;
101433d6423SLionel Sambuc 
102433d6423SLionel Sambuc 	TAILQ_ENTRY(devman_device) siblings;
103433d6423SLionel Sambuc 
104433d6423SLionel Sambuc 	/* devices attached to the this device */
105433d6423SLionel Sambuc 	TAILQ_HEAD(children_head, devman_device) children;
106433d6423SLionel Sambuc 	TAILQ_HEAD(info_head, devman_inode) infos;
107433d6423SLionel Sambuc };
108433d6423SLionel Sambuc #endif
109