From 7baaf117b24cc5f523e3e9e5ab7a9b5a361054db Mon Sep 17 00:00:00 2001 From: Justin Sobota Date: Tue, 22 Jan 2013 18:32:01 -0500 Subject: [PATCH] Added pre-main capabilities, cleaned up services and NameServer modules --- device/tci6614-cd-startup-policy.dtb | Bin 0 -> 316 bytes device/tci6614-cd-startup-policy.dts | 19 +++ device/tci6614-server-policy.dtb | Bin 2633 -> 2649 bytes device/tci6614-server-policy.dts | 3 +- include/rm_loc.h | 57 +++---- include/rm_nameserverloc.h | 46 ++++-- include/rm_policyloc.h | 105 ++++++------ include/rm_servicesloc.h | 20 +-- rm.h | 19 +++ rm_services.h | 38 ++--- src/rm.c | 234 ++++++++++++++++++++------- src/rm_nameserver.c | 142 +++++++--------- src/rm_policy.c | 191 ++++++++++------------ src/rm_services.c | 101 +++++++----- src/rm_transport.c | 4 +- 15 files changed, 554 insertions(+), 425 deletions(-) create mode 100644 device/tci6614-cd-startup-policy.dtb create mode 100644 device/tci6614-cd-startup-policy.dts diff --git a/device/tci6614-cd-startup-policy.dtb b/device/tci6614-cd-startup-policy.dtb new file mode 100644 index 0000000000000000000000000000000000000000..51a363f530b0f8742928c92b8ed08d49a23c16b4 GIT binary patch literal 316 zcmcb>`|m9S1EUQC1A_&SRshl(Kr9Hv0zeD`GC=$S%t9p?p3G8E>IlFd, "iux = (RM_Client_Delegate)", + <1 1>, "iux = (RM_Client)"; + }; + semaphores { + assignments = <0 1>, "iu = (RM_Client_Delegate RM_Client)"; + }; +}; + diff --git a/device/tci6614-server-policy.dtb b/device/tci6614-server-policy.dtb index b2ca53856b6682193bd699af69d7a526777184f5..feff2fd992723f1ffe4105fcacf69fd5b131aad6 100644 GIT binary patch delta 49 zcmX>pa#KX$0`I@K3=CY63=9kwKw4*_fH>oqjT-rkyv#r$79f@ZVv)^L7`Ji&06Uus Avj6}9 delta 39 ucmca9a#BR#0`I@K3=CYJ3=9kwKw4&^fH>omjT-rklh<>wZC=Z`h64cXBnzJa diff --git a/device/tci6614-server-policy.dts b/device/tci6614-server-policy.dts index 6ad3b89..6b57763 100644 --- a/device/tci6614-server-policy.dts +++ b/device/tci6614-server-policy.dts @@ -26,7 +26,8 @@ assignments = <0x00000000 0xFFFFFFFF>, "iux = (*)"; }; accumulator-ch { - assignments = <0 48>, "iux = (*)"; + assignments = <0 48>, "iux = (*)"; + alloc-alignments = <20>; }; qos-cluster { assignments = <0 8>, "iux = (*)"; diff --git a/include/rm_loc.h b/include/rm_loc.h index 5806800..a5d6573 100644 --- a/include/rm_loc.h +++ b/include/rm_loc.h @@ -48,6 +48,11 @@ extern "C" { #include #include +/* RM internal includes */ +#include +#include +#include + /* AVL BBST includes */ #include @@ -61,19 +66,6 @@ typedef void *Rm_TransportRouteMap; /** Pointer to RM instance's transaction queue */ typedef void *Rm_TransactionQueue; -/** Pointer to the RM instance's allocators */ -typedef void *Rm_Allocators; - -/** Pointer to the RM instance's NameServer (Valid only on Server) */ -typedef void *Rm_NameServer; - -/** Pointer to the RM instance's policy information */ -typedef void *Rm_Policy; - -/** Pointer to the RM instance's valid policy instances */ -typedef void *Rm_PolicyValidInstances; - - /** * @brief RM protocol packet resource information */ @@ -89,7 +81,7 @@ typedef struct { int32_t alignment; /** If applicable, the NameServer name assigned to the specified * resource. Used for commands centering on RM NameServer actions */ - char nsName[RM_RESOURCE_NAME_MAX_CHARS]; + char nameServerName[RM_RESOURCE_NAME_MAX_CHARS]; } Rm_ResourceInfo; /** @@ -142,7 +134,7 @@ typedef enum { } Rm_AllocatorOp; typedef struct { - void *serviceSrcInstNode; + Rm_PolicyValidInstNode *serviceSrcInstNode; Rm_AllocatorOp operation; uint32_t allocType; Rm_ResourceInfo *resourceInfo; @@ -156,23 +148,32 @@ typedef struct Rm_Allocator_s { struct Rm_Allocator_s *nextAllocator; } Rm_Allocator; + +typedef struct { + char instName[RM_INSTANCE_NAME_MAX_CHARS]; + void *startupDtb; + Rm_PolicyValidInstTree *validInstTree; + uint32_t requestCount; + Rm_ServicePreMainReq *preMainReqList; +} Rm_PreMainInst; + typedef struct { - char name[RM_INSTANCE_NAME_MAX_CHARS]; - Rm_InstType instType; - bool registeredWithDelegateOrServer; - Rm_Policy policy; - Rm_PolicyValidInstances validInstances; - Rm_Allocators allocators; - Rm_NameServer nameServer; + char instName[RM_INSTANCE_NAME_MAX_CHARS]; + Rm_InstType instType; + bool registeredWithDelegateOrServer; + void *policy; + Rm_PolicyValidInstTree *validInstances; + Rm_Allocator *allocators; + Rm_NameServerTree *nameServer; /* RM instance transport parameters */ - Rm_TransportRouteMap routeMap; + Rm_TransportRouteMap routeMap; /* RM Transaction sequence number counter */ - uint32_t transactionSeqNum; + uint32_t transactionSeqNum; /* RM transaction queue */ - Rm_TransactionQueue transactionQueue; + Rm_TransactionQueue transactionQueue; /* Transport API function pointers - not global in case application wants to * hook up different transports to RM */ - Rm_TransportCallouts transport; + Rm_TransportCallouts transport; } Rm_Inst; Rm_Transaction *Rm_transactionQueueAdd(Rm_Inst *rmInst); @@ -180,7 +181,7 @@ Rm_Transaction *Rm_transactionQueueFind(Rm_Inst *rmInst, uint32_t transactionId) int32_t Rm_transactionQueueDelete(Rm_Inst *rmInst, uint32_t transactionId); uint32_t Rm_transactionGetSequenceNum(Rm_Inst *rmInst); -Rm_Allocator *Rm_allocatorFind(Rm_Inst *rmInst, char *resourceName); +Rm_Allocator *Rm_allocatorFind(Rm_Allocator *allocatorList, char *resourceName); void Rm_transactionResponder (Rm_Inst *rmInst, Rm_Transaction *transaction); void Rm_transactionForwarder (Rm_Inst *rmInst, Rm_Transaction *transaction); @@ -192,7 +193,7 @@ void Rm_transactionProcessor (Rm_Inst *rmInst, Rm_Transaction *transaction); /* Declare the tree structure nodes */ typedef struct Rm_AllocatedTo_s { - void *instNameNode; + Rm_PolicyValidInstNode *instNameNode; struct Rm_AllocatedTo_s *nextAllocatedTo; } Rm_AllocatedTo; diff --git a/include/rm_nameserverloc.h b/include/rm_nameserverloc.h index 9dda456..a45d050 100644 --- a/include/rm_nameserverloc.h +++ b/include/rm_nameserverloc.h @@ -48,45 +48,57 @@ extern "C" { #include #include -/* RM internal includes */ -#include - /* AVL BBST includes */ #include -void Rm_nsInit(Rm_Inst *rmInst); -int32_t Rm_nsAddObject(Rm_Inst *rmInst, Rm_ResourceInfo *resourceInfo); -void Rm_nsPrintObjects(Rm_Inst *rmInst); -int32_t Rm_nsFindObject(Rm_Inst *rmInst, Rm_ResourceInfo *resourceInfo); -int32_t Rm_nsDeleteObject(Rm_Inst *rmInst, Rm_ResourceInfo *resourceInfo); +typedef struct { + char *objName; + char *resourceName; + uint32_t resourceBase; + uint32_t resourceLength; +} Rm_NameServerNodeCfg; /********************************************************************** - ******************* Red-Black Tree BBST Defines ********************** + ******************** NameServer Tree Definitions ********************* **********************************************************************/ /* Declare the tree structure nodes */ typedef struct _Rm_NameServerNode { RB_ENTRY(_Rm_NameServerNode) linkage; - char name[RM_RESOURCE_NAME_MAX_CHARS]; + char objName[RM_RESOURCE_NAME_MAX_CHARS]; char resourceName[RM_RESOURCE_NAME_MAX_CHARS]; - uint32_t base; - uint32_t length; + uint32_t resourceBase; + uint32_t resourceLength; } Rm_NameServerNode; /* Declare the tree head structure. */ typedef RB_HEAD(_Rm_NameServerTree, _Rm_NameServerNode) Rm_NameServerTree; -Rm_NameServerNode *Rm_newNameServerNode(char *name, char *resourceName, - uint32_t resourceBase, uint32_t resourceLength); -void Rm_freeNameServerNode(Rm_NameServerNode *node); +Rm_NameServerNode *Rm_nameServerNewNode(Rm_NameServerNodeCfg *nodeCfg); +void Rm_nameServerFreeNode(Rm_NameServerNode *node); /* Prototype for NameServer node comparison function * element1 < element2 --> return < 0 * element1 = element2 --> return 0 * element1 > element2 --> return > 0 */ -int Rm_NameServerNodeCompare(Rm_NameServerNode *element1, Rm_NameServerNode *element2); +int Rm_nameServerNodeCompare(Rm_NameServerNode *node1, Rm_NameServerNode *node2); /* Generate the tree prototypes */ -RB_PROTOTYPE(_Rm_NameServerTree, _Rm_NameServerNode, linkage, Rm_NameServerNodeCompare); +RB_PROTOTYPE(_Rm_NameServerTree, _Rm_NameServerNode, linkage, Rm_nameServerNodeCompare); + +/********************************************************************** + ********************* Internal NameServer APIs *********************** + **********************************************************************/ + +typedef struct { + Rm_NameServerTree *nameServerTree; + Rm_NameServerNodeCfg nodeCfg; +} Rm_NameServerObjCfg; + +int32_t Rm_nameServerAddObject(Rm_NameServerObjCfg *objCfg); +int32_t Rm_nameServerFindObject(Rm_NameServerObjCfg *objCfg); +int32_t Rm_nameServerDeleteObject(Rm_NameServerObjCfg *objCfg); +void Rm_nameServerPrintObjects(Rm_NameServerTree *nameServerTree); +Rm_NameServerTree *Rm_nameServerInit(void); #ifdef __cplusplus } diff --git a/include/rm_policyloc.h b/include/rm_policyloc.h index a81e976..1d43905 100644 --- a/include/rm_policyloc.h +++ b/include/rm_policyloc.h @@ -47,9 +47,6 @@ extern "C" { /* RM external API includes */ #include -/* RM internal API includes */ -#include - /* AVL BBST includes */ #include @@ -70,7 +67,7 @@ extern "C" { * allocated by the specified RM instances * 4 - 15 : UNUSED */ -typedef uint16_t Rm_PermissionBits; +typedef uint16_t Rm_PolicyPermBits; #define RM_POLICY_PERM_INIT_LOWER 'i' #define RM_POLICY_PERM_INIT_UPPER 'I' @@ -90,82 +87,76 @@ typedef uint16_t Rm_PermissionBits; #define RM_POLICY_PERM_TERMINATOR '&' #define RM_POLICY_PERM_ASSIGNMENT '=' -#define RM_POLICY_SET_PERM(permBits, permTypeShift, val) \ - permBits = ((permBits & (~(((Rm_PermissionBits) 0x1) << permTypeShift))) | \ - ((((Rm_PermissionBits) val) & 0x1) << permTypeShift)) -#define RM_POLICY_GET_PERM(permBits, permTypeShift) \ +#define RM_policy_SET_PERM(permBits, permTypeShift, val) \ + permBits = ((permBits & (~(((Rm_PolicyPermBits) 0x1) << permTypeShift))) | \ + ((((Rm_PolicyPermBits) val) & 0x1) << permTypeShift)) +#define RM_policy_GET_PERM(permBits, permTypeShift) \ ((permBits >> permTypeShift) & 0x1) typedef struct Rm_Permission_s { char instName[RM_INSTANCE_NAME_MAX_CHARS]; - Rm_PermissionBits permissionBits; + Rm_PolicyPermBits permissionBits; struct Rm_Permission_s *nextPermission; } Rm_PolicyPermission; -typedef struct { - const void *assignmentData; - int32_t assignmentLen; - const void *allocationSizeData; - int32_t allocationSizeLen; - const void *alignmentData; - int32_t alignmentLen; -} Rm_PolicyNodeProperties; - -typedef enum { - Rm_policyCheck_EXCLUSIVE = 0, - Rm_policyCheck_INIT, - Rm_policyCheck_USE -} Rm_PolicyCheckType; - -typedef struct { - Rm_PolicyCheckType type; - void *policyDtb; - void *validInstNode; - int32_t resourcePolicy; - uint32_t resourceBase; - uint32_t resourceLength; -} Rm_PolicyCheckCfg; - -void Rm_policyIncrementValidInstAllocationCount(void *validInstNameNode); -void Rm_policyDecrementValidInstAllocationCount(void *validInstNameNode); -void *Rm_policyGetValidInstNode(void *validInstTree, char *instName); -char *Rm_policyGetValidInstNodeName(void *validInstNode); -bool Rm_policyCheckPrivilege(Rm_PolicyCheckCfg *privilegeCfg, int32_t *result); -uint32_t Rm_policyGetResourceBase(void *policyDtb, void *validInstNode, - int32_t resourcePolicy, uint32_t allocType, - int32_t *result); -uint32_t Rm_policyGetResourceAlignment(void *policyDtb, int32_t resourcePolicy); -int32_t Rm_policyGetResourcePolicy(void *policyDtb, char *resourceName); -void *Rm_policyGetLinuxInstNode(void *validInstTree); -int32_t Rm_policyValidatePolicyResourceNames(Rm_Inst *rmInst, void *policyDtb); -int32_t Rm_policyValidatePolicy(Rm_Inst *rmInst, void *policyDtb); -void *Rm_policyCreateValidInstTree(void *policyDtb, int32_t *result); - /********************************************************************** - ******************* Red-Black Tree BBST Defines ********************** + ************** Policy Valid Instance Tree Definitions **************** **********************************************************************/ /* Declare the tree structure nodes */ -typedef struct _Rm_ValidInstNode { - RB_ENTRY(_Rm_ValidInstNode) linkage; +typedef struct _Rm_PolicyValidInstNode { + RB_ENTRY(_Rm_PolicyValidInstNode) linkage; char name[RM_INSTANCE_NAME_MAX_CHARS]; uint32_t allocRefCount; bool deletePending; -} Rm_ValidInstNode; +} Rm_PolicyValidInstNode; /* Declare the tree head structure. */ -typedef RB_HEAD(_Rm_ValidInstTree, _Rm_ValidInstNode) Rm_ValidInstTree; +typedef RB_HEAD(_Rm_PolicyValidInstTree, _Rm_PolicyValidInstNode) Rm_PolicyValidInstTree; -Rm_ValidInstNode *Rm_newValidInstNode(char *instName); -void Rm_freeValidInstNode(Rm_ValidInstNode *node); +Rm_PolicyValidInstNode *Rm_policyNewValidInstNode(char *instName); +void Rm_policyFreeValidInstNode(Rm_PolicyValidInstNode *node); /* Prototype for Valid Instance node comparison function * element1 < element2 --> return < 0 * element1 = element2 --> return 0 * element1 > element2 --> return > 0 */ -int Rm_ValidInstNodeCompare(Rm_ValidInstNode *element1, Rm_ValidInstNode *element2); +int Rm_policyValidInstNodeCompare(Rm_PolicyValidInstNode *node1, Rm_PolicyValidInstNode *node2); /* Generate the tree prototypes */ -RB_PROTOTYPE(_Rm_ValidInstTree, _Rm_ValidInstNode, linkage, Rm_ValidInstNodeCompare); +RB_PROTOTYPE(_Rm_PolicyValidInstTree, _Rm_PolicyValidInstNode, + linkage, Rm_policyValidInstNodeCompare); + +/********************************************************************** + *********************** Internal Policy APIs ************************* + **********************************************************************/ + +typedef enum { + Rm_policyCheck_EXCLUSIVE = 0, + Rm_policyCheck_INIT, + Rm_policyCheck_USE +} Rm_PolicyCheckType; + +typedef struct { + Rm_PolicyCheckType type; + void *policyDtb; + Rm_PolicyValidInstNode *validInstNode; + int32_t resourceOffset; + uint32_t resourceBase; + uint32_t resourceLength; +} Rm_PolicyCheckCfg; + +Rm_PolicyValidInstNode *Rm_policyGetValidInstNode(Rm_PolicyValidInstTree *validInstTree, char *instName); +Rm_PolicyValidInstNode *Rm_policyGetLinuxInstNode(Rm_PolicyValidInstTree *validInstTree); +bool Rm_policyCheckPrivilege(Rm_PolicyCheckCfg *privilegeCfg, int32_t *result); +uint32_t Rm_policyGetResourceBase(void *policyDtb, Rm_PolicyValidInstNode *validInstNode, + int32_t resourceOffset, uint32_t allocType, + int32_t *result); +uint32_t Rm_policyGetResourceAlignment(void *policyDtb, int32_t resourceOffset); +int32_t Rm_policyGetResourceOffset(void *policyDtb, char *resourceName); +int32_t Rm_policyValidatePolicyResourceNames(void *allocatorList, void *policyDtb); +int32_t Rm_policyValidatePolicy(void *policyDtb, Rm_PolicyValidInstTree *validInstTree); +Rm_PolicyValidInstTree *Rm_policyCreateValidInstTree(void *policyDtb, int32_t *result); +void Rm_policyFreeValidInstTree(Rm_PolicyValidInstTree *validInstTree); #ifdef __cplusplus } diff --git a/include/rm_servicesloc.h b/include/rm_servicesloc.h index f1317ae..8195ebd 100644 --- a/include/rm_servicesloc.h +++ b/include/rm_servicesloc.h @@ -37,28 +37,24 @@ * \par */ -#ifndef RMSERVICESLOC_H_ -#define RMSERVICESLOC_H_ +#ifndef RM_SERVICESLOC_H_ +#define RM_SERVICESLOC_H_ #ifdef __cplusplus extern "C" { #endif /* RM external includes */ -#include - -/* RM internal includes */ -#include - - -/* This function is executed when a RM instance receives a response to one of its requests - * and the information in the request must be provided to the original requesting component */ -void Rm_serviceResponder (Rm_Inst *rmInst, Rm_Transaction *transaction); +#include +typedef struct Rm_ServicePreMainReq_s { + Rm_ServiceReqInfo *preMainReq; + struct Rm_ServicePreMainReq_s *nextPreMainReq; +} Rm_ServicePreMainReq; #ifdef __cplusplus } #endif -#endif /* RMSERVICESLOC_H_ */ +#endif /* RM_SERVICESLOC_H_ */ diff --git a/rm.h b/rm.h index c896703..8ccbead 100644 --- a/rm.h +++ b/rm.h @@ -149,6 +149,9 @@ extern "C" { #define RM_INIT_ERROR_POLICY_SYNTAX_ERROR_INVALID_PERM_CHAR -263 #define RM_INIT_ERROR_POLICY_SYNTAX_ERROR_PERM_CHAR_WITHOUT_ASSIGN_CHAR -264 #define RM_INIT_ERROR_POLICY_SYNTAX_ERROR_INVALID_CHAR_ON_RIGHT_WITH_ASSINMENT_ON_LEFT -265 +#define RM_INIT_ERROR_PREMAIN_INST_AND_POSTMAIN_INST_NAMES_DONT_MATCH -266 + + /** * @brief Maximum number of characters in a RM instance name @@ -162,6 +165,8 @@ extern "C" { */ typedef void *Rm_Handle; +typedef void *Rm_PreMainHandle; + /** * @brief RM Instance types */ @@ -174,6 +179,12 @@ typedef enum { Rm_instType_CLIENT = 2 } Rm_InstType; +typedef struct { + char *instName; + Rm_InstType instType; + void *startupPolicyDtb; +} Rm_PreMainInitCfg; + /** * @brief RM instance initialization structure */ @@ -223,6 +234,14 @@ typedef struct { /* TESTING PURPOSES: SERVER ONLY */ void Rm_printResourceStatus(Rm_Handle *rmHandle); +Rm_PreMainHandle Rm_preMainInit(Rm_PreMainInitCfg *preMainInitCfg, int32_t *result); +/** [Server/Client Delegate Parameter] Pre-main allocation handle used to + * by application to request resources prior to main via the startup policy + * The preMainHandle will be used to validate the resources allocated prior + * to main + */ +int32_t Rm_preMainHandleValidateAndDelete(Rm_Handle rmHandle, Rm_PreMainHandle rmPreMainHandle); + /** * @b Description * @n diff --git a/rm_services.h b/rm_services.h index 2013a66..a4c4ce9 100644 --- a/rm_services.h +++ b/rm_services.h @@ -122,8 +122,12 @@ extern "C" { /** The resource couldn't be allocated because it was already allocated to an instance with exclusive * privileges for the resource */ #define RM_SERVICE_DENIED_RESOURCE_ALLOCATED_TO_INSTANCE_WITH_EXCLUSIVE_PRIV (RM_SERVICE_DENIED_BEGIN+21) +/** Pre main request was not an allocate use or allocate init request */ +#define RM_SERVICE_DENIED_INVALID_PREMAIN_REQUEST (RM_SERVICE_DENIED_BEGIN+22) +/** Startup policy denied pre-main allocation request */ +#define RM_SERVICE_DENIED_POLICY_DENIED_PREMAIN_ALLOCATION (RM_SERVICE_DENIED_BEGIN+23) /** End of resource denied reasons */ -#define RM_SERVICE_DENIED_END (RM_SERVICE_DENIED_BEGIN+21) +#define RM_SERVICE_DENIED_END (RM_SERVICE_DENIED_BEGIN+23) /** RM Service Request Error Code Base */ #define RM_SERVICE_ERROR_BASE (-64) @@ -192,21 +196,6 @@ typedef enum { Rm_service_RESOURCE_UNMAP_NAME } Rm_ServiceType; -/** - * @brief RM pre-main allocation request information provided by the pre-main - * startup function requesting the resource */ -typedef struct { - /** Pointer to the requested pre-main allocation resource name. The - * name provided by the component must match the resource names - * provided in the global resource table and allocation policies */ - char *resourceName; - /** The pre-main allocation request resource base value. For example, - * queue number or semaphore number */ - uint32_t resourceBase; - /** Range of resource starting at resourceBase */ - uint32_t resourceRange; -} Rm_PreMainAllocInfo; - /** * @brief RM service response information provided by RM back to the * requesting component @@ -305,6 +294,14 @@ typedef struct { Rm_ServiceRespInfo *serviceResponse); } Rm_ServicePort; +/** + * @brief RM pre-main allocation request information provided by the pre-main + * startup function requesting the resource */ +typedef struct { + Rm_PreMainHandle rmPreMainHandle; + Rm_ServiceReqInfo *request; +} Rm_PreMainReqCfg; + /** * @b Description * @n @@ -318,11 +315,11 @@ typedef struct { * running a RM Server or Client Delegate that has a startup policy * allowing the allocation of pre-main resources * - * @param[in] preMainAllocInfo + * @param[in] preMainRequest * Resource pre-main allocation structure that provides details of the * resource requested from RM for preallocation * - * @param[out] serviceResponse + * @param[out] preMainResponse * Contains the result information regarding the pre-main allocation request * * @retval @@ -330,8 +327,7 @@ typedef struct { * @retval * Failure - non-zero - Resource pre-main allocation request error. */ -void Rm_preMainAllocService (Rm_PreMainAllocInfo *preMainAllocInfo, - Rm_ServiceRespInfo *serviceResponse); +void Rm_servicePreMainRequest(Rm_PreMainReqCfg *reqCfg, Rm_ServiceRespInfo *preMainResp); /** * @b Description @@ -350,7 +346,7 @@ void Rm_preMainAllocService (Rm_PreMainAllocInfo *preMainAllocInfo, * @retval * Failure - NULL */ -Rm_ServicePort *Rm_getServicePort(Rm_Handle rmHandle); +Rm_ServicePort *Rm_serviceGetPort(Rm_Handle rmHandle); /** @} diff --git a/src/rm.c b/src/rm.c index c108bf6..273c175 100644 --- a/src/rm.c +++ b/src/rm.c @@ -290,18 +290,16 @@ Rm_Allocator *Rm_allocatorAdd(Rm_Inst *rmInst, const char *resourceName) return (newAllocator); } -Rm_Allocator *Rm_allocatorFind(Rm_Inst *rmInst, char *resourceName) +Rm_Allocator *Rm_allocatorFind(Rm_Allocator *allocatorList, char *resourceName) { - Rm_Allocator *allocator = (Rm_Allocator *)rmInst->allocators; - - while (allocator) { - if (strcmp(allocator->resourceName, resourceName) == 0) { + while (allocatorList) { + if (strcmp(allocatorList->resourceName, resourceName) == 0) { break; } - allocator = allocator->nextAllocator; + allocatorList = allocatorList->nextAllocator; } - return (allocator); + return (allocatorList); } int32_t Rm_allocatorDelete(Rm_Inst *rmInst, char *resourceName) @@ -365,7 +363,7 @@ void Rm_addAllocatedTo(Rm_ResourceNode *node, void *serviceInstNode) } node->allocationCount++; - Rm_policyIncrementValidInstAllocationCount(newAllocatedTo->instNameNode); + newAllocatedTo->instNameNode->allocRefCount++; } } @@ -439,7 +437,7 @@ void Rm_deleteAllocatedTo(Rm_ResourceNode *node, void *serviceInstNode) } node->allocationCount--; - Rm_policyDecrementValidInstAllocationCount(allocatedTo->instNameNode); + allocatedTo->instNameNode->allocRefCount--; Rm_osalFree((void *)allocatedTo, sizeof(Rm_AllocatedTo)); } @@ -555,14 +553,14 @@ int32_t Rm_treePreAllocate(Rm_Inst *rmInst, Rm_Allocator *allocator, int32_t res /* Configure policy checking structure */ memset((void *)&policyCheckCfg, 0, sizeof(Rm_PolicyCheckCfg)); - if (RM_POLICY_GET_PERM(opInfo->allocType, RM_POLICY_PERM_INIT_SHIFT)) { + if (RM_policy_GET_PERM(opInfo->allocType, RM_POLICY_PERM_INIT_SHIFT)) { policyCheckType = Rm_policyCheck_INIT; } - else if (RM_POLICY_GET_PERM(opInfo->allocType, RM_POLICY_PERM_USE_SHIFT)) { + else if (RM_policy_GET_PERM(opInfo->allocType, RM_POLICY_PERM_USE_SHIFT)) { policyCheckType = Rm_policyCheck_USE; } policyCheckCfg.policyDtb = rmInst->policy; - policyCheckCfg.resourcePolicy = resourcePolicy; + policyCheckCfg.resourceOffset = resourcePolicy; do { matchingNode = RB_FIND(_Rm_ResourceTree, allocator->allocatorRootEntry, &findNode); @@ -648,10 +646,10 @@ int32_t Rm_treeAllocate(Rm_Inst *rmInst, Rm_Allocator *allocator, int32_t resour /* Prepare privilege checks */ memset((void *)&policyCheckCfg, 0, sizeof(Rm_PolicyCheckCfg)); - if (RM_POLICY_GET_PERM(opInfo->allocType, RM_POLICY_PERM_INIT_SHIFT)) { + if (RM_policy_GET_PERM(opInfo->allocType, RM_POLICY_PERM_INIT_SHIFT)) { policyCheckType = Rm_policyCheck_INIT; } - else if (RM_POLICY_GET_PERM(opInfo->allocType, RM_POLICY_PERM_USE_SHIFT)) { + else if (RM_policy_GET_PERM(opInfo->allocType, RM_POLICY_PERM_USE_SHIFT)) { policyCheckType = Rm_policyCheck_USE; } @@ -667,7 +665,7 @@ int32_t Rm_treeAllocate(Rm_Inst *rmInst, Rm_Allocator *allocator, int32_t resour else { allocPassesPolicy = FALSE; policyCheckCfg.policyDtb = rmInst->policy; - policyCheckCfg.resourcePolicy = resourcePolicy; + policyCheckCfg.resourceOffset = resourcePolicy; policyCheckCfg.type = policyCheckType; policyCheckCfg.validInstNode = opInfo->serviceSrcInstNode; policyCheckCfg.resourceBase = findNode.base; @@ -1047,25 +1045,25 @@ int32_t Rm_treeFree(Rm_Inst *rmInst, Rm_Allocator *allocator, int32_t resourcePo int32_t Rm_allocatorOperation(Rm_Inst *rmInst, Rm_AllocatorOpInfo *opInfo) { Rm_Allocator *allocator = NULL; - int32_t resourcePolicy = NULL; + int32_t resourceOffsetInPolicy; int32_t retVal; void *key; /* Lock access to the RM instance's transaction queue */ key = Rm_osalMtCsEnter(); - resourcePolicy = Rm_policyGetResourcePolicy(rmInst->policy, opInfo->resourceInfo->name); - allocator = Rm_allocatorFind(rmInst, opInfo->resourceInfo->name); + resourceOffsetInPolicy = Rm_policyGetResourceOffset(rmInst->policy, opInfo->resourceInfo->name); + allocator = Rm_allocatorFind(rmInst->allocators, opInfo->resourceInfo->name); - if ((resourcePolicy > 0) && allocator) { + if ((resourceOffsetInPolicy > 0) && allocator) { if (opInfo->operation == Rm_allocatorOp_PRE_ALLOCATE) { - retVal = Rm_treePreAllocate(rmInst, allocator, resourcePolicy, opInfo); + retVal = Rm_treePreAllocate(rmInst, allocator, resourceOffsetInPolicy, opInfo); } else if (opInfo->operation == Rm_allocatorOp_ALLOCATE) { - retVal = Rm_treeAllocate(rmInst, allocator, resourcePolicy, opInfo); + retVal = Rm_treeAllocate(rmInst, allocator, resourceOffsetInPolicy, opInfo); } else if (opInfo->operation == Rm_allocatorOp_FREE) { - retVal = Rm_treeFree(rmInst, allocator, resourcePolicy, opInfo); + retVal = Rm_treeFree(rmInst, allocator, resourceOffsetInPolicy, opInfo); } } else { @@ -1080,8 +1078,9 @@ int32_t Rm_allocatorOperation(Rm_Inst *rmInst, Rm_AllocatorOpInfo *opInfo) void Rm_allocationHandler (Rm_Inst *rmInst, Rm_Transaction *transaction, void *validInstNode, uint32_t allocType) { - Rm_AllocatorOpInfo opInfo; - int32_t retVal = transaction->state; + Rm_AllocatorOpInfo opInfo; + Rm_NameServerObjCfg nameServerObjCfg; + int32_t retVal = transaction->state; memset((void *)&opInfo, 0, sizeof(Rm_AllocatorOpInfo)); @@ -1095,13 +1094,20 @@ void Rm_allocationHandler (Rm_Inst *rmInst, Rm_Transaction *transaction, void *v opInfo.serviceSrcInstNode = validInstNode; opInfo.allocType = allocType; - if (strlen(transaction->resourceInfo.nsName) > 0) { + if (strlen(transaction->resourceInfo.nameServerName) > 0) { if (transaction->resourceInfo.base != 0) { /* Both NameServer name and static value cannot be specified for the request */ retVal = RM_SERVICE_ERROR_NAMESERVER_NAME_AND_RESOURCE_RANGE_BOTH_DEFINED; } else { - retVal = Rm_nsFindObject(rmInst, opInfo.resourceInfo); + memset((void *)&nameServerObjCfg, 0, sizeof(Rm_NameServerObjCfg)); + nameServerObjCfg.nameServerTree = rmInst->nameServer; + nameServerObjCfg.nodeCfg.objName = transaction->resourceInfo.nameServerName; + if ((retVal = Rm_nameServerFindObject(&nameServerObjCfg)) == RM_SERVICE_PROCESSING) { + strcpy(transaction->resourceInfo.name, nameServerObjCfg.nodeCfg.resourceName); + transaction->resourceInfo.base = nameServerObjCfg.nodeCfg.resourceBase; + transaction->resourceInfo.length = nameServerObjCfg.nodeCfg.resourceLength; + } } } @@ -1119,7 +1125,7 @@ void Rm_allocationHandler (Rm_Inst *rmInst, Rm_Transaction *transaction, void *v transaction->state = retVal; - if (strcmp(transaction->serviceSrcInstName, rmInst->name)) { + if (strcmp(transaction->serviceSrcInstName, rmInst->instName)) { /* Source of allocation was not the server instance, provide the transaction * to the transaction responder */ Rm_transactionResponder(rmInst, transaction); @@ -1130,8 +1136,9 @@ void Rm_allocationHandler (Rm_Inst *rmInst, Rm_Transaction *transaction, void *v void Rm_freeHandler (Rm_Inst *rmInst, Rm_Transaction *transaction, void *validInstNode) { - Rm_AllocatorOpInfo opInfo; - int32_t retVal = transaction->state; + Rm_AllocatorOpInfo opInfo; + Rm_NameServerObjCfg nameServerObjCfg; + int32_t retVal = transaction->state; memset((void *)&opInfo, 0, sizeof(Rm_AllocatorOpInfo)); @@ -1143,14 +1150,22 @@ void Rm_freeHandler (Rm_Inst *rmInst, Rm_Transaction *transaction, void *validIn opInfo.resourceInfo = &transaction->resourceInfo; opInfo.serviceSrcInstNode = validInstNode; - if (strlen(transaction->resourceInfo.nsName) > 0) { + if (strlen(transaction->resourceInfo.nameServerName) > 0) { if (transaction->resourceInfo.base != 0) { /* Both a name and a value cannot be specified for the request */ retVal = RM_SERVICE_ERROR_NAMESERVER_NAME_AND_RESOURCE_RANGE_BOTH_DEFINED; } else { - retVal = Rm_nsFindObject(rmInst, opInfo.resourceInfo); + memset((void *)&nameServerObjCfg, 0, sizeof(Rm_NameServerObjCfg)); + nameServerObjCfg.nameServerTree = rmInst->nameServer; + nameServerObjCfg.nodeCfg.objName = transaction->resourceInfo.nameServerName; + if ((retVal = Rm_nameServerFindObject(&nameServerObjCfg)) == RM_SERVICE_PROCESSING) { + strcpy(transaction->resourceInfo.name, nameServerObjCfg.nodeCfg.resourceName); + transaction->resourceInfo.base = nameServerObjCfg.nodeCfg.resourceBase; + transaction->resourceInfo.length = nameServerObjCfg.nodeCfg.resourceLength; + } } + } if(retVal == RM_SERVICE_PROCESSING) { @@ -1160,7 +1175,7 @@ void Rm_freeHandler (Rm_Inst *rmInst, Rm_Transaction *transaction, void *validIn transaction->state = retVal; - if (strcmp(transaction->serviceSrcInstName, rmInst->name)) { + if (strcmp(transaction->serviceSrcInstName, rmInst->instName)) { /* Source of allocation was not the server instance, provide the transaction * to the transaction responder */ Rm_transactionResponder(rmInst, transaction); @@ -1169,6 +1184,39 @@ void Rm_freeHandler (Rm_Inst *rmInst, Rm_Transaction *transaction, void *validIn } } +/* This function is executed when a RM instance receives a response to one of its requests + * and the information in the request must be provided to the original requesting component */ +void Rm_serviceResponder (Rm_Inst *rmInst, Rm_Transaction *transaction) +{ + Rm_ServiceRespInfo serviceResponse; + + /* The responseTransaction will contain the resultant state details of + * the requestTransaction's service request */ + serviceResponse.serviceState = transaction->state; + /* Pass back the ID that was provided to the component when it requested + * the service */ + serviceResponse.serviceId = transaction->localId; + + /* Service was approved and service was an allocate request. The resource + * data is passed back to the component */ + if ((serviceResponse.serviceState == RM_SERVICE_APPROVED_AND_COMPLETED) && + ((transaction->type == Rm_service_RESOURCE_ALLOCATE_INIT) || + (transaction->type == Rm_service_RESOURCE_ALLOCATE_USE) || + (transaction->type == Rm_service_RESOURCE_GET_BY_NAME))) + { + strcpy(serviceResponse.resourceName, transaction->resourceInfo.name); + serviceResponse.resourceBase = transaction->resourceInfo.base; + serviceResponse.resourceLength = transaction->resourceInfo.length; + } + + /* Issue the callback to the requesting component with the response information */ + transaction->callback.serviceCallback(&serviceResponse); + + /* Delete the transaction from the transaction queue */ + Rm_transactionQueueDelete(rmInst, transaction->localId); + return; +} + /* Function used to send RM response transactions to lower level agents */ void Rm_transactionResponder (Rm_Inst *rmInst, Rm_Transaction *transaction) { @@ -1299,8 +1347,9 @@ void Rm_transactionForwarder (Rm_Inst *rmInst, Rm_Transaction *transaction) void Rm_transactionProcessor (Rm_Inst *rmInst, Rm_Transaction *transaction) { - void *validInstNode; - uint32_t allocType = 0; + void *validInstNode; + Rm_NameServerObjCfg nameServerObjCfg; + uint32_t allocType = 0; /* Handle auto-forwarded transactions. These transactions include: * - All request transactions received on Clients are forwarded to the Client Delegate @@ -1312,7 +1361,7 @@ void Rm_transactionProcessor (Rm_Inst *rmInst, Rm_Transaction *transaction) (transaction->type == Rm_service_RESOURCE_UNMAP_NAME)))) { if (transaction->state != RM_SERVICE_PROCESSING) { - if (strcmp(transaction->serviceSrcInstName, rmInst->name)) { + if (strcmp(transaction->serviceSrcInstName, rmInst->instName)) { /* Transaction did not originate on this instance */ Rm_transactionResponder(rmInst, transaction); } @@ -1334,7 +1383,7 @@ void Rm_transactionProcessor (Rm_Inst *rmInst, Rm_Transaction *transaction) transaction->state = RM_SERVICE_DENIED_ORIGINATING_INSTANCE_NAME_NOT_VALID; /* Send result via responder if transaction did not originate from this instance */ - if (strcmp(transaction->serviceSrcInstName, rmInst->name)) { + if (strcmp(transaction->serviceSrcInstName, rmInst->instName)) { Rm_transactionResponder(rmInst, transaction); } } @@ -1346,7 +1395,7 @@ void Rm_transactionProcessor (Rm_Inst *rmInst, Rm_Transaction *transaction) case Rm_service_RESOURCE_FREE: if (transaction->state != RM_SERVICE_PROCESSING) { /* Transaction complete */ - if (strcmp(transaction->serviceSrcInstName, rmInst->name)) { + if (strcmp(transaction->serviceSrcInstName, rmInst->instName)) { /* Transaction result not destined for this instance */ Rm_transactionResponder(rmInst, transaction); } @@ -1363,10 +1412,10 @@ void Rm_transactionProcessor (Rm_Inst *rmInst, Rm_Transaction *transaction) else { switch (transaction->type) { case Rm_service_RESOURCE_ALLOCATE_INIT: - RM_POLICY_SET_PERM(allocType, RM_POLICY_PERM_INIT_SHIFT, 1); + RM_policy_SET_PERM(allocType, RM_POLICY_PERM_INIT_SHIFT, 1); break; case Rm_service_RESOURCE_ALLOCATE_USE: - RM_POLICY_SET_PERM(allocType, RM_POLICY_PERM_USE_SHIFT, 1); + RM_policy_SET_PERM(allocType, RM_POLICY_PERM_USE_SHIFT, 1); break; } Rm_allocationHandler(rmInst, transaction, validInstNode, allocType); @@ -1377,21 +1426,31 @@ void Rm_transactionProcessor (Rm_Inst *rmInst, Rm_Transaction *transaction) case Rm_service_RESOURCE_GET_BY_NAME: case Rm_service_RESOURCE_UNMAP_NAME: /* NameServer resides on server */ + memset((void *)&nameServerObjCfg, 0, sizeof(Rm_NameServerObjCfg)); + nameServerObjCfg.nameServerTree = rmInst->nameServer; + nameServerObjCfg.nodeCfg.objName = transaction->resourceInfo.nameServerName; if (rmInst->instType == Rm_instType_SERVER) { if (transaction->type == Rm_service_RESOURCE_MAP_TO_NAME) { - transaction->state = Rm_nsAddObject(rmInst, &transaction->resourceInfo); + nameServerObjCfg.nodeCfg.resourceName = transaction->resourceInfo.name; + nameServerObjCfg.nodeCfg.resourceBase= transaction->resourceInfo.base; + nameServerObjCfg.nodeCfg.resourceLength = transaction->resourceInfo.length; + transaction->state = Rm_nameServerAddObject(&nameServerObjCfg); } else if (transaction->type == Rm_service_RESOURCE_GET_BY_NAME) { - if (Rm_nsFindObject(rmInst, &transaction->resourceInfo) == RM_SERVICE_PROCESSING) { + if ((transaction->state = Rm_nameServerFindObject(&nameServerObjCfg)) == + RM_SERVICE_PROCESSING) { + strcpy(transaction->resourceInfo.name, nameServerObjCfg.nodeCfg.resourceName); + transaction->resourceInfo.base = nameServerObjCfg.nodeCfg.resourceBase; + transaction->resourceInfo.length = nameServerObjCfg.nodeCfg.resourceLength; transaction->state = RM_SERVICE_APPROVED_AND_COMPLETED; - } + } } else if (transaction->type == Rm_service_RESOURCE_UNMAP_NAME) { - transaction->state = Rm_nsDeleteObject(rmInst, &transaction->resourceInfo); + transaction->state = Rm_nameServerDeleteObject(&nameServerObjCfg); } /* Send result via responder if transaction did not originate from this instance */ - if (strcmp(transaction->serviceSrcInstName, rmInst->name)) { + if (strcmp(transaction->serviceSrcInstName, rmInst->instName)) { Rm_transactionResponder(rmInst, transaction); } } @@ -1541,7 +1600,7 @@ int32_t Rm_createAndInitAllocator(Rm_Inst *rmInst, const char *resourceName, Rm_NsAssignment *nsAssignments = NULL; Rm_NsAssignment *nsAssignmentBasePtr = NULL; Rm_LinuxAlias *linuxAlias = NULL; - Rm_ResourceInfo resourceInfo; + Rm_NameServerObjCfg nameServerObjCfg; int32_t retVal = RM_DTB_UTIL_RESULT_OKAY; if (resourceProperties->rangeData && (resourceProperties->rangeLen > 0)) @@ -1578,15 +1637,15 @@ int32_t Rm_createAndInitAllocator(Rm_Inst *rmInst, const char *resourceName, nsAssignmentBasePtr = nsAssignments; while (nsAssignments) { - memset((void *)&resourceInfo, 0, sizeof(Rm_ResourceInfo)); - - strcpy(resourceInfo.name, resourceName); - resourceInfo.base = nsAssignments->resourceBase; - resourceInfo.length = nsAssignments->resourceLength; - strcpy(resourceInfo.nsName, nsAssignments->nsName); + memset((void *)&nameServerObjCfg, 0, sizeof(Rm_NameServerObjCfg)); + nameServerObjCfg.nameServerTree = rmInst->nameServer; + nameServerObjCfg.nodeCfg.objName = nsAssignments->nsName; + nameServerObjCfg.nodeCfg.resourceName = (char *)resourceName; + nameServerObjCfg.nodeCfg.resourceBase= nsAssignments->resourceBase; + nameServerObjCfg.nodeCfg.resourceLength = nsAssignments->resourceLength; /* TODO: RETURN IF ANY OF THE ADDS FAIL??? */ - Rm_nsAddObject(rmInst, &resourceInfo); + Rm_nameServerAddObject(&nameServerObjCfg); nsAssignments = nsAssignments->nextNsAssignment; } /* Free the memory allocated for the NameServer assignments */ @@ -1787,7 +1846,7 @@ void Rm_printResourceStatus(Rm_Handle *rmHandle) allocatedTo = treeNode->allocatedTo; Rm_osalLog("allocated to "); while (allocatedTo) { - Rm_osalLog(" %s", Rm_policyGetValidInstNodeName(allocatedTo->instNameNode)); + Rm_osalLog(" %s", allocatedTo->instNameNode->name); allocatedTo = allocatedTo->nextAllocatedTo; } Rm_osalLog("\n"); @@ -1796,7 +1855,70 @@ void Rm_printResourceStatus(Rm_Handle *rmHandle) allocator = allocator->nextAllocator; } - Rm_nsPrintObjects(rmInst); + Rm_nameServerPrintObjects(rmInst->nameServer); +} + +Rm_PreMainHandle Rm_preMainInit(Rm_PreMainInitCfg *preMainInitCfg, int32_t *result) +{ + Rm_PreMainInst *preMainInst; + + if ((strlen(preMainInitCfg->instName) + 1) > RM_INSTANCE_NAME_MAX_CHARS) { + *result = RM_INIT_ERROR_INSTANCE_NAME_TOO_BIG; + return (NULL); + } + + preMainInst = (Rm_PreMainInst *) Rm_osalMalloc (sizeof(Rm_PreMainInst)); + fdt_open_into(preMainInitCfg->startupPolicyDtb, preMainInitCfg->startupPolicyDtb, + fdt_totalsize(preMainInitCfg->startupPolicyDtb)); + preMainInst->startupDtb = preMainInitCfg->startupPolicyDtb; + + preMainInst->validInstTree = Rm_policyCreateValidInstTree(preMainInst->startupDtb, result); + if (*result == RM_INIT_OK) { + /* Validate policy assignment strings */ + *result = Rm_policyValidatePolicy(preMainInitCfg->startupPolicyDtb, preMainInst->validInstTree); + } + + if (*result != RM_INIT_OK) { + if (preMainInst->validInstTree) { + Rm_policyFreeValidInstTree(preMainInst->validInstTree); + } + Rm_osalFree((void *)preMainInst, sizeof(Rm_PreMainInst)); + preMainInst = NULL; + } + else { + strcpy(preMainInst->instName, preMainInitCfg->instName); + preMainInst->requestCount = 0; + preMainInst->preMainReqList = NULL; + } + + return((Rm_PreMainHandle)preMainInst); +} + +int32_t Rm_preMainHandleValidateAndDelete(Rm_Handle rmHandle, Rm_PreMainHandle rmPreMainHandle) +{ + Rm_Inst *rmInst = (Rm_Inst *)rmHandle; + Rm_PreMainInst *preMainInst = (Rm_PreMainInst *)rmPreMainHandle; + Rm_ServicePreMainReq *serviceReq = preMainInst->preMainReqList; + Rm_ServicePreMainReq *nextServiceReq; + int32_t retVal = RM_INIT_OK; + + if (strcmp(rmInst->instName, preMainInst->instName) == 0) { + /* TODO: Validate the requests against the global policyDtb */ + + /* Free all memory associated with the pre-main instance */ + Rm_policyFreeValidInstTree(preMainInst->validInstTree); + while(serviceReq) { + nextServiceReq = serviceReq->nextPreMainReq; + Rm_osalFree((void *)serviceReq->preMainReq, sizeof(Rm_ServiceReqInfo)); + Rm_osalFree((void *)serviceReq, sizeof(Rm_ServicePreMainReq)); + serviceReq = nextServiceReq; + } + Rm_osalFree((void *)preMainInst, sizeof(Rm_PreMainInst)); + } + else { + retVal = RM_INIT_ERROR_PREMAIN_INST_AND_POSTMAIN_INST_NAMES_DONT_MATCH; + } + return(retVal); } Rm_Handle Rm_init(Rm_InitCfg *initCfg, int32_t *result) @@ -1816,7 +1938,7 @@ Rm_Handle Rm_init(Rm_InitCfg *initCfg, int32_t *result) /* Create and initialize instance */ rmInst = Rm_osalMalloc (sizeof(Rm_Inst)); memset ((void *) rmInst, 0, sizeof(Rm_Inst)); - strcpy (&rmInst->name[0], initCfg->instName); + strcpy (rmInst->instName, initCfg->instName); rmInst->instType = initCfg->instType; rmInst->registeredWithDelegateOrServer = false; rmInst->routeMap = NULL; @@ -1841,7 +1963,7 @@ Rm_Handle Rm_init(Rm_InitCfg *initCfg, int32_t *result) /* RM Server specific actions */ if (rmInst->instType == Rm_instType_SERVER) { - Rm_nsInit(rmInst); + Rm_nameServerInit(); if (initCfg->globalResourceList) { globalResourceDtb = initCfg->globalResourceList; diff --git a/src/rm_nameserver.c b/src/rm_nameserver.c index 10b5abe..14f4469 100644 --- a/src/rm_nameserver.c +++ b/src/rm_nameserver.c @@ -2,7 +2,7 @@ * @file rm_nameserver.c * * @brief - * This is the Resource Manager NameServer source. + * Resource Manager NameServer source. * * \par * ============================================================================ @@ -46,7 +46,6 @@ #include /* RM internal API includes */ -#include #include /* AVL BBST includes */ @@ -56,143 +55,118 @@ #include /********************************************************************** - ************** Red-Black BBST Tree NameServer Functions ************** + ********************* NameServer Tree Functions ********************** **********************************************************************/ -Rm_NameServerNode *Rm_newNameServerNode(char *name, char *resourceName, - uint32_t resourceBase, uint32_t resourceLength) +Rm_NameServerNode *Rm_nameServerNewNode(Rm_NameServerNodeCfg *nodeCfg) { Rm_NameServerNode *newNode = NULL; newNode = Rm_osalMalloc(sizeof(Rm_NameServerNode)); - - /* Populate the node */ - strcpy(newNode->name, name); - strcpy(newNode->resourceName, resourceName); - newNode->base = resourceBase; - newNode->length = resourceLength; + if (newNode) { + strcpy(newNode->objName, nodeCfg->objName); + strcpy(newNode->resourceName, nodeCfg->resourceName); + newNode->resourceBase = nodeCfg->resourceBase; + newNode->resourceLength = nodeCfg->resourceLength; + } return(newNode); } -void Rm_freeNameServerNode(Rm_NameServerNode *node) +void Rm_nameServerFreeNode(Rm_NameServerNode *node) { - /* Free the memory associated with the tree node. */ - Rm_osalFree((void *)node, sizeof(Rm_NameServerNode)); + if (node) { + Rm_osalFree((void *)node, sizeof(Rm_NameServerNode)); + } } -/* Prototype for tree node comparison function - * element1 < element2 --> return < 0 - * element1 = element2 --> return 0 - * element1 > element2 --> return > 0 */ -int Rm_NameServerNodeCompare(Rm_NameServerNode *element1, Rm_NameServerNode *element2) +int Rm_nameServerNodeCompare(Rm_NameServerNode *node1, Rm_NameServerNode *node2) { - return(strcmp(element1->name, element2->name)); + return(strcmp(node1->objName, node2->objName)); } -/* Generate the red-black tree manipulation functions */ -RB_GENERATE(_Rm_NameServerTree, _Rm_NameServerNode, linkage, Rm_NameServerNodeCompare); +/* Generate the NameServer tree manipulation functions */ +RB_GENERATE(_Rm_NameServerTree, _Rm_NameServerNode, linkage, Rm_nameServerNodeCompare); /********************************************************************** - ********************** Internal Functions **************************** + ******************* Internal NameServer APIs ************************* **********************************************************************/ -int32_t Rm_nsAddObject(Rm_Inst *rmInst, Rm_ResourceInfo *resourceInfo) +int32_t Rm_nameServerAddObject(Rm_NameServerObjCfg *objCfg) { - Rm_NameServerNode *newNode = NULL; - Rm_NameServerNode *collidingNode = NULL; - int32_t retVal = RM_SERVICE_APPROVED_AND_COMPLETED; - - newNode = Rm_newNameServerNode(resourceInfo->nsName, resourceInfo->name, - resourceInfo->base, resourceInfo->length); - - if (newNode) - { - /* Try to insert the new name */ - collidingNode = RB_INSERT(_Rm_NameServerTree, rmInst->nameServer, newNode); - - if (collidingNode) - { - Rm_freeNameServerNode(newNode); + Rm_NameServerNode *newNode = NULL; + int32_t retVal = RM_SERVICE_APPROVED_AND_COMPLETED; + + if (newNode = Rm_nameServerNewNode(&objCfg->nodeCfg)) { + if (RB_INSERT(_Rm_NameServerTree, objCfg->nameServerTree, newNode)) { + /* Collision */ + Rm_nameServerFreeNode(newNode); retVal = RM_SERVICE_DENIED_NAMESERVER_ERROR_NAME_ALREADY_EXISTS; } } - else - { + else { retVal = RM_SERVICE_ERROR_NAMESERVER_OBJECT_ADD_FAILED; } return(retVal); } -int32_t Rm_nsFindObject(Rm_Inst *rmInst, Rm_ResourceInfo *resourceInfo) +int32_t Rm_nameServerFindObject(Rm_NameServerObjCfg *objCfg) { Rm_NameServerNode findNode; - Rm_NameServerNode *matchingNode = NULL; - int32_t retVal = RM_SERVICE_PROCESSING; + Rm_NameServerNode *matchingNode; + int32_t retVal = RM_SERVICE_ERROR_NAMESERVER_ERROR_NAME_DOES_NOT_EXIST; memset((void *)&findNode, 0, sizeof(Rm_NameServerNode)); - strcpy(findNode.name, resourceInfo->nsName); - - matchingNode = RB_FIND(_Rm_NameServerTree, rmInst->nameServer, &findNode); - - if (matchingNode) { - /* Copy the name's resource information */ - strcpy(resourceInfo->name, matchingNode->resourceName); - resourceInfo->base = matchingNode->base; - resourceInfo->length = matchingNode->length; - } - else { - retVal = RM_SERVICE_ERROR_NAMESERVER_ERROR_NAME_DOES_NOT_EXIST; - } + strcpy(findNode.objName, objCfg->nodeCfg.objName); + if (matchingNode = RB_FIND(_Rm_NameServerTree, objCfg->nameServerTree, &findNode)) { + /* Found in NameServer */ + strcpy(objCfg->nodeCfg.resourceName, matchingNode->resourceName); + objCfg->nodeCfg.resourceBase = matchingNode->resourceBase; + objCfg->nodeCfg.resourceLength = matchingNode->resourceLength; + + retVal = RM_SERVICE_PROCESSING; + } return(retVal); } -int32_t Rm_nsDeleteObject(Rm_Inst *rmInst, Rm_ResourceInfo *resourceInfo) +int32_t Rm_nameServerDeleteObject(Rm_NameServerObjCfg *objCfg) { - Rm_NameServerNode findNode; - Rm_NameServerNode *matchingNode = NULL; - int32_t retVal = RM_SERVICE_APPROVED_AND_COMPLETED; - - /* Copy the name to find into the find node structure */ - strcpy(findNode.name, resourceInfo->nsName); - - matchingNode = RB_FIND(_Rm_NameServerTree, rmInst->nameServer, &findNode); + Rm_NameServerNode findNode; + Rm_NameServerNode *matchingNode; + int32_t retVal = RM_SERVICE_ERROR_NAMESERVER_ERROR_NAME_DOES_NOT_EXIST; - if (matchingNode) - { - /* Remove the name from the NameServer */ - RB_REMOVE(_Rm_NameServerTree, rmInst->nameServer, matchingNode); - Rm_freeNameServerNode(matchingNode); - } - else - { - retVal = RM_SERVICE_ERROR_NAMESERVER_ERROR_NAME_DOES_NOT_EXIST; - } + memset((void *)&findNode, 0, sizeof(Rm_NameServerNode)); + strcpy(findNode.objName, objCfg->nodeCfg.objName); + if (matchingNode = RB_FIND(_Rm_NameServerTree, objCfg->nameServerTree, &findNode)) { + /* Remove from NameServer */ + RB_REMOVE(_Rm_NameServerTree, objCfg->nameServerTree, matchingNode); + Rm_nameServerFreeNode(matchingNode); + + retVal = RM_SERVICE_APPROVED_AND_COMPLETED; + } return(retVal); } -void Rm_nsPrintObjects(Rm_Inst *rmInst) +void Rm_nameServerPrintObjects(Rm_NameServerTree *nameServerTree) { Rm_NameServerNode *node; - RB_FOREACH(node, _Rm_NameServerTree, rmInst->nameServer) - { - Rm_osalLog("Name: %s resourceName: %s base: %d length: %d\n", node->name, node->resourceName, - node->base, node->length); + RB_FOREACH(node, _Rm_NameServerTree, nameServerTree) { + Rm_osalLog("Name: %s resourceName: %s base: %d length: %d\n", node->objName, node->resourceName, + node->resourceBase, node->resourceLength); } } -void Rm_nsInit(Rm_Inst *rmInst) +Rm_NameServerTree *Rm_nameServerInit(void) { Rm_NameServerTree *rootEntry = NULL; - /* Create the NameServer root entry and initialize it */ rootEntry = Rm_osalMalloc(sizeof(Rm_NameServerTree)); RB_INIT(rootEntry); - rmInst->nameServer = (void *)rootEntry; + return(rootEntry); } diff --git a/src/rm_policy.c b/src/rm_policy.c index 8e5c156..9b3022b 100644 --- a/src/rm_policy.c +++ b/src/rm_policy.c @@ -2,7 +2,7 @@ * @file rmpolicy.c * * @brief - * This is the Resource Manager Policy source. + * Resource Manager Policy source. * * \par * ============================================================================ @@ -62,19 +62,19 @@ #include /********************************************************************** - ************************** Globals *********************************** + *********************** Policy Globals ******************************* **********************************************************************/ char Rm_policyAllInstances[] = "*"; /********************************************************************** - ************ Red-Black BBST Tree Valid Instance Functions ************ + *************** Policy Valid Instance Tree Functions ***************** **********************************************************************/ -Rm_ValidInstNode *Rm_newValidInstNode(char *instName) +Rm_PolicyValidInstNode *Rm_policyNewValidInstNode(char *instName) { - Rm_ValidInstNode *newNode = NULL; + Rm_PolicyValidInstNode *newNode = NULL; - newNode = Rm_osalMalloc(sizeof(Rm_ValidInstNode)); + newNode = Rm_osalMalloc(sizeof(Rm_PolicyValidInstNode)); strcpy(newNode->name, instName); newNode->allocRefCount = 0; @@ -83,51 +83,35 @@ Rm_ValidInstNode *Rm_newValidInstNode(char *instName) return(newNode); } -void Rm_freeValidInstNode(Rm_ValidInstNode *node) +void Rm_policyFreeValidInstNode(Rm_PolicyValidInstNode *node) { if (node->allocRefCount == 0) { - Rm_osalFree((void *)node, sizeof(Rm_ValidInstNode)); + Rm_osalFree((void *)node, sizeof(Rm_PolicyValidInstNode)); } } -/* Prototype for tree node comparison function - * element1 < element2 --> return < 0 - * element1 = element2 --> return 0 - * element1 > element2 --> return > 0 */ -int Rm_ValidInstNodeCompare(Rm_ValidInstNode *element1, Rm_ValidInstNode *element2) +int Rm_policyValidInstNodeCompare(Rm_PolicyValidInstNode *node1, Rm_PolicyValidInstNode *node2) { - return(strcmp(element1->name, element2->name)); + return(strcmp(node1->name, node2->name)); } -/* Generate the red-black tree manipulation functions */ -RB_GENERATE(_Rm_ValidInstTree, _Rm_ValidInstNode, linkage, Rm_ValidInstNodeCompare); +/* Generate the valid instance tree manipulation functions */ +RB_GENERATE(_Rm_PolicyValidInstTree, _Rm_PolicyValidInstNode, linkage, Rm_policyValidInstNodeCompare); /********************************************************************** - ********************** Internal Functions **************************** + ******************** Local Policy Functions ************************** **********************************************************************/ -int32_t Rm_policyCheckInstances(Rm_ValidInstTree *root, +int32_t Rm_policyCheckInstances(Rm_PolicyValidInstTree *validInstTree, Rm_PolicyPermission *permissionsList) { - Rm_PolicyPermission *permission = permissionsList; - bool instNameMatch = FALSE; - - while (permission) { - if (strcmp(permission->instName, Rm_policyAllInstances) == 0) { - instNameMatch = TRUE; - } - else if (Rm_policyGetValidInstNode(root, permission->instName)) { - instNameMatch = TRUE; - } - - if (!instNameMatch) { + while (permissionsList) { + if (strcmp(permissionsList->instName, Rm_policyAllInstances) && + (!Rm_policyGetValidInstNode(validInstTree, permissionsList->instName))) { return(RM_INIT_ERROR_POLICY_UNKNOWN_INSTANCE); } - - permission = permission->nextPermission; - instNameMatch = FALSE; + permissionsList = permissionsList->nextPermission; } - return(RM_INIT_OK); } @@ -258,7 +242,7 @@ Rm_PolicyPermission *Rm_policyParseSubPermission(char *permStrStart, char *permS (*permStrPtr == RM_POLICY_PERM_INIT_UPPER)) { newPerm = startPerm; while (newPerm) { - RM_POLICY_SET_PERM(newPerm->permissionBits, RM_POLICY_PERM_INIT_SHIFT, 1); + RM_policy_SET_PERM(newPerm->permissionBits, RM_POLICY_PERM_INIT_SHIFT, 1); newPerm = newPerm->nextPermission; } } @@ -266,7 +250,7 @@ Rm_PolicyPermission *Rm_policyParseSubPermission(char *permStrStart, char *permS (*permStrPtr == RM_POLICY_PERM_USE_UPPER)) { newPerm = startPerm; while (newPerm) { - RM_POLICY_SET_PERM(newPerm->permissionBits, RM_POLICY_PERM_USE_SHIFT, 1); + RM_policy_SET_PERM(newPerm->permissionBits, RM_POLICY_PERM_USE_SHIFT, 1); newPerm = newPerm->nextPermission; } } @@ -274,7 +258,7 @@ Rm_PolicyPermission *Rm_policyParseSubPermission(char *permStrStart, char *permS (*permStrPtr == RM_POLICY_PERM_EXCLUSIVE_UPPER)) { newPerm = startPerm; while (newPerm) { - RM_POLICY_SET_PERM(newPerm->permissionBits, RM_POLICY_PERM_EXCLUSIVE_SHIFT, 1); + RM_policy_SET_PERM(newPerm->permissionBits, RM_POLICY_PERM_EXCLUSIVE_SHIFT, 1); newPerm = newPerm->nextPermission; } } @@ -282,7 +266,7 @@ Rm_PolicyPermission *Rm_policyParseSubPermission(char *permStrStart, char *permS (*permStrPtr == RM_POLICY_PERM_SHARED_LINUX_UPPER)) { newPerm = startPerm; while (newPerm) { - RM_POLICY_SET_PERM(newPerm->permissionBits, RM_POLICY_PERM_SHARED_LINUX_SHIFT, 1); + RM_policy_SET_PERM(newPerm->permissionBits, RM_POLICY_PERM_SHARED_LINUX_SHIFT, 1); newPerm = newPerm->nextPermission; } } @@ -357,7 +341,7 @@ Rm_PolicyPermission *Rm_policyParseSubPermission(char *permStrStart, char *permS (*permStrPtr == RM_POLICY_PERM_INIT_UPPER)) { newPerm = startPerm; while (newPerm) { - RM_POLICY_SET_PERM(newPerm->permissionBits, RM_POLICY_PERM_INIT_SHIFT, 1); + RM_policy_SET_PERM(newPerm->permissionBits, RM_POLICY_PERM_INIT_SHIFT, 1); newPerm = newPerm->nextPermission; } } @@ -365,7 +349,7 @@ Rm_PolicyPermission *Rm_policyParseSubPermission(char *permStrStart, char *permS (*permStrPtr == RM_POLICY_PERM_USE_UPPER)) { newPerm = startPerm; while (newPerm) { - RM_POLICY_SET_PERM(newPerm->permissionBits, RM_POLICY_PERM_USE_SHIFT, 1); + RM_policy_SET_PERM(newPerm->permissionBits, RM_POLICY_PERM_USE_SHIFT, 1); newPerm = newPerm->nextPermission; } } @@ -373,7 +357,7 @@ Rm_PolicyPermission *Rm_policyParseSubPermission(char *permStrStart, char *permS (*permStrPtr == RM_POLICY_PERM_EXCLUSIVE_UPPER)) { newPerm = startPerm; while (newPerm) { - RM_POLICY_SET_PERM(newPerm->permissionBits, RM_POLICY_PERM_EXCLUSIVE_SHIFT, 1); + RM_policy_SET_PERM(newPerm->permissionBits, RM_POLICY_PERM_EXCLUSIVE_SHIFT, 1); newPerm = newPerm->nextPermission; } } @@ -381,7 +365,7 @@ Rm_PolicyPermission *Rm_policyParseSubPermission(char *permStrStart, char *permS (*permStrPtr == RM_POLICY_PERM_SHARED_LINUX_UPPER)) { newPerm = startPerm; while (newPerm) { - RM_POLICY_SET_PERM(newPerm->permissionBits, RM_POLICY_PERM_SHARED_LINUX_SHIFT, 1); + RM_policy_SET_PERM(newPerm->permissionBits, RM_POLICY_PERM_SHARED_LINUX_SHIFT, 1); newPerm = newPerm->nextPermission; } } @@ -482,7 +466,7 @@ Rm_PolicyPermission *Rm_policyGetAssignmentPermissions(Rm_PolicyAssignment *assi return(startPerm); } -int32_t Rm_policyValidateAssignmentPermissions(Rm_ValidInstTree *root, +int32_t Rm_policyValidateAssignmentPermissions(Rm_PolicyValidInstTree *root, Rm_PolicyAssignment *assignmentList) { Rm_PolicyAssignment *assignment = assignmentList; @@ -508,41 +492,29 @@ int32_t Rm_policyValidateAssignmentPermissions(Rm_ValidInstTree *root, return (RM_INIT_OK); } -void Rm_policyIncrementValidInstAllocationCount(void *validInstNameNode) -{ - Rm_ValidInstNode *node = (Rm_ValidInstNode *)validInstNameNode; - - node->allocRefCount++; -} - -void Rm_policyDecrementValidInstAllocationCount(void *validInstNameNode) -{ - Rm_ValidInstNode *node = (Rm_ValidInstNode *)validInstNameNode; - - node->allocRefCount--; -} +/********************************************************************** + ************************ Internal Policy APIs ************************ + **********************************************************************/ -void *Rm_policyGetValidInstNode(void *validInstTree, char *instName) +Rm_PolicyValidInstNode *Rm_policyGetValidInstNode(Rm_PolicyValidInstTree *validInstTree, char *instName) { - Rm_ValidInstTree *root = (Rm_ValidInstTree *)validInstTree; - Rm_ValidInstNode findNode; + Rm_PolicyValidInstNode findNode; - memset((void *)&findNode, 0, sizeof(Rm_ValidInstNode)); + memset((void *)&findNode, 0, sizeof(Rm_PolicyValidInstNode)); strcpy(findNode.name, instName); - return (RB_FIND(_Rm_ValidInstTree, root, &findNode)); + return (RB_FIND(_Rm_PolicyValidInstTree, validInstTree, &findNode)); } -char *Rm_policyGetValidInstNodeName(void *validInstNode) +Rm_PolicyValidInstNode *Rm_policyGetLinuxInstNode(Rm_PolicyValidInstTree *validInstTree) { - Rm_ValidInstNode *node = validInstNode; + char linuxName[] = RM_ALLOCATED_TO_LINUX; - return (node->name); + return (Rm_policyGetValidInstNode(validInstTree, linuxName)); } bool Rm_policyCheckPrivilege(Rm_PolicyCheckCfg *privilegeCfg, int32_t *result) { - Rm_ValidInstNode *instNode = (Rm_ValidInstNode *)privilegeCfg->validInstNode; int32_t propertyOffset; const char *propertyName; int32_t propertyLen; @@ -556,7 +528,7 @@ bool Rm_policyCheckPrivilege(Rm_PolicyCheckCfg *privilegeCfg, int32_t *result) bool foundInstance; /* Get the resource's assignments */ - propertyOffset = fdt_first_property_offset(privilegeCfg->policyDtb, privilegeCfg->resourcePolicy); + propertyOffset = fdt_first_property_offset(privilegeCfg->policyDtb, privilegeCfg->resourceOffset); if (propertyOffset > RM_DTB_UTIL_STARTING_NODE_OFFSET) { while (propertyOffset > RM_DTB_UTIL_STARTING_NODE_OFFSET) { propertyData = fdt_getprop_by_offset(privilegeCfg->policyDtb, propertyOffset, &propertyName, &propertyLen); @@ -581,27 +553,27 @@ bool Rm_policyCheckPrivilege(Rm_PolicyCheckCfg *privilegeCfg, int32_t *result) permission = permissionStart = Rm_policyGetAssignmentPermissions(assignment, result); while (permission) { - if ((strcmp(permission->instName, instNode->name) == 0) || + if ((strcmp(permission->instName, privilegeCfg->validInstNode->name) == 0) || (strcmp(permission->instName, Rm_policyAllInstances) == 0)) { foundInstance = TRUE; /* Check instance's permissions */ if (privilegeCfg->type == Rm_policyCheck_INIT) { - if (!RM_POLICY_GET_PERM(permission->permissionBits, RM_POLICY_PERM_INIT_SHIFT)) { + if (!RM_policy_GET_PERM(permission->permissionBits, RM_POLICY_PERM_INIT_SHIFT)) { Rm_policyFreeAssignmentPermissions(permissionStart); Rm_policyFreeAssignments(assignmentStart); return(FALSE); } } else if (privilegeCfg->type == Rm_policyCheck_USE) { - if (!RM_POLICY_GET_PERM(permission->permissionBits, RM_POLICY_PERM_USE_SHIFT)) { + if (!RM_policy_GET_PERM(permission->permissionBits, RM_POLICY_PERM_USE_SHIFT)) { Rm_policyFreeAssignmentPermissions(permissionStart); Rm_policyFreeAssignments(assignmentStart); return(FALSE); } } else if (privilegeCfg->type == Rm_policyCheck_EXCLUSIVE) { - if (!RM_POLICY_GET_PERM(permission->permissionBits, RM_POLICY_PERM_EXCLUSIVE_SHIFT)) { + if (!RM_policy_GET_PERM(permission->permissionBits, RM_POLICY_PERM_EXCLUSIVE_SHIFT)) { Rm_policyFreeAssignmentPermissions(permissionStart); Rm_policyFreeAssignments(assignmentStart); return(FALSE); @@ -629,12 +601,11 @@ bool Rm_policyCheckPrivilege(Rm_PolicyCheckCfg *privilegeCfg, int32_t *result) return(TRUE); } -uint32_t Rm_policyGetResourceBase(void *policyDtb, void *validInstNode, - int32_t resourcePolicy, uint32_t allocType, +uint32_t Rm_policyGetResourceBase(void *policyDtb, Rm_PolicyValidInstNode *validInstNode, + int32_t resourceOffset, uint32_t allocType, int32_t *result) { - Rm_ValidInstNode *instNode = (Rm_ValidInstNode *)validInstNode; int32_t propertyOffset; const char *propertyName; int32_t propertyLen; @@ -645,7 +616,7 @@ uint32_t Rm_policyGetResourceBase(void *policyDtb, void *validInstNode, Rm_PolicyPermission *permissionStart = NULL; uint32_t resourceBase = 0; - propertyOffset = fdt_first_property_offset(policyDtb, resourcePolicy); + propertyOffset = fdt_first_property_offset(policyDtb, resourceOffset); if (propertyOffset > RM_DTB_UTIL_STARTING_NODE_OFFSET) { while (propertyOffset > RM_DTB_UTIL_STARTING_NODE_OFFSET) { propertyData = fdt_getprop_by_offset(policyDtb, propertyOffset, &propertyName, &propertyLen); @@ -662,20 +633,18 @@ uint32_t Rm_policyGetResourceBase(void *policyDtb, void *validInstNode, while (assignment) { permission = permissionStart = Rm_policyGetAssignmentPermissions(assignment, result); while (permission) { - if ((strcmp(permission->instName, instNode->name) == 0) || + if ((strcmp(permission->instName, validInstNode->name) == 0) || (strcmp(permission->instName, Rm_policyAllInstances) == 0)) { /* Check instance's permissions */ - if (RM_POLICY_GET_PERM(allocType, RM_POLICY_PERM_INIT_SHIFT)) { - if (RM_POLICY_GET_PERM(permission->permissionBits, RM_POLICY_PERM_INIT_SHIFT)) { - resourceBase = assignment->resourceBase; - break; - } + if (RM_policy_GET_PERM(allocType, RM_POLICY_PERM_INIT_SHIFT) && + RM_policy_GET_PERM(permission->permissionBits, RM_POLICY_PERM_INIT_SHIFT)) { + resourceBase = assignment->resourceBase; + break; } - else if (RM_POLICY_GET_PERM(allocType, RM_POLICY_PERM_USE_SHIFT)) { - if (RM_POLICY_GET_PERM(permission->permissionBits, RM_POLICY_PERM_USE_SHIFT)) { - resourceBase = assignment->resourceBase; - break; - } + else if (RM_policy_GET_PERM(allocType, RM_POLICY_PERM_USE_SHIFT) && + RM_policy_GET_PERM(permission->permissionBits, RM_POLICY_PERM_USE_SHIFT)) { + resourceBase = assignment->resourceBase; + break; } } permission = permission->nextPermission; @@ -698,7 +667,7 @@ uint32_t Rm_policyGetResourceBase(void *policyDtb, void *validInstNode, return(resourceBase); } -uint32_t Rm_policyGetResourceAlignment(void *policyDtb, int32_t resourcePolicy) +uint32_t Rm_policyGetResourceAlignment(void *policyDtb, int32_t resourceOffset) { int32_t propertyOffset; const char *propertyName; @@ -707,7 +676,7 @@ uint32_t Rm_policyGetResourceAlignment(void *policyDtb, int32_t resourcePolicy) Rm_ResourceValue *alignmentList; uint32_t resourceAlignment = 0; - propertyOffset = fdt_first_property_offset(policyDtb, resourcePolicy); + propertyOffset = fdt_first_property_offset(policyDtb, resourceOffset); if (propertyOffset > RM_DTB_UTIL_STARTING_NODE_OFFSET) { while (propertyOffset > RM_DTB_UTIL_STARTING_NODE_OFFSET) { propertyData = fdt_getprop_by_offset(policyDtb, propertyOffset, &propertyName, &propertyLen); @@ -722,7 +691,7 @@ uint32_t Rm_policyGetResourceAlignment(void *policyDtb, int32_t resourcePolicy) return(resourceAlignment); } -int32_t Rm_policyGetResourcePolicy(void *policyDtb, char *resourceName) +int32_t Rm_policyGetResourceOffset(void *policyDtb, char *resourceName) { int32_t nodeOffset; int32_t depth; @@ -745,15 +714,9 @@ int32_t Rm_policyGetResourcePolicy(void *policyDtb, char *resourceName) return(nodeOffset); } -void *Rm_policyGetLinuxInstNode(void * validInstTree) -{ - char linuxName[] = RM_ALLOCATED_TO_LINUX; - - return (Rm_policyGetValidInstNode(validInstTree, linuxName)); -} - -int32_t Rm_policyValidatePolicyResourceNames(Rm_Inst *rmInst, void *policyDtb) +int32_t Rm_policyValidatePolicyResourceNames(void *allocatorList, void *policyDtb) { + Rm_Allocator *allocator = (Rm_Allocator *)allocatorList; int32_t nodeOffset; int32_t depth; const char *nodeName; @@ -769,7 +732,7 @@ int32_t Rm_policyValidatePolicyResourceNames(Rm_Inst *rmInst, void *policyDtb) nodeOffset = fdt_next_node(policyDtb, nodeOffset, &depth); nodeName = fdt_get_name(policyDtb, nodeOffset, NULL); if (fdt_first_property_offset(policyDtb, nodeOffset) > RM_DTB_UTIL_STARTING_NODE_OFFSET) { - if (Rm_allocatorFind(rmInst, (char *)nodeName) == NULL) { + if (Rm_allocatorFind(allocator, (char *)nodeName) == NULL) { /* No allocator tied to resource name */ return(RM_INIT_ERROR_POLICY_UNKNOWN_RESOURCE); } @@ -779,7 +742,7 @@ int32_t Rm_policyValidatePolicyResourceNames(Rm_Inst *rmInst, void *policyDtb) } /* TODO: ADD ABILITY TO RETURN THE SYNTAX ERROR LOCATION */ -int32_t Rm_policyValidatePolicy(Rm_Inst *rmInst, void *policyDtb) +int32_t Rm_policyValidatePolicy(void *policyDtb, Rm_PolicyValidInstTree *validInstTree) { int32_t nodeOffset; int32_t propertyOffset; @@ -805,8 +768,7 @@ int32_t Rm_policyValidatePolicy(Rm_Inst *rmInst, void *policyDtb) if (Rm_policyGetPropertyType(propertyName) == Rm_policyPropType_ASSIGNMENTS) { assignmentList = Rm_policyExtractAssignments(propertyData, propertyLen); - if ((result = Rm_policyValidateAssignmentPermissions((Rm_ValidInstTree *) rmInst->validInstances, - assignmentList)) != RM_INIT_OK) { + if ((result = Rm_policyValidateAssignmentPermissions(validInstTree, assignmentList)) != RM_INIT_OK) { Rm_policyFreeAssignments(assignmentList); return(result); } @@ -818,7 +780,7 @@ int32_t Rm_policyValidatePolicy(Rm_Inst *rmInst, void *policyDtb) return(RM_INIT_OK); } -void *Rm_policyCreateValidInstTree(void *policyDtb, int32_t *result) +Rm_PolicyValidInstTree *Rm_policyCreateValidInstTree(void *policyDtb, int32_t *result) { int32_t validInstOffset; const char *validInstName; @@ -826,8 +788,8 @@ void *Rm_policyCreateValidInstTree(void *policyDtb, int32_t *result) const void *validInstData; Rm_PolicyPropType propertyType; Rm_PolicyValidInst *validInstList; - Rm_ValidInstTree *rootEntry = NULL; - Rm_ValidInstNode *newNode; + Rm_PolicyValidInstTree *rootEntry = NULL; + Rm_PolicyValidInstNode *newNode; char linuxName[] = RM_ALLOCATED_TO_LINUX; /* Valid instance list must be first and only property in the root node of @@ -850,21 +812,32 @@ void *Rm_policyCreateValidInstTree(void *policyDtb, int32_t *result) validInstList = Rm_policyExtractValidInstances(validInstData, validInstLen); /* Create the tree */ - rootEntry = Rm_osalMalloc(sizeof(Rm_ValidInstTree)); + rootEntry = Rm_osalMalloc(sizeof(Rm_PolicyValidInstTree)); RB_INIT(rootEntry); while (validInstList) { - newNode = Rm_newValidInstNode(validInstList->instName); - RB_INSERT(_Rm_ValidInstTree, rootEntry, newNode); + newNode = Rm_policyNewValidInstNode(validInstList->instName); + RB_INSERT(_Rm_PolicyValidInstTree, rootEntry, newNode); validInstList = validInstList->nextValidInst; } /* Add the Linux kernel node */ - newNode = Rm_newValidInstNode(linuxName); - RB_INSERT(_Rm_ValidInstTree, rootEntry, newNode); + newNode = Rm_policyNewValidInstNode(linuxName); + RB_INSERT(_Rm_PolicyValidInstTree, rootEntry, newNode); *result = RM_INIT_OK; - return ((void *)rootEntry); + return (rootEntry); +} + +void Rm_policyFreeValidInstTree(Rm_PolicyValidInstTree *validInstTree) +{ + Rm_PolicyValidInstNode *node; + + RB_FOREACH(node, _Rm_PolicyValidInstTree, validInstTree) { + RB_REMOVE(_Rm_PolicyValidInstTree, validInstTree, node); + Rm_policyFreeValidInstNode(node); + } + Rm_osalFree((void *)validInstTree, sizeof(Rm_PolicyValidInstTree)); } diff --git a/src/rm_services.c b/src/rm_services.c index 81027c1..b1ff067 100644 --- a/src/rm_services.c +++ b/src/rm_services.c @@ -46,7 +46,9 @@ #include /* RM internal API includes */ +#include #include +#include /* RM OSAL layer */ #include @@ -85,14 +87,14 @@ void Rm_serviceHandler (void *rmHandle, Rm_ServiceReqInfo *serviceRequest, { /* Transfer request information into the transaction */ transaction->type = serviceRequest->type; - strcpy(transaction->serviceSrcInstName, rmInst->name); + strcpy(transaction->serviceSrcInstName, rmInst->instName); transaction->callback.serviceCallback = serviceRequest->callback.serviceCallback; transaction->state = RM_SERVICE_PROCESSING; strcpy(&(transaction->resourceInfo.name)[0], serviceRequest->resourceName); transaction->resourceInfo.base = serviceRequest->resourceBase; transaction->resourceInfo.length = serviceRequest->resourceLength; transaction->resourceInfo.alignment = serviceRequest->resourceAlignment; - strcpy(&(transaction->resourceInfo.nsName)[0], serviceRequest->resourceNsName); + strcpy(transaction->resourceInfo.nameServerName, serviceRequest->resourceNsName); /* Pass the new transaction to the transaction processor */ Rm_transactionProcessor (rmInst, transaction); @@ -134,50 +136,73 @@ void Rm_serviceHandler (void *rmHandle, Rm_ServiceReqInfo *serviceRequest, return; } -/* This function is executed when a RM instance receives a response to one of its requests - * and the information in the request must be provided to the original requesting component */ -void Rm_serviceResponder (Rm_Inst *rmInst, Rm_Transaction *transaction) -{ - Rm_ServiceRespInfo serviceResponse; - - /* The responseTransaction will contain the resultant state details of - * the requestTransaction's service request */ - serviceResponse.serviceState = transaction->state; - /* Pass back the ID that was provided to the component when it requested - * the service */ - serviceResponse.serviceId = transaction->localId; - - /* Service was approved and service was an allocate request. The resource - * data is passed back to the component */ - if ((serviceResponse.serviceState == RM_SERVICE_APPROVED_AND_COMPLETED) && - ((transaction->type == Rm_service_RESOURCE_ALLOCATE_INIT) || - (transaction->type == Rm_service_RESOURCE_ALLOCATE_USE) || - (transaction->type == Rm_service_RESOURCE_GET_BY_NAME))) - { - strcpy(serviceResponse.resourceName, transaction->resourceInfo.name); - serviceResponse.resourceBase = transaction->resourceInfo.base; - serviceResponse.resourceLength = transaction->resourceInfo.length; - } - - /* Issue the callback to the requesting component with the response information */ - transaction->callback.serviceCallback(&serviceResponse); - - /* Delete the transaction from the transaction queue */ - Rm_transactionQueueDelete(rmInst, transaction->localId); - return; -} - /********************************************************************** ********************** Application visible APIs ********************** **********************************************************************/ -void Rm_preMainAllocService(Rm_PreMainAllocInfo *preMainAllocInfo, - Rm_ServiceRespInfo *serviceResponse) +void Rm_servicePreMainRequest(Rm_PreMainReqCfg *reqCfg, Rm_ServiceRespInfo *preMainResp) { + Rm_PreMainInst *preMainInst = (Rm_PreMainInst *)reqCfg->rmPreMainHandle; + Rm_PolicyCheckCfg privCheckCfg; + Rm_ServicePreMainReq *lastServiceReq; + + preMainResp->serviceState = RM_SERVICE_PROCESSING; + preMainResp->serviceId = 0; + + if ((reqCfg->request->type == Rm_service_RESOURCE_ALLOCATE_INIT) || + (reqCfg->request->type == Rm_service_RESOURCE_ALLOCATE_USE) || + (reqCfg->request->resourceBase == RM_RESOURCE_BASE_UNSPECIFIED)) { + /* Check request against startup policy */ + memset((void *)&privCheckCfg, 0, sizeof(Rm_PolicyCheckCfg)); + if (reqCfg->request->type == Rm_service_RESOURCE_ALLOCATE_INIT) { + privCheckCfg.type = Rm_policyCheck_INIT; + } + else { + privCheckCfg.type = Rm_policyCheck_USE; + } + privCheckCfg.policyDtb = preMainInst->startupDtb; + privCheckCfg.validInstNode = Rm_policyGetValidInstNode(preMainInst->validInstTree, + preMainInst->instName); + privCheckCfg.resourceOffset = Rm_policyGetResourceOffset(preMainInst->startupDtb, + reqCfg->request->resourceName); + privCheckCfg.resourceBase = reqCfg->request->resourceBase; + privCheckCfg.resourceLength = reqCfg->request->resourceLength; + + if (Rm_policyCheckPrivilege(&privCheckCfg, &preMainResp->serviceState)) { + preMainResp->serviceState = RM_SERVICE_APPROVED_AND_COMPLETED; + } + else if (preMainResp->serviceState == RM_SERVICE_PROCESSING) { + /* Privilege check returned FALSE without error */ + preMainResp->serviceState = RM_SERVICE_DENIED_POLICY_DENIED_PREMAIN_ALLOCATION; + } + } + else { + preMainResp->serviceState = RM_SERVICE_DENIED_INVALID_PREMAIN_REQUEST; + } + + /* Store the request for validation after post-main instance + * transports have been established */ + if (preMainResp->serviceState == RM_SERVICE_APPROVED_AND_COMPLETED) { + /* Store the request for validation after all instances have been setup post-main */ + lastServiceReq = preMainInst->preMainReqList; + while(lastServiceReq) { + lastServiceReq = lastServiceReq->nextPreMainReq; + } + lastServiceReq = (Rm_ServicePreMainReq *) Rm_osalMalloc (sizeof(Rm_ServicePreMainReq)); + lastServiceReq->nextPreMainReq = NULL; + lastServiceReq->preMainReq = (Rm_ServiceReqInfo *) Rm_osalMalloc(sizeof(Rm_ServiceReqInfo)); + memcpy((void *)lastServiceReq->preMainReq, (void *)reqCfg->request, sizeof(Rm_ServiceReqInfo)); + + /* Fill out response */ + preMainResp->resourceBase = reqCfg->request->resourceBase; + preMainResp->resourceLength = reqCfg->request->resourceLength; + strcpy(preMainResp->resourceName, reqCfg->request->resourceName); + preMainResp->serviceId = ++preMainInst->requestCount; + } } -Rm_ServicePort *Rm_getServicePort(Rm_Handle rmHandle) +Rm_ServicePort *Rm_serviceGetPort(Rm_Handle rmHandle) { Rm_ServicePort *newServicePort = NULL; diff --git a/src/rm_transport.c b/src/rm_transport.c index 8d203bd..de5a60b 100644 --- a/src/rm_transport.c +++ b/src/rm_transport.c @@ -274,7 +274,7 @@ Rm_Packet *Rm_transportCreateResourceReqPkt(Rm_Inst *rmInst, Rm_TransportNode *d resourceReqPkt->resourceReqType = Rm_resReqPktType_GET_NAMED; } /* Pass along the packet source and service source information */ - strcpy(resourceReqPkt->pktSrcInstName, rmInst->name); + strcpy(resourceReqPkt->pktSrcInstName, rmInst->instName); strcpy(resourceReqPkt->serviceSrcInstName, transaction->serviceSrcInstName); /* Copy the resource data */ memcpy ((void *)&(resourceReqPkt->resourceInfo), (void *)&(transaction->resourceInfo), @@ -360,7 +360,7 @@ Rm_Packet *Rm_transportCreateNsRequestPkt(Rm_Inst *rmInst, Rm_TransportNode *dst nsReqPkt->nsRequestType = Rm_nsReqPktType_UNMAP_RESOURCE; } /* Pass along the packet source and service source information */ - strcpy(nsReqPkt->pktSrcInstName, rmInst->name); + strcpy(nsReqPkt->pktSrcInstName, rmInst->instName); strcpy(nsReqPkt->serviceSrcInstName, transaction->serviceSrcInstName); /* Copy the NameServer request data */ memcpy ((void *)&(nsReqPkt->resourceInfo), (void *)&(transaction->resourceInfo), -- 2.39.2