1 /* 2 * Copyright 2004-2005, Haiku Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT license. 4 */ 5 #ifndef _DEVICE_MANAGER_H 6 #define _DEVICE_MANAGER_H 7 8 9 #include <TypeConstants.h> 10 #include <Drivers.h> 11 #include <module.h> 12 13 14 // type of I/O resource 15 enum { 16 IO_MEM = 1, 17 IO_PORT = 2, 18 ISA_DMA_CHANNEL = 3 19 }; 20 21 22 // I/O resource description 23 typedef struct { 24 uint32 type; 25 // type of I/O resource 26 27 uint32 base; 28 // I/O memory: first physical address (32 bit) 29 // I/O port: first port address (16 bit) 30 // ISA DMA channel: channel number (0-7) 31 32 uint32 length; 33 // I/O memory: size of address range (32 bit) 34 // I/O port: size of port range (16 bit) 35 // ISA DMA channel: must be 1 36 } io_resource; 37 38 // attribute of a device node 39 typedef struct { 40 const char *name; 41 type_code type; // for supported types, see value 42 union { 43 uint8 ui8; // B_UINT8_TYPE 44 uint16 ui16; // B_UINT16_TYPE 45 uint32 ui32; // B_UINT32_TYPE 46 uint64 ui64; // B_UINT64_TYPE 47 const char *string; // B_STRING_TYPE 48 struct { // B_RAW_TYPE 49 void *data; 50 size_t length; 51 } raw; 52 } value; 53 } device_attr; 54 55 56 typedef struct device_node_info *device_node_handle; 57 typedef struct io_resource_info *io_resource_handle; 58 typedef struct device_attr_info *device_attr_handle; 59 60 typedef struct driver_module_info driver_module_info; 61 62 63 // interface of the device manager 64 65 typedef struct device_manager_info { 66 module_info info; 67 68 status_t (*init_driver)(device_node_handle node, void *userCookie, 69 driver_module_info **interface, void **cookie); 70 status_t (*uninit_driver)(device_node_handle node); 71 72 status_t (*rescan)(device_node_handle node); 73 74 status_t (*register_device)(device_node_handle parent, 75 const device_attr *attrs, 76 const io_resource_handle *io_resources, 77 device_node_handle *node); 78 status_t (*unregister_device)(device_node_handle node); 79 80 status_t (*get_next_child_device)(device_node_handle parent, 81 device_node_handle *_node, const device_attr *attrs); 82 device_node_handle (*get_parent)(device_node_handle node); 83 void (*put_device_node)(device_node_handle node); 84 85 status_t (*acquire_io_resources)(io_resource *resources, 86 io_resource_handle *handles); 87 status_t (*release_io_resources)(const io_resource_handle *handles); 88 89 int32 (*create_id)(const char *generator); 90 status_t (*free_id)(const char *generator, uint32 id); 91 92 status_t (*get_attr_uint8)(device_node_handle node, 93 const char *name, uint8 *value, bool recursive); 94 status_t (*get_attr_uint16)(device_node_handle node, 95 const char *name, uint16 *value, bool recursive); 96 status_t (*get_attr_uint32)(device_node_handle node, 97 const char *name, uint32 *value, bool recursive); 98 status_t (*get_attr_uint64)(device_node_handle node, 99 const char *name, uint64 *value, bool recursive); 100 status_t (*get_attr_string)(device_node_handle node, 101 const char *name, char **value, bool recursive); 102 status_t (*get_attr_raw)(device_node_handle node, 103 const char *name, void **data, size_t *_size, 104 bool recursive); 105 106 status_t (*get_next_attr)(device_node_handle node, 107 device_attr_handle *attrHandle); 108 status_t (*release_attr)(device_node_handle node, 109 device_attr_handle attr_handle); 110 status_t (*retrieve_attr)(device_attr_handle attr_handle, 111 const device_attr **attr); 112 status_t (*write_attr)(device_node_handle node, 113 const device_attr *attr); 114 status_t (*remove_attr)(device_node_handle node, const char *name); 115 } device_manager_info; 116 117 118 #define B_DEVICE_MANAGER_MODULE_NAME "system/device_manager/v1" 119 120 121 // interface of device driver 122 123 struct driver_module_info { 124 module_info info; 125 126 float (*supports_device)(device_node_handle parent, bool *_noConnection); 127 status_t (*register_device)(device_node_handle parent); 128 129 status_t (*init_driver)(device_node_handle node, void *user_cookie, void **_cookie); 130 status_t (*uninit_driver)(void *cookie); 131 132 void (*device_removed)(device_node_handle node, void *cookie); 133 void (*device_cleanup)(device_node_handle node); 134 135 void (*get_supported_paths)(const char ***_busses, const char ***_devices); 136 }; 137 138 139 // standard device node attributes 140 141 #define PNP_MANAGER_ID_GENERATOR "id_generator" 142 // if you are using an id generator (see create_id), you can let the 143 // manager automatically free the id when the node is deleted by setting 144 // the following attributes: 145 // name of generator (string) 146 #define PNP_MANAGER_AUTO_ID "auto_id" 147 // generated id (uint32) 148 149 #define B_DRIVER_MODULE "driver/module" 150 #define B_DRIVER_PRETTY_NAME "driver/pretty name" 151 #define B_DRIVER_FIXED_CHILD "driver/fixed child" 152 #define B_DRIVER_MAPPING "driver/mapping" 153 #define B_DRIVER_BUS "driver/bus" 154 #define B_DRIVER_FIND_DEVICES_ON_DEMAND "driver/on demand" 155 #define B_DRIVER_EXPLORE_LAST "driver/explore last" 156 157 #define B_DRIVER_UNIQUE_DEVICE_ID "unique id" 158 #define B_DRIVER_DEVICE_TYPE "device type" 159 160 #define B_AUDIO_DRIVER_TYPE "audio" 161 #define B_BUS_DRIVER_TYPE "bus" 162 #define B_DISK_DRIVER_TYPE "disk" 163 #define B_GRAPHICS_DRIVER_TYPE "graphics" 164 #define B_INPUT_DRIVER_TYPE "input" 165 #define B_MISC_DRIVER_TYPE "misc" 166 #define B_NETWORK_DRIVER_TYPE "net" 167 #define B_VIDEO_DRIVER_TYPE "video" 168 169 #define PNP_DRIVER_CONNECTION "connection" 170 // connection of parent the device is attached to (optional, string) 171 // there can be only one device per connection 172 173 174 // interface of a bus device driver 175 176 typedef struct bus_module_info { 177 driver_module_info info; 178 179 // scan the bus and register all devices. 180 status_t (*register_child_devices)(void *cookie); 181 182 // user initiated rescan of the bus - only propagate changes 183 // you only need to implement this, if you cannot detect device changes yourself 184 // driver is always loaded during this call, but other hooks may 185 // be called concurrently 186 status_t (*rescan_bus)(void *cookie); 187 } bus_module_info; 188 189 190 // standard attributes 191 192 // PnP bus identification (required, uint8) 193 // define this to let the PnP manager know that this is a PnP bus 194 // the actual content is ignored 195 #define PNP_BUS_IS_BUS "bus/is_bus" 196 197 #endif /* _DEVICE_MANAGER_H */ 198