source: mainline/uspace/lib/usbhost/include/usb/host/endpoint.h@ 4c25c2fb

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 4c25c2fb was 0892663a, checked in by Ondřej Hlavatý <aearsis@…>, 7 years ago

usbhost: device removal and off/onlining moved into the library

Also, it is just not possible to make generic transfer abortion. So the
current semantics of endpoint unregistering is also aborting the pending
transfer. As it is not yet implemented in XHCI, and the stub in UHCI is
missing the magic, it breaks offlining interrupt devices, such as mouse.

When finishing this commit, I came across the fact we need some more
synchronization above device. Guard can protect internal structures, but
it cannot synchronize multiple calls to offline, or offline & removal
between each other - they both need to allow driver to unregister
endpoints, and as such must release the guard.

  • Property mode set to 100644
File size: 4.1 KB
RevLine 
[6ce42e85]1/*
2 * Copyright (c) 2011 Jan Vesely
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 libusbhost
[6ce42e85]30 * @{
31 */
32/** @file
[41924f30]33 *
34 * Endpoint structure is tightly coupled to the bus. The bus controls the
35 * life-cycle of endpoint. In order to keep endpoints lightweight, operations
36 * on endpoints are part of the bus structure.
[8dc762e0]37 *
[6ce42e85]38 */
[160b75e]39#ifndef LIBUSBHOST_HOST_ENDPOINT_H
40#define LIBUSBHOST_HOST_ENDPOINT_H
[6ce42e85]41
42#include <adt/list.h>
[64fea02]43#include <atomic.h>
[6a32665d]44#include <fibril_synch.h>
[64fea02]45#include <stdbool.h>
[0892663a]46#include <sys/time.h>
[6ce42e85]47#include <usb/usb.h>
[6832245]48#include <usb/host/bus.h>
[9efad54]49#include <usbhc_iface.h>
[6ce42e85]50
[41924f30]51typedef struct bus bus_t;
[20eaa82]52typedef struct device device_t;
[5fd9c30]53typedef struct usb_transfer_batch usb_transfer_batch_t;
[41924f30]54
[17412546]55/** Host controller side endpoint structure. */
[6ce42e85]56typedef struct endpoint {
[17873ac7]57 /** Part of linked list. */
58 link_t link;
[20eaa82]59 /** USB device */
60 device_t *device;
[6832245]61 /** Reference count. */
62 atomic_t refcnt;
[41924f30]63 /** Reserved bandwidth. */
[83c3123]64 size_t bandwidth;
[56257ba]65 /** Value of the toggle bit. Untouched by the library. */
[f567bcf]66 unsigned toggle:1;
[17873ac7]67 /** The currently active transfer batch. Write using methods, read under guard. */
68 usb_transfer_batch_t *active_batch;
[17412546]69 /** Protects resources and active status changes. */
[6a32665d]70 fibril_mutex_t guard;
[17412546]71 /** Signals change of active status. */
[6a32665d]72 fibril_condvar_t avail;
[41924f30]73
[9efad54]74 /** Enpoint number */
75 usb_endpoint_t endpoint;
76 /** Communication direction. */
77 usb_direction_t direction;
78 /** USB transfer type. */
79 usb_transfer_type_t transfer_type;
80 /** Maximum size of one packet */
81 size_t max_packet_size;
82
83 /** Maximum size of one transfer */
84 size_t max_transfer_size;
85 /** Number of packats that can be sent in one service interval (not necessarily uframe) */
86 unsigned packets_per_uframe;
87
[41924f30]88 /* This structure is meant to be extended by overriding. */
[6ce42e85]89} endpoint_t;
90
[9efad54]91extern void endpoint_init(endpoint_t *, device_t *, const usb_endpoint_descriptors_t *);
[1e70157]92
[58563585]93extern void endpoint_add_ref(endpoint_t *);
94extern void endpoint_del_ref(endpoint_t *);
[f527f58]95
[0892663a]96extern void endpoint_wait_timeout_locked(endpoint_t *ep, suseconds_t);
[17873ac7]97extern void endpoint_activate_locked(endpoint_t *, usb_transfer_batch_t *);
98extern void endpoint_deactivate_locked(endpoint_t *);
99
[6832245]100/* Calculate bandwidth */
101ssize_t endpoint_count_bw(endpoint_t *, size_t);
102
[32fb6bce]103int endpoint_send_batch(endpoint_t *, usb_target_t, usb_direction_t,
104 char *, size_t, uint64_t, usbhc_iface_transfer_callback_t, void *,
105 const char *);
106
[6832245]107static inline bus_t *endpoint_get_bus(endpoint_t *ep)
108{
[9748336]109 device_t * const device = ep->device;
110 return device ? device->bus : NULL;
[6832245]111}
112
[17412546]113/** list_get_instance wrapper.
[58563585]114 *
[17412546]115 * @param item Pointer to link member.
[58563585]116 *
[c59dbdd5]117 * @return Pointer to endpoint_t structure.
[58563585]118 *
[17412546]119 */
[7265558]120static inline endpoint_t * endpoint_get_instance(link_t *item)
121{
[c59dbdd5]122 return item ? list_get_instance(item, endpoint_t, link) : NULL;
[7265558]123}
[a5b3de6]124
[6ce42e85]125#endif
[58563585]126
[6ce42e85]127/**
128 * @}
129 */
Note: See TracBrowser for help on using the repository browser.