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

📄 sec2_cha.c

📁 freescale ppc sec2加解密单元驱动
💻 C
字号:
 /**************************************************************************** * sec2_cha.c - Channel/CHA operations code 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 * 1.1.0 Nov 15,2004 sec - merge linux changes from prior versions * 1.2   Jan 27,2005 *//*#include "sec2_const.h" */#include "stdio.h"#include "Sec2Driver.h"unsigned long Sec2ChaDoneInterruptMasks[NUM_CHAS] = {    0x00000001,    0x00000010,    0x00000100,    0x00001000,    0x00010000,    0x00100000};/*  unsigned long ChannelDoneInterruptMasks[SEC2_NUM_CHANNELS]    An array of channel done completion bit masks.    The index of the array represents the channel.  This bit mask    is applied against #sec2_InterruptStatusRegister in order to    determine if an interrupt is due to a channel completion or not.*/unsigned long Sec2ChannelDoneInterruptMasks[SEC2_NUM_CHANNELS] = {    0x00000001,    0x00000004,    0x00000010,    0x00000040};/*! \var unsigned long Sec2ChannelErrorInterruptMasks[SEC2_NUM_CHANNELS]    \brief An array of channel error bit masks.    The index of the array represents the channel.  This bit mask    is applied against #sec2_InterruptStatusRegister in order to    determine if an interrupt is due to a channel error or not.*/unsigned long Sec2ChannelErrorInterruptMasks[SEC2_NUM_CHANNELS] = {    0x00000002,    0x00000008,    0x00000020,    0x00000080};/*! \var unsigned long Sec2ChaErrorInterruptMasks[NUM_CHAS]    \brief An array of CHA error bit masks.    The index of the array represents the CHA.  This bit mask    is applied against #sec2_InterruptStatusRegister in order to    determine if an interrupt is due to a CHA error or not.*/unsigned long Sec2ChaErrorInterruptMasks[NUM_CHAS] ={    0x00000002,    0x00000020,    0x00000200,    0x00002000,    0x00020000,    0x00200000};int sec2_ReleaseCha(unsigned long channelCha, int callingTaskId, BOOLEAN locked);/****************************************************************//* Function Name: sec2_ChaNumToType                                  *//* Purpose: To translate the the CHA number to the CHA chaType  *//* Input: cha - CHA Number                                      *//* Output: ChaType                                              *//****************************************************************/int sec2_ChaNumToType(int cha){    switch (cha)    {    case CHA_AFHA:        return (CHA_AFHA);    case CHA_DES:        return (CHA_DES);    case CHA_MDHA:        return (CHA_MDHA);    case CHA_RNG:        return (CHA_RNG);    case CHA_PKHA:        return (CHA_PKHA);    case CHA_AESA:        return (CHA_AESA);    default:        return (SEC2_INVALID_CHA_TYPE);    }} /* End of sec2_ChaNumToType *//* this should only be called with channel assignments locked *//********************************************************************//* Function Name: Sec2_CheckChas                                         *//* Purpose: Check to see if the CHA is available (at least one of   *//*          this type of CHA is available)                          *//* Input: The opId requested                                        *//* Output: SEC2_SUCCESS if this type of CHA is available            *//*         otherwise the error code                                 *//********************************************************************/int Sec2_CheckChas(unsigned long OpId){    unsigned int chaType = 0;    switch (OpId & 0xf000)    {        case 0x1000:                        /* RNG Group */            chaType |= CHA_RNGA_BITMASK;            break;        case 0x2000:                        /* Des Groups */            chaType |= CHA_DESA_BITMASK;            break;        case 0x3000:                        /* RC4 Groups */            chaType |= CHA_AFHA_BITMASK;            break;        case 0x4000:                        /* MD Groups */            chaType |= CHA_MDHA_BITMASK;            break;        case 0x5000:                        /* PK Groups */            chaType |= CHA_PKHA_BITMASK;            break;        case 0x6000:                        /* AES Groups */            chaType |= CHA_AESA_BITMASK;            break;        case 0x7000:                        /* ipsec Des + MD Groups */            chaType |= (CHA_MDHA_BITMASK | CHA_DESA_BITMASK);            break;        case 0x8000:                        /* ipsec aes + md groups */            chaType |= (CHA_MDHA_BITMASK | CHA_AESA_BITMASK);            break;        default:            /* invalid opId */            return (SEC2_INVALID_OPERATION_ID);    }    if (((chaType & CHA_AFHA_BITMASK) != 0) && (sec2_FreeAfhas == 0))     {        return (SEC2_CHA_NOT_AVAILABLE);    }    else if (((chaType & CHA_DESA_BITMASK) != 0) && (sec2_FreeDesas == 0))    {        return (SEC2_CHA_NOT_AVAILABLE);    }    else if (((chaType & CHA_MDHA_BITMASK) != 0) && (sec2_FreeMdhas == 0))     {        return (SEC2_CHA_NOT_AVAILABLE);    }    else if (((chaType & CHA_RNGA_BITMASK) != 0) && (sec2_FreeRngas == 0))     {        return (SEC2_CHA_NOT_AVAILABLE);    }    else if (((chaType & CHA_PKHA_BITMASK) != 0) && (sec2_FreePkhas == 0))     {        return (SEC2_CHA_NOT_AVAILABLE);    }    else if (((chaType & CHA_AESA_BITMASK) != 0) && (sec2_FreeAesas == 0))     {        return (SEC2_CHA_NOT_AVAILABLE);    }    else if (((chaType & CHA_KEA_BITMASK) != 0) && (sec2_FreeKeas == 0))     {        return (SEC2_CHA_NOT_AVAILABLE);    }    /* CHA(s) are available, return OK */    return (SEC2_SUCCESS);}/********************************************************************//* Function Name: sec2_ReleaseChannel                                    *//* Purpose:  To free a reserved channel                             *//*                                                                  *//* Input: channel - the channel number (1-4)                        */  /*        callingTaskId - the task id                               *//*        locked - TRUE or FALSE                                    *//* Return: SEC2_SUCCESS if success otherwise the error code     *//********************************************************************/#if 0int sec2_ReleaseChannel(unsigned long channel, int callingTaskId, BOOLEAN locked){    int cha, chaType;    SEC2Dump(DBGTXT_SVCRQ, ("sec2_ReleaseChannel(%ld, taskID=0x%8x, lock=%d)\n", channel, callingTaskId, locked));    /* check channel value */    if ((channel == 0) || (channel > SEC2_NUM_CHANNELS)) return (SEC2_INVALID_CHANNEL);    if (!locked)        IOLockChannelAssignment();    /* check that calling task is the channel's owner */    if (Sec2_ChannelAssignments[channel - 1].ownerTaskId != callingTaskId)    {        /* error, caller is not the channel owner */        if (!locked)            IOUnLockChannelAssignment();        return (SEC2_INVALID_CHANNEL);    }    /* release all cha's assigned to this channel */    for (cha=0; cha<NUM_CHAS; cha++)    {        if (sec2_ChaAssignments[cha] == (unsigned char) channel)        {            /* determine cha type from cha number */            chaType = sec2_ChaNumToType(cha);            /* release the cha */            sec2_ReleaseCha(((channel << 8) | (unsigned long)chaType), callingTaskId, TRUE);        }    }    sec2_FreeChannels++;    /* release the channel */    Sec2_ChannelAssignments[channel - 1].assignment = CHANNEL_FREE;    if (!locked)    {        IOUnLockChannelAssignment();        /* schedule queued requests on any freed channels */        Sec2_ScheduleNext();    }    return (SEC2_SUCCESS);} /* end of sec2_ReleaseChannel *//**************************************************************************//* Function Name: sec2_ReleaseCha                                              *//* Purpose:  To release a specific CHA                                       *//*              or a manual channel.                                      *//* Input: channelCha - the bottom eight bits is the CHA chaType           *//*                     the next eight bits is the channel number (1-4)    */    /*        callingTaskId - the task id                                     *//*        locked - TRUE or FALSE                                          *//* Return: SEC2_SUCCESS if success otherwise the error code           *//**************************************************************************/int sec2_ReleaseCha(unsigned long channelCha, int callingTaskId, BOOLEAN locked){    unsigned char channel = (unsigned char)((channelCha >> 8) & 0xFF);    unsigned char chaType = (unsigned char)(channelCha & 0xFF);    unsigned long chaStatus[2] = {0,0};/*    unsigned long temp[2] = {0,0}; */    int cha;    int numChas = 0; /*20060920*/    SEC2Dump(DBGTXT_SVCRQ, ("sec2_ReleaseCha(%ld, taskID=0x%8x, lock=%d)\n", channelCha, callingTaskId, locked));    /* check chaType value */    if ((chaType != CHA_AFHA) && (chaType != CHA_DES) && (chaType != CHA_MDHA)        && (chaType != CHA_RNG) && (chaType != CHA_PKHA)        && (chaType != CHA_AESA)                    )        return (SEC2_INVALID_CHA_TYPE);    if (!locked)        IOLockChannelAssignment();    /* check that callingTaskId matches the channel owner */    if (Sec2_ChannelAssignments[channel - 1].ownerTaskId != callingTaskId)    {        /* error, cha owner is not current task */        if (!locked)            IOUnLockChannelAssignment();        return (SEC2_INVALID_CHANNEL);    }    /* determine number of CHAs for the chaType */    switch (chaType)    {    case CHA_AFHA:        numChas = SEC2_NUM_AFHAS;        break;    case CHA_DES:        numChas = SEC2_NUM_DESAS;        break;    case CHA_MDHA:        numChas = SEC2_NUM_MDHAS;        break;    case CHA_RNG:        numChas = SEC2_NUM_RNGAS;        break;    case CHA_PKHA:        numChas = SEC2_NUM_PKHAS;        break;    case CHA_AESA:        numChas = SEC2_NUM_AESAS;        break;	default:		printf("sec2_ReleaseCha error!\n");		return SEC2_INVALID_CHA_TYPE;    }    /* find the CHA to release */    for (cha=chaType; cha<(chaType+numChas); cha++)    {        /* see if the CHA is assigned to the given channel */        if (sec2_ChaAssignments[cha] == channel)        {            /* found a CHA assigned to the given channel */            /* release the CHA */            chaStatus[0] = *(volatile unsigned long *)(sec2_ChaAssignmentStatusRegister);            chaStatus[1] = *(volatile unsigned long *)(sec2_ChaAssignmentStatusRegister + 1);                        if (cha < 4)            {                chaStatus[0] &= (~(unsigned long)(0xF << (cha * 8))); /*20060920*/                sec2_ChaAssignments[cha] = CHA_DYNAMIC;            }            else            {                chaStatus[1] &= (~(unsigned long)(0xF << ((cha - 4) * 8)) << 16); /*20060920*/                sec2_ChaAssignments[cha] = CHA_DYNAMIC;            }                        *(sec2_ChaAssignmentControlRegister)     = chaStatus[0];            *(sec2_ChaAssignmentControlRegister + 1) = chaStatus[1];            /* reset the CHA */            *(sec2_ChaResetControlRegister[sec2_cha_idx[cha]])     = CHA_SOFTWARE_RESET;            *(sec2_ChaResetControlRegister[sec2_cha_idx[cha]] + 1) = 0;            break;        }    }    /* see if we found a CHA to release */    if (cha >= (chaType + numChas))    {        /* we didn't find a CHA to release, return an error */        if (!locked)            IOUnLockChannelAssignment();        return (SEC2_INVALID_CHA_TYPE);    }    /* update free CHA counts */    switch (chaType)    {        case CHA_AFHA:            sec2_FreeAfhas++;            break;        case CHA_DES:            sec2_FreeDesas++;            break;        case CHA_MDHA:            sec2_FreeMdhas++;            break;        case CHA_RNG:            sec2_FreeRngas++;            break;        case CHA_PKHA:            sec2_FreePkhas++;            break;        case CHA_AESA:            sec2_FreeAesas++;            break;	    default:			printf("sec2_ReleaseCha error!\n");		    return ERROR;    }    if (!locked)    {        IOUnLockChannelAssignment();        /* schedule queued requests on any freed CHAs */        Sec2_ScheduleNext();    }    return (SEC2_SUCCESS);} /* End of sec2_ReleaseCha */#endif

⌨️ 快捷键说明

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