Changeset 327f147 in mainline for uspace/lib/drv


Ignore:
Timestamp:
2017-10-23T19:03:37Z (8 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b724494
Parents:
e160bfe8
Message:

usbhost: change parameters of methods

Pass (device_t, usb_target_t) to read and write, which finally allows to drop hash tables and access device right away. Then, all callbacks to complete transfer now uses usb_transfer_batch. This requires libdrv to include libusbhost, but it is not linked against it - it is there only to share definition of usb_transfer_batch_t.

Location:
uspace/lib/drv
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/drv/Makefile

    re160bfe8 r327f147  
    3333        -Igeneric/private \
    3434        -I$(LIBUSB_PREFIX)/include \
     35        -I$(LIBUSBHOST_PREFIX)/include \
    3536        -I$(LIBPCM_PREFIX)/include
    3637LIBRARY = libdrv
  • uspace/lib/drv/generic/remote_usb.c

    re160bfe8 r327f147  
    3838#include <errno.h>
    3939#include <devman.h>
     40#include <usb/host/usb_transfer_batch.h>
    4041
    4142#include "usb_iface.h"
     
    539540}
    540541
    541 static void callback_out(int outcome, void *arg)
    542 {
    543         async_transaction_t *trans = arg;
    544 
    545         async_answer_0(trans->caller, outcome);
     542static int callback_out(usb_transfer_batch_t *batch)
     543{
     544        async_transaction_t *trans = batch->on_complete_data;
     545
     546        const int err = async_answer_0(trans->caller, batch->error);
    546547
    547548        async_transaction_destroy(trans);
    548 }
    549 
    550 static void callback_in(int outcome, size_t actual_size, void *arg)
    551 {
    552         async_transaction_t *trans = (async_transaction_t *)arg;
    553 
    554         if (outcome != EOK) {
    555                 async_answer_0(trans->caller, outcome);
    556                 if (trans->data_caller) {
     549
     550        return err;
     551}
     552
     553static int callback_in(usb_transfer_batch_t *batch)
     554{
     555        async_transaction_t *trans = batch->on_complete_data;
     556
     557        if (trans->data_caller) {
     558                if (batch->error == EOK) {
     559                        batch->error = async_data_read_finalize(trans->data_caller,
     560                            trans->buffer, batch->transfered_size);
     561                } else {
    557562                        async_answer_0(trans->data_caller, EINTR);
    558563                }
    559                 async_transaction_destroy(trans);
    560                 return;
    561         }
    562 
    563         if (trans->data_caller) {
    564                 async_data_read_finalize(trans->data_caller,
    565                     trans->buffer, actual_size);
    566         }
    567 
    568         async_answer_0(trans->caller, EOK);
    569 
     564        }
     565
     566        const int err = async_answer_0(trans->caller, batch->error);
    570567        async_transaction_destroy(trans);
     568        return err;
    571569}
    572570
     
    611609        }
    612610
     611        const usb_target_t target = {{
     612                /* .address is initialized by read itself */
     613                .endpoint = ep,
     614        }};
     615
    613616        const int rc = usb_iface->read(
    614             fun, ep, setup, trans->buffer, size, callback_in, trans);
     617            fun, target, setup, trans->buffer, size, callback_in, trans);
    615618
    616619        if (rc != EOK) {
     
    659662        }
    660663
     664        const usb_target_t target = {{
     665                /* .address is initialized by write itself */
     666                .endpoint = ep,
     667        }};
     668
    661669        const int rc = usb_iface->write(
    662             fun, ep, setup, trans->buffer, size, callback_out, trans);
     670            fun, target, setup, trans->buffer, size, callback_out, trans);
    663671
    664672        if (rc != EOK) {
  • uspace/lib/drv/include/usb_iface.h

    re160bfe8 r327f147  
    6464    size_t);
    6565
    66 /** Callback for outgoing transfer. */
    67 typedef void (*usb_iface_transfer_out_callback_t)(int, void *);
     66/** Defined in usb/host/usb_transfer_batch.h */
     67typedef struct usb_transfer_batch usb_transfer_batch_t;
    6868
    69 /** Callback for incoming transfer. */
    70 typedef void (*usb_iface_transfer_in_callback_t)(int, size_t, void *);
     69/** Callback for outgoing transfer - clone of usb_transfer_batch_callback_t */
     70typedef int (*usb_iface_transfer_callback_t)(usb_transfer_batch_t *);
    7171
    7272/** USB device communication interface. */
     
    8484        int (*unregister_endpoint)(ddf_fun_t *, usb_endpoint_desc_t *);
    8585
    86         int (*read)(ddf_fun_t *, usb_endpoint_t, uint64_t, uint8_t *, size_t,
    87             usb_iface_transfer_in_callback_t, void *);
    88         int (*write)(ddf_fun_t *, usb_endpoint_t, uint64_t, const uint8_t *,
    89             size_t, usb_iface_transfer_out_callback_t, void *);
     86        int (*read)(ddf_fun_t *, usb_target_t,
     87                uint64_t, char *, size_t,
     88                usb_iface_transfer_callback_t, void *);
     89        int (*write)(ddf_fun_t *, usb_target_t,
     90                uint64_t, const char *, size_t,
     91                usb_iface_transfer_callback_t, void *);
    9092} usb_iface_t;
    9193
Note: See TracChangeset for help on using the changeset viewer.