source: mainline/uspace/lib/drv/include/usbhc_iface.h@ 72363a1

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

Removal of usb_outcome_t (ticket 55)

  • Property mode set to 100644
File size: 8.6 KB
RevLine 
[91db50ac]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
[3b77628]29/** @addtogroup libdrv
30 * @addtogroup usb
[91db50ac]31 * @{
32 */
33/** @file
[6edd494]34 * @brief USB host controller interface definition.
[91db50ac]35 */
36
[cb59f787]37#ifndef LIBDRV_USBHC_IFACE_H_
38#define LIBDRV_USBHC_IFACE_H_
[91db50ac]39
40#include "driver.h"
41#include <usb/usb.h>
42
43
44/** IPC methods for communication with HC through DDF interface.
45 *
46 * Notes for async methods:
47 *
48 * Methods for sending data to device (OUT transactions)
[cb59f787]49 * - e.g. IPC_M_USBHC_INTERRUPT_OUT -
[91db50ac]50 * always use the same semantics:
51 * - first, IPC call with given method is made
52 * - argument #1 is target address
53 * - argument #2 is target endpoint
54 * - argument #3 is buffer size
55 * - this call is immediately followed by IPC data write (from caller)
56 * - the initial call (and the whole transaction) is answer after the
57 * transaction is scheduled by the HC and acknowledged by the device
58 * or immediately after error is detected
59 * - the answer carries only the error code
60 *
61 * Methods for retrieving data from device (IN transactions)
[cb59f787]62 * - e.g. IPC_M_USBHC_INTERRUPT_IN -
[91db50ac]63 * also use the same semantics:
64 * - first, IPC call with given method is made
65 * - argument #1 is target address
66 * - argument #2 is target endpoint
67 * - argument #3 is buffer size
[1e64b250]68 * - this call is immediately followed by IPC data read (async version)
[91db50ac]69 * - the call is not answered until the device returns some data (or until
70 * error occurs)
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.
[1e64b250]75 **
[91db50ac]76 * For all these methods, wrap functions exists. Important rule: functions
77 * for IN transactions have (as parameters) buffers where retrieved data
78 * will be stored. These buffers must be already allocated and shall not be
79 * touch until the transaction is completed
80 * (e.g. not before calling usb_wait_for() with appropriate handle).
81 * OUT transactions buffers can be freed immediately after call is dispatched
82 * (i.e. after return from wrapping function).
83 *
84 */
85typedef enum {
[aae339e9]86 /** Tell USB address assigned to device.
87 * Parameters:
88 * - devman handle id
89 * Answer:
90 * - EINVAL - unknown handle or handle not managed by this driver
91 * - ENOTSUP - operation not supported by HC (shall not happen)
92 * - arbitrary error code if returned by remote implementation
93 * - EOK - handle found, first parameter contains the USB address
94 */
95 IPC_M_USBHC_GET_ADDRESS,
96
[91db50ac]97
[6f04905]98 /** Reserve usage of default address.
99 * This call informs the host controller that the caller will be
100 * using default USB address. It is duty of the HC driver to ensure
101 * that only single entity will have it reserved.
102 * The address is returned via IPC_M_USBHC_RELEASE_DEFAULT_ADDRESS.
103 * The caller can start using the address after receiving EOK
104 * answer.
105 */
106 IPC_M_USBHC_RESERVE_DEFAULT_ADDRESS,
107
108 /** Release usage of default address.
109 * @see IPC_M_USBHC_RESERVE_DEFAULT_ADDRESS
110 */
111 IPC_M_USBHC_RELEASE_DEFAULT_ADDRESS,
112
113 /** Asks for address assignment by host controller.
114 * Answer:
115 * - ELIMIT - host controller run out of address
116 * - EOK - address assigned
117 * Answer arguments:
118 * - assigned address
119 *
120 * The address must be released by via IPC_M_USBHC_RELEASE_ADDRESS.
121 */
122 IPC_M_USBHC_REQUEST_ADDRESS,
123
[4689d40]124 /** Bind USB address with devman handle.
125 * Parameters:
126 * - USB address
127 * - devman handle
128 * Answer:
129 * - EOK - address binded
130 * - ENOENT - address is not in use
131 */
132 IPC_M_USBHC_BIND_ADDRESS,
133
[6f04905]134 /** Release address in use.
135 * Arguments:
136 * - address to be released
137 * Answer:
138 * - ENOENT - address not in use
139 * - EPERM - trying to release default USB address
140 */
141 IPC_M_USBHC_RELEASE_ADDRESS,
142
143
[91db50ac]144 /** Send interrupt data to device.
[1b22bd4]145 * See explanation at usb_iface_funcs_t (OUT transaction).
[91db50ac]146 */
[cb59f787]147 IPC_M_USBHC_INTERRUPT_OUT,
[91db50ac]148
149 /** Get interrupt data from device.
[1b22bd4]150 * See explanation at usb_iface_funcs_t (IN transaction).
[91db50ac]151 */
[cb59f787]152 IPC_M_USBHC_INTERRUPT_IN,
[91db50ac]153
154
155 /** Start WRITE control transfer.
[1b22bd4]156 * See explanation at usb_iface_funcs_t (OUT transaction).
[91db50ac]157 */
[cb59f787]158 IPC_M_USBHC_CONTROL_WRITE_SETUP,
[91db50ac]159
160 /** Send control-transfer data to device.
[1b22bd4]161 * See explanation at usb_iface_funcs_t (OUT transaction).
[91db50ac]162 */
[cb59f787]163 IPC_M_USBHC_CONTROL_WRITE_DATA,
[91db50ac]164
165 /** Terminate WRITE control transfer.
[1b22bd4]166 * See explanation at usb_iface_funcs_t (NO-DATA transaction).
[91db50ac]167 */
[cb59f787]168 IPC_M_USBHC_CONTROL_WRITE_STATUS,
[91db50ac]169
170
171
172 /** Start READ control transfer.
[1b22bd4]173 * See explanation at usb_iface_funcs_t (OUT transaction).
[91db50ac]174 */
[cb59f787]175 IPC_M_USBHC_CONTROL_READ_SETUP,
[91db50ac]176
177 /** Get control-transfer data from device.
[1b22bd4]178 * See explanation at usb_iface_funcs_t (IN transaction).
[91db50ac]179 */
[cb59f787]180 IPC_M_USBHC_CONTROL_READ_DATA,
[91db50ac]181
182 /** Terminate READ control transfer.
[1b22bd4]183 * See explanation at usb_iface_funcs_t (NO-DATA transaction).
[91db50ac]184 */
[cb59f787]185 IPC_M_USBHC_CONTROL_READ_STATUS,
[91db50ac]186
[9753220]187 /** Issue control WRITE transfer.
188 * See explanation at usb_iface_funcs_t (OUT transaction) for
189 * call parameters.
190 * This call is immediately followed by two IPC data writes
191 * from the caller (setup packet and actual data).
192 */
193 IPC_M_USBHC_CONTROL_WRITE,
194
195 /** Issue control WRITE transfer.
196 * See explanation at usb_iface_funcs_t (IN transaction) for
197 * call parameters.
198 * This call is immediately followed by IPC data read from the caller
199 * (setup packet).
200 * Actual data are retrieved through IPC_M_USBHC_GET_BUFFER.
201 */
202 IPC_M_USBHC_CONTROL_READ,
[91db50ac]203
204 /* IPC_M_USB_ */
[cb59f787]205} usbhc_iface_funcs_t;
[91db50ac]206
207/** Callback for outgoing transfer. */
[cb59f787]208typedef void (*usbhc_iface_transfer_out_callback_t)(device_t *,
[daec5e04]209 int, void *);
[91db50ac]210
211/** Callback for incoming transfer. */
[cb59f787]212typedef void (*usbhc_iface_transfer_in_callback_t)(device_t *,
[daec5e04]213 int, size_t, void *);
[91db50ac]214
[fb1dca09]215
216/** Out transfer processing function prototype. */
217typedef int (*usbhc_iface_transfer_out_t)(device_t *, usb_target_t,
218 void *, size_t,
219 usbhc_iface_transfer_out_callback_t, void *);
220
221/** Setup transfer processing function prototype. */
222typedef usbhc_iface_transfer_out_t usbhc_iface_transfer_setup_t;
223
224/** In transfer processing function prototype. */
225typedef int (*usbhc_iface_transfer_in_t)(device_t *, usb_target_t,
226 void *, size_t,
227 usbhc_iface_transfer_in_callback_t, void *);
228
[6edd494]229/** USB host controller communication interface. */
[91db50ac]230typedef struct {
[aae339e9]231 int (*tell_address)(device_t *, devman_handle_t, usb_address_t *);
[a3dfb2e]232
[6f04905]233 int (*reserve_default_address)(device_t *);
234 int (*release_default_address)(device_t *);
235 int (*request_address)(device_t *, usb_address_t *);
[4689d40]236 int (*bind_address)(device_t *, usb_address_t, devman_handle_t);
[6f04905]237 int (*release_address)(device_t *, usb_address_t);
238
[fb1dca09]239 usbhc_iface_transfer_out_t interrupt_out;
240 usbhc_iface_transfer_in_t interrupt_in;
[a3dfb2e]241
[fb1dca09]242 usbhc_iface_transfer_setup_t control_write_setup;
243 usbhc_iface_transfer_out_t control_write_data;
[a3dfb2e]244 int (*control_write_status)(device_t *, usb_target_t,
245 usbhc_iface_transfer_in_callback_t, void *);
246
[fb1dca09]247 usbhc_iface_transfer_setup_t control_read_setup;
248 usbhc_iface_transfer_in_t control_read_data;
[a3dfb2e]249 int (*control_read_status)(device_t *, usb_target_t,
250 usbhc_iface_transfer_out_callback_t, void *);
[9753220]251
252 int (*control_write)(device_t *, usb_target_t,
253 void *, size_t, void *, size_t,
254 usbhc_iface_transfer_out_callback_t, void *);
255
256 int (*control_read)(device_t *, usb_target_t,
257 void *, size_t, void *, size_t,
258 usbhc_iface_transfer_in_callback_t, void *);
[cb59f787]259} usbhc_iface_t;
[91db50ac]260
261
262#endif
263/**
264 * @}
265 */
Note: See TracBrowser for help on using the repository browser.