Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbdev/include/usb/dev/pipes.h

    rbdb23c63 rb77931d  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
     28
    2829/** @addtogroup libusbdev
    2930 * @{
     
    3637
    3738#include <sys/types.h>
     39#include <usb/usb.h>
     40#include <usb/hc.h>
     41#include <usb/descriptor.h>
    3842#include <ipc/devman.h>
    3943#include <ddf/driver.h>
    4044#include <fibril_synch.h>
    41 #include <usb/usb.h>
    42 #include <usb/descriptor.h>
    43 #include <usb/dev/usb_device_connection.h>
     45#include <async.h>
    4446
    45 #define CTRL_PIPE_MIN_PACKET_SIZE 8
     47/** Abstraction of a physical connection to the device.
     48 * This type is an abstraction of the USB wire that connects the host and
     49 * the function (device).
     50 */
     51typedef struct {
     52        /** Handle of the host controller device is connected to. */
     53        devman_handle_t hc_handle;
     54        /** Address of the device. */
     55        usb_address_t address;
     56} usb_device_connection_t;
     57
    4658/** Abstraction of a logical connection to USB device endpoint.
    47  * It encapsulates endpoint attributes (transfer type etc.).
     59 * It encapsulates endpoint attributes (transfer type etc.) as well
     60 * as information about currently running sessions.
    4861 * This endpoint must be bound with existing usb_device_connection_t
    4962 * (i.e. the wire to send data over).
     63 *
     64 * Locking order: if you want to lock both mutexes
     65 * (@c guard and @c hc_sess_mutex), lock @c guard first.
     66 * It is not necessary to lock @c guard if you want to lock @c hc_sess_mutex
     67 * only.
    5068 */
    5169typedef struct {
     70        /** Guard of the whole pipe. */
     71        fibril_mutex_t guard;
     72
    5273        /** The connection used for sending the data. */
    5374        usb_device_connection_t *wire;
     
    6586        size_t max_packet_size;
    6687
     88        /** Session to the host controller.
     89         * NULL when no session is active.
     90         * It is an error to access this member without @c hc_sess_mutex
     91         * being locked.
     92         * If call over the phone is to be made, it must be preceeded by
     93         * call to pipe_add_ref() [internal libusb function].
     94         */
     95        async_sess_t *hc_sess;
     96
     97        /** Guard for serialization of requests over the session. */
     98        fibril_mutex_t hc_sess_mutex;
     99
     100        /** Number of active transfers over the pipe. */
     101        int refcount;
     102        /** Number of failed attempts to open the HC phone.
     103         * When user requests usb_pipe_start_long_transfer() and the operation
     104         * fails, there is no way to report this to the user.
     105         * That the soft reference counter is increased to record the attempt.
     106         * When the user then request e.g. usb_pipe_read(), it will try to
     107         * add reference as well.
     108         * If that fails, it is reported to the user. If it is okay, the
     109         * real reference counter is incremented.
     110         * The problem might arise when ending the long transfer (since
     111         * the number of references would be only 1, but logically it shall be
     112         * two).
     113         * Decrementing the soft counter first shall solve this.
     114         */
     115        int refcount_soft;
     116
    67117        /** Whether to automatically reset halt on the endpoint.
    68118         * Valid only for control endpoint zero.
     
    70120        bool auto_reset_halt;
    71121} usb_pipe_t;
     122
    72123
    73124/** Description of endpoint characteristics. */
     
    105156} usb_endpoint_mapping_t;
    106157
     158int usb_device_connection_initialize_on_default_address(
     159    usb_device_connection_t *, usb_hc_connection_t *);
     160int usb_device_connection_initialize_from_device(usb_device_connection_t *,
     161    const ddf_dev_t *);
     162int usb_device_connection_initialize(usb_device_connection_t *,
     163    devman_handle_t, usb_address_t);
     164
     165int usb_device_get_assigned_interface(const ddf_dev_t *);
     166
    107167int usb_pipe_initialize(usb_pipe_t *, usb_device_connection_t *,
    108168    usb_endpoint_t, usb_transfer_type_t, size_t, usb_direction_t);
    109169int usb_pipe_initialize_default_control(usb_pipe_t *,
    110170    usb_device_connection_t *);
    111 
    112171int usb_pipe_probe_default_control(usb_pipe_t *);
    113172int usb_pipe_initialize_from_configuration(usb_endpoint_mapping_t *,
    114173    size_t, const uint8_t *, size_t, usb_device_connection_t *);
     174int usb_pipe_register(usb_pipe_t *, unsigned int, usb_hc_connection_t *);
     175int usb_pipe_unregister(usb_pipe_t *, usb_hc_connection_t *);
    115176
    116 int usb_pipe_register(usb_pipe_t *, unsigned);
    117 int usb_pipe_unregister(usb_pipe_t *);
    118 
    119 int usb_pipe_start_long_transfer(usb_pipe_t *);
    120 int usb_pipe_end_long_transfer(usb_pipe_t *);
     177void usb_pipe_start_long_transfer(usb_pipe_t *);
     178void usb_pipe_end_long_transfer(usb_pipe_t *);
    121179
    122180int usb_pipe_read(usb_pipe_t *, void *, size_t, size_t *);
    123 int usb_pipe_write(usb_pipe_t *, const void *, size_t);
     181int usb_pipe_write(usb_pipe_t *, void *, size_t);
    124182
    125183int usb_pipe_control_read(usb_pipe_t *, const void *, size_t,
Note: See TracChangeset for help on using the changeset viewer.