xref: /haiku/headers/os/drivers/Drivers.h (revision 3cb015b1ee509d69c643506e8ff573808c86dcfc)
1 #ifndef _DRIVERS_DRIVERS_H
2 #define _DRIVERS_DRIVERS_H
3 
4 #include <BeBuild.h>
5 #include <sys/types.h>
6 #include <sys/uio.h>
7 #include <SupportDefs.h>
8 #include <Select.h>
9 
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 /* ---
16 	these hooks are how the kernel accesses the device
17 --- */
18 
19 typedef status_t (*device_open_hook) (const char *name, uint32 flags, void **cookie);
20 typedef status_t (*device_close_hook) (void *cookie);
21 typedef status_t (*device_free_hook) (void *cookie);
22 typedef status_t (*device_control_hook) (void *cookie, uint32 op, void *data,
23                                          size_t len);
24 typedef status_t  (*device_read_hook) (void *cookie, off_t position, void *data,
25                                       size_t *numBytes);
26 typedef status_t  (*device_write_hook) (void *cookie, off_t position,
27                                        const void *data, size_t *numBytes);
28 typedef status_t (*device_select_hook) (void *cookie, uint8 event, uint32 ref,
29                                         selectsync *sync);
30 typedef status_t (*device_deselect_hook) (void *cookie, uint8 event,
31                                           selectsync *sync);
32 typedef status_t (*device_read_pages_hook)(void *cookie, off_t position, const iovec *vec,
33 					size_t count, size_t *_numBytes);
34 typedef status_t (*device_write_pages_hook) (void *cookie, off_t position, const iovec *vec,
35 					size_t count, size_t *_numBytes);
36 
37 #define	B_CUR_DRIVER_API_VERSION	2
38 
39 /* ---
40 	the device_hooks structure is a descriptor for the device, giving its
41 	entry points.
42 --- */
43 
44 typedef struct {
45 	device_open_hook		open;			/* called to open the device */
46 	device_close_hook		close;			/* called to close the device */
47 	device_free_hook		free;			/* called to free the cookie */
48 	device_control_hook		control;		/* called to control the device */
49 	device_read_hook		read;			/* reads from the device */
50 	device_write_hook		write;			/* writes to the device */
51 	device_select_hook		select;			/* start select */
52 	device_deselect_hook	deselect;		/* stop select */
53 	device_read_pages_hook	read_pages;		/* scatter-gather physical read from the device */
54 	device_write_pages_hook	write_pages;	/* scatter-gather physical write to the device */
55 } device_hooks;
56 
57 status_t		init_hardware(void);
58 const char	  **publish_devices(void);
59 device_hooks	*find_device(const char *name);
60 status_t		init_driver(void);
61 void			uninit_driver(void);
62 
63 extern int32	api_version;
64 
65 enum {
66 	B_GET_DEVICE_SIZE = 1,			/* get # bytes */
67 									/*   returns size_t in *data */
68 
69 	B_SET_DEVICE_SIZE,				/* set # bytes */
70 									/*   passed size_t in *data */
71 
72 	B_SET_NONBLOCKING_IO,			/* set to non-blocking i/o */
73 
74 	B_SET_BLOCKING_IO,				/* set to blocking i/o */
75 
76 	B_GET_READ_STATUS,				/* check if can read w/o blocking */
77 									/*   returns bool in *data */
78 
79 	B_GET_WRITE_STATUS,				/* check if can write w/o blocking */
80 									/*   returns bool in *data */
81 
82 	B_GET_GEOMETRY,					/* get info about device geometry */
83 									/*   returns struct geometry in *data */
84 
85 	B_GET_DRIVER_FOR_DEVICE,		/* get the path of the executable serving that device */
86 
87 	B_GET_PARTITION_INFO,			/* get info about a device partition */
88 									/*   returns struct partition_info in *data */
89 
90 	B_SET_PARTITION,				/* create a user-defined partition */
91 
92 	B_FORMAT_DEVICE,				/* low-level device format */
93 
94 	B_EJECT_DEVICE,					/* eject the media if supported */
95 
96 	B_GET_ICON,						/* return device icon (see struct below) */
97 
98 	B_GET_BIOS_GEOMETRY,			/* get info about device geometry */
99 									/* as reported by the bios */
100 									/*   returns struct geometry in *data */
101 
102 	B_GET_MEDIA_STATUS,				/* get status of media. */
103 									/* return status_t in *data: */
104 									/* B_NO_ERROR: media ready */
105 									/* B_DEV_NO_MEDIA: no media */
106 									/* B_DEV_NOT_READY: device not ready */
107 									/* B_DEV_MEDIA_CHANGED: media changed */
108 									/*  since open or last B_GET_MEDIA_STATUS */
109 									/* B_DEV_MEDIA_CHANGE_REQUESTED: user */
110 									/*  pressed button on drive */
111 									/* B_DEV_DOOR_OPEN: door open */
112 
113 	B_LOAD_MEDIA,					/* load the media if supported */
114 
115 	B_GET_BIOS_DRIVE_ID,			/* get bios id for this device */
116 
117 	B_SET_UNINTERRUPTABLE_IO,		/* prevent cntl-C from interrupting i/o */
118 	B_SET_INTERRUPTABLE_IO,			/* allow cntl-C to interrupt i/o */
119 
120 	B_FLUSH_DRIVE_CACHE,			/* flush drive cache */
121 
122 	B_GET_PATH_FOR_DEVICE,			/* get the absolute path of the device */
123 
124 	B_GET_NEXT_OPEN_DEVICE = 1000,	/* iterate through open devices */
125 	B_ADD_FIXED_DRIVER,				/* private */
126 	B_REMOVE_FIXED_DRIVER,			/* private */
127 
128 	B_AUDIO_DRIVER_BASE = 8000,		/* base for codes in audio_driver.h */
129 	B_MIDI_DRIVER_BASE = 8100,		/* base for codes in midi_driver.h */
130 	B_JOYSTICK_DRIVER_BASE = 8200,	/* base for codes in joystick.h */
131 	B_GRAPHIC_DRIVER_BASE = 8300,	/* base for codes in graphic_driver.h */
132 
133 	B_DEVICE_OP_CODES_END = 9999	/* end of Be-defined contol id's */
134 };
135 
136 /* ---
137 	geometry structure for the B_GET_GEOMETRY opcode
138 --- */
139 
140 typedef struct {
141 	uint32	bytes_per_sector;		/* sector size in bytes */
142 	uint32	sectors_per_track;		/* # sectors per track */
143 	uint32	cylinder_count;			/* # cylinders */
144 	uint32	head_count;				/* # heads */
145 	uchar	device_type;			/* type */
146 	bool	removable;				/* non-zero if removable */
147 	bool	read_only;				/* non-zero if read only */
148 	bool	write_once;				/* non-zero if write-once */
149 } device_geometry;
150 
151 
152 /* ---
153 	Be-defined device types returned by B_GET_GEOMETRY.  Use these if it makes
154 	sense for your device.
155 --- */
156 
157 enum {
158 	B_DISK = 0,						/* Hard disks, floppy disks, etc. */
159 	B_TAPE,							/* Tape drives */
160 	B_PRINTER,						/* Printers */
161 	B_CPU,							/* CPU devices */
162 	B_WORM,							/* Write-once, read-many devices */
163 	B_CD,							/* CD ROMS */
164 	B_SCANNER,						/* Scanners */
165 	B_OPTICAL,						/* Optical devices */
166 	B_JUKEBOX,						/* Jukeboxes */
167 	B_NETWORK						/* Network devices */
168 };
169 
170 
171 /* ---
172 	partition_info structure used by B_GET_PARTITION_INFO and B_SET_PARTITION
173 --- */
174 
175 typedef struct {
176 	off_t	offset;					/* offset (in bytes) */
177 	off_t	size;					/* size (in bytes) */
178 	int32	logical_block_size;		/* logical block size of partition */
179 	int32	session;				/* id of session */
180 	int32	partition;				/* id of partition */
181 	char	device[256];			/* path to the physical device */
182 } partition_info;
183 
184 /* ---
185 	driver_path structure returned by the B_GET_DRIVER_FOR_DEVICE
186 --- */
187 
188 typedef char	driver_path[256];
189 
190 
191 /* ---
192 	open_device_iterator structure used by the B_GET_NEXT_OPEN_DEVICE opcode
193 --- */
194 
195 typedef struct {
196 	uint32		cookie;			/* must be set to 0 before iterating */
197 	char		device[256];	/* device path */
198 } open_device_iterator;
199 
200 
201 /* ---
202 	icon structure for the B_GET_ICON opcode
203 --- */
204 
205 typedef struct {
206 	int32	icon_size;			/* icon size requested */
207 	void	*icon_data;			/* where to put 'em (usually BBitmap->Bits()) */
208 } device_icon;
209 
210 
211 #ifdef __cplusplus
212 }
213 #endif
214 
215 #endif /* _DRIVERS_DRIVERS_H */
216