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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 7f620e8 was 7f80313, checked in by Jan Vesely <jano.vesely@…>, 12 years ago

libdrv: Make interface structures constant.

  • Property mode set to 100644
File size: 5.3 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>
37#include <errno.h>
[9be30cdf]38#include <macros.h>
[56fb3732]39
40#include "usb_iface.h"
[eb1a2f4]41#include "ddf/driver.h"
[56fb3732]42
[56bdd9a4]43typedef enum {
44 IPC_M_USB_GET_MY_ADDRESS,
45 IPC_M_USB_GET_MY_INTERFACE,
46 IPC_M_USB_GET_HOST_CONTROLLER_HANDLE,
47} usb_iface_funcs_t;
48
49/** Tell USB address assigned to device.
50 * @param exch Vaid IPC exchange
51 * @param address Pointer to address storage place.
52 * @return Error code.
53 *
54 * Exch param is an open communication to device implementing usb_iface.
55 */
56int usb_get_my_address(async_exch_t *exch, usb_address_t *address)
57{
58 if (!exch)
[8afeb04]59 return EBADMEM;
[56bdd9a4]60 sysarg_t addr;
61 const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
62 IPC_M_USB_GET_MY_ADDRESS, &addr);
63
64 if (ret == EOK && address != NULL)
65 *address = (usb_address_t) addr;
66 return ret;
67}
[a76b01b4]68
[56bdd9a4]69/** Tell interface number given device can use.
70 * @param[in] exch IPC communication exchange
71 * @param[in] handle Id of the device
72 * @param[out] usb_iface Assigned USB interface
73 * @return Error code.
74 */
75int usb_get_my_interface(async_exch_t *exch, int *usb_iface)
76{
77 if (!exch)
[8afeb04]78 return EBADMEM;
[56bdd9a4]79 sysarg_t iface_no;
80 const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
81 IPC_M_USB_GET_MY_INTERFACE, &iface_no);
82 if (ret == EOK && usb_iface)
83 *usb_iface = (int)iface_no;
84 return ret;
85}
[a76b01b4]86
[56bdd9a4]87/** Tell devman handle of device host controller.
88 * @param[in] exch IPC communication exchange
89 * @param[out] hc_handle devman handle of the HC used by the target device.
90 * @return Error code.
91 */
92int usb_get_hc_handle(async_exch_t *exch, devman_handle_t *hc_handle)
93{
94 if (!exch)
[8afeb04]95 return EBADMEM;
[56bdd9a4]96 devman_handle_t h;
97 const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
98 IPC_M_USB_GET_HOST_CONTROLLER_HANDLE, &h);
99 if (ret == EOK && hc_handle)
100 *hc_handle = (devman_handle_t)h;
101 return ret;
102}
103
[56fb3732]104
[27ed734c]105static void remote_usb_get_my_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
[317a463]106static void remote_usb_get_my_interface(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
[eb1a2f4]107static void remote_usb_get_hc_handle(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
[56fb3732]108
109/** Remote USB interface operations. */
[9be30cdf]110static const remote_iface_func_ptr_t remote_usb_iface_ops [] = {
[27ed734c]111 [IPC_M_USB_GET_MY_ADDRESS] = remote_usb_get_my_address,
[317a463]112 [IPC_M_USB_GET_MY_INTERFACE] = remote_usb_get_my_interface,
[27ed734c]113 [IPC_M_USB_GET_HOST_CONTROLLER_HANDLE] = remote_usb_get_hc_handle,
[56fb3732]114};
115
116/** Remote USB interface structure.
117 */
[7f80313]118const remote_iface_t remote_usb_iface = {
[9be30cdf]119 .method_count = ARRAY_SIZE(remote_usb_iface_ops),
[56fb3732]120 .methods = remote_usb_iface_ops
121};
122
[a76b01b4]123
[27ed734c]124void remote_usb_get_my_address(ddf_fun_t *fun, void *iface,
[357a302]125 ipc_callid_t callid, ipc_call_t *call)
126{
[56bdd9a4]127 const usb_iface_t *usb_iface = (usb_iface_t *) iface;
[357a302]128
[27ed734c]129 if (usb_iface->get_my_address == NULL) {
[357a302]130 async_answer_0(callid, ENOTSUP);
131 return;
132 }
133
134 usb_address_t address;
[56bdd9a4]135 const int ret = usb_iface->get_my_address(fun, &address);
136 if (ret != EOK) {
137 async_answer_0(callid, ret);
[357a302]138 } else {
139 async_answer_1(callid, EOK, address);
140 }
141}
[a76b01b4]142
[317a463]143void remote_usb_get_my_interface(ddf_fun_t *fun, void *iface,
[95120c3]144 ipc_callid_t callid, ipc_call_t *call)
145{
[56bdd9a4]146 const usb_iface_t *usb_iface = (usb_iface_t *) iface;
[95120c3]147
[317a463]148 if (usb_iface->get_my_interface == NULL) {
[95120c3]149 async_answer_0(callid, ENOTSUP);
150 return;
151 }
152
153 int iface_no;
[56bdd9a4]154 const int ret = usb_iface->get_my_interface(fun, &iface_no);
155 if (ret != EOK) {
156 async_answer_0(callid, ret);
[95120c3]157 } else {
158 async_answer_1(callid, EOK, iface_no);
159 }
160}
[a76b01b4]161
[eb1a2f4]162void remote_usb_get_hc_handle(ddf_fun_t *fun, void *iface,
[56fb3732]163 ipc_callid_t callid, ipc_call_t *call)
164{
[56bdd9a4]165 const usb_iface_t *usb_iface = (usb_iface_t *) iface;
[56fb3732]166
167 if (usb_iface->get_hc_handle == NULL) {
[17aca1c]168 async_answer_0(callid, ENOTSUP);
[56fb3732]169 return;
170 }
171
172 devman_handle_t handle;
[56bdd9a4]173 const int ret = usb_iface->get_hc_handle(fun, &handle);
174 if (ret != EOK) {
175 async_answer_0(callid, ret);
[56fb3732]176 }
177
[17aca1c]178 async_answer_1(callid, EOK, (sysarg_t) handle);
[56fb3732]179}
180/**
181 * @}
182 */
Note: See TracBrowser for help on using the repository browser.