summaryrefslogtreecommitdiff
path: root/include/dm/device-internal.h
diff options
context:
space:
mode:
authorMasahiro Yamada <yamada.masahiro@socionext.com>2015-07-25 21:52:35 +0900
committerSimon Glass <sjg@chromium.org>2015-08-06 07:44:29 -0600
commit608f26c51bebc68db7f2edc7590ee513d2bc5465 (patch)
tree3f38bebfffd02994fa19fe2ba5eea98e82b0d1ec /include/dm/device-internal.h
parentaed1a4dd88e94001b811b297c1ff734c3f8d22d9 (diff)
downloadu-boot-imx-608f26c51bebc68db7f2edc7590ee513d2bc5465.zip
u-boot-imx-608f26c51bebc68db7f2edc7590ee513d2bc5465.tar.gz
u-boot-imx-608f26c51bebc68db7f2edc7590ee513d2bc5465.tar.bz2
devres: introduce Devres (Managed Device Resource) framework
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@socionext.com> Acked-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'include/dm/device-internal.h')
-rw-r--r--include/dm/device-internal.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/include/dm/device-internal.h b/include/dm/device-internal.h
index 1a9ba01..a2bf057 100644
--- a/include/dm/device-internal.h
+++ b/include/dm/device-internal.h
@@ -155,4 +155,23 @@ fdt_addr_t simple_bus_translate(struct udevice *dev, fdt_addr_t addr);
#define DM_ROOT_NON_CONST (((gd_t *)gd)->dm_root)
#define DM_UCLASS_ROOT_NON_CONST (((gd_t *)gd)->uclass_root)
+/* device resource management */
+/**
+ * devres_release_probe - Release managed resources allocated after probing
+ * @dev: Device to release resources for
+ *
+ * Release all resources allocated for @dev when it was probed or later.
+ * This function is called on driver removal.
+ */
+void devres_release_probe(struct udevice *dev);
+
+/**
+ * devres_release_all - Release all managed resources
+ * @dev: Device to release resources for
+ *
+ * Release all resources associated with @dev. This function is
+ * called on driver unbinding.
+ */
+void devres_release_all(struct udevice *dev);
+
#endif