source: mainline/uspace/lib/usb/include/usb/pipes.h@ d48fcc0

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

Fine grain locking of USB pipes

  • Property mode set to 100644
File size: 6.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 * USB pipes representation.
34 */
35#ifndef LIBUSB_PIPES_H_
36#define LIBUSB_PIPES_H_
37
38#include <sys/types.h>
39#include <usb/usb.h>
40#include <usb/usbdevice.h>
41#include <usb/descriptor.h>
42#include <ipc/devman.h>
43#include <ddf/driver.h>
44#include <fibril_synch.h>
45
46/** Abstraction of a physical connection to the device.
47 * This type is an abstraction of the USB wire that connects the host and
48 * the function (device).
49 */
50typedef struct {
51 /** Handle of the host controller device is connected to. */
52 devman_handle_t hc_handle;
53 /** Address of the device. */
54 usb_address_t address;
55} usb_device_connection_t;
56
57/** Abstraction of a logical connection to USB device endpoint.
58 * It encapsulates endpoint attributes (transfer type etc.) as well
59 * as information about currently running sessions.
60 * This endpoint must be bound with existing usb_device_connection_t
61 * (i.e. the wire to send data over).
62 *
63 * Locking order: if you want to lock both mutexes
64 * (@c guard and @c hc_phone_mutex), lock @c guard first.
65 * It is not necessary to lock @c guard if you want to lock @c hc_phone_mutex
66 * only.
67 */
68typedef struct {
69 /** Guard of the whole pipe. */
70 fibril_mutex_t guard;
71
72 /** The connection used for sending the data. */
73 usb_device_connection_t *wire;
74
75 /** Endpoint number. */
76 usb_endpoint_t endpoint_no;
77
78 /** Endpoint transfer type. */
79 usb_transfer_type_t transfer_type;
80
81 /** Endpoint direction. */
82 usb_direction_t direction;
83
84 /** Maximum packet size for the endpoint. */
85 size_t max_packet_size;
86
87 /** Phone to the host controller.
88 * Negative when no session is active.
89 * It is an error to access this member without @c hc_phone_mutex
90 * being locked.
91 * If call over the phone is to be made, it must be preceeded by
92 * call to pipe_add_ref() [internal libusb function].
93 */
94 int hc_phone;
95
96 /** Guard for serialization of requests over the phone. */
97 fibril_mutex_t hc_phone_mutex;
98
99 /** Number of active transfers over the pipe. */
100 int refcount;
101} usb_pipe_t;
102
103
104/** Description of endpoint characteristics. */
105typedef struct {
106 /** Transfer type (e.g. control or interrupt). */
107 usb_transfer_type_t transfer_type;
108 /** Transfer direction (to or from a device). */
109 usb_direction_t direction;
110 /** Interface class this endpoint belongs to (-1 for any). */
111 int interface_class;
112 /** Interface subclass this endpoint belongs to (-1 for any). */
113 int interface_subclass;
114 /** Interface protocol this endpoint belongs to (-1 for any). */
115 int interface_protocol;
116 /** Extra endpoint flags. */
117 unsigned int flags;
118} usb_endpoint_description_t;
119
120/** Mapping of endpoint pipes and endpoint descriptions. */
121typedef struct {
122 /** Endpoint pipe. */
123 usb_pipe_t *pipe;
124 /** Endpoint description. */
125 const usb_endpoint_description_t *description;
126 /** Interface number the endpoint must belong to (-1 for any). */
127 int interface_no;
128 /** Alternate interface setting to choose. */
129 int interface_setting;
130 /** Found descriptor fitting the description. */
131 usb_standard_endpoint_descriptor_t *descriptor;
132 /** Interface descriptor the endpoint belongs to. */
133 usb_standard_interface_descriptor_t *interface;
134 /** Whether the endpoint was actually found. */
135 bool present;
136} usb_endpoint_mapping_t;
137
138int usb_device_connection_initialize_on_default_address(
139 usb_device_connection_t *, usb_hc_connection_t *);
140int usb_device_connection_initialize_from_device(usb_device_connection_t *,
141 ddf_dev_t *);
142int usb_device_connection_initialize(usb_device_connection_t *,
143 devman_handle_t, usb_address_t);
144
145int usb_device_get_assigned_interface(ddf_dev_t *);
146usb_address_t usb_device_get_assigned_address(devman_handle_t);
147
148int usb_pipe_initialize(usb_pipe_t *, usb_device_connection_t *,
149 usb_endpoint_t, usb_transfer_type_t, size_t, usb_direction_t);
150int usb_pipe_initialize_default_control(usb_pipe_t *,
151 usb_device_connection_t *);
152int usb_pipe_probe_default_control(usb_pipe_t *);
153int usb_pipe_initialize_from_configuration(usb_endpoint_mapping_t *,
154 size_t, uint8_t *, size_t, usb_device_connection_t *);
155int usb_pipe_register(usb_pipe_t *, unsigned int, usb_hc_connection_t *);
156int usb_pipe_unregister(usb_pipe_t *, usb_hc_connection_t *);
157
158int usb_pipe_start_session(usb_pipe_t *);
159int usb_pipe_end_session(usb_pipe_t *);
160bool usb_pipe_is_session_started(usb_pipe_t *);
161
162int usb_pipe_read(usb_pipe_t *, void *, size_t, size_t *);
163int usb_pipe_write(usb_pipe_t *, void *, size_t);
164
165int usb_pipe_control_read(usb_pipe_t *, void *, size_t,
166 void *, size_t, size_t *);
167int usb_pipe_control_write(usb_pipe_t *, void *, size_t,
168 void *, size_t);
169
170#endif
171/**
172 * @}
173 */
Note: See TracBrowser for help on using the repository browser.