source: mainline/uspace/lib/usbdev/include/usb/dev/pipes.h@ b77931d

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b77931d was b77931d, checked in by Jan Vesely <jano.vesely@…>, 14 years ago

usb: usb_pipe_t was always allocated in usb_endpoint_mapping_t, embed it.

  • Property mode set to 100644
File size: 6.7 KB
RevLine 
[6865243c]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
[160b75e]29/** @addtogroup libusbdev
[6865243c]30 * @{
31 */
32/** @file
[d714945]33 * USB pipes representation.
[6865243c]34 */
[7d521e24]35#ifndef LIBUSBDEV_PIPES_H_
36#define LIBUSBDEV_PIPES_H_
[6865243c]37
38#include <sys/types.h>
39#include <usb/usb.h>
[0edf7c7]40#include <usb/hc.h>
[93ef8f6]41#include <usb/descriptor.h>
[6865243c]42#include <ipc/devman.h>
[eb1a2f4]43#include <ddf/driver.h>
[d5ac90f]44#include <fibril_synch.h>
[79ae36dd]45#include <async.h>
[6865243c]46
[a6add7a]47/** Abstraction of a physical connection to the device.
[6865243c]48 * This type is an abstraction of the USB wire that connects the host and
49 * the function (device).
50 */
51typedef struct {
52 /** Handle of the host controller device is connected to. */
53 devman_handle_t hc_handle;
[43f698b]54 /** Address of the device. */
55 usb_address_t address;
[6865243c]56} usb_device_connection_t;
57
[a6add7a]58/** Abstraction of a logical connection to USB device endpoint.
[6865243c]59 * It encapsulates endpoint attributes (transfer type etc.) as well
60 * as information about currently running sessions.
61 * This endpoint must be bound with existing usb_device_connection_t
62 * (i.e. the wire to send data over).
[d48fcc0]63 *
64 * Locking order: if you want to lock both mutexes
[79ae36dd]65 * (@c guard and @c hc_sess_mutex), lock @c guard first.
66 * It is not necessary to lock @c guard if you want to lock @c hc_sess_mutex
[d48fcc0]67 * only.
[6865243c]68 */
69typedef struct {
[d48fcc0]70 /** Guard of the whole pipe. */
71 fibril_mutex_t guard;
72
[6865243c]73 /** The connection used for sending the data. */
74 usb_device_connection_t *wire;
75
76 /** Endpoint number. */
77 usb_endpoint_t endpoint_no;
78
79 /** Endpoint transfer type. */
80 usb_transfer_type_t transfer_type;
81
82 /** Endpoint direction. */
83 usb_direction_t direction;
84
[25971d2]85 /** Maximum packet size for the endpoint. */
86 size_t max_packet_size;
87
[79ae36dd]88 /** Session to the host controller.
89 * NULL when no session is active.
90 * It is an error to access this member without @c hc_sess_mutex
[d48fcc0]91 * being locked.
92 * If call over the phone is to be made, it must be preceeded by
93 * call to pipe_add_ref() [internal libusb function].
[6865243c]94 */
[79ae36dd]95 async_sess_t *hc_sess;
[d5ac90f]96
[79ae36dd]97 /** Guard for serialization of requests over the session. */
98 fibril_mutex_t hc_sess_mutex;
[a546687]99
100 /** Number of active transfers over the pipe. */
101 int refcount;
[2c2cbcf]102 /** Number of failed attempts to open the HC phone.
103 * When user requests usb_pipe_start_long_transfer() and the operation
104 * fails, there is no way to report this to the user.
105 * That the soft reference counter is increased to record the attempt.
106 * When the user then request e.g. usb_pipe_read(), it will try to
107 * add reference as well.
108 * If that fails, it is reported to the user. If it is okay, the
109 * real reference counter is incremented.
110 * The problem might arise when ending the long transfer (since
111 * the number of references would be only 1, but logically it shall be
112 * two).
113 * Decrementing the soft counter first shall solve this.
114 */
115 int refcount_soft;
[fa0f53b]116
117 /** Whether to automatically reset halt on the endpoint.
118 * Valid only for control endpoint zero.
119 */
120 bool auto_reset_halt;
[a372663]121} usb_pipe_t;
[6865243c]122
[93ef8f6]123
124/** Description of endpoint characteristics. */
125typedef struct {
126 /** Transfer type (e.g. control or interrupt). */
127 usb_transfer_type_t transfer_type;
128 /** Transfer direction (to or from a device). */
129 usb_direction_t direction;
130 /** Interface class this endpoint belongs to (-1 for any). */
131 int interface_class;
132 /** Interface subclass this endpoint belongs to (-1 for any). */
133 int interface_subclass;
[1110ebd]134 /** Interface protocol this endpoint belongs to (-1 for any). */
[93ef8f6]135 int interface_protocol;
136 /** Extra endpoint flags. */
137 unsigned int flags;
138} usb_endpoint_description_t;
139
140/** Mapping of endpoint pipes and endpoint descriptions. */
141typedef struct {
142 /** Endpoint pipe. */
[b77931d]143 usb_pipe_t pipe;
[93ef8f6]144 /** Endpoint description. */
145 const usb_endpoint_description_t *description;
[18cb870]146 /** Interface number the endpoint must belong to (-1 for any). */
[6105fc0]147 int interface_no;
[159b91f4]148 /** Alternate interface setting to choose. */
149 int interface_setting;
[93ef8f6]150 /** Found descriptor fitting the description. */
[b77931d]151 const usb_standard_endpoint_descriptor_t *descriptor;
[a6add7a]152 /** Interface descriptor the endpoint belongs to. */
[b77931d]153 const usb_standard_interface_descriptor_t *interface;
[93ef8f6]154 /** Whether the endpoint was actually found. */
155 bool present;
156} usb_endpoint_mapping_t;
[6865243c]157
[d714945]158int usb_device_connection_initialize_on_default_address(
159 usb_device_connection_t *, usb_hc_connection_t *);
[23c7f4d]160int usb_device_connection_initialize_from_device(usb_device_connection_t *,
[8e5ce07]161 const ddf_dev_t *);
[52fb76e]162int usb_device_connection_initialize(usb_device_connection_t *,
163 devman_handle_t, usb_address_t);
[6865243c]164
[8e5ce07]165int usb_device_get_assigned_interface(const ddf_dev_t *);
[27a0012]166
[3954a63b]167int usb_pipe_initialize(usb_pipe_t *, usb_device_connection_t *,
[25971d2]168 usb_endpoint_t, usb_transfer_type_t, size_t, usb_direction_t);
[3954a63b]169int usb_pipe_initialize_default_control(usb_pipe_t *,
[6865243c]170 usb_device_connection_t *);
[3954a63b]171int usb_pipe_probe_default_control(usb_pipe_t *);
172int usb_pipe_initialize_from_configuration(usb_endpoint_mapping_t *,
[7c95d6f5]173 size_t, const uint8_t *, size_t, usb_device_connection_t *);
[3954a63b]174int usb_pipe_register(usb_pipe_t *, unsigned int, usb_hc_connection_t *);
175int usb_pipe_unregister(usb_pipe_t *, usb_hc_connection_t *);
[6865243c]176
[2c2cbcf]177void usb_pipe_start_long_transfer(usb_pipe_t *);
[e9ce696]178void usb_pipe_end_long_transfer(usb_pipe_t *);
179
[3954a63b]180int usb_pipe_read(usb_pipe_t *, void *, size_t, size_t *);
181int usb_pipe_write(usb_pipe_t *, void *, size_t);
[6865243c]182
[7a05ced0]183int usb_pipe_control_read(usb_pipe_t *, const void *, size_t,
[6865243c]184 void *, size_t, size_t *);
[3875af65]185int usb_pipe_control_write(usb_pipe_t *, const void *, size_t,
186 const void *, size_t);
[6865243c]187
188#endif
189/**
190 * @}
191 */
Note: See TracBrowser for help on using the repository browser.