Changes in uspace/drv/bus/usb/usbmast/main.c [920d0fc:fbcdeb8] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbmast/main.c
r920d0fc rfbcdeb8 37 37 #include <as.h> 38 38 #include <async.h> 39 #include < bd_srv.h>39 #include <ipc/bd.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_blocks98 };99 100 static usbmast_fun_t *bd_srv_usbmast(bd_srv_t *bd)101 {102 return (usbmast_fun_t *) bd->srvs->sarg;103 }104 105 84 /** Callback when a device is removed from the system. 106 85 * … … 160 139 mdev->usb_dev = dev; 161 140 162 usb_log_info("Initializing mass storage `%s'.\n", d df_dev_get_name(dev->ddf_dev));141 usb_log_info("Initializing mass storage `%s'.\n", dev->ddf_dev->name); 163 142 usb_log_debug("Bulk in endpoint: %d [%zuB].\n", 164 143 dev->pipes[BULK_IN_EP].pipe.endpoint_no, … … 240 219 mfun->lun = lun; 241 220 242 bd_srvs_init(&mfun->bds);243 mfun->bds.ops = &usbmast_bd_ops;244 mfun->bds.sarg = mfun;245 246 221 /* Set up a connection handler. */ 247 ddf_fun_set_conn_handler(fun, usbmast_bd_connection);222 fun->conn_handler = usbmast_bd_connection; 248 223 249 224 usb_log_debug("Inquire...\n"); … … 252 227 if (rc != EOK) { 253 228 usb_log_warning("Failed to inquire device `%s': %s.\n", 254 ddf_dev_get_name(mdev->ddf_dev), str_error(rc));229 mdev->ddf_dev->name, str_error(rc)); 255 230 rc = EIO; 256 231 goto error; … … 259 234 usb_log_info("Mass storage `%s' LUN %u: " \ 260 235 "%s by %s rev. %s is %s (%s).\n", 261 ddf_dev_get_name(mdev->ddf_dev),236 mdev->ddf_dev->name, 262 237 lun, 263 238 inquiry.product, … … 272 247 if (rc != EOK) { 273 248 usb_log_warning("Failed to read capacity, device `%s': %s.\n", 274 ddf_dev_get_name(mdev->ddf_dev), str_error(rc));249 mdev->ddf_dev->name, str_error(rc)); 275 250 rc = EIO; 276 251 goto error; … … 309 284 { 310 285 usbmast_fun_t *mfun; 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 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 == (void *) -1) { 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 } 368 346 369 347 /** USB mass storage driver ops. */ … … 383 361 int main(int argc, char *argv[]) 384 362 { 385 log_init(NAME);363 usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME); 386 364 387 365 return usb_driver_main(&usbmast_driver);
Note:
See TracChangeset
for help on using the changeset viewer.