Changes in / [42cfd91:1724745f] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/bd/ata_bd/ata_bd.c
r42cfd91 r1724745f 36 36 * 37 37 * This driver currently works only with CHS addressing and uses PIO. 38 * Currently based on the (now obsolete) ATA-1, ATA-2 standards. 38 * Currently based on the (now obsolete) ANSI X3.221-1994 (ATA-1) standard. 39 * At this point only reading is possible, not writing. 39 40 * 40 41 * The driver services a single controller which can have up to two disks … … 95 96 return -1; 96 97 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 97 112 (void) drive_identify(0, &disk[0]); 98 113 (void) drive_identify(1, &disk[1]); … … 133 148 uint16_t data; 134 149 uint8_t status; 135 uint8_t drv_head;136 150 size_t i; 137 151 … … 139 153 fflush(stdout); 140 154 141 drv_head = ((disk_id != 0) ? DHR_DRV : 0); 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 142 161 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);149 162 150 163 /* … … 152 165 * do the right thing to work with real drives. 153 166 */ 154 do {155 status = pio_read_8(&cmd->status);156 } while ((status & SR_BSY) != 0);157 158 167 if ((status & SR_DRDY) == 0) { 159 168 printf("None attached.\n"); 160 169 return ENOENT; 161 170 } 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 } 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; 190 183 } 191 184 } 192 193 if ((status & SR_ERR) != 0)194 return EIO;195 185 196 186 d->blocks = d->cylinders * d->heads * d->sectors; … … 371 361 /* Program a Read Sectors operation. */ 372 362 373 do {374 status = pio_read_8(&cmd->status);375 } while ((status & SR_BSY) != 0);376 377 363 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 383 364 pio_write_8(&cmd->sector_count, 1); 384 365 pio_write_8(&cmd->sector_number, s); 385 366 pio_write_8(&cmd->cylinder_low, c & 0xff); 386 367 pio_write_8(&cmd->cylinder_high, c >> 16); 387 388 368 pio_write_8(&cmd->command, CMD_READ_SECTORS); 389 369 390 do {391 status = pio_read_8(&cmd->status);392 } while ((status & SR_BSY) != 0);393 394 370 /* Read data from the disk buffer. */ 395 371 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; 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 } 405 380 406 381 fibril_mutex_unlock(&d->lock); … … 440 415 /* Program a Read Sectors operation. */ 441 416 442 do {443 status = pio_read_8(&cmd->status);444 } while ((status & SR_BSY) != 0);445 446 417 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 452 418 pio_write_8(&cmd->sector_count, 1); 453 419 pio_write_8(&cmd->sector_number, s); 454 420 pio_write_8(&cmd->cylinder_low, c & 0xff); 455 421 pio_write_8(&cmd->cylinder_high, c >> 16); 456 457 422 pio_write_8(&cmd->command, CMD_WRITE_SECTORS); 458 423 459 do {460 status = pio_read_8(&cmd->status);461 } while ((status & SR_BSY) != 0);462 463 424 /* Write data to the disk buffer. */ 464 425 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 } 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]); 469 432 } 470 433 471 434 fibril_mutex_unlock(&d->lock); 472 473 if (status & SR_ERR)474 return EIO;475 476 435 return EOK; 477 436 } 437 478 438 479 439 /**
Note:
See TracChangeset
for help on using the changeset viewer.