qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gleb Natapov <gleb@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: blauwirbel@gmail.com, alex.williamson@redhat.com,
	qemu-devel@nongnu.org, kvm@vger.kernel.org
Subject: Re: [Qemu-devel] [PATCHv2 4/8] Store IDE bus id in IDEBus structure for easy access.
Date: Wed, 3 Nov 2010 15:47:26 +0200	[thread overview]
Message-ID: <20101103134726.GI7881@redhat.com> (raw)
In-Reply-To: <m339rifrvb.fsf@blackfin.pond.sub.org>

On Wed, Nov 03, 2010 at 02:39:52PM +0100, Markus Armbruster wrote:
> Here's a generic answer to the question "which of the device's buses is
> this?"
> 
> int qbus_index(BusState *bus)
> {
>     BusState *b;
>     int i, index;
> 
>     index = -1;
>     i = 0;
>     QLIST_FOREACH(b, &bus->parent->child_bus, sibling) {
>         if (b == bus) {
>             index = i;
>         }
>         i++;
>     }
>     assert(0 <= index && index < i);
>     return i - 1 - index;
> }
> 
> The bus created first has index 0.
> 
> Note that the child_bus holds the children in reverse creation order,
> and we can't traverse it backwards.  Same problem also visible with
> makes info qtree:
> 
>       dev: piix3-ide, id ""
> [...]
>         bus: ide.1
>           type IDE
>         bus: ide.0
>           type IDE
Isn't this too implementation dependant? Are you against adding bus_id
to IDEBus? And will it work with ISA? I do not think IDEBus is
added to bus->parent->child_bus in case of ISA otherwise why both
IDEBuses have same name in isapc. Currently I have following patch
queued. It should fix isapc case too.

    Fix isapc IDE bus creation
    
    Currently we create two ide buses with the same name, so it is impossible
    to use -device ide-drive,bus= to address all possible disks in the isapc
    machine. Fix that by giving different names to different ide buses. Also
    store IDE bus id in IDEBus structure for easy access.

diff --git a/hw/ide/cmd646.c b/hw/ide/cmd646.c
index ff80dd5..b2cbdbc 100644
--- a/hw/ide/cmd646.c
+++ b/hw/ide/cmd646.c
@@ -257,8 +257,8 @@ static int pci_cmd646_ide_initfn(PCIDevice *dev)
     pci_conf[PCI_INTERRUPT_PIN] = 0x01; // interrupt on pin 1
 
     irq = qemu_allocate_irqs(cmd646_set_irq, d, 2);
-    ide_bus_new(&d->bus[0], &d->dev.qdev);
-    ide_bus_new(&d->bus[1], &d->dev.qdev);
+    ide_bus_new(&d->bus[0], &d->dev.qdev, 0);
+    ide_bus_new(&d->bus[1], &d->dev.qdev, 1);
     ide_init2(&d->bus[0], irq[0]);
     ide_init2(&d->bus[1], irq[1]);
 
diff --git a/hw/ide/internal.h b/hw/ide/internal.h
index 4165543..bde2664 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -448,6 +448,7 @@ struct IDEBus {
     IDEDevice *slave;
     BMDMAState *bmdma;
     IDEState ifs[2];
+    uint8_t bus_id;
     uint8_t unit;
     uint8_t cmd;
     qemu_irq irq;
@@ -564,7 +565,7 @@ void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo *hd0,
 void ide_init_ioport(IDEBus *bus, int iobase, int iobase2);
 
 /* hw/ide/qdev.c */
-void ide_bus_new(IDEBus *idebus, DeviceState *dev);
+void ide_bus_new(IDEBus *idebus, DeviceState *dev, uint8_t bus_id);
 IDEDevice *ide_create_drive(IDEBus *bus, int unit, DriveInfo *drive);
 
 #endif /* HW_IDE_INTERNAL_H */
diff --git a/hw/ide/isa.c b/hw/ide/isa.c
index 9b94495..b000ab8 100644
--- a/hw/ide/isa.c
+++ b/hw/ide/isa.c
@@ -66,8 +66,9 @@ static const VMStateDescription vmstate_ide_isa = {
 static int isa_ide_initfn(ISADevice *dev)
 {
     ISAIDEState *s = DO_UPCAST(ISAIDEState, dev, dev);
+    static uint8_t bus_id = 0;
 
-    ide_bus_new(&s->bus, &s->dev.qdev);
+    ide_bus_new(&s->bus, &s->dev.qdev, bus_id++);
     ide_init_ioport(&s->bus, s->iobase, s->iobase2);
     isa_init_irq(dev, &s->irq, s->isairq);
     isa_init_ioport_range(dev, s->iobase, 8);
diff --git a/hw/ide/piix.c b/hw/ide/piix.c
index 6206201..e56777f 100644
--- a/hw/ide/piix.c
+++ b/hw/ide/piix.c
@@ -129,8 +129,8 @@ static int pci_piix_ide_initfn(PCIIDEState *d)
 
     vmstate_register(&d->dev.qdev, 0, &vmstate_ide_pci, d);
 
-    ide_bus_new(&d->bus[0], &d->dev.qdev);
-    ide_bus_new(&d->bus[1], &d->dev.qdev);
+    ide_bus_new(&d->bus[0], &d->dev.qdev, 0);
+    ide_bus_new(&d->bus[1], &d->dev.qdev, 1);
     ide_init_ioport(&d->bus[0], 0x1f0, 0x3f6);
     ide_init_ioport(&d->bus[1], 0x170, 0x376);
 
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index 336ffe1..220729e 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -29,9 +29,13 @@ static struct BusInfo ide_bus_info = {
     .size  = sizeof(IDEBus),
 };
 
-void ide_bus_new(IDEBus *idebus, DeviceState *dev)
+void ide_bus_new(IDEBus *idebus, DeviceState *dev, uint8_t bus_id)
 {
-    qbus_create_inplace(&idebus->qbus, &ide_bus_info, dev, NULL);
+    char name[10];
+
+    snprintf(name, sizeof(name), "ide.%d", bus_id); 
+    qbus_create_inplace(&idebus->qbus, &ide_bus_info, dev, name);
+    idebus->bus_id = bus_id;
 }
 
 static int ide_qdev_init(DeviceState *qdev, DeviceInfo *base)
diff --git a/hw/ide/via.c b/hw/ide/via.c
index b2c7cad..cc48b2b 100644
--- a/hw/ide/via.c
+++ b/hw/ide/via.c
@@ -158,8 +158,8 @@ static int vt82c686b_ide_initfn(PCIDevice *dev)
 
     vmstate_register(&dev->qdev, 0, &vmstate_ide_pci, d);
 
-    ide_bus_new(&d->bus[0], &d->dev.qdev);
-    ide_bus_new(&d->bus[1], &d->dev.qdev);
+    ide_bus_new(&d->bus[0], &d->dev.qdev, 0);
+    ide_bus_new(&d->bus[1], &d->dev.qdev, 1);
     ide_init2(&d->bus[0], isa_reserve_irq(14));
     ide_init2(&d->bus[1], isa_reserve_irq(15));
     ide_init_ioport(&d->bus[0], 0x1f0, 0x3f6);
diff --git a/hw/pc_piix.c b/hw/pc_piix.c
index 3d07ce5..cec6c9b 100644
--- a/hw/pc_piix.c
+++ b/hw/pc_piix.c
@@ -163,7 +163,7 @@ static void pc_init1(ram_addr_t ram_size,
             ISADevice *dev;
             dev = isa_ide_init(ide_iobase[i], ide_iobase2[i], ide_irq[i],
                                hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]);
-            idebus[i] = qdev_get_child_bus(&dev->qdev, "ide.0");
+            idebus[i] = qdev_get_child_bus(&dev->qdev, i ? "ide.1" : "ide.0");
         }
     }
 
--
			Gleb.

  reply	other threads:[~2010-11-03 13:47 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-31 11:40 [Qemu-devel] [PATCHv2 0/8 RFC] boot order specification Gleb Natapov
2010-10-31 11:40 ` [Qemu-devel] [PATCHv2 1/8] Introduce deriver_name field to DeviceInfo structure Gleb Natapov
2010-11-04  9:20   ` Markus Armbruster
2010-11-04  9:42     ` Gleb Natapov
2010-11-04 14:58       ` Markus Armbruster
2010-11-04 15:44         ` Gleb Natapov
2010-11-05 14:14           ` Markus Armbruster
2010-11-05 15:41             ` Gleb Natapov
2010-11-05 16:24               ` Markus Armbruster
2010-11-05 18:31                 ` Gleb Natapov
2010-11-06  9:01                   ` Markus Armbruster
2010-11-06 11:53                     ` Gleb Natapov
2010-11-06 12:55                       ` Markus Armbruster
2010-10-31 11:40 ` [Qemu-devel] [PATCHv2 2/8] Keep track of ISA ports ISA device is using in qdev Gleb Natapov
2010-10-31 11:40 ` [Qemu-devel] [PATCHv2 3/8] Add get_dev_path callback to ISA bus " Gleb Natapov
2010-10-31 11:40 ` [Qemu-devel] [PATCHv2 4/8] Store IDE bus id in IDEBus structure for easy access Gleb Natapov
2010-11-03 13:39   ` Markus Armbruster
2010-11-03 13:47     ` Gleb Natapov [this message]
2010-11-03 15:18       ` Markus Armbruster
2010-11-03 16:43         ` Gleb Natapov
2010-11-03 17:22           ` Markus Armbruster
2010-11-04  8:07             ` Gleb Natapov
2010-11-04  8:46               ` Markus Armbruster
2010-11-04  9:23                 ` Gleb Natapov
2010-11-04 14:22                   ` Markus Armbruster
2010-11-04 15:26                     ` Gleb Natapov
2010-11-05 14:04                       ` Markus Armbruster
2010-11-05 15:54                         ` Gleb Natapov
2010-11-05 16:31                           ` Markus Armbruster
2010-11-05 18:44                             ` Gleb Natapov
2010-11-06  9:25                               ` Markus Armbruster
2010-11-06 11:37                                 ` Gleb Natapov
2010-11-06 12:46                                   ` Markus Armbruster
2010-10-31 11:40 ` [Qemu-devel] [PATCHv2 5/8] Add get_dev_path callback to IDE bus Gleb Natapov
2010-10-31 11:40 ` [Qemu-devel] [PATCHv2 6/8] Add get_dev_path callback for system bus Gleb Natapov
2010-10-31 11:40 ` [Qemu-devel] [PATCHv2 7/8] Change pci bus get_dev_path callback to print only slot and func Gleb Natapov
2010-11-08 17:17   ` [Qemu-devel] " Michael S. Tsirkin
2010-11-08 17:29     ` Gleb Natapov
2010-11-08 18:12       ` Michael S. Tsirkin
2010-11-08 18:22         ` Gleb Natapov
2010-11-08 21:00       ` Michael S. Tsirkin
2010-11-08 21:12         ` Gleb Natapov
2010-11-08 17:26   ` Michael S. Tsirkin
2010-10-31 11:40 ` [Qemu-devel] [PATCHv2 8/8] Add bootindex parameter to net/block/fd device Gleb Natapov
2010-10-31 22:25 ` [Qemu-devel] Re: [PATCHv2 0/8 RFC] boot order specification Kevin O'Connor
2010-11-01  7:53   ` Gleb Natapov
2010-11-04  9:24     ` Markus Armbruster
2010-11-04  9:45       ` Gleb Natapov

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=20101103134726.GI7881@redhat.com \
    --to=gleb@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=armbru@redhat.com \
    --cc=blauwirbel@gmail.com \
    --cc=kvm@vger.kernel.org \
    --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).