1/*
2 * Copyright 2002-2013, Haiku Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _DRIVERS_DRIVERS_H
6#define _DRIVERS_DRIVERS_H
7
8
9#include <sys/types.h>
10#include <sys/uio.h>
11
12#include <BeBuild.h>
13#include <Select.h>
14#include <SupportDefs.h>
15
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21/* These hooks are how the kernel accesses legacy devices */
22typedef status_t (*device_open_hook)(const char *name, uint32 flags,
23	void **cookie);
24typedef status_t (*device_close_hook)(void *cookie);
25typedef status_t (*device_free_hook)(void *cookie);
26typedef status_t (*device_control_hook)(void *cookie, uint32 op, void *data,
27	size_t len);
28typedef status_t  (*device_read_hook)(void *cookie, off_t position, void *data,
29	size_t *numBytes);
30typedef status_t  (*device_write_hook)(void *cookie, off_t position,
31	const void *data, size_t *numBytes);
32typedef status_t (*device_select_hook)(void *cookie, uint8 event, uint32 ref,
33	selectsync *sync);
34typedef status_t (*device_deselect_hook)(void *cookie, uint8 event,
35	selectsync *sync);
36typedef status_t (*device_read_pages_hook)(void *cookie, off_t position,
37	const iovec *vec, size_t count, size_t *_numBytes);
38typedef status_t (*device_write_pages_hook)(void *cookie, off_t position,
39	const iovec *vec, size_t count, size_t *_numBytes);
40
41#define	B_CUR_DRIVER_API_VERSION	2
42
43/* Legacy driver device hooks */
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;
54		/* scatter-gather physical read from the device */
55	device_write_pages_hook	write_pages;
56		/* scatter-gather physical write to the device */
57} device_hooks;
58
59/* Driver functions needed to be exported by legacy drivers */
60status_t		init_hardware(void);
61const char**	publish_devices(void);
62device_hooks*	find_device(const char* name);
63status_t		init_driver(void);
64void			uninit_driver(void);
65
66extern int32	api_version;
67
68enum {
69	B_GET_DEVICE_SIZE = 1,			/* get # bytes - returns size_t in *data */
70	B_SET_DEVICE_SIZE,				/* set # bytes - passes size_t in *data */
71	B_SET_NONBLOCKING_IO,			/* set to non-blocking i/o */
72	B_SET_BLOCKING_IO,				/* set to blocking i/o */
73	B_GET_READ_STATUS,				/* check if can read w/o blocking */
74									/* returns bool in *data */
75	B_GET_WRITE_STATUS,				/* check if can write w/o blocking */
76									/* returns bool in *data */
77	B_GET_GEOMETRY,					/* get info about device geometry */
78									/* returns struct geometry in *data */
79	B_GET_DRIVER_FOR_DEVICE,		/* get the path of the executable serving */
80									/* that device */
81	B_GET_PARTITION_INFO,			/* get info about a device partition */
82									/* returns struct partition_info in *data */
83	B_SET_PARTITION,				/* obsolete, will be removed */
84	B_FORMAT_DEVICE,				/* low-level device format */
85	B_EJECT_DEVICE,					/* eject the media if supported */
86	B_GET_ICON,						/* return device icon (see struct below) */
87	B_GET_BIOS_GEOMETRY,			/* get info about device geometry */
88									/* as reported by the bios */
89									/*   returns struct geometry in *data */
90	B_GET_MEDIA_STATUS,				/* get status of media. */
91									/* return status_t in *data: */
92									/* B_NO_ERROR: media ready */
93									/* B_DEV_NO_MEDIA: no media */
94									/* B_DEV_NOT_READY: device not ready */
95									/* B_DEV_MEDIA_CHANGED: media changed */
96									/*  since open or last B_GET_MEDIA_STATUS */
97									/* B_DEV_MEDIA_CHANGE_REQUESTED: user */
98									/*  pressed button on drive */
99									/* B_DEV_DOOR_OPEN: door open */
100	B_LOAD_MEDIA,					/* load the media if supported */
101	B_GET_BIOS_DRIVE_ID,			/* get bios id for this device */
102	B_SET_UNINTERRUPTABLE_IO,		/* prevent cntl-C from interrupting i/o */
103	B_SET_INTERRUPTABLE_IO,			/* allow cntl-C to interrupt i/o */
104	B_FLUSH_DRIVE_CACHE,			/* flush drive cache */
105	B_GET_PATH_FOR_DEVICE,			/* get the absolute path of the device */
106	B_GET_ICON_NAME,				/* get an icon name identifier */
107	B_GET_VECTOR_ICON,				/* retrieves the device's vector icon */
108	B_GET_DEVICE_NAME,				/* get name, string buffer */
109	B_TRIM_DEVICE,					/* trims blocks, see fs_trim_data */
110
111	B_GET_NEXT_OPEN_DEVICE = 1000,	/* obsolete, will be removed */
112	B_ADD_FIXED_DRIVER,				/* obsolete, will be removed */
113	B_REMOVE_FIXED_DRIVER,			/* obsolete, will be removed */
114
115	B_AUDIO_DRIVER_BASE = 8000,		/* base for codes in audio_driver.h */
116	B_MIDI_DRIVER_BASE = 8100,		/* base for codes in midi_driver.h */
117	B_JOYSTICK_DRIVER_BASE = 8200,	/* base for codes in joystick.h */
118	B_GRAPHIC_DRIVER_BASE = 8300,	/* base for codes in graphic_driver.h */
119
120	B_DEVICE_OP_CODES_END = 9999	/* end of Be-defined control ids */
121};
122
123/* B_GET_GEOMETRY data structure */
124typedef struct {
125	uint32	bytes_per_sector;		/* sector size in bytes */
126	uint32	sectors_per_track;		/* # sectors per track */
127	uint32	cylinder_count;			/* # cylinders */
128	uint32	head_count;				/* # heads */
129	uchar	device_type;			/* type */
130	bool	removable;				/* non-zero if removable */
131	bool	read_only;				/* non-zero if read only */
132	bool	write_once;				/* non-zero if write-once */
133} device_geometry;
134
135enum {
136	B_DISK = 0,						/* Hard disks, floppy disks, etc. */
137	B_TAPE,							/* Tape drives */
138	B_PRINTER,						/* Printers */
139	B_CPU,							/* CPU devices */
140	B_WORM,							/* Write-once, read-many devices */
141	B_CD,							/* CD ROMS */
142	B_SCANNER,						/* Scanners */
143	B_OPTICAL,						/* Optical devices */
144	B_JUKEBOX,						/* Jukeboxes */
145	B_NETWORK						/* Network devices */
146};
147
148
149/* B_GET_PARTITION_INFO data structure */
150typedef struct {
151	off_t	offset;					/* offset (in bytes) */
152	off_t	size;					/* size (in bytes) */
153	int32	logical_block_size;		/* logical block size of partition */
154	int32	session;				/* id of session */
155	int32	partition;				/* id of partition */
156	char	device[256];			/* path to the physical device */
157} partition_info;
158
159
160/* B_GET_DRIVER_FOR_DEVICE data structure */
161typedef char	driver_path[256];
162
163
164/* B_GET_ICON, and B_GET_VECTOR_ICON data structure */
165typedef struct {
166	int32	icon_size;
167		/* B_GET_VECTOR_ICON: size of the data buffer in icon_data */
168		/* B_GET_ICON: size of the icon in pixels */
169	void	*icon_data;
170} device_icon;
171
172
173/* B_TRIM_DEVICE data structure */
174typedef struct {
175	uint32	range_count;
176	uint64	trimmed_size;			/* filled on return */
177	struct range {
178		uint64	offset;				/* offset (in bytes) */
179		uint64	size;
180	} ranges[1];
181} fs_trim_data;
182
183
184#ifdef __cplusplus
185}
186#endif
187
188
189#endif /* _DRIVERS_DRIVERS_H */
190