source: mainline/uspace/lib/usbhost/include/usb/host/endpoint.h@ 205f1add

Last change on this file since 205f1add was 205f1add, checked in by Jakub Jermar <jakub@…>, 7 years ago

Get rid of sys/time.h

This commit moves the POSIX-like time functionality from libc's
sys/time.h to libposix and introduces C99-like or HelenOS-specific
interfaces to libc.

Specifically, use of sys/time.h, struct timeval, suseconds_t and
gettimeofday is replaced by time.h (C99), struct timespec (C99),
usec_t (HelenOS) and getuptime / getrealtime (HelenOS).

  • Property mode set to 100644
File size: 4.8 KB
RevLine 
[6ce42e85]1/*
2 * Copyright (c) 2011 Jan Vesely
[e0a5d4c]3 * Copyright (c) 2018 Ondrej Hlavaty
[6ce42e85]4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
[160b75e]30/** @addtogroup libusbhost
[6ce42e85]31 * @{
32 */
33/** @file
[41924f30]34 *
35 * Endpoint structure is tightly coupled to the bus. The bus controls the
36 * life-cycle of endpoint. In order to keep endpoints lightweight, operations
37 * on endpoints are part of the bus structure.
[8dc762e0]38 *
[6ce42e85]39 */
[160b75e]40#ifndef LIBUSBHOST_HOST_ENDPOINT_H
41#define LIBUSBHOST_HOST_ENDPOINT_H
[6ce42e85]42
43#include <adt/list.h>
[6a32665d]44#include <fibril_synch.h>
[498ced1]45#include <refcount.h>
[64fea02]46#include <stdbool.h>
[205f1add]47#include <time.h>
[6ce42e85]48#include <usb/usb.h>
[6832245]49#include <usb/host/bus.h>
[9efad54]50#include <usbhc_iface.h>
[6ce42e85]51
[41924f30]52typedef struct bus bus_t;
[20eaa82]53typedef struct device device_t;
[1d758fc]54typedef struct transfer_request transfer_request_t;
[5fd9c30]55typedef struct usb_transfer_batch usb_transfer_batch_t;
[41924f30]56
[4db49344]57/**
58 * Host controller side endpoint structure.
59 *
60 * This structure, though reference-counted, is very fragile. It is responsible
61 * for synchronizing transfer batch scheduling and completion.
62 *
63 * To avoid situations, in which two locks must be obtained to schedule/finish
64 * a transfer, the endpoint inherits a lock from the outside. Because the
65 * concrete instance of mutex can be unknown at the time of initialization,
66 * the HC shall pass the right lock at the time of onlining the endpoint.
67 *
68 * The fields used for scheduling (online, active_batch) are to be used only
69 * under that guard and by functions designed for this purpose. The driver can
70 * also completely avoid using this mechanism, in which case it is on its own in
71 * question of transfer aborting.
72 *
73 * Relevant information can be found in the documentation of HelenOS xHCI
74 * project.
75 */
[6ce42e85]76typedef struct endpoint {
[20eaa82]77 /** USB device */
78 device_t *device;
[6832245]79 /** Reference count. */
[498ced1]80 atomic_refcount_t refcnt;
[4db49344]81
82 /** An inherited guard */
83 fibril_mutex_t *guard;
84 /** Whether it's allowed to schedule on this endpoint */
85 bool online;
86 /** The currently active transfer batch. */
[17873ac7]87 usb_transfer_batch_t *active_batch;
[17412546]88 /** Signals change of active status. */
[6a32665d]89 fibril_condvar_t avail;
[41924f30]90
[4db49344]91 /** Endpoint number */
[9efad54]92 usb_endpoint_t endpoint;
93 /** Communication direction. */
94 usb_direction_t direction;
95 /** USB transfer type. */
96 usb_transfer_type_t transfer_type;
97 /** Maximum size of one packet */
98 size_t max_packet_size;
99
100 /** Maximum size of one transfer */
101 size_t max_transfer_size;
[1d758fc]102
103 /* Policies for transfer buffers */
[ae3a941]104 /** A hint for optimal performance. */
105 dma_policy_t transfer_buffer_policy;
106 /** Enforced by the library. */
107 dma_policy_t required_transfer_buffer_policy;
[fdc2253b]108
[4db49344]109 /**
110 * Number of packets that can be sent in one service interval
111 * (not necessarily uframe, despite its name)
112 */
[9efad54]113 unsigned packets_per_uframe;
114
[41924f30]115 /* This structure is meant to be extended by overriding. */
[6ce42e85]116} endpoint_t;
117
[ae3a941]118extern void endpoint_init(endpoint_t *, device_t *,
119 const usb_endpoint_descriptors_t *);
[1e70157]120
[58563585]121extern void endpoint_add_ref(endpoint_t *);
122extern void endpoint_del_ref(endpoint_t *);
[f527f58]123
[4db49344]124extern void endpoint_set_online(endpoint_t *, fibril_mutex_t *);
125extern void endpoint_set_offline_locked(endpoint_t *);
126
[205f1add]127extern void endpoint_wait_timeout_locked(endpoint_t *ep, usec_t);
[4db49344]128extern int endpoint_activate_locked(endpoint_t *, usb_transfer_batch_t *);
[17873ac7]129extern void endpoint_deactivate_locked(endpoint_t *);
130
[1d758fc]131int endpoint_send_batch(endpoint_t *, const transfer_request_t *);
[32fb6bce]132
[6832245]133static inline bus_t *endpoint_get_bus(endpoint_t *ep)
134{
[1433ecda]135 device_t *const device = ep->device;
[9748336]136 return device ? device->bus : NULL;
[6832245]137}
138
[6ce42e85]139#endif
[58563585]140
[6ce42e85]141/**
142 * @}
143 */
Note: See TracBrowser for help on using the repository browser.