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 18 extern "C" { 19 #endif 20 21 /* These hooks are how the kernel accesses legacy devices */ 22 typedef status_t (*device_open_hook)(const char *name, uint32 flags, 23 void **cookie); 24 typedef status_t (*device_close_hook)(void *cookie); 25 typedef status_t (*device_free_hook)(void *cookie); 26 typedef status_t (*device_control_hook)(void *cookie, uint32 op, void *data, 27 size_t len); 28 typedef status_t (*device_read_hook)(void *cookie, off_t position, void *data, 29 size_t *numBytes); 30 typedef status_t (*device_write_hook)(void *cookie, off_t position, 31 const void *data, size_t *numBytes); 32 typedef status_t (*device_select_hook)(void *cookie, uint8 event, uint32 ref, 33 selectsync *sync); 34 typedef status_t (*device_deselect_hook)(void *cookie, uint8 event, 35 selectsync *sync); 36 typedef status_t (*device_read_pages_hook)(void *cookie, off_t position, 37 const iovec *vec, size_t count, size_t *_numBytes); 38 typedef 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 */ 44 typedef 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 */ 60 status_t init_hardware(void); 61 const char** publish_devices(void); 62 device_hooks* find_device(const char* name); 63 status_t init_driver(void); 64 void uninit_driver(void); 65 66 extern int32 api_version; 67 68 enum { 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 */ 124 typedef 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 uint32 bytes_per_physical_sector; /* physical sector size in bytes */ 134 } device_geometry; 135 136 enum { 137 B_DISK = 0, /* Hard disks, floppy disks, etc. */ 138 B_TAPE, /* Tape drives */ 139 B_PRINTER, /* Printers */ 140 B_CPU, /* CPU devices */ 141 B_WORM, /* Write-once, read-many devices */ 142 B_CD, /* CD ROMS */ 143 B_SCANNER, /* Scanners */ 144 B_OPTICAL, /* Optical devices */ 145 B_JUKEBOX, /* Jukeboxes */ 146 B_NETWORK /* Network devices */ 147 }; 148 149 150 /* B_GET_PARTITION_INFO data structure */ 151 typedef struct { 152 off_t offset; /* offset (in bytes) */ 153 off_t size; /* size (in bytes) */ 154 int32 logical_block_size; /* logical block size of partition */ 155 int32 physical_block_size; /* physical block size of partition */ 156 int32 session; /* id of session */ 157 int32 partition; /* id of partition */ 158 char device[256]; /* path to the physical device */ 159 } partition_info; 160 161 162 /* B_GET_DRIVER_FOR_DEVICE data structure */ 163 typedef char driver_path[256]; 164 165 166 /* B_GET_ICON, and B_GET_VECTOR_ICON data structure */ 167 typedef struct { 168 int32 icon_size; 169 /* B_GET_VECTOR_ICON: size of the data buffer in icon_data */ 170 /* B_GET_ICON: size of the icon in pixels */ 171 void *icon_data; 172 } device_icon; 173 174 175 /* B_TRIM_DEVICE data structure */ 176 typedef struct { 177 uint32 range_count; 178 uint64 trimmed_size; /* filled on return */ 179 struct range { 180 uint64 offset; /* offset (in bytes) */ 181 uint64 size; 182 } ranges[1]; 183 } fs_trim_data; 184 185 186 #ifdef __cplusplus 187 } 188 #endif 189 190 191 #endif /* _DRIVERS_DRIVERS_H */ 192