Subversion Repositories freemyipod

Rev

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

Rev 54 Rev 57
Line 32... Line 32...
32
static unsigned int storage_drivers[NUM_DRIVES];
32
static unsigned int storage_drivers[NUM_DRIVES];
33
static unsigned int num_drives;
33
static unsigned int num_drives;
34
#endif
34
#endif
35
 
35
 
36
 
36
 
37
#ifdef HAVE_IO_PRIORITY
-
 
38
 
-
 
39
/* Same for flash? */
-
 
40
#define STORAGE_MINIMUM_IDLE_TIME (HZ/10)
-
 
41
#define STORAGE_DELAY_UNIT  (HZ/20)
-
 
42
 
-
 
43
static unsigned int storage_last_thread[NUM_DRIVES];
-
 
44
static unsigned int storage_last_activity[NUM_DRIVES];
-
 
45
 
-
 
46
static bool storage_should_wait(int drive, int prio)
-
 
47
{
-
 
48
    int other_prio = thread_get_io_priority(storage_last_thread[drive]);
-
 
49
    if(TIME_BEFORE(current_tick,storage_last_activity[drive]+STORAGE_MINIMUM_IDLE_TIME))
-
 
50
    {
-
 
51
        if(prio<=other_prio)
-
 
52
        {
-
 
53
            /* There is another active thread, but we have lower priority */
-
 
54
            return false;
-
 
55
        }
-
 
56
        else
-
 
57
        {
-
 
58
            /* There is another active thread, but it has lower priority */
-
 
59
            return true;
-
 
60
        }
-
 
61
    }
-
 
62
    else
-
 
63
    {
-
 
64
        /* There's nothing going on anyway */
-
 
65
        return false;
-
 
66
    }
-
 
67
}
-
 
68
 
-
 
69
static void storage_wait_turn(IF_MD_NONVOID(int drive))
-
 
70
{
-
 
71
#ifndef HAVE_MULTIDRIVE
-
 
72
    int drive=0;
-
 
73
#endif
-
 
74
    int my_prio = thread_get_io_priority(THREAD_ID_CURRENT);
-
 
75
    int loops=my_prio;
-
 
76
    while(storage_should_wait(drive, my_prio) && (loops--)>=0)
-
 
77
    {
-
 
78
        sleep(STORAGE_DELAY_UNIT);
-
 
79
    }
-
 
80
 
-
 
81
    storage_last_thread[drive] = thread_get_current();
-
 
82
    storage_last_activity[drive] = current_tick;
-
 
83
}
-
 
84
#endif
-
 
85
 
-
 
86
int storage_read_sectors(IF_MD2(int drive,) unsigned long start, int count,
37
int storage_read_sectors(IF_MD2(int drive,) unsigned long start, int count,
87
                         void* buf)
38
                         void* buf)
88
{
39
{
89
#ifdef HAVE_IO_PRIORITY
-
 
90
    storage_wait_turn(IF_MD(drive));
-
 
91
#endif
-
 
92
 
-
 
93
#ifdef CONFIG_STORAGE_MULTI
40
#ifdef CONFIG_STORAGE_MULTI
94
    int driver=(storage_drivers[drive] & DRIVER_MASK)>>DRIVER_OFFSET;
41
    int driver=(storage_drivers[drive] & DRIVER_MASK)>>DRIVER_OFFSET;
95
    int ldrive=(storage_drivers[drive] & DRIVE_MASK)>>DRIVE_OFFSET;
42
    int ldrive=(storage_drivers[drive] & DRIVE_MASK)>>DRIVE_OFFSET;
96
 
43
 
97
    switch (driver)
44
    switch (driver)
Line 130... Line 77...
130
}
77
}
131
 
78
 
132
int storage_write_sectors(IF_MD2(int drive,) unsigned long start, int count,
79
int storage_write_sectors(IF_MD2(int drive,) unsigned long start, int count,
133
                          const void* buf)
80
                          const void* buf)
134
{
81
{
135
#ifdef HAVE_IO_PRIORITY
-
 
136
    storage_wait_turn(IF_MD(drive));
-
 
137
#endif
-
 
138
 
-
 
139
#ifdef CONFIG_STORAGE_MULTI
82
#ifdef CONFIG_STORAGE_MULTI
140
    int driver=(storage_drivers[drive] & DRIVER_MASK)>>DRIVER_OFFSET;
83
    int driver=(storage_drivers[drive] & DRIVER_MASK)>>DRIVER_OFFSET;
141
    int ldrive=(storage_drivers[drive] & DRIVE_MASK)>>DRIVE_OFFSET;
84
    int ldrive=(storage_drivers[drive] & DRIVE_MASK)>>DRIVE_OFFSET;
142
    
85
    
143
    switch (driver)
86
    switch (driver)
Line 506... Line 449...
506
    if (t>max) max=t;
449
    if (t>max) max=t;
507
#endif
450
#endif
508
 
451
 
509
    return max;
452
    return max;
510
}
453
}
511
 
-
 
512
int storage_spinup_time(void)
-
 
513
{
-
 
514
    int max=0;
-
 
515
    int t;
-
 
516
    
-
 
517
#if (CONFIG_STORAGE & STORAGE_ATA)
-
 
518
    t=ata_spinup_time();
-
 
519
    if (t>max) max=t;
-
 
520
#endif
-
 
521
 
-
 
522
#if (CONFIG_STORAGE & STORAGE_MMC)
-
 
523
    t=mmc_spinup_time();
-
 
524
    if (t>max) max=t;
-
 
525
#endif
-
 
526
 
-
 
527
#if (CONFIG_STORAGE & STORAGE_SD)
-
 
528
    //t=sd_spinup_time();
-
 
529
    //if (t>max) max=t;
-
 
530
#endif
-
 
531
 
-
 
532
#if (CONFIG_STORAGE & STORAGE_NAND)
-
 
533
    t=nand_spinup_time();
-
 
534
    if (t>max) max=t;
-
 
535
#endif
-
 
536
 
-
 
537
#if (CONFIG_STORAGE & STORAGE_RAMDISK)
-
 
538
    t=ramdisk_spinup_time();
-
 
539
    if (t>max) max=t;
-
 
540
#endif
-
 
541
 
-
 
542
    return max;
-
 
543
}
-
 
544
 
454
 
545
#ifdef STORAGE_GET_INFO
455
#ifdef STORAGE_GET_INFO
546
void storage_get_info(int drive, struct storage_info *info)
456
void storage_get_info(int drive, struct storage_info *info)
547
{
457
{
548
    int driver=(storage_drivers[drive] & DRIVER_MASK)>>DRIVER_OFFSET;
458
    int driver=(storage_drivers[drive] & DRIVER_MASK)>>DRIVER_OFFSET;