[56fb3732] | 1 | /*
|
---|
| 2 | * Copyright (c) 2010 Vojtech Horky
|
---|
[56bdd9a4] | 3 | * Copyright (c) 2011 Jan Vesely
|
---|
[56fb3732] | 4 | * All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
---|
| 7 | * modification, are permitted provided that the following conditions
|
---|
| 8 | * are met:
|
---|
| 9 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 14 | * documentation and/or other materials provided with the distribution.
|
---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | /** @addtogroup libdrv
|
---|
| 31 | * @{
|
---|
| 32 | */
|
---|
| 33 | /** @file
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 | #include <async.h>
|
---|
[90c340fb] | 37 | #include <assert.h>
|
---|
[9be30cdf] | 38 | #include <macros.h>
|
---|
[56fb3732] | 39 | #include <errno.h>
|
---|
[e938fa6] | 40 | #include <devman.h>
|
---|
[56fb3732] | 41 |
|
---|
| 42 | #include "usb_iface.h"
|
---|
[eb1a2f4] | 43 | #include "ddf/driver.h"
|
---|
[56fb3732] | 44 |
|
---|
[56bdd9a4] | 45 |
|
---|
[94fbf78] | 46 | usb_dev_session_t *usb_dev_connect(devman_handle_t handle)
|
---|
[56bdd9a4] | 47 | {
|
---|
[b4b534ac] | 48 | return devman_device_connect(handle, IPC_FLAG_BLOCKING);
|
---|
[94fbf78] | 49 | }
|
---|
[56bdd9a4] | 50 |
|
---|
[94fbf78] | 51 | usb_dev_session_t *usb_dev_connect_to_self(ddf_dev_t *dev)
|
---|
[e938fa6] | 52 | {
|
---|
[b4b534ac] | 53 | return devman_parent_device_connect(ddf_dev_get_handle(dev), IPC_FLAG_BLOCKING);
|
---|
[e938fa6] | 54 | }
|
---|
| 55 |
|
---|
[71384bd3] | 56 | void usb_dev_disconnect(usb_dev_session_t *sess)
|
---|
[e938fa6] | 57 | {
|
---|
| 58 | if (sess)
|
---|
| 59 | async_hangup(sess);
|
---|
[56bdd9a4] | 60 | }
|
---|
[a76b01b4] | 61 |
|
---|
[56bdd9a4] | 62 | typedef enum {
|
---|
| 63 | IPC_M_USB_GET_MY_INTERFACE,
|
---|
[3121b5f] | 64 | IPC_M_USB_GET_MY_DEVICE_HANDLE,
|
---|
[56bdd9a4] | 65 | } usb_iface_funcs_t;
|
---|
| 66 |
|
---|
| 67 | /** Tell interface number given device can use.
|
---|
| 68 | * @param[in] exch IPC communication exchange
|
---|
| 69 | * @param[in] handle Id of the device
|
---|
| 70 | * @param[out] usb_iface Assigned USB interface
|
---|
| 71 | * @return Error code.
|
---|
| 72 | */
|
---|
| 73 | int usb_get_my_interface(async_exch_t *exch, int *usb_iface)
|
---|
| 74 | {
|
---|
| 75 | if (!exch)
|
---|
[8afeb04] | 76 | return EBADMEM;
|
---|
[56bdd9a4] | 77 | sysarg_t iface_no;
|
---|
| 78 | const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
|
---|
| 79 | IPC_M_USB_GET_MY_INTERFACE, &iface_no);
|
---|
| 80 | if (ret == EOK && usb_iface)
|
---|
| 81 | *usb_iface = (int)iface_no;
|
---|
| 82 | return ret;
|
---|
| 83 | }
|
---|
[a76b01b4] | 84 |
|
---|
[9d15d1b] | 85 | /** Tell devman handle of the usb device function.
|
---|
[58563585] | 86 | *
|
---|
| 87 | * @param[in] exch IPC communication exchange
|
---|
[9d15d1b] | 88 | * @param[out] handle devman handle of the HC used by the target device.
|
---|
[58563585] | 89 | *
|
---|
[56bdd9a4] | 90 | * @return Error code.
|
---|
[58563585] | 91 | *
|
---|
[56bdd9a4] | 92 | */
|
---|
[3121b5f] | 93 | int usb_get_my_device_handle(async_exch_t *exch, devman_handle_t *handle)
|
---|
[9d15d1b] | 94 | {
|
---|
| 95 | devman_handle_t h = 0;
|
---|
| 96 | const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
|
---|
[3121b5f] | 97 | IPC_M_USB_GET_MY_DEVICE_HANDLE, &h);
|
---|
[9d15d1b] | 98 | if (ret == EOK && handle)
|
---|
| 99 | *handle = (devman_handle_t)h;
|
---|
| 100 | return ret;
|
---|
| 101 | }
|
---|
| 102 |
|
---|
[317a463] | 103 | static void remote_usb_get_my_interface(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
[3121b5f] | 104 | static void remote_usb_get_my_device_handle(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
[56fb3732] | 105 |
|
---|
| 106 | /** Remote USB interface operations. */
|
---|
[9be30cdf] | 107 | static const remote_iface_func_ptr_t remote_usb_iface_ops [] = {
|
---|
[317a463] | 108 | [IPC_M_USB_GET_MY_INTERFACE] = remote_usb_get_my_interface,
|
---|
[3121b5f] | 109 | [IPC_M_USB_GET_MY_DEVICE_HANDLE] = remote_usb_get_my_device_handle,
|
---|
[56fb3732] | 110 | };
|
---|
| 111 |
|
---|
| 112 | /** Remote USB interface structure.
|
---|
| 113 | */
|
---|
[7f80313] | 114 | const remote_iface_t remote_usb_iface = {
|
---|
[9be30cdf] | 115 | .method_count = ARRAY_SIZE(remote_usb_iface_ops),
|
---|
[e938fa6] | 116 | .methods = remote_usb_iface_ops,
|
---|
[56fb3732] | 117 | };
|
---|
| 118 |
|
---|
[317a463] | 119 | void remote_usb_get_my_interface(ddf_fun_t *fun, void *iface,
|
---|
[357a302] | 120 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 121 | {
|
---|
[56bdd9a4] | 122 | const usb_iface_t *usb_iface = (usb_iface_t *) iface;
|
---|
[357a302] | 123 |
|
---|
[317a463] | 124 | if (usb_iface->get_my_interface == NULL) {
|
---|
[357a302] | 125 | async_answer_0(callid, ENOTSUP);
|
---|
| 126 | return;
|
---|
| 127 | }
|
---|
| 128 |
|
---|
[95120c3] | 129 | int iface_no;
|
---|
[56bdd9a4] | 130 | const int ret = usb_iface->get_my_interface(fun, &iface_no);
|
---|
| 131 | if (ret != EOK) {
|
---|
| 132 | async_answer_0(callid, ret);
|
---|
[357a302] | 133 | } else {
|
---|
[95120c3] | 134 | async_answer_1(callid, EOK, iface_no);
|
---|
[357a302] | 135 | }
|
---|
| 136 | }
|
---|
[a76b01b4] | 137 |
|
---|
[3121b5f] | 138 | void remote_usb_get_my_device_handle(ddf_fun_t *fun, void *iface,
|
---|
[95120c3] | 139 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 140 | {
|
---|
[56bdd9a4] | 141 | const usb_iface_t *usb_iface = (usb_iface_t *) iface;
|
---|
[95120c3] | 142 |
|
---|
[3121b5f] | 143 | if (usb_iface->get_my_device_handle == NULL) {
|
---|
[95120c3] | 144 | async_answer_0(callid, ENOTSUP);
|
---|
| 145 | return;
|
---|
| 146 | }
|
---|
| 147 |
|
---|
[9d15d1b] | 148 | devman_handle_t handle;
|
---|
[3121b5f] | 149 | const int ret = usb_iface->get_my_device_handle(fun, &handle);
|
---|
[56bdd9a4] | 150 | if (ret != EOK) {
|
---|
| 151 | async_answer_0(callid, ret);
|
---|
[95120c3] | 152 | }
|
---|
[9d15d1b] | 153 |
|
---|
| 154 | async_answer_1(callid, EOK, (sysarg_t) handle);
|
---|
[95120c3] | 155 | }
|
---|
[a76b01b4] | 156 |
|
---|
[56fb3732] | 157 | /**
|
---|
| 158 | * @}
|
---|
| 159 | */
|
---|