UPSTREAM: remoteproc: Add a rproc_set_firmware() API
A new API, rproc_set_firmware() is added to allow the remoteproc platform drivers and remoteproc client drivers to be able to configure a custom firmware name that is different from the default name used during remoteproc registration. This function is being introduced to provide a kernel-level equivalent of the current sysfs interface to remoteproc client drivers, and can only change firmwares when the remoteproc is offline. This allows some remoteproc drivers to choose different firmwares at runtime based on the functionality the remote processor is providing. The TI PRU Ethernet driver will be an example of such usage as it requires to use different firmwares for different supported protocols. Also, update the firmware_store() function used by the sysfs interface to reuse this function to avoid code duplication. Bug: 213024513 Change-Id: Ie365179ac296c43c7c5c54b46f9f9f7587d5d263 Reviewed-by: Rishabh Bhatnagar <rishabhb@codeaurora.org> Signed-off-by: Suman Anna <s-anna@ti.com> Link: https://lore.kernel.org/r/20201121032042.6195-1-s-anna@ti.com Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org> (cherry picked from commit 4c1ad562d303526b5d9b49f5e0d72da13ef78dec git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master) Signed-off-by: Mukesh Ojha <quic_mojha@quicinc.com>
This commit is contained in:
@@ -1942,6 +1942,69 @@ struct rproc *rproc_get_by_phandle(phandle phandle)
|
|||||||
#endif
|
#endif
|
||||||
EXPORT_SYMBOL(rproc_get_by_phandle);
|
EXPORT_SYMBOL(rproc_get_by_phandle);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* rproc_set_firmware() - assign a new firmware
|
||||||
|
* @rproc: rproc handle to which the new firmware is being assigned
|
||||||
|
* @fw_name: new firmware name to be assigned
|
||||||
|
*
|
||||||
|
* This function allows remoteproc drivers or clients to configure a custom
|
||||||
|
* firmware name that is different from the default name used during remoteproc
|
||||||
|
* registration. The function does not trigger a remote processor boot,
|
||||||
|
* only sets the firmware name used for a subsequent boot. This function
|
||||||
|
* should also be called only when the remote processor is offline.
|
||||||
|
*
|
||||||
|
* This allows either the userspace to configure a different name through
|
||||||
|
* sysfs or a kernel-level remoteproc or a remoteproc client driver to set
|
||||||
|
* a specific firmware when it is controlling the boot and shutdown of the
|
||||||
|
* remote processor.
|
||||||
|
*
|
||||||
|
* Return: 0 on success or a negative value upon failure
|
||||||
|
*/
|
||||||
|
int rproc_set_firmware(struct rproc *rproc, const char *fw_name)
|
||||||
|
{
|
||||||
|
struct device *dev;
|
||||||
|
int ret, len;
|
||||||
|
char *p;
|
||||||
|
|
||||||
|
if (!rproc || !fw_name)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
dev = rproc->dev.parent;
|
||||||
|
|
||||||
|
ret = mutex_lock_interruptible(&rproc->lock);
|
||||||
|
if (ret) {
|
||||||
|
dev_err(dev, "can't lock rproc %s: %d\n", rproc->name, ret);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rproc->state != RPROC_OFFLINE) {
|
||||||
|
dev_err(dev, "can't change firmware while running\n");
|
||||||
|
ret = -EBUSY;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = strcspn(fw_name, "\n");
|
||||||
|
if (!len) {
|
||||||
|
dev_err(dev, "can't provide empty string for firmware name\n");
|
||||||
|
ret = -EINVAL;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
p = kstrndup(fw_name, len, GFP_KERNEL);
|
||||||
|
if (!p) {
|
||||||
|
ret = -ENOMEM;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
kfree(rproc->firmware);
|
||||||
|
rproc->firmware = p;
|
||||||
|
|
||||||
|
out:
|
||||||
|
mutex_unlock(&rproc->lock);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(rproc_set_firmware);
|
||||||
|
|
||||||
static int rproc_validate(struct rproc *rproc)
|
static int rproc_validate(struct rproc *rproc)
|
||||||
{
|
{
|
||||||
switch (rproc->state) {
|
switch (rproc->state) {
|
||||||
|
@@ -157,38 +157,9 @@ static ssize_t firmware_store(struct device *dev,
|
|||||||
const char *buf, size_t count)
|
const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
struct rproc *rproc = to_rproc(dev);
|
struct rproc *rproc = to_rproc(dev);
|
||||||
char *p;
|
int err;
|
||||||
int err, len = count;
|
|
||||||
|
|
||||||
err = mutex_lock_interruptible(&rproc->lock);
|
err = rproc_set_firmware(rproc, buf);
|
||||||
if (err) {
|
|
||||||
dev_err(dev, "can't lock rproc %s: %d\n", rproc->name, err);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rproc->state != RPROC_OFFLINE) {
|
|
||||||
dev_err(dev, "can't change firmware while running\n");
|
|
||||||
err = -EBUSY;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
len = strcspn(buf, "\n");
|
|
||||||
if (!len) {
|
|
||||||
dev_err(dev, "can't provide a NULL firmware\n");
|
|
||||||
err = -EINVAL;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
p = kstrndup(buf, len, GFP_KERNEL);
|
|
||||||
if (!p) {
|
|
||||||
err = -ENOMEM;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
kfree(rproc->firmware);
|
|
||||||
rproc->firmware = p;
|
|
||||||
out:
|
|
||||||
mutex_unlock(&rproc->lock);
|
|
||||||
|
|
||||||
return err ? err : count;
|
return err ? err : count;
|
||||||
}
|
}
|
||||||
|
@@ -657,6 +657,7 @@ rproc_of_resm_mem_entry_init(struct device *dev, u32 of_resm_idx, size_t len,
|
|||||||
|
|
||||||
int rproc_boot(struct rproc *rproc);
|
int rproc_boot(struct rproc *rproc);
|
||||||
void rproc_shutdown(struct rproc *rproc);
|
void rproc_shutdown(struct rproc *rproc);
|
||||||
|
int rproc_set_firmware(struct rproc *rproc, const char *fw_name);
|
||||||
void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type);
|
void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type);
|
||||||
|
|
||||||
/* from remoteproc_coredump.c */
|
/* from remoteproc_coredump.c */
|
||||||
|
Reference in New Issue
Block a user