Changeset 42cfd91 in mainline
- Timestamp:
- 2009-08-08T13:49:29Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 330965c
- Parents:
- 1724745f (diff), d5f8f19 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/bd/ata_bd/ata_bd.c
r1724745f r42cfd91 36 36 * 37 37 * This driver currently works only with CHS addressing and uses PIO. 38 * Currently based on the (now obsolete) ANSI X3.221-1994 (ATA-1) standard. 39 * At this point only reading is possible, not writing. 38 * Currently based on the (now obsolete) ATA-1, ATA-2 standards. 40 39 * 41 40 * The driver services a single controller which can have up to two disks … … 96 95 return -1; 97 96 98 /* Put drives to reset, disable interrupts. */99 printf("Reset drives... ");100 fflush(stdout);101 102 pio_write_8(&ctl->device_control, DCR_SRST);103 /* FIXME: Find out how to do this properly. */104 async_usleep(100);105 pio_write_8(&ctl->device_control, 0);106 107 do {108 status = pio_read_8(&cmd->status);109 } while ((status & SR_BSY) != 0);110 printf("Done\n");111 112 97 (void) drive_identify(0, &disk[0]); 113 98 (void) drive_identify(1, &disk[1]); … … 148 133 uint16_t data; 149 134 uint8_t status; 135 uint8_t drv_head; 150 136 size_t i; 151 137 … … 153 139 fflush(stdout); 154 140 155 pio_write_8(&cmd->drive_head, ((disk_id != 0) ? DHR_DRV : 0)); 156 async_usleep(100); 157 pio_write_8(&cmd->command, CMD_IDENTIFY_DRIVE); 158 159 status = pio_read_8(&cmd->status); 160 141 drv_head = ((disk_id != 0) ? DHR_DRV : 0); 161 142 d->present = false; 143 144 do { 145 status = pio_read_8(&cmd->status); 146 } while ((status & SR_BSY) != 0); 147 148 pio_write_8(&cmd->drive_head, drv_head); 162 149 163 150 /* … … 165 152 * do the right thing to work with real drives. 166 153 */ 154 do { 155 status = pio_read_8(&cmd->status); 156 } while ((status & SR_BSY) != 0); 157 167 158 if ((status & SR_DRDY) == 0) { 168 159 printf("None attached.\n"); 169 160 return ENOENT; 170 161 } 171 172 for (i = 0; i < block_size / 2; i++) { 173 do { 174 status = pio_read_8(&cmd->status); 175 } while ((status & SR_DRDY) == 0); 176 177 data = pio_read_16(&cmd->data_port); 178 179 switch (i) { 180 case 1: d->cylinders = data; break; 181 case 3: d->heads = data; break; 182 case 6: d->sectors = data; break; 162 /***/ 163 164 do { 165 status = pio_read_8(&cmd->status); 166 } while ((status & SR_BSY) != 0 || (status & SR_DRDY) == 0); 167 168 pio_write_8(&cmd->command, CMD_IDENTIFY_DRIVE); 169 170 do { 171 status = pio_read_8(&cmd->status); 172 } while ((status & SR_BSY) != 0); 173 174 /* Read data from the disk buffer. */ 175 176 if ((status & SR_DRQ) != 0) { 177 // for (i = 0; i < block_size / 2; i++) { 178 // data = pio_read_16(&cmd->data_port); 179 // ((uint16_t *) buf)[i] = data; 180 // } 181 182 for (i = 0; i < block_size / 2; i++) { 183 data = pio_read_16(&cmd->data_port); 184 185 switch (i) { 186 case 1: d->cylinders = data; break; 187 case 3: d->heads = data; break; 188 case 6: d->sectors = data; break; 189 } 183 190 } 184 191 } 192 193 if ((status & SR_ERR) != 0) 194 return EIO; 185 195 186 196 d->blocks = d->cylinders * d->heads * d->sectors; … … 361 371 /* Program a Read Sectors operation. */ 362 372 373 do { 374 status = pio_read_8(&cmd->status); 375 } while ((status & SR_BSY) != 0); 376 363 377 pio_write_8(&cmd->drive_head, drv_head); 378 379 do { 380 status = pio_read_8(&cmd->status); 381 } while ((status & SR_BSY) != 0 || (status & SR_DRDY) == 0); 382 364 383 pio_write_8(&cmd->sector_count, 1); 365 384 pio_write_8(&cmd->sector_number, s); 366 385 pio_write_8(&cmd->cylinder_low, c & 0xff); 367 386 pio_write_8(&cmd->cylinder_high, c >> 16); 387 368 388 pio_write_8(&cmd->command, CMD_READ_SECTORS); 369 389 390 do { 391 status = pio_read_8(&cmd->status); 392 } while ((status & SR_BSY) != 0); 393 370 394 /* Read data from the disk buffer. */ 371 395 372 for (i = 0; i < block_size / 2; i++) { 373 do { 374 status = pio_read_8(&cmd->status); 375 } while ((status & SR_DRDY) == 0); 376 377 data = pio_read_16(&cmd->data_port); 378 ((uint16_t *) buf)[i] = data; 379 } 396 if ((status & SR_DRQ) != 0) { 397 for (i = 0; i < block_size / 2; i++) { 398 data = pio_read_16(&cmd->data_port); 399 ((uint16_t *) buf)[i] = data; 400 } 401 } 402 403 if ((status & SR_ERR) != 0) 404 return EIO; 380 405 381 406 fibril_mutex_unlock(&d->lock); … … 415 440 /* Program a Read Sectors operation. */ 416 441 442 do { 443 status = pio_read_8(&cmd->status); 444 } while ((status & SR_BSY) != 0); 445 417 446 pio_write_8(&cmd->drive_head, drv_head); 447 448 do { 449 status = pio_read_8(&cmd->status); 450 } while ((status & SR_BSY) != 0 || (status & SR_DRDY) == 0); 451 418 452 pio_write_8(&cmd->sector_count, 1); 419 453 pio_write_8(&cmd->sector_number, s); 420 454 pio_write_8(&cmd->cylinder_low, c & 0xff); 421 455 pio_write_8(&cmd->cylinder_high, c >> 16); 456 422 457 pio_write_8(&cmd->command, CMD_WRITE_SECTORS); 423 458 459 do { 460 status = pio_read_8(&cmd->status); 461 } while ((status & SR_BSY) != 0); 462 424 463 /* Write data to the disk buffer. */ 425 464 426 for (i = 0; i < block_size / 2; i++) { 427 do { 428 status = pio_read_8(&cmd->status); 429 } while ((status & SR_DRDY) == 0); 430 431 pio_write_16(&cmd->data_port, ((uint16_t *) buf)[i]); 465 if ((status & SR_DRQ) != 0) { 466 for (i = 0; i < block_size / 2; i++) { 467 pio_write_16(&cmd->data_port, ((uint16_t *) buf)[i]); 468 } 432 469 } 433 470 434 471 fibril_mutex_unlock(&d->lock); 472 473 if (status & SR_ERR) 474 return EIO; 475 435 476 return EOK; 436 477 } 437 438 478 439 479 /**
Note:
See TracChangeset
for help on using the changeset viewer.