14ecca339SDan Handley/* 24ecca339SDan Handley * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved. 34ecca339SDan Handley * 44ecca339SDan Handley * Redistribution and use in source and binary forms, with or without 54ecca339SDan Handley * modification, are permitted provided that the following conditions are met: 64ecca339SDan Handley * 74ecca339SDan Handley * Redistributions of source code must retain the above copyright notice, this 84ecca339SDan Handley * list of conditions and the following disclaimer. 94ecca339SDan Handley * 104ecca339SDan Handley * Redistributions in binary form must reproduce the above copyright notice, 114ecca339SDan Handley * this list of conditions and the following disclaimer in the documentation 124ecca339SDan Handley * and/or other materials provided with the distribution. 134ecca339SDan Handley * 144ecca339SDan Handley * Neither the name of ARM nor the names of its contributors may be used 154ecca339SDan Handley * to endorse or promote products derived from this software without specific 164ecca339SDan Handley * prior written permission. 174ecca339SDan Handley * 184ecca339SDan Handley * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 194ecca339SDan Handley * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 204ecca339SDan Handley * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 214ecca339SDan Handley * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 224ecca339SDan Handley * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 234ecca339SDan Handley * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 244ecca339SDan Handley * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 254ecca339SDan Handley * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 264ecca339SDan Handley * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 274ecca339SDan Handley * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 284ecca339SDan Handley * POSSIBILITY OF SUCH DAMAGE. 294ecca339SDan Handley */ 304ecca339SDan Handley 3197043ac9SDan Handley#include <arch.h> 324ecca339SDan Handley#include <asm_macros.S> 334ecca339SDan Handley 344ecca339SDan Handley .globl flush_dcache_range 354ecca339SDan Handley .globl inv_dcache_range 364ecca339SDan Handley .globl dcsw_op_louis 374ecca339SDan Handley .globl dcsw_op_all 38*8e857916SSoby Mathew .globl dcsw_op_level1 39*8e857916SSoby Mathew .globl dcsw_op_level2 40*8e857916SSoby Mathew .globl dcsw_op_level3 414ecca339SDan Handley 424ecca339SDan Handley /* ------------------------------------------ 434ecca339SDan Handley * Clean+Invalidate from base address till 444ecca339SDan Handley * size. 'x0' = addr, 'x1' = size 454ecca339SDan Handley * ------------------------------------------ 464ecca339SDan Handley */ 474ecca339SDan Handleyfunc flush_dcache_range 484ecca339SDan Handley dcache_line_size x2, x3 494ecca339SDan Handley add x1, x0, x1 504ecca339SDan Handley sub x3, x2, #1 514ecca339SDan Handley bic x0, x0, x3 524ecca339SDan Handleyflush_loop: 534ecca339SDan Handley dc civac, x0 544ecca339SDan Handley add x0, x0, x2 554ecca339SDan Handley cmp x0, x1 564ecca339SDan Handley b.lo flush_loop 574ecca339SDan Handley dsb sy 584ecca339SDan Handley ret 594ecca339SDan Handley 604ecca339SDan Handley 614ecca339SDan Handley /* ------------------------------------------ 624ecca339SDan Handley * Invalidate from base address till 634ecca339SDan Handley * size. 'x0' = addr, 'x1' = size 644ecca339SDan Handley * ------------------------------------------ 654ecca339SDan Handley */ 664ecca339SDan Handleyfunc inv_dcache_range 674ecca339SDan Handley dcache_line_size x2, x3 684ecca339SDan Handley add x1, x0, x1 694ecca339SDan Handley sub x3, x2, #1 704ecca339SDan Handley bic x0, x0, x3 714ecca339SDan Handleyinv_loop: 724ecca339SDan Handley dc ivac, x0 734ecca339SDan Handley add x0, x0, x2 744ecca339SDan Handley cmp x0, x1 754ecca339SDan Handley b.lo inv_loop 764ecca339SDan Handley dsb sy 774ecca339SDan Handley ret 784ecca339SDan Handley 794ecca339SDan Handley 805f6032a8SAndrew Thoelke /* --------------------------------------------------------------- 815f6032a8SAndrew Thoelke * Data cache operations by set/way to the level specified 825f6032a8SAndrew Thoelke * 835f6032a8SAndrew Thoelke * The main function, do_dcsw_op requires: 845f6032a8SAndrew Thoelke * x0: The operation type (0-2), as defined in arch.h 855f6032a8SAndrew Thoelke * x3: The last cache level to operate on 865f6032a8SAndrew Thoelke * x9: clidr_el1 87*8e857916SSoby Mathew * x10: The cache level to begin operation from 885f6032a8SAndrew Thoelke * and will carry out the operation on each data cache from level 0 895f6032a8SAndrew Thoelke * to the level in x3 in sequence 905f6032a8SAndrew Thoelke * 915f6032a8SAndrew Thoelke * The dcsw_op macro sets up the x3 and x9 parameters based on 925f6032a8SAndrew Thoelke * clidr_el1 cache information before invoking the main function 935f6032a8SAndrew Thoelke * --------------------------------------------------------------- 944ecca339SDan Handley */ 955f6032a8SAndrew Thoelke 965f6032a8SAndrew Thoelke .macro dcsw_op shift, fw, ls 975f6032a8SAndrew Thoelke mrs x9, clidr_el1 985f6032a8SAndrew Thoelke ubfx x3, x9, \shift, \fw 995f6032a8SAndrew Thoelke lsl x3, x3, \ls 100*8e857916SSoby Mathew mov x10, xzr 1015f6032a8SAndrew Thoelke b do_dcsw_op 1025f6032a8SAndrew Thoelke .endm 1035f6032a8SAndrew Thoelke 1045f6032a8SAndrew Thoelkefunc do_dcsw_op 1055f6032a8SAndrew Thoelke cbz x3, exit 1065f6032a8SAndrew Thoelke adr x14, dcsw_loop_table // compute inner loop address 1075f6032a8SAndrew Thoelke add x14, x14, x0, lsl #5 // inner loop is 8x32-bit instructions 1085f6032a8SAndrew Thoelke mov x0, x9 1095f6032a8SAndrew Thoelke mov w8, #1 1105f6032a8SAndrew Thoelkeloop1: 1114ecca339SDan Handley add x2, x10, x10, lsr #1 // work out 3x current cache level 1124ecca339SDan Handley lsr x1, x0, x2 // extract cache type bits from clidr 1135f6032a8SAndrew Thoelke and x1, x1, #7 // mask the bits for current cache only 1144ecca339SDan Handley cmp x1, #2 // see what cache we have at this level 1155f6032a8SAndrew Thoelke b.lt level_done // nothing to do if no cache or icache 1165f6032a8SAndrew Thoelke 1174ecca339SDan Handley msr csselr_el1, x10 // select current cache level in csselr 1184ecca339SDan Handley isb // isb to sych the new cssr&csidr 1194ecca339SDan Handley mrs x1, ccsidr_el1 // read the new ccsidr 1204ecca339SDan Handley and x2, x1, #7 // extract the length of the cache lines 1214ecca339SDan Handley add x2, x2, #4 // add 4 (line length offset) 1225f6032a8SAndrew Thoelke ubfx x4, x1, #3, #10 // maximum way number 1235f6032a8SAndrew Thoelke clz w5, w4 // bit position of way size increment 1245f6032a8SAndrew Thoelke lsl w9, w4, w5 // w9 = aligned max way number 1255f6032a8SAndrew Thoelke lsl w16, w8, w5 // w16 = way number loop decrement 1265f6032a8SAndrew Thoelke orr w9, w10, w9 // w9 = combine way and cache number 1275f6032a8SAndrew Thoelke ubfx w6, w1, #13, #15 // w6 = max set number 1285f6032a8SAndrew Thoelke lsl w17, w8, w2 // w17 = set number loop decrement 1295f6032a8SAndrew Thoelke dsb sy // barrier before we start this level 1305f6032a8SAndrew Thoelke br x14 // jump to DC operation specific loop 1315f6032a8SAndrew Thoelke 1325f6032a8SAndrew Thoelke .macro dcsw_loop _op 1335f6032a8SAndrew Thoelkeloop2_\_op: 1345f6032a8SAndrew Thoelke lsl w7, w6, w2 // w7 = aligned max set number 1355f6032a8SAndrew Thoelke 1365f6032a8SAndrew Thoelkeloop3_\_op: 1375f6032a8SAndrew Thoelke orr w11, w9, w7 // combine cache, way and set number 1385f6032a8SAndrew Thoelke dc \_op, x11 1395f6032a8SAndrew Thoelke subs w7, w7, w17 // decrement set number 1405f6032a8SAndrew Thoelke b.ge loop3_\_op 1415f6032a8SAndrew Thoelke 1425f6032a8SAndrew Thoelke subs x9, x9, x16 // decrement way number 1435f6032a8SAndrew Thoelke b.ge loop2_\_op 1445f6032a8SAndrew Thoelke 1455f6032a8SAndrew Thoelke b level_done 1465f6032a8SAndrew Thoelke .endm 1475f6032a8SAndrew Thoelke 1485f6032a8SAndrew Thoelkelevel_done: 1494ecca339SDan Handley add x10, x10, #2 // increment cache number 1504ecca339SDan Handley cmp x3, x10 1515f6032a8SAndrew Thoelke b.gt loop1 1525f6032a8SAndrew Thoelke msr csselr_el1, xzr // select cache level 0 in csselr 1535f6032a8SAndrew Thoelke dsb sy // barrier to complete final cache operation 1544ecca339SDan Handley isb 1554ecca339SDan Handleyexit: 1564ecca339SDan Handley ret 1574ecca339SDan Handley 1585f6032a8SAndrew Thoelkedcsw_loop_table: 1595f6032a8SAndrew Thoelke dcsw_loop isw 1605f6032a8SAndrew Thoelke dcsw_loop cisw 1615f6032a8SAndrew Thoelke dcsw_loop csw 1625f6032a8SAndrew Thoelke 1634ecca339SDan Handley 1644ecca339SDan Handleyfunc dcsw_op_louis 1655f6032a8SAndrew Thoelke dcsw_op #LOUIS_SHIFT, #CLIDR_FIELD_WIDTH, #LEVEL_SHIFT 1664ecca339SDan Handley 1674ecca339SDan Handley 1684ecca339SDan Handleyfunc dcsw_op_all 1695f6032a8SAndrew Thoelke dcsw_op #LOC_SHIFT, #CLIDR_FIELD_WIDTH, #LEVEL_SHIFT 170*8e857916SSoby Mathew 171*8e857916SSoby Mathew /* --------------------------------------------------------------- 172*8e857916SSoby Mathew * Helper macro for data cache operations by set/way for the 173*8e857916SSoby Mathew * level specified 174*8e857916SSoby Mathew * --------------------------------------------------------------- 175*8e857916SSoby Mathew */ 176*8e857916SSoby Mathew .macro dcsw_op_level level 177*8e857916SSoby Mathew mrs x9, clidr_el1 178*8e857916SSoby Mathew mov x3, \level 179*8e857916SSoby Mathew sub x10, x3, #2 180*8e857916SSoby Mathew b do_dcsw_op 181*8e857916SSoby Mathew .endm 182*8e857916SSoby Mathew 183*8e857916SSoby Mathew /* --------------------------------------------------------------- 184*8e857916SSoby Mathew * Data cache operations by set/way for level 1 cache 185*8e857916SSoby Mathew * 186*8e857916SSoby Mathew * The main function, do_dcsw_op requires: 187*8e857916SSoby Mathew * x0: The operation type (0-2), as defined in arch.h 188*8e857916SSoby Mathew * --------------------------------------------------------------- 189*8e857916SSoby Mathew */ 190*8e857916SSoby Mathewfunc dcsw_op_level1 191*8e857916SSoby Mathew dcsw_op_level #(1 << LEVEL_SHIFT) 192*8e857916SSoby Mathew 193*8e857916SSoby Mathew /* --------------------------------------------------------------- 194*8e857916SSoby Mathew * Data cache operations by set/way for level 2 cache 195*8e857916SSoby Mathew * 196*8e857916SSoby Mathew * The main function, do_dcsw_op requires: 197*8e857916SSoby Mathew * x0: The operation type (0-2), as defined in arch.h 198*8e857916SSoby Mathew * --------------------------------------------------------------- 199*8e857916SSoby Mathew */ 200*8e857916SSoby Mathewfunc dcsw_op_level2 201*8e857916SSoby Mathew dcsw_op_level #(2 << LEVEL_SHIFT) 202*8e857916SSoby Mathew 203*8e857916SSoby Mathew /* --------------------------------------------------------------- 204*8e857916SSoby Mathew * Data cache operations by set/way for level 3 cache 205*8e857916SSoby Mathew * 206*8e857916SSoby Mathew * The main function, do_dcsw_op requires: 207*8e857916SSoby Mathew * x0: The operation type (0-2), as defined in arch.h 208*8e857916SSoby Mathew * --------------------------------------------------------------- 209*8e857916SSoby Mathew */ 210*8e857916SSoby Mathewfunc dcsw_op_level3 211*8e857916SSoby Mathew dcsw_op_level #(3 << LEVEL_SHIFT) 212