From patchwork Wed Jun 12 08:56:27 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: 13694674 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 B4A16C27C75 for ; Wed, 12 Jun 2024 08:57:17 +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=NB0wAIAUXutz2l92MLI6lCx/JAvcyAqAA2iVNgpC0DQ=; b=ndE83b7r5dS0zgRSW74SAEFNb1 Z1fsCG0sbZ58IiraCji5pYgskfsQVISGZ9uGWSI7QJupz14uT/Cpzt/GtmHQRJQfbs4oLAe4vWDAx uBXodawOAitSSIXsvb7x8q9IAH+RdsXPiBDzt9yRgYeCwzFwbSLa7qgKp8/UqcnSLsWKTv+wKyutC hX+YoxEWdRXX7Ti6QpCmXbu5kI7yaBRgnfoaoubn4JNt7+evuXuTxudK3lRc3mWAEV3WoMd7uaP8/ HSGz6N0/jenNFVYeCqHtr+loDdYB+1m9f8qu9IuxhnqbBca+b8DGQg/KLw//ytK5gLJnxktDF5uLC G1S6VHgw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sHJmz-0000000BpY7-0PyO; Wed, 12 Jun 2024 08:57:05 +0000 Received: from mgamail.intel.com ([192.198.163.18]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sHJmw-0000000BpWh-2psi for linux-arm-kernel@lists.infradead.org; Wed, 12 Jun 2024 08:57:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718182623; x=1749718623; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NcxfY/yC3SHBjeWD6d5Ymlrrf8Uc8BwT2dNHZA+FzWQ=; b=RdcOWGeUQK+UrnylTKLdN5hDNWO1zXn7EeYZqQU2sc/ozDoGSSbXqTFW e1r/sQvW2q2unTpEVKB7J1e2hTQWCpVN1HBWgRNoCJSJw1V7dbIagAVYT RyTrfY7i+1npHF4o+Ua26+IKodCVxiM/5+NRpPFbU1FPeO2xnIW/8oFoH stIjLfYwwv3Jw9jiaiJneMD0IQlB/mqreAliUvoiwP2buSCbmEp6D3nBb J+ju5dyNsf/6oFTOp3k38PX8Uu7RGe1qDlKiyvWxqudwVsqjiogEvmEQH F/rhlA5OfOc41fTZQbNU7alq1R8YuCu6Uo01gBUpuY7jzyp+BfKv1cjdn Q==; X-CSE-ConnectionGUID: vu3iGshOTOSrLT3n977JfQ== X-CSE-MsgGUID: xqD/eWFYQ5qFwXlJPtpV1A== X-IronPort-AV: E=McAfee;i="6600,9927,11100"; a="14657747" X-IronPort-AV: E=Sophos;i="6.08,232,1712646000"; d="scan'208";a="14657747" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jun 2024 01:57:02 -0700 X-CSE-ConnectionGUID: iU7O8OBxR5qed2jgKr2Ogg== X-CSE-MsgGUID: i+morLriT6in+KIEeRAFfw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,232,1712646000"; d="scan'208";a="70925445" Received: from unknown (HELO localhost) ([10.245.247.204]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jun 2024 01:56:57 -0700 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: Bjorn Helgaas , linux-pci@vger.kernel.org, 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 1/3] resource: Add resource set range and size helpers Date: Wed, 12 Jun 2024 11:56:27 +0300 Message-Id: <20240612085629.5015-2-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240612085629.5015-1-ilpo.jarvinen@linux.intel.com> References: <20240612085629.5015-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-20240612_015702_752216_BAC255E7 X-CRM114-Status: GOOD ( 13.29 ) 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 Setting the end address for a resource with a given size lacks a helper and is therefore open coded unlike the getter side which has a helper for resource size calculation. Also, almost all callsites that calculate end address for a resource also set the start address right before it like this: res->start = start_addr; res->end = res->start + size - 1; Thus, add resource_set_range(res, start_addr, size) that sets the start address and calculates the end address to simplify this often repeated fragment. In addition, introduce resource_set_size() for the cases where setting the start address of the resource is not necessary but note resource_set_range() is preferred. Signed-off-by: Ilpo Järvinen Reviewed-by: Jonathan Cameron ` --- include/linux/ioport.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/include/linux/ioport.h b/include/linux/ioport.h index db7fe25f3370..2a1d33ad151c 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h @@ -216,6 +216,38 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start); int adjust_resource(struct resource *res, resource_size_t start, resource_size_t size); resource_size_t resource_alignment(struct resource *res); + +/** + * resource_set_size - Calculates resource end address from size and start address + * @res: The resource descriptor + * @size: The size of the resource + * + * Calculates the end address for @res based on @size. + * + * Note: The start address of @res must be set when calling this function. + * Use resource_set_range() if setting both the start address and @size. + */ +static inline void resource_set_size(struct resource *res, resource_size_t size) +{ + res->end = res->start + size - 1; +} + +/** + * resource_set_range - Sets resource start and end addresses + * @res: The resource descriptor + * @start: The start address for the resource + * @size: The size of the resource + * + * Sets @res start address and calculates the end address based on @size. + */ +static inline void resource_set_range(struct resource *res, + resource_size_t start, + resource_size_t size) +{ + res->start = start; + resource_set_size(res, size); +} + static inline resource_size_t resource_size(const struct resource *res) { return res->end - res->start + 1;