bmips: add new target
[openwrt/openwrt.git] / target / linux / bmips / image / lzma-loader / src / cache.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * LZMA compressed kernel loader for Atheros AR7XXX/AR9XXX based boards
4 *
5 * Copyright (C) 2011 Gabor Juhos <juhosg@openwrt.org>
6 *
7 * The cache manipulation routine has been taken from the U-Boot project.
8 * (C) Copyright 2003
9 * Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
10 */
11
12 #include "cache.h"
13 #include "cacheops.h"
14 #include "config.h"
15 #include "printf.h"
16
17 #define cache_op(op,addr) \
18 __asm__ __volatile__( \
19 " .set push \n" \
20 " .set noreorder \n" \
21 " .set mips3\n\t \n" \
22 " cache %0, %1 \n" \
23 " .set pop \n" \
24 : \
25 : "i" (op), "R" (*(unsigned char *)(addr)))
26
27 void flush_cache(unsigned long start_addr, unsigned long size)
28 {
29 unsigned long lsize = CONFIG_CACHELINE_SIZE;
30 unsigned long addr = start_addr & ~(lsize - 1);
31 unsigned long aend = (start_addr + size + (lsize - 1)) & ~(lsize - 1);
32
33 printf("blasting from 0x%08x to 0x%08x (0x%08x - 0x%08x)\n", start_addr, size, addr, aend);
34
35 while (1) {
36 cache_op(Hit_Writeback_Inv_D, addr);
37 cache_op(Hit_Invalidate_I, addr);
38 if (addr == aend)
39 break;
40 addr += lsize;
41 }
42 }