📄 syscachelocklib.c
字号:
/* sysCacheLockLib.c - Cache locking support routines. *//* Copyright 1984-2002 Wind River, Inc *//*modification history--------------------01d,04feb02,g_h Add L2 cache support01c,25oct01,g_h Remove underscore from functions name.01b,12oct01,g_h Remove DIAB dependences.01a,12dec00,mno created (teamf1)*//*DESCRIPTIONThis module contains code to lock and unlock L1 & L2 cache. The routinessysCacheLock/Unlock can be used to lock and unlock the L1 cache, and theroutines sysL2CacheLock/Unlock can be used to lock and unlock the L2 cache.This module supports PPC processors that support separate data and instructioncaches (harward-style) for the L1. The lock routine will lock the entirecache, after loading it with specified code or data region. When the cache islocked, data/instruction access to regions not locked in the cache will nothit the cache.L1 locking routines can be used to lock only one region of memory. Multiplecalls to lock a region will result in unlocking the previous regionn. Theregion being locked must be aligned on a 32-byte boundary, and must not belarger than the L1 cache size.These MPC750/755/74XX CPU implement a unified L2 cache that cannot be locked for separately for data and instruction. The implementation therefore supports locking the entire L2 cache for either data or instruction. While locking the L2 cache, the corresponding L1 cache must have been enabled, but not locked. Multiple calls to the L2 cache locking will silently unlock the region previously locked.The region being locked in the L1 cache must be alignedon a 32-byte boundary.SEE ALSO: *//* includes */#include "vxWorks.h"#include "cacheLib.h"#include "intLib.h"#include "string.h"#include "vmLib.h"#include "private/vmLibP.h"#include "arch/ppc/mmuPpcLib.h"#include "tickLib.h"#include "sysCacheLockLib.h"/* externs */IMPORT STATUS cachePpcDisable(CACHE_TYPE cache);IMPORT UINT sysL2crGet (void);/* defines */#define CACHE_LOCK_AND_ENABLE_RTN_SIZE ((char*)SYSL1CACHELOCK_ENDADRS - \ (char*)SYSL1CACHELOCK_STARTADRS)/************************************************************************* sysCacheLock - locks specified data/instruction region** This routine locks the specified region into the cache, <cacheType>. The* region to be locked is specified by the start address, <adrs>, and the size,* <bytes>. The region -- the start address, and size -- must be aligned on a* 32-byte boundary.** Multiple calls to this routine will silently unlock the specified cache to* lock the new region.** RETURNS: OK or error if cache is locked, or if cache is not supported.** SEE ALSO: sysCacheUnlock()*/STATUS sysCacheLock ( CACHE_TYPE cacheType, void * adrs, UINT32 bytes ) { int x; VOIDFUNCPTR cacheEnableAndLockRtn; UINT32 cacheEnableAndLockRtnSize; if (!ALIGNED(adrs, 32)) { logMsg("\n Memory Address not aligned on 32 byte boundry\n",1,2,3,4,5,6); return(ERROR); } if ((cacheType != _INSTRUCTION_CACHE) && (cacheType != _DATA_CACHE)) return(ERROR); x=intLock(); /* if l1 is locked, unlock it */ if ((vxHid0Get() & _PPC_HID0_DLOCK) || (vxHid0Get() & _PPC_HID0_ILOCK)) sysCacheUnlock(cacheType); cachePpcDisable(cacheType); if (cacheType == _DATA_CACHE) cacheEnableAndLockRtn = sysL1CacheLock; else { cacheEnableAndLockRtnSize = ROUND_UP(CACHE_LOCK_AND_ENABLE_RTN_SIZE, MMU_PPC_PAGE_SIZE); cacheEnableAndLockRtn = (VOIDFUNCPTR) cacheDmaMalloc (cacheEnableAndLockRtnSize); if (cacheEnableAndLockRtn == NULL) { intUnlock (x); return(ERROR); } VM_STATE_SET (NULL, (char *) cacheEnableAndLockRtn, cacheEnableAndLockRtnSize, VM_STATE_MASK_CACHEABLE | VM_STATE_MASK_MEM_COHERENCY, VM_STATE_CACHEABLE_NOT | VM_STATE_MEM_COHERENCY_NOT); bcopy ((char*)SYSL1CACHELOCK_STARTADRS, (char *)cacheEnableAndLockRtn, CACHE_LOCK_AND_ENABLE_RTN_SIZE); } cacheEnableAndLockRtn (cacheType, adrs, bytes); intUnlock(x); if (cacheType == _INSTRUCTION_CACHE) cacheDmaFree ((char *)cacheEnableAndLockRtn); return(OK); }/****************************************************************************** sysCacheUnlock - Unlocks the previous locked cache** This routines unlocks the specified cache, <cacheType>** RETURNS: OK or error if cache is not supported.** SEE ALSO: sysCacheLock() */STATUS sysCacheUnlock ( CACHE_TYPE cacheType ) { int x; if ((cacheType != _INSTRUCTION_CACHE) && (cacheType != _DATA_CACHE)) return(ERROR); x = intLock(); sysL1CacheUnlock (cacheType); intUnlock(x); return(OK); }#if defined(INCLUDE_CACHE_L2)/*************************************************************************** sysL2CacheLock - lock L2 cache** The routine locks the L2 cache with specified region. L2 is implemented* as a unified cache and supports locking only one region regardless of* whether it is data or instruction.** A region of data or instruction can be locked in L2 cache only when the* corresponding L1 cache is enabled but not locked.** The region of memory being locked must be aligned on a 32-byte boundary.** On consequtive calls, this routine will silently unlock the previous locked* region.** RETURNS: OK on success, and ERROR otherwise.** SEE ALSO: sysL2CacheUnlock, sysCacheLock, sysCacheUnlock**/STATUS sysL2CacheLock ( CACHE_TYPE cacheType, void * adrs, size_t bytes ) { UINT32 hid0; size_t size; if ((cacheType != _INSTRUCTION_CACHE) && (cacheType != _DATA_CACHE)) return(ERROR); if (!ALIGNED(adrs, 32) || !ALIGNED(bytes, 32)) { logMsg("Memory Address and size are not aligned on 32 byte boundry\n", 1,2,3,4,5,6); return(ERROR); } if (bytes > L2RAM_SIZE) size = L2RAM_SIZE; else size = bytes; hid0 = vxHid0Get(); /* * For data cache lock, verify that L1 data cache is enabled * and that L1 data cache is not locked */ if ((cacheType == _DATA_CACHE) && ( !(hid0 & _PPC_HID0_DCE) || (hid0 & _PPC_HID0_DLOCK))) return(ERROR); /* * For instruction cache lock, verify that L1 instruction cache is enabled * and that the instruction L1 cache is not locked */ if ((cacheType == _INSTRUCTION_CACHE) && (( ! (hid0 & _PPC_HID0_ICE)) || ( hid0 & _PPC_HID0_ILOCK))) return(ERROR); /* if l2 locked, unlock it*/ if (sysL2crGet() & ((L2DO << 16) || L2IO)) sysL2CacheUnlock(); _sysL2CacheLock(cacheType, adrs, size); return(OK); }/*************************************************************************** sysL2CacheUnlock - unlock the L2 cache** This routine unlocks the L2 cache.** RETURNS: OK, always.** SEE ALSO: sysL2CacheLock, sysCacheLock, sysCacheUnlock*/STATUS sysL2CacheUnlock (void) { _sysL2CacheUnlock(); return(OK); } #endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -