[357a302] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 Vojtech Horky
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup libusb
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | * Implementations of DDF interfaces functions (actual implementation).
|
---|
| 34 | */
|
---|
| 35 | #include <ipc/devman.h>
|
---|
[eb1a2f4] | 36 | #include <devman.h>
|
---|
| 37 | #include <async.h>
|
---|
[357a302] | 38 | #include <usb/ddfiface.h>
|
---|
[eb1a2f4] | 39 | #include <usb/debug.h>
|
---|
[357a302] | 40 | #include <errno.h>
|
---|
[eb1a2f4] | 41 | #include <assert.h>
|
---|
[357a302] | 42 |
|
---|
| 43 | /** DDF interface for USB device, implementation for typical hub. */
|
---|
| 44 | usb_iface_t usb_iface_hub_impl = {
|
---|
| 45 | .get_hc_handle = usb_iface_get_hc_handle_hub_impl,
|
---|
| 46 | .get_address = usb_iface_get_address_hub_impl
|
---|
| 47 | };
|
---|
| 48 |
|
---|
| 49 | /** DDF interface for USB device, implementation for child of a typical hub. */
|
---|
| 50 | usb_iface_t usb_iface_hub_child_impl = {
|
---|
| 51 | .get_hc_handle = usb_iface_get_hc_handle_hub_child_impl,
|
---|
| 52 | .get_address = usb_iface_get_address_hub_child_impl
|
---|
| 53 | };
|
---|
| 54 |
|
---|
| 55 |
|
---|
| 56 | /** Get host controller handle, interface implementation for hub driver.
|
---|
| 57 | *
|
---|
[bc1c6fb] | 58 | * @param[in] fun Device function the operation is running on.
|
---|
[357a302] | 59 | * @param[out] handle Storage for the host controller handle.
|
---|
| 60 | * @return Error code.
|
---|
| 61 | */
|
---|
[eb1a2f4] | 62 | int usb_iface_get_hc_handle_hub_impl(ddf_fun_t *fun, devman_handle_t *handle)
|
---|
[357a302] | 63 | {
|
---|
[eb1a2f4] | 64 | assert(fun);
|
---|
| 65 | return usb_hc_find(fun->handle, handle);
|
---|
[357a302] | 66 | }
|
---|
| 67 |
|
---|
| 68 | /** Get host controller handle, interface implementation for child of
|
---|
| 69 | * a hub driver.
|
---|
| 70 | *
|
---|
[bc1c6fb] | 71 | * @param[in] fun Device function the operation is running on.
|
---|
[357a302] | 72 | * @param[out] handle Storage for the host controller handle.
|
---|
| 73 | * @return Error code.
|
---|
| 74 | */
|
---|
[eb1a2f4] | 75 | int usb_iface_get_hc_handle_hub_child_impl(ddf_fun_t *fun,
|
---|
[357a302] | 76 | devman_handle_t *handle)
|
---|
| 77 | {
|
---|
[eb1a2f4] | 78 | assert(fun != NULL);
|
---|
[357a302] | 79 |
|
---|
[eb1a2f4] | 80 | int parent_phone = devman_parent_device_connect(fun->handle,
|
---|
| 81 | IPC_FLAG_BLOCKING);
|
---|
| 82 | if (parent_phone < 0) {
|
---|
| 83 | return parent_phone;
|
---|
| 84 | }
|
---|
[357a302] | 85 |
|
---|
[eb1a2f4] | 86 | sysarg_t hc_handle;
|
---|
| 87 | int rc = async_req_1_1(parent_phone, DEV_IFACE_ID(USB_DEV_IFACE),
|
---|
| 88 | IPC_M_USB_GET_HOST_CONTROLLER_HANDLE, &hc_handle);
|
---|
[357a302] | 89 |
|
---|
[3b271e3] | 90 | async_hangup(parent_phone);
|
---|
| 91 |
|
---|
[eb1a2f4] | 92 | if (rc != EOK) {
|
---|
| 93 | return rc;
|
---|
[357a302] | 94 | }
|
---|
| 95 |
|
---|
[eb1a2f4] | 96 | *handle = hc_handle;
|
---|
| 97 |
|
---|
| 98 | return EOK;
|
---|
[357a302] | 99 | }
|
---|
| 100 |
|
---|
| 101 | /** Get host controller handle, interface implementation for HC driver.
|
---|
| 102 | *
|
---|
[bc1c6fb] | 103 | * @param[in] fun Device function the operation is running on.
|
---|
[357a302] | 104 | * @param[out] handle Storage for the host controller handle.
|
---|
| 105 | * @return Always EOK.
|
---|
| 106 | */
|
---|
[eb1a2f4] | 107 | int usb_iface_get_hc_handle_hc_impl(ddf_fun_t *fun, devman_handle_t *handle)
|
---|
[357a302] | 108 | {
|
---|
[eb1a2f4] | 109 | assert(fun);
|
---|
[357a302] | 110 |
|
---|
| 111 | if (handle != NULL) {
|
---|
[eb1a2f4] | 112 | *handle = fun->handle;
|
---|
[357a302] | 113 | }
|
---|
| 114 |
|
---|
| 115 | return EOK;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | /** Get USB device address, interface implementation for hub driver.
|
---|
| 119 | *
|
---|
[bc1c6fb] | 120 | * @param[in] fun Device function the operation is running on.
|
---|
[357a302] | 121 | * @param[in] handle Devman handle of USB device we want address of.
|
---|
| 122 | * @param[out] address Storage for USB address of device with handle @p handle.
|
---|
| 123 | * @return Error code.
|
---|
| 124 | */
|
---|
[eb1a2f4] | 125 | int usb_iface_get_address_hub_impl(ddf_fun_t *fun, devman_handle_t handle,
|
---|
[357a302] | 126 | usb_address_t *address)
|
---|
| 127 | {
|
---|
[eb1a2f4] | 128 | assert(fun);
|
---|
| 129 | int parent_phone = devman_parent_device_connect(fun->handle,
|
---|
[357a302] | 130 | IPC_FLAG_BLOCKING);
|
---|
| 131 | if (parent_phone < 0) {
|
---|
| 132 | return parent_phone;
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | sysarg_t addr;
|
---|
| 136 | int rc = async_req_2_1(parent_phone, DEV_IFACE_ID(USB_DEV_IFACE),
|
---|
| 137 | IPC_M_USB_GET_ADDRESS, handle, &addr);
|
---|
| 138 |
|
---|
| 139 | async_hangup(parent_phone);
|
---|
| 140 |
|
---|
| 141 | if (rc != EOK) {
|
---|
| 142 | return rc;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | if (address != NULL) {
|
---|
| 146 | *address = (usb_address_t) addr;
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | return EOK;
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | /** Get USB device address, interface implementation for child of
|
---|
| 153 | * a hub driver.
|
---|
| 154 | *
|
---|
[bc1c6fb] | 155 | * @param[in] fun Device function the operation is running on.
|
---|
[357a302] | 156 | * @param[in] handle Devman handle of USB device we want address of.
|
---|
| 157 | * @param[out] address Storage for USB address of device with handle @p handle.
|
---|
| 158 | * @return Error code.
|
---|
| 159 | */
|
---|
[eb1a2f4] | 160 | int usb_iface_get_address_hub_child_impl(ddf_fun_t *fun,
|
---|
[357a302] | 161 | devman_handle_t handle, usb_address_t *address)
|
---|
| 162 | {
|
---|
[eb1a2f4] | 163 | if (handle == 0) {
|
---|
| 164 | handle = fun->handle;
|
---|
[357a302] | 165 | }
|
---|
[eb1a2f4] | 166 | return usb_iface_get_address_hub_impl(fun, handle, address);
|
---|
[357a302] | 167 | }
|
---|
| 168 |
|
---|
| 169 | /**
|
---|
| 170 | * @}
|
---|
| 171 | */
|
---|