2 * Copyright 2004-2008, Haiku Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT license.
5 #ifndef _DEVICE_MANAGER_H
6 #define _DEVICE_MANAGER_H
9 #include <TypeConstants.h>
14 /* type of I/O resource */
22 /* I/O resource description */
25 /* type of I/O resource */
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)
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
40 /* attribute of a device node */
43 type_code type
; /* for supported types, see value */
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 */
58 typedef struct device_node device_node
;
59 typedef struct driver_module_info driver_module_info
;
62 /* interface of the device manager */
64 typedef struct device_manager_info
{
67 status_t (*rescan_node
)(device_node
*node
);
69 status_t (*register_node
)(device_node
*parent
, const char *moduleName
,
70 const device_attr
*attrs
, const io_resource
*ioResources
,
72 status_t (*unregister_node
)(device_node
*node
);
74 status_t (*get_driver
)(device_node
*node
, driver_module_info
**_module
,
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
);
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
);
87 int32 (*create_id
)(const char *generator
);
88 status_t (*free_id
)(const char *generator
, uint32 id
);
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
);
103 status_t (*get_next_attr
)(device_node
*node
, device_attr
**_attr
);
104 } device_manager_info
;
107 #define B_DEVICE_MANAGER_MODULE_NAME "system/device_manager/v1"
110 /* interface of device driver */
112 struct driver_module_info
{
115 float (*supports_device
)(device_node
*parent
);
116 status_t (*register_device
)(device_node
*parent
);
118 status_t (*init_driver
)(device_node
*node
, void **_driverCookie
);
119 void (*uninit_driver
)(void *driverCookie
);
120 status_t (*register_child_devices
)(void *driverCookie
);
121 status_t (*rescan_child_devices
)(void *driverCookie
);
123 void (*device_removed
)(void *driverCookie
);
124 status_t (*suspend
)(void *driverCookie
, int32 state
);
125 status_t (*resume
)(void *driverCookie
);
129 /* standard device node attributes */
131 #define B_DEVICE_PRETTY_NAME "device/pretty name" /* string */
132 #define B_DEVICE_MAPPING "device/mapping" /* string */
133 #define B_DEVICE_BUS "device/bus" /* string */
134 #define B_DEVICE_FIXED_CHILD "device/fixed child" /* string */
135 #define B_DEVICE_FLAGS "device/flags" /* uint32 */
137 #define B_DEVICE_VENDOR_ID "device/vendor" /* uint16 */
138 #define B_DEVICE_ID "device/id" /* uint16 */
139 #define B_DEVICE_TYPE "device/type"
140 /* uint16, PCI base class */
141 #define B_DEVICE_SUB_TYPE "device/subtype"
142 /* uint16, PCI sub type */
143 #define B_DEVICE_INTERFACE "device/interface"
144 /* uint16, PCI class API */
146 #define B_DEVICE_UNIQUE_ID "device/unique id" /* string */
149 #define B_FIND_CHILD_ON_DEMAND 0x01
150 #define B_FIND_MULTIPLE_CHILDREN 0x02
151 #define B_KEEP_DRIVER_LOADED 0x04
154 #define B_DMA_LOW_ADDRESS "dma/low_address"
155 #define B_DMA_HIGH_ADDRESS "dma/high_address"
156 #define B_DMA_ALIGNMENT "dma/alignment"
157 #define B_DMA_BOUNDARY "dma/boundary"
158 #define B_DMA_MAX_TRANSFER_BLOCKS "dma/max_transfer_blocks"
159 #define B_DMA_MAX_SEGMENT_BLOCKS "dma/max_segment_blocks"
160 #define B_DMA_MAX_SEGMENT_COUNT "dma/max_segment_count"
162 /* interface of device */
164 typedef struct IORequest io_request
;
166 struct device_module_info
{
169 status_t (*init_device
)(void *driverCookie
, void **_deviceCookie
);
170 void (*uninit_device
)(void *deviceCookie
);
171 void (*device_removed
)(void *deviceCookie
);
173 status_t (*open
)(void *deviceCookie
, const char *path
, int openMode
,
175 status_t (*close
)(void *cookie
);
176 status_t (*free
)(void *cookie
);
177 status_t (*read
)(void *cookie
, off_t pos
, void *buffer
, size_t *_length
);
178 status_t (*write
)(void *cookie
, off_t pos
, const void *buffer
,
180 status_t (*io
)(void *cookie
, io_request
*request
);
181 status_t (*control
)(void *cookie
, uint32 op
, void *buffer
, size_t length
);
182 status_t (*select
)(void *cookie
, uint8 event
, selectsync
*sync
);
183 status_t (*deselect
)(void *cookie
, uint8 event
, selectsync
*sync
);
186 #endif /* _DEVICE_MANAGER_H */