⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sec2_io.c

📁 freescale ppc sec2加解密单元驱动
💻 C
字号:
/**************************************************************************** * sec2_io.c -- bus operations for SEC2 Driver  **************************************************************************** * Copyright (c) Certicom Corp. 1996-2002.  All rights reserved * Copyright (c) 2003, 2004 Freescale Semiconductor * All Rights Reserved. Proprietary and Confidential. * * NOTICE: The information contained in this file is proprietary * to Freescale Semiconductor, and is being made available to * Freescale's customers under strict license agreements. * Use or disclosure of this information is permissible only * under the terms of the existing license agreement. ***************************************************************************//* Revision History: * 1.0   Aug 24,2003 dgs adapted from the final version of mpc18x *       May 12,2004 sec - switched core interrupt for 8555 configuration * 1.1.0 Dec 05,2004 sec - merge in linux support from prior versions * 1.1.1 Dec 16,2004 sec - remove lock variable, remove old diagnostics * 1.2   Jan 27,2005 */#include "stdio.h"#include "install.h"#include "sec2Driver.h"#if (INSTALL_ON_PPC8347)||(INSTALL_ON_PPC8349)||(INSTALL_ON_ZSR1809)#define   SEC2_VEC               (int)11#endif#if INSTALL_ON_PPC8541#define   SEC2_VEC               (int)0x29#endif#ifdef VXWORKS#include "intLib.h"IO_STATUS IOInitQs(void){    /* set up ISR/Sec2_ProcessingComplete message queue */    IsrMsgQId = msgQCreate(MAX_MESSAGES, sizeof(SEC2_DEVICE_REGS), MSG_Q_FIFO);    if (IsrMsgQId == NULL)        return SEC2_VXWORKS_CANNOT_CREATE_QUEUE;    return SEC2_SUCCESS;}#if 0IO_STATUS IORegisterDriver(void){    /* start ProcessComplete task, with high priority */    taskSpawn("tSEC2_pc",              PROCESSING_COMPLETE_PRIORITY,              0,              PROCESSING_COMPLETE_STACKSIZE,              (FUNCPTR)Sec2_ProcessingComplete,               0, 0, 0, 0, 0, 0, 0, 0, 0, 0);    /* add the driver to the driver table */    driverNum = iosDrvInstall((FUNCPTR)SEC2Open, (FUNCPTR)(int)NULL, (FUNCPTR)SEC2Open, (FUNCPTR)SEC2Close, (FUNCPTR)(int)NULL, (FUNCPTR)(int)NULL, (FUNCPTR)SEC2_ioctl); /*20060920*/    if (driverNum < 0)        return (SEC2_IO_VXWORKS_DRIVER_TABLE_ADD_ERROR);    (void) iosDevAdd(&vxworksDrvDev, vxworksDrvName, driverNum);    return (SEC2_SUCCESS);}#endif#endifint IOInitChannelSemaphores(void){    /* initialize channel semaphores */	    sec2_ChannelAssignSemId = semMCreate(SEM_Q_PRIORITY | SEM_INVERSION_SAFE | SEM_DELETE_SAFE);    if(NULL == sec2_ChannelAssignSemId)    {        return SEC2_ERROR;    }    return SEC2_SUCCESS;}int InitGlobalQueueSemaphores(void){    /* initialize queue semaphores */	    sec2_QueueSemId = semMCreate(SEM_Q_PRIORITY | SEM_INVERSION_SAFE | SEM_DELETE_SAFE);    if(NULL == sec2_QueueSemId)    {        return SEC2_ERROR;    }    return SEC2_SUCCESS;}/* * IOConnectInterrupt() */ #ifdef VXWORKS/* the Interrupt connect should be moved to sysLib.c since it is board dependent */#if 0IO_STATUS IOConnectInterrupt(void){  /* Install our IRQ handler */  if(ERROR == b_cintConnect(11,                            (VOIDFUNCPTR)sec2_InterruptServiceRoutine,                            (int)0))  {       return SEC2_ERROR;  }  /* Enable the handler at the controller level */  intEnable(11);  SEC2Dump(DBGTXT_INITDEV, ("IOConnectInterrupt ISR connected\n"));  return  SEC2_SUCCESS;}#endifIO_STATUS IOConnectInterrupt(void){  /* Install our IRQ handler */  if(ERROR == intConnect((VOIDFUNCPTR*)SEC2_VEC,                         (VOIDFUNCPTR)sec2_InterruptServiceRoutine,                         (int)0))  {       return SEC2_ERROR;  }  /* Enable the handler at the controller level */  intEnable(SEC2_VEC);  SEC2Dump(DBGTXT_INITDEV, ("IOConnectInterrupt ISR connected\n"));  return  SEC2_SUCCESS;}#endif#if 0IO_STATUS IOConnectInterrupt(void){    if ((request_irq(MPC85xx_IRQ_SEC, sec2_InterruptServiceRoutine, 0, "mpc-sec", NULL)) != 0)        return -1;        return (SEC2_SUCCESS);}#endif#ifdef __KERNEL__#include <linux/sched.h>#include <asm/atomic.h>#include <asm/semaphore.h>unsigned long irq_flag;  /* here for spin locks to use */static inline int __sem_update_count(struct semaphore *sem, int incr){    int old_count, tmp;        __asm__ __volatile__("\n""1: lwarx   %0,0,%3\n""   srawi   %0,%0,31\n""   andc    %1,%0,%1\n""   add     %1,%1,%4\n"    PPC405_ERR77(0,%3)"   stwcx.  %1,0,%3\n""   bne     1b"    : "=&r" (old_count), "=&r" (tmp), "=m" (sem->count)    : "r" (&sem->count), "r" (incr), "m" (sem->count)    : "cc");        return old_count;}long __down_interruptible_timeout(struct semaphore *sem, long timeout){    int retval = 0;    struct task_struct *tsk = current;    DECLARE_WAITQUEUE(wait, tsk);        tsk->state = TASK_INTERRUPTIBLE;    add_wait_queue_exclusive(&sem->wait, &wait);    smp_wmb();        while (__sem_update_count(sem, -1) <= 0) {        if (signal_pending(current)) {            __sem_update_count(sem, 0);            retval = -EINTR;            break;        }        timeout = schedule_timeout(timeout);        tsk->state = TASK_INTERRUPTIBLE;    }    tsk->state = TASK_RUNNING;    remove_wait_queue(&sem->wait, &wait);    wake_up(&sem->wait);    return timeout >= 0 ? 0 : -1;}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -