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


Ignore:
Timestamp:
2012-08-14T19:27:42Z (12 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f7ea5400
Parents:
14c5005 (diff), 4802dd7 (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

    r14c5005 r9dec6d4  
    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_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->arg;
     103}
     104
    84105/** Callback when a device is removed from the system.
    85106 *
     
    219240        mfun->lun = lun;
    220241
     242        bd_srv_init(&mfun->bd);
     243        mfun->bd.ops = &usbmast_bd_ops;
     244        mfun->bd.arg = mfun;
     245
    221246        /* Set up a connection handler. */
    222247        fun->conn_handler = usbmast_bd_connection;
     
    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        
     311
    309312        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 }
     313        bd_conn(iid, icall, &mfun->bd);
     314}
     315
     316/** Open device. */
     317static int usbmast_bd_open(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. */
Note: See TracChangeset for help on using the changeset viewer.