xref: /openbmc/qemu/include/hw/ide/ide-dev.h (revision d13f4035)
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 
235fc5934aSThomas Huth #include "sysemu/dma.h"
24bd217d88SThomas Huth #include "hw/qdev-properties.h"
25bd217d88SThomas Huth #include "hw/block/block.h"
265fc5934aSThomas Huth 
275fc5934aSThomas Huth typedef struct IDEDevice IDEDevice;
285fc5934aSThomas Huth typedef struct IDEState IDEState;
295fc5934aSThomas Huth typedef struct IDEBus IDEBus;
305fc5934aSThomas Huth 
315fc5934aSThomas Huth typedef void EndTransferFunc(IDEState *);
325fc5934aSThomas Huth 
335fc5934aSThomas Huth #define MAX_IDE_DEVS 2
345fc5934aSThomas Huth 
355fc5934aSThomas Huth #define TYPE_IDE_DEVICE "ide-device"
365fc5934aSThomas Huth OBJECT_DECLARE_TYPE(IDEDevice, IDEDeviceClass, IDE_DEVICE)
375fc5934aSThomas Huth 
385fc5934aSThomas Huth typedef enum { IDE_HD, IDE_CD, IDE_CFATA } IDEDriveKind;
395fc5934aSThomas Huth 
405fc5934aSThomas Huth struct unreported_events {
415fc5934aSThomas Huth     bool eject_request;
425fc5934aSThomas Huth     bool new_media;
435fc5934aSThomas Huth };
445fc5934aSThomas Huth 
455fc5934aSThomas Huth enum ide_dma_cmd {
465fc5934aSThomas Huth     IDE_DMA_READ = 0,
475fc5934aSThomas Huth     IDE_DMA_WRITE,
485fc5934aSThomas Huth     IDE_DMA_TRIM,
495fc5934aSThomas Huth     IDE_DMA_ATAPI,
505fc5934aSThomas Huth     IDE_DMA__COUNT
515fc5934aSThomas Huth };
525fc5934aSThomas Huth 
535fc5934aSThomas Huth /* NOTE: IDEState represents in fact one drive */
545fc5934aSThomas Huth struct IDEState {
555fc5934aSThomas Huth     IDEBus *bus;
565fc5934aSThomas Huth     uint8_t unit;
575fc5934aSThomas Huth     /* ide config */
585fc5934aSThomas Huth     IDEDriveKind drive_kind;
595fc5934aSThomas Huth     int drive_heads, drive_sectors;
605fc5934aSThomas Huth     int cylinders, heads, sectors, chs_trans;
615fc5934aSThomas Huth     int64_t nb_sectors;
625fc5934aSThomas Huth     int mult_sectors;
635fc5934aSThomas Huth     int identify_set;
645fc5934aSThomas Huth     uint8_t identify_data[512];
655fc5934aSThomas Huth     int drive_serial;
665fc5934aSThomas Huth     char drive_serial_str[21];
675fc5934aSThomas Huth     char drive_model_str[41];
68*d13f4035SPaolo Bonzini     bool win2k_install_hack;
695fc5934aSThomas Huth     uint64_t wwn;
705fc5934aSThomas Huth     /* ide regs */
715fc5934aSThomas Huth     uint8_t feature;
725fc5934aSThomas Huth     uint8_t error;
735fc5934aSThomas Huth     uint32_t nsector;
745fc5934aSThomas Huth     uint8_t sector;
755fc5934aSThomas Huth     uint8_t lcyl;
765fc5934aSThomas Huth     uint8_t hcyl;
775fc5934aSThomas Huth     /* other part of tf for lba48 support */
785fc5934aSThomas Huth     uint8_t hob_feature;
795fc5934aSThomas Huth     uint8_t hob_nsector;
805fc5934aSThomas Huth     uint8_t hob_sector;
815fc5934aSThomas Huth     uint8_t hob_lcyl;
825fc5934aSThomas Huth     uint8_t hob_hcyl;
835fc5934aSThomas Huth 
845fc5934aSThomas Huth     uint8_t select;
855fc5934aSThomas Huth     uint8_t status;
865fc5934aSThomas Huth 
875fc5934aSThomas Huth     bool io8;
885fc5934aSThomas Huth     bool reset_reverts;
895fc5934aSThomas Huth 
905fc5934aSThomas Huth     /* set for lba48 access */
915fc5934aSThomas Huth     uint8_t lba48;
925fc5934aSThomas Huth     BlockBackend *blk;
935fc5934aSThomas Huth     char version[9];
945fc5934aSThomas Huth     /* ATAPI specific */
955fc5934aSThomas Huth     struct unreported_events events;
965fc5934aSThomas Huth     uint8_t sense_key;
975fc5934aSThomas Huth     uint8_t asc;
985fc5934aSThomas Huth     bool tray_open;
995fc5934aSThomas Huth     bool tray_locked;
1005fc5934aSThomas Huth     uint8_t cdrom_changed;
1015fc5934aSThomas Huth     int packet_transfer_size;
1025fc5934aSThomas Huth     int elementary_transfer_size;
1035fc5934aSThomas Huth     int32_t io_buffer_index;
1045fc5934aSThomas Huth     int lba;
1055fc5934aSThomas Huth     int cd_sector_size;
1065fc5934aSThomas Huth     int atapi_dma; /* true if dma is requested for the packet cmd */
1075fc5934aSThomas Huth     BlockAcctCookie acct;
1085fc5934aSThomas Huth     BlockAIOCB *pio_aiocb;
1095fc5934aSThomas Huth     QEMUIOVector qiov;
1105fc5934aSThomas Huth     QLIST_HEAD(, IDEBufferedRequest) buffered_requests;
1115fc5934aSThomas Huth     /* ATA DMA state */
1125fc5934aSThomas Huth     uint64_t io_buffer_offset;
1135fc5934aSThomas Huth     int32_t io_buffer_size;
1145fc5934aSThomas Huth     QEMUSGList sg;
1155fc5934aSThomas Huth     /* PIO transfer handling */
1165fc5934aSThomas Huth     int req_nb_sectors; /* number of sectors per interrupt */
1175fc5934aSThomas Huth     EndTransferFunc *end_transfer_func;
1185fc5934aSThomas Huth     uint8_t *data_ptr;
1195fc5934aSThomas Huth     uint8_t *data_end;
1205fc5934aSThomas Huth     uint8_t *io_buffer;
1215fc5934aSThomas Huth     /* PIO save/restore */
1225fc5934aSThomas Huth     int32_t io_buffer_total_len;
1235fc5934aSThomas Huth     int32_t cur_io_buffer_offset;
1245fc5934aSThomas Huth     int32_t cur_io_buffer_len;
1255fc5934aSThomas Huth     uint8_t end_transfer_fn_idx;
1265fc5934aSThomas Huth     QEMUTimer *sector_write_timer; /* only used for win2k install hack */
1275fc5934aSThomas Huth     uint32_t irq_count; /* counts IRQs when using win2k install hack */
1285fc5934aSThomas Huth     /* CF-ATA extended error */
1295fc5934aSThomas Huth     uint8_t ext_error;
1305fc5934aSThomas Huth     /* CF-ATA metadata storage */
1315fc5934aSThomas Huth     uint32_t mdata_size;
1325fc5934aSThomas Huth     uint8_t *mdata_storage;
1335fc5934aSThomas Huth     int media_changed;
1345fc5934aSThomas Huth     enum ide_dma_cmd dma_cmd;
1355fc5934aSThomas Huth     /* SMART */
1365fc5934aSThomas Huth     uint8_t smart_enabled;
1375fc5934aSThomas Huth     uint8_t smart_autosave;
1385fc5934aSThomas Huth     int smart_errors;
1395fc5934aSThomas Huth     uint8_t smart_selftest_count;
1405fc5934aSThomas Huth     uint8_t *smart_selftest_data;
1415fc5934aSThomas Huth     /* AHCI */
1425fc5934aSThomas Huth     int ncq_queues;
1435fc5934aSThomas Huth };
1445fc5934aSThomas Huth 
1455fc5934aSThomas Huth struct IDEDeviceClass {
1465fc5934aSThomas Huth     DeviceClass parent_class;
1475fc5934aSThomas Huth     void (*realize)(IDEDevice *dev, Error **errp);
1485fc5934aSThomas Huth };
1495fc5934aSThomas Huth 
1505fc5934aSThomas Huth struct IDEDevice {
1515fc5934aSThomas Huth     DeviceState qdev;
1525fc5934aSThomas Huth     uint32_t unit;
1535fc5934aSThomas Huth     BlockConf conf;
1545fc5934aSThomas Huth     int chs_trans;
1555fc5934aSThomas Huth     char *version;
1565fc5934aSThomas Huth     char *serial;
1575fc5934aSThomas Huth     char *model;
1585fc5934aSThomas Huth     uint64_t wwn;
1595fc5934aSThomas Huth     /*
1605fc5934aSThomas Huth      * 0x0000        - rotation rate not reported
1615fc5934aSThomas Huth      * 0x0001        - non-rotating medium (SSD)
1625fc5934aSThomas Huth      * 0x0002-0x0400 - reserved
1635fc5934aSThomas Huth      * 0x0401-0xffe  - rotations per minute
1645fc5934aSThomas Huth      * 0xffff        - reserved
1655fc5934aSThomas Huth      */
1665fc5934aSThomas Huth     uint16_t rotation_rate;
167*d13f4035SPaolo Bonzini     bool win2k_install_hack;
1685fc5934aSThomas Huth };
169bd217d88SThomas Huth 
170bd217d88SThomas Huth typedef struct IDEDrive {
171bd217d88SThomas Huth     IDEDevice dev;
172bd217d88SThomas Huth } IDEDrive;
173bd217d88SThomas Huth 
174bd217d88SThomas Huth #define DEFINE_IDE_DEV_PROPERTIES()                     \
175bd217d88SThomas Huth     DEFINE_BLOCK_PROPERTIES(IDEDrive, dev.conf),        \
176bd217d88SThomas Huth     DEFINE_BLOCK_ERROR_PROPERTIES(IDEDrive, dev.conf),  \
177bd217d88SThomas Huth     DEFINE_PROP_STRING("ver",  IDEDrive, dev.version),  \
178bd217d88SThomas Huth     DEFINE_PROP_UINT64("wwn",  IDEDrive, dev.wwn, 0),   \
179bd217d88SThomas Huth     DEFINE_PROP_STRING("serial",  IDEDrive, dev.serial),\
180bd217d88SThomas Huth     DEFINE_PROP_STRING("model", IDEDrive, dev.model)
181bd217d88SThomas Huth 
182bd217d88SThomas Huth void ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind, Error **errp);
183bd217d88SThomas Huth 
18440e074a5SThomas Huth void ide_drive_get(DriveInfo **hd, int max_bus);
18540e074a5SThomas Huth 
186bd217d88SThomas Huth #endif
187