Changeset e099f26 in mainline for uspace/drv/uhci-hcd


Ignore:
Timestamp:
2011-03-21T20:22:50Z (15 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c56c5b5b
Parents:
4fb6d9ee (diff), 31b568e (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:

Development branch changes (including OHCI)

Location:
uspace/drv/uhci-hcd
Files:
10 edited

Legend:

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

    r4fb6d9ee re099f26  
    4040        uhci_rh.c \
    4141        uhci_struct/transfer_descriptor.c \
    42         utils/device_keeper.c \
    4342        pci.c \
    4443        batch.c
  • uspace/drv/uhci-hcd/batch.c

    r4fb6d9ee re099f26  
    4242#include "uhci_hc.h"
    4343#include "utils/malloc32.h"
     44#include "uhci_struct/transfer_descriptor.h"
    4445
    4546#define DEFAULT_ERROR_COUNT 3
    4647
    47 static void batch_control(batch_t *instance,
     48typedef struct uhci_batch {
     49        qh_t *qh;
     50        td_t *tds;
     51        size_t packets;
     52        usb_device_keeper_t *manager;
     53} uhci_batch_t;
     54
     55static void batch_control(usb_transfer_batch_t *instance,
    4856    usb_packet_id data_stage, usb_packet_id status_stage);
    49 static void batch_data(batch_t *instance, usb_packet_id pid);
    50 static void batch_call_in(batch_t *instance);
    51 static void batch_call_out(batch_t *instance);
    52 static void batch_call_in_and_dispose(batch_t *instance);
    53 static void batch_call_out_and_dispose(batch_t *instance);
     57static void batch_data(usb_transfer_batch_t *instance, usb_packet_id pid);
     58static void batch_call_in_and_dispose(usb_transfer_batch_t *instance);
     59static void batch_call_out_and_dispose(usb_transfer_batch_t *instance);
    5460
    5561
     
    7682 * transaction and callback.
    7783 */
    78 batch_t * batch_get(ddf_fun_t *fun, usb_target_t target,
     84usb_transfer_batch_t * batch_get(ddf_fun_t *fun, usb_target_t target,
    7985    usb_transfer_type_t transfer_type, size_t max_packet_size,
    80     usb_speed_t speed, char *buffer, size_t size,
     86    usb_speed_t speed, char *buffer, size_t buffer_size,
    8187    char* setup_buffer, size_t setup_size,
    8288    usbhc_iface_transfer_in_callback_t func_in,
    8389    usbhc_iface_transfer_out_callback_t func_out, void *arg,
    84     device_keeper_t *manager
     90    usb_device_keeper_t *manager
    8591    )
    8692{
     
    97103        } else (void)0
    98104
    99         batch_t *instance = malloc(sizeof(batch_t));
     105        usb_transfer_batch_t *instance = malloc(sizeof(usb_transfer_batch_t));
    100106        CHECK_NULL_DISPOSE_RETURN(instance,
    101107            "Failed to allocate batch instance.\n");
    102         bzero(instance, sizeof(batch_t));
    103 
    104         instance->qh = malloc32(sizeof(qh_t));
    105         CHECK_NULL_DISPOSE_RETURN(instance->qh,
     108        usb_transfer_batch_init(instance, target, transfer_type, speed, max_packet_size,
     109            buffer, NULL, buffer_size, NULL, setup_size, func_in,
     110            func_out, arg, fun, NULL);
     111
     112
     113        uhci_batch_t *data = malloc(sizeof(uhci_batch_t));
     114        CHECK_NULL_DISPOSE_RETURN(instance,
     115            "Failed to allocate batch instance.\n");
     116        bzero(data, sizeof(uhci_batch_t));
     117        data->manager = manager;
     118        instance->private_data = data;
     119
     120        data->packets = (buffer_size + max_packet_size - 1) / max_packet_size;
     121        if (transfer_type == USB_TRANSFER_CONTROL) {
     122                data->packets += 2;
     123        }
     124
     125        data->tds = malloc32(sizeof(td_t) * data->packets);
     126        CHECK_NULL_DISPOSE_RETURN(
     127            data->tds, "Failed to allocate transfer descriptors.\n");
     128        bzero(data->tds, sizeof(td_t) * data->packets);
     129
     130        data->qh = malloc32(sizeof(qh_t));
     131        CHECK_NULL_DISPOSE_RETURN(data->qh,
    106132            "Failed to allocate batch queue head.\n");
    107         qh_init(instance->qh);
    108 
    109         instance->packets = (size + max_packet_size - 1) / max_packet_size;
    110         if (transfer_type == USB_TRANSFER_CONTROL) {
    111                 instance->packets += 2;
    112         }
    113 
    114         instance->tds = malloc32(sizeof(td_t) * instance->packets);
    115         CHECK_NULL_DISPOSE_RETURN(
    116             instance->tds, "Failed to allocate transfer descriptors.\n");
    117         bzero(instance->tds, sizeof(td_t) * instance->packets);
    118 
    119         if (size > 0) {
    120                 instance->transport_buffer = malloc32(size);
     133        qh_init(data->qh);
     134        qh_set_element_td(data->qh, addr_to_phys(data->tds));
     135
     136        if (buffer_size > 0) {
     137                instance->transport_buffer = malloc32(buffer_size);
    121138                CHECK_NULL_DISPOSE_RETURN(instance->transport_buffer,
    122139                    "Failed to allocate device accessible buffer.\n");
     
    130147        }
    131148
    132 
    133         link_initialize(&instance->link);
    134 
    135         instance->max_packet_size = max_packet_size;
    136         instance->target = target;
    137         instance->transfer_type = transfer_type;
    138         instance->buffer = buffer;
    139         instance->buffer_size = size;
    140         instance->setup_size = setup_size;
    141         instance->fun = fun;
    142         instance->arg = arg;
    143         instance->speed = speed;
    144         instance->manager = manager;
    145         instance->callback_out = func_out;
    146         instance->callback_in = func_in;
    147 
    148         qh_set_element_td(instance->qh, addr_to_phys(instance->tds));
    149 
    150149        usb_log_debug("Batch(%p) %d:%d memory structures ready.\n",
    151150            instance, target.address, target.endpoint);
     
    153152}
    154153/*----------------------------------------------------------------------------*/
    155 /** Mark batch as failed and continue with next step.
    156  *
    157  * @param[in] instance Batch structure to use.
    158  *
    159  */
    160 void batch_abort(batch_t *instance)
    161 {
    162         assert(instance);
    163         instance->error = EIO;
    164         instance->next_step(instance);
    165 }
    166 /*----------------------------------------------------------------------------*/
    167154/** Check batch TDs for activity.
    168155 *
     
    174161 * is reached.
    175162 */
    176 bool batch_is_complete(batch_t *instance)
    177 {
    178         assert(instance);
     163bool batch_is_complete(usb_transfer_batch_t *instance)
     164{
     165        assert(instance);
     166        uhci_batch_t *data = instance->private_data;
     167        assert(data);
     168
    179169        usb_log_debug2("Batch(%p) checking %d packet(s) for completion.\n",
    180             instance, instance->packets);
     170            instance, data->packets);
    181171        instance->transfered_size = 0;
    182172        size_t i = 0;
    183         for (;i < instance->packets; ++i) {
    184                 if (td_is_active(&instance->tds[i])) {
     173        for (;i < data->packets; ++i) {
     174                if (td_is_active(&data->tds[i])) {
    185175                        return false;
    186176                }
    187177
    188                 instance->error = td_status(&instance->tds[i]);
     178                instance->error = td_status(&data->tds[i]);
    189179                if (instance->error != EOK) {
    190180                        usb_log_debug("Batch(%p) found error TD(%d):%x.\n",
    191                             instance, i, instance->tds[i].status);
    192                         td_print_status(&instance->tds[i]);
    193 
    194                         device_keeper_set_toggle(instance->manager,
    195                             instance->target, td_toggle(&instance->tds[i]));
     181                            instance, i, data->tds[i].status);
     182                        td_print_status(&data->tds[i]);
     183
     184                        usb_device_keeper_set_toggle(data->manager,
     185                            instance->target, instance->direction,
     186                            td_toggle(&data->tds[i]));
    196187                        if (i > 0)
    197188                                goto substract_ret;
     
    199190                }
    200191
    201                 instance->transfered_size += td_act_size(&instance->tds[i]);
    202                 if (td_is_short(&instance->tds[i]))
     192                instance->transfered_size += td_act_size(&data->tds[i]);
     193                if (td_is_short(&data->tds[i]))
    203194                        goto substract_ret;
    204195        }
     
    214205 * Uses genercir control function with pids OUT and IN.
    215206 */
    216 void batch_control_write(batch_t *instance)
     207void batch_control_write(usb_transfer_batch_t *instance)
    217208{
    218209        assert(instance);
     
    231222 * Uses generic control with pids IN and OUT.
    232223 */
    233 void batch_control_read(batch_t *instance)
     224void batch_control_read(usb_transfer_batch_t *instance)
    234225{
    235226        assert(instance);
     
    245236 * Data transaction with PID_IN.
    246237 */
    247 void batch_interrupt_in(batch_t *instance)
    248 {
    249         assert(instance);
     238void batch_interrupt_in(usb_transfer_batch_t *instance)
     239{
     240        assert(instance);
     241        instance->direction = USB_DIRECTION_IN;
    250242        batch_data(instance, USB_PID_IN);
    251243        instance->next_step = batch_call_in_and_dispose;
     
    259251 * Data transaction with PID_OUT.
    260252 */
    261 void batch_interrupt_out(batch_t *instance)
    262 {
    263         assert(instance);
     253void batch_interrupt_out(usb_transfer_batch_t *instance)
     254{
     255        assert(instance);
     256        instance->direction = USB_DIRECTION_OUT;
    264257        /* We are data out, we are supposed to provide data */
    265258        memcpy(instance->transport_buffer, instance->buffer,
     
    276269 * Data transaction with PID_IN.
    277270 */
    278 void batch_bulk_in(batch_t *instance)
     271void batch_bulk_in(usb_transfer_batch_t *instance)
    279272{
    280273        assert(instance);
    281274        batch_data(instance, USB_PID_IN);
     275        instance->direction = USB_DIRECTION_IN;
    282276        instance->next_step = batch_call_in_and_dispose;
    283277        usb_log_debug("Batch(%p) BULK IN initialized.\n", instance);
     
    290284 * Data transaction with PID_OUT.
    291285 */
    292 void batch_bulk_out(batch_t *instance)
    293 {
    294         assert(instance);
     286void batch_bulk_out(usb_transfer_batch_t *instance)
     287{
     288        assert(instance);
     289        instance->direction = USB_DIRECTION_OUT;
    295290        /* We are data out, we are supposed to provide data */
    296291        memcpy(instance->transport_buffer, instance->buffer,
     
    309304 * The last packet is marked with IOC flag.
    310305 */
    311 void batch_data(batch_t *instance, usb_packet_id pid)
    312 {
    313         assert(instance);
     306void batch_data(usb_transfer_batch_t *instance, usb_packet_id pid)
     307{
     308        assert(instance);
     309        uhci_batch_t *data = instance->private_data;
     310        assert(data);
     311
    314312        const bool low_speed = instance->speed == USB_SPEED_LOW;
    315         int toggle =
    316             device_keeper_get_toggle(instance->manager, instance->target);
     313        int toggle = usb_device_keeper_get_toggle(
     314            data->manager, instance->target, instance->direction);
    317315        assert(toggle == 0 || toggle == 1);
    318316
     
    320318        size_t remain_size = instance->buffer_size;
    321319        while (remain_size > 0) {
    322                 char *data =
     320                char *trans_data =
    323321                    instance->transport_buffer + instance->buffer_size
    324322                    - remain_size;
     
    328326                    remain_size : instance->max_packet_size;
    329327
    330                 td_t *next_packet = (packet + 1 < instance->packets)
    331                     ? &instance->tds[packet + 1] : NULL;
    332 
    333                 assert(packet < instance->packets);
     328                td_t *next_packet = (packet + 1 < data->packets)
     329                    ? &data->tds[packet + 1] : NULL;
     330
     331                assert(packet < data->packets);
    334332                assert(packet_size <= remain_size);
    335333
    336334                td_init(
    337                     &instance->tds[packet], DEFAULT_ERROR_COUNT, packet_size,
    338                     toggle, false, low_speed, instance->target, pid, data,
     335                    &data->tds[packet], DEFAULT_ERROR_COUNT, packet_size,
     336                    toggle, false, low_speed, instance->target, pid, trans_data,
    339337                    next_packet);
    340338
     
    344342                ++packet;
    345343        }
    346         td_set_ioc(&instance->tds[packet - 1]);
    347         device_keeper_set_toggle(instance->manager, instance->target, toggle);
     344        td_set_ioc(&data->tds[packet - 1]);
     345        usb_device_keeper_set_toggle(data->manager, instance->target,
     346            instance->direction, toggle);
    348347}
    349348/*----------------------------------------------------------------------------*/
     
    359358 * The last packet is marked with IOC.
    360359 */
    361 void batch_control(batch_t *instance,
     360void batch_control(usb_transfer_batch_t *instance,
    362361   usb_packet_id data_stage, usb_packet_id status_stage)
    363362{
    364363        assert(instance);
     364        uhci_batch_t *data = instance->private_data;
     365        assert(data);
     366        assert(data->packets >= 2);
    365367
    366368        const bool low_speed = instance->speed == USB_SPEED_LOW;
    367369        int toggle = 0;
    368370        /* setup stage */
    369         td_init(instance->tds, DEFAULT_ERROR_COUNT,
    370             instance->setup_size, toggle, false, low_speed, instance->target,
    371             USB_PID_SETUP, instance->setup_buffer, &instance->tds[1]);
     371        td_init(
     372            data->tds, DEFAULT_ERROR_COUNT, instance->setup_size, toggle, false,
     373            low_speed, instance->target, USB_PID_SETUP, instance->setup_buffer,
     374            &data->tds[1]);
    372375
    373376        /* data stage */
     
    375378        size_t remain_size = instance->buffer_size;
    376379        while (remain_size > 0) {
    377                 char *data =
     380                char *control_data =
    378381                    instance->transport_buffer + instance->buffer_size
    379382                    - remain_size;
     
    386389
    387390                td_init(
    388                     &instance->tds[packet], DEFAULT_ERROR_COUNT, packet_size,
     391                    &data->tds[packet], DEFAULT_ERROR_COUNT, packet_size,
    389392                    toggle, false, low_speed, instance->target, data_stage,
    390                     data, &instance->tds[packet + 1]);
     393                    control_data, &data->tds[packet + 1]);
    391394
    392395                ++packet;
    393                 assert(packet < instance->packets);
     396                assert(packet < data->packets);
    394397                assert(packet_size <= remain_size);
    395398                remain_size -= packet_size;
     
    397400
    398401        /* status stage */
    399         assert(packet == instance->packets - 1);
    400         td_init(&instance->tds[packet], DEFAULT_ERROR_COUNT,
    401             0, 1, false, low_speed, instance->target, status_stage, NULL, NULL);
    402 
    403         td_set_ioc(&instance->tds[packet]);
     402        assert(packet == data->packets - 1);
     403
     404        td_init(
     405            &data->tds[packet], DEFAULT_ERROR_COUNT, 0, 1, false, low_speed,
     406            instance->target, status_stage, NULL, NULL);
     407        td_set_ioc(&data->tds[packet]);
     408
    404409        usb_log_debug2("Control last TD status: %x.\n",
    405             instance->tds[packet].status);
    406 }
    407 /*----------------------------------------------------------------------------*/
    408 /** Prepare data, get error status and call callback in.
    409  *
    410  * @param[in] instance Batch structure to use.
    411  * Copies data from transport buffer, and calls callback with appropriate
    412  * parameters.
    413  */
    414 void batch_call_in(batch_t *instance)
    415 {
    416         assert(instance);
    417         assert(instance->callback_in);
    418 
    419         /* We are data in, we need data */
    420         memcpy(instance->buffer, instance->transport_buffer,
    421             instance->buffer_size);
    422 
    423         int err = instance->error;
    424         usb_log_debug("Batch(%p) callback IN(type:%d): %s(%d), %zu.\n",
    425             instance, instance->transfer_type, str_error(err), err,
    426             instance->transfered_size);
    427 
    428         instance->callback_in(
    429             instance->fun, err, instance->transfered_size, instance->arg);
    430 }
    431 /*----------------------------------------------------------------------------*/
    432 /** Get error status and call callback out.
    433  *
    434  * @param[in] instance Batch structure to use.
    435  */
    436 void batch_call_out(batch_t *instance)
    437 {
    438         assert(instance);
    439         assert(instance->callback_out);
    440 
    441         int err = instance->error;
    442         usb_log_debug("Batch(%p) callback OUT(type:%d): %s(%d).\n",
    443             instance, instance->transfer_type, str_error(err), err);
    444         instance->callback_out(instance->fun,
    445             err, instance->arg);
     410            data->tds[packet].status);
     411}
     412/*----------------------------------------------------------------------------*/
     413qh_t * batch_qh(usb_transfer_batch_t *instance)
     414{
     415        assert(instance);
     416        uhci_batch_t *data = instance->private_data;
     417        assert(data);
     418        return data->qh;
    446419}
    447420/*----------------------------------------------------------------------------*/
     
    450423 * @param[in] instance Batch structure to use.
    451424 */
    452 void batch_call_in_and_dispose(batch_t *instance)
    453 {
    454         assert(instance);
    455         batch_call_in(instance);
     425void batch_call_in_and_dispose(usb_transfer_batch_t *instance)
     426{
     427        assert(instance);
     428        usb_transfer_batch_call_in(instance);
    456429        batch_dispose(instance);
    457430}
     
    461434 * @param[in] instance Batch structure to use.
    462435 */
    463 void batch_call_out_and_dispose(batch_t *instance)
    464 {
    465         assert(instance);
    466         batch_call_out(instance);
     436void batch_call_out_and_dispose(usb_transfer_batch_t *instance)
     437{
     438        assert(instance);
     439        usb_transfer_batch_call_out(instance);
    467440        batch_dispose(instance);
    468441}
     
    472445 * @param[in] instance Batch structure to use.
    473446 */
    474 void batch_dispose(batch_t *instance)
    475 {
    476         assert(instance);
     447void batch_dispose(usb_transfer_batch_t *instance)
     448{
     449        assert(instance);
     450        uhci_batch_t *data = instance->private_data;
     451        assert(data);
    477452        usb_log_debug("Batch(%p) disposing.\n", instance);
    478453        /* free32 is NULL safe */
    479         free32(instance->tds);
    480         free32(instance->qh);
     454        free32(data->tds);
     455        free32(data->qh);
    481456        free32(instance->setup_buffer);
    482457        free32(instance->transport_buffer);
     458        free(data);
    483459        free(instance);
    484460}
  • uspace/drv/uhci-hcd/batch.h

    r4fb6d9ee re099f26  
    3939#include <usbhc_iface.h>
    4040#include <usb/usb.h>
     41#include <usb/host/device_keeper.h>
     42#include <usb/host/batch.h>
    4143
    42 #include "uhci_struct/transfer_descriptor.h"
    4344#include "uhci_struct/queue_head.h"
    44 #include "utils/device_keeper.h"
    4545
    46 typedef struct batch
    47 {
    48         link_t link;
    49         usb_speed_t speed;
    50         usb_target_t target;
    51         usb_transfer_type_t transfer_type;
    52         usbhc_iface_transfer_in_callback_t callback_in;
    53         usbhc_iface_transfer_out_callback_t callback_out;
    54         void *arg;
    55         char *transport_buffer;
    56         char *setup_buffer;
    57         size_t setup_size;
    58         char *buffer;
    59         size_t buffer_size;
    60         size_t max_packet_size;
    61         size_t packets;
    62         size_t transfered_size;
    63         int error;
    64         ddf_fun_t *fun;
    65         qh_t *qh;
    66         td_t *tds;
    67         void (*next_step)(struct batch*);
    68         device_keeper_t *manager;
    69 } batch_t;
    70 
    71 batch_t * batch_get(
     46usb_transfer_batch_t * batch_get(
    7247    ddf_fun_t *fun,
    7348                usb_target_t target,
     
    8257    usbhc_iface_transfer_out_callback_t func_out,
    8358                void *arg,
    84                 device_keeper_t *manager
     59                usb_device_keeper_t *manager
    8560                );
    8661
    87 void batch_dispose(batch_t *instance);
     62void batch_dispose(usb_transfer_batch_t *instance);
    8863
    89 void batch_abort(batch_t *instance);
     64bool batch_is_complete(usb_transfer_batch_t *instance);
    9065
    91 bool batch_is_complete(batch_t *instance);
     66void batch_control_write(usb_transfer_batch_t *instance);
    9267
    93 void batch_control_write(batch_t *instance);
     68void batch_control_read(usb_transfer_batch_t *instance);
    9469
    95 void batch_control_read(batch_t *instance);
     70void batch_interrupt_in(usb_transfer_batch_t *instance);
    9671
    97 void batch_interrupt_in(batch_t *instance);
     72void batch_interrupt_out(usb_transfer_batch_t *instance);
    9873
    99 void batch_interrupt_out(batch_t *instance);
     74void batch_bulk_in(usb_transfer_batch_t *instance);
    10075
    101 void batch_bulk_in(batch_t *instance);
     76void batch_bulk_out(usb_transfer_batch_t *instance);
    10277
    103 void batch_bulk_out(batch_t *instance);
     78qh_t * batch_qh(usb_transfer_batch_t *instance);
    10479#endif
    10580/**
  • uspace/drv/uhci-hcd/iface.c

    r4fb6d9ee re099f26  
    4141#include "iface.h"
    4242#include "uhci_hc.h"
    43 #include "utils/device_keeper.h"
    4443
    4544/** Reserve default address interface function
     
    5655        assert(hc);
    5756        usb_log_debug("Default address request with speed %d.\n", speed);
    58         device_keeper_reserve_default(&hc->device_manager, speed);
     57        usb_device_keeper_reserve_default_address(&hc->device_manager, speed);
    5958        return EOK;
    6059}
     
    7170        assert(hc);
    7271        usb_log_debug("Default address release.\n");
    73         device_keeper_release_default(&hc->device_manager);
     72        usb_device_keeper_release_default_address(&hc->device_manager);
    7473        return EOK;
    7574}
     
    9190
    9291        usb_log_debug("Address request with speed %d.\n", speed);
    93         *address = device_keeper_request(&hc->device_manager, speed);
     92        *address = device_keeper_get_free_address(&hc->device_manager, speed);
    9493        usb_log_debug("Address request with result: %d.\n", *address);
    9594        if (*address <= 0)
     
    112111        assert(hc);
    113112        usb_log_debug("Address bind %d-%d.\n", address, handle);
    114         device_keeper_bind(&hc->device_manager, address, handle);
     113        usb_device_keeper_bind(&hc->device_manager, address, handle);
    115114        return EOK;
    116115}
     
    128127        assert(hc);
    129128        usb_log_debug("Address release %d.\n", address);
    130         device_keeper_release(&hc->device_manager, address);
     129        usb_device_keeper_release(&hc->device_manager, address);
    131130        return EOK;
    132131}
     
    150149        uhci_hc_t *hc = fun_to_uhci_hc(fun);
    151150        assert(hc);
    152         usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
     151        usb_speed_t speed = usb_device_keeper_get_speed(&hc->device_manager, target.address);
    153152
    154153        usb_log_debug("Interrupt OUT %d:%d %zu(%zu).\n",
    155154            target.address, target.endpoint, size, max_packet_size);
    156155
    157         batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
     156        usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
    158157            max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg,
    159158            &hc->device_manager);
     
    187186        uhci_hc_t *hc = fun_to_uhci_hc(fun);
    188187        assert(hc);
    189         usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
     188        usb_speed_t speed = usb_device_keeper_get_speed(&hc->device_manager, target.address);
    190189        usb_log_debug("Interrupt IN %d:%d %zu(%zu).\n",
    191190            target.address, target.endpoint, size, max_packet_size);
    192191
    193         batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
     192        usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
    194193            max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg,
    195194                        &hc->device_manager);
     
    223222        uhci_hc_t *hc = fun_to_uhci_hc(fun);
    224223        assert(hc);
    225         usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
     224        usb_speed_t speed = usb_device_keeper_get_speed(&hc->device_manager, target.address);
    226225
    227226        usb_log_debug("Bulk OUT %d:%d %zu(%zu).\n",
    228227            target.address, target.endpoint, size, max_packet_size);
    229228
    230         batch_t *batch = batch_get(fun, target, USB_TRANSFER_BULK,
     229        usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_BULK,
    231230            max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg,
    232231            &hc->device_manager);
     
    260259        uhci_hc_t *hc = fun_to_uhci_hc(fun);
    261260        assert(hc);
    262         usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
     261        usb_speed_t speed = usb_device_keeper_get_speed(&hc->device_manager, target.address);
    263262        usb_log_debug("Bulk IN %d:%d %zu(%zu).\n",
    264263            target.address, target.endpoint, size, max_packet_size);
    265264
    266         batch_t *batch = batch_get(fun, target, USB_TRANSFER_BULK,
     265        usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_BULK,
    267266            max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg,
    268267            &hc->device_manager);
     
    299298        uhci_hc_t *hc = fun_to_uhci_hc(fun);
    300299        assert(hc);
    301         usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
     300        usb_speed_t speed = usb_device_keeper_get_speed(&hc->device_manager, target.address);
    302301        usb_log_debug("Control WRITE (%d) %d:%d %zu(%zu).\n",
    303302            speed, target.address, target.endpoint, size, max_packet_size);
     
    306305                return EINVAL;
    307306
    308         batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
     307        usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
    309308            max_packet_size, speed, data, size, setup_data, setup_size,
    310309            NULL, callback, arg, &hc->device_manager);
    311310        if (!batch)
    312311                return ENOMEM;
    313         device_keeper_reset_if_need(&hc->device_manager, target, setup_data);
     312        usb_device_keeper_reset_if_need(&hc->device_manager, target, setup_data);
    314313        batch_control_write(batch);
    315314        const int ret = uhci_hc_schedule(hc, batch);
     
    342341        uhci_hc_t *hc = fun_to_uhci_hc(fun);
    343342        assert(hc);
    344         usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
     343        usb_speed_t speed = usb_device_keeper_get_speed(&hc->device_manager, target.address);
    345344
    346345        usb_log_debug("Control READ(%d) %d:%d %zu(%zu).\n",
    347346            speed, target.address, target.endpoint, size, max_packet_size);
    348         batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
     347        usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
    349348            max_packet_size, speed, data, size, setup_data, setup_size, callback,
    350349            NULL, arg, &hc->device_manager);
  • uspace/drv/uhci-hcd/main.c

    r4fb6d9ee re099f26  
    6262int uhci_add_device(ddf_dev_t *device)
    6363{
    64         usb_log_info("uhci_add_device() called\n");
     64        usb_log_debug("uhci_add_device() called\n");
    6565        assert(device);
    6666        uhci_t *uhci = malloc(sizeof(uhci_t));
     
    7272        int ret = uhci_init(uhci, device);
    7373        if (ret != EOK) {
    74                 usb_log_error("Failed to initialzie UHCI driver.\n");
     74                usb_log_error("Failed to initialize UHCI driver: %s.\n",
     75                    str_error(ret));
    7576                return ret;
    7677        }
    7778        device->driver_data = uhci;
     79
     80        usb_log_info("Controlling new UHCI device `%s'.\n", device->name);
     81
    7882        return EOK;
    7983}
     
    8993int main(int argc, char *argv[])
    9094{
     95        printf(NAME ": HelenOS UHCI driver.\n");
     96
    9197        sleep(3); /* TODO: remove in final version */
    92         usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME);
     98        usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME);
    9399
    94100        return ddf_driver_main(&uhci_driver);
  • uspace/drv/uhci-hcd/transfer_list.c

    r4fb6d9ee re099f26  
    3838
    3939static void transfer_list_remove_batch(
    40     transfer_list_t *instance, batch_t *batch);
     40    transfer_list_t *instance, usb_transfer_batch_t *batch);
    4141/*----------------------------------------------------------------------------*/
    4242/** Initialize transfer list structures.
     
    9191 * The batch is added to the end of the list and queue.
    9292 */
    93 void transfer_list_add_batch(transfer_list_t *instance, batch_t *batch)
     93void transfer_list_add_batch(transfer_list_t *instance, usb_transfer_batch_t *batch)
    9494{
    9595        assert(instance);
    9696        assert(batch);
    9797        usb_log_debug2("Queue %s: Adding batch(%p).\n", instance->name, batch);
    98 
    9998
    10099        fibril_mutex_lock(&instance->guard);
     
    107106        } else {
    108107                /* There is something scheduled */
    109                 batch_t *last = list_get_instance(
    110                     instance->batch_list.prev, batch_t, link);
    111                 last_qh = last->qh;
     108                usb_transfer_batch_t *last = list_get_instance(
     109                    instance->batch_list.prev, usb_transfer_batch_t, link);
     110                last_qh = batch_qh(last);
    112111        }
    113112        const uint32_t pa = addr_to_phys(batch->qh);
    114113        assert((pa & LINK_POINTER_ADDRESS_MASK) == pa);
    115114
    116         batch->qh->next = last_qh->next;
     115        /* keep link */
     116        batch_qh(batch)->next = last_qh->next;
    117117        qh_set_next_qh(last_qh, pa);
    118118
     
    120120        list_append(&batch->link, &instance->batch_list);
    121121
    122         batch_t *first = list_get_instance(
    123             instance->batch_list.next, batch_t, link);
     122        usb_transfer_batch_t *first = list_get_instance(
     123            instance->batch_list.next, usb_transfer_batch_t, link);
    124124        usb_log_debug("Batch(%p) added to queue %s, first is %p.\n",
    125125                batch, instance->name, first);
     
    146146        while (current != &instance->batch_list) {
    147147                link_t *next = current->next;
    148                 batch_t *batch = list_get_instance(current, batch_t, link);
     148                usb_transfer_batch_t *batch = list_get_instance(current, usb_transfer_batch_t, link);
    149149
    150150                if (batch_is_complete(batch)) {
     
    160160                link_t *item = done.next;
    161161                list_remove(item);
    162                 batch_t *batch = list_get_instance(item, batch_t, link);
     162                usb_transfer_batch_t *batch = list_get_instance(item, usb_transfer_batch_t, link);
    163163                batch->next_step(batch);
    164164        }
     
    174174        while (!list_empty(&instance->batch_list)) {
    175175                link_t *current = instance->batch_list.next;
    176                 batch_t *batch = list_get_instance(current, batch_t, link);
     176                usb_transfer_batch_t *batch = list_get_instance(current, usb_transfer_batch_t, link);
    177177                transfer_list_remove_batch(instance, batch);
    178                 batch_abort(batch);
     178                usb_transfer_batch_finish(batch, EIO);
    179179        }
    180180        fibril_mutex_unlock(&instance->guard);
     
    189189 * Does not lock the transfer list, caller is responsible for that.
    190190 */
    191 void transfer_list_remove_batch(transfer_list_t *instance, batch_t *batch)
    192 {
    193         assert(instance);
     191void transfer_list_remove_batch(transfer_list_t *instance, usb_transfer_batch_t *batch)
     192{
     193        assert(instance);
     194        assert(instance->queue_head);
    194195        assert(batch);
    195         assert(instance->queue_head);
    196         assert(batch->qh);
     196        assert(batch_qh(batch));
    197197        assert(fibril_mutex_is_locked(&instance->guard));
    198198
     
    205205                /* I'm the first one here */
    206206                assert((instance->queue_head->next & LINK_POINTER_ADDRESS_MASK)
    207                     == addr_to_phys(batch->qh));
    208                 instance->queue_head->next = batch->qh->next;
     207                    == addr_to_phys(bathc_qh(batch)));
     208                instance->queue_head->next = batch_qh(batch)->next;
    209209                qpos = "FIRST";
    210210        } else {
    211                 batch_t *prev =
    212                     list_get_instance(batch->link.prev, batch_t, link);
    213                 assert((prev->qh->next & LINK_POINTER_ADDRESS_MASK)
    214                     == addr_to_phys(batch->qh));
    215                 prev->qh->next = batch->qh->next;
     211                usb_transfer_batch_t *prev =
     212                    list_get_instance(batch->link.prev, usb_transfer_batch_t, link);
     213                assert((batch_qh(prev)->next & LINK_POINTER_ADDRESS_MASK)
     214                    == addr_to_phys(batch_qh(batch)));
     215                batch_qh(prev)->next = batch_qh(batch)->next;
    216216                qpos = "NOT FIRST";
    217217        }
     
    219219        list_remove(&batch->link);
    220220        usb_log_debug("Batch(%p) removed (%s) from %s, next %x.\n",
    221             batch, qpos, instance->name, batch->qh->next);
     221            batch, pos, instance->name, batch_qh(batch)->next);
    222222}
    223223/**
  • uspace/drv/uhci-hcd/transfer_list.h

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

    r4fb6d9ee re099f26  
    7070{
    7171        assert(fun);
    72         device_keeper_t *manager = &((uhci_t*)fun->dev->driver_data)->hc.device_manager;
    73 
    74         usb_address_t addr = device_keeper_find(manager, handle);
     72        usb_device_keeper_t *manager = &((uhci_t*)fun->dev->driver_data)->hc.device_manager;
     73
     74        usb_address_t addr = usb_device_keeper_find(manager, handle);
    7575        if (addr < 0) {
    7676                return addr;
     
    167167        CHECK_RET_DEST_FUN_RETURN(ret,
    168168            "Failed(%d) to get I/O addresses:.\n", ret, device->handle);
    169         usb_log_info("I/O regs at 0x%X (size %zu), IRQ %d.\n",
     169        usb_log_debug("I/O regs at 0x%X (size %zu), IRQ %d.\n",
    170170            io_reg_base, io_reg_size, irq);
    171171
  • uspace/drv/uhci-hcd/uhci_hc.c

    r4fb6d9ee re099f26  
    121121                    fibril_create(uhci_hc_interrupt_emulator, instance);
    122122                fibril_add_ready(instance->cleaner);
     123        } else {
     124                /* TODO: enable interrupts here */
    123125        }
    124126
     
    127129//      fibril_add_ready(instance->debug_checker);
    128130
    129         usb_log_info("Started UHCI driver.\n");
    130131        return EOK;
    131132#undef CHECK_RET_DEST_FUN_RETURN
     
    235236
    236237        /* Init device keeper*/
    237         device_keeper_init(&instance->device_manager);
     238        usb_device_keeper_init(&instance->device_manager);
    238239        usb_log_debug("Initialized device manager.\n");
    239240
     
    317318 * Checks for bandwidth availability and appends the batch to the proper queue.
    318319 */
    319 int uhci_hc_schedule(uhci_hc_t *instance, batch_t *batch)
     320int uhci_hc_schedule(uhci_hc_t *instance, usb_transfer_batch_t *batch)
    320321{
    321322        assert(instance);
  • uspace/drv/uhci-hcd/uhci_hc.h

    r4fb6d9ee re099f26  
    4242
    4343#include <usbhc_iface.h>
     44#include <usb/host/device_keeper.h>
    4445
    4546#include "batch.h"
    4647#include "transfer_list.h"
    47 #include "utils/device_keeper.h"
    4848
    4949typedef struct uhci_regs {
     
    8383
    8484typedef struct uhci_hc {
    85         device_keeper_t device_manager;
     85        usb_device_keeper_t device_manager;
    8686
    8787        regs_t *registers;
     
    109109    void *regs, size_t reg_size, bool interupts);
    110110
    111 int uhci_hc_schedule(uhci_hc_t *instance, batch_t *batch);
     111int uhci_hc_schedule(uhci_hc_t *instance, usb_transfer_batch_t *batch);
    112112
    113113void uhci_hc_interrupt(uhci_hc_t *instance, uint16_t status);
Note: See TracChangeset for help on using the changeset viewer.