1 /* 2 * Copyright 2004-2008, 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 B_IO_MEMORY = 1, 17 B_IO_PORT = 2, 18 B_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 33 uint32 length; 34 /* I/O memory: size of address range (32 bit) 35 * I/O port: size of port range (16 bit) 36 * ISA DMA channel: must be 1 37 */ 38 } io_resource; 39 40 /* attribute of a device node */ 41 typedef struct { 42 const char *name; 43 type_code type; /* for supported types, see value */ 44 union { 45 uint8 ui8; /* B_UINT8_TYPE */ 46 uint16 ui16; /* B_UINT16_TYPE */ 47 uint32 ui32; /* B_UINT32_TYPE */ 48 uint64 ui64; /* B_UINT64_TYPE */ 49 const char *string; /* B_STRING_TYPE */ 50 struct { /* B_RAW_TYPE */ 51 const void *data; 52 size_t length; 53 } raw; 54 } value; 55 } device_attr; 56 57 58 typedef struct device_node device_node; 59 typedef struct driver_module_info driver_module_info; 60 61 62 /* interface of the device manager */ 63 64 typedef struct device_manager_info { 65 module_info info; 66 67 status_t (*rescan_node)(device_node *node); 68 69 status_t (*register_node)(device_node *parent, const char *moduleName, 70 const device_attr *attrs, const io_resource *ioResources, 71 device_node **_node); 72 status_t (*unregister_node)(device_node *node); 73 74 status_t (*get_driver)(device_node *node, driver_module_info **_module, 75 void **_cookie); 76 77 device_node *(*get_root_node)(); 78 status_t (*get_next_child_node)(device_node *parent, 79 const device_attr *attrs, device_node **node); 80 device_node *(*get_parent_node)(device_node *node); 81 void (*put_node)(device_node *node); 82 83 status_t (*publish_device)(device_node *node, const char *path, 84 const char *deviceModuleName); 85 status_t (*unpublish_device)(device_node *node, const char *path); 86 87 int32 (*create_id)(const char *generator); 88 status_t (*free_id)(const char *generator, uint32 id); 89 90 status_t (*get_attr_uint8)(const device_node *node, const char *name, 91 uint8 *value, bool recursive); 92 status_t (*get_attr_uint16)(const device_node *node, const char *name, 93 uint16 *value, bool recursive); 94 status_t (*get_attr_uint32)(const device_node *node, const char *name, 95 uint32 *value, bool recursive); 96 status_t (*get_attr_uint64)(const device_node *node, const char *name, 97 uint64 *value, bool recursive); 98 status_t (*get_attr_string)(const device_node *node, const char *name, 99 const char **_value, bool recursive); 100 status_t (*get_attr_raw)(const device_node *node, const char *name, 101 const void **_data, size_t *_size, bool recursive); 102 103 status_t (*get_next_attr)(device_node *node, device_attr **_attr); 104 105 status_t (*find_child_node)(device_node *parent, 106 const device_attr *attrs, device_node **node); 107 108 } device_manager_info; 109 110 111 #define B_DEVICE_MANAGER_MODULE_NAME "system/device_manager/v1" 112 113 114 /* interface of device driver */ 115 116 struct driver_module_info { 117 module_info info; 118 119 float (*supports_device)(device_node *parent); 120 status_t (*register_device)(device_node *parent); 121 122 status_t (*init_driver)(device_node *node, void **_driverCookie); 123 void (*uninit_driver)(void *driverCookie); 124 status_t (*register_child_devices)(void *driverCookie); 125 status_t (*rescan_child_devices)(void *driverCookie); 126 127 void (*device_removed)(void *driverCookie); 128 status_t (*suspend)(void *driverCookie, int32 state); 129 status_t (*resume)(void *driverCookie); 130 }; 131 132 133 /* standard device node attributes */ 134 135 #define B_DEVICE_PRETTY_NAME "device/pretty name" /* string */ 136 #define B_DEVICE_MAPPING "device/mapping" /* string */ 137 #define B_DEVICE_BUS "device/bus" /* string */ 138 #define B_DEVICE_FIXED_CHILD "device/fixed child" /* string */ 139 #define B_DEVICE_FLAGS "device/flags" /* uint32 */ 140 141 #define B_DEVICE_VENDOR_ID "device/vendor" /* uint16 */ 142 #define B_DEVICE_ID "device/id" /* uint16 */ 143 #define B_DEVICE_TYPE "device/type" 144 /* uint16, PCI base class */ 145 #define B_DEVICE_SUB_TYPE "device/subtype" 146 /* uint16, PCI sub type */ 147 #define B_DEVICE_INTERFACE "device/interface" 148 /* uint16, PCI class API */ 149 150 #define B_DEVICE_UNIQUE_ID "device/unique id" /* string */ 151 152 /* device flags */ 153 #define B_FIND_CHILD_ON_DEMAND 0x01 154 #define B_FIND_MULTIPLE_CHILDREN 0x02 155 #define B_KEEP_DRIVER_LOADED 0x04 156 157 /* DMA attributes */ 158 #define B_DMA_LOW_ADDRESS "dma/low_address" 159 #define B_DMA_HIGH_ADDRESS "dma/high_address" 160 #define B_DMA_ALIGNMENT "dma/alignment" 161 #define B_DMA_BOUNDARY "dma/boundary" 162 #define B_DMA_MAX_TRANSFER_BLOCKS "dma/max_transfer_blocks" 163 #define B_DMA_MAX_SEGMENT_BLOCKS "dma/max_segment_blocks" 164 #define B_DMA_MAX_SEGMENT_COUNT "dma/max_segment_count" 165 166 /* interface of device */ 167 168 typedef struct IORequest io_request; 169 170 struct device_module_info { 171 module_info info; 172 173 status_t (*init_device)(void *driverCookie, void **_deviceCookie); 174 void (*uninit_device)(void *deviceCookie); 175 void (*device_removed)(void *deviceCookie); 176 177 status_t (*open)(void *deviceCookie, const char *path, int openMode, 178 void **_cookie); 179 status_t (*close)(void *cookie); 180 status_t (*free)(void *cookie); 181 status_t (*read)(void *cookie, off_t pos, void *buffer, size_t *_length); 182 status_t (*write)(void *cookie, off_t pos, const void *buffer, 183 size_t *_length); 184 status_t (*io)(void *cookie, io_request *request); 185 status_t (*control)(void *cookie, uint32 op, void *buffer, size_t length); 186 status_t (*select)(void *cookie, uint8 event, selectsync *sync); 187 status_t (*deselect)(void *cookie, uint8 event, selectsync *sync); 188 }; 189 190 #endif /* _DEVICE_MANAGER_H */ 191