From patchwork Fri Jun 14 10:06:03 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: 13698497 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 238CAC27C6E for ; Fri, 14 Jun 2024 10:06:47 +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=82DNwwpJr1Hy/qhCKKCRAOhyrO5/zTMnrke+lh53CV4=; b=ASLZjsACNN9WoEXgvZgPZBvHtD OPI3vRZ4AST+MdAK27uWzXWgMQVKWQHTJP01obZD1h1vkOvjPpMU8HVXsi7ierfXt5YVmmd+bPgqr +vH70Riq2JhvpvKG0hxdTm2qGNrGO0mEKqaswHdau5bPh4bj7QphBbSqnr8WxC+M5nzpEEAFz8O4X ydXAdTZ6hXkI1aSeRJszD41JYfPa1530wdBt3WZSkPxKh++2xjpteoJgpxVap8zVFDx5jJx7msunU VV/acJGut7WT19MYsC7eIc7JNgsSvBGlUeBvti8kGTQq05qRIaxBededPgNiSf+7ER8xhotSziF6O R/JIAbhg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sI3pJ-00000002LKl-1Ktx; Fri, 14 Jun 2024 10:06:33 +0000 Received: from mgamail.intel.com ([198.175.65.10]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sI3pG-00000002LJd-1Xwf for linux-arm-kernel@lists.infradead.org; Fri, 14 Jun 2024 10:06:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718359590; x=1749895590; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1v9oA92V3WbTtGsB8nsfVc3j8l6i5OSwnc8kPlM6iCU=; b=HIJIzLLWdd774vwsq16Lluru/TBVB3KPdrbmLlZ0d61IaOB5K1XhwZiS EoFvnXhyLg4OWIRHSSUg/0RUU7DJm16dsmgpH2hfxVw5E++0X23HEvYNJ b7h2l6ii9iK1w19cETsQDbFduMUyOpiIJTm+4JAGfHnKNv8pCMaX68R4/ cqepIVe2tKvdh6py83uUixq4bMjN7beBmt/c20ZDHdvz0bBLi/ieV7gra m1kn20oaLBs7JsYL0X5L9nNr4LITxnLMIcoQm+mEpAC7WSFp89TAOhDmq Up+4snszWlRRkm4AbstCC9NnDbW0R8SrdNXFgwYt5qE+gwuBITX3QAJ2R w==; X-CSE-ConnectionGUID: GYpDtDDYR5yiA8pr/pFFWQ== X-CSE-MsgGUID: H+Cn15XDTRqvx0Wt432ksg== X-IronPort-AV: E=McAfee;i="6700,10204,11102"; a="32715829" X-IronPort-AV: E=Sophos;i="6.08,237,1712646000"; d="scan'208";a="32715829" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jun 2024 03:06:30 -0700 X-CSE-ConnectionGUID: yujZaWoMQ5Cd1nQnAzBzHg== X-CSE-MsgGUID: Wq1AyD18QhWmvvsyMZIiSw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,237,1712646000"; d="scan'208";a="45575897" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.245.247.222]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jun 2024 03:06:25 -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 1/4] resource: Add resource set range and size helpers Date: Fri, 14 Jun 2024 13:06:03 +0300 Message-Id: <20240614100606.15830-2-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_030630_509129_7C5492A4 X-CRM114-Status: GOOD ( 13.23 ) 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 coded manually unlike the getter side which has a helper for resource size calculation. Also, almost all callsites that calculate the 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 mention in its kerneldoc resource_set_range() is preferred when setting both addresses. 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;