Skip to contentSkip to conversation

pciinit: Enable default VGA device

PATCH In review Alex Williamson 4 participants 5 messages Mar 20, 2013 – Mar 23, 2013

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 pciinit: Enable default VGA device

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.

---

v3: use pci_config_maskw() to trim out some code
v2: move to qemu specific pciinit.c

 src/optionroms.c |    2 +-
 src/pciinit.c    |   40 ++++++++++++++++++++++++++++++++++++++++
 src/util.h       |    1 +
 3 files changed, 42 insertions(+), 1 deletion(-)
src/optionroms.c +1 -1
index caa2151..ac92613 100644
@@ -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)
src/pciinit.c +40 -0
index ce0a4cc..bb9355f 100644
@@ -316,6 +316,44 @@ 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));
+
+    pci_config_maskw(pci->bdf, PCI_COMMAND, 0,
+                     PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
+
+    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));
+
+        pci_config_maskw(pci->bdf, PCI_BRIDGE_CONTROL, 0, PCI_BRIDGE_CTL_VGA);
+        pci_config_maskw(pci->bdf, PCI_COMMAND, 0,
+                         PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
+    }
+}
 
 /****************************************************************
  * Platform device initialization
@@ -804,4 +842,6 @@ pci_setup(void)
     pci_bios_init_devices();
 
     free(busses);
+
+    pci_enable_default_vga();
 }
src/util.h +1 -0
index af029fc..99aff78 100644
@@ -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);
Acked-by on v3 1/1
#1 lore raw

Dear Alex,

Am Mittwoch, den 20.03.2013, 10:58 -0600 schrieb Alex Williamson:

Quoted 1 line

As QEMU gains PCI bridge and PCIe root port support,

could you give a commit or version for QEMU please.

Quoted 3 lines

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.

Just to be sure, did you test this with older QEMU too?

Quoted 31 lines

---

v3: use pci_config_maskw() to trim out some code
v2: move to qemu specific pciinit.c

 src/optionroms.c |    2 +-
 src/pciinit.c    |   40 ++++++++++++++++++++++++++++++++++++++++
 src/util.h       |    1 +
 3 files changed, 42 insertions(+), 1 deletion(-)
src/optionroms.c +1 -1
index caa2151..ac92613 100644
@@ -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)
src/pciinit.c +0 -0
index ce0a4cc..bb9355f 100644
@@ -316,6 +316,44 @@ static void pci_bios_init_devices(void)
     }
 }

src/pciinit.c static void pci_bios_init_devices(void) · line 327

Quoted 10 lines
src/pciinit.c +9 -0
 
+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));

As this is used several times, a function returning a string with %02x:% 02x.%x would be handy.

Quoted 3 lines
src/pciinit.c +3 -0
+            return;
+        }
+    }

[…]

Thahks,

Paul

#2 lore raw
Quoted 7 lines · Paul Menzel

Dear Alex,

Am Mittwoch, den 20.03.2013, 10:58 -0600 schrieb Alex Williamson:

Quoted 1 line

As QEMU gains PCI bridge and PCIe root port support,

could you give a commit or version for QEMU please.

This would be targeted towards QEMU 1.5. Michael recently sent a pull request with this patch to enable VGA routing in bridges:

https://git.kernel.org/cgit/virt/kvm/mst/qemu.git/commit/?h=pci&id=e475aeac3e2e7f6632c3ea7e83f4431c0ba3a467

It's difficult to make use of without an assigned VGA device, which I plan to start posting soon.

Quoted 5 lines
Quoted 3 lines

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.

Just to be sure, did you test this with older QEMU too?

Yes, it works with the QEMU 1.2.x shipped in F18. Any existing QEMU configuration is going to have the VGA device on the host bridge and therefore bail out on the first loop, having done nothing other than add a debug print.

Quoted 45 lines
Quoted 31 lines

---

v3: use pci_config_maskw() to trim out some code
v2: move to qemu specific pciinit.c

 src/optionroms.c |    2 +-
 src/pciinit.c    |   40 ++++++++++++++++++++++++++++++++++++++++
 src/util.h       |    1 +
 3 files changed, 42 insertions(+), 1 deletion(-)
src/optionroms.c +1 -1
index caa2151..ac92613 100644
@@ -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)
src/pciinit.c +0 -0
index ce0a4cc..bb9355f 100644
@@ -316,6 +316,44 @@ static void pci_bios_init_devices(void)
     }
 }

src/pciinit.c static void pci_bios_init_devices(void) · line 327

Quoted 10 lines
src/pciinit.c +9 -0
 
+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));

As this is used several times, a function returning a string with %02x:% 02x.%x would be handy.

Quoted 7 lines
Quoted 3 lines
src/pciinit.c +3 -0
+            return;
+        }
+    }

[…]

Thanks!

Alex

#3 lore raw
In reply to Alex Williamson
Quoted 6 lines · Alex Williamson

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.

Looks good to me.

cheers,
Gerd

#4 lore raw
In reply to Alex Williamson
Quoted 6 lines · Alex Williamson

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 pushed this change.

-Kevin