dm: ensure device names are unique
RFC PATCH 1/1 dm: ensure device names are unique
From: Stephen Warren <[email protected]>
It is possible for HW to contain multiple instances of the same device. In this case, the name passed to device_bind() may not be unique across all devices within its uclass. One example is a system with multiple identical PCI Ethernet devices. Another might be a system with multiple identical I2C GPIO expanders, each connected to a separate I2C bus, yet using the same I2C address on that bus and hence having the same DT node name.
Enhance the code to detect this situation, and append a sequence number so the device name to ensure uniqueness.
---
Some possible issues with this patch:
1) Doing this in bind() rather than probe() means dev->seq isn't available, so can't be used to generate the unique name. This process should be done during bind() rather than probe() though, since devices can be seen (e.g. by running "dm tree") before they're probed. Perhaps the uclass_resolve_seq() should be called by bind() not probe().
2) uclass_find_device_by_name() needs to look up the uclass pointer again even though device_bind() already knows it.
3) Iterating over the list to find the count of devices in the uclass is a bit annoying. Should the uclass maintain this count so it doesn't need to be re-calculated each time?
--- drivers/core/device-remove.c | 4 ++++ drivers/core/device.c | 23 ++++++++++++++++++++++- include/dm/device.h | 3 +++ 3 files changed, 29 insertions(+), 1 deletion(-)
drivers/core/device-remove.c +4 -0
@@ -112,6 +112,10 @@ int device_unbind(struct udevice *dev)devres_release_all (dev); +if (dev->flags &DM_FLAG_ALLOC_NAME ) { +free ((char *)dev->name); + dev->name =NULL ; + }free (dev);return 0 ;
drivers/core/device.c +22 -1
@@ -30,7 +30,7 @@ int device_bind(struct udevice *parent, const struct driver *drv, const char *name, void *platdata, int of_offset, struct udevice **devp) { - struct udevice *dev; + struct udevice *dev, *dev2;struct uclass *uc;int size, ret =0 ;
@@ -62,6 +62,23 @@ int device_bind(struct udevice *parent, const struct driver *drv, dev->driver = drv; dev->uclass = uc; +if (!uclass_find_device_by_name (uc->uc_drv->id, dev->name, &dev2)) { +char *unique_name; +int count; + size =strlen (name) +4 +1 ; + unique_name =malloc (size); +if (!unique_name) { + ret = -ENOMEM ; + goto fail_alloc1; + } + dev->flags |=DM_FLAG_ALLOC_NAME ; + dev->name = unique_name; + count =0 ; +list_for_each_entry (dev2, &uc->dev_head, uclass_node) + count++; +snprintf (unique_name, size,"%s.%d" , name, count); + } + dev->seq =-1 ; dev->req_seq =-1 ;if (CONFIG_IS_ENABLED (OF_CONTROL ) &&CONFIG_IS_ENABLED (DM_SEQ_ALIAS )) {
@@ -186,6 +203,10 @@ fail_alloc2: dev->platdata =NULL ; } fail_alloc1: +if (dev->flags &DM_FLAG_ALLOC_NAME ) { +free ((char *)dev->name); + dev->name =NULL ; + }devres_release_all (dev);free (dev);
include/dm/device.h +3 -0
@@ -41,6 +41,9 @@ struct driver_info;/* Device is bound */ #define DM_FLAG_BOUND (1 << 6) +/* DM is responsible for allocating and freeing device name */ +#define DM_FLAG_ALLOC_NAME (1 << 7) +/** * struct udevice - An instance of a driver *
Signature · 1 line
2.8.1
RFC PATCH 1/1 dm: ensure device names are unique
Quoted 22 lines · Stephen Warren
From: Stephen Warren <[email protected]>
It is possible for HW to contain multiple instances of the same device. In this case, the name passed to
device_bind()may not be unique across all devices within its uclass. One example is a system with multiple identical PCI Ethernet devices. Another might be a system with multiple identical I2C GPIO expanders, each connected to a separate I2C bus, yet using the same I2C address on that bus and hence having the same DT node name.Enhance the code to detect this situation, and append a sequence number so the device name to ensure uniqueness.
Signed-off-by Stephen Warren <[email protected]>---
Some possible issues with this patch:1) Doing this in
bind()rather thanprobe()meansdev->seqisn't available, so can't be used to generate the unique name. This process should be done duringbind()rather thanprobe()though, since devices can be seen (e.g. by running "dm tree") before they're probed. Perhaps theuclass_resolve_seq()should be called bybind()notprobe().
Quoted 6 lines
2)
uclass_find_device_by_name()needs to look up the uclass pointer again even thoughdevice_bind()already knows it.3) Iterating over the list to find the count of devices in the uclass is a bit annoying. Should the uclass maintain this count so it doesn't need to be re-calculated each time?
4) This causes "ut dm autobind" to fail. I'll investigate that locally, but won't bother reposting until the questions above are considered.
RFC PATCH 1/1 dm: ensure device names are unique
Quoted 30 lines · Stephen Warren
Quoted 29 lines · Stephen Warren
From: Stephen Warren <[email protected]>
It is possible for HW to contain multiple instances of the same device. In
this case, the name passed todevice_bind()may not be unique across all devices within its uclass. One example is a system with multiple identical
PCI Ethernet devices. Another might be a system with multiple identical I2C GPIO expanders, each connected to a separate I2C bus, yet using the same I2C address on that bus and hence having the same DT node name.Enhance the code to detect this situation, and append a sequence number so
the device name to ensure uniqueness.Signed-off-by Stephen Warren <[email protected]>---
Some possible issues with this patch:1) Doing this in
bind()rather thanprobe()meansdev->seqisn't available, so can't be used to generate the unique name. This process should be done duringbind()rather thanprobe()though, since devices can
be seen (e.g. by running "dm tree") before they're probed. Perhaps theuclass_resolve_seq()should be called bybind()notprobe().2)
uclass_find_device_by_name()needs to look up the uclass pointer again even thoughdevice_bind()already knows it.
Quoted 7 lines
Quoted 4 lines
3) Iterating over the list to find the count of devices in the uclass is a
bit annoying. Should the uclass maintain this count so it doesn't need to be re-calculated each time?4) This causes "ut dm autobind" to fail. I'll investigate that locally, but won't bother reposting until the questions above are considered.
It looks like that's because I need to add "gd->dm_root && " to the start of the following condition:
drivers/core/device.c int device_bind(struct udevice *parent, const struct driver *drv, · line 65
Quoted 5 lines
drivers/core/device.c +1
-0@@ -62,6 +62,23 @@ int device_bind(struct udevice *parent, const struct driver *drv, dev->driver = drv; dev->uclass = uc; +if (!uclass_find_device_by_name (uc->uc_drv->id, dev->name, &dev2)) {
... otherwise, the uc_class_get/find() nested inside that end up creating a second root uclass.
I can fold that into v2, pending any other comments.
RFC PATCH 1/1 dm: ensure device names are unique
Quoted 51 lines · Stephen Warren
Quoted 32 lines · Stephen Warren
Quoted 30 lines · Stephen Warren
From: Stephen Warren <[email protected]>
It is possible for HW to contain multiple instances of the same device. In
this case, the name passed todevice_bind()may not be unique across all devices within its uclass. One example is a system with multiple identical
PCI Ethernet devices. Another might be a system with multiple identical I2C GPIO expanders, each connected to a separate I2C bus, yet using the same I2C address on that bus and hence having the same DT node name.Enhance the code to detect this situation, and append a sequence number so
the device name to ensure uniqueness.Signed-off-by Stephen Warren <[email protected]>---
Some possible issues with this patch:1) Doing this in
bind()rather thanprobe()meansdev->seqisn't available, so can't be used to generate the unique name. This process should be done duringbind()rather thanprobe()though, since devices can
be seen (e.g. by running "dm tree") before they're probed. Perhaps theuclass_resolve_seq()should be called bybind()notprobe().2)
uclass_find_device_by_name()needs to look up the uclass pointer again even thoughdevice_bind()already knows it.Quoted 8 lines
Quoted 4 lines
3) Iterating over the list to find the count of devices in the uclass is a
bit annoying. Should the uclass maintain this count so it doesn't need to be re-calculated each time?4) This causes "ut dm autobind" to fail. I'll investigate that locally, but won't bother reposting until the questions above are considered.
It looks like that's because I need to add "
gd->dm_root&& " to the start of the following condition:Quoted 5 lines
drivers/core/device.c +0
-0@@ -62,6 +62,23 @@ int device_bind(struct udevice *parent, const struct driver *drv, dev->driver = drv; dev->uclass = uc;
Quoted 6 lines
Review int device_bind(struct udevice *parent, const struct · line 67
Quoted 2 lines
(quoted diff) +1
-0+ if (!uclass_find_device_by_name(uc->uc_drv->id, dev->name, &dev2)) {... otherwise, the uc_class_get/find() nested inside that end up creating a second root uclass.
Makes sense.
Quoted 6 lines
I can fold that into v2, pending any other comments.
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot
RFC PATCH 1/1 dm: ensure device names are unique
In reply to Stephen WarrenQuoted 13 lines · Stephen Warren
From: Stephen Warren <[email protected]>
It is possible for HW to contain multiple instances of the same device. In this case, the name passed to
device_bind()may not be unique across all devices within its uclass. One example is a system with multiple identical PCI Ethernet devices. Another might be a system with multiple identical I2C GPIO expanders, each connected to a separate I2C bus, yet using the same I2C address on that bus and hence having the same DT node name.Enhance the code to detect this situation, and append a sequence number so the device name to ensure uniqueness.
Signed-off-by Stephen Warren <[email protected]>
Quoted 8 lines
---
Some possible issues with this patch:1) Doing this in
bind()rather thanprobe()meansdev->seqisn't available, so can't be used to generate the unique name. This process should be done duringbind()rather thanprobe()though, since devices can be seen (e.g. by running "dm tree") before they're probed. Perhaps theuclass_resolve_seq()should be called bybind()notprobe().
We (Simon and I) had discussion about this when I first added support for eth devices. He convinced me the correct time for seq to be evaluated is at probe time. I can dig through the mail history for reasons if you're interested.
Quoted 2 lines
2)
uclass_find_device_by_name()needs to look up the uclass pointer again even thoughdevice_bind()already knows it.
Maybe we could add a parameter to provide the pointer and if it's NULL, then it gets looked up. Might be a bit noisy change, though. Is that optimization very valuable?
Quoted 3 lines
3) Iterating over the list to find the count of devices in the uclass is a bit annoying. Should the uclass maintain this count so it doesn't need to be re-calculated each time?
These lists aren't long, right? It seems like the optimization to store the value is only helpful if the lists could be expected to be long, or the size is looked up many times.
Quoted 89 lines
drivers/core/device-remove.c | 4 ++++ drivers/core/device.c | 23 ++++++++++++++++++++++- include/dm/device.h | 3 +++ 3 files changed, 29 insertions(+), 1 deletion(-)drivers/core/device-remove.c +4
-0@@ -112,6 +112,10 @@ int device_unbind(struct udevice *dev)devres_release_all (dev); +if (dev->flags &DM_FLAG_ALLOC_NAME ) { +free ((char *)dev->name); + dev->name =NULL ; + }free (dev);return 0 ;drivers/core/device.c +22
-1@@ -30,7 +30,7 @@ int device_bind(struct udevice *parent, const struct driver *drv, const char *name, void *platdata, int of_offset, struct udevice **devp) { - struct udevice *dev; + struct udevice *dev, *dev2;struct uclass *uc;int size, ret =0 ;@@ -62,6 +62,23 @@ int device_bind(struct udevice *parent, const struct driver *drv, dev->driver = drv; dev->uclass = uc; +if (!uclass_find_device_by_name (uc->uc_drv->id, dev->name, &dev2)) { +char *unique_name; +int count; + size =strlen (name) +4 +1 ; + unique_name =malloc (size); +if (!unique_name) { + ret = -ENOMEM ; + goto fail_alloc1; + } + dev->flags |=DM_FLAG_ALLOC_NAME ; + dev->name = unique_name; + count =0 ; +list_for_each_entry (dev2, &uc->dev_head, uclass_node) + count++; +snprintf (unique_name, size,"%s.%d" , name, count); + } + dev->seq =-1 ; dev->req_seq =-1 ;if (CONFIG_IS_ENABLED (OF_CONTROL ) &&CONFIG_IS_ENABLED (DM_SEQ_ALIAS )) {@@ -186,6 +203,10 @@ fail_alloc2: dev->platdata =NULL ; } fail_alloc1: +if (dev->flags &DM_FLAG_ALLOC_NAME ) { +free ((char *)dev->name); + dev->name =NULL ; + }devres_release_all (dev);free (dev);include/dm/device.h +3
-1@@ -41,6 +41,9 @@ struct driver_info;/* Device is bound */ #define DM_FLAG_BOUND (1 << 6) +/* DM is responsible for allocating and freeing device name */ +#define DM_FLAG_ALLOC_NAME (1 << 7) +/** * struct udevice - An instance of a driver * -- 2.8.1
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot
RFC PATCH 1/1 dm: ensure device names are unique
Quoted 23 lines · Joe Hershberger
Quoted 13 lines · Stephen Warren
From: Stephen Warren <[email protected]>
It is possible for HW to contain multiple instances of the same device. In this case, the name passed to
device_bind()may not be unique across all devices within its uclass. One example is a system with multiple identical PCI Ethernet devices. Another might be a system with multiple identical I2C GPIO expanders, each connected to a separate I2C bus, yet using the same I2C address on that bus and hence having the same DT node name.Enhance the code to detect this situation, and append a sequence number so the device name to ensure uniqueness.
Signed-off-by Stephen Warren <[email protected]>Quoted 8 lines
---
Some possible issues with this patch:1) Doing this in
bind()rather thanprobe()meansdev->seqisn't available, so can't be used to generate the unique name. This process should be done duringbind()rather thanprobe()though, since devices can be seen (e.g. by running "dm tree") before they're probed. Perhaps theuclass_resolve_seq()should be called bybind()notprobe().
Quoted 4 lines
We (Simon and I) had discussion about this when I first added support for eth devices. He convinced me the correct time for seq to be evaluated is at probe time. I can dig through the mail history for reasons if you're interested.
That might be interesting. Right now, about the only thing I see moving the evaluation from probe to bind would do is very marginally increase the amount of work done in bind, which potentially might be skipped if a particular Ethernet device was never probed. I would not expect this to make a noticeable difference, especially since IIRC when the network is first used, all the Ethernet devices are probed anyway, so this just moves work around?
Quoted 6 lines
Quoted 2 lines
2)
uclass_find_device_by_name()needs to look up the uclass pointer again even thoughdevice_bind()already knows it.Maybe we could add a parameter to provide the pointer and if it's NULL, then it gets looked up. Might be a bit noisy change, though. Is that optimization very valuable?
I don't imagine there are too many uclasses, so it's probably not going to save too much time. Still, Simon has in the past objected to code that parses DT scanning the DT to find parent offsets, and this feels like exactly the same kind of thing. I'm not personally concerned about it; simply pointing it out in case anyone wanted that to be addressed.
Quoted 7 lines
Quoted 3 lines
3) Iterating over the list to find the count of devices in the uclass is a bit annoying. Should the uclass maintain this count so it doesn't need to be re-calculated each time?
These lists aren't long, right? It seems like the optimization to store the value is only helpful if the lists could be expected to be long, or the size is looked up many times.
Yes, I don't imagine this would be a particular issue in practice.
RFC PATCH 1/1 dm: ensure device names are unique
Hi Stephen,
Quoted 28 lines · Stephen Warren
Quoted 26 lines · Joe Hershberger
Quoted 22 lines · Stephen Warren
From: Stephen Warren <[email protected]>
It is possible for HW to contain multiple instances of the same device. In this case, the name passed to
device_bind()may not be unique across all devices within its uclass. One example is a system with multiple identical PCI Ethernet devices. Another might be a system with multiple identical I2C GPIO expanders, each connected to a separate I2C bus, yet using the same I2C address on that bus and hence having the same DT node name.Enhance the code to detect this situation, and append a sequence number so the device name to ensure uniqueness.
Signed-off-by Stephen Warren <[email protected]>---
Some possible issues with this patch:1) Doing this in
bind()rather thanprobe()meansdev->seqisn't available, so can't be used to generate the unique name. This process should be done duringbind()rather thanprobe()though, since devices can be seen (e.g. by running "dm tree") before they're probed. Perhaps theuclass_resolve_seq()should be called bybind()notprobe().
Quoted 7 lines
Quoted 4 lines
We (Simon and I) had discussion about this when I first added support for eth devices. He convinced me the correct time for seq to be evaluated is at probe time. I can dig through the mail history for reasons if you're interested.
That might be interesting. Right now, about the only thing I see moving the evaluation from probe to bind would do is very marginally increase the amount of work done in bind, which potentially might be skipped if a particular Ethernet device was never probed. I would not expect this to make a noticeable difference, especially since IIRC when the network is first used, all the Ethernet devices are probed anyway, so this just moves work around?
There's a somewhat deep design issue there, but so far I feel that having the numbering resolved when a device is probed works best. It is very seldom useful until then. Device names don't really need to match there sequence number.
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
2)
uclass_find_device_by_name()needs to look up the uclass pointer again even thoughdevice_bind()already knows it.
Quoted 15 lines
Quoted 3 lines
Maybe we could add a parameter to provide the pointer and if it's NULL, then it gets looked up. Might be a bit noisy change, though. Is that optimization very valuable?
I don't imagine there are too many uclasses, so it's probably not going to save too much time. Still, Simon has in the past objected to code that parses DT scanning the DT to find parent offsets, and this feels like exactly the same kind of thing. I'm not personally concerned about it; simply pointing it out in case anyone wanted that to be addressed.
Quoted 8 lines
Quoted 3 lines
3) Iterating over the list to find the count of devices in the uclass is a bit annoying. Should the uclass maintain this count so it doesn't need to be re-calculated each time?
These lists aren't long, right? It seems like the optimization to store the value is only helpful if the lists could be expected to be long, or the size is looked up many times.
There are essentially no optimisations in driver model at present. So far the benefit hasn't shown itself. Perhaps it won't in a boot loader...
Quoted 3 lines
Yes, I don't imagine this would be a particular issue in practice.
Regards,
Simon
RFC PATCH 1/1 dm: ensure device names are unique
In reply to Stephen WarrenHi Stephen,
Quoted 23 lines · Stephen Warren
It is possible for HW to contain multiple instances of the same device. In this case, the name passed to
device_bind()may not be unique across all devices within its uclass. One example is a system with multiple identical PCI Ethernet devices. Another might be a system with multiple identical I2C GPIO expanders, each connected to a separate I2C bus, yet using the same I2C address on that bus and hence having the same DT node name.Enhance the code to detect this situation, and append a sequence number so the device name to ensure uniqueness.
Signed-off-by Stephen Warren <[email protected]>---
Some possible issues with this patch:1) Doing this in
bind()rather thanprobe()meansdev->seqisn't available, so can't be used to generate the unique name. This process should be done duringbind()rather thanprobe()though, since devices can be seen (e.g. by running "dm tree") before they're probed. Perhaps theuclass_resolve_seq()should be called bybind()notprobe().2)
uclass_find_device_by_name()needs to look up the uclass pointer again even thoughdevice_bind()already knows it.
Quoted 8 lines
3) Iterating over the list to find the count of devices in the uclass is a bit annoying. Should the uclass maintain this count so it doesn't need to be re-calculated each time?
---drivers/core/device-remove.c| 4 ++++drivers/core/device.c| 23 ++++++++++++++++++++++-include/dm/device.h| 3 +++3 files changed, 29 insertions(+), 1 deletion(-)
I would rather that the caller handles this. But failing this perhaps a new function that does it? Is this for the Ethernet use case?
Regards,
Simon
RFC PATCH 1/1 dm: ensure device names are unique
Quoted 10 lines · Simon Glass
Hi Stephen,
Quoted 7 lines · Stephen Warren
It is possible for HW to contain multiple instances of the same device. In this case, the name passed to
device_bind()may not be unique across all devices within its uclass. One example is a system with multiple identical PCI Ethernet devices. Another might be a system with multiple identical I2C GPIO expanders, each connected to a separate I2C bus, yet using the same I2C address on that bus and hence having the same DT node name.
Quoted 7 lines
Quoted 4 lines
Enhance the code to detect this situation, and append a sequence number so the device name to ensure uniqueness.
Signed-off-by Stephen Warren <swarren at nvidia.com <[email protected]>>I would rather that the caller handles this. But failing this perhaps a new function that does it? Is this for the Ethernet use case?
Wouldn't all callers of this function simply call the new function? I'm not aware of any case where the code to avoid duplicate names would not be desired.
I hit this for the Ethernet case, but I believe it applies to any type of device at all; see another possible trigger case in the commit description.
RFC PATCH 1/1 dm: ensure device names are unique
Hi Stephen,
Quoted 25 lines · Stephen Warren
Quoted 14 lines · Simon Glass
Hi Stephen,
Quoted 1 line · Stephen Warren
It is possible for HW to contain multiple instances of the same device.
In
Quoted 1 line
this case, the name passed to
device_bind()may not be unique acrossall
Quoted 1 line
devices within its uclass. One example is a system with multiple
identical
Quoted 4 lines
PCI Ethernet devices. Another might be a system with multiple identical I2C GPIO expanders, each connected to a separate I2C bus, yet using the same I2C address on that bus and hence having the same DT node name.
Quoted 8 lines
Quoted 1 line
Enhance the code to detect this situation, and append a sequence
number so
Quoted 3 lines
the device name to ensure uniqueness.
Signed-off-by Stephen Warren <swarren at nvidia.com <[email protected]>>I would rather that the caller handles this. But failing this perhaps a new function that does it? Is this for the Ethernet use case?
Quoted 6 lines
Wouldn't all callers of this function simply call the new function? I'm not aware of any case where the code to avoid duplicate names would not be desired.
I hit this for the Ethernet case, but I believe it applies to any type of device at all; see another possible trigger case in the commit description.
This does not happen with devices from the device tree. It only happens with auto-probed devices. Your I2C GPIO example is odd but I'd rather solve that by using the device tree node name.
I'd like to avoid putting things in the base code that we don't need early on in boot. How about a helper function for those subsystems that create devices outside the device tree system?
Regards,
Simon
RFC PATCH 1/1 dm: ensure device names are unique
Quoted 32 lines · Simon Glass
Hi Stephen,
Quoted 29 lines · Stephen Warren
Quoted 14 lines · Simon Glass
Hi Stephen,
Quoted 1 line · Stephen Warren
It is possible for HW to contain multiple instances of the same device.
In
Quoted 1 line
this case, the name passed to
device_bind()may not be unique acrossall
Quoted 1 line
devices within its uclass. One example is a system with multiple
identical
Quoted 4 lines
PCI Ethernet devices. Another might be a system with multiple identical I2C GPIO expanders, each connected to a separate I2C bus, yet using the same I2C address on that bus and hence having the same DT node name.
Quoted 8 lines
Quoted 1 line
Enhance the code to detect this situation, and append a sequence
number so
Quoted 3 lines
the device name to ensure uniqueness.
Signed-off-by Stephen Warren <swarren at nvidia.com <[email protected]>>I would rather that the caller handles this. But failing this perhaps a new function that does it? Is this for the Ethernet use case?
Wouldn't all callers of this function simply call the new function? I'm not aware of any case where the code to avoid duplicate names would not be desired.
Quoted 6 lines
Quoted 2 lines
I hit this for the Ethernet case, but I believe it applies to any type of device at all; see another possible trigger case in the commit description.
This does not happen with devices from the device tree. It only happens with auto-probed devices. Your I2C GPIO example is odd but I'd rather solve that by using the device tree node name.
DT itself imposes no such rule; node names must be unique only within their parent node but there's no restriction on identical node names appearing in different parts of the tree.
If U-Boot imposes that rule on DT, then there's no way in general that we can guarantee U-Boot will be able to use standard DTs (i.e. identical to those used by Linux or any other OS) for any platform; it'd be another change someone would need to make to transform a DT to be "U-Boot compatible", which rather reduces a potential benefit of DT for U-Boot; being able to just drop a DT in and have it work.
It would be possible for U-Boot to decouple its internal device name from the DT node name. In which case, your statement would work. However, I don't think that's the case at the moment, and in fact it's effectively what this patch is doing, although admittedly there are other ways of doing this.
RFC PATCH 1/1 dm: ensure device names are unique
Hi Stephen,
Quoted 56 lines · Stephen Warren
Quoted 41 lines · Simon Glass
Hi Stephen,
Quoted 37 lines · Stephen Warren
Quoted 19 lines · Simon Glass
Hi Stephen,
Quoted 1 line · Stephen Warren
It is possible for HW to contain multiple instances of the same
device.
InQuoted 1 line
this case, the name passed to
device_bind()may not be unique acrossall
Quoted 1 line
devices within its uclass. One example is a system with multiple
identical
Quoted 1 line
PCI Ethernet devices. Another might be a system with multiple
identical
Quoted 1 line
I2C GPIO expanders, each connected to a separate I2C bus, yet using
the
Quoted 3 lines
same I2C address on that bus and hence having the same DT node name.
Enhance the code to detect this situation, and append a sequence
Quoted 8 lines
number so
Quoted 3 lines
the device name to ensure uniqueness.
Signed-off-by Stephen Warren <[email protected]I would rather that the caller handles this. But failing this perhaps a new function that does it? Is this for the Ethernet use case?
Wouldn't all callers of this function simply call the new function? I'm not
aware of any case where the code to avoid duplicate names would not be desired.Quoted 8 lines
Quoted 3 lines
I hit this for the Ethernet case, but I believe it applies to any type of device at all; see another possible trigger case in the commit description.
This does not happen with devices from the device tree. It only happens with auto-probed devices. Your I2C GPIO example is odd but I'd rather solve that by using the device tree node name.
DT itself imposes no such rule; node names must be unique only within their parent node but there's no restriction on identical node names appearing in different parts of the tree.
Quoted 6 lines
If U-Boot imposes that rule on DT, then there's no way in general that we can guarantee U-Boot will be able to use standard DTs (i.e. identical to those used by Linux or any other OS) for any platform; it'd be another change someone would need to make to transform a DT to be "U-Boot compatible", which rather reduces a potential benefit of DT for U-Boot; being able to just drop a DT in and have it work.
U-Boot does not impose a rule. If you want duplicate device names you can have them. I think it is bad practice though.
Quoted 5 lines
It would be possible for U-Boot to decouple its internal device name from the DT node name. In which case, your statement would work. However, I don't think that's the case at the moment, and in fact it's effectively what this patch is doing, although admittedly there are other ways of doing this.
Anyway I believe my point stands. Whereas users can edit the device tree and avoid conflicts they cannot do this with auto-probed devices. So for that case we should have a way of allocating a name before calling device_bind().
Regards,
Simon
RFC PATCH 1/1 dm: ensure device names are unique
Quoted 75 lines · Simon Glass
Hi Stephen,
Quoted 56 lines · Stephen Warren
Quoted 41 lines · Simon Glass
Hi Stephen,
Quoted 37 lines · Stephen Warren
Quoted 19 lines · Simon Glass
Hi Stephen,
Quoted 1 line · Stephen Warren
It is possible for HW to contain multiple instances of the same
device.
InQuoted 1 line
this case, the name passed to
device_bind()may not be unique acrossall
Quoted 1 line
devices within its uclass. One example is a system with multiple
identical
Quoted 1 line
PCI Ethernet devices. Another might be a system with multiple
identical
Quoted 1 line
I2C GPIO expanders, each connected to a separate I2C bus, yet using
the
Quoted 3 lines
same I2C address on that bus and hence having the same DT node name.
Enhance the code to detect this situation, and append a sequence
Quoted 8 lines
number so
Quoted 3 lines
the device name to ensure uniqueness.
Signed-off-by Stephen Warren <[email protected]I would rather that the caller handles this. But failing this perhaps a new function that does it? Is this for the Ethernet use case?
Wouldn't all callers of this function simply call the new function? I'm not
aware of any case where the code to avoid duplicate names would not be desired.Quoted 8 lines
Quoted 3 lines
I hit this for the Ethernet case, but I believe it applies to any type of device at all; see another possible trigger case in the commit description.
This does not happen with devices from the device tree. It only happens with auto-probed devices. Your I2C GPIO example is odd but I'd rather solve that by using the device tree node name.
DT itself imposes no such rule; node names must be unique only within their parent node but there's no restriction on identical node names appearing in different parts of the tree.
Quoted 6 lines
If U-Boot imposes that rule on DT, then there's no way in general that we can guarantee U-Boot will be able to use standard DTs (i.e. identical to those used by Linux or any other OS) for any platform; it'd be another change someone would need to make to transform a DT to be "U-Boot compatible", which rather reduces a potential benefit of DT for U-Boot; being able to just drop a DT in and have it work.
U-Boot does not impose a rule. If you want duplicate device names you can have them. I think it is bad practice though.
Quoted 5 lines
It would be possible for U-Boot to decouple its internal device name from the DT node name. In which case, your statement would work. However, I don't think that's the case at the moment, and in fact it's effectively what this patch is doing, although admittedly there are other ways of doing this.
Quoted 4 lines
Anyway I believe my point stands. Whereas users can edit the device tree and avoid conflicts they cannot do this with auto-probed devices. So for that case we should have a way of allocating a name before calling
device_bind().
OK. I'm just going to solve this by unplugging the second Ethernet card, or holding this patch locally for the case when I need to test the PCIe port.
RFC PATCH 1/1 dm: ensure device names are unique
Hi Stephen,
Quoted 95 lines · Stephen Warren
Quoted 94 lines · Simon Glass
Hi Stephen,
Quoted 70 lines · Stephen Warren
Quoted 56 lines · Simon Glass
Hi Stephen,
Quoted 44 lines · Stephen Warren
Quoted 24 lines · Simon Glass
Hi Stephen,
Quoted 1 line · Stephen Warren
It is possible for HW to contain multiple instances of the same
device.
InQuoted 1 line
this case, the name passed to
device_bind()may not be uniqueacross
allQuoted 1 line
devices within its uclass. One example is a system with multiple
identical
Quoted 1 line
PCI Ethernet devices. Another might be a system with multiple
identical
Quoted 1 line
I2C GPIO expanders, each connected to a separate I2C bus, yet
using
theQuoted 1 line
same I2C address on that bus and hence having the same DT node
name.
Quoted 2 lines
Enhance the code to detect this situation, and append a sequence
number so
Quoted 8 lines
Quoted 3 lines
the device name to ensure uniqueness.
Signed-off-by Stephen Warren <[email protected]I would rather that the caller handles this. But failing this perhaps a
new function that does it? Is this for the Ethernet use case?Wouldn't all callers of this function simply call the new function? I'm not
aware of any case where the code to avoid duplicate names would not be desired.Quoted 4 lines
I hit this for the Ethernet case, but I believe it applies to any type of
device at all; see another possible trigger case in the commit description.Quoted 3 lines
This does not happen with devices from the device tree. It only happens with auto-probed devices. Your I2C GPIO example is odd but I'd rather solve that by using the device tree node name.
DT itself imposes no such rule; node names must be unique only within their
parent node but there's no restriction on identical node names appearing in
different parts of the tree.Quoted 6 lines
If U-Boot imposes that rule on DT, then there's no way in general that we can guarantee U-Boot will be able to use standard DTs (i.e. identical to those used by Linux or any other OS) for any platform; it'd be another change someone would need to make to transform a DT to be "U-Boot compatible", which rather reduces a potential benefit of DT for U-Boot; being able to just drop a DT in and have it work.
U-Boot does not impose a rule. If you want duplicate device names you can have them. I think it is bad practice though.
Quoted 7 lines
It would be possible for U-Boot to decouple its internal device name from the DT node name. In which case, your statement would work. However, I don't
think that's the case at the moment, and in fact it's effectively what this
patch is doing, although admittedly there are other ways of doing this.
Quoted 9 lines
Quoted 4 lines
Anyway I believe my point stands. Whereas users can edit the device tree and avoid conflicts they cannot do this with auto-probed devices. So for that case we should have a way of allocating a name before calling
device_bind().OK. I'm just going to solve this by unplugging the second Ethernet card, or holding this patch locally for the case when I need to test the PCIe port.
Binding a device needs to be as cheap as possible. 99% of the time the name is fine, and we know the cases where it might not be. This is similar to the DM_UC_FLAG_SEQ_ALIAS - expensive functionality should be separated out so we don't require everyone to use it. It just creates bloat.
So please when contributing things to driver model (which is most welcome and appreciated) be a little more flexible. It should not take this much energy to explain the design principles and get a change to a patch.
Also see u-boot-dm/blkb-working which includes the allocation of device names. I need to resolve the comments and respin...
Regards,
Simon