]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/rm-lld.git/blobdiff - src/rm_services.c
Minor updates
[keystone-rtos/rm-lld.git] / src / rm_services.c
index 117d52ec340cf20f14e12b3cb03a5c6aedc261b3..31b8f3ccdc72f7afc191b76056f252b95200834b 100644 (file)
@@ -1,12 +1,12 @@
 /**
- *   @file  rmservices.c
+ *   @file  rm_services.c
  *
  *   @brief   
  *      This is the Resource Manager services source.
  *
  *  \par
  *  ============================================================================
- *  @n   (C) Copyright 2012, Texas Instruments, Inc.
+ *  @n   (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 
@@ -39,8 +39,8 @@
  *  \par
 */
 
-/* RM Types */
-#include <ti/drv/rm/rm_types.h>
+/* Standard includes */
+#include <string.h>
 
 /* RM external API includes */
 #include <ti/drv/rm/rm_services.h>
 #include <rm_osal.h>
 
 /**********************************************************************
- ********************** Internal Functions ****************************
+ ********************** Application visible APIs **********************
  **********************************************************************/
 
-void Rm_serviceHandler (void *rmHandle, Rm_ServiceReqInfo *serviceRequest,
+/* FUNCTION PURPOSE: Handles application component service requests
+ ***********************************************************************
+ * DESCRIPTION: Receives service requests from application components
+ *              and routes them to the transaction processor.  If
+ *              the service can be handled immediately the response
+ *              will be provided in the service response.  If the
+ *              service requires a blocking operation the handler
+ *              will provide a service ID back to the application.
+ *              The response will be sent at a later time via the
+ *              application supplied callback function.
+ */
+void Rm_serviceHandler (void *rmHandle, const Rm_ServiceReqInfo *serviceRequest,
                         Rm_ServiceRespInfo *serviceResponse)
 {
-    Rm_Inst *rmInst = (Rm_Inst *)rmHandle;
-    uint32_t transactionId = 0;
-    Rm_Transaction *transaction;
-    Rm_TransactionReceipt receipt;
-    void *key;
-
-    /* Prevent another component using the same instance from wiping out the current
-     * service request */
-    key = Rm_osalCsEnter();
-
-    /* Make sure serviceType is valid and that a callback function has been provided */
-    if ((serviceRequest->type < Rm_service_FIRST) || 
-        (serviceRequest->type > Rm_service_LAST))
-    {
-        serviceResponse->serviceResult = RM_SERVICE_ERROR_INVALID_SERVICE_TYPE;
-        Rm_osalCsExit(key);
+    Rm_Inst             *rmInst = (Rm_Inst *)rmHandle;
+    Rm_Transaction      *transaction;
+
+    if (rmInst->isLocked) {
+        serviceResponse->serviceState = RM_SERVICE_DENIED_RM_INSTANCE_LOCKED;
         return;
     }
-    else if (serviceRequest->callback.serviceCallback == NULL)
-    {
-        /* The RM Client and Client Delegate use blocking transports to consult with a 
-         * high-level RM agent prior to providing a response to the component.  It is 
-         * assumed the component's cannot block.  Therefore, all responses must go
-         * through the callback function provided by the component.  Return an error 
-         * if the component does not provide a callback function. */
-        serviceResponse->serviceResult = RM_SERVICE_ERROR_CALLBACK_NOT_PROVIDED;
-        Rm_osalCsExit(key);
+
+    if (serviceRequest->callback.serviceCallback == NULL) {
+        serviceResponse->serviceState = RM_ERROR_CALLBACK_NOT_PROVIDED;
         return;
     }
 
-    /* Create an ID for this transaction.  The ID will be used for two purposes:
-     * 1) Matching responses from higher level RM agents to requests
-     * 2) Provided to the component that requested the service so that it can match its
-     *    request with the response it receives via its callback function it provided */
-    transactionId = Rm_transactionGetSequenceNum(rmInst);
-    /* Create a new transaction */
-    transaction = Rm_transactionQueueAdd(rmInst, transactionId);
-
-    if (transaction == NULL)
-    {
-        /* Failed to create a new transaction */
-        serviceResponse->serviceResult = RM_SERVICE_ERROR_TRANSACTION_FAILED_TO_ALLOCATE;
+    if (serviceRequest->type >= Rm_service_LAST) {
+        serviceResponse->serviceState = RM_ERROR_INVALID_SERVICE_TYPE;
+        return;
     }
-    else
-    {
-        /* Clear the receipt */
-        memset((void *) &receipt, 0, sizeof(Rm_TransactionReceipt));
-
-        /* Transfer request information into the transaction */
+    
+    transaction = rmTransactionQueueAdd(rmInst);
+    if (transaction) {
         transaction->type = serviceRequest->type;
-        strcpy(transaction->sourceInstName, rmInst->name);
+        strncpy(transaction->serviceSrcInstName, rmInst->instName, RM_NAME_MAX_CHARS);
         transaction->callback.serviceCallback = serviceRequest->callback.serviceCallback;
-        transaction->state = Rm_transactionState_PROCESSING;
-        transaction->details = RM_SERVICE_PROCESSING;
-        strcpy(&(transaction->resourceInfo.name)[0], serviceRequest->resourceName);
+        transaction->state = RM_SERVICE_PROCESSING;
+        if (serviceRequest->resourceName) {
+            strncpy(transaction->resourceInfo.name, serviceRequest->resourceName, RM_NAME_MAX_CHARS);
+        }
         transaction->resourceInfo.base = serviceRequest->resourceBase;
-        transaction->resourceInfo.range = serviceRequest->resourceRange;
+        transaction->resourceInfo.length = serviceRequest->resourceLength;
         transaction->resourceInfo.alignment = serviceRequest->resourceAlignment;
-        strcpy(&(transaction->resourceInfo.nsName)[0], serviceRequest->resourceNsName);
-
-        /* Pass the new transaction to the transaction processor */
-        Rm_transactionProcessor (rmInst, transaction, &receipt);
-
-        /* Copy transaction receipt information into the response info fields for the 
-         * component based on the result of the transaction.  Denied service requests
-         * will have only a valid serviceResult field */
-        serviceResponse->serviceResult = receipt.serviceResult;
-
-        /* Service was approved and service was an allocate request the resource
-         * data is passed back to the component */
-        if ((serviceResponse->serviceResult == RM_SERVICE_APPROVED) &&
-            ((transaction->type == Rm_service_RESOURCE_ALLOCATE) ||
-             (transaction->type == Rm_service_RESOURCE_BLOCK_ALLOCATE) ||
-             (transaction->type == Rm_service_RESOURCE_ALLOCATE_BY_NAME)))
-        {
-            serviceResponse->resourceBase = receipt.resourceBase;
-            serviceResponse->resourceRange = receipt.resourceRange;
-
-            /* Delete the transaction since a response was received immediately */
-            Rm_transactionQueueDelete(rmInst, transaction->id);
-        }
-        else if (serviceResponse->serviceResult == RM_SERVICE_PROCESSING)
-        {
-            /* The service is still being processed.  Provide the transaction ID
-             * back to the component so that it can sort service responses received
-             * via the provided callback function */
-            serviceResponse->requestId = receipt.serviceId;
-        }
-        else if (serviceResponse->serviceResult <= RM_SERVICE_ERROR_BASE)
-        {
-            /* Delete the transaction since there was an error processing it. */
-            Rm_transactionQueueDelete(rmInst, transaction->id);
+        if (serviceRequest->resourceNsName) {
+            strncpy(transaction->resourceInfo.nameServerName, serviceRequest->resourceNsName, RM_NAME_MAX_CHARS);
         }
-    }
 
-    Rm_osalCsExit(key); 
-    return;
-}
+        rmTransactionProcessor (rmInst, transaction);
+        memset((void *)serviceResponse, 0, sizeof(Rm_ServiceRespInfo));
+        serviceResponse->serviceState = transaction->state;
+        if ((serviceResponse->serviceState == RM_SERVICE_PROCESSING) ||
+            (serviceResponse->serviceState == RM_SERVICE_APPROVED_STATIC)) {
+            /* Service still being processed.  Static requests will have their validation responses sent once
+             * all transports have been established.  Provide transaction ID back to component so it can sort 
+             * service responses received via callback function */
+            serviceResponse->serviceId = transaction->localId;
+        }
 
-/* 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 *responseTransaction,
-                          Rm_Transaction *requestTransaction, Rm_TransactionReceipt *receipt)
-{
-    Rm_ServiceRespInfo serviceResponse;
-
-    /* Populate the service response with the transaction response details
-     * for the component */
-    serviceResponse.serviceResult = responseTransaction->details;
-    /* Pass back the ID that was provided to the component when it requested
-     * the service */
-    serviceResponse.requestId = responseTransaction->id;
-
-    /* Service was approved and service was an allocate request.  The resource
-     * data is passed back to the component */
-    if ((serviceResponse.serviceResult == RM_SERVICE_APPROVED) &&
-        ((responseTransaction->type == Rm_service_RESOURCE_ALLOCATE) ||
-         (responseTransaction->type == Rm_service_RESOURCE_BLOCK_ALLOCATE) ||
-         (responseTransaction->type == Rm_service_RESOURCE_ALLOCATE_BY_NAME)))
-    {
-        serviceResponse.resourceBase = receipt->resourceBase;
-        serviceResponse.resourceRange = receipt->resourceRange;
-    }
+        if ((serviceResponse->serviceState == RM_SERVICE_APPROVED) ||
+            (serviceResponse->serviceState == RM_SERVICE_APPROVED_STATIC)) {
+            strncpy(serviceResponse->resourceName, transaction->resourceInfo.name, RM_NAME_MAX_CHARS);
+            serviceResponse->resourceBase = transaction->resourceInfo.base;
+            serviceResponse->resourceLength = transaction->resourceInfo.length;
+        }
 
-    /* Issue the callback to the requesting component with the response information */
-    if (requestTransaction != NULL)
-    {
-        /* The requestTransaction will be NULL if the request transaction is handled
-         * by the same RM instance it was created on.  Typically this applies to RM
-         * Client Delegate and RM Server instances.  In these cases the response
-         * transaction will be a copy of the request transaction, meaning it will contain
-         * the proper callback information */
-        requestTransaction->callback.serviceCallback(&serviceResponse);
-    }
-    else
-    {
-        responseTransaction->callback.serviceCallback(&serviceResponse);
+        /* Transactions still processing not deleted from queue.  Includes static transactions which will be 
+         * verified once all transports are up */
+        if ((serviceResponse->serviceState != RM_SERVICE_PROCESSING) &&
+            (serviceResponse->serviceState != RM_SERVICE_APPROVED_STATIC)) {
+            rmTransactionQueueDelete(rmInst, transaction->localId);
+        }
     }
-
-    /* Delete both transactions from the transaction queue */
-    Rm_transactionQueueDelete(rmInst,responseTransaction->id);
-    if (requestTransaction != NULL)
-    {
-        Rm_transactionQueueDelete(rmInst,requestTransaction->id);
+    else {
+        serviceResponse->serviceState = RM_ERROR_SERVICE_TRANS_NOT_CREATED;    
     }
-
-    /* Response to component completed */
-    receipt->serviceResult = RM_SERVICE_ACTION_OKAY;
     return;
 }
 
-/**********************************************************************
- ********************** Application visible APIs **********************
- **********************************************************************/
-
-void Rm_preMainAllocService(Rm_PreMainAllocInfo *preMainAllocInfo,
-                            Rm_ServiceRespInfo *serviceResponse)
+/* FUNCTION PURPOSE: Opens the RM instance service handle
+ ***********************************************************************
+ * DESCRIPTION: Returns the service handle for an RM instance.  Only
+ *              one service handle can be opened per instance.
+ */
+Rm_ServiceHandle *Rm_serviceOpenHandle(Rm_Handle rmHandle, int32_t *result)
 {
+    Rm_Inst          *rmInst = (Rm_Inst *)rmHandle;
+    Rm_ServiceHandle *newServiceHandle = NULL;
+
+    *result = RM_OK;
 
+    if (rmInst->serviceHandle == NULL) {
+        newServiceHandle = Rm_osalMalloc (sizeof(Rm_ServiceHandle));
+        if (newServiceHandle) {
+            newServiceHandle->rmHandle = rmHandle;
+            newServiceHandle->Rm_serviceHandler = Rm_serviceHandler;
+            rmInst->serviceHandle = newServiceHandle;
+        }
+        else {
+            *result = RM_ERROR_SERVICE_HANDLE_MEM_ALLOC_FAILED;
+        }
+    }
+    else {
+        *result = RM_ERROR_SERVICE_HANDLE_ALREADY_OPENED;
+    }
+    return (newServiceHandle);
 }
 
-Rm_ServicesPort *Rm_getServicePort(Rm_Handle rmHandle)
+/* FUNCTION PURPOSE: Closes the RM instance service handle
+ ***********************************************************************
+ * DESCRIPTION: Closes the service handle for an RM instance.
+ */
+int32_t Rm_serviceCloseHandle(Rm_ServiceHandle *rmServiceHandle)
 {
-    Rm_ServicesPort *newServicePort = NULL;
-    
-    /* Create a new service handle for the specified RM instance */
-    
-    /* Get memory for a new service port from local memory */
-    newServicePort = Rm_osalMalloc (sizeof(Rm_ServicesPort), false);
+    Rm_Inst *rmInst = (Rm_Inst *)rmServiceHandle->rmHandle;
+    int32_t  retVal = RM_OK;
 
-    /* Return NULL immediately if malloc returned NULL */
-    if (newServicePort == NULL)
-    {
-        return (newServicePort);
+    if (rmInst->serviceHandle) {
+        Rm_osalFree((void *)rmServiceHandle, sizeof(Rm_ServiceHandle));
+        rmInst->serviceHandle = NULL;
     }
-
-    newServicePort->rmHandle = rmHandle;
-    newServicePort->rmService = Rm_serviceHandler;
-
-    return (newServicePort);
+    else {
+        retVal = RM_ERROR_SERVICE_HANDLE_ALREADY_CLOSED;
+    }
+    return(retVal);
 }
 
-/**
-@}
-*/