Changeset ef40434 in mainline
- Timestamp:
- 2013-01-15T21:50:52Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0f4bff8
- Parents:
- ef4e8eb
- Location:
- uspace/lib
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/drv/generic/remote_usbhc.c
ref4e8eb ref40434 84 84 */ 85 85 typedef enum { 86 /** Asks for address assignment by host controller.87 * Answer:88 * - ELIMIT - host controller run out of address89 * - EOK - address assigned90 * Answer arguments:91 * - assigned address92 *93 * The address must be released by via IPC_M_USBHC_RELEASE_ADDRESS.94 */95 IPC_M_USBHC_REQUEST_ADDRESS,96 97 /** Bind USB address with devman handle.98 * Parameters:99 * - USB address100 * - devman handle101 * Answer:102 * - EOK - address binded103 * - ENOENT - address is not in use104 */105 IPC_M_USBHC_BIND_ADDRESS,106 107 86 /** Get handle binded with given USB address. 108 87 * Parameters … … 113 92 */ 114 93 IPC_M_USBHC_GET_HANDLE_BY_ADDRESS, 115 116 /** Release address in use.117 * Arguments:118 * - address to be released119 * Answer:120 * - ENOENT - address not in use121 * - EPERM - trying to release default USB address122 */123 IPC_M_USBHC_RELEASE_ADDRESS,124 94 125 95 /** Register endpoint attributes at host controller. … … 161 131 } usbhc_iface_funcs_t; 162 132 163 int usbhc_request_address(async_exch_t *exch, usb_address_t *address, 164 bool strict, usb_speed_t speed) 165 { 166 if (!exch || !address) 167 return EBADMEM; 168 sysarg_t new_address; 169 const int ret = async_req_4_1(exch, DEV_IFACE_ID(USBHC_DEV_IFACE), 170 IPC_M_USBHC_REQUEST_ADDRESS, *address, strict, speed, &new_address); 171 if (ret == EOK) 172 *address = (usb_address_t)new_address; 173 return ret; 174 } 175 176 int usbhc_bind_address(async_exch_t *exch, usb_address_t address, 177 devman_handle_t handle) 178 { 179 if (!exch) 180 return EBADMEM; 181 return async_req_3_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE), 182 IPC_M_USBHC_BIND_ADDRESS, address, handle); 183 } 133 184 134 185 135 int usbhc_get_handle(async_exch_t *exch, usb_address_t address, … … 196 146 } 197 147 198 int usbhc_release_address(async_exch_t *exch, usb_address_t address)199 {200 if (!exch)201 return EBADMEM;202 return async_req_2_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),203 IPC_M_USBHC_RELEASE_ADDRESS, address);204 }205 206 148 int usbhc_register_endpoint(async_exch_t *exch, usb_address_t address, 207 149 usb_endpoint_t endpoint, usb_transfer_type_t type, … … 323 265 324 266 325 static void remote_usbhc_request_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);326 static void remote_usbhc_bind_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);327 267 static void remote_usbhc_get_handle(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 328 static void remote_usbhc_release_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);329 268 static void remote_usbhc_register_endpoint(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 330 269 static void remote_usbhc_unregister_endpoint(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); … … 335 274 /** Remote USB host controller interface operations. */ 336 275 static remote_iface_func_ptr_t remote_usbhc_iface_ops[] = { 337 [IPC_M_USBHC_REQUEST_ADDRESS] = remote_usbhc_request_address,338 [IPC_M_USBHC_RELEASE_ADDRESS] = remote_usbhc_release_address,339 [IPC_M_USBHC_BIND_ADDRESS] = remote_usbhc_bind_address,340 276 [IPC_M_USBHC_GET_HANDLE_BY_ADDRESS] = remote_usbhc_get_handle, 341 277 … … 387 323 } 388 324 389 void remote_usbhc_request_address(ddf_fun_t *fun, void *iface,390 ipc_callid_t callid, ipc_call_t *call)391 {392 const usbhc_iface_t *usb_iface = iface;393 394 if (!usb_iface->request_address) {395 async_answer_0(callid, ENOTSUP);396 return;397 }398 399 usb_address_t address = DEV_IPC_GET_ARG1(*call);400 const bool strict = DEV_IPC_GET_ARG2(*call);401 const usb_speed_t speed = DEV_IPC_GET_ARG3(*call);402 403 const int rc = usb_iface->request_address(fun, &address, strict, speed);404 if (rc != EOK) {405 async_answer_0(callid, rc);406 } else {407 async_answer_1(callid, EOK, (sysarg_t) address);408 }409 }410 411 void remote_usbhc_bind_address(ddf_fun_t *fun, void *iface,412 ipc_callid_t callid, ipc_call_t *call)413 {414 const usbhc_iface_t *usb_iface = iface;415 416 if (!usb_iface->bind_address) {417 async_answer_0(callid, ENOTSUP);418 return;419 }420 421 const usb_address_t address = (usb_address_t) DEV_IPC_GET_ARG1(*call);422 const devman_handle_t handle = (devman_handle_t) DEV_IPC_GET_ARG2(*call);423 424 const int ret = usb_iface->bind_address(fun, address, handle);425 async_answer_0(callid, ret);426 }427 325 428 326 void remote_usbhc_get_handle(ddf_fun_t *fun, void *iface, … … 447 345 } 448 346 449 void remote_usbhc_release_address(ddf_fun_t *fun, void *iface,450 ipc_callid_t callid, ipc_call_t *call)451 {452 const usbhc_iface_t *usb_iface = iface;453 454 if (!usb_iface->release_address) {455 async_answer_0(callid, ENOTSUP);456 return;457 }458 459 const usb_address_t address = (usb_address_t) DEV_IPC_GET_ARG1(*call);460 461 const int ret = usb_iface->release_address(fun, address);462 async_answer_0(callid, ret);463 }464 347 465 348 static void callback_out(int outcome, void *arg) -
uspace/lib/drv/include/usbhc_iface.h
ref4e8eb ref40434 44 44 #include <stdbool.h> 45 45 46 int usbhc_request_address(async_exch_t *, usb_address_t *, bool, usb_speed_t);47 int usbhc_bind_address(async_exch_t *, usb_address_t, devman_handle_t);48 46 int usbhc_get_handle(async_exch_t *, usb_address_t, devman_handle_t *); 49 int usbhc_release_address(async_exch_t *, usb_address_t);50 47 int usbhc_register_endpoint(async_exch_t *, usb_address_t, usb_endpoint_t, 51 48 usb_transfer_type_t, usb_direction_t, size_t, unsigned int); … … 65 62 /** USB host controller communication interface. */ 66 63 typedef struct { 67 int (*request_address)(ddf_fun_t *, usb_address_t *, bool, usb_speed_t); 68 int (*bind_address)(ddf_fun_t *, usb_address_t, devman_handle_t); 69 int (*get_handle)(ddf_fun_t *, usb_address_t, 70 devman_handle_t *); 71 int (*release_address)(ddf_fun_t *, usb_address_t); 64 int (*get_handle)(ddf_fun_t *, usb_address_t, devman_handle_t *); 72 65 73 int (*register_endpoint)(ddf_fun_t *, 74 usb_address_t, usb_endpoint_t, 66 int (*register_endpoint)(ddf_fun_t *, usb_address_t, usb_endpoint_t, 75 67 usb_transfer_type_t, usb_direction_t, size_t, unsigned int); 76 68 int (*unregister_endpoint)(ddf_fun_t *, usb_address_t, usb_endpoint_t, -
uspace/lib/usbhost/src/iface.c
ref4e8eb ref40434 42 42 #include "ddf_helpers.h" 43 43 44 /** Request address interface function.45 *46 * @param[in] fun DDF function that was called.47 * @param[in] address Pointer to preferred USB address.48 * @param[out] address Place to write a new address.49 * @param[in] strict Fail if the preferred address is not available.50 * @param[in] speed Speed to associate with the new default address.51 * @return Error code.52 */53 static int request_address(54 ddf_fun_t *fun, usb_address_t *address, bool strict, usb_speed_t speed)55 {56 assert(fun);57 hcd_t *hcd = dev_to_hcd(ddf_fun_get_dev(fun));58 assert(hcd);59 assert(address);60 usb_log_debug("Address request: speed: %s, address: %d, strict: %s.\n",61 usb_str_speed(speed), *address, strict ? "YES" : "NO");62 return usb_device_manager_request_address(63 &hcd->dev_manager, address, strict, speed);64 }65 66 /** Bind address interface function.67 *68 * @param[in] fun DDF function that was called.69 * @param[in] address Address of the device70 * @param[in] handle Devman handle of the device driver.71 * @return Error code.72 */73 static int bind_address(74 ddf_fun_t *fun, usb_address_t address, devman_handle_t handle)75 {76 assert(fun);77 hcd_t *hcd = dev_to_hcd(ddf_fun_get_dev(fun));78 assert(hcd);79 80 usb_log_debug("Address bind %d-%" PRIun ".\n", address, handle);81 return usb_device_manager_bind_address(82 &hcd->dev_manager, address, handle);83 }84 85 44 /** Find device handle by address interface function. 86 45 * … … 98 57 return usb_device_manager_get_info_by_address( 99 58 &hcd->dev_manager, address, handle, NULL); 100 }101 102 /** Release address interface function.103 *104 * @param[in] fun DDF function that was called.105 * @param[in] address USB address to be released.106 * @return Error code.107 */108 static int release_address(ddf_fun_t *fun, usb_address_t address)109 {110 assert(fun);111 hcd_t *hcd = dev_to_hcd(ddf_fun_get_dev(fun));112 usb_log_debug("Address release %d.\n", address);113 return hcd_release_address(hcd, address);114 59 } 115 60 … … 134 79 const size_t size = max_packet_size; 135 80 const usb_target_t target = {{.address = address, .endpoint = endpoint}}; 136 81 137 82 usb_log_debug("Register endpoint %d:%d %s-%s %zuB %ums.\n", 138 83 address, endpoint, usb_str_transfer_type(transfer_type), … … 203 148 /** usbhc Interface implementation using hcd_t from libusbhost library. */ 204 149 usbhc_iface_t hcd_iface = { 205 .request_address = request_address,206 .bind_address = bind_address,207 150 .get_handle = find_by_address, 208 .release_address = release_address,209 151 210 152 .register_endpoint = register_endpoint,
Note:
See TracChangeset
for help on using the changeset viewer.