1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2012-2019 ARM Limited (or its affiliates). */
5 #include "cc_sram_mgr.h"
8 * cc_sram_mgr_init() - Initializes SRAM pool.
9 * The pool starts right at the beginning of SRAM.
10 * Returns zero for success, negative value otherwise.
12 * @drvdata: Associated device driver context
15 * 0 for success, negative error code for failure.
17 int cc_sram_mgr_init(struct cc_drvdata *drvdata)
20 struct device *dev = drvdata_to_dev(drvdata);
22 if (drvdata->hw_rev < CC_HW_REV_712) {
23 /* Pool starts after ROM bytes */
24 start = cc_ioread(drvdata, CC_REG(HOST_SEP_SRAM_THRESHOLD));
25 if ((start & 0x3) != 0) {
26 dev_err(dev, "Invalid SRAM offset 0x%x\n", start);
31 drvdata->sram_free_offset = start;
36 * cc_sram_alloc() - Allocate buffer from SRAM pool.
38 * @drvdata: Associated device driver context
39 * @size: The requested numer of bytes to allocate
42 * Address offset in SRAM or NULL_SRAM_ADDR for failure.
44 u32 cc_sram_alloc(struct cc_drvdata *drvdata, u32 size)
46 struct device *dev = drvdata_to_dev(drvdata);
50 dev_err(dev, "Requested buffer size (%u) is not multiple of 4",
52 return NULL_SRAM_ADDR;
54 if (size > (CC_CC_SRAM_SIZE - drvdata->sram_free_offset)) {
55 dev_err(dev, "Not enough space to allocate %u B (at offset %u)\n",
56 size, drvdata->sram_free_offset);
57 return NULL_SRAM_ADDR;
60 p = drvdata->sram_free_offset;
61 drvdata->sram_free_offset += size;
62 dev_dbg(dev, "Allocated %u B @ %u\n", size, p);
67 * cc_set_sram_desc() - Create const descriptors sequence to
68 * set values in given array into SRAM.
69 * Note: each const value can't exceed word size.
71 * @src: A pointer to array of words to set as consts.
72 * @dst: The target SRAM buffer to set into
73 * @nelement: The number of words in "src" array
74 * @seq: A pointer to the given IN/OUT descriptor sequence
75 * @seq_len: A pointer to the given IN/OUT sequence length
77 void cc_set_sram_desc(const u32 *src, u32 dst, unsigned int nelement,
78 struct cc_hw_desc *seq, unsigned int *seq_len)
81 unsigned int idx = *seq_len;
83 for (i = 0; i < nelement; i++, idx++) {
84 hw_desc_init(&seq[idx]);
85 set_din_const(&seq[idx], src[i], sizeof(u32));
86 set_dout_sram(&seq[idx], dst + (i * sizeof(u32)), sizeof(u32));
87 set_flow_mode(&seq[idx], BYPASS);