|
| 1 | +/* Copyright (c) 2009 - 2012 ARM LIMITED |
| 2 | + |
| 3 | + All rights reserved. |
| 4 | + Redistribution and use in source and binary forms, with or without |
| 5 | + modification, are permitted provided that the following conditions are met: |
| 6 | + - Redistributions of source code must retain the above copyright |
| 7 | + notice, this list of conditions and the following disclaimer. |
| 8 | + - Redistributions in binary form must reproduce the above copyright |
| 9 | + notice, this list of conditions and the following disclaimer in the |
| 10 | + documentation and/or other materials provided with the distribution. |
| 11 | + - Neither the name of ARM nor the names of its contributors may be used |
| 12 | + to endorse or promote products derived from this software without |
| 13 | + specific prior written permission. |
| 14 | + * |
| 15 | + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 16 | + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 17 | + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 18 | + ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE |
| 19 | + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 20 | + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 21 | + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 22 | + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 23 | + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 24 | + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 25 | + POSSIBILITY OF SUCH DAMAGE. |
| 26 | + ---------------------------------------------------------------------------*/ |
| 27 | + |
| 28 | +/*---------------------------------------------------------------------------- |
| 29 | + * Functions |
| 30 | + *---------------------------------------------------------------------------*/ |
| 31 | + SECTION `.text`:CODE:NOROOT(2) |
| 32 | + arm |
| 33 | + PUBLIC __v7_all_cache |
| 34 | +/* |
| 35 | + * __STATIC_ASM void __v7_all_cache(uint32_t op) { |
| 36 | + */ |
| 37 | + |
| 38 | +__v7_all_cache: |
| 39 | + |
| 40 | + |
| 41 | + PUSH {R4-R11} |
| 42 | + |
| 43 | + MRC p15, 1, R6, c0, c0, 1 /* Read CLIDR */ |
| 44 | + ANDS R3, R6, #0x07000000 /* Extract coherency level */ |
| 45 | + MOV R3, R3, LSR #23 /* Total cache levels << 1 */ |
| 46 | + BEQ Finished /* If 0, no need to clean */ |
| 47 | + |
| 48 | + MOV R10, #0 /* R10 holds current cache level << 1 */ |
| 49 | +Loop1: ADD R2, R10, R10, LSR #1 /* R2 holds cache "Set" position */ |
| 50 | + MOV R1, R6, LSR R2 /* Bottom 3 bits are the Cache-type for this level */ |
| 51 | + AND R1, R1, #7 /* Isolate those lower 3 bits */ |
| 52 | + CMP R1, #2 |
| 53 | + BLT Skip /* No cache or only instruction cache at this level */ |
| 54 | + |
| 55 | + MCR p15, 2, R10, c0, c0, 0 /* Write the Cache Size selection register */ |
| 56 | + ISB /* ISB to sync the change to the CacheSizeID reg */ |
| 57 | + MRC p15, 1, R1, c0, c0, 0 /* Reads current Cache Size ID register */ |
| 58 | + AND R2, R1, #7 /* Extract the line length field */ |
| 59 | + ADD R2, R2, #4 /* Add 4 for the line length offset (log2 16 bytes) */ |
| 60 | + LDR R4, =0x3FF |
| 61 | + ANDS R4, R4, R1, LSR #3 /* R4 is the max number on the way size (right aligned) */ |
| 62 | + CLZ R5, R4 /* R5 is the bit position of the way size increment */ |
| 63 | + LDR R7, =0x7FFF |
| 64 | + ANDS R7, R7, R1, LSR #13 /* R7 is the max number of the index size (right aligned) */ |
| 65 | + |
| 66 | +Loop2: MOV R9, R4 /* R9 working copy of the max way size (right aligned) */ |
| 67 | + |
| 68 | +Loop3: ORR R11, R10, R9, LSL R5 /* Factor in the Way number and cache number into R11 */ |
| 69 | + ORR R11, R11, R7, LSL R2 /* Factor in the Set number */ |
| 70 | + CMP R0, #0 |
| 71 | + BNE Dccsw |
| 72 | + MCR p15, 0, R11, c7, c6, 2 /* DCISW. Invalidate by Set/Way */ |
| 73 | + B cont |
| 74 | +Dccsw: CMP R0, #1 |
| 75 | + BNE Dccisw |
| 76 | + MCR p15, 0, R11, c7, c10, 2 /* DCCSW. Clean by Set/Way */ |
| 77 | + B cont |
| 78 | +Dccisw: MCR p15, 0, R11, c7, c14, 2 /* DCCISW, Clean and Invalidate by Set/Way */ |
| 79 | +cont: SUBS R9, R9, #1 /* Decrement the Way number */ |
| 80 | + BGE Loop3 |
| 81 | + SUBS R7, R7, #1 /* Decrement the Set number */ |
| 82 | + BGE Loop2 |
| 83 | +Skip: ADD R10, R10, #2 /* increment the cache number */ |
| 84 | + CMP R3, R10 |
| 85 | + BGT Loop1 |
| 86 | + |
| 87 | +Finished: |
| 88 | + DSB |
| 89 | + POP {R4-R11} |
| 90 | + BX lr |
| 91 | + |
| 92 | + |
| 93 | + END |
| 94 | +/*---------------------------------------------------------------------------- |
| 95 | + * end of file |
| 96 | + *---------------------------------------------------------------------------*/ |
| 97 | + |
0 commit comments