예제 #1
0
/****************************************************************************
* DibBridgephy_deinit
****************************************************************************/
DIBSTATUS DibBridgeTargetDeinit(struct DibBridgeContext *pContext)
{
   DibDeAllocateLock(&pContext->DibTargetAccessLock);
   DibDeAllocateLock(&pContext->BridgeTargetCtx.IrqLock);

   return DIBSTATUS_SUCCESS;
}
void DibBridgeDeinitMsgQueue(struct DibBridgeContext *pContext)
{
   /** msg queue lock and event are freed uppon close */
   DibDeAllocateLock(&pContext->MsgQueueLock);
   DibDeAllocateEvent(&pContext->MsgQueueEvent);
   DIB_DEBUG(PORT_LOG, (CRB "DibBridgeDeinitMsgQueue!" CRA));
}
static void IntBridgeTargetModuleFreeStruct(struct DibBridgeContext *pContext)
{
   if(pContext)
   {
      /* Free IOCTL Lock */
      DibDeAllocateLock(&pContext->BridgeTargetCtx.IoctlLock);

      /* Free buffer for IOCTL request */
      if(pContext->BridgeTargetCtx.IoctlReq)
      {
         if(pContext->BridgeTargetCtx.IoctlReq->Buffer)
         {
            kfree(pContext->BridgeTargetCtx.IoctlReq->Buffer);
            pContext->BridgeTargetCtx.IoctlReq->Buffer = NULL;
         }

         /* Free ptr for IOCTL request */
         kfree(pContext->BridgeTargetCtx.IoctlReq);
         pContext->BridgeTargetCtx.IoctlReq = NULL;
      }

      /* Free context */
      DibBridgeTargetFreeBuf((uint8_t *)pContext, sizeof(*pContext));
   }
}
예제 #4
0
DIBSTATUS DibOpen(struct DibDriverContext **pContextAddr, enum DibBoardType BoardType, BOARD_HDL BoardHdl)
{
   DIBSTATUS status = DIBSTATUS_ERROR;

   struct DibDriverContext *pContext = (struct DibDriverContext *)DibMemAlloc(sizeof(struct DibDriverContext));

   if(pContext == NULL)
      return DIBSTATUS_ERROR;

   memset(pContext, 0, sizeof(struct DibDriverContext));

   DibAllocateLock(&pContext->UserLock);
   DibInitLock(&pContext->UserLock);
   DibAcquireLock(&pContext->UserLock);

   status = DibDriverInit(pContext, BoardType, BoardHdl);

   if(status == DIBSTATUS_SUCCESS)
   {
      *pContextAddr   = pContext;
      DibReleaseLock(&pContext->UserLock);
   }
   else
   {
   /* Do not set to null even if we should sice client may use twice a dibopen using the same context
      we do not check if the pointer was set to a value as the client may not have initialised it's variable */

   /* *pContextAddr = NULL; */
       DibDeAllocateLock(&pContext->UserLock);
       DibMemFree(pContext, sizeof(struct DibDriverContext));
   }


   return status;
}
/****************************************************************************
 * DeInit the bridge from the driver
 ****************************************************************************/
DIBSTATUS DibDriverTargetDeinit(struct DibDriverContext * pContext)
{
   /* this will destroy bridge thread and then destroy driver thread and trigger IrqRead event */
   ioctl(pContext->DriverTargetCtx.BridgeFd, REQUEST_BRIDGE_MODULE_SHUTDOWN, NULL);

   DibWaitForEvent(&pContext->DriverTargetCtx.IrqReadDone, 0);

   /** Free thread internal information */
   pthread_join(pContext->DriverTargetCtx.IrqThread, NULL);

   close(pContext->DriverTargetCtx.BridgeFd);

   DIB_DEBUG(PORT_LOG, (CRB "Stopped reading thread" CRA));

   DibDeAllocateEvent(&pContext->DriverTargetCtx.IrqReadDone);
   DibDeAllocateLock(&pContext->DriverTargetCtx.IrqLock);

   return DIBSTATUS_SUCCESS;
}
예제 #6
0
DIBSTATUS DibClose(struct DibDriverContext *pContext)
{
   DIBSTATUS status = DIBSTATUS_ERROR;

   if(pContext && pContext->Open)
   {
      DibAcquireLock(&pContext->UserLock);

      status = DibDriverDeinit(pContext);

      DibReleaseLock(&pContext->UserLock);
      DibDeAllocateLock(&pContext->UserLock);

      /* This is to help prevent double memory free by multiple calls to DibClose(),
         However as memory will be freed, it can be paged out in any case and cause an error.
         To prevent this DibClose should take struct DibDriverContext **pContext to clear out user reference to driver.*/
      pContext->Open = eDIB_FALSE;

      DibMemFree(pContext, sizeof(struct DibDriverContext));
   }

   return status;
}
void DibDriverDebugExit(struct DibDriverContext *ctx)
{
   DibDriverDebugPlatformExit(ctx);
   DibDeAllocateLock(&ctx->DebugCtx.Lock);
}