diff options
author | Robert Tivy <rtivy@ti.com> | 2013-03-28 21:41:44 -0400 |
---|---|---|
committer | Ohad Ben-Cohen <ohad@wizery.com> | 2013-04-07 08:40:04 -0400 |
commit | 8b4aec9ac7b59754df9c594569af9ae8f456ee07 (patch) | |
tree | 2ccfb6df12fc10d3c4219184202c9d8246e5bfe1 /drivers/remoteproc | |
parent | e5bc0294ca03a684f322a1a37538ebc3c121d86a (diff) |
remoteproc: support default firmware name in rproc_alloc()
If rproc_alloc isn't given a firmware name, look for a default
one using the "rproc-%s-fw" template.
Signed-off-by: Robert Tivy <rtivy@ti.com>
[add commit log, document change, use snprintf, minor style change]
Signed-off-by: Ohad Ben-Cohen <ohad@wizery.com>
Diffstat (limited to 'drivers/remoteproc')
-rw-r--r-- | drivers/remoteproc/remoteproc_core.c | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 7c357370083a..56a0f8d6855b 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c | |||
@@ -1236,11 +1236,11 @@ static struct device_type rproc_type = { | |||
1236 | * @dev: the underlying device | 1236 | * @dev: the underlying device |
1237 | * @name: name of this remote processor | 1237 | * @name: name of this remote processor |
1238 | * @ops: platform-specific handlers (mainly start/stop) | 1238 | * @ops: platform-specific handlers (mainly start/stop) |
1239 | * @firmware: name of firmware file to load | 1239 | * @firmware: name of firmware file to load, can be NULL |
1240 | * @len: length of private data needed by the rproc driver (in bytes) | 1240 | * @len: length of private data needed by the rproc driver (in bytes) |
1241 | * | 1241 | * |
1242 | * Allocates a new remote processor handle, but does not register | 1242 | * Allocates a new remote processor handle, but does not register |
1243 | * it yet. | 1243 | * it yet. if @firmware is NULL, a default name is used. |
1244 | * | 1244 | * |
1245 | * This function should be used by rproc implementations during initialization | 1245 | * This function should be used by rproc implementations during initialization |
1246 | * of the remote processor. | 1246 | * of the remote processor. |
@@ -1259,19 +1259,39 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, | |||
1259 | const char *firmware, int len) | 1259 | const char *firmware, int len) |
1260 | { | 1260 | { |
1261 | struct rproc *rproc; | 1261 | struct rproc *rproc; |
1262 | char *p, *template = "rproc-%s-fw"; | ||
1263 | int name_len = 0; | ||
1262 | 1264 | ||
1263 | if (!dev || !name || !ops) | 1265 | if (!dev || !name || !ops) |
1264 | return NULL; | 1266 | return NULL; |
1265 | 1267 | ||
1266 | rproc = kzalloc(sizeof(struct rproc) + len, GFP_KERNEL); | 1268 | if (!firmware) |
1269 | /* | ||
1270 | * Make room for default firmware name (minus %s plus '\0'). | ||
1271 | * If the caller didn't pass in a firmware name then | ||
1272 | * construct a default name. We're already glomming 'len' | ||
1273 | * bytes onto the end of the struct rproc allocation, so do | ||
1274 | * a few more for the default firmware name (but only if | ||
1275 | * the caller doesn't pass one). | ||
1276 | */ | ||
1277 | name_len = strlen(name) + strlen(template) - 2 + 1; | ||
1278 | |||
1279 | rproc = kzalloc(sizeof(struct rproc) + len + name_len, GFP_KERNEL); | ||
1267 | if (!rproc) { | 1280 | if (!rproc) { |
1268 | dev_err(dev, "%s: kzalloc failed\n", __func__); | 1281 | dev_err(dev, "%s: kzalloc failed\n", __func__); |
1269 | return NULL; | 1282 | return NULL; |
1270 | } | 1283 | } |
1271 | 1284 | ||
1285 | if (!firmware) { | ||
1286 | p = (char *)rproc + sizeof(struct rproc) + len; | ||
1287 | snprintf(p, name_len, template, name); | ||
1288 | } else { | ||
1289 | p = (char *)firmware; | ||
1290 | } | ||
1291 | |||
1292 | rproc->firmware = p; | ||
1272 | rproc->name = name; | 1293 | rproc->name = name; |
1273 | rproc->ops = ops; | 1294 | rproc->ops = ops; |
1274 | rproc->firmware = firmware; | ||
1275 | rproc->priv = &rproc[1]; | 1295 | rproc->priv = &rproc[1]; |
1276 | 1296 | ||
1277 | device_initialize(&rproc->dev); | 1297 | device_initialize(&rproc->dev); |