Changeset 50ba203 in mainline for uspace/drv


Ignore:
Timestamp:
2011-02-20T15:46:48Z (15 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6bb83c7
Parents:
d81ef61c (diff), 0c00dac (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 with usb/development

Location:
uspace/drv
Files:
1 added
1 deleted
24 edited
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci-hcd/Makefile

    rd81ef61c r50ba203  
    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

    rd81ef61c r50ba203  
    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

    rd81ef61c r50ba203  
    5454}
    5555/*----------------------------------------------------------------------------*/
    56 static int reserve_default_address(device_t *dev)
     56static int reserve_default_address(device_t *dev, bool full_speed)
    5757{
    5858        assert(dev);
     
    7272}
    7373/*----------------------------------------------------------------------------*/
    74 static int request_address(device_t *dev, usb_address_t *address)
     74static int request_address(device_t *dev, bool full_speed,
     75    usb_address_t *address)
    7576{
    7677        assert(dev);
     
    103104/*----------------------------------------------------------------------------*/
    104105static int interrupt_out(device_t *dev, usb_target_t target,
    105     void *data, size_t size,
    106     usbhc_iface_transfer_out_callback_t callback, void *arg)
     106    size_t max_packet_size,
     107    void *data, size_t size,
     108    usbhc_iface_transfer_out_callback_t callback, void *arg)
     109{
     110        dev_speed_t speed = FULL_SPEED;
     111
     112        batch_t *batch = batch_get(dev, target, USB_TRANSFER_INTERRUPT,
     113            max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg);
     114        if (!batch)
     115                return ENOMEM;
     116        batch_interrupt_out(batch);
     117        return EOK;
     118}
     119/*----------------------------------------------------------------------------*/
     120static int interrupt_in(device_t *dev, usb_target_t target,
     121    size_t max_packet_size,
     122    void *data, size_t size,
     123    usbhc_iface_transfer_in_callback_t callback, void *arg)
     124{
     125        dev_speed_t speed = FULL_SPEED;
     126
     127        batch_t *batch = batch_get(dev, target, USB_TRANSFER_INTERRUPT,
     128            max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg);
     129        if (!batch)
     130                return ENOMEM;
     131        batch_interrupt_in(batch);
     132        return EOK;
     133}
     134/*----------------------------------------------------------------------------*/
     135static int control_write(device_t *dev, usb_target_t target,
     136    size_t max_packet_size,
     137    void *setup_data, size_t setup_size, void *data, size_t size,
     138    usbhc_iface_transfer_out_callback_t callback, void *arg)
     139{
     140        dev_speed_t speed = FULL_SPEED;
     141
     142        batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,
     143            max_packet_size, speed, data, size, setup_data, setup_size,
     144            NULL, callback, arg);
     145        if (!batch)
     146                return ENOMEM;
     147        batch_control_write(batch);
     148        return EOK;
     149}
     150/*----------------------------------------------------------------------------*/
     151static int control_read(device_t *dev, usb_target_t target,
     152    size_t max_packet_size,
     153    void *setup_data, size_t setup_size, void *data, size_t size,
     154    usbhc_iface_transfer_in_callback_t callback, void *arg)
     155{
     156        dev_speed_t speed = FULL_SPEED;
     157
     158        batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,
     159            max_packet_size, speed, data, size, setup_data, setup_size, callback,
     160            NULL, arg);
     161        if (!batch)
     162                return ENOMEM;
     163        batch_control_read(batch);
     164        return EOK;
     165}
     166/*----------------------------------------------------------------------------*/
     167static int control_write_setup(device_t *dev, usb_target_t target,
     168    size_t max_packet_size,
     169    void *data, size_t size,
     170    usbhc_iface_transfer_out_callback_t callback, void *arg)
     171{
     172        dev_speed_t speed = FULL_SPEED;
     173
     174        usb_log_warning("Using deprecated API %s.\n", __FUNCTION__);
     175        batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,
     176            max_packet_size, speed, NULL, 0, data, size, NULL, callback, arg);
     177        if (!batch)
     178                return ENOMEM;
     179        batch_control_setup_old(batch);
     180        return EOK;
     181}
     182/*----------------------------------------------------------------------------*/
     183static int control_write_data(device_t *dev, usb_target_t target,
     184    size_t max_packet_size,
     185    void *data, size_t size,
     186    usbhc_iface_transfer_out_callback_t callback, void *arg)
     187{
     188        dev_speed_t speed = FULL_SPEED;
     189
     190        usb_log_warning("Using deprecated API %s.\n", __FUNCTION__);
     191        batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,
     192            max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg);
     193        if (!batch)
     194                return ENOMEM;
     195        batch_control_write_data_old(batch);
     196        return EOK;
     197}
     198/*----------------------------------------------------------------------------*/
     199static int control_write_status(device_t *dev, usb_target_t target,
     200    usbhc_iface_transfer_in_callback_t callback, void *arg)
    107201{
    108202        size_t max_packet_size = 8;
    109203        dev_speed_t speed = FULL_SPEED;
    110204
    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);
    116         return EOK;
    117 }
    118 /*----------------------------------------------------------------------------*/
    119 static int interrupt_in(device_t *dev, usb_target_t target,
    120     void *data, size_t size,
    121     usbhc_iface_transfer_in_callback_t callback, void *arg)
    122 {
    123         size_t max_packet_size = 4;
    124         dev_speed_t speed = FULL_SPEED;
    125 
    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);
    131         return EOK;
    132 }
    133 /*----------------------------------------------------------------------------*/
    134 static int control_write(device_t *dev, usb_target_t target,
    135     void *setup_data, size_t setup_size, void *data, size_t size,
     205        usb_log_warning("Using deprecated API %s.\n", __FUNCTION__);
     206        batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,
     207            max_packet_size, speed, NULL, 0, NULL, 0, callback, NULL, arg);
     208        if (!batch)
     209                return ENOMEM;
     210        batch_control_write_status_old(batch);
     211        return EOK;
     212}
     213/*----------------------------------------------------------------------------*/
     214static int control_read_setup(device_t *dev, usb_target_t target,
     215    size_t max_packet_size,
     216    void *data, size_t size,
     217    usbhc_iface_transfer_out_callback_t callback, void *arg)
     218{
     219        dev_speed_t speed = FULL_SPEED;
     220
     221        usb_log_warning("Using deprecated API %s.\n", __FUNCTION__);
     222        batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,
     223            max_packet_size, speed, NULL, 0, data, size, NULL, callback, arg);
     224        if (!batch)
     225                return ENOMEM;
     226        batch_control_setup_old(batch);
     227        return EOK;
     228}
     229/*----------------------------------------------------------------------------*/
     230static int control_read_data(device_t *dev, usb_target_t target,
     231    size_t max_packet_size,
     232    void *data, size_t size,
     233    usbhc_iface_transfer_in_callback_t callback, void *arg)
     234{
     235        dev_speed_t speed = FULL_SPEED;
     236
     237        usb_log_warning("Using deprecated API %s.\n", __FUNCTION__);
     238        batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,
     239            max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg);
     240        if (!batch)
     241                return ENOMEM;
     242        batch_control_read_data_old(batch);
     243        return EOK;
     244}
     245/*----------------------------------------------------------------------------*/
     246static int control_read_status(device_t *dev, usb_target_t target,
    136247    usbhc_iface_transfer_out_callback_t callback, void *arg)
    137248{
     
    139250        dev_speed_t speed = FULL_SPEED;
    140251
    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);
    146         return EOK;
    147 }
    148 /*----------------------------------------------------------------------------*/
    149 static int control_read(device_t *dev, usb_target_t target,
    150     void *setup_data, size_t setup_size, void *data, size_t size,
    151     usbhc_iface_transfer_in_callback_t callback, void *arg)
    152 {
    153         size_t max_packet_size = 8;
    154         dev_speed_t speed = FULL_SPEED;
    155 
    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);
    161         return EOK;
    162 }
    163 /*----------------------------------------------------------------------------*/
    164 static int control_write_setup(device_t *dev, usb_target_t target,
    165     void *data, size_t size,
    166     usbhc_iface_transfer_out_callback_t callback, void *arg)
    167 {
    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);
    174         return EOK;
    175 }
    176 /*----------------------------------------------------------------------------*/
    177 static int control_write_data(device_t *dev, usb_target_t target,
    178     void *data, size_t size,
    179     usbhc_iface_transfer_out_callback_t callback, void *arg)
    180 {
    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         return EOK;
    187 }
    188 /*----------------------------------------------------------------------------*/
    189 static int control_write_status(device_t *dev, usb_target_t target,
    190     usbhc_iface_transfer_in_callback_t callback, void *arg)
    191 {
    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);
    197         return EOK;
    198 }
    199 /*----------------------------------------------------------------------------*/
    200 static int control_read_setup(device_t *dev, usb_target_t target,
    201     void *data, size_t size,
    202     usbhc_iface_transfer_out_callback_t callback, void *arg)
    203 {
    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);
    210         return EOK;
    211 }
    212 /*----------------------------------------------------------------------------*/
    213 static int control_read_data(device_t *dev, usb_target_t target,
    214     void *data, size_t size,
    215     usbhc_iface_transfer_in_callback_t callback, void *arg)
    216 {
    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);
    222         return EOK;
    223 }
    224 /*----------------------------------------------------------------------------*/
    225 static int control_read_status(device_t *dev, usb_target_t target,
    226     usbhc_iface_transfer_out_callback_t callback, void *arg)
    227 {
    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);
     252        usb_log_warning("Using deprecated API %s.\n", __FUNCTION__);
     253        batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,
     254            max_packet_size, speed, NULL, 0, NULL, 0, NULL, callback, arg);
     255        if (!batch)
     256                return ENOMEM;
     257        batch_control_read_status_old(batch);
    233258        return EOK;
    234259}
  • uspace/drv/uhci-hcd/root_hub.c

    rd81ef61c r50ba203  
    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

    rd81ef61c r50ba203  
    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

    rd81ef61c r50ba203  
    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

    rd81ef61c r50ba203  
    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

    rd81ef61c r50ba203  
    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

    rd81ef61c r50ba203  
    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

    rd81ef61c r50ba203  
    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

    rd81ef61c r50ba203  
    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

    rd81ef61c r50ba203  
    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

    rd81ef61c r50ba203  
    3333 */
    3434#include <errno.h>
     35#include <str_error.h>
    3536
    3637#include <usb/usb.h>    /* usb_address_t */
    37 #include <usb/usbdrv.h> /* usb_drv_*     */
     38#include <usb/usbdevice.h>
     39#include <usb/hub.h>
     40#include <usb/request.h>
    3841#include <usb/debug.h>
     42#include <usb/recognise.h>
    3943
    4044#include "port.h"
     
    5660        port->attached_device = 0;
    5761        port->rh = rh;
    58         port->hc_phone = parent_phone;
     62        int rc = usb_hc_connection_initialize_from_device(
     63            &port->hc_connection, rh);
     64        if (rc != EOK) {
     65                usb_log_error("Failed to initialize connection to HC.");
     66                return rc;
     67        }
    5968
    6069        port->checker = fibril_create(uhci_port_check, port);
     
    96105
    97106                if (port_status & STATUS_CONNECTED_CHANGED) {
     107                        int rc = usb_hc_connection_open(
     108                            &port_instance->hc_connection);
     109                        if (rc != EOK) {
     110                                usb_log_error("Failed to connect to HC.");
     111                                goto next;
     112                        }
     113
    98114                        if (port_status & STATUS_CONNECTED) {
    99115                                /* new device */
     
    102118                                uhci_port_remove_device(port_instance);
    103119                        }
     120
     121                        rc = usb_hc_connection_close(
     122                            &port_instance->hc_connection);
     123                        if (rc != EOK) {
     124                                usb_log_error("Failed to disconnect from HC.");
     125                                goto next;
     126                        }
    104127                }
     128        next:
    105129                async_usleep(port_instance->wait_period_usec);
    106130        }
     
    111135{
    112136        assert(port);
    113         assert(port->hc_phone);
     137        assert(usb_hc_connection_is_opened(&port->hc_connection));
    114138
    115139        usb_log_info("Adding new device on port %d.\n", port->number);
    116140
    117141        /* get address of the future device */
    118         const usb_address_t usb_address = usb_drv_request_address(port->hc_phone);
     142        const usb_address_t usb_address = usb_hc_request_address(
     143            &port->hc_connection, true);
    119144
    120145        if (usb_address <= 0) {
     
    126151
    127152        /* get default address */
    128         int ret = usb_drv_reserve_default_address(port->hc_phone);
     153        int ret = usb_hc_reserve_default_address(&port->hc_connection, true);
    129154        if (ret != EOK) {
    130155                usb_log_error("Failed to reserve default address on port %d.\n",
    131156                    port->number);
    132                 int ret2 =
    133                   usb_drv_release_address(port->hc_phone, usb_address);
     157                int ret2 = usb_hc_unregister_device(&port->hc_connection,
     158                    usb_address);
    134159                if (ret2 != EOK) {
    135160                        usb_log_fatal("Failed to return requested address on port %d.\n",
     
    172197        }
    173198
    174         /* assign address to device */
    175         ret = usb_drv_req_set_address(port->hc_phone, 0, usb_address);
     199        /*
     200         * Initialize connection to the device.
     201         */
     202        /* FIXME: check for errors. */
     203        usb_device_connection_t new_dev_connection;
     204        usb_endpoint_pipe_t new_dev_ctrl_pipe;
     205        usb_device_connection_initialize_on_default_address(
     206            &new_dev_connection, &port->hc_connection);
     207        usb_endpoint_pipe_initialize_default_control(&new_dev_ctrl_pipe,
     208            &new_dev_connection);
     209
     210        /*
     211         * Assign new address to the device. This function updates
     212         * the backing connection to still point to the same device.
     213         */
     214        /* FIXME: check for errors. */
     215        usb_endpoint_pipe_start_session(&new_dev_ctrl_pipe);
     216        ret = usb_request_set_address(&new_dev_ctrl_pipe, usb_address);
     217        usb_endpoint_pipe_end_session(&new_dev_ctrl_pipe);
    176218
    177219        if (ret != EOK) { /* address assigning went wrong */
    178220                usb_log_error("Failed(%d) to assign address to the device.\n", ret);
    179221                uhci_port_set_enabled(port, false);
    180                 int release = usb_drv_release_default_address(port->hc_phone);
     222                int release = usb_hc_release_default_address(&port->hc_connection);
    181223                if (release != EOK) {
    182224                        usb_log_error("Failed to release default address on port %d.\n",
     
    192234
    193235        /* release default address */
    194         ret = usb_drv_release_default_address(port->hc_phone);
     236        ret = usb_hc_release_default_address(&port->hc_connection);
    195237        if (ret != EOK) {
    196238                usb_log_error("Failed to release default address on port %d.\n",
     
    204246        assert(port->attached_device == 0);
    205247
    206         ret = usb_drv_register_child_in_devman(port->hc_phone, port->rh,
    207           usb_address, &port->attached_device);
     248        ret = usb_device_register_child_in_devman(new_dev_connection.address,
     249            new_dev_connection.hc_handle, port->rh, &port->attached_device);
    208250
    209251        if (ret != EOK) { /* something went wrong */
     
    215257                port->number, usb_address, port->attached_device);
    216258
    217         ret =
    218           usb_drv_bind_address(port->hc_phone, usb_address, port->attached_device);
     259        /*
     260         * Register the device in the host controller.
     261         */
     262        usb_hc_attached_device_t new_device = {
     263                .address = new_dev_connection.address,
     264                .handle = port->attached_device
     265        };
     266
     267        ret = usb_hc_register_device(&port->hc_connection, &new_device);
    219268        // TODO: proper error check here
    220269        assert(ret == EOK);
  • uspace/drv/uhci-rhd/port.h

    rd81ef61c r50ba203  
    3838#include <driver.h> /* device_t */
    3939#include <stdint.h>
     40#include <usb/usbdevice.h>
    4041
    4142#include "port_status.h"
     
    4647        unsigned number;
    4748        unsigned wait_period_usec;
    48         int hc_phone;
     49        usb_hc_connection_t hc_connection;
    4950        device_t *rh;
    5051        devman_handle_t attached_device;
  • uspace/drv/usbhid/hid.h

    rd81ef61c r50ba203  
    6969        device_t *device;
    7070        usb_hid_configuration_t *conf;
    71         usb_address_t address;
    7271        usb_hid_report_parser_t *parser;
    7372
    7473        usb_device_connection_t wire;
     74        usb_endpoint_pipe_t ctrl_pipe;
    7575        usb_endpoint_pipe_t poll_pipe;
    7676} usb_hid_dev_kbd_t;
  • uspace/drv/usbhid/main.c

    rd81ef61c r50ba203  
    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>
    49 #include <usb/devreq.h>
     51#include <usb/request.h>
    5052#include <usb/descriptor.h>
    5153#include <io/console.h>
     
    6062
    6163#define GUESSED_POLL_ENDPOINT 1
     64
     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};
    6274
    6375static void default_connection_handler(device_t *, ipc_callid_t, ipc_call_t *);
     
    262274}
    263275
    264 # if 0
    265276/*
    266277 * Kbd functions
     
    281292               
    282293                // get the descriptor from the device
    283                 int rc = usb_drv_req_get_descriptor(kbd_dev->device->parent_phone,
    284                     kbd_dev->address, USB_REQUEST_TYPE_CLASS, USB_DESCTYPE_HID_REPORT,
    285                     0, i, kbd_dev->conf->interfaces[i].report_desc, length,
     294                int rc = usb_request_get_descriptor(&kbd_dev->ctrl_pipe,
     295                    USB_REQUEST_TYPE_CLASS, USB_DESCTYPE_HID_REPORT,
     296                    i, 0,
     297                    kbd_dev->conf->interfaces[i].report_desc, length,
    286298                    &actual_size);
    287299
     
    303315        usb_standard_configuration_descriptor_t config_desc;
    304316       
    305         int rc = usb_drv_req_get_bare_configuration_descriptor(
    306             kbd_dev->device->parent_phone, kbd_dev->address, 0, &config_desc);
     317        int rc;
     318        rc = usb_request_get_bare_configuration_descriptor(&kbd_dev->ctrl_pipe,
     319            0, &config_desc);
    307320       
    308321        if (rc != EOK) {
     
    318331        size_t transferred = 0;
    319332        // get full configuration descriptor
    320         rc = usb_drv_req_get_full_configuration_descriptor(
    321             kbd_dev->device->parent_phone, kbd_dev->address, 0, descriptors,
     333        rc = usb_request_get_full_configuration_descriptor(&kbd_dev->ctrl_pipe,
     334            0, descriptors,
    322335            config_desc.total_length, &transferred);
    323336       
     
    329342        }
    330343       
     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
    331371        kbd_dev->conf = (usb_hid_configuration_t *)calloc(1,
    332372            sizeof(usb_hid_configuration_t));
     
    336376        }
    337377       
    338         rc = usbkbd_parse_descriptors(descriptors, transferred, kbd_dev->conf);
     378        /*rc = usbkbd_parse_descriptors(descriptors, transferred, kbd_dev->conf);
    339379        free(descriptors);
    340380        if (rc != EOK) {
     
    343383        }
    344384
    345         // get and report descriptors
     385        // get and report descriptors*/
    346386        rc = usbkbd_get_report_descriptor(kbd_dev);
    347387        if (rc != EOK) {
     
    360400     *    as the endpoint for polling
    361401         */
    362        
     402
    363403        return EOK;
    364404}
    365 #endif
     405
    366406static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev)
    367407{
     408        int rc;
     409
    368410        usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)calloc(1,
    369411            sizeof(usb_hid_dev_kbd_t));
     
    376418        kbd_dev->device = dev;
    377419
    378         // get phone to my HC and save it as my parent's phone
    379         // TODO: maybe not a good idea if DDF will use parent_phone
    380         int rc = kbd_dev->device->parent_phone = usb_drv_hc_connect_auto(dev, 0);
    381         if (rc < 0) {
    382                 printf("Problem setting phone to HC.\n");
    383                 goto error_leave;
    384         }
    385 
    386         rc = kbd_dev->address = usb_drv_get_my_address(dev->parent_phone, dev);
    387         if (rc < 0) {
    388                 printf("Problem getting address of the device.\n");
    389                 goto error_leave;
    390         }
    391 
    392         // doesn't matter now that we have no address
    393 //      if (kbd_dev->address < 0) {
    394 //              fprintf(stderr, NAME ": No device address!\n");
    395 //              free(kbd_dev);
    396 //              return NULL;
    397 //      }
    398 
    399         /*
    400          * will need all descriptors:
    401          * 1) choose one configuration from configuration descriptors
    402          *    (set it to the device)
    403          * 2) set endpoints from endpoint descriptors
    404          */
    405 
    406 
    407         // TODO: get descriptors, parse descriptors and save endpoints
    408         //usbkbd_process_descriptors(kbd_dev);
    409         usb_drv_req_set_configuration(
    410           kbd_dev->device->parent_phone, kbd_dev->address, 1);
    411 
    412 
    413 
    414420        /*
    415421         * Initialize the backing connection to the host controller.
     
    425431         * Initialize device pipes.
    426432         */
    427         rc = usb_endpoint_pipe_initialize(&kbd_dev->poll_pipe, &kbd_dev->wire,
    428             GUESSED_POLL_ENDPOINT, USB_TRANSFER_INTERRUPT, USB_DIRECTION_IN);
    429         if (rc != EOK) {
    430                 printf("Failed to initialize interrupt in pipe: %s.\n",
     433        rc = usb_endpoint_pipe_initialize_default_control(&kbd_dev->ctrl_pipe,
     434            &kbd_dev->wire);
     435        if (rc != EOK) {
     436                printf("Failed to initialize default control pipe: %s.\n",
    431437                    str_error(rc));
    432438                goto error_leave;
    433439        }
    434440
     441        /*
     442         * will need all descriptors:
     443         * 1) choose one configuration from configuration descriptors
     444         *    (set it to the device)
     445         * 2) set endpoints from endpoint descriptors
     446         */
     447
     448        // TODO: get descriptors, parse descriptors and save endpoints
     449        usb_endpoint_pipe_start_session(&kbd_dev->ctrl_pipe);
     450        //usb_request_set_configuration(&kbd_dev->ctrl_pipe, 1);
     451        rc = usbkbd_process_descriptors(kbd_dev);
     452        usb_endpoint_pipe_end_session(&kbd_dev->ctrl_pipe);
     453        if (rc != EOK) {
     454                goto error_leave;
     455        }
    435456
    436457        return kbd_dev;
     
    590611int main(int argc, char *argv[])
    591612{
     613        usb_log_enable(USB_LOG_LEVEL_INFO, "usbhid");
    592614        return driver_main(&kbd_driver);
    593615}
  • uspace/drv/usbhub/usbhub.c

    rd81ef61c r50ba203  
    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/request.h>
     
    7678        result->device = device;
    7779
     80<<<<<<< TREE
    7881        result->usb_device = usb_new(usb_hcd_attached_device_info_t);
    7982       
     83=======
     84
     85        dprintf(USB_LOG_LEVEL_DEBUG, "phone to hc = %d", hc);
     86        if (hc < 0) {
     87                return result;
     88        }
     89        //get some hub info
     90        usb_address_t addr = usb_drv_get_my_address(hc, device);
     91        dprintf(USB_LOG_LEVEL_DEBUG, "address of newly created hub = %d", addr);
     92        /*if(addr<0){
     93                //return result;
     94
     95        }*/
     96
     97        result->address = addr;
     98
     99>>>>>>> MERGE-SOURCE
    80100        // get hub descriptor
    81101
     
    148168        int port;
    149169        int opResult;
     170<<<<<<< TREE
    150171        //usb_target_t target;
    151172        //target.address = hub_info->usb_device->address;
    152173        //target.endpoint = 0;
     174=======
     175        usb_target_t target;
     176        target.address = hub_info->address;
     177        target.endpoint = 0;
     178>>>>>>> MERGE-SOURCE
    153179
    154180        //get configuration descriptor
     
    212238        dprintf(USB_LOG_LEVEL_INFO, "hub dev added");
    213239        dprintf(USB_LOG_LEVEL_DEBUG, "\taddress %d, has %d ports ",
    214                         hub_info->usb_device->address,
     240                        hub_info->address,
    215241                        hub_info->port_count);
    216242        dprintf(USB_LOG_LEVEL_DEBUG, "\tused configuration %d",config_descriptor.configuration_number);
     
    317343        }
    318344
     345        devman_handle_t hc_handle;
     346        opResult = usb_drv_find_hc(hub->device, &hc_handle);
     347        if (opResult != EOK) {
     348                usb_log_error("Failed to get handle of host controller: %s.\n",
     349                    str_error(opResult));
     350                return;
     351        }
     352
    319353        devman_handle_t child_handle;
    320         opResult = usb_drv_register_child_in_devman(hc, hub->device,
    321             new_device_address, &child_handle);
     354        opResult = usb_device_register_child_in_devman(new_device_address,
     355            hc_handle, hub->device, &child_handle);
    322356        if (opResult != EOK) {
    323357                dprintf(USB_LOG_LEVEL_ERROR, "could not start driver for new device");
     
    472506                /*
    473507                usb_target_t target;
    474                 target.address = hub_info->usb_device->address;
     508                target.address = hub_info->address;
    475509                target.endpoint = 1;/// \TODO get from endpoint descriptor
    476510                dprintf(USB_LOG_LEVEL_INFO, "checking changes for hub at addr %d",
     
    515549                        if (interrupt) {
    516550                                usb_hub_process_interrupt(
     551<<<<<<< TREE
    517552                                        hub_info, port);
     553=======
     554                                        hub_info, hc, port, hub_info->address);
     555>>>>>>> MERGE-SOURCE
    518556                        }
    519557                }
  • uspace/drv/usbhub/usbhub.h

    rd81ef61c r50ba203  
    3636#define DRV_USBHUB_USBHUB_H
    3737
     38#include <ipc/devman.h>
     39#include <usb/usb.h>
     40#include <driver.h>
     41
    3842#define NAME "usbhub"
    3943
     44<<<<<<< TREE
    4045#include "usb/hcdhubd.h"
    4146
    4247#include <usb/pipes.h>
    4348
     49=======
     50>>>>>>> MERGE-SOURCE
    4451/** basic information about device attached to hub */
    4552typedef struct{
     
    6269        /** attached device handles, for each port one */
    6370        usb_hub_attached_device_t * attached_devs;
    64         /** General usb device info. */
    65         usb_hcd_attached_device_info_t * usb_device;
     71        /** USB address of the hub. */
     72        usb_address_t address;
    6673        /** General device info*/
    6774        device_t * device;
     75<<<<<<< TREE
    6876        /** connection to hcd */
    6977        usb_device_connection_t connection;
     
    7179        usb_hub_endpoints_t endpoints;
    7280
     81=======
     82>>>>>>> MERGE-SOURCE
    7383} usb_hub_info_t;
    7484
  • uspace/drv/vhc/conn.h

    rd81ef61c r50ba203  
    3737
    3838#include <usb/usb.h>
    39 #include <usb/hcdhubd.h>
    4039#include <usbhc_iface.h>
    4140#include "vhcd.h"
     
    4443void connection_handler_host(sysarg_t);
    4544
    46 usb_hcd_transfer_ops_t vhc_transfer_ops;
    4745usbhc_iface_t vhc_iface;
    4846
  • uspace/drv/vhc/connhost.c

    rd81ef61c r50ba203  
    3636#include <errno.h>
    3737#include <usb/usb.h>
    38 #include <usb/hcd.h>
     38#include <usb/addrkeep.h>
    3939
    4040#include "vhcd.h"
     
    6464
    6565static void universal_callback(void *buffer, size_t size,
    66     usb_transaction_outcome_t outcome, void *arg)
     66    int outcome, void *arg)
    6767{
    6868        transfer_info_t *transfer = (transfer_info_t *) arg;
     
    107107
    108108static void control_abort_prematurely(control_transfer_info_t *transfer,
    109     size_t size, usb_transaction_outcome_t outcome)
     109    size_t size, int outcome)
    110110{
    111111        switch (transfer->direction) {
     
    127127
    128128static void control_callback_two(void *buffer, size_t size,
    129     usb_transaction_outcome_t outcome, void *arg)
     129    int outcome, void *arg)
    130130{
    131131        control_transfer_info_t *ctrl_transfer = (control_transfer_info_t *) arg;
    132132
    133         if (outcome != USB_OUTCOME_OK) {
     133        if (outcome != EOK) {
    134134                control_abort_prematurely(ctrl_transfer, outcome, size);
    135135                free(ctrl_transfer);
     
    165165
    166166static void control_callback_one(void *buffer, size_t size,
    167     usb_transaction_outcome_t outcome, void *arg)
     167    int outcome, void *arg)
    168168{
    169169        control_transfer_info_t *transfer = (control_transfer_info_t *) arg;
    170170
    171         if (outcome != USB_OUTCOME_OK) {
     171        if (outcome != EOK) {
    172172                control_abort_prematurely(transfer, outcome, size);
    173173                free(transfer);
     
    276276
    277277static int interrupt_out(device_t *dev, usb_target_t target,
     278    size_t max_packet_size,
    278279    void *data, size_t size,
    279280    usbhc_iface_transfer_out_callback_t callback, void *arg)
     
    285286
    286287static int interrupt_in(device_t *dev, usb_target_t target,
     288    size_t max_packet_size,
    287289    void *data, size_t size,
    288290    usbhc_iface_transfer_in_callback_t callback, void *arg)
     
    294296
    295297static int control_write_setup(device_t *dev, usb_target_t target,
     298    size_t max_packet_size,
    296299    void *data, size_t size,
    297300    usbhc_iface_transfer_out_callback_t callback, void *arg)
     
    303306
    304307static int control_write_data(device_t *dev, usb_target_t target,
     308    size_t max_packet_size,
    305309    void *data, size_t size,
    306310    usbhc_iface_transfer_out_callback_t callback, void *arg)
     
    320324
    321325static int control_write(device_t *dev, usb_target_t target,
     326    size_t max_packet_size,
    322327    void *setup_packet, size_t setup_packet_size,
    323328    void *data, size_t data_size,
     
    337342
    338343static int control_read_setup(device_t *dev, usb_target_t target,
     344    size_t max_packet_size,
    339345    void *data, size_t size,
    340346    usbhc_iface_transfer_out_callback_t callback, void *arg)
     
    346352
    347353static int control_read_data(device_t *dev, usb_target_t target,
     354    size_t max_packet_size,
    348355    void *data, size_t size,
    349356    usbhc_iface_transfer_in_callback_t callback, void *arg)
     
    363370
    364371static int control_read(device_t *dev, usb_target_t target,
     372    size_t max_packet_size,
    365373    void *setup_packet, size_t setup_packet_size,
    366374    void *data, size_t data_size,
     
    382390
    383391
    384 static int reserve_default_address(device_t *dev)
     392static int reserve_default_address(device_t *dev, bool ignored)
    385393{
    386394        usb_address_keeping_reserve_default(&addresses);
     
    394402}
    395403
    396 static int request_address(device_t *dev, usb_address_t *address)
     404static int request_address(device_t *dev, bool ignored, usb_address_t *address)
    397405{
    398406        usb_address_t addr = usb_address_keeping_request(&addresses);
  • uspace/drv/vhc/devices.c

    rd81ef61c r50ba203  
    112112 * @param transaction Transaction to be sent over the bus.
    113113 */
    114 usb_transaction_outcome_t virtdev_send_to_all(transaction_t *transaction)
     114int virtdev_send_to_all(transaction_t *transaction)
    115115{
    116116        /* For easier debugging. */
     
    126126                        assert(false && "unreachable branch in switch()");
    127127        }
    128         usb_transaction_outcome_t outcome = USB_OUTCOME_BABBLE;
     128        int outcome = EBADCHECKSUM;
    129129
    130130        link_t *pos;
     
    185185                 */
    186186                if (rc == EOK) {
    187                         outcome = USB_OUTCOME_OK;
     187                        outcome = EOK;
    188188                }
    189189        }
     
    221221                                break;
    222222                }
    223                 outcome = USB_OUTCOME_OK;
     223                outcome = EOK;
    224224        }
    225225       
  • uspace/drv/vhc/devices.h

    rd81ef61c r50ba203  
    5454virtdev_connection_t *virtdev_find(sysarg_t);
    5555void virtdev_destroy_device(virtdev_connection_t *);
    56 usb_transaction_outcome_t virtdev_send_to_all(transaction_t *);
     56int virtdev_send_to_all(transaction_t *);
    5757
    5858#endif
  • uspace/drv/vhc/hc.c

    rd81ef61c r50ba203  
    8989 */
    9090static void process_transaction_with_outcome(transaction_t * transaction,
    91     usb_transaction_outcome_t outcome)
     91    int outcome)
    9292{
    9393        usb_log_debug2("Transaction " TRANSACTION_FORMAT " done: %s.\n",
    9494            TRANSACTION_PRINTF(*transaction),
    95             usb_str_transaction_outcome(outcome));
     95            str_error(outcome));
    9696       
    9797        transaction->callback(transaction->buffer, transaction->actual_len,
     
    127127                    TRANSACTION_PRINTF(*transaction), ports);
    128128
    129                 usb_transaction_outcome_t outcome;
     129                int outcome;
    130130                outcome = virtdev_send_to_all(transaction);
    131131               
  • uspace/drv/vhc/hc.h

    rd81ef61c r50ba203  
    4747 */
    4848typedef void (*hc_transaction_done_callback_t)(void *buffer, size_t size,
    49     usb_transaction_outcome_t outcome, void *arg);
     49    int outcome, void *arg);
    5050
    5151/** Pending transaction details. */
  • uspace/drv/vhc/hub.c

    rd81ef61c r50ba203  
    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
Note: See TracChangeset for help on using the changeset viewer.