1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2020 Broadcom
15 * The Resource Manager (RM) module provides basic DB handling for
16 * internal resources. These resources exists within the actual device
17 * and are controlled by the HCAPI Resource Manager running on the
20 * The RM DBs are all intended to be indexed using TF types there for
21 * a lookup requires no additional conversion. The DB configuration
22 * specifies the TF Type to HCAPI Type mapping and it becomes the
23 * responsibility of the DB initialization to handle this static
26 * Accessor functions are providing access to the DB, thus hiding the
29 * The RM DB will work on its initial allocated sizes so the
30 * capability of dynamically growing a particular resource is not
31 * possible. If this capability later becomes a requirement then the
32 * MAX pool size of the Chip Å“needs to be added to the tf_rm_elem_info
33 * structure and several new APIs would need to be added to allow for
34 * growth of a single TF resource type.
36 * The access functions does not check for NULL pointers as it's a
37 * support module, not called directly.
41 * Resource reservation single entry result. Used when accessing HCAPI
44 struct tf_rm_new_entry {
45 /** Starting index of the allocated resource */
47 /** Number of allocated elements */
52 * RM Element configuration enumeration. Used by the Device to
53 * indicate how the RM elements the DB consists off, are to be
54 * configured at time of DB creation. The TF may present types to the
55 * ULP layer that is not controlled by HCAPI within the Firmware.
57 enum tf_rm_elem_cfg_type {
58 /** No configuration */
60 /** HCAPI 'controlled' */
62 /** Private thus not HCAPI 'controlled' */
63 TF_RM_ELEM_CFG_PRIVATE,
65 * Shared element thus it belongs to a shared FW Session and
66 * is not controlled by the Host.
68 TF_RM_ELEM_CFG_SHARED,
73 * RM Reservation strategy enumeration. Type of strategy comes from
74 * the HCAPI RM QCAPS handshake.
76 enum tf_rm_resc_resv_strategy {
77 TF_RM_RESC_RESV_STATIC_PARTITION,
78 TF_RM_RESC_RESV_STRATEGY_1,
79 TF_RM_RESC_RESV_STRATEGY_2,
80 TF_RM_RESC_RESV_STRATEGY_3,
85 * RM Element configuration structure, used by the Device to configure
86 * how an individual TF type is configured in regard to the HCAPI RM
89 struct tf_rm_element_cfg {
91 * RM Element config controls how the DB for that element is
94 enum tf_rm_elem_cfg_type cfg_type;
96 /* If a HCAPI to TF type conversion is required then TF type
101 * HCAPI RM Type for the element. Used for TF to HCAPI type
108 * Allocation information for a single element.
110 struct tf_rm_alloc_info {
112 * HCAPI RM allocated range information.
115 * In case of dynamic allocation support this would have
116 * to be changed to linked list of tf_rm_entry instead.
118 struct tf_rm_new_entry entry;
122 * Create RM DB parameters
124 struct tf_rm_create_db_parms {
126 * [in] Receive or transmit direction
130 * [in] Number of elements.
132 uint16_t num_elements;
134 * [in] Parameter structure array. Array size is num_elements.
136 struct tf_rm_element_cfg *cfg;
138 * Allocation number array. Array size is num_elements.
148 * Free RM DB parameters
150 struct tf_rm_free_db_parms {
152 * [in] Receive or transmit direction
162 * Allocate RM parameters for a single element
164 struct tf_rm_allocate_parms {
170 * [in] DB Index, indicates which DB entry to perform the
175 * [in] Pointer to the allocated index in normalized
176 * form. Normalized means the index has been adjusted,
177 * i.e. Full Action Record offsets.
183 * Free RM parameters for a single element
185 struct tf_rm_free_parms {
191 * [in] DB Index, indicates which DB entry to perform the
202 * Is Allocated parameters for a single element
204 struct tf_rm_is_allocated_parms {
210 * [in] DB Index, indicates which DB entry to perform the
219 * [in] Pointer to flag that indicates the state of the query
225 * Get Allocation information for a single element
227 struct tf_rm_get_alloc_info_parms {
233 * [in] DB Index, indicates which DB entry to perform the
238 * [out] Pointer to the requested allocation information for
239 * the specified db_index
241 struct tf_rm_alloc_info *info;
245 * Get HCAPI type parameters for a single element
247 struct tf_rm_get_hcapi_parms {
253 * [in] DB Index, indicates which DB entry to perform the
258 * [out] Pointer to the hcapi type for the specified db_index
260 uint16_t *hcapi_type;
264 * @page rm Resource Manager
266 * @ref tf_rm_create_db
270 * @ref tf_rm_allocate
274 * @ref tf_rm_is_allocated
276 * @ref tf_rm_get_info
278 * @ref tf_rm_get_hcapi_type
282 * Creates and fills a Resource Manager (RM) DB with requested
283 * elements. The DB is indexed per the parms structure.
286 * Pointer to TF handle, used for HCAPI communication
289 * Pointer to create parameters
292 * - (0) if successful.
293 * - (-EINVAL) on failure.
297 * - Fail on parameter check
298 * - Fail on DB creation, i.e. alloc amount is not possible or validation fails
299 * - Fail on DB creation if DB already exist
303 * - Does hcapi reservation
304 * - Populates the pool with allocated elements
305 * - Returns handle to the created DB
307 int tf_rm_create_db(struct tf *tfp,
308 struct tf_rm_create_db_parms *parms);
311 * Closes the Resource Manager (RM) DB and frees all allocated
312 * resources per the associated database.
315 * Pointer to TF handle, used for HCAPI communication
318 * Pointer to free parameters
321 * - (0) if successful.
322 * - (-EINVAL) on failure.
324 int tf_rm_free_db(struct tf *tfp,
325 struct tf_rm_free_db_parms *parms);
328 * Allocates a single element for the type specified, within the DB.
331 * Pointer to allocate parameters
334 * - (0) if successful.
335 * - (-EINVAL) on failure.
336 * - (-ENOMEM) if pool is empty
338 int tf_rm_allocate(struct tf_rm_allocate_parms *parms);
341 * Free's a single element for the type specified, within the DB.
344 * Pointer to free parameters
347 * - (0) if successful.
348 * - (-EINVAL) on failure.
350 int tf_rm_free(struct tf_rm_free_parms *parms);
353 * Performs an allocation verification check on a specified element.
356 * Pointer to is allocated parameters
359 * - (0) if successful.
360 * - (-EINVAL) on failure.
364 * - If pool is set to Chip MAX, then the query index must be checked
365 * against the allocated range and query index must be allocated as well.
366 * - If pool is allocated size only, then check if query index is allocated.
368 int tf_rm_is_allocated(struct tf_rm_is_allocated_parms *parms);
371 * Retrieves an elements allocation information from the Resource
375 * Pointer to get info parameters
378 * - (0) if successful.
379 * - (-EINVAL) on failure.
381 int tf_rm_get_info(struct tf_rm_get_alloc_info_parms *parms);
384 * Performs a lookup in the Resource Manager DB and retrieves the
385 * requested HCAPI type.
388 * Pointer to get hcapi parameters
391 * - (0) if successful.
392 * - (-EINVAL) on failure.
394 int tf_rm_get_hcapi_type(struct tf_rm_get_hcapi_parms *parms);
396 #endif /* TF_RM_NEW_H_ */