]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/rm-lld.git/blob - include/rm_policyloc.h
Added pre-main capabilities, cleaned up services and NameServer modules
[keystone-rtos/rm-lld.git] / include / rm_policyloc.h
1 /*
2  *  file  rm_policyloc.h
3  *
4  *  Prototypes and data structures for the Resource Manager Policies.
5  *
6  *  ============================================================================
7  *      (C) Copyright 2012, Texas Instruments, Inc.
8  * 
9  *  Redistribution and use in source and binary forms, with or without 
10  *  modification, are permitted provided that the following conditions 
11  *  are met:
12  *
13  *    Redistributions of source code must retain the above copyright 
14  *    notice, this list of conditions and the following disclaimer.
15  *
16  *    Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the 
18  *    documentation and/or other materials provided with the   
19  *    distribution.
20  *
21  *    Neither the name of Texas Instruments Incorporated nor the names of
22  *    its contributors may be used to endorse or promote products derived
23  *    from this software without specific prior written permission.
24  *
25  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
26  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
27  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
29  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
30  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
31  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
34  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
35  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  *
37  *  \par
38 */
40 #ifndef RM_POLICYLOC_H_
41 #define RM_POLICYLOC_H_
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
47 /* RM external API includes */
48 #include <ti/drv/rm/rm_policy.h>
50 /* AVL BBST includes */
51 #include <ti/drv/rm/include/tree.h>
53 /** String stored for resource elements that are reserved by the Linux kernel.  These
54  *  resources will be in use for the lifetime of the system 
55  *
56  * TODO: MOVE TO policy.h LATER SO INTEGRATORS KNOW NOT TO NAME RM INSTANCES THIS NAME*/
57 #define RM_ALLOCATED_TO_LINUX "Linux-Kernel"
59 /* Bit : Description
60  *-----------------------------
61  *  0  : Init         (iI) - RM instance has initialization permission for resource
62  *  1  : Use          (uU) - RM instance has usage permission for resource
63  *  2  : Exclusive    (xX) - RM instance has exclusive allocation privilege for resource
64  *                           i.e. No other RM instance can reserve the resource if a RM
65  *                           instance with exclusive privilege reserves the resource
66  *  3  : Shared Linux (sS) - Resource has been reserved by the Linux kernel but can be
67  *                           allocated by the specified RM instances
68  *  4 - 15 : UNUSED
69  */
70 typedef uint16_t Rm_PolicyPermBits;
72 #define RM_POLICY_PERM_INIT_LOWER         'i'
73 #define RM_POLICY_PERM_INIT_UPPER         'I'
74 #define RM_POLICY_PERM_INIT_SHIFT          0
75 #define RM_POLICY_PERM_USE_LOWER          'u'
76 #define RM_POLICY_PERM_USE_UPPER          'U'
77 #define RM_POLICY_PERM_USE_SHIFT           1
78 #define RM_POLICY_PERM_EXCLUSIVE_LOWER    'x'
79 #define RM_POLICY_PERM_EXCLUSIVE_UPPER    'X'
80 #define RM_POLICY_PERM_EXCLUSIVE_SHIFT     2
81 #define RM_POLICY_PERM_SHARED_LINUX_LOWER 's'
82 #define RM_POLICY_PERM_SHARED_LINUX_UPPER 'S'
83 #define RM_POLICY_PERM_SHARED_LINUX_SHIFT  3
85 #define RM_POLICY_PERM_SUBGROUP_START     '('
86 #define RM_POLICY_PERM_SUBGROUP_END       ')'
87 #define RM_POLICY_PERM_TERMINATOR         '&'
88 #define RM_POLICY_PERM_ASSIGNMENT         '='
90 #define RM_policy_SET_PERM(permBits, permTypeShift, val) \
91     permBits = ((permBits & (~(((Rm_PolicyPermBits) 0x1) << permTypeShift))) | \
92                ((((Rm_PolicyPermBits) val) & 0x1) << permTypeShift))
93 #define RM_policy_GET_PERM(permBits, permTypeShift) \
94     ((permBits >> permTypeShift) & 0x1)
96 typedef struct Rm_Permission_s {
97     char                    instName[RM_INSTANCE_NAME_MAX_CHARS];
98     Rm_PolicyPermBits       permissionBits;
99     struct Rm_Permission_s *nextPermission;
100 } Rm_PolicyPermission;
102 /**********************************************************************
103  ************** Policy Valid Instance Tree Definitions ****************
104  **********************************************************************/
106 /* Declare the tree structure nodes */
107 typedef struct _Rm_PolicyValidInstNode {
108     RB_ENTRY(_Rm_PolicyValidInstNode) linkage;
109     char                        name[RM_INSTANCE_NAME_MAX_CHARS];
110     uint32_t                    allocRefCount;
111     bool                        deletePending;
112 } Rm_PolicyValidInstNode;
114 /* Declare the tree head structure. */
115 typedef RB_HEAD(_Rm_PolicyValidInstTree, _Rm_PolicyValidInstNode) Rm_PolicyValidInstTree;
117 Rm_PolicyValidInstNode *Rm_policyNewValidInstNode(char *instName);
118 void Rm_policyFreeValidInstNode(Rm_PolicyValidInstNode *node);
119 /* Prototype for Valid Instance node comparison function
120  * element1 < element2 --> return < 0
121  * element1 = element2 --> return 0
122  * element1 > element2 --> return > 0 */
123 int Rm_policyValidInstNodeCompare(Rm_PolicyValidInstNode *node1, Rm_PolicyValidInstNode *node2); 
125 /* Generate the tree prototypes */
126 RB_PROTOTYPE(_Rm_PolicyValidInstTree, _Rm_PolicyValidInstNode,
127              linkage, Rm_policyValidInstNodeCompare);
129 /**********************************************************************
130  *********************** Internal Policy APIs *************************
131  **********************************************************************/
133 typedef enum {
134     Rm_policyCheck_EXCLUSIVE = 0,
135     Rm_policyCheck_INIT,
136     Rm_policyCheck_USE
137 } Rm_PolicyCheckType;
139 typedef struct {
140     Rm_PolicyCheckType      type;
141     void                   *policyDtb;
142     Rm_PolicyValidInstNode *validInstNode;
143     int32_t                 resourceOffset;
144     uint32_t                resourceBase;
145     uint32_t                resourceLength;
146 } Rm_PolicyCheckCfg;
148 Rm_PolicyValidInstNode *Rm_policyGetValidInstNode(Rm_PolicyValidInstTree *validInstTree, char *instName);
149 Rm_PolicyValidInstNode *Rm_policyGetLinuxInstNode(Rm_PolicyValidInstTree *validInstTree);
150 bool     Rm_policyCheckPrivilege(Rm_PolicyCheckCfg *privilegeCfg, int32_t *result);
151 uint32_t Rm_policyGetResourceBase(void *policyDtb, Rm_PolicyValidInstNode *validInstNode, 
152                                   int32_t resourceOffset, uint32_t allocType, 
153                                   int32_t *result);
154 uint32_t Rm_policyGetResourceAlignment(void *policyDtb, int32_t resourceOffset);
155 int32_t  Rm_policyGetResourceOffset(void *policyDtb, char *resourceName);
156 int32_t  Rm_policyValidatePolicyResourceNames(void *allocatorList, void *policyDtb);
157 int32_t  Rm_policyValidatePolicy(void *policyDtb, Rm_PolicyValidInstTree *validInstTree);
158 Rm_PolicyValidInstTree *Rm_policyCreateValidInstTree(void *policyDtb, int32_t *result);
159 void     Rm_policyFreeValidInstTree(Rm_PolicyValidInstTree *validInstTree);
161 #ifdef __cplusplus
163 #endif
165 #endif /* RM_POLICYLOC_H_ */