Skip to content

Commit 2700225

Browse files
ij-intelbjorn-helgaas
authored andcommitted
resource: Export find_resource_space()
PCI bridge window logic needs to find out in advance to the actual allocation if there is an empty space big enough to fit the window. Export find_resource_space() for the purpose. Also move the struct resource_constraint into generic header to be able to use the new interface. Link: https://lore.kernel.org/r/[email protected] Tested-by: Lidong Wang <[email protected]> Signed-off-by: Ilpo Järvinen <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Reviewed-by: Mika Westerberg <[email protected]>
1 parent 094c0ce commit 2700225

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

include/linux/ioport.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,25 @@ typedef resource_size_t (*resource_alignf)(void *data,
205205
resource_size_t size,
206206
resource_size_t align);
207207

208+
/**
209+
* struct resource_constraint - constraints to be met while searching empty
210+
* resource space
211+
* @min: The minimum address for the memory range
212+
* @max: The maximum address for the memory range
213+
* @align: Alignment for the start address of the empty space
214+
* @alignf: Additional alignment constraints callback
215+
* @alignf_data: Data provided for @alignf callback
216+
*
217+
* Contains the range and alignment constraints that have to be met during
218+
* find_resource_space(). @alignf can be NULL indicating no alignment beyond
219+
* @align is necessary.
220+
*/
221+
struct resource_constraint {
222+
resource_size_t min, max, align;
223+
resource_alignf alignf;
224+
void *alignf_data;
225+
};
226+
208227
/* PC/ISA/whatever - the normal PC address spaces: IO and memory */
209228
extern struct resource ioport_resource;
210229
extern struct resource iomem_resource;
@@ -278,6 +297,9 @@ static inline bool resource_union(const struct resource *r1, const struct resour
278297
return true;
279298
}
280299

300+
int find_resource_space(struct resource *root, struct resource *new,
301+
resource_size_t size, struct resource_constraint *constraint);
302+
281303
/* Convenience shorthand with allocation */
282304
#define request_region(start,n,name) __request_region(&ioport_resource, (start), (n), (name), 0)
283305
#define request_muxed_region(start,n,name) __request_region(&ioport_resource, (start), (n), (name), IORESOURCE_MUXED)

kernel/resource.c

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,6 @@ struct resource iomem_resource = {
4848
};
4949
EXPORT_SYMBOL(iomem_resource);
5050

51-
/**
52-
* struct resource_constraint - constraints to be met while searching empty
53-
* resource space
54-
* @min: The minimum address for the memory range
55-
* @max: The maximum address for the memory range
56-
* @align: Alignment for the start address of the empty space
57-
* @alignf: Additional alignment constraints callback
58-
* @alignf_data: Data provided for @alignf callback
59-
*
60-
* Contains the range and alignment constraints that have to be met during
61-
* find_resource_space(). @alignf can be NULL indicating no alignment beyond
62-
* @align is necessary.
63-
*/
64-
struct resource_constraint {
65-
resource_size_t min, max, align;
66-
resource_alignf alignf;
67-
void *alignf_data;
68-
};
69-
7051
static DEFINE_RWLOCK(resource_lock);
7152

7253
static struct resource *next_resource(struct resource *p, bool skip_children)
@@ -708,12 +689,13 @@ next: if (!this || this->end == root->end)
708689
* * %0 - if successful, @new members start, end, and flags are altered.
709690
* * %-EBUSY - if no empty space was found.
710691
*/
711-
static int find_resource_space(struct resource *root, struct resource *new,
712-
resource_size_t size,
713-
struct resource_constraint *constraint)
692+
int find_resource_space(struct resource *root, struct resource *new,
693+
resource_size_t size,
694+
struct resource_constraint *constraint)
714695
{
715696
return __find_resource_space(root, NULL, new, size, constraint);
716697
}
698+
EXPORT_SYMBOL_GPL(find_resource_space);
717699

718700
/**
719701
* reallocate_resource - allocate a slot in the resource tree given range & alignment.

0 commit comments

Comments
 (0)