Subversion Repositories freemyipod

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
301 theseven 1
/***************************************************************************
2
 *             __________               __   ___.
3
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
4
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
5
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
6
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
7
 *                     \/            \/     \/    \/            \/
8
 * $Id$
9
 *
10
 * Copyright (C) 2007 Dave Chapman
11
 *
12
 * This program is free software; you can redistribute it and/or
13
 * modify it under the terms of the GNU General Public License
14
 * as published by the Free Software Foundation; either version 2
15
 * of the License, or (at your option) any later version.
16
 *
17
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18
 * KIND, either express or implied.
19
 *
20
 ****************************************************************************/
21
#include "global.h"
22
#include "thread.h"
23
#include "disk.h"
24
#include "storage.h"
25
#include "timer.h"
26
#include "../ipodnano3g/s5l8702.h"
27
 
28
/** static, private data **/ 
29
uint16_t ata_identify_data[0x100];
30
bool ata_lba48;
31
bool ata_dma;
32
uint64_t ata_total_sectors;
33
static struct mutex ata_mutex;
34
static struct wakeup ata_wakeup;
35
static uint32_t ata_dma_flags;
36
static long ata_last_activity_value = -1;
37
static long ata_sleep_timeout = 20000000;
38
static uint32_t ata_stack[0x80];
39
static bool ata_powered;
40
 
328 theseven 41
#ifdef ATA_HAVE_BBT
42
#include "panic.h"
43
uint16_t ata_bbt[ATA_BBT_PAGES][0x20];
44
uint32_t ata_virtual_sectors;
337 theseven 45
uint32_t ata_last_offset;
46
uint64_t ata_last_phys;
301 theseven 47
 
328 theseven 48
int ata_rw_sectors_internal(uint64_t sector, uint32_t count, void* buffer, bool write);
49
 
50
void ata_bbt_read_sectors(uint32_t sector, uint32_t count, void* buffer)
51
{
52
    int rc = ata_rw_sectors_internal(sector, count, buffer, false);
53
    if (IS_ERR(rc))
54
        panicf(PANIC_KILLTHREAD, "ATA: Error %08X while reading BBT (sector %d, count %d)\n",
55
               rc, sector, count);
56
}
57
#endif
58
 
59
 
301 theseven 60
static uint16_t ata_read_cbr(uint32_t volatile* reg)
61
{
317 theseven 62
    while (!(ATA_PIO_READY & 2)) yield();
301 theseven 63
    volatile uint32_t dummy = *reg;
317 theseven 64
    while (!(ATA_PIO_READY & 1)) yield();
301 theseven 65
    return ATA_PIO_RDATA;
66
}
67
 
68
static void ata_write_cbr(uint32_t volatile* reg, uint16_t data)
69
{
317 theseven 70
    while (!(ATA_PIO_READY & 2)) yield();
301 theseven 71
    *reg = data;
72
}
73
 
74
static int ata_wait_for_not_bsy(long timeout)
75
{
76
    long startusec = USEC_TIMER;
77
    while (true)
78
    {
79
        uint8_t csd = ata_read_cbr(&ATA_PIO_CSD);
80
        if (!(csd & BIT(7))) return 0;
81
        if (TIMEOUT_EXPIRED(startusec, timeout)) RET_ERR(0);
82
    }
83
}
84
 
85
static int ata_wait_for_rdy(long timeout)
86
{
87
    long startusec = USEC_TIMER;
88
    PASS_RC(ata_wait_for_not_bsy(timeout), 1, 0);
89
    while (true)
90
    {
91
        uint8_t dad = ata_read_cbr(&ATA_PIO_DAD);
92
        if (dad & BIT(6)) return 0;
93
        if (TIMEOUT_EXPIRED(startusec, timeout)) RET_ERR(1);
94
    }
95
}
96
 
97
static int ata_wait_for_start_of_transfer(long timeout)
98
{
99
    long startusec = USEC_TIMER;
100
    PASS_RC(ata_wait_for_not_bsy(timeout), 2, 0);
101
    while (true)
102
    {
103
        uint8_t dad = ata_read_cbr(&ATA_PIO_DAD);
104
        if (dad & BIT(0)) RET_ERR(1);
105
        if ((dad & (BIT(7) | BIT(3))) == BIT(3)) return 0;
106
        if (TIMEOUT_EXPIRED(startusec, timeout)) RET_ERR(2);
107
    }
108
}
109
 
110
static int ata_wait_for_end_of_transfer(long timeout)
111
{
112
    PASS_RC(ata_wait_for_not_bsy(timeout), 2, 0);
113
    uint8_t dad = ata_read_cbr(&ATA_PIO_DAD);
114
    if (dad & BIT(0)) RET_ERR(1);
115
    if ((dad & (BIT(3) | BITRANGE(5, 7))) == BIT(6)) return 0;
116
    RET_ERR(2);
117
}    
118
 
119
int ata_identify(uint16_t* buf)
120
{
121
    int i;
122
    PASS_RC(ata_wait_for_not_bsy(10000000), 1, 0);
123
    ata_write_cbr(&ATA_PIO_DVR, 0);
124
    ata_write_cbr(&ATA_PIO_CSD, 0xec);
125
    PASS_RC(ata_wait_for_start_of_transfer(10000000), 1, 1);
126
    for (i = 0; i < 0x100; i++)
127
    {
128
        uint16_t word = ata_read_cbr(&ATA_PIO_DTR);
129
        buf[i] = (word >> 8) | (word << 8);
130
    }
131
}
132
 
133
void ata_set_active(void)
134
{
135
    ata_last_activity_value = USEC_TIMER;
136
}
137
 
317 theseven 138
int ata_set_feature(uint32_t feature, uint32_t param)
139
{
140
    PASS_RC(ata_wait_for_rdy(500000), 1, 0);
141
    ata_write_cbr(&ATA_PIO_DVR, 0);
142
    ata_write_cbr(&ATA_PIO_FED, 3);
143
    ata_write_cbr(&ATA_PIO_SCR, param);
144
    ata_write_cbr(&ATA_PIO_CSD, feature);
145
    PASS_RC(ata_wait_for_rdy(500000), 1, 1);
146
    return 0;
147
}
148
 
301 theseven 149
int ata_power_up()
150
{
151
    ata_set_active();
152
    i2c_sendbyte(0, 0xe6, 0x1b, 1);
153
    clockgate_enable(5, true);
154
    ATA_CFG = BIT(0);
155
    sleep(1000);
156
    ATA_CFG = 0;
157
    sleep(6000);
158
    ATA_SWRST = BIT(0);
159
    sleep(500);
160
    ATA_SWRST = 0;
161
    sleep(90000);
162
    ATA_CONTROL = BIT(0);
163
    sleep(200000);
164
    ATA_PIO_TIME = 0x191f7;
165
    ATA_PIO_LHR = 0;
166
    while (!(ATA_PIO_READY & BIT(1))) sleep(100);
167
    PASS_RC(ata_identify(ata_identify_data), 2, 0);
168
    uint32_t piotime = 0x11f3;
169
    uint32_t mdmatime = 0x1c175;
170
    uint32_t udmatime = 0x5071152;
171
    uint32_t param = 0;
172
    ata_dma_flags = 0;
173
    ata_lba48 = ata_identify_data[83] & BIT(10) ? true : false;
174
    if (ata_lba48)
175
        ata_total_sectors = ata_identify_data[100]
176
                          | (((uint64_t)ata_identify_data[101]) << 16)
177
                          | (((uint64_t)ata_identify_data[102]) << 32)
178
                          | (((uint64_t)ata_identify_data[103]) << 48);
179
    else ata_total_sectors = ata_identify_data[60] | (((uint32_t)ata_identify_data[61]) << 16);
328 theseven 180
    ata_total_sectors >>= 3;
301 theseven 181
    if (ata_identify_data[53] & BIT(1))
182
    {
183
        if (ata_identify_data[64] & BIT(1)) piotime = 0x2072;
184
        else if (ata_identify_data[64] & BIT(0)) piotime = 0x7083;
185
    }
186
    if (ata_identify_data[63] & BIT(2))
187
    {
188
        mdmatime = 0x5072;
189
        param = 0x22;
190
    }
191
    else if (ata_identify_data[63] & BIT(1))
192
    {
193
        mdmatime = 0x7083;
194
        param = 0x21;
195
    }
196
    if (ata_identify_data[63] & BITRANGE(0, 2))
197
    {
198
        ata_dma_flags = BIT(3) | BIT(10);
199
        param |= 0x20;
200
    }
201
    if (ata_identify_data[53] & BIT(2))
202
    {
203
        if (ata_identify_data[88] & BIT(4))
204
        {
205
            udmatime = 0x2010a52;
206
            param = 0x44;
207
        }
208
        else if (ata_identify_data[88] & BIT(3))
209
        {
210
            udmatime = 0x2020a52;
211
            param = 0x43;
212
        }
213
        else if (ata_identify_data[88] & BIT(2))
214
        {
215
            udmatime = 0x3030a52;
216
            param = 0x42;
217
        }
218
        else if (ata_identify_data[88] & BIT(1))
219
        {
220
            udmatime = 0x3050a52;
221
            param = 0x41;
222
        }
223
        if (ata_identify_data[88] & BITRANGE(0, 4))
224
        {
225
            ata_dma_flags = BIT(2) | BIT(3) | BIT(9) | BIT(10);
226
            param |= 0x40;
227
        }
228
    }
229
    ata_dma = param ? true : false;
317 theseven 230
    PASS_RC(ata_set_feature(0xef, param), 2, 1);
337 theseven 231
    if (ata_identify_data[82] & BIT(5)) PASS_RC(ata_set_feature(0x02, 0), 2, 2);
232
    if (ata_identify_data[82] & BIT(6)) PASS_RC(ata_set_feature(0x55, 0), 2, 3);
301 theseven 233
    ATA_PIO_TIME = piotime;
234
    ATA_MDMA_TIME = mdmatime;
235
    ATA_UDMA_TIME = udmatime;
236
    ata_powered = true;
237
    ata_set_active();
238
    return 0;
239
}
240
 
241
void ata_power_down()
242
{
243
    ata_powered = false;
244
    ata_wait_for_rdy(1000000);
245
    ata_write_cbr(&ATA_PIO_DVR, 0);
246
    ata_write_cbr(&ATA_PIO_CSD, 0xe0);
247
    ata_wait_for_rdy(1000000);
248
    sleep(30000);
249
    ATA_CONTROL = 0;
317 theseven 250
    while (!(ATA_CONTROL & BIT(1))) yield();
301 theseven 251
    clockgate_enable(5, false);
252
    i2c_sendbyte(0, 0xe6, 0x1b, 0);
253
}
254
 
337 theseven 255
int ata_rw_chunk(uint64_t sector, uint32_t cnt, void* buffer, bool write)
256
{
257
    PASS_RC(ata_wait_for_rdy(100000), 2, 0);
258
    ata_write_cbr(&ATA_PIO_DVR, 0);
259
    if (ata_lba48)
260
    {
261
        ata_write_cbr(&ATA_PIO_SCR, cnt >> 5);
262
        ata_write_cbr(&ATA_PIO_SCR, (cnt << 3) & 0xff);
263
        ata_write_cbr(&ATA_PIO_LHR, (sector >> 37) & 0xff);
264
        ata_write_cbr(&ATA_PIO_LMR, (sector >> 29) & 0xff);
265
        ata_write_cbr(&ATA_PIO_LLR, (sector >> 21) & 0xff);
266
        ata_write_cbr(&ATA_PIO_LHR, (sector >> 13) & 0xff);
267
        ata_write_cbr(&ATA_PIO_LMR, (sector >> 5) & 0xff);
268
        ata_write_cbr(&ATA_PIO_LLR, (sector << 3) & 0xff);
269
        ata_write_cbr(&ATA_PIO_DVR, BIT(6));
270
        if (write) ata_write_cbr(&ATA_PIO_CSD, ata_dma ? 0x35 : 0x39);
271
        else ata_write_cbr(&ATA_PIO_CSD, ata_dma ? 0x25 : 0x29);
272
    }
273
    else
274
    {
275
        ata_write_cbr(&ATA_PIO_SCR, (cnt << 3) & 0xff);
276
        ata_write_cbr(&ATA_PIO_LHR, (sector >> 13) & 0xff);
277
        ata_write_cbr(&ATA_PIO_LMR, (sector >> 5) & 0xff);
278
        ata_write_cbr(&ATA_PIO_LLR, (sector << 3) & 0xff);
279
        ata_write_cbr(&ATA_PIO_DVR, BIT(6) | ((sector >> 21) & 0xf));
280
        if (write) ata_write_cbr(&ATA_PIO_CSD, ata_dma ? 0xca : 0x30);
281
        else ata_write_cbr(&ATA_PIO_CSD, ata_dma ? 0xc8 : 0xc4);
282
    }
283
    if (ata_dma)
284
    {
285
        PASS_RC(ata_wait_for_start_of_transfer(500000), 2, 1);
286
        if (write)
287
        {
288
            ATA_SBUF_START = buffer;
289
            ATA_SBUF_SIZE = SECTOR_SIZE * cnt;
290
            ATA_CFG |= BIT(4);
291
        }
292
        else
293
        {
294
            ATA_TBUF_START = buffer;
295
            ATA_TBUF_SIZE = SECTOR_SIZE * cnt;
296
            ATA_CFG &= ~BIT(4);
297
        }
298
        ATA_XFR_NUM = SECTOR_SIZE * cnt - 1;
299
        ATA_CFG |= ata_dma_flags;
300
        ATA_CFG &= ~(BIT(7) | BIT(8));
301
        wakeup_wait(&ata_wakeup, TIMEOUT_NONE);
302
        ATA_IRQ = BITRANGE(0, 4);
303
        ATA_IRQ_MASK = BIT(0);
304
        ATA_COMMAND = BIT(0);
305
        if (wakeup_wait(&ata_wakeup, 500000) == THREAD_TIMEOUT)
306
        {
307
            ATA_COMMAND = BIT(1);
308
            ATA_CFG &= ~(BITRANGE(2, 3) | BIT(12));
309
            RET_ERR(2);
310
        }
311
        ATA_COMMAND = BIT(1);
312
        ATA_CFG &= ~(BITRANGE(2, 3) | BIT(12));
313
    }
314
    else
315
    {
316
        cnt *= SECTOR_SIZE / 512;
317
        while (cnt--)
318
        {
319
            int i;
320
            PASS_RC(ata_wait_for_start_of_transfer(500000), 2, 1);
321
            if (write)
322
                for (i = 0; i < 256; i++)
323
                    ata_write_cbr(&ATA_PIO_DTR, ((uint16_t*)buffer)[i]);
324
            else
325
                for (i = 0; i < 256; i++)
326
                    ((uint16_t*)buffer)[i] = ata_read_cbr(&ATA_PIO_DTR);
327
            buffer += 512;
328
        }
329
    }
330
    PASS_RC(ata_wait_for_end_of_transfer(100000), 2, 3);
331
    return 0;
332
}
333
 
301 theseven 334
int ata_rw_sectors(uint64_t sector, uint32_t count, void* buffer, bool write)
335
{
328 theseven 336
#ifdef ATA_HAVE_BBT
337
    if (sector + count > ata_virtual_sectors) RET_ERR(0);
338
    while (count)
339
    {
337 theseven 340
        uint32_t offset;
328 theseven 341
        uint32_t l0idx = sector >> 15;
342
        uint32_t l0offs = sector & 0x7fff;
343
        uint32_t cnt = MIN(count, 0x8000 - l0offs);
344
        uint32_t l0data = ata_bbt[0][l0idx << 1];
345
        uint32_t base = ata_bbt[0][(l0idx << 1) | 1] << 12;
337 theseven 346
        if (l0data < 0x8000) offset = l0data + base;
328 theseven 347
        else
348
        {
349
            uint32_t l1idx = (sector >> 10) & 0x1f;
350
            uint32_t l1offs = sector & 0x3ff;
351
            cnt = MIN(count, 0x400 - l1offs);
352
            uint32_t l1data = ata_bbt[l0data & 0x7fff][l1idx];
337 theseven 353
            if (l1data < 0x8000) offset = l1data + base;
328 theseven 354
            else
355
            {
356
                uint32_t l2idx = (sector >> 5) & 0x1f;
357
                uint32_t l2offs = sector & 0x1f;
358
                cnt = MIN(count, 0x20 - l2offs);
359
                uint32_t l2data = ata_bbt[l1data & 0x7fff][l2idx];
337 theseven 360
                if (l2data < 0x8000) offset = l2data + base;
328 theseven 361
                else
362
                {
363
                    uint32_t l3idx = sector & 0x1f;
337 theseven 364
                    uint32_t l3data = ata_bbt[l2data & 0x7fff][l3idx];
328 theseven 365
                    for (cnt = 1; cnt < count && l3idx + cnt < 0x20; cnt++)
337 theseven 366
                        if (ata_bbt[l2data & 0x7fff][l3idx + cnt] != l3data)
328 theseven 367
                            break;
337 theseven 368
                    offset = l3data + base;
328 theseven 369
                }
370
            }
371
        }
337 theseven 372
        uint64_t phys = sector + offset;
373
        if (offset != ata_last_offset && phys - ata_last_phys < 64) ata_soft_reset();
374
        ata_last_offset = offset;
375
        ata_last_phys = phys + cnt;
328 theseven 376
        PASS_RC(ata_rw_sectors_internal(phys, cnt, buffer, write), 0, 0);
377
        buffer += cnt * SECTOR_SIZE;
378
        sector += cnt;
379
        count -= cnt;
380
    }
381
    return 0;
382
}
383
 
384
int ata_rw_sectors_internal(uint64_t sector, uint32_t count, void* buffer, bool write)
385
{
386
#endif
301 theseven 387
    if (sector + count > ata_total_sectors) RET_ERR(0);
388
    if (!ata_powered) ata_power_up();
389
    ata_set_active();
390
    if (ata_dma && write) clean_dcache();
391
    else if (ata_dma) invalidate_dcache();
392
    ATA_COMMAND = BIT(1);
393
    while (count)
394
    {
317 theseven 395
        uint32_t cnt = MIN(ata_lba48 ? 8192 : 32, count);
337 theseven 396
        int rc = -1;
397
        int tries = 3;
398
        while (tries-- && rc)
301 theseven 399
        {
337 theseven 400
            rc = ata_rw_chunk(sector, cnt, buffer, write);
401
            if (rc) ata_soft_reset();
301 theseven 402
        }
337 theseven 403
        if (rc)
301 theseven 404
        {
337 theseven 405
            void* buf = buffer;
406
            int sect;
407
            for (sect = sector; sect < sector + cnt; sect++)
408
            {
409
                rc = -1;
410
                tries = 3;
411
                while (tries-- && rc)
412
                {
413
                    rc = ata_rw_chunk(sect, 1, buf, write);
414
                    if (rc) ata_soft_reset();
415
                }
416
                if (rc) break;
417
                buf += SECTOR_SIZE;
418
            }
301 theseven 419
        }
337 theseven 420
        PASS_RC(rc, 1, 1);
421
        buffer += SECTOR_SIZE * cnt;
301 theseven 422
        sector += cnt;
423
        count -= cnt;
424
    }
425
    ata_set_active();
426
    return 0;
427
}
428
 
429
static void ata_thread(void)
430
{
431
    while (true)
432
    {
433
        mutex_lock(&ata_mutex, TIMEOUT_BLOCK);
434
        if (TIME_AFTER(USEC_TIMER, ata_last_activity_value + ata_sleep_timeout) && ata_powered)
435
            ata_power_down();
436
        mutex_unlock(&ata_mutex);
437
        sleep(1000000);
438
    }
439
}
440
 
441
/* API Functions */
442
int ata_soft_reset()
443
{
444
    mutex_lock(&ata_mutex, TIMEOUT_BLOCK);
445
    if (!ata_powered) ata_power_up();
446
    ata_set_active();
447
    ata_write_cbr(&ATA_PIO_DAD, BIT(1) | BIT(2));
448
    sleep(10);
449
    ata_write_cbr(&ATA_PIO_DAD, 0);
337 theseven 450
    PASS_RC_MTX(ata_wait_for_rdy(60000000), 0, 0, &ata_mutex);
301 theseven 451
    ata_set_active();
452
    mutex_unlock(&ata_mutex);
453
}
454
 
455
int ata_read_sectors(IF_MD2(int drive,) unsigned long start, int incount,
456
                     void* inbuf)
457
{
458
    mutex_lock(&ata_mutex, TIMEOUT_BLOCK);
337 theseven 459
    int rc = ata_rw_sectors(start, incount, inbuf, false);
301 theseven 460
    mutex_unlock(&ata_mutex);
461
    return rc;
462
}
463
 
464
int ata_write_sectors(IF_MD2(int drive,) unsigned long start, int count,
465
                      const void* outbuf)
466
{
467
    mutex_lock(&ata_mutex, TIMEOUT_BLOCK);
337 theseven 468
    int rc = ata_rw_sectors(start, count, (void*)((uint32_t)outbuf), true);
301 theseven 469
    mutex_unlock(&ata_mutex);
470
    return rc;
471
}
472
 
337 theseven 473
void ata_spindown(int seconds)
474
{
475
    ata_sleep_timeout = seconds * 1000000;
476
}
301 theseven 477
 
478
void ata_sleep(void)
479
{
480
    mutex_lock(&ata_mutex, TIMEOUT_BLOCK);
481
    ata_power_down();
482
    mutex_unlock(&ata_mutex);
483
}
484
 
485
void ata_sleepnow(void)
486
{
487
    ata_sleep();
488
}
489
 
490
void ata_close(void)
491
{
492
    ata_sleep();
493
}
494
 
495
void ata_spin(void)
496
{
497
    ata_power_up();
498
}
499
 
500
void ata_get_info(IF_MD2(int drive,) struct storage_info *info)
501
{
502
    (*info).sector_size = SECTOR_SIZE;
328 theseven 503
#ifdef ATA_HAVE_BBT
504
    (*info).num_sectors = ata_virtual_sectors;
505
#else
301 theseven 506
    (*info).num_sectors = ata_total_sectors;
328 theseven 507
#endif
301 theseven 508
    (*info).vendor = "Apple";
509
    (*info).product = "iPod Classic";
510
    (*info).revision = "1.0";
511
}
512
 
513
long ata_last_disk_activity(void)
514
{
515
    return ata_last_activity_value;
516
}
517
 
518
int ata_init(void)
519
{
520
    mutex_init(&ata_mutex);
521
    wakeup_init(&ata_wakeup);
522
    PCON(7) = 0x44444444;
523
    PCON(8) = 0x44444444;
524
    PCON(9) = 0x44444444;
525
    PCON(10) = (PCON(10) & ~0xffff) | 0x4444;
526
    ata_powered = false;
527
    ata_total_sectors = 0;
328 theseven 528
#ifdef ATA_HAVE_BBT
529
    mutex_lock(&ata_mutex, TIMEOUT_BLOCK);
530
    memset(ata_bbt, 0, sizeof(ata_bbt));
531
    ata_power_up();
532
    uint32_t* buf = (uint32_t*)(ata_bbt[ARRAYLEN(ata_bbt) - 64]);
533
    ata_bbt_read_sectors(0, 1, buf);
534
    if (!memcmp(buf, "emBIbbth", 8))
535
    {
536
        ata_virtual_sectors = buf[0x1fe];
537
        uint32_t count = buf[0x1ff];
538
        if (count > (ATA_BBT_PAGES >> 6))
337 theseven 539
            panicf(PANIC_KILLTHREAD, "ATA: BBT too big! (%d pages, limit: %d)\n", count << 6, ATA_BBT_PAGES);
328 theseven 540
        uint32_t i;
541
        uint32_t cnt;
542
        for (i = 0; i < count; i += cnt)
543
        {
544
            uint32_t phys = buf[0x200 + i];
545
            for (cnt = 1; cnt < count; cnt++)
546
                if (buf[0x200 + i + cnt] != phys + cnt)
547
                    break;
548
            ata_bbt_read_sectors(phys, cnt, ata_bbt[i << 6]);
549
        }
550
    }
551
    else ata_virtual_sectors = ata_total_sectors;
552
    mutex_unlock(&ata_mutex);
553
#endif
301 theseven 554
    thread_create("ATA idle monitor", ata_thread, ata_stack,
555
                  sizeof(ata_stack), USER_THREAD, 1, true);
556
    return 0;
557
}
558
 
559
#ifdef CONFIG_STORAGE_MULTI
560
int ata_num_drives(int first_drive)
561
{
562
    /* We don't care which logical drive number(s) we have been assigned */
563
    (void)first_drive;
564
 
565
    return 1;
566
}
567
#endif
568
 
569
void INT_ATA()
570
{
571
    uint32_t ata_irq = ATA_IRQ;
572
    ATA_IRQ = ata_irq;
573
    if (ata_irq & ATA_IRQ_MASK) wakeup_signal(&ata_wakeup);
574
    ATA_IRQ_MASK = 0;
575
}