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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3cdaa7f was f9d0a86, checked in by Aearsis <Hlavaty.Ondrej@…>, 8 years ago

Merge tag '0.7.1'

The merge wasn't clean, because of changes in build system. The most
significant change was partial revert of usbhc callback refactoring,
which now does not take usb transfer batch, but few named fields again.

  • Property mode set to 100644
File size: 4.5 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_INTERFACE,
64 IPC_M_USB_GET_MY_DEVICE_HANDLE,
65} usb_iface_funcs_t;
66
67/** Tell interface number given device can use.
68 * @param[in] exch IPC communication exchange
69 * @param[in] handle Id of the device
70 * @param[out] usb_iface Assigned USB interface
71 * @return Error code.
72 */
73int usb_get_my_interface(async_exch_t *exch, int *usb_iface)
74{
75 if (!exch)
76 return EBADMEM;
77 sysarg_t iface_no;
78 const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
79 IPC_M_USB_GET_MY_INTERFACE, &iface_no);
80 if (ret == EOK && usb_iface)
81 *usb_iface = (int)iface_no;
82 return ret;
83}
84
85/** Tell devman handle of the usb device function.
86 *
87 * @param[in] exch IPC communication exchange
88 * @param[out] handle devman handle of the HC used by the target device.
89 *
90 * @return Error code.
91 *
92 */
93int usb_get_my_device_handle(async_exch_t *exch, devman_handle_t *handle)
94{
95 devman_handle_t h = 0;
96 const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
97 IPC_M_USB_GET_MY_DEVICE_HANDLE, &h);
98 if (ret == EOK && handle)
99 *handle = (devman_handle_t)h;
100 return ret;
101}
102
103static void remote_usb_get_my_interface(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
104static void remote_usb_get_my_device_handle(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
105
106/** Remote USB interface operations. */
107static const remote_iface_func_ptr_t remote_usb_iface_ops [] = {
108 [IPC_M_USB_GET_MY_INTERFACE] = remote_usb_get_my_interface,
109 [IPC_M_USB_GET_MY_DEVICE_HANDLE] = remote_usb_get_my_device_handle,
110};
111
112/** Remote USB interface structure.
113 */
114const remote_iface_t remote_usb_iface = {
115 .method_count = ARRAY_SIZE(remote_usb_iface_ops),
116 .methods = remote_usb_iface_ops,
117};
118
119void remote_usb_get_my_interface(ddf_fun_t *fun, void *iface,
120 ipc_callid_t callid, ipc_call_t *call)
121{
122 const usb_iface_t *usb_iface = (usb_iface_t *) iface;
123
124 if (usb_iface->get_my_interface == NULL) {
125 async_answer_0(callid, ENOTSUP);
126 return;
127 }
128
129 int iface_no;
130 const int ret = usb_iface->get_my_interface(fun, &iface_no);
131 if (ret != EOK) {
132 async_answer_0(callid, ret);
133 } else {
134 async_answer_1(callid, EOK, iface_no);
135 }
136}
137
138void remote_usb_get_my_device_handle(ddf_fun_t *fun, void *iface,
139 ipc_callid_t callid, ipc_call_t *call)
140{
141 const usb_iface_t *usb_iface = (usb_iface_t *) iface;
142
143 if (usb_iface->get_my_device_handle == NULL) {
144 async_answer_0(callid, ENOTSUP);
145 return;
146 }
147
148 devman_handle_t handle;
149 const int ret = usb_iface->get_my_device_handle(fun, &handle);
150 if (ret != EOK) {
151 async_answer_0(callid, ret);
152 }
153
154 async_answer_1(callid, EOK, (sysarg_t) handle);
155}
156
157/**
158 * @}
159 */
Note: See TracBrowser for help on using the repository browser.