[U-Boot] [RFC PATCH] dm: ensure device names are unique

Simon Glass sjg at chromium.org
Fri Apr 29 15:24:07 CEST 2016


Hi Stephen,

On 28 April 2016 at 10:00, Stephen Warren <swarren at wwwdotorg.org> wrote:
>
> On 04/27/2016 10:42 PM, Joe Hershberger wrote:
>>
>> On Tue, Apr 26, 2016 at 4:30 PM, Stephen Warren <swarren at wwwdotorg.org> wrote:
>>>
>>> From: Stephen Warren <swarren at nvidia.com>
>>>
>>> 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 <swarren at nvidia.com>
>>> ---
>>> 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().
>>
>>
>> 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.

>
>>> 2) uclass_find_device_by_name() needs to look up the uclass pointer again
>>> even though device_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.
>
>>> 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...

>
>
> Yes, I don't imagine this would be a particular issue in practice.

Regards,
Simon


More information about the U-Boot mailing list