This source file includes following definitions.
- cc_sram_mgr_fini
- cc_sram_mgr_init
- cc_sram_alloc
- cc_set_sram_desc
1
2
3
4 #include "cc_driver.h"
5 #include "cc_sram_mgr.h"
6
7
8
9
10
11 struct cc_sram_ctx {
12 cc_sram_addr_t sram_free_offset;
13 };
14
15
16
17
18
19
20 void cc_sram_mgr_fini(struct cc_drvdata *drvdata)
21 {
22
23 }
24
25
26
27
28
29
30
31
32 int cc_sram_mgr_init(struct cc_drvdata *drvdata)
33 {
34 struct cc_sram_ctx *ctx;
35 dma_addr_t start = 0;
36 struct device *dev = drvdata_to_dev(drvdata);
37
38 if (drvdata->hw_rev < CC_HW_REV_712) {
39
40 start = (dma_addr_t)cc_ioread(drvdata,
41 CC_REG(HOST_SEP_SRAM_THRESHOLD));
42
43 if ((start & 0x3) != 0) {
44 dev_err(dev, "Invalid SRAM offset %pad\n", &start);
45 return -EINVAL;
46 }
47 }
48
49
50 ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
51
52 if (!ctx)
53 return -ENOMEM;
54
55 ctx->sram_free_offset = start;
56 drvdata->sram_mgr_handle = ctx;
57
58 return 0;
59 }
60
61
62
63
64
65
66
67
68
69
70 cc_sram_addr_t cc_sram_alloc(struct cc_drvdata *drvdata, u32 size)
71 {
72 struct cc_sram_ctx *smgr_ctx = drvdata->sram_mgr_handle;
73 struct device *dev = drvdata_to_dev(drvdata);
74 cc_sram_addr_t p;
75
76 if ((size & 0x3)) {
77 dev_err(dev, "Requested buffer size (%u) is not multiple of 4",
78 size);
79 return NULL_SRAM_ADDR;
80 }
81 if (size > (CC_CC_SRAM_SIZE - smgr_ctx->sram_free_offset)) {
82 dev_err(dev, "Not enough space to allocate %u B (at offset %llu)\n",
83 size, smgr_ctx->sram_free_offset);
84 return NULL_SRAM_ADDR;
85 }
86
87 p = smgr_ctx->sram_free_offset;
88 smgr_ctx->sram_free_offset += size;
89 dev_dbg(dev, "Allocated %u B @ %u\n", size, (unsigned int)p);
90 return p;
91 }
92
93
94
95
96
97
98
99
100
101
102
103
104 void cc_set_sram_desc(const u32 *src, cc_sram_addr_t dst,
105 unsigned int nelement, struct cc_hw_desc *seq,
106 unsigned int *seq_len)
107 {
108 u32 i;
109 unsigned int idx = *seq_len;
110
111 for (i = 0; i < nelement; i++, idx++) {
112 hw_desc_init(&seq[idx]);
113 set_din_const(&seq[idx], src[i], sizeof(u32));
114 set_dout_sram(&seq[idx], dst + (i * sizeof(u32)), sizeof(u32));
115 set_flow_mode(&seq[idx], BYPASS);
116 }
117
118 *seq_len = idx;
119 }