* [Qemu-devel] [PATCH 00/12] scsi-disk: Add DVD-ROM support and media change + atapi: nitpicking
@ 2011-09-20 15:26 Paolo Bonzini
2011-09-20 15:26 ` [Qemu-devel] [PATCH 01/12] scsi: pass correct sense code for ENOMEDIUM Paolo Bonzini
` (11 more replies)
0 siblings, 12 replies; 13+ messages in thread
From: Paolo Bonzini @ 2011-09-20 15:26 UTC (permalink / raw)
To: qemu-devel
This series brings scsi-disk and ide/atapi almost on feature parity.
After this series, the only missing feature in scsi-disk is the READ
CD command. The main addition is media change support, both via
unit attention and via GET EVENT STATUS NOTIFICATION.
I originally planned to work on this after migration, but since media
change supports adds a couple of fields that have to be migrated, it
is better to include this early.
The actual packets are still sometimes different, mostly in irrelevant
details, but apart from READ CD the implemented commands are the same.
Unifying the two implementations is a much larger job, and would likely
require significant work in the block layer too. It may come out nicely
as a byproduct of more SCSI features (e.g. SCSI passthrough for iSCSI
devices) but not soon.
Paolo Bonzini (12):
scsi: pass correct sense code for ENOMEDIUM
atapi/scsi: unify definitions for MMC
atapi: move GESN definitions to scsi-defs.h
atapi: fill in AUDIO_CTL page correctly
scsi: notify the device when unit attention is reported
scsi-disk: report media changed via unit attention sense codes
scsi-disk: add stubs for more MMC commands
scsi-disk: store valid mode pages in a table
atapi/scsi-disk: make mode page values coherent between the two
scsi-disk: support DVD profile in GET CONFIGURATION
scsi-disk: support READ DVD STRUCTURE
scsi-disk: report media changed via GET EVENT STATUS NOTIFICATION
hw/ide/atapi.c | 109 ++++++-----------
hw/ide/core.c | 4 +-
hw/ide/internal.h | 71 +-----------
hw/ide/macio.c | 2 +-
hw/scsi-bus.c | 39 +++++-
hw/scsi-defs.h | 90 ++++++++++++++
hw/scsi-disk.c | 341 ++++++++++++++++++++++++++++++++++++++++++++++++-----
hw/scsi.h | 4 +
8 files changed, 482 insertions(+), 178 deletions(-)
--
1.7.6
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Qemu-devel] [PATCH 01/12] scsi: pass correct sense code for ENOMEDIUM
2011-09-20 15:26 [Qemu-devel] [PATCH 00/12] scsi-disk: Add DVD-ROM support and media change + atapi: nitpicking Paolo Bonzini
@ 2011-09-20 15:26 ` Paolo Bonzini
2011-09-20 15:26 ` [Qemu-devel] [PATCH 02/12] atapi/scsi: unify definitions for MMC Paolo Bonzini
` (10 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Paolo Bonzini @ 2011-09-20 15:26 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/scsi-disk.c | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 48abe49..534baa2 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -230,6 +230,9 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int error, int type)
vm_stop(VMSTOP_DISKFULL);
} else {
switch (error) {
+ case ENOMEDIUM:
+ scsi_check_condition(r, SENSE_CODE(NO_MEDIUM));
+ break;
case ENOMEM:
scsi_check_condition(r, SENSE_CODE(TARGET_FAILURE));
break;
--
1.7.6
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Qemu-devel] [PATCH 02/12] atapi/scsi: unify definitions for MMC
2011-09-20 15:26 [Qemu-devel] [PATCH 00/12] scsi-disk: Add DVD-ROM support and media change + atapi: nitpicking Paolo Bonzini
2011-09-20 15:26 ` [Qemu-devel] [PATCH 01/12] scsi: pass correct sense code for ENOMEDIUM Paolo Bonzini
@ 2011-09-20 15:26 ` Paolo Bonzini
2011-09-20 15:26 ` [Qemu-devel] [PATCH 03/12] atapi: move GESN definitions to scsi-defs.h Paolo Bonzini
` (9 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Paolo Bonzini @ 2011-09-20 15:26 UTC (permalink / raw)
To: qemu-devel
The definitions in ide/internal.h are duplicates, since ATAPI commands
actually come from SCSI. Use the ones in scsi-defs.h and move the
missing ones there. Two exceptions:
- MODE_PAGE_WRITE_PARMS conflicts with the "flexible disk geometry"
page in scsi-disk.c. It is unused, so pick the latter.
- GPCMD_* is left in ide/internal.h, at least for now.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/ide/atapi.c | 52 +++++++++++++++++++-------------------
hw/ide/core.c | 4 +-
hw/ide/internal.h | 71 +----------------------------------------------------
hw/ide/macio.c | 2 +-
hw/scsi-bus.c | 2 +-
hw/scsi-defs.h | 66 +++++++++++++++++++++++++++++++++++++++++++++++++
hw/scsi-disk.c | 8 +++---
7 files changed, 101 insertions(+), 104 deletions(-)
diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
index 3f909c3..be3b728 100644
--- a/hw/ide/atapi.c
+++ b/hw/ide/atapi.c
@@ -154,10 +154,10 @@ void ide_atapi_io_error(IDEState *s, int ret)
{
/* XXX: handle more errors */
if (ret == -ENOMEDIUM) {
- ide_atapi_cmd_error(s, SENSE_NOT_READY,
+ ide_atapi_cmd_error(s, NOT_READY,
ASC_MEDIUM_NOT_PRESENT);
} else {
- ide_atapi_cmd_error(s, SENSE_ILLEGAL_REQUEST,
+ ide_atapi_cmd_error(s, ILLEGAL_REQUEST,
ASC_LOGICAL_BLOCK_OOR);
}
}
@@ -282,7 +282,7 @@ static void ide_atapi_cmd_check_status(IDEState *s)
#ifdef DEBUG_IDE_ATAPI
printf("atapi_cmd_check_status\n");
#endif
- s->error = MC_ERR | (SENSE_UNIT_ATTENTION << 4);
+ s->error = MC_ERR | (UNIT_ATTENTION << 4);
s->status = ERR_STAT;
s->nsector = 0;
ide_set_irq(s->bus);
@@ -354,7 +354,7 @@ static void ide_atapi_cmd_read_dma_cb(void *opaque, int ret)
ide_atapi_cmd_read_dma_cb, s);
if (!s->bus->dma->aiocb) {
/* Note: media not present is the most likely case */
- ide_atapi_cmd_error(s, SENSE_NOT_READY,
+ ide_atapi_cmd_error(s, NOT_READY,
ASC_MEDIUM_NOT_PRESENT);
goto eot;
}
@@ -595,7 +595,7 @@ static void cmd_get_event_status_notification(IDEState *s,
/* It is fine by the MMC spec to not support async mode operations */
if (!(gesn_cdb->polled & 0x01)) { /* asynchronous mode */
/* Only polling is supported, asynchronous mode is not. */
- ide_atapi_cmd_error(s, SENSE_ILLEGAL_REQUEST,
+ ide_atapi_cmd_error(s, ILLEGAL_REQUEST,
ASC_INV_FIELD_IN_CMD_PACKET);
return;
}
@@ -643,8 +643,8 @@ static void cmd_request_sense(IDEState *s, uint8_t *buf)
buf[7] = 10;
buf[12] = s->asc;
- if (s->sense_key == SENSE_UNIT_ATTENTION) {
- s->sense_key = SENSE_NONE;
+ if (s->sense_key == UNIT_ATTENTION) {
+ s->sense_key = NO_SENSE;
}
ide_atapi_cmd_reply(s, 18, max_len);
@@ -676,7 +676,7 @@ static void cmd_get_configuration(IDEState *s, uint8_t *buf)
/* only feature 0 is supported */
if (buf[2] != 0 || buf[3] != 0) {
- ide_atapi_cmd_error(s, SENSE_ILLEGAL_REQUEST,
+ ide_atapi_cmd_error(s, ILLEGAL_REQUEST,
ASC_INV_FIELD_IN_CMD_PACKET);
return;
}
@@ -733,7 +733,7 @@ static void cmd_mode_sense(IDEState *s, uint8_t *buf)
switch(action) {
case 0: /* current values */
switch(code) {
- case GPMODE_R_W_ERROR_PAGE: /* error recovery */
+ case MODE_PAGE_R_W_ERROR: /* error recovery */
cpu_to_ube16(&buf[0], 16 + 6);
buf[2] = 0x70;
buf[3] = 0;
@@ -752,7 +752,7 @@ static void cmd_mode_sense(IDEState *s, uint8_t *buf)
buf[15] = 0x00;
ide_atapi_cmd_reply(s, 16, max_len);
break;
- case GPMODE_AUDIO_CTL_PAGE:
+ case MODE_PAGE_AUDIO_CTL:
cpu_to_ube16(&buf[0], 24 + 6);
buf[2] = 0x70;
buf[3] = 0;
@@ -769,7 +769,7 @@ static void cmd_mode_sense(IDEState *s, uint8_t *buf)
ide_atapi_cmd_reply(s, 24, max_len);
break;
- case GPMODE_CAPABILITIES_PAGE:
+ case MODE_PAGE_CAPABILITIES:
cpu_to_ube16(&buf[0], 28 + 6);
buf[2] = 0x70;
buf[3] = 0;
@@ -813,14 +813,14 @@ static void cmd_mode_sense(IDEState *s, uint8_t *buf)
goto error_cmd;
default:
case 3: /* saved values */
- ide_atapi_cmd_error(s, SENSE_ILLEGAL_REQUEST,
+ ide_atapi_cmd_error(s, ILLEGAL_REQUEST,
ASC_SAVING_PARAMETERS_NOT_SUPPORTED);
break;
}
return;
error_cmd:
- ide_atapi_cmd_error(s, SENSE_ILLEGAL_REQUEST, ASC_INV_FIELD_IN_CMD_PACKET);
+ ide_atapi_cmd_error(s, ILLEGAL_REQUEST, ASC_INV_FIELD_IN_CMD_PACKET);
}
static void cmd_test_unit_ready(IDEState *s, uint8_t *buf)
@@ -883,7 +883,7 @@ static void cmd_read_cd(IDEState *s, uint8_t* buf)
ide_atapi_cmd_read(s, lba, nb_sectors, 2352);
break;
default:
- ide_atapi_cmd_error(s, SENSE_ILLEGAL_REQUEST,
+ ide_atapi_cmd_error(s, ILLEGAL_REQUEST,
ASC_INV_FIELD_IN_CMD_PACKET);
break;
}
@@ -896,7 +896,7 @@ static void cmd_seek(IDEState *s, uint8_t* buf)
lba = ube32_to_cpu(buf + 2);
if (lba >= total_sectors) {
- ide_atapi_cmd_error(s, SENSE_ILLEGAL_REQUEST, ASC_LOGICAL_BLOCK_OOR);
+ ide_atapi_cmd_error(s, ILLEGAL_REQUEST, ASC_LOGICAL_BLOCK_OOR);
return;
}
@@ -912,7 +912,7 @@ static void cmd_start_stop_unit(IDEState *s, uint8_t* buf)
if (loej) {
if (!start && !s->tray_open && s->tray_locked) {
sense = bdrv_is_inserted(s->bs)
- ? SENSE_NOT_READY : SENSE_ILLEGAL_REQUEST;
+ ? NOT_READY : ILLEGAL_REQUEST;
ide_atapi_cmd_error(s, sense, ASC_MEDIA_REMOVAL_PREVENTED);
return;
}
@@ -971,7 +971,7 @@ static void cmd_read_toc_pma_atip(IDEState *s, uint8_t* buf)
break;
default:
error_cmd:
- ide_atapi_cmd_error(s, SENSE_ILLEGAL_REQUEST,
+ ide_atapi_cmd_error(s, ILLEGAL_REQUEST,
ASC_INV_FIELD_IN_CMD_PACKET);
}
}
@@ -997,11 +997,11 @@ static void cmd_read_dvd_structure(IDEState *s, uint8_t* buf)
if (format < 0xff) {
if (media_is_cd(s)) {
- ide_atapi_cmd_error(s, SENSE_ILLEGAL_REQUEST,
+ ide_atapi_cmd_error(s, ILLEGAL_REQUEST,
ASC_INCOMPATIBLE_FORMAT);
return;
} else if (!media_present(s)) {
- ide_atapi_cmd_error(s, SENSE_ILLEGAL_REQUEST,
+ ide_atapi_cmd_error(s, ILLEGAL_REQUEST,
ASC_INV_FIELD_IN_CMD_PACKET);
return;
}
@@ -1017,7 +1017,7 @@ static void cmd_read_dvd_structure(IDEState *s, uint8_t* buf)
ret = ide_dvd_read_structure(s, format, buf, buf);
if (ret < 0) {
- ide_atapi_cmd_error(s, SENSE_ILLEGAL_REQUEST, -ret);
+ ide_atapi_cmd_error(s, ILLEGAL_REQUEST, -ret);
} else {
ide_atapi_cmd_reply(s, ret, max_len);
}
@@ -1034,7 +1034,7 @@ static void cmd_read_dvd_structure(IDEState *s, uint8_t* buf)
case 0x90: /* TODO: List of recognized format layers */
case 0xc0: /* TODO: Write protection status */
default:
- ide_atapi_cmd_error(s, SENSE_ILLEGAL_REQUEST,
+ ide_atapi_cmd_error(s, ILLEGAL_REQUEST,
ASC_INV_FIELD_IN_CMD_PACKET);
break;
}
@@ -1106,7 +1106,7 @@ void ide_atapi_cmd(IDEState *s)
* condition response unless a higher priority status, defined by the drive
* here, is pending.
*/
- if (s->sense_key == SENSE_UNIT_ATTENTION &&
+ if (s->sense_key == UNIT_ATTENTION &&
!(atapi_cmd_table[s->io_buffer[0]].flags & ALLOW_UA)) {
ide_atapi_cmd_check_status(s);
return;
@@ -1119,10 +1119,10 @@ void ide_atapi_cmd(IDEState *s)
* states rely on this behavior.
*/
if (!s->tray_open && bdrv_is_inserted(s->bs) && s->cdrom_changed) {
- ide_atapi_cmd_error(s, SENSE_NOT_READY, ASC_MEDIUM_NOT_PRESENT);
+ ide_atapi_cmd_error(s, NOT_READY, ASC_MEDIUM_NOT_PRESENT);
s->cdrom_changed = 0;
- s->sense_key = SENSE_UNIT_ATTENTION;
+ s->sense_key = UNIT_ATTENTION;
s->asc = ASC_MEDIUM_MAY_HAVE_CHANGED;
return;
}
@@ -1131,7 +1131,7 @@ void ide_atapi_cmd(IDEState *s)
if ((atapi_cmd_table[s->io_buffer[0]].flags & CHECK_READY) &&
(!media_present(s) || !bdrv_is_inserted(s->bs)))
{
- ide_atapi_cmd_error(s, SENSE_NOT_READY, ASC_MEDIUM_NOT_PRESENT);
+ ide_atapi_cmd_error(s, NOT_READY, ASC_MEDIUM_NOT_PRESENT);
return;
}
@@ -1141,5 +1141,5 @@ void ide_atapi_cmd(IDEState *s)
return;
}
- ide_atapi_cmd_error(s, SENSE_ILLEGAL_REQUEST, ASC_ILLEGAL_OPCODE);
+ ide_atapi_cmd_error(s, ILLEGAL_REQUEST, ASC_ILLEGAL_OPCODE);
}
diff --git a/hw/ide/core.c b/hw/ide/core.c
index f424347..9df8090 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -797,7 +797,7 @@ static void ide_cd_change_cb(void *opaque, bool load)
* First indicate to the guest that a CD has been removed. That's
* done on the next command the guest sends us.
*
- * Then we set SENSE_UNIT_ATTENTION, by which the guest will
+ * Then we set UNIT_ATTENTION, by which the guest will
* detect a new CD in the drive. See ide_atapi_cmd() for details.
*/
s->cdrom_changed = 1;
@@ -2017,7 +2017,7 @@ static int ide_drive_post_load(void *opaque, int version_id)
IDEState *s = opaque;
if (version_id < 3) {
- if (s->sense_key == SENSE_UNIT_ATTENTION &&
+ if (s->sense_key == UNIT_ATTENTION &&
s->asc == ASC_MEDIUM_MAY_HAVE_CHANGED) {
s->cdrom_changed = 1;
}
diff --git a/hw/ide/internal.h b/hw/ide/internal.h
index 233915c..68bd33a 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -9,6 +9,7 @@
#include <hw/ide.h>
#include "iorange.h"
#include "dma.h"
+#include "hw/scsi-defs.h"
/* debug IDE devices */
//#define DEBUG_IDE
@@ -278,71 +279,6 @@ typedef struct IDEDMAOps IDEDMAOps;
#define GPCMD_GET_MEDIA_STATUS 0xda
#define GPCMD_MODE_SENSE_6 0x1a
-/* Mode page codes for mode sense/set */
-#define GPMODE_R_W_ERROR_PAGE 0x01
-#define GPMODE_WRITE_PARMS_PAGE 0x05
-#define GPMODE_AUDIO_CTL_PAGE 0x0e
-#define GPMODE_POWER_PAGE 0x1a
-#define GPMODE_FAULT_FAIL_PAGE 0x1c
-#define GPMODE_TO_PROTECT_PAGE 0x1d
-#define GPMODE_CAPABILITIES_PAGE 0x2a
-#define GPMODE_ALL_PAGES 0x3f
-/* Not in Mt. Fuji, but in ATAPI 2.6 -- depricated now in favor
- * of MODE_SENSE_POWER_PAGE */
-#define GPMODE_CDROM_PAGE 0x0d
-
-/*
- * Based on values from <linux/cdrom.h> but extending CD_MINS
- * to the maximum common size allowed by the Orange's Book ATIP
- *
- * 90 and 99 min CDs are also available but using them as the
- * upper limit reduces the effectiveness of the heuristic to
- * detect DVDs burned to less than 25% of their maximum capacity
- */
-
-/* Some generally useful CD-ROM information */
-#define CD_MINS 80 /* max. minutes per CD */
-#define CD_SECS 60 /* seconds per minute */
-#define CD_FRAMES 75 /* frames per second */
-#define CD_FRAMESIZE 2048 /* bytes per frame, "cooked" mode */
-#define CD_MAX_BYTES (CD_MINS * CD_SECS * CD_FRAMES * CD_FRAMESIZE)
-#define CD_MAX_SECTORS (CD_MAX_BYTES / 512)
-
-/*
- * The MMC values are not IDE specific and might need to be moved
- * to a common header if they are also needed for the SCSI emulation
- */
-
-/* Profile list from MMC-6 revision 1 table 91 */
-#define MMC_PROFILE_NONE 0x0000
-#define MMC_PROFILE_CD_ROM 0x0008
-#define MMC_PROFILE_CD_R 0x0009
-#define MMC_PROFILE_CD_RW 0x000A
-#define MMC_PROFILE_DVD_ROM 0x0010
-#define MMC_PROFILE_DVD_R_SR 0x0011
-#define MMC_PROFILE_DVD_RAM 0x0012
-#define MMC_PROFILE_DVD_RW_RO 0x0013
-#define MMC_PROFILE_DVD_RW_SR 0x0014
-#define MMC_PROFILE_DVD_R_DL_SR 0x0015
-#define MMC_PROFILE_DVD_R_DL_JR 0x0016
-#define MMC_PROFILE_DVD_RW_DL 0x0017
-#define MMC_PROFILE_DVD_DDR 0x0018
-#define MMC_PROFILE_DVD_PLUS_RW 0x001A
-#define MMC_PROFILE_DVD_PLUS_R 0x001B
-#define MMC_PROFILE_DVD_PLUS_RW_DL 0x002A
-#define MMC_PROFILE_DVD_PLUS_R_DL 0x002B
-#define MMC_PROFILE_BD_ROM 0x0040
-#define MMC_PROFILE_BD_R_SRM 0x0041
-#define MMC_PROFILE_BD_R_RRM 0x0042
-#define MMC_PROFILE_BD_RE 0x0043
-#define MMC_PROFILE_HDDVD_ROM 0x0050
-#define MMC_PROFILE_HDDVD_R 0x0051
-#define MMC_PROFILE_HDDVD_RAM 0x0052
-#define MMC_PROFILE_HDDVD_RW 0x0053
-#define MMC_PROFILE_HDDVD_R_DL 0x0058
-#define MMC_PROFILE_HDDVD_RW_DL 0x005A
-#define MMC_PROFILE_INVALID 0xFFFF
-
#define ATAPI_INT_REASON_CD 0x01 /* 0 = data transfer */
#define ATAPI_INT_REASON_IO 0x02 /* 1 = transfer to the host */
#define ATAPI_INT_REASON_REL 0x04
@@ -364,11 +300,6 @@ typedef struct IDEDMAOps IDEDMAOps;
#define CFA_INVALID_ADDRESS 0x21
#define CFA_ADDRESS_OVERFLOW 0x2f
-#define SENSE_NONE 0
-#define SENSE_NOT_READY 2
-#define SENSE_ILLEGAL_REQUEST 5
-#define SENSE_UNIT_ATTENTION 6
-
#define SMART_READ_DATA 0xd0
#define SMART_READ_THRESH 0xd1
#define SMART_ATTR_AUTOSAVE 0xd2
diff --git a/hw/ide/macio.c b/hw/ide/macio.c
index 37b8239..70b3342 100644
--- a/hw/ide/macio.c
+++ b/hw/ide/macio.c
@@ -87,7 +87,7 @@ static void pmac_ide_atapi_transfer_cb(void *opaque, int ret)
if (!m->aiocb) {
qemu_sglist_destroy(&s->sg);
/* Note: media not present is the most likely case */
- ide_atapi_cmd_error(s, SENSE_NOT_READY,
+ ide_atapi_cmd_error(s, NOT_READY,
ASC_MEDIUM_NOT_PRESENT);
goto done;
}
diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
index aca65a1..fc2f823 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -800,7 +800,7 @@ const struct SCSISense sense_code_SAVING_PARAMS_NOT_SUPPORTED = {
};
/* Illegal request, Incompatible medium installed */
-const struct SCSISense sense_code_INCOMPATIBLE_MEDIUM = {
+const struct SCSISense sense_code_INCOMPATIBLE_FORMAT = {
.key = ILLEGAL_REQUEST, .asc = 0x30, .ascq = 0x00
};
diff --git a/hw/scsi-defs.h b/hw/scsi-defs.h
index bfe9392..dfa3095 100644
--- a/hw/scsi-defs.h
+++ b/hw/scsi-defs.h
@@ -188,3 +188,69 @@
#define TYPE_INACTIVE 0x20
#define TYPE_NO_LUN 0x7f
+/* Mode page codes for mode sense/set */
+#define MODE_PAGE_R_W_ERROR 0x01
+#define MODE_PAGE_HD_GEOMETRY 0x04
+#define MODE_PAGE_FLEXIBLE_DISK_GEOMETRY 0x05
+#define MODE_PAGE_CACHING 0x08
+#define MODE_PAGE_AUDIO_CTL 0x0e
+#define MODE_PAGE_POWER 0x1a
+#define MODE_PAGE_FAULT_FAIL 0x1c
+#define MODE_PAGE_TO_PROTECT 0x1d
+#define MODE_PAGE_CAPABILITIES 0x2a
+#define MODE_PAGE_ALLS 0x3f
+/* Not in Mt. Fuji, but in ATAPI 2.6 -- depricated now in favor
+ * of MODE_PAGE_SENSE_POWER */
+#define MODE_PAGE_CDROM 0x0d
+
+/*
+ * Based on values from <linux/cdrom.h> but extending CD_MINS
+ * to the maximum common size allowed by the Orange's Book ATIP
+ *
+ * 90 and 99 min CDs are also available but using them as the
+ * upper limit reduces the effectiveness of the heuristic to
+ * detect DVDs burned to less than 25% of their maximum capacity
+ */
+
+/* Some generally useful CD-ROM information */
+#define CD_MINS 80 /* max. minutes per CD */
+#define CD_SECS 60 /* seconds per minute */
+#define CD_FRAMES 75 /* frames per second */
+#define CD_FRAMESIZE 2048 /* bytes per frame, "cooked" mode */
+#define CD_MAX_BYTES (CD_MINS * CD_SECS * CD_FRAMES * CD_FRAMESIZE)
+#define CD_MAX_SECTORS (CD_MAX_BYTES / 512)
+
+/*
+ * The MMC values are not IDE specific and might need to be moved
+ * to a common header if they are also needed for the SCSI emulation
+ */
+
+/* Profile list from MMC-6 revision 1 table 91 */
+#define MMC_PROFILE_NONE 0x0000
+#define MMC_PROFILE_CD_ROM 0x0008
+#define MMC_PROFILE_CD_R 0x0009
+#define MMC_PROFILE_CD_RW 0x000A
+#define MMC_PROFILE_DVD_ROM 0x0010
+#define MMC_PROFILE_DVD_R_SR 0x0011
+#define MMC_PROFILE_DVD_RAM 0x0012
+#define MMC_PROFILE_DVD_RW_RO 0x0013
+#define MMC_PROFILE_DVD_RW_SR 0x0014
+#define MMC_PROFILE_DVD_R_DL_SR 0x0015
+#define MMC_PROFILE_DVD_R_DL_JR 0x0016
+#define MMC_PROFILE_DVD_RW_DL 0x0017
+#define MMC_PROFILE_DVD_DDR 0x0018
+#define MMC_PROFILE_DVD_PLUS_RW 0x001A
+#define MMC_PROFILE_DVD_PLUS_R 0x001B
+#define MMC_PROFILE_DVD_PLUS_RW_DL 0x002A
+#define MMC_PROFILE_DVD_PLUS_R_DL 0x002B
+#define MMC_PROFILE_BD_ROM 0x0040
+#define MMC_PROFILE_BD_R_SRM 0x0041
+#define MMC_PROFILE_BD_R_RRM 0x0042
+#define MMC_PROFILE_BD_RE 0x0043
+#define MMC_PROFILE_HDDVD_ROM 0x0050
+#define MMC_PROFILE_HDDVD_R 0x0051
+#define MMC_PROFILE_HDDVD_RAM 0x0052
+#define MMC_PROFILE_HDDVD_RW 0x0053
+#define MMC_PROFILE_HDDVD_R_DL 0x0058
+#define MMC_PROFILE_HDDVD_RW_DL 0x005A
+#define MMC_PROFILE_INVALID 0xFFFF
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 534baa2..b5447af 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -575,7 +575,7 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf,
* The buffer was already menset to zero by the caller of this function.
*/
switch (page) {
- case 4: /* Rigid disk device geometry page. */
+ case MODE_PAGE_HD_GEOMETRY:
if (s->qdev.type == TYPE_ROM) {
return -1;
}
@@ -610,7 +610,7 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf,
p[21] = 5400 & 0xff;
break;
- case 5: /* Flexible disk device geometry page. */
+ case MODE_PAGE_FLEXIBLE_DISK_GEOMETRY:
if (s->qdev.type == TYPE_ROM) {
return -1;
}
@@ -652,7 +652,7 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf,
p[29] = 5400 & 0xff;
break;
- case 8: /* Caching page. */
+ case MODE_PAGE_CACHING:
p[0] = 8;
p[1] = 0x12;
if (page_control == 1) { /* Changeable Values */
@@ -663,7 +663,7 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf,
}
break;
- case 0x2a: /* CD Capabilities and Mechanical Status page. */
+ case MODE_PAGE_CAPABILITIES:
if (s->qdev.type != TYPE_ROM) {
return -1;
}
--
1.7.6
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Qemu-devel] [PATCH 03/12] atapi: move GESN definitions to scsi-defs.h
2011-09-20 15:26 [Qemu-devel] [PATCH 00/12] scsi-disk: Add DVD-ROM support and media change + atapi: nitpicking Paolo Bonzini
2011-09-20 15:26 ` [Qemu-devel] [PATCH 01/12] scsi: pass correct sense code for ENOMEDIUM Paolo Bonzini
2011-09-20 15:26 ` [Qemu-devel] [PATCH 02/12] atapi/scsi: unify definitions for MMC Paolo Bonzini
@ 2011-09-20 15:26 ` Paolo Bonzini
2011-09-20 15:26 ` [Qemu-devel] [PATCH 04/12] atapi: fill in AUDIO_CTL page correctly Paolo Bonzini
` (8 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Paolo Bonzini @ 2011-09-20 15:26 UTC (permalink / raw)
To: qemu-devel
As a complement to the previous patch, move definitions for GET EVENT
STATUS NOTIFICATION from the two functions to scsi-defs.h.
The NCR_* constants are just bit values corresponding to the ENC_*
values, with no offsets even, so keep just one copy.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/ide/atapi.c | 43 ++++++-------------------------------------
hw/scsi-defs.h | 21 +++++++++++++++++++++
2 files changed, 27 insertions(+), 37 deletions(-)
diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
index be3b728..347c38d 100644
--- a/hw/ide/atapi.c
+++ b/hw/ide/atapi.c
@@ -505,19 +505,6 @@ static int ide_dvd_read_structure(IDEState *s, int format,
static unsigned int event_status_media(IDEState *s,
uint8_t *buf)
{
- enum media_event_code {
- MEC_NO_CHANGE = 0, /* Status unchanged */
- MEC_EJECT_REQUESTED, /* received a request from user to eject */
- MEC_NEW_MEDIA, /* new media inserted and ready for access */
- MEC_MEDIA_REMOVAL, /* only for media changers */
- MEC_MEDIA_CHANGED, /* only for media changers */
- MEC_BG_FORMAT_COMPLETED, /* MRW or DVD+RW b/g format completed */
- MEC_BG_FORMAT_RESTARTED, /* MRW or DVD+RW b/g format restarted */
- };
- enum media_status {
- MS_TRAY_OPEN = 1,
- MS_MEDIA_PRESENT = 2,
- };
uint8_t event_code, media_status;
media_status = 0;
@@ -564,27 +551,6 @@ static void cmd_get_event_status_notification(IDEState *s,
uint8_t notification_class;
uint8_t supported_events;
} QEMU_PACKED *gesn_event_header;
-
- enum notification_class_request_type {
- NCR_RESERVED1 = 1 << 0,
- NCR_OPERATIONAL_CHANGE = 1 << 1,
- NCR_POWER_MANAGEMENT = 1 << 2,
- NCR_EXTERNAL_REQUEST = 1 << 3,
- NCR_MEDIA = 1 << 4,
- NCR_MULTI_HOST = 1 << 5,
- NCR_DEVICE_BUSY = 1 << 6,
- NCR_RESERVED2 = 1 << 7,
- };
- enum event_notification_class_field {
- ENC_NO_EVENTS = 0,
- ENC_OPERATIONAL_CHANGE,
- ENC_POWER_MANAGEMENT,
- ENC_EXTERNAL_REQUEST,
- ENC_MEDIA,
- ENC_MULTIPLE_HOSTS,
- ENC_DEVICE_BUSY,
- ENC_RESERVED,
- };
unsigned int max_len, used_len;
gesn_cdb = (void *)packet;
@@ -606,8 +572,11 @@ static void cmd_get_event_status_notification(IDEState *s,
* These are the supported events.
*
* We currently only support requests of the 'media' type.
+ * Notification class requests and supported event classes are bitmasks,
+ * but they are build from the same values as the "notification class"
+ * field.
*/
- gesn_event_header->supported_events = NCR_MEDIA;
+ gesn_event_header->supported_events = 1 << GESN_MEDIA;
/*
* We use |= below to set the class field; other bits in this byte
@@ -621,8 +590,8 @@ static void cmd_get_event_status_notification(IDEState *s,
* notification_class_request_type enum above specifies the
* priority: upper elements are higher prio than lower ones.
*/
- if (gesn_cdb->class & NCR_MEDIA) {
- gesn_event_header->notification_class |= ENC_MEDIA;
+ if (gesn_cdb->class & (1 << GESN_MEDIA)) {
+ gesn_event_header->notification_class |= GESN_MEDIA;
used_len = event_status_media(s, buf);
} else {
gesn_event_header->notification_class = 0x80; /* No event available */
diff --git a/hw/scsi-defs.h b/hw/scsi-defs.h
index dfa3095..8094698 100644
--- a/hw/scsi-defs.h
+++ b/hw/scsi-defs.h
@@ -203,6 +203,27 @@
* of MODE_PAGE_SENSE_POWER */
#define MODE_PAGE_CDROM 0x0d
+/* Event notification classes for GET EVENT STATUS NOTIFICATION */
+#define GESN_NO_EVENTS 0
+#define GESN_OPERATIONAL_CHANGE 1
+#define GESN_POWER_MANAGEMENT 2
+#define GESN_EXTERNAL_REQUEST 3
+#define GESN_MEDIA 4
+#define GESN_MULTIPLE_HOSTS 5
+#define GESN_DEVICE_BUSY 6
+
+/* Event codes for MEDIA event status notification */
+#define MEC_NO_CHANGE 0
+#define MEC_EJECT_REQUESTED 1
+#define MEC_NEW_MEDIA 2
+#define MEC_MEDIA_REMOVAL 3 /* only for media changers */
+#define MEC_MEDIA_CHANGED 4 /* only for media changers */
+#define MEC_BG_FORMAT_COMPLETED 5 /* MRW or DVD+RW b/g format completed */
+#define MEC_BG_FORMAT_RESTARTED 6 /* MRW or DVD+RW b/g format restarted */
+
+#define MS_TRAY_OPEN 1
+#define MS_MEDIA_PRESENT 2
+
/*
* Based on values from <linux/cdrom.h> but extending CD_MINS
* to the maximum common size allowed by the Orange's Book ATIP
--
1.7.6
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Qemu-devel] [PATCH 04/12] atapi: fill in AUDIO_CTL page correctly
2011-09-20 15:26 [Qemu-devel] [PATCH 00/12] scsi-disk: Add DVD-ROM support and media change + atapi: nitpicking Paolo Bonzini
` (2 preceding siblings ...)
2011-09-20 15:26 ` [Qemu-devel] [PATCH 03/12] atapi: move GESN definitions to scsi-defs.h Paolo Bonzini
@ 2011-09-20 15:26 ` Paolo Bonzini
2011-09-20 15:26 ` [Qemu-devel] [PATCH 05/12] scsi: notify the device when unit attention is reported Paolo Bonzini
` (7 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Paolo Bonzini @ 2011-09-20 15:26 UTC (permalink / raw)
To: qemu-devel
The page is not anymore in MMC, but at least keep the values sane.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/ide/atapi.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
index 347c38d..10f161f 100644
--- a/hw/ide/atapi.c
+++ b/hw/ide/atapi.c
@@ -731,6 +731,8 @@ static void cmd_mode_sense(IDEState *s, uint8_t *buf)
buf[7] = 0;
/* Fill with CDROM audio volume */
+ buf[8] = 0x0e;
+ buf[9] = 0x0e;
buf[17] = 0;
buf[19] = 0;
buf[21] = 0;
--
1.7.6
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Qemu-devel] [PATCH 05/12] scsi: notify the device when unit attention is reported
2011-09-20 15:26 [Qemu-devel] [PATCH 00/12] scsi-disk: Add DVD-ROM support and media change + atapi: nitpicking Paolo Bonzini
` (3 preceding siblings ...)
2011-09-20 15:26 ` [Qemu-devel] [PATCH 04/12] atapi: fill in AUDIO_CTL page correctly Paolo Bonzini
@ 2011-09-20 15:26 ` Paolo Bonzini
2011-09-20 15:26 ` [Qemu-devel] [PATCH 06/12] scsi-disk: report media changed via unit attention sense codes Paolo Bonzini
` (6 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Paolo Bonzini @ 2011-09-20 15:26 UTC (permalink / raw)
To: qemu-devel
Reporting media change events via unit attention sense codes requires
a small state machine: first report "NO MEDIUM", then report "MEDIUM MAY
HAVE CHANGED". Unfortunately there is no good hooking point for the
device to notice that its pending unit attention condition has been
reported. This patch reworks the generic machinery to add one.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/scsi-bus.c | 32 +++++++++++++++++++++++++++-----
hw/scsi.h | 2 ++
2 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
index fc2f823..c190509 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -295,6 +295,13 @@ static int32_t scsi_target_send_command(SCSIRequest *req, uint8_t *buf)
r->len = scsi_device_get_sense(r->req.dev, r->buf,
MIN(req->cmd.xfer, sizeof r->buf),
(req->cmd.buf[1] & 1) == 0);
+ if (r->req.dev->sense_is_ua) {
+ if (r->req.dev->info->unit_attention_reported) {
+ r->req.dev->info->unit_attention_reported(req->dev);
+ }
+ r->req.dev->sense_len = 0;
+ r->req.dev->sense_is_ua = false;
+ }
break;
default:
scsi_req_build_sense(req, SENSE_CODE(LUN_NOT_SUPPORTED));
@@ -383,7 +390,13 @@ SCSIRequest *scsi_req_new(SCSIDevice *d, uint32_t tag, uint32_t lun,
(buf[0] != INQUIRY &&
buf[0] != REPORT_LUNS &&
buf[0] != GET_CONFIGURATION &&
- buf[0] != GET_EVENT_STATUS_NOTIFICATION)) {
+ buf[0] != GET_EVENT_STATUS_NOTIFICATION &&
+
+ /*
+ * If we already have a pending unit attention condition,
+ * report this one before triggering another one.
+ */
+ !(buf[0] == REQUEST_SENSE && d->sense_is_ua))) {
req = scsi_req_alloc(&reqops_unit_attention, d, tag, lun,
hba_private);
} else if (lun != d->lun ||
@@ -479,10 +492,15 @@ int scsi_req_get_sense(SCSIRequest *req, uint8_t *buf, int len)
*
* We assume UA_INTLCK_CTRL to be 00b for HBAs that support autosense, and
* 10b for HBAs that do not support it (do not call scsi_req_get_sense).
- * In the latter case, scsi_req_complete clears unit attention conditions
- * after moving them to the device's sense buffer.
+ * Here we handle unit attention clearing for UA_INTLCK_CTRL == 00b.
*/
- scsi_clear_unit_attention(req);
+ if (req->dev->sense_is_ua) {
+ if (req->dev->info->unit_attention_reported) {
+ req->dev->info->unit_attention_reported(req->dev);
+ }
+ req->dev->sense_len = 0;
+ req->dev->sense_is_ua = false;
+ }
return ret;
}
@@ -1082,8 +1100,12 @@ void scsi_req_complete(SCSIRequest *req, int status)
if (req->sense_len) {
memcpy(req->dev->sense, req->sense, req->sense_len);
+ req->dev->sense_len = req->sense_len;
+ req->dev->sense_is_ua = (req->ops == &reqops_unit_attention);
+ } else {
+ req->dev->sense_len = 0;
+ req->dev->sense_is_ua = false;
}
- req->dev->sense_len = req->sense_len;
/*
* Unit attention state is now stored in the device's sense buffer
diff --git a/hw/scsi.h b/hw/scsi.h
index e8dcabf..6d40b8e 100644
--- a/hw/scsi.h
+++ b/hw/scsi.h
@@ -62,6 +62,7 @@ struct SCSIDevice
BlockConf conf;
SCSIDeviceInfo *info;
SCSISense unit_attention;
+ bool sense_is_ua;
uint8_t sense[SCSI_SENSE_BUF_SIZE];
uint32_t sense_len;
QTAILQ_HEAD(, SCSIRequest) requests;
@@ -92,6 +93,7 @@ struct SCSIDeviceInfo {
void (*destroy)(SCSIDevice *s);
SCSIRequest *(*alloc_req)(SCSIDevice *s, uint32_t tag, uint32_t lun,
void *hba_private);
+ void (*unit_attention_reported)(SCSIDevice *s);
SCSIReqOps reqops;
};
--
1.7.6
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Qemu-devel] [PATCH 06/12] scsi-disk: report media changed via unit attention sense codes
2011-09-20 15:26 [Qemu-devel] [PATCH 00/12] scsi-disk: Add DVD-ROM support and media change + atapi: nitpicking Paolo Bonzini
` (4 preceding siblings ...)
2011-09-20 15:26 ` [Qemu-devel] [PATCH 05/12] scsi: notify the device when unit attention is reported Paolo Bonzini
@ 2011-09-20 15:26 ` Paolo Bonzini
2011-09-20 15:26 ` [Qemu-devel] [PATCH 07/12] scsi-disk: add stubs for more MMC commands Paolo Bonzini
` (5 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Paolo Bonzini @ 2011-09-20 15:26 UTC (permalink / raw)
To: qemu-devel
Building on the previous patch, this one adds a media change callback
to scsi-disk.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/scsi-bus.c | 5 +++++
hw/scsi-disk.c | 29 ++++++++++++++++++++++++++++-
hw/scsi.h | 2 ++
3 files changed, 35 insertions(+), 1 deletions(-)
diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
index c190509..867b1a8 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -847,6 +847,11 @@ const struct SCSISense sense_code_RESET = {
.key = UNIT_ATTENTION, .asc = 0x29, .ascq = 0x00
};
+/* Unit attention, No medium */
+const struct SCSISense sense_code_UNIT_ATTENTION_NO_MEDIUM = {
+ .key = UNIT_ATTENTION, .asc = 0x3a, .ascq = 0x00
+};
+
/* Unit attention, Medium may have changed */
const struct SCSISense sense_code_MEDIUM_CHANGED = {
.key = UNIT_ATTENTION, .asc = 0x28, .ascq = 0x00
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index b5447af..5052a63 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -71,6 +71,7 @@ struct SCSIDiskState
int cluster_size;
uint32_t removable;
uint64_t max_lba;
+ bool media_changed;
QEMUBH *bh;
char *version;
char *serial;
@@ -1197,7 +1198,18 @@ static void scsi_destroy(SCSIDevice *dev)
static void scsi_cd_change_media_cb(void *opaque, bool load)
{
- ((SCSIDiskState *)opaque)->tray_open = !load;
+ SCSIDiskState *s = opaque;
+
+ /*
+ * When a CD gets changed, we have to report an ejected state and
+ * then a loaded state to guests so that they detect tray
+ * open/close and media change events. Guests that do not use
+ * GET_EVENT_STATUS_NOTIFICATION to detect such tray open/close
+ * states rely on this behavior.
+ */
+ s->media_changed = load;
+ s->tray_open = !load;
+ s->qdev.unit_attention = SENSE_CODE(UNIT_ATTENTION_NO_MEDIUM);
}
static bool scsi_cd_is_tray_open(void *opaque)
@@ -1216,6 +1231,15 @@ static const BlockDevOps scsi_cd_block_ops = {
.is_medium_locked = scsi_cd_is_medium_locked,
};
+static void scsi_disk_unit_attention_reported(SCSIDevice *dev)
+{
+ SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
+ if (s->media_changed) {
+ s->media_changed = false;
+ s->qdev.unit_attention = SENSE_CODE(MEDIUM_CHANGED);
+ }
+}
+
static int scsi_initfn(SCSIDevice *dev, uint8_t scsi_type)
{
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
@@ -1327,6 +1351,7 @@ static SCSIDeviceInfo scsi_disk_info[] = {
.init = scsi_hd_initfn,
.destroy = scsi_destroy,
.alloc_req = scsi_new_request,
+ .unit_attention_reported = scsi_disk_unit_attention_reported,
.qdev.props = (Property[]) {
DEFINE_SCSI_DISK_PROPERTIES(),
DEFINE_PROP_BIT("removable", SCSIDiskState, removable, 0, false),
@@ -1341,6 +1366,7 @@ static SCSIDeviceInfo scsi_disk_info[] = {
.init = scsi_cd_initfn,
.destroy = scsi_destroy,
.alloc_req = scsi_new_request,
+ .unit_attention_reported = scsi_disk_unit_attention_reported,
.qdev.props = (Property[]) {
DEFINE_SCSI_DISK_PROPERTIES(),
DEFINE_PROP_END_OF_LIST(),
@@ -1354,6 +1380,7 @@ static SCSIDeviceInfo scsi_disk_info[] = {
.init = scsi_disk_initfn,
.destroy = scsi_destroy,
.alloc_req = scsi_new_request,
+ .unit_attention_reported = scsi_disk_unit_attention_reported,
.qdev.props = (Property[]) {
DEFINE_SCSI_DISK_PROPERTIES(),
DEFINE_PROP_BIT("removable", SCSIDiskState, removable, 0, false),
diff --git a/hw/scsi.h b/hw/scsi.h
index 6d40b8e..7004aaa 100644
--- a/hw/scsi.h
+++ b/hw/scsi.h
@@ -161,6 +161,8 @@ extern const struct SCSISense sense_code_IO_ERROR;
extern const struct SCSISense sense_code_I_T_NEXUS_LOSS;
/* Command aborted, Logical Unit failure */
extern const struct SCSISense sense_code_LUN_FAILURE;
+/* LUN not ready, Medium not present */
+extern const struct SCSISense sense_code_UNIT_ATTENTION_NO_MEDIUM;
/* Unit attention, Power on, reset or bus device reset occurred */
extern const struct SCSISense sense_code_RESET;
/* Unit attention, Medium may have changed*/
--
1.7.6
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Qemu-devel] [PATCH 07/12] scsi-disk: add stubs for more MMC commands
2011-09-20 15:26 [Qemu-devel] [PATCH 00/12] scsi-disk: Add DVD-ROM support and media change + atapi: nitpicking Paolo Bonzini
` (5 preceding siblings ...)
2011-09-20 15:26 ` [Qemu-devel] [PATCH 06/12] scsi-disk: report media changed via unit attention sense codes Paolo Bonzini
@ 2011-09-20 15:26 ` Paolo Bonzini
2011-09-20 15:26 ` [Qemu-devel] [PATCH 08/12] scsi-disk: store valid mode pages in a table Paolo Bonzini
` (4 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Paolo Bonzini @ 2011-09-20 15:26 UTC (permalink / raw)
To: qemu-devel
This patch adds a few stub implementations for MMC commands to
scsi-disk, to be filled in later in the series. It also adds to
scsi-defs.h constants for commands implemented by ide/atapi.c,
when missing.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/scsi-defs.h | 3 ++
hw/scsi-disk.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++----
2 files changed, 61 insertions(+), 5 deletions(-)
diff --git a/hw/scsi-defs.h b/hw/scsi-defs.h
index 8094698..030d4c2 100644
--- a/hw/scsi-defs.h
+++ b/hw/scsi-defs.h
@@ -113,6 +113,7 @@
#define READ_12 0xa8
#define WRITE_12 0xaa
#define SERVICE_ACTION_IN_12 0xab
+#define READ_DVD_STRUCTURE 0xad
#define WRITE_VERIFY_12 0xae
#define VERIFY_12 0xaf
#define SEARCH_HIGH_12 0xb0
@@ -122,6 +123,8 @@
#define SEND_VOLUME_TAG 0xb6
#define READ_DEFECT_DATA_12 0xb7
#define SET_CD_SPEED 0xbb
+#define MECHANISM_STATUS 0xbd
+#define READ_CD 0xbe
/*
* SERVICE ACTION IN subcodes
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 5052a63..624996b 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -562,6 +562,43 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf)
return buflen;
}
+static int scsi_read_dvd_structure(SCSIDiskState *s, SCSIDiskReq *r,
+ uint8_t *outbuf)
+{
+ scsi_check_condition(r, SENSE_CODE(INVALID_OPCODE));
+ return -1;
+}
+
+static int scsi_get_event_status_notification(SCSIDiskState *s,
+ SCSIDiskReq *r, uint8_t *outbuf)
+{
+ scsi_check_condition(r, SENSE_CODE(INVALID_OPCODE));
+ return -1;
+}
+
+static int scsi_get_configuration(SCSIDiskState *s, SCSIDiskReq *r,
+ uint8_t *outbuf)
+{
+ if (s->qdev.type != TYPE_ROM) {
+ return -1;
+ }
+ memset(outbuf, 0, 8);
+ /* ??? This should probably return much more information. For now
+ just return the basic header indicating the CD-ROM profile. */
+ outbuf[7] = 8; // CD-ROM
+ return 8;
+}
+
+static int scsi_emulate_mechanism_status(SCSIDiskState *s, uint8_t *outbuf)
+{
+ if (s->qdev.type != TYPE_ROM) {
+ return -1;
+ }
+ memset(outbuf, 0, 8);
+ outbuf[5] = 1; // CD-ROM
+ return 8;
+}
+
static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf,
int page_control)
{
@@ -946,12 +983,25 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r)
outbuf[7] = 0;
buflen = 8;
break;
+ case MECHANISM_STATUS:
+ buflen = scsi_emulate_mechanism_status(s, outbuf);
+ if (buflen < 0)
+ goto illegal_request;
+ break;
case GET_CONFIGURATION:
- memset(outbuf, 0, 8);
- /* ??? This should probably return much more information. For now
- just return the basic header indicating the CD-ROM profile. */
- outbuf[7] = 8; // CD-ROM
- buflen = 8;
+ buflen = scsi_get_configuration(s, r, outbuf);
+ if (buflen < 0)
+ goto illegal_request;
+ break;
+ case GET_EVENT_STATUS_NOTIFICATION:
+ buflen = scsi_get_event_status_notification(s, r, outbuf);
+ if (buflen < 0)
+ goto illegal_request;
+ break;
+ case READ_DVD_STRUCTURE:
+ buflen = scsi_read_dvd_structure(s, r, outbuf);
+ if (buflen < 0)
+ goto illegal_request;
break;
case SERVICE_ACTION_IN_16:
/* Service Action In subcommands. */
@@ -1054,7 +1104,10 @@ static int32_t scsi_send_command(SCSIRequest *req, uint8_t *buf)
case ALLOW_MEDIUM_REMOVAL:
case READ_CAPACITY_10:
case READ_TOC:
+ case READ_DVD_STRUCTURE:
case GET_CONFIGURATION:
+ case GET_EVENT_STATUS_NOTIFICATION:
+ case MECHANISM_STATUS:
case SERVICE_ACTION_IN_16:
case VERIFY_10:
rc = scsi_disk_emulate_command(r);
--
1.7.6
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Qemu-devel] [PATCH 08/12] scsi-disk: store valid mode pages in a table
2011-09-20 15:26 [Qemu-devel] [PATCH 00/12] scsi-disk: Add DVD-ROM support and media change + atapi: nitpicking Paolo Bonzini
` (6 preceding siblings ...)
2011-09-20 15:26 ` [Qemu-devel] [PATCH 07/12] scsi-disk: add stubs for more MMC commands Paolo Bonzini
@ 2011-09-20 15:26 ` Paolo Bonzini
2011-09-20 15:26 ` [Qemu-devel] [PATCH 09/12] atapi/scsi-disk: make mode page values coherent between the two Paolo Bonzini
` (3 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Paolo Bonzini @ 2011-09-20 15:26 UTC (permalink / raw)
To: qemu-devel
A small refactoring of the MODE SENSE implementation in scsi-disk.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/scsi-disk.c | 25 +++++++++++++------------
1 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 624996b..0c47a39 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -602,10 +602,23 @@ static int scsi_emulate_mechanism_status(SCSIDiskState *s, uint8_t *outbuf)
static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf,
int page_control)
{
+ static const int mode_sense_valid[0x3f] = {
+ [MODE_PAGE_HD_GEOMETRY] = (1 << TYPE_DISK),
+ [MODE_PAGE_FLEXIBLE_DISK_GEOMETRY] = (1 << TYPE_DISK),
+ [MODE_PAGE_CACHING] = (1 << TYPE_DISK) | (1 << TYPE_ROM),
+ [MODE_PAGE_CAPABILITIES] = (1 << TYPE_ROM),
+ };
+
BlockDriverState *bdrv = s->bs;
int cylinders, heads, secs;
uint8_t *p = *p_outbuf;
+ if ((mode_sense_valid[page] & (1 << s->qdev.type)) == 0) {
+ return -1;
+ }
+
+ p[0] = page;
+
/*
* If Changeable Values are requested, a mask denoting those mode parameters
* that are changeable shall be returned. As we currently don't support
@@ -614,10 +627,6 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf,
*/
switch (page) {
case MODE_PAGE_HD_GEOMETRY:
- if (s->qdev.type == TYPE_ROM) {
- return -1;
- }
- p[0] = 4;
p[1] = 0x16;
if (page_control == 1) { /* Changeable Values */
break;
@@ -649,10 +658,6 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf,
break;
case MODE_PAGE_FLEXIBLE_DISK_GEOMETRY:
- if (s->qdev.type == TYPE_ROM) {
- return -1;
- }
- p[0] = 5;
p[1] = 0x1e;
if (page_control == 1) { /* Changeable Values */
break;
@@ -702,10 +707,6 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf,
break;
case MODE_PAGE_CAPABILITIES:
- if (s->qdev.type != TYPE_ROM) {
- return -1;
- }
- p[0] = 0x2a;
p[1] = 0x14;
if (page_control == 1) { /* Changeable Values */
break;
--
1.7.6
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Qemu-devel] [PATCH 09/12] atapi/scsi-disk: make mode page values coherent between the two
2011-09-20 15:26 [Qemu-devel] [PATCH 00/12] scsi-disk: Add DVD-ROM support and media change + atapi: nitpicking Paolo Bonzini
` (7 preceding siblings ...)
2011-09-20 15:26 ` [Qemu-devel] [PATCH 08/12] scsi-disk: store valid mode pages in a table Paolo Bonzini
@ 2011-09-20 15:26 ` Paolo Bonzini
2011-09-20 15:26 ` [Qemu-devel] [PATCH 10/12] scsi-disk: support DVD profile in GET CONFIGURATION Paolo Bonzini
` (2 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Paolo Bonzini @ 2011-09-20 15:26 UTC (permalink / raw)
To: qemu-devel
This patch adds to scsi-disk the missing mode page 0x01 for both disk
and CD-ROM drives, and mode page 0x0e for CD drives only.
A few offsets were wrong in atapi.c. Also change the 2Ah mode page to
expose DVD media read capabilities in the IDE cdrom. This lets you run
dvd+rw-mediainfo on the virtual DVD drives.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/ide/atapi.c | 12 ++++++------
hw/scsi-disk.c | 33 ++++++++++++++++++++++++---------
2 files changed, 30 insertions(+), 15 deletions(-)
diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
index 10f161f..c6eb8f0 100644
--- a/hw/ide/atapi.c
+++ b/hw/ide/atapi.c
@@ -751,7 +751,7 @@ static void cmd_mode_sense(IDEState *s, uint8_t *buf)
buf[8] = 0x2a;
buf[9] = 0x12;
- buf[10] = 0x00;
+ buf[10] = 0x3b; /* read CDR/CDRW/DVDROM/DVDR/DVDRAM */
buf[11] = 0x00;
/* Claim PLAY_AUDIO capability (0x01) since some Linux
@@ -760,14 +760,14 @@ static void cmd_mode_sense(IDEState *s, uint8_t *buf)
buf[13] = 3 << 5;
buf[14] = (1 << 0) | (1 << 3) | (1 << 5);
if (s->tray_locked) {
- buf[6] |= 1 << 1;
+ buf[14] |= 1 << 1;
}
- buf[15] = 0x00;
- cpu_to_ube16(&buf[16], 706);
+ buf[15] = 0x00; /* No volume & mute control, no changer */
+ cpu_to_ube16(&buf[16], 704); /* 4x read speed */
buf[18] = 0;
buf[19] = 2;
- cpu_to_ube16(&buf[20], 512);
- cpu_to_ube16(&buf[22], 706);
+ cpu_to_ube16(&buf[20], 512); /* 512k buffer */
+ cpu_to_ube16(&buf[22], 704); /* 4x read speed current */
buf[24] = 0;
buf[25] = 0;
buf[26] = 0;
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 0c47a39..33bab8c 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -606,6 +606,8 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf,
[MODE_PAGE_HD_GEOMETRY] = (1 << TYPE_DISK),
[MODE_PAGE_FLEXIBLE_DISK_GEOMETRY] = (1 << TYPE_DISK),
[MODE_PAGE_CACHING] = (1 << TYPE_DISK) | (1 << TYPE_ROM),
+ [MODE_PAGE_R_W_ERROR] = (1 << TYPE_DISK) | (1 << TYPE_ROM),
+ [MODE_PAGE_AUDIO_CTL] = (1 << TYPE_ROM),
[MODE_PAGE_CAPABILITIES] = (1 << TYPE_ROM),
};
@@ -706,13 +708,26 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf,
}
break;
+ case MODE_PAGE_R_W_ERROR:
+ p[1] = 10;
+ p[2] = 0x80; /* Automatic Write Reallocation Enabled */
+ if (s->qdev.type == TYPE_ROM) {
+ p[3] = 0x20; /* Read Retry Count */
+ }
+ break;
+
+ case MODE_PAGE_AUDIO_CTL:
+ p[1] = 14;
+ break;
+
case MODE_PAGE_CAPABILITIES:
p[1] = 0x14;
if (page_control == 1) { /* Changeable Values */
break;
}
- p[2] = 3; // CD-R & CD-RW read
- p[3] = 0; // Writing not supported
+
+ p[2] = 0x3b; /* CD-R & CD-RW read */
+ p[3] = 0; /* Writing not supported */
p[4] = 0x7f; /* Audio, composite, digital out,
mode 2 form 1&2, multi session */
p[5] = 0xff; /* CD DA, DA accurate, RW supported,
@@ -722,17 +737,17 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf,
/* Locking supported, jumper present, eject, tray */
p[7] = 0; /* no volume & mute control, no
changer */
- p[8] = (50 * 176) >> 8; // 50x read speed
+ p[8] = (50 * 176) >> 8; /* 50x read speed */
p[9] = (50 * 176) & 0xff;
- p[10] = 0 >> 8; // No volume
- p[11] = 0 & 0xff;
- p[12] = 2048 >> 8; // 2M buffer
+ p[10] = 0 >> 8; /* Volume */
+ p[11] = 2 & 0xff;
+ p[12] = 2048 >> 8; /* 2M buffer */
p[13] = 2048 & 0xff;
- p[14] = (16 * 176) >> 8; // 16x read speed current
+ p[14] = (16 * 176) >> 8; /* 16x read speed current */
p[15] = (16 * 176) & 0xff;
- p[18] = (16 * 176) >> 8; // 16x write speed
+ p[18] = (16 * 176) >> 8; /* 16x write speed */
p[19] = (16 * 176) & 0xff;
- p[20] = (16 * 176) >> 8; // 16x write speed current
+ p[20] = (16 * 176) >> 8; /* 16x write speed current */
p[21] = (16 * 176) & 0xff;
break;
--
1.7.6
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Qemu-devel] [PATCH 10/12] scsi-disk: support DVD profile in GET CONFIGURATION
2011-09-20 15:26 [Qemu-devel] [PATCH 00/12] scsi-disk: Add DVD-ROM support and media change + atapi: nitpicking Paolo Bonzini
` (8 preceding siblings ...)
2011-09-20 15:26 ` [Qemu-devel] [PATCH 09/12] atapi/scsi-disk: make mode page values coherent between the two Paolo Bonzini
@ 2011-09-20 15:26 ` Paolo Bonzini
2011-09-20 15:26 ` [Qemu-devel] [PATCH 11/12] scsi-disk: support READ DVD STRUCTURE Paolo Bonzini
2011-09-20 15:26 ` [Qemu-devel] [PATCH 12/12] scsi-disk: report media changed via GET EVENT STATUS NOTIFICATION Paolo Bonzini
11 siblings, 0 replies; 13+ messages in thread
From: Paolo Bonzini @ 2011-09-20 15:26 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/scsi-disk.c | 50 ++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 42 insertions(+), 8 deletions(-)
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 33bab8c..d6b5bfe 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -562,6 +562,19 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf)
return buflen;
}
+static inline bool media_is_dvd(SCSIDiskState *s)
+{
+ uint64_t nb_sectors;
+ if (s->qdev.type != TYPE_ROM) {
+ return false;
+ }
+ if (!bdrv_is_inserted(s->bs)) {
+ return false;
+ }
+ bdrv_get_geometry(s->bs, &nb_sectors);
+ return nb_sectors > CD_MAX_SECTORS;
+}
+
static int scsi_read_dvd_structure(SCSIDiskState *s, SCSIDiskReq *r,
uint8_t *outbuf)
{
@@ -576,17 +589,38 @@ static int scsi_get_event_status_notification(SCSIDiskState *s,
return -1;
}
-static int scsi_get_configuration(SCSIDiskState *s, SCSIDiskReq *r,
- uint8_t *outbuf)
+static int scsi_get_configuration(SCSIDiskState *s, uint8_t *outbuf)
{
+ int current;
+
if (s->qdev.type != TYPE_ROM) {
return -1;
}
- memset(outbuf, 0, 8);
- /* ??? This should probably return much more information. For now
- just return the basic header indicating the CD-ROM profile. */
- outbuf[7] = 8; // CD-ROM
- return 8;
+ current = media_is_dvd(s) ? MMC_PROFILE_DVD_ROM : MMC_PROFILE_CD_ROM;
+ memset(outbuf, 0, 40);
+ stl_be_p(&outbuf[0], 36); /* Bytes after the data length field */
+ /* outbuf[4] - outbuf[19]: Feature 0 - Profile list */
+ stw_be_p(&outbuf[6], current);
+ outbuf[10] = 0x03; /* persistent, current */
+ outbuf[11] = 8; /* two profiles */
+ stw_be_p(&outbuf[12], MMC_PROFILE_DVD_ROM);
+ outbuf[14] = (current == MMC_PROFILE_DVD_ROM);
+ stw_be_p(&outbuf[16], MMC_PROFILE_CD_ROM);
+ outbuf[18] = (current == MMC_PROFILE_CD_ROM);
+ /* outbuf[20] - outbuf[31]: Feature 1 - Core feature */
+ stw_be_p(&outbuf[20], 1);
+ outbuf[22] = 0x08 | 0x03; /* version 2, persistent, current */
+ outbuf[23] = 8;
+ stl_be_p(&outbuf[24], 1); /* SCSI */
+ outbuf[28] = 1; /* DBE = 1, mandatory */
+ /* outbuf[32] - outbuf[39]: Feature 3 - Removable media feature */
+ stw_be_p(&outbuf[32], 3);
+ outbuf[34] = 0x08 | 0x03; /* version 2, persistent, current */
+ outbuf[35] = 4;
+ outbuf[36] = 0x39; /* tray, load=1, eject=1, unlocked at powerup, lock=1 */
+ /* TODO: Random readable, CD read, DVD read, drive serial number,
+ power management */
+ return 40;
}
static int scsi_emulate_mechanism_status(SCSIDiskState *s, uint8_t *outbuf)
@@ -1005,7 +1039,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r)
goto illegal_request;
break;
case GET_CONFIGURATION:
- buflen = scsi_get_configuration(s, r, outbuf);
+ buflen = scsi_get_configuration(s, outbuf);
if (buflen < 0)
goto illegal_request;
break;
--
1.7.6
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Qemu-devel] [PATCH 11/12] scsi-disk: support READ DVD STRUCTURE
2011-09-20 15:26 [Qemu-devel] [PATCH 00/12] scsi-disk: Add DVD-ROM support and media change + atapi: nitpicking Paolo Bonzini
` (9 preceding siblings ...)
2011-09-20 15:26 ` [Qemu-devel] [PATCH 10/12] scsi-disk: support DVD profile in GET CONFIGURATION Paolo Bonzini
@ 2011-09-20 15:26 ` Paolo Bonzini
2011-09-20 15:26 ` [Qemu-devel] [PATCH 12/12] scsi-disk: report media changed via GET EVENT STATUS NOTIFICATION Paolo Bonzini
11 siblings, 0 replies; 13+ messages in thread
From: Paolo Bonzini @ 2011-09-20 15:26 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/scsi-disk.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 100 insertions(+), 1 deletions(-)
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index d6b5bfe..778332e 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -575,10 +575,109 @@ static inline bool media_is_dvd(SCSIDiskState *s)
return nb_sectors > CD_MAX_SECTORS;
}
+static inline bool media_is_cd(SCSIDiskState *s)
+{
+ uint64_t nb_sectors;
+ if (s->qdev.type != TYPE_ROM) {
+ return false;
+ }
+ if (!bdrv_is_inserted(s->bs)) {
+ return false;
+ }
+ bdrv_get_geometry(s->bs, &nb_sectors);
+ return nb_sectors <= CD_MAX_SECTORS;
+}
+
static int scsi_read_dvd_structure(SCSIDiskState *s, SCSIDiskReq *r,
uint8_t *outbuf)
{
- scsi_check_condition(r, SENSE_CODE(INVALID_OPCODE));
+ static const int rds_caps_size[5] = {
+ [0] = 2048 + 4,
+ [1] = 4 + 4,
+ [3] = 188 + 4,
+ [4] = 2048 + 4,
+ };
+
+ uint8_t media = r->req.cmd.buf[1];
+ uint8_t layer = r->req.cmd.buf[6];
+ uint8_t format = r->req.cmd.buf[7];
+ int size = -1;
+
+ if (s->qdev.type != TYPE_ROM || !bdrv_is_inserted(s->bs)) {
+ return -1;
+ }
+ if (s->tray_open || !bdrv_is_inserted(s->bs)) {
+ scsi_check_condition(r, SENSE_CODE(NO_MEDIUM));
+ return -1;
+ }
+ if (media_is_cd(s)) {
+ scsi_check_condition(r, SENSE_CODE(INCOMPATIBLE_FORMAT));
+ return -1;
+ }
+ if (media != 0) {
+ scsi_check_condition(r, SENSE_CODE(INCOMPATIBLE_FORMAT));
+ return -1;
+ }
+
+ if (format != 0xff) {
+ if (format >= sizeof(rds_caps_size) / sizeof(rds_caps_size[0])) {
+ return -1;
+ }
+ size = rds_caps_size[format];
+ memset(outbuf, 0, size);
+ }
+
+ switch (format) {
+ case 0x00: {
+ /* Physical format information */
+ uint64_t nb_sectors;
+ if (layer != 0)
+ goto fail;
+ bdrv_get_geometry(s->bs, &nb_sectors);
+
+ outbuf[4] = 1; /* DVD-ROM, part version 1 */
+ outbuf[5] = 0xf; /* 120mm disc, minimum rate unspecified */
+ outbuf[6] = 1; /* one layer, read-only (per MMC-2 spec) */
+ outbuf[7] = 0; /* default densities */
+
+ stl_be_p(&outbuf[12], (nb_sectors >> 2) - 1); /* end sector */
+ stl_be_p(&outbuf[16], (nb_sectors >> 2) - 1); /* l0 end sector */
+ break;
+ }
+
+ case 0x01: /* DVD copyright information, all zeros */
+ break;
+
+ case 0x03: /* BCA information - invalid field for no BCA info */
+ return -1;
+
+ case 0x04: /* DVD disc manufacturing information, all zeros */
+ break;
+
+ case 0xff: { /* List capabilities */
+ int i;
+ size = 4;
+ for (i = 0; i < sizeof(rds_caps_size) / sizeof(rds_caps_size[0]); i++) {
+ if (!rds_caps_size[i]) {
+ continue;
+ }
+ outbuf[size] = i;
+ outbuf[size + 1] = 0x40; /* Not writable, readable */
+ stw_be_p(&outbuf[size + 2], rds_caps_size[i]);
+ size += 4;
+ }
+ break;
+ }
+
+ default:
+ return -1;
+ }
+
+ /* Size of buffer, not including 2 byte size field */
+ stw_be_p(outbuf, size - 2);
+ return size;
+
+fail:
return -1;
}
--
1.7.6
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Qemu-devel] [PATCH 12/12] scsi-disk: report media changed via GET EVENT STATUS NOTIFICATION
2011-09-20 15:26 [Qemu-devel] [PATCH 00/12] scsi-disk: Add DVD-ROM support and media change + atapi: nitpicking Paolo Bonzini
` (10 preceding siblings ...)
2011-09-20 15:26 ` [Qemu-devel] [PATCH 11/12] scsi-disk: support READ DVD STRUCTURE Paolo Bonzini
@ 2011-09-20 15:26 ` Paolo Bonzini
11 siblings, 0 replies; 13+ messages in thread
From: Paolo Bonzini @ 2011-09-20 15:26 UTC (permalink / raw)
To: qemu-devel
This adds support for media change notification via the GET EVENT STATUS
NOTIFICATION command, used by Linux versions 2.6.38 and newer.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/scsi-disk.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 53 insertions(+), 4 deletions(-)
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 778332e..6f5d607 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -72,6 +72,7 @@ struct SCSIDiskState
uint32_t removable;
uint64_t max_lba;
bool media_changed;
+ bool new_media;
QEMUBH *bh;
char *version;
char *serial;
@@ -681,11 +682,58 @@ fail:
return -1;
}
-static int scsi_get_event_status_notification(SCSIDiskState *s,
- SCSIDiskReq *r, uint8_t *outbuf)
+static int scsi_event_status_media(SCSIDiskState *s, uint8_t *outbuf)
{
- scsi_check_condition(r, SENSE_CODE(INVALID_OPCODE));
- return -1;
+ uint8_t event_code, media_status;
+
+ media_status = 0;
+ if (s->tray_open) {
+ media_status = MS_TRAY_OPEN;
+ } else if (bdrv_is_inserted(s->bs)) {
+ media_status = MS_MEDIA_PRESENT;
+ }
+
+ /* Event notification descriptor */
+ event_code = MEC_NO_CHANGE;
+ if (media_status != MS_TRAY_OPEN && s->new_media) {
+ event_code = MEC_NEW_MEDIA;
+ s->new_media = false;
+ }
+
+ outbuf[0] = event_code;
+ outbuf[1] = media_status;
+
+ /* These fields are reserved, just clear them. */
+ outbuf[2] = 0;
+ outbuf[3] = 0;
+ return 4;
+}
+
+static int scsi_get_event_status_notification(SCSIDiskState *s, SCSIDiskReq *r,
+ uint8_t *outbuf)
+{
+ int size;
+ uint8_t *buf = r->req.cmd.buf;
+ uint8_t notification_class_request = buf[4];
+ if (s->qdev.type != TYPE_ROM) {
+ return -1;
+ }
+ if ((buf[1] & 1) == 0) {
+ /* asynchronous */
+ return -1;
+ }
+
+ size = 4;
+ outbuf[0] = outbuf[1] = 0;
+ outbuf[3] = 1 << GESN_MEDIA; /* supported events */
+ if (notification_class_request & (1 << GESN_MEDIA)) {
+ outbuf[2] = GESN_MEDIA;
+ size += scsi_event_status_media(s, &outbuf[size]);
+ } else {
+ outbuf[2] = 0x80;
+ }
+ stw_be_p(outbuf, size - 4);
+ return size;
}
static int scsi_get_configuration(SCSIDiskState *s, uint8_t *outbuf)
@@ -1415,6 +1463,7 @@ static void scsi_cd_change_media_cb(void *opaque, bool load)
s->media_changed = load;
s->tray_open = !load;
s->qdev.unit_attention = SENSE_CODE(UNIT_ATTENTION_NO_MEDIUM);
+ s->new_media = true;
}
static bool scsi_cd_is_tray_open(void *opaque)
--
1.7.6
^ permalink raw reply related [flat|nested] 13+ messages in thread
end of thread, other threads:[~2011-09-20 15:27 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-20 15:26 [Qemu-devel] [PATCH 00/12] scsi-disk: Add DVD-ROM support and media change + atapi: nitpicking Paolo Bonzini
2011-09-20 15:26 ` [Qemu-devel] [PATCH 01/12] scsi: pass correct sense code for ENOMEDIUM Paolo Bonzini
2011-09-20 15:26 ` [Qemu-devel] [PATCH 02/12] atapi/scsi: unify definitions for MMC Paolo Bonzini
2011-09-20 15:26 ` [Qemu-devel] [PATCH 03/12] atapi: move GESN definitions to scsi-defs.h Paolo Bonzini
2011-09-20 15:26 ` [Qemu-devel] [PATCH 04/12] atapi: fill in AUDIO_CTL page correctly Paolo Bonzini
2011-09-20 15:26 ` [Qemu-devel] [PATCH 05/12] scsi: notify the device when unit attention is reported Paolo Bonzini
2011-09-20 15:26 ` [Qemu-devel] [PATCH 06/12] scsi-disk: report media changed via unit attention sense codes Paolo Bonzini
2011-09-20 15:26 ` [Qemu-devel] [PATCH 07/12] scsi-disk: add stubs for more MMC commands Paolo Bonzini
2011-09-20 15:26 ` [Qemu-devel] [PATCH 08/12] scsi-disk: store valid mode pages in a table Paolo Bonzini
2011-09-20 15:26 ` [Qemu-devel] [PATCH 09/12] atapi/scsi-disk: make mode page values coherent between the two Paolo Bonzini
2011-09-20 15:26 ` [Qemu-devel] [PATCH 10/12] scsi-disk: support DVD profile in GET CONFIGURATION Paolo Bonzini
2011-09-20 15:26 ` [Qemu-devel] [PATCH 11/12] scsi-disk: support READ DVD STRUCTURE Paolo Bonzini
2011-09-20 15:26 ` [Qemu-devel] [PATCH 12/12] scsi-disk: report media changed via GET EVENT STATUS NOTIFICATION Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).