Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/block/ata_bd/ata_bd.c

    r35b8bfe r4abe919  
    9797static int ata_bd_get_block_size(bd_srv_t *, size_t *);
    9898static int ata_bd_get_num_blocks(bd_srv_t *, aoff64_t *);
     99static int ata_bd_sync_cache(bd_srv_t *, aoff64_t, size_t);
    99100
    100101static int ata_rcmd_read(disk_t *disk, uint64_t ba, size_t cnt,
     
    102103static int ata_rcmd_write(disk_t *disk, uint64_t ba, size_t cnt,
    103104    const void *buf);
     105static int ata_rcmd_flush_cache(disk_t *disk);
    104106static int disk_init(ata_ctrl_t *ctrl, disk_t *d, int disk_id);
    105107static int ata_identify_dev(disk_t *disk, void *buf);
     
    129131        .write_blocks = ata_bd_write_blocks,
    130132        .get_block_size = ata_bd_get_block_size,
    131         .get_num_blocks = ata_bd_get_num_blocks
     133        .get_num_blocks = ata_bd_get_num_blocks,
     134        .sync_cache = ata_bd_sync_cache
    132135};
    133136
     
    586589}
    587590
     591/** Flush cache. */
     592static int ata_bd_sync_cache(bd_srv_t *bd, uint64_t ba, size_t cnt)
     593{
     594        disk_t *disk = bd_srv_disk(bd);
     595
     596        /* ATA cannot flush just some blocks, we just flush everything. */
     597        (void)ba;
     598        (void)cnt;
     599
     600        return ata_rcmd_flush_cache(disk);
     601}
     602
    588603/** PIO data-in command protocol. */
    589604static int ata_pio_data_in(disk_t *disk, void *obuf, size_t obuf_size,
     
    639654                }
    640655        }
     656
     657        if (status & SR_ERR)
     658                return EIO;
     659
     660        return EOK;
     661}
     662
     663/** PIO non-data command protocol. */
     664static int ata_pio_nondata(disk_t *disk)
     665{
     666        ata_ctrl_t *ctrl = disk->ctrl;
     667        uint8_t status;
     668
     669        if (wait_status(ctrl, 0, ~SR_BSY, &status, TIMEOUT_BSY) != EOK)
     670                return EIO;
    641671
    642672        if (status & SR_ERR)
     
    10761106        rc = ata_pio_data_out(disk, buf, cnt * disk->block_size,
    10771107            disk->block_size, cnt);
     1108
     1109        fibril_mutex_unlock(&ctrl->lock);
     1110        return rc;
     1111}
     1112
     1113/** Flush cached data to nonvolatile storage.
     1114 *
     1115 * @param disk          Disk
     1116 *
     1117 * @return EOK on success, EIO on error.
     1118 */
     1119static int ata_rcmd_flush_cache(disk_t *disk)
     1120{
     1121        ata_ctrl_t *ctrl = disk->ctrl;
     1122        uint8_t drv_head;
     1123        int rc;
     1124
     1125        /* New value for Drive/Head register */
     1126        drv_head =
     1127            (disk_dev_idx(disk) != 0) ? DHR_DRV : 0;
     1128
     1129        fibril_mutex_lock(&ctrl->lock);
     1130
     1131        /* Program a Flush Cache operation. */
     1132
     1133        if (wait_status(ctrl, 0, ~SR_BSY, NULL, TIMEOUT_BSY) != EOK) {
     1134                fibril_mutex_unlock(&ctrl->lock);
     1135                return EIO;
     1136        }
     1137
     1138        pio_write_8(&ctrl->cmd->drive_head, drv_head);
     1139
     1140        if (wait_status(ctrl, SR_DRDY, ~SR_BSY, NULL, TIMEOUT_DRDY) != EOK) {
     1141                fibril_mutex_unlock(&ctrl->lock);
     1142                return EIO;
     1143        }
     1144
     1145        pio_write_8(&ctrl->cmd->command, CMD_FLUSH_CACHE);
     1146
     1147        rc = ata_pio_nondata(disk);
    10781148
    10791149        fibril_mutex_unlock(&ctrl->lock);
Note: See TracChangeset for help on using the changeset viewer.