Received: by 2002:ab2:6c55:0:b0:1fd:c486:4f03 with SMTP id v21csp358133lqp; Wed, 12 Jun 2024 03:57:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUU/gV4Dqsv+woV7CT0qE979Zw36aoO9a5a/4BlWzmCN6DKoWHtcD9nT6mp7IvyX4KbvM/OHHYf8r8EEoJpBa58P3zcF1D1fwdi9F2BaA== X-Google-Smtp-Source: AGHT+IEEM4fUGGCD+/9HyWb3ZXvLDP14Rw/aCdzltOglFlAe4RV0N6kxo1DTz1my1oWk0Wj+6f0v X-Received: by 2002:a05:6a00:2284:b0:704:32bb:1eb3 with SMTP id d2e1a72fcca58-705bcdf4544mr1897968b3a.1.1718189871076; Wed, 12 Jun 2024 03:57:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718189871; cv=pass; d=google.com; s=arc-20160816; b=S57C+Z/i6+5md+z3VagwEKaex8Jo7pyrjcgQ60MvDH1wUUEsk41msKQpk/Da3To+UI azGXLeh5Da24dKnBh42Ubv1GzcpU8lPNUuy4uxZCIOjlQ1+VJjp1oDo2iZYuV1Ke6sqZ Qt8qVcqC8eWqjtdili9JlqUeqsNlUvyOsivpjVQolwuEd7iUJ1bI2jOTyft+7nLe33DD VCm77DnI1Bre5UFGAwlSvbu01cv0KemIPOXSejmfALT8fnmTXUetVBhTCyJ3HgaWEAWN y2eiC/gGJ4UKCXFsxJgJ869Pv/xWVaUEBPXsJZgz7Bfiih0MfOCDR96O62Z/8mSFHFlF sgug== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=NB0wAIAUXutz2l92MLI6lCx/JAvcyAqAA2iVNgpC0DQ=; fh=m2r3qIppnYma6SljloBPkPBpoyyTtgJ09WmC826NvgI=; b=ocKNw8p66RaUo4rHDUcfU6Ww9uzqDN9GJWhVGszP4COT1J48bN5UTQrOUWNaPXeoJR LcpgjBjkJpUS99Z8mfWOjjWLexGB2rr6B2XpYnLKCtekBnHtkuh5tWuehqc+0/bTPPAh ouiUmcWVOZ1v5Mh5dUtXlofznJBLpny+7DYMkF5DWoZF6vvad46WZ80mJ5iLZ8W82bvA /5A0BtkZdA4L6HufwaVyEgGQZb+0GMV8hsJIW/MYumc8zWaOzpzKxHDTt3+54nKndjhq fmmxLAV/ax5d6Sz+L11lQWHNzhbr72IaEauArjWy0jDLUyYGSO+Qmn3OGL4fvT6LNmLm TB+w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RdcOWGeU; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-211222-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-211222-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 41be03b00d2f7-6e3819ffbebsi9207907a12.484.2024.06.12.03.57.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 03:57:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-211222-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RdcOWGeU; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-211222-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-211222-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 1CE7AB21319 for ; Wed, 12 Jun 2024 08:57:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C935116D4F7; Wed, 12 Jun 2024 08:57:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="RdcOWGeU" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6190E18E02; Wed, 12 Jun 2024 08:57:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718182624; cv=none; b=Wt7/+znhcHpfOWZQ6hqXqkdt4+XqIjboYxeT5yIDKt3wZNGXGyqceFv4RGxjK2mT1FCh0NEbaLwn3E8lipyMTRTCHY+7426i21ANx+My8Csi86JlHOX3wLiAh8z1ys703Qy3hK8ooHrbkS5O82BJ9pmraLm3mPuT5hNNLAlKPEE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718182624; c=relaxed/simple; bh=NcxfY/yC3SHBjeWD6d5Ymlrrf8Uc8BwT2dNHZA+FzWQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=ofriaUnmbD/+seP78na8Xnz+quFhn2cuBjouBHMqy/5pJ/Ap20kHpCNvq9h1LFAXPprLx2DyZYPFDsYHaeO9JEiGh59xpOqbSpZ2KOXsjzv7ZpjXu1rPDT0mQV8xY+xicjaZsjpa1/XyQoMNduFIRHLTX0i1nD5+fmwTY0yMqxc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=RdcOWGeU; arc=none smtp.client-ip=192.198.163.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com 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: t7ils0w6RE+/1GmFQXFrmA== X-CSE-MsgGUID: T+wMsRkbQd6kMoQksj2edg== X-IronPort-AV: E=McAfee;i="6600,9927,11100"; a="14657744" X-IronPort-AV: E=Sophos;i="6.08,232,1712646000"; d="scan'208";a="14657744" 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=20J=C3=A4rvinen?= To: Bjorn Helgaas , linux-pci@vger.kernel.org, Lorenzo Pieralisi , Rob Herring , =?UTF-8?q?Krzysztof=20Wilczy=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=20J=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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- 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; -- 2.39.2