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];
76 /* other part of tf for lba48 support */
89 /* set for lba48 access */
94 struct unreported_events events
;
99 uint8_t cdrom_changed
;
100 int packet_transfer_size
;
101 int elementary_transfer_size
;
102 int32_t io_buffer_index
;
105 int atapi_dma
; /* true if dma is requested for the packet cmd */
106 BlockAcctCookie acct
;
107 BlockAIOCB
*pio_aiocb
;
109 QLIST_HEAD(, IDEBufferedRequest
) buffered_requests
;
111 uint64_t io_buffer_offset
;
112 int32_t io_buffer_size
;
114 /* PIO transfer handling */
115 int req_nb_sectors
; /* number of sectors per interrupt */
116 EndTransferFunc
*end_transfer_func
;
120 /* PIO save/restore */
121 int32_t io_buffer_total_len
;
122 int32_t cur_io_buffer_offset
;
123 int32_t cur_io_buffer_len
;
124 uint8_t end_transfer_fn_idx
;
125 QEMUTimer
*sector_write_timer
; /* only used for win2k install hack */
126 uint32_t irq_count
; /* counts IRQs when using win2k install hack */
127 /* CF-ATA extended error */
129 /* CF-ATA metadata storage */
131 uint8_t *mdata_storage
;
133 enum ide_dma_cmd dma_cmd
;
135 uint8_t smart_enabled
;
136 uint8_t smart_autosave
;
138 uint8_t smart_selftest_count
;
139 uint8_t *smart_selftest_data
;
144 struct IDEDeviceClass
{
145 DeviceClass parent_class
;
146 void (*realize
)(IDEDevice
*dev
, Error
**errp
);
159 * 0x0000 - rotation rate not reported
160 * 0x0001 - non-rotating medium (SSD)
161 * 0x0002-0x0400 - reserved
162 * 0x0401-0xffe - rotations per minute
165 uint16_t rotation_rate
;
168 typedef struct IDEDrive
{
172 #define DEFINE_IDE_DEV_PROPERTIES() \
173 DEFINE_BLOCK_PROPERTIES(IDEDrive, dev.conf), \
174 DEFINE_BLOCK_ERROR_PROPERTIES(IDEDrive, dev.conf), \
175 DEFINE_PROP_STRING("ver", IDEDrive, dev.version), \
176 DEFINE_PROP_UINT64("wwn", IDEDrive, dev.wwn, 0), \
177 DEFINE_PROP_STRING("serial", IDEDrive, dev.serial),\
178 DEFINE_PROP_STRING("model", IDEDrive, dev.model)
180 void ide_dev_initfn(IDEDevice
*dev
, IDEDriveKind kind
, Error
**errp
);