Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

remoteproc: introduce rproc_get_by_phandle API

Allow users of remoteproc the ability to get a handle to an rproc by
passing a phandle supplied in the user's device tree node. This is
useful in situations that require manual booting of the rproc.

This patch uses the code removed by commit 40e575b1d0b3 ("remoteproc:
remove the get_by_name/put API") for the ref counting but is modified
to use a simple list and locking mechanism and has rproc_get_by_name
replaced with an rproc_get_by_phandle API.

Signed-off-by: Dave Gerlach <d-gerlach@ti.com>
Signed-off-by: Suman Anna <s-anna@ti.com>
[fix order of Signed-off-by tags]
Signed-off-by: Ohad Ben-Cohen <ohad@wizery.com>

authored by

Dave Gerlach and committed by
Ohad Ben-Cohen
fec47d86 172e6ab1

+60 -3
+6
Documentation/remoteproc.txt
··· 51 51 rproc_shutdown() returns, and users can still use it with a subsequent 52 52 rproc_boot(), if needed. 53 53 54 + struct rproc *rproc_get_by_phandle(phandle phandle) 55 + - Find an rproc handle using a device tree phandle. Returns the rproc 56 + handle on success, and NULL on failure. This function increments 57 + the remote processor's refcount, so always use rproc_put() to 58 + decrement it back once rproc isn't needed anymore. 59 + 54 60 3. Typical usage 55 61 56 62 #include <linux/remoteproc.h>
+50
drivers/remoteproc/remoteproc_core.c
··· 44 44 45 45 #include "remoteproc_internal.h" 46 46 47 + static DEFINE_MUTEX(rproc_list_mutex); 48 + static LIST_HEAD(rproc_list); 49 + 47 50 typedef int (*rproc_handle_resources_t)(struct rproc *rproc, 48 51 struct resource_table *table, int len); 49 52 typedef int (*rproc_handle_resource_t)(struct rproc *rproc, ··· 1148 1145 EXPORT_SYMBOL(rproc_shutdown); 1149 1146 1150 1147 /** 1148 + * rproc_get_by_phandle() - find a remote processor by phandle 1149 + * @phandle: phandle to the rproc 1150 + * 1151 + * Finds an rproc handle using the remote processor's phandle, and then 1152 + * return a handle to the rproc. 1153 + * 1154 + * This function increments the remote processor's refcount, so always 1155 + * use rproc_put() to decrement it back once rproc isn't needed anymore. 1156 + * 1157 + * Returns the rproc handle on success, and NULL on failure. 1158 + */ 1159 + struct rproc *rproc_get_by_phandle(phandle phandle) 1160 + { 1161 + struct rproc *rproc = NULL, *r; 1162 + struct device_node *np; 1163 + 1164 + np = of_find_node_by_phandle(phandle); 1165 + if (!np) 1166 + return NULL; 1167 + 1168 + mutex_lock(&rproc_list_mutex); 1169 + list_for_each_entry(r, &rproc_list, node) { 1170 + if (r->dev.parent && r->dev.parent->of_node == np) { 1171 + rproc = r; 1172 + get_device(&rproc->dev); 1173 + break; 1174 + } 1175 + } 1176 + mutex_unlock(&rproc_list_mutex); 1177 + 1178 + of_node_put(np); 1179 + 1180 + return rproc; 1181 + } 1182 + EXPORT_SYMBOL(rproc_get_by_phandle); 1183 + 1184 + /** 1151 1185 * rproc_add() - register a remote processor 1152 1186 * @rproc: the remote processor handle to register 1153 1187 * ··· 1212 1172 ret = device_add(dev); 1213 1173 if (ret < 0) 1214 1174 return ret; 1175 + 1176 + /* expose to rproc_get_by_phandle users */ 1177 + mutex_lock(&rproc_list_mutex); 1178 + list_add(&rproc->node, &rproc_list); 1179 + mutex_unlock(&rproc_list_mutex); 1215 1180 1216 1181 dev_info(dev, "%s is available\n", rproc->name); 1217 1182 ··· 1404 1359 1405 1360 /* Free the copy of the resource table */ 1406 1361 kfree(rproc->cached_table); 1362 + 1363 + /* the rproc is downref'ed as soon as it's removed from the klist */ 1364 + mutex_lock(&rproc_list_mutex); 1365 + list_del(&rproc->node); 1366 + mutex_unlock(&rproc_list_mutex); 1407 1367 1408 1368 device_del(&rproc->dev); 1409 1369
+4 -3
include/linux/remoteproc.h
··· 36 36 #define REMOTEPROC_H 37 37 38 38 #include <linux/types.h> 39 - #include <linux/klist.h> 40 39 #include <linux/mutex.h> 41 40 #include <linux/virtio.h> 42 41 #include <linux/completion.h> 43 42 #include <linux/idr.h> 43 + #include <linux/of.h> 44 44 45 45 /** 46 46 * struct resource_table - firmware resource table header ··· 375 375 376 376 /** 377 377 * struct rproc - represents a physical remote processor device 378 - * @node: klist node of this rproc object 378 + * @node: list node of this rproc object 379 379 * @domain: iommu domain 380 380 * @name: human readable name of the rproc 381 381 * @firmware: name of firmware file to be loaded ··· 407 407 * @has_iommu: flag to indicate if remote processor is behind an MMU 408 408 */ 409 409 struct rproc { 410 - struct klist_node node; 410 + struct list_head node; 411 411 struct iommu_domain *domain; 412 412 const char *name; 413 413 const char *firmware; ··· 481 481 u32 rsc_offset; 482 482 }; 483 483 484 + struct rproc *rproc_get_by_phandle(phandle phandle); 484 485 struct rproc *rproc_alloc(struct device *dev, const char *name, 485 486 const struct rproc_ops *ops, 486 487 const char *firmware, int len);