Changeset d9f4c76 in mainline for uspace/srv/bd/ata_bd/ata_bd.c


Ignore:
Timestamp:
2009-06-13T12:26:05Z (16 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2a18193c
Parents:
5481d1bb
Message:

Write support in ata_bd. Not used, not tested.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/bd/ata_bd/ata_bd.c

    r5481d1bb rd9f4c76  
    7777static int ata_bd_read_block(int disk_id, uint64_t blk_idx, size_t blk_cnt,
    7878    void *buf);
     79static int ata_bd_write_block(int disk_id, uint64_t blk_idx, size_t blk_cnt,
     80    const void *buf);
    7981static int drive_identify(int drive_id, disk_t *d);
    8082
     
    307309                        rc = ata_bd_read_block(disk_id, blk_idx, 1, buf);
    308310                else
    309                         rc = ENOTSUP;
     311                        rc = ata_bd_write_block(disk_id, blk_idx, 1, buf);
    310312
    311313                if (rc != EOK)
     
    380382}
    381383
     384static 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
    382437
    383438/**
Note: See TracChangeset for help on using the changeset viewer.