]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/rm-lld.git/blob - include/rm_policyloc.h
e1c209b09896b4cdc6bad3829e3de283ee062411
[keystone-rtos/rm-lld.git] / include / rm_policyloc.h
1 /*
2  *  file  rm_policyloc.h
3  *
4  *  Internal prototypes and data structures for the Resource Manager Policies.
5  *
6  *  ============================================================================
7  *      (C) Copyright 2012-2015, 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 includes */
48 #include <ti/drv/rm/rm.h>
50 /* RM internal includes */
51 #include <ti/drv/rm/include/rm_treeloc.h>
53 /* Index of global permission bits in policy tree node permission array */
54 #define RM_POLICY_GLOBAL_PERM_INDEX        0
56 /* String stored for resource elements that are reserved by the Linux kernel.
57  * These resources will be in use for the lifetime of the system
58  *
59  * TODO: MOVE TO policy.h LATER SO INTEGRATORS KNOW NOT TO NAME RM INSTANCES
60  * THIS NAME */
61 #define RM_ALLOCATED_TO_LINUX "Linux-Kernel"
63 /* Full permissions bit mask */
64 #define RM_policy_PERM_FULL_MASK          ((1u << RM_POLICY_PERM_MAX_BITS) - 1)
66 /* Calculates number of instance permission sets per permission word */
67 #define RM_policy_PERM_INST_PER_WORD \
68     ((sizeof(Rm_PolicyPermBits) * 8) / RM_POLICY_PERM_MAX_BITS)
69 /* Calculates the instance's word index into the permission word array */
70 #define RM_policy_PERM_INDEX(instIdx) \
71     (instIdx / RM_policy_PERM_INST_PER_WORD)
72 /* Calculates the instance's bit offset into the permission word */
73 #define RM_policy_PERM_OFFSET(instIdx)          \
74     ((instIdx % RM_policy_PERM_INST_PER_WORD) * \
75      RM_POLICY_PERM_MAX_BITS)
77 /* Sets a permission for an instance */
78 #define RM_policy_PERM_SET(permArray, wordIdx, wordOffset, permOffset, val) \
79     permArray[wordIdx] &= ~(0x1u << (wordOffset + permOffset));             \
80     permArray[wordIdx] |= (val & 0x1u) << (wordOffset + permOffset);
81 /* Gets a permission for an instance */
82 #define RM_policy_PERM_GET(permArray, wordIdx, wordOffset, permOffset)  \
83     ((permArray[wordIdx] >> (wordOffset + permOffset)) & 0x1u)
85 /* Assigned instance permissions linked list node */
86 typedef struct Rm_Permission_s {
87     /* Instance name of instance assigned the permissions */
88     char                    instName[RM_NAME_MAX_CHARS];
89     /* Permissions assigned to the RM instance with instName */
90     Rm_PolicyPermBits       permissionBits;
91     /* Next permissions node */
92     struct Rm_Permission_s *nextPermission;
93 } Rm_PolicyPermission;
95 /* Permission validation types */
96 typedef enum {
97     /* Validate exclusive permissions for a resource */
98     Rm_policyCheck_EXCLUSIVE = 0,
99     /* Validate initialization permissions for a resource */
100     Rm_policyCheck_INIT,
101     /* Validate usage permissions for a resource */
102     Rm_policyCheck_USE,
103     /* Validate shared Linux permissions for a resource */
104     Rm_policyCheck_SHARED_LINUX,
105     /* Validate shared UNSPECIFIED allocation exclusion for a resource */
106     Rm_policyCheck_UNSPEC_EXCLUSION
107 } Rm_PolicyCheckType;
109 /* Permissions validation configuration structure */
110 typedef struct {
111     /* The type of validation to perform */
112     Rm_PolicyCheckType      type;
113     /* Negative check:
114      * RM_FALSE (0) - Check if passes policy
115      * RM_TRUE  (1) - Check if fails policy */
116     uint32_t                neg;
117     /* Resource's policy tree used to validate permissions */
118     Rm_PolicyTree          *polTree;
119     /* Valid instance node having its permissions checked for the resource */
120     Rm_PolicyValidInstNode *validInstNode;
121     /* Resource base to validate permissions for the valid instance node */
122     uint32_t                resourceBase;
123     /* Resource length to validate permissions for the valid instance node */
124     uint32_t                resourceLength;
125 } Rm_PolicyCheckCfg;
127 Rm_PolicyValidInstNode *rmPolicyGetValidInstNode(Rm_Handle rmHandle,
128                                                  const char *instName);
129 Rm_PolicyValidInstNode *rmPolicyGetLinuxInstNode(Rm_Handle rmHandle);
130 int32_t rmPolicyCheckPrivilege(Rm_PolicyCheckCfg *privilegeCfg);
131 int32_t rmPolicyGetResourceBase(Rm_PolicyTree *policyTree,
132                                  Rm_PolicyValidInstNode *validInstNode,
133                                  Rm_PolicyCheckType policyCheckType,
134                                  int32_t *resBase);
135 uint32_t rmPolicyGetAllocAlign(Rm_PolicyTree *policyTree);
136 uint32_t rmPolicyGetCdAllocSize(Rm_PolicyTree *policyTree);
137 Rm_PolicyValidInstTree *rmPolicyVInstTreeInit(Rm_Handle rmHandle,
138                                               void *policyDtb,
139                                               int addLinux,
140                                               int32_t *result);
141 void rmPolicyVInstTreeDelete(Rm_Handle rmHandle);
142 int32_t rmPolicyPopulateTree(Rm_Handle rmHandle, Rm_PolicyTree *policyTree,
143                              void *policyDtb, const char *resName);
145 #ifdef __cplusplus
147 #endif
149 #endif /* RM_POLICYLOC_H_ */