Subversion Repositories freemyipod

Rev

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

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