blob: 8d7c508a28c3effe5847d5f2e158cf2f5bb04034 [file] [log] [blame]
Kevin O'Connorc09492e2008-03-01 13:38:07 -05001// Low level ATA disk definitions
2//
3// Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
4// Copyright (C) 2002 MandrakeSoft S.A.
5//
6// This file may be distributed under the terms of the GNU GPLv3 license.
7
Kevin O'Connor6eee8ca2008-03-03 20:14:12 -05008#ifndef __ATA_H
9#define __ATA_H
10
Kevin O'Connor3491e8b2008-02-29 00:22:27 -050011#include "types.h" // u16
Kevin O'Connor1fcf1442008-03-11 19:42:41 -040012#include "atabits.h"
13
14struct ata_pio_command {
Kevin O'Connorefde6092008-03-12 20:33:15 -040015 void *far_buffer;
Kevin O'Connor1fcf1442008-03-11 19:42:41 -040016 u8 biosid;
17
18 u8 feature;
19 u8 sector_count;
20 u8 lba_low;
21 u8 lba_mid;
22 u8 lba_high;
23 u8 device;
24 u8 command;
25
26 u8 sector_count2;
27 u8 lba_low2;
28 u8 lba_mid2;
29 u8 lba_high2;
30};
Kevin O'Connor3491e8b2008-02-29 00:22:27 -050031
32// Function definitions
33void ata_reset(u16 device);
Kevin O'Connor1fcf1442008-03-11 19:42:41 -040034int ata_transfer(struct ata_pio_command *cmd);
35int ata_cmd_packet(u16 device, u8 *cmdbuf, u8 cmdlen
Kevin O'Connorefde6092008-03-12 20:33:15 -040036 , u16 header, u32 length, void *far_buffer);
Kevin O'Connor1fcf1442008-03-11 19:42:41 -040037int cdrom_read(u16 device, u32 lba, u32 count
Kevin O'Connorefde6092008-03-12 20:33:15 -040038 , void *far_buffer, u16 skip);
Kevin O'Connor15aee2e2008-03-01 13:34:04 -050039void ata_detect();
Kevin O'Connor3491e8b2008-02-29 00:22:27 -050040
Kevin O'Connor1fcf1442008-03-11 19:42:41 -040041static inline int
Kevin O'Connorefde6092008-03-12 20:33:15 -040042ata_cmd_data(u16 biosid, u16 command, u32 lba, u16 count, void *far_buffer)
Kevin O'Connor1fcf1442008-03-11 19:42:41 -040043{
44 u8 slave = biosid % 2;
Kevin O'Connor3491e8b2008-02-29 00:22:27 -050045
Kevin O'Connor1fcf1442008-03-11 19:42:41 -040046 struct ata_pio_command cmd;
Kevin O'Connorefde6092008-03-12 20:33:15 -040047 cmd.far_buffer = far_buffer;
Kevin O'Connor1fcf1442008-03-11 19:42:41 -040048 cmd.biosid = biosid;
Kevin O'Connor3491e8b2008-02-29 00:22:27 -050049
Kevin O'Connor1fcf1442008-03-11 19:42:41 -040050 if (count >= (1<<8) || lba + count >= (1<<28)) {
51 cmd.sector_count2 = count >> 8;
52 cmd.lba_low2 = lba >> 24;
53 cmd.lba_mid2 = 0;
54 cmd.lba_high2 = 0;
Kevin O'Connor3491e8b2008-02-29 00:22:27 -050055
Kevin O'Connor1fcf1442008-03-11 19:42:41 -040056 command |= 0x04;
57 lba &= 0xffffff;
58 }
Kevin O'Connor3491e8b2008-02-29 00:22:27 -050059
Kevin O'Connor1fcf1442008-03-11 19:42:41 -040060 cmd.feature = 0;
61 cmd.sector_count = count;
62 cmd.lba_low = lba;
63 cmd.lba_mid = lba >> 8;
64 cmd.lba_high = lba >> 16;
65 cmd.device = ((slave ? ATA_CB_DH_DEV1 : ATA_CB_DH_DEV0)
66 | ((lba >> 24) & 0xf) | ATA_CB_DH_LBA);
67 cmd.command = command;
68 return ata_transfer(&cmd);
69}
Kevin O'Connor3491e8b2008-02-29 00:22:27 -050070
Kevin O'Connor1fcf1442008-03-11 19:42:41 -040071static inline int
72ata_cmd_data_chs(u16 biosid, u16 command, u16 cyl, u16 head, u16 sect, u16 count
Kevin O'Connorefde6092008-03-12 20:33:15 -040073 , void *far_buffer)
Kevin O'Connor1fcf1442008-03-11 19:42:41 -040074{
75 u8 slave = biosid % 2;
Kevin O'Connor3491e8b2008-02-29 00:22:27 -050076
Kevin O'Connor1fcf1442008-03-11 19:42:41 -040077 struct ata_pio_command cmd;
Kevin O'Connorefde6092008-03-12 20:33:15 -040078 cmd.far_buffer = far_buffer;
Kevin O'Connor1fcf1442008-03-11 19:42:41 -040079 cmd.biosid = biosid;
Kevin O'Connor3491e8b2008-02-29 00:22:27 -050080
Kevin O'Connor1fcf1442008-03-11 19:42:41 -040081 cmd.sector_count = count & 0xff;
82 cmd.feature = 0;
83 cmd.lba_low = sect;
84 cmd.lba_mid = cyl;
85 cmd.lba_high = cyl >> 8;
86 cmd.device = (slave ? ATA_CB_DH_DEV1 : ATA_CB_DH_DEV0) | (head & 0xff);
87 cmd.command = command;
88 return ata_transfer(&cmd);
89}
Kevin O'Connor3491e8b2008-02-29 00:22:27 -050090
Kevin O'Connor6eee8ca2008-03-03 20:14:12 -050091#endif /* __ATA_H */