Hello, I'm working on understanding how to correctly find reserved memory regions for a board using a device tree. I've read through the device tree specs found here (https://github.com/devicetree-org/devic ... s/tag/v0.4).
Section 3.5 discusses a /reserved-memory node and section 5.3 details the Memory Reservation Block. I've viewed both of these for a couple of different device trees. I'm confused because one of the device trees does not have any reserved memory blocks in the Memory Reservation Block. And for the device tree that does have something in the Memory Reservation Block, the reservation does not match what I see in the /reserved-memory node. I also see that nodes in the device tree have a unit-address and a reg property that describes the address range for the node.
So, I'm wondering what is the most correct and standard way to find what memory regions should not be used by my OS? My OS targets Arm64 architecture. The two boards I've looked at are the rk3588 and the pi3b. I appreciate any help/knowledge!
[SOLVED] Using Device Tree To Find Reserved Memory
[SOLVED] Using Device Tree To Find Reserved Memory
Last edited by CorkiMain on Fri Aug 30, 2024 2:59 pm, edited 1 time in total.
-
- Member
- Posts: 5494
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Using Device Tree To Find Reserved Memory
Going by some old emails, I'd say you have to use both the memory reservation block and the reserved-memory nodes. That seems to be what Linux does.
Re: Using Device Tree To Find Reserved Memory
I'll give that a try. Thanks!Octocontrabass wrote: ↑Wed Aug 07, 2024 9:53 pm Going by some old emails, I'd say you have to use both the memory reservation block and the reserved-memory nodes. That seems to be what Linux does.
Re: Using Device Tree To Find Reserved Memory
When a child node in a reserved-memory node has a size property, does anyone know where the memory reservation should be placed? For example, here's what the reserved-memory node looks like for a pi3b.
I got this information from the device tree specifications.
Since the device tree specs say a reservation with the size property is dynamic, and that Linux saves the reservation for later without an address, I'm guessing that the reservation is something that an OS may want to reserve (but isn't required to)? But I really have no clue! If someone has done this before and knows how to interpret the size property, I'd be grateful for that knowledge.
Code: Select all
reserved-memory {
#address-cells = <0x01>;
#size-cells = <0x01>;
ranges;
phandle = <0x38>;
linux,cma {
compatible = "shared-dma-pool";
size = <0x4000000>;
reusable;
linux,cma-default;
phandle = <0x39>;
};
};
I found that the Linux kernel saves the nodes that contain size properties. This is seen in the fdt_scan_reserved_mem function. When the function saves the node, it passes 0 for the address and size of the reservation.3.5.2 /reserved-memory/ child nodes
Each child of the reserved-memory node specifies one or more regions of reserved memory. Each child node may either
use a reg property to specify a specific range of reserved memory, or a size property with optional constraints to request
a dynamically allocated block of memory.
Following the generic-names recommended practice, node names should reflect the purpose of the node (ie. “framebuffer”
or “dma-pool”). Unit address (@<address>) should be appended to the name if the node is a static allocation.
A reserved memory node requires either a reg property for static allocations, or a size property for dynamics allocations.
Dynamic allocations may use alignment and alloc-ranges properties to constrain where the memory is allocated from.
If both reg and size are present, then the region is treated as a static allocation with the reg property taking precedence
and size is ignored.
Since the device tree specs say a reservation with the size property is dynamic, and that Linux saves the reservation for later without an address, I'm guessing that the reservation is something that an OS may want to reserve (but isn't required to)? But I really have no clue! If someone has done this before and knows how to interpret the size property, I'd be grateful for that knowledge.
-
- Member
- Posts: 5494
- Joined: Mon Mar 25, 2013 7:01 pm