@@ -1004,3 +1004,33 @@ int devm_acquire_resources(struct device *dev)
return ret;
}
+
+/*
+ * this must be the called before any of the others, or not at
+ * all, if dev_set_drvdata() has already been called.
+ */
+static void devm_resource_alloc_release(struct device *dev, void *res)
+{
+ dev_set_drvdata(dev, NULL);
+}
+
+int devm_resource_alloc(struct device *dev,
+ const struct devm_resource *resource)
+{
+ struct devres *dr;
+
+ if (dev_get_drvdata(dev))
+ return -EBUSY;
+
+ dr = alloc_dr(devm_resource_alloc_release, resource->offset,
+ GFP_KERNEL | __GFP_ZERO);
+ if (unlikely(!dr))
+ return -ENOMEM;
+
+ dev_set_drvdata(dev, dr->data);
+ set_node_dbginfo(&dr->node, "devm_resource_alloc", resource->offset);
+ devres_add(dev, dr->data);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(devm_resource_alloc);
@@ -681,6 +681,12 @@ extern void devm_free_pages(struct device *dev, unsigned long addr);
extern int devm_acquire_resources(struct device *dev);
+extern int devm_resource_alloc(struct device *dev,
+ const struct devm_resource *resource);
+
+#define DEVM_ALLOC(_struct) \
+ { .initfunc = devm_resource_alloc, .offset = sizeof(struct _struct), }
+
void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res);
/* allows to add/remove a custom action to devres stack */
Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com> --- drivers/base/devres.c | 30 ++++++++++++++++++++++++++++++ include/linux/device.h | 6 ++++++ 2 files changed, 36 insertions(+)