summaryrefslogtreecommitdiffstats
path: root/src/device/resource_allocator_common.c
diff options
context:
space:
mode:
authorFurquan Shaikh <furquan@google.com>2020-05-15 15:43:15 -0700
committerPatrick Georgi <pgeorgi@google.com>2020-05-26 15:15:21 +0000
commit69395742b8e45433e42c54e6cf8e67a692f923e9 (patch)
tree9b54309edf00f03dd7bb6739348f548c9af86f3e /src/device/resource_allocator_common.c
parentafaae8aa00d59a1a74e7f7891d8def8cc21d9eb2 (diff)
downloadcoreboot-69395742b8e45433e42c54e6cf8e67a692f923e9.tar.gz
coreboot-69395742b8e45433e42c54e6cf8e67a692f923e9.tar.bz2
coreboot-69395742b8e45433e42c54e6cf8e67a692f923e9.zip
device: Move resource allocation into a separate compilation unit
This change moves the resource allocator functions out of device.c and into two separate files: 1. resource_allocator_v3.c: This is the old implementation of resource allocator that uses a single window for resource allocation. It is required to support some AMD chipsets that do not provide an accurate map of allocated resources by the time the allocator runs. They work fine with the old allocator since it restricts itself to allocations in a single window at the top of the 4G space. 2. resource_allocator_common.c: This file contains the functions that can be shared by the old and new resource allocator. Entry point into the resource allocation is allocate_resources() which can be implemented by both old and new allocators. This change also adds a Kconfig option RESOURCE_ALLOCATOR_V3 which enables the old resource allocator. This config option is enabled by default currently, but in the following CLs this will be enabled only for the broken boards. Reason for this split: Both the old and new resource allocators need to be retained in the tree until the broken chipsets are fixed. Change-Id: I2f5440cf83c6e9e15a5f22e79cc3c66aa2cec4c0 Signed-off-by: Furquan Shaikh <furquan@google.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/41442 Reviewed-by: Aaron Durbin <adurbin@chromium.org> Reviewed-by: Mike Banon <mikebdp2@gmail.com> Reviewed-by: Nico Huber <nico.h@gmx.de> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'src/device/resource_allocator_common.c')
-rw-r--r--src/device/resource_allocator_common.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/device/resource_allocator_common.c b/src/device/resource_allocator_common.c
new file mode 100644
index 000000000000..202318bfe6a9
--- /dev/null
+++ b/src/device/resource_allocator_common.c
@@ -0,0 +1,61 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <console/console.h>
+#include <device/device.h>
+
+struct pick_largest_state {
+ struct resource *last;
+ const struct device *result_dev;
+ struct resource *result;
+ int seen_last;
+};
+
+static void pick_largest_resource(void *gp, struct device *dev,
+ struct resource *resource)
+{
+ struct pick_largest_state *state = gp;
+ struct resource *last;
+
+ last = state->last;
+
+ /* Be certain to pick the successor to last. */
+ if (resource == last) {
+ state->seen_last = 1;
+ return;
+ }
+ if (resource->flags & IORESOURCE_FIXED)
+ return; /* Skip it. */
+ if (last && ((last->align < resource->align) ||
+ ((last->align == resource->align) &&
+ (last->size < resource->size)) ||
+ ((last->align == resource->align) &&
+ (last->size == resource->size) && (!state->seen_last)))) {
+ return;
+ }
+ if (!state->result ||
+ (state->result->align < resource->align) ||
+ ((state->result->align == resource->align) &&
+ (state->result->size < resource->size))) {
+ state->result_dev = dev;
+ state->result = resource;
+ }
+}
+
+const struct device *largest_resource(struct bus *bus,
+ struct resource **result_res,
+ unsigned long type_mask,
+ unsigned long type)
+{
+ struct pick_largest_state state;
+
+ state.last = *result_res;
+ state.result_dev = NULL;
+ state.result = NULL;
+ state.seen_last = 0;
+
+ search_bus_resources(bus, type_mask, type, pick_largest_resource,
+ &state);
+
+ *result_res = state.result;
+ return state.result_dev;
+}