XilinxProcessorIPLib/drivers/axidma/src/xaxidma_bdring.c
int XAxiDma_BdRingUnAlloc(XAxiDma_BdRing * RingPtr, int NumBd,
	XAxiDma_Bd * BdSetPtr)
{
	XAxiDma_Bd *TmpBd;

	if (NumBd <= 0) {

		xdbg_printf(XDBG_DEBUG_ERROR, "BdRingUnAlloc: negative BD"
		" number %d\r\n", NumBd);

		return XST_INVALID_PARAM;
	}

	/* Enough BDs in the preprocessing state for the request? */
	if (RingPtr->PreCnt < NumBd) {
		xdbg_printf(XDBG_DEBUG_ERROR,
		"Pre-allocated BDs less than requested %d/%d\r\n",
		RingPtr->PreCnt, NumBd);

		return XST_FAILURE;
	}

	/* The last BD in the BD set must has the FreeHead as its next BD.
	 * Otherwise, this is not a valid operation.
	 */
	TmpBd = BdSetPtr;
	XAXIDMA_RING_SEEKAHEAD(RingPtr, TmpBd, NumBd);

	if (TmpBd != RingPtr->FreeHead) {
		xdbg_printf(XDBG_DEBUG_ERROR,
		    "Unalloc does not go back to free head\r\n");

		return XST_FAILURE;
	}

	/* Set the return argument and move FreeHead backward */
	XAXIDMA_RING_SEEKBACK(RingPtr, RingPtr->FreeHead, NumBd);
	RingPtr->FreeCnt += NumBd;
	RingPtr->PreCnt -= NumBd;

	return XST_SUCCESS;
}
/*****************************************************************************/
/**
 * Fully or partially undo an XAxiDma_BdRingAlloc() operation. Use this
 * function if all the BDs allocated by XAxiDma_BdRingAlloc() could not be
 * transferred to hardware with XAxiDma_BdRingToHw().
 *
 * This function releases the BDs after they have been allocated but before
 * they have been given to hardware.
 *
 * This function is not the same as XAxiDma_BdRingFree(). The Free function
 * returns BDs to the free list after they have been processed by hardware,
 * while UnAlloc returns them before being processed by hardware.
 *
 * There are two scenarios where this function can be used. Full UnAlloc or
 * Partial UnAlloc. A Full UnAlloc means all the BDs Alloc'd will be returned:
 *
 * <pre>
 *    Status = XAxiDma_BdRingAlloc(MyRingPtr, 10, &BdPtr);
 *        ...
 *        ...
 *    if (Error)
 *    {
 *        Status = XAxiDma_BdRingUnAlloc(MyRingPtr, 10, &BdPtr);
 *    }
 * </pre>
 *
 * A partial UnAlloc means some of the BDs Alloc'd will be returned:
 *
 * <pre>
 *    Status = XAxiDma_BdRingAlloc(MyRingPtr, 10, &BdPtr);
 *    BdsLeft = 10;
 *    CurBdPtr = BdPtr;
 *
 *    while (BdsLeft)
 *    {
 *       if (Error)
 *       {
 *          Status = XAxiDma_BdRingUnAlloc(MyRingPtr, BdsLeft, CurBdPtr);
 *       }
 *
 *       CurBdPtr = XAxiDma_BdRingNext(MyRingPtr, CurBdPtr);
 *       BdsLeft--;
 *    }
 * </pre>
 *
 * A partial UnAlloc must include the last BD in the list that was Alloc'd.
 *
 * @param	RingPtr is a pointer to the descriptor ring instance to be
 *		worked on.
 * @param	NumBd is the number of BDs to unallocate
 * @param	BdSetPtr points to the first of the BDs to be returned.
 *
 * @return
 *		- XST_SUCCESS if the BDs were unallocated.
 *		- XST_INVALID_PARAM if passed in NumBd is negative
 *		- XST_FAILURE if NumBd parameter was greater that the number of
 *		BDs in the preprocessing state.
 *
 * @note	This function should not be preempted by another XAxiDma ring
 *		function call that modifies the BD space. It is the caller's
 *		responsibility to provide a mutual exclusion mechanism.
 *
 *		This function can be used only when DMA is in SG mode
 *
 *****************************************************************************/
Fully or partially undo an XAxiDma_BdRingAlloc() operation. Use this
function if all the BDs allocated by XAxiDma_BdRingAlloc() could not be
transferred to hardware with XAxiDma_BdRingToHw().

This function releases the BDs after they have been allocated but before
they have been given to hardware.

This function is not the same as XAxiDma_BdRingFree(). The Free function
returns BDs to the free list after they have been processed by hardware,
while UnAlloc returns them before being processed by hardware.

There are two scenarios where this function can be used.



A partial UnAlloc means some of the BDs Alloc'd will be returned.







A partial UnAlloc must include the last BD in the list that was Alloc'd.

@param       RingPtr is a pointer to the descriptor ring instance to be
worked on.
@param       NumBd is the number of BDs to unallocate
@param       BdSetPtr points to the first of the BDs to be returned.

@return
- XST_SUCCESS if the BDs were unallocated.
- XST_INVALID_PARAM if passed in NumBd is negative
- XST_FAILURE if NumBd parameter was greater that the number of
BDs in the preprocessing state.

@note        This function should not be preempted by another XAxiDma ring
function call that modifies the BD space. It is the caller's
responsibility to provide a mutual exclusion mechanism.

This function can be used only when DMA is in SG mode
Fully or partially undo an XAxiDma_BdRingAlloc () operation . Use this function if all the BDs allocated by XAxiDma_BdRingAlloc () could not be transferred to hardware with XAxiDma_BdRingToHw () . This function releases the BDs after they have been allocated but before they have been given to hardware . This function is not the same as XAxiDma_BdRingFree () . The Free function returns BDs to the free list after they have been processed by hardware while UnAlloc returns them before being processed by hardware . There are two scenarios where this function can be used . A partial UnAlloc means some of the BDs Alloc ' d will be returned . A partial UnAlloc must include the last BD in the list that was Alloc ' d . @param RingPtr is a pointer to the descriptor ring instance to be worked on . @param NumBd is the number of BDs to unallocate @param BdSetPtr points to the first of the BDs to be returned . @return - XST_SUCCESS if the BDs were unallocated . - XST_INVALID_PARAM if passed in NumBd is negative - XST_FAILURE if NumBd parameter was greater that the number of BDs in the preprocessing state . @note This function should not be preempted by another XAxiDma ring function call that modifies the BD space . It is the caller ' s responsibility to provide a mutual exclusion mechanism . This function can be used only when DMA is in SG mode
int XAxiDma_BdRingUnAlloc(XAxiDma_BdRing * RingPtr, int NumBd,
	XAxiDma_Bd * BdSetPtr)
{
	XAxiDma_Bd *TmpBd;
	if (NumBd <= 0) {
		xdbg_printf(XDBG_DEBUG_ERROR, "BdRingUnAlloc: negative BD"
		" number %d\r\n", NumBd);
		return XST_INVALID_PARAM;
	}
	if (RingPtr->PreCnt < NumBd) {
		xdbg_printf(XDBG_DEBUG_ERROR,
		"Pre-allocated BDs less than requested %d/%d\r\n",
		RingPtr->PreCnt, NumBd);
		return XST_FAILURE;
	}
	TmpBd = BdSetPtr;
	XAXIDMA_RING_SEEKAHEAD(RingPtr, TmpBd, NumBd);
	if (TmpBd != RingPtr->FreeHead) {
		xdbg_printf(XDBG_DEBUG_ERROR,
		    "Unalloc does not go back to free head\r\n");
		return XST_FAILURE;
	}
	XAXIDMA_RING_SEEKBACK(RingPtr, RingPtr->FreeHead, NumBd);
	RingPtr->FreeCnt += NumBd;
	RingPtr->PreCnt -= NumBd;
	return XST_SUCCESS;
}
int XAxiDma_BdRingUnAlloc ( XAxiDma_BdRing * RingPtr , int NumBd , XAxiDma_Bd * BdSetPtr ) { XAxiDma_Bd * TmpBd ; if ( NumBd <= 0 ) { xdbg_printf ( XDBG_DEBUG_ERROR , " " " \r \n " , NumBd ) ; return XST_INVALID_PARAM ; } if ( RingPtr -> PreCnt < NumBd ) { xdbg_printf ( XDBG_DEBUG_ERROR , " \r \n " , RingPtr -> PreCnt , NumBd ) ; return XST_FAILURE ; } TmpBd = BdSetPtr ; XAXIDMA_RING_SEEKAHEAD ( RingPtr , TmpBd , NumBd ) ; if ( TmpBd != RingPtr -> FreeHead ) { xdbg_printf ( XDBG_DEBUG_ERROR , " \r \n " ) ; return XST_FAILURE ; } XAXIDMA_RING_SEEKBACK ( RingPtr , RingPtr -> FreeHead , NumBd ) ; RingPtr -> FreeCnt += NumBd ; RingPtr -> PreCnt -= NumBd ; return XST_SUCCESS ; }
Fully or partially undo an XAxiDma_BdRingAlloc() operation.
Fully or partially undo an XAxiDma_BdRingAlloc () operation .
/* Enough BDs in the preprocessing state for the request? */ /* The last BD in the BD set must has the FreeHead as its next BD.
	 * Otherwise, this is not a valid operation.
	 */ /* Set the return argument and move FreeHead backward */