]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/rm-lld.git/blobdiff - include/rm_loc.h
Integrated red-black tree algorithm for tree allocators
[keystone-rtos/rm-lld.git] / include / rm_loc.h
index ea6828f0ef9517da3ffbcbb07022b773b366b584..18717972c76af0f180fcaef4c60691ca239fc741 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  file  rmloc.h
+ *  file  rm_loc.h
  *
  *  General private data structures of Resource Manager.
  *
@@ -49,70 +49,13 @@ extern "C" {
 #include <ti/drv/rm/rm_policy.h>
 #include <ti/drv/rm/rm_transport.h>
 
-#if 0
-/* RM permissions structure for CPPI DMA channels and flows */
-typedef struct
-{
-    /** Array of pointers to each DMAs channel or flow permissions
-       * From CPPI LLD - DMA 0 = SRIO
-       *                          DMA 1 = AIF
-       *                          DMA 2 = FFTC A
-       *                          DMA 3 = FFTC B
-       *                          DMA 4 = PASS
-       *                          DMA 5 = QMSS
-       *                          DMA 6 = FFTC C
-       *                          DMA 7 = BCP 
-       * 
-       * Note: Some DMAs may not be supported based on the device */
-    Rm_Perms *dmaPermPtrs[RM_CPPI_MAX_DMAS];
-} Rm_CppiChAndFlowPerms;
-
-/* RM Cache Line Alignment Defines and Macros */
-
-#define RM_MAX_CACHE_ALIGN 128  /* Maximum alignment for cache line size */
-
-/* This macro generates compiler error if postulate is false, so 
- * allows 0 overhead compile time size check.  This "works" when
- * the expression contains sizeof() which otherwise doesn't work
- * with preprocessor */
-#define RM_COMPILE_TIME_SIZE_CHECK(postulate)                         \
-   do {                                                                 \
-       typedef struct {                                                 \
-         uint8_t NegativeSizeIfPostulateFalse[((int)(postulate))*2 - 1];\
-       } PostulateCheck_t;                                              \
-   }                                                                    \
-   while (0)
-
-/* Macro to pad out internal permission structures to multiple of RM_MAX_CACHE_ALIGN bytes
-  * The macro prevent something else from being placed on same cache line as the permission.  
-  * arrays.  Note that pad[0] is illegal, so must add full RM_MAX_CACHE_ALIGN if structure
-  * is already padded by chance. */
-#define RM_ALIGN_PERMISSIONS_ARRAY(numElements, permStructType) ( \
-     (((sizeof(permStructType) * (numElements)) % RM_MAX_CACHE_ALIGN) == 0) ? (numElements) : \
-     ((numElements) + \
-       (RM_MAX_CACHE_ALIGN - \
-         ((sizeof(permStructType) * (numElements)) % RM_MAX_CACHE_ALIGN))/sizeof(permStructType)))
-
-/* RM Global Sync Object (unpadded) */
-typedef struct
-{
-    /** Rm_init/Rm_start synchronization object. */
-    uint8_t globalSyncObj;
-} Rm_Sync_Obj_Unpadded;
-
-/* RM Global Sync Object (padded) */
-typedef struct
-{
-    /** Data structure without padding, so sizeof() can compute padding */
-    Rm_Sync_Obj_Unpadded obj;
-    /** Pad out to end of RM_MAX_CACHE_ALIGN bytes to prevent something else
-     * from being placed on same cache line as Rm_Synci_Obj.  Note that 
-     * pad[0] is illegal, so must add full RM_MAX_CACHE_ALIGN if structure
-     * is already padded by chance. */
-    uint8_t  pad[RM_MAX_CACHE_ALIGN - 
-                       (sizeof(Rm_Sync_Obj_Unpadded) % RM_MAX_CACHE_ALIGN)];
-} Rm_Sync_Obj;
-#endif
+/* AVL BBST includes */
+#include <ti/drv/rm/include/tree.h>
+
+/** String stored for resource elements that are not currently allocated to anyone.  If the
+ *  resource is allocated the allocatedTo field will be populated with the RM instance
+ *  name it was allocated to. */
+#define RM_NOT_ALLOCATED_STRING "\0"
 
 /** Maximum size of a transmittable RM policy in bytes */
 #define RM_MAX_POLICY_SIZE_BYTES (64)  // Placeholder: This will change 
@@ -124,6 +67,9 @@ typedef void *Rm_TransportRouteMap;
 /** Pointer to RM instance's transaction queue */
 typedef void *Rm_TransactionQueue;
 
+/** Pointer to the RM instance's allocators */
+typedef void *Rm_Allocators;
+
 /**
  * @brief RM transaction details values.  Details values provide more fine-grained
  *        information regarding a transaction request or response
@@ -177,22 +123,66 @@ typedef struct {
     char sourceInstName[RM_INSTANCE_NAME_MAX_CHARS];
     /** Transaction's associated callback function */
     Rm_ServiceCallback callback;
-    /** Transaction state */
-    Rm_TransactionState state;
-    /** Transaction result.  The codes are externally visible and tracked
+    /** Transaction state.  The codes are externally visible and tracked
      *  in rmservices.h */
-    int32_t result;
+    int32_t state;
     /** Resource information */
     Rm_ResourceInfo resourceInfo;
     /** Link to the next transaction in the queue */
     void *nextTransaction;    
 } Rm_Transaction;
 
+typedef struct {
+    const void *allocatorData;
+    int32_t allocatorLen;
+    const void *rangeData;
+    int32_t rangeLen;
+    const void *nsAssignData;
+    int32_t nsAssignLen;
+} Rm_ResourceProperties;
+
+typedef enum {
+    Rm_allocatorType_INTEGER = 0,
+    Rm_allocatorType_TREE = 1,
+} Rm_AllocatorType;
+
+typedef enum {
+    Rm_allocatorOp_ALLOCATE = 0,
+    Rm_allocatorOp_FREE = 1,
+    Rm_allocatorOp_PRE_ALLOCATE = 2,
+} Rm_AllocatorOp;
+
+typedef struct {
+    char *srcInstName;
+    Rm_AllocatorOp operation;
+    Rm_ResourceInfo *resourceInfo;
+} Rm_AllocatorOpInfo;
+
+typedef struct {
+    uint32_t value;
+    char allocatedTo[RM_INSTANCE_NAME_MAX_CHARS];
+} Rm_IntegerEntry;
+
+typedef struct {
+    uint32_t numResourceElements;
+    Rm_IntegerEntry *resourceArrayBase;
+} Rm_IntegerAllocatorRootEntry;
+
+typedef struct {
+    char resourceName[RM_RESOURCE_NAME_MAX_CHARS];
+    Rm_AllocatorType type;
+    /** Pointer to the first resource entry in the allocator */
+    void *allocatorRootEntry;
+    /** Pointer to next resource allocator */
+    void *nextAllocator;
+} Rm_Allocator;
+
 typedef struct {
     char name[RM_INSTANCE_NAME_MAX_CHARS];
     Rm_InstType instType;
     bool registeredWithDelegateOrServer;
-    Rm_PolicyHandle instPolicy;  /* Client Delegate only? */
+    Rm_PolicyHandle policyDtb;
+    Rm_Allocators allocators;
     /* RM instance transport parameters */
     Rm_TransportRouteMap routeMap;
     /* RM Transaction sequence number counter */
@@ -204,14 +194,41 @@ typedef struct {
     Rm_TransportCallouts transport;
 } Rm_Inst;
 
-Rm_Transaction *Rm_transactionQueueAdd(Rm_Inst *rmInst, uint32_t transactionId);
+Rm_Transaction *Rm_transactionQueueAdd(Rm_Inst *rmInst);
 Rm_Transaction *Rm_transactionQueueFind(Rm_Inst *rmInst, uint32_t transactionId);
 int32_t Rm_transactionQueueDelete(Rm_Inst *rmInst, uint32_t transactionId);
 uint32_t Rm_transactionGetSequenceNum(Rm_Inst *rmInst);
 
-void Rm_transactionProcessor (Rm_Inst *rmInst, Rm_Transaction *transaction, 
-                              Rm_TransactionReceipt *receipt);
-
+void Rm_transactionProcessor (Rm_Inst *rmInst, Rm_Transaction *transaction);
+
+/**********************************************************************
+ ******************* Red-Black Tree BBST Defines **********************
+ **********************************************************************/
+
+/* Declare the tree structure nodes */
+typedef struct _Rm_ResourceTreeNode {
+    RB_ENTRY(_Rm_ResourceTreeNode) linkage;
+    uint32_t base;
+    uint32_t length;
+    char allocatedTo[RM_INSTANCE_NAME_MAX_CHARS];
+} Rm_ResourceTreeNode;
+
+/* Will need to malloc a tree of type Rm_ResourceTree for each tree i want to create */
+/* Declare the tree head structure */
+typedef RB_HEAD(_Rm_ResourceTree, _Rm_ResourceTreeNode) Rm_ResourceTree;
+
+/* Prototype for function that allocates new tree nodes */
+Rm_ResourceTreeNode *Rm_newResourceTreeNode(uint32_t resourceBase, uint32_t resourceLength);
+/* Prototype for function that frees new tree nodes */
+void Rm_freeResourceTreeNode(Rm_ResourceTreeNode *treeNode);
+/* Prototype for tree node comparison function
+ * element1 < element2 --> return < 0
+ * element1 = element2 --> return 0
+ * element1 > element2 --> return > 0 */
+int Rm_ResourceTreeNodeCompare(Rm_ResourceTreeNode *element1, Rm_ResourceTreeNode *element2); 
+
+/* Generate the tree prototypes */
+RB_PROTOTYPE(_Rm_ResourceTree, _Rm_ResourceTreeNode, linkage, Rm_ResourceTreeNodeCompare);
 
 #ifdef __cplusplus
 }