Changeset efdfebc in mainline for uspace/drv/bus/usb/usbmast/main.c


Ignore:
Timestamp:
2012-11-06T21:03:44Z (11 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
338810f
Parents:
de73242 (diff), 94795812 (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 mainline changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbmast/main.c

    rde73242 refdfebc  
    3737#include <as.h>
    3838#include <async.h>
    39 #include <ipc/bd.h>
     39#include <bd_srv.h>
    4040#include <macros.h>
    4141#include <usb/dev/driver.h>
     
    8282    void *arg);
    8383
     84static int usbmast_bd_open(bd_srvs_t *, bd_srv_t *);
     85static int usbmast_bd_close(bd_srv_t *);
     86static int usbmast_bd_read_blocks(bd_srv_t *, aoff64_t, size_t, void *, size_t);
     87static int usbmast_bd_write_blocks(bd_srv_t *, aoff64_t, size_t, const void *, size_t);
     88static int usbmast_bd_get_block_size(bd_srv_t *, size_t *);
     89static int usbmast_bd_get_num_blocks(bd_srv_t *, aoff64_t *);
     90
     91static bd_ops_t usbmast_bd_ops = {
     92        .open = usbmast_bd_open,
     93        .close = usbmast_bd_close,
     94        .read_blocks = usbmast_bd_read_blocks,
     95        .write_blocks = usbmast_bd_write_blocks,
     96        .get_block_size = usbmast_bd_get_block_size,
     97        .get_num_blocks = usbmast_bd_get_num_blocks
     98};
     99
     100static usbmast_fun_t *bd_srv_usbmast(bd_srv_t *bd)
     101{
     102        return (usbmast_fun_t *) bd->srvs->sarg;
     103}
     104
    84105/** Callback when a device is removed from the system.
    85106 *
     
    139160        mdev->usb_dev = dev;
    140161
    141         usb_log_info("Initializing mass storage `%s'.\n", dev->ddf_dev->name);
     162        usb_log_info("Initializing mass storage `%s'.\n", ddf_dev_get_name(dev->ddf_dev));
    142163        usb_log_debug("Bulk in endpoint: %d [%zuB].\n",
    143164            dev->pipes[BULK_IN_EP].pipe.endpoint_no,
     
    219240        mfun->lun = lun;
    220241
     242        bd_srvs_init(&mfun->bds);
     243        mfun->bds.ops = &usbmast_bd_ops;
     244        mfun->bds.sarg = mfun;
     245
    221246        /* Set up a connection handler. */
    222         fun->conn_handler = usbmast_bd_connection;
     247        ddf_fun_set_conn_handler(fun, usbmast_bd_connection);
    223248
    224249        usb_log_debug("Inquire...\n");
     
    227252        if (rc != EOK) {
    228253                usb_log_warning("Failed to inquire device `%s': %s.\n",
    229                     mdev->ddf_dev->name, str_error(rc));
     254                    ddf_dev_get_name(mdev->ddf_dev), str_error(rc));
    230255                rc = EIO;
    231256                goto error;
     
    234259        usb_log_info("Mass storage `%s' LUN %u: " \
    235260            "%s by %s rev. %s is %s (%s).\n",
    236             mdev->ddf_dev->name,
     261            ddf_dev_get_name(mdev->ddf_dev),
    237262            lun,
    238263            inquiry.product,
     
    247272        if (rc != EOK) {
    248273                usb_log_warning("Failed to read capacity, device `%s': %s.\n",
    249                     mdev->ddf_dev->name, str_error(rc));
     274                    ddf_dev_get_name(mdev->ddf_dev), str_error(rc));
    250275                rc = EIO;
    251276                goto error;
     
    284309{
    285310        usbmast_fun_t *mfun;
    286         void *comm_buf = NULL;
    287         size_t comm_size;
    288         ipc_callid_t callid;
    289         ipc_call_t call;
    290         unsigned int flags;
    291         sysarg_t method;
    292         uint64_t ba;
    293         size_t cnt;
    294         int retval;
    295 
    296         async_answer_0(iid, EOK);
    297 
    298         if (!async_share_out_receive(&callid, &comm_size, &flags)) {
    299                 async_answer_0(callid, EHANGUP);
    300                 return;
    301         }
    302        
    303         (void) async_share_out_finalize(callid, &comm_buf);
    304         if (comm_buf == AS_MAP_FAILED) {
    305                 async_answer_0(callid, EHANGUP);
    306                 return;
    307         }
    308        
    309         mfun = (usbmast_fun_t *) ((ddf_fun_t *)arg)->driver_data;
    310 
    311         while (true) {
    312                 callid = async_get_call(&call);
    313                 method = IPC_GET_IMETHOD(call);
    314 
    315                 if (!method) {
    316                         /* The other side hung up. */
    317                         async_answer_0(callid, EOK);
    318                         return;
    319                 }
    320 
    321                 switch (method) {
    322                 case BD_GET_BLOCK_SIZE:
    323                         async_answer_1(callid, EOK, mfun->block_size);
    324                         break;
    325                 case BD_GET_NUM_BLOCKS:
    326                         async_answer_2(callid, EOK, LOWER32(mfun->nblocks),
    327                             UPPER32(mfun->nblocks));
    328                         break;
    329                 case BD_READ_BLOCKS:
    330                         ba = MERGE_LOUP32(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
    331                         cnt = IPC_GET_ARG3(call);
    332                         retval = usbmast_read(mfun, ba, cnt, comm_buf);
    333                         async_answer_0(callid, retval);
    334                         break;
    335                 case BD_WRITE_BLOCKS:
    336                         ba = MERGE_LOUP32(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
    337                         cnt = IPC_GET_ARG3(call);
    338                         retval = usbmast_write(mfun, ba, cnt, comm_buf);
    339                         async_answer_0(callid, retval);
    340                         break;
    341                 default:
    342                         async_answer_0(callid, EINVAL);
    343                 }
    344         }
    345 }
     311
     312        mfun = (usbmast_fun_t *) ddf_fun_data_get((ddf_fun_t *)arg);
     313        bd_conn(iid, icall, &mfun->bds);
     314}
     315
     316/** Open device. */
     317static int usbmast_bd_open(bd_srvs_t *bds, bd_srv_t *bd)
     318{
     319        return EOK;
     320}
     321
     322/** Close device. */
     323static int usbmast_bd_close(bd_srv_t *bd)
     324{
     325        return EOK;
     326}
     327
     328/** Read blocks from the device. */
     329static int usbmast_bd_read_blocks(bd_srv_t *bd, uint64_t ba, size_t cnt, void *buf,
     330    size_t size)
     331{
     332        usbmast_fun_t *mfun = bd_srv_usbmast(bd);
     333
     334        if (size < cnt * mfun->block_size)
     335                return EINVAL;
     336
     337        return usbmast_read(mfun, ba, cnt, buf);
     338}
     339
     340/** Write blocks to the device. */
     341static int usbmast_bd_write_blocks(bd_srv_t *bd, uint64_t ba, size_t cnt,
     342    const void *buf, size_t size)
     343{
     344        usbmast_fun_t *mfun = bd_srv_usbmast(bd);
     345
     346        if (size < cnt * mfun->block_size)
     347                return EINVAL;
     348
     349        return usbmast_write(mfun, ba, cnt, buf);
     350}
     351
     352/** Get device block size. */
     353static int usbmast_bd_get_block_size(bd_srv_t *bd, size_t *rsize)
     354{
     355        usbmast_fun_t *mfun = bd_srv_usbmast(bd);
     356        *rsize = mfun->block_size;
     357        return EOK;
     358}
     359
     360/** Get number of blocks on device. */
     361static int usbmast_bd_get_num_blocks(bd_srv_t *bd, aoff64_t *rnb)
     362{
     363        usbmast_fun_t *mfun = bd_srv_usbmast(bd);
     364        *rnb = mfun->nblocks;
     365        return EOK;
     366}
     367
    346368
    347369/** USB mass storage driver ops. */
     
    361383int main(int argc, char *argv[])
    362384{
    363         usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME);
     385        log_init(NAME);
    364386
    365387        return usb_driver_main(&usbmast_driver);
Note: See TracChangeset for help on using the changeset viewer.