1 // Low level ATA disk definitions
3 // Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
4 // Copyright (C) 2002 MandrakeSoft S.A.
6 // This file may be distributed under the terms of the GNU GPLv3 license.
11 #include "types.h" // u16
14 struct ata_pio_command {
33 // Function definitions
34 void ata_reset(u16 device);
35 int ata_transfer(struct ata_pio_command *cmd);
36 int ata_cmd_packet(u16 device, u8 *cmdbuf, u8 cmdlen
37 , u16 header, u32 length, u16 bufseg, u16 bufoff);
38 int cdrom_read(u16 device, u32 lba, u32 count
39 , u16 segment, u16 offset, u16 skip);
43 ata_cmd_data(u16 biosid, u16 command, u32 lba, u16 count
44 , u16 segment, u16 offset)
46 u8 slave = biosid % 2;
48 struct ata_pio_command cmd;
50 cmd.segment = segment;
53 if (count >= (1<<8) || lba + count >= (1<<28)) {
54 cmd.sector_count2 = count >> 8;
55 cmd.lba_low2 = lba >> 24;
64 cmd.sector_count = count;
66 cmd.lba_mid = lba >> 8;
67 cmd.lba_high = lba >> 16;
68 cmd.device = ((slave ? ATA_CB_DH_DEV1 : ATA_CB_DH_DEV0)
69 | ((lba >> 24) & 0xf) | ATA_CB_DH_LBA);
70 cmd.command = command;
71 return ata_transfer(&cmd);
75 ata_cmd_data_chs(u16 biosid, u16 command, u16 cyl, u16 head, u16 sect, u16 count
76 , u16 segment, u16 offset)
78 u8 slave = biosid % 2;
80 struct ata_pio_command cmd;
82 cmd.segment = segment;
85 cmd.sector_count = count & 0xff;
89 cmd.lba_high = cyl >> 8;
90 cmd.device = (slave ? ATA_CB_DH_DEV1 : ATA_CB_DH_DEV0) | (head & 0xff);
91 cmd.command = command;
92 return ata_transfer(&cmd);