1 /* ata.h - ATA disk access. */
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef GRUB_ATA_HEADER
21 #define GRUB_ATA_HEADER 1
23 #include <grub/misc.h>
24 #include <grub/symbol.h>
25 #include <grub/disk.h>
26 /* XXX: For now this only works on i386. */
27 #include <grub/cpu/io.h>
34 } grub_ata_addressing_t
;
36 #define GRUB_ATA_CH0_PORT1 0x1f0
37 #define GRUB_ATA_CH1_PORT1 0x170
39 #define GRUB_ATA_CH0_PORT2 0x3f6
40 #define GRUB_ATA_CH1_PORT2 0x376
42 #define GRUB_ATA_REG_DATA 0
43 #define GRUB_ATA_REG_ERROR 1
44 #define GRUB_ATA_REG_FEATURES 1
45 #define GRUB_ATA_REG_SECTORS 2
46 #define GRUB_ATAPI_REG_IREASON 2
47 #define GRUB_ATA_REG_SECTNUM 3
48 #define GRUB_ATA_REG_CYLLSB 4
49 #define GRUB_ATA_REG_CYLMSB 5
50 #define GRUB_ATA_REG_LBALOW 3
51 #define GRUB_ATA_REG_LBAMID 4
52 #define GRUB_ATAPI_REG_CNTLOW 4
53 #define GRUB_ATA_REG_LBAHIGH 5
54 #define GRUB_ATAPI_REG_CNTHIGH 5
55 #define GRUB_ATA_REG_DISK 6
56 #define GRUB_ATA_REG_CMD 7
57 #define GRUB_ATA_REG_STATUS 7
59 #define GRUB_ATA_REG2_CONTROL 0
61 #define GRUB_ATA_STATUS_ERR 0x01
62 #define GRUB_ATA_STATUS_INDEX 0x02
63 #define GRUB_ATA_STATUS_ECC 0x04
64 #define GRUB_ATA_STATUS_DRQ 0x08
65 #define GRUB_ATA_STATUS_SEEK 0x10
66 #define GRUB_ATA_STATUS_WRERR 0x20
67 #define GRUB_ATA_STATUS_READY 0x40
68 #define GRUB_ATA_STATUS_BUSY 0x80
70 /* ATAPI interrupt reason values (I/O, D/C bits). */
71 #define GRUB_ATAPI_IREASON_MASK 0x3
72 #define GRUB_ATAPI_IREASON_DATA_OUT 0x0
73 #define GRUB_ATAPI_IREASON_CMD_OUT 0x1
74 #define GRUB_ATAPI_IREASON_DATA_IN 0x2
75 #define GRUB_ATAPI_IREASON_ERROR 0x3
77 enum grub_ata_commands
79 GRUB_ATA_CMD_CHECK_POWER_MODE
= 0xe5,
80 GRUB_ATA_CMD_IDENTIFY_DEVICE
= 0xec,
81 GRUB_ATA_CMD_IDENTIFY_PACKET_DEVICE
= 0xa1,
82 GRUB_ATA_CMD_IDLE
= 0xe3,
83 GRUB_ATA_CMD_PACKET
= 0xa0,
84 GRUB_ATA_CMD_READ_SECTORS
= 0x20,
85 GRUB_ATA_CMD_READ_SECTORS_EXT
= 0x24,
86 GRUB_ATA_CMD_READ_SECTORS_DMA
= 0xc8,
87 GRUB_ATA_CMD_READ_SECTORS_DMA_EXT
= 0x25,
89 GRUB_ATA_CMD_SECURITY_FREEZE_LOCK
= 0xf5,
90 GRUB_ATA_CMD_SET_FEATURES
= 0xef,
91 GRUB_ATA_CMD_SLEEP
= 0xe6,
92 GRUB_ATA_CMD_SMART
= 0xb0,
93 GRUB_ATA_CMD_STANDBY_IMMEDIATE
= 0xe0,
94 GRUB_ATA_CMD_WRITE_SECTORS
= 0x30,
95 GRUB_ATA_CMD_WRITE_SECTORS_EXT
= 0x34,
96 GRUB_ATA_CMD_WRITE_SECTORS_DMA_EXT
= 0x35,
97 GRUB_ATA_CMD_WRITE_SECTORS_DMA
= 0xca,
100 enum grub_ata_timeout_milliseconds
102 GRUB_ATA_TOUT_STD
= 1000, /* 1s standard timeout. */
103 GRUB_ATA_TOUT_DATA
= 10000, /* 10s DATA I/O timeout. */
104 GRUB_ATA_TOUT_SPINUP
= 10000, /* Give the device 10s on first try to spinon. */
109 grub_uint8_t raw
[11];
114 grub_uint8_t features
;
119 grub_uint8_t sectors
;
120 grub_uint8_t atapi_ireason
;
124 grub_uint8_t lba_low
;
125 grub_uint8_t sectnum
;
129 grub_uint8_t lba_mid
;
131 grub_uint8_t atapi_cntlow
;
135 grub_uint8_t lba_high
;
137 grub_uint8_t atapi_cnthigh
;
145 grub_uint8_t sectors48
;
146 grub_uint8_t lba48_low
;
147 grub_uint8_t lba48_mid
;
148 grub_uint8_t lba48_high
;
152 /* ATA pass through parameters and function. */
153 struct grub_disk_ata_pass_through_parms
155 grub_ata_regs_t taskfile
;
166 /* Addressing methods available for accessing this device. If CHS
167 is only available, use that. Otherwise use LBA, except for the
168 high sectors. In that case use LBA48. */
169 grub_ata_addressing_t addr
;
173 grub_uint32_t log_sector_size
;
176 grub_uint16_t cylinders
;
178 grub_uint16_t sectors_per_track
;
180 /* Set to 0 for ATA, set to 1 for ATAPI. */
185 grub_size_t maxbuffer
;
191 struct grub_ata_dev
*dev
;
194 typedef struct grub_ata
*grub_ata_t
;
198 /* Call HOOK with each device name, until HOOK returns non-zero. */
199 int (*iterate
) (int (*hook
) (int id
, int bus
),
200 grub_disk_pull_t pull
);
202 /* Open the device named NAME, and set up SCSI. */
203 grub_err_t (*open
) (int id
, int bus
, struct grub_ata
*scsi
);
205 /* Close the scsi device SCSI. */
206 void (*close
) (struct grub_ata
*ata
);
208 /* Read SIZE bytes from the device SCSI into BUF after sending the
209 command CMD of size CMDSIZE. */
210 grub_err_t (*readwrite
) (struct grub_ata
*ata
,
211 struct grub_disk_ata_pass_through_parms
*parms
,
214 /* The next scsi device. */
215 struct grub_ata_dev
*next
;
218 typedef struct grub_ata_dev
*grub_ata_dev_t
;
220 void grub_ata_dev_register (grub_ata_dev_t dev
);
221 void grub_ata_dev_unregister (grub_ata_dev_t dev
);
223 #endif /* ! GRUB_ATA_HEADER */