Drivers.h revision 085320ea
15f79d3a8SDavid Reid#ifndef _DRIVERS_DRIVERS_H
25f79d3a8SDavid Reid#define _DRIVERS_DRIVERS_H
352a38012Sejakowatz
4085320eaSAxel Dörfler#include <sys/types.h>
552a38012Sejakowatz#include <defines.h>
603b27173SDavid Reid#include <sys/uio.h>
752a38012Sejakowatz
852a38012Sejakowatz/* ---
952a38012Sejakowatz	these hooks are how the kernel accesses the device
1052a38012Sejakowatz--- */
1152a38012Sejakowatz
1252a38012Sejakowatzstruct selectsync;
1352a38012Sejakowatztypedef struct selectsync selectsync;
1452a38012Sejakowatz
1552a38012Sejakowatztypedef status_t (*device_open_hook) (const char *name, uint32 flags, void **cookie);
1652a38012Sejakowatztypedef status_t (*device_close_hook) (void *cookie);
1752a38012Sejakowatztypedef status_t (*device_free_hook) (void *cookie);
1852a38012Sejakowatztypedef status_t (*device_control_hook) (void *cookie, uint32 op, void *data,
1952a38012Sejakowatz                                         size_t len);
2052a38012Sejakowatztypedef ssize_t  (*device_read_hook) (void *cookie, off_t position, void *data,
2152a38012Sejakowatz                                      size_t *numBytes);
2252a38012Sejakowatztypedef ssize_t  (*device_write_hook) (void *cookie, off_t position,
2352a38012Sejakowatz                                       const void *data, size_t *numBytes);
2452a38012Sejakowatztypedef status_t (*device_select_hook) (void *cookie, uint8 event, uint32 ref,
2552a38012Sejakowatz                                        selectsync *sync);
2652a38012Sejakowatztypedef status_t (*device_deselect_hook) (void *cookie, uint8 event,
2752a38012Sejakowatz                                          selectsync *sync);
2852a38012Sejakowatztypedef status_t (*device_readv_hook) (void *cookie, off_t position, const iovec *vec,
2952a38012Sejakowatz					size_t count, size_t *numBytes);
3052a38012Sejakowatztypedef status_t (*device_writev_hook) (void *cookie, off_t position, const iovec *vec,
3152a38012Sejakowatz					size_t count, size_t *numBytes);
3203b27173SDavid Reid
3303b27173SDavid Reid#define	B_CUR_DRIVER_API_VERSION	2
3452a38012Sejakowatz
3552a38012Sejakowatz/* ---
3652a38012Sejakowatz	the device_hooks structure is a descriptor for the device, giving its
3752a38012Sejakowatz	entry points.
3852a38012Sejakowatz--- */
3952a38012Sejakowatz
4052a38012Sejakowatztypedef struct {
4152a38012Sejakowatz	device_open_hook		open;		/* called to open the device */
4252a38012Sejakowatz	device_close_hook		close;		/* called to close the device */
4352a38012Sejakowatz	device_free_hook		free;		/* called to free the cookie */
4452a38012Sejakowatz	device_control_hook		control;	/* called to control the device */
4552a38012Sejakowatz	device_read_hook		read;		/* reads from the device */
4652a38012Sejakowatz	device_write_hook		write;		/* writes to the device */
4752a38012Sejakowatz	device_select_hook		select;		/* start select */
4852a38012Sejakowatz	device_deselect_hook	deselect;	/* stop select */
4903b27173SDavid Reid	device_readv_hook		readv;		/* scatter-gather read from the device */
5003b27173SDavid Reid	device_writev_hook		writev;		/* scatter-gather write to the device */
5152a38012Sejakowatz} device_hooks;
5252a38012Sejakowatz
5352a38012Sejakowatzstatus_t		init_hardware(void);
5452a38012Sejakowatzconst char	  **publish_devices(void);
5552a38012Sejakowatzdevice_hooks	*find_device(const char *name);
5652a38012Sejakowatzstatus_t		init_driver(void);
5752a38012Sejakowatzvoid			uninit_driver(void);
5852a38012Sejakowatz
5952a38012Sejakowatzextern int32	api_version;
6052a38012Sejakowatz
6152a38012Sejakowatzenum {
6252a38012Sejakowatz	// called on partition device to get info
6352a38012Sejakowatz	IOCTL_DEVFS_GET_PARTITION_INFO = 1000,
6452a38012Sejakowatz	// called on raw device to declare one partition
6552a38012Sejakowatz	IOCTL_DEVFS_SET_PARTITION,
6652a38012Sejakowatz};
6752a38012Sejakowatz
6852a38012Sejakowatztypedef struct devfs_partition_info {
6952a38012Sejakowatz	// offset and size relative to raw device in bytes
7052a38012Sejakowatz	off_t offset;
7152a38012Sejakowatz	off_t size;
7252a38012Sejakowatz
7352a38012Sejakowatz	// logical block size in bytes
7452a38012Sejakowatz	uint32 logical_block_size;
7552a38012Sejakowatz
7652a38012Sejakowatz	// session/partition id
7752a38012Sejakowatz	uint32 session;
7852a38012Sejakowatz	uint32 partition;
7952a38012Sejakowatz
8052a38012Sejakowatz	// path of raw device (GET_PARTITION_INFO only)
8152a38012Sejakowatz	char raw_device[SYS_MAX_PATH_LEN];
8252a38012Sejakowatz} devfs_partition_info;
8352a38012Sejakowatz
845f79d3a8SDavid Reidenum {
855f79d3a8SDavid Reid	B_GET_DEVICE_SIZE = 1,			/* get # bytes */
865f79d3a8SDavid Reid									/*   returns size_t in *data */
875f79d3a8SDavid Reid
885f79d3a8SDavid Reid	B_SET_DEVICE_SIZE,				/* set # bytes */
895f79d3a8SDavid Reid									/*   passed size_t in *data */
905f79d3a8SDavid Reid
915f79d3a8SDavid Reid	B_SET_NONBLOCKING_IO,			/* set to non-blocking i/o */
925f79d3a8SDavid Reid
935f79d3a8SDavid Reid	B_SET_BLOCKING_IO,				/* set to blocking i/o */
945f79d3a8SDavid Reid
955f79d3a8SDavid Reid	B_GET_READ_STATUS,				/* check if can read w/o blocking */
965f79d3a8SDavid Reid									/*   returns bool in *data */
975f79d3a8SDavid Reid
985f79d3a8SDavid Reid	B_GET_WRITE_STATUS,				/* check if can write w/o blocking */
995f79d3a8SDavid Reid									/*   returns bool in *data */
1005f79d3a8SDavid Reid
1015f79d3a8SDavid Reid	B_GET_GEOMETRY,					/* get info about device geometry */
1025f79d3a8SDavid Reid									/*   returns struct geometry in *data */
1035f79d3a8SDavid Reid
1045f79d3a8SDavid Reid	B_GET_DRIVER_FOR_DEVICE,		/* get the path of the executable serving that device */
1055f79d3a8SDavid Reid
1065f79d3a8SDavid Reid	B_GET_PARTITION_INFO,			/* get info about a device partition */
1075f79d3a8SDavid Reid									/*   returns struct partition_info in *data */
1085f79d3a8SDavid Reid
1095f79d3a8SDavid Reid	B_SET_PARTITION,				/* create a user-defined partition */
1105f79d3a8SDavid Reid
1115f79d3a8SDavid Reid	B_FORMAT_DEVICE,				/* low-level device format */
1125f79d3a8SDavid Reid
1135f79d3a8SDavid Reid	B_EJECT_DEVICE,					/* eject the media if supported */
1145f79d3a8SDavid Reid
1155f79d3a8SDavid Reid	B_GET_ICON,						/* return device icon (see struct below) */
1165f79d3a8SDavid Reid
1175f79d3a8SDavid Reid	B_GET_BIOS_GEOMETRY,			/* get info about device geometry */
1185f79d3a8SDavid Reid									/* as reported by the bios */
1195f79d3a8SDavid Reid									/*   returns struct geometry in *data */
1205f79d3a8SDavid Reid
1215f79d3a8SDavid Reid	B_GET_MEDIA_STATUS,				/* get status of media. */
1225f79d3a8SDavid Reid									/* return status_t in *data: */
1235f79d3a8SDavid Reid									/* B_NO_ERROR: media ready */
1245f79d3a8SDavid Reid									/* B_DEV_NO_MEDIA: no media */
1255f79d3a8SDavid Reid									/* B_DEV_NOT_READY: device not ready */
1265f79d3a8SDavid Reid									/* B_DEV_MEDIA_CHANGED: media changed */
1275f79d3a8SDavid Reid									/*  since open or last B_GET_MEDIA_STATUS */
1285f79d3a8SDavid Reid									/* B_DEV_MEDIA_CHANGE_REQUESTED: user */
1295f79d3a8SDavid Reid									/*  pressed button on drive */
1305f79d3a8SDavid Reid									/* B_DEV_DOOR_OPEN: door open */
1315f79d3a8SDavid Reid
1325f79d3a8SDavid Reid	B_LOAD_MEDIA,					/* load the media if supported */
1335f79d3a8SDavid Reid
1345f79d3a8SDavid Reid	B_GET_BIOS_DRIVE_ID,			/* get bios id for this device */
1355f79d3a8SDavid Reid
1365f79d3a8SDavid Reid	B_SET_UNINTERRUPTABLE_IO,		/* prevent cntl-C from interrupting i/o */
1375f79d3a8SDavid Reid	B_SET_INTERRUPTABLE_IO,			/* allow cntl-C to interrupt i/o */
1385f79d3a8SDavid Reid
1395f79d3a8SDavid Reid	B_FLUSH_DRIVE_CACHE,			/* flush drive cache */
1405f79d3a8SDavid Reid
1415f79d3a8SDavid Reid	B_GET_NEXT_OPEN_DEVICE = 1000,	/* iterate through open devices */
1425f79d3a8SDavid Reid	B_ADD_FIXED_DRIVER,				/* private */
1435f79d3a8SDavid Reid	B_REMOVE_FIXED_DRIVER,			/* private */
1445f79d3a8SDavid Reid
1455f79d3a8SDavid Reid	B_AUDIO_DRIVER_BASE = 8000,		/* base for codes in audio_driver.h */
1465f79d3a8SDavid Reid	B_MIDI_DRIVER_BASE = 8100,		/* base for codes in midi_driver.h */
1475f79d3a8SDavid Reid	B_JOYSTICK_DRIVER_BASE = 8200,	/* base for codes in joystick.h */
1485f79d3a8SDavid Reid	B_GRAPHIC_DRIVER_BASE = 8300,	/* base for codes in graphic_driver.h */
1495f79d3a8SDavid Reid
1505f79d3a8SDavid Reid	B_DEVICE_OP_CODES_END = 9999	/* end of Be-defined contol id's */
1515f79d3a8SDavid Reid};
1525f79d3a8SDavid Reid
1535f79d3a8SDavid Reid#endif /* _DRIVERS_DRIVERS_H */
154