1173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel/* 2173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel * include/asm-xtensa/cacheasm.h 3173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel * 4173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel * This file is subject to the terms and conditions of the GNU General Public 5173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel * License. See the file "COPYING" in the main directory of this archive 6173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel * for more details. 7173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel * 8173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel * Copyright (C) 2006 Tensilica Inc. 9173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel */ 10173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 11173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel#include <asm/cache.h> 12173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel#include <asm/asmmacro.h> 13173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel#include <linux/stringify.h> 14173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 15173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel/* 16173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel * Define cache functions as macros here so that they can be used 17173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel * by the kernel and boot loader. We should consider moving them to a 18173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel * library that can be linked by both. 19173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel * 20173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel * Locking 21173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel * 22173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel * ___unlock_dcache_all 23173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel * ___unlock_icache_all 24173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel * 25173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel * Flush and invaldating 26173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel * 27173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel * ___flush_invalidate_dcache_{all|range|page} 28173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel * ___flush_dcache_{all|range|page} 29173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel * ___invalidate_dcache_{all|range|page} 30173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel * ___invalidate_icache_{all|range|page} 31173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel * 32173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel */ 33173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 34173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .macro __loop_cache_all ar at insn size line_width 35173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 36173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel movi \ar, 0 37173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 38173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel __loopi \ar, \at, \size, (4 << (\line_width)) 39173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel \insn \ar, 0 << (\line_width) 40173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel \insn \ar, 1 << (\line_width) 41173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel \insn \ar, 2 << (\line_width) 42173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel \insn \ar, 3 << (\line_width) 43173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel __endla \ar, \at, 4 << (\line_width) 44173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 45173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .endm 46173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 47173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 48173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .macro __loop_cache_range ar as at insn line_width 49173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 50173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel extui \at, \ar, 0, \line_width 51173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel add \as, \as, \at 52173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 53173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel __loops \ar, \as, \at, \line_width 54173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel \insn \ar, 0 55173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel __endla \ar, \at, (1 << (\line_width)) 56173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 57173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .endm 58173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 59173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 60173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .macro __loop_cache_page ar at insn line_width 61173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 62173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel __loopi \ar, \at, PAGE_SIZE, 4 << (\line_width) 63173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel \insn \ar, 0 << (\line_width) 64173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel \insn \ar, 1 << (\line_width) 65173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel \insn \ar, 2 << (\line_width) 66173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel \insn \ar, 3 << (\line_width) 67173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel __endla \ar, \at, 4 << (\line_width) 68173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 69173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .endm 70173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 71173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 72173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel#if XCHAL_DCACHE_LINE_LOCKABLE 73173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 74173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .macro ___unlock_dcache_all ar at 75173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 76173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel __loop_cache_all \ar \at diu XCHAL_DCACHE_SIZE XCHAL_DCACHE_LINEWIDTH 77173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 78173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .endm 79173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 80173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel#endif 81173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 82173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel#if XCHAL_ICACHE_LINE_LOCKABLE 83173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 84173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .macro ___unlock_icache_all ar at 85173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 86173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel __loop_cache_all \ar \at iiu XCHAL_ICACHE_SIZE XCHAL_ICACHE_LINEWIDTH 87173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 88173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .endm 89173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel#endif 90173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 91173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .macro ___flush_invalidate_dcache_all ar at 92173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 93173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel __loop_cache_all \ar \at diwbi XCHAL_DCACHE_SIZE XCHAL_DCACHE_LINEWIDTH 94173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 95173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .endm 96173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 97173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 98173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .macro ___flush_dcache_all ar at 99173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 100173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel __loop_cache_all \ar \at diwb XCHAL_DCACHE_SIZE XCHAL_DCACHE_LINEWIDTH 101173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 102173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .endm 103173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 104173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 105173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .macro ___invalidate_dcache_all ar at 106173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 107173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel __loop_cache_all \ar \at dii __stringify(DCACHE_WAY_SIZE) \ 108173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel XCHAL_DCACHE_LINEWIDTH 109173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 110173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .endm 111173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 112173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 113173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .macro ___invalidate_icache_all ar at 114173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 115173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel __loop_cache_all \ar \at iii __stringify(ICACHE_WAY_SIZE) \ 116173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel XCHAL_ICACHE_LINEWIDTH 117173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 118173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .endm 119173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 120173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 121173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 122173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .macro ___flush_invalidate_dcache_range ar as at 123173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 124173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel __loop_cache_range \ar \as \at dhwbi XCHAL_DCACHE_LINEWIDTH 125173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 126173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .endm 127173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 128173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 129173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .macro ___flush_dcache_range ar as at 130173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 131173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel __loop_cache_range \ar \as \at dhwb XCHAL_DCACHE_LINEWIDTH 132173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 133173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .endm 134173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 135173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 136173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .macro ___invalidate_dcache_range ar as at 137173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 138173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel __loop_cache_range \ar \as \at dhi XCHAL_DCACHE_LINEWIDTH 139173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 140173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .endm 141173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 142173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 143173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .macro ___invalidate_icache_range ar as at 144173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 145173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel __loop_cache_range \ar \as \at ihi XCHAL_ICACHE_LINEWIDTH 146173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 147173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .endm 148173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 149173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 150173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 151173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .macro ___flush_invalidate_dcache_page ar as 152173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 153173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel __loop_cache_page \ar \as dhwbi XCHAL_DCACHE_LINEWIDTH 154173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 155173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .endm 156173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 157173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 158173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .macro ___flush_dcache_page ar as 159173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 160173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel __loop_cache_page \ar \as dhwb XCHAL_DCACHE_LINEWIDTH 161173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 162173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .endm 163173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 164173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 165173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .macro ___invalidate_dcache_page ar as 166173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 167173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel __loop_cache_page \ar \as dhi XCHAL_DCACHE_LINEWIDTH 168173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 169173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .endm 170173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 171173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 172173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .macro ___invalidate_icache_page ar as 173173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 174173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel __loop_cache_page \ar \as ihi XCHAL_ICACHE_LINEWIDTH 175173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel 176173d6681380aa1d60dfc35ed7178bd7811ba2784Chris Zankel .endm 177