Changes in / [41ef5b9:fd9f6e4c] in mainline


Ignore:
Files:
7 added
13 deleted
56 edited

Legend:

Unmodified
Added
Removed
  • .bzrignore

    r41ef5b9 rfd9f6e4c  
    8888./uspace/drv/uhci-hcd/uhci-hcd
    8989./uspace/drv/uhci-rhd/uhci-rhd
    90 ./uspace/drv/usbflbk/usbflbk
    9190./uspace/drv/usbhub/usbhub
    9291./uspace/drv/usbhid/usbhid
  • boot/arch/amd64/Makefile.inc

    r41ef5b9 rfd9f6e4c  
    4747        uhci-hcd \
    4848        uhci-rhd \
    49         usbflbk \
    5049        usbhub \
    5150        usbhid \
  • kernel/tools/genmap.py

    r41ef5b9 rfd9f6e4c  
    100100                        for addr, symbol in symbols:
    101101                                value = fname + ':' + symbol
    102                                 value_bytes = value.encode('ascii')
    103                                 data = struct.pack(symtabfmt, addr + offset, value_bytes[:MAXSTRING])
     102                                data = struct.pack(symtabfmt, addr + offset, value[:MAXSTRING])
    104103                                out.write(data)
    105104                       
    106         out.write(struct.pack(symtabfmt, 0, b''))
     105        out.write(struct.pack(symtabfmt, 0, ''))
    107106
    108107def main():
  • tools/mkfat.py

    r41ef5b9 rfd9f6e4c  
    211211        dir_entry = xstruct.create(DIR_ENTRY)
    212212       
    213         dir_entry.name = mangle_fname(name).encode('ascii')
    214         dir_entry.ext = mangle_ext(name).encode('ascii')
     213        dir_entry.name = mangle_fname(name)
     214        dir_entry.ext = mangle_ext(name)
    215215       
    216216        if (directory):
     
    239239       
    240240        dir_entry.signature = 0x2e
    241         dir_entry.name = b'       '
    242         dir_entry.ext = b'   '
     241        dir_entry.name = '       '
     242        dir_entry.ext = '   '
    243243        dir_entry.attr = 0x10
    244244       
     
    258258       
    259259        dir_entry.signature = [0x2e, 0x2e]
    260         dir_entry.name = b'      '
    261         dir_entry.ext = b'   '
     260        dir_entry.name = '      '
     261        dir_entry.ext = '   '
    262262        dir_entry.attr = 0x10
    263263       
  • tools/mkhord.py

    r41ef5b9 rfd9f6e4c  
    8484        payload_size_aligned = align_up(payload_size, align)
    8585       
    86         header.tag = b"HORD"
     86        header.tag = "HORD"
    8787        header.version = 1
    8888        header.encoding = HORD_LSB
  • tools/mktmpfs.py

    r41ef5b9 rfd9f6e4c  
    8080                        dentry.kind = TMPFS_FILE
    8181                        dentry.fname_len = len(name)
    82                         dentry.fname = name.encode('ascii')
     82                        dentry.fname = name
    8383                        dentry.flen = size
    8484                       
     
    9797                        dentry.kind = TMPFS_DIRECTORY
    9898                        dentry.fname_len = len(name)
    99                         dentry.fname = name.encode('ascii')
     99                        dentry.fname = name
    100100                       
    101101                        outf.write(dentry.pack())
     
    122122       
    123123        header = xstruct.create(HEADER)
    124         header.tag = b"TMPFS"
     124        header.tag = "TMPFS"
    125125       
    126126        outf.write(header.pack())
  • uspace/Makefile

    r41ef5b9 rfd9f6e4c  
    121121                drv/uhci-hcd \
    122122                drv/uhci-rhd \
    123                 drv/usbflbk \
    124123                drv/usbhid \
    125124                drv/usbhub \
     
    141140                drv/uhci-hcd \
    142141                drv/uhci-rhd \
    143                 drv/usbflbk \
    144142                drv/usbhid \
    145143                drv/usbhub \
  • uspace/app/bdsh/cmds/modules/bdd/bdd.c

    r41ef5b9 rfd9f6e4c  
    7070        unsigned int i, j;
    7171        devmap_handle_t handle;
    72         aoff64_t offset;
    7372        uint8_t *blk;
    7473        size_t size, bytes, rows;
     
    121120        }
    122121
    123         offset = ba * block_size;
    124 
    125122        while (size > 0) {
    126123                rc = block_read_direct(handle, ba, 1, blk);
     
    136133
    137134                for (j = 0; j < rows; j++) {
    138                         printf("[%06" PRIxOFF64 "] ", offset);
    139135                        for (i = 0; i < BPR; i++) {
    140136                                if (j * BPR + i < bytes)
     
    156152                                }
    157153                        }
    158                         offset += BPR;
    159154                        putchar('\n');
    160155                }
  • uspace/app/usbinfo/dev.c

    r41ef5b9 rfd9f6e4c  
    5959        }
    6060
    61         rc = usb_pipe_initialize_default_control(&dev->ctrl_pipe,
     61        rc = usb_endpoint_pipe_initialize_default_control(&dev->ctrl_pipe,
    6262            &dev->wire);
    6363        if (rc != EOK) {
     
    6868        }
    6969
    70         rc = usb_pipe_probe_default_control(&dev->ctrl_pipe);
     70        rc = usb_endpoint_pipe_probe_default_control(&dev->ctrl_pipe);
    7171        if (rc != EOK) {
    7272                fprintf(stderr,
     
    7676        }
    7777
    78         rc = usb_pipe_start_session(&dev->ctrl_pipe);
     78        rc = usb_endpoint_pipe_start_session(&dev->ctrl_pipe);
    7979        if (rc != EOK) {
    8080                fprintf(stderr,
     
    107107
    108108leave:
    109         if (usb_pipe_is_session_started(&dev->ctrl_pipe)) {
    110                 usb_pipe_end_session(&dev->ctrl_pipe);
     109        if (usb_endpoint_pipe_is_session_started(&dev->ctrl_pipe)) {
     110                usb_endpoint_pipe_end_session(&dev->ctrl_pipe);
    111111        }
    112112
     
    118118void destroy_device(usbinfo_device_t *dev)
    119119{
    120         usb_pipe_end_session(&dev->ctrl_pipe);
     120        usb_endpoint_pipe_end_session(&dev->ctrl_pipe);
    121121        free(dev);
    122122}
  • uspace/app/usbinfo/info.c

    r41ef5b9 rfd9f6e4c  
    4242#include <usb/classes/classes.h>
    4343#include <usb/classes/hid.h>
    44 #include <usb/classes/hub.h>
    4544#include "usbinfo.h"
    4645
     
    110109    usb_standard_device_descriptor_t *descriptor)
    111110{
    112         printf("%sDevice (0x%04x by 0x%04x, %s, %zu configurations)\n", prefix,
     111        printf("%sDevice (0x%04x by 0x%04x, %s)\n", prefix,
    113112            (int) descriptor->product_id,
    114113            (int) descriptor->vendor_id,
    115             usb_str_class(descriptor->device_class),
    116             (size_t) descriptor->configuration_count);
     114            usb_str_class(descriptor->device_class));
    117115}
    118116
     
    120118    usb_standard_configuration_descriptor_t *descriptor)
    121119{
    122         printf("%sConfiguration #%d (%zu interfaces, total %zuB)\n", prefix,
    123             (int) descriptor->configuration_number,
    124             (size_t) descriptor->interface_count,
    125             (size_t) descriptor->total_length);
     120        printf("%sConfiguration #%d\n", prefix,
     121            (int) descriptor->configuration_number);
    126122}
    127123
     
    129125    usb_standard_interface_descriptor_t *descriptor)
    130126{
    131         printf("%sInterface #%d (%s, 0x%02x, 0x%02x), alternate %d\n", prefix,
     127        printf("%sInterface #%d (%s, 0x%02x, 0x%02x)\n", prefix,
    132128            (int) descriptor->interface_number,
    133129            usb_str_class(descriptor->interface_class),
    134130            (int) descriptor->interface_subclass,
    135             (int) descriptor->interface_protocol,
    136             (int) descriptor->alternate_setting);
     131            (int) descriptor->interface_protocol);
    137132}
    138133
     
    158153}
    159154
    160 static void dump_descriptor_tree_brief_hub(const char *prefix,
    161     usb_hub_descriptor_header_t *descriptor)
    162 {
    163         printf("%shub (%d ports)\n", prefix,
    164             (int) descriptor->port_count);
    165 }
    166 
    167 
    168 static void dump_descriptor_tree_callback(uint8_t *descriptor,
     155
     156static void dump_descriptor_tree_brief_callback(uint8_t *descriptor,
    169157    size_t depth, void *arg)
    170158{
     
    183171                if (descr_size >= sizeof(descriptor_type)) { \
    184172                        callback(indent, (descriptor_type *) descriptor); \
    185                         if (arg != NULL) { \
    186                                 usb_dump_standard_descriptor(stdout, \
    187                                     get_indent(depth +2), "\n", \
    188                                     descriptor, descr_size); \
    189                         } \
    190173                } else { \
    191174                        descr_type = -1; \
     
    208191                    usb_standard_hid_descriptor_t,
    209192                    dump_descriptor_tree_brief_hid);
    210                 /*
    211                  * Probably useless, hub descriptor shall not be part of
    212                  * configuration descriptor.
    213                  */
    214                 _BRANCH(USB_DESCTYPE_HUB,
    215                     usb_hub_descriptor_header_t,
    216                     dump_descriptor_tree_brief_hub);
    217193
    218194                default:
     
    227203void dump_descriptor_tree_brief(usbinfo_device_t *dev)
    228204{
    229         dump_descriptor_tree_callback((uint8_t *)&dev->device_descriptor,
     205        dump_descriptor_tree_brief_callback((uint8_t *)&dev->device_descriptor,
    230206            (size_t) -1, NULL);
    231207        usb_dp_walk_simple(dev->full_configuration_descriptor,
    232208            dev->full_configuration_descriptor_size,
    233209            usb_dp_standard_descriptor_nesting,
    234             dump_descriptor_tree_callback,
     210            dump_descriptor_tree_brief_callback,
    235211            NULL);
    236212}
    237 
    238 void dump_descriptor_tree_full(usbinfo_device_t *dev)
    239 {
    240         dump_descriptor_tree_callback((uint8_t *)&dev->device_descriptor,
    241             (size_t) -1, dev);
    242         usb_dp_walk_simple(dev->full_configuration_descriptor,
    243             dev->full_configuration_descriptor_size,
    244             usb_dp_standard_descriptor_nesting,
    245             dump_descriptor_tree_callback,
    246             dev);
    247 }
    248 
    249213
    250214void dump_strings(usbinfo_device_t *dev)
  • uspace/app/usbinfo/main.c

    r41ef5b9 rfd9f6e4c  
    134134        _OPTION("-m --match-ids", "Print match ids generated for the device.");
    135135        _OPTION("-t --descriptor-tree", "Print descriptor tree.");
    136         _OPTION("-T --descriptor-tree-full", "Print detailed descriptor tree");
    137136        _OPTION("-s --strings", "Try to print all string descriptors.");
    138137
     
    150149        {"match-ids", no_argument, NULL, 'm'},
    151150        {"descriptor-tree", no_argument, NULL, 't'},
    152         {"descriptor-tree-full", no_argument, NULL, 'T'},
    153151        {"strings", no_argument, NULL, 's'},
    154152        {0, 0, NULL, 0}
    155153};
    156 static const char *short_options = "himtTs";
     154static const char *short_options = "himts";
    157155
    158156static usbinfo_action_t actions[] = {
     
    170168                .opt = 't',
    171169                .action = dump_descriptor_tree_brief,
    172                 .active = false
    173         },
    174         {
    175                 .opt = 'T',
    176                 .action = dump_descriptor_tree_full,
    177170                .active = false
    178171        },
  • uspace/app/usbinfo/usbinfo.h

    r41ef5b9 rfd9f6e4c  
    4444
    4545typedef struct {
    46         usb_pipe_t ctrl_pipe;
     46        usb_endpoint_pipe_t ctrl_pipe;
    4747        usb_device_connection_t wire;
    4848        usb_standard_device_descriptor_t device_descriptor;
     
    8282void dump_device_match_ids(usbinfo_device_t *);
    8383void dump_descriptor_tree_brief(usbinfo_device_t *);
    84 void dump_descriptor_tree_full(usbinfo_device_t *);
    8584void dump_strings(usbinfo_device_t *);
    8685
  • uspace/doc/doxygroups.h

    r41ef5b9 rfd9f6e4c  
    274274         */
    275275
    276         /**
    277          * @defgroup drvusbfallback USB fallback driver.
    278          * @ingroup usb
    279          * @brief Fallback driver for any USB device.
    280          * @details
    281          * The purpose of this driver is to simplify querying of unknown
    282          * devices from within HelenOS (without a driver, no node at all
    283          * may appear under /dev/devices).
    284          */
    285 
    286 
     276
  • uspace/drv/ohci/Makefile

    r41ef5b9 rfd9f6e4c  
    3333
    3434SOURCES = \
    35         iface.c \
     35        hc_iface.c \
    3636        batch.c \
    3737        main.c \
    38         hc.c \
    39         root_hub.c \
     38        ohci_hc.c \
     39        ohci_rh.c \
    4040        pci.c
    4141
  • uspace/drv/ohci/batch.c

    r41ef5b9 rfd9f6e4c  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup drvusbohci
     28/** @addtogroup drvusbohcihc
    2929 * @{
    3030 */
     
    3939
    4040#include "batch.h"
    41 #include "utils/malloc32.h"
    42 
    43 static void batch_call_in_and_dispose(usb_transfer_batch_t *instance);
    44 static void batch_call_out_and_dispose(usb_transfer_batch_t *instance);
    45 
    46 #define DEFAULT_ERROR_COUNT 3
    47 usb_transfer_batch_t * batch_get(
    48     ddf_fun_t *fun,
    49                 usb_target_t target,
    50     usb_transfer_type_t transfer_type,
    51                 size_t max_packet_size,
    52     usb_speed_t speed,
    53                 char *buffer,
    54                 size_t buffer_size,
    55                 char *setup_buffer,
    56                 size_t setup_size,
     41
     42static void batch_call_in(batch_t *instance);
     43static void batch_call_out(batch_t *instance);
     44static void batch_call_in_and_dispose(batch_t *instance);
     45static void batch_call_out_and_dispose(batch_t *instance);
     46
     47/** Allocate memory and initialize internal data structure.
     48 *
     49 * @param[in] fun DDF function to pass to callback.
     50 * @param[in] target Device and endpoint target of the transaction.
     51 * @param[in] transfer_type Interrupt, Control or Bulk.
     52 * @param[in] max_packet_size maximum allowed size of data packets.
     53 * @param[in] speed Speed of the transaction.
     54 * @param[in] buffer Data source/destination.
     55 * @param[in] size Size of the buffer.
     56 * @param[in] setup_buffer Setup data source (if not NULL)
     57 * @param[in] setup_size Size of setup_buffer (should be always 8)
     58 * @param[in] func_in function to call on inbound transaction completion
     59 * @param[in] func_out function to call on outbound transaction completion
     60 * @param[in] arg additional parameter to func_in or func_out
     61 * @param[in] manager Pointer to toggle management structure.
     62 * @return Valid pointer if all substructures were successfully created,
     63 * NULL otherwise.
     64 *
     65 * Determines the number of needed packets (TDs). Prepares a transport buffer
     66 * (that is accessible by the hardware). Initializes parameters needed for the
     67 * transaction and callback.
     68 */
     69batch_t * batch_get(ddf_fun_t *fun, usb_target_t target,
     70    usb_transfer_type_t transfer_type, size_t max_packet_size,
     71    usb_speed_t speed, char *buffer, size_t size,
     72    char* setup_buffer, size_t setup_size,
    5773    usbhc_iface_transfer_in_callback_t func_in,
    58     usbhc_iface_transfer_out_callback_t func_out,
    59                 void *arg,
    60                 usb_device_keeper_t *manager
    61                 )
    62 {
     74    usbhc_iface_transfer_out_callback_t func_out, void *arg
     75    )
     76{
     77        assert(func_in == NULL || func_out == NULL);
     78        assert(func_in != NULL || func_out != NULL);
     79
    6380#define CHECK_NULL_DISPOSE_RETURN(ptr, message...) \
    64         if (ptr == NULL) { \
    65                 usb_log_error(message); \
    66                 if (instance) { \
    67                         batch_dispose(instance); \
    68                 } \
    69                 return NULL; \
    70         } else (void)0
    71 
    72         usb_transfer_batch_t *instance = malloc(sizeof(usb_transfer_batch_t));
     81        if (ptr == NULL) { \
     82                usb_log_error(message); \
     83                if (instance) { \
     84                        batch_dispose(instance); \
     85                } \
     86                return NULL; \
     87        } else (void)0
     88
     89        batch_t *instance = malloc(sizeof(batch_t));
    7390        CHECK_NULL_DISPOSE_RETURN(instance,
    7491            "Failed to allocate batch instance.\n");
    75         usb_transfer_batch_init(instance, target, transfer_type, speed, max_packet_size,
    76             buffer, NULL, buffer_size, NULL, setup_size, func_in,
    77             func_out, arg, fun, NULL);
    78 
    79         if (buffer_size > 0) {
    80                 instance->transport_buffer = malloc32(buffer_size);
    81                 CHECK_NULL_DISPOSE_RETURN(instance->transport_buffer,
    82                     "Failed to allocate device accessible buffer.\n");
    83         }
    84 
    85         if (setup_size > 0) {
    86                 instance->setup_buffer = malloc32(setup_size);
    87                 CHECK_NULL_DISPOSE_RETURN(instance->setup_buffer,
    88                     "Failed to allocate device accessible setup buffer.\n");
    89                 memcpy(instance->setup_buffer, setup_buffer, setup_size);
    90         }
    91 
    92 
     92        bzero(instance, sizeof(batch_t));
     93
     94        if (size > 0) {
     95                /* TODO: use device accessible malloc here */
     96                instance->transport_buffer = malloc(size);
     97                CHECK_NULL_DISPOSE_RETURN(instance->transport_buffer,
     98                    "Failed to allocate device accessible buffer.\n");
     99        }
     100
     101        if (setup_size > 0) {
     102                /* TODO: use device accessible malloc here */
     103                instance->setup_buffer = malloc(setup_size);
     104                CHECK_NULL_DISPOSE_RETURN(instance->setup_buffer,
     105                    "Failed to allocate device accessible setup buffer.\n");
     106                memcpy(instance->setup_buffer, setup_buffer, setup_size);
     107        }
     108
     109        link_initialize(&instance->link);
     110
     111        instance->max_packet_size = max_packet_size;
     112        instance->target = target;
     113        instance->transfer_type = transfer_type;
     114        instance->buffer = buffer;
     115        instance->buffer_size = size;
     116        instance->setup_size = setup_size;
     117        instance->fun = fun;
     118        instance->arg = arg;
     119        instance->speed = speed;
     120        instance->callback_out = func_out;
     121        instance->callback_in = func_in;
     122
     123        usb_log_debug("Batch(%p) %d:%d memory structures ready.\n",
     124            instance, target.address, target.endpoint);
    93125        return instance;
    94126}
    95127/*----------------------------------------------------------------------------*/
    96 void batch_dispose(usb_transfer_batch_t *instance)
    97 {
    98         assert(instance);
    99         free32(instance->transport_buffer);
    100         free32(instance->setup_buffer);
    101         free(instance);
    102 }
    103 /*----------------------------------------------------------------------------*/
    104 void batch_control_write(usb_transfer_batch_t *instance)
     128/** Mark batch as finished and continue with next step.
     129 *
     130 * @param[in] instance Batch structure to use.
     131 *
     132 */
     133void batch_finish(batch_t *instance, int error)
     134{
     135        assert(instance);
     136        instance->error = error;
     137        instance->next_step(instance);
     138}
     139/*----------------------------------------------------------------------------*/
     140/** Check batch TDs for activity.
     141 *
     142 * @param[in] instance Batch structure to use.
     143 * @return False, if there is an active TD, true otherwise.
     144 *
     145 * Walk all TDs. Stop with false if there is an active one (it is to be
     146 * processed). Stop with true if an error is found. Return true if the last TS
     147 * is reached.
     148 */
     149bool batch_is_complete(batch_t *instance)
     150{
     151        assert(instance);
     152        /* TODO: implement */
     153        return true;
     154}
     155/*----------------------------------------------------------------------------*/
     156/** Prepares control write transaction.
     157 *
     158 * @param[in] instance Batch structure to use.
     159 *
     160 * Uses genercir control function with pids OUT and IN.
     161 */
     162void batch_control_write(batch_t *instance)
    105163{
    106164        assert(instance);
     
    113171}
    114172/*----------------------------------------------------------------------------*/
    115 void batch_control_read(usb_transfer_batch_t *instance)
     173/** Prepares control read transaction.
     174 *
     175 * @param[in] instance Batch structure to use.
     176 *
     177 * Uses generic control with pids IN and OUT.
     178 */
     179void batch_control_read(batch_t *instance)
    116180{
    117181        assert(instance);
    118182        instance->next_step = batch_call_in_and_dispose;
    119183        /* TODO: implement */
    120         usb_log_debug("Batch(%p) CONTROL WRITE initialized.\n", instance);
    121 }
    122 /*----------------------------------------------------------------------------*/
    123 void batch_interrupt_in(usb_transfer_batch_t *instance)
    124 {
    125         assert(instance);
    126         instance->direction = USB_DIRECTION_IN;
     184        usb_log_debug("Batch(%p) CONTROL READ initialized.\n", instance);
     185}
     186/*----------------------------------------------------------------------------*/
     187/** Prepare interrupt in transaction.
     188 *
     189 * @param[in] instance Batch structure to use.
     190 *
     191 * Data transaction with PID_IN.
     192 */
     193void batch_interrupt_in(batch_t *instance)
     194{
     195        assert(instance);
     196        /* TODO: implement */
    127197        instance->next_step = batch_call_in_and_dispose;
    128         /* TODO: implement */
    129198        usb_log_debug("Batch(%p) INTERRUPT IN initialized.\n", instance);
    130199}
    131200/*----------------------------------------------------------------------------*/
    132 void batch_interrupt_out(usb_transfer_batch_t *instance)
    133 {
    134         assert(instance);
    135         instance->direction = USB_DIRECTION_OUT;
     201/** Prepare interrupt out transaction.
     202 *
     203 * @param[in] instance Batch structure to use.
     204 *
     205 * Data transaction with PID_OUT.
     206 */
     207void batch_interrupt_out(batch_t *instance)
     208{
     209        assert(instance);
    136210        /* We are data out, we are supposed to provide data */
    137211        memcpy(instance->transport_buffer, instance->buffer,
     
    142216}
    143217/*----------------------------------------------------------------------------*/
    144 void batch_bulk_in(usb_transfer_batch_t *instance)
    145 {
    146         assert(instance);
    147         instance->direction = USB_DIRECTION_IN;
     218/** Prepare bulk in transaction.
     219 *
     220 * @param[in] instance Batch structure to use.
     221 *
     222 * Data transaction with PID_IN.
     223 */
     224void batch_bulk_in(batch_t *instance)
     225{
     226        assert(instance);
    148227        instance->next_step = batch_call_in_and_dispose;
    149228        /* TODO: implement */
     
    151230}
    152231/*----------------------------------------------------------------------------*/
    153 void batch_bulk_out(usb_transfer_batch_t *instance)
    154 {
    155         assert(instance);
    156         instance->direction = USB_DIRECTION_IN;
    157         instance->next_step = batch_call_in_and_dispose;
    158         /* TODO: implement */
    159         usb_log_debug("Batch(%p) BULK IN initialized.\n", instance);
     232/** Prepare bulk out transaction.
     233 *
     234 * @param[in] instance Batch structure to use.
     235 *
     236 * Data transaction with PID_OUT.
     237 */
     238void batch_bulk_out(batch_t *instance)
     239{
     240        assert(instance);
     241        /* We are data out, we are supposed to provide data */
     242        memcpy(instance->transport_buffer, instance->buffer,
     243            instance->buffer_size);
     244        instance->next_step = batch_call_out_and_dispose;
     245        /* TODO: implement */
     246        usb_log_debug("Batch(%p) BULK OUT initialized.\n", instance);
     247}
     248/*----------------------------------------------------------------------------*/
     249/** Prepare data, get error status and call callback in.
     250 *
     251 * @param[in] instance Batch structure to use.
     252 * Copies data from transport buffer, and calls callback with appropriate
     253 * parameters.
     254 */
     255void batch_call_in(batch_t *instance)
     256{
     257        assert(instance);
     258        assert(instance->callback_in);
     259
     260        /* We are data in, we need data */
     261        memcpy(instance->buffer, instance->transport_buffer,
     262            instance->buffer_size);
     263
     264        int err = instance->error;
     265        usb_log_debug("Batch(%p) callback IN(type:%d): %s(%d), %zu.\n",
     266            instance, instance->transfer_type, str_error(err), err,
     267            instance->transfered_size);
     268
     269        instance->callback_in(
     270            instance->fun, err, instance->transfered_size, instance->arg);
     271}
     272/*----------------------------------------------------------------------------*/
     273/** Get error status and call callback out.
     274 *
     275 * @param[in] instance Batch structure to use.
     276 */
     277void batch_call_out(batch_t *instance)
     278{
     279        assert(instance);
     280        assert(instance->callback_out);
     281
     282        int err = instance->error;
     283        usb_log_debug("Batch(%p) callback OUT(type:%d): %s(%d).\n",
     284            instance, instance->transfer_type, str_error(err), err);
     285        instance->callback_out(instance->fun,
     286            err, instance->arg);
    160287}
    161288/*----------------------------------------------------------------------------*/
     
    164291 * @param[in] instance Batch structure to use.
    165292 */
    166 void batch_call_in_and_dispose(usb_transfer_batch_t *instance)
    167 {
    168         assert(instance);
    169         usb_transfer_batch_call_in(instance);
     293void batch_call_in_and_dispose(batch_t *instance)
     294{
     295        assert(instance);
     296        batch_call_in(instance);
    170297        batch_dispose(instance);
    171298}
     
    175302 * @param[in] instance Batch structure to use.
    176303 */
    177 void batch_call_out_and_dispose(usb_transfer_batch_t *instance)
    178 {
    179         assert(instance);
    180         usb_transfer_batch_call_out(instance);
     304void batch_call_out_and_dispose(batch_t *instance)
     305{
     306        assert(instance);
     307        batch_call_out(instance);
    181308        batch_dispose(instance);
     309}
     310/*----------------------------------------------------------------------------*/
     311/** Correctly dispose all used data structures.
     312 *
     313 * @param[in] instance Batch structure to use.
     314 */
     315void batch_dispose(batch_t *instance)
     316{
     317        assert(instance);
     318        usb_log_debug("Batch(%p) disposing.\n", instance);
     319        if (instance->setup_buffer)
     320                free(instance->setup_buffer);
     321        if (instance->transport_buffer)
     322                free(instance->transport_buffer);
     323        free(instance);
    182324}
    183325/**
  • uspace/drv/ohci/batch.h

    r41ef5b9 rfd9f6e4c  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup drvusbohci
     28/** @addtogroup drvusbuhcihc
    2929 * @{
    3030 */
    3131/** @file
    32  * @brief OHCI driver USB transaction structure
     32 * @brief UHCI driver USB transaction structure
    3333 */
    34 #ifndef DRV_OHCI_BATCH_H
    35 #define DRV_OHCI_BATCH_H
     34#ifndef DRV_UHCI_BATCH_H
     35#define DRV_UHCI_BATCH_H
    3636
     37#include <adt/list.h>
    3738
    3839#include <usbhc_iface.h>
    3940#include <usb/usb.h>
    40 #include <usb/host/device_keeper.h>
    41 #include <usb/host/batch.h>
    4241
    43 usb_transfer_batch_t * batch_get(
     42typedef struct batch
     43{
     44        link_t link;
     45        usb_speed_t speed;
     46        usb_target_t target;
     47        usb_transfer_type_t transfer_type;
     48        usbhc_iface_transfer_in_callback_t callback_in;
     49        usbhc_iface_transfer_out_callback_t callback_out;
     50        void *arg;
     51        char *transport_buffer;
     52        char *setup_buffer;
     53        size_t setup_size;
     54        char *buffer;
     55        size_t buffer_size;
     56        size_t max_packet_size;
     57        size_t packets;
     58        size_t transfered_size;
     59        int error;
     60        ddf_fun_t *fun;
     61        void (*next_step)(struct batch*);
     62} batch_t;
     63
     64batch_t * batch_get(
    4465    ddf_fun_t *fun,
    4566                usb_target_t target,
     
    5374    usbhc_iface_transfer_in_callback_t func_in,
    5475    usbhc_iface_transfer_out_callback_t func_out,
    55                 void *arg,
    56                 usb_device_keeper_t *manager
     76                void *arg
    5777                );
    5878
    59 void batch_dispose(usb_transfer_batch_t *instance);
     79void batch_dispose(batch_t *instance);
    6080
    61 void batch_control_write(usb_transfer_batch_t *instance);
     81void batch_finish(batch_t *instance, int error);
    6282
    63 void batch_control_read(usb_transfer_batch_t *instance);
     83bool batch_is_complete(batch_t *instance);
    6484
    65 void batch_interrupt_in(usb_transfer_batch_t *instance);
     85void batch_control_write(batch_t *instance);
    6686
    67 void batch_interrupt_out(usb_transfer_batch_t *instance);
     87void batch_control_read(batch_t *instance);
    6888
    69 void batch_bulk_in(usb_transfer_batch_t *instance);
     89void batch_interrupt_in(batch_t *instance);
    7090
    71 void batch_bulk_out(usb_transfer_batch_t *instance);
     91void batch_interrupt_out(batch_t *instance);
     92
     93void batch_bulk_in(batch_t *instance);
     94
     95void batch_bulk_out(batch_t *instance);
    7296#endif
    7397/**
  • uspace/drv/ohci/iface.h

    r41ef5b9 rfd9f6e4c  
    4040#define NAME "ohci"
    4141
    42 extern usbhc_iface_t hc_iface;
     42extern usbhc_iface_t ohci_hc_iface;
    4343
    4444#endif
  • uspace/drv/ohci/main.c

    r41ef5b9 rfd9f6e4c  
    4545#include "pci.h"
    4646#include "iface.h"
    47 #include "hc.h"
     47#include "ohci_hc.h"
    4848
    4949static int ohci_add_device(ddf_dev_t *device);
    50 static int get_hc_handle(ddf_fun_t *fun, devman_handle_t *handle)
    51 {
    52         assert(handle);
    53   assert(fun != NULL);
    54 
    55   *handle = fun->handle;
    56   return EOK;
    57 }
    58 /*----------------------------------------------------------------------------*/
    59 static int get_address(
    60     ddf_fun_t *fun, devman_handle_t handle, usb_address_t *address)
    61 {
    62         assert(fun);
    63         usb_device_keeper_t *manager = &fun_to_hc(fun)->manager;
    64   usb_address_t addr = usb_device_keeper_find(manager, handle);
    65   if (addr < 0) {
    66     return addr;
    67   }
    68 
    69   if (address != NULL) {
    70     *address = addr;
    71   }
    72 
    73   return EOK;
    74 }
    7550/*----------------------------------------------------------------------------*/
    7651/** IRQ handling callback, identifies device
     
    8358{
    8459        assert(dev);
    85         hc_t *hc = (hc_t*)dev->driver_data;
     60        ohci_hc_t *hc = (ohci_hc_t*)dev->driver_data;
    8661        assert(hc);
    87         hc_interrupt(hc, 0);
     62        ohci_hc_interrupt(hc, 0);
    8863}
    8964/*----------------------------------------------------------------------------*/
     
    9671        .driver_ops = &ohci_driver_ops
    9772};
    98 /*----------------------------------------------------------------------------*/
    99 static usb_iface_t hc_usb_iface = {
    100         .get_address = get_address,
    101         .get_hc_handle = get_hc_handle,
     73static ddf_dev_ops_t hc_ops = {
     74        .interfaces[USBHC_DEV_IFACE] = &ohci_hc_iface,
    10275};
    103 /*----------------------------------------------------------------------------*/
    104 static ddf_dev_ops_t hc_ops = {
    105         .interfaces[USB_DEV_IFACE] = &hc_usb_iface,
    106         .interfaces[USBHC_DEV_IFACE] = &hc_iface,
    107 };
     76
    10877/*----------------------------------------------------------------------------*/
    10978/** Initializes a new ddf driver instance of OHCI hcd.
     
    136105            "Failed(%d) disable legacy USB: %s.\n", ret, str_error(ret));
    137106
    138         hc_t *hcd = malloc(sizeof(hc_t));
     107        ohci_hc_t *hcd = malloc(sizeof(ohci_hc_t));
    139108        if (hcd == NULL) {
    140109                usb_log_error("Failed to allocate OHCI driver.\n");
     
    160129        }
    161130
    162         ret = hc_init(hcd, hc_fun, device, mem_reg_base, mem_reg_size, interrupts);
     131        ret = ohci_hc_init(hcd, hc_fun, mem_reg_base, mem_reg_size, interrupts);
    163132        if (ret != EOK) {
    164133                usb_log_error("Failed to initialize OHCI driver.\n");
     
    179148        hc_fun->driver_data = hcd;
    180149
    181         fid_t later = fibril_create((int(*)(void*))hc_register_hub, hcd);
    182         fibril_add_ready(later);
     150        /* TODO: register interrupt handler */
    183151
    184152        usb_log_info("Controlling new OHCI device `%s' (handle %llu).\n",
  • uspace/drv/ohci/ohci_regs.h

    r41ef5b9 rfd9f6e4c  
    4343        volatile uint32_t command_status;
    4444        volatile uint32_t interrupt_status;
    45 #define IS_SO (1 << 0)
    46 #define IS_WDH (1 << 1)
    47 #define IS_SF (1 << 2)
    48 #define IS_RD (1 << 3)
    49 #define IS_UE (1 << 4)
    50 #define IS_FNO (1 << 5)
    51 #define IS_RHSC (1 << 6)
    52 #define IS_OC (1 << 30)
    5345        volatile uint32_t interupt_enable;
    5446#define IE_SO   (1 << 0)
  • uspace/drv/uhci-hcd/Makefile

    r41ef5b9 rfd9f6e4c  
    4040        uhci_rh.c \
    4141        uhci_struct/transfer_descriptor.c \
     42        utils/device_keeper.c \
    4243        pci.c \
    4344        batch.c
  • uspace/drv/uhci-hcd/batch.c

    r41ef5b9 rfd9f6e4c  
    4242#include "uhci_hc.h"
    4343#include "utils/malloc32.h"
    44 #include "uhci_struct/transfer_descriptor.h"
    4544
    4645#define DEFAULT_ERROR_COUNT 3
    4746
    48 typedef struct uhci_batch {
    49         qh_t *qh;
    50         td_t *tds;
    51         size_t packets;
    52         usb_device_keeper_t *manager;
    53 } uhci_batch_t;
    54 
    55 static void batch_control(usb_transfer_batch_t *instance,
     47static void batch_control(batch_t *instance,
    5648    usb_packet_id data_stage, usb_packet_id status_stage);
    57 static void batch_data(usb_transfer_batch_t *instance, usb_packet_id pid);
    58 static void batch_call_in_and_dispose(usb_transfer_batch_t *instance);
    59 static void batch_call_out_and_dispose(usb_transfer_batch_t *instance);
     49static void batch_data(batch_t *instance, usb_packet_id pid);
     50static void batch_call_in(batch_t *instance);
     51static void batch_call_out(batch_t *instance);
     52static void batch_call_in_and_dispose(batch_t *instance);
     53static void batch_call_out_and_dispose(batch_t *instance);
    6054
    6155
     
    8276 * transaction and callback.
    8377 */
    84 usb_transfer_batch_t * batch_get(ddf_fun_t *fun, usb_target_t target,
     78batch_t * batch_get(ddf_fun_t *fun, usb_target_t target,
    8579    usb_transfer_type_t transfer_type, size_t max_packet_size,
    86     usb_speed_t speed, char *buffer, size_t buffer_size,
     80    usb_speed_t speed, char *buffer, size_t size,
    8781    char* setup_buffer, size_t setup_size,
    8882    usbhc_iface_transfer_in_callback_t func_in,
    8983    usbhc_iface_transfer_out_callback_t func_out, void *arg,
    90     usb_device_keeper_t *manager
     84    device_keeper_t *manager
    9185    )
    9286{
     
    10397        } else (void)0
    10498
    105         usb_transfer_batch_t *instance = malloc(sizeof(usb_transfer_batch_t));
     99        batch_t *instance = malloc(sizeof(batch_t));
    106100        CHECK_NULL_DISPOSE_RETURN(instance,
    107101            "Failed to allocate batch instance.\n");
    108         usb_transfer_batch_init(instance, target, transfer_type, speed, max_packet_size,
    109             buffer, NULL, buffer_size, NULL, setup_size, func_in,
    110             func_out, arg, fun, NULL);
    111 
    112 
    113         uhci_batch_t *data = malloc(sizeof(uhci_batch_t));
    114         CHECK_NULL_DISPOSE_RETURN(instance,
    115             "Failed to allocate batch instance.\n");
    116         bzero(data, sizeof(uhci_batch_t));
    117         data->manager = manager;
    118         instance->private_data = data;
    119 
    120         data->packets = (buffer_size + max_packet_size - 1) / max_packet_size;
     102        bzero(instance, sizeof(batch_t));
     103
     104        instance->qh = malloc32(sizeof(qh_t));
     105        CHECK_NULL_DISPOSE_RETURN(instance->qh,
     106            "Failed to allocate batch queue head.\n");
     107        qh_init(instance->qh);
     108
     109        instance->packets = (size + max_packet_size - 1) / max_packet_size;
    121110        if (transfer_type == USB_TRANSFER_CONTROL) {
    122                 data->packets += 2;
    123         }
    124 
    125         data->tds = malloc32(sizeof(td_t) * data->packets);
     111                instance->packets += 2;
     112        }
     113
     114        instance->tds = malloc32(sizeof(td_t) * instance->packets);
    126115        CHECK_NULL_DISPOSE_RETURN(
    127             data->tds, "Failed to allocate transfer descriptors.\n");
    128         bzero(data->tds, sizeof(td_t) * data->packets);
    129 
    130         data->qh = malloc32(sizeof(qh_t));
    131         CHECK_NULL_DISPOSE_RETURN(data->qh,
    132             "Failed to allocate batch queue head.\n");
    133         qh_init(data->qh);
    134         qh_set_element_td(data->qh, addr_to_phys(data->tds));
    135 
    136         if (buffer_size > 0) {
    137                 instance->transport_buffer = malloc32(buffer_size);
     116            instance->tds, "Failed to allocate transfer descriptors.\n");
     117        bzero(instance->tds, sizeof(td_t) * instance->packets);
     118
     119        if (size > 0) {
     120                instance->transport_buffer = malloc32(size);
    138121                CHECK_NULL_DISPOSE_RETURN(instance->transport_buffer,
    139122                    "Failed to allocate device accessible buffer.\n");
     
    147130        }
    148131
     132
     133        link_initialize(&instance->link);
     134
     135        instance->max_packet_size = max_packet_size;
     136        instance->target = target;
     137        instance->transfer_type = transfer_type;
     138        instance->buffer = buffer;
     139        instance->buffer_size = size;
     140        instance->setup_size = setup_size;
     141        instance->fun = fun;
     142        instance->arg = arg;
     143        instance->speed = speed;
     144        instance->manager = manager;
     145        instance->callback_out = func_out;
     146        instance->callback_in = func_in;
     147
     148        qh_set_element_td(instance->qh, addr_to_phys(instance->tds));
     149
    149150        usb_log_debug("Batch(%p) %d:%d memory structures ready.\n",
    150151            instance, target.address, target.endpoint);
     
    152153}
    153154/*----------------------------------------------------------------------------*/
     155/** Mark batch as failed and continue with next step.
     156 *
     157 * @param[in] instance Batch structure to use.
     158 *
     159 */
     160void batch_abort(batch_t *instance)
     161{
     162        assert(instance);
     163        instance->error = EIO;
     164        instance->next_step(instance);
     165}
     166/*----------------------------------------------------------------------------*/
    154167/** Check batch TDs for activity.
    155168 *
     
    161174 * is reached.
    162175 */
    163 bool batch_is_complete(usb_transfer_batch_t *instance)
    164 {
    165         assert(instance);
    166         uhci_batch_t *data = instance->private_data;
    167         assert(data);
    168 
     176bool batch_is_complete(batch_t *instance)
     177{
     178        assert(instance);
    169179        usb_log_debug2("Batch(%p) checking %d packet(s) for completion.\n",
    170             instance, data->packets);
     180            instance, instance->packets);
    171181        instance->transfered_size = 0;
    172182        size_t i = 0;
    173         for (;i < data->packets; ++i) {
    174                 if (td_is_active(&data->tds[i])) {
     183        for (;i < instance->packets; ++i) {
     184                if (td_is_active(&instance->tds[i])) {
    175185                        return false;
    176186                }
    177187
    178                 instance->error = td_status(&data->tds[i]);
     188                instance->error = td_status(&instance->tds[i]);
    179189                if (instance->error != EOK) {
    180190                        usb_log_debug("Batch(%p) found error TD(%d):%x.\n",
    181                             instance, i, data->tds[i].status);
    182                         td_print_status(&data->tds[i]);
    183 
    184                         usb_device_keeper_set_toggle(data->manager,
    185                             instance->target, instance->direction,
    186                             td_toggle(&data->tds[i]));
     191                            instance, i, instance->tds[i].status);
     192                        td_print_status(&instance->tds[i]);
     193
     194                        device_keeper_set_toggle(instance->manager,
     195                            instance->target, td_toggle(&instance->tds[i]));
    187196                        if (i > 0)
    188197                                goto substract_ret;
     
    190199                }
    191200
    192                 instance->transfered_size += td_act_size(&data->tds[i]);
    193                 if (td_is_short(&data->tds[i]))
     201                instance->transfered_size += td_act_size(&instance->tds[i]);
     202                if (td_is_short(&instance->tds[i]))
    194203                        goto substract_ret;
    195204        }
     
    205214 * Uses genercir control function with pids OUT and IN.
    206215 */
    207 void batch_control_write(usb_transfer_batch_t *instance)
     216void batch_control_write(batch_t *instance)
    208217{
    209218        assert(instance);
     
    222231 * Uses generic control with pids IN and OUT.
    223232 */
    224 void batch_control_read(usb_transfer_batch_t *instance)
     233void batch_control_read(batch_t *instance)
    225234{
    226235        assert(instance);
     
    236245 * Data transaction with PID_IN.
    237246 */
    238 void batch_interrupt_in(usb_transfer_batch_t *instance)
    239 {
    240         assert(instance);
    241         instance->direction = USB_DIRECTION_IN;
     247void batch_interrupt_in(batch_t *instance)
     248{
     249        assert(instance);
    242250        batch_data(instance, USB_PID_IN);
    243251        instance->next_step = batch_call_in_and_dispose;
     
    251259 * Data transaction with PID_OUT.
    252260 */
    253 void batch_interrupt_out(usb_transfer_batch_t *instance)
    254 {
    255         assert(instance);
    256         instance->direction = USB_DIRECTION_OUT;
     261void batch_interrupt_out(batch_t *instance)
     262{
     263        assert(instance);
    257264        /* We are data out, we are supposed to provide data */
    258265        memcpy(instance->transport_buffer, instance->buffer,
     
    269276 * Data transaction with PID_IN.
    270277 */
    271 void batch_bulk_in(usb_transfer_batch_t *instance)
     278void batch_bulk_in(batch_t *instance)
    272279{
    273280        assert(instance);
    274281        batch_data(instance, USB_PID_IN);
    275         instance->direction = USB_DIRECTION_IN;
    276282        instance->next_step = batch_call_in_and_dispose;
    277283        usb_log_debug("Batch(%p) BULK IN initialized.\n", instance);
     
    284290 * Data transaction with PID_OUT.
    285291 */
    286 void batch_bulk_out(usb_transfer_batch_t *instance)
    287 {
    288         assert(instance);
    289         instance->direction = USB_DIRECTION_OUT;
     292void batch_bulk_out(batch_t *instance)
     293{
     294        assert(instance);
    290295        /* We are data out, we are supposed to provide data */
    291296        memcpy(instance->transport_buffer, instance->buffer,
     
    304309 * The last packet is marked with IOC flag.
    305310 */
    306 void batch_data(usb_transfer_batch_t *instance, usb_packet_id pid)
    307 {
    308         assert(instance);
    309         uhci_batch_t *data = instance->private_data;
    310         assert(data);
    311 
     311void batch_data(batch_t *instance, usb_packet_id pid)
     312{
     313        assert(instance);
    312314        const bool low_speed = instance->speed == USB_SPEED_LOW;
    313         int toggle = usb_device_keeper_get_toggle(
    314             data->manager, instance->target, instance->direction);
     315        int toggle =
     316            device_keeper_get_toggle(instance->manager, instance->target);
    315317        assert(toggle == 0 || toggle == 1);
    316318
     
    318320        size_t remain_size = instance->buffer_size;
    319321        while (remain_size > 0) {
    320                 char *trans_data =
     322                char *data =
    321323                    instance->transport_buffer + instance->buffer_size
    322324                    - remain_size;
     
    326328                    remain_size : instance->max_packet_size;
    327329
    328                 td_t *next_packet = (packet + 1 < data->packets)
    329                     ? &data->tds[packet + 1] : NULL;
    330 
    331                 assert(packet < data->packets);
     330                td_t *next_packet = (packet + 1 < instance->packets)
     331                    ? &instance->tds[packet + 1] : NULL;
     332
     333                assert(packet < instance->packets);
    332334                assert(packet_size <= remain_size);
    333335
    334336                td_init(
    335                     &data->tds[packet], DEFAULT_ERROR_COUNT, packet_size,
    336                     toggle, false, low_speed, instance->target, pid, trans_data,
     337                    &instance->tds[packet], DEFAULT_ERROR_COUNT, packet_size,
     338                    toggle, false, low_speed, instance->target, pid, data,
    337339                    next_packet);
    338340
     
    342344                ++packet;
    343345        }
    344         td_set_ioc(&data->tds[packet - 1]);
    345         usb_device_keeper_set_toggle(data->manager, instance->target,
    346             instance->direction, toggle);
     346        td_set_ioc(&instance->tds[packet - 1]);
     347        device_keeper_set_toggle(instance->manager, instance->target, toggle);
    347348}
    348349/*----------------------------------------------------------------------------*/
     
    358359 * The last packet is marked with IOC.
    359360 */
    360 void batch_control(usb_transfer_batch_t *instance,
     361void batch_control(batch_t *instance,
    361362   usb_packet_id data_stage, usb_packet_id status_stage)
    362363{
    363364        assert(instance);
    364         uhci_batch_t *data = instance->private_data;
    365         assert(data);
    366         assert(data->packets >= 2);
    367365
    368366        const bool low_speed = instance->speed == USB_SPEED_LOW;
    369367        int toggle = 0;
    370368        /* setup stage */
    371         td_init(
    372             data->tds, DEFAULT_ERROR_COUNT, instance->setup_size, toggle, false,
    373             low_speed, instance->target, USB_PID_SETUP, instance->setup_buffer,
    374             &data->tds[1]);
     369        td_init(instance->tds, DEFAULT_ERROR_COUNT,
     370            instance->setup_size, toggle, false, low_speed, instance->target,
     371            USB_PID_SETUP, instance->setup_buffer, &instance->tds[1]);
    375372
    376373        /* data stage */
     
    378375        size_t remain_size = instance->buffer_size;
    379376        while (remain_size > 0) {
    380                 char *control_data =
     377                char *data =
    381378                    instance->transport_buffer + instance->buffer_size
    382379                    - remain_size;
     
    389386
    390387                td_init(
    391                     &data->tds[packet], DEFAULT_ERROR_COUNT, packet_size,
     388                    &instance->tds[packet], DEFAULT_ERROR_COUNT, packet_size,
    392389                    toggle, false, low_speed, instance->target, data_stage,
    393                     control_data, &data->tds[packet + 1]);
     390                    data, &instance->tds[packet + 1]);
    394391
    395392                ++packet;
    396                 assert(packet < data->packets);
     393                assert(packet < instance->packets);
    397394                assert(packet_size <= remain_size);
    398395                remain_size -= packet_size;
     
    400397
    401398        /* status stage */
    402         assert(packet == data->packets - 1);
    403 
    404         td_init(
    405             &data->tds[packet], DEFAULT_ERROR_COUNT, 0, 1, false, low_speed,
    406             instance->target, status_stage, NULL, NULL);
    407         td_set_ioc(&data->tds[packet]);
    408 
     399        assert(packet == instance->packets - 1);
     400        td_init(&instance->tds[packet], DEFAULT_ERROR_COUNT,
     401            0, 1, false, low_speed, instance->target, status_stage, NULL, NULL);
     402
     403        td_set_ioc(&instance->tds[packet]);
    409404        usb_log_debug2("Control last TD status: %x.\n",
    410             data->tds[packet].status);
    411 }
    412 /*----------------------------------------------------------------------------*/
    413 qh_t * batch_qh(usb_transfer_batch_t *instance)
    414 {
    415         assert(instance);
    416         uhci_batch_t *data = instance->private_data;
    417         assert(data);
    418         return data->qh;
     405            instance->tds[packet].status);
     406}
     407/*----------------------------------------------------------------------------*/
     408/** Prepare data, get error status and call callback in.
     409 *
     410 * @param[in] instance Batch structure to use.
     411 * Copies data from transport buffer, and calls callback with appropriate
     412 * parameters.
     413 */
     414void batch_call_in(batch_t *instance)
     415{
     416        assert(instance);
     417        assert(instance->callback_in);
     418
     419        /* We are data in, we need data */
     420        memcpy(instance->buffer, instance->transport_buffer,
     421            instance->buffer_size);
     422
     423        int err = instance->error;
     424        usb_log_debug("Batch(%p) callback IN(type:%d): %s(%d), %zu.\n",
     425            instance, instance->transfer_type, str_error(err), err,
     426            instance->transfered_size);
     427
     428        instance->callback_in(
     429            instance->fun, err, instance->transfered_size, instance->arg);
     430}
     431/*----------------------------------------------------------------------------*/
     432/** Get error status and call callback out.
     433 *
     434 * @param[in] instance Batch structure to use.
     435 */
     436void batch_call_out(batch_t *instance)
     437{
     438        assert(instance);
     439        assert(instance->callback_out);
     440
     441        int err = instance->error;
     442        usb_log_debug("Batch(%p) callback OUT(type:%d): %s(%d).\n",
     443            instance, instance->transfer_type, str_error(err), err);
     444        instance->callback_out(instance->fun,
     445            err, instance->arg);
    419446}
    420447/*----------------------------------------------------------------------------*/
     
    423450 * @param[in] instance Batch structure to use.
    424451 */
    425 void batch_call_in_and_dispose(usb_transfer_batch_t *instance)
    426 {
    427         assert(instance);
    428         usb_transfer_batch_call_in(instance);
     452void batch_call_in_and_dispose(batch_t *instance)
     453{
     454        assert(instance);
     455        batch_call_in(instance);
    429456        batch_dispose(instance);
    430457}
     
    434461 * @param[in] instance Batch structure to use.
    435462 */
    436 void batch_call_out_and_dispose(usb_transfer_batch_t *instance)
    437 {
    438         assert(instance);
    439         usb_transfer_batch_call_out(instance);
     463void batch_call_out_and_dispose(batch_t *instance)
     464{
     465        assert(instance);
     466        batch_call_out(instance);
    440467        batch_dispose(instance);
    441468}
     
    445472 * @param[in] instance Batch structure to use.
    446473 */
    447 void batch_dispose(usb_transfer_batch_t *instance)
    448 {
    449         assert(instance);
    450         uhci_batch_t *data = instance->private_data;
    451         assert(data);
     474void batch_dispose(batch_t *instance)
     475{
     476        assert(instance);
    452477        usb_log_debug("Batch(%p) disposing.\n", instance);
    453478        /* free32 is NULL safe */
    454         free32(data->tds);
    455         free32(data->qh);
     479        free32(instance->tds);
     480        free32(instance->qh);
    456481        free32(instance->setup_buffer);
    457482        free32(instance->transport_buffer);
    458         free(data);
    459483        free(instance);
    460484}
  • uspace/drv/uhci-hcd/batch.h

    r41ef5b9 rfd9f6e4c  
    3939#include <usbhc_iface.h>
    4040#include <usb/usb.h>
    41 #include <usb/host/device_keeper.h>
    42 #include <usb/host/batch.h>
    4341
     42#include "uhci_struct/transfer_descriptor.h"
    4443#include "uhci_struct/queue_head.h"
     44#include "utils/device_keeper.h"
    4545
    46 usb_transfer_batch_t * batch_get(
     46typedef struct batch
     47{
     48        link_t link;
     49        usb_speed_t speed;
     50        usb_target_t target;
     51        usb_transfer_type_t transfer_type;
     52        usbhc_iface_transfer_in_callback_t callback_in;
     53        usbhc_iface_transfer_out_callback_t callback_out;
     54        void *arg;
     55        char *transport_buffer;
     56        char *setup_buffer;
     57        size_t setup_size;
     58        char *buffer;
     59        size_t buffer_size;
     60        size_t max_packet_size;
     61        size_t packets;
     62        size_t transfered_size;
     63        int error;
     64        ddf_fun_t *fun;
     65        qh_t *qh;
     66        td_t *tds;
     67        void (*next_step)(struct batch*);
     68        device_keeper_t *manager;
     69} batch_t;
     70
     71batch_t * batch_get(
    4772    ddf_fun_t *fun,
    4873                usb_target_t target,
     
    5782    usbhc_iface_transfer_out_callback_t func_out,
    5883                void *arg,
    59                 usb_device_keeper_t *manager
     84                device_keeper_t *manager
    6085                );
    6186
    62 void batch_dispose(usb_transfer_batch_t *instance);
     87void batch_dispose(batch_t *instance);
    6388
    64 bool batch_is_complete(usb_transfer_batch_t *instance);
     89void batch_abort(batch_t *instance);
    6590
    66 void batch_control_write(usb_transfer_batch_t *instance);
     91bool batch_is_complete(batch_t *instance);
    6792
    68 void batch_control_read(usb_transfer_batch_t *instance);
     93void batch_control_write(batch_t *instance);
    6994
    70 void batch_interrupt_in(usb_transfer_batch_t *instance);
     95void batch_control_read(batch_t *instance);
    7196
    72 void batch_interrupt_out(usb_transfer_batch_t *instance);
     97void batch_interrupt_in(batch_t *instance);
    7398
    74 void batch_bulk_in(usb_transfer_batch_t *instance);
     99void batch_interrupt_out(batch_t *instance);
    75100
    76 void batch_bulk_out(usb_transfer_batch_t *instance);
     101void batch_bulk_in(batch_t *instance);
    77102
    78 qh_t * batch_qh(usb_transfer_batch_t *instance);
     103void batch_bulk_out(batch_t *instance);
    79104#endif
    80105/**
  • uspace/drv/uhci-hcd/iface.c

    r41ef5b9 rfd9f6e4c  
    4141#include "iface.h"
    4242#include "uhci_hc.h"
     43#include "utils/device_keeper.h"
    4344
    4445/** Reserve default address interface function
     
    5556        assert(hc);
    5657        usb_log_debug("Default address request with speed %d.\n", speed);
    57         usb_device_keeper_reserve_default_address(&hc->device_manager, speed);
     58        device_keeper_reserve_default(&hc->device_manager, speed);
    5859        return EOK;
    5960}
     
    7071        assert(hc);
    7172        usb_log_debug("Default address release.\n");
    72         usb_device_keeper_release_default_address(&hc->device_manager);
     73        device_keeper_release_default(&hc->device_manager);
    7374        return EOK;
    7475}
     
    9091
    9192        usb_log_debug("Address request with speed %d.\n", speed);
    92         *address = device_keeper_get_free_address(&hc->device_manager, speed);
     93        *address = device_keeper_request(&hc->device_manager, speed);
    9394        usb_log_debug("Address request with result: %d.\n", *address);
    9495        if (*address <= 0)
     
    111112        assert(hc);
    112113        usb_log_debug("Address bind %d-%d.\n", address, handle);
    113         usb_device_keeper_bind(&hc->device_manager, address, handle);
     114        device_keeper_bind(&hc->device_manager, address, handle);
    114115        return EOK;
    115116}
     
    127128        assert(hc);
    128129        usb_log_debug("Address release %d.\n", address);
    129         usb_device_keeper_release(&hc->device_manager, address);
     130        device_keeper_release(&hc->device_manager, address);
    130131        return EOK;
    131132}
     
    149150        uhci_hc_t *hc = fun_to_uhci_hc(fun);
    150151        assert(hc);
    151         usb_speed_t speed = usb_device_keeper_get_speed(&hc->device_manager, target.address);
     152        usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
    152153
    153154        usb_log_debug("Interrupt OUT %d:%d %zu(%zu).\n",
    154155            target.address, target.endpoint, size, max_packet_size);
    155156
    156         usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
     157        batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
    157158            max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg,
    158159            &hc->device_manager);
     
    186187        uhci_hc_t *hc = fun_to_uhci_hc(fun);
    187188        assert(hc);
    188         usb_speed_t speed = usb_device_keeper_get_speed(&hc->device_manager, target.address);
     189        usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
    189190        usb_log_debug("Interrupt IN %d:%d %zu(%zu).\n",
    190191            target.address, target.endpoint, size, max_packet_size);
    191192
    192         usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
     193        batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
    193194            max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg,
    194195                        &hc->device_manager);
     
    222223        uhci_hc_t *hc = fun_to_uhci_hc(fun);
    223224        assert(hc);
    224         usb_speed_t speed = usb_device_keeper_get_speed(&hc->device_manager, target.address);
     225        usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
    225226
    226227        usb_log_debug("Bulk OUT %d:%d %zu(%zu).\n",
    227228            target.address, target.endpoint, size, max_packet_size);
    228229
    229         usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_BULK,
     230        batch_t *batch = batch_get(fun, target, USB_TRANSFER_BULK,
    230231            max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg,
    231232            &hc->device_manager);
     
    259260        uhci_hc_t *hc = fun_to_uhci_hc(fun);
    260261        assert(hc);
    261         usb_speed_t speed = usb_device_keeper_get_speed(&hc->device_manager, target.address);
     262        usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
    262263        usb_log_debug("Bulk IN %d:%d %zu(%zu).\n",
    263264            target.address, target.endpoint, size, max_packet_size);
    264265
    265         usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_BULK,
     266        batch_t *batch = batch_get(fun, target, USB_TRANSFER_BULK,
    266267            max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg,
    267268            &hc->device_manager);
     
    298299        uhci_hc_t *hc = fun_to_uhci_hc(fun);
    299300        assert(hc);
    300         usb_speed_t speed = usb_device_keeper_get_speed(&hc->device_manager, target.address);
     301        usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
    301302        usb_log_debug("Control WRITE (%d) %d:%d %zu(%zu).\n",
    302303            speed, target.address, target.endpoint, size, max_packet_size);
     
    305306                return EINVAL;
    306307
    307         usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
     308        batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
    308309            max_packet_size, speed, data, size, setup_data, setup_size,
    309310            NULL, callback, arg, &hc->device_manager);
    310311        if (!batch)
    311312                return ENOMEM;
    312         usb_device_keeper_reset_if_need(&hc->device_manager, target, setup_data);
     313        device_keeper_reset_if_need(&hc->device_manager, target, setup_data);
    313314        batch_control_write(batch);
    314315        const int ret = uhci_hc_schedule(hc, batch);
     
    341342        uhci_hc_t *hc = fun_to_uhci_hc(fun);
    342343        assert(hc);
    343         usb_speed_t speed = usb_device_keeper_get_speed(&hc->device_manager, target.address);
     344        usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
    344345
    345346        usb_log_debug("Control READ(%d) %d:%d %zu(%zu).\n",
    346347            speed, target.address, target.endpoint, size, max_packet_size);
    347         usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
     348        batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
    348349            max_packet_size, speed, data, size, setup_data, setup_size, callback,
    349350            NULL, arg, &hc->device_manager);
  • uspace/drv/uhci-hcd/transfer_list.c

    r41ef5b9 rfd9f6e4c  
    3838
    3939static void transfer_list_remove_batch(
    40     transfer_list_t *instance, usb_transfer_batch_t *batch);
     40    transfer_list_t *instance, batch_t *batch);
    4141/*----------------------------------------------------------------------------*/
    4242/** Initialize transfer list structures.
     
    9292 * The batch is added to the end of the list and queue.
    9393 */
    94 void transfer_list_add_batch(transfer_list_t *instance, usb_transfer_batch_t *batch)
     94void transfer_list_add_batch(transfer_list_t *instance, batch_t *batch)
    9595{
    9696        assert(instance);
     
    9898        usb_log_debug2("Queue %s: Adding batch(%p).\n", instance->name, batch);
    9999
    100         const uint32_t pa = addr_to_phys(batch_qh(batch));
     100        const uint32_t pa = addr_to_phys(batch->qh);
    101101        assert((pa & LINK_POINTER_ADDRESS_MASK) == pa);
    102102
    103103        /* New batch will be added to the end of the current list
    104104         * so set the link accordingly */
    105         qh_set_next_qh(batch_qh(batch), instance->queue_head->next);
     105        qh_set_next_qh(batch->qh, instance->queue_head->next);
    106106
    107107        fibril_mutex_lock(&instance->guard);
     
    115115        } else {
    116116                /* There is something scheduled */
    117                 usb_transfer_batch_t *last = list_get_instance(
    118                     instance->batch_list.prev, usb_transfer_batch_t, link);
    119                 qh_set_next_qh(batch_qh(last), pa);
     117                batch_t *last = list_get_instance(
     118                    instance->batch_list.prev, batch_t, link);
     119                qh_set_next_qh(last->qh, pa);
    120120        }
    121121        /* Add to the driver list */
    122122        list_append(&batch->link, &instance->batch_list);
    123123
    124         usb_transfer_batch_t *first = list_get_instance(
    125             instance->batch_list.next, usb_transfer_batch_t, link);
     124        batch_t *first = list_get_instance(
     125            instance->batch_list.next, batch_t, link);
    126126        usb_log_debug("Batch(%p) added to queue %s, first is %p.\n",
    127127                batch, instance->name, first);
     
    148148        while (current != &instance->batch_list) {
    149149                link_t *next = current->next;
    150                 usb_transfer_batch_t *batch = list_get_instance(current, usb_transfer_batch_t, link);
     150                batch_t *batch = list_get_instance(current, batch_t, link);
    151151
    152152                if (batch_is_complete(batch)) {
     
    162162                link_t *item = done.next;
    163163                list_remove(item);
    164                 usb_transfer_batch_t *batch = list_get_instance(item, usb_transfer_batch_t, link);
     164                batch_t *batch = list_get_instance(item, batch_t, link);
    165165                batch->next_step(batch);
    166166        }
     
    176176        while (list_empty(&instance->batch_list)) {
    177177                link_t *current = instance->batch_list.next;
    178                 usb_transfer_batch_t *batch = list_get_instance(current, usb_transfer_batch_t, link);
     178                batch_t *batch = list_get_instance(current, batch_t, link);
    179179                transfer_list_remove_batch(instance, batch);
    180                 usb_transfer_batch_finish(batch, EIO);
     180                batch_abort(batch);
    181181        }
    182182        fibril_mutex_unlock(&instance->guard);
     
    191191 * Does not lock the transfer list, caller is responsible for that.
    192192 */
    193 void transfer_list_remove_batch(transfer_list_t *instance, usb_transfer_batch_t *batch)
    194 {
    195         assert(instance);
     193void transfer_list_remove_batch(transfer_list_t *instance, batch_t *batch)
     194{
     195        assert(instance);
     196        assert(batch);
    196197        assert(instance->queue_head);
    197         assert(batch);
    198         assert(batch_qh(batch));
     198        assert(batch->qh);
    199199        usb_log_debug2(
    200200            "Queue %s: removing batch(%p).\n", instance->name, batch);
     
    204204        if (batch->link.prev == &instance->batch_list) {
    205205                /* I'm the first one here */
    206                 qh_set_element_qh(instance->queue_head, batch_qh(batch)->next);
     206                qh_set_element_qh(instance->queue_head, batch->qh->next);
    207207                pos = "FIRST";
    208208        } else {
    209                 usb_transfer_batch_t *prev =
    210                     list_get_instance(batch->link.prev, usb_transfer_batch_t, link);
    211                 qh_set_next_qh(batch_qh(prev), batch_qh(batch)->next);
     209                batch_t *prev =
     210                    list_get_instance(batch->link.prev, batch_t, link);
     211                qh_set_next_qh(prev->qh, batch->qh->next);
    212212                pos = "NOT FIRST";
    213213        }
     
    215215        list_remove(&batch->link);
    216216        usb_log_debug("Batch(%p) removed (%s) from %s, next element %x.\n",
    217             batch, pos, instance->name, batch_qh(batch)->next);
     217            batch, pos, instance->name, batch->qh->next);
    218218}
    219219/**
  • uspace/drv/uhci-hcd/transfer_list.h

    r41ef5b9 rfd9f6e4c  
    6666void transfer_list_set_next(transfer_list_t *instance, transfer_list_t *next);
    6767
    68 void transfer_list_add_batch(transfer_list_t *instance, usb_transfer_batch_t *batch);
     68void transfer_list_add_batch(transfer_list_t *instance, batch_t *batch);
    6969
    7070void transfer_list_remove_finished(transfer_list_t *instance);
  • uspace/drv/uhci-hcd/uhci.c

    r41ef5b9 rfd9f6e4c  
    7070{
    7171        assert(fun);
    72         usb_device_keeper_t *manager = &((uhci_t*)fun->dev->driver_data)->hc.device_manager;
    73 
    74         usb_address_t addr = usb_device_keeper_find(manager, handle);
     72        device_keeper_t *manager = &((uhci_t*)fun->dev->driver_data)->hc.device_manager;
     73
     74        usb_address_t addr = device_keeper_find(manager, handle);
    7575        if (addr < 0) {
    7676                return addr;
  • uspace/drv/uhci-hcd/uhci_hc.c

    r41ef5b9 rfd9f6e4c  
    121121                    fibril_create(uhci_hc_interrupt_emulator, instance);
    122122                fibril_add_ready(instance->cleaner);
    123         } else {
    124                 /* TODO: enable interrupts here */
    125123        }
    126124
     
    236234
    237235        /* Init device keeper*/
    238         usb_device_keeper_init(&instance->device_manager);
     236        device_keeper_init(&instance->device_manager);
    239237        usb_log_debug("Initialized device manager.\n");
    240238
     
    318316 * Checks for bandwidth availability and appends the batch to the proper queue.
    319317 */
    320 int uhci_hc_schedule(uhci_hc_t *instance, usb_transfer_batch_t *batch)
     318int uhci_hc_schedule(uhci_hc_t *instance, batch_t *batch)
    321319{
    322320        assert(instance);
  • uspace/drv/uhci-hcd/uhci_hc.h

    r41ef5b9 rfd9f6e4c  
    4242
    4343#include <usbhc_iface.h>
    44 #include <usb/host/device_keeper.h>
    4544
    4645#include "batch.h"
    4746#include "transfer_list.h"
     47#include "utils/device_keeper.h"
    4848
    4949typedef struct uhci_regs {
     
    8383
    8484typedef struct uhci_hc {
    85         usb_device_keeper_t device_manager;
     85        device_keeper_t device_manager;
    8686
    8787        regs_t *registers;
     
    109109    void *regs, size_t reg_size, bool interupts);
    110110
    111 int uhci_hc_schedule(uhci_hc_t *instance, usb_transfer_batch_t *batch);
     111int uhci_hc_schedule(uhci_hc_t *instance, batch_t *batch);
    112112
    113113void uhci_hc_interrupt(uhci_hc_t *instance, uint16_t status);
  • uspace/drv/usbhid/hiddev.c

    r41ef5b9 rfd9f6e4c  
    184184 *                     successfuly initialize the structure.
    185185 *
    186  * @sa usb_pipe_initialize_from_configuration(),
     186 * @sa usb_endpoint_pipe_initialize_from_configuration(),
    187187 *     usbhid_dev_get_report_descriptor()
    188188 */
     
    218218        };
    219219       
    220         rc = usb_pipe_initialize_from_configuration(
     220        rc = usb_endpoint_pipe_initialize_from_configuration(
    221221            endpoint_mapping, 1, descriptors, descriptors_size,
    222222            &hid_dev->wire);
     
    359359 * @return Other value inherited from one of functions
    360360 *         usb_device_connection_initialize_from_device(),
    361  *         usb_pipe_initialize_default_control(),
    362  *         usb_pipe_start_session(), usb_pipe_end_session(),
     361 *         usb_endpoint_pipe_initialize_default_control(),
     362 *         usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(),
    363363 *         usbhid_dev_process_descriptors().
    364364 *
     
    404404         * Initialize device pipes.
    405405         */
    406         rc = usb_pipe_initialize_default_control(&hid_dev->ctrl_pipe,
     406        rc = usb_endpoint_pipe_initialize_default_control(&hid_dev->ctrl_pipe,
    407407            &hid_dev->wire);
    408408        if (rc != EOK) {
     
    411411                return rc;
    412412        }
    413         rc = usb_pipe_probe_default_control(&hid_dev->ctrl_pipe);
     413        rc = usb_endpoint_pipe_probe_default_control(&hid_dev->ctrl_pipe);
    414414        if (rc != EOK) {
    415415                usb_log_error("Probing default control pipe failed: %s.\n",
     
    430430         * Get descriptors, parse descriptors and save endpoints.
    431431         */
    432         rc = usb_pipe_start_session(&hid_dev->ctrl_pipe);
     432        rc = usb_endpoint_pipe_start_session(&hid_dev->ctrl_pipe);
    433433        if (rc != EOK) {
    434434                usb_log_error("Failed to start session on the control pipe: %s"
     
    440440        if (rc != EOK) {
    441441                /* TODO: end session?? */
    442                 usb_pipe_end_session(&hid_dev->ctrl_pipe);
     442                usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe);
    443443                usb_log_error("Failed to process descriptors: %s.\n",
    444444                    str_error(rc));
     
    446446        }
    447447       
    448         rc = usb_pipe_end_session(&hid_dev->ctrl_pipe);
     448        rc = usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe);
    449449        if (rc != EOK) {
    450450                usb_log_warning("Failed to start session on the control pipe: "
  • uspace/drv/usbhid/hiddev.h

    r41ef5b9 rfd9f6e4c  
    6868        usb_device_connection_t wire;
    6969        /** USB pipe corresponding to the default Control endpoint. */
    70         usb_pipe_t ctrl_pipe;
     70        usb_endpoint_pipe_t ctrl_pipe;
    7171        /** USB pipe corresponding to the Interrupt In (polling) pipe. */
    72         usb_pipe_t poll_pipe;
     72        usb_endpoint_pipe_t poll_pipe;
    7373       
    7474        /** Polling interval retreived from the Interface descriptor. */
  • uspace/drv/usbhid/hidreq.c

    r41ef5b9 rfd9f6e4c  
    5757 * @retval EINVAL if no HID device is given.
    5858 * @return Other value inherited from one of functions
    59  *         usb_pipe_start_session(), usb_pipe_end_session(),
     59 *         usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(),
    6060 *         usb_control_request_set().
    6161 */
     
    7676        int rc, sess_rc;
    7777       
    78         sess_rc = usb_pipe_start_session(&hid_dev->ctrl_pipe);
     78        sess_rc = usb_endpoint_pipe_start_session(&hid_dev->ctrl_pipe);
    7979        if (sess_rc != EOK) {
    8080                usb_log_warning("Failed to start a session: %s.\n",
     
    9292            USB_HIDREQ_SET_REPORT, value, hid_dev->iface, buffer, buf_size);
    9393
    94         sess_rc = usb_pipe_end_session(&hid_dev->ctrl_pipe);
     94        sess_rc = usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe);
    9595
    9696        if (rc != EOK) {
     
    119119 * @retval EINVAL if no HID device is given.
    120120 * @return Other value inherited from one of functions
    121  *         usb_pipe_start_session(), usb_pipe_end_session(),
     121 *         usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(),
    122122 *         usb_control_request_set().
    123123 */
     
    137137        int rc, sess_rc;
    138138       
    139         sess_rc = usb_pipe_start_session(&hid_dev->ctrl_pipe);
     139        sess_rc = usb_endpoint_pipe_start_session(&hid_dev->ctrl_pipe);
    140140        if (sess_rc != EOK) {
    141141                usb_log_warning("Failed to start a session: %s.\n",
     
    151151            USB_HIDREQ_SET_PROTOCOL, protocol, hid_dev->iface, NULL, 0);
    152152
    153         sess_rc = usb_pipe_end_session(&hid_dev->ctrl_pipe);
     153        sess_rc = usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe);
    154154
    155155        if (rc != EOK) {
     
    179179 * @retval EINVAL if no HID device is given.
    180180 * @return Other value inherited from one of functions
    181  *         usb_pipe_start_session(), usb_pipe_end_session(),
     181 *         usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(),
    182182 *         usb_control_request_set().
    183183 */
     
    197197        int rc, sess_rc;
    198198       
    199         sess_rc = usb_pipe_start_session(&hid_dev->ctrl_pipe);
     199        sess_rc = usb_endpoint_pipe_start_session(&hid_dev->ctrl_pipe);
    200200        if (sess_rc != EOK) {
    201201                usb_log_warning("Failed to start a session: %s.\n",
     
    213213            USB_HIDREQ_SET_IDLE, value, hid_dev->iface, NULL, 0);
    214214
    215         sess_rc = usb_pipe_end_session(&hid_dev->ctrl_pipe);
     215        sess_rc = usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe);
    216216
    217217        if (rc != EOK) {
     
    244244 * @retval EINVAL if no HID device is given.
    245245 * @return Other value inherited from one of functions
    246  *         usb_pipe_start_session(), usb_pipe_end_session(),
     246 *         usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(),
    247247 *         usb_control_request_set().
    248248 */
     
    263263        int rc, sess_rc;
    264264       
    265         sess_rc = usb_pipe_start_session(&hid_dev->ctrl_pipe);
     265        sess_rc = usb_endpoint_pipe_start_session(&hid_dev->ctrl_pipe);
    266266        if (sess_rc != EOK) {
    267267                usb_log_warning("Failed to start a session: %s.\n",
     
    280280            actual_size);
    281281
    282         sess_rc = usb_pipe_end_session(&hid_dev->ctrl_pipe);
     282        sess_rc = usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe);
    283283
    284284        if (rc != EOK) {
     
    307307 * @retval EINVAL if no HID device is given.
    308308 * @return Other value inherited from one of functions
    309  *         usb_pipe_start_session(), usb_pipe_end_session(),
     309 *         usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(),
    310310 *         usb_control_request_set().
    311311 */
     
    325325        int rc, sess_rc;
    326326       
    327         sess_rc = usb_pipe_start_session(&hid_dev->ctrl_pipe);
     327        sess_rc = usb_endpoint_pipe_start_session(&hid_dev->ctrl_pipe);
    328328        if (sess_rc != EOK) {
    329329                usb_log_warning("Failed to start a session: %s.\n",
     
    342342            USB_HIDREQ_GET_PROTOCOL, 0, hid_dev->iface, buffer, 1, &actual_size);
    343343
    344         sess_rc = usb_pipe_end_session(&hid_dev->ctrl_pipe);
     344        sess_rc = usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe);
    345345
    346346        if (rc != EOK) {
     
    378378 * @retval EINVAL if no HID device is given.
    379379 * @return Other value inherited from one of functions
    380  *         usb_pipe_start_session(), usb_pipe_end_session(),
     380 *         usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(),
    381381 *         usb_control_request_set().
    382382 */
     
    396396        int rc, sess_rc;
    397397       
    398         sess_rc = usb_pipe_start_session(&hid_dev->ctrl_pipe);
     398        sess_rc = usb_endpoint_pipe_start_session(&hid_dev->ctrl_pipe);
    399399        if (sess_rc != EOK) {
    400400                usb_log_warning("Failed to start a session: %s.\n",
     
    415415            &actual_size);
    416416
    417         sess_rc = usb_pipe_end_session(&hid_dev->ctrl_pipe);
     417        sess_rc = usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe);
    418418
    419419        if (rc != EOK) {
  • uspace/drv/usbhid/kbddev.c

    r41ef5b9 rfd9f6e4c  
    780780
    781781        while (true) {
    782                 sess_rc = usb_pipe_start_session(
     782                sess_rc = usb_endpoint_pipe_start_session(
    783783                    &kbd_dev->hid_dev->poll_pipe);
    784784                if (sess_rc != EOK) {
     
    788788                }
    789789
    790                 rc = usb_pipe_read(&kbd_dev->hid_dev->poll_pipe,
     790                rc = usb_endpoint_pipe_read(&kbd_dev->hid_dev->poll_pipe,
    791791                    buffer, BOOTP_BUFFER_SIZE, &actual_size);
    792792               
    793                 sess_rc = usb_pipe_end_session(
     793                sess_rc = usb_endpoint_pipe_end_session(
    794794                    &kbd_dev->hid_dev->poll_pipe);
    795795
  • uspace/drv/usbhub/main.c

    r41ef5b9 rfd9f6e4c  
    4242#include "usbhub_private.h"
    4343
    44 /** Hub status-change endpoint description.
    45  *
    46  * For more information see section 11.15.1 of USB 1.1 specification.
    47  */
    48 static usb_endpoint_description_t hub_status_change_endpoint_description = {
     44
     45usb_endpoint_description_t hub_status_change_endpoint_description = {
    4946        .transfer_type = USB_TRANSFER_INTERRUPT,
    5047        .direction = USB_DIRECTION_IN,
     
    6057};
    6158
    62 static usb_endpoint_description_t *usb_hub_endpoints[] = {
    63         &hub_status_change_endpoint_description,
    64         NULL
    65 };
    66 
    6759static usb_driver_t usb_hub_driver = {
    68         .name = NAME,
    69         .ops = &usb_hub_driver_ops,
    70         .endpoints = usb_hub_endpoints
     60        .name = "usbhub",
     61        .ops = &usb_hub_driver_ops
    7162};
    7263
     
    7465int main(int argc, char *argv[])
    7566{
    76         printf(NAME ": HelenOS USB hub driver.\n");
     67        usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME);
     68        usb_log_info("starting hub driver\n");
    7769
    78         usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME);
    7970       
     71        usb_hub_driver.endpoints = (usb_endpoint_description_t**)
     72                        malloc(2 * sizeof(usb_endpoint_description_t*));
     73        usb_hub_driver.endpoints[0] = &hub_status_change_endpoint_description;
     74        usb_hub_driver.endpoints[1] = NULL;
     75
    8076        return usb_driver_main(&usb_hub_driver);
    8177}
  • uspace/drv/usbhub/usbhub.c

    r41ef5b9 rfd9f6e4c  
    157157static int usb_hub_set_configuration(usb_hub_info_t * hub_info){
    158158        //device descriptor
    159         usb_standard_device_descriptor_t *std_descriptor
    160             = &hub_info->usb_device->descriptors.device;
     159        usb_standard_device_descriptor_t std_descriptor;
     160        int opResult = usb_request_get_device_descriptor(
     161                &hub_info->usb_device->ctrl_pipe,
     162            &std_descriptor);
     163        if(opResult!=EOK){
     164                usb_log_error("could not get device descriptor, %d\n",opResult);
     165                return opResult;
     166        }
    161167        usb_log_info("hub has %d configurations\n",
    162             std_descriptor->configuration_count);
    163         if(std_descriptor->configuration_count<1){
     168                        std_descriptor.configuration_count);
     169        if(std_descriptor.configuration_count<1){
    164170                usb_log_error("THERE ARE NO CONFIGURATIONS AVAILABLE\n");
    165171                //shouldn`t I return?
    166                 //definitely
    167                 return EINVAL;
    168         }
    169 
     172        }
     173
     174        /* Retrieve full configuration descriptor. */
     175        uint8_t *descriptors = NULL;
     176        size_t descriptors_size = 0;
     177        opResult = usb_request_get_full_configuration_descriptor_alloc(
     178            &hub_info->usb_device->ctrl_pipe, 0,
     179            (void **) &descriptors, &descriptors_size);
     180        if (opResult != EOK) {
     181                usb_log_error("Could not get configuration descriptor: %s.\n",
     182                    str_error(opResult));
     183                return opResult;
     184        }
    170185        usb_standard_configuration_descriptor_t *config_descriptor
    171             = (usb_standard_configuration_descriptor_t *)
    172             hub_info->usb_device->descriptors.configuration;
     186            = (usb_standard_configuration_descriptor_t *) descriptors;
    173187
    174188        /* Set configuration. */
    175         int opResult = usb_request_set_configuration(
    176             &hub_info->usb_device->ctrl_pipe,
     189        opResult = usb_request_set_configuration(&hub_info->usb_device->ctrl_pipe,
    177190            config_descriptor->configuration_number);
    178191
     
    184197        usb_log_debug("\tused configuration %d\n",
    185198                        config_descriptor->configuration_number);
    186 
     199        free(descriptors);
    187200        return EOK;
    188201}
     
    211224        }
    212225       
    213         usb_pipe_start_session(hub_info->control_pipe);
     226        usb_endpoint_pipe_start_session(hub_info->control_pipe);
    214227        //set hub configuration
    215228        opResult = usb_hub_set_configuration(hub_info);
     
    226239                return opResult;
    227240        }
    228         usb_pipe_end_session(hub_info->control_pipe);
     241        usb_endpoint_pipe_end_session(hub_info->control_pipe);
    229242
    230243
    231244        /// \TODO what is this?
    232         usb_log_debug("Creating `hub' function.\n");
     245        usb_log_debug("adding to ddf");
    233246        ddf_fun_t *hub_fun = ddf_fun_create(hub_info->usb_device->ddf_dev,
    234247                        fun_exposed, "hub");
     
    244257        fid_t fid = fibril_create(usb_hub_control_loop, hub_info);
    245258        if (fid == 0) {
    246                 usb_log_error("failed to start monitoring fibril for new hub.\n");
     259                usb_log_error("failed to start monitoring fibril for new hub");
    247260                return ENOMEM;
    248261        }
    249262        fibril_add_ready(fid);
    250         usb_log_debug("Hub fibril created.\n");
    251 
    252         usb_log_info("Controlling hub `%s' (%d ports).\n",
    253             hub_info->usb_device->ddf_dev->name, hub_info->port_count);
     263        usb_log_debug("hub fibril created");
     264        usb_log_debug("has %d ports ",hub_info->port_count);
    254265        return EOK;
    255266}
     
    310321        //reset port
    311322        usb_hub_set_reset_port_request(&request, port);
    312         opResult = usb_pipe_control_write(
     323        opResult = usb_endpoint_pipe_control_write(
    313324                        hub->control_pipe,
    314325                        &request,sizeof(usb_device_request_setup_packet_t),
     
    343354        }
    344355        //create connection to device
    345         usb_pipe_t new_device_pipe;
     356        usb_endpoint_pipe_t new_device_pipe;
    346357        usb_device_connection_t new_device_connection;
    347358        usb_device_connection_initialize_on_default_address(
     
    349360                        &hub->connection
    350361                        );
    351         usb_pipe_initialize_default_control(
     362        usb_endpoint_pipe_initialize_default_control(
    352363                        &new_device_pipe,
    353364                        &new_device_connection);
    354         usb_pipe_probe_default_control(&new_device_pipe);
     365        usb_endpoint_pipe_probe_default_control(&new_device_pipe);
    355366
    356367        /* Request address from host controller. */
     
    368379        //opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT,
    369380        //    new_device_address);
    370         usb_pipe_start_session(&new_device_pipe);
     381        usb_endpoint_pipe_start_session(&new_device_pipe);
    371382        opResult = usb_request_set_address(&new_device_pipe,new_device_address);
    372         usb_pipe_end_session(&new_device_pipe);
     383        usb_endpoint_pipe_end_session(&new_device_pipe);
    373384        if (opResult != EOK) {
    374385                usb_log_error("could not set address for new device %d\n",opResult);
     
    477488        usb_log_debug("interrupt at port %d\n", port);
    478489        //determine type of change
    479         usb_pipe_t *pipe = hub->control_pipe;
     490        usb_endpoint_pipe_t *pipe = hub->control_pipe;
    480491       
    481492        int opResult;
     
    488499        //endpoint 0
    489500
    490         opResult = usb_pipe_control_read(
     501        opResult = usb_endpoint_pipe_control_read(
    491502                        pipe,
    492503                        &request, sizeof(usb_device_request_setup_packet_t),
     
    522533        //port reset
    523534        if (usb_port_reset_completed(&status)) {
    524                 usb_log_info("port reset complete\n");
     535                usb_log_info("port reset complete");
    525536                if (usb_port_enabled(&status)) {
    526537                        usb_hub_finalize_add_device(hub, port, usb_port_speed(&status));
     
    549560int usb_hub_check_hub_changes(usb_hub_info_t * hub_info){
    550561        int opResult;
    551         opResult = usb_pipe_start_session(
     562        opResult = usb_endpoint_pipe_start_session(
    552563                        hub_info->status_change_pipe);
    553564        if(opResult != EOK){
     
    567578         * Send the request.
    568579         */
    569         opResult = usb_pipe_read(
     580        opResult = usb_endpoint_pipe_read(
    570581                        hub_info->status_change_pipe,
    571582                        change_bitmap, byte_length, &actual_size
     
    575586                free(change_bitmap);
    576587                usb_log_warning("something went wrong while getting status of hub\n");
    577                 usb_pipe_end_session(hub_info->status_change_pipe);
     588                usb_endpoint_pipe_end_session(hub_info->status_change_pipe);
    578589                return opResult;
    579590        }
    580591        unsigned int port;
    581         opResult = usb_pipe_start_session(hub_info->control_pipe);
     592        opResult = usb_endpoint_pipe_start_session(hub_info->control_pipe);
    582593        if(opResult!=EOK){
    583594                usb_log_error("could not start control pipe session %d\n", opResult);
    584                 usb_pipe_end_session(hub_info->status_change_pipe);
     595                usb_endpoint_pipe_end_session(hub_info->status_change_pipe);
    585596                return opResult;
    586597        }
     
    589600                usb_log_error("could not start host controller session %d\n",
    590601                                opResult);
    591                 usb_pipe_end_session(hub_info->control_pipe);
    592                 usb_pipe_end_session(hub_info->status_change_pipe);
     602                usb_endpoint_pipe_end_session(hub_info->control_pipe);
     603                usb_endpoint_pipe_end_session(hub_info->status_change_pipe);
    593604                return opResult;
    594605        }
     
    604615        }
    605616        usb_hc_connection_close(&hub_info->connection);
    606         usb_pipe_end_session(hub_info->control_pipe);
    607         usb_pipe_end_session(hub_info->status_change_pipe);
     617        usb_endpoint_pipe_end_session(hub_info->control_pipe);
     618        usb_endpoint_pipe_end_session(hub_info->status_change_pipe);
    608619        free(change_bitmap);
    609620        return EOK;
  • uspace/drv/usbhub/usbhub.h

    r41ef5b9 rfd9f6e4c  
    4848
    4949
     50/** Hub status-change endpoint description
     51 *
     52 * For more see usb hub specification in 11.15.1 of
     53 */
     54extern usb_endpoint_description_t hub_status_change_endpoint_description;
     55
     56
     57
     58/* Hub endpoints. */
     59/*typedef struct {
     60        usb_endpoint_pipe_t control;
     61        usb_endpoint_pipe_t status_change;
     62} usb_hub_endpoints_t;
     63*/
     64
     65
    5066/** Information about attached hub. */
    5167typedef struct {
     
    7288         * searched again and again for the 'right pipe'.
    7389         */
    74         usb_pipe_t * status_change_pipe;
     90        usb_endpoint_pipe_t * status_change_pipe;
    7591
    7692        /** convenience pointer to control pipe
     
    8096         * searched again and again for the 'right pipe'.
    8197         */
    82         usb_pipe_t * control_pipe;
     98        usb_endpoint_pipe_t * control_pipe;
    8399
    84100        /** generic usb device data*/
  • uspace/drv/usbhub/usbhub_private.h

    r41ef5b9 rfd9f6e4c  
    9595 * @return Operation result
    9696 */
    97 static inline int usb_hub_clear_port_feature(usb_pipe_t *pipe,
     97static inline int usb_hub_clear_port_feature(usb_endpoint_pipe_t *pipe,
    9898    int port_index,
    9999    usb_hub_class_feature_t feature) {
     
    106106        };
    107107        clear_request.value = feature;
    108         return usb_pipe_control_write(pipe, &clear_request,
     108        return usb_endpoint_pipe_control_write(pipe, &clear_request,
    109109            sizeof(clear_request), NULL, 0);
    110110}
  • uspace/drv/usbmid/main.c

    r41ef5b9 rfd9f6e4c  
    6161        int rc;
    6262
    63         rc = usb_pipe_start_session(&dev->ctrl_pipe);
     63        rc = usb_endpoint_pipe_start_session(&dev->ctrl_pipe);
    6464        if (rc != EOK) {
    6565                usb_log_error("Failed to start session on control pipe: %s.\n",
     
    7070        bool accept = usbmid_explore_device(dev);
    7171
    72         rc = usb_pipe_end_session(&dev->ctrl_pipe);
     72        rc = usb_endpoint_pipe_end_session(&dev->ctrl_pipe);
    7373        if (rc != EOK) {
    7474                usb_log_warning("Failed to end session on control pipe: %s.\n",
  • uspace/drv/usbmid/usbmid.c

    r41ef5b9 rfd9f6e4c  
    108108        }
    109109
    110         rc = usb_pipe_initialize_default_control(&mid->ctrl_pipe,
     110        rc = usb_endpoint_pipe_initialize_default_control(&mid->ctrl_pipe,
    111111            &mid->wire);
    112112        if (rc != EOK) {
     
    116116                return NULL;
    117117        }
    118         rc = usb_pipe_probe_default_control(&mid->ctrl_pipe);
     118        rc = usb_endpoint_pipe_probe_default_control(&mid->ctrl_pipe);
    119119        if (rc != EOK) {
    120120                usb_log_error("Probing default control pipe failed: %s.\n",
  • uspace/drv/usbmid/usbmid.h

    r41ef5b9 rfd9f6e4c  
    5252        usb_device_connection_t wire;
    5353        /** Default control pipe. */
    54         usb_pipe_t ctrl_pipe;
     54        usb_endpoint_pipe_t ctrl_pipe;
    5555} usbmid_device_t;
    5656
  • uspace/drv/usbmouse/init.c

    r41ef5b9 rfd9f6e4c  
    126126       
    127127        /* Open the control pipe. */
    128         rc = usb_pipe_start_session(&dev->ctrl_pipe);
     128        rc = usb_endpoint_pipe_start_session(&dev->ctrl_pipe);
    129129        if (rc != EOK) {
    130130                goto leave;
     
    141141       
    142142        /* Close the control pipe (ignore errors). */
    143         usb_pipe_end_session(&dev->ctrl_pipe);
     143        usb_endpoint_pipe_end_session(&dev->ctrl_pipe);
    144144
    145145
  • uspace/lib/usb/Makefile

    r41ef5b9 rfd9f6e4c  
    4949        src/request.c \
    5050        src/usb.c \
    51         src/usbdevice.c \
    52         src/host/device_keeper.c \
    53         src/host/batch.c
     51        src/usbdevice.c
    5452
    5553include $(USPACE_PREFIX)/Makefile.common
  • uspace/lib/usb/include/usb/classes/hub.h

    r41ef5b9 rfd9f6e4c  
    6060} usb_hub_class_feature_t;
    6161
    62 /** Header of standard hub descriptor without the "variadic" part. */
    63 typedef struct {
    64         /** Descriptor length. */
    65         uint8_t length;
    66         /** Descriptor type (0x29). */
    67         uint8_t descriptor_type;
    68         /** Number of downstream ports. */
    69         uint8_t port_count;
    70         /** Characteristics bitmask. */
    71         uint16_t characteristics;
    72         /** Time from power-on to stabilization of current on the port. */
    73         uint8_t power_good_time;
    74         /** Maximum current requirements in mA. */
    75         uint8_t max_current;
    76 } __attribute__ ((packed)) usb_hub_descriptor_header_t;
    7762
    7863/**
  • uspace/lib/usb/include/usb/devdrv.h

    r41ef5b9 rfd9f6e4c  
    3838#include <usb/pipes.h>
    3939
    40 /** Descriptors for USB device. */
    41 typedef struct {
    42         /** Standard device descriptor. */
    43         usb_standard_device_descriptor_t device;
    44         /** Full configuration descriptor of current configuration. */
    45         uint8_t *configuration;
    46         size_t configuration_size;
    47 } usb_device_descriptors_t;
    48 
    4940/** USB device structure. */
    5041typedef struct {
    5142        /** The default control pipe. */
    52         usb_pipe_t ctrl_pipe;
     43        usb_endpoint_pipe_t ctrl_pipe;
    5344        /** Other endpoint pipes.
    5445         * This is an array of other endpoint pipes in the same order as
     
    6152         */
    6253        int interface_no;
    63 
    64         /** Some useful descriptors. */
    65         usb_device_descriptors_t descriptors;
    66 
    6754        /** Generic DDF device backing this one. */
    6855        ddf_dev_t *ddf_dev;
  • uspace/lib/usb/include/usb/pipes.h

    r41ef5b9 rfd9f6e4c  
    8080         */
    8181        int hc_phone;
    82 } usb_pipe_t;
     82} usb_endpoint_pipe_t;
    8383
    8484
     
    102102typedef struct {
    103103        /** Endpoint pipe. */
    104         usb_pipe_t *pipe;
     104        usb_endpoint_pipe_t *pipe;
    105105        /** Endpoint description. */
    106106        const usb_endpoint_description_t *description;
     
    125125usb_address_t usb_device_get_assigned_address(devman_handle_t);
    126126
    127 int usb_pipe_initialize(usb_pipe_t *, usb_device_connection_t *,
     127int usb_endpoint_pipe_initialize(usb_endpoint_pipe_t *,
     128    usb_device_connection_t *,
    128129    usb_endpoint_t, usb_transfer_type_t, size_t, usb_direction_t);
    129 int usb_pipe_initialize_default_control(usb_pipe_t *,
     130int usb_endpoint_pipe_initialize_default_control(usb_endpoint_pipe_t *,
    130131    usb_device_connection_t *);
    131 int usb_pipe_probe_default_control(usb_pipe_t *);
    132 int usb_pipe_initialize_from_configuration(usb_endpoint_mapping_t *,
     132int usb_endpoint_pipe_probe_default_control(usb_endpoint_pipe_t *);
     133int usb_endpoint_pipe_initialize_from_configuration(usb_endpoint_mapping_t *,
    133134    size_t, uint8_t *, size_t, usb_device_connection_t *);
    134 int usb_pipe_register(usb_pipe_t *, unsigned int, usb_hc_connection_t *);
    135 int usb_pipe_unregister(usb_pipe_t *, usb_hc_connection_t *);
     135int usb_endpoint_pipe_register(usb_endpoint_pipe_t *, unsigned int,
     136    usb_hc_connection_t *);
     137int usb_endpoint_pipe_unregister(usb_endpoint_pipe_t *, usb_hc_connection_t *);
    136138
    137 int usb_pipe_start_session(usb_pipe_t *);
    138 int usb_pipe_end_session(usb_pipe_t *);
    139 bool usb_pipe_is_session_started(usb_pipe_t *);
     139int usb_endpoint_pipe_start_session(usb_endpoint_pipe_t *);
     140int usb_endpoint_pipe_end_session(usb_endpoint_pipe_t *);
     141bool usb_endpoint_pipe_is_session_started(usb_endpoint_pipe_t *);
    140142
    141 int usb_pipe_read(usb_pipe_t *, void *, size_t, size_t *);
    142 int usb_pipe_write(usb_pipe_t *, void *, size_t);
     143int usb_endpoint_pipe_read(usb_endpoint_pipe_t *, void *, size_t, size_t *);
     144int usb_endpoint_pipe_write(usb_endpoint_pipe_t *, void *, size_t);
    143145
    144 int usb_pipe_control_read(usb_pipe_t *, void *, size_t,
     146int usb_endpoint_pipe_control_read(usb_endpoint_pipe_t *, void *, size_t,
    145147    void *, size_t, size_t *);
    146 int usb_pipe_control_write(usb_pipe_t *, void *, size_t,
     148int usb_endpoint_pipe_control_write(usb_endpoint_pipe_t *, void *, size_t,
    147149    void *, size_t);
    148150
  • uspace/lib/usb/include/usb/recognise.h

    r41ef5b9 rfd9f6e4c  
    4848    const usb_standard_interface_descriptor_t *, match_id_list_t *);
    4949
    50 int usb_device_create_match_ids(usb_pipe_t *, match_id_list_t *);
     50int usb_device_create_match_ids(usb_endpoint_pipe_t *, match_id_list_t *);
    5151
    5252int usb_device_register_child_in_devman(usb_address_t, devman_handle_t,
  • uspace/lib/usb/include/usb/request.h

    r41ef5b9 rfd9f6e4c  
    8686} __attribute__ ((packed)) usb_device_request_setup_packet_t;
    8787
    88 int usb_control_request_set(usb_pipe_t *,
     88int usb_control_request_set(usb_endpoint_pipe_t *,
    8989    usb_request_type_t, usb_request_recipient_t, uint8_t,
    9090    uint16_t, uint16_t, void *, size_t);
    9191
    92 int usb_control_request_get(usb_pipe_t *,
     92int usb_control_request_get(usb_endpoint_pipe_t *,
    9393    usb_request_type_t, usb_request_recipient_t, uint8_t,
    9494    uint16_t, uint16_t, void *, size_t, size_t *);
    9595
    96 int usb_request_get_status(usb_pipe_t *, usb_request_recipient_t,
    97     uint16_t, uint16_t *);
    98 int usb_request_clear_feature(usb_pipe_t *, usb_request_type_t,
    99     usb_request_recipient_t, uint16_t, uint16_t);
    100 int usb_request_set_feature(usb_pipe_t *, usb_request_type_t,
    101     usb_request_recipient_t, uint16_t, uint16_t);
    102 int usb_request_set_address(usb_pipe_t *, usb_address_t);
    103 int usb_request_get_descriptor(usb_pipe_t *, usb_request_type_t,
     96int usb_request_set_address(usb_endpoint_pipe_t *, usb_address_t);
     97int usb_request_get_descriptor(usb_endpoint_pipe_t *, usb_request_type_t,
    10498    usb_request_recipient_t, uint8_t, uint8_t, uint16_t, void *, size_t,
    10599    size_t *);
    106 int usb_request_get_descriptor_alloc(usb_pipe_t *, usb_request_type_t,
     100int usb_request_get_descriptor_alloc(usb_endpoint_pipe_t *, usb_request_type_t,
    107101    usb_request_recipient_t, uint8_t, uint8_t, uint16_t, void **, size_t *);
    108 int usb_request_get_device_descriptor(usb_pipe_t *,
     102int usb_request_get_device_descriptor(usb_endpoint_pipe_t *,
    109103    usb_standard_device_descriptor_t *);
    110 int usb_request_get_bare_configuration_descriptor(usb_pipe_t *, int,
     104int usb_request_get_bare_configuration_descriptor(usb_endpoint_pipe_t *, int,
    111105    usb_standard_configuration_descriptor_t *);
    112 int usb_request_get_full_configuration_descriptor(usb_pipe_t *, int,
     106int usb_request_get_full_configuration_descriptor(usb_endpoint_pipe_t *, int,
    113107    void *, size_t, size_t *);
    114 int usb_request_get_full_configuration_descriptor_alloc(usb_pipe_t *,
     108int usb_request_get_full_configuration_descriptor_alloc(usb_endpoint_pipe_t *,
    115109    int, void **, size_t *);
    116 int usb_request_set_descriptor(usb_pipe_t *, usb_request_type_t,
    117     usb_request_recipient_t, uint8_t, uint8_t, uint16_t, void *, size_t);
    118 int usb_request_get_configuration(usb_pipe_t *, uint8_t *);
    119 int usb_request_set_configuration(usb_pipe_t *, uint8_t);
    120 int usb_request_get_interface(usb_pipe_t *, uint8_t, uint8_t *);
    121 int usb_request_set_interface(usb_pipe_t *, uint8_t, uint8_t);
     110int usb_request_set_configuration(usb_endpoint_pipe_t *, uint8_t);
    122111
    123 int usb_request_get_supported_languages(usb_pipe_t *,
     112int usb_request_get_supported_languages(usb_endpoint_pipe_t *,
    124113    l18_win_locales_t **, size_t *);
    125 int usb_request_get_string(usb_pipe_t *, size_t, l18_win_locales_t,
     114int usb_request_get_string(usb_endpoint_pipe_t *, size_t, l18_win_locales_t,
    126115    char **);
    127116
  • uspace/lib/usb/include/usb/usb.h

    r41ef5b9 rfd9f6e4c  
    6161
    6262const char * usb_str_transfer_type(usb_transfer_type_t t);
    63 const char * usb_str_transfer_type_short(usb_transfer_type_t t);
    6463
    6564/** USB data transfer direction. */
     
    7978        USB_SPEED_HIGH
    8079} usb_speed_t;
    81 
    82 const char *usb_str_speed(usb_speed_t);
    83 
    8480
    8581/** USB request type target. */
  • uspace/lib/usb/src/devdrv.c

    r41ef5b9 rfd9f6e4c  
    126126
    127127        for (i = 0; i < pipe_count; i++) {
    128                 dev->pipes[i].pipe = malloc(sizeof(usb_pipe_t));
     128                dev->pipes[i].pipe = malloc(sizeof(usb_endpoint_pipe_t));
    129129                if (dev->pipes[i].pipe == NULL) {
    130130                        usb_log_oom(dev->ddf_dev);
     
    137137        }
    138138
    139         rc = usb_pipe_initialize_from_configuration(dev->pipes, pipe_count,
    140             dev->descriptors.configuration, dev->descriptors.configuration_size,
    141             &dev->wire);
     139        void *config_descriptor;
     140        size_t config_descriptor_size;
     141        rc = usb_request_get_full_configuration_descriptor_alloc(
     142            &dev->ctrl_pipe, 0, &config_descriptor, &config_descriptor_size);
     143        if (rc != EOK) {
     144                usb_log_error("Failed retrieving configuration of `%s': %s.\n",
     145                    dev->ddf_dev->name, str_error(rc));
     146                goto rollback;
     147        }
     148
     149        rc = usb_endpoint_pipe_initialize_from_configuration(dev->pipes,
     150           pipe_count, config_descriptor, config_descriptor_size, &dev->wire);
    142151        if (rc != EOK) {
    143152                usb_log_error("Failed initializing USB endpoints: %s.\n",
     
    163172        for (i = 0; i < pipe_count; i++) {
    164173                if (dev->pipes[i].present) {
    165                         rc = usb_pipe_register(dev->pipes[i].pipe,
     174                        rc = usb_endpoint_pipe_register(dev->pipes[i].pipe,
    166175                            dev->pipes[i].descriptor->poll_interval,
    167176                            &hc_conn);
     
    210219        }
    211220
    212         rc = usb_pipe_initialize_default_control(&dev->ctrl_pipe,
     221        rc = usb_endpoint_pipe_initialize_default_control(&dev->ctrl_pipe,
    213222            &dev->wire);
    214223        if (rc != EOK) {
     
    219228        }
    220229
    221         rc = usb_pipe_probe_default_control(&dev->ctrl_pipe);
     230        rc = usb_endpoint_pipe_probe_default_control(&dev->ctrl_pipe);
    222231        if (rc != EOK) {
    223232                usb_log_error(
     
    228237
    229238        /*
    230          * For further actions, we need open session on default control pipe.
     239         * Initialization of other pipes requires open session on
     240         * default control pipe.
    231241         */
    232         rc = usb_pipe_start_session(&dev->ctrl_pipe);
     242        rc = usb_endpoint_pipe_start_session(&dev->ctrl_pipe);
    233243        if (rc != EOK) {
    234244                usb_log_error("Failed to start an IPC session: %s.\n",
    235245                    str_error(rc));
    236                 return rc;
    237         }
    238 
    239         /* Get the device descriptor. */
    240         rc = usb_request_get_device_descriptor(&dev->ctrl_pipe,
    241             &dev->descriptors.device);
    242         if (rc != EOK) {
    243                 usb_log_error("Failed to retrieve device descriptor: %s.\n",
    244                     str_error(rc));
    245                 return rc;
    246         }
    247 
    248         /* Get the full configuration descriptor. */
    249         rc = usb_request_get_full_configuration_descriptor_alloc(
    250             &dev->ctrl_pipe, 0, (void **) &dev->descriptors.configuration,
    251             &dev->descriptors.configuration_size);
    252         if (rc != EOK) {
    253                 usb_log_error("Failed retrieving configuration descriptor: %s.\n",
    254                     dev->ddf_dev->name, str_error(rc));
    255246                return rc;
    256247        }
     
    261252
    262253        /* No checking here. */
    263         usb_pipe_end_session(&dev->ctrl_pipe);
    264 
    265         /* Rollback actions. */
    266         if (rc != EOK) {
    267                 if (dev->descriptors.configuration != NULL) {
    268                         free(dev->descriptors.configuration);
    269                 }
    270         }
     254        usb_endpoint_pipe_end_session(&dev->ctrl_pipe);
    271255
    272256        return rc;
     
    299283        dev->ddf_dev->driver_data = dev;
    300284        dev->driver_data = NULL;
    301         dev->descriptors.configuration = NULL;
    302285
    303286        rc = initialize_pipes(dev);
  • uspace/lib/usb/src/devpoll.c

    r41ef5b9 rfd9f6e4c  
    6464        assert(polling_data);
    6565
    66         usb_pipe_t *pipe
     66        usb_endpoint_pipe_t *pipe
    6767            = polling_data->dev->pipes[polling_data->pipe_index].pipe;
    6868
     
    7171                int rc;
    7272
    73                 rc = usb_pipe_start_session(pipe);
     73                rc = usb_endpoint_pipe_start_session(pipe);
    7474                if (rc != EOK) {
    7575                        failed_attempts++;
     
    7878
    7979                size_t actual_size;
    80                 rc = usb_pipe_read(pipe, polling_data->buffer,
     80                rc = usb_endpoint_pipe_read(pipe, polling_data->buffer,
    8181                    polling_data->request_size, &actual_size);
    8282
    8383                /* Quit the session regardless of errors. */
    84                 usb_pipe_end_session(pipe);
     84                usb_endpoint_pipe_end_session(pipe);
    8585
    8686                if (rc != EOK) {
  • uspace/lib/usb/src/hub.c

    r41ef5b9 rfd9f6e4c  
    228228        }
    229229
    230         usb_pipe_t ctrl_pipe;
    231         rc = usb_pipe_initialize_default_control(&ctrl_pipe,
     230        usb_endpoint_pipe_t ctrl_pipe;
     231        rc = usb_endpoint_pipe_initialize_default_control(&ctrl_pipe,
    232232            &dev_conn);
    233233        if (rc != EOK) {
     
    235235                goto leave_release_default_address;
    236236        }
    237         rc = usb_pipe_probe_default_control(&ctrl_pipe);
     237        rc = usb_endpoint_pipe_probe_default_control(&ctrl_pipe);
    238238        if (rc != EOK) {
    239239                rc = ENOTCONN;
     
    241241        }
    242242
    243         rc = usb_pipe_start_session(&ctrl_pipe);
     243        rc = usb_endpoint_pipe_start_session(&ctrl_pipe);
    244244        if (rc != EOK) {
    245245                rc = ENOTCONN;
     
    253253        }
    254254
    255         usb_pipe_end_session(&ctrl_pipe);
     255        usb_endpoint_pipe_end_session(&ctrl_pipe);
    256256
    257257        /*
     
    306306
    307307leave_stop_session:
    308         usb_pipe_end_session(&ctrl_pipe);
     308        usb_endpoint_pipe_end_session(&ctrl_pipe);
    309309
    310310leave_release_default_address:
  • uspace/lib/usb/src/pipes.c

    r41ef5b9 rfd9f6e4c  
    4242#include <assert.h>
    4343
    44 #define IPC_AGAIN_DELAY (1000 * 2) /* 2ms */
    45 
    4644/** Tell USB address assigned to given device.
    4745 *
     
    152150        }
    153151
    154         /*
    155          * Asking for "my" address may require several attempts.
    156          * That is because following scenario may happen:
    157          *  - parent driver (i.e. driver of parent device) announces new device
    158          *    and devman launches current driver
    159          *  - parent driver is preempted and thus does not send address-handle
    160          *    binding to HC driver
    161          *  - this driver gets here and wants the binding
    162          *  - the HC does not know the binding yet and thus it answers ENOENT
    163          *  So, we need to wait for the HC to learn the binding.
    164          */
    165         do {
    166                 my_address = get_my_address(parent_phone, dev);
    167 
    168                 if (my_address == ENOENT) {
    169                         /* Be nice, let other fibrils run and try again. */
    170                         async_usleep(IPC_AGAIN_DELAY);
    171                 } else if (my_address < 0) {
    172                         /* Some other problem, no sense trying again. */
    173                         rc = my_address;
    174                         goto leave;
    175                 }
    176 
    177         } while (my_address < 0);
     152        my_address = get_my_address(parent_phone, dev);
     153        if (my_address < 0) {
     154                rc = my_address;
     155                goto leave;
     156        }
    178157
    179158        rc = usb_device_connection_initialize(connection,
     
    233212 * A session is something inside what any communication occurs.
    234213 * It is expected that sessions would be started right before the transfer
    235  * and ended - see usb_pipe_end_session() - after the last
     214 * and ended - see usb_endpoint_pipe_end_session() - after the last
    236215 * transfer.
    237216 * The reason for this is that session actually opens some communication
     
    244223 * @return Error code.
    245224 */
    246 int usb_pipe_start_session(usb_pipe_t *pipe)
     225int usb_endpoint_pipe_start_session(usb_endpoint_pipe_t *pipe)
    247226{
    248227        assert(pipe);
    249228
    250         if (usb_pipe_is_session_started(pipe)) {
     229        if (usb_endpoint_pipe_is_session_started(pipe)) {
    251230                return EBUSY;
    252231        }
     
    265244/** Ends a session on the endpoint pipe.
    266245 *
    267  * @see usb_pipe_start_session
     246 * @see usb_endpoint_pipe_start_session
    268247 *
    269248 * @param pipe Endpoint pipe to end the session on.
    270249 * @return Error code.
    271250 */
    272 int usb_pipe_end_session(usb_pipe_t *pipe)
     251int usb_endpoint_pipe_end_session(usb_endpoint_pipe_t *pipe)
    273252{
    274253        assert(pipe);
    275254
    276         if (!usb_pipe_is_session_started(pipe)) {
     255        if (!usb_endpoint_pipe_is_session_started(pipe)) {
    277256                return ENOENT;
    278257        }
     
    296275 * @return Whether @p pipe has opened a session.
    297276 */
    298 bool usb_pipe_is_session_started(usb_pipe_t *pipe)
     277bool usb_endpoint_pipe_is_session_started(usb_endpoint_pipe_t *pipe)
    299278{
    300279        return (pipe->hc_phone >= 0);
  • uspace/lib/usb/src/pipesinit.c

    r41ef5b9 rfd9f6e4c  
    193193        }
    194194
    195         int rc = usb_pipe_initialize(ep_mapping->pipe, wire,
     195        int rc = usb_endpoint_pipe_initialize(ep_mapping->pipe, wire,
    196196            ep_no, description.transfer_type, endpoint->max_packet_size,
    197197            description.direction);
     
    276276 * @return Error code.
    277277 */
    278 int usb_pipe_initialize_from_configuration(
     278int usb_endpoint_pipe_initialize_from_configuration(
    279279    usb_endpoint_mapping_t *mapping, size_t mapping_count,
    280280    uint8_t *configuration_descriptor, size_t configuration_descriptor_size,
     
    342342 * @return Error code.
    343343 */
    344 int usb_pipe_initialize(usb_pipe_t *pipe,
     344int usb_endpoint_pipe_initialize(usb_endpoint_pipe_t *pipe,
    345345    usb_device_connection_t *connection, usb_endpoint_t endpoint_no,
    346346    usb_transfer_type_t transfer_type, size_t max_packet_size,
     
    367367 * @return Error code.
    368368 */
    369 int usb_pipe_initialize_default_control(usb_pipe_t *pipe,
     369int usb_endpoint_pipe_initialize_default_control(usb_endpoint_pipe_t *pipe,
    370370    usb_device_connection_t *connection)
    371371{
     
    373373        assert(connection);
    374374
    375         int rc = usb_pipe_initialize(pipe, connection,
     375        int rc = usb_endpoint_pipe_initialize(pipe, connection,
    376376            0, USB_TRANSFER_CONTROL, CTRL_PIPE_MIN_PACKET_SIZE,
    377377            USB_DIRECTION_BOTH);
     
    390390 * @return Error code.
    391391 */
    392 int usb_pipe_probe_default_control(usb_pipe_t *pipe)
     392int usb_endpoint_pipe_probe_default_control(usb_endpoint_pipe_t *pipe)
    393393{
    394394        assert(pipe);
     
    408408
    409409        TRY_LOOP(failed_attempts) {
    410                 rc = usb_pipe_start_session(pipe);
     410                rc = usb_endpoint_pipe_start_session(pipe);
    411411                if (rc == EOK) {
    412412                        break;
     
    433433                }
    434434        }
    435         usb_pipe_end_session(pipe);
     435        usb_endpoint_pipe_end_session(pipe);
    436436        if (rc != EOK) {
    437437                return rc;
     
    451451 * @return Error code.
    452452 */
    453 int usb_pipe_register(usb_pipe_t *pipe,
     453int usb_endpoint_pipe_register(usb_endpoint_pipe_t *pipe,
    454454    unsigned int interval,
    455455    usb_hc_connection_t *hc_connection)
     
    479479 * @return Error code.
    480480 */
    481 int usb_pipe_unregister(usb_pipe_t *pipe,
     481int usb_endpoint_pipe_unregister(usb_endpoint_pipe_t *pipe,
    482482    usb_hc_connection_t *hc_connection)
    483483{
  • uspace/lib/usb/src/pipesio.c

    r41ef5b9 rfd9f6e4c  
    5858 * @return Error code.
    5959 */
    60 static int usb_pipe_read_no_checks(usb_pipe_t *pipe,
     60static int usb_endpoint_pipe_read_no_checks(usb_endpoint_pipe_t *pipe,
    6161    void *buffer, size_t size, size_t *size_transfered)
    6262{
     
    140140 * @return Error code.
    141141 */
    142 int usb_pipe_read(usb_pipe_t *pipe,
     142int usb_endpoint_pipe_read(usb_endpoint_pipe_t *pipe,
    143143    void *buffer, size_t size, size_t *size_transfered)
    144144{
     
    153153        }
    154154
    155         if (!usb_pipe_is_session_started(pipe)) {
     155        if (!usb_endpoint_pipe_is_session_started(pipe)) {
    156156                return EBADF;
    157157        }
     
    168168        int rc;
    169169
    170         rc = usb_pipe_read_no_checks(pipe, buffer, size, &act_size);
     170        rc = usb_endpoint_pipe_read_no_checks(pipe, buffer, size, &act_size);
    171171        if (rc != EOK) {
    172172                return rc;
     
    190190 * @return Error code.
    191191 */
    192 static int usb_pipe_write_no_check(usb_pipe_t *pipe,
     192static int usb_endpoint_pipe_write_no_check(usb_endpoint_pipe_t *pipe,
    193193    void *buffer, size_t size)
    194194{
     
    247247 * @return Error code.
    248248 */
    249 int usb_pipe_write(usb_pipe_t *pipe,
     249int usb_endpoint_pipe_write(usb_endpoint_pipe_t *pipe,
    250250    void *buffer, size_t size)
    251251{
     
    260260        }
    261261
    262         if (!usb_pipe_is_session_started(pipe)) {
     262        if (!usb_endpoint_pipe_is_session_started(pipe)) {
    263263                return EBADF;
    264264        }
     
    272272        }
    273273
    274         int rc = usb_pipe_write_no_check(pipe, buffer, size);
     274        int rc = usb_endpoint_pipe_write_no_check(pipe, buffer, size);
    275275
    276276        return rc;
     
    289289 * @return Error code.
    290290 */
    291 static int usb_pipe_control_read_no_check(usb_pipe_t *pipe,
     291static int usb_endpoint_pipe_control_read_no_check(usb_endpoint_pipe_t *pipe,
    292292    void *setup_buffer, size_t setup_buffer_size,
    293293    void *data_buffer, size_t data_buffer_size, size_t *data_transfered_size)
     
    365365 * @return Error code.
    366366 */
    367 int usb_pipe_control_read(usb_pipe_t *pipe,
     367int usb_endpoint_pipe_control_read(usb_endpoint_pipe_t *pipe,
    368368    void *setup_buffer, size_t setup_buffer_size,
    369369    void *data_buffer, size_t data_buffer_size, size_t *data_transfered_size)
     
    379379        }
    380380
    381         if (!usb_pipe_is_session_started(pipe)) {
     381        if (!usb_endpoint_pipe_is_session_started(pipe)) {
    382382                return EBADF;
    383383        }
     
    389389
    390390        size_t act_size = 0;
    391         int rc = usb_pipe_control_read_no_check(pipe,
     391        int rc = usb_endpoint_pipe_control_read_no_check(pipe,
    392392            setup_buffer, setup_buffer_size,
    393393            data_buffer, data_buffer_size, &act_size);
     
    414414 * @return Error code.
    415415 */
    416 static int usb_pipe_control_write_no_check(usb_pipe_t *pipe,
     416static int usb_endpoint_pipe_control_write_no_check(usb_endpoint_pipe_t *pipe,
    417417    void *setup_buffer, size_t setup_buffer_size,
    418418    void *data_buffer, size_t data_buffer_size)
     
    473473 * @return Error code.
    474474 */
    475 int usb_pipe_control_write(usb_pipe_t *pipe,
     475int usb_endpoint_pipe_control_write(usb_endpoint_pipe_t *pipe,
    476476    void *setup_buffer, size_t setup_buffer_size,
    477477    void *data_buffer, size_t data_buffer_size)
     
    491491        }
    492492
    493         if (!usb_pipe_is_session_started(pipe)) {
     493        if (!usb_endpoint_pipe_is_session_started(pipe)) {
    494494                return EBADF;
    495495        }
     
    500500        }
    501501
    502         int rc = usb_pipe_control_write_no_check(pipe,
     502        int rc = usb_endpoint_pipe_control_write_no_check(pipe,
    503503            setup_buffer, setup_buffer_size, data_buffer, data_buffer_size);
    504504
  • uspace/lib/usb/src/recognise.c

    r41ef5b9 rfd9f6e4c  
    247247#undef VENDOR_ONLY_FMT
    248248#undef VENDOR_ONLY_ARGS
    249 
    250         /* As a last resort, try fallback driver. */
    251         ADD_MATCHID_OR_RETURN(matches, 10, "usb&interface&fallback");
    252249
    253250        return EOK;
     
    294291        }
    295292       
    296         /* As a last resort, try fallback driver. */
    297         ADD_MATCHID_OR_RETURN(matches, 10, "usb&fallback");
    298 
    299293        return EOK;
    300294}
     
    311305 * @return Error code.
    312306 */
    313 int usb_device_create_match_ids(usb_pipe_t *ctrl_pipe,
     307int usb_device_create_match_ids(usb_endpoint_pipe_t *ctrl_pipe,
    314308    match_id_list_t *matches)
    315309{
     
    363357        int rc;
    364358        usb_device_connection_t dev_connection;
    365         usb_pipe_t ctrl_pipe;
     359        usb_endpoint_pipe_t ctrl_pipe;
    366360
    367361        rc = usb_device_connection_initialize(&dev_connection, hc_handle, address);
     
    370364        }
    371365
    372         rc = usb_pipe_initialize_default_control(&ctrl_pipe,
     366        rc = usb_endpoint_pipe_initialize_default_control(&ctrl_pipe,
    373367            &dev_connection);
    374368        if (rc != EOK) {
    375369                goto failure;
    376370        }
    377         rc = usb_pipe_probe_default_control(&ctrl_pipe);
     371        rc = usb_endpoint_pipe_probe_default_control(&ctrl_pipe);
    378372        if (rc != EOK) {
    379373                goto failure;
     
    404398        child->driver_data = dev_data;
    405399
    406         rc = usb_pipe_start_session(&ctrl_pipe);
     400        rc = usb_endpoint_pipe_start_session(&ctrl_pipe);
    407401        if (rc != EOK) {
    408402                goto failure;
     
    414408        }
    415409
    416         rc = usb_pipe_end_session(&ctrl_pipe);
     410        rc = usb_endpoint_pipe_end_session(&ctrl_pipe);
    417411        if (rc != EOK) {
    418412                goto failure;
  • uspace/lib/usb/src/request.c

    r41ef5b9 rfd9f6e4c  
    4242/** Generic wrapper for SET requests using standard control request format.
    4343 *
    44  * @see usb_pipe_control_write
     44 * @see usb_endpoint_pipe_control_write
    4545 *
    4646 * @param pipe Pipe used for the communication.
     
    6060 * @retval ERANGE Data buffer too large.
    6161 */
    62 int usb_control_request_set(usb_pipe_t *pipe,
     62int usb_control_request_set(usb_endpoint_pipe_t *pipe,
    6363    usb_request_type_t request_type, usb_request_recipient_t recipient,
    6464    uint8_t request,
     
    9090        setup_packet.length = (uint16_t) data_size;
    9191
    92         int rc = usb_pipe_control_write(pipe,
     92        int rc = usb_endpoint_pipe_control_write(pipe,
    9393            &setup_packet, sizeof(setup_packet),
    9494            data, data_size);
     
    9999 /** Generic wrapper for GET requests using standard control request format.
    100100  *
    101   * @see usb_pipe_control_read
     101  * @see usb_endpoint_pipe_control_read
    102102  *
    103103  * @param pipe Pipe used for the communication.
     
    120120  * @retval ERANGE Data buffer too large.
    121121  */
    122 int usb_control_request_get(usb_pipe_t *pipe,
     122int usb_control_request_get(usb_endpoint_pipe_t *pipe,
    123123    usb_request_type_t request_type, usb_request_recipient_t recipient,
    124124    uint8_t request,
     
    150150        setup_packet.length = (uint16_t) data_size;
    151151
    152         int rc = usb_pipe_control_read(pipe,
     152        int rc = usb_endpoint_pipe_control_read(pipe,
    153153            &setup_packet, sizeof(setup_packet),
    154154            data, data_size, actual_data_size);
    155 
    156         return rc;
    157 }
    158 
    159 /** Retrieve status of a USB device.
    160  *
    161  * @param[in] pipe Control endpoint pipe (session must be already started).
    162  * @param[in] index Recipient index (in native endianness).
    163  * @param[in] recipient Recipient of the GET_STATUS request.
    164  * @param[out] status Recipient status (in native endianness).
    165  * @return Error code.
    166  */
    167 int usb_request_get_status(usb_pipe_t *pipe,
    168     usb_request_recipient_t recipient, uint16_t index,
    169     uint16_t *status)
    170 {
    171         if ((recipient == USB_REQUEST_RECIPIENT_DEVICE) && (index != 0)) {
    172                 return EINVAL;
    173         }
    174 
    175         if (status == NULL) {
    176                 return EBADMEM;
    177         }
    178 
    179         uint16_t status_usb_endianess;
    180         size_t data_transfered_size;
    181         int rc = usb_control_request_get(pipe, USB_REQUEST_TYPE_STANDARD,
    182             recipient, USB_DEVREQ_GET_STATUS, 0, uint16_host2usb(index),
    183             &status_usb_endianess, 2, &data_transfered_size);
    184         if (rc != EOK) {
    185                 return rc;
    186         }
    187         if (data_transfered_size != 2) {
    188                 return ELIMIT;
    189         }
    190 
    191         *status = uint16_usb2host(status_usb_endianess);
    192 
    193         return EOK;
    194 }
    195 
    196 /** Clear or disable specific device feature.
    197  *
    198  * @param[in] pipe Control endpoint pipe (session must be already started).
    199  * @param[in] request_type Request type (standard/class/vendor).
    200  * @param[in] recipient Recipient of the CLEAR_FEATURE request.
    201  * @param[in] feature_selector Feature selector (in native endianness).
    202  * @param[in] index Recipient index (in native endianness).
    203  * @return Error code.
    204  */
    205 int usb_request_clear_feature(usb_pipe_t *pipe,
    206     usb_request_type_t request_type, usb_request_recipient_t recipient,
    207     uint16_t feature_selector, uint16_t index)
    208 {
    209         if (request_type == USB_REQUEST_TYPE_STANDARD) {
    210                 if ((recipient == USB_REQUEST_RECIPIENT_DEVICE)
    211                     && (index != 0)) {
    212                         return EINVAL;
    213                 }
    214         }
    215 
    216         int rc = usb_control_request_set(pipe, request_type, recipient,
    217             USB_DEVREQ_CLEAR_FEATURE,
    218             uint16_host2usb(feature_selector), uint16_host2usb(index),
    219             NULL, 0);
    220 
    221         return rc;
    222 }
    223 
    224 /** Set or enable specific device feature.
    225  *
    226  * @param[in] pipe Control endpoint pipe (session must be already started).
    227  * @param[in] request_type Request type (standard/class/vendor).
    228  * @param[in] recipient Recipient of the SET_FEATURE request.
    229  * @param[in] feature_selector Feature selector (in native endianness).
    230  * @param[in] index Recipient index (in native endianness).
    231  * @return Error code.
    232  */
    233 int usb_request_set_feature(usb_pipe_t *pipe,
    234     usb_request_type_t request_type, usb_request_recipient_t recipient,
    235     uint16_t feature_selector, uint16_t index)
    236 {
    237         if (request_type == USB_REQUEST_TYPE_STANDARD) {
    238                 if ((recipient == USB_REQUEST_RECIPIENT_DEVICE)
    239                     && (index != 0)) {
    240                         return EINVAL;
    241                 }
    242         }
    243 
    244         int rc = usb_control_request_set(pipe, request_type, recipient,
    245             USB_DEVREQ_SET_FEATURE,
    246             uint16_host2usb(feature_selector), uint16_host2usb(index),
    247             NULL, 0);
    248155
    249156        return rc;
     
    258165 * @return Error code.
    259166 */
    260 int usb_request_set_address(usb_pipe_t *pipe,
     167int usb_request_set_address(usb_endpoint_pipe_t *pipe,
    261168    usb_address_t new_address)
    262169{
     
    297204 * @return Error code.
    298205 */
    299 int usb_request_get_descriptor(usb_pipe_t *pipe,
     206int usb_request_get_descriptor(usb_endpoint_pipe_t *pipe,
    300207    usb_request_type_t request_type, usb_request_recipient_t recipient,
    301208    uint8_t descriptor_type, uint8_t descriptor_index,
     
    331238 * @return
    332239 */
    333 int usb_request_get_descriptor_alloc(usb_pipe_t * pipe,
     240int usb_request_get_descriptor_alloc(usb_endpoint_pipe_t * pipe,
    334241    usb_request_type_t request_type, usb_request_recipient_t recipient,
    335242    uint8_t descriptor_type, uint8_t descriptor_index,
     
    400307 * @return Error code.
    401308 */
    402 int usb_request_get_device_descriptor(usb_pipe_t *pipe,
     309int usb_request_get_device_descriptor(usb_endpoint_pipe_t *pipe,
    403310    usb_standard_device_descriptor_t *descriptor)
    404311{
     
    442349 * @return Error code.
    443350 */
    444 int usb_request_get_bare_configuration_descriptor(usb_pipe_t *pipe,
     351int usb_request_get_bare_configuration_descriptor(usb_endpoint_pipe_t *pipe,
    445352    int index, usb_standard_configuration_descriptor_t *descriptor)
    446353{
     
    488395 * @return Error code.
    489396 */
    490 int usb_request_get_full_configuration_descriptor(usb_pipe_t *pipe,
     397int usb_request_get_full_configuration_descriptor(usb_endpoint_pipe_t *pipe,
    491398    int index, void *descriptor, size_t descriptor_size, size_t *actual_size)
    492399{
     
    514421 */
    515422int usb_request_get_full_configuration_descriptor_alloc(
    516     usb_pipe_t *pipe, int index,
     423    usb_endpoint_pipe_t *pipe, int index,
    517424    void **descriptor_ptr, size_t *descriptor_size)
    518425{
     
    566473}
    567474
    568 /** Update existing or add new USB descriptor to a USB device.
    569  *
    570  * @param[in] pipe Control endpoint pipe (session must be already started).
    571  * @param[in] request_type Request type (standard/class/vendor).
    572  * @param[in] recipient Request recipient (device/interface/endpoint).
    573  * @param[in] descriptor_type Descriptor type (device/configuration/HID/...).
    574  * @param[in] descriptor_index Descriptor index.
    575  * @param[in] language Language index (in native endianness).
    576  * @param[in] buffer Buffer with the new descriptor (in USB endianness).
    577  * @param[in] size Size of the @p buffer in bytes (in native endianness).
    578  * @return Error code.
    579  */
    580 int usb_request_set_descriptor(usb_pipe_t *pipe,
    581     usb_request_type_t request_type, usb_request_recipient_t recipient,
    582     uint8_t descriptor_type, uint8_t descriptor_index,
    583     uint16_t language,
    584     void *buffer, size_t size)
    585 {
    586         if (buffer == NULL) {
    587                 return EBADMEM;
    588         }
    589         if (size == 0) {
    590                 return EINVAL;
    591         }
    592 
    593         /* FIXME: proper endianness. */
    594         uint16_t wValue = descriptor_index | (descriptor_type << 8);
    595 
    596         return usb_control_request_set(pipe,
    597             request_type, recipient,
    598             USB_DEVREQ_SET_DESCRIPTOR,
    599             wValue, language,
    600             buffer, size);
    601 }
    602 
    603 /** Get current configuration value of USB device.
    604  *
    605  * @param[in] pipe Control endpoint pipe (session must be already started).
    606  * @param[out] configuration_value Current configuration value.
    607  * @return Error code.
    608  */
    609 int usb_request_get_configuration(usb_pipe_t *pipe,
    610     uint8_t *configuration_value)
    611 {
    612         uint8_t value;
    613         size_t actual_size;
    614 
    615         int rc = usb_control_request_get(pipe,
    616             USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE,
    617             USB_DEVREQ_GET_CONFIGURATION,
    618             0, 0,
    619             &value, 1, &actual_size);
    620 
    621         if (rc != EOK) {
    622                 return rc;
    623         }
    624         if (actual_size != 1) {
    625                 return ELIMIT;
    626         }
    627 
    628         if (configuration_value != NULL) {
    629                 *configuration_value = value;
    630         }
    631 
    632         return EOK;
    633 }
    634 
    635475/** Set configuration of USB device.
    636476 *
     
    639479 * @return Error code.
    640480 */
    641 int usb_request_set_configuration(usb_pipe_t *pipe,
     481int usb_request_set_configuration(usb_endpoint_pipe_t *pipe,
    642482    uint8_t configuration_value)
    643483{
     
    651491}
    652492
    653 /** Get selected alternate setting for USB interface.
    654  *
    655  * @param[in] pipe Control endpoint pipe (session must be already started).
    656  * @param[in] interface_index Interface index.
    657  * @param[out] alternate_setting Alternate setting for the interface.
    658  * @return Error code.
    659  */
    660 int usb_request_get_interface(usb_pipe_t *pipe,
    661     uint8_t interface_index, uint8_t *alternate_setting)
    662 {
    663         uint8_t value;
    664         size_t actual_size;
    665 
    666         int rc = usb_control_request_get(pipe,
    667             USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_INTERFACE,
    668             USB_DEVREQ_GET_INTERFACE,
    669             0, uint16_host2usb((uint16_t) interface_index),
    670             &value, 1, &actual_size);
    671 
    672         if (rc != EOK) {
    673                 return rc;
    674         }
    675         if (actual_size != 1) {
    676                 return ELIMIT;
    677         }
    678 
    679         if (alternate_setting != NULL) {
    680                 *alternate_setting = value;
    681         }
    682 
    683         return EOK;
    684 }
    685 
    686 /** Select alternate setting for USB interface.
    687  *
    688  * @param[in] pipe Control endpoint pipe (session must be already started).
    689  * @param[in] interface_index Interface index.
    690  * @param[in] alternate_setting Alternate setting to select.
    691  * @return Error code.
    692  */
    693 int usb_request_set_interface(usb_pipe_t *pipe,
    694     uint8_t interface_index, uint8_t alternate_setting)
    695 {
    696         return usb_control_request_set(pipe,
    697             USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_INTERFACE,
    698             USB_DEVREQ_SET_INTERFACE,
    699             uint16_host2usb((uint16_t) alternate_setting),
    700             uint16_host2usb((uint16_t) interface_index),
    701             NULL, 0);
    702 }
    703 
    704493/** Get list of supported languages by USB device.
    705494 *
     
    710499 * @return Error code.
    711500 */
    712 int usb_request_get_supported_languages(usb_pipe_t *pipe,
     501int usb_request_get_supported_languages(usb_endpoint_pipe_t *pipe,
    713502    l18_win_locales_t **languages_ptr, size_t *languages_count)
    714503{
     
    782571 * @return Error code.
    783572 */
    784 int usb_request_get_string(usb_pipe_t *pipe,
     573int usb_request_get_string(usb_endpoint_pipe_t *pipe,
    785574    size_t index, l18_win_locales_t lang, char **string_ptr)
    786575{
  • uspace/lib/usb/src/usb.c

    r41ef5b9 rfd9f6e4c  
    3636#include <errno.h>
    3737
    38 #define ARR_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
    39 
    40 static const char *str_speed[] = {
    41         "low",
    42         "full",
    43         "high"
    44 };
    45 
    46 static const char *str_transfer_type[] = {
    47         "control",
    48         "isochronous",
    49         "bulk",
    50         "interrupt"
    51 };
    52 
    53 static const char *str_transfer_type_short[] = {
    54         "ctrl",
    55         "iso",
    56         "bulk",
    57         "intr"
    58 };
    5938
    6039/** String representation for USB transfer type.
     
    6342 * @return Transfer type as a string (in English).
    6443 */
    65 const char *usb_str_transfer_type(usb_transfer_type_t t)
     44const char * usb_str_transfer_type(usb_transfer_type_t t)
    6645{
    67         if (t >= ARR_SIZE(str_transfer_type)) {
    68                 return "invalid";
     46        switch (t) {
     47                case USB_TRANSFER_ISOCHRONOUS:
     48                        return "isochronous";
     49                case USB_TRANSFER_INTERRUPT:
     50                        return "interrupt";
     51                case USB_TRANSFER_CONTROL:
     52                        return "control";
     53                case USB_TRANSFER_BULK:
     54                        return "bulk";
     55                default:
     56                        return "unknown";
    6957        }
    70         return str_transfer_type[t];
    71 }
    72 
    73 /** String representation for USB transfer type (short version).
    74  *
    75  * @param t Transfer type.
    76  * @return Transfer type as a short string for debugging messages.
    77  */
    78 const char *usb_str_transfer_type_short(usb_transfer_type_t t)
    79 {
    80         if (t >= ARR_SIZE(str_transfer_type_short)) {
    81                 return "invl";
    82         }
    83         return str_transfer_type_short[t];
    84 }
    85 
    86 /** String representation of USB speed.
    87  *
    88  * @param s The speed.
    89  * @return USB speed as a string (in English).
    90  */
    91 const char *usb_str_speed(usb_speed_t s)
    92 {
    93         if (s >= ARR_SIZE(str_speed)) {
    94                 return "invalid";
    95         }
    96         return str_speed[s];
    9758}
    9859
Note: See TracChangeset for help on using the changeset viewer.