1*c978b524SChris Zankel /* 2*c978b524SChris Zankel * Copyright (C) 2006 Tensilica Inc. 3*c978b524SChris Zankel * Copyright (C) 2014 - 2016 Cadence Design Systems Inc. 4*c978b524SChris Zankel * 5*c978b524SChris Zankel * SPDX-License-Identifier: GPL-2.0+ 6*c978b524SChris Zankel */ 7*c978b524SChris Zankel 8*c978b524SChris Zankel #ifndef _XTENSA_CACHEASM_H 9*c978b524SChris Zankel #define _XTENSA_CACHEASM_H 10*c978b524SChris Zankel 11*c978b524SChris Zankel #include <asm/cache.h> 12*c978b524SChris Zankel #include <asm/asmmacro.h> 13*c978b524SChris Zankel #include <linux/stringify.h> 14*c978b524SChris Zankel 15*c978b524SChris Zankel #define PAGE_SIZE 4096 16*c978b524SChris Zankel #define DCACHE_WAY_SIZE (XCHAL_DCACHE_SIZE/XCHAL_DCACHE_WAYS) 17*c978b524SChris Zankel #define ICACHE_WAY_SIZE (XCHAL_ICACHE_SIZE/XCHAL_ICACHE_WAYS) 18*c978b524SChris Zankel #define DCACHE_WAY_SHIFT (XCHAL_DCACHE_SETWIDTH + XCHAL_DCACHE_LINEWIDTH) 19*c978b524SChris Zankel #define ICACHE_WAY_SHIFT (XCHAL_ICACHE_SETWIDTH + XCHAL_ICACHE_LINEWIDTH) 20*c978b524SChris Zankel 21*c978b524SChris Zankel /* 22*c978b524SChris Zankel * Define cache functions as macros here so that they can be used 23*c978b524SChris Zankel * by the kernel and boot loader. We should consider moving them to a 24*c978b524SChris Zankel * library that can be linked by both. 25*c978b524SChris Zankel * 26*c978b524SChris Zankel * Locking 27*c978b524SChris Zankel * 28*c978b524SChris Zankel * ___unlock_dcache_all 29*c978b524SChris Zankel * ___unlock_icache_all 30*c978b524SChris Zankel * 31*c978b524SChris Zankel * Flush and invaldating 32*c978b524SChris Zankel * 33*c978b524SChris Zankel * ___flush_invalidate_dcache_{all|range|page} 34*c978b524SChris Zankel * ___flush_dcache_{all|range|page} 35*c978b524SChris Zankel * ___invalidate_dcache_{all|range|page} 36*c978b524SChris Zankel * ___invalidate_icache_{all|range|page} 37*c978b524SChris Zankel * 38*c978b524SChris Zankel */ 39*c978b524SChris Zankel 40*c978b524SChris Zankel .macro __loop_cache_all ar at insn size line_width 41*c978b524SChris Zankel 42*c978b524SChris Zankel movi \ar, 0 43*c978b524SChris Zankel 44*c978b524SChris Zankel __loopi \ar, \at, \size, (4 << (\line_width)) 45*c978b524SChris Zankel 46*c978b524SChris Zankel \insn \ar, 0 << (\line_width) 47*c978b524SChris Zankel \insn \ar, 1 << (\line_width) 48*c978b524SChris Zankel \insn \ar, 2 << (\line_width) 49*c978b524SChris Zankel \insn \ar, 3 << (\line_width) 50*c978b524SChris Zankel 51*c978b524SChris Zankel __endla \ar, \at, 4 << (\line_width) 52*c978b524SChris Zankel 53*c978b524SChris Zankel .endm 54*c978b524SChris Zankel 55*c978b524SChris Zankel 56*c978b524SChris Zankel .macro __loop_cache_range ar as at insn line_width 57*c978b524SChris Zankel 58*c978b524SChris Zankel extui \at, \ar, 0, \line_width 59*c978b524SChris Zankel add \as, \as, \at 60*c978b524SChris Zankel 61*c978b524SChris Zankel __loops \ar, \as, \at, \line_width 62*c978b524SChris Zankel \insn \ar, 0 63*c978b524SChris Zankel __endla \ar, \at, (1 << (\line_width)) 64*c978b524SChris Zankel 65*c978b524SChris Zankel .endm 66*c978b524SChris Zankel 67*c978b524SChris Zankel 68*c978b524SChris Zankel .macro __loop_cache_page ar at insn line_width 69*c978b524SChris Zankel 70*c978b524SChris Zankel __loopi \ar, \at, PAGE_SIZE, 4 << (\line_width) 71*c978b524SChris Zankel 72*c978b524SChris Zankel \insn \ar, 0 << (\line_width) 73*c978b524SChris Zankel \insn \ar, 1 << (\line_width) 74*c978b524SChris Zankel \insn \ar, 2 << (\line_width) 75*c978b524SChris Zankel \insn \ar, 3 << (\line_width) 76*c978b524SChris Zankel 77*c978b524SChris Zankel __endla \ar, \at, 4 << (\line_width) 78*c978b524SChris Zankel 79*c978b524SChris Zankel .endm 80*c978b524SChris Zankel 81*c978b524SChris Zankel 82*c978b524SChris Zankel .macro ___unlock_dcache_all ar at 83*c978b524SChris Zankel 84*c978b524SChris Zankel #if XCHAL_DCACHE_LINE_LOCKABLE && XCHAL_DCACHE_SIZE 85*c978b524SChris Zankel __loop_cache_all \ar \at diu XCHAL_DCACHE_SIZE XCHAL_DCACHE_LINEWIDTH 86*c978b524SChris Zankel #endif 87*c978b524SChris Zankel 88*c978b524SChris Zankel .endm 89*c978b524SChris Zankel 90*c978b524SChris Zankel 91*c978b524SChris Zankel .macro ___unlock_icache_all ar at 92*c978b524SChris Zankel 93*c978b524SChris Zankel #if XCHAL_ICACHE_LINE_LOCKABLE && XCHAL_ICACHE_SIZE 94*c978b524SChris Zankel __loop_cache_all \ar \at iiu XCHAL_ICACHE_SIZE XCHAL_ICACHE_LINEWIDTH 95*c978b524SChris Zankel #endif 96*c978b524SChris Zankel 97*c978b524SChris Zankel .endm 98*c978b524SChris Zankel 99*c978b524SChris Zankel 100*c978b524SChris Zankel .macro ___flush_invalidate_dcache_all ar at 101*c978b524SChris Zankel 102*c978b524SChris Zankel #if XCHAL_DCACHE_SIZE 103*c978b524SChris Zankel __loop_cache_all \ar \at diwbi XCHAL_DCACHE_SIZE XCHAL_DCACHE_LINEWIDTH 104*c978b524SChris Zankel #endif 105*c978b524SChris Zankel 106*c978b524SChris Zankel .endm 107*c978b524SChris Zankel 108*c978b524SChris Zankel 109*c978b524SChris Zankel .macro ___flush_dcache_all ar at 110*c978b524SChris Zankel 111*c978b524SChris Zankel #if XCHAL_DCACHE_SIZE 112*c978b524SChris Zankel __loop_cache_all \ar \at diwb XCHAL_DCACHE_SIZE XCHAL_DCACHE_LINEWIDTH 113*c978b524SChris Zankel #endif 114*c978b524SChris Zankel 115*c978b524SChris Zankel .endm 116*c978b524SChris Zankel 117*c978b524SChris Zankel 118*c978b524SChris Zankel .macro ___invalidate_dcache_all ar at 119*c978b524SChris Zankel 120*c978b524SChris Zankel #if XCHAL_DCACHE_SIZE 121*c978b524SChris Zankel __loop_cache_all \ar \at dii __stringify(DCACHE_WAY_SIZE) \ 122*c978b524SChris Zankel XCHAL_DCACHE_LINEWIDTH 123*c978b524SChris Zankel #endif 124*c978b524SChris Zankel 125*c978b524SChris Zankel .endm 126*c978b524SChris Zankel 127*c978b524SChris Zankel 128*c978b524SChris Zankel .macro ___invalidate_icache_all ar at 129*c978b524SChris Zankel 130*c978b524SChris Zankel #if XCHAL_ICACHE_SIZE 131*c978b524SChris Zankel __loop_cache_all \ar \at iii __stringify(ICACHE_WAY_SIZE) \ 132*c978b524SChris Zankel XCHAL_ICACHE_LINEWIDTH 133*c978b524SChris Zankel #endif 134*c978b524SChris Zankel 135*c978b524SChris Zankel .endm 136*c978b524SChris Zankel 137*c978b524SChris Zankel 138*c978b524SChris Zankel 139*c978b524SChris Zankel .macro ___flush_invalidate_dcache_range ar as at 140*c978b524SChris Zankel 141*c978b524SChris Zankel #if XCHAL_DCACHE_SIZE 142*c978b524SChris Zankel __loop_cache_range \ar \as \at dhwbi XCHAL_DCACHE_LINEWIDTH 143*c978b524SChris Zankel #endif 144*c978b524SChris Zankel 145*c978b524SChris Zankel .endm 146*c978b524SChris Zankel 147*c978b524SChris Zankel 148*c978b524SChris Zankel .macro ___flush_dcache_range ar as at 149*c978b524SChris Zankel 150*c978b524SChris Zankel #if XCHAL_DCACHE_SIZE 151*c978b524SChris Zankel __loop_cache_range \ar \as \at dhwb XCHAL_DCACHE_LINEWIDTH 152*c978b524SChris Zankel #endif 153*c978b524SChris Zankel 154*c978b524SChris Zankel .endm 155*c978b524SChris Zankel 156*c978b524SChris Zankel 157*c978b524SChris Zankel .macro ___invalidate_dcache_range ar as at 158*c978b524SChris Zankel 159*c978b524SChris Zankel #if XCHAL_DCACHE_SIZE 160*c978b524SChris Zankel __loop_cache_range \ar \as \at dhi XCHAL_DCACHE_LINEWIDTH 161*c978b524SChris Zankel #endif 162*c978b524SChris Zankel 163*c978b524SChris Zankel .endm 164*c978b524SChris Zankel 165*c978b524SChris Zankel 166*c978b524SChris Zankel .macro ___invalidate_icache_range ar as at 167*c978b524SChris Zankel 168*c978b524SChris Zankel #if XCHAL_ICACHE_SIZE 169*c978b524SChris Zankel __loop_cache_range \ar \as \at ihi XCHAL_ICACHE_LINEWIDTH 170*c978b524SChris Zankel #endif 171*c978b524SChris Zankel 172*c978b524SChris Zankel .endm 173*c978b524SChris Zankel 174*c978b524SChris Zankel 175*c978b524SChris Zankel 176*c978b524SChris Zankel .macro ___flush_invalidate_dcache_page ar as 177*c978b524SChris Zankel 178*c978b524SChris Zankel #if XCHAL_DCACHE_SIZE 179*c978b524SChris Zankel __loop_cache_page \ar \as dhwbi XCHAL_DCACHE_LINEWIDTH 180*c978b524SChris Zankel #endif 181*c978b524SChris Zankel 182*c978b524SChris Zankel .endm 183*c978b524SChris Zankel 184*c978b524SChris Zankel 185*c978b524SChris Zankel .macro ___flush_dcache_page ar as 186*c978b524SChris Zankel 187*c978b524SChris Zankel #if XCHAL_DCACHE_SIZE 188*c978b524SChris Zankel __loop_cache_page \ar \as dhwb XCHAL_DCACHE_LINEWIDTH 189*c978b524SChris Zankel #endif 190*c978b524SChris Zankel 191*c978b524SChris Zankel .endm 192*c978b524SChris Zankel 193*c978b524SChris Zankel 194*c978b524SChris Zankel .macro ___invalidate_dcache_page ar as 195*c978b524SChris Zankel 196*c978b524SChris Zankel #if XCHAL_DCACHE_SIZE 197*c978b524SChris Zankel __loop_cache_page \ar \as dhi XCHAL_DCACHE_LINEWIDTH 198*c978b524SChris Zankel #endif 199*c978b524SChris Zankel 200*c978b524SChris Zankel .endm 201*c978b524SChris Zankel 202*c978b524SChris Zankel 203*c978b524SChris Zankel .macro ___invalidate_icache_page ar as 204*c978b524SChris Zankel 205*c978b524SChris Zankel #if XCHAL_ICACHE_SIZE 206*c978b524SChris Zankel __loop_cache_page \ar \as ihi XCHAL_ICACHE_LINEWIDTH 207*c978b524SChris Zankel #endif 208*c978b524SChris Zankel 209*c978b524SChris Zankel .endm 210*c978b524SChris Zankel 211*c978b524SChris Zankel #endif /* _XTENSA_CACHEASM_H */ 212