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