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

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

Merge mainline changes (DDF refactoring)

This merge includes DDF refactoring that brought multifunctional devices
(i.e. ddf_dev_t and ddf_fun_t). Please, see ticket #295 at HelenOS
upstream Trac.

The conflicts themselves were easy to solve (merely several renamings).

Changes to USB subsystem:

  • drivers uses ddf_dev_t and ddf_fun_t
  • different signatures of many library functions
  • several hacks around communication with parent device (now the communication is clearer and somehow what we have now is hack about other hacks)
    • will repair and clean later
  • maybe added some extra debugging messages (the diff has about 240K, and I admit I have no energy to double check that)

WARNING:

  • the diff is VERY long, recommended is viewing partial diffs of the merge (i.e. merges in mainline branch that lead to the parent one)
  • merging with your branches might involve huge renamings, sorry, no other way is possible

BUGS:

  • hub driver will not work (no function created)

GOOD NEWS:

  • QEMU keyboard seems to work with QEMU 0.13 and 0.14
  • we are up-to-date with mainline again
  • Property mode set to 100644
File size: 4.9 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] device Device 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] device Device 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 if (rc != EOK) {
91 return rc;
92 }
93
94 *handle = hc_handle;
95
96 return EOK;
97}
98
99/** Get host controller handle, interface implementation for HC driver.
100 *
101 * @param[in] device Device the operation is running on.
102 * @param[out] handle Storage for the host controller handle.
103 * @return Always EOK.
104 */
105int usb_iface_get_hc_handle_hc_impl(ddf_fun_t *fun, devman_handle_t *handle)
106{
107 assert(fun);
108
109 if (handle != NULL) {
110 *handle = fun->handle;
111 }
112
113 return EOK;
114}
115
116/** Get USB device address, interface implementation for hub driver.
117 *
118 * @param[in] device Device the operation is running on.
119 * @param[in] handle Devman handle of USB device we want address of.
120 * @param[out] address Storage for USB address of device with handle @p handle.
121 * @return Error code.
122 */
123int usb_iface_get_address_hub_impl(ddf_fun_t *fun, devman_handle_t handle,
124 usb_address_t *address)
125{
126 assert(fun);
127 int parent_phone = devman_parent_device_connect(fun->handle,
128 IPC_FLAG_BLOCKING);
129 if (parent_phone < 0) {
130 return parent_phone;
131 }
132
133 sysarg_t addr;
134 int rc = async_req_2_1(parent_phone, DEV_IFACE_ID(USB_DEV_IFACE),
135 IPC_M_USB_GET_ADDRESS, handle, &addr);
136
137 async_hangup(parent_phone);
138
139 if (rc != EOK) {
140 return rc;
141 }
142
143 if (address != NULL) {
144 *address = (usb_address_t) addr;
145 }
146
147 return EOK;
148}
149
150/** Get USB device address, interface implementation for child of
151 * a hub driver.
152 *
153 * @param[in] device Device the operation is running on.
154 * @param[in] handle Devman handle of USB device we want address of.
155 * @param[out] address Storage for USB address of device with handle @p handle.
156 * @return Error code.
157 */
158int usb_iface_get_address_hub_child_impl(ddf_fun_t *fun,
159 devman_handle_t handle, usb_address_t *address)
160{
161 if (handle == 0) {
162 handle = fun->handle;
163 }
164 return usb_iface_get_address_hub_impl(fun, handle, address);
165}
166
167/**
168 * @}
169 */
Note: See TracBrowser for help on using the repository browser.