Changes in / [299d53e:81c508c] in mainline


Ignore:
Location:
uspace/drv
Files:
1 added
2 deleted
21 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/pciintel/pci.c

    r299d53e r81c508c  
    320320        /* Get the value of the BAR. */
    321321        val = pci_conf_read_32(fun, addr);
    322 
    323 #define IO_MASK  (~0x3)
    324 #define MEM_MASK (~0xf)
    325322       
    326323        io = (bool) (val & 1);
    327324        if (io) {
    328325                addrw64 = false;
    329                 mask = IO_MASK;
    330326        } else {
    331                 mask = MEM_MASK;
    332327                switch ((val >> 1) & 3) {
    333328                case 0:
     
    345340        /* Get the address mask. */
    346341        pci_conf_write_32(fun, addr, 0xffffffff);
    347         mask &= pci_conf_read_32(fun, addr);
     342        mask = pci_conf_read_32(fun, addr);
    348343       
    349344        /* Restore the original value. */
     
    664659size_t pci_bar_mask_to_size(uint32_t mask)
    665660{
    666         size_t size = mask & ~(mask - 1);
    667         return size;
     661        return ((mask & 0xfffffff0) ^ 0xffffffff) + 1;
    668662}
    669663
  • uspace/drv/uhci-hcd/Makefile

    r299d53e r81c508c  
    3939        uhci.c \
    4040        uhci_struct/transfer_descriptor.c \
    41         utils/device_keeper.c \
    4241        pci.c \
    4342        batch.c
  • uspace/drv/uhci-hcd/batch.c

    r299d53e r81c508c  
    3333 */
    3434#include <errno.h>
    35 #include <str_error.h>
    3635
    3736#include <usb/debug.h>
     
    5453batch_t * batch_get(ddf_fun_t *fun, usb_target_t target,
    5554    usb_transfer_type_t transfer_type, size_t max_packet_size,
    56     usb_speed_t speed, char *buffer, size_t size,
     55    dev_speed_t speed, char *buffer, size_t size,
    5756    char* setup_buffer, size_t setup_size,
    5857    usbhc_iface_transfer_in_callback_t func_in,
     
    140139{
    141140        assert(instance);
    142         usb_log_debug2("Batch(%p) checking %d packet(s) for completion.\n",
     141        usb_log_debug("Checking(%p) %d packet for completion.\n",
    143142            instance, instance->packets);
    144143        instance->transfered_size = 0;
     
    152151                        if (i > 0)
    153152                                instance->transfered_size -= instance->setup_size;
    154                         usb_log_debug("Batch(%p) found error TD(%d):%x.\n",
    155                           instance, i, instance->tds[i].status);
    156153                        return true;
    157154                }
     
    159156                    transfer_descriptor_actual_size(&instance->tds[i]);
    160157        }
     158        /* This is just an ugly trick to support the old API */
    161159        instance->transfered_size -= instance->setup_size;
    162160        return true;
     
    170168        memcpy(instance->transport_buffer, instance->buffer, instance->buffer_size);
    171169
    172         const bool low_speed = instance->speed == USB_SPEED_LOW;
    173170        int toggle = 0;
    174171        /* setup stage */
    175172        transfer_descriptor_init(instance->tds, DEFAULT_ERROR_COUNT,
    176             instance->setup_size, toggle, false, low_speed,
    177             instance->target, USB_PID_SETUP, instance->setup_buffer,
    178             &instance->tds[1]);
     173            instance->setup_size, toggle, false, instance->target,
     174            USB_PID_SETUP, instance->setup_buffer, &instance->tds[1]);
    179175
    180176        /* data stage */
     
    186182
    187183                transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT,
    188                     instance->max_packet_size, toggle++, false, low_speed,
    189                     instance->target, USB_PID_OUT, data, &instance->tds[i + 1]);
     184                    instance->max_packet_size, toggle++, false, instance->target,
     185                    USB_PID_OUT, data, &instance->tds[i + 1]);
    190186        }
    191187
     
    193189        i = instance->packets - 1;
    194190        transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT,
    195             0, 1, false, low_speed, instance->target, USB_PID_IN, NULL, NULL);
     191            0, 1, false, instance->target, USB_PID_IN, NULL, NULL);
    196192
    197193        instance->tds[i].status |= TD_STATUS_COMPLETE_INTERRUPT_FLAG;
    198         usb_log_debug("Control write last TD status: %x.\n",
    199                 instance->tds[i].status);
    200194
    201195        instance->next_step = batch_call_out_and_dispose;
     
    207201        assert(instance);
    208202
    209         const bool low_speed = instance->speed == USB_SPEED_LOW;
    210203        int toggle = 0;
    211204        /* setup stage */
    212205        transfer_descriptor_init(instance->tds, DEFAULT_ERROR_COUNT,
    213             instance->setup_size, toggle, false, low_speed, instance->target,
     206            instance->setup_size, toggle, false, instance->target,
    214207            USB_PID_SETUP, instance->setup_buffer, &instance->tds[1]);
    215208
     
    222215
    223216                transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT,
    224                     instance->max_packet_size, toggle, false, low_speed,
    225                                 instance->target, USB_PID_IN, data, &instance->tds[i + 1]);
     217                    instance->max_packet_size, toggle, false, instance->target,
     218                    USB_PID_IN, data, &instance->tds[i + 1]);
    226219        }
    227220
     
    229222        i = instance->packets - 1;
    230223        transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT,
    231             0, 1, false, low_speed, instance->target, USB_PID_OUT, NULL, NULL);
     224            0, 1, false, instance->target, USB_PID_OUT, NULL, NULL);
    232225
    233226        instance->tds[i].status |= TD_STATUS_COMPLETE_INTERRUPT_FLAG;
    234         usb_log_debug("Control read last TD status: %x.\n",
    235                 instance->tds[i].status);
    236227
    237228        instance->next_step = batch_call_in_and_dispose;
     
    243234        assert(instance);
    244235
    245         const bool low_speed = instance->speed == USB_SPEED_LOW;
    246236        int toggle = 1;
    247237        size_t i = 0;
     
    254244
    255245                transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT,
    256                     instance->max_packet_size, toggle, false, low_speed,
    257                     instance->target, USB_PID_IN, data, next);
     246                    instance->max_packet_size, toggle, false, instance->target,
     247                    USB_PID_IN, data, next);
    258248        }
    259249
     
    270260        memcpy(instance->transport_buffer, instance->buffer, instance->buffer_size);
    271261
    272         const bool low_speed = instance->speed == USB_SPEED_LOW;
    273262        int toggle = 1;
    274263        size_t i = 0;
     
    281270
    282271                transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT,
    283                     instance->max_packet_size, toggle++, false, low_speed,
    284                     instance->target, USB_PID_OUT, data, next);
     272                    instance->max_packet_size, toggle++, false, instance->target,
     273                    USB_PID_OUT, data, next);
    285274        }
    286275
     
    299288
    300289        int err = instance->error;
    301         usb_log_info("Batch(%p) callback IN(type:%d): %s(%d), %zu.\n",
    302             instance, instance->transfer_type, str_error(err), err,
    303             instance->transfered_size);
     290        usb_log_info("Callback IN(%d): %d, %zu.\n", instance->transfer_type,
     291            err, instance->transfered_size);
    304292
    305293        instance->callback_in(instance->fun,
     
    314302
    315303        int err = instance->error;
    316         usb_log_info("Batch(%p) callback OUT(type:%d): %s(%d).\n",
    317             instance, instance->transfer_type, str_error(err), err);
     304        usb_log_info("Callback OUT(%d): %d.\n", instance->transfer_type, err);
    318305        instance->callback_out(instance->fun,
    319306            err, instance->arg);
     
    324311        assert(instance);
    325312        batch_call_in(instance);
    326         usb_log_debug("Batch(%p) disposing.\n", instance);
     313        usb_log_debug("Disposing batch: %p.\n", instance);
    327314        free32(instance->tds);
    328315        free32(instance->qh);
     
    336323        assert(instance);
    337324        batch_call_out(instance);
    338         usb_log_debug("Batch(%p) disposing.\n", instance);
     325        usb_log_debug("Disposing batch: %p.\n", instance);
    339326        free32(instance->tds);
    340327        free32(instance->qh);
     
    351338        return uhci_schedule(hc, instance);
    352339}
     340/*----------------------------------------------------------------------------*/
     341/* DEPRECATED FUNCTIONS NEEDED BY THE OLD API */
     342void batch_control_setup_old(batch_t *instance)
     343{
     344        assert(instance);
     345        instance->packets = 1;
     346
     347        /* setup stage */
     348        transfer_descriptor_init(instance->tds, DEFAULT_ERROR_COUNT,
     349            instance->setup_size, 0, false, instance->target,
     350            USB_PID_SETUP, instance->setup_buffer, NULL);
     351
     352        instance->next_step = batch_call_out_and_dispose;
     353        batch_schedule(instance);
     354}
     355/*----------------------------------------------------------------------------*/
     356void batch_control_write_data_old(batch_t *instance)
     357{
     358        assert(instance);
     359        instance->packets -= 2;
     360        batch_interrupt_out(instance);
     361}
     362/*----------------------------------------------------------------------------*/
     363void batch_control_read_data_old(batch_t *instance)
     364{
     365        assert(instance);
     366        instance->packets -= 2;
     367        batch_interrupt_in(instance);
     368}
     369/*----------------------------------------------------------------------------*/
     370void batch_control_write_status_old(batch_t *instance)
     371{
     372        assert(instance);
     373        instance->packets = 1;
     374        transfer_descriptor_init(instance->tds, DEFAULT_ERROR_COUNT,
     375            0, 1, false, instance->target, USB_PID_IN, NULL, NULL);
     376        instance->next_step = batch_call_in_and_dispose;
     377        batch_schedule(instance);
     378}
     379/*----------------------------------------------------------------------------*/
     380void batch_control_read_status_old(batch_t *instance)
     381{
     382        assert(instance);
     383        instance->packets = 1;
     384        transfer_descriptor_init(instance->tds, DEFAULT_ERROR_COUNT,
     385            0, 1, false, instance->target, USB_PID_OUT, NULL, NULL);
     386        instance->next_step = batch_call_out_and_dispose;
     387        batch_schedule(instance);
     388}
    353389/**
    354390 * @}
  • uspace/drv/uhci-hcd/batch.h

    r299d53e r81c508c  
    4343#include "uhci_struct/queue_head.h"
    4444
     45typedef enum {
     46        LOW_SPEED,
     47        FULL_SPEED,
     48} dev_speed_t;
     49
    4550typedef struct batch
    4651{
    4752        link_t link;
    48         usb_speed_t speed;
     53        dev_speed_t speed;
    4954        usb_target_t target;
    5055        usb_transfer_type_t transfer_type;
     
    7176batch_t * batch_get(ddf_fun_t *fun, usb_target_t target,
    7277    usb_transfer_type_t transfer_type, size_t max_packet_size,
    73     usb_speed_t speed, char *buffer, size_t size,
     78    dev_speed_t speed, char *buffer, size_t size,
    7479                char *setup_buffer, size_t setup_size,
    7580    usbhc_iface_transfer_in_callback_t func_in,
  • uspace/drv/uhci-hcd/iface.c

    r299d53e r81c508c  
    4141#include "iface.h"
    4242#include "uhci.h"
    43 #include "utils/device_keeper.h"
    4443
    4544/*----------------------------------------------------------------------------*/
     
    4948        uhci_t *hc = fun_to_uhci(fun);
    5049        assert(hc);
    51         usb_log_debug("Default address request with speed %d.\n", speed);
    52         device_keeper_reserve_default(&hc->device_manager, speed);
     50        usb_address_keeping_reserve_default(&hc->address_manager);
    5351        return EOK;
    5452}
     
    5957        uhci_t *hc = fun_to_uhci(fun);
    6058        assert(hc);
    61         usb_log_debug("Default address release.\n");
    62         device_keeper_release_default(&hc->device_manager);
     59        usb_address_keeping_release_default(&hc->address_manager);
    6360        return EOK;
    6461}
     
    7067        uhci_t *hc = fun_to_uhci(fun);
    7168        assert(hc);
    72         assert(address);
    73 
    74         usb_log_debug("Address request with speed %d.\n", speed);
    75         *address = device_keeper_request(&hc->device_manager, speed);
    76         usb_log_debug("Address request with result: %d.\n", *address);
     69        *address = usb_address_keeping_request(&hc->address_manager);
    7770        if (*address <= 0)
    7871          return *address;
     
    8679        uhci_t *hc = fun_to_uhci(fun);
    8780        assert(hc);
    88         usb_log_debug("Address bind %d-%d.\n", address, handle);
    89         device_keeper_bind(&hc->device_manager, address, handle);
     81        usb_address_keeping_devman_bind(&hc->address_manager, address, handle);
    9082        return EOK;
    9183}
     
    9688        uhci_t *hc = fun_to_uhci(fun);
    9789        assert(hc);
    98         usb_log_debug("Address release %d.\n", address);
    99         device_keeper_release(&hc->device_manager, address);
     90        usb_address_keeping_release_default(&hc->address_manager);
    10091        return EOK;
    10192}
    10293/*----------------------------------------------------------------------------*/
    10394static int interrupt_out(ddf_fun_t *fun, usb_target_t target,
    104     size_t max_packet_size, void *data, size_t size,
     95    size_t max_packet_size,
     96    void *data, size_t size,
    10597    usbhc_iface_transfer_out_callback_t callback, void *arg)
    10698{
    107         assert(fun);
    108         uhci_t *hc = fun_to_uhci(fun);
    109         assert(hc);
    110         usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
    111 
    112         usb_log_debug("Interrupt OUT %d:%d %zu(%zu).\n",
    113             target.address, target.endpoint, size, max_packet_size);
     99        dev_speed_t speed = FULL_SPEED;
    114100
    115101        batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
     
    122108/*----------------------------------------------------------------------------*/
    123109static int interrupt_in(ddf_fun_t *fun, usb_target_t target,
    124     size_t max_packet_size, void *data, size_t size,
     110    size_t max_packet_size,
     111    void *data, size_t size,
    125112    usbhc_iface_transfer_in_callback_t callback, void *arg)
    126113{
    127         assert(fun);
    128         uhci_t *hc = fun_to_uhci(fun);
    129         assert(hc);
    130         usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
    131         usb_log_debug("Interrupt IN %d:%d %zu(%zu).\n",
    132             target.address, target.endpoint, size, max_packet_size);
     114        dev_speed_t speed = FULL_SPEED;
    133115
    134116        batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
     
    145127    usbhc_iface_transfer_out_callback_t callback, void *arg)
    146128{
    147         assert(fun);
    148         uhci_t *hc = fun_to_uhci(fun);
    149         assert(hc);
    150         usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
    151         usb_log_debug("Control WRITE %d:%d %zu(%zu).\n",
    152             target.address, target.endpoint, size, max_packet_size);
     129        dev_speed_t speed = FULL_SPEED;
    153130
    154131        batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
     
    166143    usbhc_iface_transfer_in_callback_t callback, void *arg)
    167144{
    168         assert(fun);
    169         uhci_t *hc = fun_to_uhci(fun);
    170         assert(hc);
    171         usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
     145        dev_speed_t speed = FULL_SPEED;
    172146
    173         usb_log_debug("Control READ %d:%d %zu(%zu).\n",
    174             target.address, target.endpoint, size, max_packet_size);
    175147        batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
    176148            max_packet_size, speed, data, size, setup_data, setup_size, callback,
  • uspace/drv/uhci-hcd/main.c

    r299d53e r81c508c  
    8282        usb_log_info("uhci_add_device() called\n");
    8383
    84         uintptr_t io_reg_base = 0;
    85         size_t io_reg_size = 0;
    86         int irq = 0;
     84
     85        uintptr_t io_reg_base;
     86        size_t io_reg_size;
     87        int irq;
    8788
    8889        int ret =
     
    9495            io_reg_base, io_reg_size, irq);
    9596
    96 //      ret = pci_enable_interrupts(device);
    97 //      CHECK_RET_RETURN(ret, "Failed(%d) to get enable interrupts:\n", ret);
     97        ret = pci_enable_interrupts(device);
     98        CHECK_RET_RETURN(ret, "Failed(%d) to get enable interrupts:\n", ret);
    9899
    99100        uhci_t *uhci_hc = malloc(sizeof(uhci_t));
     
    113114         */
    114115        device->driver_data = uhci_hc;
     116
    115117        ret = register_interrupt_handler(device, irq, irq_handler,
    116118            &uhci_hc->interrupt_code);
     
    147149{
    148150        sleep(3);
    149         usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME);
     151        usb_log_enable(USB_LOG_LEVEL_INFO, NAME);
    150152
    151153        return ddf_driver_main(&uhci_driver);
  • uspace/drv/uhci-hcd/pci.c

    r299d53e r81c508c  
    3838#include <devman.h>
    3939#include <device/hw_res.h>
    40 
    41 #include <usb/debug.h>
    4240
    4341#include "pci.h"
     
    8583                                irq = res->res.interrupt.irq;
    8684                                irq_found = true;
    87                                 usb_log_debug("Found interrupt: %d.\n", irq);
    8885                                break;
    8986                        case IO_RANGE:
    90                                 io_address = res->res.io_range.address;
     87                                io_address = (uintptr_t)
     88                                    res->res.io_range.address;
    9189                                io_size = res->res.io_range.size;
    92                                 usb_log_debug("Found io: %llx %zu %zu.\n",
    93                                     res->res.io_range.address, res->res.io_range.size, io_size);
    9490                                io_found = true;
    9591                                break;
     
    109105        }
    110106
    111         *io_reg_address = io_address;
    112         *io_reg_size = io_size;
    113         *irq_no = irq;
     107        if (io_reg_address != NULL) {
     108                *io_reg_address = io_address;
     109        }
     110        if (io_reg_size != NULL) {
     111                *io_reg_size = io_size;
     112        }
     113        if (irq_no != NULL) {
     114                *irq_no = irq;
     115        }
    114116
    115117        rc = EOK;
     
    125127            IPC_FLAG_BLOCKING);
    126128        bool enabled = hw_res_enable_interrupt(parent_phone);
    127         async_hangup(parent_phone);
    128129        return enabled ? EOK : EIO;
    129130}
  • uspace/drv/uhci-hcd/root_hub.c

    r299d53e r81c508c  
    3535#include <errno.h>
    3636#include <stdio.h>
    37 #include <ops/hw_res.h>
    38 
    3937#include <usb_iface.h>
    4038#include <usb/debug.h>
     
    4341#include "uhci.h"
    4442
    45 /*----------------------------------------------------------------------------*/
    4643static int usb_iface_get_hc_handle_rh_impl(ddf_fun_t *root_hub_fun,
    4744    devman_handle_t *handle)
     
    5451        return EOK;
    5552}
    56 /*----------------------------------------------------------------------------*/
     53
    5754static int usb_iface_get_address_rh_impl(ddf_fun_t *fun, devman_handle_t handle,
    5855    usb_address_t *address)
     
    6461        assert(hc);
    6562
    66         usb_address_t addr = device_keeper_find(&hc->device_manager,
     63        usb_address_t addr = usb_address_keeping_find(&hc->address_manager,
    6764            handle);
    6865        if (addr < 0) {
     
    7673        return EOK;
    7774}
    78 /*----------------------------------------------------------------------------*/
     75
    7976usb_iface_t usb_iface_root_hub_fun_impl = {
    8077        .get_hc_handle = usb_iface_get_hc_handle_rh_impl,
    8178        .get_address = usb_iface_get_address_rh_impl
    8279};
    83 /*----------------------------------------------------------------------------*/
    84 static hw_resource_list_t *get_resource_list(ddf_fun_t *dev)
    85 {
    86         assert(dev);
    87         ddf_fun_t *hc_ddf_instance = dev->driver_data;
    88         assert(hc_ddf_instance);
    89         uhci_t *hc = hc_ddf_instance->driver_data;
    90         assert(hc);
    9180
    92         //TODO: fix memory leak
    93         hw_resource_list_t *resource_list = malloc(sizeof(hw_resource_list_t));
    94         assert(resource_list);
    95         resource_list->count = 1;
    96         resource_list->resources = malloc(sizeof(hw_resource_t));
    97         assert(resource_list->resources);
    98         resource_list->resources[0].type = IO_RANGE;
    99         resource_list->resources[0].res.io_range.address =
    100             ((uintptr_t)hc->registers) + 0x10; // see UHCI design guide
    101         resource_list->resources[0].res.io_range.size = 4;
    102         resource_list->resources[0].res.io_range.endianness = LITTLE_ENDIAN;
     81static ddf_dev_ops_t root_hub_ops = {
     82        .interfaces[USB_DEV_IFACE] = &usb_iface_root_hub_fun_impl
     83};
    10384
    104         return resource_list;
    105 }
    106 /*----------------------------------------------------------------------------*/
    107 static hw_res_ops_t hw_res_iface = {
    108         .get_resource_list = get_resource_list,
    109         .enable_interrupt = NULL
    110 };
    111 /*----------------------------------------------------------------------------*/
    112 static ddf_dev_ops_t root_hub_ops = {
    113         .interfaces[USB_DEV_IFACE] = &usb_iface_root_hub_fun_impl,
    114         .interfaces[HW_RES_DEV_IFACE] = &hw_res_iface
    115 };
    11685/*----------------------------------------------------------------------------*/
    11786int setup_root_hub(ddf_fun_t **fun, ddf_dev_t *hc)
  • uspace/drv/uhci-hcd/transfer_list.c

    r299d53e r81c508c  
    7070        assert(instance);
    7171        assert(batch);
    72         usb_log_debug("Adding batch(%p) to queue %s.\n", batch, instance->name);
    7372
    7473        uint32_t pa = (uintptr_t)addr_to_phys(batch->qh);
     
    124123}
    125124/*----------------------------------------------------------------------------*/
    126 void transfer_list_remove_finished(transfer_list_t *instance)
     125void transfer_list_check(transfer_list_t *instance)
    127126{
    128127        assert(instance);
    129 
    130         LIST_INITIALIZE(done);
    131 
    132128        fibril_mutex_lock(&instance->guard);
    133129        link_t *current = instance->batch_list.next;
     
    138134                if (batch_is_complete(batch)) {
    139135                        transfer_list_remove_batch(instance, batch);
    140                         list_append(current, &done);
     136                        batch->next_step(batch);
    141137                }
    142138                current = next;
    143139        }
    144140        fibril_mutex_unlock(&instance->guard);
    145 
    146         while (!list_empty(&done)) {
    147                 link_t *item = done.next;
    148                 list_remove(item);
    149                 batch_t *batch = list_get_instance(item, batch_t, link);
    150                 batch->next_step(batch);
    151         }
    152141}
    153142/**
  • uspace/drv/uhci-hcd/transfer_list.h

    r299d53e r81c508c  
    6060        queue_head_dispose(instance->queue_head);
    6161}
    62 void transfer_list_remove_finished(transfer_list_t *instance);
     62void transfer_list_check(transfer_list_t *instance);
    6363
    6464void transfer_list_add_batch(transfer_list_t *instance, batch_t *batch);
  • uspace/drv/uhci-hcd/uhci.c

    r299d53e r81c508c  
    4848        {
    4949                .cmd = CMD_PIO_READ_16,
    50                 .addr = NULL, /* patched for every instance */
     50                .addr = (void*)0xc022,
    5151                .dstarg = 1
    5252        },
    5353        {
    5454                .cmd = CMD_PIO_WRITE_16,
    55                 .addr = NULL, /* pathed for every instance */
     55                .addr = (void*)0xc022,
    5656                .value = 0x1f
    5757        },
     
    6868        assert(hc);
    6969
    70         usb_address_t addr = device_keeper_find(&hc->device_manager,
     70        usb_address_t addr = usb_address_keeping_find(&hc->address_manager,
    7171            handle);
    7272        if (addr < 0) {
     
    8080        return EOK;
    8181}
    82 /*----------------------------------------------------------------------------*/
     82
     83
    8384static usb_iface_t hc_usb_iface = {
    8485        .get_hc_handle = usb_iface_get_hc_handle_hc_impl,
     
    8889static ddf_dev_ops_t uhci_ops = {
    8990        .interfaces[USB_DEV_IFACE] = &hc_usb_iface,
    90         .interfaces[USBHC_DEV_IFACE] = &uhci_iface,
     91        .interfaces[USBHC_DEV_IFACE] = &uhci_iface
    9192};
    9293
     
    140141
    141142        instance->cleaner = fibril_create(uhci_interrupt_emulator, instance);
    142         fibril_add_ready(instance->cleaner);
     143//      fibril_add_ready(instance->cleaner);
    143144
    144145        instance->debug_checker = fibril_create(uhci_debug_checker, instance);
     
    150151void uhci_init_hw(uhci_t *instance)
    151152{
    152         /* reset everything, who knows what touched it before us */
    153         pio_write_16(&instance->registers->usbcmd, UHCI_CMD_GLOBAL_RESET);
    154         async_usleep(10000); /* 10ms according to USB spec */
    155         pio_write_16(&instance->registers->usbcmd, 0);
    156 
    157         /* reset hc, all states and counters */
    158         pio_write_16(&instance->registers->usbcmd, UHCI_CMD_HCRESET);
    159         while ((pio_read_16(&instance->registers->usbcmd) & UHCI_CMD_HCRESET) != 0)
    160                 { async_usleep(10); }
    161153
    162154        /* set framelist pointer */
     
    211203
    212204        /* init address keeper(libusb) */
    213         device_keeper_init(&instance->device_manager);
    214         usb_log_debug("Initialized device manager.\n");
     205        usb_address_keeping_init(&instance->address_manager, USB11_ADDRESS_MAX);
     206        usb_log_debug("Initialized address manager.\n");
    215207
    216208        return EOK;
     
    263255        assert(instance);
    264256        assert(batch);
    265         const int low_speed = (batch->speed == USB_SPEED_LOW);
     257        const int low_speed = (batch->speed == LOW_SPEED);
    266258        if (!allowed_usb_packet(
    267259            low_speed, batch->transfer_type, batch->max_packet_size)) {
     
    284276{
    285277        assert(instance);
    286 //      if ((status & (UHCI_STATUS_INTERRUPT | UHCI_STATUS_ERROR_INTERRUPT)) == 0)
    287 //              return;
    288 //      usb_log_debug2("UHCI interrupt: %X.\n", status);
    289         transfer_list_remove_finished(&instance->transfers_interrupt);
    290         transfer_list_remove_finished(&instance->transfers_control_slow);
    291         transfer_list_remove_finished(&instance->transfers_control_full);
    292         transfer_list_remove_finished(&instance->transfers_bulk_full);
     278        if ((status & (UHCI_STATUS_INTERRUPT | UHCI_STATUS_ERROR_INTERRUPT)) == 0)
     279                return;
     280        usb_log_debug("UHCI interrupt: %X.\n", status);
     281        transfer_list_check(&instance->transfers_interrupt);
     282        transfer_list_check(&instance->transfers_control_slow);
     283        transfer_list_check(&instance->transfers_control_full);
     284        transfer_list_check(&instance->transfers_bulk_full);
    293285}
    294286/*----------------------------------------------------------------------------*/
     
    299291        assert(instance);
    300292
    301         while (1) {
     293        while(1) {
    302294                uint16_t status = pio_read_16(&instance->registers->usbsts);
    303                 if (status != 0)
    304                         usb_log_debug2("UHCI status: %x.\n", status);
    305                 status |= 1;
    306295                uhci_interrupt(instance, status);
    307                 pio_write_16(&instance->registers->usbsts, 0x1f);
    308                 async_usleep(UHCI_CLEANER_TIMEOUT * 5);
     296                async_usleep(UHCI_CLEANER_TIMEOUT);
    309297        }
    310298        return EOK;
     
    319307                const uint16_t sts = pio_read_16(&instance->registers->usbsts);
    320308                const uint16_t intr = pio_read_16(&instance->registers->usbintr);
    321                 if (((cmd & UHCI_CMD_RUN_STOP) != 1) || (sts != 0)) {
    322                         usb_log_debug2("Command: %X Status: %X Intr: %x\n",
    323                             cmd, sts, intr);
    324                 }
    325 
    326                 uintptr_t frame_list =
    327                     pio_read_32(&instance->registers->flbaseadd) & ~0xfff;
     309                usb_log_debug("Command: %X Status: %X Interrupts: %x\n",
     310                    cmd, sts, intr);
     311
     312                uintptr_t frame_list = pio_read_32(&instance->registers->flbaseadd);
    328313                if (frame_list != addr_to_phys(instance->frame_list)) {
    329314                        usb_log_debug("Framelist address: %p vs. %p.\n",
  • uspace/drv/uhci-hcd/uhci.h

    r299d53e r81c508c  
    4141#include <ddi.h>
    4242
     43#include <usb/addrkeep.h>
    4344#include <usbhc_iface.h>
    4445
     46#include "transfer_list.h"
    4547#include "batch.h"
    46 #include "transfer_list.h"
    47 #include "utils/device_keeper.h"
    4848
    4949typedef struct uhci_regs {
     
    8282
    8383typedef struct uhci {
    84         device_keeper_t device_manager;
    85 
     84        usb_address_keeping_t address_manager;
    8685        volatile regs_t *registers;
    8786
  • uspace/drv/uhci-hcd/uhci_struct/transfer_descriptor.c

    r299d53e r81c508c  
    3939
    4040void transfer_descriptor_init(transfer_descriptor_t *instance,
    41     int error_count, size_t size, bool toggle, bool isochronous, bool low_speed,
     41    int error_count, size_t size, bool toggle, bool isochronous,
    4242    usb_target_t target, int pid, void *buffer, transfer_descriptor_t *next)
    4343{
     
    5050        instance->status = 0
    5151          | ((error_count & TD_STATUS_ERROR_COUNT_MASK) << TD_STATUS_ERROR_COUNT_POS)
    52                 | (low_speed ? TD_STATUS_LOW_SPEED_FLAG : 0)
    5352          | TD_STATUS_ERROR_ACTIVE;
    5453
     
    7069                instance->next, instance->status, instance->device,
    7170          instance->buffer_ptr, buffer);
     71#if 0
     72        if (size) {
     73                unsigned char * buff = buffer;
     74                uhci_print_verbose("TD Buffer dump(%p-%dB): ", buffer, size);
     75                unsigned i = 0;
     76                /* TODO: Verbose? */
     77                for (; i < size; ++i) {
     78                        printf((i & 1) ? "%x " : "%x", buff[i]);
     79                }
     80                printf("\n");
     81        }
     82#endif
    7283}
    7384/*----------------------------------------------------------------------------*/
     
    7788
    7889        if ((instance->status & TD_STATUS_ERROR_STALLED) != 0)
    79                 return ESTALL;
     90                return EIO;
    8091
    8192        if ((instance->status & TD_STATUS_ERROR_CRC) != 0)
    82                 return EBADCHECKSUM;
     93                return EAGAIN;
    8394
    8495        if ((instance->status & TD_STATUS_ERROR_BUFFER) != 0)
  • uspace/drv/uhci-hcd/uhci_struct/transfer_descriptor.h

    r299d53e r81c508c  
    9292
    9393void transfer_descriptor_init(transfer_descriptor_t *instance,
    94     int error_count, size_t size, bool toggle, bool isochronous, bool low_speed,
     94    int error_count, size_t size, bool toggle, bool isochronous,
    9595    usb_target_t target, int pid, void *buffer, transfer_descriptor_t * next);
    9696
  • uspace/drv/uhci-rhd/main.c

    r299d53e r81c508c  
    3333 */
    3434#include <ddf/driver.h>
    35 #include <devman.h>
    36 #include <device/hw_res.h>
    3735#include <usb_iface.h>
    3836#include <usb/ddfiface.h>
     
    4543
    4644#define NAME "uhci-rhd"
    47 static int hc_get_my_registers(ddf_dev_t *dev,
    48     uintptr_t *io_reg_address, size_t *io_reg_size);
    4945
    5046static int usb_iface_get_hc_handle(ddf_fun_t *fun, devman_handle_t *handle)
     
    8480        }
    8581
    86         uintptr_t io_regs = 0;
    87         size_t io_size = 0;
    88 
    89         int ret = hc_get_my_registers(device, &io_regs, &io_size);
    90         assert(ret == EOK);
    91 
    92         /* TODO: verify values from hc */
    93         usb_log_info("I/O regs at 0x%X (size %zu).\n", io_regs, io_size);
    94         ret = uhci_root_hub_init(rh, (void*)io_regs, io_size, device);
     82        /* TODO: get register values from hc */
     83        int ret = uhci_root_hub_init(rh, (void*)0xc030, 4, device);
    9584        if (ret != EOK) {
    9685                usb_log_error("Failed(%d) to initialize driver instance.\n", ret);
     
    113102        .driver_ops = &uhci_rh_driver_ops
    114103};
    115 /*----------------------------------------------------------------------------*/
     104
    116105int main(int argc, char *argv[])
    117106{
     
    119108        return ddf_driver_main(&uhci_rh_driver);
    120109}
    121 /*----------------------------------------------------------------------------*/
    122 int hc_get_my_registers(ddf_dev_t *dev,
    123     uintptr_t *io_reg_address, size_t *io_reg_size)
    124 {
    125         assert(dev != NULL);
    126 
    127         int parent_phone = devman_parent_device_connect(dev->handle,
    128             IPC_FLAG_BLOCKING);
    129         if (parent_phone < 0) {
    130                 return parent_phone;
    131         }
    132 
    133         int rc;
    134 
    135         hw_resource_list_t hw_resources;
    136         rc = hw_res_get_resource_list(parent_phone, &hw_resources);
    137         if (rc != EOK) {
    138                 goto leave;
    139         }
    140 
    141         uintptr_t io_address = 0;
    142         size_t io_size = 0;
    143         bool io_found = false;
    144 
    145         size_t i;
    146         for (i = 0; i < hw_resources.count; i++) {
    147                 hw_resource_t *res = &hw_resources.resources[i];
    148                 switch (res->type) {
    149                         case IO_RANGE:
    150                                 io_address = (uintptr_t)
    151                                     res->res.io_range.address;
    152                                 io_size = res->res.io_range.size;
    153                                 io_found = true;
    154                                 break;
    155                         default:
    156                                 break;
    157                 }
    158         }
    159 
    160         if (!io_found) {
    161                 rc = ENOENT;
    162                 goto leave;
    163         }
    164 
    165         if (io_reg_address != NULL) {
    166                 *io_reg_address = io_address;
    167         }
    168         if (io_reg_size != NULL) {
    169                 *io_reg_size = io_size;
    170         }
    171         rc = EOK;
    172 leave:
    173         async_hangup(parent_phone);
    174 
    175         return rc;
    176 }
    177110/**
    178111 * @}
  • uspace/drv/uhci-rhd/port.c

    r299d53e r81c508c  
    3434#include <errno.h>
    3535#include <str_error.h>
    36 #include <fibril_synch.h>
    3736
    3837#include <usb/usb.h>    /* usb_address_t */
     
    4645#include "port_status.h"
    4746
    48 static int uhci_port_new_device(uhci_port_t *port, uint16_t status);
     47static int uhci_port_new_device(uhci_port_t *port);
    4948static int uhci_port_remove_device(uhci_port_t *port);
    5049static int uhci_port_set_enabled(uhci_port_t *port, bool enabled);
    5150static int uhci_port_check(void *port);
    52 static int new_device_enable_port(int portno, void *arg);
    5351
    5452int uhci_port_init(
    5553  uhci_port_t *port, port_status_t *address, unsigned number,
    56   unsigned usec, ddf_dev_t *rh)
     54  unsigned usec, ddf_dev_t *rh, int parent_phone)
    5755{
    5856        assert(port);
     
    9290        uhci_port_t *port_instance = port;
    9391        assert(port_instance);
    94         port_status_write(port_instance->address, 0);
    95 
    96         uint64_t count = 0;
    9792
    9893        while (1) {
    99                 async_usleep(port_instance->wait_period_usec);
    100 
    10194                /* read register value */
    10295                port_status_t port_status =
     
    10497
    10598                /* debug print */
    106                 static fibril_mutex_t dbg_mtx = FIBRIL_MUTEX_INITIALIZER(dbg_mtx);
    107                 fibril_mutex_lock(&dbg_mtx);
    108                 usb_log_debug("Port %d status at %p: 0x%04x. === %llu\n",
    109                   port_instance->number, port_instance->address, port_status, count++);
    110 //              print_port_status(port_status);
    111                 fibril_mutex_unlock(&dbg_mtx);
    112 
    113                 if ((port_status & STATUS_CONNECTED_CHANGED) != 0) {
    114                         usb_log_debug("Change detected on port %d: %x.\n",
    115                             port_instance->number, port_status);
    116 
    117 
     99                usb_log_debug("Port %d status at %p: 0x%04x.\n",
     100                  port_instance->number, port_instance->address, port_status);
     101                print_port_status(port_status);
     102
     103                if (port_status & STATUS_CONNECTED_CHANGED) {
    118104                        int rc = usb_hc_connection_open(
    119105                            &port_instance->hc_connection);
    120106                        if (rc != EOK) {
    121107                                usb_log_error("Failed to connect to HC.");
    122                                 continue;
     108                                goto next;
    123109                        }
    124110
    125                         /* remove any old device */
    126                         if (port_instance->attached_device) {
    127                                 usb_log_debug("Removing device on port %d.\n",
    128                                     port_instance->number);
     111                        if (port_status & STATUS_CONNECTED) {
     112                                /* new device */
     113                                uhci_port_new_device(port_instance);
     114                        } else {
    129115                                uhci_port_remove_device(port_instance);
    130                         }
    131 
    132                         if ((port_status & STATUS_CONNECTED) != 0) {
    133                                 /* new device */
    134                                 uhci_port_new_device(port_instance, port_status);
    135                         } else {
    136                                 /* ack changes by writing one to WC bits */
    137                                 port_status_write(port_instance->address, port_status);
    138                                 usb_log_debug("Change status ack on port %d.\n",
    139                                                 port_instance->number);
    140116                        }
    141117
     
    144120                        if (rc != EOK) {
    145121                                usb_log_error("Failed to disconnect from HC.");
     122                                goto next;
    146123                        }
    147124                }
     125        next:
     126                async_usleep(port_instance->wait_period_usec);
    148127        }
    149128        return EOK;
     
    168147        async_usleep(100000);
    169148
     149        /* Enable the port. */
     150        uhci_port_set_enabled(port, true);
    170151
    171152        /* The hub maintains the reset signal to that port for 10 ms
     
    188169        }
    189170
    190         /* Enable the port. */
    191         uhci_port_set_enabled(port, true);
    192 
    193         return EOK;
    194 }
    195 
    196 /*----------------------------------------------------------------------------*/
    197 static int uhci_port_new_device(uhci_port_t *port, uint16_t status)
     171        return EOK;
     172}
     173
     174/*----------------------------------------------------------------------------*/
     175static int uhci_port_new_device(uhci_port_t *port)
    198176{
    199177        assert(port);
     
    204182        usb_address_t dev_addr;
    205183        int rc = usb_hc_new_device_wrapper(port->rh, &port->hc_connection,
    206             ((status & STATUS_LOW_SPEED) != 0) ? USB_SPEED_LOW : USB_SPEED_FULL,
     184            USB_SPEED_FULL,
    207185            new_device_enable_port, port->number, port,
    208186            &dev_addr, &port->attached_device, NULL, NULL, NULL);
    209 
    210187        if (rc != EOK) {
    211188                usb_log_error("Failed adding new device on port %u: %s.\n",
  • uspace/drv/uhci-rhd/port.h

    r299d53e r81c508c  
    5555int uhci_port_init(
    5656  uhci_port_t *port, port_status_t *address, unsigned number,
    57   unsigned usec, ddf_dev_t *rh);
     57  unsigned usec, ddf_dev_t *rh, int parent_phone);
    5858
    5959void uhci_port_fini(uhci_port_t *port);
  • uspace/drv/uhci-rhd/port_status.c

    r299d53e r81c508c  
    4141struct flag_name
    4242{
    43         uint16_t flag;
     43        unsigned flag;
    4444        const char *name;
    4545};
     
    6565        for (;i < sizeof(flags)/sizeof(struct flag_name); ++i) {
    6666                usb_log_debug2("\t%s status: %s.\n", flags[i].name,
    67                   ((value & flags[i].flag) != 0) ? "YES" : "NO");
     67                  value & flags[i].flag ? "YES" : "NO");
    6868        }
    6969}
  • uspace/drv/uhci-rhd/port_status.h

    r299d53e r81c508c  
    4141typedef uint16_t port_status_t;
    4242
    43 #define STATUS_CONNECTED         (1 << 0)
    44 #define STATUS_CONNECTED_CHANGED (1 << 1)
    45 #define STATUS_ENABLED           (1 << 2)
    46 #define STATUS_ENABLED_CHANGED   (1 << 3)
    47 #define STATUS_LINE_D_PLUS       (1 << 4)
    48 #define STATUS_LINE_D_MINUS      (1 << 5)
    49 #define STATUS_RESUME            (1 << 6)
    50 #define STATUS_ALWAYS_ONE        (1 << 7)
     43enum {
     44        STATUS_CONNECTED         = 1 << 0,
     45        STATUS_CONNECTED_CHANGED = 1 << 1,
     46        STATUS_ENABLED           = 1 << 2,
     47        STATUS_ENABLED_CHANGED   = 1 << 3,
     48        STATUS_LINE_D_PLUS       = 1 << 4,
     49        STATUS_LINE_D_MINUS      = 1 << 5,
     50        STATUS_RESUME            = 1 << 6,
     51        STATUS_ALWAYS_ONE        = 1 << 7,
    5152
    52 #define STATUS_LOW_SPEED (1 <<  8)
    53 #define STATUS_IN_RESET  (1 <<  9)
    54 #define STATUS_SUSPEND   (1 << 12)
     53        STATUS_LOW_SPEED = 1 <<  8,
     54        STATUS_IN_RESET  = 1 <<  9,
     55        STATUS_SUSPEND   = 1 << 12,
     56};
    5557
    5658static inline port_status_t port_status_read(port_status_t * address)
  • uspace/drv/uhci-rhd/root_hub.c

    r299d53e r81c508c  
    4040#include "root_hub.h"
    4141
     42
    4243int uhci_root_hub_init(
    4344  uhci_root_hub_t *instance, void *addr, size_t size, ddf_dev_t *rh)
     
    6667        unsigned i = 0;
    6768        for (; i < UHCI_ROOT_HUB_PORT_COUNT; ++i) {
     69                /* connect to the parent device (HC) */
     70                int parent_phone = devman_device_connect(instance->hc_handle, 0);
     71                //usb_drv_hc_connect(rh, instance->hc_handle, 0);
     72                if (parent_phone < 0) {
     73                        usb_log_error("Failed to connect to the HC device port %d.\n", i);
     74                        return parent_phone;
     75                }
    6876                /* mind pointer arithmetics */
    6977                int ret = uhci_port_init(
    70                   &instance->ports[i], regs + i, i, ROOT_HUB_WAIT_USEC, rh);
     78                  &instance->ports[i], regs + i, i, ROOT_HUB_WAIT_USEC, rh, parent_phone);
    7179                if (ret != EOK) {
    7280                        unsigned j = 0;
  • uspace/drv/uhci-rhd/root_hub.h

    r299d53e r81c508c  
    4141
    4242#define UHCI_ROOT_HUB_PORT_COUNT 2
    43 #define ROOT_HUB_WAIT_USEC 5000000 /* 5 seconds */
     43#define UHCI_ROOT_HUB_PORT_REGISTERS_OFFSET 0x10
     44#define ROOT_HUB_WAIT_USEC 10000000 /* 10 seconds */
    4445
    4546typedef struct root_hub {
Note: See TracChangeset for help on using the changeset viewer.