| 1 | /*
|
|---|
| 2 | * Copyright (c) 2010 Vojtech Horky
|
|---|
| 3 | * Copyright (c) 2011 Jan Vesely
|
|---|
| 4 | * Copyright (c) 2018 Michal Staruch, Ondrej Hlavaty
|
|---|
| 5 | * All rights reserved.
|
|---|
| 6 | *
|
|---|
| 7 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 8 | * modification, are permitted provided that the following conditions
|
|---|
| 9 | * are met:
|
|---|
| 10 | *
|
|---|
| 11 | * - Redistributions of source code must retain the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 13 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 14 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 15 | * documentation and/or other materials provided with the distribution.
|
|---|
| 16 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 17 | * derived from this software without specific prior written permission.
|
|---|
| 18 | *
|
|---|
| 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 29 | */
|
|---|
| 30 |
|
|---|
| 31 | /** @addtogroup libdrv
|
|---|
| 32 | * @{
|
|---|
| 33 | */
|
|---|
| 34 | /** @file
|
|---|
| 35 | */
|
|---|
| 36 |
|
|---|
| 37 | #include <async.h>
|
|---|
| 38 | #include <assert.h>
|
|---|
| 39 | #include <macros.h>
|
|---|
| 40 | #include <errno.h>
|
|---|
| 41 | #include <devman.h>
|
|---|
| 42 |
|
|---|
| 43 | #include "usb_iface.h"
|
|---|
| 44 | #include "ddf/driver.h"
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 | usb_dev_session_t *usb_dev_connect(devman_handle_t handle)
|
|---|
| 48 | {
|
|---|
| 49 | return devman_device_connect(handle, IPC_FLAG_BLOCKING);
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | usb_dev_session_t *usb_dev_connect_to_self(ddf_dev_t *dev)
|
|---|
| 53 | {
|
|---|
| 54 | return devman_parent_device_connect(ddf_dev_get_handle(dev),
|
|---|
| 55 | IPC_FLAG_BLOCKING);
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | void usb_dev_disconnect(usb_dev_session_t *sess)
|
|---|
| 59 | {
|
|---|
| 60 | if (sess)
|
|---|
| 61 | async_hangup(sess);
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | typedef enum {
|
|---|
| 65 | IPC_M_USB_GET_MY_DESCRIPTION,
|
|---|
| 66 | } usb_iface_funcs_t;
|
|---|
| 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 | errno_t usb_get_my_description(async_exch_t *exch, usb_device_desc_t *desc)
|
|---|
| 75 | {
|
|---|
| 76 | if (!exch)
|
|---|
| 77 | return EBADMEM;
|
|---|
| 78 |
|
|---|
| 79 | sysarg_t address, depth, speed, handle, iface;
|
|---|
| 80 |
|
|---|
| 81 | const errno_t ret = async_req_1_5(exch, DEV_IFACE_ID(USB_DEV_IFACE),
|
|---|
| 82 | IPC_M_USB_GET_MY_DESCRIPTION, &address, &depth, &speed, &handle,
|
|---|
| 83 | &iface);
|
|---|
| 84 | if (ret == EOK && desc) {
|
|---|
| 85 | *desc = (usb_device_desc_t) {
|
|---|
| 86 | .address = address,
|
|---|
| 87 | .depth = depth,
|
|---|
| 88 | .speed = speed,
|
|---|
| 89 | .handle = handle,
|
|---|
| 90 | .iface = iface,
|
|---|
| 91 | };
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | return ret;
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | static void remote_usb_get_my_description(ddf_fun_t *, void *, ipc_call_t *);
|
|---|
| 98 |
|
|---|
| 99 | /** Remote USB interface operations. */
|
|---|
| 100 | static const remote_iface_func_ptr_t remote_usb_iface_ops [] = {
|
|---|
| 101 | [IPC_M_USB_GET_MY_DESCRIPTION] = remote_usb_get_my_description,
|
|---|
| 102 | };
|
|---|
| 103 |
|
|---|
| 104 | /** Remote USB interface structure.
|
|---|
| 105 | */
|
|---|
| 106 | const remote_iface_t remote_usb_iface = {
|
|---|
| 107 | .method_count = ARRAY_SIZE(remote_usb_iface_ops),
|
|---|
| 108 | .methods = remote_usb_iface_ops,
|
|---|
| 109 | };
|
|---|
| 110 |
|
|---|
| 111 | void remote_usb_get_my_description(ddf_fun_t *fun, void *iface,
|
|---|
| 112 | ipc_call_t *call)
|
|---|
| 113 | {
|
|---|
| 114 | const usb_iface_t *usb_iface = (usb_iface_t *) iface;
|
|---|
| 115 |
|
|---|
| 116 | if (usb_iface->get_my_description == NULL) {
|
|---|
| 117 | async_answer_0(call, ENOTSUP);
|
|---|
| 118 | return;
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | usb_device_desc_t desc;
|
|---|
| 122 | const errno_t ret = usb_iface->get_my_description(fun, &desc);
|
|---|
| 123 | if (ret != EOK) {
|
|---|
| 124 | async_answer_0(call, ret);
|
|---|
| 125 | } else {
|
|---|
| 126 | async_answer_5(call, EOK,
|
|---|
| 127 | (sysarg_t) desc.address,
|
|---|
| 128 | (sysarg_t) desc.depth,
|
|---|
| 129 | (sysarg_t) desc.speed,
|
|---|
| 130 | desc.handle,
|
|---|
| 131 | desc.iface);
|
|---|
| 132 | }
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | /**
|
|---|
| 136 | * @}
|
|---|
| 137 | */
|
|---|