Fix FreeBSD build.
[haiku.git] / headers / os / drivers / Drivers.h
bloba854305b38dd56978e2b79a51ae3feb697bdec5b
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
9 #include <sys/types.h>
10 #include <sys/uio.h>
12 #include <BeBuild.h>
13 #include <Select.h>
14 #include <SupportDefs.h>
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
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);
41 #define B_CUR_DRIVER_API_VERSION 2
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;
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);
66 extern int32 api_version;
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 */
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 */
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 */
120 B_DEVICE_OP_CODES_END = 9999 /* end of Be-defined control ids */
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 } device_geometry;
135 enum {
136 B_DISK = 0, /* Hard disks, floppy disks, etc. */
137 B_TAPE, /* Tape drives */
138 B_PRINTER, /* Printers */
139 B_CPU, /* CPU devices */
140 B_WORM, /* Write-once, read-many devices */
141 B_CD, /* CD ROMS */
142 B_SCANNER, /* Scanners */
143 B_OPTICAL, /* Optical devices */
144 B_JUKEBOX, /* Jukeboxes */
145 B_NETWORK /* Network devices */
149 /* B_GET_PARTITION_INFO data structure */
150 typedef struct {
151 off_t offset; /* offset (in bytes) */
152 off_t size; /* size (in bytes) */
153 int32 logical_block_size; /* logical block size of partition */
154 int32 session; /* id of session */
155 int32 partition; /* id of partition */
156 char device[256]; /* path to the physical device */
157 } partition_info;
160 /* B_GET_DRIVER_FOR_DEVICE data structure */
161 typedef char driver_path[256];
164 /* B_GET_ICON, and B_GET_VECTOR_ICON data structure */
165 typedef struct {
166 int32 icon_size;
167 /* B_GET_VECTOR_ICON: size of the data buffer in icon_data */
168 /* B_GET_ICON: size of the icon in pixels */
169 void *icon_data;
170 } device_icon;
173 /* B_TRIM_DEVICE data structure */
174 typedef struct {
175 uint32 range_count;
176 uint64 trimmed_size; /* filled on return */
177 struct range {
178 uint64 offset; /* offset (in bytes) */
179 uint64 size;
180 } ranges[1];
181 } fs_trim_data;
184 #ifdef __cplusplus
186 #endif
189 #endif /* _DRIVERS_DRIVERS_H */