📄 tmchnl.c
字号:
/*----------------------------------------------------------------------------
COPYRIGHT (c) 1995 by Philips Semiconductors
THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY ONLY BE USED AND COPIED IN
ACCORDANCE WITH THE TERMS AND CONDITIONS OF SUCH A LICENSE AND WITH THE
INCLUSION OF THE THIS COPY RIGHT NOTICE. THIS SOFTWARE OR ANY OTHER COPIES
OF THIS SOFTWARE MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER
PERSON. THE OWNERSHIP AND TITLE OF THIS SOFTWARE IS NOT TRANSFERRED.
THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT ANY PRIOR NOTICE
AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY Philips Semiconductor.
PHILIPS ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF THIS SOFTWARE
ON PLATFORMS OTHER THAN THE ONE ON WHICH THIS SOFTWARE IS FURNISHED.
----------------------------------------------------------------------------*/
/*
HISTORY
#define TR Tilakraj Roy
960530 TR Created
960905 TR Pulled in from host channel sources
960907 TR Moved packet queuing to higher layer
960924 TR Pulled in mailbox sources from IPC
961019 TR Enabled in the new interface stuff.
*/
/*----------------------------------------------------------------------------
SYSTEM INCLUDE FILES
----------------------------------------------------------------------------*/
#include "tmman.h"
#undef CHNL_DEBUG
/*----------------------------------------------------------------------------
DRIVER SPECIFIC INCLUDE FILES
----------------------------------------------------------------------------*/
#include "tmhd.h"
#include "tmdbg.h"
#include "tmmmio.h"
#include "tmhal.h"
#include "tmipc.h"
#include "tmchnl.h"
#include "tmshare.h"
#include "tm1/tmInterrupts.h"
/* prototypes to be registered with IPC */
STATUS chnlmOnPacketSend ( PVOID pvContext );
STATUS chnlmOnPacketRecv ( PVOID pvContext,
PVOID pvPacketBuffer, DWORD dwPacketCount );
STATUS chnlmOnAsyncCallback ( PVOID pvContext );
VOID chnlDebugDump ( PVOID pBoard );
STATUS chnlmCallback ( DWORD InterruptID, DWORD Count, PVOID pContext );
/*
chnlmCreate
Creates a channel manager object dynamically.
Allocates an array of pointers for storing pointers to channel objects
that it will manage.
Opens and registers callbacks with the IPC interface.
*/
STATUS chnlmCreate (
PVOID pContainer, /* pointer to the driver object */
DWORD ChannelCount, /* number of channels that will be supported */
PVOID *ppChnlMgr ) /* address of memory where object ptr is stored */
{
PTMCHNL_MGR_OBJECT this;
STATUS Status;
DWORD ChnlIdx;
if ( ( this = (PTMCHNL_MGR_OBJECT)malloc (
sizeof ( TMCHNL_MGR_OBJECT ) * 1 ) ) == NULL )
{
DT(0, ( "chnlmCreate:ManagerObjectMalloc:FAIL\n"));
Status = TM_STATUS ( TMCHNL_ERR_MGROBJMALLOCFAIL );
goto chnlmCreate_fail1;
}
if ( ( this->pChnlTab =
(PVOID)malloc ( sizeof ( PVOID ) * ChannelCount ) ) == NULL )
{
DT(0, ( "chnlmCreate:ObjectPointerArrayMalloc:FAIL\n"));
Status = TM_STATUS ( TMCHNL_ERR_OBJPTRTABMALLOCFAIL );
goto chnlmCreate_fail2;
}
this->Flags = 0;
this->Size = sizeof (TMCHNL_MGR_OBJECT);
this->pContainer = pContainer;
this->ChannelCount = ChannelCount;
this->AllocatedCount = 0;
this->IdxSent = 0;
this->pIPC = GetIPCObject();
tmParameterDWORDGet ( TMHD_PARAM_CHNL, (PDWORD)&this->pSharedData );
for ( ChnlIdx = 0 ; ChnlIdx < ChannelCount ; ChnlIdx ++ )
{
this->pChnlTab[ChnlIdx] = NULL;
}
this->DPCReqCount = 0;
this->DPCAckCount = 0;
this->PktSendCount = 0;
this->PktRecvCount = 0;
this->PktSendDropCount = 0;
this->PktRecvDropCount = 0;
this->PktRecvInvDirCount = 0;
this->PktRecvInvChCount = 0;
this->PktSendSequence = 0;
this->PktRecvSequence = 0;
this->InchnlmOnPacketSend = 0;
if ( ( Status = ipcRegisterCallback (
GetIPCObject(), TMHD_IPC_CHNLINTERRUPT, chnlmCallback,
this ) ) != TMOK )
goto chnlmCreate_fail3;
FlagSet ( this->Flags, TMCHNL_MGR_FLAGINITIALIZED);
*ppChnlMgr = this;
return TMOK;
chnlmCreate_fail4:
ipcUnregisterCallback ( GetIPCObject(), TMHD_IPC_CHNLINTERRUPT );
chnlmCreate_fail3:
free ( this->pChnlTab );
chnlmCreate_fail2:
free ( this );
chnlmCreate_fail1:
return Status;
}
/*
chnlmCreateChnl
Allocates the number of packet buffers requried by the caller i.e
message and streams.
These buffers are allocated out of page locked memory.
The channel manager could be aware of all these buffers or the channel
manager could be calling functions with each of these channel objects
to retrieve packets out of these buffers.
Channels are inherently unidirectional. This means that both messages
and streams require two channels for bi-directional communications.
*/
STATUS chnlmCreateChnl (
PVOID pChnlMgr, /* pointer to channel manager */
BOOL Direction, /* channel direction */
DWORD ChannelID, /* channel ID - passed by the host */
DWORD QueueSize, /* queue depth */
PVOID OnCallback, /* receive & send callback */
PVOID pContext, /* receive and send callback context */
PVOID *ppChnl ) /* address of pointer for string chnl object */
{
PTMCHNL_MGR_OBJECT this = (PTMCHNL_MGR_OBJECT)pChnlMgr;
PTMCHNL_OBJECT pChannel;
DWORD dwIdx;
STATUS Status;
/* validate parameters here
OnRecvPacket
ChannelID
Direction
*/
if ( OnCallback == NULL )
{
DT(0, ( "chnlmCreateChnl:InvalidParameter:OnCallback:FAIL\n"));
return TM_STATUS ( TMCHNL_ERR_INVALIDPARAM ) ;
}
if ( this->AllocatedCount >= this->ChannelCount )
{
DT(0, ( "chnlmCreateChnl:OutOfChannels:FAIL\n"));
return TM_STATUS(TMCHNL_ERR_OUTOFCHANNELS);
}
if ( ChannelID >= this->ChannelCount )
{
DT(0, ( "chnlmCreateChnl:IDOutOfLimit:FAIL[%x]\n",ChannelID ));
return TM_STATUS(TMCHNL_ERR_CHNLIDOUTOFLIMIT);
}
if ( this->pChnlTab[ChannelID] )
{
DT(0, ( "chnlmCreateChnl:ChannelAlreadyAllocated:FAIL[%x]\n",ChannelID));
return TM_STATUS(TMCHNL_ERR_CHNLALREADYALLOCATED);
}
if ( ( pChannel = (PTMCHNL_OBJECT)malloc (
sizeof ( TMCHNL_OBJECT ) * 1 ) ) == NULL )
{
DT(0, ( "chnlmCreateChnl:ObjectAlloc:FAIL\n"));
return TM_STATUS ( TMCHNL_ERR_OBJALLOCFAIL );
}
this->pChnlTab[ChannelID] = (PVOID)pChannel;
this->AllocatedCount++;
this->Flags = 0;
FlagSet ( pChannel->Flags, TMCHNL_CHNL_FLAGALLOCATED );
pChannel->Size = sizeof ( TMCHNL_OBJECT );
pChannel->ID = ChannelID;
pChannel->OnCallback = OnCallback;
pChannel->pContext = pContext;
pChannel->Direction = Direction;
pChannel->pContainer = this->pContainer;
pChannel->PacketCounter = 0;
/*
TR960907 : commented out since queuing is the higher layers responsibility
*/
pChannel->pQueue = NULL;
if ( cqueueCreate ( QueueSize, sizeof ( TMSTD_PACKET ), NULL,
&pChannel->pQueue ) == FALSE )
{
DT(0, ( "chnlmCreateChnl:cqueueCreate:FAIL\n"));
Status = TM_STATUS ( TMCHNL_ERR_QUEUECREATEFAIL );
goto chnlmCreateChnl_fail2;
}
*ppChnl = (PVOID)pChannel;
/* chnlDebugDump ( NULL ); */
return TMOK;
chnlmCreateChnl_fail2:
FlagClr ( pChannel->Flags, TMCHNL_CHNL_FLAGALLOCATED );
pChannel->Size = 0;
free ( pChannel );
this->AllocatedCount--;
this->pChnlTab[ChannelID] = NULL;
chnlmCreateChnl_fail1:
return Status;
}
STATUS chnlDestroy (
PVOID pChnl ) /* pointer to the channel object */
{
PTMCHNL_OBJECT this = (PTMCHNL_OBJECT)pChnl;
STATUS Status;
if ( ( Status = chnlValidateHandle ( pChnl )) != TMOK )
{
return Status;
}
cqueueDestroy (this->pQueue );
FlagClr ( this->Flags, TMCHNL_CHNL_FLAGALLOCATED );
this->Size = 0;
((PTMCHNL_MGR_OBJECT)GetChnlMgrObject())->AllocatedCount--;
((PTMCHNL_MGR_OBJECT)GetChnlMgrObject())->pChnlTab[this->ID] = NULL;
free ( this );
return TMOK;
}
STATUS chnlmDestroy (PVOID pChnlMgr)
{
PTMCHNL_MGR_OBJECT this = (PTMCHNL_MGR_OBJECT)pChnlMgr;
ipcUnregisterCallback (
GetIPCObject(), TMHD_IPC_CHNLINTERRUPT );
FlagClr ( this->Flags, TMCHNL_MGR_FLAGINITIALIZED);
this->Size = 0;
free ( this->pChnlTab );
free ( this );
return TMOK;
}
/*
chnlmPacketSend
This function inserts the given packet in the per-channel packet queue and
then calls the chnlmOnPacketSend function to send as many pacskets from
all the queues to the interprocessor mailbox
*/
STATUS chnlPacketSend ( PVOID pChnl, PVOID pPacket )
{
PTMCHNL_OBJECT this = (PTMCHNL_OBJECT)pChnl;
STATUS Status;
DWORD PCSW;
PTMCHNL_MGR_OBJECT pChnlMgr =
GetChnlMgrObject ( );
PTMHD_CHNL_MAILQUEUE pHost = &pChnlMgr->pSharedData->ToHost;
if ( ( Status = chnlValidateHandle ( this ) ) != TMOK )
{
return Status;
}
PCSW = halRaiseIrql( GetHalObject(), 6 );
pChnlMgr->PktSendCount++;
DT(3, ( "[QSEND|CH:%x|CM:%x|A0:%x|A1:%x|A2:%x|A3:%x|A4:%x]\n",
this->ID,
((PTMSTD_PACKET)pPacket)->dwCommand,
((PTMSTD_PACKET)pPacket)->dwArgument[0],
((PTMSTD_PACKET)pPacket)->dwArgument[1],
((PTMSTD_PACKET)pPacket)->dwArgument[2],
((PTMSTD_PACKET)pPacket)->dwArgument[3],
((PTMSTD_PACKET)pPacket)->dwArgument[4] ));
if ( cqueueInsert ( this->pQueue, pPacket ) == FALSE )
{
pChnlMgr->PktSendDropCount++;
DT(0, ("tmman:chnlPacketSend:cqueueInsert:#[%x]:FAIL\n", this->ID));
chnlmOnPacketSend ( pChnlMgr );
return TM_STATUS ( TMCHNL_ERR_CHANNELQUEUEFULL );
}
#ifdef CHNL_DEBUG
DPT(0, ("[I:%x]", ((PTMSTD_PACKET)pPacket)->dwArgument[4] ));
#endif
/*
dump not only this packet but all the packets in all the queues
this is called by IPC but we call this function directly from here
*/
chnlmOnPacketSend ( pChnlMgr );
/*
here we have to emulate exactly what chnlmCallback does
*/
if ( pHost->dwReadIndex != pHost->dwWriteIndex )
{
pChnlMgr->pSharedData->ToHost.IntCmd = TMHD_CHNL_MBOXREADY;
ipcGenerateIRQ ( GetIPCObject(), TMHD_IPC_CHNLINTERRUPT );
}
halLowerIrql( GetHalObject(), PCSW );
return TMOK;
}
/*
chnlmOnPacketSend
This function may be called when ever there is room in the interprocessor
mailboxes. This functions starts at the channel that it left off last time.
This is done so that every channel gets a fair chance to send packets to its
peer. When there is no more room in the interprocessor mailbox, this
functions aborts expecting to be called again when there is room or when a
client inserts a packet in any of the channel queues.
*/
STATUS chnlmOnPacketSend (
PVOID pContext ) /* pointer to the channel manager object */
{
PTMCHNL_MGR_OBJECT this = (PTMCHNL_MGR_OBJECT)pContext;
PTMCHNL_OBJECT pChannel;
TMHD_CHNL_MAILSLOT MailSlot;
DWORD Count;
PTMHD_CHNL_MAILQUEUE pDSP = &this->pSharedData->ToDSP;
PTMHD_CHNL_MAILQUEUE pHost = &this->pSharedData->ToHost;
DWORD dwWriteIndex;
DWORD PCSW;
/* check for reentrancy */
if ( this->InchnlmOnPacketSend )
{
DT(0, ("TM:PANIC:chnlmOnPacketSend:ReEntered:ERROR\n" ));
return TMOK;
}
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -