1 From 9fb6fef0fb49124291837af1da5028f79d53f98e Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= <ilpo.jarvinen@linux.intel.com>
3 Date: Fri, 14 Jun 2024 13:06:03 +0300
4 Subject: [PATCH] resource: Add resource set range and size helpers
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 Setting the end address for a resource with a given size lacks a helper and
10 is therefore coded manually unlike the getter side which has a helper for
11 resource size calculation. Also, almost all callsites that calculate the
12 end address for a resource also set the start address right before it like
15 res->start = start_addr;
16 res->end = res->start + size - 1;
18 Add resource_set_range(res, start_addr, size) that sets the start address
19 and calculates the end address to simplify this often repeated fragment.
21 Also add resource_set_size() for the cases where setting the start address
22 of the resource is not necessary but mention in its kerneldoc that
23 resource_set_range() is preferred when setting both addresses.
25 Link: https://lore.kernel.org/r/20240614100606.15830-2-ilpo.jarvinen@linux.intel.com
26 Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
27 Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
28 Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
30 include/linux/ioport.h | 32 ++++++++++++++++++++++++++++++++
31 1 file changed, 32 insertions(+)
33 --- a/include/linux/ioport.h
34 +++ b/include/linux/ioport.h
35 @@ -216,6 +216,38 @@ struct resource *lookup_resource(struct
36 int adjust_resource(struct resource *res, resource_size_t start,
37 resource_size_t size);
38 resource_size_t resource_alignment(struct resource *res);
41 + * resource_set_size - Calculate resource end address from size and start
42 + * @res: Resource descriptor
43 + * @size: Size of the resource
45 + * Calculate the end address for @res based on @size.
47 + * Note: The start address of @res must be set when calling this function.
48 + * Prefer resource_set_range() if setting both the start address and @size.
50 +static inline void resource_set_size(struct resource *res, resource_size_t size)
52 + res->end = res->start + size - 1;
56 + * resource_set_range - Set resource start and end addresses
57 + * @res: Resource descriptor
58 + * @start: Start address for the resource
59 + * @size: Size of the resource
61 + * Set @res start address and calculate the end address based on @size.
63 +static inline void resource_set_range(struct resource *res,
64 + resource_size_t start,
65 + resource_size_t size)
68 + resource_set_size(res, size);
71 static inline resource_size_t resource_size(const struct resource *res)
73 return res->end - res->start + 1;