2012-01-14 16:36:32 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
// $Id$
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2012-08-31 00:41:25 +04:00
|
|
|
// SCSI emulation layer (ported from QEMU)
|
|
|
|
//
|
|
|
|
// Copyright (C) 2006 CodeSourcery.
|
|
|
|
// Based on code by Fabrice Bellard
|
|
|
|
//
|
|
|
|
// Written by Paul Brook
|
|
|
|
//
|
2018-03-23 22:02:38 +03:00
|
|
|
// Copyright (C) 2007-2018 The Bochs Project
|
2012-01-14 16:36:32 +04:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
#ifndef BX_IODEV_SCSI_DEVICE_H
|
|
|
|
#define BX_IODEV_SCSI_DEVICE_H
|
|
|
|
|
|
|
|
typedef void (*scsi_completionfn)(void *opaque, int reason, Bit32u tag,
|
|
|
|
Bit32u arg);
|
2013-11-05 22:06:39 +04:00
|
|
|
class cdrom_base_c;
|
2012-01-14 16:36:32 +04:00
|
|
|
|
|
|
|
enum scsidev_type {
|
|
|
|
SCSIDEV_TYPE_DISK,
|
|
|
|
SCSIDEV_TYPE_CDROM
|
|
|
|
};
|
|
|
|
|
|
|
|
enum scsi_reason {
|
|
|
|
SCSI_REASON_DONE,
|
|
|
|
SCSI_REASON_DATA
|
|
|
|
};
|
|
|
|
|
|
|
|
#define SENSE_NO_SENSE 0
|
|
|
|
#define SENSE_NOT_READY 2
|
2014-01-24 23:07:51 +04:00
|
|
|
#define SENSE_MEDIUM_ERROR 3
|
2012-01-14 16:36:32 +04:00
|
|
|
#define SENSE_HARDWARE_ERROR 4
|
|
|
|
#define SENSE_ILLEGAL_REQUEST 5
|
|
|
|
|
|
|
|
#define STATUS_GOOD 0
|
|
|
|
#define STATUS_CHECK_CONDITION 2
|
|
|
|
|
|
|
|
#define SCSI_DMA_BUF_SIZE 131072
|
|
|
|
#define SCSI_MAX_INQUIRY_LEN 256
|
|
|
|
|
|
|
|
typedef struct SCSIRequest {
|
|
|
|
Bit32u tag;
|
|
|
|
Bit64u sector;
|
|
|
|
Bit32u sector_count;
|
|
|
|
int buf_len;
|
2014-01-29 00:29:12 +04:00
|
|
|
Bit8u *dma_buf;
|
2012-01-14 16:36:32 +04:00
|
|
|
Bit32u status;
|
2015-09-16 20:08:50 +03:00
|
|
|
bx_bool write_cmd;
|
|
|
|
bx_bool async_mode;
|
2015-10-03 10:19:48 +03:00
|
|
|
Bit8u seek_pending;
|
2012-01-14 16:36:32 +04:00
|
|
|
struct SCSIRequest *next;
|
|
|
|
} SCSIRequest;
|
|
|
|
|
|
|
|
|
|
|
|
class scsi_device_t : public logfunctions {
|
|
|
|
public:
|
|
|
|
scsi_device_t(device_image_t *_hdimage, int _tcq,
|
|
|
|
scsi_completionfn _completion, void *_dev);
|
2013-11-05 22:06:39 +04:00
|
|
|
scsi_device_t(cdrom_base_c *_cdrom, int _tcq,
|
2012-01-14 16:36:32 +04:00
|
|
|
scsi_completionfn _completion, void *_dev);
|
|
|
|
virtual ~scsi_device_t(void);
|
|
|
|
|
|
|
|
void register_state(bx_list_c *parent, const char *name);
|
2015-09-13 23:04:41 +03:00
|
|
|
Bit32s scsi_send_command(Bit32u tag, Bit8u *buf, int lun, bx_bool async);
|
2012-01-14 16:36:32 +04:00
|
|
|
void scsi_command_complete(SCSIRequest *r, int status, int sense);
|
|
|
|
void scsi_cancel_io(Bit32u tag);
|
|
|
|
void scsi_read_complete(void *req, int ret);
|
2015-10-03 10:19:48 +03:00
|
|
|
void scsi_read_data(Bit32u tag);
|
2012-01-14 16:36:32 +04:00
|
|
|
void scsi_write_complete(void *req, int ret);
|
2015-10-03 10:19:48 +03:00
|
|
|
void scsi_write_data(Bit32u tag);
|
2012-01-14 16:36:32 +04:00
|
|
|
Bit8u* scsi_get_buf(Bit32u tag);
|
|
|
|
const char *get_serial_number() {return drive_serial_str;}
|
2014-01-22 00:56:50 +04:00
|
|
|
void set_inserted(bx_bool value);
|
2012-01-14 16:36:32 +04:00
|
|
|
bx_bool get_inserted() {return inserted;}
|
2015-08-23 19:09:24 +03:00
|
|
|
bx_bool get_locked() {return locked;}
|
2014-01-24 23:07:51 +04:00
|
|
|
static void seek_timer_handler(void *);
|
2014-01-29 00:29:12 +04:00
|
|
|
bx_bool save_requests(const char *path);
|
|
|
|
void restore_requests(const char *path);
|
2015-09-03 21:54:51 +03:00
|
|
|
void set_debug_mode();
|
2012-01-14 16:36:32 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
SCSIRequest* scsi_new_request(Bit32u tag);
|
|
|
|
void scsi_remove_request(SCSIRequest *r);
|
|
|
|
SCSIRequest *scsi_find_request(Bit32u tag);
|
|
|
|
|
|
|
|
private:
|
2015-09-13 23:04:41 +03:00
|
|
|
void start_seek(SCSIRequest *r);
|
|
|
|
void seek_timer(void);
|
2015-09-15 20:55:32 +03:00
|
|
|
void seek_complete(SCSIRequest *r);
|
2015-09-13 23:04:41 +03:00
|
|
|
|
2015-10-04 11:54:36 +03:00
|
|
|
// members set in constructor
|
2012-01-14 16:36:32 +04:00
|
|
|
enum scsidev_type type;
|
|
|
|
device_image_t *hdimage;
|
2013-11-05 22:06:39 +04:00
|
|
|
cdrom_base_c *cdrom;
|
2018-03-23 22:02:38 +03:00
|
|
|
int block_size;
|
2012-01-14 16:36:32 +04:00
|
|
|
int tcq;
|
|
|
|
scsi_completionfn completion;
|
|
|
|
void *dev;
|
|
|
|
char drive_serial_str[21];
|
2014-01-24 23:07:51 +04:00
|
|
|
int seek_timer_index;
|
2015-10-03 10:19:48 +03:00
|
|
|
int statusbar_id;
|
2015-10-04 11:54:36 +03:00
|
|
|
// members set in constructor / runtime config
|
|
|
|
Bit64u max_lba;
|
|
|
|
bx_bool inserted;
|
|
|
|
// members handled by save/restore
|
|
|
|
Bit64u curr_lba;
|
|
|
|
int sense;
|
|
|
|
bx_bool locked;
|
|
|
|
SCSIRequest *requests;
|
2012-01-14 16:36:32 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|