From patchwork Tue Jan 5 13:44:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 11998921 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0535C43381 for ; Tue, 5 Jan 2021 13:44:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C0E4F229C4 for ; Tue, 5 Jan 2021 13:44:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730343AbhAENow (ORCPT ); Tue, 5 Jan 2021 08:44:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730161AbhAENov (ORCPT ); Tue, 5 Jan 2021 08:44:51 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3010C061793 for ; Tue, 5 Jan 2021 05:44:10 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id c124so3046156wma.5 for ; Tue, 05 Jan 2021 05:44:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oxBOSPXdt1KE4KRfESGM7lDH9UwLyaTef5/94sYT5Lg=; b=k9E22mhtoYSmxWgLV32Zz/wEftwzeTRJXDbpQLK6jVSyHqR/ukMZ4xEK9wd3kGdOu3 ApSHMRCcDOAMuT5v8n/diwEZKz24dasn4j0Q6KXvok2eOdNYIkuFsTbk2XXtKoMOGb8F wjxt2ShqGzrkqLnm/BnTM6jH7hbioAlEQbj0ycjfaNkwqLSI27JVHkd1dkA3xQTITzGP 0fSOqZeiriMZIA6pHXemwgiJ3jsELV3pLdhyK+LINiPYjIffVrZQMVPTcmgcZ5dNTMTj iYrcNgy1+HLmpZgWq0Hq7zMYcw58K1KjWeyXmC45kjNaUT/VD2CLE+gJaDcs/N8AqDzX w2xA== 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:mime-version:content-transfer-encoding; bh=oxBOSPXdt1KE4KRfESGM7lDH9UwLyaTef5/94sYT5Lg=; b=lpb10TpaE8H3ukZK6aIn9F4dteLIGHVC71VJ3BRWRB3Sp4weXjmif21hx1ojg+DdFf z7g14lVXO2KYribO7VUoN+37yEL6Q/1JhOu5gl43bD3KqmJIZMPXvRKJkz8fK5KFPJNT SnrVwm37tw1s9d62sEuhTOPFtuX+aVrBSri+gavN3VsAh7KbwBO9oln7SYl//rFjTeMx +QKZxlHe5h3VW6Py4PYkt+VejP4PVyqKO1QBkizOA8S23y4y9yeXen+POdkgr6m9MZLd HduwcU81ZmpmHOw8QIRVaDlZhFeUJgisOy7InjAoERrwilnHKDMzoBANVSjuVfQQ/IXP 3sAQ== X-Gm-Message-State: AOAM533OmlwxZBiB/cIzVwtVJYk3j/tvbBbCZ6Kb/nTVcygnGuDp1MQG 7D/XsFEESWNYkkLRm4o1WIaxcu++tLI= X-Google-Smtp-Source: ABdhPJzEQpuZDGSyAKMlkTFO1nHHUn6kxF5BqQSJS9BhEdjJ9giJfYIF4nCODnMfgKaEKi9Q8gXe7A== X-Received: by 2002:a1c:e10b:: with SMTP id y11mr3636179wmg.65.1609854249584; Tue, 05 Jan 2021 05:44:09 -0800 (PST) Received: from abel.fritz.box ([2a02:908:1252:fb60:3137:60b9:8d8f:7f55]) by smtp.gmail.com with ESMTPSA id l20sm102191243wrh.82.2021.01.05.05.44.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Jan 2021 05:44:09 -0800 (PST) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: bhelgaas@google.com Cc: devspam@moreofthesa.me.uk, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-pci@vger.kernel.org Subject: [PATCH 1/4] pci: export pci_rebar_get_possible_sizes Date: Tue, 5 Jan 2021 14:44:01 +0100 Message-Id: <20210105134404.1545-2-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210105134404.1545-1-christian.koenig@amd.com> References: <20210105134404.1545-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Darren Salt This is to assist driver modules which do BAR resizing. Signed-off-by: Darren Salt --- drivers/pci/pci.c | 1 + drivers/pci/pci.h | 1 - include/linux/pci.h | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index e578d34095e9..ef80ed451415 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -3579,6 +3579,7 @@ u32 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar) pci_read_config_dword(pdev, pos + PCI_REBAR_CAP, &cap); return (cap & PCI_REBAR_CAP_SIZES) >> 4; } +EXPORT_SYMBOL(pci_rebar_get_possible_sizes); /** * pci_rebar_get_current_size - get the current size of a BAR diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index f86cae9aa1f4..640ae7d74fc3 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -608,7 +608,6 @@ int acpi_get_rc_resources(struct device *dev, const char *hid, u16 segment, struct resource *res); #endif -u32 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar); int pci_rebar_get_current_size(struct pci_dev *pdev, int bar); int pci_rebar_set_size(struct pci_dev *pdev, int bar, int size); static inline u64 pci_rebar_size_to_bytes(int size) diff --git a/include/linux/pci.h b/include/linux/pci.h index 22207a79762c..9999040cfad9 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1226,6 +1226,7 @@ void pci_update_resource(struct pci_dev *dev, int resno); int __must_check pci_assign_resource(struct pci_dev *dev, int i); int __must_check pci_reassign_resource(struct pci_dev *dev, int i, resource_size_t add_size, resource_size_t align); void pci_release_resource(struct pci_dev *dev, int resno); +u32 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar); int __must_check pci_resize_resource(struct pci_dev *dev, int i, int size); int pci_select_bars(struct pci_dev *dev, unsigned long flags); bool pci_device_is_present(struct pci_dev *pdev); From patchwork Tue Jan 5 13:44:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 11998923 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0AAA0C433E9 for ; Tue, 5 Jan 2021 13:44:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D4FC2229C5 for ; Tue, 5 Jan 2021 13:44:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730339AbhAENox (ORCPT ); Tue, 5 Jan 2021 08:44:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730341AbhAENow (ORCPT ); Tue, 5 Jan 2021 08:44:52 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91D27C061795 for ; Tue, 5 Jan 2021 05:44:11 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id v14so3076571wml.1 for ; Tue, 05 Jan 2021 05:44:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Hp+FXY/j+HS1RZY1QPCjRJHJ011MN+/S057cH09kSZs=; b=Bxrd3/zrHtZFlcg9No5k3H03zGO6iHX15NG1AZTMYc7Ng9vEIpuGlqq44W73lwetV6 fMA7uOIIsPAPsg1f1CxdrWL164L3qJlgJG1h7vaSLiapwq414qWh5D3JH4poemMxla6E 4B2kkt/gejIKWcR+j6lfgmcoM0VmfDkaLTRgcLxQDFSG7Zd3ubJTBjyMj57mT5AOyIyw CBWhTDiFlD83wSML+AgFYErqJxS5dvHUjzesuzGM25DKt99PKAAZB46Vyq1THUNSlh8g 7CexgOJ0G5RWhTvh3VEgC0474S/KnMYExwLNwOGfVdyVw4ZIj1IePFHf9kxhMbYcMTNc Rpzg== 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:mime-version:content-transfer-encoding; bh=Hp+FXY/j+HS1RZY1QPCjRJHJ011MN+/S057cH09kSZs=; b=J1UnghxIoEzh3roMKEhow9kWBbg3x1T113UsPKGV2TZirqrSJJ0AXDRbjiLoWtUI3A 955ByoBx19ab9MXBTU/pCf7xF6q1qeKJIUpadedKg/yGkm72+5JyS/iguQk1bdtJ+WwI jFsuTUu7YX4bPPDsy5eNQyEs9WztOegvCG9bkt7NFSrjTVsDJfahPXx7cxC0rUH5WHNF 61hSkJ9/VRuls5RFvqJl/7dfFHP5dVA8clefB4G97fRDCZYFyQ9V8vyzQGeYz9lIWow0 pOA80XBW1/ZIQZ9CcPTFsgzevjSFnZsFaAZLhNhVk2FxdINTjHerFdkfDbDsh0jGKii+ Zrpw== X-Gm-Message-State: AOAM531FZbJBBwpsdoDM1H4nE+J7cwDiOjeFxTm6CM+SNIEgJEyk6AX+ UB3diVhVTQItFuPCFi+UlWY= X-Google-Smtp-Source: ABdhPJz7Dxb6nnjRrvu9rS/LYHVJIiS73Lk13z8bDFfT28Aif2E3DZKCZs3vAjf70aQm1RjwchIn9A== X-Received: by 2002:a1c:41c5:: with SMTP id o188mr3563620wma.18.1609854250423; Tue, 05 Jan 2021 05:44:10 -0800 (PST) Received: from abel.fritz.box ([2a02:908:1252:fb60:3137:60b9:8d8f:7f55]) by smtp.gmail.com with ESMTPSA id l20sm102191243wrh.82.2021.01.05.05.44.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Jan 2021 05:44:10 -0800 (PST) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: bhelgaas@google.com Cc: devspam@moreofthesa.me.uk, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-pci@vger.kernel.org Subject: [PATCH 2/4] pci: add BAR bytes->size helper & expose size->bytes helper v2 Date: Tue, 5 Jan 2021 14:44:02 +0100 Message-Id: <20210105134404.1545-3-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210105134404.1545-1-christian.koenig@amd.com> References: <20210105134404.1545-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Darren Salt This is to assist driver modules which do BAR resizing. v2 (chk): Use ilog2 and make the new funtion extra defensive. Also use the new function on the two existing ocassions. Signed-off-by: Darren Salt Signed-off-by: Christian König --- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 +-- drivers/pci/pci.c | 2 +- drivers/pci/pci.h | 4 ---- include/linux/pci.h | 12 ++++++++++++ 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c index dce0e66b2364..70acd673e3f2 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c @@ -1089,8 +1089,7 @@ void amdgpu_device_wb_free(struct amdgpu_device *adev, u32 wb) */ int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev) { - u64 space_needed = roundup_pow_of_two(adev->gmc.real_vram_size); - u32 rbar_size = order_base_2(((space_needed >> 20) | 1)) - 1; + u32 rbar_size = pci_rebar_bytes_to_size(adev->gmc.real_vram_size); struct pci_bus *root; struct resource *res; unsigned i; diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index ef80ed451415..16216186b51c 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1648,7 +1648,7 @@ static void pci_restore_rebar_state(struct pci_dev *pdev) pci_read_config_dword(pdev, pos + PCI_REBAR_CTRL, &ctrl); bar_idx = ctrl & PCI_REBAR_CTRL_BAR_IDX; res = pdev->resource + bar_idx; - size = ilog2(resource_size(res)) - 20; + size = pci_rebar_bytes_to_size(resource_size(res)); ctrl &= ~PCI_REBAR_CTRL_BAR_SIZE; ctrl |= size << PCI_REBAR_CTRL_BAR_SHIFT; pci_write_config_dword(pdev, pos + PCI_REBAR_CTRL, ctrl); diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 640ae7d74fc3..0fa31ff3d4e4 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -610,10 +610,6 @@ int acpi_get_rc_resources(struct device *dev, const char *hid, u16 segment, int pci_rebar_get_current_size(struct pci_dev *pdev, int bar); int pci_rebar_set_size(struct pci_dev *pdev, int bar, int size); -static inline u64 pci_rebar_size_to_bytes(int size) -{ - return 1ULL << (size + 20); -} struct device_node; diff --git a/include/linux/pci.h b/include/linux/pci.h index 9999040cfad9..673606f871b7 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1226,6 +1226,18 @@ void pci_update_resource(struct pci_dev *dev, int resno); int __must_check pci_assign_resource(struct pci_dev *dev, int i); int __must_check pci_reassign_resource(struct pci_dev *dev, int i, resource_size_t add_size, resource_size_t align); void pci_release_resource(struct pci_dev *dev, int resno); + +static __always_inline int pci_rebar_bytes_to_size(u64 bytes) +{ + bytes = roundup_pow_of_two(bytes); + return max(ilog2(bytes), 20) - 20; +} + +static __always_inline u64 pci_rebar_size_to_bytes(int size) +{ + return 1ULL << (size + 20); +} + u32 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar); int __must_check pci_resize_resource(struct pci_dev *dev, int i, int size); int pci_select_bars(struct pci_dev *dev, unsigned long flags); From patchwork Tue Jan 5 13:44:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 11998927 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DAA6C4332D for ; Tue, 5 Jan 2021 13:44:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EBE0A229C4 for ; Tue, 5 Jan 2021 13:44:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730345AbhAENoy (ORCPT ); Tue, 5 Jan 2021 08:44:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730161AbhAENox (ORCPT ); Tue, 5 Jan 2021 08:44:53 -0500 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62588C061796 for ; Tue, 5 Jan 2021 05:44:12 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id r3so36259411wrt.2 for ; Tue, 05 Jan 2021 05:44:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4uTZYuSmoeTiRu33iHMIlMouIHVooiXnKLwMhzI2plk=; b=YLVW6yaz4t2tTxAlT7N9+bLCR18/eFsvPFiFFdhF+38gMYzmjR9uWvyDt1FUjqrDad qZuW6FjBp/2HVZt8h4Fkkefp2Z11UWNrqrHGBwOe2dldv5E7bWG1qBlrMggcCpneniSF /pQvB4U1bPCcEXQRT2jBVYhggUF+v299sxZxzraG6Fl0EJsbYU+VfOt7MpIXpzNYrDBs r99ADcF1Kce/XRWO4273uOPAFoB5DQSeRzn4tONPK/02cyNvLmrTaQMLL3euKvHHBvBw sjh8tDthm968s1bUEtRspTUxVY5XpkYhPeoqHgPbqSvqo9qAAiT9EY2KgbPPQv59svE/ 4u4A== 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:mime-version:content-transfer-encoding; bh=4uTZYuSmoeTiRu33iHMIlMouIHVooiXnKLwMhzI2plk=; b=RxQM/g/x+tsWslAxIqp/2SvfO8CjasTWMWxBWlxDXeJWT7m6vgytThGjUUF7KECRjJ c43Qz7DwUm4wfv84t83N1AEIBHECYMk+jn9+jdNEX8sfzYAJ2tTdH3RDZ52ZxdMnq875 PVb7keO1PpNAVCuXKBV8iATZY+bE71FmIzE3/hynW2u6PEUeLklsp37rMN04+uFJwfgt H9lmDxXPCBymTtXrtI9IRYkArD4RF8MLkJk7WK5Z+XMp3Ee0g3RoGLllTW3BP7oRh71N 8J7Q6uB9E5bdX0IvEUflLb7iNLh8RXn9yj49YpqCXfyeBbEJ0Fdjfe0EhusshOZgg5AW 8M6w== X-Gm-Message-State: AOAM530eP9u49Q65Vplo/zm5U/KpwP+SIxu5GhTXMtC13DgnNKQRY7Cu 6CY9uXdoFe1idNZxkSpKyYA= X-Google-Smtp-Source: ABdhPJz5gt/7ovBihzHlh30pzyKlkA2e3I28sjv3mvtpk/2hFlTNoNgDQDk+RVB3ef2kI+uYHLqrBA== X-Received: by 2002:adf:f344:: with SMTP id e4mr85434282wrp.25.1609854251240; Tue, 05 Jan 2021 05:44:11 -0800 (PST) Received: from abel.fritz.box ([2a02:908:1252:fb60:3137:60b9:8d8f:7f55]) by smtp.gmail.com with ESMTPSA id l20sm102191243wrh.82.2021.01.05.05.44.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Jan 2021 05:44:10 -0800 (PST) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: bhelgaas@google.com Cc: devspam@moreofthesa.me.uk, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-pci@vger.kernel.org Subject: [PATCH 3/4] amdgpu: resize BAR0 to the maximum available size, even if it doesn't cover VRAM (v6) Date: Tue, 5 Jan 2021 14:44:03 +0100 Message-Id: <20210105134404.1545-4-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210105134404.1545-1-christian.koenig@amd.com> References: <20210105134404.1545-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Darren Salt This allows BAR0 resizing to be done for cards which don't advertise support for a size large enough to cover the VRAM but which do advertise at least one size larger than the default. For example, my RX 5600 XT, which advertises 256MB, 512MB and 1GB. [v6] (chk) Reduce to only the necessary functionality [v5] Drop the retry loop… [v4] Use bit ops to find sizes to try. [v3] Don't use pci_rebar_get_current_size(). [v2] Rewritten to use PCI helper functions; some extra log text. Signed-off-by: Darren Salt Signed-off-by: Christian König --- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c index 70acd673e3f2..da78746174f5 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c @@ -1089,7 +1089,7 @@ void amdgpu_device_wb_free(struct amdgpu_device *adev, u32 wb) */ int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev) { - u32 rbar_size = pci_rebar_bytes_to_size(adev->gmc.real_vram_size); + int rbar_size = pci_rebar_bytes_to_size(adev->gmc.real_vram_size); struct pci_bus *root; struct resource *res; unsigned i; @@ -1120,6 +1120,10 @@ int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev) if (!res) return 0; + /* Limit the BAR size to what is available */ + rbar_size = min(fls(pci_rebar_get_possible_sizes(adev->pdev, 0)) - 1, + rbar_size); + /* Disable memory decoding while we change the BAR addresses and size */ pci_read_config_word(adev->pdev, PCI_COMMAND, &cmd); pci_write_config_word(adev->pdev, PCI_COMMAND, From patchwork Tue Jan 5 13:44:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 11998925 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35BE8C4332B for ; Tue, 5 Jan 2021 13:44:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0EF5422B30 for ; Tue, 5 Jan 2021 13:44:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730346AbhAENoy (ORCPT ); Tue, 5 Jan 2021 08:44:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730341AbhAENox (ORCPT ); Tue, 5 Jan 2021 08:44:53 -0500 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CE47C061798 for ; Tue, 5 Jan 2021 05:44:13 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id q18so36283978wrn.1 for ; Tue, 05 Jan 2021 05:44:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/Xh8qZOWXZauoXa9vZ+K50zm9g9s+n1GKQJc2m0FrV8=; b=T9snQ9bKRyo+aHfNWsQiaTwtbweBwUVEbh1FBzR8gZDwjxw5kJ6Urcd3PHcyKp/i7F YuuVOjdv/SL6s2B62e00kEz7gzKjGyM2V1HTtHWdXpI5mqFGqPxqfdRX6ZzDCk98Dz8z V5Xgz1HalBD2/m+gbbOqiROSZG74t8xD+3fXm9RHa9aIrBnOi/OGvclNG4gq3cjC7Jyw hIee/qStDHEI+TPdS8nxykvg/q4+5JRFMwVloX2jOMhP1ty/hfMDlc4ymKMzyfJpWahd b74rKOQUOVrhYyGJB4NoBfxZKS7F5XZvn1Z0ajOcrwYWX4skrHOFTFE7Qte7E80ToxCw BD7g== 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:mime-version:content-transfer-encoding; bh=/Xh8qZOWXZauoXa9vZ+K50zm9g9s+n1GKQJc2m0FrV8=; b=XSqxVisGkgQPFsC6S1+liRCXhbEH8EalWdmIRwOVPUM7f65As4IeQEhjkCRraferjj 7d65n4rTYb7Sl9aWstHKbuh06OtZZ+5F9Qd0+nBgCPXkefvblQXxos4vT0Ta8X5zBFlg Tc34hiB7vSzvXDixGNN6uAyvOaHUtDbuVh4DXHRiR32FZJmqjn3n9OQ3vfxkZ82KoIe2 J2SJ0SBPbvVjnDLfBjpGr3rbPvR8FdkK+yBw2IY4XYwlwe35PBjVHjJ2pJejzNH1HYlq ed2WaQK5yMmkHigfB/KqltySWox4hGZX+c9b4kzPk98QE6ASER2oJblBgu/guUGtUIP9 bWxQ== X-Gm-Message-State: AOAM531he7jheS3mjZJBX2CgrlnGRi/9V5kL+8DYyo9WPI/7FNsRBAn+ hOS6Q2v4AEU3IJcgRnCuciU= X-Google-Smtp-Source: ABdhPJwLkmDD5Zg3fZC6NkuylnaqkeVxjvv3JjNRuhSiiF+n5kQbFv7JVfDkAm/Kbhghi2ev482tTQ== X-Received: by 2002:adf:dc10:: with SMTP id t16mr80583385wri.345.1609854252040; Tue, 05 Jan 2021 05:44:12 -0800 (PST) Received: from abel.fritz.box ([2a02:908:1252:fb60:3137:60b9:8d8f:7f55]) by smtp.gmail.com with ESMTPSA id l20sm102191243wrh.82.2021.01.05.05.44.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Jan 2021 05:44:11 -0800 (PST) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: bhelgaas@google.com Cc: devspam@moreofthesa.me.uk, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-pci@vger.kernel.org Subject: [PATCH 4/4] PCI: add a REBAR size quirk for Sapphire RX 5600 XT Pulse. Date: Tue, 5 Jan 2021 14:44:04 +0100 Message-Id: <20210105134404.1545-5-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210105134404.1545-1-christian.koenig@amd.com> References: <20210105134404.1545-1-christian.koenig@amd.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Otherwise the CPU can't fully access the BAR. Signed-off-by: Christian König Reported-by: kernel test robot Reported-by: kernel test robot Reported-by: Dan Carpenter --- drivers/pci/pci.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 16216186b51c..b66e4703c214 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -3577,7 +3577,14 @@ u32 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar) return 0; pci_read_config_dword(pdev, pos + PCI_REBAR_CAP, &cap); - return (cap & PCI_REBAR_CAP_SIZES) >> 4; + cap = (cap & PCI_REBAR_CAP_SIZES) >> 4; + + /* Sapphire RX 5600 XT Pulse has an invalid cap dword for BAR 0 */ + if (pdev->vendor == PCI_VENDOR_ID_ATI && pdev->device == 0x731f && + bar == 0 && cap == 0x700) + cap == 0x7f00; + + return cap; } EXPORT_SYMBOL(pci_rebar_get_possible_sizes);