From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: "Bjorn Helgaas" <bhelgaas@google.com>,
linux-pci@vger.kernel.org,
"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Wilczyński" <kw@linux.com>,
linux-kernel@vger.kernel.org
Cc: "Jonathan Hunter" <jonathanh@nvidia.com>,
linux-arm-kernel@lists.infradead.org,
linux-tegra@vger.kernel.org, "Robert Richter" <rric@kernel.org>,
"Thierry Reding" <thierry.reding@gmail.com>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Subject: [PATCH 1/3] resource: Add resource set range and size helpers
Date: Wed, 12 Jun 2024 11:56:27 +0300 [thread overview]
Message-ID: <20240612085629.5015-2-ilpo.jarvinen@linux.intel.com> (raw)
In-Reply-To: <20240612085629.5015-1-ilpo.jarvinen@linux.intel.com>
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 <ilpo.jarvinen@linux.intel.com>
---
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
next prev parent reply other threads:[~2024-06-12 8:57 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-12 8:56 [PATCH 0/3] PCI: Resource helper improvements Ilpo Järvinen
2024-06-12 8:56 ` Ilpo Järvinen [this message]
2024-06-12 13:48 ` [PATCH 1/3] resource: Add resource set range and size helpers Philipp Stanner
2024-06-13 13:28 ` Jonathan Cameron
2024-06-13 13:55 ` Ilpo Järvinen
2024-06-12 8:56 ` [PATCH 2/3] PCI: Use resource_set_{range,size}() helpers Ilpo Järvinen
2024-06-13 13:41 ` Jonathan Cameron
2024-06-12 8:56 ` [PATCH 3/3] PCI: Use align and resource helpers, and SZ_* in quirk_s3_64M() Ilpo Järvinen
2024-06-13 13:42 ` Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240612085629.5015-2-ilpo.jarvinen@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=bhelgaas@google.com \
--cc=jonathanh@nvidia.com \
--cc=kw@linux.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=robh@kernel.org \
--cc=rric@kernel.org \
--cc=thierry.reding@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox