Upgraded GRUB2 to 2.00 release.
[AROS.git] / arch / all-pc / boot / grub2-aros / include / grub / ata.h
blobefba7b71d3fa0d2457854ed35a1651a42e445c3d
1 /* ata.h - ATA disk access. */
2 /*
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>
29 typedef enum
31 GRUB_ATA_CHS,
32 GRUB_ATA_LBA,
33 GRUB_ATA_LBA48
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. */
107 typedef union
109 grub_uint8_t raw[11];
110 struct
112 union
114 grub_uint8_t features;
115 grub_uint8_t error;
117 union
119 grub_uint8_t sectors;
120 grub_uint8_t atapi_ireason;
122 union
124 grub_uint8_t lba_low;
125 grub_uint8_t sectnum;
127 union
129 grub_uint8_t lba_mid;
130 grub_uint8_t cyllsb;
131 grub_uint8_t atapi_cntlow;
133 union
135 grub_uint8_t lba_high;
136 grub_uint8_t cylmsb;
137 grub_uint8_t atapi_cnthigh;
139 grub_uint8_t disk;
140 union
142 grub_uint8_t cmd;
143 grub_uint8_t status;
145 grub_uint8_t sectors48;
146 grub_uint8_t lba48_low;
147 grub_uint8_t lba48_mid;
148 grub_uint8_t lba48_high;
150 } grub_ata_regs_t;
152 /* ATA pass through parameters and function. */
153 struct grub_disk_ata_pass_through_parms
155 grub_ata_regs_t taskfile;
156 void * buffer;
157 grub_size_t size;
158 int write;
159 void *cmd;
160 int cmdsize;
161 int dma;
164 struct grub_ata
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;
171 /* Sector count. */
172 grub_uint64_t size;
173 grub_uint32_t log_sector_size;
175 /* CHS maximums. */
176 grub_uint16_t cylinders;
177 grub_uint16_t heads;
178 grub_uint16_t sectors_per_track;
180 /* Set to 0 for ATA, set to 1 for ATAPI. */
181 int atapi;
183 int dma;
185 grub_size_t maxbuffer;
187 int *present;
189 void *data;
191 struct grub_ata_dev *dev;
194 typedef struct grub_ata *grub_ata_t;
196 struct grub_ata_dev
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,
212 int spinup);
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 */