Ignore:
Timestamp:
2018-02-28T16:37:50Z (6 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1b20da0
Parents:
f5e5f73 (diff), b2dca8de (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Jakub Jermar <jakub@…> (2018-02-28 16:06:42)
git-committer:
Jakub Jermar <jakub@…> (2018-02-28 16:37:50)
Message:

Merge github.com:helenos-xhci-team/helenos

This commit merges support for USB 3 and generally refactors, fixes,
extends and cleans up the existing USB framework.

Notable additions and features:

  • new host controller driver has been implemented to control various xHC models (among others, NEC Renesas uPD720200)
  • isochronous data transfer mode
  • support for explicit USB device removal
  • USB tablet driver
File:
1 edited

Legend:

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

    rf5e5f73 rdf6ded8  
    11/*
    22 * Copyright (c) 2011 Jan Vesely
     3 * Copyright (c) 2018 Ondrej Hlavaty
    34 * All rights reserved.
    45 *
     
    3233/** @file
    3334 *
     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.
     38 *
    3439 */
    3540#ifndef LIBUSBHOST_HOST_ENDPOINT_H
    3641#define LIBUSBHOST_HOST_ENDPOINT_H
    3742
     43#include <adt/list.h>
     44#include <atomic.h>
     45#include <fibril_synch.h>
    3846#include <stdbool.h>
    39 #include <adt/list.h>
    40 #include <fibril_synch.h>
     47#include <sys/time.h>
    4148#include <usb/usb.h>
    42 #include <atomic.h>
     49#include <usb/host/bus.h>
     50#include <usbhc_iface.h>
    4351
    44 /** Host controller side endpoint structure. */
     52typedef struct bus bus_t;
     53typedef struct device device_t;
     54typedef struct transfer_request transfer_request_t;
     55typedef struct usb_transfer_batch usb_transfer_batch_t;
     56
     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 */
    4576typedef struct endpoint {
     77        /** USB device */
     78        device_t *device;
    4679        /** Reference count. */
    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. */
     80        atomic_t refcnt;
     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. */
     87        usb_transfer_batch_t *active_batch;
     88        /** Signals change of active status. */
     89        fibril_condvar_t avail;
     90
     91        /** Endpoint number */
    5392        usb_endpoint_t endpoint;
    5493        /** Communication direction. */
     
    5695        /** USB transfer type. */
    5796        usb_transfer_type_t transfer_type;
    58         /** Communication speed. */
    59         usb_speed_t speed;
    60         /** Maximum size of data packets. */
     97        /** Maximum size of one packet */
    6198        size_t max_packet_size;
    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;
     99
     100        /** Maximum size of one transfer */
     101        size_t max_transfer_size;
     102
     103        /* Policies for transfer buffers */
     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;
     108
     109        /**
     110         * Number of packets that can be sent in one service interval
     111         * (not necessarily uframe, despite its name)
     112         */
     113        unsigned packets_per_uframe;
     114
     115        /* This structure is meant to be extended by overriding. */
    88116} endpoint_t;
    89117
    90 extern 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);
    93 extern void endpoint_destroy(endpoint_t *);
     118extern void endpoint_init(endpoint_t *, device_t *,
     119    const usb_endpoint_descriptors_t *);
    94120
    95121extern void endpoint_add_ref(endpoint_t *);
    96122extern void endpoint_del_ref(endpoint_t *);
    97123
    98 extern void endpoint_set_hc_data(endpoint_t *, void *, int (*)(void *),
    99     void (*)(void *, int));
    100 extern void endpoint_clear_hc_data(endpoint_t *);
     124extern void endpoint_set_online(endpoint_t *, fibril_mutex_t *);
     125extern void endpoint_set_offline_locked(endpoint_t *);
    101126
    102 extern void endpoint_use(endpoint_t *);
    103 extern void endpoint_release(endpoint_t *);
     127extern void endpoint_wait_timeout_locked(endpoint_t *ep, suseconds_t);
     128extern int endpoint_activate_locked(endpoint_t *, usb_transfer_batch_t *);
     129extern void endpoint_deactivate_locked(endpoint_t *);
    104130
    105 extern int endpoint_toggle_get(endpoint_t *);
    106 extern void endpoint_toggle_set(endpoint_t *, int);
     131int endpoint_send_batch(endpoint_t *, const transfer_request_t *);
    107132
    108 /** list_get_instance wrapper.
    109  *
    110  * @param item Pointer to link member.
    111  *
    112  * @return Pointer to endpoint_t structure.
    113  *
    114  */
    115 static inline endpoint_t * endpoint_get_instance(link_t *item)
     133static inline bus_t *endpoint_get_bus(endpoint_t *ep)
    116134{
    117         return item ? list_get_instance(item, endpoint_t, link) : NULL;
     135        device_t * const device = ep->device;
     136        return device ? device->bus : NULL;
    118137}
     138
    119139#endif
    120140
Note: See TracChangeset for help on using the changeset viewer.