• Bjorn Helgaas's avatar
    vgaarb: Select a default VGA device even if there's no legacy VGA · a37c0f48
    Bjorn Helgaas authored
    Daniel Axtens reported that on the HiSilicon D05 board, the VGA device is
    behind a bridge that doesn't support PCI_BRIDGE_CTL_VGA, so the VGA arbiter
    never selects it as the default, which means Xorg auto-detection doesn't
    work.
    
    VGA is a legacy PCI feature: a VGA device can respond to addresses, e.g.,
    [mem 0xa0000-0xbffff], [io 0x3b0-0x3bb], [io 0x3c0-0x3df], etc., that are
    not configurable by BARs.  Consequently, multiple VGA devices can conflict
    with each other.  The VGA arbiter avoids conflicts by ensuring that those
    legacy resources are only routed to one VGA device at a time.
    
    The arbiter identifies the "default VGA" device, i.e., a legacy VGA device
    that was used by boot firmware.  It selects the first device that:
    
      - is of PCI_CLASS_DISPLAY_VGA,
      - has both PCI_COMMAND_IO and PCI_COMMAND_MEMORY enabled, and
      - has PCI_BRIDGE_CTL_VGA set in all upstream bridges.
    
    Some systems don't have such a device.  For example, if a host bridge
    doesn't support I/O space, PCI_COMMAND_IO probably won't be enabled for any
    devices below it.  Or, as on the HiSilicon D05, the VGA device may be
    behind a bridge that doesn't support PCI_BRIDGE_CTL_VGA, so accesses to the
    legacy VGA resources will never reach the device.
    
    This patch extends the arbiter so that if it doesn't find a device that
    meets all the above criteria, it selects the first device that:
    
      - is of PCI_CLASS_DISPLAY_VGA and
      - has PCI_COMMAND_IO or PCI_COMMAND_MEMORY enabled
    
    If it doesn't find even that, it selects the first device that:
    
      - is of class PCI_CLASS_DISPLAY_VGA.
    
    Such a device may not be able to use the legacy VGA resources, but most
    drivers can operate the device without those.  Setting it as the default
    device means its "boot_vga" sysfs file will contain "1", which Xorg (via
    libpciaccess) uses to help select its default output device.
    
    This fixes Xorg auto-detection on some arm64 systems (HiSilicon D05 in
    particular; see the link below).
    
    It also replaces the powerpc fixup_vga() quirk, albeit with slightly
    different semantics: the quirk selected the first VGA device we found, and
    overrode that selection with any enabled VGA device we found.  If there
    were several enabled VGA devices, the *last* one we found would become the
    default.
    
    The code here instead selects the *first* enabled VGA device we find, and
    if none are enabled, the first VGA device we find.
    
    Link: http://lkml.kernel.org/r/20170901072744.2409-1-dja@axtens.net
    Tested-by: Daniel Axtens <dja@axtens.net>       # arm64, ppc64-qemu-tcg
    Tested-by: Zhou Wang <wangzhou1@hisilicon.com>  # D05 Hisi Hip07, Hip08
    Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
    Acked-by: default avatarArd Biesheuvel <ard.biesheuvel@linaro.org>
    Reviewed-by: default avatarDaniel Axtens <dja@axtens.net>
    Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
    Link: https://patchwork.freedesktop.org/patch/msgid/20171013034721.14630.65913.stgit@bhelgaas-glaptop.roam.corp.google.com
    a37c0f48
vgaarb.c 41.1 KB