source: mainline/uspace/lib/usbhost/include/usb/host/bus.h@ f9d787c

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since f9d787c was 41924f30, checked in by Ondřej Hlavatý <aearsis@…>, 8 years ago

WIP usbhost refactoring

This commit replaces callbacks with more systematic virtual-like inheritance-like solution. Currently breaks build of HelenOS, but both xhci and usbhost are buildable. More refactoring follows…

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 * Copyright (c) 2017 Ondrej Hlavaty <aearsis@eideo.cz>
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/** @addtogroup libusbhost
29 * @{
30 */
31/** @file
32 * Virtual base for usb bus implementations.
33 *
34 * The purpose of this structure is to keep information about connected devices
35 * and enpoints, manage available bandwidth and the toggle bit flipping.
36 *
37 * The generic implementation is provided for USB 1 and 2 in usb2_bus.c. Some
38 * details in [OUE]HCI are solved through overriding some functions. XHCI does
39 * not need the bookkeeping functionality, because addresses are managed by HC
40 * itself.
41 */
42#ifndef LIBUSBHOST_HOST_BUS_H
43#define LIBUSBHOST_HOST_BUS_H
44
45#include <usb/usb.h>
46
47#include <fibril_synch.h>
48#include <stdbool.h>
49
50typedef struct hcd hcd_t;
51typedef struct endpoint endpoint_t;
52typedef struct bus bus_t;
53
54typedef struct {
55 endpoint_t *(*create_endpoint)(bus_t *);
56 int (*register_endpoint)(bus_t *, endpoint_t *);
57 int (*release_endpoint)(bus_t *, endpoint_t *);
58 endpoint_t *(*find_endpoint)(bus_t *, usb_target_t, usb_direction_t);
59
60 int (*request_address)(bus_t *, usb_address_t*, bool, usb_speed_t);
61 int (*get_speed)(bus_t *, usb_address_t, usb_speed_t *);
62 int (*release_address)(bus_t *, usb_address_t);
63
64 int (*reset_toggle)(bus_t *, usb_target_t, bool);
65
66 size_t (*count_bw) (endpoint_t *, size_t);
67
68 /* Endpoint ops, optional (have generic fallback) */
69 void (*destroy_endpoint)(endpoint_t *);
70 int (*endpoint_get_toggle)(endpoint_t *);
71 void (*endpoint_set_toggle)(endpoint_t *, unsigned);
72} bus_ops_t;
73
74/** Endpoint management structure */
75typedef struct bus {
76 hcd_t *hcd;
77
78 /* Synchronization of ops */
79 fibril_mutex_t guard;
80
81 /* Do not call directly, ops are synchronized. */
82 bus_ops_t ops;
83
84 /* This structure is meant to be extended by overriding. */
85} bus_t;
86
87void bus_init(bus_t *, hcd_t *hcd);
88
89endpoint_t *bus_create_endpoint(bus_t *);
90int bus_register_endpoint(bus_t *, endpoint_t *);
91int bus_release_endpoint(bus_t *, endpoint_t *);
92endpoint_t *bus_find_endpoint(bus_t *, usb_target_t, usb_direction_t);
93
94size_t bus_count_bw(endpoint_t *, size_t);
95
96int bus_request_address(bus_t *, usb_address_t *, bool, usb_speed_t);
97int bus_get_speed(bus_t *, usb_address_t, usb_speed_t *);
98int bus_release_address(bus_t *, usb_address_t);
99
100int bus_reset_toggle(bus_t *, usb_target_t, bool);
101
102#endif
103/**
104 * @}
105 */
Note: See TracBrowser for help on using the repository browser.