[SeaBIOS] [PATCH 1/6] pci, optionrom: enable non-vga display devices

Gerd Hoffmann posted 6 patches 6 years, 11 months ago
There is a newer version of this series
[SeaBIOS] [PATCH 1/6] pci, optionrom: enable non-vga display devices
Posted by Gerd Hoffmann 6 years, 11 months ago
In case no VGA device was found look for other display devices,
in both pci initialization and in vgabios rom scan.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 src/fw/pciinit.c | 15 +++++++++++----
 src/optionroms.c | 29 ++++++++++++++++++++++++++++-
 2 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/src/fw/pciinit.c b/src/fw/pciinit.c
index 3a2f747984..e9518741b5 100644
--- a/src/fw/pciinit.c
+++ b/src/fw/pciinit.c
@@ -431,6 +431,7 @@ static void pci_bios_init_devices(void)
 static void pci_enable_default_vga(void)
 {
     struct pci_device *pci;
+    int is_vga = 1;
 
     foreachpci(pci) {
         if (is_pci_vga(pci)) {
@@ -441,16 +442,22 @@ static void pci_enable_default_vga(void)
 
     pci = pci_find_class(PCI_CLASS_DISPLAY_VGA);
     if (!pci) {
-        dprintf(1, "PCI: No VGA devices found\n");
-        return;
+        dprintf(1, "PCI: No VGA devices found, trying other display devices\n");
+        pci = pci_find_class(PCI_CLASS_DISPLAY_OTHER);
+        if (!pci) {
+            dprintf(1, "PCI: No other display devices found\n");
+            return;
+        }
+        is_vga = 0;
     }
 
-    dprintf(1, "PCI: Enabling %pP for primary VGA\n", pci);
+    dprintf(1, "PCI: Enabling %pP for primary %s\n", pci
+            , is_vga ? "VGA" : "display");
 
     pci_config_maskw(pci->bdf, PCI_COMMAND, 0,
                      PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
 
-    while (pci->parent) {
+    while (is_vga && pci->parent) {
         pci = pci->parent;
 
         dprintf(1, "PCI: Setting VGA enable on bridge %pP\n", pci);
diff --git a/src/optionroms.c b/src/optionroms.c
index 092393a56c..7febd7fcf8 100644
--- a/src/optionroms.c
+++ b/src/optionroms.c
@@ -224,6 +224,17 @@ is_pci_vga(struct pci_device *pci)
     return 1;
 }
 
+int
+is_pci_display_other(struct pci_device *pci)
+{
+    if (pci->class != PCI_CLASS_DISPLAY_OTHER)
+        return 0;
+    u16 cmd = pci_config_readw(pci->bdf, PCI_COMMAND);
+    if (!(cmd & PCI_COMMAND_IO && cmd & PCI_COMMAND_MEMORY))
+        return 0;
+    return 1;
+}
+
 // Copy a rom to its permanent location below 1MiB
 static struct rom_header *
 copy_rom(struct rom_header *rom)
@@ -350,7 +361,9 @@ optionrom_setup(void)
     // Find and deploy PCI roms.
     struct pci_device *pci;
     foreachpci(pci) {
-        if (pci->class == PCI_CLASS_DISPLAY_VGA || pci->have_driver)
+        if (pci->class == PCI_CLASS_DISPLAY_VGA ||
+            pci->class == PCI_CLASS_DISPLAY_OTHER ||
+            pci->have_driver)
             continue;
         init_pcirom(pci, 0, sources);
     }
@@ -404,6 +417,8 @@ struct rom_header *VgaROM;
 void
 vgarom_setup(void)
 {
+    int have_vga = 0;
+
     if (! CONFIG_OPTIONROMS)
         return;
 
@@ -425,8 +440,20 @@ vgarom_setup(void)
             continue;
         vgahook_setup(pci);
         init_pcirom(pci, 1, NULL);
+        have_vga = 1;
         break;
     }
+    if (!have_vga) {
+        // no VGA, try fallback to display
+        dprintf(1, "no vga, try display\n");
+        foreachpci(pci) {
+            if (!is_pci_display_other(pci))
+                continue;
+            vgahook_setup(pci);
+            init_pcirom(pci, 1, NULL);
+            break;
+        }
+    }
 
     // Find and deploy CBFS vga-style roms not associated with a device.
     run_file_roms("vgaroms/", 1, NULL);
-- 
2.9.3


_______________________________________________
SeaBIOS mailing list
SeaBIOS@seabios.org
https://mail.coreboot.org/mailman/listinfo/seabios
Re: [SeaBIOS] [PATCH 1/6] pci, optionrom: enable non-vga display devices
Posted by Kevin O'Connor 6 years, 11 months ago
On Thu, May 31, 2018 at 08:33:48AM +0200, Gerd Hoffmann wrote:
> In case no VGA device was found look for other display devices,
> in both pci initialization and in vgabios rom scan.
> 
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  src/fw/pciinit.c | 15 +++++++++++----
>  src/optionroms.c | 29 ++++++++++++++++++++++++++++-
>  2 files changed, 39 insertions(+), 5 deletions(-)
> 
> diff --git a/src/fw/pciinit.c b/src/fw/pciinit.c
> index 3a2f747984..e9518741b5 100644
> --- a/src/fw/pciinit.c
> +++ b/src/fw/pciinit.c
> @@ -431,6 +431,7 @@ static void pci_bios_init_devices(void)
>  static void pci_enable_default_vga(void)
>  {
>      struct pci_device *pci;
> +    int is_vga = 1;
>  
>      foreachpci(pci) {
>          if (is_pci_vga(pci)) {
> @@ -441,16 +442,22 @@ static void pci_enable_default_vga(void)
>  
>      pci = pci_find_class(PCI_CLASS_DISPLAY_VGA);
>      if (!pci) {
> -        dprintf(1, "PCI: No VGA devices found\n");
> -        return;
> +        dprintf(1, "PCI: No VGA devices found, trying other display devices\n");
> +        pci = pci_find_class(PCI_CLASS_DISPLAY_OTHER);
> +        if (!pci) {
> +            dprintf(1, "PCI: No other display devices found\n");
> +            return;
> +        }
> +        is_vga = 0;
>      }
>  
> -    dprintf(1, "PCI: Enabling %pP for primary VGA\n", pci);
> +    dprintf(1, "PCI: Enabling %pP for primary %s\n", pci
> +            , is_vga ? "VGA" : "display");
>  
>      pci_config_maskw(pci->bdf, PCI_COMMAND, 0,
>                       PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
>  
> -    while (pci->parent) {
> +    while (is_vga && pci->parent) {
>          pci = pci->parent;
>  
>          dprintf(1, "PCI: Setting VGA enable on bridge %pP\n", pci);
> diff --git a/src/optionroms.c b/src/optionroms.c
> index 092393a56c..7febd7fcf8 100644
> --- a/src/optionroms.c
> +++ b/src/optionroms.c
> @@ -224,6 +224,17 @@ is_pci_vga(struct pci_device *pci)
>      return 1;
>  }
>  
> +int
> +is_pci_display_other(struct pci_device *pci)
> +{
> +    if (pci->class != PCI_CLASS_DISPLAY_OTHER)
> +        return 0;
> +    u16 cmd = pci_config_readw(pci->bdf, PCI_COMMAND);
> +    if (!(cmd & PCI_COMMAND_IO && cmd & PCI_COMMAND_MEMORY))
> +        return 0;
> +    return 1;
> +}
> +
>  // Copy a rom to its permanent location below 1MiB
>  static struct rom_header *
>  copy_rom(struct rom_header *rom)
> @@ -350,7 +361,9 @@ optionrom_setup(void)
>      // Find and deploy PCI roms.
>      struct pci_device *pci;
>      foreachpci(pci) {
> -        if (pci->class == PCI_CLASS_DISPLAY_VGA || pci->have_driver)
> +        if (pci->class == PCI_CLASS_DISPLAY_VGA ||
> +            pci->class == PCI_CLASS_DISPLAY_OTHER ||
> +            pci->have_driver)
>              continue;
>          init_pcirom(pci, 0, sources);
>      }
> @@ -404,6 +417,8 @@ struct rom_header *VgaROM;
>  void
>  vgarom_setup(void)
>  {
> +    int have_vga = 0;
> +
>      if (! CONFIG_OPTIONROMS)
>          return;
>  
> @@ -425,8 +440,20 @@ vgarom_setup(void)
>              continue;
>          vgahook_setup(pci);
>          init_pcirom(pci, 1, NULL);
> +        have_vga = 1;
>          break;
>      }
> +    if (!have_vga) {
> +        // no VGA, try fallback to display
> +        dprintf(1, "no vga, try display\n");
> +        foreachpci(pci) {
> +            if (!is_pci_display_other(pci))
> +                continue;
> +            vgahook_setup(pci);
> +            init_pcirom(pci, 1, NULL);
> +            break;
> +        }
> +    }

Is the goal of this patch to bring up the display device early during
boot?  If so, do we need to change pciinit.c?  Could we instead add:
    if (!have_vga) try_setup_display_other();
here and then let that function do all the work?  The funky pciinit.c
stuff is there because on coreboot there could be multiple vga devices
in the machine and we want to choose the primary vga device, which is
the one that coreboot did the vga mapping for.

Separately, I don't think we need to call vgahook_setup() if a real
vga device wasn't found.

Thanks,
-Kevin

_______________________________________________
SeaBIOS mailing list
SeaBIOS@seabios.org
https://mail.coreboot.org/mailman/listinfo/seabios
Re: [SeaBIOS] [PATCH 1/6] pci, optionrom: enable non-vga display devices
Posted by Gerd Hoffmann 6 years, 11 months ago
> > +    if (!have_vga) {
> > +        // no VGA, try fallback to display
> > +        dprintf(1, "no vga, try display\n");
> > +        foreachpci(pci) {
> > +            if (!is_pci_display_other(pci))
> > +                continue;
> > +            vgahook_setup(pci);
> > +            init_pcirom(pci, 1, NULL);
> > +            break;
> > +        }
> > +    }
> 
> Is the goal of this patch to bring up the display device early during
> boot?

Yes.

> If so, do we need to change pciinit.c?  Could we instead add:
>     if (!have_vga) try_setup_display_other();
> here and then let that function do all the work?

The only thing the pciinit patch effectively does (beside the printk) is
setting the PCI_COMMAND register.  We could do that elsewhere.  Either
the vgabios does it itself (are roms expected to do that?), or
try_setup_display_other() does it.

> Separately, I don't think we need to call vgahook_setup() if a real
> vga device wasn't found.

Indeed.

cheers,
  Gerd


_______________________________________________
SeaBIOS mailing list
SeaBIOS@seabios.org
https://mail.coreboot.org/mailman/listinfo/seabios