From patchwork Wed Jul 19 02:15:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Axtens X-Patchwork-Id: 9850331 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 13C63602A7 for ; Wed, 19 Jul 2017 02:16:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F07FF28585 for ; Wed, 19 Jul 2017 02:16:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E53932859E; Wed, 19 Jul 2017 02:16:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7FC6928585 for ; Wed, 19 Jul 2017 02:16:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752070AbdGSCQQ (ORCPT ); Tue, 18 Jul 2017 22:16:16 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:36249 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751560AbdGSCQQ (ORCPT ); Tue, 18 Jul 2017 22:16:16 -0400 Received: by mail-pf0-f195.google.com with SMTP id a11so4679705pfj.3 for ; Tue, 18 Jul 2017 19:16:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=D5Gh4BL3njsbeHn5YsYxxJAwMFrOZl/kvv57GI/zamM=; b=Oa33fB0T5h4u0U9dBuKmmI2MqP3VNP9f+vmHy7o8wX9VbGU7zQ/EyfQ6ffIaAMH+Dp rB5aSKhrLJ1/6fo4bRv3APAz84i7qQZPx0LweJtbCyvsDACM2Rv/TBmlmHv49w8gPGXK OCFk1ST4ZYBSvk/oVAhN/f/LowDnHPBPgNIL4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=D5Gh4BL3njsbeHn5YsYxxJAwMFrOZl/kvv57GI/zamM=; b=DD02QhWsaUxYNGnNyvgR+etVYIWJd/v+fp/9pcmCgWqoamXuxr9ohRFKZOl6joINPy ThwmfigfpVtDQWlK6UqCrKc5ARsuWZLqIKGIAuD5fBTkvKaEd4zjCILavZCXvmEwzR4I 3VnQQo//E29uMFreMTV0/rHhSDeIv59CWC8NhMw4DoDtVY/XBDhSkQ5z5BWEtukx/21e DfHAL2RsBtVTEQ6d4Dsrdn0/BIEUY2fEBB6f70X933jwDYQEf1LmOIZcPe0O+Ia0RXpk iGR8/VewyywWN5cxnrQ+G7R/4Y6oCg7la5Lc5KY/rqKRUHEpfp/lghtg7209XY3ZunJp BZxQ== X-Gm-Message-State: AIVw110fl0EgNlIpNkJ70sFnPU8w0CCgeRGzHHAU2vjjCAWlziqeMA56 sxqfJ7F4GstUYaMdyZ87tA== X-Received: by 10.98.111.194 with SMTP id k185mr541611pfc.235.1500430575709; Tue, 18 Jul 2017 19:16:15 -0700 (PDT) Received: from localhost.localdomain (203-59-51-51.dyn.iinet.net.au. [203.59.51.51]) by smtp.gmail.com with ESMTPSA id d70sm8732241pfg.132.2017.07.18.19.16.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Jul 2017 19:16:15 -0700 (PDT) From: Daniel Axtens To: linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org Cc: benh@kernel.crashing.org, z.liuxinliang@hisilicon.com, zourongrong@gmail.com, catalin.marinas@arm.com, will.deacon@arm.com, gabriele.paoloni@huawei.com, bhelgaas@google.com, airlied@linux.ie, daniel.vetter@intel.com, alex.williamson@redhat.com, Daniel Axtens Subject: [PATCH v2 2/4] vgaarb: allow non-legacy cards to be marked as default Date: Wed, 19 Jul 2017 12:15:14 +1000 Message-Id: <20170719021516.24718-3-dja@axtens.net> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170719021516.24718-1-dja@axtens.net> References: <20170719021516.24718-1-dja@axtens.net> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The VGA arbiter currently only selects a card as default if it can decode legacy I/O and memory ranges. However, on some architectures, legacy PCI resources are not used. This has lead to a powerpc quirk, and issues on arm64. Allow architectures to select ARCH_WANT_VGA_ARB_FALLBACK. When that symbol is selected, add a PCI_FIXUP_CLASS_ENABLE hook, which will mark the first card that is enabled and that can control I/O and memory as the default card. Behaviour is unchanged unless arches opt-in by selecting the Kconfig option. Signed-off-by: Daniel Axtens --- drivers/gpu/vga/Kconfig | 7 +++++++ drivers/gpu/vga/vgaarb.c | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/drivers/gpu/vga/Kconfig b/drivers/gpu/vga/Kconfig index 29437eabe095..1205c6cc1ff5 100644 --- a/drivers/gpu/vga/Kconfig +++ b/drivers/gpu/vga/Kconfig @@ -17,6 +17,13 @@ config VGA_ARB_MAX_GPUS Reserves space in the kernel to maintain resource locking for multiple GPUS. The overhead for each GPU is very small. +config ARCH_WANT_VGA_ARB_FALLBACK + bool + help + Some architectures don't have a concept of "legacy" PCI addresses + which the VGA arbiter relies on. Instead, they can fall back to + selecting the first device that decodes memory and I/O. + config VGA_SWITCHEROO bool "Laptop Hybrid Graphics - GPU switching support" depends on X86 diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c index 76875f6299b8..2135b04759c5 100644 --- a/drivers/gpu/vga/vgaarb.c +++ b/drivers/gpu/vga/vgaarb.c @@ -1472,3 +1472,24 @@ static int __init vga_arb_device_init(void) return rc; } subsys_initcall(vga_arb_device_init); + +#if defined(CONFIG_ARCH_WANT_VGA_ARB_FALLBACK) +static void vga_arb_fallback_fixup(struct pci_dev *pdev) +{ + u16 cmd; + + if (vga_default_device()) + return; + + pci_read_config_word(pdev, PCI_COMMAND, &cmd); + if (cmd & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY)) { + vgaarb_info(&pdev->dev, "[fallback]" + " setting as default device\n"); + vga_set_default_device(pdev); + } + +} +DECLARE_PCI_FIXUP_CLASS_ENABLE(PCI_ANY_ID, PCI_ANY_ID, + PCI_CLASS_DISPLAY_VGA, 8, + vga_arb_fallback_fixup); +#endif