1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2021 Broadcom
6 #ifndef _TF_SRAM_MGR_H_
7 #define _TF_SRAM_MGR_H_
20 /* When special access registers are used to access the SRAM, stats can be
21 * automatically cleared on read by the hardware. This requires additional
22 * support to be added in the firmware to use these registers for statistics.
23 * The support entails using the special access registers to read the stats.
24 * These are stored in bank 3 currently but may move depending upon the
25 * policy defined in tf_device_p58.h
27 #define STATS_CLEAR_ON_READ_SUPPORT 0
29 #define TF_SRAM_MGR_BLOCK_SZ_BYTES 64
30 #define TF_SRAM_MGR_MIN_SLICE_BYTES 8
34 enum tf_sram_bank_id {
35 TF_SRAM_BANK_ID_0, /**< SRAM Bank 0 id */
36 TF_SRAM_BANK_ID_1, /**< SRAM Bank 1 id */
37 TF_SRAM_BANK_ID_2, /**< SRAM Bank 2 id */
38 TF_SRAM_BANK_ID_3, /**< SRAM Bank 3 id */
39 TF_SRAM_BANK_ID_MAX /**< SRAM Bank index limit */
45 * A slice is part of a 64B row
47 * Each slice is a multiple of 8B
49 enum tf_sram_slice_size {
50 TF_SRAM_SLICE_SIZE_8B, /**< 8 byte SRAM slice */
51 TF_SRAM_SLICE_SIZE_16B, /**< 16 byte SRAM slice */
52 TF_SRAM_SLICE_SIZE_32B, /**< 32 byte SRAM slice */
53 TF_SRAM_SLICE_SIZE_64B, /**< 64 byte SRAM slice */
54 TF_SRAM_SLICE_SIZE_MAX /**< slice limit */
58 /** Initialize the SRAM slice manager
60 * The SRAM slice manager manages slices within 64B rows. Slices are of size
61 * tf_sram_slice_size. This function provides a handle to the SRAM manager
64 * SRAM manager data may dynamically allocate data upon initialization if
65 * running on the host.
67 * [in/out] sram_handle
68 * Pointer to SRAM handle
72 * - (-EINVAL) on failure
74 * Returns the handle for the SRAM slice manager
76 int tf_sram_mgr_bind(void **sram_handle);
78 /** Uninitialize the SRAM slice manager
80 * Frees any dynamically allocated data structures for SRAM slice management.
83 * Pointer to SRAM handle
87 * - (-EINVAL) on failure
89 int tf_sram_mgr_unbind(void *sram_handle);
92 * tf_sram_mgr_alloc_parms parameter definition
94 struct tf_sram_mgr_alloc_parms {
102 * the SRAM bank to allocate from
104 enum tf_sram_bank_id bank_id;
108 * the slice size to allocate
110 enum tf_sram_slice_size slice_size;
112 * [in/out] sram_slice
114 * A pointer to be filled with an 8B sram slice offset
116 uint16_t *sram_offset;
118 * [in] RM DB Handle required for RM allocation
124 enum tf_tbl_type tbl_type;
128 * Allocate an SRAM Slice
130 * Allocate an SRAM slice from the indicated bank. If successful an 8B SRAM
131 * offset will be returned. Slices are variable sized. This may result in
132 * a row being allocated from the RM SRAM bank pool if required.
135 * Pointer to SRAM handle
138 * Pointer to the SRAM alloc parameters
141 * - (0) if successful
142 * - (-EINVAL) on failure
145 int tf_sram_mgr_alloc(void *sram_handle,
146 struct tf_sram_mgr_alloc_parms *parms);
148 * tf_sram_mgr_free_parms parameter definition
150 struct tf_sram_mgr_free_parms {
158 * the SRAM bank to free to
160 enum tf_sram_bank_id bank_id;
164 * the slice size to be returned
166 enum tf_sram_slice_size slice_size;
170 * the SRAM slice offset (8B) to be returned
172 uint16_t sram_offset;
174 * [in] RM DB Handle required for RM free
180 enum tf_tbl_type tbl_type;
181 #if (STATS_CLEAR_ON_READ_SUPPORT == 0)
185 * A pointer to the tf handle
194 * Free an SRAM slice to the indicated bank. This may result in a 64B row
195 * being returned to the RM SRAM bank pool.
198 * Pointer to SRAM handle
201 * Pointer to the SRAM free parameters
204 * - (0) if successful
205 * - (-EINVAL) on failure
208 int tf_sram_mgr_free(void *sram_handle,
209 struct tf_sram_mgr_free_parms *parms);
212 * tf_sram_mgr_dump_parms parameter definition
214 struct tf_sram_mgr_dump_parms {
222 * the SRAM bank to dump
224 enum tf_sram_bank_id bank_id;
228 * the slice size list to be dumped
230 enum tf_sram_slice_size slice_size;
236 * Dump the slice list given the SRAM bank and the slice size
239 * Pointer to SRAM handle
242 * Pointer to the SRAM free parameters
245 * - (0) if successful
246 * - (-EINVAL) on failure
249 int tf_sram_mgr_dump(void *sram_handle,
250 struct tf_sram_mgr_dump_parms *parms);
253 * tf_sram_mgr_is_allocated_parms parameter definition
255 struct tf_sram_mgr_is_allocated_parms {
263 * the SRAM bank to allocate from
265 enum tf_sram_bank_id bank_id;
269 * the slice size which was allocated
271 enum tf_sram_slice_size slice_size;
275 * The sram slice offset to validate
277 uint16_t sram_offset;
279 * [in/out] is_allocated
281 * Pointer passed in to be filled with indication of allocation
287 * Validate an SRAM Slice is allocated
289 * Validate whether the SRAM slice is allocated
292 * Pointer to SRAM handle
295 * Pointer to the SRAM alloc parameters
298 * - (0) if successful
299 * - (-EINVAL) on failure
302 int tf_sram_mgr_is_allocated(void *sram_handle,
303 struct tf_sram_mgr_is_allocated_parms *parms);
306 * Given the slice size, return a char string
309 *tf_sram_slice_2_str(enum tf_sram_slice_size slice_size);
312 * Given the bank_id, return a char string
315 *tf_sram_bank_2_str(enum tf_sram_bank_id bank_id);
317 #endif /* _TF_SRAM_MGR_H_ */