Subversion Repositories freemyipod

Rev

Rev 840 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 840 Rev 920
Line 877... Line 877...
877
 
877
 
878
int ata_rw_sectors_internal(uint64_t sector, uint32_t count, void* buffer, bool write)
878
int ata_rw_sectors_internal(uint64_t sector, uint32_t count, void* buffer, bool write)
879
{
879
{
880
#endif
880
#endif
881
    if (sector + count > ata_total_sectors) RET_ERR(0);
881
    if (sector + count > ata_total_sectors) RET_ERR(0);
882
    if (!ata_powered) ata_power_up();
882
    if (!ata_powered) PASS_RC(ata_power_up(), 2, 1);
883
    ata_set_active();
883
    ata_set_active();
884
    if (ata_dma && write) clean_dcache();
884
    if (ata_dma && write) clean_dcache();
885
    else if (ata_dma) invalidate_dcache();
885
    else if (ata_dma) invalidate_dcache();
886
    if (!ceata) ATA_COMMAND = BIT(1);
886
    if (!ceata) ATA_COMMAND = BIT(1);
887
    while (count)
887
    while (count)
Line 905... Line 905...
905
                }
905
                }
906
                if (rc) break;
906
                if (rc) break;
907
                buf += SECTOR_SIZE;
907
                buf += SECTOR_SIZE;
908
            }
908
            }
909
        }
909
        }
910
        PASS_RC(rc, 1, 1);
910
        PASS_RC(rc, 2, 2);
911
        buffer += SECTOR_SIZE * cnt;
911
        buffer += SECTOR_SIZE * cnt;
912
        sector += cnt;
912
        sector += cnt;
913
        count -= cnt;
913
        count -= cnt;
914
    }
914
    }
915
    ata_set_active();
915
    ata_set_active();
Line 931... Line 931...
931
/* API Functions */
931
/* API Functions */
932
int ata_soft_reset()
932
int ata_soft_reset()
933
{
933
{
934
    int rc;
934
    int rc;
935
    mutex_lock(&ata_mutex, TIMEOUT_BLOCK);
935
    mutex_lock(&ata_mutex, TIMEOUT_BLOCK);
936
    if (!ata_powered) ata_power_up();
936
    if (!ata_powered) PASS_RC(ata_power_up(), 1, 0);
937
    ata_set_active();
937
    ata_set_active();
938
    if (ceata) rc = ceata_soft_reset();
938
    if (ceata) rc = ceata_soft_reset();
939
    else
939
    else
940
    {
940
    {
941
        ata_write_cbr(&ATA_PIO_DAD, BIT(1) | BIT(2));
941
        ata_write_cbr(&ATA_PIO_DAD, BIT(1) | BIT(2));
Line 949... Line 949...
949
        sleep(3000000);
949
        sleep(3000000);
950
        ata_power_up();
950
        ata_power_up();
951
    }
951
    }
952
    ata_set_active();
952
    ata_set_active();
953
    mutex_unlock(&ata_mutex);
953
    mutex_unlock(&ata_mutex);
954
    return rc;
954
    PASS_RC(rc, 1, 1);
955
}
955
}
956
 
956
 
957
int ata_read_sectors(IF_MD2(int drive,) unsigned long start, int incount,
957
int ata_read_sectors(IF_MD2(int drive,) unsigned long start, int incount,
958
                     void* inbuf)
958
                     void* inbuf)
959
{
959
{
Line 1026... Line 1026...
1026
    ata_bbt = NULL;
1026
    ata_bbt = NULL;
1027
    ata_virtual_sectors = ata_total_sectors;
1027
    ata_virtual_sectors = ata_total_sectors;
1028
    mutex_unlock(&ata_mutex);
1028
    mutex_unlock(&ata_mutex);
1029
}
1029
}
1030
 
1030
 
1031
void ata_bbt_reload()
1031
int ata_bbt_reload()
1032
{
1032
{
1033
    mutex_lock(&ata_mutex, TIMEOUT_BLOCK);
1033
    mutex_lock(&ata_mutex, TIMEOUT_BLOCK);
1034
    ata_bbt_disable();
1034
    ata_bbt_disable();
1035
    ata_power_up();
1035
    PASS_RC(ata_power_up(), 0, 0);
1036
    uint32_t* buf = (uint32_t*)memalign(0x10, 0x1000);
1036
    uint32_t* buf = (uint32_t*)memalign(0x10, 0x1000);
1037
    if (buf)
1037
    if (buf)
1038
    {
1038
    {
1039
        if (IS_ERR(ata_bbt_read_sectors(0, 1, buf)))
1039
        if (IS_ERR(ata_bbt_read_sectors(0, 1, buf)))
1040
            ata_virtual_sectors = ata_total_sectors;
1040
            ata_virtual_sectors = ata_total_sectors;
Line 1102... Line 1102...
1102
        PCON(10) = (PCON(10) & ~0xffff) | 0x4444;
1102
        PCON(10) = (PCON(10) & ~0xffff) | 0x4444;
1103
    }
1103
    }
1104
    ata_powered = false;
1104
    ata_powered = false;
1105
    ata_total_sectors = 0;
1105
    ata_total_sectors = 0;
1106
#ifdef ATA_HAVE_BBT
1106
#ifdef ATA_HAVE_BBT
1107
    ata_bbt_reload();
1107
    PASS_RC(ata_bbt_reload(), 0, 0);
1108
#endif
1108
#endif
1109
    thread_create(&ata_thread_handle, "ATA idle monitor", ata_thread, ata_stack,
1109
    thread_create(&ata_thread_handle, "ATA idle monitor", ata_thread, ata_stack,
1110
                  sizeof(ata_stack), OS_THREAD, 1, true, NULL, NULL, NULL, NULL);
1110
                  sizeof(ata_stack), OS_THREAD, 1, true, NULL, NULL, NULL, NULL);
1111
    return 0;
1111
    return 0;
1112
}
1112
}