From patchwork Fri Jun 14 10:06:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 13698621 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9CE72C27C6E for ; Fri, 14 Jun 2024 11:19:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=vso0MLqMiZ+Y7pY5vQztqc8wYoStGI4uebZsv7O5Fvs=; b=YsiC3T6KTiKvCdDZw/pJuE58gV 9mtdHl+6j87MaCr5XKfpFtaRcK50dOYwkvF5ow5kQfbf4j0twbVvOiQ3YDqi4f/cVWOTuPPjGfsfA wCazy4MMAcr3ZufvQ1298pWNpZIckPm11QG7ZS53cvFH1XAyrOLbH0eU+q3jz/pSK+B6fe4lZkeVH LgFUm2evD8YX/8KPE6wEx22wlA0EKz8NkMmjYbr6Ytf5J3peiW1LU8LkBDh1w8J0krhWJgbjH/iwZ p+HKBy0WtQtE64QUwU3kaxtumVQc/kziF1ZEzg7oylx20KuikZuCreGP40tuFFnWSxyOm8QGkz/EZ pUWYmw5w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sI4xW-00000002Zf9-1RM3; Fri, 14 Jun 2024 11:19:06 +0000 Received: from mgamail.intel.com ([198.175.65.18]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sI3qJ-00000002LZU-1nQz for linux-arm-kernel@lists.infradead.org; Fri, 14 Jun 2024 10:07:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718359656; x=1749895656; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5G6fJaJVWMpmbme+Rt8CFcBUcQjzifvZi4qRRIEqHyE=; b=oH1QylxRFYULOqYkshJzTGV+865+ljb8HPY7EuzQC2OtatrEaaPWghyH cDCyoFk5gD5LFGzyzyj8hLHj4LJInqU906frOCRqZsO+WtDczQSumoWmM cWWK4I19BCyjw6S33+j8ScHBGtuxwU1kBGk95f0qi/DTarL3w2Q2gGfEn 1bEh/53UUmAvosHM+J6ge5AMBAopFccgbxgUbVFUA/Jv5l3cRBwpRBDxT RII1l6gWRE8eshBpp7omCFHvOATvWvnHu1epfnBXMEcQh2O/6pqENVyND y+/7RkcDdui7ePTi8mDMAw2WwCr70IiIBbfzpfDkesnzgpcWoOJHDdQN+ g==; X-CSE-ConnectionGUID: pVT0BREyTPOwWsvw2qUxoA== X-CSE-MsgGUID: 8t8POD4vRsm/WU8gB7FjsA== X-IronPort-AV: E=McAfee;i="6700,10204,11102"; a="15389001" X-IronPort-AV: E=Sophos;i="6.08,237,1712646000"; d="scan'208";a="15389001" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jun 2024 03:07:04 -0700 X-CSE-ConnectionGUID: D5iayefDQtGYL+TTvlaOig== X-CSE-MsgGUID: bAYFmz4tRPOLHnrKQplGcQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,237,1712646000"; d="scan'208";a="77933772" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.245.247.222]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jun 2024 03:06:59 -0700 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: linux-pci@vger.kernel.org, Bjorn Helgaas , Jonathan Cameron , Philipp Stanner , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , linux-kernel@vger.kernel.org Cc: Jonathan Hunter , linux-arm-kernel@lists.infradead.org, linux-tegra@vger.kernel.org, Robert Richter , Thierry Reding , =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH v2 4/4] PCI: Introduce ALIGN_DOWN_IF_NONZERO() helper locally Date: Fri, 14 Jun 2024 13:06:06 +0300 Message-Id: <20240614100606.15830-5-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240614100606.15830-1-ilpo.jarvinen@linux.intel.com> References: <20240614100606.15830-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240614_030735_610576_99F90F41 X-CRM114-Status: GOOD ( 11.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 Signed-off-by: Ilpo Järvinen Reviewed-by: Jonathan Cameron --- 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. --- 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,