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 * Check if the indexes are in the range of reserved resource
320 struct tf_rm_check_indexes_in_range_parms {
326 * [in] DB Index, indicates which DB entry to perform the
331 * [in] Starting index
333 uint16_t starting_index;
335 * [in] number of entries
337 uint16_t num_entries;
341 * @page rm Resource Manager
343 * @ref tf_rm_create_db
347 * @ref tf_rm_allocate
351 * @ref tf_rm_is_allocated
353 * @ref tf_rm_get_info
355 * @ref tf_rm_get_hcapi_type
357 * @ref tf_rm_get_inuse_count
361 * Creates and fills a Resource Manager (RM) DB with requested
362 * elements. The DB is indexed per the parms structure.
365 * Pointer to TF handle, used for HCAPI communication
368 * Pointer to create parameters
371 * - (0) if successful.
372 * - (-EINVAL) on failure.
376 * - Fail on parameter check
377 * - Fail on DB creation, i.e. alloc amount is not possible or validation fails
378 * - Fail on DB creation if DB already exist
382 * - Does hcapi reservation
383 * - Populates the pool with allocated elements
384 * - Returns handle to the created DB
386 int tf_rm_create_db(struct tf *tfp,
387 struct tf_rm_create_db_parms *parms);
390 * Closes the Resource Manager (RM) DB and frees all allocated
391 * resources per the associated database.
394 * Pointer to TF handle, used for HCAPI communication
397 * Pointer to free parameters
400 * - (0) if successful.
401 * - (-EINVAL) on failure.
403 int tf_rm_free_db(struct tf *tfp,
404 struct tf_rm_free_db_parms *parms);
407 * Allocates a single element for the type specified, within the DB.
410 * Pointer to allocate parameters
413 * - (0) if successful.
414 * - (-EINVAL) on failure.
415 * - (-ENOMEM) if pool is empty
417 int tf_rm_allocate(struct tf_rm_allocate_parms *parms);
420 * Free's a single element for the type specified, within the DB.
423 * Pointer to free parameters
426 * - (0) if successful.
427 * - (-EINVAL) on failure.
429 int tf_rm_free(struct tf_rm_free_parms *parms);
432 * Performs an allocation verification check on a specified element.
435 * Pointer to is allocated parameters
438 * - (0) if successful.
439 * - (-EINVAL) on failure.
443 * - If pool is set to Chip MAX, then the query index must be checked
444 * against the allocated range and query index must be allocated as well.
445 * - If pool is allocated size only, then check if query index is allocated.
447 int tf_rm_is_allocated(struct tf_rm_is_allocated_parms *parms);
450 * Retrieves an elements allocation information from the Resource
454 * Pointer to get info parameters
457 * - (0) if successful.
458 * - (-EINVAL) on failure.
460 int tf_rm_get_info(struct tf_rm_get_alloc_info_parms *parms);
463 * Performs a lookup in the Resource Manager DB and retrieves the
464 * requested HCAPI RM type.
467 * Pointer to get hcapi parameters
470 * - (0) if successful.
471 * - (-EINVAL) on failure.
473 int tf_rm_get_hcapi_type(struct tf_rm_get_hcapi_parms *parms);
476 * Performs a lookup in the Resource Manager DB and retrieves the
477 * requested HCAPI RM type inuse count.
480 * Pointer to get inuse parameters
483 * - (0) if successful.
484 * - (-EINVAL) on failure.
486 int tf_rm_get_inuse_count(struct tf_rm_get_inuse_count_parms *parms);
489 * Check if the requested indexes are in the range of reserved resource.
492 * Pointer to get inuse parameters
495 * - (0) if successful.
496 * - (-EINVAL) on failure.
499 tf_rm_check_indexes_in_range(struct tf_rm_check_indexes_in_range_parms *parms);
502 #endif /* TF_RM_NEW_H_ */