source: mainline/uspace/drv/vhc/hub/hub.h@ bd8c753d

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

Doxygen group for USB virtualization

Virtual host controller and libusbvirt has separate Doxygen groups because
the usb group was polluted way too much.

  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 * Copyright (c) 2010 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 drvusbvhc
30 * @{
31 */
32/** @file
33 * @brief Representation of an USB hub.
34 */
35#ifndef VHC_HUB_HUB_H_
36#define VHC_HUB_HUB_H_
37
38#include <fibril_synch.h>
39
40#define HUB_PORT_COUNT 2
41#define BITS2BYTES(bits) (bits ? ((((bits)-1)>>3)+1) : 0)
42
43/** Hub port internal state.
44 * Some states (e.g. port over current) are not covered as they are not
45 * simulated at all.
46 */
47typedef enum {
48 HUB_PORT_STATE_UNKNOWN,
49 HUB_PORT_STATE_NOT_CONFIGURED,
50 HUB_PORT_STATE_POWERED_OFF,
51 HUB_PORT_STATE_DISCONNECTED,
52 HUB_PORT_STATE_DISABLED,
53 HUB_PORT_STATE_RESETTING,
54 HUB_PORT_STATE_ENABLED,
55 HUB_PORT_STATE_SUSPENDED,
56 HUB_PORT_STATE_RESUMING,
57 /* HUB_PORT_STATE_, */
58} hub_port_state_t;
59
60char hub_port_state_to_char(hub_port_state_t);
61
62/** Hub status change mask bits. */
63typedef enum {
64 HUB_STATUS_C_PORT_CONNECTION = (1 << 0),
65 HUB_STATUS_C_PORT_ENABLE = (1 << 1),
66 HUB_STATUS_C_PORT_SUSPEND = (1 << 2),
67 HUB_STATUS_C_PORT_OVER_CURRENT = (1 << 3),
68 HUB_STATUS_C_PORT_RESET = (1 << 4),
69 /* HUB_STATUS_C_ = (1 << ), */
70} hub_status_change_t;
71
72/** Hub port information. */
73typedef struct {
74 /** Custom pointer to connected device. */
75 void *connected_device;
76 /** Port index (one based). */
77 size_t index;
78 /** Port state. */
79 hub_port_state_t state;
80 /** Status change bitmap. */
81 uint16_t status_change;
82} hub_port_t;
83
84/** Hub device type. */
85typedef struct {
86 /** Hub ports. */
87 hub_port_t ports[HUB_PORT_COUNT];
88 /** Custom hub data. */
89 void *custom_data;
90 /** Access guard to the whole hub. */
91 fibril_mutex_t guard;
92} hub_t;
93
94void hub_init(hub_t *);
95size_t hub_connect_device(hub_t *, void *);
96int hub_disconnect_device(hub_t *, void *);
97size_t hub_find_device(hub_t *, void *);
98void hub_acquire(hub_t *);
99void hub_release(hub_t *);
100void hub_set_port_state(hub_t *, size_t, hub_port_state_t);
101void hub_set_port_state_all(hub_t *, hub_port_state_t);
102hub_port_state_t hub_get_port_state(hub_t *, size_t);
103void hub_clear_port_status_change(hub_t *, size_t, hub_status_change_t);
104uint16_t hub_get_port_status_change(hub_t *, size_t);
105uint32_t hub_get_port_status(hub_t *, size_t);
106uint8_t hub_get_status_change_bitmap(hub_t *);
107
108
109#endif
110/**
111 * @}
112 */
Note: See TracBrowser for help on using the repository browser.