.. | .. |
---|
1 | 1 | // SPDX-License-Identifier: GPL-2.0 |
---|
2 | | -/* Copyright (C) 2012-2018 ARM Limited or its affiliates. */ |
---|
| 2 | +/* Copyright (C) 2012-2019 ARM Limited (or its affiliates). */ |
---|
3 | 3 | |
---|
4 | 4 | #include "cc_driver.h" |
---|
5 | 5 | #include "cc_sram_mgr.h" |
---|
6 | | - |
---|
7 | | -/** |
---|
8 | | - * struct cc_sram_ctx -Internal RAM context manager |
---|
9 | | - * @sram_free_offset: the offset to the non-allocated area |
---|
10 | | - */ |
---|
11 | | -struct cc_sram_ctx { |
---|
12 | | - cc_sram_addr_t sram_free_offset; |
---|
13 | | -}; |
---|
14 | | - |
---|
15 | | -/** |
---|
16 | | - * cc_sram_mgr_fini() - Cleanup SRAM pool. |
---|
17 | | - * |
---|
18 | | - * @drvdata: Associated device driver context |
---|
19 | | - */ |
---|
20 | | -void cc_sram_mgr_fini(struct cc_drvdata *drvdata) |
---|
21 | | -{ |
---|
22 | | - /* Free "this" context */ |
---|
23 | | - kfree(drvdata->sram_mgr_handle); |
---|
24 | | -} |
---|
25 | 6 | |
---|
26 | 7 | /** |
---|
27 | 8 | * cc_sram_mgr_init() - Initializes SRAM pool. |
---|
.. | .. |
---|
29 | 10 | * Returns zero for success, negative value otherwise. |
---|
30 | 11 | * |
---|
31 | 12 | * @drvdata: Associated device driver context |
---|
| 13 | + * |
---|
| 14 | + * Return: |
---|
| 15 | + * 0 for success, negative error code for failure. |
---|
32 | 16 | */ |
---|
33 | 17 | int cc_sram_mgr_init(struct cc_drvdata *drvdata) |
---|
34 | 18 | { |
---|
35 | | - struct cc_sram_ctx *ctx; |
---|
36 | | - dma_addr_t start = 0; |
---|
| 19 | + u32 start = 0; |
---|
37 | 20 | struct device *dev = drvdata_to_dev(drvdata); |
---|
38 | 21 | |
---|
39 | 22 | if (drvdata->hw_rev < CC_HW_REV_712) { |
---|
40 | 23 | /* Pool starts after ROM bytes */ |
---|
41 | | - start = (dma_addr_t)cc_ioread(drvdata, |
---|
42 | | - CC_REG(HOST_SEP_SRAM_THRESHOLD)); |
---|
43 | | - |
---|
| 24 | + start = cc_ioread(drvdata, CC_REG(HOST_SEP_SRAM_THRESHOLD)); |
---|
44 | 25 | if ((start & 0x3) != 0) { |
---|
45 | | - dev_err(dev, "Invalid SRAM offset %pad\n", &start); |
---|
| 26 | + dev_err(dev, "Invalid SRAM offset 0x%x\n", start); |
---|
46 | 27 | return -EINVAL; |
---|
47 | 28 | } |
---|
48 | 29 | } |
---|
49 | 30 | |
---|
50 | | - /* Allocate "this" context */ |
---|
51 | | - ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); |
---|
52 | | - |
---|
53 | | - if (!ctx) |
---|
54 | | - return -ENOMEM; |
---|
55 | | - |
---|
56 | | - ctx->sram_free_offset = start; |
---|
57 | | - drvdata->sram_mgr_handle = ctx; |
---|
58 | | - |
---|
| 31 | + drvdata->sram_free_offset = start; |
---|
59 | 32 | return 0; |
---|
60 | 33 | } |
---|
61 | 34 | |
---|
62 | | -/*! |
---|
63 | | - * Allocated buffer from SRAM pool. |
---|
64 | | - * Note: Caller is responsible to free the LAST allocated buffer. |
---|
65 | | - * This function does not taking care of any fragmentation may occur |
---|
66 | | - * by the order of calls to alloc/free. |
---|
| 35 | +/** |
---|
| 36 | + * cc_sram_alloc() - Allocate buffer from SRAM pool. |
---|
67 | 37 | * |
---|
68 | | - * \param drvdata |
---|
69 | | - * \param size The requested bytes to allocate |
---|
| 38 | + * @drvdata: Associated device driver context |
---|
| 39 | + * @size: The requested numer of bytes to allocate |
---|
| 40 | + * |
---|
| 41 | + * Return: |
---|
| 42 | + * Address offset in SRAM or NULL_SRAM_ADDR for failure. |
---|
70 | 43 | */ |
---|
71 | | -cc_sram_addr_t cc_sram_alloc(struct cc_drvdata *drvdata, u32 size) |
---|
| 44 | +u32 cc_sram_alloc(struct cc_drvdata *drvdata, u32 size) |
---|
72 | 45 | { |
---|
73 | | - struct cc_sram_ctx *smgr_ctx = drvdata->sram_mgr_handle; |
---|
74 | 46 | struct device *dev = drvdata_to_dev(drvdata); |
---|
75 | | - cc_sram_addr_t p; |
---|
| 47 | + u32 p; |
---|
76 | 48 | |
---|
77 | 49 | if ((size & 0x3)) { |
---|
78 | 50 | dev_err(dev, "Requested buffer size (%u) is not multiple of 4", |
---|
79 | 51 | size); |
---|
80 | 52 | return NULL_SRAM_ADDR; |
---|
81 | 53 | } |
---|
82 | | - if (size > (CC_CC_SRAM_SIZE - smgr_ctx->sram_free_offset)) { |
---|
83 | | - dev_err(dev, "Not enough space to allocate %u B (at offset %llu)\n", |
---|
84 | | - size, smgr_ctx->sram_free_offset); |
---|
| 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); |
---|
85 | 57 | return NULL_SRAM_ADDR; |
---|
86 | 58 | } |
---|
87 | 59 | |
---|
88 | | - p = smgr_ctx->sram_free_offset; |
---|
89 | | - smgr_ctx->sram_free_offset += size; |
---|
90 | | - dev_dbg(dev, "Allocated %u B @ %u\n", size, (unsigned int)p); |
---|
| 60 | + p = drvdata->sram_free_offset; |
---|
| 61 | + drvdata->sram_free_offset += size; |
---|
| 62 | + dev_dbg(dev, "Allocated %u B @ %u\n", size, p); |
---|
91 | 63 | return p; |
---|
92 | 64 | } |
---|
93 | 65 | |
---|
.. | .. |
---|
98 | 70 | * |
---|
99 | 71 | * @src: A pointer to array of words to set as consts. |
---|
100 | 72 | * @dst: The target SRAM buffer to set into |
---|
101 | | - * @nelements: The number of words in "src" array |
---|
| 73 | + * @nelement: The number of words in "src" array |
---|
102 | 74 | * @seq: A pointer to the given IN/OUT descriptor sequence |
---|
103 | 75 | * @seq_len: A pointer to the given IN/OUT sequence length |
---|
104 | 76 | */ |
---|
105 | | -void cc_set_sram_desc(const u32 *src, cc_sram_addr_t dst, |
---|
106 | | - unsigned int nelement, struct cc_hw_desc *seq, |
---|
107 | | - unsigned int *seq_len) |
---|
| 77 | +void cc_set_sram_desc(const u32 *src, u32 dst, unsigned int nelement, |
---|
| 78 | + struct cc_hw_desc *seq, unsigned int *seq_len) |
---|
108 | 79 | { |
---|
109 | 80 | u32 i; |
---|
110 | 81 | unsigned int idx = *seq_len; |
---|