source: mainline/uspace/lib/drv/generic/remote_usb.c@ 5595841

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 5595841 was 5a6cc679, checked in by Jenda <jenda.jzqk73@…>, 8 years ago

Merge commit '50f19b7ee8e94570b5c63896736c4eb49cfa18db' into forwardport

Not all ints are converted to errno_t in xhci tree yet, however it compiles and works :)

  • Property mode set to 100644
File size: 3.7 KB
RevLine 
[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]46usb_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]51usb_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]56void usb_dev_disconnect(usb_dev_session_t *sess)
[e938fa6]57{
58 if (sess)
59 async_hangup(sess);
[56bdd9a4]60}
[a76b01b4]61
[56bdd9a4]62typedef enum {
[c280d7e]63 IPC_M_USB_GET_MY_DESCRIPTION,
[56bdd9a4]64} usb_iface_funcs_t;
65
66/** Tell interface number given device can use.
67 * @param[in] exch IPC communication exchange
68 * @param[in] handle Id of the device
69 * @param[out] usb_iface Assigned USB interface
70 * @return Error code.
71 */
[5a6cc679]72errno_t usb_get_my_description(async_exch_t *exch, usb_device_desc_t *desc)
[56bdd9a4]73{
74 if (!exch)
[8afeb04]75 return EBADMEM;
[a76b01b4]76
[c280d7e]77 usb_device_desc_t tmp_desc;
78
[5a6cc679]79 const errno_t ret = async_req_1_5(exch, DEV_IFACE_ID(USB_DEV_IFACE),
[c280d7e]80 IPC_M_USB_GET_MY_DESCRIPTION,
81 (sysarg_t *) &tmp_desc.address,
[2aaba7e]82 (sysarg_t *) &tmp_desc.depth,
[c280d7e]83 (sysarg_t *) &tmp_desc.speed,
84 &tmp_desc.handle,
85 (sysarg_t *) &tmp_desc.iface);
86 if (ret == EOK && desc)
87 *desc = tmp_desc;
[9d15d1b]88 return ret;
89}
90
[c280d7e]91static void remote_usb_get_my_description(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
[56fb3732]92
93/** Remote USB interface operations. */
[9be30cdf]94static const remote_iface_func_ptr_t remote_usb_iface_ops [] = {
[c280d7e]95 [IPC_M_USB_GET_MY_DESCRIPTION] = remote_usb_get_my_description,
[56fb3732]96};
97
98/** Remote USB interface structure.
99 */
[7f80313]100const remote_iface_t remote_usb_iface = {
[9be30cdf]101 .method_count = ARRAY_SIZE(remote_usb_iface_ops),
[e938fa6]102 .methods = remote_usb_iface_ops,
[56fb3732]103};
104
[c280d7e]105void remote_usb_get_my_description(ddf_fun_t *fun, void *iface,
[357a302]106 ipc_callid_t callid, ipc_call_t *call)
107{
[56bdd9a4]108 const usb_iface_t *usb_iface = (usb_iface_t *) iface;
[357a302]109
[c280d7e]110 if (usb_iface->get_my_description == NULL) {
[357a302]111 async_answer_0(callid, ENOTSUP);
112 return;
113 }
114
[c280d7e]115 usb_device_desc_t desc;
[5a6cc679]116 const errno_t ret = usb_iface->get_my_description(fun, &desc);
[56bdd9a4]117 if (ret != EOK) {
118 async_answer_0(callid, ret);
[357a302]119 } else {
[2aaba7e]120 async_answer_5(callid, EOK,
[c280d7e]121 (sysarg_t) desc.address,
[2aaba7e]122 (sysarg_t) desc.depth,
[c280d7e]123 (sysarg_t) desc.speed,
124 desc.handle,
125 desc.iface);
[357a302]126 }
127}
[a76b01b4]128
[56fb3732]129/**
130 * @}
131 */
Note: See TracBrowser for help on using the repository browser.