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
35 * A slice is part of a 64B row
37 * Each slice is a multiple of 8B
39 enum tf_sram_slice_size {
40 TF_SRAM_SLICE_SIZE_8B, /**< 8 byte SRAM slice */
41 TF_SRAM_SLICE_SIZE_16B, /**< 16 byte SRAM slice */
42 TF_SRAM_SLICE_SIZE_32B, /**< 32 byte SRAM slice */
43 TF_SRAM_SLICE_SIZE_64B, /**< 64 byte SRAM slice */
44 TF_SRAM_SLICE_SIZE_MAX /**< slice limit */
48 /** Initialize the SRAM slice manager
50 * The SRAM slice manager manages slices within 64B rows. Slices are of size
51 * tf_sram_slice_size. This function provides a handle to the SRAM manager
54 * SRAM manager data may dynamically allocate data upon initialization if
55 * running on the host.
57 * [in/out] sram_handle
58 * Pointer to SRAM handle
62 * - (-EINVAL) on failure
64 * Returns the handle for the SRAM slice manager
66 int tf_sram_mgr_bind(void **sram_handle);
68 /** Uninitialize the SRAM slice manager
70 * Frees any dynamically allocated data structures for SRAM slice management.
73 * Pointer to SRAM handle
77 * - (-EINVAL) on failure
79 int tf_sram_mgr_unbind(void *sram_handle);
82 * tf_sram_mgr_alloc_parms parameter definition
84 struct tf_sram_mgr_alloc_parms {
92 * the SRAM bank to allocate from
94 enum tf_sram_bank_id bank_id;
98 * the slice size to allocate
100 enum tf_sram_slice_size slice_size;
102 * [in/out] sram_slice
104 * A pointer to be filled with an 8B sram slice offset
106 uint16_t *sram_offset;
108 * [in] RM DB Handle required for RM allocation
114 enum tf_tbl_type tbl_type;
118 * Allocate an SRAM Slice
120 * Allocate an SRAM slice from the indicated bank. If successful an 8B SRAM
121 * offset will be returned. Slices are variable sized. This may result in
122 * a row being allocated from the RM SRAM bank pool if required.
125 * Pointer to SRAM handle
128 * Pointer to the SRAM alloc parameters
131 * - (0) if successful
132 * - (-EINVAL) on failure
135 int tf_sram_mgr_alloc(void *sram_handle,
136 struct tf_sram_mgr_alloc_parms *parms);
138 * tf_sram_mgr_free_parms parameter definition
140 struct tf_sram_mgr_free_parms {
148 * the SRAM bank to free to
150 enum tf_sram_bank_id bank_id;
154 * the slice size to be returned
156 enum tf_sram_slice_size slice_size;
160 * the SRAM slice offset (8B) to be returned
162 uint16_t sram_offset;
164 * [in] RM DB Handle required for RM free
170 enum tf_tbl_type tbl_type;
171 #if (STATS_CLEAR_ON_READ_SUPPORT == 0)
175 * A pointer to the tf handle
184 * Free an SRAM slice to the indicated bank. This may result in a 64B row
185 * being returned to the RM SRAM bank pool.
188 * Pointer to SRAM handle
191 * Pointer to the SRAM free parameters
194 * - (0) if successful
195 * - (-EINVAL) on failure
198 int tf_sram_mgr_free(void *sram_handle,
199 struct tf_sram_mgr_free_parms *parms);
202 * tf_sram_mgr_dump_parms parameter definition
204 struct tf_sram_mgr_dump_parms {
212 * the SRAM bank to dump
214 enum tf_sram_bank_id bank_id;
218 * the slice size list to be dumped
220 enum tf_sram_slice_size slice_size;
226 * Dump the slice list given the SRAM bank and the slice size
229 * Pointer to SRAM handle
232 * Pointer to the SRAM free parameters
235 * - (0) if successful
236 * - (-EINVAL) on failure
239 int tf_sram_mgr_dump(void *sram_handle,
240 struct tf_sram_mgr_dump_parms *parms);
243 * tf_sram_mgr_is_allocated_parms parameter definition
245 struct tf_sram_mgr_is_allocated_parms {
253 * the SRAM bank to allocate from
255 enum tf_sram_bank_id bank_id;
259 * the slice size which was allocated
261 enum tf_sram_slice_size slice_size;
265 * The sram slice offset to validate
267 uint16_t sram_offset;
269 * [in/out] is_allocated
271 * Pointer passed in to be filled with indication of allocation
277 * Validate an SRAM Slice is allocated
279 * Validate whether the SRAM slice is allocated
282 * Pointer to SRAM handle
285 * Pointer to the SRAM alloc parameters
288 * - (0) if successful
289 * - (-EINVAL) on failure
292 int tf_sram_mgr_is_allocated(void *sram_handle,
293 struct tf_sram_mgr_is_allocated_parms *parms);
296 * Given the slice size, return a char string
299 *tf_sram_slice_2_str(enum tf_sram_slice_size slice_size);
302 * Given the bank_id, return a char string
305 *tf_sram_bank_2_str(enum tf_sram_bank_id bank_id);
307 #endif /* _TF_SRAM_MGR_H_ */