# EFI, KMS, vfio - selecting GPU for framebuffer console

## manwe_

Hi *.

Recently I've switched to EFI and KMS (from BIOS and "nomodeset"). Everything is working fine on one PC (AMD GPU) and laptop (Intel GPU), but second PC (Intel + nVidia) is giving me a headache. 

On that PC, Gentoo should be using Intel GPU, while nVidia is passed to vfio for Windows under Qemu/KVM. Of course UEFI/BIOS is configured to use Intel GPU as the default one. And while it used to work fine with BIOS and "nomodeset", on EFI+KMS, kernel is ignoring this setting and for 80% of the time is trying to boot on with nVidia as a primary display. Then in a second it tries to pass it to vfio and freezes. 

So I had to restart over and over and hope this time it will draw Intel GPU as the main one. Kinda annoying. Sometimes it took up to 6 tries. I've found one thread on Arch forum about this, and the only solution then was to try "fbcon=map:1". This, according to fbcon documentaction, disables the console. 

But again, there's a problem. PC is turned on, somehow on the first boot "fbcon=map:1" is ignored by the kernel, system starts with the console on Intel GPU, but fails to run X. This is what Xorg.0.log says:

```
[    14.256] (II) LoadModule: "intel"

[    14.256] (II) Loading /usr/lib64/xorg/modules/drivers/intel_drv.so

[    14.259] (II) Module intel: vendor="X.Org Foundation"

[    14.259]    compiled for 1.18.4, module version = 2.99.917

[    14.259]    Module class: X.Org Video Driver

[    14.259]    ABI class: X.Org Video Driver, version 20.0

[    14.259] (II) LoadModule: "nouveau"

[    14.259] (WW) Warning, couldn't open module nouveau

[    14.259] (II) UnloadModule: "nouveau"

[    14.259] (II) Unloading nouveau

[    14.259] (EE) Failed to load module "nouveau" (module does not exist, 0)

[    14.259] (II) LoadModule: "nv"

[    14.259] (WW) Warning, couldn't open module nv

[    14.259] (II) UnloadModule: "nv"

[    14.259] (II) Unloading nv

[    14.259] (EE) Failed to load module "nv" (module does not exist, 0)

[    14.259] (II) LoadModule: "modesetting"

[    14.259] (II) Loading /usr/lib64/xorg/modules/drivers/modesetting_drv.so

[    14.260] (II) Module modesetting: vendor="X.Org Foundation"

[    14.260]    compiled for 1.18.4, module version = 1.18.4

[    14.260]    Module class: X.Org Video Driver

[    14.260]    ABI class: X.Org Video Driver, version 20.0

[    14.260] (II) LoadModule: "fbdev"

[    14.260] (WW) Warning, couldn't open module fbdev

[    14.260] (II) UnloadModule: "fbdev"

[    14.260] (II) Unloading fbdev

[    14.260] (EE) Failed to load module "fbdev" (module does not exist, 0)

[    14.260] (II) LoadModule: "vesa"

[    14.260] (WW) Warning, couldn't open module vesa

[    14.260] (II) UnloadModule: "vesa"

[    14.260] (II) Unloading vesa

[    14.260] (EE) Failed to load module "vesa" (module does not exist, 0)

[    14.260] (II) intel: Driver for Intel(R) Integrated Graphics Chipsets:

        i810, i810-dc100, i810e, i815, i830M, 845G, 854, 852GM/855GM, 865G,

        915G, E7221 (i915), 915GM, 945G, 945GM, 945GME, Pineview GM,

        Pineview G, 965G, G35, 965Q, 946GZ, 965GM, 965GME/GLE, G33, Q35, Q33,

        GM45, 4 Series, G45/G43, Q45/Q43, G41, B43

[    14.260] (II) intel: Driver for Intel(R) HD Graphics: 2000-6000

[    14.260] (II) intel: Driver for Intel(R) Iris(TM) Graphics: 5100, 6100

[    14.260] (II) intel: Driver for Intel(R) Iris(TM) Pro Graphics: 5200, 6200, P6300

[    14.260] (II) modesetting: Driver for Modesetting Kernel Drivers: kms

[    14.260] (--) using VT number 7

[    14.263] (II) intel(G0): Using Kernel Mode Setting driver: i915, version 1.6.0 20160425

[    14.264] (WW) Falling back to old probe method for modesetting

[    14.264] (EE) Screen 0 deleted because of no matching config section.

[    14.264] (II) UnloadModule: "modesetting"

[    14.264] (EE) Device(s) detected, but none match those in the config file.

[    14.264] (EE) 

Fatal server error:

[    14.264] (EE) no screens found(EE) 

```

After that I have to reboot and this time "fbcon=map:1" works. I have no framebuffer console, but system boots and X starts. I even made myself a script for those condition ("no screens found" + small uptime) to just execute /sbin/reboot. 

Any idea how to force kernel to use Intel GPU for KMS/framebuffer and completly ignore nVidia as a possible display? Drivers for nVidia are not in the kernel, there are no modules except for virtualbox:

```
# CONFIG_DRM_NOUVEAU is not set

# CONFIG_FB_NVIDIA is not set

```

----------

## zino

You might have to create an Xorg config file to tell X which card to use by specifying the BusID of your Intel GPU. Here's what I use for my radeon card in order to give you an idea of what I mean:

```
Section   "Device"

   Identifier   "Device0"

   Driver      "radeon"

   Option      "DRI3"            "on"

   Option      "ColorTiling2D"      "True"

   Option       "AccelMethod"       "glamor"

   VendorName   "AMD"

   BusID      "PCI:5:0:0"

   Screen      0

EndSection
```

As for telling the kernel to ignore the Nvdia card  altogether: Is vfio_pci a module or builtin in your kernel config? (Builtin is preferred, imho.) Additionally you could also give pci_stub a try instead. In my experience pci_stub seems to load earlier in the boot process than vfio_pci.

----------

## hceline

My solution to the same kind of problem was compiling pci-stub and vfio-pci into the kernel and and binding the cards destined for Qemu from kernel-commandline.

vfio-pci will probably do, the only one I needed pci-stub for was the sata-card as the kernel insists on starting ahci before vfio-pci.

----------

