From patchwork Thu Jan 7 17:50:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Das, Nirmoy" X-Patchwork-Id: 12004595 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, 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 0A845C433DB for ; Thu, 7 Jan 2021 17:50:56 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B8E6A233FB for ; Thu, 7 Jan 2021 17:50:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B8E6A233FB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 878196E49C; Thu, 7 Jan 2021 17:50:52 +0000 (UTC) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2088.outbound.protection.outlook.com [40.107.93.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3F3806E49C for ; Thu, 7 Jan 2021 17:50:51 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cXSBxPqa7RkT9eZ+9VrcKB+u3O352xiObA06KhsjiukdbFD4y5UBYpSzUBCjUh0g+YzsNwQAc1EW8AWf1PWryuYQOfWalJ52bbeg1rmyWqWc1CcTm588oOt3Rhsg/jiuzDLd9tzNNgdhwW0x2QiqHAGo0CkZieqajDWOX0Acohe66Jjt/7n06aicGUcrCUQENU/VO3w6upgNZlRGQ5Y6FlpRroNiJVUaX8ts3VXOI3QB/VP6GrTp99Vi43XH4yKMcJdACAJA0aOWEhkUaTaZZDUrEfaJm+CEf2HS1aBMqWWsztMYSh1YofF8oIhga5VrF8xygl24Adad7aWX0Yxgaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sg/CDzXyze3tWUJxj0mz1HiBNVrEWG7Jo2YIZ4wHVUk=; b=lRAbROB/o7M3+hXHDCtR4qjyDcFabWowkDQ42dDDGR5v7mnOrGYceD7m2C00hMPfOtYgJxIBFmCEoRuk980zmdYfR5KtjDVCej4QEwT5TajVXShCoiluWFX6eBIrmm15gA6nb91ygQs2h6tNDQZui2lIzFh/YeC1kdNCeLEjZjVXHSGftSXtKe5nxfHMvnyVxBjEdCcBRf6qfLyhPxOd3TwiSnbGBSxdiKM4TuWji+R9jSiI2vjECE8i0HjGoWlzNy84GFHFbRxswyIVYcjmmVYwoOpUOg47UAWT9Sz4IIiwWnLMH7dOPK32XZFy9eCNgXXVZKObDtXRWxW+X2toPg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sg/CDzXyze3tWUJxj0mz1HiBNVrEWG7Jo2YIZ4wHVUk=; b=fC9Pd8JQuIWgGTx0qc0tFEvyoP3CgaJ4qKoF97572WQNwYRmi/zpWCe1wkZc66cmo5YrmWAfOekMQZlugs64F7QNRZDljqoC8eLj6+U9KAjyX1bJ89qsAymHzJN42fLvHtQDRcUP/AFr3Ynrm5/Jo/0a3s17e3WESx8Zb9yF64U= Authentication-Results: google.com; dkim=none (message not signed) header.d=none;google.com; dmarc=none action=none header.from=amd.com; Received: from DM6PR12MB3916.namprd12.prod.outlook.com (2603:10b6:5:1ca::21) by DM6PR12MB3066.namprd12.prod.outlook.com (2603:10b6:5:11a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6; Thu, 7 Jan 2021 17:50:50 +0000 Received: from DM6PR12MB3916.namprd12.prod.outlook.com ([fe80::f872:3677:28c3:660b]) by DM6PR12MB3916.namprd12.prod.outlook.com ([fe80::f872:3677:28c3:660b%5]) with mapi id 15.20.3721.024; Thu, 7 Jan 2021 17:50:50 +0000 From: Nirmoy Das To: bhelgaas@google.com Subject: [PATCH 2/4] PCI: Add pci_rebar_bytes_to_size() Date: Thu, 7 Jan 2021 18:50:15 +0100 Message-Id: <20210107175017.15893-3-nirmoy.das@amd.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210107175017.15893-1-nirmoy.das@amd.com> References: <20210107175017.15893-1-nirmoy.das@amd.com> X-Originating-IP: [217.86.111.165] X-ClientProxiedBy: AM0PR03CA0093.eurprd03.prod.outlook.com (2603:10a6:208:69::34) To DM6PR12MB3916.namprd12.prod.outlook.com (2603:10b6:5:1ca::21) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from brihaspati.fritz.box (217.86.111.165) by AM0PR03CA0093.eurprd03.prod.outlook.com (2603:10a6:208:69::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6 via Frontend Transport; Thu, 7 Jan 2021 17:50:48 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 1659d772-1a1e-4a33-07b1-08d8b334c536 X-MS-TrafficTypeDiagnostic: DM6PR12MB3066: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:586; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8fZVVfVQKUhK4jHgy0xx2FcF5EODaYXNclS8auonvf6NDsJnnpZhztuNSHp/N6VmU6EAiTBsP9NNZRtdd268f2SnW9Q18Zg1A8MbJUFD0zqtejNYn89P+XLsbnaE/0+JYFJFtjuTWP299mswkTFuw5BNMVgLbCslxytGijBmOakD8tVBeWIaSA2cCSIZrEUBG2uod1zPeO5d5OLlop/5k/TYhkD5U9TWOJalyBlY0+8a0cuOYaRIAOMfboz2xrg7iii62QMe1jCNL6yHfYr1CxnM5Dfc/IYnK3xxLuA8iW9hI10GEpqsQd7oVAFOmDIz087AsxImzn5EAi+pXVZ7gU3bS8lIoYiJgbNzQ/bFIP6W+jLC7OS2NcEWyp2k8qmCyXGFKFur6G2eHzPq+1mWjQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR12MB3916.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(346002)(376002)(136003)(39860400002)(396003)(4326008)(6916009)(316002)(1076003)(66574015)(83380400001)(478600001)(6486002)(54906003)(36756003)(26005)(66476007)(66556008)(5660300002)(8936002)(66946007)(2616005)(16526019)(44832011)(2906002)(52116002)(6506007)(8676002)(86362001)(6666004)(956004)(6512007)(186003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?j2rZriM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l78mzvSVJ6qaUj4vzIJFws+?= =?utf-8?q?6nGoaW5xDtz0r87BeutE88ijn8dMAGGnquXHH9GnytN7PsYQvIfhHJbS2zEG8yj1E?= =?utf-8?q?aaIs5IN1PyWt9VdspsN?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3916.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jan 2021 17:50:50.0039 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: 1659d772-1a1e-4a33-07b1-08d8b334c536 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: cvmwmxmnAHZyZeyNm+GhAqb96CSZkvyjrdQvBLiS+FL7R7PgdhYzE0pXLLBEkidf24ITTHsPCF8xKc2vogT67A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3066 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ckoenig.leichtzumerken@gmail.com, dri-devel@lists.freedesktop.org, Nirmoy Das , linux-pci@vger.kernel.org, devspam@moreofthesa.me.uk, =?utf-8?q?Christian_K=C3=B6nig?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Users of pci_resize_resource() need a way to calculate bar size from desired bytes. Add a helper function and export it so that modular drivers can use it. Signed-off-by: Darren Salt Signed-off-by: Christian König Signed-off-by: Nirmoy Das Acked-by: Bjorn Helgaas --- drivers/pci/pci.c | 2 +- include/linux/pci.h | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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/include/linux/pci.h b/include/linux/pci.h index 9999040cfad9..77fed01523e0 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1226,6 +1226,12 @@ 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 inline int pci_rebar_bytes_to_size(u64 bytes) +{ + bytes = roundup_pow_of_two(bytes); + return max(ilog2(bytes), 20) - 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);