public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Avi Kivity <avi@qumranet.com>, Alexander Graf <agraf@suse.de>
Cc: kvm-devel@lists.sourceforge.net, Marcelo Tosatti <mtosatti@redhat.com>
Subject: [patch 2/3] QEMU/KVM: ACPI PCI hotplug multiple bus support
Date: Fri, 02 May 2008 14:35:49 -0300	[thread overview]
Message-ID: <20080502174204.558653191@localhost.localdomain> (raw)
In-Reply-To: 20080502173547.001963501@localhost.localdomain

[-- Attachment #1: hotplug-support --]
[-- Type: text/plain, Size: 4863 bytes --]

Support more than one bus in the ACPI PCI hotplug code.

Currently 4 buses are supported, but can be easily extended.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

Index: kvm-userspace.pci3/qemu/hw/acpi.c
===================================================================
--- kvm-userspace.pci3.orig/qemu/hw/acpi.c
+++ kvm-userspace.pci3/qemu/hw/acpi.c
@@ -552,10 +552,11 @@ struct gpe_regs {
 struct pci_status {
     uint32_t up;
     uint32_t down;
+    unsigned long base;
 };
 
 static struct gpe_regs gpe;
-static struct pci_status pci0_status;
+static struct pci_status pci_bus_status[4];
 
 static uint32_t gpe_readb(void *opaque, uint32_t addr)
 {
@@ -625,16 +626,19 @@ static void gpe_writeb(void *opaque, uin
 
 static uint32_t pcihotplug_read(void *opaque, uint32_t addr)
 {
-    uint32_t val = 0;
     struct pci_status *g = opaque;
-    switch (addr) {
-        case PCI_BASE:
+    uint32_t val, offset;
+
+    offset = addr - g->base;
+    switch (offset) {
+        case 0:
             val = g->up;
             break;
-        case PCI_BASE + 4:
+        case 4:
             val = g->down;
             break;
         default:
+            val = 0;
             break;
     }
 
@@ -647,11 +651,13 @@ static uint32_t pcihotplug_read(void *op
 static void pcihotplug_write(void *opaque, uint32_t addr, uint32_t val)
 {
     struct pci_status *g = opaque;
-    switch (addr) {
-        case PCI_BASE:
+    uint32_t offset = addr - g->base;
+
+    switch (offset) {
+        case 0:
             g->up = val;
             break;
-        case PCI_BASE + 4:
+        case 4:
             g->down = val;
             break;
    }
@@ -671,9 +677,13 @@ static uint32_t pciej_read(void *opaque,
 
 static void pciej_write(void *opaque, uint32_t addr, uint32_t val)
 {
-    int slot = ffs(val) - 1;
+    struct pci_status *g = opaque;
+    int slot, bus;
 
-    device_hot_remove_success(0, slot);
+    bus = (g->base - PCI_BASE) / 12;
+    slot = ffs(val) - 1;
+
+    device_hot_remove_success(bus, slot);
 
 #if defined(DEBUG)
     printf("pciej write %lx <== %d\n", addr, val);
@@ -684,17 +694,25 @@ static const char *model;
 
 void qemu_system_hot_add_init(const char *cpu_model)
 {
+    int i;
+
     register_ioport_write(GPE_BASE, 4, 1, gpe_writeb, &gpe);
     register_ioport_read(GPE_BASE, 4, 1,  gpe_readb, &gpe);
 
     register_ioport_write(PROC_BASE, 4, 1, gpe_writeb, &gpe);
     register_ioport_read(PROC_BASE, 4, 1,  gpe_readb, &gpe);
 
-    register_ioport_write(PCI_BASE, 8, 4, pcihotplug_write, &pci0_status);
-    register_ioport_read(PCI_BASE, 8, 4,  pcihotplug_read, &pci0_status);
+    for (i = 0; i < 4; i++) {
+        struct pci_status *pci_status = &pci_bus_status[i];
+        unsigned long base = PCI_BASE + (i*12);
+
+        pci_status->base = base;
+        register_ioport_write(base, 8, 4, pcihotplug_write, pci_status);
+        register_ioport_read(base, 8, 4,  pcihotplug_read, pci_status);
+        register_ioport_write(base+8, 4, 4, pciej_write, pci_status);
+        register_ioport_read(base+8, 4, 4,  pciej_read, pci_status);
+    }
 
-    register_ioport_write(PCI_EJ_BASE, 4, 4, pciej_write, NULL);
-    register_ioport_read(PCI_EJ_BASE, 4, 4,  pciej_read, NULL);
 
     model = cpu_model;
 }
@@ -740,28 +758,34 @@ void qemu_system_cpu_hot_add(int cpu, in
 }
 #endif
 
-static void enable_device(struct pci_status *p, struct gpe_regs *g, int slot)
+static void enable_device(struct pci_status *p, struct gpe_regs *g, int bus, int slot)
 {
-    g->sts |= 2;
-    g->en |= 2;
+    int gpe_bit = (1 << (bus+1));
+
+    g->sts |= gpe_bit;
+    g->en |= gpe_bit;
     p->up |= (1 << slot);
 }
 
-static void disable_device(struct pci_status *p, struct gpe_regs *g, int slot)
+static void disable_device(struct pci_status *p, struct gpe_regs *g, int bus, int slot)
 {
-    g->sts |= 2;
-    g->en |= 2;
+    int gpe_bit = (1 << (bus+1));
+
+    g->sts |= gpe_bit;
+    g->en |= gpe_bit;
     p->down |= (1 << slot);
 }
 
 void qemu_system_device_hot_add(int pcibus, int slot, int state)
 {
+    struct pci_status *pci_status = &pci_bus_status[pcibus];
+
     qemu_set_irq(pm_state->irq, 1);
-    pci0_status.up = 0;
-    pci0_status.down = 0;
+    pci_status->up = 0;
+    pci_status->down = 0;
     if (state)
-        enable_device(&pci0_status, &gpe, slot);
+        enable_device(pci_status, &gpe, pcibus, slot);
     else
-        disable_device(&pci0_status, &gpe, slot);
+        disable_device(pci_status, &gpe, pcibus, slot);
     qemu_set_irq(pm_state->irq, 0);
 }

-- 


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone

  parent reply	other threads:[~2008-05-02 17:35 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-02 17:35 [patch 0/3] QEMU/KVM: add support for 128 PCI slots (v2) Marcelo Tosatti
2008-05-02 17:35 ` [patch 1/3] QEMU/KVM: add 3 PCI bridges to ACPI table Marcelo Tosatti
2008-05-03 21:03   ` Alexander Graf
2008-05-02 17:35 ` Marcelo Tosatti [this message]
2008-05-02 17:35 ` [patch 3/3] QEMU/KVM: add 3 PCI bridges Marcelo Tosatti
2008-05-04  7:56 ` [patch 0/3] QEMU/KVM: add support for 128 PCI slots (v2) Avi Kivity
2008-05-05 22:40   ` Alexander Graf
2008-05-06 10:14     ` Avi Kivity
2008-05-05 22:53   ` Anthony Liguori
2008-05-06 10:01     ` Avi Kivity
2008-05-05 23:16   ` Alexander Graf

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=20080502174204.558653191@localhost.localdomain \
    --to=mtosatti@redhat.com \
    --cc=agraf@suse.de \
    --cc=avi@qumranet.com \
    --cc=kvm-devel@lists.sourceforge.net \
    /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