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=-13.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 1DAC7C433DB for ; Thu, 7 Jan 2021 21:18:01 +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 D1CB823444 for ; Thu, 7 Jan 2021 21:18:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D1CB823444 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org 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 5BBFB6E4B7; Thu, 7 Jan 2021 21:18:00 +0000 (UTC) Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3BD0A6E4B7 for ; Thu, 7 Jan 2021 21:17:59 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id AB48623441; Thu, 7 Jan 2021 21:17:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1610054279; bh=5uoZNAJGLvzV9shzy8WW8XkIqE6H2k9ymeZVJrOtI2U=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=ofjJMoRrimEABG4LRevwmiB41Ps4MRs38jGoi36wqXyh0ztgxlE33oPjaXvjh6rHE wPttEqAFZ6h3AWNUiJa5r5nrUlo62dnEGh0LKEdRdjXqNUQKmv311SKXiQPda9Zag4 GHFQpxrlpVZdPDYB1Cf0nrjsmd0AkSxsZaWguM0rjEsuUVTjNAzsd42SjdCFT4JBqp hfqY8/NR0LbT8qUp2XpGwD7+0QyP8CEwcNseC6wV4Pt6G6ZJcylNgkWKingruevsXr OJAL2+xlCM0KsQwXPKX1b91RGVkW9uimIq56efrdjV3Ntvmqyc6xqlMeOqpIsmKwja Rtol1IwF0trQg== Date: Thu, 7 Jan 2021 15:17:57 -0600 From: Bjorn Helgaas To: Nirmoy Das Subject: Re: [PATCH 2/4] PCI: Add pci_rebar_bytes_to_size() Message-ID: <20210107211757.GA1391831@bjorn-Precision-5520> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210107175017.15893-3-nirmoy.das@amd.com> 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, devspam@moreofthesa.me.uk, linux-pci@vger.kernel.org, bhelgaas@google.com, Christian =?iso-8859-1?Q?K=F6nig?= Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Thu, Jan 07, 2021 at 06:50:15PM +0100, Nirmoy Das wrote: > 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. s/bar/BAR/ > Signed-off-by: Darren Salt > Signed-off-by: Christian K=F6nig > 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 =3D ctrl & PCI_REBAR_CTRL_BAR_IDX; > res =3D pdev->resource + bar_idx; > - size =3D ilog2(resource_size(res)) - 20; > + size =3D pci_rebar_bytes_to_size(resource_size(res)); > ctrl &=3D ~PCI_REBAR_CTRL_BAR_SIZE; > ctrl |=3D 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, resou= rce_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 =3D roundup_pow_of_two(bytes); > + return max(ilog2(bytes), 20) - 20; This isn't returning a "size", is it? It looks like it's returning the log2 of the number of MB the BAR will be, i.e., the encoding used by the Resizable BAR Control register "BAR Size" field. Needs a brief comment to that effect and/or a different function name. > +} > + > 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 siz= e); > int pci_select_bars(struct pci_dev *dev, unsigned long flags); > -- = > 2.29.2 > = _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel