aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lew <clew@codeaurora.org>2017-10-11 17:29:09 -0400
committerAndy Gross <andy.gross@linaro.org>2017-10-12 00:48:27 -0400
commit5b3940676107dd65165b5eaea58fa60442d29a1f (patch)
tree4bc4a889fbff1fe5d474d656a4014edcb9dfa0c8
parentd52e404874369f10d20519f4095478d9cb4d6aad (diff)
soc: qcom: smem: Support dynamic item limit
In V12 SMEM, SBL writes SMEM parameter information after the TOC. Use the SBL provided item count as the max item number. Signed-off-by: Chris Lew <clew@codeaurora.org> Acked-by: Bjorn Andersson <bjorn.andersson@linaro.org> Signed-off-by: Andy Gross <andy.gross@linaro.org>
-rw-r--r--drivers/soc/qcom/smem.c51
1 files changed, 45 insertions, 6 deletions
diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c
index 6a3134e9c591..19704baa65f4 100644
--- a/drivers/soc/qcom/smem.c
+++ b/drivers/soc/qcom/smem.c
@@ -223,6 +223,24 @@ struct smem_private_entry {
223#define SMEM_PRIVATE_CANARY 0xa5a5 223#define SMEM_PRIVATE_CANARY 0xa5a5
224 224
225/** 225/**
226 * struct smem_info - smem region info located after the table of contents
227 * @magic: magic number, must be SMEM_INFO_MAGIC
228 * @size: size of the smem region
229 * @base_addr: base address of the smem region
230 * @reserved: for now reserved entry
231 * @num_items: highest accepted item number
232 */
233struct smem_info {
234 u8 magic[4];
235 __le32 size;
236 __le32 base_addr;
237 __le32 reserved;
238 __le16 num_items;
239};
240
241static const u8 SMEM_INFO_MAGIC[] = { 0x53, 0x49, 0x49, 0x49 }; /* SIII */
242
243/**
226 * struct smem_region - representation of a chunk of memory used for smem 244 * struct smem_region - representation of a chunk of memory used for smem
227 * @aux_base: identifier of aux_mem base 245 * @aux_base: identifier of aux_mem base
228 * @virt_base: virtual base address of memory with this aux_mem identifier 246 * @virt_base: virtual base address of memory with this aux_mem identifier
@@ -243,6 +261,7 @@ struct smem_region {
243 * @partitions: list of pointers to partitions affecting the current 261 * @partitions: list of pointers to partitions affecting the current
244 * processor/host 262 * processor/host
245 * @cacheline: list of cacheline sizes for each host 263 * @cacheline: list of cacheline sizes for each host
264 * @item_count: max accepted item number
246 * @num_regions: number of @regions 265 * @num_regions: number of @regions
247 * @regions: list of the memory regions defining the shared memory 266 * @regions: list of the memory regions defining the shared memory
248 */ 267 */
@@ -255,6 +274,7 @@ struct qcom_smem {
255 size_t global_cacheline; 274 size_t global_cacheline;
256 struct smem_partition_header *partitions[SMEM_HOST_COUNT]; 275 struct smem_partition_header *partitions[SMEM_HOST_COUNT];
257 size_t cacheline[SMEM_HOST_COUNT]; 276 size_t cacheline[SMEM_HOST_COUNT];
277 u32 item_count;
258 278
259 unsigned num_regions; 279 unsigned num_regions;
260 struct smem_region regions[0]; 280 struct smem_region regions[0];
@@ -386,9 +406,6 @@ static int qcom_smem_alloc_global(struct qcom_smem *smem,
386 struct smem_global_entry *entry; 406 struct smem_global_entry *entry;
387 struct smem_header *header; 407 struct smem_header *header;
388 408
389 if (WARN_ON(item >= SMEM_ITEM_COUNT))
390 return -EINVAL;
391
392 header = smem->regions[0].virt_base; 409 header = smem->regions[0].virt_base;
393 entry = &header->toc[item]; 410 entry = &header->toc[item];
394 if (entry->allocated) 411 if (entry->allocated)
@@ -439,6 +456,9 @@ int qcom_smem_alloc(unsigned host, unsigned item, size_t size)
439 return -EINVAL; 456 return -EINVAL;
440 } 457 }
441 458
459 if (WARN_ON(item >= __smem->item_count))
460 return -EINVAL;
461
442 ret = hwspin_lock_timeout_irqsave(__smem->hwlock, 462 ret = hwspin_lock_timeout_irqsave(__smem->hwlock,
443 HWSPINLOCK_TIMEOUT, 463 HWSPINLOCK_TIMEOUT,
444 &flags); 464 &flags);
@@ -471,9 +491,6 @@ static void *qcom_smem_get_global(struct qcom_smem *smem,
471 u32 aux_base; 491 u32 aux_base;
472 unsigned i; 492 unsigned i;
473 493
474 if (WARN_ON(item >= SMEM_ITEM_COUNT))
475 return ERR_PTR(-EINVAL);
476
477 header = smem->regions[0].virt_base; 494 header = smem->regions[0].virt_base;
478 entry = &header->toc[item]; 495 entry = &header->toc[item];
479 if (!entry->allocated) 496 if (!entry->allocated)
@@ -569,6 +586,9 @@ void *qcom_smem_get(unsigned host, unsigned item, size_t *size)
569 if (!__smem) 586 if (!__smem)
570 return ptr; 587 return ptr;
571 588
589 if (WARN_ON(item >= __smem->item_count))
590 return ERR_PTR(-EINVAL);
591
572 ret = hwspin_lock_timeout_irqsave(__smem->hwlock, 592 ret = hwspin_lock_timeout_irqsave(__smem->hwlock,
573 HWSPINLOCK_TIMEOUT, 593 HWSPINLOCK_TIMEOUT,
574 &flags); 594 &flags);
@@ -656,6 +676,22 @@ static struct smem_ptable *qcom_smem_get_ptable(struct qcom_smem *smem)
656 return ptable; 676 return ptable;
657} 677}
658 678
679static u32 qcom_smem_get_item_count(struct qcom_smem *smem)
680{
681 struct smem_ptable *ptable;
682 struct smem_info *info;
683
684 ptable = qcom_smem_get_ptable(smem);
685 if (IS_ERR_OR_NULL(ptable))
686 return SMEM_ITEM_COUNT;
687
688 info = (struct smem_info *)&ptable->entry[ptable->num_entries];
689 if (memcmp(info->magic, SMEM_INFO_MAGIC, sizeof(info->magic)))
690 return SMEM_ITEM_COUNT;
691
692 return le16_to_cpu(info->num_items);
693}
694
659static int qcom_smem_set_global_partition(struct qcom_smem *smem) 695static int qcom_smem_set_global_partition(struct qcom_smem *smem)
660{ 696{
661 struct smem_partition_header *header; 697 struct smem_partition_header *header;
@@ -883,7 +919,10 @@ static int qcom_smem_probe(struct platform_device *pdev)
883 ret = qcom_smem_set_global_partition(smem); 919 ret = qcom_smem_set_global_partition(smem);
884 if (ret < 0) 920 if (ret < 0)
885 return ret; 921 return ret;
922 smem->item_count = qcom_smem_get_item_count(smem);
923 break;
886 case SMEM_GLOBAL_HEAP_VERSION: 924 case SMEM_GLOBAL_HEAP_VERSION:
925 smem->item_count = SMEM_ITEM_COUNT;
887 break; 926 break;
888 default: 927 default:
889 dev_err(&pdev->dev, "Unsupported SMEM version 0x%x\n", version); 928 dev_err(&pdev->dev, "Unsupported SMEM version 0x%x\n", version);