]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/rm-lld.git/blob - include/rm_policyloc.h
Completed shared server feature
[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-2013, 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 /* 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 /* Policy permission bit storage type
60  * Bit : Description
61  *-----------------------------
62  *  0  : Init         (i) - RM instance has initialization permission for resource
63  *  1  : Use          (u) - RM instance has usage permission for resource
64  *  2  : Exclusive    (x) - RM instance has exclusive allocation privilege for resource
65  *                          i.e. No other RM instance can reserve the resource if a RM
66  *                          instance with exclusive privilege reserves the resource
67  *  3  : Shared Linux (s) - Resource has been reserved by the Linux kernel but can be
68  *                          allocated by the specified RM instances
69  *  4 - 15 : UNUSED
70  */
71 typedef uint16_t Rm_PolicyPermBits;
73 /* Initialization permission characters */
74 #define RM_POLICY_PERM_INIT_LOWER         'i'
75 #define RM_POLICY_PERM_INIT_UPPER         'I'
76 /* Initialization permission bit shift */
77 #define RM_POLICY_PERM_INIT_SHIFT          0
78 /* Usage permission characters */
79 #define RM_POLICY_PERM_USE_LOWER          'u'
80 #define RM_POLICY_PERM_USE_UPPER          'U'
81 /* Usage permission bit shift */
82 #define RM_POLICY_PERM_USE_SHIFT           1
83 /* Exclusive permission characters */
84 #define RM_POLICY_PERM_EXCLUSIVE_LOWER    'x'
85 #define RM_POLICY_PERM_EXCLUSIVE_UPPER    'X'
86 /* Exclusive permission bit shift */
87 #define RM_POLICY_PERM_EXCLUSIVE_SHIFT     2
88 /* Shared Linux permission characters */
89 #define RM_POLICY_PERM_SHARED_LINUX_LOWER 's'
90 #define RM_POLICY_PERM_SHARED_LINUX_UPPER 'S'
91 /* Shared Linux permission bit shift */
92 #define RM_POLICY_PERM_SHARED_LINUX_SHIFT  3
94 /* Permissions subgroup start character */
95 #define RM_POLICY_PERM_SUBGROUP_START     '('
96 /* Permissions subgroup end character */
97 #define RM_POLICY_PERM_SUBGROUP_END       ')'
98 /* Permissions subgroup terminator */
99 #define RM_POLICY_PERM_TERMINATOR         '&'
100 /* Permissions assignment character */
101 #define RM_POLICY_PERM_ASSIGNMENT         '='
103 /* Macro to set permissions in a Rm_PolicyPermBits type */
104 #define RM_policy_SET_PERM(permBits, permTypeShift, val) \
105     permBits = ((permBits & (~(((Rm_PolicyPermBits) 0x1) << permTypeShift))) | \
106                ((((Rm_PolicyPermBits) val) & 0x1) << permTypeShift))
107 /* Macro to get permissions from Rm_PolicyPermBits type */               
108 #define RM_policy_GET_PERM(permBits, permTypeShift) \
109     ((permBits >> permTypeShift) & 0x1)
111 /* Assigned instance permissions linked list node */
112 typedef struct Rm_Permission_s {
113     /* Instance name of instance assigned the permissions */
114     char                    instName[RM_NAME_MAX_CHARS];
115     /* Permissions assigned to the RM instance with instName */
116     Rm_PolicyPermBits       permissionBits;
117     /* Next permissions node */
118     struct Rm_Permission_s *nextPermission;
119 } Rm_PolicyPermission;
121 /* Permission validation types */
122 typedef enum {
123     /* Validate exclusive permissions for a resource */
124     Rm_policyCheck_EXCLUSIVE = 0,
125     /* Validate initialization permissions for a resource */
126     Rm_policyCheck_INIT,
127     /* Validate usage permissions for a resource */
128     Rm_policyCheck_USE,
129     /* Validate shared Linux permissions for a resource */
130     Rm_policyCheck_SHARED_LINUX
131 } Rm_PolicyCheckType;
133 /* Permissions validation configuration structure */
134 typedef struct {
135     /* The type of validation to perform */
136     Rm_PolicyCheckType      type;
137     /* Policy to validate the permission check against */
138     void                   *policyDtb;
139     /* Valid instance node that will have its permissions checked for 
140      * the defined resource */
141     Rm_PolicyValidInstNode *validInstNode;
142     /* Resource node offset in the policy DTB */
143     int32_t                 resourceOffset;
144     /* Resource base to validate permissions for the valid instance node */
145     uint32_t                resourceBase;
146     /* Resource length to validate permissions for the valid instance node */
147     uint32_t                resourceLength;
148 } Rm_PolicyCheckCfg;
150 void *rmPolicyGetPolicy(Rm_Handle rmHandle);
151 Rm_PolicyValidInstNode *rmPolicyGetValidInstNode(Rm_Handle rmHandle, char *instName);
152 Rm_PolicyValidInstNode *rmPolicyGetLinuxInstNode(Rm_Handle rmHandle);
153 int rmPolicyCheckPrivilege(Rm_PolicyCheckCfg *privilegeCfg, int32_t *result);
154 uint32_t rmPolicyGetResourceBase(void *policyDtb, Rm_PolicyValidInstNode *validInstNode, 
155                                  int32_t resourceOffset, uint32_t allocType, 
156                                  int32_t *result);
157 uint32_t rmPolicyGetResourceAlignment(void *policyDtb, int32_t resourceOffset);
158 int32_t rmPolicyGetResourceOffset(void *policyDtb, char *resourceName);
159 int32_t rmPolicyValidatePolicyResourceNames(Rm_Handle rmHandle);
160 int32_t rmPolicyValidatePolicy(void *policyDtb, Rm_PolicyValidInstTree *validInstTree);
161 Rm_PolicyValidInstTree *rmPolicyCreateValidInstTree(Rm_Handle rmHandle, int addLinux, int32_t *result);
162 void rmPolicyFreeValidInstTree(Rm_Handle rmHandle);
164 #ifdef __cplusplus
166 #endif
168 #endif /* RM_POLICYLOC_H_ */