Re: Ranges - Intended use case

David Gibson
2026-02-13T06:14:35Z

[-- Attachment #1: Type: text/plain, Size: 3322 bytes --]

On Thu, Feb 12, 2026 at 01:14:33PM +0000, Kyle Bonnici wrote:
> Hi
>
> I have been trying to understand how ranges should/should not be used.
>
> Looking at the spec
>
> > The ranges property provides a means of defining a mapping or translation between the address space of the
> bus (the child address space) and the address space of the bus node’s parent (the parent address space).
>
> This to me the spec leave some space for interpretation on if ranges should be used on just buses or not. Below are some examples to try to get a better understanding.
>
> ```
> / {
> foo { // not a bus
> #address-cells = <1>;
> #size-cells = <1>;
> ranges; // does this ranges have any meaning?

An empty ranges property is a special case, which means there is an
identity mapping between parent and child. In this case, this is
invalid - / has no #address-cells or #size-cells properties, meaning
the parent bus has the default values of 2 and 1 respectively. Since
#address-cells is different from the child bus, you can't use an empty
ranges property here.

> bar@10 {
> reg<0x10 …>
> };
> };
> };
> ```
>
> ```
> / {
> foo { // not a bus

I'm not sure that there's really any hard distinction between a "bus"
and "not a bus".

> #address-cells = <1>;
> #size-cells = <1>;
> reg = <0x100 0x50>;
> ranges = <0x0 0x100 0x50>; // is this an intended use case?

It's a perfectly valid use case. In this case again, the format is
invalid since the parent's #address-cells defaults to 2. It should be:
ranges = <0x0 0x0 0x100 0x50>;

> bar@10 {
> reg<0x10 …> // hence abs address is 0x110.
> };
> };
> };
> ```
>
> ```
> / {
> foo { // bus
> compatible = <simple-bus>;
> #address-cells = <1>;
> #size-cells = <1>;
> ranges; // this I understand to declare that children will have direct mapping
>
> bar {
> ranges; // is this needed? Or is it implied that the foobar is in the same address space of bar?

It is needed. If there is no ranges property, the child registers are
not directly accessible from the parent address space (they might be
indirectly accessible via registers in the bus bridge).

This is again technically invalid: bar has no #address-cells so it
defaults to 2, which differs from the parent.

> foobar@10 {
> reg<0x10 …> // hence abs address is 0x10.
> };
> };
> };
> };
> ```
>
> ```
> / {
> soc { // bus
> compatible = <simple-bus>;
> #address-cells = <1>;
> #size-cells = <1>;
> ranges; // this I understand to declare that children will have direct mapping
>
> flash@1000 {
> reg<0x1000 …>
> ranges = <0x0 0x1000 …>;
>
> partitions {
> ranges; // is this needed? Or is it implied that the partition1 is in the same address space of partitions?
>
> partition1@10 {
> reg<0x10 …> // hence abs address is 0x1010.
> };
> };
> };
> };
> };
> ```
>
> Looking forward to explanations on this topic to extend my understanding of devicetree
>
> Regards
> Kyle

--
David Gibson (he or they) | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you, not the other way
| around.
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]