Received: by 2002:ac0:de83:0:0:0:0:0 with SMTP id b3csp1242414imk; Sun, 3 Jul 2022 21:45:12 -0700 (PDT) X-Google-Smtp-Source: AGRyM1to1wVZ6AvSmp8N24HPf1ysLE2My9ybIcCCQOVOCF4NPxakhZ/qrwxnn3RY9AtscW2Wls6q X-Received: by 2002:a05:6402:5409:b0:42a:a643:4eb8 with SMTP id ev9-20020a056402540900b0042aa6434eb8mr36108357edb.71.1656909912493; Sun, 03 Jul 2022 21:45:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656909912; cv=none; d=google.com; s=arc-20160816; b=ZxvDPjcwwdQ2Skx3VNlPwSWlpgDAEEmwuQzcOXjMawDuXWP4yIKYkiszbb/hW7FQFL kE1zIHcbZc/qTtsmFSALb99Z6WhYv9wl/HUqQeE7z5A+4u26hykBT6H2/7VcGWImR+KU K+bapLaZJ7Xjs0ev6CiBpsNJ/j8atoMKdJrhMNAvU392ufSa+1/YJsCSgm782v5b7Hwq YOB4v+R7EnZBGd+XacmrnX1RTBajGMsIQQJMbfAzyYxDn/p42D7kj4CKdBReYI5ZWYJA f3RwwewVSam5fbFhT0QTJIyjGOM9Ck4PfkgzgwQ3nGuC6LJVFPATbOcPALcNVj8ekEdE idYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:subject:cc:to:from:date; bh=7Afal9IdGN6UTfF0M1R6ffga8WsYWw8d5fTDhdCRVLc=; b=dzJ82XJ/0RTbjTzUykE+u3nK5cKOQxVbaZSC4jZ6/wrRFT1xnXx67wHfbVNroucbau vc4HwBwc2u61slRK5XGHrFf5Eo9diU7AlxBvcW3Z8g6rfxHQ+GnVZ7w4MzW47qdNpKtC rFUbKLRKUcDzRQ+7PrAn9oBJm964+NayHqLNdITW7jrekHLEHSMFNmYQoX/7TBZACRjw PWiGFR21q0rNbIT2KtwmOdF4BogG1QXggDpmhABxndI9SX84+FXxsArPLXltnkAR4hH/ KrGO6SAWkBZ/iI7QIy8AI4aQ7r2w1ONnGvqYYnLRAcmRd8BcAsrzu2+Gttd+ZJrCW7kR UQOg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v9-20020a056402348900b004360d44b72dsi8639783edc.583.2022.07.03.21.44.46; Sun, 03 Jul 2022 21:45:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231605AbiGDEeK (ORCPT + 99 others); Mon, 4 Jul 2022 00:34:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229461AbiGDEeJ (ORCPT ); Mon, 4 Jul 2022 00:34:09 -0400 Received: from mx2.absolutedigital.net (mx2.absolutedigital.net [50.242.207.105]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AA24B5F55 for ; Sun, 3 Jul 2022 21:34:08 -0700 (PDT) Received: from lancer.cnet.absolutedigital.net (lancer.cnet.absolutedigital.net [10.7.5.10]) by luxor.inet.absolutedigital.net (8.14.4/8.14.4) with ESMTP id 2644XoMD017608 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Mon, 4 Jul 2022 00:33:50 -0400 Received: from localhost (localhost [127.0.0.1]) by lancer.cnet.absolutedigital.net (8.17.1/8.17.1) with ESMTPS id 2644XoDH029139 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 4 Jul 2022 00:33:50 -0400 Date: Mon, 4 Jul 2022 00:33:50 -0400 (EDT) From: Cal Peake To: Randy Dunlap cc: Kernel Mailing List , Bjorn Helgaas , Huacai Chen Subject: [PATCH] vgaarb: Add module param to allow for choosing the boot VGA device Message-ID: <29b1e2e3-8954-2516-78f2-7e57cd5b976d@absolutedigital.net> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org My first attempt at solving this problem was based on a bit of a misunderstanding of the code and, while it worked, could be much improved. This is a new attempt that creates the module parameter 'vgaarb.bootdev' that can be passed a PCI ID (e.g. 0a:00.0) that the VGA arbiter will attempt to use as the boot VGA device over any other eligible devices. If the passed ID is invalid or is an ineligible device, the arbiter will fallback to its normal method of trying to find the preferred device for the job. I've tested it thoroughly and it is working very well for me. The patch is available below for review and, if found acceptable, can be pulled via: git pull https://github.com/peake/linux.git vgaarb-2 -- Cal Peake Signed-off-by: Cal Peake diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 2522b11e593f..21ac87f4a8a9 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -6518,6 +6518,13 @@ This is actually a boot loader parameter; the value is passed to the kernel using a special protocol. + vgaarb.bootdev= [PCI] Specify the PCI ID (e.g. 0e:00.0) of the + device to use as the boot VGA device, overriding + the heuristic used to normally determine which + of the eligible VGA devices to use. If the device + specified is not valid or not eligible, then we + fallback to the heuristic. + vm_debug[=options] [KNL] Available with CONFIG_DEBUG_VM=y. May slow down system boot speed, especially when enabled on systems with a large amount of memory. diff --git a/drivers/pci/vgaarb.c b/drivers/pci/vgaarb.c index f80b6ec88dc3..d3689b7dc63d 100644 --- a/drivers/pci/vgaarb.c +++ b/drivers/pci/vgaarb.c @@ -35,6 +35,34 @@ #include +static char *bootdev __initdata; +module_param(bootdev, charp, 0); +MODULE_PARM_DESC(bootdev, "Force boot device to the specified PCI ID"); + +/* + * Initialize to the last possible ID to have things work as normal + * when no 'bootdev' option is supplied. We especially do not want + * this to be zero (0) since that is a valid PCI ID (00:00.0). + */ +static u16 bootdev_id = 0xffff; + +static void __init parse_bootdev(char *input) +{ + unsigned int bus, dev, func; + int ret; + + if (input == NULL) + return; + + ret = sscanf(input, "%x:%x.%x", &bus, &dev, &func); + if (ret != 3) { + pr_warn("Improperly formatted PCI ID: %s\n", input); + return; + } + + bootdev_id = PCI_DEVID(bus, PCI_DEVFN(dev, func)); +} + static void vga_arbiter_notify_clients(void); /* * We keep a list of all vga devices in the system to speed @@ -53,6 +81,7 @@ struct vga_device { bool bridge_has_one_vga; bool is_firmware_default; /* device selected by firmware */ unsigned int (*set_decode)(struct pci_dev *pdev, bool decode); + bool is_chosen_one; /* device specified on command line */ }; static LIST_HEAD(vga_list); @@ -605,6 +634,7 @@ static bool vga_is_boot_device(struct vga_device *vgadev) /* * We select the default VGA device in this order: + * User specified device (see module param bootdev=) * Firmware framebuffer (see vga_arb_select_default_device()) * Legacy VGA device (owns VGA_RSRC_LEGACY_MASK) * Non-legacy integrated device (see vga_arb_select_default_device()) @@ -612,6 +642,14 @@ static bool vga_is_boot_device(struct vga_device *vgadev) * Other device (see vga_arb_select_default_device()) */ + if (boot_vga && boot_vga->is_chosen_one) + return false; + + if (bootdev_id == PCI_DEVID(pdev->bus->number, pdev->devfn)) { + vgadev->is_chosen_one = true; + return true; + } + /* * We always prefer a firmware default device, so if we've already * found one, there's no need to consider vgadev. @@ -1544,6 +1582,8 @@ static int __init vga_arb_device_init(void) int rc; struct pci_dev *pdev; + parse_bootdev(bootdev); + rc = misc_register(&vga_arb_device); if (rc < 0) pr_err("error %d registering device\n", rc);