Changeset d15809b4 in mainline


Ignore:
Timestamp:
2011-02-14T10:14:31Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
962ce100
Parents:
0d36c20 (diff), 45c01a1 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge development/ changes

Location:
uspace
Files:
3 added
1 deleted
23 edited
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/app/usbinfo/info.c

    r0d36c20 rd15809b4  
    3939#include <usb/usbdrv.h>
    4040#include <usb/pipes.h>
     41#include <usb/recognise.h>
    4142#include <usb/request.h>
    4243#include "usbinfo.h"
     
    4748        usb_device_connection_t wire;
    4849        usb_endpoint_pipe_t ctrl_pipe;
    49         ctrl_pipe.hc_phone = -1;
    50 
    51         int hc_phone = devman_device_connect(hc_handle, 0);
    52         if (hc_phone < 0) {
    53                 fprintf(stderr,
    54                     NAME ": failed to connect to host controller (%zu): %s.\n",
    55                         (size_t) hc_handle, str_error(hc_phone));
    56                 return hc_phone;
    57         }
    58 
    59         /*
    60          * Dump information about possible match ids.
    61          */
    62         match_id_list_t match_id_list;
    63         init_match_ids(&match_id_list);
    64         rc = usb_drv_create_device_match_ids(hc_phone, &match_id_list, address);
    65         if (rc != EOK) {
    66                 fprintf(stderr,
    67                     NAME ": failed to fetch match ids of the device: %s.\n",
    68                     str_error(rc));
    69                 goto leave;
    70         }
    71         dump_match_ids(&match_id_list);
    7250
    7351        /*
     
    9573                goto leave;
    9674        }
     75
     76        /*
     77         * Dump information about possible match ids.
     78         */
     79        match_id_list_t match_id_list;
     80        init_match_ids(&match_id_list);
     81        rc = usb_device_create_match_ids(&ctrl_pipe, &match_id_list);
     82        if (rc != EOK) {
     83                fprintf(stderr,
     84                    NAME ": failed to fetch match ids of the device: %s.\n",
     85                    str_error(rc));
     86                goto leave;
     87        }
     88        dump_match_ids(&match_id_list);
    9789
    9890        /*
     
    141133leave:
    142134        /* Ignoring errors here. */
    143         async_hangup(hc_phone);
    144135        usb_endpoint_pipe_end_session(&ctrl_pipe);
    145136
  • uspace/app/usbinfo/main.c

    r0d36c20 rd15809b4  
    8181{
    8282        int rc;
     83
     84        if (str_cmp(path, "uhci") == 0) {
     85                path = "/hw/pci0/00:01.2";
     86        }
    8387
    8488        devman_handle_t handle;
  • uspace/drv/uhci-hcd/Makefile

    r0d36c20 rd15809b4  
    4040        uhci_struct/transfer_descriptor.c \
    4141        pci.c \
    42         tracker.c
     42        batch.c
    4343
    4444include $(USPACE_PREFIX)/Makefile.common
  • uspace/drv/uhci-hcd/batch.h

    r0d36c20 rd15809b4  
    3232 * @brief UHCI driver
    3333 */
    34 #ifndef DRV_UHCI_TRACKER_H
    35 #define DRV_UHCI_TRACKER_H
     34#ifndef DRV_UHCI_BATCH_H
     35#define DRV_UHCI_BATCH_H
    3636
    3737#include <adt/list.h>
     
    4141
    4242#include "uhci_struct/transfer_descriptor.h"
     43#include "uhci_struct/queue_head.h"
    4344
    4445typedef enum {
     
    4748} dev_speed_t;
    4849
    49 typedef struct tracker
     50typedef struct batch
    5051{
    5152        link_t link;
     53        dev_speed_t speed;
    5254        usb_target_t target;
    5355        usb_transfer_type_t transfer_type;
     
    5759        };
    5860        void *arg;
     61        char *transport_buffer;
     62        char *setup_buffer;
     63        size_t setup_size;
    5964        char *buffer;
    60         char *packet;
    6165        size_t buffer_size;
    6266        size_t max_packet_size;
    63         size_t packet_size;
    64         size_t buffer_offset;
    65         dev_speed_t speed;
     67        size_t packets;
     68        size_t transfered_size;
     69        int error;
    6670        device_t *dev;
    67         transfer_descriptor_t *td;
    68         void (*next_step)(struct tracker*);
    69         unsigned toggle:1;
    70 } tracker_t;
     71        queue_head_t *qh;
     72        transfer_descriptor_t *tds;
     73        void (*next_step)(struct batch*);
     74} batch_t;
    7175
    72 
    73 tracker_t * tracker_get(device_t *dev, usb_target_t target,
     76batch_t * batch_get(device_t *dev, usb_target_t target,
    7477    usb_transfer_type_t transfer_type, size_t max_packet_size,
    7578    dev_speed_t speed, char *buffer, size_t size,
     79                char *setup_buffer, size_t setup_size,
    7680    usbhc_iface_transfer_in_callback_t func_in,
    7781    usbhc_iface_transfer_out_callback_t func_out, void *arg);
    7882
    79 void tracker_control_write(
    80     tracker_t *instance, char* setup_buffer, size_t setup_size);
     83bool batch_is_complete(batch_t *instance);
    8184
    82 void tracker_control_read(
    83     tracker_t *instance, char* setup_buffer, size_t setup_size);
     85void batch_control_write(batch_t *instance);
    8486
    85 void tracker_interrupt_in(tracker_t *instance);
     87void batch_control_read(batch_t *instance);
    8688
    87 void tracker_interrupt_out(tracker_t *instance);
     89void batch_interrupt_in(batch_t *instance);
     90
     91void batch_interrupt_out(batch_t *instance);
    8892
    8993/* DEPRECATED FUNCTIONS NEEDED BY THE OLD API */
    90 void tracker_control_setup_old(tracker_t *instance);
     94void batch_control_setup_old(batch_t *instance);
    9195
    92 void tracker_control_write_data_old(tracker_t *instance);
     96void batch_control_write_data_old(batch_t *instance);
    9397
    94 void tracker_control_read_data_old(tracker_t *instance);
     98void batch_control_read_data_old(batch_t *instance);
    9599
    96 void tracker_control_write_status_old(tracker_t *instance);
     100void batch_control_write_status_old(batch_t *instance);
    97101
    98 void tracker_control_read_status_old(tracker_t *instance);
     102void batch_control_read_status_old(batch_t *instance);
    99103#endif
    100104/**
  • uspace/drv/uhci-hcd/iface.c

    r0d36c20 rd15809b4  
    109109        dev_speed_t speed = FULL_SPEED;
    110110
    111         tracker_t *tracker = tracker_get(dev, target, USB_TRANSFER_INTERRUPT,
    112             max_packet_size, speed, data, size, NULL, callback, arg);
    113         if (!tracker)
    114                 return ENOMEM;
    115         tracker_interrupt_out(tracker);
     111        batch_t *batch = batch_get(dev, target, USB_TRANSFER_INTERRUPT,
     112            max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg);
     113        if (!batch)
     114                return ENOMEM;
     115        batch_interrupt_out(batch);
    116116        return EOK;
    117117}
     
    124124        dev_speed_t speed = FULL_SPEED;
    125125
    126         tracker_t *tracker = tracker_get(dev, target, USB_TRANSFER_INTERRUPT,
    127             max_packet_size, speed, data, size, callback, NULL, arg);
    128         if (!tracker)
    129                 return ENOMEM;
    130         tracker_interrupt_in(tracker);
     126        batch_t *batch = batch_get(dev, target, USB_TRANSFER_INTERRUPT,
     127            max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg);
     128        if (!batch)
     129                return ENOMEM;
     130        batch_interrupt_in(batch);
    131131        return EOK;
    132132}
     
    139139        dev_speed_t speed = FULL_SPEED;
    140140
    141         tracker_t *tracker = tracker_get(dev, target, USB_TRANSFER_CONTROL,
    142             max_packet_size, speed, data, size, NULL, callback, arg);
    143         if (!tracker)
    144                 return ENOMEM;
    145         tracker_control_write(tracker, setup_data, setup_size);
     141        batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,
     142            max_packet_size, speed, data, size, setup_data, setup_size,
     143            NULL, callback, arg);
     144        if (!batch)
     145                return ENOMEM;
     146        batch_control_write(batch);
    146147        return EOK;
    147148}
     
    154155        dev_speed_t speed = FULL_SPEED;
    155156
    156         tracker_t *tracker = tracker_get(dev, target, USB_TRANSFER_CONTROL,
    157             max_packet_size, speed, data, size, callback, NULL, arg);
    158         if (!tracker)
    159                 return ENOMEM;
    160         tracker_control_read(tracker, setup_data, setup_size);
     157        batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,
     158            max_packet_size, speed, data, size, setup_data, setup_size, callback,
     159            NULL, arg);
     160        if (!batch)
     161                return ENOMEM;
     162        batch_control_read(batch);
    161163        return EOK;
    162164}
     
    166168    usbhc_iface_transfer_out_callback_t callback, void *arg)
    167169{
    168         usb_log_warning("Using deprecated API control write setup.\n");
    169         tracker_t *tracker = tracker_get(dev, target, USB_TRANSFER_CONTROL,
    170             8, FULL_SPEED, data, size, NULL, callback, arg);
    171         if (!tracker)
    172                 return ENOMEM;
    173         tracker_control_setup_old(tracker);
     170        size_t max_packet_size = 8;
     171        dev_speed_t speed = FULL_SPEED;
     172
     173        usb_log_warning("Using deprecated API %s.\n", __FUNCTION__);
     174        batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,
     175            max_packet_size, speed, NULL, 0, data, size, NULL, callback, arg);
     176        if (!batch)
     177                return ENOMEM;
     178        batch_control_setup_old(batch);
    174179        return EOK;
    175180}
     
    179184    usbhc_iface_transfer_out_callback_t callback, void *arg)
    180185{
    181         tracker_t *tracker = tracker_get(dev, target, USB_TRANSFER_CONTROL,
    182             size, FULL_SPEED, data, size, NULL, callback, arg);
    183         if (!tracker)
    184                 return ENOMEM;
    185         tracker_control_write_data_old(tracker);
     186        size_t max_packet_size = 8;
     187        dev_speed_t speed = FULL_SPEED;
     188
     189        usb_log_warning("Using deprecated API %s.\n", __FUNCTION__);
     190        batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,
     191            max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg);
     192        if (!batch)
     193                return ENOMEM;
     194        batch_control_write_data_old(batch);
    186195        return EOK;
    187196}
     
    190199    usbhc_iface_transfer_in_callback_t callback, void *arg)
    191200{
    192         tracker_t *tracker = tracker_get(dev, target, USB_TRANSFER_CONTROL,
    193             0, FULL_SPEED, NULL, 0, callback, NULL, arg);
    194         if (!tracker)
    195                 return ENOMEM;
    196         tracker_control_write_status_old(tracker);
     201        size_t max_packet_size = 8;
     202        dev_speed_t speed = FULL_SPEED;
     203
     204        usb_log_warning("Using deprecated API %s.\n", __FUNCTION__);
     205        batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,
     206            max_packet_size, speed, NULL, 0, NULL, 0, callback, NULL, arg);
     207        if (!batch)
     208                return ENOMEM;
     209        batch_control_write_status_old(batch);
    197210        return EOK;
    198211}
     
    202215    usbhc_iface_transfer_out_callback_t callback, void *arg)
    203216{
    204         usb_log_warning("Using deprecated API control read setup.\n");
    205         tracker_t *tracker = tracker_get(dev, target, USB_TRANSFER_CONTROL,
    206             8, FULL_SPEED, data, size, NULL, callback, arg);
    207         if (!tracker)
    208                 return ENOMEM;
    209         tracker_control_setup_old(tracker);
     217        size_t max_packet_size = 8;
     218        dev_speed_t speed = FULL_SPEED;
     219
     220        usb_log_warning("Using deprecated API %s.\n", __FUNCTION__);
     221        batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,
     222            max_packet_size, speed, NULL, 0, data, size, NULL, callback, arg);
     223        if (!batch)
     224                return ENOMEM;
     225        batch_control_setup_old(batch);
    210226        return EOK;
    211227}
     
    215231    usbhc_iface_transfer_in_callback_t callback, void *arg)
    216232{
    217         tracker_t *tracker = tracker_get(dev, target, USB_TRANSFER_CONTROL,
    218             size, FULL_SPEED, data, size, callback, NULL, arg);
    219         if (!tracker)
    220                 return ENOMEM;
    221         tracker_control_read_data_old(tracker);
     233        size_t max_packet_size = 8;
     234        dev_speed_t speed = FULL_SPEED;
     235
     236        usb_log_warning("Using deprecated API %s.\n", __FUNCTION__);
     237        batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,
     238            max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg);
     239        if (!batch)
     240                return ENOMEM;
     241        batch_control_read_data_old(batch);
    222242        return EOK;
    223243}
     
    226246    usbhc_iface_transfer_out_callback_t callback, void *arg)
    227247{
    228         tracker_t *tracker = tracker_get(dev, target, USB_TRANSFER_CONTROL,
    229             0, FULL_SPEED, NULL, 0, NULL, callback, arg);
    230         if (!tracker)
    231                 return ENOMEM;
    232         tracker_control_read_status_old(tracker);
     248        size_t max_packet_size = 8;
     249        dev_speed_t speed = FULL_SPEED;
     250
     251        usb_log_warning("Using deprecated API %s.\n", __FUNCTION__);
     252        batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,
     253            max_packet_size, speed, NULL, 0, NULL, 0, NULL, callback, arg);
     254        if (!batch)
     255                return ENOMEM;
     256        batch_control_read_status_old(batch);
    233257        return EOK;
    234258}
  • uspace/drv/uhci-hcd/root_hub.c

    r0d36c20 rd15809b4  
    3535#include <errno.h>
    3636#include <stdio.h>
    37 
    3837#include <usb_iface.h>
    39 
    4038#include <usb/debug.h>
    4139
    4240#include "root_hub.h"
     41
     42extern device_ops_t child_ops;
    4343/*----------------------------------------------------------------------------*/
    44 static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle)
    45 {
    46   assert(dev);
    47   assert(dev->parent != NULL);
    48 
    49   device_t *parent = dev->parent;
    50 
    51   if (parent->ops && parent->ops->interfaces[USB_DEV_IFACE]) {
    52     usb_iface_t *usb_iface
    53         = (usb_iface_t *) parent->ops->interfaces[USB_DEV_IFACE];
    54     assert(usb_iface != NULL);
    55     if (usb_iface->get_hc_handle) {
    56       int rc = usb_iface->get_hc_handle(parent, handle);
    57       return rc;
    58     }
    59   }
    60 
    61   return ENOTSUP;
    62 }
    63 /*----------------------------------------------------------------------------*/
    64 static usb_iface_t usb_iface = {
    65   .get_hc_handle = usb_iface_get_hc_handle
    66 };
    67 
    68 static device_ops_t rh_ops = {
    69         .interfaces[USB_DEV_IFACE] = &usb_iface
    70 };
    71 
    7244int setup_root_hub(device_t **device, device_t *hc)
    7345{
     
    10880        hub->name = name;
    10981        hub->parent = hc;
    110         hub->ops = &rh_ops;
     82        hub->ops = &child_ops;
    11183
    11284        *device = hub;
  • uspace/drv/uhci-hcd/transfer_list.c

    r0d36c20 rd15809b4  
    5151
    5252        queue_head_init(instance->queue_head);
     53        list_initialize(&instance->batch_list);
     54        fibril_mutex_initialize(&instance->guard);
    5355        return EOK;
    5456}
     
    5860        assert(instance);
    5961        assert(next);
    60         instance->next = next;
    6162        if (!instance->queue_head)
    6263                return;
    63         queue_head_add_next(instance->queue_head, next->queue_head_pa);
     64        queue_head_append_qh(instance->queue_head, next->queue_head_pa);
     65        instance->queue_head->element = instance->queue_head->next_queue;
    6466}
    6567/*----------------------------------------------------------------------------*/
    66 void transfer_list_add_tracker(transfer_list_t *instance, tracker_t *tracker)
     68void transfer_list_add_batch(transfer_list_t *instance, batch_t *batch)
    6769{
    6870        assert(instance);
    69         assert(tracker);
     71        assert(batch);
    7072
    71         uint32_t pa = (uintptr_t)addr_to_phys(tracker->td);
     73        uint32_t pa = (uintptr_t)addr_to_phys(batch->qh);
    7274        assert((pa & LINK_POINTER_ADDRESS_MASK) == pa);
     75        pa |= LINK_POINTER_QUEUE_HEAD_FLAG;
    7376
     77        batch->qh->next_queue = instance->queue_head->next_queue;
    7478
    75         if (instance->queue_head->element & LINK_POINTER_TERMINATE_FLAG) {
    76                 usb_log_debug2("Adding td(%X:%X) to queue %s first.\n",
    77                         tracker->td->status, tracker->td->device, instance->name);
     79        fibril_mutex_lock(&instance->guard);
     80
     81        if (instance->queue_head->element == instance->queue_head->next_queue) {
    7882                /* there is nothing scheduled */
    79                 instance->last_tracker = tracker;
     83                list_append(&batch->link, &instance->batch_list);
    8084                instance->queue_head->element = pa;
    81                 usb_log_debug2("Added td(%X:%X) to queue %s first.\n",
    82                         tracker->td->status, tracker->td->device, instance->name);
     85                usb_log_debug2("Added batch(%p) to queue %s first.\n",
     86                        batch, instance->name);
     87                fibril_mutex_unlock(&instance->guard);
    8388                return;
    8489        }
    85         usb_log_debug2("Adding td(%X:%X) to queue %s last.%p\n",
    86             tracker->td->status, tracker->td->device, instance->name,
    87             instance->last_tracker);
    88         /* now we can be sure that last_tracker is a valid pointer */
    89         instance->last_tracker->td->next = pa;
    90         instance->last_tracker = tracker;
     90        /* now we can be sure that there is someting scheduled */
     91        assert(!list_empty(&instance->batch_list));
     92        batch_t *first = list_get_instance(
     93                  instance->batch_list.next, batch_t, link);
     94        batch_t *last = list_get_instance(
     95            instance->batch_list.prev, batch_t, link);
     96        queue_head_append_qh(last->qh, pa);
     97        list_append(&batch->link, &instance->batch_list);
     98        usb_log_debug2("Added batch(%p) to queue %s last, first is %p.\n",
     99                batch, instance->name, first );
     100        fibril_mutex_unlock(&instance->guard);
     101}
     102/*----------------------------------------------------------------------------*/
     103static void transfer_list_remove_batch(
     104    transfer_list_t *instance, batch_t *batch)
     105{
     106        assert(instance);
     107        assert(batch);
     108        assert(instance->queue_head);
     109        assert(batch->qh);
    91110
    92         usb_log_debug2("Added td(%X:%X) to queue %s last.\n",
    93                 tracker->td->status, tracker->td->device, instance->name);
     111        /* I'm the first one here */
     112        if (batch->link.prev == &instance->batch_list) {
     113                usb_log_debug("Removing tracer %p was first, next element %x.\n",
     114                        batch, batch->qh->next_queue);
     115                instance->queue_head->element = batch->qh->next_queue;
     116        } else {
     117                usb_log_debug("Removing tracer %p was NOT first, next element %x.\n",
     118                        batch, batch->qh->next_queue);
     119                batch_t *prev = list_get_instance(batch->link.prev, batch_t, link);
     120                prev->qh->next_queue = batch->qh->next_queue;
     121        }
     122        list_remove(&batch->link);
     123}
     124/*----------------------------------------------------------------------------*/
     125void transfer_list_check(transfer_list_t *instance)
     126{
     127        assert(instance);
     128        fibril_mutex_lock(&instance->guard);
     129        link_t *current = instance->batch_list.next;
     130        while (current != &instance->batch_list) {
     131                link_t *next = current->next;
     132                batch_t *batch = list_get_instance(current, batch_t, link);
    94133
    95         /* check again, may be use atomic compare and swap */
    96         if (instance->queue_head->element & LINK_POINTER_TERMINATE_FLAG) {
    97                 instance->queue_head->element = pa;
    98                 usb_log_debug2("Added td(%X:%X) to queue first2 %s.\n",
    99                         tracker->td->status, tracker->td->device, instance->name);
     134                if (batch_is_complete(batch)) {
     135                        transfer_list_remove_batch(instance, batch);
     136                        batch->next_step(batch);
     137                }
     138                current = next;
    100139        }
     140        fibril_mutex_unlock(&instance->guard);
    101141}
    102142/**
  • uspace/drv/uhci-hcd/transfer_list.h

    r0d36c20 rd15809b4  
    3535#define DRV_UHCI_TRANSFER_LIST_H
    3636
     37#include <fibril_synch.h>
     38
    3739#include "uhci_struct/queue_head.h"
    38 #include "tracker.h"
     40
     41#include "batch.h"
    3942
    4043typedef struct transfer_list
    4144{
    42         tracker_t *last_tracker;
    43 
     45        fibril_mutex_t guard;
    4446        queue_head_t *queue_head;
    4547        uint32_t queue_head_pa;
    4648        struct transfer_list *next;
    4749        const char *name;
     50        link_t batch_list;
    4851} transfer_list_t;
    4952
     
    5760        queue_head_dispose(instance->queue_head);
    5861}
     62void transfer_list_check(transfer_list_t *instance);
    5963
    60 
    61 void transfer_list_add_tracker(transfer_list_t *instance, tracker_t *tracker);
    62 
     64void transfer_list_add_batch(transfer_list_t *instance, batch_t *batch);
    6365#endif
    6466/**
  • uspace/drv/uhci-hcd/uhci.c

    r0d36c20 rd15809b4  
    8989        pio_write_32(&instance->registers->flbaseadd, (uint32_t)pa);
    9090
    91         list_initialize(&instance->tracker_list);
    92         fibril_mutex_initialize(&instance->tracker_list_mutex);
     91        list_initialize(&instance->batch_list);
     92        fibril_mutex_initialize(&instance->batch_list_mutex);
    9393
    9494        instance->cleaner = fibril_create(uhci_clean_finished, instance);
     
    152152}
    153153/*----------------------------------------------------------------------------*/
    154 int uhci_schedule(uhci_t *instance, tracker_t *tracker)
    155 {
    156         assert(instance);
    157         assert(tracker);
    158         const int low_speed = (tracker->speed == LOW_SPEED);
     154int uhci_schedule(uhci_t *instance, batch_t *batch)
     155{
     156        assert(instance);
     157        assert(batch);
     158        const int low_speed = (batch->speed == LOW_SPEED);
    159159        if (!allowed_usb_packet(
    160             low_speed, tracker->transfer_type, tracker->packet_size)) {
     160            low_speed, batch->transfer_type, batch->max_packet_size)) {
    161161                usb_log_warning("Invalid USB packet specified %s SPEED %d %zu.\n",
    162                           low_speed ? "LOW" : "FULL" , tracker->transfer_type,
    163                     tracker->packet_size);
     162                          low_speed ? "LOW" : "FULL" , batch->transfer_type,
     163                    batch->max_packet_size);
    164164                return ENOTSUP;
    165165        }
    166166        /* TODO: check available bandwith here */
    167167
    168         usb_log_debug2("Scheduler(%d) acquiring tracker list mutex.\n",
    169             fibril_get_id());
    170         fibril_mutex_lock(&instance->tracker_list_mutex);
    171         usb_log_debug2("Scheduler(%d) acquired tracker list mutex.\n",
    172             fibril_get_id());
    173 
    174168        transfer_list_t *list =
    175             instance->transfers[low_speed][tracker->transfer_type];
     169            instance->transfers[low_speed][batch->transfer_type];
    176170        assert(list);
    177         transfer_list_add_tracker(list, tracker);
    178         list_append(&tracker->link, &instance->tracker_list);
    179 
    180         usb_log_debug2("Scheduler(%d) releasing tracker list mutex.\n",
    181             fibril_get_id());
    182         fibril_mutex_unlock(&instance->tracker_list_mutex);
    183         usb_log_debug2("Scheduler(%d) released tracker list mutex.\n",
    184             fibril_get_id());
     171        transfer_list_add_batch(list, batch);
    185172
    186173        return EOK;
     
    194181
    195182        while(1) {
    196                 LIST_INITIALIZE(done_trackers);
    197                 /* tracker iteration */
    198 
    199                 usb_log_debug2("Cleaner(%d) acquiring tracker list mutex.\n",
    200                     fibril_get_id());
    201                 fibril_mutex_lock(&instance->tracker_list_mutex);
    202                 usb_log_debug2("Cleaner(%d) acquired tracker list mutex.\n",
    203                     fibril_get_id());
    204 
    205                 link_t *current = instance->tracker_list.next;
    206                 while (current != &instance->tracker_list)
    207                 {
    208 
    209                         link_t *next = current->next;
    210                         tracker_t *tracker = list_get_instance(current, tracker_t, link);
    211 
    212                         assert(current == &tracker->link);
    213                         assert(tracker);
    214                         assert(tracker->next_step);
    215                         assert(tracker->td);
    216 
    217                         if (!transfer_descriptor_is_active(tracker->td)) {
    218                                 usb_log_info("Found inactive tracker with status: %x:%x.\n",
    219                                     tracker->td->status, tracker->td->device);
    220                                 list_remove(current);
    221                                 list_append(current, &done_trackers);
    222                         }
    223                         current = next;
    224                 }
    225 
    226                 usb_log_debug2("Cleaner(%d) releasing tracker list mutex.\n",
    227                     fibril_get_id());
    228                 fibril_mutex_unlock(&instance->tracker_list_mutex);
    229                 usb_log_debug2("Cleaner(%d) released tracker list mutex.\n",
    230                     fibril_get_id());
    231 
    232                 while (!list_empty(&done_trackers)) {
    233                         tracker_t *tracker = list_get_instance(
    234                           done_trackers.next, tracker_t, link);
    235                         list_remove(&tracker->link);
    236                         tracker->next_step(tracker);
    237                 }
     183                transfer_list_check(&instance->transfers_interrupt);
     184                transfer_list_check(&instance->transfers_control_slow);
     185                transfer_list_check(&instance->transfers_control_full);
     186                transfer_list_check(&instance->transfers_bulk_full);
    238187                async_usleep(UHCI_CLEANER_TIMEOUT);
    239188        }
  • uspace/drv/uhci-hcd/uhci.h

    r0d36c20 rd15809b4  
    4444
    4545#include "transfer_list.h"
    46 #include "tracker.h"
     46#include "batch.h"
    4747
    4848typedef struct uhci_regs {
     
    8181        link_pointer_t *frame_list;
    8282
    83         link_t tracker_list;
    84         fibril_mutex_t tracker_list_mutex;
     83        link_t batch_list;
     84        fibril_mutex_t batch_list_mutex;
    8585
    8686        transfer_list_t transfers_bulk_full;
     
    113113  void *arg );
    114114
    115 int uhci_schedule(uhci_t *instance, tracker_t *tracker);
     115int uhci_schedule(uhci_t *instance, batch_t *batch);
    116116
    117117static inline uhci_t * dev_to_uhci(device_t *dev)
  • uspace/drv/uhci-hcd/uhci_struct/queue_head.h

    r0d36c20 rd15809b4  
    5555}
    5656
    57 static inline void queue_head_add_next(queue_head_t *instance, uint32_t next_queue_pa)
     57static inline void queue_head_append_qh(queue_head_t *instance, uint32_t pa)
    5858{
    59         if (next_queue_pa) {
    60                 instance->next_queue = (next_queue_pa & LINK_POINTER_ADDRESS_MASK)
    61                   | LINK_POINTER_QUEUE_HEAD_FLAG;
     59        if (pa) {
     60                instance->next_queue = (pa & LINK_POINTER_ADDRESS_MASK)
     61                    | LINK_POINTER_QUEUE_HEAD_FLAG;
    6262        }
    6363}
    6464
    65 static inline queue_head_t * queue_head_get()
    66         { return malloc32(sizeof(queue_head_t)); }
     65static inline void queue_head_element_qh(queue_head_t *instance, uint32_t pa)
     66{
     67        if (pa) {
     68                instance->next_queue = (pa & LINK_POINTER_ADDRESS_MASK)
     69                    | LINK_POINTER_QUEUE_HEAD_FLAG;
     70        }
     71}
     72
     73static inline void queue_head_element_td(queue_head_t *instance, uint32_t pa)
     74{
     75        if (pa) {
     76                instance->element = (pa & LINK_POINTER_ADDRESS_MASK);
     77        }
     78}
     79
     80static inline queue_head_t * queue_head_get() {
     81        queue_head_t *ret = malloc32(sizeof(queue_head_t));
     82        if (ret)
     83                queue_head_init(ret);
     84        return ret;
     85}
    6786
    6887static inline void queue_head_dispose(queue_head_t *head)
  • uspace/drv/uhci-hcd/uhci_struct/transfer_descriptor.c

    r0d36c20 rd15809b4  
    4040void transfer_descriptor_init(transfer_descriptor_t *instance,
    4141    int error_count, size_t size, bool toggle, bool isochronous,
    42     usb_target_t target, int pid, void *buffer)
     42    usb_target_t target, int pid, void *buffer, transfer_descriptor_t *next)
    4343{
    4444        assert(instance);
    4545
    46         instance->next = 0 | LINK_POINTER_TERMINATE_FLAG;
     46        instance->next = 0
     47            | LINK_POINTER_VERTICAL_FLAG
     48            | ((next != NULL) ? addr_to_phys(next) : LINK_POINTER_TERMINATE_FLAG);
    4749
    4850        instance->status = 0
     
    8082#endif
    8183}
    82 
    83 static inline usb_transaction_outcome_t convert_outcome(uint32_t status)
    84 {
    85         /*TODO: refactor into something sane */
    86         /*TODO: add additional usb_errors to usb_outcome_t */
    87 
    88         if (status & TD_STATUS_ERROR_STALLED)
    89                 return USB_OUTCOME_CRCERROR;
    90 
    91         if (status & TD_STATUS_ERROR_BUFFER)
    92                 return USB_OUTCOME_CRCERROR;
    93 
    94         if (status & TD_STATUS_ERROR_BABBLE)
    95                 return USB_OUTCOME_BABBLE;
    96 
    97         if (status & TD_STATUS_ERROR_NAK)
    98                 return USB_OUTCOME_CRCERROR;
    99 
    100   if (status & TD_STATUS_ERROR_CRC)
    101                 return USB_OUTCOME_CRCERROR;
    102 
    103         if (status & TD_STATUS_ERROR_BIT_STUFF)
    104                 return USB_OUTCOME_CRCERROR;
    105 
    106 //      assert((((status >> TD_STATUS_ERROR_POS) & TD_STATUS_ERROR_MASK)
    107 //      | TD_STATUS_ERROR_RESERVED) == TD_STATUS_ERROR_RESERVED);
    108         return USB_OUTCOME_OK;
    109 }
    11084/*----------------------------------------------------------------------------*/
    11185int transfer_descriptor_status(transfer_descriptor_t *instance)
    11286{
    11387        assert(instance);
    114         if (convert_outcome(instance->status))
    115                 return EINVAL; //TODO: use sane error value here
     88
     89        if ((instance->status & TD_STATUS_ERROR_STALLED) != 0)
     90                return EIO;
     91
     92        if ((instance->status & TD_STATUS_ERROR_CRC) != 0)
     93                return EAGAIN;
     94
     95        if ((instance->status & TD_STATUS_ERROR_BUFFER) != 0)
     96                return EAGAIN;
     97
     98        if ((instance->status & TD_STATUS_ERROR_BABBLE) != 0)
     99                return EIO;
     100
     101        if ((instance->status & TD_STATUS_ERROR_NAK) != 0)
     102                return EAGAIN;
     103
     104        if ((instance->status & TD_STATUS_ERROR_BIT_STUFF) != 0)
     105                return EAGAIN;
     106
    116107        return EOK;
    117108}
  • uspace/drv/uhci-hcd/uhci_struct/transfer_descriptor.h

    r0d36c20 rd15809b4  
    9393void transfer_descriptor_init(transfer_descriptor_t *instance,
    9494    int error_count, size_t size, bool toggle, bool isochronous,
    95     usb_target_t target, int pid, void *buffer);
     95    usb_target_t target, int pid, void *buffer, transfer_descriptor_t * next);
    9696
    9797int transfer_descriptor_status(transfer_descriptor_t *instance);
     98
     99static inline size_t transfer_descriptor_actual_size(
     100    transfer_descriptor_t *instance)
     101{
     102        assert(instance);
     103        return
     104            ((instance->status >> TD_STATUS_ACTLEN_POS) + 1) & TD_STATUS_ACTLEN_MASK;
     105}
    98106
    99107static inline bool transfer_descriptor_is_active(
  • uspace/drv/uhci-hcd/utils/malloc32.h

    r0d36c20 rd15809b4  
    4545#define UHCI_REQUIRED_PAGE_SIZE 4096
    4646
    47 static inline void * addr_to_phys(void *addr)
     47static inline uintptr_t addr_to_phys(void *addr)
    4848{
    4949        uintptr_t result;
     
    5151
    5252        assert(ret == 0);
    53         return (void*)(result | ((uintptr_t)addr & 0xfff));
     53        return (result | ((uintptr_t)addr & 0xfff));
    5454}
    5555
  • uspace/drv/uhci-rhd/port.c

    r0d36c20 rd15809b4  
    3333 */
    3434#include <errno.h>
     35#include <str_error.h>
    3536
    3637#include <usb/usb.h>    /* usb_address_t */
    3738#include <usb/usbdrv.h> /* usb_drv_*     */
    3839#include <usb/debug.h>
     40#include <usb/recognise.h>
    3941
    4042#include "port.h"
     
    204206        assert(port->attached_device == 0);
    205207
    206         ret = usb_drv_register_child_in_devman(port->hc_phone, port->rh,
    207           usb_address, &port->attached_device);
    208 
     208        devman_handle_t hc_handle;
     209        ret = usb_drv_find_hc(port->rh, &hc_handle);
     210        if (ret != EOK) {
     211                usb_log_error("Failed to get handle of host controller: %s.\n",
     212                    str_error(ret));
     213                uhci_port_set_enabled(port, false);
     214                return ENOMEM;
     215        }
     216
     217        ret = usb_device_register_child_in_devman(usb_address, hc_handle,
     218            port->rh, &port->attached_device);
    209219        if (ret != EOK) { /* something went wrong */
    210220                usb_log_error("Failed(%d) in usb_drv_register_child.\n", ret);
  • uspace/drv/usbhid/main.c

    r0d36c20 rd15809b4  
    4545#include <str_error.h>
    4646#include <fibril.h>
     47#include <usb/debug.h>
     48#include <usb/classes/classes.h>
    4749#include <usb/classes/hid.h>
    4850#include <usb/classes/hidparser.h>
     
    6163#define GUESSED_POLL_ENDPOINT 1
    6264
     65/** Keyboard polling endpoint description for boot protocol class. */
     66static usb_endpoint_description_t poll_endpoint_description = {
     67        .transfer_type = USB_TRANSFER_INTERRUPT,
     68        .direction = USB_DIRECTION_IN,
     69        .interface_class = USB_CLASS_HID,
     70        .interface_subclass = USB_HID_SUBCLASS_BOOT,
     71        .interface_protocol = USB_HID_PROTOCOL_KEYBOARD,
     72        .flags = 0
     73};
     74
    6375static void default_connection_handler(device_t *, ipc_callid_t, ipc_call_t *);
    6476static device_ops_t keyboard_ops = {
     
    330342        }
    331343       
     344        /*
     345         * Initialize the interrupt in endpoint.
     346         */
     347        usb_endpoint_mapping_t endpoint_mapping[1] = {
     348                {
     349                        .pipe = &kbd_dev->poll_pipe,
     350                        .description = &poll_endpoint_description
     351                }
     352        };
     353        rc = usb_endpoint_pipe_initialize_from_configuration(
     354            endpoint_mapping, 1,
     355            descriptors, config_desc.total_length,
     356            &kbd_dev->wire);
     357        if (rc != EOK) {
     358                usb_log_error("Failed to initialize poll pipe: %s.\n",
     359                    str_error(rc));
     360                return rc;
     361        }
     362        if (!endpoint_mapping[0].present) {
     363                usb_log_warning("Not accepting device, " \
     364                    "not boot-protocol keyboard.\n");
     365                return EREFUSED;
     366        }
     367
     368
     369
     370
    332371        kbd_dev->conf = (usb_hid_configuration_t *)calloc(1,
    333372            sizeof(usb_hid_configuration_t));
     
    337376        }
    338377       
    339         rc = usbkbd_parse_descriptors(descriptors, transferred, kbd_dev->conf);
     378        /*rc = usbkbd_parse_descriptors(descriptors, transferred, kbd_dev->conf);
    340379        free(descriptors);
    341380        if (rc != EOK) {
     
    344383        }
    345384
    346         // get and report descriptors
     385        // get and report descriptors*/
    347386        rc = usbkbd_get_report_descriptor(kbd_dev);
    348387        if (rc != EOK) {
     
    361400     *    as the endpoint for polling
    362401         */
    363        
     402
    364403        return EOK;
    365404}
     
    396435        if (rc != EOK) {
    397436                printf("Failed to initialize default control pipe: %s.\n",
    398                     str_error(rc));
    399                 goto error_leave;
    400         }
    401 
    402         rc = usb_endpoint_pipe_initialize(&kbd_dev->poll_pipe, &kbd_dev->wire,
    403             GUESSED_POLL_ENDPOINT, USB_TRANSFER_INTERRUPT, USB_DIRECTION_IN);
    404         if (rc != EOK) {
    405                 printf("Failed to initialize interrupt in pipe: %s.\n",
    406437                    str_error(rc));
    407438                goto error_leave;
     
    418449        usb_endpoint_pipe_start_session(&kbd_dev->ctrl_pipe);
    419450        //usb_request_set_configuration(&kbd_dev->ctrl_pipe, 1);
    420         usbkbd_process_descriptors(kbd_dev);
     451        rc = usbkbd_process_descriptors(kbd_dev);
    421452        usb_endpoint_pipe_end_session(&kbd_dev->ctrl_pipe);
     453        if (rc != EOK) {
     454                goto error_leave;
     455        }
    422456
    423457        return kbd_dev;
     
    577611int main(int argc, char *argv[])
    578612{
     613        usb_log_enable(USB_LOG_LEVEL_INFO, "usbhid");
    579614        return driver_main(&kbd_driver);
    580615}
  • uspace/drv/usbhub/usbhub.c

    r0d36c20 rd15809b4  
    3636#include <bool.h>
    3737#include <errno.h>
     38#include <str_error.h>
    3839
    3940#include <usb_iface.h>
    4041#include <usb/usbdrv.h>
    4142#include <usb/descriptor.h>
     43#include <usb/recognise.h>
    4244#include <usb/devreq.h>
    4345#include <usb/classes/hub.h>
     
    317319        }
    318320
     321        devman_handle_t hc_handle;
     322        opResult = usb_drv_find_hc(hub->device, &hc_handle);
     323        if (opResult != EOK) {
     324                usb_log_error("Failed to get handle of host controller: %s.\n",
     325                    str_error(opResult));
     326                return;
     327        }
     328
    319329        devman_handle_t child_handle;
    320         opResult = usb_drv_register_child_in_devman(hc, hub->device,
    321             new_device_address, &child_handle);
     330        opResult = usb_device_register_child_in_devman(new_device_address,
     331            hc_handle, hub->device, &child_handle);
    322332        if (opResult != EOK) {
    323333                dprintf(USB_LOG_LEVEL_ERROR, "could not start driver for new device");
  • uspace/drv/vhc/hub.c

    r0d36c20 rd15809b4  
    4141#include <driver.h>
    4242#include <usb/usbdrv.h>
     43#include <usb/recognise.h>
    4344
    4445#include "hub.h"
     
    9394
    9495        devman_handle_t hub_handle;
    95         usb_drv_register_child_in_devman(hc, hc_dev, hub_address, &hub_handle);
     96        usb_device_register_child_in_devman(hub_address, hc_dev->handle,
     97            hc_dev, &hub_handle);
     98        //usb_drv_register_child_in_devman(hc, hc_dev, hub_address, &hub_handle);
    9699        usb_drv_bind_address(hc, hub_address, hub_handle);
    97100
  • uspace/lib/usb/Makefile

    r0d36c20 rd15809b4  
    4444        src/localdrv.c \
    4545        src/pipes.c \
     46        src/pipesinit.c \
    4647        src/recognise.c \
    4748        src/remotedrv.c \
  • uspace/lib/usb/include/usb/classes/hid.h

    r0d36c20 rd15809b4  
    5050        USB_HIDREQ_SET_PROTOCOL = 11
    5151} usb_hid_request_t;
     52
     53/** USB/HID subclass constants. */
     54typedef enum {
     55        USB_HID_SUBCLASS_NONE = 0,
     56        USB_HID_SUBCLASS_BOOT = 1
     57} usb_hid_subclass_t;
    5258
    5359/** USB/HID interface protocols. */
  • uspace/lib/usb/include/usb/pipes.h

    r0d36c20 rd15809b4  
    3838#include <sys/types.h>
    3939#include <usb/usb.h>
     40#include <usb/descriptor.h>
    4041#include <ipc/devman.h>
    4142#include <driver.h>
     
    7374        usb_direction_t direction;
    7475
     76        /** Maximum packet size for the endpoint. */
     77        size_t max_packet_size;
     78
    7579        /** Phone to the host controller.
    7680         * Negative when no session is active.
     
    7983} usb_endpoint_pipe_t;
    8084
     85
     86/** Description of endpoint characteristics. */
     87typedef struct {
     88        /** Transfer type (e.g. control or interrupt). */
     89        usb_transfer_type_t transfer_type;
     90        /** Transfer direction (to or from a device). */
     91        usb_direction_t direction;
     92        /** Interface class this endpoint belongs to (-1 for any). */
     93        int interface_class;
     94        /** Interface subclass this endpoint belongs to (-1 for any). */
     95        int interface_subclass;
     96        /** Interface protocol this endpoint belongs to (-1 for any). */
     97        int interface_protocol;
     98        /** Extra endpoint flags. */
     99        unsigned int flags;
     100} usb_endpoint_description_t;
     101
     102/** Mapping of endpoint pipes and endpoint descriptions. */
     103typedef struct {
     104        /** Endpoint pipe. */
     105        usb_endpoint_pipe_t *pipe;
     106        /** Endpoint description. */
     107        const usb_endpoint_description_t *description;
     108        /** Found descriptor fitting the description. */
     109        usb_standard_endpoint_descriptor_t *descriptor;
     110        /** Interface the endpoint belongs to. */
     111        usb_standard_interface_descriptor_t *interface;
     112        /** Whether the endpoint was actually found. */
     113        bool present;
     114} usb_endpoint_mapping_t;
    81115
    82116int usb_device_connection_initialize_from_device(usb_device_connection_t *,
     
    87121int usb_endpoint_pipe_initialize(usb_endpoint_pipe_t *,
    88122    usb_device_connection_t *,
    89     usb_endpoint_t, usb_transfer_type_t, usb_direction_t);
     123    usb_endpoint_t, usb_transfer_type_t, size_t, usb_direction_t);
    90124int usb_endpoint_pipe_initialize_default_control(usb_endpoint_pipe_t *,
    91125    usb_device_connection_t *);
     126int usb_endpoint_pipe_initialize_from_configuration(usb_endpoint_mapping_t *,
     127    size_t, uint8_t *, size_t, usb_device_connection_t *);
    92128
    93129
  • uspace/lib/usb/include/usb/usbdrv.h

    r0d36c20 rd15809b4  
    106106    const void *, size_t);
    107107
    108 int usb_drv_create_device_match_ids(int, match_id_list_t *, usb_address_t);
    109 int usb_drv_register_child_in_devman(int, device_t *, usb_address_t,
    110     devman_handle_t *);
    111 
    112108
    113109#endif
  • uspace/lib/usb/src/pipes.c

    r0d36c20 rd15809b4  
    123123 * @param endpoint_no Endpoint number (in USB 1.1 in range 0 to 15).
    124124 * @param transfer_type Transfer type (e.g. interrupt or bulk).
     125 * @param max_packet_size Maximum packet size in bytes.
    125126 * @param direction Endpoint direction (in/out).
    126127 * @return Error code.
     
    128129int usb_endpoint_pipe_initialize(usb_endpoint_pipe_t *pipe,
    129130    usb_device_connection_t *connection, usb_endpoint_t endpoint_no,
    130     usb_transfer_type_t transfer_type, usb_direction_t direction)
     131    usb_transfer_type_t transfer_type, size_t max_packet_size,
     132    usb_direction_t direction)
    131133{
    132134        assert(pipe);
     
    137139        pipe->endpoint_no = endpoint_no;
    138140        pipe->transfer_type = transfer_type;
     141        pipe->max_packet_size = max_packet_size;
    139142        pipe->direction = direction;
    140143
     
    156159
    157160        int rc = usb_endpoint_pipe_initialize(pipe, connection,
    158             0, USB_TRANSFER_CONTROL, USB_DIRECTION_BOTH);
     161            0, USB_TRANSFER_CONTROL, 8, USB_DIRECTION_BOTH);
    159162
    160163        return rc;
  • uspace/lib/usb/src/recognise.c

    r0d36c20 rd15809b4  
    3636#include <usb_iface.h>
    3737#include <usb/usbdrv.h>
     38#include <usb/pipes.h>
     39#include <usb/recognise.h>
     40#include <usb/request.h>
    3841#include <usb/classes/classes.h>
    3942#include <stdio.h>
    4043#include <errno.h>
     44
     45static size_t device_name_index = 0;
     46static FIBRIL_MUTEX_INITIALIZE(device_name_index_mutex);
    4147
    4248/** Callback for getting host controller handle.
     
    7076};
    7177
    72 static device_ops_t child_ops = {
     78device_ops_t child_ops = {
    7379        .interfaces[USB_DEV_IFACE] = &usb_iface
    7480};
     
    155161                /* First, with release number. */
    156162                rc = usb_add_match_id(matches, 100,
    157                     "usb&vendor=%d&product=%d&release=" BCD_FMT,
     163                    "usb&vendor=0x%04x&product=0x%04x&release=" BCD_FMT,
    158164                    (int) device_descriptor->vendor_id,
    159165                    (int) device_descriptor->product_id,
     
    164170               
    165171                /* Next, without release number. */
    166                 rc = usb_add_match_id(matches, 90, "usb&vendor=%d&product=%d",
     172                rc = usb_add_match_id(matches, 90,
     173                    "usb&vendor=0x%04x&product=0x%04x",
    167174                    (int) device_descriptor->vendor_id,
    168175                    (int) device_descriptor->product_id);
     
    241248/** Add match ids based on configuration descriptor.
    242249 *
    243  * @param hc Open phone to host controller.
     250 * @param pipe Control pipe to the device.
    244251 * @param matches Match ids list to add matches to.
    245  * @param address USB address of the attached device.
    246252 * @param config_count Number of configurations the device has.
    247253 * @return Error code.
    248254 */
    249 static int usb_add_config_descriptor_match_ids(int hc,
    250     match_id_list_t *matches, usb_address_t address,
    251     int config_count)
     255static int usb_add_config_descriptor_match_ids(usb_endpoint_pipe_t *pipe,
     256    match_id_list_t *matches, int config_count)
    252257{
    253258        int final_rc = EOK;
     
    257262                int rc;
    258263                usb_standard_configuration_descriptor_t config_descriptor;
    259                 rc = usb_drv_req_get_bare_configuration_descriptor(hc,
    260                     address,  config_index, &config_descriptor);
     264                rc = usb_request_get_bare_configuration_descriptor(pipe,
     265                    config_index, &config_descriptor);
    261266                if (rc != EOK) {
    262267                        final_rc = rc;
     
    267272                void *full_config_descriptor
    268273                    = malloc(config_descriptor.total_length);
    269                 rc = usb_drv_req_get_full_configuration_descriptor(hc,
    270                     address, config_index,
     274                rc = usb_request_get_full_configuration_descriptor(pipe,
     275                    config_index,
    271276                    full_config_descriptor, config_descriptor.total_length,
    272277                    &full_config_descriptor_size);
     
    299304 * function exits with error.
    300305 *
    301  * @param hc Open phone to host controller.
     306 * @param ctrl_pipe Control pipe to given device (session must be already
     307 *      started).
    302308 * @param matches Initialized list of match ids.
    303  * @param address USB address of the attached device.
    304  * @return Error code.
    305  */
    306 int usb_drv_create_device_match_ids(int hc, match_id_list_t *matches,
    307     usb_address_t address)
     309 * @return Error code.
     310 */
     311int usb_device_create_match_ids(usb_endpoint_pipe_t *ctrl_pipe,
     312    match_id_list_t *matches)
    308313{
    309314        int rc;
    310        
    311315        /*
    312316         * Retrieve device descriptor and add matches from it.
     
    314318        usb_standard_device_descriptor_t device_descriptor;
    315319
    316         rc = usb_drv_req_get_device_descriptor(hc, address,
    317             &device_descriptor);
     320        rc = usb_request_get_device_descriptor(ctrl_pipe, &device_descriptor);
    318321        if (rc != EOK) {
    319322                return rc;
    320323        }
    321        
     324
    322325        rc = usb_drv_create_match_ids_from_device_descriptor(matches,
    323326            &device_descriptor);
     
    325328                return rc;
    326329        }
    327        
     330
    328331        /*
    329332         * Go through all configurations and add matches
    330333         * based on interface class.
    331334         */
    332         rc = usb_add_config_descriptor_match_ids(hc, matches,
    333             address, device_descriptor.configuration_count);
     335        rc = usb_add_config_descriptor_match_ids(ctrl_pipe, matches,
     336            device_descriptor.configuration_count);
    334337        if (rc != EOK) {
    335338                return rc;
     
    347350}
    348351
    349 
    350352/** Probe for device kind and register it in devman.
    351353 *
    352  * @param[in] hc Open phone to the host controller.
     354 * @param[in] address Address of the (unknown) attached device.
     355 * @param[in] hc_handle Handle of the host controller.
    353356 * @param[in] parent Parent device.
    354  * @param[in] address Address of the (unknown) attached device.
    355357 * @param[out] child_handle Handle of the child device.
    356358 * @return Error code.
    357359 */
    358 int usb_drv_register_child_in_devman(int hc, device_t *parent,
    359     usb_address_t address, devman_handle_t *child_handle)
    360 {
    361         static size_t device_name_index = 0;
    362         static FIBRIL_MUTEX_INITIALIZE(device_name_index_mutex);
    363 
     360int usb_device_register_child_in_devman(usb_address_t address,
     361    devman_handle_t hc_handle,
     362    device_t *parent, devman_handle_t *child_handle)
     363{
    364364        size_t this_device_name_index;
    365365
     
    369369        fibril_mutex_unlock(&device_name_index_mutex);
    370370
    371 
    372371        device_t *child = NULL;
    373372        char *child_name = NULL;
    374373        int rc;
     374        usb_device_connection_t dev_connection;
     375        usb_endpoint_pipe_t ctrl_pipe;
     376
     377        rc = usb_device_connection_initialize(&dev_connection, hc_handle, address);
     378        if (rc != EOK) {
     379                goto failure;
     380        }
     381
     382        rc = usb_endpoint_pipe_initialize_default_control(&ctrl_pipe,
     383            &dev_connection);
     384        if (rc != EOK) {
     385                goto failure;
     386        }
    375387
    376388        child = create_device();
     
    391403        child->name = child_name;
    392404        child->ops = &child_ops;
    393        
    394         rc = usb_drv_create_device_match_ids(hc, &child->match_ids, address);
     405
     406        rc = usb_endpoint_pipe_start_session(&ctrl_pipe);
     407        if (rc != EOK) {
     408                goto failure;
     409        }
     410
     411        rc = usb_device_create_match_ids(&ctrl_pipe, &child->match_ids);
     412        if (rc != EOK) {
     413                goto failure;
     414        }
     415
     416        rc = usb_endpoint_pipe_end_session(&ctrl_pipe);
    395417        if (rc != EOK) {
    396418                goto failure;
     
    405427                *child_handle = child->handle;
    406428        }
    407        
     429
    408430        return EOK;
    409431
     
    419441
    420442        return rc;
    421 
    422443}
    423444
Note: See TracChangeset for help on using the changeset viewer.