]> git.proxmox.com Git - mirror_qemu.git/blob - hw/ide/internal.h
Merge remote-tracking branch 'qemu-kvm-tmp/memory/core' into staging
[mirror_qemu.git] / hw / ide / internal.h
1 #ifndef HW_IDE_INTERNAL_H
2 #define HW_IDE_INTERNAL_H
3
4 /*
5 * QEMU IDE Emulation -- internal header file
6 * only files in hw/ide/ are supposed to include this file.
7 * non-internal declarations are in hw/ide.h
8 */
9 #include <hw/ide.h>
10 #include "block_int.h"
11 #include "iorange.h"
12 #include "dma.h"
13
14 /* debug IDE devices */
15 //#define DEBUG_IDE
16 //#define DEBUG_IDE_ATAPI
17 //#define DEBUG_AIO
18 #define USE_DMA_CDROM
19
20 typedef struct IDEBus IDEBus;
21 typedef struct IDEDevice IDEDevice;
22 typedef struct IDEDeviceInfo IDEDeviceInfo;
23 typedef struct IDEState IDEState;
24 typedef struct IDEDMA IDEDMA;
25 typedef struct IDEDMAOps IDEDMAOps;
26
27 /* Bits of HD_STATUS */
28 #define ERR_STAT 0x01
29 #define INDEX_STAT 0x02
30 #define ECC_STAT 0x04 /* Corrected error */
31 #define DRQ_STAT 0x08
32 #define SEEK_STAT 0x10
33 #define SRV_STAT 0x10
34 #define WRERR_STAT 0x20
35 #define READY_STAT 0x40
36 #define BUSY_STAT 0x80
37
38 /* Bits for HD_ERROR */
39 #define MARK_ERR 0x01 /* Bad address mark */
40 #define TRK0_ERR 0x02 /* couldn't find track 0 */
41 #define ABRT_ERR 0x04 /* Command aborted */
42 #define MCR_ERR 0x08 /* media change request */
43 #define ID_ERR 0x10 /* ID field not found */
44 #define MC_ERR 0x20 /* media changed */
45 #define ECC_ERR 0x40 /* Uncorrectable ECC error */
46 #define BBD_ERR 0x80 /* pre-EIDE meaning: block marked bad */
47 #define ICRC_ERR 0x80 /* new meaning: CRC error during transfer */
48
49 /* Bits of HD_NSECTOR */
50 #define CD 0x01
51 #define IO 0x02
52 #define REL 0x04
53 #define TAG_MASK 0xf8
54
55 #define IDE_CMD_RESET 0x04
56 #define IDE_CMD_DISABLE_IRQ 0x02
57
58 /* ATA/ATAPI Commands pre T13 Spec */
59 #define WIN_NOP 0x00
60 /*
61 * 0x01->0x02 Reserved
62 */
63 #define CFA_REQ_EXT_ERROR_CODE 0x03 /* CFA Request Extended Error Code */
64 /*
65 * 0x04->0x05 Reserved
66 */
67 #define WIN_DSM 0x06
68 /*
69 * 0x07 Reserved
70 */
71 #define WIN_SRST 0x08 /* ATAPI soft reset command */
72 #define WIN_DEVICE_RESET 0x08
73 /*
74 * 0x09->0x0F Reserved
75 */
76 #define WIN_RECAL 0x10
77 #define WIN_RESTORE WIN_RECAL
78 /*
79 * 0x10->0x1F Reserved
80 */
81 #define WIN_READ 0x20 /* 28-Bit */
82 #define WIN_READ_ONCE 0x21 /* 28-Bit without retries */
83 #define WIN_READ_LONG 0x22 /* 28-Bit */
84 #define WIN_READ_LONG_ONCE 0x23 /* 28-Bit without retries */
85 #define WIN_READ_EXT 0x24 /* 48-Bit */
86 #define WIN_READDMA_EXT 0x25 /* 48-Bit */
87 #define WIN_READDMA_QUEUED_EXT 0x26 /* 48-Bit */
88 #define WIN_READ_NATIVE_MAX_EXT 0x27 /* 48-Bit */
89 /*
90 * 0x28
91 */
92 #define WIN_MULTREAD_EXT 0x29 /* 48-Bit */
93 /*
94 * 0x2A->0x2F Reserved
95 */
96 #define WIN_WRITE 0x30 /* 28-Bit */
97 #define WIN_WRITE_ONCE 0x31 /* 28-Bit without retries */
98 #define WIN_WRITE_LONG 0x32 /* 28-Bit */
99 #define WIN_WRITE_LONG_ONCE 0x33 /* 28-Bit without retries */
100 #define WIN_WRITE_EXT 0x34 /* 48-Bit */
101 #define WIN_WRITEDMA_EXT 0x35 /* 48-Bit */
102 #define WIN_WRITEDMA_QUEUED_EXT 0x36 /* 48-Bit */
103 #define WIN_SET_MAX_EXT 0x37 /* 48-Bit */
104 #define CFA_WRITE_SECT_WO_ERASE 0x38 /* CFA Write Sectors without erase */
105 #define WIN_MULTWRITE_EXT 0x39 /* 48-Bit */
106 /*
107 * 0x3A->0x3B Reserved
108 */
109 #define WIN_WRITE_VERIFY 0x3C /* 28-Bit */
110 /*
111 * 0x3D->0x3F Reserved
112 */
113 #define WIN_VERIFY 0x40 /* 28-Bit - Read Verify Sectors */
114 #define WIN_VERIFY_ONCE 0x41 /* 28-Bit - without retries */
115 #define WIN_VERIFY_EXT 0x42 /* 48-Bit */
116 /*
117 * 0x43->0x4F Reserved
118 */
119 #define WIN_FORMAT 0x50
120 /*
121 * 0x51->0x5F Reserved
122 */
123 #define WIN_INIT 0x60
124 /*
125 * 0x61->0x5F Reserved
126 */
127 #define WIN_SEEK 0x70 /* 0x70-0x7F Reserved */
128 #define CFA_TRANSLATE_SECTOR 0x87 /* CFA Translate Sector */
129 #define WIN_DIAGNOSE 0x90
130 #define WIN_SPECIFY 0x91 /* set drive geometry translation */
131 #define WIN_DOWNLOAD_MICROCODE 0x92
132 #define WIN_STANDBYNOW2 0x94
133 #define CFA_IDLEIMMEDIATE 0x95 /* force drive to become "ready" */
134 #define WIN_STANDBY2 0x96
135 #define WIN_SETIDLE2 0x97
136 #define WIN_CHECKPOWERMODE2 0x98
137 #define WIN_SLEEPNOW2 0x99
138 /*
139 * 0x9A VENDOR
140 */
141 #define WIN_PACKETCMD 0xA0 /* Send a packet command. */
142 #define WIN_PIDENTIFY 0xA1 /* identify ATAPI device */
143 #define WIN_QUEUED_SERVICE 0xA2
144 #define WIN_SMART 0xB0 /* self-monitoring and reporting */
145 #define CFA_ACCESS_METADATA_STORAGE 0xB8
146 #define CFA_ERASE_SECTORS 0xC0 /* microdrives implement as NOP */
147 #define WIN_MULTREAD 0xC4 /* read sectors using multiple mode*/
148 #define WIN_MULTWRITE 0xC5 /* write sectors using multiple mode */
149 #define WIN_SETMULT 0xC6 /* enable/disable multiple mode */
150 #define WIN_READDMA_QUEUED 0xC7 /* read sectors using Queued DMA transfers */
151 #define WIN_READDMA 0xC8 /* read sectors using DMA transfers */
152 #define WIN_READDMA_ONCE 0xC9 /* 28-Bit - without retries */
153 #define WIN_WRITEDMA 0xCA /* write sectors using DMA transfers */
154 #define WIN_WRITEDMA_ONCE 0xCB /* 28-Bit - without retries */
155 #define WIN_WRITEDMA_QUEUED 0xCC /* write sectors using Queued DMA transfers */
156 #define CFA_WRITE_MULTI_WO_ERASE 0xCD /* CFA Write multiple without erase */
157 #define WIN_GETMEDIASTATUS 0xDA
158 #define WIN_ACKMEDIACHANGE 0xDB /* ATA-1, ATA-2 vendor */
159 #define WIN_POSTBOOT 0xDC
160 #define WIN_PREBOOT 0xDD
161 #define WIN_DOORLOCK 0xDE /* lock door on removable drives */
162 #define WIN_DOORUNLOCK 0xDF /* unlock door on removable drives */
163 #define WIN_STANDBYNOW1 0xE0
164 #define WIN_IDLEIMMEDIATE 0xE1 /* force drive to become "ready" */
165 #define WIN_STANDBY 0xE2 /* Set device in Standby Mode */
166 #define WIN_SETIDLE1 0xE3
167 #define WIN_READ_BUFFER 0xE4 /* force read only 1 sector */
168 #define WIN_CHECKPOWERMODE1 0xE5
169 #define WIN_SLEEPNOW1 0xE6
170 #define WIN_FLUSH_CACHE 0xE7
171 #define WIN_WRITE_BUFFER 0xE8 /* force write only 1 sector */
172 #define WIN_WRITE_SAME 0xE9 /* read ata-2 to use */
173 /* SET_FEATURES 0x22 or 0xDD */
174 #define WIN_FLUSH_CACHE_EXT 0xEA /* 48-Bit */
175 #define WIN_IDENTIFY 0xEC /* ask drive to identify itself */
176 #define WIN_MEDIAEJECT 0xED
177 #define WIN_IDENTIFY_DMA 0xEE /* same as WIN_IDENTIFY, but DMA */
178 #define WIN_SETFEATURES 0xEF /* set special drive features */
179 #define EXABYTE_ENABLE_NEST 0xF0
180 #define IBM_SENSE_CONDITION 0xF0 /* measure disk temperature */
181 #define WIN_SECURITY_SET_PASS 0xF1
182 #define WIN_SECURITY_UNLOCK 0xF2
183 #define WIN_SECURITY_ERASE_PREPARE 0xF3
184 #define WIN_SECURITY_ERASE_UNIT 0xF4
185 #define WIN_SECURITY_FREEZE_LOCK 0xF5
186 #define CFA_WEAR_LEVEL 0xF5 /* microdrives implement as NOP */
187 #define WIN_SECURITY_DISABLE 0xF6
188 #define WIN_READ_NATIVE_MAX 0xF8 /* return the native maximum address */
189 #define WIN_SET_MAX 0xF9
190 #define DISABLE_SEAGATE 0xFB
191
192 /* set to 1 set disable mult support */
193 #define MAX_MULT_SECTORS 16
194
195 #define IDE_DMA_BUF_SECTORS 256
196
197 /* feature values for Data Set Management */
198 #define DSM_TRIM 0x01
199
200 #if (IDE_DMA_BUF_SECTORS < MAX_MULT_SECTORS)
201 #error "IDE_DMA_BUF_SECTORS must be bigger or equal to MAX_MULT_SECTORS"
202 #endif
203
204 /* ATAPI defines */
205
206 #define ATAPI_PACKET_SIZE 12
207
208 /* The generic packet command opcodes for CD/DVD Logical Units,
209 * From Table 57 of the SFF8090 Ver. 3 (Mt. Fuji) draft standard. */
210 #define GPCMD_BLANK 0xa1
211 #define GPCMD_CLOSE_TRACK 0x5b
212 #define GPCMD_FLUSH_CACHE 0x35
213 #define GPCMD_FORMAT_UNIT 0x04
214 #define GPCMD_GET_CONFIGURATION 0x46
215 #define GPCMD_GET_EVENT_STATUS_NOTIFICATION 0x4a
216 #define GPCMD_GET_PERFORMANCE 0xac
217 #define GPCMD_INQUIRY 0x12
218 #define GPCMD_LOAD_UNLOAD 0xa6
219 #define GPCMD_MECHANISM_STATUS 0xbd
220 #define GPCMD_MODE_SELECT_10 0x55
221 #define GPCMD_MODE_SENSE_10 0x5a
222 #define GPCMD_PAUSE_RESUME 0x4b
223 #define GPCMD_PLAY_AUDIO_10 0x45
224 #define GPCMD_PLAY_AUDIO_MSF 0x47
225 #define GPCMD_PLAY_AUDIO_TI 0x48
226 #define GPCMD_PLAY_CD 0xbc
227 #define GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL 0x1e
228 #define GPCMD_READ_10 0x28
229 #define GPCMD_READ_12 0xa8
230 #define GPCMD_READ_CDVD_CAPACITY 0x25
231 #define GPCMD_READ_CD 0xbe
232 #define GPCMD_READ_CD_MSF 0xb9
233 #define GPCMD_READ_DISC_INFO 0x51
234 #define GPCMD_READ_DVD_STRUCTURE 0xad
235 #define GPCMD_READ_FORMAT_CAPACITIES 0x23
236 #define GPCMD_READ_HEADER 0x44
237 #define GPCMD_READ_TRACK_RZONE_INFO 0x52
238 #define GPCMD_READ_SUBCHANNEL 0x42
239 #define GPCMD_READ_TOC_PMA_ATIP 0x43
240 #define GPCMD_REPAIR_RZONE_TRACK 0x58
241 #define GPCMD_REPORT_KEY 0xa4
242 #define GPCMD_REQUEST_SENSE 0x03
243 #define GPCMD_RESERVE_RZONE_TRACK 0x53
244 #define GPCMD_SCAN 0xba
245 #define GPCMD_SEEK 0x2b
246 #define GPCMD_SEND_DVD_STRUCTURE 0xad
247 #define GPCMD_SEND_EVENT 0xa2
248 #define GPCMD_SEND_KEY 0xa3
249 #define GPCMD_SEND_OPC 0x54
250 #define GPCMD_SET_READ_AHEAD 0xa7
251 #define GPCMD_SET_STREAMING 0xb6
252 #define GPCMD_START_STOP_UNIT 0x1b
253 #define GPCMD_STOP_PLAY_SCAN 0x4e
254 #define GPCMD_TEST_UNIT_READY 0x00
255 #define GPCMD_VERIFY_10 0x2f
256 #define GPCMD_WRITE_10 0x2a
257 #define GPCMD_WRITE_AND_VERIFY_10 0x2e
258 /* This is listed as optional in ATAPI 2.6, but is (curiously)
259 * missing from Mt. Fuji, Table 57. It _is_ mentioned in Mt. Fuji
260 * Table 377 as an MMC command for SCSi devices though... Most ATAPI
261 * drives support it. */
262 #define GPCMD_SET_SPEED 0xbb
263 /* This seems to be a SCSI specific CD-ROM opcode
264 * to play data at track/index */
265 #define GPCMD_PLAYAUDIO_TI 0x48
266 /*
267 * From MS Media Status Notification Support Specification. For
268 * older drives only.
269 */
270 #define GPCMD_GET_MEDIA_STATUS 0xda
271 #define GPCMD_MODE_SENSE_6 0x1a
272
273 /* Mode page codes for mode sense/set */
274 #define GPMODE_R_W_ERROR_PAGE 0x01
275 #define GPMODE_WRITE_PARMS_PAGE 0x05
276 #define GPMODE_AUDIO_CTL_PAGE 0x0e
277 #define GPMODE_POWER_PAGE 0x1a
278 #define GPMODE_FAULT_FAIL_PAGE 0x1c
279 #define GPMODE_TO_PROTECT_PAGE 0x1d
280 #define GPMODE_CAPABILITIES_PAGE 0x2a
281 #define GPMODE_ALL_PAGES 0x3f
282 /* Not in Mt. Fuji, but in ATAPI 2.6 -- depricated now in favor
283 * of MODE_SENSE_POWER_PAGE */
284 #define GPMODE_CDROM_PAGE 0x0d
285
286 /*
287 * Based on values from <linux/cdrom.h> but extending CD_MINS
288 * to the maximum common size allowed by the Orange's Book ATIP
289 *
290 * 90 and 99 min CDs are also available but using them as the
291 * upper limit reduces the effectiveness of the heuristic to
292 * detect DVDs burned to less than 25% of their maximum capacity
293 */
294
295 /* Some generally useful CD-ROM information */
296 #define CD_MINS 80 /* max. minutes per CD */
297 #define CD_SECS 60 /* seconds per minute */
298 #define CD_FRAMES 75 /* frames per second */
299 #define CD_FRAMESIZE 2048 /* bytes per frame, "cooked" mode */
300 #define CD_MAX_BYTES (CD_MINS * CD_SECS * CD_FRAMES * CD_FRAMESIZE)
301 #define CD_MAX_SECTORS (CD_MAX_BYTES / 512)
302
303 /*
304 * The MMC values are not IDE specific and might need to be moved
305 * to a common header if they are also needed for the SCSI emulation
306 */
307
308 /* Profile list from MMC-6 revision 1 table 91 */
309 #define MMC_PROFILE_NONE 0x0000
310 #define MMC_PROFILE_CD_ROM 0x0008
311 #define MMC_PROFILE_CD_R 0x0009
312 #define MMC_PROFILE_CD_RW 0x000A
313 #define MMC_PROFILE_DVD_ROM 0x0010
314 #define MMC_PROFILE_DVD_R_SR 0x0011
315 #define MMC_PROFILE_DVD_RAM 0x0012
316 #define MMC_PROFILE_DVD_RW_RO 0x0013
317 #define MMC_PROFILE_DVD_RW_SR 0x0014
318 #define MMC_PROFILE_DVD_R_DL_SR 0x0015
319 #define MMC_PROFILE_DVD_R_DL_JR 0x0016
320 #define MMC_PROFILE_DVD_RW_DL 0x0017
321 #define MMC_PROFILE_DVD_DDR 0x0018
322 #define MMC_PROFILE_DVD_PLUS_RW 0x001A
323 #define MMC_PROFILE_DVD_PLUS_R 0x001B
324 #define MMC_PROFILE_DVD_PLUS_RW_DL 0x002A
325 #define MMC_PROFILE_DVD_PLUS_R_DL 0x002B
326 #define MMC_PROFILE_BD_ROM 0x0040
327 #define MMC_PROFILE_BD_R_SRM 0x0041
328 #define MMC_PROFILE_BD_R_RRM 0x0042
329 #define MMC_PROFILE_BD_RE 0x0043
330 #define MMC_PROFILE_HDDVD_ROM 0x0050
331 #define MMC_PROFILE_HDDVD_R 0x0051
332 #define MMC_PROFILE_HDDVD_RAM 0x0052
333 #define MMC_PROFILE_HDDVD_RW 0x0053
334 #define MMC_PROFILE_HDDVD_R_DL 0x0058
335 #define MMC_PROFILE_HDDVD_RW_DL 0x005A
336 #define MMC_PROFILE_INVALID 0xFFFF
337
338 #define ATAPI_INT_REASON_CD 0x01 /* 0 = data transfer */
339 #define ATAPI_INT_REASON_IO 0x02 /* 1 = transfer to the host */
340 #define ATAPI_INT_REASON_REL 0x04
341 #define ATAPI_INT_REASON_TAG 0xf8
342
343 /* same constants as bochs */
344 #define ASC_ILLEGAL_OPCODE 0x20
345 #define ASC_LOGICAL_BLOCK_OOR 0x21
346 #define ASC_INV_FIELD_IN_CMD_PACKET 0x24
347 #define ASC_MEDIUM_MAY_HAVE_CHANGED 0x28
348 #define ASC_INCOMPATIBLE_FORMAT 0x30
349 #define ASC_MEDIUM_NOT_PRESENT 0x3a
350 #define ASC_SAVING_PARAMETERS_NOT_SUPPORTED 0x39
351 #define ASC_MEDIA_REMOVAL_PREVENTED 0x53
352
353 #define CFA_NO_ERROR 0x00
354 #define CFA_MISC_ERROR 0x09
355 #define CFA_INVALID_COMMAND 0x20
356 #define CFA_INVALID_ADDRESS 0x21
357 #define CFA_ADDRESS_OVERFLOW 0x2f
358
359 #define SENSE_NONE 0
360 #define SENSE_NOT_READY 2
361 #define SENSE_ILLEGAL_REQUEST 5
362 #define SENSE_UNIT_ATTENTION 6
363
364 #define SMART_READ_DATA 0xd0
365 #define SMART_READ_THRESH 0xd1
366 #define SMART_ATTR_AUTOSAVE 0xd2
367 #define SMART_SAVE_ATTR 0xd3
368 #define SMART_EXECUTE_OFFLINE 0xd4
369 #define SMART_READ_LOG 0xd5
370 #define SMART_WRITE_LOG 0xd6
371 #define SMART_ENABLE 0xd8
372 #define SMART_DISABLE 0xd9
373 #define SMART_STATUS 0xda
374
375 typedef enum { IDE_HD, IDE_CD, IDE_CFATA } IDEDriveKind;
376
377 typedef void EndTransferFunc(IDEState *);
378
379 typedef void DMAStartFunc(IDEDMA *, IDEState *, BlockDriverCompletionFunc *);
380 typedef int DMAFunc(IDEDMA *);
381 typedef int DMAIntFunc(IDEDMA *, int);
382 typedef void DMARestartFunc(void *, int, int);
383
384 struct unreported_events {
385 bool eject_request;
386 bool new_media;
387 };
388
389 enum ide_dma_cmd {
390 IDE_DMA_READ,
391 IDE_DMA_WRITE,
392 IDE_DMA_TRIM,
393 };
394
395 #define ide_cmd_is_read(s) \
396 ((s)->dma_cmd == IDE_DMA_READ)
397
398 /* NOTE: IDEState represents in fact one drive */
399 struct IDEState {
400 IDEBus *bus;
401 uint8_t unit;
402 /* ide config */
403 IDEDriveKind drive_kind;
404 int cylinders, heads, sectors;
405 int64_t nb_sectors;
406 int mult_sectors;
407 int identify_set;
408 uint8_t identify_data[512];
409 int drive_serial;
410 char drive_serial_str[21];
411 /* ide regs */
412 uint8_t feature;
413 uint8_t error;
414 uint32_t nsector;
415 uint8_t sector;
416 uint8_t lcyl;
417 uint8_t hcyl;
418 /* other part of tf for lba48 support */
419 uint8_t hob_feature;
420 uint8_t hob_nsector;
421 uint8_t hob_sector;
422 uint8_t hob_lcyl;
423 uint8_t hob_hcyl;
424
425 uint8_t select;
426 uint8_t status;
427
428 /* set for lba48 access */
429 uint8_t lba48;
430 BlockDriverState *bs;
431 char version[9];
432 /* ATAPI specific */
433 struct unreported_events events;
434 uint8_t sense_key;
435 uint8_t asc;
436 uint8_t cdrom_changed;
437 int packet_transfer_size;
438 int elementary_transfer_size;
439 int io_buffer_index;
440 int lba;
441 int cd_sector_size;
442 int atapi_dma; /* true if dma is requested for the packet cmd */
443 BlockAcctCookie acct;
444 /* ATA DMA state */
445 int io_buffer_size;
446 QEMUSGList sg;
447 /* PIO transfer handling */
448 int req_nb_sectors; /* number of sectors per interrupt */
449 EndTransferFunc *end_transfer_func;
450 uint8_t *data_ptr;
451 uint8_t *data_end;
452 uint8_t *io_buffer;
453 /* PIO save/restore */
454 int32_t io_buffer_total_len;
455 int cur_io_buffer_offset;
456 int cur_io_buffer_len;
457 uint8_t end_transfer_fn_idx;
458 QEMUTimer *sector_write_timer; /* only used for win2k install hack */
459 uint32_t irq_count; /* counts IRQs when using win2k install hack */
460 /* CF-ATA extended error */
461 uint8_t ext_error;
462 /* CF-ATA metadata storage */
463 uint32_t mdata_size;
464 uint8_t *mdata_storage;
465 int media_changed;
466 enum ide_dma_cmd dma_cmd;
467 /* SMART */
468 uint8_t smart_enabled;
469 uint8_t smart_autosave;
470 int smart_errors;
471 uint8_t smart_selftest_count;
472 uint8_t *smart_selftest_data;
473 /* AHCI */
474 int ncq_queues;
475 };
476
477 struct IDEDMAOps {
478 DMAStartFunc *start_dma;
479 DMAFunc *start_transfer;
480 DMAIntFunc *prepare_buf;
481 DMAIntFunc *rw_buf;
482 DMAIntFunc *set_unit;
483 DMAIntFunc *add_status;
484 DMAFunc *set_inactive;
485 DMARestartFunc *restart_cb;
486 DMAFunc *reset;
487 };
488
489 struct IDEDMA {
490 const struct IDEDMAOps *ops;
491 struct iovec iov;
492 QEMUIOVector qiov;
493 BlockDriverAIOCB *aiocb;
494 };
495
496 struct IDEBus {
497 BusState qbus;
498 IDEDevice *master;
499 IDEDevice *slave;
500 IDEState ifs[2];
501 int bus_id;
502 IDEDMA *dma;
503 uint8_t unit;
504 uint8_t cmd;
505 qemu_irq irq;
506
507 int error_status;
508 };
509
510 struct IDEDevice {
511 DeviceState qdev;
512 uint32_t unit;
513 BlockConf conf;
514 char *version;
515 char *serial;
516 };
517
518 typedef int (*ide_qdev_initfn)(IDEDevice *dev);
519 struct IDEDeviceInfo {
520 DeviceInfo qdev;
521 ide_qdev_initfn init;
522 };
523
524 #define BM_STATUS_DMAING 0x01
525 #define BM_STATUS_ERROR 0x02
526 #define BM_STATUS_INT 0x04
527
528 /* FIXME These are not status register bits */
529 #define BM_STATUS_DMA_RETRY 0x08
530 #define BM_STATUS_PIO_RETRY 0x10
531 #define BM_STATUS_RETRY_READ 0x20
532 #define BM_STATUS_RETRY_FLUSH 0x40
533 #define BM_STATUS_RETRY_TRIM 0x80
534
535 #define BM_MIGRATION_COMPAT_STATUS_BITS \
536 (BM_STATUS_DMA_RETRY | BM_STATUS_PIO_RETRY | \
537 BM_STATUS_RETRY_READ | BM_STATUS_RETRY_FLUSH)
538
539 #define BM_CMD_START 0x01
540 #define BM_CMD_READ 0x08
541
542 static inline IDEState *idebus_active_if(IDEBus *bus)
543 {
544 return bus->ifs + bus->unit;
545 }
546
547 static inline void ide_set_irq(IDEBus *bus)
548 {
549 if (!(bus->cmd & IDE_CMD_DISABLE_IRQ)) {
550 qemu_irq_raise(bus->irq);
551 }
552 }
553
554 /* hw/ide/core.c */
555 extern const VMStateDescription vmstate_ide_bus;
556
557 #define VMSTATE_IDE_BUS(_field, _state) \
558 VMSTATE_STRUCT(_field, _state, 1, vmstate_ide_bus, IDEBus)
559
560 #define VMSTATE_IDE_BUS_ARRAY(_field, _state, _num) \
561 VMSTATE_STRUCT_ARRAY(_field, _state, _num, 1, vmstate_ide_bus, IDEBus)
562
563 extern const VMStateDescription vmstate_ide_drive;
564
565 #define VMSTATE_IDE_DRIVES(_field, _state) \
566 VMSTATE_STRUCT_ARRAY(_field, _state, 2, 3, vmstate_ide_drive, IDEState)
567
568 void ide_bus_reset(IDEBus *bus);
569 int64_t ide_get_sector(IDEState *s);
570 void ide_set_sector(IDEState *s, int64_t sector_num);
571
572 void ide_dma_error(IDEState *s);
573
574 void ide_atapi_cmd_ok(IDEState *s);
575 void ide_atapi_cmd_error(IDEState *s, int sense_key, int asc);
576 void ide_atapi_io_error(IDEState *s, int ret);
577
578 void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val);
579 uint32_t ide_ioport_read(void *opaque, uint32_t addr1);
580 uint32_t ide_status_read(void *opaque, uint32_t addr);
581 void ide_cmd_write(void *opaque, uint32_t addr, uint32_t val);
582 void ide_data_writew(void *opaque, uint32_t addr, uint32_t val);
583 uint32_t ide_data_readw(void *opaque, uint32_t addr);
584 void ide_data_writel(void *opaque, uint32_t addr, uint32_t val);
585 uint32_t ide_data_readl(void *opaque, uint32_t addr);
586
587 int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind,
588 const char *version, const char *serial);
589 void ide_init2(IDEBus *bus, qemu_irq irq);
590 void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo *hd0,
591 DriveInfo *hd1, qemu_irq irq);
592 void ide_init_ioport(IDEBus *bus, int iobase, int iobase2);
593
594 void ide_exec_cmd(IDEBus *bus, uint32_t val);
595 void ide_dma_cb(void *opaque, int ret);
596 void ide_sector_write(IDEState *s);
597 void ide_sector_read(IDEState *s);
598 void ide_flush_cache(IDEState *s);
599
600 void ide_transfer_start(IDEState *s, uint8_t *buf, int size,
601 EndTransferFunc *end_transfer_func);
602 void ide_transfer_stop(IDEState *s);
603 void ide_set_inactive(IDEState *s);
604 BlockDriverAIOCB *ide_issue_trim(BlockDriverState *bs,
605 int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
606 BlockDriverCompletionFunc *cb, void *opaque);
607
608 /* hw/ide/atapi.c */
609 void ide_atapi_cmd(IDEState *s);
610 void ide_atapi_cmd_reply_end(IDEState *s);
611
612 /* hw/ide/qdev.c */
613 void ide_bus_new(IDEBus *idebus, DeviceState *dev, int bus_id);
614 IDEDevice *ide_create_drive(IDEBus *bus, int unit, DriveInfo *drive);
615
616 #endif /* HW_IDE_INTERNAL_H */