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