source: mainline/uspace/lib/usb/src/ddfiface.c@ c4e3b1f7

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since c4e3b1f7 was bc1c6fb, checked in by Vojtech Horky <vojtechhorky@…>, 14 years ago

Doxygen comments fixes

No change in functionality.

  • Property mode set to 100644
File size: 5.0 KB
Line 
1/*
2 * Copyright (c) 2011 Vojtech Horky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libusb
30 * @{
31 */
32/** @file
33 * Implementations of DDF interfaces functions (actual implementation).
34 */
35#include <ipc/devman.h>
36#include <devman.h>
37#include <async.h>
38#include <usb/ddfiface.h>
39#include <usb/debug.h>
40#include <errno.h>
41#include <assert.h>
42
43/** DDF interface for USB device, implementation for typical hub. */
44usb_iface_t usb_iface_hub_impl = {
45 .get_hc_handle = usb_iface_get_hc_handle_hub_impl,
46 .get_address = usb_iface_get_address_hub_impl
47};
48
49/** DDF interface for USB device, implementation for child of a typical hub. */
50usb_iface_t usb_iface_hub_child_impl = {
51 .get_hc_handle = usb_iface_get_hc_handle_hub_child_impl,
52 .get_address = usb_iface_get_address_hub_child_impl
53};
54
55
56/** Get host controller handle, interface implementation for hub driver.
57 *
58 * @param[in] fun Device function the operation is running on.
59 * @param[out] handle Storage for the host controller handle.
60 * @return Error code.
61 */
62int usb_iface_get_hc_handle_hub_impl(ddf_fun_t *fun, devman_handle_t *handle)
63{
64 assert(fun);
65 return usb_hc_find(fun->handle, handle);
66}
67
68/** Get host controller handle, interface implementation for child of
69 * a hub driver.
70 *
71 * @param[in] fun Device function the operation is running on.
72 * @param[out] handle Storage for the host controller handle.
73 * @return Error code.
74 */
75int usb_iface_get_hc_handle_hub_child_impl(ddf_fun_t *fun,
76 devman_handle_t *handle)
77{
78 assert(fun != NULL);
79
80 int parent_phone = devman_parent_device_connect(fun->handle,
81 IPC_FLAG_BLOCKING);
82 if (parent_phone < 0) {
83 return parent_phone;
84 }
85
86 sysarg_t hc_handle;
87 int rc = async_req_1_1(parent_phone, DEV_IFACE_ID(USB_DEV_IFACE),
88 IPC_M_USB_GET_HOST_CONTROLLER_HANDLE, &hc_handle);
89
90 async_hangup(parent_phone);
91
92 if (rc != EOK) {
93 return rc;
94 }
95
96 *handle = hc_handle;
97
98 return EOK;
99}
100
101/** Get host controller handle, interface implementation for HC driver.
102 *
103 * @param[in] fun Device function the operation is running on.
104 * @param[out] handle Storage for the host controller handle.
105 * @return Always EOK.
106 */
107int usb_iface_get_hc_handle_hc_impl(ddf_fun_t *fun, devman_handle_t *handle)
108{
109 assert(fun);
110
111 if (handle != NULL) {
112 *handle = fun->handle;
113 }
114
115 return EOK;
116}
117
118/** Get USB device address, interface implementation for hub driver.
119 *
120 * @param[in] fun Device function the operation is running on.
121 * @param[in] handle Devman handle of USB device we want address of.
122 * @param[out] address Storage for USB address of device with handle @p handle.
123 * @return Error code.
124 */
125int usb_iface_get_address_hub_impl(ddf_fun_t *fun, devman_handle_t handle,
126 usb_address_t *address)
127{
128 assert(fun);
129 int parent_phone = devman_parent_device_connect(fun->handle,
130 IPC_FLAG_BLOCKING);
131 if (parent_phone < 0) {
132 return parent_phone;
133 }
134
135 sysarg_t addr;
136 int rc = async_req_2_1(parent_phone, DEV_IFACE_ID(USB_DEV_IFACE),
137 IPC_M_USB_GET_ADDRESS, handle, &addr);
138
139 async_hangup(parent_phone);
140
141 if (rc != EOK) {
142 return rc;
143 }
144
145 if (address != NULL) {
146 *address = (usb_address_t) addr;
147 }
148
149 return EOK;
150}
151
152/** Get USB device address, interface implementation for child of
153 * a hub driver.
154 *
155 * @param[in] fun Device function the operation is running on.
156 * @param[in] handle Devman handle of USB device we want address of.
157 * @param[out] address Storage for USB address of device with handle @p handle.
158 * @return Error code.
159 */
160int usb_iface_get_address_hub_child_impl(ddf_fun_t *fun,
161 devman_handle_t handle, usb_address_t *address)
162{
163 if (handle == 0) {
164 handle = fun->handle;
165 }
166 return usb_iface_get_address_hub_impl(fun, handle, address);
167}
168
169/**
170 * @}
171 */
Note: See TracBrowser for help on using the repository browser.