[270] | 1 | /**************************************************************************//**
|
---|
| 2 | * @file pl310.c
|
---|
| 3 | * @brief Implementation of PL310 PrimeCell Level 2 Cache Controller functions
|
---|
| 4 | * @version
|
---|
| 5 | * @date 3 December 2014
|
---|
| 6 | *
|
---|
| 7 | * @note
|
---|
| 8 | *
|
---|
| 9 | ******************************************************************************/
|
---|
| 10 | /* Copyright (c) 2011 - 2013 ARM LIMITED
|
---|
| 11 |
|
---|
| 12 | All rights reserved.
|
---|
| 13 | Redistribution and use in source and binary forms, with or without
|
---|
| 14 | modification, are permitted provided that the following conditions are met:
|
---|
| 15 | - Redistributions of source code must retain the above copyright
|
---|
| 16 | notice, this list of conditions and the following disclaimer.
|
---|
| 17 | - Redistributions in binary form must reproduce the above copyright
|
---|
| 18 | notice, this list of conditions and the following disclaimer in the
|
---|
| 19 | documentation and/or other materials provided with the distribution.
|
---|
| 20 | - Neither the name of ARM nor the names of its contributors may be used
|
---|
| 21 | to endorse or promote products derived from this software without
|
---|
| 22 | specific prior written permission.
|
---|
| 23 | *
|
---|
| 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
---|
| 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
| 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
---|
| 27 | ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
|
---|
| 28 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
---|
| 29 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
---|
| 30 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
---|
| 31 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
---|
| 32 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
---|
| 33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
---|
| 34 | POSSIBILITY OF SUCH DAMAGE.
|
---|
| 35 | ---------------------------------------------------------------------------*/
|
---|
| 36 | #include "MBRZA1H.h"
|
---|
| 37 |
|
---|
| 38 | //Cache Sync operation
|
---|
| 39 | void PL310_Sync(void)
|
---|
| 40 | {
|
---|
| 41 | PL310->CACHE_SYNC = 0x0;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | //return Cache controller cache ID
|
---|
| 45 | int PL310_GetID (void)
|
---|
| 46 | {
|
---|
| 47 | return PL310->CACHE_ID;
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | //return Cache controller cache Type
|
---|
| 51 | int PL310_GetType (void)
|
---|
| 52 | {
|
---|
| 53 | return PL310->CACHE_TYPE;
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | //Invalidate all cache by way
|
---|
| 57 | void PL310_InvAllByWay (void)
|
---|
| 58 | {
|
---|
| 59 | unsigned int assoc;
|
---|
| 60 |
|
---|
| 61 | if (PL310->AUX_CNT & (1<<16))
|
---|
| 62 | assoc = 16;
|
---|
| 63 | else
|
---|
| 64 | assoc = 8;
|
---|
| 65 |
|
---|
| 66 | PL310->INV_WAY = (1 << assoc) - 1;
|
---|
| 67 | while(PL310->INV_WAY & ((1 << assoc) - 1)); //poll invalidate
|
---|
| 68 |
|
---|
| 69 | PL310_Sync();
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | //Clean and Invalidate all cache by way
|
---|
| 73 | void PL310_CleanInvAllByWay (void)
|
---|
| 74 | {
|
---|
| 75 | unsigned int assoc;
|
---|
| 76 |
|
---|
| 77 | if (PL310->AUX_CNT & (1<<16))
|
---|
| 78 | assoc = 16;
|
---|
| 79 | else
|
---|
| 80 | assoc = 8;
|
---|
| 81 |
|
---|
| 82 | PL310->CLEAN_INV_WAY = (1 << assoc) - 1;
|
---|
| 83 | while(PL310->CLEAN_INV_WAY & ((1 << assoc) - 1)); //poll invalidate
|
---|
| 84 |
|
---|
| 85 | PL310_Sync();
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | //Enable Cache
|
---|
| 89 | void PL310_Enable(void)
|
---|
| 90 | {
|
---|
| 91 | PL310->CONTROL = 0;
|
---|
| 92 | PL310->INTERRUPT_CLEAR = 0x000001FFuL;
|
---|
| 93 | PL310->DEBUG_CONTROL = 0;
|
---|
| 94 | PL310->DATA_LOCK_0_WAY = 0;
|
---|
| 95 | PL310->CACHE_SYNC = 0;
|
---|
| 96 |
|
---|
| 97 | PL310->CONTROL = 0x01;
|
---|
| 98 | PL310_Sync();
|
---|
| 99 | }
|
---|
| 100 | //Disable Cache
|
---|
| 101 | void PL310_Disable(void)
|
---|
| 102 | {
|
---|
| 103 | PL310->CONTROL = 0x00;
|
---|
| 104 | PL310_Sync();
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | //Invalidate cache by physical address
|
---|
| 108 | void PL310_InvPa (void *pa)
|
---|
| 109 | {
|
---|
| 110 | PL310->INV_LINE_PA = (unsigned int)pa;
|
---|
| 111 | PL310_Sync();
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | //Clean cache by physical address
|
---|
| 115 | void PL310_CleanPa (void *pa)
|
---|
| 116 | {
|
---|
| 117 | PL310->CLEAN_LINE_PA = (unsigned int)pa;
|
---|
| 118 | PL310_Sync();
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | //Clean and invalidate cache by physical address
|
---|
| 122 | void PL310_CleanInvPa (void *pa)
|
---|
| 123 | {
|
---|
| 124 | PL310->CLEAN_INV_LINE_PA = (unsigned int)pa;
|
---|
| 125 | PL310_Sync();
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 |
|
---|