Changeset 7b084d3 in mainline
- Timestamp:
- 2015-04-12T09:37:32Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c4f32fff
- Parents:
- 3f04c28
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/block/ddisk/ddisk.c
r3f04c28 r7b084d3 94 94 } ddisk_regs_t; 95 95 96 struct ddisk_dev; 97 98 typedef struct ddisk_fun { 99 ddf_fun_t *fun; 100 struct ddisk_dev *ddisk_dev; 101 102 size_t blocks; 103 104 bd_srvs_t bds; 105 } ddisk_fun_t; 106 107 typedef struct ddisk_dev { 96 typedef struct { 108 97 fibril_mutex_t lock; 109 98 fibril_condvar_t io_cv; 110 99 bool io_busy; 111 100 ddf_dev_t *dev; 101 ddf_fun_t *fun; 112 102 ddisk_res_t ddisk_res; 113 ddisk_fun_t *ddisk_fun;114 103 ddisk_regs_t *ddisk_regs; 115 104 uintptr_t dma_buffer_phys; 116 105 void *dma_buffer; 106 bd_srvs_t bds; 117 107 } ddisk_dev_t; 118 108 … … 206 196 read, ba, buf); 207 197 208 if (ba >= ddisk_dev->ddisk_fun->blocks)198 if (ba >= pio_read_32(&ddisk_dev->ddisk_regs->size) / DDISK_BLOCK_SIZE) 209 199 return ELIMIT; 210 200 … … 239 229 size_t size, bool is_read) 240 230 { 241 ddisk_ fun_t *ddisk_fun = (ddisk_fun_t *) bd->srvs->sarg;231 ddisk_dev_t *ddisk_dev = (ddisk_dev_t *) bd->srvs->sarg; 242 232 aoff64_t i; 243 233 int rc; … … 247 237 248 238 for (i = 0; i < cnt; i++) { 249 rc = ddisk_rw_block(ddisk_ fun->ddisk_dev, is_read, ba + i,239 rc = ddisk_rw_block(ddisk_dev, is_read, ba + i, 250 240 buf + i * DDISK_BLOCK_SIZE); 251 241 if (rc != EOK) … … 276 266 int ddisk_bd_get_num_blocks(bd_srv_t *bd, aoff64_t *rnb) 277 267 { 278 ddisk_ fun_t *ddisk_fun = (ddisk_fun_t *) bd->srvs->sarg;279 280 *rnb = ddisk_fun->blocks;268 ddisk_dev_t *ddisk_dev = (ddisk_dev_t *) bd->srvs->sarg; 269 270 *rnb = pio_read_32(&ddisk_dev->ddisk_regs->size) / DDISK_BLOCK_SIZE; 281 271 return EOK; 282 272 } … … 321 311 int rc; 322 312 ddf_fun_t *fun = NULL; 323 ddisk_fun_t *ddisk_fun = NULL;324 313 325 314 fun = ddf_fun_create(ddisk_dev->dev, fun_exposed, DDISK_FUN_NAME); … … 330 319 } 331 320 332 /* Allocate soft state */333 ddisk_fun = ddf_fun_data_alloc(fun, sizeof(ddisk_fun_t));334 if (!ddisk_fun) {335 ddf_msg(LVL_ERROR, "Failed allocating softstate.");336 rc = ENOMEM;337 goto error;338 }339 340 ddisk_fun->fun = fun;341 ddisk_fun->ddisk_dev = ddisk_dev;342 343 bd_srvs_init(&ddisk_fun->bds);344 ddisk_fun->bds.ops = &ddisk_bd_ops;345 ddisk_fun->bds.sarg = ddisk_fun;346 347 321 /* Set up a connection handler. */ 348 322 ddf_fun_set_conn_handler(fun, ddisk_bd_connection); 349 323 350 ddisk_fun->blocks = pio_read_32(&ddisk_dev->ddisk_regs->size) /351 DDISK_BLOCK_SIZE;352 353 324 rc = ddf_fun_bind(fun); 354 325 if (rc != EOK) { … … 359 330 360 331 ddf_fun_add_to_category(fun, "bd"); 361 362 ddisk_dev->ddisk_fun = ddisk_fun; 332 ddisk_dev->fun = fun; 333 363 334 return EOK; 364 335 error: … … 369 340 } 370 341 371 static int ddisk_fun_remove(ddisk_ fun_t *ddisk_fun)372 { 373 int rc; 374 375 if (ddisk_ fun->fun == NULL)342 static int ddisk_fun_remove(ddisk_dev_t *ddisk_dev) 343 { 344 int rc; 345 346 if (ddisk_dev->fun == NULL) 376 347 return EOK; 377 348 378 ddf_msg(LVL_DEBUG, "ddisk_fun_remove(%p, '%s')", ddisk_ fun,349 ddf_msg(LVL_DEBUG, "ddisk_fun_remove(%p, '%s')", ddisk_dev, 379 350 DDISK_FUN_NAME); 380 rc = ddf_fun_offline(ddisk_ fun->fun);351 rc = ddf_fun_offline(ddisk_dev->fun); 381 352 if (rc != EOK) { 382 353 ddf_msg(LVL_ERROR, "Error offlining function '%s'.", … … 385 356 } 386 357 387 rc = ddf_fun_unbind(ddisk_ fun->fun);358 rc = ddf_fun_unbind(ddisk_dev->fun); 388 359 if (rc != EOK) { 389 360 ddf_msg(LVL_ERROR, "Failed unbinding function '%s'.", … … 392 363 } 393 364 394 ddf_fun_destroy(ddisk_ fun->fun);395 ddisk_ fun->fun = NULL;365 ddf_fun_destroy(ddisk_dev->fun); 366 ddisk_dev->fun = NULL; 396 367 rc = EOK; 397 368 error: … … 399 370 } 400 371 401 static int ddisk_fun_unbind(ddisk_ fun_t *ddisk_fun)402 { 403 int rc; 404 405 if (ddisk_ fun->fun == NULL)372 static int ddisk_fun_unbind(ddisk_dev_t *ddisk_dev) 373 { 374 int rc; 375 376 if (ddisk_dev->fun == NULL) 406 377 return EOK; 407 378 408 ddf_msg(LVL_DEBUG, "ddisk_fun_unbind(%p, '%s')", ddisk_ fun,379 ddf_msg(LVL_DEBUG, "ddisk_fun_unbind(%p, '%s')", ddisk_dev, 409 380 DDISK_FUN_NAME); 410 rc = ddf_fun_unbind(ddisk_ fun->fun);381 rc = ddf_fun_unbind(ddisk_dev->fun); 411 382 if (rc != EOK) { 412 383 ddf_msg(LVL_ERROR, "Failed unbinding function '%s'.", … … 415 386 } 416 387 417 ddf_fun_destroy(ddisk_ fun->fun);418 ddisk_ fun->fun = NULL;388 ddf_fun_destroy(ddisk_dev->fun); 389 ddisk_dev->fun = NULL; 419 390 rc = EOK; 391 420 392 error: 421 393 return rc; … … 483 455 ddf_msg(LVL_NOTE, "Allocated DMA buffer at %p virtual and %p physical.", 484 456 ddisk_dev->dma_buffer, (void *) ddisk_dev->dma_buffer_phys); 457 458 bd_srvs_init(&ddisk_dev->bds); 459 ddisk_dev->bds.ops = &ddisk_bd_ops; 460 ddisk_dev->bds.sarg = ddisk_dev; 485 461 486 462 rc = ddisk_fun_create(ddisk_dev); … … 509 485 */ 510 486 ddf_msg(LVL_NOTE, 511 "Device at %p with %zu blocks (%zuB) using interrupt %d", 512 (void *) ddisk_dev->ddisk_res.base, ddisk_dev->ddisk_fun->blocks, 513 ddisk_dev->ddisk_fun->blocks * DDISK_BLOCK_SIZE, 487 "Device at %p with %" PRIu32 " blocks (%" PRIu32 488 "B) using interrupt %d", 489 (void *) ddisk_dev->ddisk_res.base, 490 pio_read_32(&ddisk_dev->ddisk_regs->size) / DDISK_BLOCK_SIZE, 491 pio_read_32(&ddisk_dev->ddisk_regs->size), 514 492 ddisk_dev->ddisk_res.irq); 515 493 516 494 return EOK; 495 517 496 error: 518 497 if (ddisk_dev->ddisk_regs) … … 529 508 530 509 if (!surprise) 531 rc = ddisk_fun_remove(ddisk_dev ->ddisk_fun);510 rc = ddisk_fun_remove(ddisk_dev); 532 511 else 533 rc = ddisk_fun_unbind(ddisk_dev->ddisk_fun); 512 rc = ddisk_fun_unbind(ddisk_dev); 513 534 514 if (rc != EOK) { 535 515 ddf_msg(LVL_ERROR, "Unable to cleanup function '%s'.", … … 554 534 555 535 ddf_msg(LVL_DEBUG, "ddisk_dev_remove(%p)", dev); 556 557 536 return ddisk_dev_remove_common(ddisk_dev, false); 558 537 } … … 563 542 564 543 ddf_msg(LVL_DEBUG, "ddisk_dev_gone(%p)", dev); 565 566 544 return ddisk_dev_remove_common(ddisk_dev, true); 567 545 } … … 582 560 static void ddisk_bd_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 583 561 { 584 ddisk_fun_t *ddfun; 585 586 ddfun = (ddisk_fun_t *) ddf_fun_data_get((ddf_fun_t *)arg); 587 bd_conn(iid, icall, &ddfun->bds); 562 ddisk_dev_t *ddisk_dev; 563 ddf_fun_t *fun = (ddf_fun_t *) arg; 564 565 ddisk_dev = (ddisk_dev_t *) ddf_dev_data_get(ddf_fun_get_dev(fun)); 566 bd_conn(iid, icall, &ddisk_dev->bds); 588 567 } 589 568
Note:
See TracChangeset
for help on using the changeset viewer.