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 /* RM internal API includes */
51 #include <ti/drv/rm/include/rm_loc.h>
53 /* AVL BBST includes */
54 #include <ti/drv/rm/include/tree.h>
56 /** String stored for resource elements that are reserved by the Linux kernel. These
57 * 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 THIS NAME*/
60 #define RM_ALLOCATED_TO_LINUX "Linux-Kernel"
62 /* Bit : Description
63 *-----------------------------
64 * 0 : Init (iI) - RM instance has initialization permission for resource
65 * 1 : Use (uU) - RM instance has usage permission for resource
66 * 2 : Exclusive (xX) - RM instance has exclusive allocation privilege for resource
67 * i.e. No other RM instance can reserve the resource if a RM
68 * instance with exclusive privilege reserves the resource
69 * 3 : Shared Linux (sS) - Resource has been reserved by the Linux kernel but can be
70 * allocated by the specified RM instances
71 * 4 - 15 : UNUSED
72 */
73 typedef uint16_t Rm_PermissionBits;
75 #define RM_POLICY_PERM_INIT_LOWER 'i'
76 #define RM_POLICY_PERM_INIT_UPPER 'I'
77 #define RM_POLICY_PERM_INIT_SHIFT 0
78 #define RM_POLICY_PERM_USE_LOWER 'u'
79 #define RM_POLICY_PERM_USE_UPPER 'U'
80 #define RM_POLICY_PERM_USE_SHIFT 1
81 #define RM_POLICY_PERM_EXCLUSIVE_LOWER 'x'
82 #define RM_POLICY_PERM_EXCLUSIVE_UPPER 'X'
83 #define RM_POLICY_PERM_EXCLUSIVE_SHIFT 2
84 #define RM_POLICY_PERM_SHARED_LINUX_LOWER 's'
85 #define RM_POLICY_PERM_SHARED_LINUX_UPPER 'S'
86 #define RM_POLICY_PERM_SHARED_LINUX_SHIFT 3
88 #define RM_POLICY_PERM_SUBGROUP_START '('
89 #define RM_POLICY_PERM_SUBGROUP_END ')'
90 #define RM_POLICY_PERM_TERMINATOR '&'
91 #define RM_POLICY_PERM_ASSIGNMENT '='
93 #define RM_POLICY_SET_PERM(permBits, permTypeShift, val) \
94 permBits = ((permBits & (~(((Rm_PermissionBits) 0x1) << permTypeShift))) | \
95 ((((Rm_PermissionBits) val) & 0x1) << permTypeShift))
96 #define RM_POLICY_GET_PERM(permBits, permTypeShift) \
97 ((permBits >> permTypeShift) & 0x1)
99 typedef struct Rm_Permission_s {
100 char instName[RM_INSTANCE_NAME_MAX_CHARS];
101 Rm_PermissionBits permissionBits;
102 struct Rm_Permission_s *nextPermission;
103 } Rm_PolicyPermission;
105 typedef struct {
106 const void *assignmentData;
107 int32_t assignmentLen;
108 const void *allocationSizeData;
109 int32_t allocationSizeLen;
110 const void *alignmentData;
111 int32_t alignmentLen;
112 } Rm_PolicyNodeProperties;
114 void Rm_policyIncrementValidInstAllocationCount(void *validInstNameNode);
115 void Rm_policyDecrementValidInstAllocationCount(void *validInstNameNode);
116 void *Rm_policyGetValidInstNode(void *validInstTree, char *instName);
117 char *Rm_policyGetValidInstNodeName(void *validInstNode);
118 void *Rm_policyGetLinuxInstNode(void *validInstTree);
119 int32_t Rm_policyValidatePolicy(Rm_Inst *rmInst, void *policyDtb);
120 void *Rm_policyCreateValidInstTree(void *policyDtb, int32_t *result);
122 /**********************************************************************
123 ******************* Red-Black Tree BBST Defines **********************
124 **********************************************************************/
126 /* Declare the tree structure nodes */
127 typedef struct _Rm_ValidInstNode {
128 RB_ENTRY(_Rm_ValidInstNode) linkage;
129 char name[RM_INSTANCE_NAME_MAX_CHARS];
130 uint32_t allocRefCount;
131 bool deletePending;
132 } Rm_ValidInstNode;
134 /* Declare the tree head structure. */
135 typedef RB_HEAD(_Rm_ValidInstTree, _Rm_ValidInstNode) Rm_ValidInstTree;
137 Rm_ValidInstNode *Rm_newValidInstNode(char *instName);
138 void Rm_freeValidInstNode(Rm_ValidInstNode *node);
139 /* Prototype for Valid Instance node comparison function
140 * element1 < element2 --> return < 0
141 * element1 = element2 --> return 0
142 * element1 > element2 --> return > 0 */
143 int Rm_ValidInstNodeCompare(Rm_ValidInstNode *element1, Rm_ValidInstNode *element2);
145 /* Generate the tree prototypes */
146 RB_PROTOTYPE(_Rm_ValidInstTree, _Rm_ValidInstNode, linkage, Rm_ValidInstNodeCompare);
148 #ifdef __cplusplus
149 }
150 #endif
152 #endif /* RM_POLICYLOC_H_ */