Ignore:
File:
1 edited

Legend:

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

    r135486d rfaba839  
    3737#include <as.h>
    3838#include <async.h>
    39 #include <bd_srv.h>
     39#include <ipc/bd.h>
    4040#include <macros.h>
    4141#include <usb/dev/driver.h>
     
    8181static void usbmast_bd_connection(ipc_callid_t iid, ipc_call_t *icall,
    8282    void *arg);
    83 
    84 static int usbmast_bd_open(bd_srvs_t *, bd_srv_t *);
    85 static int usbmast_bd_close(bd_srv_t *);
    86 static int usbmast_bd_read_blocks(bd_srv_t *, aoff64_t, size_t, void *, size_t);
    87 static int usbmast_bd_write_blocks(bd_srv_t *, aoff64_t, size_t, const void *, size_t);
    88 static int usbmast_bd_get_block_size(bd_srv_t *, size_t *);
    89 static int usbmast_bd_get_num_blocks(bd_srv_t *, aoff64_t *);
    90 
    91 static 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 
    100 static usbmast_fun_t *bd_srv_usbmast(bd_srv_t *bd)
    101 {
    102         return (usbmast_fun_t *)bd->srvs->sarg;
    103 }
    10483
    10584/** Callback when a device is removed from the system.
     
    240219        mfun->lun = lun;
    241220
    242         bd_srvs_init(&mfun->bds);
    243         mfun->bds.ops = &usbmast_bd_ops;
    244         mfun->bds.sarg = mfun;
    245 
    246221        /* Set up a connection handler. */
    247222        fun->conn_handler = usbmast_bd_connection;
     
    309284{
    310285        usbmast_fun_t *mfun;
    311 
     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       
    312309        mfun = (usbmast_fun_t *) ((ddf_fun_t *)arg)->driver_data;
    313         bd_conn(iid, icall, &mfun->bds);
    314 }
    315 
    316 /** Open device. */
    317 static int usbmast_bd_open(bd_srvs_t *bds, bd_srv_t *bd)
    318 {
    319         return EOK;
    320 }
    321 
    322 /** Close device. */
    323 static int usbmast_bd_close(bd_srv_t *bd)
    324 {
    325         return EOK;
    326 }
    327 
    328 /** Read blocks from the device. */
    329 static 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. */
    341 static 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. */
    353 static 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. */
    361 static 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 
     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}
    368346
    369347/** USB mass storage driver ops. */
Note: See TracChangeset for help on using the changeset viewer.