Changeset f97717d9 in mainline for uspace/drv/uhci-hcd/iface.c


Ignore:
Timestamp:
2011-03-25T16:22:14Z (14 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
da3dafc, e6223239
Parents:
d8421c4 (diff), f08c560 (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 from development

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci-hcd/iface.c

    rd8421c4 rf97717d9  
    3333 */
    3434#include <ddf/driver.h>
    35 #include <remote_usbhc.h>
     35#include <errno.h>
    3636
    3737#include <usb/debug.h>
    3838
    39 #include <errno.h>
    40 
    4139#include "iface.h"
    42 #include "uhci_hc.h"
     40#include "hc.h"
    4341
    4442/** Reserve default address interface function
     
    4846 * @return Error code.
    4947 */
    50 /*----------------------------------------------------------------------------*/
    5148static int reserve_default_address(ddf_fun_t *fun, usb_speed_t speed)
    5249{
    5350        assert(fun);
    54         uhci_hc_t *hc = fun_to_uhci_hc(fun);
     51        hc_t *hc = fun_to_hc(fun);
    5552        assert(hc);
    5653        usb_log_debug("Default address request with speed %d.\n", speed);
    57         usb_device_keeper_reserve_default_address(&hc->device_manager, speed);
     54        usb_device_keeper_reserve_default_address(&hc->manager, speed);
    5855        return EOK;
    5956}
     
    6764{
    6865        assert(fun);
    69         uhci_hc_t *hc = fun_to_uhci_hc(fun);
     66        hc_t *hc = fun_to_hc(fun);
    7067        assert(hc);
    7168        usb_log_debug("Default address release.\n");
    72         usb_device_keeper_release_default_address(&hc->device_manager);
     69        usb_device_keeper_release_default_address(&hc->manager);
    7370        return EOK;
    7471}
     
    8178 * @return Error code.
    8279 */
    83 static int request_address(ddf_fun_t *fun, usb_speed_t speed,
    84     usb_address_t *address)
    85 {
    86         assert(fun);
    87         uhci_hc_t *hc = fun_to_uhci_hc(fun);
     80static int request_address(
     81    ddf_fun_t *fun, usb_speed_t speed, usb_address_t *address)
     82{
     83        assert(fun);
     84        hc_t *hc = fun_to_hc(fun);
    8885        assert(hc);
    8986        assert(address);
    9087
    9188        usb_log_debug("Address request with speed %d.\n", speed);
    92         *address = device_keeper_get_free_address(&hc->device_manager, speed);
     89        *address = device_keeper_get_free_address(&hc->manager, speed);
    9390        usb_log_debug("Address request with result: %d.\n", *address);
    9491        if (*address <= 0)
    95           return *address;
     92                return *address;
    9693        return EOK;
    9794}
     
    108105{
    109106        assert(fun);
    110         uhci_hc_t *hc = fun_to_uhci_hc(fun);
     107        hc_t *hc = fun_to_hc(fun);
    111108        assert(hc);
    112109        usb_log_debug("Address bind %d-%d.\n", address, handle);
    113         usb_device_keeper_bind(&hc->device_manager, address, handle);
     110        usb_device_keeper_bind(&hc->manager, address, handle);
    114111        return EOK;
    115112}
     
    124121{
    125122        assert(fun);
    126         uhci_hc_t *hc = fun_to_uhci_hc(fun);
     123        hc_t *hc = fun_to_hc(fun);
    127124        assert(hc);
    128125        usb_log_debug("Address release %d.\n", address);
    129         usb_device_keeper_release(&hc->device_manager, address);
     126        usb_device_keeper_release(&hc->manager, address);
    130127        return EOK;
    131128}
     
    142139 * @return Error code.
    143140 */
    144 static int interrupt_out(ddf_fun_t *fun, usb_target_t target,
    145     size_t max_packet_size, void *data, size_t size,
    146     usbhc_iface_transfer_out_callback_t callback, void *arg)
    147 {
    148         assert(fun);
    149         uhci_hc_t *hc = fun_to_uhci_hc(fun);
    150         assert(hc);
    151         usb_speed_t speed = usb_device_keeper_get_speed(&hc->device_manager, target.address);
     141static int interrupt_out(
     142    ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, void *data,
     143    size_t size, usbhc_iface_transfer_out_callback_t callback, void *arg)
     144{
     145        assert(fun);
     146        hc_t *hc = fun_to_hc(fun);
     147        assert(hc);
     148        usb_speed_t speed =
     149            usb_device_keeper_get_speed(&hc->manager, target.address);
    152150
    153151        usb_log_debug("Interrupt OUT %d:%d %zu(%zu).\n",
    154152            target.address, target.endpoint, size, max_packet_size);
    155153
    156         usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
    157             max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg,
    158             &hc->device_manager);
     154        usb_transfer_batch_t *batch =
     155            batch_get(fun, target, USB_TRANSFER_INTERRUPT, max_packet_size,
     156                speed, data, size, NULL, 0, NULL, callback, arg, &hc->manager);
    159157        if (!batch)
    160158                return ENOMEM;
    161159        batch_interrupt_out(batch);
    162         const int ret = uhci_hc_schedule(hc, batch);
    163         if (ret != EOK) {
    164                 batch_dispose(batch);
    165                 return ret;
    166         }
    167         return EOK;
     160        const int ret = hc_schedule(hc, batch);
     161        if (ret != EOK) {
     162                batch_dispose(batch);
     163        }
     164        return ret;
    168165}
    169166/*----------------------------------------------------------------------------*/
     
    179176 * @return Error code.
    180177 */
    181 static int interrupt_in(ddf_fun_t *fun, usb_target_t target,
    182     size_t max_packet_size, void *data, size_t size,
    183     usbhc_iface_transfer_in_callback_t callback, void *arg)
    184 {
    185         assert(fun);
    186         uhci_hc_t *hc = fun_to_uhci_hc(fun);
    187         assert(hc);
    188         usb_speed_t speed = usb_device_keeper_get_speed(&hc->device_manager, target.address);
     178static int interrupt_in(
     179    ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, void *data,
     180    size_t size, usbhc_iface_transfer_in_callback_t callback, void *arg)
     181{
     182        assert(fun);
     183        hc_t *hc = fun_to_hc(fun);
     184        assert(hc);
     185        usb_speed_t speed =
     186            usb_device_keeper_get_speed(&hc->manager, target.address);
    189187        usb_log_debug("Interrupt IN %d:%d %zu(%zu).\n",
    190188            target.address, target.endpoint, size, max_packet_size);
    191189
    192         usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
    193             max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg,
    194                         &hc->device_manager);
     190        usb_transfer_batch_t *batch =
     191            batch_get(fun, target, USB_TRANSFER_INTERRUPT, max_packet_size,
     192                speed, data, size, NULL, 0, callback, NULL, arg, &hc->manager);
    195193        if (!batch)
    196194                return ENOMEM;
    197195        batch_interrupt_in(batch);
    198         const int ret = uhci_hc_schedule(hc, batch);
    199         if (ret != EOK) {
    200                 batch_dispose(batch);
    201                 return ret;
    202         }
    203         return EOK;
     196        const int ret = hc_schedule(hc, batch);
     197        if (ret != EOK) {
     198                batch_dispose(batch);
     199        }
     200        return ret;
    204201}
    205202/*----------------------------------------------------------------------------*/
     
    215212 * @return Error code.
    216213 */
    217 static int bulk_out(ddf_fun_t *fun, usb_target_t target,
    218     size_t max_packet_size, void *data, size_t size,
    219     usbhc_iface_transfer_out_callback_t callback, void *arg)
    220 {
    221         assert(fun);
    222         uhci_hc_t *hc = fun_to_uhci_hc(fun);
    223         assert(hc);
    224         usb_speed_t speed = usb_device_keeper_get_speed(&hc->device_manager, target.address);
     214static int bulk_out(
     215    ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, void *data,
     216    size_t size, usbhc_iface_transfer_out_callback_t callback, void *arg)
     217{
     218        assert(fun);
     219        hc_t *hc = fun_to_hc(fun);
     220        assert(hc);
     221        usb_speed_t speed =
     222            usb_device_keeper_get_speed(&hc->manager, target.address);
    225223
    226224        usb_log_debug("Bulk OUT %d:%d %zu(%zu).\n",
    227225            target.address, target.endpoint, size, max_packet_size);
    228226
    229         usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_BULK,
    230             max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg,
    231             &hc->device_manager);
     227        usb_transfer_batch_t *batch =
     228            batch_get(fun, target, USB_TRANSFER_BULK, max_packet_size, speed,
     229                data, size, NULL, 0, NULL, callback, arg, &hc->manager);
    232230        if (!batch)
    233231                return ENOMEM;
    234232        batch_bulk_out(batch);
    235         const int ret = uhci_hc_schedule(hc, batch);
    236         if (ret != EOK) {
    237                 batch_dispose(batch);
    238                 return ret;
    239         }
    240         return EOK;
     233        const int ret = hc_schedule(hc, batch);
     234        if (ret != EOK) {
     235                batch_dispose(batch);
     236        }
     237        return ret;
    241238}
    242239/*----------------------------------------------------------------------------*/
     
    252249 * @return Error code.
    253250 */
    254 static int bulk_in(ddf_fun_t *fun, usb_target_t target,
    255     size_t max_packet_size, void *data, size_t size,
    256     usbhc_iface_transfer_in_callback_t callback, void *arg)
    257 {
    258         assert(fun);
    259         uhci_hc_t *hc = fun_to_uhci_hc(fun);
    260         assert(hc);
    261         usb_speed_t speed = usb_device_keeper_get_speed(&hc->device_manager, target.address);
     251static int bulk_in(
     252    ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, void *data,
     253    size_t size, usbhc_iface_transfer_in_callback_t callback, void *arg)
     254{
     255        assert(fun);
     256        hc_t *hc = fun_to_hc(fun);
     257        assert(hc);
     258        usb_speed_t speed =
     259            usb_device_keeper_get_speed(&hc->manager, target.address);
    262260        usb_log_debug("Bulk IN %d:%d %zu(%zu).\n",
    263261            target.address, target.endpoint, size, max_packet_size);
    264262
    265         usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_BULK,
    266             max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg,
    267             &hc->device_manager);
     263        usb_transfer_batch_t *batch =
     264            batch_get(fun, target, USB_TRANSFER_BULK, max_packet_size, speed,
     265                data, size, NULL, 0, callback, NULL, arg, &hc->manager);
    268266        if (!batch)
    269267                return ENOMEM;
    270268        batch_bulk_in(batch);
    271         const int ret = uhci_hc_schedule(hc, batch);
    272         if (ret != EOK) {
    273                 batch_dispose(batch);
    274                 return ret;
    275         }
    276         return EOK;
     269        const int ret = hc_schedule(hc, batch);
     270        if (ret != EOK) {
     271                batch_dispose(batch);
     272        }
     273        return ret;
    277274}
    278275/*----------------------------------------------------------------------------*/
     
    282279 * @param[in] target USB device to write to.
    283280 * @param[in] max_packet_size maximum size of data packet the device accepts.
    284  * @param[in] setup_data Data to send with SETUP packet.
    285  * @param[in] setup_size Size of data to send with SETUP packet (should be 8B).
     281 * @param[in] setup_data Data to send with SETUP transfer.
     282 * @param[in] setup_size Size of data to send with SETUP transfer (always 8B).
    286283 * @param[in] data Source of data.
    287284 * @param[in] size Size of data source.
     
    290287 * @return Error code.
    291288 */
    292 static int control_write(ddf_fun_t *fun, usb_target_t target,
    293     size_t max_packet_size,
     289static int control_write(
     290    ddf_fun_t *fun, usb_target_t target, size_t max_packet_size,
    294291    void *setup_data, size_t setup_size, void *data, size_t size,
    295292    usbhc_iface_transfer_out_callback_t callback, void *arg)
    296293{
    297294        assert(fun);
    298         uhci_hc_t *hc = fun_to_uhci_hc(fun);
    299         assert(hc);
    300         usb_speed_t speed = usb_device_keeper_get_speed(&hc->device_manager, target.address);
     295        hc_t *hc = fun_to_hc(fun);
     296        assert(hc);
     297        usb_speed_t speed =
     298            usb_device_keeper_get_speed(&hc->manager, target.address);
    301299        usb_log_debug("Control WRITE (%d) %d:%d %zu(%zu).\n",
    302300            speed, target.address, target.endpoint, size, max_packet_size);
     
    305303                return EINVAL;
    306304
    307         usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
    308             max_packet_size, speed, data, size, setup_data, setup_size,
    309             NULL, callback, arg, &hc->device_manager);
    310         if (!batch)
    311                 return ENOMEM;
    312         usb_device_keeper_reset_if_need(&hc->device_manager, target, setup_data);
     305        usb_transfer_batch_t *batch =
     306            batch_get(fun, target, USB_TRANSFER_CONTROL, max_packet_size, speed,
     307                data, size, setup_data, setup_size, NULL, callback, arg,
     308                &hc->manager);
     309        if (!batch)
     310                return ENOMEM;
     311        usb_device_keeper_reset_if_need(&hc->manager, target, setup_data);
    313312        batch_control_write(batch);
    314         const int ret = uhci_hc_schedule(hc, batch);
    315         if (ret != EOK) {
    316                 batch_dispose(batch);
    317                 return ret;
    318         }
    319         return EOK;
     313        const int ret = hc_schedule(hc, batch);
     314        if (ret != EOK) {
     315                batch_dispose(batch);
     316        }
     317        return ret;
    320318}
    321319/*----------------------------------------------------------------------------*/
     
    333331 * @return Error code.
    334332 */
    335 static int control_read(ddf_fun_t *fun, usb_target_t target,
    336     size_t max_packet_size,
     333static int control_read(
     334    ddf_fun_t *fun, usb_target_t target, size_t max_packet_size,
    337335    void *setup_data, size_t setup_size, void *data, size_t size,
    338336    usbhc_iface_transfer_in_callback_t callback, void *arg)
    339337{
    340338        assert(fun);
    341         uhci_hc_t *hc = fun_to_uhci_hc(fun);
    342         assert(hc);
    343         usb_speed_t speed = usb_device_keeper_get_speed(&hc->device_manager, target.address);
     339        hc_t *hc = fun_to_hc(fun);
     340        assert(hc);
     341        usb_speed_t speed =
     342            usb_device_keeper_get_speed(&hc->manager, target.address);
    344343
    345344        usb_log_debug("Control READ(%d) %d:%d %zu(%zu).\n",
    346345            speed, target.address, target.endpoint, size, max_packet_size);
    347         usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
    348             max_packet_size, speed, data, size, setup_data, setup_size, callback,
    349             NULL, arg, &hc->device_manager);
     346        usb_transfer_batch_t *batch =
     347            batch_get(fun, target, USB_TRANSFER_CONTROL, max_packet_size, speed,
     348                data, size, setup_data, setup_size, callback, NULL, arg,
     349                &hc->manager);
    350350        if (!batch)
    351351                return ENOMEM;
    352352        batch_control_read(batch);
    353         const int ret = uhci_hc_schedule(hc, batch);
    354         if (ret != EOK) {
    355                 batch_dispose(batch);
    356                 return ret;
    357         }
    358         return EOK;
    359 }
    360 /*----------------------------------------------------------------------------*/
    361 usbhc_iface_t uhci_hc_iface = {
     353        const int ret = hc_schedule(hc, batch);
     354        if (ret != EOK) {
     355                batch_dispose(batch);
     356        }
     357        return ret;
     358}
     359/*----------------------------------------------------------------------------*/
     360usbhc_iface_t hc_iface = {
    362361        .reserve_default_address = reserve_default_address,
    363362        .release_default_address = release_default_address,
     
    369368        .interrupt_in = interrupt_in,
    370369
     370        .bulk_out = bulk_out,
    371371        .bulk_in = bulk_in,
    372         .bulk_out = bulk_out,
    373 
     372
     373        .control_write = control_write,
    374374        .control_read = control_read,
    375         .control_write = control_write,
    376375};
    377376/**
Note: See TracChangeset for help on using the changeset viewer.