1a38a92c9SIngo Weinhold#ifndef _FSSH_DRIVERS_DRIVERS_H
2a38a92c9SIngo Weinhold#define _FSSH_DRIVERS_DRIVERS_H
3a38a92c9SIngo Weinhold
4a38a92c9SIngo Weinhold#include "fssh_defs.h"
5a38a92c9SIngo Weinhold#include "fssh_fs_interface.h"
6a38a92c9SIngo Weinhold
7a38a92c9SIngo Weinhold
8a38a92c9SIngo Weinhold#ifdef __cplusplus
9a38a92c9SIngo Weinholdextern "C" {
10a38a92c9SIngo Weinhold#endif
11a38a92c9SIngo Weinhold
12a38a92c9SIngo Weinhold/* ---
13a38a92c9SIngo Weinhold	these hooks are how the kernel accesses the device
14a38a92c9SIngo Weinhold--- */
15a38a92c9SIngo Weinhold
16a38a92c9SIngo Weinholdtypedef fssh_status_t (*fssh_device_open_hook) (const char *name,
17a38a92c9SIngo Weinhold								uint32_t flags, void **cookie);
18a38a92c9SIngo Weinholdtypedef fssh_status_t (*fssh_device_close_hook) (void *cookie);
19a38a92c9SIngo Weinholdtypedef fssh_status_t (*fssh_device_free_hook) (void *cookie);
20a38a92c9SIngo Weinholdtypedef fssh_status_t (*fssh_device_control_hook) (void *cookie, uint32_t op,
21a38a92c9SIngo Weinhold								void *data, fssh_size_t len);
22a38a92c9SIngo Weinholdtypedef fssh_status_t  (*fssh_device_read_hook) (void *cookie,
23a38a92c9SIngo Weinhold								fssh_off_t position, void *data,
24a38a92c9SIngo Weinhold								fssh_size_t *numBytes);
25a38a92c9SIngo Weinholdtypedef fssh_status_t  (*fssh_device_write_hook) (void *cookie,
26a38a92c9SIngo Weinhold								fssh_off_t position, const void *data,
27a38a92c9SIngo Weinhold								fssh_size_t *numBytes);
28a38a92c9SIngo Weinholdtypedef fssh_status_t (*fssh_device_select_hook) (void *cookie, uint8_t event,
29a38a92c9SIngo Weinhold								uint32_t ref, fssh_selectsync *sync);
30a38a92c9SIngo Weinholdtypedef fssh_status_t (*fssh_device_deselect_hook) (void *cookie, uint8_t event,
31a38a92c9SIngo Weinhold								fssh_selectsync *sync);
32a38a92c9SIngo Weinholdtypedef fssh_status_t (*fssh_device_read_pages_hook)(void *cookie,
33a38a92c9SIngo Weinhold								fssh_off_t position, const fssh_iovec *vec,
34a38a92c9SIngo Weinhold								fssh_size_t count, fssh_size_t *_numBytes);
35a38a92c9SIngo Weinholdtypedef fssh_status_t (*fssh_device_write_pages_hook) (void *cookie,
36a38a92c9SIngo Weinhold								fssh_off_t position, const fssh_iovec *vec,
37a38a92c9SIngo Weinhold								fssh_size_t count, fssh_size_t *_numBytes);
38a38a92c9SIngo Weinhold
39a38a92c9SIngo Weinhold#define	FSSH_B_CUR_DRIVER_API_VERSION	2
40a38a92c9SIngo Weinhold
41a38a92c9SIngo Weinhold/* ---
42a38a92c9SIngo Weinhold	the device_hooks structure is a descriptor for the device, giving its
43a38a92c9SIngo Weinhold	entry points.
44a38a92c9SIngo Weinhold--- */
45a38a92c9SIngo Weinhold
46a38a92c9SIngo Weinholdtypedef struct {
47a38a92c9SIngo Weinhold	fssh_device_open_hook			open;			/* called to open the device */
48a38a92c9SIngo Weinhold	fssh_device_close_hook			close;			/* called to close the device */
49a38a92c9SIngo Weinhold	fssh_device_free_hook			free;			/* called to free the cookie */
50a38a92c9SIngo Weinhold	fssh_device_control_hook		control;		/* called to control the device */
51a38a92c9SIngo Weinhold	fssh_device_read_hook			read;			/* reads from the device */
52a38a92c9SIngo Weinhold	fssh_device_write_hook			write;			/* writes to the device */
53a38a92c9SIngo Weinhold	fssh_device_select_hook			select;			/* start select */
54a38a92c9SIngo Weinhold	fssh_device_deselect_hook		deselect;		/* stop select */
55a38a92c9SIngo Weinhold	fssh_device_read_pages_hook		read_pages;		/* scatter-gather physical read from the device */
56a38a92c9SIngo Weinhold	fssh_device_write_pages_hook	write_pages;	/* scatter-gather physical write to the device */
57a38a92c9SIngo Weinhold} fssh_device_hooks;
58a38a92c9SIngo Weinhold
59a38a92c9SIngo Weinholdfssh_status_t		fssh_init_hardware(void);
60a38a92c9SIngo Weinholdconst char		  **fssh_publish_devices(void);
61a38a92c9SIngo Weinholdfssh_device_hooks	*fssh_find_device(const char *name);
62a38a92c9SIngo Weinholdfssh_status_t		fssh_init_driver(void);
6329a84508SAxel Dörflervoid				fssh_uninit_driver(void);
64a38a92c9SIngo Weinhold
65a38a92c9SIngo Weinholdextern int32_t	fssh_api_version;
66a38a92c9SIngo Weinhold
67a38a92c9SIngo Weinholdenum {
68a38a92c9SIngo Weinhold	FSSH_B_GET_DEVICE_SIZE = 1,			/* get # bytes */
69a38a92c9SIngo Weinhold										/*   returns size_t in *data */
70a38a92c9SIngo Weinhold
71a38a92c9SIngo Weinhold	FSSH_B_SET_DEVICE_SIZE,				/* set # bytes */
72a38a92c9SIngo Weinhold										/*   passed size_t in *data */
73a38a92c9SIngo Weinhold
74a38a92c9SIngo Weinhold	FSSH_B_SET_NONBLOCKING_IO,			/* set to non-blocking i/o */
75a38a92c9SIngo Weinhold
76a38a92c9SIngo Weinhold	FSSH_B_SET_BLOCKING_IO,				/* set to blocking i/o */
77a38a92c9SIngo Weinhold
78a38a92c9SIngo Weinhold	FSSH_B_GET_READ_STATUS,				/* check if can read w/o blocking */
79a38a92c9SIngo Weinhold										/*   returns bool in *data */
80a38a92c9SIngo Weinhold
81a38a92c9SIngo Weinhold	FSSH_B_GET_WRITE_STATUS,			/* check if can write w/o blocking */
82a38a92c9SIngo Weinhold										/*   returns bool in *data */
83a38a92c9SIngo Weinhold
84a38a92c9SIngo Weinhold	FSSH_B_GET_GEOMETRY,				/* get info about device geometry */
85a38a92c9SIngo Weinhold										/*   returns struct geometry in *data */
86a38a92c9SIngo Weinhold
87a38a92c9SIngo Weinhold	FSSH_B_GET_DRIVER_FOR_DEVICE,		/* get the path of the executable serving that device */
88a38a92c9SIngo Weinhold
89a38a92c9SIngo Weinhold	FSSH_B_GET_PARTITION_INFO,			/* get info about a device partition */
90a38a92c9SIngo Weinhold										/*   returns struct partition_info in *data */
91a38a92c9SIngo Weinhold
92a38a92c9SIngo Weinhold	FSSH_B_SET_PARTITION,				/* create a user-defined partition */
93a38a92c9SIngo Weinhold
94a38a92c9SIngo Weinhold	FSSH_B_FORMAT_DEVICE,				/* low-level device format */
95a38a92c9SIngo Weinhold
96a38a92c9SIngo Weinhold	FSSH_B_EJECT_DEVICE,				/* eject the media if supported */
97a38a92c9SIngo Weinhold
98a38a92c9SIngo Weinhold	FSSH_B_GET_ICON,					/* return device icon (see struct below) */
99a38a92c9SIngo Weinhold
100a38a92c9SIngo Weinhold	FSSH_B_GET_BIOS_GEOMETRY,			/* get info about device geometry */
101a38a92c9SIngo Weinhold										/* as reported by the bios */
102a38a92c9SIngo Weinhold										/*   returns struct geometry in *data */
103a38a92c9SIngo Weinhold
104a38a92c9SIngo Weinhold	FSSH_B_GET_MEDIA_STATUS,			/* get status of media. */
105a38a92c9SIngo Weinhold										/* return fssh_status_t in *data: */
106a38a92c9SIngo Weinhold										/* B_NO_ERROR: media ready */
107a38a92c9SIngo Weinhold										/* B_DEV_NO_MEDIA: no media */
108a38a92c9SIngo Weinhold										/* B_DEV_NOT_READY: device not ready */
109a38a92c9SIngo Weinhold										/* B_DEV_MEDIA_CHANGED: media changed */
110a38a92c9SIngo Weinhold										/*  since open or last B_GET_MEDIA_STATUS */
111a38a92c9SIngo Weinhold										/* B_DEV_MEDIA_CHANGE_REQUESTED: user */
112a38a92c9SIngo Weinhold										/*  pressed button on drive */
113a38a92c9SIngo Weinhold										/* B_DEV_DOOR_OPEN: door open */
11429a84508SAxel Dörfler
115a38a92c9SIngo Weinhold	FSSH_B_LOAD_MEDIA,					/* load the media if supported */
11629a84508SAxel Dörfler
117a38a92c9SIngo Weinhold	FSSH_B_GET_BIOS_DRIVE_ID,			/* get bios id for this device */
118a38a92c9SIngo Weinhold
119a38a92c9SIngo Weinhold	FSSH_B_SET_UNINTERRUPTABLE_IO,		/* prevent cntl-C from interrupting i/o */
120a38a92c9SIngo Weinhold	FSSH_B_SET_INTERRUPTABLE_IO,		/* allow cntl-C to interrupt i/o */
121a38a92c9SIngo Weinhold
122a38a92c9SIngo Weinhold	FSSH_B_FLUSH_DRIVE_CACHE,			/* flush drive cache */
123a38a92c9SIngo Weinhold	FSSH_B_GET_PATH_FOR_DEVICE,			/* get the absolute path of the device */
12429a84508SAxel Dörfler	FSSH_B_GET_ICON_NAME,				/* get an icon name identifier */
12529a84508SAxel Dörfler	FSSH_B_GET_VECTOR_ICON,				/* retrieves the device's vector icon */
12629a84508SAxel Dörfler	FSSH_B_GET_DEVICE_NAME,				/* get name, string buffer */
12729a84508SAxel Dörfler	FSSH_B_TRIM_DEVICE,					/* trims blocks, see fs_trim_data */
128a38a92c9SIngo Weinhold
129a38a92c9SIngo Weinhold	FSSH_B_GET_NEXT_OPEN_DEVICE = 1000,	/* iterate through open devices */
130a38a92c9SIngo Weinhold	FSSH_B_ADD_FIXED_DRIVER,			/* private */
131a38a92c9SIngo Weinhold	FSSH_B_REMOVE_FIXED_DRIVER,			/* private */
132a38a92c9SIngo Weinhold
133a38a92c9SIngo Weinhold	FSSH_B_AUDIO_DRIVER_BASE = 8000,	/* base for codes in audio_driver.h */
134a38a92c9SIngo Weinhold	FSSH_B_MIDI_DRIVER_BASE = 8100,		/* base for codes in midi_driver.h */
135a38a92c9SIngo Weinhold	FSSH_B_JOYSTICK_DRIVER_BASE = 8200,	/* base for codes in joystick.h */
136a38a92c9SIngo Weinhold	FSSH_B_GRAPHIC_DRIVER_BASE = 8300,	/* base for codes in graphic_driver.h */
137a38a92c9SIngo Weinhold
138a38a92c9SIngo Weinhold	FSSH_B_DEVICE_OP_CODES_END = 9999	/* end of Be-defined contol id's */
139a38a92c9SIngo Weinhold};
140a38a92c9SIngo Weinhold
141a38a92c9SIngo Weinhold/* ---
142a38a92c9SIngo Weinhold	geometry structure for the B_GET_GEOMETRY opcode
143a38a92c9SIngo Weinhold--- */
144a38a92c9SIngo Weinhold
145a38a92c9SIngo Weinholdtypedef struct {
146a38a92c9SIngo Weinhold	uint32_t	bytes_per_sector;		/* sector size in bytes */
147a38a92c9SIngo Weinhold	uint32_t	sectors_per_track;		/* # sectors per track */
148a38a92c9SIngo Weinhold	uint32_t	cylinder_count;			/* # cylinders */
149a38a92c9SIngo Weinhold	uint32_t	head_count;				/* # heads */
150a38a92c9SIngo Weinhold	uint8_t		device_type;			/* type */
151a38a92c9SIngo Weinhold	bool		removable;				/* non-zero if removable */
152a38a92c9SIngo Weinhold	bool		read_only;				/* non-zero if read only */
153a38a92c9SIngo Weinhold	bool		write_once;				/* non-zero if write-once */
154a38a92c9SIngo Weinhold} fssh_device_geometry;
155a38a92c9SIngo Weinhold
156a38a92c9SIngo Weinhold
157a38a92c9SIngo Weinhold/* ---
158a38a92c9SIngo Weinhold	Be-defined device types returned by B_GET_GEOMETRY.  Use these if it makes
159a38a92c9SIngo Weinhold	sense for your device.
160a38a92c9SIngo Weinhold--- */
161a38a92c9SIngo Weinhold
162a38a92c9SIngo Weinholdenum {
163a38a92c9SIngo Weinhold	FSSH_B_DISK = 0,					/* Hard disks, floppy disks, etc. */
164a38a92c9SIngo Weinhold	FSSH_B_TAPE,						/* Tape drives */
165a38a92c9SIngo Weinhold	FSSH_B_PRINTER,						/* Printers */
166a38a92c9SIngo Weinhold	FSSH_B_CPU,							/* CPU devices */
167a38a92c9SIngo Weinhold	FSSH_B_WORM,						/* Write-once, read-many devices */
168a38a92c9SIngo Weinhold	FSSH_B_CD,							/* CD ROMS */
169a38a92c9SIngo Weinhold	FSSH_B_SCANNER,						/* Scanners */
170a38a92c9SIngo Weinhold	FSSH_B_OPTICAL,						/* Optical devices */
171a38a92c9SIngo Weinhold	FSSH_B_JUKEBOX,						/* Jukeboxes */
172a38a92c9SIngo Weinhold	FSSH_B_NETWORK						/* Network devices */
173a38a92c9SIngo Weinhold};
174a38a92c9SIngo Weinhold
175a38a92c9SIngo Weinhold
176a38a92c9SIngo Weinhold/* ---
177a38a92c9SIngo Weinhold	partition_info structure used by B_GET_PARTITION_INFO and B_SET_PARTITION
178a38a92c9SIngo Weinhold--- */
179a38a92c9SIngo Weinhold
180a38a92c9SIngo Weinholdtypedef struct {
181a38a92c9SIngo Weinhold	fssh_off_t	offset;					/* offset (in bytes) */
182a38a92c9SIngo Weinhold	fssh_off_t	size;					/* size (in bytes) */
183a38a92c9SIngo Weinhold	int32_t		logical_block_size;		/* logical block size of partition */
184a38a92c9SIngo Weinhold	int32_t		session;				/* id of session */
185a38a92c9SIngo Weinhold	int32_t		partition;				/* id of partition */
186a38a92c9SIngo Weinhold	char		device[256];			/* path to the physical device */
187a38a92c9SIngo Weinhold} fssh_partition_info;
188a38a92c9SIngo Weinhold
189a38a92c9SIngo Weinhold/* ---
190a38a92c9SIngo Weinhold	driver_path structure returned by the B_GET_DRIVER_FOR_DEVICE
191a38a92c9SIngo Weinhold--- */
192a38a92c9SIngo Weinhold
193a38a92c9SIngo Weinholdtypedef char	fssh_driver_path[256];
194a38a92c9SIngo Weinhold
195a38a92c9SIngo Weinhold
196a38a92c9SIngo Weinhold/* ---
197a38a92c9SIngo Weinhold	open_device_iterator structure used by the B_GET_NEXT_OPEN_DEVICE opcode
198a38a92c9SIngo Weinhold--- */
199a38a92c9SIngo Weinhold
200a38a92c9SIngo Weinholdtypedef struct {
201a38a92c9SIngo Weinhold	uint32_t	cookie;			/* must be set to 0 before iterating */
20229a84508SAxel Dörfler	char		device[256];	/* device path */
203a38a92c9SIngo Weinhold} fssh_open_device_iterator;
204a38a92c9SIngo Weinhold
205a38a92c9SIngo Weinhold
206a38a92c9SIngo Weinhold/* ---
207a38a92c9SIngo Weinhold	icon structure for the B_GET_ICON opcode
208a38a92c9SIngo Weinhold--- */
209a38a92c9SIngo Weinhold
210a38a92c9SIngo Weinholdtypedef struct {
211a38a92c9SIngo Weinhold	int32_t	icon_size;			/* icon size requested */
212a38a92c9SIngo Weinhold	void	*icon_data;			/* where to put 'em (usually BBitmap->Bits()) */
213a38a92c9SIngo Weinhold} fssh_device_icon;
214a38a92c9SIngo Weinhold
215a38a92c9SIngo Weinhold
21629a84508SAxel Dörfler/* B_TRIM_DEVICE data structure */
21729a84508SAxel Dörflertypedef struct {
21899086aa3SAxel Dörfler	uint32_t	range_count;
21999086aa3SAxel Dörfler	uint64_t	trimmed_size;			/* filled on return */
22099086aa3SAxel Dörfler	struct range {
22199086aa3SAxel Dörfler		uint64_t	offset;				/* offset (in bytes) */
22299086aa3SAxel Dörfler		uint64_t	size;
22399086aa3SAxel Dörfler	} ranges[1];
22429a84508SAxel Dörfler} fssh_fs_trim_data;
22529a84508SAxel Dörfler
22629a84508SAxel Dörfler
227a38a92c9SIngo Weinhold#ifdef __cplusplus
228a38a92c9SIngo Weinhold}
229a38a92c9SIngo Weinhold#endif
230a38a92c9SIngo Weinhold
231a38a92c9SIngo Weinhold#endif /* _FSSH_DRIVERS_DRIVERS_H */
232