]> 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 2dff7571588bafdf5e27c754a8a94692afc0db3a..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
@@ -131,12 +77,10 @@ typedef void *Rm_TransactionQueue;
 typedef enum {
     /** Transaction is being processed */
     Rm_transactionState_PROCESSING = 0,
-    /** Transaction is waiting for response from higher level agent */
-    Rm_transactionState_AWAITING_RESPONSE = 1,
     /** Transaction has been approved */
-    Rm_transactionState_RESOURCE_APPROVED = 2,
+    Rm_transactionState_TRANSACTION_APPROVED = 1,
     /** Transaction has been denied */
-    Rm_transactionState_RESOURCE_DENIED = 3  
+    Rm_transactionState_TRANSACTION_DENIED = 2  
 } Rm_TransactionState;
 
 /**
@@ -161,66 +105,84 @@ typedef struct {
  * @brief RM transactions are the internalized version of service requests received 
  *        from components and RM commands received from other RM instances.
  *        Transactions that cannot immediately be serviced are placed in the RM
- *        instance's transaction queue.
+ *        instance's transaction queue.  The transactions track all service
+ *        requests within the RM infrastructure.
  */
 typedef struct {
     /** Transaction service type */
     Rm_ServiceType type;
-    /** ID of transaction.  Maps to the RM protocol packet ID when forwarding
-     *  RM requests or received RM responses. */
-    uint32_t id;
+    /** Local ID of the transaction. */
+    uint32_t localId;
+    /** ID of transaction on lower level RM instance that generated the
+     *  packet that resulted in the creation of the transaction.  The
+     *  originating ID will be placed in the transaction's response packet
+     *  to the lower level RM instance.  The lower level RM instance will 
+     *  match the response packet with the originating request using the ID */
+    uint32_t remoteOriginatingId;
     /** Name of the RM instance the transaction originated from */
     char sourceInstName[RM_INSTANCE_NAME_MAX_CHARS];
     /** Transaction's associated callback function */
     Rm_ServiceCallback callback;
-    /** Transaction state */
-    Rm_TransactionState state;
-    /** Transaction details.  Provides detailed request/response codes such as
-     *  resource denial reasons.  The codes are externally visible and tracked
+    /** Transaction state.  The codes are externally visible and tracked
      *  in rmservices.h */
-    int32_t details;
+    int32_t state;
     /** Resource information */
     Rm_ResourceInfo resourceInfo;
     /** Link to the next transaction in the queue */
     void *nextTransaction;    
 } Rm_Transaction;
 
-/**
- * @brief Transaction receipt contains transaction result information that is passed
- *        back to the entity that was the source of the transaction.  The source can be
- *        a component that requested a service or a RM instance that sent a command.
- */
 typedef struct {
-    /** Result of the requested service.  Service result types are explained in the 
-     *  Rm_services.h header */
-    int32_t serviceResult;
-    /** If RM cannot provide a result to the service immediately a service ID will
-     *  be provided to the service requester.  The service ID should be used by the
-     *  requester to map RM service responses received via the callback function
-     *  provided to RM at the time of requesting the service */
-    uint32_t serviceId;
-    /** Base value of resource affected by the service request if RM immediately handles
-     *  the request */
-    uint32_t resourceBase;
-    /** Range of resource starting at resourceBase affected by the service request if RM
-     *  immediately handles the request */
-    uint32_t resourceRange;
-} Rm_TransactionReceipt;
+    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 {
-    /** running */
-    RM_state_IDLE = 0,
-    /** handling request */
-    RM_state_HANDLING_REQUEST = 1
-    /** etc...flesh all these out later will need states for the different alloc, free, request/response handlers */
-} Rm_State;
+    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;
-    Rm_State instState;  // IS THIS NEEDED???
     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 */
@@ -232,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
 }