Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/include/usb/host/endpoint.h

    r1d758fc r58563585  
    3232/** @file
    3333 *
    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.
    37  *
    3834 */
    3935#ifndef LIBUSBHOST_HOST_ENDPOINT_H
    4036#define LIBUSBHOST_HOST_ENDPOINT_H
    4137
     38#include <stdbool.h>
    4239#include <adt/list.h>
     40#include <fibril_synch.h>
     41#include <usb/usb.h>
    4342#include <atomic.h>
    44 #include <fibril_synch.h>
    45 #include <stdbool.h>
    46 #include <sys/time.h>
    47 #include <usb/usb.h>
    48 #include <usb/host/bus.h>
    49 #include <usbhc_iface.h>
    5043
    51 typedef struct bus bus_t;
    52 typedef struct device device_t;
    53 typedef struct transfer_request transfer_request_t;
    54 typedef struct usb_transfer_batch usb_transfer_batch_t;
    55 
    56 /**
    57  * Host controller side endpoint structure.
    58  *
    59  * This structure, though reference-counted, is very fragile. It is responsible
    60  * for synchronizing transfer batch scheduling and completion.
    61  *
    62  * To avoid situations, in which two locks must be obtained to schedule/finish
    63  * a transfer, the endpoint inherits a lock from the outside. Because the
    64  * concrete instance of mutex can be unknown at the time of initialization,
    65  * the HC shall pass the right lock at the time of onlining the endpoint.
    66  *
    67  * The fields used for scheduling (online, active_batch) are to be used only
    68  * under that guard and by functions designed for this purpose. The driver can
    69  * also completely avoid using this mechanism, in which case it is on its own in
    70  * question of transfer aborting.
    71  *
    72  * Relevant information can be found in the documentation of HelenOS xHCI
    73  * project.
    74  */
     44/** Host controller side endpoint structure. */
    7545typedef struct endpoint {
    76         /** USB device */
    77         device_t *device;
    7846        /** Reference count. */
    79         atomic_t refcnt;
    80 
    81         /** An inherited guard */
    82         fibril_mutex_t *guard;
    83         /** Whether it's allowed to schedule on this endpoint */
    84         bool online;
    85         /** The currently active transfer batch. */
    86         usb_transfer_batch_t *active_batch;
    87         /** Signals change of active status. */
    88         fibril_condvar_t avail;
    89 
    90         /** Endpoint number */
     47        atomic_t refcnt;       
     48        /** Part of linked list. */
     49        link_t link;
     50        /** USB address. */
     51        usb_address_t address;
     52        /** USB endpoint number. */
    9153        usb_endpoint_t endpoint;
    9254        /** Communication direction. */
     
    9456        /** USB transfer type. */
    9557        usb_transfer_type_t transfer_type;
    96         /** Maximum size of one packet */
     58        /** Communication speed. */
     59        usb_speed_t speed;
     60        /** Maximum size of data packets. */
    9761        size_t max_packet_size;
    98 
    99         /** Maximum size of one transfer */
    100         size_t max_transfer_size;
    101 
    102         /* Policies for transfer buffers */
    103         dma_policy_t transfer_buffer_policy;            /**< A hint for optimal performance. */
    104         dma_policy_t required_transfer_buffer_policy;   /**< Enforced by the library. */
    105 
    106         /**
    107          * Number of packets that can be sent in one service interval
    108          * (not necessarily uframe, despite its name)
    109          */
    110         unsigned packets_per_uframe;
    111 
    112         /* This structure is meant to be extended by overriding. */
     62        /** Additional opportunities per uframe */
     63        unsigned packets;
     64        /** Necessary bandwidth. */
     65        size_t bandwidth;
     66        /** Value of the toggle bit. */
     67        unsigned toggle:1;
     68        /** True if there is a batch using this scheduled for this endpoint. */
     69        volatile bool active;
     70        /** Protects resources and active status changes. */
     71        fibril_mutex_t guard;
     72        /** Signals change of active status. */
     73        fibril_condvar_t avail;
     74        /** High speed TT data */
     75        struct {
     76                usb_address_t address;
     77                unsigned port;
     78        } tt;
     79        /** Optional device specific data. */
     80        struct {
     81                /** Device specific data. */
     82                void *data;
     83                /** Callback to get the value of toggle bit. */
     84                int (*toggle_get)(void *);
     85                /** Callback to set the value of toggle bit. */
     86                void (*toggle_set)(void *, int);
     87        } hc_data;
    11388} endpoint_t;
    11489
    115 extern void endpoint_init(endpoint_t *, device_t *, const usb_endpoint_descriptors_t *);
     90extern endpoint_t *endpoint_create(usb_address_t, usb_endpoint_t,
     91    usb_direction_t, usb_transfer_type_t, usb_speed_t, size_t, unsigned int,
     92    size_t, usb_address_t, unsigned int);
     93extern void endpoint_destroy(endpoint_t *);
    11694
    11795extern void endpoint_add_ref(endpoint_t *);
    11896extern void endpoint_del_ref(endpoint_t *);
    11997
    120 extern void endpoint_set_online(endpoint_t *, fibril_mutex_t *);
    121 extern void endpoint_set_offline_locked(endpoint_t *);
     98extern void endpoint_set_hc_data(endpoint_t *, void *, int (*)(void *),
     99    void (*)(void *, int));
     100extern void endpoint_clear_hc_data(endpoint_t *);
    122101
    123 extern void endpoint_wait_timeout_locked(endpoint_t *ep, suseconds_t);
    124 extern int endpoint_activate_locked(endpoint_t *, usb_transfer_batch_t *);
    125 extern void endpoint_deactivate_locked(endpoint_t *);
     102extern void endpoint_use(endpoint_t *);
     103extern void endpoint_release(endpoint_t *);
    126104
    127 int endpoint_send_batch(endpoint_t *, const transfer_request_t *);
     105extern int endpoint_toggle_get(endpoint_t *);
     106extern void endpoint_toggle_set(endpoint_t *, int);
    128107
    129 static inline bus_t *endpoint_get_bus(endpoint_t *ep)
     108/** list_get_instance wrapper.
     109 *
     110 * @param item Pointer to link member.
     111 *
     112 * @return Pointer to endpoint_t structure.
     113 *
     114 */
     115static inline endpoint_t * endpoint_get_instance(link_t *item)
    130116{
    131         device_t * const device = ep->device;
    132         return device ? device->bus : NULL;
     117        return item ? list_get_instance(item, endpoint_t, link) : NULL;
    133118}
    134 
    135119#endif
    136120
Note: See TracChangeset for help on using the changeset viewer.