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 31*97043ac9SDan Handley#include <arch.h> 324ecca339SDan Handley#include <asm_macros.S> 334ecca339SDan Handley 344ecca339SDan Handley .globl dcisw 354ecca339SDan Handley .globl dccisw 364ecca339SDan Handley .globl dccsw 374ecca339SDan Handley .globl dccvac 384ecca339SDan Handley .globl dcivac 394ecca339SDan Handley .globl dccivac 404ecca339SDan Handley .globl dccvau 414ecca339SDan Handley .globl dczva 424ecca339SDan Handley .globl flush_dcache_range 434ecca339SDan Handley .globl inv_dcache_range 444ecca339SDan Handley .globl dcsw_op_louis 454ecca339SDan Handley .globl dcsw_op_all 464ecca339SDan Handley 474ecca339SDan Handleyfunc dcisw 484ecca339SDan Handley dc isw, x0 494ecca339SDan Handley dsb sy 504ecca339SDan Handley isb 514ecca339SDan Handley ret 524ecca339SDan Handley 534ecca339SDan Handley 544ecca339SDan Handleyfunc dccisw 554ecca339SDan Handley dc cisw, x0 564ecca339SDan Handley dsb sy 574ecca339SDan Handley isb 584ecca339SDan Handley ret 594ecca339SDan Handley 604ecca339SDan Handley 614ecca339SDan Handleyfunc dccsw 624ecca339SDan Handley dc csw, x0 634ecca339SDan Handley dsb sy 644ecca339SDan Handley isb 654ecca339SDan Handley ret 664ecca339SDan Handley 674ecca339SDan Handley 684ecca339SDan Handleyfunc dccvac 694ecca339SDan Handley dc cvac, x0 704ecca339SDan Handley dsb sy 714ecca339SDan Handley isb 724ecca339SDan Handley ret 734ecca339SDan Handley 744ecca339SDan Handley 754ecca339SDan Handleyfunc dcivac 764ecca339SDan Handley dc ivac, x0 774ecca339SDan Handley dsb sy 784ecca339SDan Handley isb 794ecca339SDan Handley ret 804ecca339SDan Handley 814ecca339SDan Handley 824ecca339SDan Handleyfunc dccivac 834ecca339SDan Handley dc civac, x0 844ecca339SDan Handley dsb sy 854ecca339SDan Handley isb 864ecca339SDan Handley ret 874ecca339SDan Handley 884ecca339SDan Handley 894ecca339SDan Handleyfunc dccvau 904ecca339SDan Handley dc cvau, x0 914ecca339SDan Handley dsb sy 924ecca339SDan Handley isb 934ecca339SDan Handley ret 944ecca339SDan Handley 954ecca339SDan Handley 964ecca339SDan Handleyfunc dczva 974ecca339SDan Handley dc zva, x0 984ecca339SDan Handley dsb sy 994ecca339SDan Handley isb 1004ecca339SDan Handley ret 1014ecca339SDan Handley 1024ecca339SDan Handley 1034ecca339SDan Handley /* ------------------------------------------ 1044ecca339SDan Handley * Clean+Invalidate from base address till 1054ecca339SDan Handley * size. 'x0' = addr, 'x1' = size 1064ecca339SDan Handley * ------------------------------------------ 1074ecca339SDan Handley */ 1084ecca339SDan Handleyfunc flush_dcache_range 1094ecca339SDan Handley dcache_line_size x2, x3 1104ecca339SDan Handley add x1, x0, x1 1114ecca339SDan Handley sub x3, x2, #1 1124ecca339SDan Handley bic x0, x0, x3 1134ecca339SDan Handleyflush_loop: 1144ecca339SDan Handley dc civac, x0 1154ecca339SDan Handley add x0, x0, x2 1164ecca339SDan Handley cmp x0, x1 1174ecca339SDan Handley b.lo flush_loop 1184ecca339SDan Handley dsb sy 1194ecca339SDan Handley ret 1204ecca339SDan Handley 1214ecca339SDan Handley 1224ecca339SDan Handley /* ------------------------------------------ 1234ecca339SDan Handley * Invalidate from base address till 1244ecca339SDan Handley * size. 'x0' = addr, 'x1' = size 1254ecca339SDan Handley * ------------------------------------------ 1264ecca339SDan Handley */ 1274ecca339SDan Handleyfunc inv_dcache_range 1284ecca339SDan Handley dcache_line_size x2, x3 1294ecca339SDan Handley add x1, x0, x1 1304ecca339SDan Handley sub x3, x2, #1 1314ecca339SDan Handley bic x0, x0, x3 1324ecca339SDan Handleyinv_loop: 1334ecca339SDan Handley dc ivac, x0 1344ecca339SDan Handley add x0, x0, x2 1354ecca339SDan Handley cmp x0, x1 1364ecca339SDan Handley b.lo inv_loop 1374ecca339SDan Handley dsb sy 1384ecca339SDan Handley ret 1394ecca339SDan Handley 1404ecca339SDan Handley 1414ecca339SDan Handley /* ------------------------------------------ 1424ecca339SDan Handley * Data cache operations by set/way to the 1434ecca339SDan Handley * level specified 1444ecca339SDan Handley * ------------------------------------------ 1454ecca339SDan Handley * ---------------------------------- 1464ecca339SDan Handley * Call this func with the clidr in 1474ecca339SDan Handley * x0, starting cache level in x10, 1484ecca339SDan Handley * last cache level in x3 & cm op in 1494ecca339SDan Handley * x14 1504ecca339SDan Handley * ---------------------------------- 1514ecca339SDan Handley */ 1524ecca339SDan Handleyfunc dcsw_op 1534ecca339SDan Handleyall_start_at_level: 1544ecca339SDan Handley add x2, x10, x10, lsr #1 // work out 3x current cache level 1554ecca339SDan Handley lsr x1, x0, x2 // extract cache type bits from clidr 1564ecca339SDan Handley and x1, x1, #7 // mask of the bits for current cache only 1574ecca339SDan Handley cmp x1, #2 // see what cache we have at this level 1584ecca339SDan Handley b.lt skip // skip if no cache, or just i-cache 1594ecca339SDan Handley msr csselr_el1, x10 // select current cache level in csselr 1604ecca339SDan Handley isb // isb to sych the new cssr&csidr 1614ecca339SDan Handley mrs x1, ccsidr_el1 // read the new ccsidr 1624ecca339SDan Handley and x2, x1, #7 // extract the length of the cache lines 1634ecca339SDan Handley add x2, x2, #4 // add 4 (line length offset) 1644ecca339SDan Handley mov x4, #0x3ff 1654ecca339SDan Handley and x4, x4, x1, lsr #3 // find maximum number on the way size 1664ecca339SDan Handley clz w5, w4 // find bit position of way size increment 1674ecca339SDan Handley mov x7, #0x7fff 1684ecca339SDan Handley and x7, x7, x1, lsr #13 // extract max number of the index size 1694ecca339SDan Handleyloop2: 1704ecca339SDan Handley mov x9, x4 // create working copy of max way size 1714ecca339SDan Handleyloop3: 1724ecca339SDan Handley lsl x6, x9, x5 1734ecca339SDan Handley orr x11, x10, x6 // factor way and cache number into x11 1744ecca339SDan Handley lsl x6, x7, x2 1754ecca339SDan Handley orr x11, x11, x6 // factor index number into x11 1764ecca339SDan Handley mov x12, x0 1774ecca339SDan Handley mov x13, x30 // lr 1784ecca339SDan Handley mov x0, x11 1794ecca339SDan Handley blr x14 1804ecca339SDan Handley mov x0, x12 1814ecca339SDan Handley mov x30, x13 // lr 1824ecca339SDan Handley subs x9, x9, #1 // decrement the way 1834ecca339SDan Handley b.ge loop3 1844ecca339SDan Handley subs x7, x7, #1 // decrement the index 1854ecca339SDan Handley b.ge loop2 1864ecca339SDan Handleyskip: 1874ecca339SDan Handley add x10, x10, #2 // increment cache number 1884ecca339SDan Handley cmp x3, x10 1894ecca339SDan Handley b.gt all_start_at_level 1904ecca339SDan Handleyfinished: 1914ecca339SDan Handley mov x10, #0 // swith back to cache level 0 1924ecca339SDan Handley msr csselr_el1, x10 // select current cache level in csselr 1934ecca339SDan Handley dsb sy 1944ecca339SDan Handley isb 1954ecca339SDan Handley ret 1964ecca339SDan Handley 1974ecca339SDan Handley 1984ecca339SDan Handleyfunc do_dcsw_op 1994ecca339SDan Handley cbz x3, exit 2004ecca339SDan Handley cmp x0, #DCISW 2014ecca339SDan Handley b.eq dc_isw 2024ecca339SDan Handley cmp x0, #DCCISW 2034ecca339SDan Handley b.eq dc_cisw 2044ecca339SDan Handley cmp x0, #DCCSW 2054ecca339SDan Handley b.eq dc_csw 2064ecca339SDan Handleydc_isw: 2074ecca339SDan Handley mov x0, x9 2084ecca339SDan Handley adr x14, dcisw 2094ecca339SDan Handley b dcsw_op 2104ecca339SDan Handleydc_cisw: 2114ecca339SDan Handley mov x0, x9 2124ecca339SDan Handley adr x14, dccisw 2134ecca339SDan Handley b dcsw_op 2144ecca339SDan Handleydc_csw: 2154ecca339SDan Handley mov x0, x9 2164ecca339SDan Handley adr x14, dccsw 2174ecca339SDan Handley b dcsw_op 2184ecca339SDan Handleyexit: 2194ecca339SDan Handley ret 2204ecca339SDan Handley 2214ecca339SDan Handley 2224ecca339SDan Handleyfunc dcsw_op_louis 2234ecca339SDan Handley dsb sy 2244ecca339SDan Handley setup_dcsw_op_args x10, x3, x9, #LOUIS_SHIFT, #CLIDR_FIELD_WIDTH, #LEVEL_SHIFT 2254ecca339SDan Handley b do_dcsw_op 2264ecca339SDan Handley 2274ecca339SDan Handley 2284ecca339SDan Handleyfunc dcsw_op_all 2294ecca339SDan Handley dsb sy 2304ecca339SDan Handley setup_dcsw_op_args x10, x3, x9, #LOC_SHIFT, #CLIDR_FIELD_WIDTH, #LEVEL_SHIFT 2314ecca339SDan Handley b do_dcsw_op 232