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 device_node_handle (*get_root)(); 81 status_t (*get_next_child_device)(device_node_handle parent, 82 device_node_handle *_node, const device_attr *attrs); 83 device_node_handle (*get_parent)(device_node_handle node); 84 void (*put_device_node)(device_node_handle node); 85 86 status_t (*acquire_io_resources)(io_resource *resources, 87 io_resource_handle *handles); 88 status_t (*release_io_resources)(const io_resource_handle *handles); 89 90 int32 (*create_id)(const char *generator); 91 status_t (*free_id)(const char *generator, uint32 id); 92 93 status_t (*get_attr_uint8)(device_node_handle node, 94 const char *name, uint8 *value, bool recursive); 95 status_t (*get_attr_uint16)(device_node_handle node, 96 const char *name, uint16 *value, bool recursive); 97 status_t (*get_attr_uint32)(device_node_handle node, 98 const char *name, uint32 *value, bool recursive); 99 status_t (*get_attr_uint64)(device_node_handle node, 100 const char *name, uint64 *value, bool recursive); 101 status_t (*get_attr_string)(device_node_handle node, 102 const char *name, char **value, bool recursive); 103 status_t (*get_attr_raw)(device_node_handle node, 104 const char *name, void **data, size_t *_size, 105 bool recursive); 106 107 status_t (*get_next_attr)(device_node_handle node, 108 device_attr_handle *attrHandle); 109 status_t (*release_attr)(device_node_handle node, 110 device_attr_handle attr_handle); 111 status_t (*retrieve_attr)(device_attr_handle attr_handle, 112 const device_attr **attr); 113 status_t (*write_attr)(device_node_handle node, 114 const device_attr *attr); 115 status_t (*remove_attr)(device_node_handle node, const char *name); 116 } device_manager_info; 117 118 119 #define B_DEVICE_MANAGER_MODULE_NAME "system/device_manager/v1" 120 121 122 // interface of device driver 123 124 struct driver_module_info { 125 module_info info; 126 127 float (*supports_device)(device_node_handle parent, bool *_noConnection); 128 status_t (*register_device)(device_node_handle parent); 129 130 status_t (*init_driver)(device_node_handle node, void *user_cookie, void **_cookie); 131 status_t (*uninit_driver)(void *cookie); 132 133 void (*device_removed)(device_node_handle node, void *cookie); 134 void (*device_cleanup)(device_node_handle node); 135 136 void (*get_supported_paths)(const char ***_busses, const char ***_devices); 137 }; 138 139 140 // standard device node attributes 141 142 #define PNP_MANAGER_ID_GENERATOR "id_generator" 143 // if you are using an id generator (see create_id), you can let the 144 // manager automatically free the id when the node is deleted by setting 145 // the following attributes: 146 // name of generator (string) 147 #define PNP_MANAGER_AUTO_ID "auto_id" 148 // generated id (uint32) 149 150 #define B_DRIVER_MODULE "driver/module" 151 #define B_DRIVER_PRETTY_NAME "driver/pretty name" 152 #define B_DRIVER_FIXED_CHILD "driver/fixed child" 153 #define B_DRIVER_MAPPING "driver/mapping" 154 #define B_DRIVER_BUS "driver/bus" 155 #define B_DRIVER_FIND_DEVICES_ON_DEMAND "driver/on demand" 156 #define B_DRIVER_EXPLORE_LAST "driver/explore last" 157 158 #define B_DRIVER_UNIQUE_DEVICE_ID "unique id" 159 #define B_DRIVER_DEVICE_TYPE "device type" 160 161 #define B_AUDIO_DRIVER_TYPE "audio" 162 #define B_BUS_DRIVER_TYPE "bus" 163 #define B_DISK_DRIVER_TYPE "disk" 164 #define B_GRAPHICS_DRIVER_TYPE "graphics" 165 #define B_INPUT_DRIVER_TYPE "input" 166 #define B_MISC_DRIVER_TYPE "misc" 167 #define B_NETWORK_DRIVER_TYPE "net" 168 #define B_VIDEO_DRIVER_TYPE "video" 169 #define B_INTERRUPT_CONTROLLER_DRIVER_TYPE "interrupt controller" 170 171 #define PNP_DRIVER_CONNECTION "connection" 172 // connection of parent the device is attached to (optional, string) 173 // there can be only one device per connection 174 175 176 // interface of a bus device driver 177 178 typedef struct bus_module_info { 179 driver_module_info info; 180 181 // scan the bus and register all devices. 182 status_t (*register_child_devices)(void *cookie); 183 184 // user initiated rescan of the bus - only propagate changes 185 // you only need to implement this, if you cannot detect device changes yourself 186 // driver is always loaded during this call, but other hooks may 187 // be called concurrently 188 status_t (*rescan_bus)(void *cookie); 189 } bus_module_info; 190 191 192 // standard attributes 193 194 // PnP bus identification (required, uint8) 195 // define this to let the PnP manager know that this is a PnP bus 196 // the actual content is ignored 197 #define PNP_BUS_IS_BUS "bus/is_bus" 198 199 #endif /* _DEVICE_MANAGER_H */ 200