[f51594fa] | 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 | /** @addtogroup drvusbehci
|
---|
| 29 | * @{
|
---|
| 30 | */
|
---|
| 31 | /** @file
|
---|
| 32 | * USB-HC interface implementation.
|
---|
| 33 | */
|
---|
| 34 | #include <ddf/driver.h>
|
---|
| 35 | #include <ddf/interrupt.h>
|
---|
| 36 | #include <device/hw_res.h>
|
---|
| 37 | #include <errno.h>
|
---|
| 38 | #include <str_error.h>
|
---|
| 39 |
|
---|
| 40 | #include <usb_iface.h>
|
---|
| 41 | #include <usb/ddfiface.h>
|
---|
| 42 | #include <usb/debug.h>
|
---|
| 43 |
|
---|
| 44 | #include "ehci.h"
|
---|
| 45 |
|
---|
| 46 | #define UNSUPPORTED(methodname) \
|
---|
| 47 | usb_log_warning("Unsupported interface method `%s()' in %s:%d.\n", \
|
---|
| 48 | methodname, __FILE__, __LINE__)
|
---|
| 49 |
|
---|
[a763eb4] | 50 | /** Reserve default address.
|
---|
| 51 | *
|
---|
| 52 | * This function may block the caller.
|
---|
| 53 | *
|
---|
| 54 | * @param[in] fun Device function the action was invoked on.
|
---|
| 55 | * @param[in] speed Speed of the device for which the default address is
|
---|
| 56 | * reserved.
|
---|
| 57 | * @return Error code.
|
---|
| 58 | */
|
---|
[f51594fa] | 59 | static int reserve_default_address(ddf_fun_t *fun, usb_speed_t speed)
|
---|
| 60 | {
|
---|
| 61 | UNSUPPORTED("reserve_default_address");
|
---|
| 62 |
|
---|
| 63 | return ENOTSUP;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
[a763eb4] | 66 | /** Release default address.
|
---|
| 67 | *
|
---|
| 68 | * @param[in] fun Device function the action was invoked on.
|
---|
| 69 | * @return Error code.
|
---|
| 70 | */
|
---|
[f51594fa] | 71 | static int release_default_address(ddf_fun_t *fun)
|
---|
| 72 | {
|
---|
| 73 | UNSUPPORTED("release_default_address");
|
---|
| 74 |
|
---|
| 75 | return ENOTSUP;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
[a763eb4] | 78 | /** Found free USB address.
|
---|
| 79 | *
|
---|
| 80 | * @param[in] fun Device function the action was invoked on.
|
---|
| 81 | * @param[in] speed Speed of the device that will get this address.
|
---|
| 82 | * @param[out] address Non-null pointer where to store the free address.
|
---|
| 83 | * @return Error code.
|
---|
| 84 | */
|
---|
| 85 | static int request_address(ddf_fun_t *fun, usb_speed_t speed,
|
---|
| 86 | usb_address_t *address)
|
---|
[f51594fa] | 87 | {
|
---|
| 88 | UNSUPPORTED("request_address");
|
---|
| 89 |
|
---|
| 90 | return ENOTSUP;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
[a763eb4] | 93 | /** Bind USB address with device devman handle.
|
---|
| 94 | *
|
---|
| 95 | * @param[in] fun Device function the action was invoked on.
|
---|
| 96 | * @param[in] address USB address of the device.
|
---|
| 97 | * @param[in] handle Devman handle of the device.
|
---|
| 98 | * @return Error code.
|
---|
| 99 | */
|
---|
| 100 | static int bind_address(ddf_fun_t *fun,
|
---|
| 101 | usb_address_t address, devman_handle_t handle)
|
---|
[f51594fa] | 102 | {
|
---|
| 103 | UNSUPPORTED("bind_address");
|
---|
| 104 |
|
---|
| 105 | return ENOTSUP;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
[df25ab6] | 108 | /** Find device handle by USB address.
|
---|
| 109 | *
|
---|
| 110 | * @param[in] fun DDF function that was called.
|
---|
| 111 | * @param[in] address Address in question.
|
---|
| 112 | * @param[out] handle Where to store device handle if found.
|
---|
| 113 | * @return Error code.
|
---|
| 114 | */
|
---|
| 115 | static int find_by_address(ddf_fun_t *fun, usb_address_t address,
|
---|
| 116 | devman_handle_t *handle)
|
---|
| 117 | {
|
---|
| 118 | UNSUPPORTED("find_by_address");
|
---|
| 119 |
|
---|
| 120 | return ENOTSUP;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
[a763eb4] | 123 | /** Release previously requested address.
|
---|
| 124 | *
|
---|
| 125 | * @param[in] fun Device function the action was invoked on.
|
---|
| 126 | * @param[in] address USB address to be released.
|
---|
| 127 | * @return Error code.
|
---|
| 128 | */
|
---|
[f51594fa] | 129 | static int release_address(ddf_fun_t *fun, usb_address_t address)
|
---|
| 130 | {
|
---|
| 131 | UNSUPPORTED("release_address");
|
---|
| 132 |
|
---|
| 133 | return ENOTSUP;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
[a763eb4] | 136 | /** Register endpoint for bandwidth reservation.
|
---|
| 137 | *
|
---|
| 138 | * @param[in] fun Device function the action was invoked on.
|
---|
| 139 | * @param[in] address USB address of the device.
|
---|
[1998bcd] | 140 | * @param[in] speed Endpoint speed (invalid means to use device one).
|
---|
[a763eb4] | 141 | * @param[in] endpoint Endpoint number.
|
---|
| 142 | * @param[in] transfer_type USB transfer type.
|
---|
| 143 | * @param[in] direction Endpoint data direction.
|
---|
| 144 | * @param[in] max_packet_size Max packet size of the endpoint.
|
---|
| 145 | * @param[in] interval Polling interval.
|
---|
| 146 | * @return Error code.
|
---|
| 147 | */
|
---|
| 148 | static int register_endpoint(ddf_fun_t *fun,
|
---|
[1998bcd] | 149 | usb_address_t address, usb_speed_t speed, usb_endpoint_t endpoint,
|
---|
[f51594fa] | 150 | usb_transfer_type_t transfer_type, usb_direction_t direction,
|
---|
| 151 | size_t max_packet_size, unsigned int interval)
|
---|
| 152 | {
|
---|
| 153 | UNSUPPORTED("register_endpoint");
|
---|
| 154 |
|
---|
| 155 | return ENOTSUP;
|
---|
| 156 | }
|
---|
| 157 |
|
---|
[a763eb4] | 158 | /** Unregister endpoint (free some bandwidth reservation).
|
---|
| 159 | *
|
---|
| 160 | * @param[in] fun Device function the action was invoked on.
|
---|
| 161 | * @param[in] address USB address of the device.
|
---|
| 162 | * @param[in] endpoint Endpoint number.
|
---|
| 163 | * @param[in] direction Endpoint data direction.
|
---|
| 164 | * @return Error code.
|
---|
| 165 | */
|
---|
| 166 | static int unregister_endpoint(ddf_fun_t *fun, usb_address_t address,
|
---|
| 167 | usb_endpoint_t endpoint, usb_direction_t direction)
|
---|
[f51594fa] | 168 | {
|
---|
| 169 | UNSUPPORTED("unregister_endpoint");
|
---|
| 170 |
|
---|
| 171 | return ENOTSUP;
|
---|
| 172 | }
|
---|
| 173 |
|
---|
[a763eb4] | 174 | /** Schedule interrupt out transfer.
|
---|
| 175 | *
|
---|
| 176 | * The callback is supposed to be called once the transfer (on the wire) is
|
---|
| 177 | * complete regardless of the outcome.
|
---|
| 178 | * However, the callback could be called only when this function returns
|
---|
| 179 | * with success status (i.e. returns EOK).
|
---|
| 180 | *
|
---|
| 181 | * @param[in] fun Device function the action was invoked on.
|
---|
| 182 | * @param[in] target Target pipe (address and endpoint number) specification.
|
---|
| 183 | * @param[in] data Data to be sent (in USB endianess, allocated and deallocated
|
---|
| 184 | * by the caller).
|
---|
| 185 | * @param[in] size Size of the @p data buffer in bytes.
|
---|
| 186 | * @param[in] callback Callback to be issued once the transfer is complete.
|
---|
| 187 | * @param[in] arg Pass-through argument to the callback.
|
---|
| 188 | * @return Error code.
|
---|
| 189 | */
|
---|
[f51594fa] | 190 | static int interrupt_out(ddf_fun_t *fun, usb_target_t target,
|
---|
[7dfc06fa] | 191 | void *data, size_t size,
|
---|
[f51594fa] | 192 | usbhc_iface_transfer_out_callback_t callback, void *arg)
|
---|
| 193 | {
|
---|
| 194 | UNSUPPORTED("interrupt_out");
|
---|
| 195 |
|
---|
| 196 | return ENOTSUP;
|
---|
| 197 | }
|
---|
| 198 |
|
---|
[a763eb4] | 199 | /** Schedule interrupt in transfer.
|
---|
| 200 | *
|
---|
| 201 | * The callback is supposed to be called once the transfer (on the wire) is
|
---|
| 202 | * complete regardless of the outcome.
|
---|
| 203 | * However, the callback could be called only when this function returns
|
---|
| 204 | * with success status (i.e. returns EOK).
|
---|
| 205 | *
|
---|
| 206 | * @param[in] fun Device function the action was invoked on.
|
---|
| 207 | * @param[in] target Target pipe (address and endpoint number) specification.
|
---|
| 208 | * @param[in] data Buffer where to store the data (in USB endianess,
|
---|
| 209 | * allocated and deallocated by the caller).
|
---|
| 210 | * @param[in] size Size of the @p data buffer in bytes.
|
---|
| 211 | * @param[in] callback Callback to be issued once the transfer is complete.
|
---|
| 212 | * @param[in] arg Pass-through argument to the callback.
|
---|
| 213 | * @return Error code.
|
---|
| 214 | */
|
---|
[f51594fa] | 215 | static int interrupt_in(ddf_fun_t *fun, usb_target_t target,
|
---|
[7dfc06fa] | 216 | void *data, size_t size,
|
---|
[f51594fa] | 217 | usbhc_iface_transfer_in_callback_t callback, void *arg)
|
---|
| 218 | {
|
---|
| 219 | UNSUPPORTED("interrupt_in");
|
---|
| 220 |
|
---|
| 221 | return ENOTSUP;
|
---|
| 222 | }
|
---|
| 223 |
|
---|
[a763eb4] | 224 | /** Schedule bulk out transfer.
|
---|
| 225 | *
|
---|
| 226 | * The callback is supposed to be called once the transfer (on the wire) is
|
---|
| 227 | * complete regardless of the outcome.
|
---|
| 228 | * However, the callback could be called only when this function returns
|
---|
| 229 | * with success status (i.e. returns EOK).
|
---|
| 230 | *
|
---|
| 231 | * @param[in] fun Device function the action was invoked on.
|
---|
| 232 | * @param[in] target Target pipe (address and endpoint number) specification.
|
---|
| 233 | * @param[in] data Data to be sent (in USB endianess, allocated and deallocated
|
---|
| 234 | * by the caller).
|
---|
| 235 | * @param[in] size Size of the @p data buffer in bytes.
|
---|
| 236 | * @param[in] callback Callback to be issued once the transfer is complete.
|
---|
| 237 | * @param[in] arg Pass-through argument to the callback.
|
---|
| 238 | * @return Error code.
|
---|
| 239 | */
|
---|
[f51594fa] | 240 | static int bulk_out(ddf_fun_t *fun, usb_target_t target,
|
---|
[7dfc06fa] | 241 | void *data, size_t size,
|
---|
[f51594fa] | 242 | usbhc_iface_transfer_out_callback_t callback, void *arg)
|
---|
| 243 | {
|
---|
| 244 | UNSUPPORTED("bulk_out");
|
---|
| 245 |
|
---|
| 246 | return ENOTSUP;
|
---|
| 247 | }
|
---|
| 248 |
|
---|
[a763eb4] | 249 | /** Schedule bulk in transfer.
|
---|
| 250 | *
|
---|
| 251 | * The callback is supposed to be called once the transfer (on the wire) is
|
---|
| 252 | * complete regardless of the outcome.
|
---|
| 253 | * However, the callback could be called only when this function returns
|
---|
| 254 | * with success status (i.e. returns EOK).
|
---|
| 255 | *
|
---|
| 256 | * @param[in] fun Device function the action was invoked on.
|
---|
| 257 | * @param[in] target Target pipe (address and endpoint number) specification.
|
---|
| 258 | * @param[in] data Buffer where to store the data (in USB endianess,
|
---|
| 259 | * allocated and deallocated by the caller).
|
---|
| 260 | * @param[in] size Size of the @p data buffer in bytes.
|
---|
| 261 | * @param[in] callback Callback to be issued once the transfer is complete.
|
---|
| 262 | * @param[in] arg Pass-through argument to the callback.
|
---|
| 263 | * @return Error code.
|
---|
| 264 | */
|
---|
[f51594fa] | 265 | static int bulk_in(ddf_fun_t *fun, usb_target_t target,
|
---|
[7dfc06fa] | 266 | void *data, size_t size,
|
---|
[f51594fa] | 267 | usbhc_iface_transfer_in_callback_t callback, void *arg)
|
---|
| 268 | {
|
---|
| 269 | UNSUPPORTED("bulk_in");
|
---|
| 270 |
|
---|
| 271 | return ENOTSUP;
|
---|
| 272 | }
|
---|
| 273 |
|
---|
[a763eb4] | 274 | /** Schedule control write transfer.
|
---|
| 275 | *
|
---|
| 276 | * The callback is supposed to be called once the transfer (on the wire) is
|
---|
| 277 | * complete regardless of the outcome.
|
---|
| 278 | * However, the callback could be called only when this function returns
|
---|
| 279 | * with success status (i.e. returns EOK).
|
---|
| 280 | *
|
---|
| 281 | * @param[in] fun Device function the action was invoked on.
|
---|
| 282 | * @param[in] target Target pipe (address and endpoint number) specification.
|
---|
| 283 | * @param[in] setup_packet Setup packet buffer (in USB endianess, allocated
|
---|
| 284 | * and deallocated by the caller).
|
---|
| 285 | * @param[in] setup_packet_size Size of @p setup_packet buffer in bytes.
|
---|
| 286 | * @param[in] data_buffer Data buffer (in USB endianess, allocated and
|
---|
| 287 | * deallocated by the caller).
|
---|
| 288 | * @param[in] data_buffer_size Size of @p data_buffer buffer in bytes.
|
---|
| 289 | * @param[in] callback Callback to be issued once the transfer is complete.
|
---|
| 290 | * @param[in] arg Pass-through argument to the callback.
|
---|
| 291 | * @return Error code.
|
---|
| 292 | */
|
---|
[f51594fa] | 293 | static int control_write(ddf_fun_t *fun, usb_target_t target,
|
---|
[a763eb4] | 294 | void *setup_packet, size_t setup_packet_size,
|
---|
| 295 | void *data_buffer, size_t data_buffer_size,
|
---|
[f51594fa] | 296 | usbhc_iface_transfer_out_callback_t callback, void *arg)
|
---|
| 297 | {
|
---|
| 298 | UNSUPPORTED("control_write");
|
---|
| 299 |
|
---|
| 300 | return ENOTSUP;
|
---|
| 301 | }
|
---|
| 302 |
|
---|
[a763eb4] | 303 | /** Schedule control read transfer.
|
---|
| 304 | *
|
---|
| 305 | * The callback is supposed to be called once the transfer (on the wire) is
|
---|
| 306 | * complete regardless of the outcome.
|
---|
| 307 | * However, the callback could be called only when this function returns
|
---|
| 308 | * with success status (i.e. returns EOK).
|
---|
| 309 | *
|
---|
| 310 | * @param[in] fun Device function the action was invoked on.
|
---|
| 311 | * @param[in] target Target pipe (address and endpoint number) specification.
|
---|
| 312 | * @param[in] setup_packet Setup packet buffer (in USB endianess, allocated
|
---|
| 313 | * and deallocated by the caller).
|
---|
| 314 | * @param[in] setup_packet_size Size of @p setup_packet buffer in bytes.
|
---|
| 315 | * @param[in] data_buffer Buffer where to store the data (in USB endianess,
|
---|
| 316 | * allocated and deallocated by the caller).
|
---|
| 317 | * @param[in] data_buffer_size Size of @p data_buffer buffer in bytes.
|
---|
| 318 | * @param[in] callback Callback to be issued once the transfer is complete.
|
---|
| 319 | * @param[in] arg Pass-through argument to the callback.
|
---|
| 320 | * @return Error code.
|
---|
| 321 | */
|
---|
[f51594fa] | 322 | static int control_read(ddf_fun_t *fun, usb_target_t target,
|
---|
[a763eb4] | 323 | void *setup_packet, size_t setup_packet_size,
|
---|
| 324 | void *data_buffer, size_t data_buffer_size,
|
---|
[f51594fa] | 325 | usbhc_iface_transfer_in_callback_t callback, void *arg)
|
---|
| 326 | {
|
---|
| 327 | UNSUPPORTED("control_read");
|
---|
| 328 |
|
---|
| 329 | return ENOTSUP;
|
---|
| 330 | }
|
---|
| 331 |
|
---|
[a763eb4] | 332 | /** Host controller interface implementation for EHCI. */
|
---|
[f51594fa] | 333 | usbhc_iface_t ehci_hc_iface = {
|
---|
| 334 | .reserve_default_address = reserve_default_address,
|
---|
| 335 | .release_default_address = release_default_address,
|
---|
| 336 | .request_address = request_address,
|
---|
| 337 | .bind_address = bind_address,
|
---|
[df25ab6] | 338 | .find_by_address = find_by_address,
|
---|
[f51594fa] | 339 | .release_address = release_address,
|
---|
| 340 |
|
---|
| 341 | .register_endpoint = register_endpoint,
|
---|
| 342 | .unregister_endpoint = unregister_endpoint,
|
---|
| 343 |
|
---|
| 344 | .interrupt_out = interrupt_out,
|
---|
| 345 | .interrupt_in = interrupt_in,
|
---|
| 346 |
|
---|
| 347 | .bulk_out = bulk_out,
|
---|
| 348 | .bulk_in = bulk_in,
|
---|
| 349 |
|
---|
| 350 | .control_write = control_write,
|
---|
| 351 | .control_read = control_read
|
---|
| 352 | };
|
---|
| 353 |
|
---|
| 354 | /**
|
---|
| 355 | * @}
|
---|
| 356 | */
|
---|