Patchwork [RESEND,v2] pciinit: Enable default VGA device

login
register
mail settings
Submitter Alex Williamson
Date March 19, 2013, 3:07 a.m.
Message ID <20130319030657.14697.64825.stgit@bling.home>
Download mbox | patch
Permalink /patch/228909/
State New
Headers show

Comments

Alex Williamson - March 19, 2013, 3:07 a.m.
As QEMU gains PCI bridge and PCIe root port support, we won't always
find the VGA device on the root bus.  We therefore need to add support
to find and enable a VGA device and the path to it through the VGA
Enable support in the PCI bridge control register.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
 src/optionroms.c |    2 +-
 src/pciinit.c    |   45 +++++++++++++++++++++++++++++++++++++++++++++
 src/util.h       |    1 +
 3 files changed, 47 insertions(+), 1 deletion(-)
Kevin O'Connor - March 19, 2013, 11:08 p.m.
On Mon, Mar 18, 2013 at 09:07:21PM -0600, Alex Williamson wrote:
> As QEMU gains PCI bridge and PCIe root port support, we won't always
> find the VGA device on the root bus.  We therefore need to add support
> to find and enable a VGA device and the path to it through the VGA
> Enable support in the PCI bridge control register.

Thanks.  I'm okay with the change.  It would be nice if someone more
familiar with the QEMU side could ack this patch.

As a minor nitpick - there is a pci_config_maskw() that would simplify
your code.

-Kevin
Alex Williamson - March 20, 2013, 4:52 a.m.
On Tue, 2013-03-19 at 19:08 -0400, Kevin O'Connor wrote:
> On Mon, Mar 18, 2013 at 09:07:21PM -0600, Alex Williamson wrote:
> > As QEMU gains PCI bridge and PCIe root port support, we won't always
> > find the VGA device on the root bus.  We therefore need to add support
> > to find and enable a VGA device and the path to it through the VGA
> > Enable support in the PCI bridge control register.
> 
> Thanks.  I'm okay with the change.  It would be nice if someone more
> familiar with the QEMU side could ack this patch.
> 
> As a minor nitpick - there is a pci_config_maskw() that would simplify
> your code.

Ah, that does clean it up a bit.  Actually, hold off on this patch.  I'm
getting VGA routing setup as I expect, but guests are not happy with the
other apertures on the bridges and I'm not sure if I'm contributing to
that problem yet.  Thanks,

Alex
Alex Williamson - March 20, 2013, 5:45 a.m.
On Tue, 2013-03-19 at 22:52 -0600, Alex Williamson wrote:
> On Tue, 2013-03-19 at 19:08 -0400, Kevin O'Connor wrote:
> > On Mon, Mar 18, 2013 at 09:07:21PM -0600, Alex Williamson wrote:
> > > As QEMU gains PCI bridge and PCIe root port support, we won't always
> > > find the VGA device on the root bus.  We therefore need to add support
> > > to find and enable a VGA device and the path to it through the VGA
> > > Enable support in the PCI bridge control register.
> > 
> > Thanks.  I'm okay with the change.  It would be nice if someone more
> > familiar with the QEMU side could ack this patch.
> > 
> > As a minor nitpick - there is a pci_config_maskw() that would simplify
> > your code.
> 
> Ah, that does clean it up a bit.  Actually, hold off on this patch.  I'm
> getting VGA routing setup as I expect, but guests are not happy with the
> other apertures on the bridges and I'm not sure if I'm contributing to
> that problem yet.  Thanks,

Turns out it's this:

commit 76e58028d28e78431f9de3cee0b3c88d807fa39d
Author: Kevin O'Connor <kevin@koconnor.net>
Date:   Wed Mar 6 21:50:09 2013 -0500

    acpi: Eliminate BDAT parameter passing to DSDT code.
    
    The "BDAT" construct is the only ACPI mechanism that relies on SeaBIOS
    reserved memory.  Replace it with the SSDT based template system.
    
    Signed-off-by: Kevin O'Connor <kevin@koconnor.net>

I'll look at it more tomorrow, I should already be asleep by now.  When
I boot a linux guest on qemu with a device behind a bridge I see "no
compatible bridge window for <range>" messages and the apertures get
de-programmed.  So I think the VGA patch here still works, but it's kind
of useless as only the VGA ranges get routed and we can't even get to
VESA modes because of the apertures getting shutdown.  Thanks,

Alex
Gerd Hoffmann - March 20, 2013, 7:17 a.m.
Hi,

> Turns out it's this:
> 
> commit 76e58028d28e78431f9de3cee0b3c88d807fa39d
> Author: Kevin O'Connor <kevin@koconnor.net>
> Date:   Wed Mar 6 21:50:09 2013 -0500
> 
>     acpi: Eliminate BDAT parameter passing to DSDT code.
>     
>     The "BDAT" construct is the only ACPI mechanism that relies on SeaBIOS
>     reserved memory.  Replace it with the SSDT based template system.
>     
>     Signed-off-by: Kevin O'Connor <kevin@koconnor.net>

That is most likely dsdt + bios.bin not being in sync.  Simply using
'qemu -bios /path/to/seabios/out/bios.bin' doesn't fly due to qemu using
a non-matching dsdt then.

With qemu/master you can just use 'qemu -L /path/to/seabios/out' instead
and qemu will pick up both bios.bin and dsdt from the fresh seabios
build directory then (and anything else it doesn't find there from the
default locations).

HTH,
  Gerd
Alex Williamson - March 20, 2013, 4:18 p.m.
On Wed, 2013-03-20 at 08:17 +0100, Gerd Hoffmann wrote:
>   Hi,
> 
> > Turns out it's this:
> > 
> > commit 76e58028d28e78431f9de3cee0b3c88d807fa39d
> > Author: Kevin O'Connor <kevin@koconnor.net>
> > Date:   Wed Mar 6 21:50:09 2013 -0500
> > 
> >     acpi: Eliminate BDAT parameter passing to DSDT code.
> >     
> >     The "BDAT" construct is the only ACPI mechanism that relies on SeaBIOS
> >     reserved memory.  Replace it with the SSDT based template system.
> >     
> >     Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
> 
> That is most likely dsdt + bios.bin not being in sync.  Simply using
> 'qemu -bios /path/to/seabios/out/bios.bin' doesn't fly due to qemu using
> a non-matching dsdt then.
> 
> With qemu/master you can just use 'qemu -L /path/to/seabios/out' instead
> and qemu will pick up both bios.bin and dsdt from the fresh seabios
> build directory then (and anything else it doesn't find there from the
> default locations).

Thanks, yes that's it.  QEMU only seems to look in the -L path or the
current directory for the missing files, so it's a bit messy but works.
I'll just go ahead and roll a v3 of the VGA patch that converts to wmask
since I'm muddied the waters on v2 here.  Thanks,

Alex
Gerd Hoffmann - March 20, 2013, 4:46 p.m.
Hi,

>> With qemu/master you can just use 'qemu -L /path/to/seabios/out' instead
>> and qemu will pick up both bios.bin and dsdt from the fresh seabios
>> build directory then (and anything else it doesn't find there from the
>> default locations).
> 
> Thanks, yes that's it.  QEMU only seems to look in the -L path or the
> current directory for the missing files, so it's a bit messy but works.

You can specify -L multiple times now (master only, not in 1.4.0) and
create a search path that way.

HTH,
  Gerd
Alex Williamson - March 20, 2013, 4:55 p.m.
On Wed, 2013-03-20 at 17:46 +0100, Gerd Hoffmann wrote:
>   Hi,
> 
> >> With qemu/master you can just use 'qemu -L /path/to/seabios/out' instead
> >> and qemu will pick up both bios.bin and dsdt from the fresh seabios
> >> build directory then (and anything else it doesn't find there from the
> >> default locations).
> > 
> > Thanks, yes that's it.  QEMU only seems to look in the -L path or the
> > current directory for the missing files, so it's a bit messy but works.
> 
> You can specify -L multiple times now (master only, not in 1.4.0) and
> create a search path that way.

Awesome.  Thanks

Patch

diff --git a/src/optionroms.c b/src/optionroms.c
index caa2151..ac92613 100644
--- a/src/optionroms.c
+++ b/src/optionroms.c
@@ -213,7 +213,7 @@  run_file_roms(const char *prefix, int isvga, u64 *sources)
  ****************************************************************/
 
 // Verify device is a vga device with legacy address decoding enabled.
-static int
+int
 is_pci_vga(struct pci_device *pci)
 {
     if (pci->class != PCI_CLASS_DISPLAY_VGA)
diff --git a/src/pciinit.c b/src/pciinit.c
index ce0a4cc..eb49a76 100644
--- a/src/pciinit.c
+++ b/src/pciinit.c
@@ -316,6 +316,49 @@  static void pci_bios_init_devices(void)
     }
 }
 
+static void pci_enable_default_vga(void)
+{
+    struct pci_device *pci;
+
+    foreachpci(pci) {
+        if (is_pci_vga(pci)) {
+            dprintf(1, "PCI: Using %02x:%02x.%x for primary VGA\n",
+                    pci_bdf_to_bus(pci->bdf), pci_bdf_to_dev(pci->bdf),
+                    pci_bdf_to_fn(pci->bdf));
+            return;
+        }
+    }
+
+    pci = pci_find_class(PCI_CLASS_DISPLAY_VGA);
+    if (!pci) {
+        dprintf(1, "PCI: No VGA devices found\n");
+        return;
+    }
+
+    dprintf(1, "PCI: Enabling %02x:%02x.%x for primary VGA\n",
+            pci_bdf_to_bus(pci->bdf), pci_bdf_to_dev(pci->bdf),
+            pci_bdf_to_fn(pci->bdf));
+
+    u16 cmd = pci_config_readw(pci->bdf, PCI_COMMAND);
+    cmd |= PCI_COMMAND_IO | PCI_COMMAND_MEMORY;
+    pci_config_writew(pci->bdf, PCI_COMMAND, cmd);
+
+    while (pci->parent) {
+        pci = pci->parent;
+
+        dprintf(1, "PCI: Setting VGA enable on bridge %02x:%02x.%x\n",
+                pci_bdf_to_bus(pci->bdf), pci_bdf_to_dev(pci->bdf),
+                pci_bdf_to_fn(pci->bdf));
+
+        u8 ctrl = pci_config_readb(pci->bdf, PCI_BRIDGE_CONTROL);
+        ctrl |= PCI_BRIDGE_CTL_VGA;
+        pci_config_writeb(pci->bdf, PCI_BRIDGE_CONTROL, ctrl);
+
+        u16 cmd = pci_config_readw(pci->bdf, PCI_COMMAND);
+        cmd |= PCI_COMMAND_IO | PCI_COMMAND_MEMORY;
+        pci_config_writew(pci->bdf, PCI_COMMAND, cmd);
+    }
+}
 
 /****************************************************************
  * Platform device initialization
@@ -804,4 +847,6 @@  pci_setup(void)
     pci_bios_init_devices();
 
     free(busses);
+
+    pci_enable_default_vga();
 }
diff --git a/src/util.h b/src/util.h
index af029fc..99aff78 100644
--- a/src/util.h
+++ b/src/util.h
@@ -344,6 +344,7 @@  void vgahook_setup(struct pci_device *pci);
 
 // optionroms.c
 void call_bcv(u16 seg, u16 ip);
+int is_pci_vga(struct pci_device *pci);
 void optionrom_setup(void);
 void vgarom_setup(void);
 void s3_resume_vga(void);