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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since d345ce2 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
Line 
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 <assert.h>
38#include <macros.h>
39#include <errno.h>
40#include <devman.h>
41
42#include "usb_iface.h"
43#include "ddf/driver.h"
44
45
46usb_dev_session_t *usb_dev_connect(devman_handle_t handle)
47{
48 return devman_device_connect(handle, IPC_FLAG_BLOCKING);
49}
50
51usb_dev_session_t *usb_dev_connect_to_self(ddf_dev_t *dev)
52{
53 return devman_parent_device_connect(ddf_dev_get_handle(dev), IPC_FLAG_BLOCKING);
54}
55
56void usb_dev_disconnect(usb_dev_session_t *sess)
57{
58 if (sess)
59 async_hangup(sess);
60}
61
62typedef enum {
63 IPC_M_USB_GET_MY_DESCRIPTION,
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 */
72errno_t usb_get_my_description(async_exch_t *exch, usb_device_desc_t *desc)
73{
74 if (!exch)
75 return EBADMEM;
76
77 usb_device_desc_t tmp_desc;
78
79 const errno_t ret = async_req_1_5(exch, DEV_IFACE_ID(USB_DEV_IFACE),
80 IPC_M_USB_GET_MY_DESCRIPTION,
81 (sysarg_t *) &tmp_desc.address,
82 (sysarg_t *) &tmp_desc.depth,
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;
88 return ret;
89}
90
91static void remote_usb_get_my_description(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
92
93/** Remote USB interface operations. */
94static const remote_iface_func_ptr_t remote_usb_iface_ops [] = {
95 [IPC_M_USB_GET_MY_DESCRIPTION] = remote_usb_get_my_description,
96};
97
98/** Remote USB interface structure.
99 */
100const remote_iface_t remote_usb_iface = {
101 .method_count = ARRAY_SIZE(remote_usb_iface_ops),
102 .methods = remote_usb_iface_ops,
103};
104
105void remote_usb_get_my_description(ddf_fun_t *fun, void *iface,
106 ipc_callid_t callid, ipc_call_t *call)
107{
108 const usb_iface_t *usb_iface = (usb_iface_t *) iface;
109
110 if (usb_iface->get_my_description == NULL) {
111 async_answer_0(callid, ENOTSUP);
112 return;
113 }
114
115 usb_device_desc_t desc;
116 const errno_t ret = usb_iface->get_my_description(fun, &desc);
117 if (ret != EOK) {
118 async_answer_0(callid, ret);
119 } else {
120 async_answer_5(callid, EOK,
121 (sysarg_t) desc.address,
122 (sysarg_t) desc.depth,
123 (sysarg_t) desc.speed,
124 desc.handle,
125 desc.iface);
126 }
127}
128
129/**
130 * @}
131 */
Note: See TracBrowser for help on using the repository browser.