Changeset 42d0eeb6 in mainline for uspace/drv/block/ddisk/ddisk.c
- Timestamp:
- 2015-04-12T11:25:17Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 73e894c
- Parents:
- c4f32fff
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/block/ddisk/ddisk.c
rc4f32fff r42d0eeb6 113 113 114 114 bd_srvs_t bds; 115 } ddisk_ dev_t;115 } ddisk_t; 116 116 117 117 static int ddisk_bd_open(bd_srvs_t *, bd_srv_t *); … … 179 179 (uint32_t) IPC_GET_ARG1(*icall)); 180 180 181 ddisk_ dev_t *ddisk_dev = (ddisk_dev_t *) ddf_dev_data_get(dev);181 ddisk_t *ddisk = (ddisk_t *) ddf_dev_data_get(dev); 182 182 183 fibril_mutex_lock(&ddisk _dev->lock);184 fibril_condvar_broadcast(&ddisk _dev->io_cv);185 fibril_mutex_unlock(&ddisk _dev->lock);183 fibril_mutex_lock(&ddisk->lock); 184 fibril_condvar_broadcast(&ddisk->io_cv); 185 fibril_mutex_unlock(&ddisk->lock); 186 186 } 187 187 … … 197 197 198 198 static 199 int ddisk_rw_block(ddisk_ dev_t *ddisk_dev, bool read, aoff64_t ba, void *buf)200 { 201 fibril_mutex_lock(&ddisk _dev->lock);199 int ddisk_rw_block(ddisk_t *ddisk, bool read, aoff64_t ba, void *buf) 200 { 201 fibril_mutex_lock(&ddisk->lock); 202 202 203 203 ddf_msg(LVL_DEBUG, "ddisk_rw_block(): read=%d, ba=%" PRId64 ", buf=%p", 204 204 read, ba, buf); 205 205 206 if (ba >= ddisk _dev->blocks)206 if (ba >= ddisk->blocks) 207 207 return ELIMIT; 208 208 209 while (ddisk _dev->io_busy)210 fibril_condvar_wait(&ddisk _dev->io_cv, &ddisk_dev->lock);211 212 ddisk _dev->io_busy = true;209 while (ddisk->io_busy) 210 fibril_condvar_wait(&ddisk->io_cv, &ddisk->lock); 211 212 ddisk->io_busy = true; 213 213 214 214 if (!read) 215 memcpy(ddisk _dev->dma_buffer, buf, DDISK_BLOCK_SIZE);215 memcpy(ddisk->dma_buffer, buf, DDISK_BLOCK_SIZE); 216 216 217 pio_write_32(&ddisk _dev->ddisk_regs->dma_buffer,218 ddisk _dev->dma_buffer_phys);219 pio_write_32(&ddisk _dev->ddisk_regs->block, (uint32_t) ba);220 pio_write_32(&ddisk _dev->ddisk_regs->command,217 pio_write_32(&ddisk->ddisk_regs->dma_buffer, 218 ddisk->dma_buffer_phys); 219 pio_write_32(&ddisk->ddisk_regs->block, (uint32_t) ba); 220 pio_write_32(&ddisk->ddisk_regs->command, 221 221 read ? DDISK_CMD_READ : DDISK_CMD_WRITE); 222 222 223 fibril_condvar_wait(&ddisk _dev->io_cv, &ddisk_dev->lock);223 fibril_condvar_wait(&ddisk->io_cv, &ddisk->lock); 224 224 225 225 if (read) 226 memcpy(buf, ddisk _dev->dma_buffer, DDISK_BLOCK_SIZE);227 228 ddisk _dev->io_busy = false;229 fibril_condvar_signal(&ddisk _dev->io_cv);230 fibril_mutex_unlock(&ddisk _dev->lock);226 memcpy(buf, ddisk->dma_buffer, DDISK_BLOCK_SIZE); 227 228 ddisk->io_busy = false; 229 fibril_condvar_signal(&ddisk->io_cv); 230 fibril_mutex_unlock(&ddisk->lock); 231 231 232 232 return EOK; … … 237 237 size_t size, bool is_read) 238 238 { 239 ddisk_ dev_t *ddisk_dev = (ddisk_dev_t *) bd->srvs->sarg;239 ddisk_t *ddisk = (ddisk_t *) bd->srvs->sarg; 240 240 aoff64_t i; 241 241 int rc; … … 245 245 246 246 for (i = 0; i < cnt; i++) { 247 rc = ddisk_rw_block(ddisk _dev, is_read, ba + i,247 rc = ddisk_rw_block(ddisk, is_read, ba + i, 248 248 buf + i * DDISK_BLOCK_SIZE); 249 249 if (rc != EOK) … … 274 274 int ddisk_bd_get_num_blocks(bd_srv_t *bd, aoff64_t *rnb) 275 275 { 276 ddisk_ dev_t *ddisk_dev = (ddisk_dev_t *) bd->srvs->sarg;277 278 *rnb = ddisk _dev->blocks;276 ddisk_t *ddisk = (ddisk_t *) bd->srvs->sarg; 277 278 *rnb = ddisk->blocks; 279 279 return EOK; 280 280 } … … 315 315 } 316 316 317 static int ddisk_fun_create(ddisk_ dev_t *ddisk_dev)317 static int ddisk_fun_create(ddisk_t *ddisk) 318 318 { 319 319 int rc; 320 320 ddf_fun_t *fun = NULL; 321 321 322 fun = ddf_fun_create(ddisk _dev->dev, fun_exposed, DDISK_FUN_NAME);322 fun = ddf_fun_create(ddisk->dev, fun_exposed, DDISK_FUN_NAME); 323 323 if (fun == NULL) { 324 324 ddf_msg(LVL_ERROR, "Failed creating DDF function."); … … 338 338 339 339 ddf_fun_add_to_category(fun, "bd"); 340 ddisk _dev->fun = fun;340 ddisk->fun = fun; 341 341 342 342 return EOK; … … 348 348 } 349 349 350 static int ddisk_fun_remove(ddisk_ dev_t *ddisk_dev)351 { 352 int rc; 353 354 if (ddisk _dev->fun == NULL)350 static int ddisk_fun_remove(ddisk_t *ddisk) 351 { 352 int rc; 353 354 if (ddisk->fun == NULL) 355 355 return EOK; 356 356 357 ddf_msg(LVL_DEBUG, "ddisk_fun_remove(%p, '%s')", ddisk _dev,357 ddf_msg(LVL_DEBUG, "ddisk_fun_remove(%p, '%s')", ddisk, 358 358 DDISK_FUN_NAME); 359 rc = ddf_fun_offline(ddisk _dev->fun);359 rc = ddf_fun_offline(ddisk->fun); 360 360 if (rc != EOK) { 361 361 ddf_msg(LVL_ERROR, "Error offlining function '%s'.", … … 364 364 } 365 365 366 rc = ddf_fun_unbind(ddisk _dev->fun);366 rc = ddf_fun_unbind(ddisk->fun); 367 367 if (rc != EOK) { 368 368 ddf_msg(LVL_ERROR, "Failed unbinding function '%s'.", … … 371 371 } 372 372 373 ddf_fun_destroy(ddisk _dev->fun);374 ddisk _dev->fun = NULL;373 ddf_fun_destroy(ddisk->fun); 374 ddisk->fun = NULL; 375 375 rc = EOK; 376 376 … … 379 379 } 380 380 381 static int ddisk_fun_unbind(ddisk_ dev_t *ddisk_dev)382 { 383 int rc; 384 385 if (ddisk _dev->fun == NULL)381 static int ddisk_fun_unbind(ddisk_t *ddisk) 382 { 383 int rc; 384 385 if (ddisk->fun == NULL) 386 386 return EOK; 387 387 388 ddf_msg(LVL_DEBUG, "ddisk_fun_unbind(%p, '%s')", ddisk _dev,388 ddf_msg(LVL_DEBUG, "ddisk_fun_unbind(%p, '%s')", ddisk, 389 389 DDISK_FUN_NAME); 390 rc = ddf_fun_unbind(ddisk _dev->fun);390 rc = ddf_fun_unbind(ddisk->fun); 391 391 if (rc != EOK) { 392 392 ddf_msg(LVL_ERROR, "Failed unbinding function '%s'.", … … 395 395 } 396 396 397 ddf_fun_destroy(ddisk _dev->fun);398 ddisk _dev->fun = NULL;397 ddf_fun_destroy(ddisk->fun); 398 ddisk->fun = NULL; 399 399 rc = EOK; 400 400 … … 410 410 static int ddisk_dev_add(ddf_dev_t *dev) 411 411 { 412 ddisk_ dev_t *ddisk_dev;412 ddisk_t *ddisk; 413 413 ddisk_res_t res; 414 414 int rc; … … 426 426 * Allocate soft state. 427 427 */ 428 ddisk _dev = ddf_dev_data_alloc(dev, sizeof(ddisk_dev_t));429 if (!ddisk _dev) {428 ddisk = ddf_dev_data_alloc(dev, sizeof(ddisk_t)); 429 if (!ddisk) { 430 430 ddf_msg(LVL_ERROR, "Failed allocating soft state."); 431 431 rc = ENOMEM; … … 436 436 * Initialize soft state. 437 437 */ 438 fibril_mutex_initialize(&ddisk _dev->lock);439 ddisk _dev->dev = dev;440 ddisk _dev->ddisk_res = res;441 442 fibril_condvar_initialize(&ddisk _dev->io_cv);443 ddisk _dev->io_busy = false;444 445 bd_srvs_init(&ddisk _dev->bds);446 ddisk _dev->bds.ops = &ddisk_bd_ops;447 ddisk _dev->bds.sarg = ddisk_dev;438 fibril_mutex_initialize(&ddisk->lock); 439 ddisk->dev = dev; 440 ddisk->ddisk_res = res; 441 442 fibril_condvar_initialize(&ddisk->io_cv); 443 ddisk->io_busy = false; 444 445 bd_srvs_init(&ddisk->bds); 446 ddisk->bds.ops = &ddisk_bd_ops; 447 ddisk->bds.sarg = ddisk; 448 448 449 449 /* … … 456 456 goto error; 457 457 } 458 ddisk _dev->ddisk_regs = vaddr;459 460 ddisk _dev->size = (int32_t) pio_read_32(&ddisk_dev->ddisk_regs->size);461 ddisk _dev->blocks = ddisk_dev->size / DDISK_BLOCK_SIZE;462 463 if (ddisk _dev->size <= 0) {458 ddisk->ddisk_regs = vaddr; 459 460 ddisk->size = (int32_t) pio_read_32(&ddisk->ddisk_regs->size); 461 ddisk->blocks = ddisk->size / DDISK_BLOCK_SIZE; 462 463 if (ddisk->size <= 0) { 464 464 ddf_msg(LVL_WARN, "No disk detected."); 465 465 rc = EIO; … … 470 470 * Allocate DMA buffer. 471 471 */ 472 ddisk _dev->dma_buffer = AS_AREA_ANY;472 ddisk->dma_buffer = AS_AREA_ANY; 473 473 rc = dmamem_map_anonymous(DDISK_BLOCK_SIZE, DMAMEM_4GiB, 474 AS_AREA_READ | AS_AREA_WRITE, 0, &ddisk _dev->dma_buffer_phys,475 &ddisk _dev->dma_buffer);474 AS_AREA_READ | AS_AREA_WRITE, 0, &ddisk->dma_buffer_phys, 475 &ddisk->dma_buffer); 476 476 if (rc != EOK) { 477 477 ddf_msg(LVL_ERROR, "Cannot allocate DMA memory."); … … 480 480 481 481 ddf_msg(LVL_NOTE, "Allocated DMA buffer at %p virtual and %p physical.", 482 ddisk _dev->dma_buffer, (void *) ddisk_dev->dma_buffer_phys);482 ddisk->dma_buffer, (void *) ddisk->dma_buffer_phys); 483 483 484 484 /* 485 485 * Create an exposed function. 486 486 */ 487 rc = ddisk_fun_create(ddisk _dev);487 rc = ddisk_fun_create(ddisk); 488 488 if (rc != EOK) { 489 489 ddf_msg(LVL_ERROR, "Failed initializing ddisk controller."); … … 499 499 ddisk_irq_commands[0].addr = (void *) &res_phys->status; 500 500 ddisk_irq_commands[3].addr = (void *) &res_phys->command; 501 rc = register_interrupt_handler(dev, ddisk _dev->ddisk_res.irq,501 rc = register_interrupt_handler(dev, ddisk->ddisk_res.irq, 502 502 ddisk_irq_handler, &ddisk_irq_code); 503 503 if (rc != EOK) { … … 511 511 ddf_msg(LVL_NOTE, 512 512 "Device at %p with %zd blocks (%zuB) using interrupt %d", 513 (void *) ddisk _dev->ddisk_res.base, ddisk_dev->blocks,514 ddisk _dev->size, ddisk_dev->ddisk_res.irq);513 (void *) ddisk->ddisk_res.base, ddisk->blocks, 514 ddisk->size, ddisk->ddisk_res.irq); 515 515 516 516 return EOK; 517 517 518 518 error: 519 if (ddisk _dev->ddisk_regs)520 pio_disable(ddisk _dev->ddisk_regs, sizeof(ddisk_regs_t));521 if (ddisk _dev->dma_buffer)522 dmamem_unmap_anonymous(ddisk _dev->dma_buffer);519 if (ddisk->ddisk_regs) 520 pio_disable(ddisk->ddisk_regs, sizeof(ddisk_regs_t)); 521 if (ddisk->dma_buffer) 522 dmamem_unmap_anonymous(ddisk->dma_buffer); 523 523 524 524 return rc; … … 526 526 527 527 528 static int ddisk_dev_remove_common(ddisk_ dev_t *ddisk_dev, bool surprise)528 static int ddisk_dev_remove_common(ddisk_t *ddisk, bool surprise) 529 529 { 530 530 int rc; 531 531 532 532 if (!surprise) 533 rc = ddisk_fun_remove(ddisk _dev);533 rc = ddisk_fun_remove(ddisk); 534 534 else 535 rc = ddisk_fun_unbind(ddisk _dev);535 rc = ddisk_fun_unbind(ddisk); 536 536 537 537 if (rc != EOK) { … … 541 541 } 542 542 543 rc = pio_disable(ddisk _dev->ddisk_regs, sizeof(ddisk_regs_t));543 rc = pio_disable(ddisk->ddisk_regs, sizeof(ddisk_regs_t)); 544 544 if (rc != EOK) { 545 545 ddf_msg(LVL_ERROR, "Unable to disable PIO."); … … 547 547 } 548 548 549 dmamem_unmap_anonymous(ddisk _dev->dma_buffer);549 dmamem_unmap_anonymous(ddisk->dma_buffer); 550 550 551 551 return EOK; … … 554 554 static int ddisk_dev_remove(ddf_dev_t *dev) 555 555 { 556 ddisk_ dev_t *ddisk_dev = (ddisk_dev_t *) ddf_dev_data_get(dev);556 ddisk_t *ddisk = (ddisk_t *) ddf_dev_data_get(dev); 557 557 558 558 ddf_msg(LVL_DEBUG, "ddisk_dev_remove(%p)", dev); 559 return ddisk_dev_remove_common(ddisk _dev, false);559 return ddisk_dev_remove_common(ddisk, false); 560 560 } 561 561 562 562 static int ddisk_dev_gone(ddf_dev_t *dev) 563 563 { 564 ddisk_ dev_t *ddisk_dev = (ddisk_dev_t *) ddf_dev_data_get(dev);564 ddisk_t *ddisk = (ddisk_t *) ddf_dev_data_get(dev); 565 565 566 566 ddf_msg(LVL_DEBUG, "ddisk_dev_gone(%p)", dev); 567 return ddisk_dev_remove_common(ddisk _dev, true);567 return ddisk_dev_remove_common(ddisk, true); 568 568 } 569 569 … … 583 583 static void ddisk_bd_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 584 584 { 585 ddisk_ dev_t *ddisk_dev;585 ddisk_t *ddisk; 586 586 ddf_fun_t *fun = (ddf_fun_t *) arg; 587 587 588 ddisk _dev = (ddisk_dev_t *) ddf_dev_data_get(ddf_fun_get_dev(fun));589 bd_conn(iid, icall, &ddisk _dev->bds);588 ddisk = (ddisk_t *) ddf_dev_data_get(ddf_fun_get_dev(fun)); 589 bd_conn(iid, icall, &ddisk->bds); 590 590 } 591 591
Note:
See TracChangeset
for help on using the changeset viewer.