qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Graf <agraf@suse.de>
To: "qemu-devel@nongnu.org Developers" <qemu-devel@nongnu.org>
Cc: Kevin Wolf <kwolf@redhat.com>
Subject: [Qemu-devel] [PATCH] ahci: add -drive support
Date: Tue, 12 Jun 2012 11:59:43 +0200	[thread overview]
Message-ID: <1339495183-29577-1-git-send-email-agraf@suse.de> (raw)

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 <agraf@suse.de>
---
 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
-- 
1.6.0.2

             reply	other threads:[~2012-06-13 15:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-12  9:59 Alexander Graf [this message]
2012-06-14  7:29 ` [Qemu-devel] [PATCH] ahci: add -drive support Markus Armbruster
2012-06-14  7:34   ` Alexander Graf
2012-06-14  7:49     ` Kevin Wolf
2012-06-14  9:06     ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1339495183-29577-1-git-send-email-agraf@suse.de \
    --to=agraf@suse.de \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).