2 * ide device definitions
4 * Copyright (c) 2009 Gerd Hoffmann <kraxel@redhat.com>
6 * This code is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library 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 GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
23 #include "sysemu/dma.h"
24 #include "hw/qdev-properties.h"
25 #include "hw/block/block.h"
27 typedef struct IDEDevice IDEDevice
;
28 typedef struct IDEState IDEState
;
29 typedef struct IDEBus IDEBus
;
31 typedef void EndTransferFunc(IDEState
*);
33 #define MAX_IDE_DEVS 2
35 #define TYPE_IDE_DEVICE "ide-device"
36 OBJECT_DECLARE_TYPE(IDEDevice
, IDEDeviceClass
, IDE_DEVICE
)
38 typedef enum { IDE_HD
, IDE_CD
, IDE_CFATA
} IDEDriveKind
;
40 struct unreported_events
{
53 /* NOTE: IDEState represents in fact one drive */
58 IDEDriveKind drive_kind
;
59 int drive_heads
, drive_sectors
;
60 int cylinders
, heads
, sectors
, chs_trans
;
64 uint8_t identify_data
[512];
66 char drive_serial_str
[21];
67 char drive_model_str
[41];
68 bool win2k_install_hack
;
77 /* other part of tf for lba48 support */
90 /* set for lba48 access */
95 struct unreported_events events
;
100 uint8_t cdrom_changed
;
101 int packet_transfer_size
;
102 int elementary_transfer_size
;
103 int32_t io_buffer_index
;
106 int atapi_dma
; /* true if dma is requested for the packet cmd */
107 BlockAcctCookie acct
;
108 BlockAIOCB
*pio_aiocb
;
110 QLIST_HEAD(, IDEBufferedRequest
) buffered_requests
;
112 uint64_t io_buffer_offset
;
113 int32_t io_buffer_size
;
115 /* PIO transfer handling */
116 int req_nb_sectors
; /* number of sectors per interrupt */
117 EndTransferFunc
*end_transfer_func
;
121 /* PIO save/restore */
122 int32_t io_buffer_total_len
;
123 int32_t cur_io_buffer_offset
;
124 int32_t cur_io_buffer_len
;
125 uint8_t end_transfer_fn_idx
;
126 QEMUTimer
*sector_write_timer
; /* only used for win2k install hack */
127 uint32_t irq_count
; /* counts IRQs when using win2k install hack */
128 /* CF-ATA extended error */
130 /* CF-ATA metadata storage */
132 uint8_t *mdata_storage
;
134 enum ide_dma_cmd dma_cmd
;
136 uint8_t smart_enabled
;
137 uint8_t smart_autosave
;
139 uint8_t smart_selftest_count
;
140 uint8_t *smart_selftest_data
;
145 struct IDEDeviceClass
{
146 DeviceClass parent_class
;
147 void (*realize
)(IDEDevice
*dev
, Error
**errp
);
160 * 0x0000 - rotation rate not reported
161 * 0x0001 - non-rotating medium (SSD)
162 * 0x0002-0x0400 - reserved
163 * 0x0401-0xffe - rotations per minute
166 uint16_t rotation_rate
;
167 bool win2k_install_hack
;
170 typedef struct IDEDrive
{
174 #define DEFINE_IDE_DEV_PROPERTIES() \
175 DEFINE_BLOCK_PROPERTIES(IDEDrive, dev.conf), \
176 DEFINE_BLOCK_ERROR_PROPERTIES(IDEDrive, dev.conf), \
177 DEFINE_PROP_STRING("ver", IDEDrive, dev.version), \
178 DEFINE_PROP_UINT64("wwn", IDEDrive, dev.wwn, 0), \
179 DEFINE_PROP_STRING("serial", IDEDrive, dev.serial),\
180 DEFINE_PROP_STRING("model", IDEDrive, dev.model)
182 void ide_dev_initfn(IDEDevice
*dev
, IDEDriveKind kind
, Error
**errp
);
184 void ide_drive_get(DriveInfo
**hd
, int max_bus
);