I have been working on devicetree stuff for my kernel recently.
Currently I am trying to handle the properties of a devicetree memory node.
For anyone that wants to know more about that, feel free to take a look at my devicetree branch and at the devicetree spec.
So, there is the reg
property which is an array consisting of (address, length)
pairs. address
and length
for each item are big-endian integers that have a size specified in the address-cells
and size-cells
properties (they specify how many u32
cells one address or size/length property takes).
The problem is that those sizes are runtime-known and, as the sizes are a 32-bit unsigned integer, the properties can take very much space (in theory).
As I am discovering the available memory using the devicetree, I can’t use an allocator safely.
I thought of two approaches to handle this problem:
- Use an union for integer types and a function that returns matching tags for that union
- Just reading until a normal
usize
is full (because an address with more bits thanusize
would be unnecessary)
The problem with (1) would be that the union could get very long (a zig integer has up to 65536 bit length possibilities as seen in the standard library and we can only use each 32nd length, so there are 65536/32=2048 different tags for the enum behind the union).
The problem with (2) would be that it isn’t fully conformant.
Any further approaches / ideas about my approaches?