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
12extern "C" {
13#endif
14
15/* ---
16	these hooks are how the kernel accesses the device
17--- */
18
19typedef status_t (*device_open_hook) (const char *name, uint32 flags, void **cookie);
20typedef status_t (*device_close_hook) (void *cookie);
21typedef status_t (*device_free_hook) (void *cookie);
22typedef status_t (*device_control_hook) (void *cookie, uint32 op, void *data,
23                                         size_t len);
24typedef status_t  (*device_read_hook) (void *cookie, off_t position, void *data,
25                                      size_t *numBytes);
26typedef status_t  (*device_write_hook) (void *cookie, off_t position,
27                                       const void *data, size_t *numBytes);
28typedef status_t (*device_select_hook) (void *cookie, uint8 event, uint32 ref,
29                                        selectsync *sync);
30typedef status_t (*device_deselect_hook) (void *cookie, uint8 event,
31                                          selectsync *sync);
32typedef status_t (*device_read_pages_hook)(void *cookie, off_t position, const iovec *vec,
33					size_t count, size_t *_numBytes);
34typedef 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
44typedef 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
57status_t		init_hardware(void);
58const char	  **publish_devices(void);
59device_hooks	*find_device(const char *name);
60status_t		init_driver(void);
61void			uninit_driver(void);
62
63extern int32	api_version;
64
65enum {
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_NEXT_OPEN_DEVICE = 1000,	/* iterate through open devices */
123	B_ADD_FIXED_DRIVER,				/* private */
124	B_REMOVE_FIXED_DRIVER,			/* private */
125
126	B_AUDIO_DRIVER_BASE = 8000,		/* base for codes in audio_driver.h */
127	B_MIDI_DRIVER_BASE = 8100,		/* base for codes in midi_driver.h */
128	B_JOYSTICK_DRIVER_BASE = 8200,	/* base for codes in joystick.h */
129	B_GRAPHIC_DRIVER_BASE = 8300,	/* base for codes in graphic_driver.h */
130
131	B_DEVICE_OP_CODES_END = 9999	/* end of Be-defined contol id's */
132};
133
134/* ---
135	geometry structure for the B_GET_GEOMETRY opcode
136--- */
137
138typedef struct {
139	uint32	bytes_per_sector;		/* sector size in bytes */
140	uint32	sectors_per_track;		/* # sectors per track */
141	uint32	cylinder_count;			/* # cylinders */
142	uint32	head_count;				/* # heads */
143	uchar	device_type;			/* type */
144	bool	removable;				/* non-zero if removable */
145	bool	read_only;				/* non-zero if read only */
146	bool	write_once;				/* non-zero if write-once */
147} device_geometry;
148
149
150/* ---
151	Be-defined device types returned by B_GET_GEOMETRY.  Use these if it makes
152	sense for your device.
153--- */
154
155enum {
156	B_DISK = 0,						/* Hard disks, floppy disks, etc. */
157	B_TAPE,							/* Tape drives */
158	B_PRINTER,						/* Printers */
159	B_CPU,							/* CPU devices */
160	B_WORM,							/* Write-once, read-many devices */
161	B_CD,							/* CD ROMS */
162	B_SCANNER,						/* Scanners */
163	B_OPTICAL,						/* Optical devices */
164	B_JUKEBOX,						/* Jukeboxes */
165	B_NETWORK						/* Network devices */
166};
167
168
169/* ---
170	partition_info structure used by B_GET_PARTITION_INFO and B_SET_PARTITION
171--- */
172
173typedef struct {
174	off_t	offset;					/* offset (in bytes) */
175	off_t	size;					/* size (in bytes) */
176	int32	logical_block_size;		/* logical block size of partition */
177	int32	session;				/* id of session */
178	int32	partition;				/* id of partition */
179	char	device[256];			/* path to the physical device */
180} partition_info;
181
182/* ---
183	driver_path structure returned by the B_GET_DRIVER_FOR_DEVICE
184--- */
185
186typedef char	driver_path[256];
187
188
189/* ---
190	open_device_iterator structure used by the B_GET_NEXT_OPEN_DEVICE opcode
191--- */
192
193typedef struct {
194	uint32		cookie;			/* must be set to 0 before iterating */
195	char		device[256];	/* device path */
196} open_device_iterator;
197
198
199/* ---
200	icon structure for the B_GET_ICON opcode
201--- */
202
203typedef struct {
204	int32	icon_size;			/* icon size requested */
205	void	*icon_data;			/* where to put 'em (usually BBitmap->Bits()) */
206} device_icon;
207
208
209#ifdef __cplusplus
210}
211#endif
212
213#endif /* _DRIVERS_DRIVERS_H */
214