source: mainline/uspace/lib/drv/include/usb_iface.h@ 91db50ac

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

USB driver to HC communication uses DDF interfaces

Started work on using interfaces on the background of communication
between HC and USB driver. However, for driver developers, this will
be hidden completely.

  • Property mode set to 100644
File size: 5.6 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 libdrv usb
30 * @{
31 */
32/** @file
33 * @brief USB interface definition.
34 */
35
36#ifndef LIBDRV_USB_IFACE_H_
37#define LIBDRV_USB_IFACE_H_
38
39#include "driver.h"
40#include <usb/usb.h>
41
42
43/** IPC methods for communication with HC through DDF interface.
44 *
45 * Notes for async methods:
46 *
47 * Methods for sending data to device (OUT transactions)
48 * - e.g. IPC_M_USB_INTERRUPT_OUT -
49 * always use the same semantics:
50 * - first, IPC call with given method is made
51 * - argument #1 is target address
52 * - argument #2 is target endpoint
53 * - argument #3 is buffer size
54 * - this call is immediately followed by IPC data write (from caller)
55 * - the initial call (and the whole transaction) is answer after the
56 * transaction is scheduled by the HC and acknowledged by the device
57 * or immediately after error is detected
58 * - the answer carries only the error code
59 *
60 * Methods for retrieving data from device (IN transactions)
61 * - e.g. IPC_M_USB_INTERRUPT_IN -
62 * also use the same semantics:
63 * - first, IPC call with given method is made
64 * - argument #1 is target address
65 * - argument #2 is target endpoint
66 * - argument #3 is buffer size
67 * - the call is not answered until the device returns some data (or until
68 * error occurs)
69 * - if the call is answered with EOK, first argument of the answer is buffer
70 * hash that could be used to retrieve the actual data
71 *
72 * Some special methods (NO-DATA transactions) do not send any data. These
73 * might behave as both OUT or IN transactions because communication parts
74 * where actual buffers are exchanged are omitted.
75 *
76 * The mentioned data retrieval can be done any time after receiving EOK
77 * answer to IN method.
78 * This retrieval is done using the IPC_M_USB_GET_BUFFER where
79 * the first argument is buffer hash from call answer.
80 * This call must be immediately followed by data read-in and after the
81 * data are transferred, the initial call (IPC_M_USB_GET_BUFFER)
82 * is answered. Each buffer can be retrieved only once.
83 *
84 * For all these methods, wrap functions exists. Important rule: functions
85 * for IN transactions have (as parameters) buffers where retrieved data
86 * will be stored. These buffers must be already allocated and shall not be
87 * touch until the transaction is completed
88 * (e.g. not before calling usb_wait_for() with appropriate handle).
89 * OUT transactions buffers can be freed immediately after call is dispatched
90 * (i.e. after return from wrapping function).
91 *
92 */
93typedef enum {
94 /** Asks for data buffer.
95 * See explanation at usb_method_t.
96 */
97 IPC_M_USB_GET_BUFFER,
98
99
100 /** Send interrupt data to device.
101 * See explanation at usb_method_t (OUT transaction).
102 */
103 IPC_M_USB_INTERRUPT_OUT,
104
105 /** Get interrupt data from device.
106 * See explanation at usb_method_t (IN transaction).
107 */
108 IPC_M_USB_INTERRUPT_IN,
109
110
111 /** Start WRITE control transfer.
112 * See explanation at usb_method_t (OUT transaction).
113 */
114 IPC_M_USB_CONTROL_WRITE_SETUP,
115
116 /** Send control-transfer data to device.
117 * See explanation at usb_method_t (OUT transaction).
118 */
119 IPC_M_USB_CONTROL_WRITE_DATA,
120
121 /** Terminate WRITE control transfer.
122 * See explanation at usb_method_t (NO-DATA transaction).
123 */
124 IPC_M_USB_CONTROL_WRITE_STATUS,
125
126
127
128 /** Start READ control transfer.
129 * See explanation at usb_method_t (OUT transaction).
130 */
131 IPC_M_USB_CONTROL_READ_SETUP,
132
133 /** Get control-transfer data from device.
134 * See explanation at usb_method_t (IN transaction).
135 */
136 IPC_M_USB_CONTROL_READ_DATA,
137
138 /** Terminate READ control transfer.
139 * See explanation at usb_method_t (NO-DATA transaction).
140 */
141 IPC_M_USB_CONTROL_READ_STATUS,
142
143
144 /* IPC_M_USB_ */
145} usb_iface_funcs_t;
146
147/** Callback for outgoing transfer. */
148typedef void (*usb_iface_transfer_out_callback_t)(device_t *,
149 usb_transaction_outcome_t, void *);
150
151/** Callback for incoming transfer. */
152typedef void (*usb_iface_transfer_in_callback_t)(device_t *,
153 usb_transaction_outcome_t, size_t, void *);
154
155/** USB devices communication interface. */
156typedef struct {
157 int (*interrupt_out)(device_t *, usb_endpoint_t,
158 void *, size_t,
159 usb_iface_transfer_out_callback_t, void *);
160 int (*interrupt_in)(device_t *, usb_endpoint_t,
161 void *, size_t,
162 usb_iface_transfer_in_callback_t, void *);
163} usb_iface_t;
164
165
166#endif
167/**
168 * @}
169 */
Note: See TracBrowser for help on using the repository browser.