Skip to content

Commit 59289e3

Browse files
a3fsaschahauer
authored andcommitted
memory: add support for requesting barebox area as a whole
barebox-specific code and data is normally located at the end of early-known memory. To ensure it's not overwritten, parts of it are reserved with request_sdram_region at different places. Gaps in the reservation lead to multiple issues in the past. So for documentation purposes and to avoid functiosn like memory_bank_first_find_space finding vacant area where there isn't, allow architectures call register_barebox_area to do one full SDRAM request for the area. Region requests for subsets of this area will be switched in the follow-up commit to use the new request_barebox_region, which allocates a subregion if it lies inside a registered barebox area and defers to request_sdram_region otherwise. The motivation for this patch is that with the addition of handoff data, doing separate memory reservation for every accounting structure (cookie and linked list) in addition to the data could make iomem output a bit unwieldy, but we really want to avoid anyone else overwriting it. While at it, we also rename the regions for barebox code and bss to be more descriptive. Signed-off-by: Ahmad Fatoum <[email protected]> Link: https://lore.barebox.org/[email protected] Signed-off-by: Sascha Hauer <[email protected]>
1 parent a2822ae commit 59289e3

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

common/memory.c

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,40 @@ void mem_malloc_init(void *start, void *end)
5757
mem_malloc_initialized = 1;
5858
}
5959

60+
static struct resource *barebox_res;
61+
static resource_size_t barebox_start;
62+
static resource_size_t barebox_size;
63+
64+
void register_barebox_area(resource_size_t start,
65+
resource_size_t size)
66+
{
67+
barebox_start = start,
68+
barebox_size = size;
69+
}
70+
71+
static int mem_register_barebox(void)
72+
{
73+
if (barebox_start && barebox_size)
74+
barebox_res = request_sdram_region("barebox", barebox_start,
75+
barebox_size);
76+
return 0;
77+
}
78+
postmem_initcall(mem_register_barebox);
79+
80+
struct resource *request_barebox_region(const char *name,
81+
resource_size_t start,
82+
resource_size_t size)
83+
{
84+
resource_size_t end = start + size - 1;
85+
86+
if (barebox_res && barebox_res->start <= start &&
87+
end <= barebox_res->end)
88+
return __request_region(barebox_res, start, end,
89+
name, IORESOURCE_MEM);
90+
91+
return request_sdram_region(name, start, size);
92+
}
93+
6094
static int mem_malloc_resource(void)
6195
{
6296
#if !defined __SANDBOX__
@@ -69,15 +103,15 @@ static int mem_malloc_resource(void)
69103
request_sdram_region("malloc space",
70104
malloc_start,
71105
malloc_end - malloc_start + 1);
72-
request_sdram_region("barebox",
106+
request_sdram_region("barebox code",
73107
(unsigned long)&_stext,
74108
(unsigned long)&_etext -
75109
(unsigned long)&_stext);
76110
request_sdram_region("barebox data",
77111
(unsigned long)&_sdata,
78112
(unsigned long)&_edata -
79113
(unsigned long)&_sdata);
80-
request_sdram_region("bss",
114+
request_sdram_region("barebox bss",
81115
(unsigned long)&__bss_start,
82116
(unsigned long)&__bss_stop -
83117
(unsigned long)&__bss_start);

include/memory.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,10 @@ static inline u64 memory_sdram_size(unsigned int cols,
6161
return (u64)banks * width << (rows + cols);
6262
}
6363

64+
void register_barebox_area(resource_size_t start, resource_size_t size);
65+
66+
struct resource *request_barebox_region(const char *name,
67+
resource_size_t start,
68+
resource_size_t size);
69+
6470
#endif

0 commit comments

Comments
 (0)