xref: /openbmc/qemu/include/hw/ide/ide-dev.h (revision 5fc5934a)
1bd217d88SThomas Huth /*
2bd217d88SThomas Huth  * ide device definitions
3bd217d88SThomas Huth  *
4bd217d88SThomas Huth  * Copyright (c) 2009 Gerd Hoffmann <kraxel@redhat.com>
5bd217d88SThomas Huth  *
6bd217d88SThomas Huth  * This code is free software; you can redistribute it and/or
7bd217d88SThomas Huth  * modify it under the terms of the GNU Lesser General Public
8bd217d88SThomas Huth  * License as published by the Free Software Foundation; either
9bd217d88SThomas Huth  * version 2.1 of the License, or (at your option) any later version.
10bd217d88SThomas Huth  *
11bd217d88SThomas Huth  * This library is distributed in the hope that it will be useful,
12bd217d88SThomas Huth  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13bd217d88SThomas Huth  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14bd217d88SThomas Huth  * Lesser General Public License for more details.
15bd217d88SThomas Huth  *
16bd217d88SThomas Huth  * You should have received a copy of the GNU Lesser General Public
17bd217d88SThomas Huth  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18bd217d88SThomas Huth  */
19bd217d88SThomas Huth 
20bd217d88SThomas Huth #ifndef IDE_DEV_H
21bd217d88SThomas Huth #define IDE_DEV_H
22bd217d88SThomas Huth 
23*5fc5934aSThomas Huth #include "sysemu/dma.h"
24bd217d88SThomas Huth #include "hw/qdev-properties.h"
25bd217d88SThomas Huth #include "hw/block/block.h"
26*5fc5934aSThomas Huth 
27*5fc5934aSThomas Huth typedef struct IDEDevice IDEDevice;
28*5fc5934aSThomas Huth typedef struct IDEState IDEState;
29*5fc5934aSThomas Huth typedef struct IDEBus IDEBus;
30*5fc5934aSThomas Huth 
31*5fc5934aSThomas Huth typedef void EndTransferFunc(IDEState *);
32*5fc5934aSThomas Huth 
33*5fc5934aSThomas Huth #define MAX_IDE_DEVS 2
34*5fc5934aSThomas Huth 
35*5fc5934aSThomas Huth #define TYPE_IDE_DEVICE "ide-device"
36*5fc5934aSThomas Huth OBJECT_DECLARE_TYPE(IDEDevice, IDEDeviceClass, IDE_DEVICE)
37*5fc5934aSThomas Huth 
38*5fc5934aSThomas Huth typedef enum { IDE_HD, IDE_CD, IDE_CFATA } IDEDriveKind;
39*5fc5934aSThomas Huth 
40*5fc5934aSThomas Huth struct unreported_events {
41*5fc5934aSThomas Huth     bool eject_request;
42*5fc5934aSThomas Huth     bool new_media;
43*5fc5934aSThomas Huth };
44*5fc5934aSThomas Huth 
45*5fc5934aSThomas Huth enum ide_dma_cmd {
46*5fc5934aSThomas Huth     IDE_DMA_READ = 0,
47*5fc5934aSThomas Huth     IDE_DMA_WRITE,
48*5fc5934aSThomas Huth     IDE_DMA_TRIM,
49*5fc5934aSThomas Huth     IDE_DMA_ATAPI,
50*5fc5934aSThomas Huth     IDE_DMA__COUNT
51*5fc5934aSThomas Huth };
52*5fc5934aSThomas Huth 
53*5fc5934aSThomas Huth /* NOTE: IDEState represents in fact one drive */
54*5fc5934aSThomas Huth struct IDEState {
55*5fc5934aSThomas Huth     IDEBus *bus;
56*5fc5934aSThomas Huth     uint8_t unit;
57*5fc5934aSThomas Huth     /* ide config */
58*5fc5934aSThomas Huth     IDEDriveKind drive_kind;
59*5fc5934aSThomas Huth     int drive_heads, drive_sectors;
60*5fc5934aSThomas Huth     int cylinders, heads, sectors, chs_trans;
61*5fc5934aSThomas Huth     int64_t nb_sectors;
62*5fc5934aSThomas Huth     int mult_sectors;
63*5fc5934aSThomas Huth     int identify_set;
64*5fc5934aSThomas Huth     uint8_t identify_data[512];
65*5fc5934aSThomas Huth     int drive_serial;
66*5fc5934aSThomas Huth     char drive_serial_str[21];
67*5fc5934aSThomas Huth     char drive_model_str[41];
68*5fc5934aSThomas Huth     uint64_t wwn;
69*5fc5934aSThomas Huth     /* ide regs */
70*5fc5934aSThomas Huth     uint8_t feature;
71*5fc5934aSThomas Huth     uint8_t error;
72*5fc5934aSThomas Huth     uint32_t nsector;
73*5fc5934aSThomas Huth     uint8_t sector;
74*5fc5934aSThomas Huth     uint8_t lcyl;
75*5fc5934aSThomas Huth     uint8_t hcyl;
76*5fc5934aSThomas Huth     /* other part of tf for lba48 support */
77*5fc5934aSThomas Huth     uint8_t hob_feature;
78*5fc5934aSThomas Huth     uint8_t hob_nsector;
79*5fc5934aSThomas Huth     uint8_t hob_sector;
80*5fc5934aSThomas Huth     uint8_t hob_lcyl;
81*5fc5934aSThomas Huth     uint8_t hob_hcyl;
82*5fc5934aSThomas Huth 
83*5fc5934aSThomas Huth     uint8_t select;
84*5fc5934aSThomas Huth     uint8_t status;
85*5fc5934aSThomas Huth 
86*5fc5934aSThomas Huth     bool io8;
87*5fc5934aSThomas Huth     bool reset_reverts;
88*5fc5934aSThomas Huth 
89*5fc5934aSThomas Huth     /* set for lba48 access */
90*5fc5934aSThomas Huth     uint8_t lba48;
91*5fc5934aSThomas Huth     BlockBackend *blk;
92*5fc5934aSThomas Huth     char version[9];
93*5fc5934aSThomas Huth     /* ATAPI specific */
94*5fc5934aSThomas Huth     struct unreported_events events;
95*5fc5934aSThomas Huth     uint8_t sense_key;
96*5fc5934aSThomas Huth     uint8_t asc;
97*5fc5934aSThomas Huth     bool tray_open;
98*5fc5934aSThomas Huth     bool tray_locked;
99*5fc5934aSThomas Huth     uint8_t cdrom_changed;
100*5fc5934aSThomas Huth     int packet_transfer_size;
101*5fc5934aSThomas Huth     int elementary_transfer_size;
102*5fc5934aSThomas Huth     int32_t io_buffer_index;
103*5fc5934aSThomas Huth     int lba;
104*5fc5934aSThomas Huth     int cd_sector_size;
105*5fc5934aSThomas Huth     int atapi_dma; /* true if dma is requested for the packet cmd */
106*5fc5934aSThomas Huth     BlockAcctCookie acct;
107*5fc5934aSThomas Huth     BlockAIOCB *pio_aiocb;
108*5fc5934aSThomas Huth     QEMUIOVector qiov;
109*5fc5934aSThomas Huth     QLIST_HEAD(, IDEBufferedRequest) buffered_requests;
110*5fc5934aSThomas Huth     /* ATA DMA state */
111*5fc5934aSThomas Huth     uint64_t io_buffer_offset;
112*5fc5934aSThomas Huth     int32_t io_buffer_size;
113*5fc5934aSThomas Huth     QEMUSGList sg;
114*5fc5934aSThomas Huth     /* PIO transfer handling */
115*5fc5934aSThomas Huth     int req_nb_sectors; /* number of sectors per interrupt */
116*5fc5934aSThomas Huth     EndTransferFunc *end_transfer_func;
117*5fc5934aSThomas Huth     uint8_t *data_ptr;
118*5fc5934aSThomas Huth     uint8_t *data_end;
119*5fc5934aSThomas Huth     uint8_t *io_buffer;
120*5fc5934aSThomas Huth     /* PIO save/restore */
121*5fc5934aSThomas Huth     int32_t io_buffer_total_len;
122*5fc5934aSThomas Huth     int32_t cur_io_buffer_offset;
123*5fc5934aSThomas Huth     int32_t cur_io_buffer_len;
124*5fc5934aSThomas Huth     uint8_t end_transfer_fn_idx;
125*5fc5934aSThomas Huth     QEMUTimer *sector_write_timer; /* only used for win2k install hack */
126*5fc5934aSThomas Huth     uint32_t irq_count; /* counts IRQs when using win2k install hack */
127*5fc5934aSThomas Huth     /* CF-ATA extended error */
128*5fc5934aSThomas Huth     uint8_t ext_error;
129*5fc5934aSThomas Huth     /* CF-ATA metadata storage */
130*5fc5934aSThomas Huth     uint32_t mdata_size;
131*5fc5934aSThomas Huth     uint8_t *mdata_storage;
132*5fc5934aSThomas Huth     int media_changed;
133*5fc5934aSThomas Huth     enum ide_dma_cmd dma_cmd;
134*5fc5934aSThomas Huth     /* SMART */
135*5fc5934aSThomas Huth     uint8_t smart_enabled;
136*5fc5934aSThomas Huth     uint8_t smart_autosave;
137*5fc5934aSThomas Huth     int smart_errors;
138*5fc5934aSThomas Huth     uint8_t smart_selftest_count;
139*5fc5934aSThomas Huth     uint8_t *smart_selftest_data;
140*5fc5934aSThomas Huth     /* AHCI */
141*5fc5934aSThomas Huth     int ncq_queues;
142*5fc5934aSThomas Huth };
143*5fc5934aSThomas Huth 
144*5fc5934aSThomas Huth struct IDEDeviceClass {
145*5fc5934aSThomas Huth     DeviceClass parent_class;
146*5fc5934aSThomas Huth     void (*realize)(IDEDevice *dev, Error **errp);
147*5fc5934aSThomas Huth };
148*5fc5934aSThomas Huth 
149*5fc5934aSThomas Huth struct IDEDevice {
150*5fc5934aSThomas Huth     DeviceState qdev;
151*5fc5934aSThomas Huth     uint32_t unit;
152*5fc5934aSThomas Huth     BlockConf conf;
153*5fc5934aSThomas Huth     int chs_trans;
154*5fc5934aSThomas Huth     char *version;
155*5fc5934aSThomas Huth     char *serial;
156*5fc5934aSThomas Huth     char *model;
157*5fc5934aSThomas Huth     uint64_t wwn;
158*5fc5934aSThomas Huth     /*
159*5fc5934aSThomas Huth      * 0x0000        - rotation rate not reported
160*5fc5934aSThomas Huth      * 0x0001        - non-rotating medium (SSD)
161*5fc5934aSThomas Huth      * 0x0002-0x0400 - reserved
162*5fc5934aSThomas Huth      * 0x0401-0xffe  - rotations per minute
163*5fc5934aSThomas Huth      * 0xffff        - reserved
164*5fc5934aSThomas Huth      */
165*5fc5934aSThomas Huth     uint16_t rotation_rate;
166*5fc5934aSThomas Huth };
167bd217d88SThomas Huth 
168bd217d88SThomas Huth typedef struct IDEDrive {
169bd217d88SThomas Huth     IDEDevice dev;
170bd217d88SThomas Huth } IDEDrive;
171bd217d88SThomas Huth 
172bd217d88SThomas Huth #define DEFINE_IDE_DEV_PROPERTIES()                     \
173bd217d88SThomas Huth     DEFINE_BLOCK_PROPERTIES(IDEDrive, dev.conf),        \
174bd217d88SThomas Huth     DEFINE_BLOCK_ERROR_PROPERTIES(IDEDrive, dev.conf),  \
175bd217d88SThomas Huth     DEFINE_PROP_STRING("ver",  IDEDrive, dev.version),  \
176bd217d88SThomas Huth     DEFINE_PROP_UINT64("wwn",  IDEDrive, dev.wwn, 0),   \
177bd217d88SThomas Huth     DEFINE_PROP_STRING("serial",  IDEDrive, dev.serial),\
178bd217d88SThomas Huth     DEFINE_PROP_STRING("model", IDEDrive, dev.model)
179bd217d88SThomas Huth 
180bd217d88SThomas Huth void ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind, Error **errp);
181bd217d88SThomas Huth 
182bd217d88SThomas Huth #endif
183