baseport/syborg/soundsc/virtio.cpp
changeset 45 01c1ffcc4fca
equal deleted inserted replaced
44:72a7468afdd4 45:01c1ffcc4fca
       
     1 /*
       
     2 * This component and the accompanying materials are made available
       
     3 * under the terms of the License "Eclipse Public License v1.0"
       
     4 * which accompanies this distribution, and is available
       
     5 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     6 *
       
     7 * Initial Contributors:
       
     8 * Accenture Ltd
       
     9 *
       
    10 * Contributors:
       
    11 *
       
    12 * Description: This file is a part of sound driver for Syborg adaptation.
       
    13 *
       
    14 */
       
    15 
       
    16 #include "virtio.h"
       
    17 
       
    18 namespace VirtIo 
       
    19 {
       
    20 
       
    21 #define MIN(x,y) (((x)<=(y))?(x):(y))
       
    22 #define INVALID_PHYSADDR(x) ((x)==TPhysAddr(-1))
       
    23 
       
    24 TInt LinearToSGL( TAny* aVirtual, TUint aSize, TAddrLen aSGL[], TUint& aSGLCount )
       
    25 	{
       
    26 	const TUint pageSize = Kern::RoundToPageSize(1);
       
    27 	TUint8* virtAddr = reinterpret_cast<TUint8*>( aVirtual );
       
    28 	TPhysAddr physAddr = Epoc::LinearToPhysical( TLinAddr(virtAddr) );
       
    29 	if (INVALID_PHYSADDR(physAddr))
       
    30 		{ return KErrArgument; }
       
    31 	TUint sglLimit = aSGLCount;
       
    32 	aSGLCount = 0;
       
    33 	TUint left = aSize;
       
    34 	while (left)
       
    35 		{
       
    36 		TPhysAddr startPhysAddr = physAddr;
       
    37 		TUint8* startVirtAddr = virtAddr;
       
    38 		while ( (left) 
       
    39 			&& ( Epoc::LinearToPhysical( TLinAddr(virtAddr) ) == physAddr ) )
       
    40 			{
       
    41 			TUint size = MIN(left, pageSize);
       
    42 			physAddr += size;
       
    43 			virtAddr += size;
       
    44 			left -= size;
       
    45 			}
       
    46 		if (INVALID_PHYSADDR(physAddr))
       
    47 			{ return KErrArgument; }
       
    48 		if ((aSGL) && (aSGLCount<sglLimit))
       
    49 			{
       
    50 			aSGL[aSGLCount].iAddr = (TUint32) startPhysAddr;
       
    51 			aSGL[aSGLCount].iLen = virtAddr - startVirtAddr;
       
    52 			}
       
    53 		aSGLCount++;
       
    54 		}
       
    55 	return (aSGLCount<=sglLimit)?KErrNone:KErrNoMemory;
       
    56 	}
       
    57 	
       
    58 } // namespace VirtIo