linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: linux-pci@vger.kernel.org, "Bjorn Helgaas" <bhelgaas@google.com>,
	"Philipp Stanner" <pstanner@redhat.com>,
	"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Wilczyński" <kw@linux.com>,
	linux-kernel@vger.kernel.org,
	"Jonathan Hunter" <jonathanh@nvidia.com>,
	linux-arm-kernel@lists.infradead.org,
	linux-tegra@vger.kernel.org, "Robert Richter" <rric@kernel.org>,
	"Thierry Reding" <thierry.reding@gmail.com>
Subject: Re: [PATCH v2 4/4] PCI: Introduce ALIGN_DOWN_IF_NONZERO() helper locally
Date: Fri, 14 Jun 2024 14:20:53 +0100	[thread overview]
Message-ID: <20240614142053.00005a9c@Huawei.com> (raw)
In-Reply-To: <20240614100606.15830-5-ilpo.jarvinen@linux.intel.com>

On Fri, 14 Jun 2024 13:06:06 +0300
Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> wrote:

> pci_bus_distribute_available_resources() performs alignment in case of
> non-zero alignment requirement on 3 occasions. Introduce
> ALIGN_DOWN_IF_NONZERO() helper to avoid coding the non-zero check 3
> times.
> 
> Suggested-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> ---
> 
> I tried to look other similar cases for both ALIGN() and ALIGN_DOWN()
> kernel-wide but it seems this is not very common so I did not put
> ALIGN_DOWN_IF_NONZERO() into the generic header.
Makes sense. It's a weird quirk of the return value of
pci_resource_alignement() to return 0 when it really means 1.

LGTM

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/pci/setup-bus.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
> index 004405edf290..39552d1a1793 100644
> --- a/drivers/pci/setup-bus.c
> +++ b/drivers/pci/setup-bus.c
> @@ -1819,6 +1819,9 @@ static void remove_dev_resources(struct pci_dev *dev, struct resource *io,
>  	}
>  }
>  
> +#define ALIGN_DOWN_IF_NONZERO(addr, align) \
> +			((align) ? ALIGN_DOWN((addr), (align)) : (addr))
> +
>  /*
>   * io, mmio and mmio_pref contain the total amount of bridge window space
>   * available. This includes the minimal space needed to cover all the
> @@ -1930,8 +1933,7 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus,
>  		 * what is available).
>  		 */
>  		align = pci_resource_alignment(dev, res);
> -		resource_set_size(&io, align ? ALIGN_DOWN(io_per_b, align)
> -					     : io_per_b);
> +		resource_set_size(&io, ALIGN_DOWN_IF_NONZERO(io_per_b, align));
>  
>  		/*
>  		 * The x_per_b holds the extra resource space that can be
> @@ -1943,15 +1945,13 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus,
>  
>  		res = &dev->resource[PCI_BRIDGE_MEM_WINDOW];
>  		align = pci_resource_alignment(dev, res);
> -		resource_set_size(&mmio, align ? ALIGN_DOWN(mmio_per_b, align)
> -					       : mmio_per_b);
> +		resource_set_size(&mmio, ALIGN_DOWN_IF_NONZERO(mmio_per_b, align));
>  		mmio.start -= resource_size(res);
>  
>  		res = &dev->resource[PCI_BRIDGE_PREF_MEM_WINDOW];
>  		align = pci_resource_alignment(dev, res);
>  		resource_set_size(&mmio_pref,
> -				  align ? ALIGN_DOWN(mmio_pref_per_b, align)
> -					: mmio_pref_per_b);
> +				  ALIGN_DOWN_IF_NONZERO(mmio_pref_per_b, align));
>  		mmio_pref.start -= resource_size(res);
>  
>  		pci_bus_distribute_available_resources(b, add_list, io, mmio,



  reply	other threads:[~2024-06-14 13:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-14 10:06 [PATCH v2 0/4] PCI: Resource helper improvements Ilpo Järvinen
2024-06-14 10:06 ` [PATCH v2 1/4] resource: Add resource set range and size helpers Ilpo Järvinen
2024-06-14 10:06 ` [PATCH v2 2/4] PCI: Use resource_set_{range,size}() helpers Ilpo Järvinen
2024-06-14 10:06 ` [PATCH v2 3/4] PCI: Use align and resource helpers, and SZ_* in quirk_s3_64M() Ilpo Järvinen
2024-06-14 10:06 ` [PATCH v2 4/4] PCI: Introduce ALIGN_DOWN_IF_NONZERO() helper locally Ilpo Järvinen
2024-06-14 13:20   ` Jonathan Cameron [this message]
2024-10-10 22:48 ` [PATCH v2 0/4] PCI: Resource helper improvements Bjorn Helgaas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240614142053.00005a9c@Huawei.com \
    --to=jonathan.cameron@huawei.com \
    --cc=bhelgaas@google.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=jonathanh@nvidia.com \
    --cc=kw@linux.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=pstanner@redhat.com \
    --cc=robh@kernel.org \
    --cc=rric@kernel.org \
    --cc=thierry.reding@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).