1*4ecca339SDan Handley/* 2*4ecca339SDan Handley * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved. 3*4ecca339SDan Handley * 4*4ecca339SDan Handley * Redistribution and use in source and binary forms, with or without 5*4ecca339SDan Handley * modification, are permitted provided that the following conditions are met: 6*4ecca339SDan Handley * 7*4ecca339SDan Handley * Redistributions of source code must retain the above copyright notice, this 8*4ecca339SDan Handley * list of conditions and the following disclaimer. 9*4ecca339SDan Handley * 10*4ecca339SDan Handley * Redistributions in binary form must reproduce the above copyright notice, 11*4ecca339SDan Handley * this list of conditions and the following disclaimer in the documentation 12*4ecca339SDan Handley * and/or other materials provided with the distribution. 13*4ecca339SDan Handley * 14*4ecca339SDan Handley * Neither the name of ARM nor the names of its contributors may be used 15*4ecca339SDan Handley * to endorse or promote products derived from this software without specific 16*4ecca339SDan Handley * prior written permission. 17*4ecca339SDan Handley * 18*4ecca339SDan Handley * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19*4ecca339SDan Handley * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20*4ecca339SDan Handley * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21*4ecca339SDan Handley * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22*4ecca339SDan Handley * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23*4ecca339SDan Handley * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24*4ecca339SDan Handley * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25*4ecca339SDan Handley * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26*4ecca339SDan Handley * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27*4ecca339SDan Handley * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28*4ecca339SDan Handley * POSSIBILITY OF SUCH DAMAGE. 29*4ecca339SDan Handley */ 30*4ecca339SDan Handley 31*4ecca339SDan Handley#include <arch_helpers.h> 32*4ecca339SDan Handley#include <asm_macros.S> 33*4ecca339SDan Handley 34*4ecca339SDan Handley .globl dcisw 35*4ecca339SDan Handley .globl dccisw 36*4ecca339SDan Handley .globl dccsw 37*4ecca339SDan Handley .globl dccvac 38*4ecca339SDan Handley .globl dcivac 39*4ecca339SDan Handley .globl dccivac 40*4ecca339SDan Handley .globl dccvau 41*4ecca339SDan Handley .globl dczva 42*4ecca339SDan Handley .globl flush_dcache_range 43*4ecca339SDan Handley .globl inv_dcache_range 44*4ecca339SDan Handley .globl dcsw_op_louis 45*4ecca339SDan Handley .globl dcsw_op_all 46*4ecca339SDan Handley 47*4ecca339SDan Handleyfunc dcisw 48*4ecca339SDan Handley dc isw, x0 49*4ecca339SDan Handley dsb sy 50*4ecca339SDan Handley isb 51*4ecca339SDan Handley ret 52*4ecca339SDan Handley 53*4ecca339SDan Handley 54*4ecca339SDan Handleyfunc dccisw 55*4ecca339SDan Handley dc cisw, x0 56*4ecca339SDan Handley dsb sy 57*4ecca339SDan Handley isb 58*4ecca339SDan Handley ret 59*4ecca339SDan Handley 60*4ecca339SDan Handley 61*4ecca339SDan Handleyfunc dccsw 62*4ecca339SDan Handley dc csw, x0 63*4ecca339SDan Handley dsb sy 64*4ecca339SDan Handley isb 65*4ecca339SDan Handley ret 66*4ecca339SDan Handley 67*4ecca339SDan Handley 68*4ecca339SDan Handleyfunc dccvac 69*4ecca339SDan Handley dc cvac, x0 70*4ecca339SDan Handley dsb sy 71*4ecca339SDan Handley isb 72*4ecca339SDan Handley ret 73*4ecca339SDan Handley 74*4ecca339SDan Handley 75*4ecca339SDan Handleyfunc dcivac 76*4ecca339SDan Handley dc ivac, x0 77*4ecca339SDan Handley dsb sy 78*4ecca339SDan Handley isb 79*4ecca339SDan Handley ret 80*4ecca339SDan Handley 81*4ecca339SDan Handley 82*4ecca339SDan Handleyfunc dccivac 83*4ecca339SDan Handley dc civac, x0 84*4ecca339SDan Handley dsb sy 85*4ecca339SDan Handley isb 86*4ecca339SDan Handley ret 87*4ecca339SDan Handley 88*4ecca339SDan Handley 89*4ecca339SDan Handleyfunc dccvau 90*4ecca339SDan Handley dc cvau, x0 91*4ecca339SDan Handley dsb sy 92*4ecca339SDan Handley isb 93*4ecca339SDan Handley ret 94*4ecca339SDan Handley 95*4ecca339SDan Handley 96*4ecca339SDan Handleyfunc dczva 97*4ecca339SDan Handley dc zva, x0 98*4ecca339SDan Handley dsb sy 99*4ecca339SDan Handley isb 100*4ecca339SDan Handley ret 101*4ecca339SDan Handley 102*4ecca339SDan Handley 103*4ecca339SDan Handley /* ------------------------------------------ 104*4ecca339SDan Handley * Clean+Invalidate from base address till 105*4ecca339SDan Handley * size. 'x0' = addr, 'x1' = size 106*4ecca339SDan Handley * ------------------------------------------ 107*4ecca339SDan Handley */ 108*4ecca339SDan Handleyfunc flush_dcache_range 109*4ecca339SDan Handley dcache_line_size x2, x3 110*4ecca339SDan Handley add x1, x0, x1 111*4ecca339SDan Handley sub x3, x2, #1 112*4ecca339SDan Handley bic x0, x0, x3 113*4ecca339SDan Handleyflush_loop: 114*4ecca339SDan Handley dc civac, x0 115*4ecca339SDan Handley add x0, x0, x2 116*4ecca339SDan Handley cmp x0, x1 117*4ecca339SDan Handley b.lo flush_loop 118*4ecca339SDan Handley dsb sy 119*4ecca339SDan Handley ret 120*4ecca339SDan Handley 121*4ecca339SDan Handley 122*4ecca339SDan Handley /* ------------------------------------------ 123*4ecca339SDan Handley * Invalidate from base address till 124*4ecca339SDan Handley * size. 'x0' = addr, 'x1' = size 125*4ecca339SDan Handley * ------------------------------------------ 126*4ecca339SDan Handley */ 127*4ecca339SDan Handleyfunc inv_dcache_range 128*4ecca339SDan Handley dcache_line_size x2, x3 129*4ecca339SDan Handley add x1, x0, x1 130*4ecca339SDan Handley sub x3, x2, #1 131*4ecca339SDan Handley bic x0, x0, x3 132*4ecca339SDan Handleyinv_loop: 133*4ecca339SDan Handley dc ivac, x0 134*4ecca339SDan Handley add x0, x0, x2 135*4ecca339SDan Handley cmp x0, x1 136*4ecca339SDan Handley b.lo inv_loop 137*4ecca339SDan Handley dsb sy 138*4ecca339SDan Handley ret 139*4ecca339SDan Handley 140*4ecca339SDan Handley 141*4ecca339SDan Handley /* ------------------------------------------ 142*4ecca339SDan Handley * Data cache operations by set/way to the 143*4ecca339SDan Handley * level specified 144*4ecca339SDan Handley * ------------------------------------------ 145*4ecca339SDan Handley * ---------------------------------- 146*4ecca339SDan Handley * Call this func with the clidr in 147*4ecca339SDan Handley * x0, starting cache level in x10, 148*4ecca339SDan Handley * last cache level in x3 & cm op in 149*4ecca339SDan Handley * x14 150*4ecca339SDan Handley * ---------------------------------- 151*4ecca339SDan Handley */ 152*4ecca339SDan Handleyfunc dcsw_op 153*4ecca339SDan Handleyall_start_at_level: 154*4ecca339SDan Handley add x2, x10, x10, lsr #1 // work out 3x current cache level 155*4ecca339SDan Handley lsr x1, x0, x2 // extract cache type bits from clidr 156*4ecca339SDan Handley and x1, x1, #7 // mask of the bits for current cache only 157*4ecca339SDan Handley cmp x1, #2 // see what cache we have at this level 158*4ecca339SDan Handley b.lt skip // skip if no cache, or just i-cache 159*4ecca339SDan Handley msr csselr_el1, x10 // select current cache level in csselr 160*4ecca339SDan Handley isb // isb to sych the new cssr&csidr 161*4ecca339SDan Handley mrs x1, ccsidr_el1 // read the new ccsidr 162*4ecca339SDan Handley and x2, x1, #7 // extract the length of the cache lines 163*4ecca339SDan Handley add x2, x2, #4 // add 4 (line length offset) 164*4ecca339SDan Handley mov x4, #0x3ff 165*4ecca339SDan Handley and x4, x4, x1, lsr #3 // find maximum number on the way size 166*4ecca339SDan Handley clz w5, w4 // find bit position of way size increment 167*4ecca339SDan Handley mov x7, #0x7fff 168*4ecca339SDan Handley and x7, x7, x1, lsr #13 // extract max number of the index size 169*4ecca339SDan Handleyloop2: 170*4ecca339SDan Handley mov x9, x4 // create working copy of max way size 171*4ecca339SDan Handleyloop3: 172*4ecca339SDan Handley lsl x6, x9, x5 173*4ecca339SDan Handley orr x11, x10, x6 // factor way and cache number into x11 174*4ecca339SDan Handley lsl x6, x7, x2 175*4ecca339SDan Handley orr x11, x11, x6 // factor index number into x11 176*4ecca339SDan Handley mov x12, x0 177*4ecca339SDan Handley mov x13, x30 // lr 178*4ecca339SDan Handley mov x0, x11 179*4ecca339SDan Handley blr x14 180*4ecca339SDan Handley mov x0, x12 181*4ecca339SDan Handley mov x30, x13 // lr 182*4ecca339SDan Handley subs x9, x9, #1 // decrement the way 183*4ecca339SDan Handley b.ge loop3 184*4ecca339SDan Handley subs x7, x7, #1 // decrement the index 185*4ecca339SDan Handley b.ge loop2 186*4ecca339SDan Handleyskip: 187*4ecca339SDan Handley add x10, x10, #2 // increment cache number 188*4ecca339SDan Handley cmp x3, x10 189*4ecca339SDan Handley b.gt all_start_at_level 190*4ecca339SDan Handleyfinished: 191*4ecca339SDan Handley mov x10, #0 // swith back to cache level 0 192*4ecca339SDan Handley msr csselr_el1, x10 // select current cache level in csselr 193*4ecca339SDan Handley dsb sy 194*4ecca339SDan Handley isb 195*4ecca339SDan Handley ret 196*4ecca339SDan Handley 197*4ecca339SDan Handley 198*4ecca339SDan Handleyfunc do_dcsw_op 199*4ecca339SDan Handley cbz x3, exit 200*4ecca339SDan Handley cmp x0, #DCISW 201*4ecca339SDan Handley b.eq dc_isw 202*4ecca339SDan Handley cmp x0, #DCCISW 203*4ecca339SDan Handley b.eq dc_cisw 204*4ecca339SDan Handley cmp x0, #DCCSW 205*4ecca339SDan Handley b.eq dc_csw 206*4ecca339SDan Handleydc_isw: 207*4ecca339SDan Handley mov x0, x9 208*4ecca339SDan Handley adr x14, dcisw 209*4ecca339SDan Handley b dcsw_op 210*4ecca339SDan Handleydc_cisw: 211*4ecca339SDan Handley mov x0, x9 212*4ecca339SDan Handley adr x14, dccisw 213*4ecca339SDan Handley b dcsw_op 214*4ecca339SDan Handleydc_csw: 215*4ecca339SDan Handley mov x0, x9 216*4ecca339SDan Handley adr x14, dccsw 217*4ecca339SDan Handley b dcsw_op 218*4ecca339SDan Handleyexit: 219*4ecca339SDan Handley ret 220*4ecca339SDan Handley 221*4ecca339SDan Handley 222*4ecca339SDan Handleyfunc dcsw_op_louis 223*4ecca339SDan Handley dsb sy 224*4ecca339SDan Handley setup_dcsw_op_args x10, x3, x9, #LOUIS_SHIFT, #CLIDR_FIELD_WIDTH, #LEVEL_SHIFT 225*4ecca339SDan Handley b do_dcsw_op 226*4ecca339SDan Handley 227*4ecca339SDan Handley 228*4ecca339SDan Handleyfunc dcsw_op_all 229*4ecca339SDan Handley dsb sy 230*4ecca339SDan Handley setup_dcsw_op_args x10, x3, x9, #LOC_SHIFT, #CLIDR_FIELD_WIDTH, #LEVEL_SHIFT 231*4ecca339SDan Handley b do_dcsw_op 232