Changeset e938fa6 in mainline
- Timestamp:
- 2013-01-07T16:26:05Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 56bd6f11
- Parents:
- b995183
- Location:
- uspace/lib/drv
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/drv/generic/remote_usb.c
rb995183 re938fa6 35 35 36 36 #include <async.h> 37 #include <macros.h> 37 38 #include <errno.h> 39 #include <devman.h> 38 40 39 41 #include "usb_iface.h" 40 42 #include "ddf/driver.h" 43 44 usb_dev_session_t *usb_dev_connect(ddf_dev_t *parent) 45 { 46 // TODO All usb requests are atomic so this is safe, 47 // it will need to change once USING EXCHNAGE PARALLEL is safe with 48 // devman_parent_device_connect 49 return devman_parent_device_connect(EXCHANGE_ATOMIC, 50 ddf_dev_get_handle(parent), IPC_FLAG_BLOCKING); 51 } 52 53 void usb_dev_session_close(usb_dev_session_t *sess) 54 { 55 if (sess) 56 async_hangup(sess); 57 } 41 58 42 59 typedef enum { … … 44 61 IPC_M_USB_GET_MY_INTERFACE, 45 62 IPC_M_USB_GET_HOST_CONTROLLER_HANDLE, 63 IPC_M_USB_RESERVE_DEFAULT_ADDRESS, 64 IPC_M_USB_RELEASE_DEFAULT_ADDRESS, 65 IPC_M_USB_DEVICE_ENUMERATE, 66 IPC_M_USB_DEVICE_REMOVE, 46 67 } usb_iface_funcs_t; 47 68 … … 101 122 } 102 123 124 /** Reserve default USB address. 125 * @param[in] exch IPC communication exchange 126 * @param[in] speed Communication speed of the newly attached device 127 * @return Error code. 128 */ 129 int usb_reserve_default_address(async_exch_t *exch, usb_speed_t speed) 130 { 131 if (!exch) 132 return EBADMEM; 133 return async_req_2_0(exch, DEV_IFACE_ID(USB_DEV_IFACE), 134 IPC_M_USB_RESERVE_DEFAULT_ADDRESS, speed); 135 } 136 137 /** Release default USB address. 138 * @param[in] exch IPC communication exchange 139 * @return Error code. 140 */ 141 int usb_release_default_address(async_exch_t *exch) 142 { 143 if (!exch) 144 return EBADMEM; 145 return async_req_1_0(exch, DEV_IFACE_ID(USB_DEV_IFACE), 146 IPC_M_USB_RELEASE_DEFAULT_ADDRESS); 147 } 148 149 /** Trigger USB device enumeration 150 * @param[in] exch IPC communication exchange 151 * @param[out] handle Identifier of the newly added device (if successful) 152 * @return Error code. 153 */ 154 int usb_device_enumerate(async_exch_t *exch, usb_device_handle_t *handle) 155 { 156 if (!exch || !handle) 157 return EBADMEM; 158 sysarg_t h; 159 const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE), 160 IPC_M_USB_DEVICE_ENUMERATE, &h); 161 if (ret == EOK) 162 *handle = (usb_device_handle_t)h; 163 return ret; 164 } 165 166 /** Trigger USB device enumeration 167 * @param[in] exch IPC communication exchange 168 * @param[in] handle Identifier of the device 169 * @return Error code. 170 */ 171 int usb_device_remove(async_exch_t *exch, usb_device_handle_t handle) 172 { 173 if (!exch) 174 return EBADMEM; 175 return async_req_2_0(exch, DEV_IFACE_ID(USB_DEV_IFACE), 176 IPC_M_USB_DEVICE_REMOVE, handle); 177 } 103 178 104 179 static void remote_usb_get_my_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 105 180 static void remote_usb_get_my_interface(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 106 181 static void remote_usb_get_hc_handle(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 182 183 static void remote_usb_reserve_default_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 184 static void remote_usb_release_default_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 185 static void remote_usb_device_enumerate(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 186 static void remote_usb_device_remove(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 107 187 108 188 /** Remote USB interface operations. */ … … 111 191 [IPC_M_USB_GET_MY_INTERFACE] = remote_usb_get_my_interface, 112 192 [IPC_M_USB_GET_HOST_CONTROLLER_HANDLE] = remote_usb_get_hc_handle, 193 [IPC_M_USB_RESERVE_DEFAULT_ADDRESS] = remote_usb_reserve_default_address, 194 [IPC_M_USB_RELEASE_DEFAULT_ADDRESS] = remote_usb_release_default_address, 195 [IPC_M_USB_DEVICE_ENUMERATE] = remote_usb_device_enumerate, 196 [IPC_M_USB_DEVICE_REMOVE] = remote_usb_device_remove, 113 197 }; 114 198 … … 116 200 */ 117 201 remote_iface_t remote_usb_iface = { 118 .method_count = sizeof(remote_usb_iface_ops) / 119 sizeof(remote_usb_iface_ops[0]), 120 .methods = remote_usb_iface_ops 202 .method_count = ARRAY_SIZE(remote_usb_iface_ops), 203 .methods = remote_usb_iface_ops, 121 204 }; 122 205 … … 178 261 async_answer_1(callid, EOK, (sysarg_t) handle); 179 262 } 263 264 void remote_usb_reserve_default_address(ddf_fun_t *fun, void *iface, 265 ipc_callid_t callid, ipc_call_t *call) 266 { 267 const usb_iface_t *usb_iface = (usb_iface_t *) iface; 268 269 if (usb_iface->reserve_default_address == NULL) { 270 async_answer_0(callid, ENOTSUP); 271 return; 272 } 273 274 usb_speed_t speed = DEV_IPC_GET_ARG1(*call); 275 const int ret = usb_iface->reserve_default_address(fun, speed); 276 async_answer_0(callid, ret); 277 } 278 279 void remote_usb_release_default_address(ddf_fun_t *fun, void *iface, 280 ipc_callid_t callid, ipc_call_t *call) 281 { 282 const usb_iface_t *usb_iface = (usb_iface_t *) iface; 283 284 if (usb_iface->release_default_address == NULL) { 285 async_answer_0(callid, ENOTSUP); 286 return; 287 } 288 289 const int ret = usb_iface->release_default_address(fun); 290 async_answer_0(callid, ret); 291 } 292 293 static void remote_usb_device_enumerate(ddf_fun_t *fun, void *iface, 294 ipc_callid_t callid, ipc_call_t *call) 295 { 296 const usb_iface_t *usb_iface = (usb_iface_t *) iface; 297 298 if (usb_iface->device_enumerate == NULL) { 299 async_answer_0(callid, ENOTSUP); 300 return; 301 } 302 303 usb_device_handle_t handle = 0; 304 const int ret = usb_iface->device_enumerate(fun, &handle); 305 if (ret != EOK) { 306 async_answer_0(callid, ret); 307 } 308 309 async_answer_1(callid, EOK, (sysarg_t) handle); 310 } 311 312 static void remote_usb_device_remove(ddf_fun_t *fun, void *iface, 313 ipc_callid_t callid, ipc_call_t *call) 314 { 315 const usb_iface_t *usb_iface = (usb_iface_t *) iface; 316 317 if (usb_iface->device_remove == NULL) { 318 async_answer_0(callid, ENOTSUP); 319 return; 320 } 321 322 usb_device_handle_t handle = DEV_IPC_GET_ARG1(*call); 323 const int ret = usb_iface->device_remove(fun, handle); 324 async_answer_0(callid, ret); 325 } 180 326 /** 181 327 * @} -
uspace/lib/drv/include/usb_iface.h
rb995183 re938fa6 42 42 #include <usb/usb.h> 43 43 44 typedef intptr_t usb_device_handle_t; 45 enum { 46 USB_DEVICE_HANDLE_INVALID = -1 47 }; 48 typedef async_sess_t usb_dev_session_t; 49 50 usb_dev_session_t *usb_dev_connect(ddf_dev_t *dev); 51 void usb_dev_session_close(usb_dev_session_t *); 52 44 53 int usb_get_my_address(async_exch_t *, usb_address_t *); 45 54 int usb_get_my_interface(async_exch_t *, int *); 46 55 int usb_get_hc_handle(async_exch_t *, devman_handle_t *); 56 57 int usb_reserve_default_address(async_exch_t *, usb_speed_t); 58 int usb_release_default_address(async_exch_t *); 59 60 int usb_device_enumerate(async_exch_t *, usb_device_handle_t *); 61 int usb_device_remove(async_exch_t *, usb_device_handle_t); 47 62 48 63 /** USB device communication interface. */ … … 51 66 int (*get_my_interface)(ddf_fun_t *, int *); 52 67 int (*get_hc_handle)(ddf_fun_t *, devman_handle_t *); 68 69 int (*reserve_default_address)(ddf_fun_t *, usb_speed_t); 70 int (*release_default_address)(ddf_fun_t *); 71 int (*device_enumerate)(ddf_fun_t *, usb_device_handle_t *); 72 int (*device_remove)(ddf_fun_t *, usb_device_handle_t); 53 73 } usb_iface_t; 54 74
Note:
See TracChangeset
for help on using the changeset viewer.