Changeset a1f48f6 in mainline for uspace/srv/bd/ata_bd/ata_bd.c
- Timestamp:
- 2009-08-22T18:36:30Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1c1657c
- Parents:
- 4ef117f8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/bd/ata_bd/ata_bd.c
r4ef117f8 ra1f48f6 35 35 * @brief ATA disk driver 36 36 * 37 * This driver currently works only with CHS addressing and uses PIO. 38 * Currently based on the (now obsolete) ATA-1, ATA-2 standards. 37 * This driver supports CHS, 28-bit and 48-bit LBA addressing. It only uses 38 * PIO transfers. There is no support DMA, the PACKET feature set or any other 39 * fancy features such as S.M.A.R.T, removable devices, etc. 40 * 41 * This driver is based on the ATA-1, ATA-2, ATA-3 and ATA/ATAPI-4 through 7 42 * standards, as published by the ANSI, NCITS and INCITS standards bodies, 43 * which are freely available. This driver contains no vendor-specific 44 * code at this moment. 39 45 * 40 46 * The driver services a single controller which can have up to two disks … … 100 106 printf(NAME ": ATA disk driver\n"); 101 107 102 printf("I/O address 0x% x\n", cmd_physical);108 printf("I/O address 0x%p/0x%p\n", ctl_physical, cmd_physical); 103 109 104 110 if (ata_bd_init() != EOK) … … 156 162 printf("%s: ", d->model); 157 163 158 if (d->amode == am_chs) { 164 switch (d->amode) { 165 case am_chs: 159 166 printf("CHS %u cylinders, %u heads, %u sectors", 160 167 disk->geom.cylinders, disk->geom.heads, disk->geom.sectors); 161 } else { 168 break; 169 case am_lba28: 162 170 printf("LBA-28"); 171 break; 172 case am_lba48: 173 printf("LBA-48"); 174 break; 163 175 } 164 176 … … 288 300 size_t pos, len; 289 301 int rc; 290 inti;302 unsigned i; 291 303 292 304 rc = drive_identify(disk_id, &idata); … … 305 317 306 318 d->blocks = d->geom.cylinders * d->geom.heads * d->geom.sectors; 307 } else {308 /* Device supports LBA-28. */319 } else if ((idata.cmd_set1 & cs1_addr48) == 0) { 320 /* Device only supports LBA-28 addressing. */ 309 321 d->amode = am_lba28; 310 322 … … 314 326 315 327 d->blocks = 316 (uint32_t) idata.total_lba_sec0 | 317 ((uint32_t) idata.total_lba_sec1 << 16); 328 (uint32_t) idata.total_lba28_0 | 329 ((uint32_t) idata.total_lba28_1 << 16); 330 } else { 331 /* Device supports LBA-48 addressing. */ 332 d->amode = am_lba48; 333 334 d->geom.cylinders = 0; 335 d->geom.heads = 0; 336 d->geom.sectors = 0; 337 338 d->blocks = 339 (uint64_t) idata.total_lba48_0 | 340 ((uint64_t) idata.total_lba48_1 << 16) | 341 ((uint64_t) idata.total_lba48_2 << 32) | 342 ((uint64_t) idata.total_lba48_3 << 48); 318 343 } 319 344 … … 451 476 uint16_t data; 452 477 uint8_t status; 453 uint64_t c, h, s ;478 uint64_t c, h, s, c1, s1; 454 479 uint64_t idx; 455 480 uint8_t drv_head; … … 462 487 return EINVAL; 463 488 464 if (d->amode == am_chs) { 489 switch (d->amode) { 490 case am_chs: 465 491 /* Compute CHS coordinates. */ 466 492 c = blk_idx / (d->geom.heads * d->geom.sectors); … … 469 495 h = idx / d->geom.sectors; 470 496 s = 1 + (idx % d->geom.sectors); 471 } else { 497 break; 498 499 case am_lba28: 472 500 /* Compute LBA-28 coordinates. */ 473 501 s = blk_idx & 0xff; /* bits 0-7 */ 474 502 c = (blk_idx >> 8) & 0xffff; /* bits 8-23 */ 475 503 h = (blk_idx >> 24) & 0x0f; /* bits 24-27 */ 504 break; 505 506 case am_lba48: 507 /* Compute LBA-48 coordinates. */ 508 s = blk_idx & 0xff; /* bits 0-7 */ 509 c = (blk_idx >> 8) & 0xffff; /* bits 8-23 */ 510 s1 = (blk_idx >> 24) & 0xff; /* bits 24-31 */ 511 c1 = (blk_idx >> 32) & 0xffff; /* bits 32-47 */ 512 h = 0; 513 break; 476 514 } 477 515 … … 498 536 } 499 537 538 if (d->amode == am_lba48) { 539 /* Write high-order bits. */ 540 pio_write_8(&cmd->sector_count, 0); 541 pio_write_8(&cmd->sector_number, s1); 542 pio_write_8(&cmd->cylinder_low, c1 & 0xff); 543 pio_write_8(&cmd->cylinder_high, c1 >> 16); 544 } 545 546 /* Write low-order bits. */ 500 547 pio_write_8(&cmd->sector_count, 1); 501 548 pio_write_8(&cmd->sector_number, s); … … 540 587 size_t i; 541 588 uint8_t status; 542 uint64_t c, h, s ;589 uint64_t c, h, s, c1, s1; 543 590 uint64_t idx; 544 591 uint8_t drv_head; … … 551 598 return EINVAL; 552 599 553 if (d->amode == am_chs) { 600 switch (d->amode) { 601 case am_chs: 554 602 /* Compute CHS coordinates. */ 555 603 c = blk_idx / (d->geom.heads * d->geom.sectors); … … 558 606 h = idx / d->geom.sectors; 559 607 s = 1 + (idx % d->geom.sectors); 560 } else { 608 break; 609 610 case am_lba28: 561 611 /* Compute LBA-28 coordinates. */ 562 612 s = blk_idx & 0xff; /* bits 0-7 */ 563 613 c = (blk_idx >> 8) & 0xffff; /* bits 8-23 */ 564 614 h = (blk_idx >> 24) & 0x0f; /* bits 24-27 */ 615 break; 616 617 case am_lba48: 618 /* Compute LBA-48 coordinates. */ 619 s = blk_idx & 0xff; /* bits 0-7 */ 620 c = (blk_idx >> 8) & 0xffff; /* bits 8-23 */ 621 s1 = (blk_idx >> 24) & 0xff; /* bits 24-31 */ 622 c1 = (blk_idx >> 32) & 0xffff; /* bits 32-47 */ 623 h = 0; 624 break; 565 625 } 566 626 … … 587 647 } 588 648 649 if (d->amode == am_lba48) { 650 /* Write high-order bits. */ 651 pio_write_8(&cmd->sector_count, 0); 652 pio_write_8(&cmd->sector_number, s1); 653 pio_write_8(&cmd->cylinder_low, c1 & 0xff); 654 pio_write_8(&cmd->cylinder_high, c1 >> 16); 655 } 656 657 /* Write low-order bits. */ 589 658 pio_write_8(&cmd->sector_count, 1); 590 659 pio_write_8(&cmd->sector_number, s);
Note:
See TracChangeset
for help on using the changeset viewer.