106ba3f0aSAxel Dörfler/*
229a84508SAxel Dörfler * Copyright 2002-2013, Haiku Inc. All Rights Reserved.
306ba3f0aSAxel Dörfler * Distributed under the terms of the MIT License.
406ba3f0aSAxel Dörfler */
55f79d3a8SDavid Reid#ifndef _DRIVERS_DRIVERS_H
65f79d3a8SDavid Reid#define _DRIVERS_DRIVERS_H
806ba3f0aSAxel Dörfler
9085320eaSAxel Dörfler#include <sys/types.h>
1003b27173SDavid Reid#include <sys/uio.h>
1106ba3f0aSAxel Dörfler
1206ba3f0aSAxel Dörfler#include <BeBuild.h>
138384cc5cSAxel Dörfler#include <Select.h>
1406ba3f0aSAxel Dörfler#include <SupportDefs.h>
158384cc5cSAxel Dörfler
17f97b4ac4SIngo Weinhold#ifdef __cplusplus
18f97b4ac4SIngo Weinholdextern "C" {
19f97b4ac4SIngo Weinhold#endif
20f97b4ac4SIngo Weinhold
2106ba3f0aSAxel Dörfler/* These hooks are how the kernel accesses legacy devices */
2206ba3f0aSAxel Dörflertypedef status_t (*device_open_hook)(const char *name, uint32 flags,
2306ba3f0aSAxel Dörfler	void **cookie);
2406ba3f0aSAxel Dörflertypedef status_t (*device_close_hook)(void *cookie);
2506ba3f0aSAxel Dörflertypedef status_t (*device_free_hook)(void *cookie);
2606ba3f0aSAxel Dörflertypedef status_t (*device_control_hook)(void *cookie, uint32 op, void *data,
2706ba3f0aSAxel Dörfler	size_t len);
2806ba3f0aSAxel Dörflertypedef status_t  (*device_read_hook)(void *cookie, off_t position, void *data,
2906ba3f0aSAxel Dörfler	size_t *numBytes);
3006ba3f0aSAxel Dörflertypedef status_t  (*device_write_hook)(void *cookie, off_t position,
3106ba3f0aSAxel Dörfler	const void *data, size_t *numBytes);
3206ba3f0aSAxel Dörflertypedef status_t (*device_select_hook)(void *cookie, uint8 event, uint32 ref,
3306ba3f0aSAxel Dörfler	selectsync *sync);
3406ba3f0aSAxel Dörflertypedef status_t (*device_deselect_hook)(void *cookie, uint8 event,
3506ba3f0aSAxel Dörfler	selectsync *sync);
3606ba3f0aSAxel Dörflertypedef status_t (*device_read_pages_hook)(void *cookie, off_t position,
3706ba3f0aSAxel Dörfler	const iovec *vec, size_t count, size_t *_numBytes);
3806ba3f0aSAxel Dörflertypedef status_t (*device_write_pages_hook)(void *cookie, off_t position,
3906ba3f0aSAxel Dörfler	const iovec *vec, size_t count, size_t *_numBytes);
4003b27173SDavid Reid
4103b27173SDavid Reid#define	B_CUR_DRIVER_API_VERSION	2
4306ba3f0aSAxel Dörfler/* Legacy driver device hooks */
4452a38012Sejakowatztypedef struct {
459edfb372SAxel Dörfler	device_open_hook		open;			/* called to open the device */
469edfb372SAxel Dörfler	device_close_hook		close;			/* called to close the device */
479edfb372SAxel Dörfler	device_free_hook		free;			/* called to free the cookie */
489edfb372SAxel Dörfler	device_control_hook		control;		/* called to control the device */
499edfb372SAxel Dörfler	device_read_hook		read;			/* reads from the device */
509edfb372SAxel Dörfler	device_write_hook		write;			/* writes to the device */
519edfb372SAxel Dörfler	device_select_hook		select;			/* start select */
529edfb372SAxel Dörfler	device_deselect_hook	deselect;		/* stop select */
5306ba3f0aSAxel Dörfler	device_read_pages_hook	read_pages;
5406ba3f0aSAxel Dörfler		/* scatter-gather physical read from the device */
5506ba3f0aSAxel Dörfler	device_write_pages_hook	write_pages;
5606ba3f0aSAxel Dörfler		/* scatter-gather physical write to the device */
5752a38012Sejakowatz} device_hooks;
5906ba3f0aSAxel Dörfler/* Driver functions needed to be exported by legacy drivers */
6052a38012Sejakowatzstatus_t		init_hardware(void);
6106ba3f0aSAxel Dörflerconst char**	publish_devices(void);
6206ba3f0aSAxel Dörflerdevice_hooks*	find_device(const char* name);
6352a38012Sejakowatzstatus_t		init_driver(void);
6406ba3f0aSAxel Dörflervoid			uninit_driver(void);
6652a38012Sejakowatzextern int32	api_version;
685f79d3a8SDavid Reidenum {
6906ba3f0aSAxel Dörfler	B_GET_DEVICE_SIZE = 1,			/* get # bytes - returns size_t in *data */
7006ba3f0aSAxel Dörfler	B_SET_DEVICE_SIZE,				/* set # bytes - passes size_t in *data */
715f79d3a8SDavid Reid	B_SET_NONBLOCKING_IO,			/* set to non-blocking i/o */
725f79d3a8SDavid Reid	B_SET_BLOCKING_IO,				/* set to blocking i/o */
735f79d3a8SDavid Reid	B_GET_READ_STATUS,				/* check if can read w/o blocking */
7406ba3f0aSAxel Dörfler									/* returns bool in *data */
755f79d3a8SDavid Reid	B_GET_WRITE_STATUS,				/* check if can write w/o blocking */
7606ba3f0aSAxel Dörfler									/* returns bool in *data */
775f79d3a8SDavid Reid	B_GET_GEOMETRY,					/* get info about device geometry */
7806ba3f0aSAxel Dörfler									/* returns struct geometry in *data */
7906ba3f0aSAxel Dörfler	B_GET_DRIVER_FOR_DEVICE,		/* get the path of the executable serving */
8006ba3f0aSAxel Dörfler									/* that device */
815f79d3a8SDavid Reid	B_GET_PARTITION_INFO,			/* get info about a device partition */
8206ba3f0aSAxel Dörfler									/* returns struct partition_info in *data */
8306ba3f0aSAxel Dörfler	B_SET_PARTITION,				/* obsolete, will be removed */
845f79d3a8SDavid Reid	B_FORMAT_DEVICE,				/* low-level device format */
855f79d3a8SDavid Reid	B_EJECT_DEVICE,					/* eject the media if supported */
865f79d3a8SDavid Reid	B_GET_ICON,						/* return device icon (see struct below) */
875f79d3a8SDavid Reid	B_GET_BIOS_GEOMETRY,			/* get info about device geometry */
885f79d3a8SDavid Reid									/* as reported by the bios */
895f79d3a8SDavid Reid									/*   returns struct geometry in *data */
905f79d3a8SDavid Reid	B_GET_MEDIA_STATUS,				/* get status of media. */
915f79d3a8SDavid Reid									/* return status_t in *data: */
925f79d3a8SDavid Reid									/* B_NO_ERROR: media ready */
935f79d3a8SDavid Reid									/* B_DEV_NO_MEDIA: no media */
945f79d3a8SDavid Reid									/* B_DEV_NOT_READY: device not ready */
955f79d3a8SDavid Reid									/* B_DEV_MEDIA_CHANGED: media changed */
965f79d3a8SDavid Reid									/*  since open or last B_GET_MEDIA_STATUS */
975f79d3a8SDavid Reid									/* B_DEV_MEDIA_CHANGE_REQUESTED: user */
985f79d3a8SDavid Reid									/*  pressed button on drive */
995f79d3a8SDavid Reid									/* B_DEV_DOOR_OPEN: door open */
1005f79d3a8SDavid Reid	B_LOAD_MEDIA,					/* load the media if supported */
1015f79d3a8SDavid Reid	B_GET_BIOS_DRIVE_ID,			/* get bios id for this device */
1025f79d3a8SDavid Reid	B_SET_UNINTERRUPTABLE_IO,		/* prevent cntl-C from interrupting i/o */
1035f79d3a8SDavid Reid	B_SET_INTERRUPTABLE_IO,			/* allow cntl-C to interrupt i/o */
1045f79d3a8SDavid Reid	B_FLUSH_DRIVE_CACHE,			/* flush drive cache */
1056210a1ddSFrançois Revol	B_GET_PATH_FOR_DEVICE,			/* get the absolute path of the device */
10606ba3f0aSAxel Dörfler	B_GET_ICON_NAME,				/* get an icon name identifier */
10706ba3f0aSAxel Dörfler	B_GET_VECTOR_ICON,				/* retrieves the device's vector icon */
10851d76425SAxel Dörfler	B_GET_DEVICE_NAME,				/* get name, string buffer */
10929a84508SAxel Dörfler	B_TRIM_DEVICE,					/* trims blocks, see fs_trim_data */
1106210a1ddSFrançois Revol
11106ba3f0aSAxel Dörfler	B_GET_NEXT_OPEN_DEVICE = 1000,	/* obsolete, will be removed */
11206ba3f0aSAxel Dörfler	B_ADD_FIXED_DRIVER,				/* obsolete, will be removed */
11306ba3f0aSAxel Dörfler	B_REMOVE_FIXED_DRIVER,			/* obsolete, will be removed */
1145f79d3a8SDavid Reid
1155f79d3a8SDavid Reid	B_AUDIO_DRIVER_BASE = 8000,		/* base for codes in audio_driver.h */
1165f79d3a8SDavid Reid	B_MIDI_DRIVER_BASE = 8100,		/* base for codes in midi_driver.h */
1175f79d3a8SDavid Reid	B_JOYSTICK_DRIVER_BASE = 8200,	/* base for codes in joystick.h */
1185f79d3a8SDavid Reid	B_GRAPHIC_DRIVER_BASE = 8300,	/* base for codes in graphic_driver.h */
1195f79d3a8SDavid Reid
120626e25b1SMichael Lotz	B_DEVICE_OP_CODES_END = 9999	/* end of Be-defined control ids */
1215f79d3a8SDavid Reid};
1225f79d3a8SDavid Reid
12306ba3f0aSAxel Dörfler/* B_GET_GEOMETRY data structure */
124d7e489f8Sbevelopertypedef struct {
125d7e489f8Sbeveloper	uint32	bytes_per_sector;		/* sector size in bytes */
126d7e489f8Sbeveloper	uint32	sectors_per_track;		/* # sectors per track */
127d7e489f8Sbeveloper	uint32	cylinder_count;			/* # cylinders */
128d7e489f8Sbeveloper	uint32	head_count;				/* # heads */
129d7e489f8Sbeveloper	uchar	device_type;			/* type */
130d7e489f8Sbeveloper	bool	removable;				/* non-zero if removable */
131d7e489f8Sbeveloper	bool	read_only;				/* non-zero if read only */
132d7e489f8Sbeveloper	bool	write_once;				/* non-zero if write-once */
133d7e489f8Sbeveloper} device_geometry;
135d7e489f8Sbeveloperenum {
136d7e489f8Sbeveloper	B_DISK = 0,						/* Hard disks, floppy disks, etc. */
137d7e489f8Sbeveloper	B_TAPE,							/* Tape drives */
138d7e489f8Sbeveloper	B_PRINTER,						/* Printers */
139d7e489f8Sbeveloper	B_CPU,							/* CPU devices */
1406f3c0b6cSFrançois Revol	B_WORM,							/* Write-once, read-many devices */
141d7e489f8Sbeveloper	B_CD,							/* CD ROMS */
142d7e489f8Sbeveloper	B_SCANNER,						/* Scanners */
143d7e489f8Sbeveloper	B_OPTICAL,						/* Optical devices */
144d7e489f8Sbeveloper	B_JUKEBOX,						/* Jukeboxes */
145d7e489f8Sbeveloper	B_NETWORK						/* Network devices */
14906ba3f0aSAxel Dörfler/* B_GET_PARTITION_INFO data structure */
150d7e489f8Sbevelopertypedef struct {
151d7e489f8Sbeveloper	off_t	offset;					/* offset (in bytes) */
152d7e489f8Sbeveloper	off_t	size;					/* size (in bytes) */
153d7e489f8Sbeveloper	int32	logical_block_size;		/* logical block size of partition */
154d7e489f8Sbeveloper	int32	session;				/* id of session */
155d7e489f8Sbeveloper	int32	partition;				/* id of partition */
156d7e489f8Sbeveloper	char	device[256];			/* path to the physical device */
157d7e489f8Sbeveloper} partition_info;
16006ba3f0aSAxel Dörfler/* B_GET_DRIVER_FOR_DEVICE data structure */
161d7e489f8Sbevelopertypedef char	driver_path[256];
16406ba3f0aSAxel Dörfler/* B_GET_ICON, and B_GET_VECTOR_ICON data structure */
165d7e489f8Sbevelopertypedef struct {
16606ba3f0aSAxel Dörfler	int32	icon_size;
16706ba3f0aSAxel Dörfler		/* B_GET_VECTOR_ICON: size of the data buffer in icon_data */
16806ba3f0aSAxel Dörfler		/* B_GET_ICON: size of the icon in pixels */
16906ba3f0aSAxel Dörfler	void	*icon_data;
170d7e489f8Sbeveloper} device_icon;
17329a84508SAxel Dörfler/* B_TRIM_DEVICE data structure */
17429a84508SAxel Dörflertypedef struct {
17599086aa3SAxel Dörfler	uint32	range_count;
17699086aa3SAxel Dörfler	uint64	trimmed_size;			/* filled on return */
17799086aa3SAxel Dörfler	struct range {
17899086aa3SAxel Dörfler		uint64	offset;				/* offset (in bytes) */
17999086aa3SAxel Dörfler		uint64	size;
18099086aa3SAxel Dörfler	} ranges[1];
18129a84508SAxel Dörfler} fs_trim_data;
18229a84508SAxel Dörfler
18329a84508SAxel Dörfler
184f97b4ac4SIngo Weinhold#ifdef __cplusplus
185f97b4ac4SIngo Weinhold}
186f97b4ac4SIngo Weinhold#endif
18851d76425SAxel Dörfler
1895f79d3a8SDavid Reid#endif /* _DRIVERS_DRIVERS_H */