/* * file rm_policyloc.h * * Internal prototypes and data structures for the Resource Manager Policies. * * ============================================================================ * (C) Copyright 2012-2013, Texas Instruments, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the * distribution. * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * \par */ #ifndef RM_POLICYLOC_H_ #define RM_POLICYLOC_H_ #ifdef __cplusplus extern "C" { #endif /* RM external includes */ #include /* RM internal includes */ #include /* String stored for resource elements that are reserved by the Linux kernel. These * resources will be in use for the lifetime of the system * * TODO: MOVE TO policy.h LATER SO INTEGRATORS KNOW NOT TO NAME RM INSTANCES THIS NAME */ #define RM_ALLOCATED_TO_LINUX "Linux-Kernel" /* Policy permission bit storage type * Bit : Description *----------------------------- * 0 : Init (i) - RM instance has initialization permission for resource * 1 : Use (u) - RM instance has usage permission for resource * 2 : Exclusive (x) - RM instance has exclusive allocation privilege for resource * i.e. No other RM instance can reserve the resource if a RM * instance with exclusive privilege reserves the resource * 3 : Shared Linux (s) - Resource has been reserved by the Linux kernel but can be * allocated by the specified RM instances * 4 - 15 : UNUSED */ typedef uint16_t Rm_PolicyPermBits; /* Initialization permission characters */ #define RM_POLICY_PERM_INIT_LOWER 'i' #define RM_POLICY_PERM_INIT_UPPER 'I' /* Initialization permission bit shift */ #define RM_POLICY_PERM_INIT_SHIFT 0 /* Usage permission characters */ #define RM_POLICY_PERM_USE_LOWER 'u' #define RM_POLICY_PERM_USE_UPPER 'U' /* Usage permission bit shift */ #define RM_POLICY_PERM_USE_SHIFT 1 /* Exclusive permission characters */ #define RM_POLICY_PERM_EXCLUSIVE_LOWER 'x' #define RM_POLICY_PERM_EXCLUSIVE_UPPER 'X' /* Exclusive permission bit shift */ #define RM_POLICY_PERM_EXCLUSIVE_SHIFT 2 /* Shared Linux permission characters */ #define RM_POLICY_PERM_SHARED_LINUX_LOWER 's' #define RM_POLICY_PERM_SHARED_LINUX_UPPER 'S' /* Shared Linux permission bit shift */ #define RM_POLICY_PERM_SHARED_LINUX_SHIFT 3 /* Permissions subgroup start character */ #define RM_POLICY_PERM_SUBGROUP_START '(' /* Permissions subgroup end character */ #define RM_POLICY_PERM_SUBGROUP_END ')' /* Permissions subgroup terminator */ #define RM_POLICY_PERM_TERMINATOR '&' /* Permissions assignment character */ #define RM_POLICY_PERM_ASSIGNMENT '=' /* Macro to set permissions in a Rm_PolicyPermBits type */ #define RM_policy_SET_PERM(permBits, permTypeShift, val) \ permBits = ((permBits & (~(((Rm_PolicyPermBits) 0x1) << permTypeShift))) | \ ((((Rm_PolicyPermBits) val) & 0x1) << permTypeShift)) /* Macro to get permissions from Rm_PolicyPermBits type */ #define RM_policy_GET_PERM(permBits, permTypeShift) \ ((permBits >> permTypeShift) & 0x1) /* Assigned instance permissions linked list node */ typedef struct Rm_Permission_s { /* Instance name of instance assigned the permissions */ char instName[RM_NAME_MAX_CHARS]; /* Permissions assigned to the RM instance with instName */ Rm_PolicyPermBits permissionBits; /* Next permissions node */ struct Rm_Permission_s *nextPermission; } Rm_PolicyPermission; /* Permission validation types */ typedef enum { /* Validate exclusive permissions for a resource */ Rm_policyCheck_EXCLUSIVE = 0, /* Validate initialization permissions for a resource */ Rm_policyCheck_INIT, /* Validate usage permissions for a resource */ Rm_policyCheck_USE, /* Validate shared Linux permissions for a resource */ Rm_policyCheck_SHARED_LINUX } Rm_PolicyCheckType; /* Permissions validation configuration structure */ typedef struct { /* The type of validation to perform */ Rm_PolicyCheckType type; /* Policy to validate the permission check against */ void *policyDtb; /* Valid instance node that will have its permissions checked for * the defined resource */ Rm_PolicyValidInstNode *validInstNode; /* Resource node offset in the policy DTB */ int32_t resourceOffset; /* Resource base to validate permissions for the valid instance node */ uint32_t resourceBase; /* Resource length to validate permissions for the valid instance node */ uint32_t resourceLength; } Rm_PolicyCheckCfg; void *rmPolicyGetPolicy(Rm_Handle rmHandle); Rm_PolicyValidInstNode *rmPolicyGetValidInstNode(Rm_Handle rmHandle, char *instName); Rm_PolicyValidInstNode *rmPolicyGetLinuxInstNode(Rm_Handle rmHandle); int rmPolicyCheckPrivilege(Rm_PolicyCheckCfg *privilegeCfg, int32_t *result); uint32_t rmPolicyGetResourceBase(void *policyDtb, Rm_PolicyValidInstNode *validInstNode, int32_t resourceOffset, Rm_PolicyCheckType policyCheckType, int32_t *result); uint32_t rmPolicyGetResourceAlignment(void *policyDtb, int32_t resourceOffset); uint32_t rmPolicyGetResourceCdAllocSize(void *policyDtb, int32_t resourceOffset); int32_t rmPolicyGetResourceOffset(void *policyDtb, char *resourceName); int32_t rmPolicyValidatePolicyResourceNames(Rm_Handle rmHandle); int32_t rmPolicyValidatePolicy(Rm_Handle rmHandle); Rm_PolicyValidInstTree *rmPolicyCreateValidInstTree(Rm_Handle rmHandle, int addLinux, int32_t *result); void rmPolicyFreeValidInstTree(Rm_Handle rmHandle); #ifdef __cplusplus } #endif #endif /* RM_POLICYLOC_H_ */