#size-cells = <0> in a bus node, and kernel messages complaining about this
I believe I've seen the following construct bandied about as the correct way of representing a bunch of nodes that have the same name (since they represent the same type of object) within device-tree.
regulators {
compatible = "simple-bus";
#address-cells = <1>;
#size-cells = <0>;
regulator@0 {
compatible = "regulator-fixed";
reg = <0>;
...
};
regulator@1 {
compatible = "regulator-fixed";
reg = <1>;
...
};
};However, when the kernel parses that, it issues messages such as:
prom_parse: Bad cell count for /regulators/regulator@0prom_parse: Bad cell count for /regulators/regulator@1
The message is issued when #size-cells==0. Is the response simply "don't do that", and so I should set #size-cells=1, and add a fake size cell in the reg property too?
Given the number of hits on '#size-cells = <0>' in the kernel source tree, it seems like I must be missing something here; it's quite widely used. I guess the warning is probably only emitted when the node with #size-cells=0 is a bus, and so the children are enumerated to instantiated devices; perhaps that's why this hasn't been raised before?
Quoted 22 lines · Stephen Warren
I believe I've seen the following construct bandied about as the correct way of representing a bunch of nodes that have the same name (since they represent the same type of object) within device-tree.
regulators { compatible = "simple-bus"; #address-cells = <1>; #size-cells = <0>; regulator@0 { compatible = "regulator-fixed"; reg = <0>; ... }; regulator@1 { compatible = "regulator-fixed"; reg = <1>; ... }; };
Quoted 4 lines
However, when the kernel parses that, it issues messages such as:
prom_parse: Bad cell count for /regulators/regulator@0prom_parse: Bad cell count for /regulators/regulator@1
The message comes from __of_translate_address(), which has the comment:
* Note: We consider that crossing any level with #size-cells == 0 to mean
* that translation is impossible (that is we are not dealing with a value
* that can be mapped to a cpu physical address). This is not really specified
* that way, but this is traditionally the way IBM at least do things
So it seems that the problem only occurs if something tries to translate the regulator's "reg" address to a CPU address. Is that possible/meaningful in your case?
I ran into a problem like this recently. If I recall correctly, the root cause was that some code that I "inherited" was using of_address_to_resource() to process a "reg" property in a case where the "reg" was not memory-mappable. I changed the code to use "of_get_address()" instead.
of_address_to_resource() calls of_get_address(), and then proceeds to convert the bus-relative address to a CPU address.
Quoted 15 lines
The message is issued when #size-cells==0. Is the response simply "don't do that", and so I should set #size-cells=1, and add a fake size cell in the reg property too?
Given the number of hits on '#size-cells = <0>' in the kernel source tree, it seems like I must be missing something here; it's quite widely used. I guess the warning is probably only emitted when the node with #size-cells=0 is a bus, and so the children are enumerated to instantiated devices; perhaps that's why this hasn't been raised before?
_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss
Quoted 36 lines · Mitch Bradley
Quoted 22 lines · Stephen Warren
I believe I've seen the following construct bandied about as the correct way of representing a bunch of nodes that have the same name (since they represent the same type of object) within device-tree.
regulators { compatible = "simple-bus"; #address-cells = <1>; #size-cells = <0>; regulator@0 { compatible = "regulator-fixed"; reg = <0>; ... }; regulator@1 { compatible = "regulator-fixed"; reg = <1>; ... }; };Quoted 4 lines
However, when the kernel parses that, it issues messages such as:
prom_parse: Bad cell count for /regulators/regulator@0prom_parse: Bad cell count for /regulators/regulator@1The message comes from
__of_translate_address(), which has the comment:* Note: We consider that crossing any level with #size-cells == 0 to mean
* that translation is impossible (that is we are not dealing with a value
* that can be mapped to a cpu physical address). This is not really
specified
* that way, but this is traditionally the way IBM at least do things
Quoted 4 lines
So it seems that the problem only occurs if something tries to translate the regulator's "reg" address to a CPU address. Is that possible/meaningful
in your case?
That's quite likely.
Note that the regulators node is compatible = "simple-bus", and I'm doing that so that the child regulator nodes are automatically recursed into, and a platform device created for each. Part of creating those platform devices is to convert the reg and interrupts properties to platform device resources, which is almost certainly what's calling __of_translate_address(). This is a compatibility thing on ARM; I guess pure OF-style drivers call something like of_get_address()/of_iomap() themselves in their probe() function if appropriate, rather than relying on calling platform_get_resource(), and hence forcing the DT parsing code to convert resources beforehand in all cases, even if not used.
Perhaps simple-bus could be enhanced to detect when size-cells==0 and know that this means the bus is really just a container/grouping of non-addressed objects, and hence not provide the memory resources. Or, perhaps we should introduce a new compatible value that only triggers child instantiation but not resource setup, or something like that?
Quoted 55 lines · Stephen Warren
Quoted 36 lines · Mitch Bradley
Quoted 22 lines · Stephen Warren
I believe I've seen the following construct bandied about as the correct way of representing a bunch of nodes that have the same name (since they represent the same type of object) within device-tree.
regulators { compatible = "simple-bus"; #address-cells = <1>; #size-cells = <0>; regulator@0 { compatible = "regulator-fixed"; reg = <0>; ... }; regulator@1 { compatible = "regulator-fixed"; reg = <1>; ... }; };Quoted 4 lines
However, when the kernel parses that, it issues messages such as:
prom_parse: Bad cell count for /regulators/regulator@0prom_parse: Bad cell count for /regulators/regulator@1The message comes from
__of_translate_address(), which has the comment:* Note: We consider that crossing any level with #size-cells == 0 to mean
* that translation is impossible (that is we are not dealing with a value
* that can be mapped to a cpu physical address). This is not really
specified
* that way, but this is traditionally the way IBM at least do thingsQuoted 4 lines
So it seems that the problem only occurs if something tries to translate the regulator's "reg" address to a CPU address. Is that possible/meaningful
in your case?That's quite likely.
Note that the regulators node is compatible = "simple-bus", and I'm doing that so that the child regulator nodes are automatically recursed into, and a platform device created for each. Part of creating those platform devices is to convert the reg and interrupts properties to platform device resources, which is almost certainly what's calling
__of_translate_address(). This is a compatibility thing on ARM; I guess pure OF-style drivers call something like of_get_address()/of_iomap() themselves in theirprobe()function if appropriate, rather than relying on callingplatform_get_resource(), and hence forcing the DT parsing code to convert resources beforehand in all cases, even if not used.
Quoted 5 lines
Perhaps simple-bus could be enhanced to detect when size-cells==0 and know that this means the bus is really just a container/grouping of non-addressed objects, and hence not provide the memory resources. Or, perhaps we should introduce a new compatible value that only triggers child instantiation but not resource setup, or something like that?
ISTM that if you want different semantics, a different compatible value is the best approach. My mental model is that "simple-bus" has memory-mapped children. Perhaps something like "enumerated-bus" for non-memory-mapped ?
Quoted 1 line
Quoted 66 lines · Mitch Bradley
Quoted 59 lines · Stephen Warren
Quoted 40 lines · Mitch Bradley
Quoted 24 lines · Stephen Warren
I believe I've seen the following construct bandied about as the correct
way of representing a bunch of nodes that have the same name (since they
represent the same type of object) within device-tree.regulators { compatible = "simple-bus"; #address-cells = <1>; #size-cells = <0>; regulator@0 { compatible = "regulator-fixed"; reg = <0>; ... }; regulator@1 { compatible = "regulator-fixed"; reg = <1>; ... }; };Quoted 4 lines
However, when the kernel parses that, it issues messages such as:
prom_parse: Bad cell count for /regulators/regulator@0prom_parse: Bad cell count for /regulators/regulator@1The message comes from
__of_translate_address(), which has the comment:* Note: We consider that crossing any level with #size-cells == 0
to mean
* that translation is impossible (that is we are not dealing with a
value
* that can be mapped to a cpu physical address). This is not really
specified
* that way, but this is traditionally the way IBM at least do thingsQuoted 4 lines
So it seems that the problem only occurs if something tries to translate the regulator's "reg" address to a CPU address. Is that possible/meaningful
in your case?That's quite likely.
Note that the regulators node is compatible = "simple-bus", and I'm doing that so that the child regulator nodes are automatically recursed into, and a platform device created for each. Part of creating those platform devices is to convert the reg and interrupts properties to platform device resources, which is almost certainly what's calling
__of_translate_address(). This is a compatibility thing on ARM; I guess pure OF-style drivers call something like of_get_address()/of_iomap() themselves in theirprobe()function if appropriate, rather than relying on callingplatform_get_resource(), and hence forcing the DT parsing code to convert resources beforehand in all cases, even if not used.Quoted 5 lines
Perhaps simple-bus could be enhanced to detect when size-cells==0 and know that this means the bus is really just a container/grouping of non-addressed objects, and hence not provide the memory resources. Or, perhaps we should introduce a new compatible value that only triggers child instantiation but not resource setup, or something like that?
Quoted 4 lines
ISTM that if you want different semantics, a different compatible value is the best approach. My mental model is that "simple-bus" has memory-mapped children. Perhaps something like "enumerated-bus" for non-memory-mapped ?
I just looked at the code in platform.c that calls of_translate_address() (in of_device_make_bus_id()). It appears that the reason for translating the address is to create a unique device name via:
dev_set_name(dev, "%llx.%s", addr, node->name);
Failure of_translate_address() is not treated as an error, rather the code falls back to naming the device with an incrementing number:
dev_set_name(dev, "%s.%d", node->name, magic - 1);
Perhaps the solution is add an additional step to the heuristic. If of_translate_address() fails, try to use the untranslated reg property value to make the name unique, generating a name like:
name.N,M
where N,M is a list of #address-cells numbers from the first entry of the reg property value.
That would be better than the existing heuristic (which includes the phrase "(and pray ...)" in its commentary), and fully consistent with device tree dogma.
One could still add a new compatible value to distinguish that from a "simple-bus", as platform.c has a match table that includes simple-bus and others. The heuristic for making the unique name is not contingent upon a specific bus name.
Quoted 8 lines
Quoted 2 lines
_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss
Quoted 95 lines · Mitch Bradley
Quoted 67 lines · Mitch Bradley
Quoted 60 lines · Stephen Warren
Quoted 40 lines · Mitch Bradley
Quoted 24 lines · Stephen Warren
I believe I've seen the following construct bandied about as the correct
way of representing a bunch of nodes that have the same name (since they
represent the same type of object) within device-tree.regulators { compatible = "simple-bus"; #address-cells = <1>; #size-cells = <0>; regulator@0 { compatible = "regulator-fixed"; reg = <0>; ... }; regulator@1 { compatible = "regulator-fixed"; reg = <1>; ... }; };Quoted 4 lines
However, when the kernel parses that, it issues messages such as:
prom_parse: Bad cell count for /regulators/regulator@0prom_parse: Bad cell count for /regulators/regulator@1The message comes from
__of_translate_address(), which has the comment:* Note: We consider that crossing any level with #size-cells == 0
to mean
* that translation is impossible (that is we are not dealing with a
value
* that can be mapped to a cpu physical address). This is not really
specified
* that way, but this is traditionally the way IBM at least do thingsQuoted 5 lines
So it seems that the problem only occurs if something tries to translate
the regulator's "reg" address to a CPU address. Is that possible/meaningful
in your case?That's quite likely.
Note that the regulators node is compatible = "simple-bus", and I'm doing that so that the child regulator nodes are automatically recursed into, and a platform device created for each. Part of creating those platform devices is to convert the reg and interrupts properties to platform device resources, which is almost certainly what's calling
__of_translate_address(). This is a compatibility thing on ARM; I guess pure OF-style drivers call something like of_get_address()/of_iomap() themselves in theirprobe()function if appropriate, rather than relying on callingplatform_get_resource(), and hence forcing the DT parsing code to convert resources beforehand in all cases, even if not used.Quoted 5 lines
Perhaps simple-bus could be enhanced to detect when size-cells==0 and know that this means the bus is really just a container/grouping of non-addressed objects, and hence not provide the memory resources. Or, perhaps we should introduce a new compatible value that only triggers child instantiation but not resource setup, or something like that?
Quoted 4 lines
ISTM that if you want different semantics, a different compatible value is the best approach. My mental model is that "simple-bus" has memory-mapped children. Perhaps something like "enumerated-bus" for non-memory-mapped ?
I just looked at the code in
platform.cthat callsof_translate_address()(inof_device_make_bus_id()). It appears that the reason for translating the address is to create a unique device name via:dev_set_name(dev, "%llx.%s", addr, node->name);Failure
of_translate_address()is not treated as an error, rather the code falls back to naming the device with an incrementing number:dev_set_name(dev, "%s.%d", node->name, magic - 1);Perhaps the solution is add an additional step to the heuristic. If
of_translate_address()fails, try to use the untranslated reg property value to make the name unique, generating a name like:name.N,M
where N,M is a list of #address-cells numbers from the first entry of the reg property value.
Quoted 8 lines
That would be better than the existing heuristic (which includes the phrase "(and pray ...)" in its commentary), and fully consistent with device tree dogma.
One could still add a new compatible value to distinguish that from a "simple-bus", as
platform.chas a match table that includes simple-bus and others. The heuristic for making the unique name is not contingent upon a specific bus name.
Hmmm.
1) The "KERN_ERR "prom_parse: Bad cell count ..." message is presumptuous, if one treats failure of of_translate_address() other than as a hard failure. So if the device naming heuristic were to be improved as suggested above, that message should probably be removed, or at least downgraded to a warning or debug message.
2) of_get_address() also uses OF_CHECK_COUNTS(), which is unhappy with #size-cells == 0. That's not right. #size-cells==0 is perfectly reasonable for enumerated children and should be supported.
I'm reasonably certain that the right fix is simply to remove:
if (!OF_CHECK_COUNTS(na, ns)) return NULL;
from of_get_address(). I looked at all of the places that use of_get_address(). With two exceptions, of_get_address() is followed by of_translate_address(), which will (correctly) fail if #size-cells is 0.
The two exceptions are for devices that can only exist below specific
buses, which presumably are known to have nonzero #size-cells.
Quoted 16 lines
Quoted 10 lines
Quoted 4 lines
_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss
Quoted 122 lines · Mitch Bradley
Quoted 97 lines · Mitch Bradley
Quoted 69 lines · Mitch Bradley
Quoted 62 lines · Stephen Warren
Quoted 41 lines · Mitch Bradley
Quoted 24 lines · Stephen Warren
I believe I've seen the following construct bandied about as the correct
way of representing a bunch of nodes that have the same name (since they
represent the same type of object) within device-tree.regulators { compatible = "simple-bus"; #address-cells = <1>; #size-cells = <0>; regulator@0 { compatible = "regulator-fixed"; reg = <0>; ... }; regulator@1 { compatible = "regulator-fixed"; reg = <1>; ... }; };Quoted 4 lines
However, when the kernel parses that, it issues messages such as:
prom_parse: Bad cell count for /regulators/regulator@0prom_parse: Bad cell count for /regulators/regulator@1The message comes from
__of_translate_address(), which has the comment:* Note: We consider that crossing any level with #size-cells == 0
to mean
* that translation is impossible (that is we are not dealing with a
value
* that can be mapped to a cpu physical address). This is not really
specified
* that way, but this is traditionally the way IBM at least do thingsQuoted 5 lines
So it seems that the problem only occurs if something tries to translate
the regulator's "reg" address to a CPU address. Is that possible/meaningful
in your case?That's quite likely.
Note that the regulators node is compatible = "simple-bus", and I'm doing that so that the child regulator nodes are automatically recursed into, and a platform device created for each. Part of creating those platform devices is to convert the reg and interrupts properties to platform device resources, which is almost certainly what's calling
__of_translate_address(). This is a compatibility thing on ARM; I guess pure OF-style drivers call something like of_get_address()/of_iomap() themselves in theirprobe()function if appropriate, rather than relying
on callingplatform_get_resource(), and hence forcing the DT parsing code to convert resources beforehand in all cases, even if not used.Quoted 5 lines
Perhaps simple-bus could be enhanced to detect when size-cells==0 and know that this means the bus is really just a container/grouping of non-addressed objects, and hence not provide the memory resources. Or, perhaps we should introduce a new compatible value that only triggers child instantiation but not resource setup, or something like that?
Quoted 4 lines
ISTM that if you want different semantics, a different compatible value is the best approach. My mental model is that "simple-bus" has memory-mapped children. Perhaps something like "enumerated-bus" for non-memory-mapped ?
I just looked at the code in
platform.cthat callsof_translate_address()(inof_device_make_bus_id()). It appears that the reason for translating the address is to create a unique device name via:dev_set_name(dev, "%llx.%s", addr, node->name);Failure
of_translate_address()is not treated as an error, rather the code falls back to naming the device with an incrementing number:dev_set_name(dev, "%s.%d", node->name, magic - 1);Perhaps the solution is add an additional step to the heuristic. If
of_translate_address()fails, try to use the untranslated reg property value to make the name unique, generating a name like:name.N,M
where N,M is a list of #address-cells numbers from the first entry of the reg property value.
Quoted 8 lines
That would be better than the existing heuristic (which includes the phrase "(and pray ...)" in its commentary), and fully consistent with device tree dogma.
One could still add a new compatible value to distinguish that from a "simple-bus", as
platform.chas a match table that includes simple-bus and others. The heuristic for making the unique name is not contingent upon a specific bus name.Hmmm.
1) The "
KERN_ERR"prom_parse: Bad cell count ..." message is presumptuous, if one treats failure ofof_translate_address()other than as a hard failure. So if the device naming heuristic were to be improved as suggested above, that message should probably be removed, or at least downgraded to a warning or debug message.2)
of_get_address()also usesOF_CHECK_COUNTS(), which is unhappy with #size-cells == 0. That's not right. #size-cells==0 is perfectly reasonable for enumerated children and should be supported.I'm reasonably certain that the right fix is simply to remove:
Quoted 8 lines
if (!OF_CHECK_COUNTS(na, ns)) return NULL;from
of_get_address(). I looked at all of the places that useof_get_address(). With two exceptions,of_get_address()is followed byof_translate_address(), which will (correctly) fail if #size-cells is 0.
The two exceptions are for devices that can only exist below specific
buses, which presumably are known to have nonzero #size-cells.
There's more needed than that:-(
I think of_get_address() still wants to check the address-cells value. Splitting up OF_CHECK_COUNTS as follows:
#define OF_CHECK_ADDR_COUNTS(na) ((na) > 0 && (na) <= OF_MAX_ADDR_CELLS)
#define OF_CHECK_COUNTS(na, ns) (OF_CHECK_ADDR_COUNTS(na) && (ns) > 0)
... and using OF_CHECK_ADDR_COUNTS in place of OF_CHECK_COUNTS in of_get_address() would allow that.
However, that still leaves of_device_make_bus_id() calling of_translate_address() in order to generate the device name. That will issue the diagnostic and fall back to the global counter. It seems like we could make of_device_make_bus_id() call of_get_address() instead of of_translate_address(). However, that would only give the value of the reg property, and not apply the translations all the way to the top of the tree. That in turn means that the following two nodes would be named the same:
/ {
bus-a {
compatible = "simple-bus";
ranges = <...>;
foo {
reg = <0x8000>;
};
};
bus-b {
compatible = "simple-bus";
ranges = <...>;
foo {
reg = <0x8000>;
};
};
};... since they have the same bus-local offset.
So, at /least/ we could only make that switch for nodes that were children of an "enumerated-bus" and not a "simple-bus". That'd be pretty easy to code up.
But that would still expose us to the same non-unique-name issue if those were enumerated buses:
/ {
container-a {
compatible = "enumerated-bus";
ranges = <...>;
regulator {
reg = <0>;
};
};
container-b {
compatible = "enumerated-bus";
ranges = <...>;
regulator {
reg = <0>;
};
};
};Do we need to include the full DT path to an enumerated device, or some other unique data for the node's bus, in the device name of a child of an enumerated bus?
Quoted 134 lines · Stephen Warren
Quoted 122 lines · Mitch Bradley
Quoted 97 lines · Mitch Bradley
Quoted 69 lines · Mitch Bradley
Quoted 62 lines · Stephen Warren
Quoted 41 lines · Mitch Bradley
Quoted 24 lines · Stephen Warren
I believe I've seen the following construct bandied about as the correct
way of representing a bunch of nodes that have the same name (since they
represent the same type of object) within device-tree.regulators { compatible = "simple-bus"; #address-cells = <1>; #size-cells = <0>; regulator@0 { compatible = "regulator-fixed"; reg = <0>; ... }; regulator@1 { compatible = "regulator-fixed"; reg = <1>; ... }; };Quoted 4 lines
However, when the kernel parses that, it issues messages such as:
prom_parse: Bad cell count for /regulators/regulator@0prom_parse: Bad cell count for /regulators/regulator@1The message comes from
__of_translate_address(), which has the comment:* Note: We consider that crossing any level with #size-cells == 0
to mean
* that translation is impossible (that is we are not dealing with a
value
* that can be mapped to a cpu physical address). This is not really
specified
* that way, but this is traditionally the way IBM at least do thingsQuoted 5 lines
So it seems that the problem only occurs if something tries to translate
the regulator's "reg" address to a CPU address. Is that possible/meaningful
in your case?That's quite likely.
Note that the regulators node is compatible = "simple-bus", and I'm doing that so that the child regulator nodes are automatically recursed into, and a platform device created for each. Part of creating those platform devices is to convert the reg and interrupts properties to platform device resources, which is almost certainly what's calling
__of_translate_address(). This is a compatibility thing on ARM; I guess pure OF-style drivers call something like of_get_address()/of_iomap() themselves in theirprobe()function if appropriate, rather than relying
on callingplatform_get_resource(), and hence forcing the DT parsing code to convert resources beforehand in all cases, even if not used.Quoted 5 lines
Perhaps simple-bus could be enhanced to detect when size-cells==0 and know that this means the bus is really just a container/grouping of non-addressed objects, and hence not provide the memory resources. Or, perhaps we should introduce a new compatible value that only triggers child instantiation but not resource setup, or something like that?
Quoted 4 lines
ISTM that if you want different semantics, a different compatible value is the best approach. My mental model is that "simple-bus" has memory-mapped children. Perhaps something like "enumerated-bus" for non-memory-mapped ?
I just looked at the code in
platform.cthat callsof_translate_address()(inof_device_make_bus_id()). It appears that the reason for translating the address is to create a unique device name via:dev_set_name(dev, "%llx.%s", addr, node->name);Failure
of_translate_address()is not treated as an error, rather the code falls back to naming the device with an incrementing number:dev_set_name(dev, "%s.%d", node->name, magic - 1);Perhaps the solution is add an additional step to the heuristic. If
of_translate_address()fails, try to use the untranslated reg property value to make the name unique, generating a name like:name.N,M
where N,M is a list of #address-cells numbers from the first entry of the reg property value.
Quoted 8 lines
That would be better than the existing heuristic (which includes the phrase "(and pray ...)" in its commentary), and fully consistent with device tree dogma.
One could still add a new compatible value to distinguish that from a "simple-bus", as
platform.chas a match table that includes simple-bus and others. The heuristic for making the unique name is not contingent upon a specific bus name.Hmmm.
1) The "
KERN_ERR"prom_parse: Bad cell count ..." message is presumptuous, if one treats failure ofof_translate_address()other than as a hard failure. So if the device naming heuristic were to be improved as suggested above, that message should probably be removed, or at least downgraded to a warning or debug message.2)
of_get_address()also usesOF_CHECK_COUNTS(), which is unhappy with #size-cells == 0. That's not right. #size-cells==0 is perfectly reasonable for enumerated children and should be supported.I'm reasonably certain that the right fix is simply to remove:
Quoted 8 lines
if (!OF_CHECK_COUNTS(na, ns)) return NULL;from
of_get_address(). I looked at all of the places that useof_get_address(). With two exceptions,of_get_address()is followed byof_translate_address(), which will (correctly) fail if #size-cells is 0.
The two exceptions are for devices that can only exist below specific
buses, which presumably are known to have nonzero #size-cells.There's more needed than that:-(
Quoted 8 lines
I think
of_get_address()still wants to check the address-cells value. Splitting upOF_CHECK_COUNTSas follows:#define
OF_CHECK_ADDR_COUNTS(na)((na) > 0 && (na) <=OF_MAX_ADDR_CELLS)
#defineOF_CHECK_COUNTS(na, ns)(OF_CHECK_ADDR_COUNTS(na)&& (ns) > 0)... and using
OF_CHECK_ADDR_COUNTSin place ofOF_CHECK_COUNTSinof_get_address()would allow that.
I agree.
Quoted 4 lines
However, that still leaves
of_device_make_bus_id()callingof_translate_address()in order to generate the device name. That will issue the diagnostic and fall back to the global counter.
My suggestion was to eliminate the diagnostic message or downgrade it to warning or debug level. Then the naming heuristic would be:
First try of_translate_address() to get a globally-unique address. Failing that, try of_get_address() to get a locally-unique bound
address.
Failing that, use a counter.
It seems like
Quoted 49 lines
we could make
of_device_make_bus_id()callof_get_address()instead ofof_translate_address(). However, that would only give the value of the reg property, and not apply the translations all the way to the top of the tree. That in turn means that the following two nodes would be named the same:/ { bus-a { compatible = "simple-bus"; ranges = <...>; foo { reg = <0x8000>; }; }; bus-b { compatible = "simple-bus"; ranges = <...>; foo { reg = <0x8000>; }; }; };... since they have the same bus-local offset.
So, at /least/ we could only make that switch for nodes that were children of an "enumerated-bus" and not a "simple-bus". That'd be pretty easy to code up.
But that would still expose us to the same non-unique-name issue if those were enumerated buses:
/ { container-a { compatible = "enumerated-bus"; ranges = <...>; regulator { reg = <0>; }; }; container-b { compatible = "enumerated-bus"; ranges = <...>; regulator { reg = <0>; }; }; };
Quoted 3 lines
Do we need to include the full DT path to an enumerated device, or some other unique data for the node's bus, in the device name of a child of an enumerated bus?
I don't know. Is the device name space flat?
Quoted 2 lines · Mitch Bradley
Quoted 1 line · Stephen Warren
On 06/28/2012 02:28 PM, Mitch Bradley wrote:
...
Quoted 40 lines
Quoted 25 lines
Quoted 14 lines
Hmmm.
1) The "
KERN_ERR"prom_parse: Bad cell count ..." message is presumptuous, if one treats failure ofof_translate_address()other than as a hard failure. So if the device naming heuristic were to be improved as suggested above, that message should probably be removed, or at least downgraded to a warning or debug message.2)
of_get_address()also usesOF_CHECK_COUNTS(), which is unhappy with #size-cells == 0. That's not right. #size-cells==0 is perfectly reasonable for enumerated children and should be supported.I'm reasonably certain that the right fix is simply to remove:
Quoted 8 lines
if (!OF_CHECK_COUNTS(na, ns)) return NULL;from
of_get_address(). I looked at all of the places that useof_get_address(). With two exceptions,of_get_address()is followed byof_translate_address(), which will (correctly) fail if #size-cells is 0.
The two exceptions are for devices that can only exist below specific
buses, which presumably are known to have nonzero #size-cells.There's more needed than that:-(
Quoted 8 lines
I think
of_get_address()still wants to check the address-cells value. Splitting upOF_CHECK_COUNTSas follows:#define
OF_CHECK_ADDR_COUNTS(na)((na) > 0 && (na) <=OF_MAX_ADDR_CELLS)
#defineOF_CHECK_COUNTS(na, ns)(OF_CHECK_ADDR_COUNTS(na)&& (ns) > 0)... and using
OF_CHECK_ADDR_COUNTSin place ofOF_CHECK_COUNTSinof_get_address()would allow that.I agree.
Quoted 3 lines
However, that still leaves
of_device_make_bus_id()callingof_translate_address()in order to generate the device name. That will issue the diagnostic and fall back to the global counter.
Quoted 7 lines
My suggestion was to eliminate the diagnostic message or downgrade it to warning or debug level. Then the naming heuristic would be:
First try
of_translate_address()to get a globally-unique address. Failing that, tryof_get_address()to get a locally-unique bound
address.
Failing that, use a counter.
Ah yes.
I'd somewhat prefer to avoid calling of_translate_address() when we know it's going to fail though, by passing a parameter to of_device_make_bus_id() indicating whether to use that or of_get_address(). The parameter would be set based on enumerated-bus vs. any other bus type. I coded that locally and it seems to work OK. That way, the diagnostic in of_translate_address() can be left unchanged; it seems like it really is an error.
Quoted 6 lines
Quoted 6 lines
It seems like
we could makeof_device_make_bus_id()callof_get_address()instead ofof_translate_address(). However, that would only give the value of the reg property, and not apply the translations all the way to the top of the tree. That in turn means that the following two nodes would be named the same:
...
Quoted 20 lines
Quoted 20 lines
But that would still expose us to the same non-unique-name issue if those were enumerated buses:
/ { container-a { compatible = "enumerated-bus"; ranges = <...>; regulator { reg = <0>; }; }; container-b { compatible = "enumerated-bus"; ranges = <...>; regulator { reg = <0>; }; }; };
Quoted 5 lines
Quoted 3 lines
Do we need to include the full DT path to an enumerated device, or some other unique data for the node's bus, in the device name of a child of an enumerated bus?
I don't know. Is the device name space flat?
Hmmm. It depends on where you look.
I end up with /sys/devices/regulators.3/[01].regulator/ this way, the path structure of which is defined by the parent/child device relationship, and implies that device names are relative to their parent.
However, device names are treated as a flat namespace in many other places. For example, clocks, regulators, pinctrl settings, etc. are looked up by device name, and the names in the lookup tables are just the device name itself, with no reference to the device's parent.
Quoted 9 lines · Stephen Warren
Quoted 2 lines · Mitch Bradley
Quoted 1 line · Stephen Warren
On 06/28/2012 02:28 PM, Mitch Bradley wrote:
...
Quoted 1 line
Quoted 1 line
Quoted 1 line
Hmmm....
Ah yes.
Quoted 7 lines
I'd somewhat prefer to avoid calling
of_translate_address()when we know it's going to fail though, by passing a parameter toof_device_make_bus_id()indicating whether to use that orof_get_address(). The parameter would be set based on enumerated-bus vs. any other bus type. I coded that locally and it seems to work OK. That way, the diagnostic inof_translate_address()can be left unchanged; it seems like it really is an error.
Win.
Quoted 10 lines
...
Quoted 5 lines
Quoted 3 lines
Do we need to include the full DT path to an enumerated device, or some other unique data for the node's bus, in the device name of a child of an enumerated bus?
I don't know. Is the device name space flat?
Hmmm. It depends on where you look.
Quoted 8 lines
I end up with /sys/devices/regulators.3/[01].regulator/ this way, the path structure of which is defined by the parent/child device relationship, and implies that device names are relative to their parent.
However, device names are treated as a flat namespace in many other places. For example, clocks, regulators, pinctrl settings, etc. are looked up by device name, and the names in the lookup tables are just the device name itself, with no reference to the device's parent.
The world in general seems to manage just fine with namespaces that are sometimes fully-qualified but more often at least partially ambiguous. Personally, I find that scrupulous avoidance of ambiguity - with dotted namespaces or hashes - ends up being hard for humans (or at least this human) to deal with. So maybe it's okay if we don't fully address this problem.
Quoted 55 lines · Stephen Warren
Quoted 36 lines · Mitch Bradley
Quoted 22 lines · Stephen Warren
I believe I've seen the following construct bandied about as the correct way of representing a bunch of nodes that have the same name (since they represent the same type of object) within device-tree.
regulators { compatible = "simple-bus"; #address-cells = <1>; #size-cells = <0>; regulator@0 { compatible = "regulator-fixed"; reg = <0>; ... }; regulator@1 { compatible = "regulator-fixed"; reg = <1>; ... }; };Quoted 4 lines
However, when the kernel parses that, it issues messages such as:
prom_parse: Bad cell count for /regulators/regulator@0prom_parse: Bad cell count for /regulators/regulator@1The message comes from
__of_translate_address(), which has the comment:* Note: We consider that crossing any level with #size-cells == 0 to mean
* that translation is impossible (that is we are not dealing with a value
* that can be mapped to a cpu physical address). This is not really
specified
* that way, but this is traditionally the way IBM at least do thingsQuoted 4 lines
So it seems that the problem only occurs if something tries to translate the regulator's "reg" address to a CPU address. Is that possible/meaningful
in your case?That's quite likely.
Note that the regulators node is compatible = "simple-bus", and I'm doing that so that the child regulator nodes are automatically recursed into, and a platform device created for each. Part of creating those platform devices is to convert the reg and interrupts properties to platform device resources, which is almost certainly what's calling
__of_translate_address(). This is a compatibility thing on ARM; I guess pure OF-style drivers call something like of_get_address()/of_iomap() themselves in theirprobe()function if appropriate, rather than relying on callingplatform_get_resource(), and hence forcing the DT parsing code to convert resources beforehand in all cases, even if not used.
Quoted 3 lines
Perhaps simple-bus could be enhanced to detect when size-cells==0 and know that this means the bus is really just a container/grouping of non-addressed objects, and hence not provide the memory resources.
That definitely doesn't make sense. The device tree already expresses whether a bus is mapped into the top-level address space in the absence of ranges properties in the parent bus.
Signature · 4 lines
David Gibson | 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