2024-06-14 12:36:53

by Ilpo Järvinen

[permalink] [raw]
Subject: [PATCH v2 0/4] PCI: Resource helper improvements

This series introduces resource_set_{range,size}() helpers to replace
often repeated code fragments to set resource start and end addresses.
The last two patches clean up nearby code.

For now, this series only converts PCI subsystem. There are plenty of
resource start/end setting code elsewhere in the kernel but those can
be converted once the helpers reach Linus' tree.

--
v2:
- Improved commit message
- Added patch to introduce ALIGN_DOWN_IF_NONZERO()

Ilpo Järvinen (4):
resource: Add resource set range and size helpers
PCI: Use resource_set_{range,size}() helpers
PCI: Use align and resource helpers, and SZ_* in quirk_s3_64M()
PCI: Introduce ALIGN_DOWN_IF_NONZERO() helper locally

drivers/pci/controller/pci-tegra.c | 2 +-
drivers/pci/controller/pci-thunder-pem.c | 4 +--
drivers/pci/ecam.c | 2 +-
drivers/pci/iov.c | 6 ++--
drivers/pci/pci.c | 3 +-
drivers/pci/quirks.c | 23 +++++++---------
drivers/pci/setup-bus.c | 35 ++++++++++--------------
drivers/pci/setup-res.c | 7 ++---
include/linux/ioport.h | 32 ++++++++++++++++++++++
9 files changed, 68 insertions(+), 46 deletions(-)

--
2.39.2



2024-06-14 13:08:00

by Ilpo Järvinen

[permalink] [raw]
Subject: [PATCH v2 1/4] resource: Add resource set range and size helpers

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 <[email protected]>
Reviewed-by: Jonathan Cameron <[email protected]>
---
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