omap3530/assp/src/register.cpp
changeset 0 6663340f3fc9
equal deleted inserted replaced
-1:000000000000 0:6663340f3fc9
       
     1 // Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // omap3530/assp/src/register.cpp
       
    15 //
       
    16 
       
    17 #include <assp.h>
       
    18 #include <assp/omap3530_assp/omap3530_asspreg.h>
       
    19 
       
    20 #ifdef __SMP__
       
    21 TSpinLock AsspLock(TSpinLock::EOrderGenericIrqLow1);
       
    22 #endif
       
    23 
       
    24 ///////////////////////////////////////////////////////////////////////////////
       
    25 //
       
    26 // MHA - Modular Hardware Adaption
       
    27 //
       
    28 // Register Access
       
    29 //
       
    30 ///////////////////////////////////////////////////////////////////////////////
       
    31 
       
    32 
       
    33 ///////////////////////////////////////////////////////////////////////////////
       
    34 // We need spin locks around read, modify, write operations because another CPU
       
    35 // may access the same memory in between operations and potentially cause
       
    36 // memory corruption.
       
    37 ///////////////////////////////////////////////////////////////////////////////
       
    38 EXPORT_C void AsspRegister::Modify8(TLinAddr aAddr, TUint8 aClearMask, TUint8 aSetMask)
       
    39 	{
       
    40 	TUint irq = __SPIN_LOCK_IRQSAVE(AsspLock);
       
    41 	TUint8  value = *(volatile TUint8  *)aAddr;
       
    42 	value &= ~aClearMask;
       
    43 	value |= aSetMask;
       
    44 	*(volatile TUint8  *)aAddr = value;
       
    45 	__SPIN_UNLOCK_IRQRESTORE(AsspLock,irq);
       
    46 	}
       
    47 
       
    48 EXPORT_C void AsspRegister::Modify16(TLinAddr aAddr, TUint16 aClearMask, TUint16 aSetMask)
       
    49 	{
       
    50 	TUint irq = __SPIN_LOCK_IRQSAVE(AsspLock);
       
    51 	TUint16 value = *(volatile TUint16 *)aAddr;
       
    52 	value &= ~aClearMask;
       
    53 	value |= aSetMask;
       
    54 	*(volatile TUint16 *)aAddr = value;
       
    55 	__SPIN_UNLOCK_IRQRESTORE(AsspLock,irq);
       
    56 	}
       
    57 
       
    58 EXPORT_C void AsspRegister::Modify32(TLinAddr aAddr, TUint32 aClearMask, TUint32 aSetMask)
       
    59 	{
       
    60 	TUint irq = __SPIN_LOCK_IRQSAVE(AsspLock);
       
    61 	TUint32 value = *(volatile TUint32 *)aAddr;
       
    62 	value &= ~aClearMask;
       
    63 	value |= aSetMask;
       
    64 	*(volatile TUint32 *)aAddr = value;
       
    65 	__SPIN_UNLOCK_IRQRESTORE(AsspLock,irq);
       
    66 	}
       
    67 
       
    68 ///////////////////////////////////////////////////////////////////////////////
       
    69 // 64 bit operations may be more complex than 8/16/32 bit operations, depending
       
    70 // upon hardware support for 64 bit accesses.
       
    71 //
       
    72 // For example, one platform required an assembly language function to prevent
       
    73 // the compliler optimising the accesses into 2 x 32 bit accesses and causing a
       
    74 // bus error.
       
    75 //
       
    76 // Spinlocks are required for non-atomic operations and are therefore
       
    77 // recommended for 64 bit accesses on current platforms.
       
    78 ///////////////////////////////////////////////////////////////////////////////
       
    79 extern TUint64 DoRead64(TLinAddr aAddr);
       
    80 
       
    81 EXPORT_C TUint64 AsspRegister::Read64(TLinAddr aAddr)
       
    82 	{
       
    83 	TUint irq = __SPIN_LOCK_IRQSAVE(AsspLock);
       
    84 	TUint64 value = DoRead64(aAddr);
       
    85 	__SPIN_UNLOCK_IRQRESTORE(AsspLock,irq);
       
    86 	return value;
       
    87 	}
       
    88 
       
    89 extern void DoWrite64(TLinAddr aAddr, TUint64 aValue);
       
    90 
       
    91 EXPORT_C void AsspRegister::Write64(TLinAddr aAddr, TUint64 aValue)
       
    92 	{
       
    93 	TUint irq = __SPIN_LOCK_IRQSAVE(AsspLock);
       
    94 	DoWrite64(aAddr, aValue);
       
    95 	__SPIN_UNLOCK_IRQRESTORE(AsspLock,irq);
       
    96 	}
       
    97 
       
    98 EXPORT_C void AsspRegister::Modify64(TLinAddr aAddr, TUint64 aClearMask, TUint64 aSetMask)
       
    99 	{
       
   100 	TUint irq = __SPIN_LOCK_IRQSAVE(AsspLock);
       
   101 	TUint64 value = DoRead64(aAddr);
       
   102 	value &= ~aClearMask;
       
   103 	value |= aSetMask;
       
   104 	DoWrite64(aAddr, value);
       
   105 	__SPIN_UNLOCK_IRQRESTORE(AsspLock,irq);
       
   106 	}
       
   107