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"
26
#include "usb/usbdrv.h"
27
#include "storage_ata-target.h"
601 theseven 28
#include "thread.h"
346 theseven 29
 
30
 
31
int usb_target_handle_request(uint32_t* buffer, int bufsize)
32
{
33
    int size = 0;
34
    switch (buffer[0])
35
    {
36
        case 0xffff0001:  // GET DISK INFO
37
        {
38
            buffer[0] = 1;
39
            buffer[1] = (uint32_t)ata_identify_data;
40
            buffer[2] = ata_total_sectors;
41
            buffer[3] = ata_total_sectors >> 32;
42
#ifdef ATA_HAVE_BBT
43
            buffer[4] = ata_virtual_sectors;
44
            buffer[5] = ata_virtual_sectors >> 32;
45
            buffer[6] = (uint32_t)ata_bbt;
432 theseven 46
            buffer[7] = 0;
346 theseven 47
#else
48
            buffer[4] = ata_total_sectors;
49
            buffer[5] = ata_total_sectors >> 32;
50
            buffer[6] = 0;
51
            buffer[7] = 0;
52
#endif
53
            size = 32;
54
            break;
55
        }
56
        case 0xffff0002:  // LOWLEVEL DISK ACCESS
57
        {
601 theseven 58
            mutex_lock(&ata_mutex, TIMEOUT_BLOCK);
348 theseven 59
#ifdef ATA_HAVE_BBT
346 theseven 60
            int rc = ata_rw_sectors_internal((((uint64_t)(buffer[3])) << 32) | buffer[2],
61
                                             buffer[4], (void*)(buffer[5]), (bool)(buffer[1]));
348 theseven 62
#else
63
            int rc = ata_rw_sectors((((uint64_t)(buffer[3])) << 32) | buffer[2],
64
                                    buffer[4], (void*)(buffer[5]), (bool)(buffer[1]));
65
#endif
601 theseven 66
            mutex_unlock(&ata_mutex);
346 theseven 67
            buffer[0] = 1;
68
            buffer[1] = (uint32_t)rc;
69
            size = 16;
70
            break;
71
        }
613 theseven 72
        case 0xffff0003:  // ATA_BBT_RELOAD
73
        {
74
            ata_bbt_reload();
75
            buffer[0] = 1;
76
            size = 16;
77
            break;
78
        }
79
        case 0xffff0004:  // ATA_BBT_DISABLE
80
        {
81
            ata_bbt_disable();
82
            buffer[0] = 1;
83
            size = 16;
84
            break;
85
        }
346 theseven 86
        default:
87
            buffer[0] = 2;
88
            size = 16;
89
    }
90
    return size;
91
}