From patchwork Tue Oct 25 10:40:17 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 121659 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 659C2B6F95 for ; Tue, 25 Oct 2011 23:51:46 +1100 (EST) Received: from localhost ([::1]:44545 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RIeRu-0000ll-UC for incoming@patchwork.ozlabs.org; Tue, 25 Oct 2011 06:41:38 -0400 Received: from eggs.gnu.org ([140.186.70.92]:59577) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RIeRL-0008NK-Dx for qemu-devel@nongnu.org; Tue, 25 Oct 2011 06:41:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RIeRH-0006IW-JW for qemu-devel@nongnu.org; Tue, 25 Oct 2011 06:41:02 -0400 Received: from mail-wy0-f173.google.com ([74.125.82.173]:49684) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RIeRH-0006FG-5c for qemu-devel@nongnu.org; Tue, 25 Oct 2011 06:40:59 -0400 Received: by mail-wy0-f173.google.com with SMTP id 15so379083wyh.4 for ; Tue, 25 Oct 2011 03:40:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=5hlBmiL3wqfofPVbJ6TWAZIDBLOwJLjQ7yTZvfe4oJU=; b=TzvfkEY/gXI4GUKtfBXKUd0IUtMXe/AT9aQfhWKJHTgvZQ+dvX0yGCUyODJckXTE8r Hmq8kXq2tcGTVLKEcDcpovIh3AsNQNDisYtAlj8X0jmK2ParZx8safv+9aRgJ0CgA/ka pLgFCjJQufQ2r9q4dMnIZG9kp+UwXniEb1X7A= Received: by 10.227.206.143 with SMTP id fu15mr2776931wbb.16.1319539258542; Tue, 25 Oct 2011 03:40:58 -0700 (PDT) Received: from localhost.localdomain (93-34-199-98.ip51.fastwebnet.it. [93.34.199.98]) by mx.google.com with ESMTPS id fr4sm15677349wbb.0.2011.10.25.03.40.57 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 25 Oct 2011 03:40:58 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 25 Oct 2011 12:40:17 +0200 Message-Id: <1319539241-26436-10-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.6 In-Reply-To: <1319539241-26436-1-git-send-email-pbonzini@redhat.com> References: <1319539241-26436-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 74.125.82.173 Cc: kwolf@redhat.com Subject: [Qemu-devel] [PATCH v2 09/33] scsi-disk: store valid mode pages in a table X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org A small refactoring of the MODE SENSE implementation in scsi-disk. Signed-off-by: Paolo Bonzini --- 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 0557ede..bcce076 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -607,10 +607,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 @@ -619,10 +632,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; @@ -654,10 +663,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; @@ -707,10 +712,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;