Changeset d9f4c76 in mainline for uspace/srv/bd/ata_bd/ata_bd.c
- Timestamp:
- 2009-06-13T12:26:05Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2a18193c
- Parents:
- 5481d1bb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/bd/ata_bd/ata_bd.c
r5481d1bb rd9f4c76 77 77 static int ata_bd_read_block(int disk_id, uint64_t blk_idx, size_t blk_cnt, 78 78 void *buf); 79 static int ata_bd_write_block(int disk_id, uint64_t blk_idx, size_t blk_cnt, 80 const void *buf); 79 81 static int drive_identify(int drive_id, disk_t *d); 80 82 … … 307 309 rc = ata_bd_read_block(disk_id, blk_idx, 1, buf); 308 310 else 309 rc = ENOTSUP;311 rc = ata_bd_write_block(disk_id, blk_idx, 1, buf); 310 312 311 313 if (rc != EOK) … … 380 382 } 381 383 384 static int ata_bd_write_block(int disk_id, uint64_t blk_idx, size_t blk_cnt, 385 const void *buf) 386 { 387 size_t i; 388 uint8_t status; 389 uint64_t c, h, s; 390 uint64_t idx; 391 uint8_t drv_head; 392 disk_t *d; 393 394 d = &disk[disk_id]; 395 396 /* Check device bounds. */ 397 if (blk_idx >= d->blocks) 398 return EINVAL; 399 400 /* Compute CHS. */ 401 c = blk_idx / (d->heads * d->sectors); 402 idx = blk_idx % (d->heads * d->sectors); 403 404 h = idx / d->sectors; 405 s = 1 + (idx % d->sectors); 406 407 /* New value for Drive/Head register */ 408 drv_head = 409 ((disk_id != 0) ? DHR_DRV : 0) | 410 (h & 0x0f); 411 412 futex_down(&dev_futex); 413 414 /* Program a Read Sectors operation. */ 415 416 pio_write_8(&cmd->drive_head, drv_head); 417 pio_write_8(&cmd->sector_count, 1); 418 pio_write_8(&cmd->sector_number, s); 419 pio_write_8(&cmd->cylinder_low, c & 0xff); 420 pio_write_8(&cmd->cylinder_high, c >> 16); 421 pio_write_8(&cmd->command, CMD_WRITE_SECTORS); 422 423 /* Write data to the disk buffer. */ 424 425 for (i = 0; i < block_size / 2; i++) { 426 do { 427 status = pio_read_8(&cmd->status); 428 } while ((status & SR_DRDY) == 0); 429 430 pio_write_16(&cmd->data_port, ((uint16_t *) buf)[i]); 431 } 432 433 futex_up(&dev_futex); 434 return EOK; 435 } 436 382 437 383 438 /**
Note:
See TracChangeset
for help on using the changeset viewer.