5 #include <gpxe/blockdev.h>
6 #include <gpxe/uaccess.h>
15 * An ATA Logical Block Address
17 * ATA controllers have three byte-wide registers for specifying the
18 * block address: LBA Low, LBA Mid and LBA High. This allows for a
19 * 24-bit address. Some devices support the "48-bit address feature
20 * set" (LBA48), in which case each of these byte-wide registers is
21 * actually a two-entry FIFO, and the "previous" byte pushed into the
22 * FIFO is used as the corresponding high-order byte. So, to set up
23 * the 48-bit address 0x12345678abcd, you would issue
25 * 0x56 -> LBA Low register
26 * 0xcd -> LBA Low register
27 * 0x34 -> LBA Mid register
28 * 0xab -> LBA Mid register
29 * 0x12 -> LBA High register
30 * 0x78 -> LBA High register
32 * This structure encapsulates this information by providing a single
33 * 64-bit integer in native byte order, unioned with bytes named so
34 * that the sequence becomes
36 * low_prev -> LBA Low register
37 * low_cur -> LBA Low register
38 * mid_prev -> LBA Mid register
39 * mid_cur -> LBA Mid register
40 * high_prev -> LBA High register
41 * high_cur -> LBA High register
43 * Just to complicate matters further, in non-LBA48 mode it is
44 * possible to have a 28-bit address, in which case bits 27:24 must be
45 * written into the low four bits of the Device register.
48 /** LBA as a 64-bit integer in native-endian order */
52 #if __BYTE_ORDER == __LITTLE_ENDIAN
60 #elif __BYTE_ORDER == __BIG_ENDIAN
69 #error "I need a byte order"
74 /** An ATA 2-byte FIFO register */
76 /** Value in native-endian order */
80 #if __BYTE_ORDER == __LITTLE_ENDIAN
83 #elif __BYTE_ORDER == __BIG_ENDIAN
87 #error "I need a byte order"
92 /** ATA command block */
94 /** Logical block address */
98 /** Error/feature register */
99 union ata_fifo err_feat;
100 /** Device register */
102 /** Command/status register */
106 * This field does not correspond to any ATA register.
111 /** LBA48 extended addressing */
112 #define ATA_FL_LBA48 0x40
114 /** Device 1 ("slave") */
115 #define ATA_FL_SLAVE 0x10
118 #define ATA_FL_WRITE 0x01
120 /** Obsolete bits in the ATA device register */
121 #define ATA_DEV_OBSOLETE 0xa0
123 /** LBA flag in the ATA device register */
124 #define ATA_DEV_LBA 0x40
126 /** "Read sectors" command */
127 #define ATA_CMD_READ 0x20
129 /** "Write sectors" command */
130 #define ATA_CMD_WRITE 0x30
132 /** "Identify" command */
133 #define ATA_CMD_IDENTIFY 0xec
135 /** "Extended (LBA48)" command modifier
137 * This doesn't apply to all ATA commands, but it does for @c
138 * ATA_CMD_READ and @c ATA_CMD_WRITE.
140 #define ATA_CMD_EXT 0x04
142 /** An ATA command */
144 /** ATA command block */
148 /** Data buffer length */
153 * Structure returned by ATA IDENTIFY command
155 * This is a huge structure with many fields that we don't care about,
156 * so we implement only a few fields.
158 struct ata_identity {
159 uint16_t ignore_a[60]; /* words 0-59 */
160 uint32_t lba_sectors; /* words 60-61 */
161 uint16_t ignore_b[21]; /* words 62-82 */
162 uint16_t supports_lba48; /* word 83 */
163 uint16_t ignore_c[16]; /* words 84-99 */
164 uint64_t lba48_sectors; /* words 100-103 */
165 uint16_t ignore_d[152]; /* words 104-255 */
168 /** Supports LBA48 flag */
169 #define ATA_SUPPORTS_LBA48 ( 1 << 10 )
171 /** ATA sector size */
172 #define ATA_SECTOR_SIZE 512
176 /** Block device interface */
177 struct block_device blockdev;
184 * @v command ATA command
185 * @ret rc Return status code
187 int ( * command ) ( struct ata_device *ata,
188 struct ata_command *command );
191 extern int init_atadev ( struct ata_device *ata );
193 #endif /* _GPXE_ATA_H */