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 |
|
---|
46 | usb_dev_session_t *usb_dev_connect(devman_handle_t handle)
|
---|
47 | {
|
---|
48 | return devman_device_connect(handle, IPC_FLAG_BLOCKING);
|
---|
49 | }
|
---|
50 |
|
---|
51 | usb_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 |
|
---|
56 | void usb_dev_disconnect(usb_dev_session_t *sess)
|
---|
57 | {
|
---|
58 | if (sess)
|
---|
59 | async_hangup(sess);
|
---|
60 | }
|
---|
61 |
|
---|
62 | typedef 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 | */
|
---|
72 | int 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 int ret = async_req_1_4(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.speed,
|
---|
83 | &tmp_desc.handle,
|
---|
84 | (sysarg_t *) &tmp_desc.iface);
|
---|
85 | if (ret == EOK && desc)
|
---|
86 | *desc = tmp_desc;
|
---|
87 | return ret;
|
---|
88 | }
|
---|
89 |
|
---|
90 | static void remote_usb_get_my_description(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
91 |
|
---|
92 | /** Remote USB interface operations. */
|
---|
93 | static const remote_iface_func_ptr_t remote_usb_iface_ops [] = {
|
---|
94 | [IPC_M_USB_GET_MY_DESCRIPTION] = remote_usb_get_my_description,
|
---|
95 | };
|
---|
96 |
|
---|
97 | /** Remote USB interface structure.
|
---|
98 | */
|
---|
99 | const remote_iface_t remote_usb_iface = {
|
---|
100 | .method_count = ARRAY_SIZE(remote_usb_iface_ops),
|
---|
101 | .methods = remote_usb_iface_ops,
|
---|
102 | };
|
---|
103 |
|
---|
104 | void remote_usb_get_my_description(ddf_fun_t *fun, void *iface,
|
---|
105 | ipc_callid_t callid, ipc_call_t *call)
|
---|
106 | {
|
---|
107 | const usb_iface_t *usb_iface = (usb_iface_t *) iface;
|
---|
108 |
|
---|
109 | if (usb_iface->get_my_description == NULL) {
|
---|
110 | async_answer_0(callid, ENOTSUP);
|
---|
111 | return;
|
---|
112 | }
|
---|
113 |
|
---|
114 | usb_device_desc_t desc;
|
---|
115 | const int ret = usb_iface->get_my_description(fun, &desc);
|
---|
116 | if (ret != EOK) {
|
---|
117 | async_answer_0(callid, ret);
|
---|
118 | } else {
|
---|
119 | async_answer_4(callid, EOK,
|
---|
120 | (sysarg_t) desc.address,
|
---|
121 | (sysarg_t) desc.speed,
|
---|
122 | desc.handle,
|
---|
123 | desc.iface);
|
---|
124 | }
|
---|
125 | }
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * @}
|
---|
129 | */
|
---|