| 1 | /*
|
|---|
| 2 | * Copyright (c) 2010 Vojtech Horky
|
|---|
| 3 | * Copyright (c) 2011 Jan Vesely
|
|---|
| 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>
|
|---|
| 37 | #include <errno.h>
|
|---|
| 38 |
|
|---|
| 39 | #include "usb_iface.h"
|
|---|
| 40 | #include "ddf/driver.h"
|
|---|
| 41 |
|
|---|
| 42 | typedef enum {
|
|---|
| 43 | IPC_M_USB_GET_MY_ADDRESS,
|
|---|
| 44 | IPC_M_USB_GET_MY_INTERFACE,
|
|---|
| 45 | IPC_M_USB_GET_HOST_CONTROLLER_HANDLE,
|
|---|
| 46 | } usb_iface_funcs_t;
|
|---|
| 47 |
|
|---|
| 48 | /** Tell USB address assigned to device.
|
|---|
| 49 | * @param exch Vaid IPC exchange
|
|---|
| 50 | * @param address Pointer to address storage place.
|
|---|
| 51 | * @return Error code.
|
|---|
| 52 | *
|
|---|
| 53 | * Exch param is an open communication to device implementing usb_iface.
|
|---|
| 54 | */
|
|---|
| 55 | int usb_get_my_address(async_exch_t *exch, usb_address_t *address)
|
|---|
| 56 | {
|
|---|
| 57 | if (!exch)
|
|---|
| 58 | return EINVAL;
|
|---|
| 59 | sysarg_t addr;
|
|---|
| 60 | const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
|
|---|
| 61 | IPC_M_USB_GET_MY_ADDRESS, &addr);
|
|---|
| 62 |
|
|---|
| 63 | if (ret == EOK && address != NULL)
|
|---|
| 64 | *address = (usb_address_t) addr;
|
|---|
| 65 | return ret;
|
|---|
| 66 | }
|
|---|
| 67 | /*----------------------------------------------------------------------------*/
|
|---|
| 68 | /** Tell interface number given device can use.
|
|---|
| 69 | * @param[in] exch IPC communication exchange
|
|---|
| 70 | * @param[in] handle Id of the device
|
|---|
| 71 | * @param[out] usb_iface Assigned USB interface
|
|---|
| 72 | * @return Error code.
|
|---|
| 73 | */
|
|---|
| 74 | int usb_get_my_interface(async_exch_t *exch, int *usb_iface)
|
|---|
| 75 | {
|
|---|
| 76 | if (!exch)
|
|---|
| 77 | return EINVAL;
|
|---|
| 78 | sysarg_t iface_no;
|
|---|
| 79 | const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
|
|---|
| 80 | IPC_M_USB_GET_MY_INTERFACE, &iface_no);
|
|---|
| 81 | if (ret == EOK && usb_iface)
|
|---|
| 82 | *usb_iface = (int)iface_no;
|
|---|
| 83 | return ret;
|
|---|
| 84 | }
|
|---|
| 85 | /*----------------------------------------------------------------------------*/
|
|---|
| 86 | /** Tell devman handle of device host controller.
|
|---|
| 87 | * @param[in] exch IPC communication exchange
|
|---|
| 88 | * @param[out] hc_handle devman handle of the HC used by the target device.
|
|---|
| 89 | * @return Error code.
|
|---|
| 90 | */
|
|---|
| 91 | int usb_get_hc_handle(async_exch_t *exch, devman_handle_t *hc_handle)
|
|---|
| 92 | {
|
|---|
| 93 | if (!exch)
|
|---|
| 94 | return EINVAL;
|
|---|
| 95 | devman_handle_t h;
|
|---|
| 96 | const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
|
|---|
| 97 | IPC_M_USB_GET_HOST_CONTROLLER_HANDLE, &h);
|
|---|
| 98 | if (ret == EOK && hc_handle)
|
|---|
| 99 | *hc_handle = (devman_handle_t)h;
|
|---|
| 100 | return ret;
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 | static void remote_usb_get_my_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
|---|
| 105 | static void remote_usb_get_my_interface(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
|---|
| 106 | static void remote_usb_get_hc_handle(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
|---|
| 107 |
|
|---|
| 108 | /** Remote USB interface operations. */
|
|---|
| 109 | static remote_iface_func_ptr_t remote_usb_iface_ops [] = {
|
|---|
| 110 | [IPC_M_USB_GET_MY_ADDRESS] = remote_usb_get_my_address,
|
|---|
| 111 | [IPC_M_USB_GET_MY_INTERFACE] = remote_usb_get_my_interface,
|
|---|
| 112 | [IPC_M_USB_GET_HOST_CONTROLLER_HANDLE] = remote_usb_get_hc_handle,
|
|---|
| 113 | };
|
|---|
| 114 |
|
|---|
| 115 | /** Remote USB interface structure.
|
|---|
| 116 | */
|
|---|
| 117 | 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
|
|---|
| 121 | };
|
|---|
| 122 |
|
|---|
| 123 | /*----------------------------------------------------------------------------*/
|
|---|
| 124 | void remote_usb_get_my_address(ddf_fun_t *fun, void *iface,
|
|---|
| 125 | ipc_callid_t callid, ipc_call_t *call)
|
|---|
| 126 | {
|
|---|
| 127 | const usb_iface_t *usb_iface = (usb_iface_t *) iface;
|
|---|
| 128 |
|
|---|
| 129 | if (usb_iface->get_my_address == NULL) {
|
|---|
| 130 | async_answer_0(callid, ENOTSUP);
|
|---|
| 131 | return;
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | usb_address_t address;
|
|---|
| 135 | const int ret = usb_iface->get_my_address(fun, &address);
|
|---|
| 136 | if (ret != EOK) {
|
|---|
| 137 | async_answer_0(callid, ret);
|
|---|
| 138 | } else {
|
|---|
| 139 | async_answer_1(callid, EOK, address);
|
|---|
| 140 | }
|
|---|
| 141 | }
|
|---|
| 142 | /*----------------------------------------------------------------------------*/
|
|---|
| 143 | void remote_usb_get_my_interface(ddf_fun_t *fun, void *iface,
|
|---|
| 144 | ipc_callid_t callid, ipc_call_t *call)
|
|---|
| 145 | {
|
|---|
| 146 | const usb_iface_t *usb_iface = (usb_iface_t *) iface;
|
|---|
| 147 |
|
|---|
| 148 | if (usb_iface->get_my_interface == NULL) {
|
|---|
| 149 | async_answer_0(callid, ENOTSUP);
|
|---|
| 150 | return;
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | int iface_no;
|
|---|
| 154 | const int ret = usb_iface->get_my_interface(fun, &iface_no);
|
|---|
| 155 | if (ret != EOK) {
|
|---|
| 156 | async_answer_0(callid, ret);
|
|---|
| 157 | } else {
|
|---|
| 158 | async_answer_1(callid, EOK, iface_no);
|
|---|
| 159 | }
|
|---|
| 160 | }
|
|---|
| 161 | /*----------------------------------------------------------------------------*/
|
|---|
| 162 | void remote_usb_get_hc_handle(ddf_fun_t *fun, void *iface,
|
|---|
| 163 | ipc_callid_t callid, ipc_call_t *call)
|
|---|
| 164 | {
|
|---|
| 165 | const usb_iface_t *usb_iface = (usb_iface_t *) iface;
|
|---|
| 166 |
|
|---|
| 167 | if (usb_iface->get_hc_handle == NULL) {
|
|---|
| 168 | async_answer_0(callid, ENOTSUP);
|
|---|
| 169 | return;
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | devman_handle_t handle;
|
|---|
| 173 | const int ret = usb_iface->get_hc_handle(fun, &handle);
|
|---|
| 174 | if (ret != EOK) {
|
|---|
| 175 | async_answer_0(callid, ret);
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 | async_answer_1(callid, EOK, (sysarg_t) handle);
|
|---|
| 179 | }
|
|---|
| 180 | /**
|
|---|
| 181 | * @}
|
|---|
| 182 | */
|
|---|