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

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

USB interfaces reorganization

The most important change is that getting USB address of a device
is an operation of generic USB interface, not USB-HC interface.
That is needed for proper functionality of a MID driver.

Also added sample implementation of USB interface operations as is
needed by most drivers (sample does not mean unfunctional or partially
implemented here).
They are stored in libusb/ddfiface.h

Updated UHCI, UHCI-RH, hub, VHC drivers to use these sample
implementations.

Updated libusb device recognition routines to route get_address requests
through USB interface.

  • Property mode set to 100644
File size: 5.2 KB
RevLine 
[357a302]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 <usb/ddfiface.h>
37#include <errno.h>
38
39/** DDF interface for USB device, implementation for typical hub. */
40usb_iface_t usb_iface_hub_impl = {
41 .get_hc_handle = usb_iface_get_hc_handle_hub_impl,
42 .get_address = usb_iface_get_address_hub_impl
43};
44
45/** DDF interface for USB device, implementation for child of a typical hub. */
46usb_iface_t usb_iface_hub_child_impl = {
47 .get_hc_handle = usb_iface_get_hc_handle_hub_child_impl,
48 .get_address = usb_iface_get_address_hub_child_impl
49};
50
51
52/** Get host controller handle, interface implementation for hub driver.
53 *
54 * @param[in] device Device the operation is running on.
55 * @param[out] handle Storage for the host controller handle.
56 * @return Error code.
57 */
58int usb_iface_get_hc_handle_hub_impl(device_t *device, devman_handle_t *handle)
59{
60 assert(device);
61 return usb_hc_find(device->handle, handle);
62}
63
64/** Get host controller handle, interface implementation for child of
65 * a hub driver.
66 *
67 * @param[in] device Device the operation is running on.
68 * @param[out] handle Storage for the host controller handle.
69 * @return Error code.
70 */
71int usb_iface_get_hc_handle_hub_child_impl(device_t *device,
72 devman_handle_t *handle)
73{
74 assert(device);
75 device_t *parent = device->parent;
76
77 /* Default error, device does not support this operation. */
78 int rc = ENOTSUP;
79
80 if (parent && parent->ops && parent->ops->interfaces[USB_DEV_IFACE]) {
81 usb_iface_t *usb_iface
82 = (usb_iface_t *) parent->ops->interfaces[USB_DEV_IFACE];
83 assert(usb_iface != NULL);
84
85 if (usb_iface->get_hc_handle) {
86 rc = usb_iface->get_hc_handle(parent, handle);
87 }
88 }
89
90 return rc;
91}
92
93/** Get host controller handle, interface implementation for HC driver.
94 *
95 * @param[in] device Device the operation is running on.
96 * @param[out] handle Storage for the host controller handle.
97 * @return Always EOK.
98 */
99int usb_iface_get_hc_handle_hc_impl(device_t *device, devman_handle_t *handle)
100{
101 assert(device);
102
103 if (handle != NULL) {
104 *handle = device->handle;
105 }
106
107 return EOK;
108}
109
110/** Get USB device address, interface implementation for hub driver.
111 *
112 * @param[in] device Device the operation is running on.
113 * @param[in] handle Devman handle of USB device we want address of.
114 * @param[out] address Storage for USB address of device with handle @p handle.
115 * @return Error code.
116 */
117int usb_iface_get_address_hub_impl(device_t *device, devman_handle_t handle,
118 usb_address_t *address)
119{
120 assert(device);
121 int parent_phone = devman_parent_device_connect(device->handle,
122 IPC_FLAG_BLOCKING);
123 if (parent_phone < 0) {
124 return parent_phone;
125 }
126
127 sysarg_t addr;
128 int rc = async_req_2_1(parent_phone, DEV_IFACE_ID(USB_DEV_IFACE),
129 IPC_M_USB_GET_ADDRESS, handle, &addr);
130
131 async_hangup(parent_phone);
132
133 if (rc != EOK) {
134 return rc;
135 }
136
137 if (address != NULL) {
138 *address = (usb_address_t) addr;
139 }
140
141 return EOK;
142}
143
144/** Get USB device address, interface implementation for child of
145 * a hub driver.
146 *
147 * @param[in] device Device the operation is running on.
148 * @param[in] handle Devman handle of USB device we want address of.
149 * @param[out] address Storage for USB address of device with handle @p handle.
150 * @return Error code.
151 */
152int usb_iface_get_address_hub_child_impl(device_t *device,
153 devman_handle_t handle, usb_address_t *address)
154{
155 assert(device);
156 device_t *parent = device->parent;
157
158 /* Default error, device does not support this operation. */
159 int rc = ENOTSUP;
160
161 if (parent && parent->ops && parent->ops->interfaces[USB_DEV_IFACE]) {
162 usb_iface_t *usb_iface
163 = (usb_iface_t *) parent->ops->interfaces[USB_DEV_IFACE];
164 assert(usb_iface != NULL);
165
166 if (usb_iface->get_address) {
167 rc = usb_iface->get_address(parent, handle, address);
168 }
169 }
170
171 return rc;
172}
173
174/**
175 * @}
176 */
Note: See TracBrowser for help on using the repository browser.