[11144] | 1 | /* $Id: ata.h 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
[1] | 2 | /** @file
|
---|
[11144] | 3 | * VBox storage devices: ATA/ATAPI declarations
|
---|
[1] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
[1] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
[69181] | 11 | *
|
---|
[96407] | 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
[69181] | 25 | * The contents of this file may alternatively be used under the terms
|
---|
| 26 | * of the Common Development and Distribution License Version 1.0
|
---|
[96407] | 27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
| 28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
[69181] | 29 | * CDDL are applicable instead of those of the GPL.
|
---|
| 30 | *
|
---|
| 31 | * You may elect to license modified versions of this file under the
|
---|
| 32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
[96407] | 33 | *
|
---|
| 34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
[1] | 35 | */
|
---|
| 36 |
|
---|
[76558] | 37 | #ifndef VBOX_INCLUDED_ata_h
|
---|
| 38 | #define VBOX_INCLUDED_ata_h
|
---|
[76507] | 39 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
| 40 | # pragma once
|
---|
| 41 | #endif
|
---|
[1] | 42 |
|
---|
| 43 |
|
---|
| 44 | /* Bits of HD_STATUS */
|
---|
| 45 | #define ATA_STAT_ERR 0x01
|
---|
| 46 | #define ATA_STAT_INDEX 0x02
|
---|
| 47 | #define ATA_STAT_ECC 0x04 /* Corrected error */
|
---|
| 48 | #define ATA_STAT_DRQ 0x08
|
---|
| 49 | #define ATA_STAT_SEEK 0x10
|
---|
| 50 | #define ATA_STAT_SRV 0x10
|
---|
| 51 | #define ATA_STAT_WRERR 0x20
|
---|
| 52 | #define ATA_STAT_READY 0x40
|
---|
| 53 | #define ATA_STAT_BUSY 0x80
|
---|
| 54 |
|
---|
| 55 | /* Bits for HD_ERROR */
|
---|
| 56 | #define MARK_ERR 0x01 /* Bad address mark */
|
---|
| 57 | #define TRK0_ERR 0x02 /* couldn't find track 0 */
|
---|
| 58 | #define ABRT_ERR 0x04 /* Command aborted */
|
---|
| 59 | #define MCR_ERR 0x08 /* media change request */
|
---|
| 60 | #define ID_ERR 0x10 /* ID field not found */
|
---|
| 61 | #define MC_ERR 0x20 /* media changed */
|
---|
| 62 | #define ECC_ERR 0x40 /* Uncorrectable ECC error */
|
---|
| 63 | #define BBD_ERR 0x80 /* pre-EIDE meaning: block marked bad */
|
---|
| 64 | #define ICRC_ERR 0x80 /* new meaning: CRC error during transfer */
|
---|
| 65 |
|
---|
| 66 | /* Bits for uATARegDevCtl. */
|
---|
| 67 | #define ATA_DEVCTL_DISABLE_IRQ 0x02
|
---|
| 68 | #define ATA_DEVCTL_RESET 0x04
|
---|
| 69 | #define ATA_DEVCTL_HOB 0x80
|
---|
| 70 |
|
---|
| 71 |
|
---|
| 72 | /* ATA/ATAPI Commands (as of ATA/ATAPI-8 draft T13/1699D Revision 3a).
|
---|
| 73 | * Please keep this in sync with g_apszATACmdNames. */
|
---|
| 74 | typedef enum ATACMD
|
---|
| 75 | {
|
---|
| 76 | ATA_NOP = 0x00,
|
---|
| 77 | ATA_CFA_REQUEST_EXTENDED_ERROR_CODE = 0x03,
|
---|
[38622] | 78 | ATA_DATA_SET_MANAGEMENT = 0x06,
|
---|
[1] | 79 | ATA_DEVICE_RESET = 0x08,
|
---|
| 80 | ATA_RECALIBRATE = 0x10,
|
---|
| 81 | ATA_READ_SECTORS = 0x20,
|
---|
| 82 | ATA_READ_SECTORS_WITHOUT_RETRIES = 0x21,
|
---|
| 83 | ATA_READ_LONG = 0x22,
|
---|
| 84 | ATA_READ_LONG_WITHOUT_RETRIES = 0x23,
|
---|
| 85 | ATA_READ_SECTORS_EXT = 0x24,
|
---|
| 86 | ATA_READ_DMA_EXT = 0x25,
|
---|
| 87 | ATA_READ_DMA_QUEUED_EXT = 0x26,
|
---|
| 88 | ATA_READ_NATIVE_MAX_ADDRESS_EXT = 0x27,
|
---|
| 89 | ATA_READ_MULTIPLE_EXT = 0x29,
|
---|
| 90 | ATA_READ_STREAM_DMA_EXT = 0x2a,
|
---|
| 91 | ATA_READ_STREAM_EXT = 0x2b,
|
---|
| 92 | ATA_READ_LOG_EXT = 0x2f,
|
---|
| 93 | ATA_WRITE_SECTORS = 0x30,
|
---|
| 94 | ATA_WRITE_SECTORS_WITHOUT_RETRIES = 0x31,
|
---|
| 95 | ATA_WRITE_LONG = 0x32,
|
---|
| 96 | ATA_WRITE_LONG_WITHOUT_RETRIES = 0x33,
|
---|
| 97 | ATA_WRITE_SECTORS_EXT = 0x34,
|
---|
| 98 | ATA_WRITE_DMA_EXT = 0x35,
|
---|
| 99 | ATA_WRITE_DMA_QUEUED_EXT = 0x36,
|
---|
| 100 | ATA_SET_MAX_ADDRESS_EXT = 0x37,
|
---|
| 101 | ATA_CFA_WRITE_SECTORS_WITHOUT_ERASE = 0x38,
|
---|
| 102 | ATA_WRITE_MULTIPLE_EXT = 0x39,
|
---|
| 103 | ATA_WRITE_STREAM_DMA_EXT = 0x3a,
|
---|
| 104 | ATA_WRITE_STREAM_EXT = 0x3b,
|
---|
| 105 | ATA_WRITE_VERIFY = 0x3c,
|
---|
| 106 | ATA_WRITE_DMA_FUA_EXT = 0x3d,
|
---|
| 107 | ATA_WRITE_DMA_QUEUED_FUA_EXT = 0x3e,
|
---|
| 108 | ATA_WRITE_LOG_EXT = 0x3f,
|
---|
| 109 | ATA_READ_VERIFY_SECTORS = 0x40,
|
---|
| 110 | ATA_READ_VERIFY_SECTORS_WITHOUT_RETRIES = 0x41,
|
---|
| 111 | ATA_READ_VERIFY_SECTORS_EXT = 0x42,
|
---|
| 112 | ATA_WRITE_UNCORRECTABLE_EXT = 0x45,
|
---|
| 113 | ATA_READ_LOG_DMA_EXT = 0x47,
|
---|
| 114 | ATA_FORMAT_TRACK = 0x50,
|
---|
| 115 | ATA_CONFIGURE_STREAM = 0x51,
|
---|
| 116 | ATA_WRITE_LOG_DMA_EXT = 0x57,
|
---|
| 117 | ATA_TRUSTED_RECEIVE = 0x5c,
|
---|
| 118 | ATA_TRUSTED_RECEIVE_DMA = 0x5d,
|
---|
| 119 | ATA_TRUSTED_SEND = 0x5e,
|
---|
| 120 | ATA_TRUSTED_SEND_DMA = 0x5f,
|
---|
[6239] | 121 | ATA_READ_FPDMA_QUEUED = 0x60,
|
---|
| 122 | ATA_WRITE_FPDMA_QUEUED = 0x61,
|
---|
[1] | 123 | ATA_SEEK = 0x70,
|
---|
| 124 | ATA_CFA_TRANSLATE_SECTOR = 0x87,
|
---|
| 125 | ATA_EXECUTE_DEVICE_DIAGNOSTIC = 0x90,
|
---|
| 126 | ATA_INITIALIZE_DEVICE_PARAMETERS = 0x91,
|
---|
| 127 | ATA_DOWNLOAD_MICROCODE = 0x92,
|
---|
| 128 | ATA_STANDBY_IMMEDIATE__ALT = 0x94,
|
---|
| 129 | ATA_IDLE_IMMEDIATE__ALT = 0x95,
|
---|
| 130 | ATA_STANDBY__ALT = 0x96,
|
---|
| 131 | ATA_IDLE__ALT = 0x97,
|
---|
| 132 | ATA_CHECK_POWER_MODE__ALT = 0x98,
|
---|
| 133 | ATA_SLEEP__ALT = 0x99,
|
---|
| 134 | ATA_PACKET = 0xa0,
|
---|
| 135 | ATA_IDENTIFY_PACKET_DEVICE = 0xa1,
|
---|
| 136 | ATA_SERVICE = 0xa2,
|
---|
| 137 | ATA_SMART = 0xb0,
|
---|
| 138 | ATA_DEVICE_CONFIGURATION_OVERLAY = 0xb1,
|
---|
| 139 | ATA_NV_CACHE = 0xb6,
|
---|
| 140 | ATA_CFA_ERASE_SECTORS = 0xc0,
|
---|
| 141 | ATA_READ_MULTIPLE = 0xc4,
|
---|
| 142 | ATA_WRITE_MULTIPLE = 0xc5,
|
---|
| 143 | ATA_SET_MULTIPLE_MODE = 0xc6,
|
---|
| 144 | ATA_READ_DMA_QUEUED = 0xc7,
|
---|
| 145 | ATA_READ_DMA = 0xc8,
|
---|
| 146 | ATA_READ_DMA_WITHOUT_RETRIES = 0xc9,
|
---|
| 147 | ATA_WRITE_DMA = 0xca,
|
---|
| 148 | ATA_WRITE_DMA_WITHOUT_RETRIES = 0xcb,
|
---|
| 149 | ATA_WRITE_DMA_QUEUED = 0xcc,
|
---|
| 150 | ATA_CFA_WRITE_MULTIPLE_WITHOUT_ERASE = 0xcd,
|
---|
| 151 | ATA_WRITE_MULTIPLE_FUA_EXT = 0xce,
|
---|
| 152 | ATA_CHECK_MEDIA_CARD_TYPE = 0xd1,
|
---|
| 153 | ATA_GET_MEDIA_STATUS = 0xda,
|
---|
| 154 | ATA_ACKNOWLEDGE_MEDIA_CHANGE = 0xdb,
|
---|
| 155 | ATA_BOOT_POST_BOOT = 0xdc,
|
---|
| 156 | ATA_BOOT_PRE_BOOT = 0xdd,
|
---|
| 157 | ATA_MEDIA_LOCK = 0xde,
|
---|
| 158 | ATA_MEDIA_UNLOCK = 0xdf,
|
---|
| 159 | ATA_STANDBY_IMMEDIATE = 0xe0,
|
---|
| 160 | ATA_IDLE_IMMEDIATE = 0xe1,
|
---|
| 161 | ATA_STANDBY = 0xe2,
|
---|
| 162 | ATA_IDLE = 0xe3,
|
---|
| 163 | ATA_READ_BUFFER = 0xe4,
|
---|
| 164 | ATA_CHECK_POWER_MODE = 0xe5,
|
---|
| 165 | ATA_SLEEP = 0xe6,
|
---|
| 166 | ATA_FLUSH_CACHE = 0xe7,
|
---|
| 167 | ATA_WRITE_BUFFER = 0xe8,
|
---|
| 168 | ATA_WRITE_SAME = 0xe9,
|
---|
| 169 | ATA_FLUSH_CACHE_EXT = 0xea,
|
---|
| 170 | ATA_IDENTIFY_DEVICE = 0xec,
|
---|
| 171 | ATA_MEDIA_EJECT = 0xed,
|
---|
| 172 | ATA_IDENTIFY_DMA = 0xee,
|
---|
| 173 | ATA_SET_FEATURES = 0xef,
|
---|
| 174 | ATA_SECURITY_SET_PASSWORD = 0xf1,
|
---|
| 175 | ATA_SECURITY_UNLOCK = 0xf2,
|
---|
| 176 | ATA_SECURITY_ERASE_PREPARE = 0xf3,
|
---|
| 177 | ATA_SECURITY_ERASE_UNIT = 0xf4,
|
---|
| 178 | ATA_SECURITY_FREEZE_LOCK = 0xf5,
|
---|
| 179 | ATA_SECURITY_DISABLE_PASSWORD = 0xf6,
|
---|
| 180 | ATA_READ_NATIVE_MAX_ADDRESS = 0xf8,
|
---|
| 181 | ATA_SET_MAX = 0xf9
|
---|
| 182 | } ATACMD;
|
---|
| 183 |
|
---|
| 184 |
|
---|
| 185 | #define ATA_MODE_MDMA 0x20
|
---|
| 186 | #define ATA_MODE_UDMA 0x40
|
---|
| 187 |
|
---|
| 188 |
|
---|
| 189 | #define ATA_TRANSFER_ID(thismode, maxspeed, currmode) \
|
---|
| 190 | ( ((1 << (maxspeed + 1)) - 1) \
|
---|
| 191 | | ((((thismode ^ currmode) & 0xf8) == 0) ? 1 << ((currmode & 0x07) + 8) : 0))
|
---|
| 192 |
|
---|
[37264] | 193 | /**
|
---|
| 194 | * Length of the ATA VPD data (without termination)
|
---|
| 195 | */
|
---|
| 196 | #define ATA_SERIAL_NUMBER_LENGTH 20
|
---|
| 197 | #define ATA_FIRMWARE_REVISION_LENGTH 8
|
---|
| 198 | #define ATA_MODEL_NUMBER_LENGTH 40
|
---|
[1] | 199 |
|
---|
[38894] | 200 | /** Mask to get the LBA value from a LBA range. */
|
---|
| 201 | #define ATA_RANGE_LBA_MASK UINT64_C(0xffffffffffff)
|
---|
| 202 | /** Mas to get the length value from a LBA range. */
|
---|
| 203 | #define ATA_RANGE_LENGTH_MASK UINT64_C(0xffff000000000000)
|
---|
| 204 | /** Returns the length of the range in sectors. */
|
---|
| 205 | #define ATA_RANGE_LENGTH_GET(val) (((val) & ATA_RANGE_LENGTH_MASK) >> 48)
|
---|
[37264] | 206 |
|
---|
[1] | 207 | /* ATAPI defines */
|
---|
| 208 |
|
---|
| 209 | #define ATAPI_PACKET_SIZE 12
|
---|
| 210 |
|
---|
| 211 |
|
---|
| 212 | #define ATAPI_INT_REASON_CD 0x01 /* 0 = data transfer */
|
---|
| 213 | #define ATAPI_INT_REASON_IO 0x02 /* 1 = transfer to the host */
|
---|
| 214 | #define ATAPI_INT_REASON_REL 0x04
|
---|
| 215 | #define ATAPI_INT_REASON_TAG_MASK 0xf8
|
---|
| 216 |
|
---|
[61946] | 217 | #if defined(LOG_ENABLED) && defined(IN_RING3)
|
---|
[12931] | 218 | const char * ATACmdText(uint8_t uCmd);
|
---|
[12551] | 219 | #endif
|
---|
[1] | 220 |
|
---|
[76585] | 221 | #endif /* !VBOX_INCLUDED_ata_h */
|
---|
[11144] | 222 |
|
---|