Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp161250lqs; Thu, 13 Jun 2024 06:55:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUDYsjbVLeqNNTsn5dhwkqzijiHm/5akGNa3r6xw9DHkqiZODcjNwDawRWjr+CDuSN9wesLsU+/aOnW6nDsTTZh+I4IhWog3InEmPHG5w== X-Google-Smtp-Source: AGHT+IHV2lfZL3xRx1ooYccQhxyTTFle2mfoAMrfCTXeSnW8/aqmInU20sZ8awudqU/2wAjwvSqh X-Received: by 2002:a05:6102:9ab:b0:48d:97b0:9e08 with SMTP id ada2fe7eead31-48d97b0b0bdmr4311887137.15.1718286957941; Thu, 13 Jun 2024 06:55:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718286957; cv=pass; d=google.com; s=arc-20160816; b=aXHFXBZuWpwX/a4Qj5hI/HO6eMZWxOrmkUSctuGE4v9T+LqTos/xTnDz9w19YkVZVX PpAJ/v9INXk4o2tQuPuy3sEiO+sQEtuAZg1fH39r0VaYvyixxjHR28LNW4xso57ueNH7 6w1gowHcDb6jD+Ll9vV5yPtc6k4r35GL+gA2DHzwH0U53bzhbg+blmT9PYxxMPSMz6/d 3circ5Y7sWIz/4PpdCwSOxz1rMR9DmQEBEKKHO6z13E93WXjjDNZSMIJJBeuK0hucVaw a2HeVzwf+i9gmlFClWHbWu1MQUxvu2aIVG9Uy262tzuoBNeAjl6m582EMN15pJ7K5oOA cH4g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:message-id:in-reply-to:subject:cc:to:date :from:dkim-signature; bh=2XpcLWMSZVbMLI/7g+T0g1jCspDfipIWaRh1vHKfY5U=; fh=NzNY7jdPV6ZhOFbwlTEEo0TyeBv2fHVg3ExSz/tUwq0=; b=i704w1t6JpMh50WypXh9OO9mN2cH+YHXyfSkUDEyWzWADIaYiV7I+avEIBlc/jJl1E u4OXaRgjL59OEi1YM5/M0m1u359vYfOM2d2b5bmEe4IZDl+aC7qLg3YYPe8muYGQS0OV Fp/63TRCkCokp8HtdoWO6n2gz1eEaJ48BEA0r4lSybCSIcU5lKUqBRqfwusE5m0HEZiX YXTlFwH2ST+Gjj1u6s7Vkt+wU5YMqiim4j1uvmPD75MB56kBi9CMzMX0Xr5IoG5XNwPa X3EyvOmJ31Fb1DQ/a+CCKZCJ+Uq26MNcaQ/21L2c7GjbOlPKHRWixY6HfKvI2J/vpdhC J1PQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZnyKaN3a; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-213381-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213381-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-798ab9f95c8si140332285a.315.2024.06.13.06.55.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 06:55:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-213381-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZnyKaN3a; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-213381-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213381-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 919811C24049 for ; Thu, 13 Jun 2024 13:55:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E0D81145335; Thu, 13 Jun 2024 13:55:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ZnyKaN3a" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (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 EE9619476; Thu, 13 Jun 2024 13:55:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718286946; cv=none; b=MzNxSYWCFM5jfKf57yUc2c2EtGg3JcgK1a+PxJRsUDjQ+VYctjm9w5AYcVy9BDK0XV2MTj7kHjOfOQ5yFmS+1DSzmyTtr+9wMh7OzYTO+T9Wssadt27rTyLx2977yp7sJWB9Z4t7yUfjUjScNCQsZ/cog7W9VwAGDShqDyb9MyE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718286946; c=relaxed/simple; bh=u1DajbW7oUtOx74DBLX0ZPOjMtqIm5yVgGA3dX4bi0E=; h=From:Date:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=g/RDWS6pdpHMoZ6xTmoix4f3Xq/xJ5jjYH4wjm54CheRjwmDP9D9I+J+EE3o6EyedFvMOJIZQMI+Kgftj1bZO4tYEMR5n8CQgCkRgDf3RxT3O+7jyWB5GrKKWrNCyf/USEahYGtM5xq4eWzDVmFta7PqGbSAe95nBI+WJo0KPxs= 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=ZnyKaN3a; arc=none smtp.client-ip=198.175.65.15 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=1718286944; x=1749822944; h=from:date:to:cc:subject:in-reply-to:message-id: references:mime-version:content-id; bh=u1DajbW7oUtOx74DBLX0ZPOjMtqIm5yVgGA3dX4bi0E=; b=ZnyKaN3aA64F/9OKEiC10I539baswxjitM5sUuMYFVgq8iRg4uWWwGnH RBxAZ5WtoIJqdHYmK3K2NVgrzETQg/9piWdhc3NBqpLju7iAlbm9iMtyE qUiuqHFDZ2to8p0NxvnFC0oSgMITjOi/tPN0jJCrc4669s3yW/wdFT6L8 sLwj5JMmHqYeGiOyBTU079N2jPgurQTHKUaLWYin9N5lUBLi6D82mThzg 4UBKDpSJJiLLYbGa8YWv4dbPhhYoT9So27+mIp3e0xzK3BU3YVb97Vyd+ fIuBMc6AmL1Hq8eCLng2c2+fX5kIl5CMfCoQrnNs69dbR9b/FntIEq4fw A==; X-CSE-ConnectionGUID: QCdhTQI8RdWn3ddO2fENSQ== X-CSE-MsgGUID: vF6Vnb9wTna4qg0hYrDmjw== X-IronPort-AV: E=McAfee;i="6700,10204,11101"; a="18889941" X-IronPort-AV: E=Sophos;i="6.08,235,1712646000"; d="scan'208";a="18889941" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jun 2024 06:55:43 -0700 X-CSE-ConnectionGUID: 8p2jxRSWQsSOquJyVui+vg== X-CSE-MsgGUID: UkphOpaQTqCpQK01l29b8g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,235,1712646000"; d="scan'208";a="40791406" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.245.247.209]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jun 2024 06:55:39 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Date: Thu, 13 Jun 2024 16:55:35 +0300 (EEST) To: Jonathan Cameron cc: Bjorn Helgaas , linux-pci@vger.kernel.org, Lorenzo Pieralisi , Rob Herring , =?ISO-8859-2?Q?Krzysztof_Wilczy=F1ski?= , LKML , Jonathan Hunter , linux-arm-kernel@lists.infradead.org, linux-tegra@vger.kernel.org, Robert Richter , Thierry Reding , linux-cxl@vger.kernel.org Subject: Re: [PATCH 1/3] resource: Add resource set range and size helpers In-Reply-To: <20240613142820.00005c77@Huawei.com> Message-ID: References: <20240612085629.5015-1-ilpo.jarvinen@linux.intel.com> <20240612085629.5015-2-ilpo.jarvinen@linux.intel.com> <20240613142820.00005c77@Huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: multipart/mixed; BOUNDARY="8323328-1916017572-1718286144=:8853" Content-ID: This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323328-1916017572-1718286144=:8853 Content-Type: text/plain; CHARSET=ISO-8859-15 Content-Transfer-Encoding: QUOTED-PRINTABLE Content-ID: <0d32d090-d629-878a-fbd5-e965710d3b5a@linux.intel.com> On Thu, 13 Jun 2024, Jonathan Cameron wrote: > On Wed, 12 Jun 2024 11:56:27 +0300 > Ilpo J=E4rvinen wrote: >=20 > > 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: > >=20 > > =09res->start =3D start_addr; > > =09res->end =3D res->start + size - 1; > >=20 > > 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. > >=20 > > Signed-off-by: Ilpo J=E4rvinen >=20 > We have a bunch of cases of this in CXL. Adding this helper seems like > a good idea to me. Sadly this won't help struct range cases which feature the same math. > I'm not sure the odd semantics of resource_set_size() are a good idea. > Maybe it could by naming hint that it's relying internally on > size already being set. >=20 > resource_update_size() for instance might make people think or perhaps > that's just more obscure. Meh, I've argued myself around to there > not being a better name. Yeah, I tried to figure out solution to this very challenge too, but alas, couldn't really find any good solution to it. __ prefix would have kind of conveyed the meaning that you better know=20 what you're doing but as some people oppose __ too, I didn't want to stir= =20 that pot. So it is what it is. > Reviewed-by: Jonathan Cameron ` FYI, I dropped the extra ` from that (no need to reply because of it). Thanks for the reviews. --=20 i. > > --- > > include/linux/ioport.h | 32 ++++++++++++++++++++++++++++++++ > > 1 file changed, 32 insertions(+) > >=20 > > 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, > > =09=09 resource_size_t size); > > resource_size_t resource_alignment(struct resource *res); > > + > > +/** > > + * resource_set_size - Calculates resource end address from size and s= tart 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 funct= ion. > > + * Use resource_set_range() if setting both the start address and @siz= e. > > + */ > > +static inline void resource_set_size(struct resource *res, resource_si= ze_t size) > > +{ > > +=09res->end =3D 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 @si= ze. > > + */ > > +static inline void resource_set_range(struct resource *res, > > +=09=09=09=09 resource_size_t start, > > +=09=09=09=09 resource_size_t size) > > +{ > > +=09res->start =3D start; > > +=09resource_set_size(res, size); > > +} > > + > > static inline resource_size_t resource_size(const struct resource *res= ) > > { > > =09return res->end - res->start + 1; >=20 --8323328-1916017572-1718286144=:8853--