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