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