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 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 /* --- 14 these hooks are how the kernel accesses the device 15 --- */ 16 17 // XXX hack, this is also in private/kernel/defines.h 18 #ifndef SYS_MAX_PATH_LEN 19 #define SYS_MAX_PATH_LEN 512 20 #endif 21 22 struct selectsync; 23 typedef struct selectsync selectsync; 24 25 typedef status_t (*device_open_hook) (const char *name, uint32 flags, void **cookie); 26 typedef status_t (*device_close_hook) (void *cookie); 27 typedef status_t (*device_free_hook) (void *cookie); 28 typedef status_t (*device_control_hook) (void *cookie, uint32 op, void *data, 29 size_t len); 30 typedef ssize_t (*device_read_hook) (void *cookie, off_t position, void *data, 31 size_t *numBytes); 32 typedef ssize_t (*device_write_hook) (void *cookie, off_t position, 33 const void *data, size_t *numBytes); 34 typedef status_t (*device_select_hook) (void *cookie, uint8 event, uint32 ref, 35 selectsync *sync); 36 typedef status_t (*device_deselect_hook) (void *cookie, uint8 event, 37 selectsync *sync); 38 typedef status_t (*device_readv_hook) (void *cookie, off_t position, const iovec *vec, 39 size_t count, size_t *numBytes); 40 typedef status_t (*device_writev_hook) (void *cookie, off_t position, const iovec *vec, 41 size_t count, size_t *numBytes); 42 43 #define B_CUR_DRIVER_API_VERSION 2 44 45 /* --- 46 the device_hooks structure is a descriptor for the device, giving its 47 entry points. 48 --- */ 49 50 typedef struct { 51 device_open_hook open; /* called to open the device */ 52 device_close_hook close; /* called to close the device */ 53 device_free_hook free; /* called to free the cookie */ 54 device_control_hook control; /* called to control the device */ 55 device_read_hook read; /* reads from the device */ 56 device_write_hook write; /* writes to the device */ 57 device_select_hook select; /* start select */ 58 device_deselect_hook deselect; /* stop select */ 59 device_readv_hook readv; /* scatter-gather read from the device */ 60 device_writev_hook writev; /* scatter-gather write to the device */ 61 } device_hooks; 62 63 status_t init_hardware(void); 64 const char **publish_devices(void); 65 device_hooks *find_device(const char *name); 66 status_t init_driver(void); 67 void uninit_driver(void); 68 69 extern int32 api_version; 70 71 enum { 72 // called on partition device to get info 73 IOCTL_DEVFS_GET_PARTITION_INFO = 1000, 74 // called on raw device to declare one partition 75 IOCTL_DEVFS_SET_PARTITION, 76 }; 77 78 typedef struct devfs_partition_info { 79 // offset and size relative to raw device in bytes 80 off_t offset; 81 off_t size; 82 83 // logical block size in bytes 84 uint32 logical_block_size; 85 86 // session/partition id 87 uint32 session; 88 uint32 partition; 89 90 // path of raw device (GET_PARTITION_INFO only) 91 char raw_device[SYS_MAX_PATH_LEN]; 92 } devfs_partition_info; 93 94 enum { 95 B_GET_DEVICE_SIZE = 1, /* get # bytes */ 96 /* returns size_t in *data */ 97 98 B_SET_DEVICE_SIZE, /* set # bytes */ 99 /* passed size_t in *data */ 100 101 B_SET_NONBLOCKING_IO, /* set to non-blocking i/o */ 102 103 B_SET_BLOCKING_IO, /* set to blocking i/o */ 104 105 B_GET_READ_STATUS, /* check if can read w/o blocking */ 106 /* returns bool in *data */ 107 108 B_GET_WRITE_STATUS, /* check if can write w/o blocking */ 109 /* returns bool in *data */ 110 111 B_GET_GEOMETRY, /* get info about device geometry */ 112 /* returns struct geometry in *data */ 113 114 B_GET_DRIVER_FOR_DEVICE, /* get the path of the executable serving that device */ 115 116 B_GET_PARTITION_INFO, /* get info about a device partition */ 117 /* returns struct partition_info in *data */ 118 119 B_SET_PARTITION, /* create a user-defined partition */ 120 121 B_FORMAT_DEVICE, /* low-level device format */ 122 123 B_EJECT_DEVICE, /* eject the media if supported */ 124 125 B_GET_ICON, /* return device icon (see struct below) */ 126 127 B_GET_BIOS_GEOMETRY, /* get info about device geometry */ 128 /* as reported by the bios */ 129 /* returns struct geometry in *data */ 130 131 B_GET_MEDIA_STATUS, /* get status of media. */ 132 /* return status_t in *data: */ 133 /* B_NO_ERROR: media ready */ 134 /* B_DEV_NO_MEDIA: no media */ 135 /* B_DEV_NOT_READY: device not ready */ 136 /* B_DEV_MEDIA_CHANGED: media changed */ 137 /* since open or last B_GET_MEDIA_STATUS */ 138 /* B_DEV_MEDIA_CHANGE_REQUESTED: user */ 139 /* pressed button on drive */ 140 /* B_DEV_DOOR_OPEN: door open */ 141 142 B_LOAD_MEDIA, /* load the media if supported */ 143 144 B_GET_BIOS_DRIVE_ID, /* get bios id for this device */ 145 146 B_SET_UNINTERRUPTABLE_IO, /* prevent cntl-C from interrupting i/o */ 147 B_SET_INTERRUPTABLE_IO, /* allow cntl-C to interrupt i/o */ 148 149 B_FLUSH_DRIVE_CACHE, /* flush drive cache */ 150 151 B_GET_NEXT_OPEN_DEVICE = 1000, /* iterate through open devices */ 152 B_ADD_FIXED_DRIVER, /* private */ 153 B_REMOVE_FIXED_DRIVER, /* private */ 154 155 B_AUDIO_DRIVER_BASE = 8000, /* base for codes in audio_driver.h */ 156 B_MIDI_DRIVER_BASE = 8100, /* base for codes in midi_driver.h */ 157 B_JOYSTICK_DRIVER_BASE = 8200, /* base for codes in joystick.h */ 158 B_GRAPHIC_DRIVER_BASE = 8300, /* base for codes in graphic_driver.h */ 159 160 B_DEVICE_OP_CODES_END = 9999 /* end of Be-defined contol id's */ 161 }; 162 163 /* --- 164 geometry structure for the B_GET_GEOMETRY opcode 165 --- */ 166 167 typedef struct { 168 uint32 bytes_per_sector; /* sector size in bytes */ 169 uint32 sectors_per_track; /* # sectors per track */ 170 uint32 cylinder_count; /* # cylinders */ 171 uint32 head_count; /* # heads */ 172 uchar device_type; /* type */ 173 bool removable; /* non-zero if removable */ 174 bool read_only; /* non-zero if read only */ 175 bool write_once; /* non-zero if write-once */ 176 } device_geometry; 177 178 179 /* --- 180 Be-defined device types returned by B_GET_GEOMETRY. Use these if it makes 181 sense for your device. 182 --- */ 183 184 enum { 185 B_DISK = 0, /* Hard disks, floppy disks, etc. */ 186 B_TAPE, /* Tape drives */ 187 B_PRINTER, /* Printers */ 188 B_CPU, /* CPU devices */ 189 B_WORM, /* Write-once, read-many devives */ 190 B_CD, /* CD ROMS */ 191 B_SCANNER, /* Scanners */ 192 B_OPTICAL, /* Optical devices */ 193 B_JUKEBOX, /* Jukeboxes */ 194 B_NETWORK /* Network devices */ 195 }; 196 197 198 /* --- 199 partition_info structure used by B_GET_PARTITION_INFO and B_SET_PARTITION 200 --- */ 201 202 typedef struct { 203 off_t offset; /* offset (in bytes) */ 204 off_t size; /* size (in bytes) */ 205 int32 logical_block_size; /* logical block size of partition */ 206 int32 session; /* id of session */ 207 int32 partition; /* id of partition */ 208 char device[256]; /* path to the physical device */ 209 } partition_info; 210 211 /* --- 212 driver_path structure returned by the B_GET_DRIVER_FOR_DEVICE 213 --- */ 214 215 typedef char driver_path[256]; 216 217 218 /* --- 219 open_device_iterator structure used by the B_GET_NEXT_OPEN_DEVICE opcode 220 --- */ 221 222 typedef struct { 223 uint32 cookie; /* must be set to 0 before iterating */ 224 char device[256]; /* device path */ 225 } open_device_iterator; 226 227 228 /* --- 229 icon structure for the B_GET_ICON opcode 230 --- */ 231 232 typedef struct { 233 int32 icon_size; /* icon size requested */ 234 void *icon_data; /* where to put 'em (usually BBitmap->Bits()) */ 235 } device_icon; 236 237 238 #ifdef __cplusplus 239 } 240 #endif 241 242 #endif /* _DRIVERS_DRIVERS_H */ 243