navienginebsp/naviengine_assp/pci/mapman.h
changeset 0 5de814552237
equal deleted inserted replaced
-1:000000000000 0:5de814552237
       
     1 /*
       
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef __MAPMAN_H__
       
    21 #define __MAPMAN_H__
       
    22 
       
    23 #include <e32cmn.h>
       
    24 
       
    25 //helper maths functions
       
    26 TUint32 Clp2(TUint32 aNumber);
       
    27 TUint32 Log2(TUint32 aNumber);
       
    28 
       
    29 class TAddressAllocator;
       
    30 class DMutex;
       
    31 
       
    32 /**
       
    33 Responsible for creating outbound mappings so that
       
    34 PCI peripherals can access system memory.
       
    35 */
       
    36 class TMappingManager
       
    37 	{
       
    38 public:
       
    39 	TMappingManager(TInt aNumOfBars, TAddressAllocator& aAllocator, TUint32 aBaseAddress);
       
    40 	~TMappingManager();
       
    41 	TInt CreateMapping(TUint32 aPhysicalAddress, TInt aSize, TUint32& aPciAddress);
       
    42 	TInt RemoveMapping(TUint32 aPhysicalAddress);
       
    43 
       
    44 	TInt GetPciAddress(TUint32 aPhysicalAddress, TUint32& aPciAddress);
       
    45 	TInt GetPhysicalAddress(TUint32 aPciAddress, TUint32& aPhysicalAddress);
       
    46 
       
    47 private:
       
    48 	/**
       
    49 	Associates BAR with an allocated PCI address
       
    50 	*/
       
    51 	struct TMapping
       
    52 		{
       
    53 		TMapping();
       
    54 		static TBool UsedCompare(const TMapping& aKeyMapping, const TMapping& aMapping);
       
    55 		static TBool PhysAddrCompare(const TUint32*, const TMapping& aMapping);
       
    56 		static TBool ContainsPhysical(const TUint32*, const TMapping& aMapping);
       
    57 		static TBool ContainsPci(const TUint32*, const TMapping& aMapping);
       
    58 
       
    59 		inline TUint32 PciAddress(TUint32 aPhysAddress);
       
    60 		inline TUint32 PhysAddress(TUint32 aPciAddress);
       
    61 
       
    62 		TUint32 iPciAddr;
       
    63 		TUint32 iPhysAddr;
       
    64 		TUint32 iSize;
       
    65 		TBool iUsed;
       
    66 		};
       
    67 
       
    68 	void DoCreateMapping(TInt aBarIndex, TUint32 aPhysicalAddress, TInt& aSize, TUint32& aPciAddress);
       
    69 
       
    70 	TAddressAllocator& iAllocator;
       
    71 	const TInt iNumOfBars;
       
    72 	const TUint32 iBaseAddress;
       
    73 
       
    74 	RArray<TMapping> iMappings;
       
    75 	DMutex* iMutex;
       
    76 	};
       
    77 #endif // __MAPMAN_H__