From patchwork Tue Jun 12 09:59:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 164710 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 214F8B6FBB for ; Thu, 14 Jun 2012 01:35:42 +1000 (EST) Received: from localhost ([::1]:48682 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sepbg-0003mP-14 for incoming@patchwork.ozlabs.org; Wed, 13 Jun 2012 11:35:40 -0400 Received: from eggs.gnu.org ([208.118.235.92]:48554) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SepbU-0003lf-UD for qemu-devel@nongnu.org; Wed, 13 Jun 2012 11:35:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SepbO-0005UW-BX for qemu-devel@nongnu.org; Wed, 13 Jun 2012 11:35:28 -0400 Received: from cantor2.suse.de ([195.135.220.15]:59155 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SepbO-0005UJ-26 for qemu-devel@nongnu.org; Wed, 13 Jun 2012 11:35:22 -0400 Received: from relay1.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 4116C8FFDD; Wed, 13 Jun 2012 17:35:20 +0200 (CEST) From: Alexander Graf To: "qemu-devel@nongnu.org Developers" Date: Tue, 12 Jun 2012 11:59:43 +0200 Message-Id: <1339495183-29577-1-git-send-email-agraf@suse.de> X-Mailer: git-send-email 1.6.0.2 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-Received-From: 195.135.220.15 Cc: Kevin Wolf Subject: [Qemu-devel] [PATCH] ahci: add -drive support 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 We've had support for creating AHCI devices using -device for a while now, but it's cumbersome to users. We really should provide an easier way for them to leverage the power of AHCI! So let's introduce a new if= option to -drive, bumping it en par with virtio. Signed-off-by: Alexander Graf --- blockdev.c | 25 +++++++++++++++++++++++-- blockdev.h | 1 + qemu-options.hx | 7 ++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/blockdev.c b/blockdev.c index 622ecba..5405f6c 100644 --- a/blockdev.c +++ b/blockdev.c @@ -32,6 +32,7 @@ static const char *const if_name[IF_COUNT] = { [IF_SD] = "sd", [IF_VIRTIO] = "virtio", [IF_XEN] = "xen", + [IF_AHCI] = "ahci", }; static const int if_max_devs[IF_COUNT] = { @@ -519,7 +520,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi) } else { /* no id supplied -> create one */ dinfo->id = g_malloc0(32); - if (type == IF_IDE || type == IF_SCSI) + if (type == IF_IDE || type == IF_SCSI || type == IF_AHCI) mediastr = (media == MEDIA_CDROM) ? "-cd" : "-hd"; if (max_devs) snprintf(dinfo->id, 32, "%s%i%s%i", @@ -549,6 +550,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi) case IF_IDE: case IF_SCSI: case IF_XEN: + case IF_AHCI: case IF_NONE: switch(media) { case MEDIA_DISK: @@ -582,6 +584,25 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi) default: abort(); } + + if (type == IF_AHCI) { + static int ahci_bus = 0; + char devname[] = "ahciXXX"; + char busname[] = "ahciXXX.0"; + snprintf(devname, sizeof(devname), "ahci%d", ahci_bus); + snprintf(busname, sizeof(busname), "ahci%d.0", ahci_bus++); + + /* add ahci host controller */ + opts = qemu_opts_create(qemu_find_opts("device"), devname, 0, NULL); + qemu_opt_set(opts, "driver", "ich9-ahci"); + + /* and attach a single ata disk to its bus */ + opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0, NULL); + qemu_opt_set(opts, "driver", "ide-drive"); + qemu_opt_set(opts, "bus", busname); + qemu_opt_set(opts, "drive", dinfo->id); + } + if (!file || !*file) { return dinfo; } @@ -604,7 +625,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi) ro = 1; } else if (ro == 1) { if (type != IF_SCSI && type != IF_VIRTIO && type != IF_FLOPPY && - type != IF_NONE && type != IF_PFLASH) { + type != IF_NONE && type != IF_PFLASH && type != IF_AHCI) { error_report("readonly not supported by this bus type"); goto err; } diff --git a/blockdev.h b/blockdev.h index 260e16b..e14c1d5 100644 --- a/blockdev.h +++ b/blockdev.h @@ -23,6 +23,7 @@ typedef enum { IF_DEFAULT = -1, /* for use with drive_add() only */ IF_NONE, IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD, IF_SD, IF_VIRTIO, IF_XEN, + IF_AHCI, IF_COUNT } BlockInterfaceType; diff --git a/qemu-options.hx b/qemu-options.hx index 8b66264..9527c51 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -160,7 +160,7 @@ Special files such as iSCSI devices can be specified using protocol specific URLs. See the section for "Device URL Syntax" for more information. @item if=@var{interface} This option defines on which type on interface the drive is connected. -Available types are: ide, scsi, sd, mtd, floppy, pflash, virtio. +Available types are: ide, scsi, sd, mtd, floppy, pflash, virtio, ahci. @item bus=@var{bus},unit=@var{unit} These options define where is connected the drive by defining the bus number and the unit id. @@ -260,6 +260,11 @@ You can connect a SCSI disk with unit ID 6 on the bus #0: qemu-system-i386 -drive file=file,if=scsi,bus=0,unit=6 @end example +You can attach a SATA disk using AHCI: +@example +qemu-system-i386 -drive file=file,if=ahci +@end example + Instead of @option{-fda}, @option{-fdb}, you can use: @example qemu-system-i386 -drive file=file,index=0,if=floppy