aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/resource.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/resource.c')
-rw-r--r--kernel/resource.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/kernel/resource.c b/kernel/resource.c
index 7b36976e5dea..7dc8ad24f915 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -357,6 +357,14 @@ int __weak page_is_ram(unsigned long pfn)
357 return walk_system_ram_range(pfn, 1, NULL, __is_ram) == 1; 357 return walk_system_ram_range(pfn, 1, NULL, __is_ram) == 1;
358} 358}
359 359
360static resource_size_t simple_align_resource(void *data,
361 const struct resource *avail,
362 resource_size_t size,
363 resource_size_t align)
364{
365 return avail->start;
366}
367
360/* 368/*
361 * Find empty slot in the resource tree given range and alignment. 369 * Find empty slot in the resource tree given range and alignment.
362 */ 370 */
@@ -391,8 +399,8 @@ static int find_resource(struct resource *root, struct resource *new,
391 if (tmp.end > max) 399 if (tmp.end > max)
392 tmp.end = max; 400 tmp.end = max;
393 tmp.start = ALIGN(tmp.start, align); 401 tmp.start = ALIGN(tmp.start, align);
394 if (alignf) 402
395 tmp.start = alignf(alignf_data, &tmp, size, align); 403 tmp.start = alignf(alignf_data, &tmp, size, align);
396 if (tmp.start < tmp.end && tmp.end - tmp.start >= size - 1) { 404 if (tmp.start < tmp.end && tmp.end - tmp.start >= size - 1) {
397 new->start = tmp.start; 405 new->start = tmp.start;
398 new->end = tmp.start + size - 1; 406 new->end = tmp.start + size - 1;
@@ -428,6 +436,9 @@ int allocate_resource(struct resource *root, struct resource *new,
428{ 436{
429 int err; 437 int err;
430 438
439 if (!alignf)
440 alignf = simple_align_resource;
441
431 write_lock(&resource_lock); 442 write_lock(&resource_lock);
432 err = find_resource(root, new, size, min, max, align, alignf, alignf_data); 443 err = find_resource(root, new, size, min, max, align, alignf, alignf_data);
433 if (err >= 0 && __request_resource(root, new)) 444 if (err >= 0 && __request_resource(root, new))