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; }
/**************************************************************************** * Init the bridge from the driver ****************************************************************************/ DIBSTATUS DibDriverTargetInit(struct DibDriverContext *pContext) { struct IoctlInit pReq; if((pContext->DriverTargetCtx.BridgeFd = open(DEVICE_FILE_NAME, O_RDWR)) < 0) { DIB_DEBUG(PORT_ERR, (CRB "Could not open device %s" CRA, DEVICE_FILE_NAME)); return DIBSTATUS_ERROR; } /* this will create and initialise bridge */ pReq.BoardHdl = pContext->BoardHdl; pReq.ChipSelect = pContext->DibChip; #if (USE_DRAGONFLY == 1) if((pContext->DibChip == DIB_VOYAGER) || (pContext->DibChip == DIB_NAUTILUS)) { pReq.Config[0] = pContext->DragonflyRegisters.JedecAddr; pReq.Config[1] = pContext->DragonflyRegisters.JedecValue; pReq.Config[2] = pContext->DragonflyRegisters.MacMbxSize; pReq.Config[3] = pContext->DragonflyRegisters.MacMbxStart; pReq.Config[4] = pContext->DragonflyRegisters.MacMbxEnd; pReq.Config[5] = pContext->DragonflyRegisters.HostMbxSize; pReq.Config[6] = pContext->DragonflyRegisters.HostMbxStart; pReq.Config[7] = pContext->DragonflyRegisters.HostMbxEnd; pReq.Config[8] = pContext->DragonflyRegisters.HostMbxRdPtrReg; pReq.Config[9] = pContext->DragonflyRegisters.HostMbxWrPtrReg; pReq.Config[10] = pContext->DragonflyRegisters.MacMbxRdPtrReg; pReq.Config[11] = pContext->DragonflyRegisters.MacMbxWrPtrReg; } else #endif DibZeroMemory(pReq.Config, sizeof(pReq.Config)); if(ioctl(pContext->DriverTargetCtx.BridgeFd, REQUEST_BRIDGE_MODULE_INIT, &pReq) != DIBSTATUS_SUCCESS) { DIB_DEBUG(PORT_ERR, (CRB "Could initialise Bridge %s" CRA, DEVICE_FILE_NAME)); /* close open device and free allocated memory*/ close(pContext->DriverTargetCtx.BridgeFd); return DIBSTATUS_ERROR; } DibAllocateEvent(&pContext->DriverTargetCtx.IrqReadDone); DibInitNotificationEvent(&pContext->DriverTargetCtx.IrqReadDone); DibAllocateLock(&pContext->DriverTargetCtx.IrqLock); DibInitLock(&pContext->DriverTargetCtx.IrqLock); DIB_DEBUG(PORT_LOG, (CRB "Launching interrupt thread" CRA)); pthread_create(&pContext->DriverTargetCtx.IrqThread, NULL, IntDriverTargetIrqRead, (void *)pContext); DibWaitForEvent(&pContext->DriverTargetCtx.IrqReadDone, 0); return DIBSTATUS_SUCCESS; }
/**************************************************************************** * DibBridgeTargetInit ****************************************************************************/ DIBSTATUS DibBridgeTargetInit(struct DibBridgeContext *pContext) { DIBSTATUS rc = DIBSTATUS_SUCCESS; /*** Initialize Mutex to avoid concurrent access ***/ DibAllocateLock(&pContext->DibTargetAccessLock); DibInitLock(&pContext->DibTargetAccessLock); DibAllocateLock(&pContext->BridgeTargetCtx.IrqLock); DibInitLock(&pContext->BridgeTargetCtx.IrqLock); /*** Configure Driver for SRAM interface ***/ DibBridgeSetHostIfMode(pContext, eSRAM); /*** Initialize SRAM Controller ***/ SramInit(pContext); return rc; }
/**************************************************************************** * Bridge 2 Driver msg handling function. Also used to transmit SIPSI fragment * buffers to the Driver. ****************************************************************************/ void DibBridgeInitMsgQueue(struct DibBridgeContext *pContext) { DibAllocateLock(&pContext->MsgQueueLock); DibInitLock(&pContext->MsgQueueLock); DibAllocateEvent(&pContext->MsgQueueEvent); DibInitNotificationEvent(&pContext->MsgQueueEvent); pContext->MsgQueueTail = 0; pContext->MsgQueueHead = 0; pContext->MsgQueueInitialized = 1; }
/**************************************************************************** * DibBridgeTargetInit ****************************************************************************/ DIBSTATUS DibBridgeTargetInit(struct DibBridgeContext *pContext) { DIBSTATUS rc = DIBSTATUS_SUCCESS; /*** Initialize Mutex to avoid concurrent access ***/ DibAllocateLock(&pContext->DibTargetAccessLock); DibInitLock(&pContext->DibTargetAccessLock); DibAllocateLock(&pContext->BridgeTargetCtx.IrqLock); DibInitLock(&pContext->BridgeTargetCtx.IrqLock); /*** Configure Driver for I2C interface ***/ DibBridgeSetHostIfMode(pContext, eI2C); /*** Use a global variable to call in DibWaitForEvent ***/ pLocalContext = pContext; /*** Initialize I2C by Parallel port **i*/ I2CInit(); return rc; }
void DibDriverDebugInit(struct DibDriverContext *ctx) { int i; DibAllocateLock(&ctx->DebugCtx.Lock); DibInitLock(&ctx->DebugCtx.Lock); for (i = 0; i < DIB_MAX_NB_DEBUG_INSTANCES; i++) { ctx->DebugCtx.Instance[i].Id = -2 - i; ctx->DebugCtx.Instance[i].Context = NULL; } ctx->DebugCtx.Context = ctx; DibDriverDebugPlatformInit(ctx); }
/*----------------------------------------------------------------------- | Open the Device Driver -----------------------------------------------------------------------*/ static int32_t DibBridgeTargetModuleOpen(struct inode *inode, struct file *file) { int32_t status = DIBSTATUS_ERROR; struct DibBridgeContext *pBridgeContext = NULL; printk(CRB "Trying to open dibbridge.."); pBridgeContext = (struct DibBridgeContext *) DibBridgeTargetAllocBuf(sizeof(struct DibBridgeContext)); if(pBridgeContext == NULL) { printk(CRB "%s: Out of memory" CRA, __func__); return -ENOMEM; } /* Clear Content */ DibZeroMemory(pBridgeContext, sizeof(struct DibBridgeContext)); /* Allocate ptr for IOCTL request */ pBridgeContext->BridgeTargetCtx.IoctlReq = kmalloc(sizeof(struct IoctlHead), GFP_KERNEL); if(pBridgeContext->BridgeTargetCtx.IoctlReq == NULL) { printk(CRB "%s: Out of memory" CRA, __func__); status = -ENOMEM; goto End; } /* Allocate buffer for IOCTL request */ pBridgeContext->BridgeTargetCtx.IoctlReq->Buffer = kmalloc(MAX_BRIDGE_DRIVER_BUFFER, GFP_KERNEL); if(pBridgeContext->BridgeTargetCtx.IoctlReq->Buffer == NULL) { printk(CRB "%s: Out of memory" CRA, __func__); status = -ENOMEM; goto End; } /* Init IOCTL Lock */ DibAllocateLock(&pBridgeContext->BridgeTargetCtx.IoctlLock); DibInitLock(&pBridgeContext->BridgeTargetCtx.IoctlLock); status = DIBSTATUS_SUCCESS; End: if(status != DIBSTATUS_SUCCESS) { /* Free possibly allocated struct */ IntBridgeTargetModuleFreeStruct(pBridgeContext); } else { status = (int32_t)DIBSTATUS_SUCCESS; /* Store Allocated Bridge Context */ file->private_data = pBridgeContext; try_module_get(THIS_MODULE); } return status; }