Commit 1a03964d authored by Stephen Boyd's avatar Stephen Boyd Committed by Andy Gross

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: default avatarStephen Boyd <sboyd@codeaurora.org>
Reviewed-by: default avatarBjorn Andersson <bjorn.andersson@sonymobile.com>
Signed-off-by: default avatarAndy Gross <agross@codeaurora.org>
parent 7d0c8bee
...@@ -989,10 +989,11 @@ static struct qcom_smd_channel *qcom_smd_create_channel(struct qcom_smd_edge *ed ...@@ -989,10 +989,11 @@ static struct qcom_smd_channel *qcom_smd_create_channel(struct qcom_smd_edge *ed
spin_lock_init(&channel->recv_lock); spin_lock_init(&channel->recv_lock);
init_waitqueue_head(&channel->fblockread_event); init_waitqueue_head(&channel->fblockread_event);
ret = qcom_smem_get(edge->remote_pid, smem_info_item, (void **)&info, info = qcom_smem_get(edge->remote_pid, smem_info_item, &info_size);
&info_size); if (IS_ERR(info)) {
if (ret) ret = PTR_ERR(info);
goto free_name_and_channel; goto free_name_and_channel;
}
/* /*
* Use the size of the item to figure out which channel info struct to * 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,10 +1012,11 @@ static struct qcom_smd_channel *qcom_smd_create_channel(struct qcom_smd_edge *ed
goto free_name_and_channel; goto free_name_and_channel;
} }
ret = qcom_smem_get(edge->remote_pid, smem_fifo_item, &fifo_base, fifo_base = qcom_smem_get(edge->remote_pid, smem_fifo_item, &fifo_size);
&fifo_size); if (IS_ERR(fifo_base)) {
if (ret) ret = PTR_ERR(fifo_base);
goto free_name_and_channel; goto free_name_and_channel;
}
/* The channel consist of a rx and tx fifo of equal size */ /* The channel consist of a rx and tx fifo of equal size */
fifo_size /= 2; fifo_size /= 2;
...@@ -1051,16 +1053,13 @@ static void qcom_discover_channels(struct qcom_smd_edge *edge) ...@@ -1051,16 +1053,13 @@ static void qcom_discover_channels(struct qcom_smd_edge *edge)
unsigned long flags; unsigned long flags;
unsigned fifo_id; unsigned fifo_id;
unsigned info_id; unsigned info_id;
int ret;
int tbl; int tbl;
int i; int i;
for (tbl = 0; tbl < SMD_ALLOC_TBL_COUNT; tbl++) { for (tbl = 0; tbl < SMD_ALLOC_TBL_COUNT; tbl++) {
ret = qcom_smem_get(edge->remote_pid, alloc_tbl = qcom_smem_get(edge->remote_pid,
smem_items[tbl].alloc_tbl_id, smem_items[tbl].alloc_tbl_id, NULL);
(void **)&alloc_tbl, if (IS_ERR(alloc_tbl))
NULL);
if (ret < 0)
continue; continue;
for (i = 0; i < SMD_ALLOC_TBL_SIZE; i++) { for (i = 0; i < SMD_ALLOC_TBL_SIZE; i++) {
...@@ -1238,11 +1237,12 @@ static int qcom_smd_probe(struct platform_device *pdev) ...@@ -1238,11 +1237,12 @@ static int qcom_smd_probe(struct platform_device *pdev)
int num_edges; int num_edges;
int ret; int ret;
int i = 0; int i = 0;
void *p;
/* Wait for smem */ /* Wait for smem */
ret = qcom_smem_get(QCOM_SMEM_HOST_ANY, smem_items[0].alloc_tbl_id, NULL, NULL); p = qcom_smem_get(QCOM_SMEM_HOST_ANY, smem_items[0].alloc_tbl_id, NULL);
if (ret == -EPROBE_DEFER) if (PTR_ERR(p) == -EPROBE_DEFER)
return ret; return PTR_ERR(p);
num_edges = of_get_available_child_count(pdev->dev.of_node); num_edges = of_get_available_child_count(pdev->dev.of_node);
array_size = sizeof(*smd) + num_edges * sizeof(struct qcom_smd_edge); array_size = sizeof(*smd) + num_edges * sizeof(struct qcom_smd_edge);
......
...@@ -378,10 +378,9 @@ int qcom_smem_alloc(unsigned host, unsigned item, size_t size) ...@@ -378,10 +378,9 @@ int qcom_smem_alloc(unsigned host, unsigned item, size_t size)
} }
EXPORT_SYMBOL(qcom_smem_alloc); EXPORT_SYMBOL(qcom_smem_alloc);
static int qcom_smem_get_global(struct qcom_smem *smem, static void *qcom_smem_get_global(struct qcom_smem *smem,
unsigned item, unsigned item,
void **ptr, size_t *size)
size_t *size)
{ {
struct smem_header *header; struct smem_header *header;
struct smem_region *area; struct smem_region *area;
...@@ -390,36 +389,32 @@ static int qcom_smem_get_global(struct qcom_smem *smem, ...@@ -390,36 +389,32 @@ static int qcom_smem_get_global(struct qcom_smem *smem,
unsigned i; unsigned i;
if (WARN_ON(item >= SMEM_ITEM_COUNT)) if (WARN_ON(item >= SMEM_ITEM_COUNT))
return -EINVAL; return ERR_PTR(-EINVAL);
header = smem->regions[0].virt_base; header = smem->regions[0].virt_base;
entry = &header->toc[item]; entry = &header->toc[item];
if (!entry->allocated) if (!entry->allocated)
return -ENXIO; return ERR_PTR(-ENXIO);
if (ptr != NULL) { aux_base = entry->aux_base & AUX_BASE_MASK;
aux_base = entry->aux_base & AUX_BASE_MASK;
for (i = 0; i < smem->num_regions; i++) { for (i = 0; i < smem->num_regions; i++) {
area = &smem->regions[i]; area = &smem->regions[i];
if (area->aux_base == aux_base || !aux_base) { if (area->aux_base == aux_base || !aux_base) {
*ptr = area->virt_base + entry->offset; if (size != NULL)
break; *size = entry->size;
} return area->virt_base + entry->offset;
} }
} }
if (size != NULL)
*size = entry->size;
return 0; return ERR_PTR(-ENOENT);
} }
static int qcom_smem_get_private(struct qcom_smem *smem, static void *qcom_smem_get_private(struct qcom_smem *smem,
unsigned host, unsigned host,
unsigned item, unsigned item,
void **ptr, size_t *size)
size_t *size)
{ {
struct smem_partition_header *phdr; struct smem_partition_header *phdr;
struct smem_private_entry *hdr; struct smem_private_entry *hdr;
...@@ -435,55 +430,54 @@ static int qcom_smem_get_private(struct qcom_smem *smem, ...@@ -435,55 +430,54 @@ static int qcom_smem_get_private(struct qcom_smem *smem,
dev_err(smem->dev, dev_err(smem->dev,
"Found invalid canary in host %d partition\n", "Found invalid canary in host %d partition\n",
host); host);
return -EINVAL; return ERR_PTR(-EINVAL);
} }
if (hdr->item == item) { if (hdr->item == item) {
if (ptr != NULL)
*ptr = p + sizeof(*hdr) + hdr->padding_hdr;
if (size != NULL) if (size != NULL)
*size = hdr->size - hdr->padding_data; *size = hdr->size - hdr->padding_data;
return 0; return p + sizeof(*hdr) + hdr->padding_hdr;
} }
p += sizeof(*hdr) + hdr->padding_hdr + hdr->size; p += sizeof(*hdr) + hdr->padding_hdr + hdr->size;
} }
return -ENOENT; return ERR_PTR(-ENOENT);
} }
/** /**
* qcom_smem_get() - resolve ptr of size of a smem item * qcom_smem_get() - resolve ptr of size of a smem item
* @host: the remote processor, or -1 * @host: the remote processor, or -1
* @item: smem item handle * @item: smem item handle
* @ptr: pointer to be filled out with address of the item
* @size: pointer to be filled out with size of the item * @size: pointer to be filled out with size of the item
* *
* Looks up pointer and size of a smem item. * Looks up smem item and returns pointer to it. Size of smem
* item is returned in @size.
*/ */
int qcom_smem_get(unsigned host, unsigned item, void **ptr, size_t *size) void *qcom_smem_get(unsigned host, unsigned item, size_t *size)
{ {
unsigned long flags; unsigned long flags;
int ret; int ret;
void *ptr = ERR_PTR(-EPROBE_DEFER);
if (!__smem) if (!__smem)
return -EPROBE_DEFER; return ptr;
ret = hwspin_lock_timeout_irqsave(__smem->hwlock, ret = hwspin_lock_timeout_irqsave(__smem->hwlock,
HWSPINLOCK_TIMEOUT, HWSPINLOCK_TIMEOUT,
&flags); &flags);
if (ret) if (ret)
return ret; return ERR_PTR(ret);
if (host < SMEM_HOST_COUNT && __smem->partitions[host]) if (host < SMEM_HOST_COUNT && __smem->partitions[host])
ret = qcom_smem_get_private(__smem, host, item, ptr, size); ptr = qcom_smem_get_private(__smem, host, item, size);
else else
ret = qcom_smem_get_global(__smem, item, ptr, size); ptr = qcom_smem_get_global(__smem, item, size);
hwspin_unlock_irqrestore(__smem->hwlock, &flags); hwspin_unlock_irqrestore(__smem->hwlock, &flags);
return ret;
return ptr;
} }
EXPORT_SYMBOL(qcom_smem_get); EXPORT_SYMBOL(qcom_smem_get);
...@@ -520,11 +514,9 @@ static int qcom_smem_get_sbl_version(struct qcom_smem *smem) ...@@ -520,11 +514,9 @@ static int qcom_smem_get_sbl_version(struct qcom_smem *smem)
{ {
unsigned *versions; unsigned *versions;
size_t size; size_t size;
int ret;
ret = qcom_smem_get_global(smem, SMEM_ITEM_VERSION, versions = qcom_smem_get_global(smem, SMEM_ITEM_VERSION, &size);
(void **)&versions, &size); if (IS_ERR(versions)) {
if (ret < 0) {
dev_err(smem->dev, "Unable to read the version item\n"); dev_err(smem->dev, "Unable to read the version item\n");
return -ENOENT; return -ENOENT;
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#define QCOM_SMEM_HOST_ANY -1 #define QCOM_SMEM_HOST_ANY -1
int qcom_smem_alloc(unsigned host, unsigned item, size_t size); int qcom_smem_alloc(unsigned host, unsigned item, size_t size);
int qcom_smem_get(unsigned host, unsigned item, void **ptr, size_t *size); void *qcom_smem_get(unsigned host, unsigned item, size_t *size);
int qcom_smem_get_free_space(unsigned host); int qcom_smem_get_free_space(unsigned host);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment