|
@@ -44,6 +44,9 @@
|
|
|
|
|
|
#include "remoteproc_internal.h"
|
|
#include "remoteproc_internal.h"
|
|
|
|
|
|
|
|
+static DEFINE_MUTEX(rproc_list_mutex);
|
|
|
|
+static LIST_HEAD(rproc_list);
|
|
|
|
+
|
|
typedef int (*rproc_handle_resources_t)(struct rproc *rproc,
|
|
typedef int (*rproc_handle_resources_t)(struct rproc *rproc,
|
|
struct resource_table *table, int len);
|
|
struct resource_table *table, int len);
|
|
typedef int (*rproc_handle_resource_t)(struct rproc *rproc,
|
|
typedef int (*rproc_handle_resource_t)(struct rproc *rproc,
|
|
@@ -1144,6 +1147,43 @@ out:
|
|
}
|
|
}
|
|
EXPORT_SYMBOL(rproc_shutdown);
|
|
EXPORT_SYMBOL(rproc_shutdown);
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * rproc_get_by_phandle() - find a remote processor by phandle
|
|
|
|
+ * @phandle: phandle to the rproc
|
|
|
|
+ *
|
|
|
|
+ * Finds an rproc handle using the remote processor's phandle, and then
|
|
|
|
+ * return a handle to the rproc.
|
|
|
|
+ *
|
|
|
|
+ * This function increments the remote processor's refcount, so always
|
|
|
|
+ * use rproc_put() to decrement it back once rproc isn't needed anymore.
|
|
|
|
+ *
|
|
|
|
+ * Returns the rproc handle on success, and NULL on failure.
|
|
|
|
+ */
|
|
|
|
+struct rproc *rproc_get_by_phandle(phandle phandle)
|
|
|
|
+{
|
|
|
|
+ struct rproc *rproc = NULL, *r;
|
|
|
|
+ struct device_node *np;
|
|
|
|
+
|
|
|
|
+ np = of_find_node_by_phandle(phandle);
|
|
|
|
+ if (!np)
|
|
|
|
+ return NULL;
|
|
|
|
+
|
|
|
|
+ mutex_lock(&rproc_list_mutex);
|
|
|
|
+ list_for_each_entry(r, &rproc_list, node) {
|
|
|
|
+ if (r->dev.parent && r->dev.parent->of_node == np) {
|
|
|
|
+ rproc = r;
|
|
|
|
+ get_device(&rproc->dev);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ mutex_unlock(&rproc_list_mutex);
|
|
|
|
+
|
|
|
|
+ of_node_put(np);
|
|
|
|
+
|
|
|
|
+ return rproc;
|
|
|
|
+}
|
|
|
|
+EXPORT_SYMBOL(rproc_get_by_phandle);
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* rproc_add() - register a remote processor
|
|
* rproc_add() - register a remote processor
|
|
* @rproc: the remote processor handle to register
|
|
* @rproc: the remote processor handle to register
|
|
@@ -1173,6 +1213,11 @@ int rproc_add(struct rproc *rproc)
|
|
if (ret < 0)
|
|
if (ret < 0)
|
|
return ret;
|
|
return ret;
|
|
|
|
|
|
|
|
+ /* expose to rproc_get_by_phandle users */
|
|
|
|
+ mutex_lock(&rproc_list_mutex);
|
|
|
|
+ list_add(&rproc->node, &rproc_list);
|
|
|
|
+ mutex_unlock(&rproc_list_mutex);
|
|
|
|
+
|
|
dev_info(dev, "%s is available\n", rproc->name);
|
|
dev_info(dev, "%s is available\n", rproc->name);
|
|
|
|
|
|
dev_info(dev, "Note: remoteproc is still under development and considered experimental.\n");
|
|
dev_info(dev, "Note: remoteproc is still under development and considered experimental.\n");
|
|
@@ -1360,6 +1405,11 @@ int rproc_del(struct rproc *rproc)
|
|
/* Free the copy of the resource table */
|
|
/* Free the copy of the resource table */
|
|
kfree(rproc->cached_table);
|
|
kfree(rproc->cached_table);
|
|
|
|
|
|
|
|
+ /* the rproc is downref'ed as soon as it's removed from the klist */
|
|
|
|
+ mutex_lock(&rproc_list_mutex);
|
|
|
|
+ list_del(&rproc->node);
|
|
|
|
+ mutex_unlock(&rproc_list_mutex);
|
|
|
|
+
|
|
device_del(&rproc->dev);
|
|
device_del(&rproc->dev);
|
|
|
|
|
|
return 0;
|
|
return 0;
|