Changes in uspace/drv/bus/usb/usbmast/main.c [faba839:56fd7cf] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbmast/main.c
rfaba839 r56fd7cf 37 37 #include <as.h> 38 38 #include <async.h> 39 #include < ipc/bd.h>39 #include <bd_srv.h> 40 40 #include <macros.h> 41 41 #include <usb/dev/driver.h> … … 82 82 void *arg); 83 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 } 104 84 105 /** Callback when a device is removed from the system. 85 106 * … … 139 160 mdev->usb_dev = dev; 140 161 141 usb_log_info("Initializing mass storage `%s'.\n", d ev->ddf_dev->name);162 usb_log_info("Initializing mass storage `%s'.\n", ddf_dev_get_name(dev->ddf_dev)); 142 163 usb_log_debug("Bulk in endpoint: %d [%zuB].\n", 143 164 dev->pipes[BULK_IN_EP].pipe.endpoint_no, … … 219 240 mfun->lun = lun; 220 241 242 bd_srvs_init(&mfun->bds); 243 mfun->bds.ops = &usbmast_bd_ops; 244 mfun->bds.sarg = mfun; 245 221 246 /* Set up a connection handler. */ 222 fun->conn_handler = usbmast_bd_connection;247 ddf_fun_set_conn_handler(fun, usbmast_bd_connection); 223 248 224 249 usb_log_debug("Inquire...\n"); … … 227 252 if (rc != EOK) { 228 253 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)); 230 255 rc = EIO; 231 256 goto error; … … 234 259 usb_log_info("Mass storage `%s' LUN %u: " \ 235 260 "%s by %s rev. %s is %s (%s).\n", 236 mdev->ddf_dev->name,261 ddf_dev_get_name(mdev->ddf_dev), 237 262 lun, 238 263 inquiry.product, … … 247 272 if (rc != EOK) { 248 273 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)); 250 275 rc = EIO; 251 276 goto error; … … 284 309 { 285 310 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. */ 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 346 368 347 369 /** USB mass storage driver ops. */
Note:
See TracChangeset
for help on using the changeset viewer.