of: reserved_mem: Add code to dynamically allocate reserved_mem array
authorOreoluwa Babatunde <quic_obabatun@quicinc.com>
Tue, 8 Oct 2024 22:06:24 +0000 (15:06 -0700)
committerRob Herring (Arm) <robh@kernel.org>
Tue, 15 Oct 2024 15:34:33 +0000 (10:34 -0500)
commit00c9a452a235c61f099504783badd9a7675ff5a5
tree3a1ae301946efa55ce48a3af98a3707b3beecbb9
parent8a6e02d0c00e7b62e6acb74146878bb91e9e7e31
of: reserved_mem: Add code to dynamically allocate reserved_mem array

The reserved_mem array is statically allocated with a size of
MAX_RESERVED_REGIONS(64). Therefore, if the number of reserved_mem
regions exceeds this size, there will not be enough space to store
all the data.

Hence, extend the use of the static array by introducing a
dynamically allocated array based on the number of reserved memory
regions specified in the DT.

On architectures such as arm64, memblock allocated memory is not
writable until after the page tables have been setup. Hence, the
dynamic allocation of the reserved_mem array will need to be done only
after the page tables have been setup.

As a result, a temporary static array is still needed in the initial
stages to store the information of the dynamically-placed reserved
memory regions because the start address is selected only at run-time
and is not stored anywhere else.
It is not possible to wait until the reserved_mem array is allocated
because this is done after the page tables are setup and the reserved
memory regions need to be initialized before then.

After the reserved_mem array is allocated, all entries from the static
array is copied over to the new array, and the rest of the information
for the statically-placed reserved memory regions are read in from the
DT and stored in the new array as well.

Once the init process is completed, the temporary static array is
released back to the system because it is no longer needed. This is
achieved by marking it as __initdata.

Signed-off-by: Oreoluwa Babatunde <quic_obabatun@quicinc.com>
Link: https://lore.kernel.org/r/20241008220624.551309-3-quic_obabatun@quicinc.com
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
drivers/of/of_reserved_mem.c