From 860df4b2b627f025b963920d085316e694135564 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Mon, 5 Sep 2022 12:48:53 +0000 Subject: [PATCH] x86: Fix interaction between consinit, device_pci_register, and drm. Leave an essay on what's going on here in both places with cross-references. PR kern/56996 --- sys/arch/x86/pci/pci_machdep.c | 31 +++++++++++++++++++++++-------- sys/arch/x86/x86/consinit.c | 9 +++++++++ 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/sys/arch/x86/pci/pci_machdep.c b/sys/arch/x86/pci/pci_machdep.c index 1029001b438e..8e2cdd5a6020 100644 --- a/sys/arch/x86/pci/pci_machdep.c +++ b/sys/arch/x86/pci/pci_machdep.c @@ -1228,14 +1228,29 @@ device_pci_register(device_t dev, void *aux) */ populate_fbinfo(dev, dict); -#if 1 && NWSDISPLAY > 0 && NGENFB > 0 - /* XXX */ - if (device_is_a(dev, "genfb")) { - prop_dictionary_set_bool(dict, "is_console", - genfb_is_console()); - } else -#endif - prop_dictionary_set_bool(dict, "is_console", true); + /* + * If the bootloader requested console=pc and + * specified a framebuffer, and if + * x86_genfb_cnattach succeeded in setting it + * up during consinit, then consinit will call + * genfb_cnattach which makes genfb_is_console + * return true. In this case, if it's the + * first genfb we've seen, we will instruct the + * genfb driver via the is_console property + * that it has been selected as the console. + * + * If not all of that happened, then consinit + * can't have selected a genfb console, so this + * device is definitely not the console. + * + * XXX What happens if there's more than one + * PCI display device, and the bootloader picks + * the second one's framebuffer as the console + * framebuffer address? Tough...but this has + * probably never worked. + */ + prop_dictionary_set_bool(dict, "is_console", + genfb_is_console()); prop_dictionary_set_bool(dict, "clear-screen", false); #if NWSDISPLAY > 0 && NGENFB > 0 diff --git a/sys/arch/x86/x86/consinit.c b/sys/arch/x86/x86/consinit.c index ea34d968d01a..a619c4ba4132 100644 --- a/sys/arch/x86/x86/consinit.c +++ b/sys/arch/x86/x86/consinit.c @@ -197,6 +197,15 @@ consinit(void) int error; #if (NGENFB > 0) if (fbinfo && fbinfo->physaddr > 0) { + /* + * If we have a framebuffer address, and + * x86_genfb_cnattach can map it, then + * genfb_cnattach causes genfb_is_console to + * later return true. device_pci_register will + * use this to set up the device properties for + * a PCI display-class device to notify it that + * it has been selected as the console. + */ if (x86_genfb_cnattach() == -1) { initted = 0; /* defer */ return;