qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: marcel.a@redhat.com
Cc: Gal Hammer <ghammer@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	"seabios@seabios.org" <seabios@seabios.org>,
	qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] piix: do not reset APIC base address (0x80) on piix4_reset.
Date: Thu, 19 Dec 2013 12:35:48 +0200	[thread overview]
Message-ID: <20131219103548.GA7976@redhat.com> (raw)
In-Reply-To: <1387446561.28892.8.camel@localhost.localdomain>

On Thu, Dec 19, 2013 at 11:49:21AM +0200, Marcel Apfelbaum wrote:
> > > Basically something like the below (warning: completely untested,
> > > sorry).
> > I tested and it works fine for both windows and linux guests!
> Actually it doesn't work :(
> I was testing a "working hack", not the master branch.
> I still think it is the right direction.
> 
> Thanks,
> Marcel

Actually in hindsight there's no chance this can work:
it assumes device memory is mapped already.
I really meant just calling pci_init_device.
Maybe something like the below, or maybe we
even need a separate table for resume callbacks.

---

diff --git a/src/hw/pci.h b/src/hw/pci.h
index 9c7351d..a64f7c5 100644
--- a/src/hw/pci.h
+++ b/src/hw/pci.h
@@ -66,6 +66,7 @@ extern u64 pcimem64_start, pcimem64_end;
 extern struct hlist_head PCIDevices;
 extern int MaxPCIBus;
 int pci_probe_host(void);
+void pci_probe_device(int bdf, struct pci_device *dev);
 void pci_probe_devices(void);
 static inline u32 pci_classprog(struct pci_device *pci) {
     return (pci->class << 8) | pci->prog_if;
diff --git a/src/util.h b/src/util.h
index e6a6cb5..3a24dba 100644
--- a/src/util.h
+++ b/src/util.h
@@ -28,6 +28,7 @@ void boot_add_cbfs(void *data, const char *desc, int prio);
 void interactive_bootmenu(void);
 void bcv_prepboot(void);
 struct pci_device;
+void pci_bios_resume_device(struct pci_device *pci);
 int bootprio_find_pci_device(struct pci_device *pci);
 int bootprio_find_scsi_device(struct pci_device *pci, int target, int lun);
 int bootprio_find_ata_device(struct pci_device *pci, int chanid, int slave);
diff --git a/src/fw/pciinit.c b/src/fw/pciinit.c
index 34279a4..a4cedfb 100644
--- a/src/fw/pciinit.c
+++ b/src/fw/pciinit.c
@@ -293,6 +293,11 @@ static const struct pci_device_id pci_device_tbl[] = {
     PCI_DEVICE_END,
 };
 
+void pci_bios_resume_device(struct pci_device *pci)
+{
+    pci_init_device(pci_device_tbl, pci, NULL);
+}
+
 static void pci_bios_init_device(struct pci_device *pci)
 {
     u16 bdf = pci->bdf;
diff --git a/src/hw/pci.c b/src/hw/pci.c
index 6c9aa81..c2873c3 100644
--- a/src/hw/pci.c
+++ b/src/hw/pci.c
@@ -105,6 +105,24 @@ pci_probe_host(void)
     return 0;
 }
 
+void
+pci_probe_device(int bdf, struct pci_device *dev)
+{
+    dev->bdf = bdf;
+    u32 vendev = pci_config_readl(bdf, PCI_VENDOR_ID);
+    dev->vendor = vendev & 0xffff;
+    dev->device = vendev >> 16;
+    u32 classrev = pci_config_readl(bdf, PCI_CLASS_REVISION);
+    dev->class = classrev >> 16;
+    dev->prog_if = classrev >> 8;
+    dev->revision = classrev & 0xff;
+    dev->header_type = pci_config_readb(bdf, PCI_HEADER_TYPE);
+    u8 v = dev->header_type & 0x7f;
+    if (v == PCI_HEADER_TYPE_BRIDGE || v == PCI_HEADER_TYPE_CARDBUS) {
+        u8 secbus = pci_config_readb(bdf, PCI_SECONDARY_BUS);
+        dev->secondary_bus = secbus;
+    }
+}
 // Find all PCI devices and populate PCIDevices linked list.
 void
 pci_probe_devices(void)
@@ -145,21 +163,12 @@ pci_probe_devices(void)
             }
 
             // Populate pci_device info.
-            dev->bdf = bdf;
+            pci_probe_device(bdf, dev);
             dev->parent = parent;
             dev->rootbus = rootbus;
-            u32 vendev = pci_config_readl(bdf, PCI_VENDOR_ID);
-            dev->vendor = vendev & 0xffff;
-            dev->device = vendev >> 16;
-            u32 classrev = pci_config_readl(bdf, PCI_CLASS_REVISION);
-            dev->class = classrev >> 16;
-            dev->prog_if = classrev >> 8;
-            dev->revision = classrev & 0xff;
-            dev->header_type = pci_config_readb(bdf, PCI_HEADER_TYPE);
             u8 v = dev->header_type & 0x7f;
             if (v == PCI_HEADER_TYPE_BRIDGE || v == PCI_HEADER_TYPE_CARDBUS) {
-                u8 secbus = pci_config_readb(bdf, PCI_SECONDARY_BUS);
-                dev->secondary_bus = secbus;
+                u8 secbus = dev->secondary_bus;
                 if (secbus > bus && !busdevs[secbus])
                     busdevs[secbus] = dev;
                 if (secbus > MaxPCIBus)
diff --git a/src/resume.c b/src/resume.c
index fc2fee9..9aac853 100644
--- a/src/resume.c
+++ b/src/resume.c
@@ -101,6 +101,14 @@ s3_resume(void)
     pic_setup();
     smm_setup();
 
+    int bdf;
+    foreachbdf(bdf, 0) {
+        // Create new pci_device struct and add to list.
+        struct pci_device pci;
+        pci_probe_device(bdf, &pci);
+        pci_bios_resume_device(&pci);
+    }
+
     s3_resume_vga();
 
     make_bios_readonly();

  reply	other threads:[~2013-12-19 10:32 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-11  9:21 [Qemu-devel] [PATCH] piix: do not reset APIC base address (0x80) on piix4_reset Gal Hammer
2013-12-11 10:23 ` Paolo Bonzini
2013-12-11 10:44   ` Michael S. Tsirkin
2013-12-11 11:04     ` Gal Hammer
2013-12-18 14:19       ` Paolo Bonzini
2013-12-18 15:16         ` Gal Hammer
2013-12-18 21:57         ` Laszlo Ersek
2013-12-18 14:22 ` Paolo Bonzini
2013-12-18 15:22   ` Michael S. Tsirkin
2013-12-18 16:27     ` Marcel Apfelbaum
2013-12-18 16:33       ` Michael S. Tsirkin
2013-12-18 16:34         ` Paolo Bonzini
2013-12-18 16:55           ` Marcel Apfelbaum
2013-12-18 17:21             ` Michael S. Tsirkin
2013-12-19 16:06             ` Kevin O'Connor
2013-12-19 18:03               ` Marcel Apfelbaum
2013-12-19 18:17                 ` Kevin O'Connor
2013-12-18 16:58           ` Michael S. Tsirkin
2013-12-18 22:10           ` Laszlo Ersek
2013-12-18 22:16             ` Laszlo Ersek
2013-12-18 23:43             ` Paolo Bonzini
2013-12-18 16:49         ` Marcel Apfelbaum
2013-12-18 17:20           ` Michael S. Tsirkin
2013-12-19  9:37             ` Marcel Apfelbaum
2013-12-19  9:49               ` Marcel Apfelbaum
2013-12-19 10:35                 ` Michael S. Tsirkin [this message]
2013-12-18 15:59   ` Gal Hammer
2013-12-18 16:00     ` Paolo Bonzini

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=20131219103548.GA7976@redhat.com \
    --to=mst@redhat.com \
    --cc=ghammer@redhat.com \
    --cc=marcel.a@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=seabios@seabios.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).