1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2020 Broadcom
11 #include "tf_device.h"
15 /** RM return codes */
16 #define TF_RM_ALLOCATED_ENTRY_FREE 0
17 #define TF_RM_ALLOCATED_ENTRY_IN_USE 1
18 #define TF_RM_ALLOCATED_NO_ENTRY_FOUND -1
21 * The Resource Manager (RM) module provides basic DB handling for
22 * internal resources. These resources exists within the actual device
23 * and are controlled by the HCAPI Resource Manager running on the
26 * The RM DBs are all intended to be indexed using TF types there for
27 * a lookup requires no additional conversion. The DB configuration
28 * specifies the TF Type to HCAPI Type mapping and it becomes the
29 * responsibility of the DB initialization to handle this static
32 * Accessor functions are providing access to the DB, thus hiding the
35 * The RM DB will work on its initial allocated sizes so the
36 * capability of dynamically growing a particular resource is not
37 * possible. If this capability later becomes a requirement then the
38 * MAX pool size of the Chip Å“needs to be added to the tf_rm_elem_info
39 * structure and several new APIs would need to be added to allow for
40 * growth of a single TF resource type.
42 * The access functions does not check for NULL pointers as it's a
43 * support module, not called directly.
47 * Resource reservation single entry result. Used when accessing HCAPI
50 struct tf_rm_new_entry {
51 /** Starting index of the allocated resource */
53 /** Number of allocated elements */
58 * RM Element configuration enumeration. Used by the Device to
59 * indicate how the RM elements the DB consists off, are to be
60 * configured at time of DB creation. The TF may present types to the
61 * ULP layer that is not controlled by HCAPI within the Firmware.
63 enum tf_rm_elem_cfg_type {
68 /** HCAPI 'controlled', no RM storage thus the Device Module
69 * using the RM can chose to handle storage locally.
72 /** HCAPI 'controlled', uses a Bit Allocator Pool for internal
75 TF_RM_ELEM_CFG_HCAPI_BA,
77 * Shared element thus it belongs to a shared FW Session and
78 * is not controlled by the Host.
80 TF_RM_ELEM_CFG_SHARED,
85 * RM Reservation strategy enumeration. Type of strategy comes from
86 * the HCAPI RM QCAPS handshake.
88 enum tf_rm_resc_resv_strategy {
89 TF_RM_RESC_RESV_STATIC_PARTITION,
90 TF_RM_RESC_RESV_STRATEGY_1,
91 TF_RM_RESC_RESV_STRATEGY_2,
92 TF_RM_RESC_RESV_STRATEGY_3,
97 * RM Element configuration structure, used by the Device to configure
98 * how an individual TF type is configured in regard to the HCAPI RM
101 struct tf_rm_element_cfg {
103 * RM Element config controls how the DB for that element is
106 enum tf_rm_elem_cfg_type cfg_type;
108 /* If a HCAPI to TF type conversion is required then TF type
113 * HCAPI RM Type for the element. Used for TF to HCAPI type
120 * Allocation information for a single element.
122 struct tf_rm_alloc_info {
124 * HCAPI RM allocated range information.
127 * In case of dynamic allocation support this would have
128 * to be changed to linked list of tf_rm_entry instead.
130 struct tf_rm_new_entry entry;
134 * Create RM DB parameters
136 struct tf_rm_create_db_parms {
138 * [in] Device module type. Used for logging purposes.
140 enum tf_device_module_type type;
142 * [in] Receive or transmit direction.
146 * [in] Number of elements.
148 uint16_t num_elements;
150 * [in] Parameter structure array. Array size is num_elements.
152 struct tf_rm_element_cfg *cfg;
154 * Resource allocation count array. This array content
155 * originates from the tf_session_resources that is passed in
157 * Array size is num_elements.
167 * Free RM DB parameters
169 struct tf_rm_free_db_parms {
171 * [in] Receive or transmit direction
181 * Allocate RM parameters for a single element
183 struct tf_rm_allocate_parms {
189 * [in] DB Index, indicates which DB entry to perform the
194 * [in] Pointer to the allocated index in normalized
195 * form. Normalized means the index has been adjusted,
196 * i.e. Full Action Record offsets.
200 * [in] Priority, indicates the priority of the entry
201 * priority 0: allocate from top of the tcam (from index 0
202 * or lowest available index)
203 * priority !0: allocate from bottom of the tcam (from highest
208 * [in] Pointer to the allocated index before adjusted.
210 uint32_t *base_index;
214 * Free RM parameters for a single element
216 struct tf_rm_free_parms {
222 * [in] DB Index, indicates which DB entry to perform the
233 * Is Allocated parameters for a single element
235 struct tf_rm_is_allocated_parms {
241 * [in] DB Index, indicates which DB entry to perform the
250 * [in] Pointer to flag that indicates the state of the query
254 * [in] Pointer to the allocated index before adjusted.
256 uint32_t *base_index;
260 * Get Allocation information for a single element
262 struct tf_rm_get_alloc_info_parms {
268 * [in] DB Index, indicates which DB entry to perform the
273 * [out] Pointer to the requested allocation information for
274 * the specified db_index
276 struct tf_rm_alloc_info *info;
280 * Get HCAPI type parameters for a single element
282 struct tf_rm_get_hcapi_parms {
288 * [in] DB Index, indicates which DB entry to perform the
293 * [out] Pointer to the hcapi type for the specified db_index
295 uint16_t *hcapi_type;
299 * Get InUse count parameters for single element
301 struct tf_rm_get_inuse_count_parms {
307 * [in] DB Index, indicates which DB entry to perform the
312 * [out] Pointer to the inuse count for the specified db_index
318 * @page rm Resource Manager
320 * @ref tf_rm_create_db
324 * @ref tf_rm_allocate
328 * @ref tf_rm_is_allocated
330 * @ref tf_rm_get_info
332 * @ref tf_rm_get_hcapi_type
334 * @ref tf_rm_get_inuse_count
338 * Creates and fills a Resource Manager (RM) DB with requested
339 * elements. The DB is indexed per the parms structure.
342 * Pointer to TF handle, used for HCAPI communication
345 * Pointer to create parameters
348 * - (0) if successful.
349 * - (-EINVAL) on failure.
353 * - Fail on parameter check
354 * - Fail on DB creation, i.e. alloc amount is not possible or validation fails
355 * - Fail on DB creation if DB already exist
359 * - Does hcapi reservation
360 * - Populates the pool with allocated elements
361 * - Returns handle to the created DB
363 int tf_rm_create_db(struct tf *tfp,
364 struct tf_rm_create_db_parms *parms);
367 * Closes the Resource Manager (RM) DB and frees all allocated
368 * resources per the associated database.
371 * Pointer to TF handle, used for HCAPI communication
374 * Pointer to free parameters
377 * - (0) if successful.
378 * - (-EINVAL) on failure.
380 int tf_rm_free_db(struct tf *tfp,
381 struct tf_rm_free_db_parms *parms);
384 * Allocates a single element for the type specified, within the DB.
387 * Pointer to allocate parameters
390 * - (0) if successful.
391 * - (-EINVAL) on failure.
392 * - (-ENOMEM) if pool is empty
394 int tf_rm_allocate(struct tf_rm_allocate_parms *parms);
397 * Free's a single element for the type specified, within the DB.
400 * Pointer to free parameters
403 * - (0) if successful.
404 * - (-EINVAL) on failure.
406 int tf_rm_free(struct tf_rm_free_parms *parms);
409 * Performs an allocation verification check on a specified element.
412 * Pointer to is allocated parameters
415 * - (0) if successful.
416 * - (-EINVAL) on failure.
420 * - If pool is set to Chip MAX, then the query index must be checked
421 * against the allocated range and query index must be allocated as well.
422 * - If pool is allocated size only, then check if query index is allocated.
424 int tf_rm_is_allocated(struct tf_rm_is_allocated_parms *parms);
427 * Retrieves an elements allocation information from the Resource
431 * Pointer to get info parameters
434 * - (0) if successful.
435 * - (-EINVAL) on failure.
437 int tf_rm_get_info(struct tf_rm_get_alloc_info_parms *parms);
440 * Performs a lookup in the Resource Manager DB and retrieves the
441 * requested HCAPI RM type.
444 * Pointer to get hcapi parameters
447 * - (0) if successful.
448 * - (-EINVAL) on failure.
450 int tf_rm_get_hcapi_type(struct tf_rm_get_hcapi_parms *parms);
453 * Performs a lookup in the Resource Manager DB and retrieves the
454 * requested HCAPI RM type inuse count.
457 * Pointer to get inuse parameters
460 * - (0) if successful.
461 * - (-EINVAL) on failure.
463 int tf_rm_get_inuse_count(struct tf_rm_get_inuse_count_parms *parms);
465 #endif /* TF_RM_NEW_H_ */