Subversion Repositories freemyipod

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
346 theseven 1
//
2
//
3
//    Copyright 2010 TheSeven
4
//
5
//
427 farthen 6
//    This file is part of emCORE.
346 theseven 7
//
427 farthen 8
//    emCORE is free software: you can redistribute it and/or
346 theseven 9
//    modify it under the terms of the GNU General Public License as
10
//    published by the Free Software Foundation, either version 2 of the
11
//    License, or (at your option) any later version.
12
//
427 farthen 13
//    emCORE is distributed in the hope that it will be useful,
346 theseven 14
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
//    See the GNU General Public License for more details.
17
//
18
//    You should have received a copy of the GNU General Public License along
427 farthen 19
//    with emCORE.  If not, see <http://www.gnu.org/licenses/>.
346 theseven 20
//
21
//
22
 
23
 
24
#include "global.h"
25
#include "usb/usbtarget.h"
891 theseven 26
#include "usb/usb.h"
346 theseven 27
#include "storage_ata-target.h"
601 theseven 28
#include "thread.h"
346 theseven 29
 
30
 
891 theseven 31
int usb_target_handle_request(uint32_t* buf, int bufsize, void** addr)
346 theseven 32
{
891 theseven 33
    int len = 0;
34
    switch (buf[0])
346 theseven 35
    {
36
        case 0xffff0001:  // GET DISK INFO
891 theseven 37
            buf[0] = 1;
38
            buf[1] = (uint32_t)ata_identify_data;
39
            buf[2] = ata_total_sectors;
40
            buf[3] = ata_total_sectors >> 32;
346 theseven 41
#ifdef ATA_HAVE_BBT
891 theseven 42
            buf[4] = ata_virtual_sectors;
43
            buf[5] = ata_virtual_sectors >> 32;
44
            buf[6] = (uint32_t)ata_bbt;
45
            buf[7] = 0;
346 theseven 46
#else
891 theseven 47
            buf[4] = ata_total_sectors;
48
            buf[5] = ata_total_sectors >> 32;
49
            buf[6] = 0;
50
            buf[7] = 0;
346 theseven 51
#endif
891 theseven 52
            len = 16;
346 theseven 53
            break;
54
        case 0xffff0002:  // LOWLEVEL DISK ACCESS
891 theseven 55
            buf[0] = 1;
601 theseven 56
            mutex_lock(&ata_mutex, TIMEOUT_BLOCK);
348 theseven 57
#ifdef ATA_HAVE_BBT
891 theseven 58
            buf[1] = (uint32_t)ata_rw_sectors_internal((((uint64_t)(buf[3])) << 32) | buf[2],
59
                                                       buf[4], (void*)(buf[5]), (bool)(buf[1]));
348 theseven 60
#else
891 theseven 61
            buf[1] = (uint32_t)ata_rw_sectors((((uint64_t)(buf[3])) << 32) | buf[2],
62
                                              buf[4], (void*)(buf[5]), (bool)(buf[1]));
348 theseven 63
#endif
601 theseven 64
            mutex_unlock(&ata_mutex);
346 theseven 65
            break;
613 theseven 66
        case 0xffff0003:  // ATA_BBT_RELOAD
67
            ata_bbt_reload();
891 theseven 68
            buf[0] = 1;
613 theseven 69
            break;
70
        case 0xffff0004:  // ATA_BBT_DISABLE
71
            ata_bbt_disable();
891 theseven 72
            buf[0] = 1;
613 theseven 73
            break;
346 theseven 74
        default:
891 theseven 75
            buf[0] = 2;
76
            break;
346 theseven 77
    }
891 theseven 78
    return len;
79
}