[PATCH v1 08/54] resource: assign memory banks a default type and attr
Ahmad Fatoum
a.fatoum at pengutronix.de
Thu Dec 18 02:37:28 PST 2025
The resource_iter family of functions iterates over both resources and
the gaps between them and will inherit the parents type and attrs into
the gaps.
Give the SDRAM suitable attributes for the gaps, so users need not
special case the region_is_gap case if they are interested in collecting
all memory type and attributes.
---
common/memory.c | 4 ++++
efi/loader/memory.c | 39 +++++++++++++++++++--------------------
2 files changed, 23 insertions(+), 20 deletions(-)
diff --git a/common/memory.c b/common/memory.c
index 8974482ccb8b..0e07ba432053 100644
--- a/common/memory.c
+++ b/common/memory.c
@@ -237,6 +237,10 @@ int barebox_add_memory_bank(const char *name, resource_size_t start,
res->flags = IORESOURCE_MEM;
+ res->type = MEMTYPE_CONVENTIONAL;
+ res->attrs = MEMATTRS_NORMAL;
+ res->flags |= IORESOURCE_TYPE_VALID;
+
bank = xzalloc(sizeof(*bank));
bank->res = res;
diff --git a/efi/loader/memory.c b/efi/loader/memory.c
index 075b559367fe..6ed7f76714f9 100644
--- a/efi/loader/memory.c
+++ b/efi/loader/memory.c
@@ -121,7 +121,7 @@ static u64 efi_memory_type_default_attrs(enum efi_memory_type type)
return MEMATTRS_RW | MEMATTR_SP;
case EFI_UNUSABLE_MEMORY:
case EFI_MAX_MEMORY_TYPE:
- pr_warn("Unallocatable type %u\n", type); // FIXME
+ pr_warn("Unallocatable type %u\n", type);
return MEMATTRS_FAULT;
}
@@ -188,9 +188,8 @@ efi_status_t efi_allocate_pages(enum efi_allocate_type type,
efi_memory_type_to_resource_type(memory_type),
attrs);
if (!res) {
- pr_err("failed to request %s at page 0x%zx+%zu (%s)\n",
- namebuf, new_page, npages, typestr);
- dump_stack();
+ pr_err("failed to request %s at page 0x%llx+%zx (%s)\n",
+ namebuf, new_addr, npages << EFI_PAGE_SHIFT, typestr);
return EFI_OUT_OF_RESOURCES;
}
@@ -204,22 +203,6 @@ efi_status_t efi_allocate_pages(enum efi_allocate_type type,
return EFI_SUCCESS;
}
-static int free_efi_only(struct resource *res, void *data)
-{
- int *nfreed = data;
-
- if (!(res->flags & IORESOURCE_EFI_ALLOC)) {
- pr_warn("refusing to free non-EFI allocated resource %s at 0x%llx\n",
- res->name, res->start);
- *nfreed = -1;
- return false;
- }
-
- if (nfreed >= 0)
- ++*nfreed;
- return true;
-}
-
// SPDX-SnippetBegin
// SPDX-License-Identifier: GPL-2.0+
// SPDX-SnippetCopyrightText: 2016 Alexander Graf
@@ -281,6 +264,22 @@ void *efi_alloc_aligned_pages(u64 len, int memory_type, size_t align,
// SPDX-SnippetEnd
+static int free_efi_only(struct resource *res, void *data)
+{
+ int *nfreed = data;
+
+ if (!(res->flags & IORESOURCE_EFI_ALLOC)) {
+ pr_err("refusing to free non-EFI allocated resource %s at 0x%pap\n",
+ res->name, &res->start);
+ *nfreed = -1;
+ return false;
+ }
+
+ if (nfreed >= 0)
+ ++*nfreed;
+ return true;
+}
+
/**
* efi_free_pages() - free memory pages
*
--
2.47.3
More information about the barebox
mailing list