📄 usbehcdutil.c
字号:
/* usbEhcdUtil.c - contains the utility functions of EHCD *//* Copyright 2004-2005 Wind River Systems, Inc. This software includes software licensed to Wind River Systems, Inc. by Wipro, Ltd. Wind River licensees may use this software according to the terms of their Wind River license agreement(s) applicable to this software.*//*modification history--------------------01l,22apr05,pdg Fix for 64 bit split isochronous transfers01k,28mar05,pdg non-PCI changes01j,22mar05,mta 64-bit support added (SPR #104950)01i,25feb05,mta SPR 10627601h,03dec04,ami Merged IP Changes01g,26oct04,ami Severity Changes for Debug Messages01f,15oct04,ami Apigen Changes01e,05oct04,mta SPR100704- Removal of floating point math01f,15oct04,ami Apigen Changes01e,05oct04,mta SPR100704- Removal of floating point math01d,23Jul03,??? Incorporated changes identified during testing on MIPS.01c,16Jul03,??? updated the next link pointer of the aligned pointer in the free list to be NULL.01b,26jun03,gpd changing the code to WRS standards.01a,25apr02,ram written.*//*DESCRIPTIONThis module defines the functions which serve as utility functions for theEHCI Host Controller Driver.INCLUDE FILES: usbhst.h, usbEhcdDataStructures.h, usbEhcdUtil.h, usbEhcdDebug.h,SEE ALSO: <USB specification, revision 2.0> <EHCI specification, revision 1.0>*//* INTERNAL ******************************************************************************* * * Filename : EHCD_Util.c * * Copyright : * * THE COPYRIGHT IN THE CONTENTS OF THIS SOFTWARE VEST WITH WIPRO * LIMITED A COMPANY INCORPORATED UNDER THE LAWS OF INDIA AND HAVING * ITS REGISTERED OFFICE AT DODDAKANNELLI SARJAPUR ROAD BANGALORE * 560 035. DISTRIBUTION OR COPYING OF THIS SOFTWARE BY * ANY INDIVIDUAL OR ENTITY OTHER THAN THE ADDRESSEE IS STRICTLY * PROHIBITED AND MAY INCUR LEGAL LIABILITY. IF YOU ARE NOT THE * ADDRESSEE PLEASE NOTIFY US IMMEDIATELY BY PHONE OR BY RETURN EMAIL. * THE ADDRESSEE IS ADVISED TO MAINTAIN THE PROPRIETARY INTERESTS OF * THIS COPYRIGHT AS PER APPLICABLE LAWS. * * Description : This contains the utility functions which are used by the * EHCI Driver. * * ******************************************************************************/#include "usb2/usbOsal.h"#include "usb2/BusAbstractionLayer.h"#include "usb2/usbHst.h"#include "usb2/usbEhcdDataStructures.h"#include "usb2/usbEhcdUtil.h"#include "usb2/usbHcdInstr.h"/* To hold the head of the Free QH list */LOCAL pUSB_EHCD_QH pHeadFreeQH = NULL;/* To hold the tail of the Free QH list */LOCAL pUSB_EHCD_QH pTailFreeQH = NULL;/* To hold the head of the Free QTD list */LOCAL pUSB_EHCD_QTD pHeadFreeQTD = NULL;/* To hold the tail of the Free QTD list */LOCAL pUSB_EHCD_QTD pTailFreeQTD = NULL;/* To hold the head of the free isochronous TD list */LOCAL pUSB_EHCD_ITD pHeadFreeITD = NULL;/* To hold the tail of the free isochronous TD list */LOCAL pUSB_EHCD_ITD pTailFreeITD = NULL;/* To hold the head of the free split isochronous TD list */LOCAL pUSB_EHCD_SITD pHeadFreeSITD = NULL;/* To hold the tail of the free split isochronous TD list */LOCAL pUSB_EHCD_SITD pTailFreeSITD = NULL;/* To hold the event which prevents the list accesses */#define pUSB_EHCD_QTD_NEXT_QTD_POINTER_OFFSET 0#define pUSB_EHCD_QTD_pNext_OFFSET 22extern OS_EVENT_ID g_ListAccessEvent;LOCAL pUSB_EHCD_ITD usbEhcdFormEmptyITD ( pUSB_EHCD_DATA pHCDData,/* Pointer to the USB_EHCD_DATA structure */ pUSB_EHCD_PIPE pHCDPipe /* Pointer to the USB_EHCD_PIPE structure */ );/* forward declarations */LOCAL pUSB_EHCD_SITD usbEhcdFormEmptySITD ( pUSB_EHCD_DATA pHCDData,/* Pointer to the USB_EHCD_DATA structure */ pUSB_EHCD_PIPE pHCDPipe /* Pointer to the USB_EHCD_PIPE structure */ );LOCAL UINT32 usbEhcdFillITD ( UINT8 index, /* index of the host controller */ pUSB_EHCD_ITD pITD, /* Pointer to the ITD */ UINT8 uMicroFrameMask, /* Microframe mask value */ UCHAR *pBuffer, /* Pointer to the buffer value */ UINT32 uPktCnt, /* No of packet */ pUSBHST_ISO_PACKET_DESC pIsoPktDesc /* array of packet descriptor */ );LOCAL BOOLEAN usbEhcdFillSITD ( UINT8 index, /* index of the host controller */ pUSB_EHCD_SITD pSITD, /* Pointer to the SITD */ UCHAR * pBuffer, /* Pointer to the start of the buffer */ UINT32 uTransferLength /* Transfer length */ );/***************************************************************************** usbEhcdAlign - aligns the memory location** This function is used to align a memory location.** <pMemory> Pointer to the allocated memory.* <uAlignment> Alignment size.** RETURNS: Pointer to a void.** ERRNO:* None.** \NOMANUAL*/VOID * usbEhcdAlign ( VOID * pMemory, UINT32 uAlignment ) { /* To hold the offset value */ UINT32 uOffset = 0; OS_LOG_MESSAGE_LOW(EHCD,"usbEhcdAlign - Entry\n",0,0,0,0); /* Check if the parameters are valid */ if (NULL == pMemory || 0 == uAlignment) { OS_LOG_MESSAGE_HIGH(EHCD,"usbEhcdAlign - Parameters not valid\n",0,0,0,0); return NULL; } /* Calculate the offset value */ uOffset = (UINT32)pMemory & (uAlignment - 1); /* If it not aligned, align it */ if (0 != uOffset) { pMemory = ((UINT8 *)pMemory) + uAlignment - uOffset; } /* Return the aligned memory location */ return pMemory; } /* End of function usbEhcdAlign() *//***************************************************************************** usbEhcdAddToFreeQHList - adds the QH to the free list** This function is used to add a QH to the free QH list.** <pQH> Pointer to the USB_EHCD_QH data structure.** RETURNS: TRUE if the QH is added successfully.* FALSE if the QH is not added successfully.** ERRNO:* None.* * \NOMANUAL*/BOOLEAN usbEhcdAddToFreeQHList ( pUSB_EHCD_QH pQH ) { /* Pointer to the allocated memory location */ VOID * pAllocatedMem = NULL; UINT32 uSize = 0; OS_LOG_MESSAGE_LOW(EHCD,"usbEhcdAddToFreeQHList - Entry\n",0,0,0,0); /* Check the validity of the parameter */ if (NULL == pQH) { OS_LOG_MESSAGE_HIGH(EHCD,"usbEhcdAddToFreeQHList - \ Parameter not valid\n",0,0,0,0); return FALSE; } /* Assert if the Allocated memory for the QH is not valid */ OS_ASSERT(NULL != pQH->pAllocatedMem); /* Store the allocated memory in a temporary pointer */ pAllocatedMem = pQH->pAllocatedMem; /* * Retrieve the size of the QH. pQH.size consist of the total allocated * size for the queue head. * While adding the QH to the free list, we set the complete * allocated memory with 0. * Then we write back the size of the allocated structure and the allocated * pointer value in the respective feilds. */ uSize = pQH->uSize; /* Reinitialize the memory */ OS_MEMSET(pAllocatedMem, 0, uSize); /* Copy the allocated memory pointer back */ pQH->pAllocatedMem = pAllocatedMem; /* Copy the size back to QH */ pQH->uSize = uSize; /* Wait on the signalling of the event */ OS_WAIT_FOR_EVENT(g_ListAccessEvent,OS_WAIT_INFINITE); /* Update the next element of the QTD */ pQH->pNext = pHeadFreeQH; /* Make this QTD as the head of the free list */ pHeadFreeQH = pQH; /* If tail pointer is NULL, this QTD becomes the tail pointer */ if (NULL == pTailFreeQH) { pTailFreeQH = pQH; } /* Release the event */ OS_RELEASE_EVENT(g_ListAccessEvent); return TRUE; } /* End of usbEhcdAddToFreeQHList() *//***************************************************************************** usbEhcdAddToFreeQTDList - adds the QTD to the free list** This function is used to add a QTD to the free QH list.** <pQTD> Pointer to the USB_EHCD_QTD data structure.** RETURNS: TRUE if the QTD is added successfully.* FALSE if the QTD is not added successfully.** ERRNO:* None.** \NOMANUAL*/BOOLEAN usbEhcdAddToFreeQTDList ( pUSB_EHCD_QTD pQTD ) { /* Pointer to the allocated memory location */ VOID * pAllocatedMem = NULL; UINT32 uSize = 0; /* Check the validity of the parameter */ if (NULL == pQTD) { OS_LOG_MESSAGE_HIGH(EHCD,"usbEhcdAddToFreeQTDList - \ Parameter not valid\n",0,0,0,0); return FALSE; } /* Assert if the Allocated memory for the QTD is not valid */ OS_ASSERT(NULL != pQTD->pAllocatedMem); /* Store the allocated memory in a temporary pointer */ pAllocatedMem = pQTD->pAllocatedMem; /* * Retrieve the size of the QTD. pQTD.size consist of the total allocated * size for the queue head. * While adding the QTD to the free list, we set the complete * allocated memory with 0. * Then we write back the size of the allocated structure and the allocated * pointer value in the respective feilds. */ uSize = pQTD->uSize; /* Reinitialize the memory */ OS_MEMSET(pAllocatedMem, 0, uSize); /* Copy the allocated memory pointer back */ pQTD->pAllocatedMem = pAllocatedMem; /* Copy back the size of QTD */ pQTD->uSize = uSize; /* Wait on the signalling of the event */ OS_WAIT_FOR_EVENT(g_ListAccessEvent,OS_WAIT_INFINITE); /* Update the next element of the QTD */ pQTD->pNext = pHeadFreeQTD; /* Make this QTD as the head of the free list */ pHeadFreeQTD = pQTD; /* If tail pointer is NULL, this QTD becomes the tail pointer */ if (NULL == pTailFreeQTD) { pTailFreeQTD = pQTD; } /* Release the event */ OS_RELEASE_EVENT(g_ListAccessEvent); return TRUE; } /* End of EHCD_AddToFreeTDList() *//***************************************************************************** usbEhcdAddToFreeITDList - adds the ITD to the free list** This function is used to add a ITD to the free QH list.** <pITD> Pointer to the USB_EHCD_ITD data structure.** RETURNS: TRUE if the ITD is added successfully.* FALSE if the ITD is not added successfully.** ERRNO:* None.* * \NOMANUAL*/BOOLEAN usbEhcdAddToFreeITDList ( pUSB_EHCD_ITD pITD ) { /* Pointer to the allocated memory location */ VOID * pAllocatedMem = NULL; UINT32 uSize = 0; OS_LOG_MESSAGE_LOW(EHCD,"usbEhcdAddToFreeITDList - Entry\n",0,0,0,0); /* Check the validity of the parameter */ if (NULL == pITD) { OS_LOG_MESSAGE_HIGH(EHCD,"usbEhcdAddToFreeITDList - \ Parameter not valid\n",0,0,0,0); return FALSE; } /* Assert if the Allocated memory for the ITD is not valid */ OS_ASSERT(NULL != pITD->pAllocatedMem); /* Store the allocated memory in a temporary pointer */ pAllocatedMem = pITD->pAllocatedMem; /* * Retrieve the size of the ITD. pITD.size consist of the total allocated * size for the queue head. * While adding the ITD to the free list, we set the complete * allocated memory with 0. * Then we write back the size of the allocated memory and the allocated * pointer value in the respective feilds. */ uSize = pITD->uSize; /* Reinitialize the memory */ OS_MEMSET(pAllocatedMem, 0, uSize); /* Copy the allocated memory pointer back */ pITD->pAllocatedMem = pAllocatedMem; /* Store the size of ITD */ pITD->uSize = uSize; /* Wait on the signalling of the event */ OS_WAIT_FOR_EVENT(g_ListAccessEvent,OS_WAIT_INFINITE); /* Update the next element of the ITD */ pITD->pNext = pHeadFreeITD; /* Make this ITD as the head of the free list */ pHeadFreeITD = pITD; /* If tail pointer is NULL, this ITD becomes the tail pointer */ if (NULL == pTailFreeITD) { pTailFreeITD = pITD; } /* Release the event */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -