Changes in uspace/lib/drv/generic/remote_usb.c [70a422b:9d58539] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/drv/generic/remote_usb.c
r70a422b r9d58539 35 35 36 36 #include <async.h> 37 #include <macros.h>38 37 #include <errno.h> 39 #include <devman.h>40 38 41 39 #include "usb_iface.h" 42 40 #include "ddf/driver.h" 43 44 45 usb_dev_session_t *usb_dev_connect(devman_handle_t handle)46 {47 // TODO All usb requests are atomic so this is safe,48 // it will need to change once USING EXCHANGE PARALLEL is safe with49 // devman_device_connect50 return devman_device_connect(EXCHANGE_ATOMIC, handle, IPC_FLAG_BLOCKING);51 }52 53 usb_dev_session_t *usb_dev_connect_to_self(ddf_dev_t *dev)54 {55 // TODO All usb requests are atomic so this is safe,56 // it will need to change once USING EXCHANGE PARALLEL is safe with57 // devman_parent_device_connect58 return devman_parent_device_connect(EXCHANGE_ATOMIC,59 ddf_dev_get_handle(dev), IPC_FLAG_BLOCKING);60 }61 62 void usb_dev_disconnect(usb_dev_session_t *sess)63 {64 if (sess)65 async_hangup(sess);66 }67 41 68 42 typedef enum { … … 70 44 IPC_M_USB_GET_MY_INTERFACE, 71 45 IPC_M_USB_GET_HOST_CONTROLLER_HANDLE, 72 IPC_M_USB_RESERVE_DEFAULT_ADDRESS,73 IPC_M_USB_RELEASE_DEFAULT_ADDRESS,74 IPC_M_USB_DEVICE_ENUMERATE,75 IPC_M_USB_DEVICE_REMOVE,76 IPC_M_USB_REGISTER_ENDPOINT,77 IPC_M_USB_UNREGISTER_ENDPOINT,78 46 } usb_iface_funcs_t; 79 47 … … 88 56 { 89 57 if (!exch) 90 return E BADMEM;58 return EINVAL; 91 59 sysarg_t addr; 92 60 const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE), … … 97 65 return ret; 98 66 } 99 67 /*----------------------------------------------------------------------------*/ 100 68 /** Tell interface number given device can use. 101 69 * @param[in] exch IPC communication exchange … … 107 75 { 108 76 if (!exch) 109 return E BADMEM;77 return EINVAL; 110 78 sysarg_t iface_no; 111 79 const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE), … … 115 83 return ret; 116 84 } 117 85 /*----------------------------------------------------------------------------*/ 118 86 /** Tell devman handle of device host controller. 119 87 * @param[in] exch IPC communication exchange … … 124 92 { 125 93 if (!exch) 126 return E BADMEM;94 return EINVAL; 127 95 devman_handle_t h; 128 96 const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE), … … 133 101 } 134 102 135 /** Reserve default USB address.136 * @param[in] exch IPC communication exchange137 * @param[in] speed Communication speed of the newly attached device138 * @return Error code.139 */140 int usb_reserve_default_address(async_exch_t *exch, usb_speed_t speed)141 {142 if (!exch)143 return EBADMEM;144 return async_req_2_0(exch, DEV_IFACE_ID(USB_DEV_IFACE),145 IPC_M_USB_RESERVE_DEFAULT_ADDRESS, speed);146 }147 148 /** Release default USB address.149 * @param[in] exch IPC communication exchange150 * @return Error code.151 */152 int usb_release_default_address(async_exch_t *exch)153 {154 if (!exch)155 return EBADMEM;156 return async_req_1_0(exch, DEV_IFACE_ID(USB_DEV_IFACE),157 IPC_M_USB_RELEASE_DEFAULT_ADDRESS);158 }159 160 /** Trigger USB device enumeration161 * @param[in] exch IPC communication exchange162 * @param[out] handle Identifier of the newly added device (if successful)163 * @return Error code.164 */165 int usb_device_enumerate(async_exch_t *exch, usb_device_handle_t *handle)166 {167 if (!exch || !handle)168 return EBADMEM;169 sysarg_t h;170 const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),171 IPC_M_USB_DEVICE_ENUMERATE, &h);172 if (ret == EOK)173 *handle = (usb_device_handle_t)h;174 return ret;175 }176 177 /** Trigger USB device enumeration178 * @param[in] exch IPC communication exchange179 * @param[in] handle Identifier of the device180 * @return Error code.181 */182 int usb_device_remove(async_exch_t *exch, usb_device_handle_t handle)183 {184 if (!exch)185 return EBADMEM;186 return async_req_2_0(exch, DEV_IFACE_ID(USB_DEV_IFACE),187 IPC_M_USB_DEVICE_REMOVE, handle);188 }189 190 int usb_register_endpoint(async_exch_t *exch, usb_endpoint_t endpoint,191 usb_transfer_type_t type, usb_direction_t direction,192 size_t mps, unsigned interval)193 {194 if (!exch)195 return EBADMEM;196 #define _PACK2(high, low) (((high & 0xffff) << 16) | (low & 0xffff))197 198 return async_req_4_0(exch, DEV_IFACE_ID(USB_DEV_IFACE),199 IPC_M_USB_REGISTER_ENDPOINT, endpoint,200 _PACK2(type, direction), _PACK2(mps, interval));201 202 #undef _PACK2203 }204 205 int usb_unregister_endpoint(async_exch_t *exch, usb_endpoint_t endpoint,206 usb_direction_t direction)207 {208 if (!exch)209 return EBADMEM;210 return async_req_3_0(exch, DEV_IFACE_ID(USB_DEV_IFACE),211 IPC_M_USB_UNREGISTER_ENDPOINT, endpoint, direction);212 }213 103 214 104 static void remote_usb_get_my_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 215 105 static void remote_usb_get_my_interface(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 216 106 static void remote_usb_get_hc_handle(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 217 218 static void remote_usb_reserve_default_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);219 static void remote_usb_release_default_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);220 static void remote_usb_device_enumerate(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);221 static void remote_usb_device_remove(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);222 static void remote_usb_register_endpoint(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);223 static void remote_usb_unregister_endpoint(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);224 107 225 108 /** Remote USB interface operations. */ … … 228 111 [IPC_M_USB_GET_MY_INTERFACE] = remote_usb_get_my_interface, 229 112 [IPC_M_USB_GET_HOST_CONTROLLER_HANDLE] = remote_usb_get_hc_handle, 230 [IPC_M_USB_RESERVE_DEFAULT_ADDRESS] = remote_usb_reserve_default_address,231 [IPC_M_USB_RELEASE_DEFAULT_ADDRESS] = remote_usb_release_default_address,232 [IPC_M_USB_DEVICE_ENUMERATE] = remote_usb_device_enumerate,233 [IPC_M_USB_DEVICE_REMOVE] = remote_usb_device_remove,234 [IPC_M_USB_REGISTER_ENDPOINT] = remote_usb_register_endpoint,235 [IPC_M_USB_UNREGISTER_ENDPOINT] = remote_usb_unregister_endpoint,236 113 }; 237 114 … … 239 116 */ 240 117 remote_iface_t remote_usb_iface = { 241 .method_count = ARRAY_SIZE(remote_usb_iface_ops), 242 .methods = remote_usb_iface_ops, 118 .method_count = sizeof(remote_usb_iface_ops) / 119 sizeof(remote_usb_iface_ops[0]), 120 .methods = remote_usb_iface_ops 243 121 }; 244 122 245 123 /*----------------------------------------------------------------------------*/ 246 124 void remote_usb_get_my_address(ddf_fun_t *fun, void *iface, 247 125 ipc_callid_t callid, ipc_call_t *call) … … 262 140 } 263 141 } 264 142 /*----------------------------------------------------------------------------*/ 265 143 void remote_usb_get_my_interface(ddf_fun_t *fun, void *iface, 266 144 ipc_callid_t callid, ipc_call_t *call) … … 281 159 } 282 160 } 283 161 /*----------------------------------------------------------------------------*/ 284 162 void remote_usb_get_hc_handle(ddf_fun_t *fun, void *iface, 285 163 ipc_callid_t callid, ipc_call_t *call) … … 300 178 async_answer_1(callid, EOK, (sysarg_t) handle); 301 179 } 302 303 void remote_usb_reserve_default_address(ddf_fun_t *fun, void *iface,304 ipc_callid_t callid, ipc_call_t *call)305 {306 const usb_iface_t *usb_iface = (usb_iface_t *) iface;307 308 if (usb_iface->reserve_default_address == NULL) {309 async_answer_0(callid, ENOTSUP);310 return;311 }312 313 usb_speed_t speed = DEV_IPC_GET_ARG1(*call);314 const int ret = usb_iface->reserve_default_address(fun, speed);315 async_answer_0(callid, ret);316 }317 318 void remote_usb_release_default_address(ddf_fun_t *fun, void *iface,319 ipc_callid_t callid, ipc_call_t *call)320 {321 const usb_iface_t *usb_iface = (usb_iface_t *) iface;322 323 if (usb_iface->release_default_address == NULL) {324 async_answer_0(callid, ENOTSUP);325 return;326 }327 328 const int ret = usb_iface->release_default_address(fun);329 async_answer_0(callid, ret);330 }331 332 static void remote_usb_device_enumerate(ddf_fun_t *fun, void *iface,333 ipc_callid_t callid, ipc_call_t *call)334 {335 const usb_iface_t *usb_iface = (usb_iface_t *) iface;336 337 if (usb_iface->device_enumerate == NULL) {338 async_answer_0(callid, ENOTSUP);339 return;340 }341 342 usb_device_handle_t handle = 0;343 const int ret = usb_iface->device_enumerate(fun, &handle);344 if (ret != EOK) {345 async_answer_0(callid, ret);346 }347 348 async_answer_1(callid, EOK, (sysarg_t) handle);349 }350 351 static void remote_usb_device_remove(ddf_fun_t *fun, void *iface,352 ipc_callid_t callid, ipc_call_t *call)353 {354 const usb_iface_t *usb_iface = (usb_iface_t *) iface;355 356 if (usb_iface->device_remove == NULL) {357 async_answer_0(callid, ENOTSUP);358 return;359 }360 361 usb_device_handle_t handle = DEV_IPC_GET_ARG1(*call);362 const int ret = usb_iface->device_remove(fun, handle);363 async_answer_0(callid, ret);364 }365 366 static void remote_usb_register_endpoint(ddf_fun_t *fun, void *iface,367 ipc_callid_t callid, ipc_call_t *call)368 {369 usb_iface_t *usb_iface = (usb_iface_t *) iface;370 371 if (!usb_iface->register_endpoint) {372 async_answer_0(callid, ENOTSUP);373 return;374 }375 376 #define _INIT_FROM_HIGH_DATA2(type, var, arg_no) \377 type var = (type) (DEV_IPC_GET_ARG##arg_no(*call) >> 16)378 #define _INIT_FROM_LOW_DATA2(type, var, arg_no) \379 type var = (type) (DEV_IPC_GET_ARG##arg_no(*call) & 0xffff)380 381 const usb_endpoint_t endpoint = DEV_IPC_GET_ARG1(*call);382 383 _INIT_FROM_HIGH_DATA2(usb_transfer_type_t, transfer_type, 2);384 _INIT_FROM_LOW_DATA2(usb_direction_t, direction, 2);385 386 _INIT_FROM_HIGH_DATA2(size_t, max_packet_size, 3);387 _INIT_FROM_LOW_DATA2(unsigned int, interval, 3);388 389 #undef _INIT_FROM_HIGH_DATA2390 #undef _INIT_FROM_LOW_DATA2391 392 const int ret = usb_iface->register_endpoint(fun, endpoint,393 transfer_type, direction, max_packet_size, interval);394 395 async_answer_0(callid, ret);396 }397 398 static void remote_usb_unregister_endpoint(ddf_fun_t *fun, void *iface,399 ipc_callid_t callid, ipc_call_t *call)400 {401 usb_iface_t *usb_iface = (usb_iface_t *) iface;402 403 if (!usb_iface->unregister_endpoint) {404 async_answer_0(callid, ENOTSUP);405 return;406 }407 408 usb_endpoint_t endpoint = (usb_endpoint_t) DEV_IPC_GET_ARG1(*call);409 usb_direction_t direction = (usb_direction_t) DEV_IPC_GET_ARG2(*call);410 411 int rc = usb_iface->unregister_endpoint(fun, endpoint, direction);412 413 async_answer_0(callid, rc);414 }415 180 /** 416 181 * @}
Note:
See TracChangeset
for help on using the changeset viewer.