allocator_v4: Manually inline some thin functions

Inline functions that are only called once to improve readability. The
calling functions still have rather short bodies, and the reader won't
have to look down yet another layer to understand what they are doing.

Change-Id: Ib4aa5d61dfa88c804a1aaee028185e00c5fbb923
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/65422
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Felix Singer <service+coreboot-gerrit@felixsinger.de>
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
This commit is contained in:
Nico Huber 2020-05-24 18:32:51 +02:00 committed by Arthur Heymans
parent ee57065dad
commit 866eff06ed
1 changed files with 22 additions and 46 deletions

View File

@ -268,27 +268,6 @@ static void compute_domain_resources(const struct device *domain)
} }
} }
static unsigned char get_alignment_by_resource_type(const unsigned long type)
{
if (type & IORESOURCE_MEM)
return 12; /* Page-aligned --> log2(4KiB) */
else if (type & IORESOURCE_IO)
return 0; /* No special alignment required --> log2(1) */
die("Unexpected resource type: flags(%lu)!\n", type);
}
static void update_constraints(struct memranges *ranges, const struct device *dev,
const struct resource *res)
{
if (!res->size)
return;
print_fixed_res(dev, res, __func__);
memranges_create_hole(ranges, res->base, res->size);
}
/* /*
* Scan the entire tree to identify any fixed resources allocated by * Scan the entire tree to identify any fixed resources allocated by
* any device to ensure that the address map for domain resources are * any device to ensure that the address map for domain resources are
@ -310,7 +289,10 @@ static void avoid_fixed_resources(struct memranges *ranges, const struct device
for (res = dev->resource_list; res != NULL; res = res->next) { for (res = dev->resource_list; res != NULL; res = res->next) {
if ((res->flags & mask_match) != mask_match) if ((res->flags & mask_match) != mask_match)
continue; continue;
update_constraints(ranges, dev, res); if (!res->size)
continue;
print_fixed_res(dev, res, __func__);
memranges_create_hole(ranges, res->base, res->size);
} }
bus = dev->link_list; bus = dev->link_list;
@ -321,28 +303,6 @@ static void avoid_fixed_resources(struct memranges *ranges, const struct device
avoid_fixed_resources(ranges, child, mask_match); avoid_fixed_resources(ranges, child, mask_match);
} }
static void constrain_domain_resources(const struct device *domain, struct memranges *ranges,
unsigned long type)
{
unsigned long mask_match = type | IORESOURCE_FIXED;
if (type == IORESOURCE_IO) {
/*
* Don't allow allocations in the VGA I/O range. PCI has special
* cases for that.
*/
memranges_create_hole(ranges, 0x3b0, 0x3df - 0x3b0 + 1);
/*
* Resource allocator no longer supports the legacy behavior where
* I/O resource allocation is guaranteed to avoid aliases over legacy
* PCI expansion card addresses.
*/
}
avoid_fixed_resources(ranges, domain, mask_match);
}
/* /*
* This function creates a list of memranges of given type using the * This function creates a list of memranges of given type using the
* resource that is provided. It applies additional constraints to * resource that is provided. It applies additional constraints to
@ -356,8 +316,10 @@ static void setup_resource_ranges(const struct device *const domain,
const unsigned long type, const unsigned long type,
struct memranges *const ranges) struct memranges *const ranges)
{ {
/* Align mem resources to 2^12 (4KiB pages) at a minimum, so they
can be memory-mapped individually (e.g. for virtualization guests). */
const unsigned char alignment = type == IORESOURCE_MEM ? 12 : 0;
const unsigned long type_mask = IORESOURCE_TYPE_MASK | IORESOURCE_FIXED; const unsigned long type_mask = IORESOURCE_TYPE_MASK | IORESOURCE_FIXED;
const unsigned char alignment = get_alignment_by_resource_type(type);
memranges_init_empty_with_alignment(ranges, NULL, 0, alignment); memranges_init_empty_with_alignment(ranges, NULL, 0, alignment);
@ -368,7 +330,21 @@ static void setup_resource_ranges(const struct device *const domain,
memranges_insert(ranges, res->base, res->limit - res->base + 1, type); memranges_insert(ranges, res->base, res->limit - res->base + 1, type);
} }
constrain_domain_resources(domain, ranges, type); if (type == IORESOURCE_IO) {
/*
* Don't allow allocations in the VGA I/O range. PCI has special
* cases for that.
*/
memranges_create_hole(ranges, 0x3b0, 0x3df - 0x3b0 + 1);
/*
* Resource allocator no longer supports the legacy behavior where
* I/O resource allocation is guaranteed to avoid aliases over legacy
* PCI expansion card addresses.
*/
}
avoid_fixed_resources(ranges, domain, type | IORESOURCE_FIXED);
print_resource_ranges(domain, ranges); print_resource_ranges(domain, ranges);
} }