Skip to content

Commit

Permalink
remoteproc: Add device-managed variants of rproc_alloc/rproc_add
Browse files Browse the repository at this point in the history
Add API functions devm_rproc_alloc() and devm_rproc_add(), which behave
like rproc_alloc() and rproc_add() respectively, but register their
respective cleanup function to be called on driver detach.

Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Link: https://lore.kernel.org/r/20200417170040.174319-2-paul@crapouillou.net
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
  • Loading branch information
Paul Cercueil authored and Bjorn Andersson committed Apr 21, 2020
1 parent db65527 commit 305ac5a
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
67 changes: 67 additions & 0 deletions drivers/remoteproc/remoteproc_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1976,6 +1976,33 @@ int rproc_add(struct rproc *rproc)
}
EXPORT_SYMBOL(rproc_add);

static void devm_rproc_remove(void *rproc)
{
rproc_del(rproc);
}

/**
* devm_rproc_add() - resource managed rproc_add()
* @dev: the underlying device
* @rproc: the remote processor handle to register
*
* This function performs like rproc_add() but the registered rproc device will
* automatically be removed on driver detach.
*
* Returns: 0 on success, negative errno on failure
*/
int devm_rproc_add(struct device *dev, struct rproc *rproc)
{
int err;

err = rproc_add(rproc);
if (err)
return err;

return devm_add_action_or_reset(dev, devm_rproc_remove, rproc);
}
EXPORT_SYMBOL(devm_rproc_add);

/**
* rproc_type_release() - release a remote processor instance
* @dev: the rproc's device
Expand Down Expand Up @@ -2215,6 +2242,46 @@ int rproc_del(struct rproc *rproc)
}
EXPORT_SYMBOL(rproc_del);

static void devm_rproc_free(struct device *dev, void *res)
{
rproc_free(*(struct rproc **)res);
}

/**
* devm_rproc_alloc() - resource managed rproc_alloc()
* @dev: the underlying device
* @name: name of this remote processor
* @ops: platform-specific handlers (mainly start/stop)
* @firmware: name of firmware file to load, can be NULL
* @len: length of private data needed by the rproc driver (in bytes)
*
* This function performs like rproc_alloc() but the acquired rproc device will
* automatically be released on driver detach.
*
* Returns: new rproc instance, or NULL on failure
*/
struct rproc *devm_rproc_alloc(struct device *dev, const char *name,
const struct rproc_ops *ops,
const char *firmware, int len)
{
struct rproc **ptr, *rproc;

ptr = devres_alloc(devm_rproc_free, sizeof(*ptr), GFP_KERNEL);
if (!ptr)
return ERR_PTR(-ENOMEM);

rproc = rproc_alloc(dev, name, ops, firmware, len);
if (rproc) {
*ptr = rproc;
devres_add(dev, ptr);
} else {
devres_free(ptr);
}

return rproc;
}
EXPORT_SYMBOL(devm_rproc_alloc);

/**
* rproc_add_subdev() - add a subdevice to a remoteproc
* @rproc: rproc handle to add the subdevice to
Expand Down
5 changes: 5 additions & 0 deletions include/linux/remoteproc.h
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,11 @@ int rproc_add(struct rproc *rproc);
int rproc_del(struct rproc *rproc);
void rproc_free(struct rproc *rproc);

struct rproc *devm_rproc_alloc(struct device *dev, const char *name,
const struct rproc_ops *ops,
const char *firmware, int len);
int devm_rproc_add(struct device *dev, struct rproc *rproc);

void rproc_add_carveout(struct rproc *rproc, struct rproc_mem_entry *mem);

struct rproc_mem_entry *
Expand Down

0 comments on commit 305ac5a

Please sign in to comment.