[U-Boot] [PATCH v4 2/5] devres: introduce Devres (Managed Device Resource) framework
Simon Glass
sjg at chromium.org
Wed Jul 29 05:30:00 CEST 2015
On 28 July 2015 at 12:07, Simon Glass <sjg at chromium.org> wrote:
> On 25 July 2015 at 06:52, Masahiro Yamada <yamada.masahiro at socionext.com> wrote:
>> In U-Boot's driver model, memory is basically allocated and freed
>> in the core framework. So, low level drivers generally only have
>> to specify the size of needed memory with .priv_auto_alloc_size,
>> .platdata_auto_alloc_size, etc. Nevertheless, some drivers still
>> need to allocate/free memory on their own in case they cannot
>> statically know the necessary memory size. So, I believe it is
>> reasonable enough to port Devres into U-boot.
>>
>> Devres, which originates in Linux, manages device resources for each
>> device and automatically releases them on driver detach. With devres,
>> device resources are guaranteed to be freed whether initialization
>> fails half-way or the device gets detached.
>>
>> The basic idea is totally the same to that of Linux, but I tweaked
>> it a bit so that it fits in U-Boot's driver model.
>>
>> In U-Boot, drivers are activated in two steps: binding and probing.
>> Binding puts a driver and a device together. It is just data
>> manipulation on the system memory, so nothing has happened on the
>> hardware device at this moment. When the device is really used, it
>> is probed. Probing initializes the real hardware device to make it
>> really ready for use.
>>
>> So, the resources acquired during the probing process must be freed
>> when the device is removed. Likewise, what has been allocated in
>> binding should be released when the device is unbound. The struct
>> devres has a member "probe" to remember when the resource was
>> allocated.
>>
>> CONFIG_DEBUG_DEVRES is also supported for easier debugging.
>> If enabled, debug messages are printed each time a resource is
>> allocated/freed.
>>
>> Signed-off-by: Masahiro Yamada <yamada.masahiro at socionext.com>
>> ---
>>
>> Changes in v4:
>> - Comment struct devres
>>
>> Changes in v3:
>> - Update git-description. Do not mention about the DM core part.
>>
>> Changes in v2:
>> - Add more APIs: _free, _find, _get, _remove, _destroy, _release
>> - Move devres_release_probe() and devres_release_all() decrlarations
>> to dm/device-internal.h
>> - Move comments to headers
>>
>> drivers/core/Kconfig | 10 +++
>> drivers/core/Makefile | 2 +-
>> drivers/core/device-remove.c | 5 ++
>> drivers/core/device.c | 3 +
>> drivers/core/devres.c | 196 +++++++++++++++++++++++++++++++++++++++++++
>> include/dm/device-internal.h | 19 +++++
>> include/dm/device.h | 140 +++++++++++++++++++++++++++++++
>> 7 files changed, 374 insertions(+), 1 deletion(-)
>
> Acked-by: Simon Glass <sjg at chromium.org>
Applied to u-boot-dm, thanks!
More information about the U-Boot
mailing list