aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Boyd <sboyd@codeaurora.org>2015-09-02 18:46:44 -0400
committerAndy Gross <agross@codeaurora.org>2015-10-14 15:51:20 -0400
commit1a03964dec3cecb6382d172b9dfe318735c2cad7 (patch)
treec70613e4c997e4c77dda6e488d4036182b79fd6a
parent7d0c8beea6b8d158d9a628b798dfc1638a7a8ce0 (diff)
soc: qcom: Make qcom_smem_get() return a pointer
Passing a void ** almost always requires a cast at the call site. Instead of littering the code with casts every time this function is called, have qcom_smem_get() return a void pointer to the location of the smem item. This frees the caller from having to cast the pointer. Cc: Bjorn Andersson <bjorn.andersson@sonymobile.com> Signed-off-by: Stephen Boyd <sboyd@codeaurora.org> Reviewed-by: Bjorn Andersson <bjorn.andersson@sonymobile.com> Signed-off-by: Andy Gross <agross@codeaurora.org>
-rw-r--r--drivers/soc/qcom/smd.c30
-rw-r--r--drivers/soc/qcom/smem.c72
-rw-r--r--include/linux/soc/qcom/smem.h2
3 files changed, 48 insertions, 56 deletions
diff --git a/drivers/soc/qcom/smd.c b/drivers/soc/qcom/smd.c
index d883c16d1775..beaea1d5169f 100644
--- a/drivers/soc/qcom/smd.c
+++ b/drivers/soc/qcom/smd.c
@@ -989,10 +989,11 @@ static struct qcom_smd_channel *qcom_smd_create_channel(struct qcom_smd_edge *ed
989 spin_lock_init(&channel->recv_lock); 989 spin_lock_init(&channel->recv_lock);
990 init_waitqueue_head(&channel->fblockread_event); 990 init_waitqueue_head(&channel->fblockread_event);
991 991
992 ret = qcom_smem_get(edge->remote_pid, smem_info_item, (void **)&info, 992 info = qcom_smem_get(edge->remote_pid, smem_info_item, &info_size);
993 &info_size); 993 if (IS_ERR(info)) {
994 if (ret) 994 ret = PTR_ERR(info);
995 goto free_name_and_channel; 995 goto free_name_and_channel;
996 }
996 997
997 /* 998 /*
998 * Use the size of the item to figure out which channel info struct to 999 * Use the size of the item to figure out which channel info struct to
@@ -1011,10 +1012,11 @@ static struct qcom_smd_channel *qcom_smd_create_channel(struct qcom_smd_edge *ed
1011 goto free_name_and_channel; 1012 goto free_name_and_channel;
1012 } 1013 }
1013 1014
1014 ret = qcom_smem_get(edge->remote_pid, smem_fifo_item, &fifo_base, 1015 fifo_base = qcom_smem_get(edge->remote_pid, smem_fifo_item, &fifo_size);
1015 &fifo_size); 1016 if (IS_ERR(fifo_base)) {
1016 if (ret) 1017 ret = PTR_ERR(fifo_base);
1017 goto free_name_and_channel; 1018 goto free_name_and_channel;
1019 }
1018 1020
1019 /* The channel consist of a rx and tx fifo of equal size */ 1021 /* The channel consist of a rx and tx fifo of equal size */
1020 fifo_size /= 2; 1022 fifo_size /= 2;
@@ -1051,16 +1053,13 @@ static void qcom_discover_channels(struct qcom_smd_edge *edge)
1051 unsigned long flags; 1053 unsigned long flags;
1052 unsigned fifo_id; 1054 unsigned fifo_id;
1053 unsigned info_id; 1055 unsigned info_id;
1054 int ret;
1055 int tbl; 1056 int tbl;
1056 int i; 1057 int i;
1057 1058
1058 for (tbl = 0; tbl < SMD_ALLOC_TBL_COUNT; tbl++) { 1059 for (tbl = 0; tbl < SMD_ALLOC_TBL_COUNT; tbl++) {
1059 ret = qcom_smem_get(edge->remote_pid, 1060 alloc_tbl = qcom_smem_get(edge->remote_pid,
1060 smem_items[tbl].alloc_tbl_id, 1061 smem_items[tbl].alloc_tbl_id, NULL);
1061 (void **)&alloc_tbl, 1062 if (IS_ERR(alloc_tbl))
1062 NULL);
1063 if (ret < 0)
1064 continue; 1063 continue;
1065 1064
1066 for (i = 0; i < SMD_ALLOC_TBL_SIZE; i++) { 1065 for (i = 0; i < SMD_ALLOC_TBL_SIZE; i++) {
@@ -1238,11 +1237,12 @@ static int qcom_smd_probe(struct platform_device *pdev)
1238 int num_edges; 1237 int num_edges;
1239 int ret; 1238 int ret;
1240 int i = 0; 1239 int i = 0;
1240 void *p;
1241 1241
1242 /* Wait for smem */ 1242 /* Wait for smem */
1243 ret = qcom_smem_get(QCOM_SMEM_HOST_ANY, smem_items[0].alloc_tbl_id, NULL, NULL); 1243 p = qcom_smem_get(QCOM_SMEM_HOST_ANY, smem_items[0].alloc_tbl_id, NULL);
1244 if (ret == -EPROBE_DEFER) 1244 if (PTR_ERR(p) == -EPROBE_DEFER)
1245 return ret; 1245 return PTR_ERR(p);
1246 1246
1247 num_edges = of_get_available_child_count(pdev->dev.of_node); 1247 num_edges = of_get_available_child_count(pdev->dev.of_node);
1248 array_size = sizeof(*smd) + num_edges * sizeof(struct qcom_smd_edge); 1248 array_size = sizeof(*smd) + num_edges * sizeof(struct qcom_smd_edge);
diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c
index f402a606eb7d..e6d0dae63845 100644
--- a/drivers/soc/qcom/smem.c
+++ b/drivers/soc/qcom/smem.c
@@ -378,10 +378,9 @@ int qcom_smem_alloc(unsigned host, unsigned item, size_t size)
378} 378}
379EXPORT_SYMBOL(qcom_smem_alloc); 379EXPORT_SYMBOL(qcom_smem_alloc);
380 380
381static int qcom_smem_get_global(struct qcom_smem *smem, 381static void *qcom_smem_get_global(struct qcom_smem *smem,
382 unsigned item, 382 unsigned item,
383 void **ptr, 383 size_t *size)
384 size_t *size)
385{ 384{
386 struct smem_header *header; 385 struct smem_header *header;
387 struct smem_region *area; 386 struct smem_region *area;
@@ -390,36 +389,32 @@ static int qcom_smem_get_global(struct qcom_smem *smem,
390 unsigned i; 389 unsigned i;
391 390
392 if (WARN_ON(item >= SMEM_ITEM_COUNT)) 391 if (WARN_ON(item >= SMEM_ITEM_COUNT))
393 return -EINVAL; 392 return ERR_PTR(-EINVAL);
394 393
395 header = smem->regions[0].virt_base; 394 header = smem->regions[0].virt_base;
396 entry = &header->toc[item]; 395 entry = &header->toc[item];
397 if (!entry->allocated) 396 if (!entry->allocated)
398 return -ENXIO; 397 return ERR_PTR(-ENXIO);
399 398
400 if (ptr != NULL) { 399 aux_base = entry->aux_base & AUX_BASE_MASK;
401 aux_base = entry->aux_base & AUX_BASE_MASK;
402 400
403 for (i = 0; i < smem->num_regions; i++) { 401 for (i = 0; i < smem->num_regions; i++) {
404 area = &smem->regions[i]; 402 area = &smem->regions[i];
405 403
406 if (area->aux_base == aux_base || !aux_base) { 404 if (area->aux_base == aux_base || !aux_base) {
407 *ptr = area->virt_base + entry->offset; 405 if (size != NULL)
408 break; 406 *size = entry->size;
409 } 407 return area->virt_base + entry->offset;
410 } 408 }
411 } 409 }
412 if (size != NULL)
413 *size = entry->size;
414 410
415 return 0; 411 return ERR_PTR(-ENOENT);
416} 412}
417 413
418static int qcom_smem_get_private(struct qcom_smem *smem, 414static void *qcom_smem_get_private(struct qcom_smem *smem,
419 unsigned host, 415 unsigned host,
420 unsigned item, 416 unsigned item,
421 void **ptr, 417 size_t *size)
422 size_t *size)
423{ 418{
424 struct smem_partition_header *phdr; 419 struct smem_partition_header *phdr;
425 struct smem_private_entry *hdr; 420 struct smem_private_entry *hdr;
@@ -435,55 +430,54 @@ static int qcom_smem_get_private(struct qcom_smem *smem,
435 dev_err(smem->dev, 430 dev_err(smem->dev,
436 "Found invalid canary in host %d partition\n", 431 "Found invalid canary in host %d partition\n",
437 host); 432 host);
438 return -EINVAL; 433 return ERR_PTR(-EINVAL);
439 } 434 }
440 435
441 if (hdr->item == item) { 436 if (hdr->item == item) {
442 if (ptr != NULL)
443 *ptr = p + sizeof(*hdr) + hdr->padding_hdr;
444
445 if (size != NULL) 437 if (size != NULL)
446 *size = hdr->size - hdr->padding_data; 438 *size = hdr->size - hdr->padding_data;
447 439
448 return 0; 440 return p + sizeof(*hdr) + hdr->padding_hdr;
449 } 441 }
450 442
451 p += sizeof(*hdr) + hdr->padding_hdr + hdr->size; 443 p += sizeof(*hdr) + hdr->padding_hdr + hdr->size;
452 } 444 }
453 445
454 return -ENOENT; 446 return ERR_PTR(-ENOENT);
455} 447}
456 448
457/** 449/**
458 * qcom_smem_get() - resolve ptr of size of a smem item 450 * qcom_smem_get() - resolve ptr of size of a smem item
459 * @host: the remote processor, or -1 451 * @host: the remote processor, or -1
460 * @item: smem item handle 452 * @item: smem item handle
461 * @ptr: pointer to be filled out with address of the item
462 * @size: pointer to be filled out with size of the item 453 * @size: pointer to be filled out with size of the item
463 * 454 *
464 * Looks up pointer and size of a smem item. 455 * Looks up smem item and returns pointer to it. Size of smem
456 * item is returned in @size.
465 */ 457 */
466int qcom_smem_get(unsigned host, unsigned item, void **ptr, size_t *size) 458void *qcom_smem_get(unsigned host, unsigned item, size_t *size)
467{ 459{
468 unsigned long flags; 460 unsigned long flags;
469 int ret; 461 int ret;
462 void *ptr = ERR_PTR(-EPROBE_DEFER);
470 463
471 if (!__smem) 464 if (!__smem)
472 return -EPROBE_DEFER; 465 return ptr;
473 466
474 ret = hwspin_lock_timeout_irqsave(__smem->hwlock, 467 ret = hwspin_lock_timeout_irqsave(__smem->hwlock,
475 HWSPINLOCK_TIMEOUT, 468 HWSPINLOCK_TIMEOUT,
476 &flags); 469 &flags);
477 if (ret) 470 if (ret)
478 return ret; 471 return ERR_PTR(ret);
479 472
480 if (host < SMEM_HOST_COUNT && __smem->partitions[host]) 473 if (host < SMEM_HOST_COUNT && __smem->partitions[host])
481 ret = qcom_smem_get_private(__smem, host, item, ptr, size); 474 ptr = qcom_smem_get_private(__smem, host, item, size);
482 else 475 else
483 ret = qcom_smem_get_global(__smem, item, ptr, size); 476 ptr = qcom_smem_get_global(__smem, item, size);
484 477
485 hwspin_unlock_irqrestore(__smem->hwlock, &flags); 478 hwspin_unlock_irqrestore(__smem->hwlock, &flags);
486 return ret; 479
480 return ptr;
487 481
488} 482}
489EXPORT_SYMBOL(qcom_smem_get); 483EXPORT_SYMBOL(qcom_smem_get);
@@ -520,11 +514,9 @@ static int qcom_smem_get_sbl_version(struct qcom_smem *smem)
520{ 514{
521 unsigned *versions; 515 unsigned *versions;
522 size_t size; 516 size_t size;
523 int ret;
524 517
525 ret = qcom_smem_get_global(smem, SMEM_ITEM_VERSION, 518 versions = qcom_smem_get_global(smem, SMEM_ITEM_VERSION, &size);
526 (void **)&versions, &size); 519 if (IS_ERR(versions)) {
527 if (ret < 0) {
528 dev_err(smem->dev, "Unable to read the version item\n"); 520 dev_err(smem->dev, "Unable to read the version item\n");
529 return -ENOENT; 521 return -ENOENT;
530 } 522 }
diff --git a/include/linux/soc/qcom/smem.h b/include/linux/soc/qcom/smem.h
index bc9630d3aced..785e196ee2ca 100644
--- a/include/linux/soc/qcom/smem.h
+++ b/include/linux/soc/qcom/smem.h
@@ -4,7 +4,7 @@
4#define QCOM_SMEM_HOST_ANY -1 4#define QCOM_SMEM_HOST_ANY -1
5 5
6int qcom_smem_alloc(unsigned host, unsigned item, size_t size); 6int qcom_smem_alloc(unsigned host, unsigned item, size_t size);
7int qcom_smem_get(unsigned host, unsigned item, void **ptr, size_t *size); 7void *qcom_smem_get(unsigned host, unsigned item, size_t *size);
8 8
9int qcom_smem_get_free_space(unsigned host); 9int qcom_smem_get_free_space(unsigned host);
10 10